예제 #1
0
    def post_training(self, trainer, trainer_msg="", targ_msg="", **kwargs):
        """
        Handles bookkeeping after this character is trained.

        Args:
            trainer: Character that trained us.
            trainer_msg (str): Message to send to trainer
            targ_msg (str): Message to send to this Character

        Returns:
            True if everything went off. Used for trying to catch extremely elusive caching errors.
        """
        from server.utils.arx_utils import trainer_diagnostics

        currently_training = trainer.db.currently_training or []
        # num_trained is redundancy to attempt to prevent cache errors.
        num_trained = trainer.db.num_trained or len(currently_training)
        if num_trained < len(currently_training):
            num_trained = len(currently_training)
        num_trained += 1
        self.db.trainer = trainer
        currently_training.append(self)
        trainer.db.currently_training = currently_training
        trainer.db.num_trained = num_trained
        if trainer_msg:
            trainer.msg(trainer_msg)
        if targ_msg:
            self.msg(targ_msg)
        print("Character.post_training call: %s" %
              trainer_diagnostics(trainer))
        return True
예제 #2
0
파일: npc.py 프로젝트: notcutty/arxcode
 def post_training(self,
                   trainer,
                   trainer_msg="",
                   targ_msg="",
                   ap_spent=0,
                   **kwargs):
     # if post_training works, then we proceed with training the agent
     if super(Retainer, self).post_training(trainer,
                                            trainer_msg=trainer_msg,
                                            targ_msg=targ_msg):
         currently_training = trainer.db.currently_training or []
         if self not in currently_training:
             # this should not be possible. Nonetheless, it has happened.
             from server.utils.arx_utils import trainer_diagnostics
             raise RuntimeError(
                 "Error: Training list not properly updated: %s" %
                 trainer_diagnostics(trainer))
         self.train_agent(trainer, ap_spent)
     else:
         raise RuntimeError(
             "Somehow, post_training was not called or did not return a value."
         )