Example #1
0
 def try_do_weighted_action(self):
     """
     Does the ranged attack, assumes that can_do_ranged_attack returned True.
     """
     targeted_actions = [action for action in self.parent.get_children_with_tag("monster_weighted_action")
                         if action.can_act()]
     chosen_action = rng.weighted_choice(targeted_actions)
     if "monster_target_action" in chosen_action.tags:
         chosen_target = random.choice(chosen_action.get_target_options())
         if (not chosen_target.has("is_player")  # Only target the player if monster is aware of the player.
             or self.parent.monster_actor_state.value == MonsterActorState.HUNTING):
             return chosen_action.act(chosen_target.position.value)
         else:
             return
     return chosen_action.act()
Example #2
0
 def roll(self, numLines = -1):
     if numLines == -1:
         numLines = len(self.m_lines)
     primeChance = 0.02*numLines
     ranks = []
     for i in range(numLines):
         if i == 0:
             ranks.append(self.m_rank)
         else:
             if ranks[i - 1] == self.m_rank and random.random() < primeChance:
                 ranks.append(self.m_rank)
             else:
                 ranks.append(max(0, self.m_rank - 1))
     self.m_lines = []
     for i in range(numLines):
         line = rng.weighted_choice(PotentialLib.roll(self, ranks[i]))
         self.m_lines.append(line)
Example #3
0
 def expand(self):
     self.m_lines.append(rng.weighted_choice(PotentialLib.roll(self, max(0, self.m_rank - 1))))