예제 #1
0
 def decide_what_to_do(self):
     actions = []
     
     if self.deer.is_attacked():
         if rng.rand() < self.deer.aggro_chance:
             self.action_queue.append(PursueAction(self.deer, self.deer.attacker))
         else:
             self.action_queue.append(FleeAction(self.deer, self.deer.attacker))
     elif self.deer.herd_is_attacked():
         if rng.rand() < self.deer.get_herd_aggro_chance():
             self.deer.recent_actions.append(f"{self.deer.entity_name} is defending his herd!")
             for d in self.deer.herd:
                 if d.is_attacked():
                     self.action_queue.append(PursueAction(self.deer, d.attacker))
                     break
         else:
             self.roam()
     elif self.deer.is_hungry():
         flog.debug("deer is hungry")
         self.action_queue.append(GrazeAction(self.deer))
     elif self.deer.is_tired():
         flog.debug("deer is tired")
         self.deer.recent_actions.append(f"{self.deer.entity_name} is laying down.")
         self.deer.ai.action_queue.append(SleepAction(self.deer))
     else:
         self.roam()
     
     return actions
예제 #2
0
    def progress(self):
        if self.alive:
            if self.is_affected_by(stfx.Starvation):
                self.curr_health -= stats.Stats.map(
                )["wolf"]["starvation-health-loss"]
                if not self.alive:
                    self.recent_actions.append("Wolf died of starvation!")
            if self.is_affected_by(stfx.SleepDeprivation):
                self.curr_health -= stats.Stats.map(
                )["wolf"]["sleep-deprivation-health-loss"]
                chance_to_pass_out = self.rand_health_alert(
                ) * stats.Stats.map(
                )["wolf"]["sleep-deprivation-chance-to-pass-out"]
                roll = rng.rand()

                # flog.debug("---chance to pass out---")
                # flog.debug(f"health: {self.curr_health}")
                # flog.debug(f"chance: {chance_to_pass_out}")
                # flog.debug(f"roll: {roll}")
                # flog.debug(f"res: {chance_to_pass_out > roll}")

                if chance_to_pass_out > roll and not self.asleep:
                    self.recent_actions.append(
                        "Wolf passed out from sleep deprivation!")
                    self.ai.clear_action_queue()
                    self.ai.action_queue.append(SleepAction(self))

            self.curr_hunger -= stats.Stats.map()["wolf"]["hunger-loss"]
            self.curr_energy -= stats.Stats.map()["wolf"]["energy-loss"]
            self.try_flush_recent_actions()
예제 #3
0
    def shoot(self, user, target):
        hit = (self.accuracy * user.accuracy) > rng.rand()

        if hit:
            target.curr_health -= self.damage
        else:
            flog.debug("arrow shot missed!")

        return hit
            
예제 #4
0
    def spawn_entities(self):
        intelligent_entities = []
        static_entities = []
        self.berry_bush_count = 0

        # wolf = wlf.Wolf(self, 80, 20)
        # self.game_map.tiles[20][80].entities.append(wolf)
        # intelligent_entities.append(wolf)

        for y, row in enumerate(self.game_map.tiles):
            for x, tile in enumerate(row):
                if tile.terrain.walkable:
                    if rng.rand() < stats.Stats.map()["rabbit"]["spawn"]:
                        burrow = rbt.Burrow(x, y)
                        rabbit = rbt.Rabbit(self, x, y)
                        rabbit.burrow = burrow
                        self.game_map.tiles[y][x].add_entities(
                            [burrow, rabbit])
                        intelligent_entities.append(rabbit)
                    if rng.rand() < stats.Stats.map()["wolf"]["spawn"]:
                        wolf = wlf.Wolf(self, x, y)
                        self.game_map.tiles[y][x].entities.append(wolf)
                        intelligent_entities.append(wolf)
                    if rng.rand() < stats.Stats.map()["deer"]["spawn"]:
                        buck = dr.Buck(self, x, y)
                        self.game_map.tiles[y][x].entities.append(buck)
                        intelligent_entities.append(buck)

                        for i in range(rng.range_int(1, 4)):
                            doe = dr.Doe(self, x, y, buck)
                            self.game_map.tiles[y][x].entities.append(doe)
                            intelligent_entities.append(doe)
                            buck.herd.append(doe)
                if isinstance(tile.terrain, terrain.Grass) or isinstance(
                        tile.terrain, terrain.Forest):
                    if rng.rand() < stats.Stats.map()["berry-bush"]["spawn"]:
                        berry_bush = bb.BerryBush(self, x, y)
                        self.game_map.tiles[y][x].entities.append(berry_bush)
                        static_entities.append(berry_bush)
                        self.berry_bush_count += 1

        return intelligent_entities, static_entities
예제 #5
0
    def perform(self):
        sleep_in = rng.rand() < stats.Stats.map()["rabbit"]["sleep-in-chance"]

        if self.rabbit.is_tired() or sleep_in:
            flog.debug("rabbit is sleeping")
            self.rabbit.recent_actions.append(
                "Rabbit is asleep in its burrow.")
            self.rabbit.asleep = True
            self.rabbit.hide()
            self.rabbit.ai.action_queue.append(SleepAction(self.rabbit))
        else:
            flog.debug("rabbit woke up")
            self.rabbit.recent_actions.append(
                "Rabbit woke up and is leaving its burrow.")
            self.rabbit.asleep = False
            self.rabbit.unhide()
예제 #6
0
    def perform(self):
        sleep_in = rng.rand() < stats.Stats.map()["deer"]["sleep-in-chance"]

        if self.deer.should_wake_up():
            flog.debug("deer woke up after being attacked")
            self.deer.recent_actions.append(f"{self.deer.entity_name} woke up.")
            self.deer.asleep = False
        elif self.deer.is_tired():
            flog.debug("deer is sleeping")
            self.deer.recent_actions.append(f"{self.deer.entity_name} is asleep.")
            self.deer.asleep = True
            self.deer.ai.action_queue.append(SleepAction(self.deer))
        else:
            flog.debug("deer woke up")
            self.deer.recent_actions.append(f"{self.deer.entity_name} woke up.")
            self.deer.asleep = False
예제 #7
0
    def should_wake_up(self):
        if self.is_attacked():
            return True
        else:
            chance_to_wake_up = 0

            if self.is_affected_by(stfx.Starvation):
                chance_to_wake_up += self.rand_health_alert()

            roll = rng.rand()

            # flog.debug("---chance to wake up---")
            # flog.debug(f"health: {self.curr_health}")
            # flog.debug(f"chance: {chance_to_wake_up}")
            # flog.debug(f"roll: {roll})")
            # flog.debug(f"res: {chance_to_wake_up > roll}")

            return roll < chance_to_wake_up
예제 #8
0
    def decide_what_to_do(self):
        actions = []

        if self.wolf.is_hungry():
            flog.debug("wolf is hungry")
            self.action_queue.append(SearchAreaAction(self.wolf))
        elif self.wolf.is_tired():
            flog.debug("wolf is tired")
            self.action_queue.append(SleepAction(self.wolf))
        else:
            if rng.rand() < stats.Stats.map()["wolf"]["nap-chance"]:
                flog.debug("wolf is napping")
                self.wolf.recent_actions.append(
                    f"Wolf is laying down for a nap.")
                self.action_queue.append(SleepAction(self.wolf))
            else:
                self.roam()

        return actions
예제 #9
0
    def perform(self):
        self.wolf.curr_energy += stats.Stats.map()["wolf"]["sleep-energy-gain"]
        self.wolf.curr_health += stats.Stats.map()["wolf"]["sleep-health-gain"]
        sleep_in = rng.rand() < stats.Stats.map()["wolf"]["sleep-in-chance"]

        if self.wolf.should_wake_up():
            flog.debug("wolf woke up after being attacked")
            self.wolf.recent_actions.append(
                f"{self.wolf.entity_name} woke up.")
            self.wolf.asleep = False
        elif self.wolf.curr_energy < (
                self.wolf.max_energy -
                stats.Stats.map()["wolf"]["energy-loss"]):
            flog.debug("wolf is sleeping")
            self.wolf.recent_actions.append(
                f"{self.wolf.entity_name} is asleep.")
            self.wolf.asleep = True
            self.wolf.ai.action_queue.append(SleepAction(self.wolf))
        else:
            flog.debug("wolf woke up")
            self.wolf.recent_actions.append(
                f"{self.wolf.entity_name} woke up.")
            self.wolf.asleep = False
예제 #10
0
    def should_wake_up(self):
        if self.attacked:
            return True
        else:
            chance_to_wake_up = 0

            if self.bed == None:
                chance_to_wake_up += stats.Stats.map()["ground"]["wake-chance"]
            else:
                chance_to_wake_up += self.bed.wake_chance

            if self.is_affected_by(stfx.Starvation):
                chance_to_wake_up += self.rand_health_alert()

            roll = rng.rand()

            # flog.debug("---chance to wake up---")
            # flog.debug(f"health: {self.curr_health}")
            # flog.debug(f"chance: {chance_to_wake_up}")
            # flog.debug(f"roll: {roll})")
            # flog.debug(f"res: {chance_to_wake_up > roll}")

            return roll < chance_to_wake_up
예제 #11
0
 def is_hungry(self):
     return self.curr_hunger < stats.Stats.map(
     )["wolf"]["hunger-threshold"] or rng.rand() < self.need_a_snack_chance
예제 #12
0
 def is_hungry(self):
     return rng.rand() < stats.Stats.map()["rabbit"]["hunger-chance"]
예제 #13
0
 def should_maintain_pursuit(self):
     return rng.rand() > self.stop_pursuit_chance