Exemple #1
0
        public override void Attack(Creature foe)
        {
            if (!(foe is Monster))
            {
                throw new ArgumentException();
            }
            Monster foe_ = foe as Monster;         //player can only attack a monster

            Pack tempPack = foe_.pack;             //monster's pack

            Node packLocation = tempPack.location; //same as player's location

            //gives information to the user
            Logger.log("Location is " + tempPack.location.id);
            Logger.log("All monsters in the pack: ");
            foreach (Monster m in tempPack.members)
            {
                Logger.log(m.id);
            }
            Logger.log("All packs in location ");
            foreach (Pack p in packLocation.packs)
            {
                Logger.log(p.id);
            }
            if (!accelerated)                                       //if user is not accelerated, player only attacks to parameter monster
            {
                foe.HP = (int)Math.Max(0, foe.HP - AttackRating);   //HP can not be less than 0
                String killMsg = foe.HP == 0 ? ", KILLING it" : ""; //monster dies
                Logger.log("Creature " + id + " attacks " + foe.id + killMsg + ".");
                if (foe.HP == 0)                                    //if the monster died
                {
                    tempPack.members.Remove(foe_);                  //remove monster from its pack

                    if (tempPack.members.Count == 0)                //check if the pack is empty
                    {
                        Logger.log("Pack is now empty' pack id " + tempPack.id);
                        Logger.log("Remaining packs in the location:");

                        foreach (Pack pack in packLocation.packs)
                        {
                            Logger.log("Pack " + pack.id + " in node " + packLocation);
                        }

                        //THIS PART SHOULD BE TESTED, I forgot why Chris and I checked for tempPack==null
                        // We probably forgot to change it back after debugging
                        //commented null comparison

                        //pack is removed from the node, regarding what AttackBool returns to the main flow

                        /*
                         * if (tempPack == null)
                         * {
                         *  Logger.log("it is null");
                         *  foreach (Pack pack in packLocation.packs)
                         *  {
                         *      Logger.log("Pack " + pack.id + " in node " + packLocation);
                         *  }
                         * }
                         * else {
                         *  Logger.log("It is not null");
                         *  foreach (Pack pack in packLocation.packs)
                         *  {
                         *      Logger.log("Pack " + pack.id + " in node " + packLocation);
                         *  }
                         * }*/
                        //packLocation.packs.Remove(tempPack);
                        //Logger.log("Killed the pack' commented remove");
                    }
                    KillPoint++;
                }
            }
            else
            {                                                          //player attacks every monster in the pack
                int packCount = foe_.pack.members.Count;
                foe_.pack.members.RemoveAll(target => target.HP <= 0); //already dead monsters?
                KillPoint += (uint)(packCount - foe_.pack.members.Count);
                // Added the following
                for (int i = packCount - 1; i >= 0; i--)                  //for each monster in the pack
                {
                    Monster target = foe_.pack.members.ElementAt(i);

                    target.HP = (int)Math.Max(0, target.HP - AttackRating);                     //player attacks to the monster
                    String killMsg = target.HP == 0 ? ", KILLING it" : "";
                    Logger.log("Creature " + id + " attacks " + target.id + killMsg + ".");
                    //base.Attack(target);
                    if (target.HP == 0)                   //if the monster dies
                    {
                        foe_.pack.members.Remove(target); //remove it from the list
                        KillPoint++;
                    }
                }

                accelerated = false; //player not accelerated anymore
            }
        }