DIBedTime java

Code:

package chobit;

import java.util.ArrayList;

public class DIBedTime extends DISkill {
   /*
    * a simple skill at bed time she will sing a lullabye next if the user
    * addresses the AGI she will scold him the skill ensures the AGI has quite time
    * the scold mode is active for 1 hour after the lullabye the user can reset the
    * trigger bedtime by saying "lv2name intHour is bedtime" this is an automatic
    * lv2 skill can be stand alone or as a set of the DIJirachi skill
    * the time trigger cannot be set at the time it is set.
    */
   private boolean standbye = true;
   private PlayGround playGround = new PlayGround();
   private int trigHour = 20;
   private int algToUse = 0; // 0 nothing 1 lullabye, 2 scold
   private RegexUtil regexUtil = new RegexUtil();
   public DIBedTime(Kokoro kokoro) {
      super(kokoro);
   }

   @Override
   public void input(String ear, String skin, String eye) {
      int nowHour = playGround.getHoursAsInt(); // the current hour
      // set up alg to summon :
      if (standbye) {
         if (trigHour == nowHour) {
            algToUse = 1;
            this.setSentAlg(true);
            standbye = false;
            return;
         }
      } else {
         if (nowHour != trigHour) {
            standbye = true;
         } else if (!ear.isEmpty()) {
            algToUse = 2;
            this.setSentAlg(true);
         }
         return;
      }
      // check if user wants a different bedtime :
      String bedTime = regexUtil.regexChecker("(\\d+)(?= is bedtime)", ear);
      if (bedTime != "") {
         trigHour = Integer.parseInt(bedTime);
         if (trigHour > 24 || trigHour < 0) {
            trigHour = 20;
         }
      }
   }

   @Override
   public void output(Neuron noiron) {
      switch (algToUse) {
      case 1:
         noiron.algParts.add(lullabye());
         // this.setSentAlg(true);
         break;
      case 2:
         noiron.algParts.add(scold());
         // this.setSentAlg(true);
         break;
      default:
         break;
      }
      algToUse = 0;
   }

   private Algorithm lullabye() {
      AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "lullabye"));
      String representation = "lullabye";
      ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
      algParts1.add(itte);
      Algorithm algorithm = new Algorithm("lullabye", representation, algParts1);
      return algorithm;
   }

   private Algorithm scold() {
      AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "go to sleep"));
      String representation = "scold";
      ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
      algParts1.add(itte);
      Algorithm algorithm = new Algorithm("scold", representation, algParts1);
      return algorithm;
   }

   @Override
   public Boolean auto() {
      // TODO Auto-generated method stub
      return true;
   }
}


DIBedTime alternative ver :

Code:

package chobit;

import java.util.ArrayList;

public class DIBedTime extends DISkill {
   /*
    * a simple skill at bed time she will sing a lullabye next if the user
    * addresses the AGI she will scold him the skill ensures the AGI has quite time
    * the scold mode is active for 1 hour after the lullabye the user can reset the
    * trigger bedtime by saying "lv2name intHour is bedtime" this is an automatic
    * lv2 skill can be stand alone or as a set of the DIJirachi skill the time
    */
   private boolean standbye = true;
   private PlayGround playGround = new PlayGround();
   private int trigHour = 20;
   private int algToUse = 0; // 0 nothing 1 lullabye, 2 scold
   private RegexUtil regexUtil = new RegexUtil();
   public DIBedTime(Kokoro kokoro) {
      super(kokoro);
   }

   @Override
   public void input(String ear, String skin, String eye) {
      int nowHour = playGround.getHoursAsInt(); // the current hour
      // set up alg to summon :
      if (standbye) {
         if (trigHour == nowHour) {
            algToUse = 1;
            this.setSentAlg(true);
            standbye = false;
            return;
         }
      } else {
         if (nowHour != trigHour) {
            standbye = true;
         } else if (!ear.isEmpty()) {
            algToUse = 2;
            this.setSentAlg(true);
         }
         // return;
      }
      // check if user wants a different bedtime :
      String bedTime = regexUtil.regexChecker("(\\d+)(?= is bedtime)", ear);
      if (bedTime != "") {
         trigHour = Integer.parseInt(bedTime);
         if (trigHour > 24 || trigHour < 0) {
            trigHour = 20;
         }
      }
   }

   @Override
   public void output(Neuron noiron) {
      switch (algToUse) {
      case 1:
         noiron.algParts.add(lullabye());
         // this.setSentAlg(true);
         break;
      case 2:
         noiron.algParts.add(scold());
         // this.setSentAlg(true);
         break;
      default:
         break;
      }
      algToUse = 0;
   }

   private Algorithm lullabye() {
      AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "lullabye"));
      String representation = "lullabye";
      ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
      algParts1.add(itte);
      Algorithm algorithm = new Algorithm("lullabye", representation, algParts1);
      return algorithm;
   }

   private Algorithm scold() {
      AbsAlgPart itte = new Chi(this.kokoro, this.getClass().getSimpleName(), new APSay(1, "go to sleep"));
      String representation = "scold";
      ArrayList<AbsAlgPart> algParts1 = new ArrayList<>();
      algParts1.add(itte);
      Algorithm algorithm = new Algorithm("scold", representation, algParts1);
      return algorithm;
   }

   @Override
   public Boolean auto() {
      // TODO Auto-generated method stub
      return true;
   }
}


you can add this skill as a stand alone skill or as a set of the mommygf skills :

update to the Bijuu class :

Code:

package chobit;

import java.util.ArrayList;

public class Bijuu extends AbsCmdReq {
   /*
    * a container cls for a list of DIskills
    */
   protected ArrayList<DISkill> dSkills = new ArrayList<>();
   private Kokoro kokoro;
   final int constTolerance = 3;
   private int tolerance = constTolerance;
   private Boolean enabled = true;
   private Boolean fastBreak = true;
   protected Boolean isAutomatic = false;
   protected Person person;

   public Bijuu(Person master, Kokoro kokoro, DISkill... skills) {
      super();
      this.kokoro = kokoro;
      this.person = person;
      for (DISkill i : skills) {
         dSkills.add(i);
      }
      for (DISkill i : skills) {
         if(i.auto()) {isAutomatic = true;break;}
      }
   }

   public void modeFlip() {
      // pain = *repetition/ actual high level pain
      // sets weather the Bijuu is active or not
      tolerance -= kokoro.getPain(this.getClass().getSimpleName());
      if (tolerance < 1) {
         this.enabled = !this.enabled;
      }
   }

   @Override
   public void input(String ear, String skin, String eye) {
      if (enabled) {
         // if Bijuu enabled
         for (DISkill dISkill : dSkills) {
            dISkill.input(ear, skin, eye);
            if (dISkill.getSentAlg()) {
               /*
                * found an alg ! exit the loop ! I dont need another alg !!
                */
               dISkill.setOutput(true);
               // hey, DIskill, remind me you have an alg waiting for pickup
               fastBreak = false;
               // dont skip alg pick up stage.
               break;
            }
         }
      }
      else {
         reenable(ear, skin, eye); // maybe I should be revived
      }
   }

   @Override
   public void output(Neuron noiron) {
      // TODO Auto-generated method stub
      if (!fastBreak) {
         // if alg waiting for pick up
         fastBreak = true; // reset
         for (DISkill dISkill : dSkills) {
            if (dISkill.getOutput()) {
               // found the alg
               dISkill.output(noiron);
               // OK done, bye
               break;
            }
         }
      }
   }

   public void reenable(String ear, String skin, String eye) {
      if (ear.contains("pain") || skin.contains("pain")) {
         tolerance -= 1;
         if (tolerance < 1) {
            this.enabled = true;
         }
      }
   }
   @Override
   public Boolean auto() {
      // TODO Auto-generated method stub
      return isAutomatic;
   }
}


DIJirachi skill add bedtime skill to the set :

Code:

package chobit;

public class DIJirachi extends Bijuu {
   // a set of skills to make the user happy and grant his wishes
   public DIJirachi(Person master, Kokoro kokoro) {
      super(master, kokoro, new DIMommyGf(kokoro, master), new DIBedTime(kokoro));

   }

}


new DIBedTime(kokoro) is all the coded needed to add DIBedTime to the DIJirachi
which is the mommygf skill set

to sum it app, add the above classes and
in the Chobit c'tor :
dClassesLv3.add(new DIJirachi(master, kokoro));

:humiliation: :pepecool: