/* Execute a fight between the player and the packs in this node. * Such a fight can take multiple rounds as describe in the Project Document. * A fight terminates when either the node has no more monster-pack, or when * the player's HP is reduced to 0. */ public void fight(Player player) { if (packs.Count == 0 || player == null) { return; } // calculate flee probability Pack pack = packs[0]; int currentHP = pack.currentTotalHP(); float probability = (1f - currentHP / pack.startingHP) / 2f; float percentage = probability * 100; float randomNr = RandomGenerator.rnd.Next(0, 101); // pack attempts to flee if (randomNr <= percentage) { // move to first node which is not overpopulated foreach (Node n in neighbors) { // calculate max capacity uint capacity = pack.dungeon.M * (pack.dungeon.level(n) + 1); // calculate current population in node int population = 0; foreach (Pack p in n.packs) { population += p.members.Count; } // move to node if pack fits in it and pack remains in its own zone (level) if (population + pack.members.Count <= capacity && pack.dungeon.level(pack.location) == pack.dungeon.level(n)) { pack.move(n); break; } } } // pack attacks player else { pack.Attack(player); } }