public void GetCharacterFishes(Character character)
        {
            List <Inventory> inventories   = GetAllInventories();
            FishItemLogic    fishItemLogic = new FishItemLogic();
            List <FishItem>  fishItems     = fishItemLogic.GetAllFishItems();

            foreach (var inventory in inventories)
            {
                if (inventory.CharacterID == character.ID)
                {
                    foreach (var fishItem in fishItems)
                    {
                        if (fishItem.ID == inventory.FishID)
                        {
                            fishItem.Amount = inventory.Amount;
                            character.myFishItems.Add(fishItem);
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public Character MonsterKilled(Character character, Monster monster)
        {
            //Loops through all monsterdrops to see if defeating this monster offers a chance on one or multiple items
            foreach (MonsterDrop monsterDrop in monsterDropContainerRepository.GetAllMonsterDrops())
            {
                if (monsterDrop.ID == monster.ID)
                {
                    //Picks a random number 1-100. If this numbers is the same or lower as the chance to get it the player will get it
                    //(this way we created a drop system with drops based on percentages).
                    Random random = new Random();
                    int    number = random.Next(1, 100);

                    if (number <= monsterDrop.Chance)
                    {
                        foreach (Drop drop in dropContainerRepository.GetAllDrops())
                        {
                            if (monsterDrop.DropID == drop.DropID)
                            {
                                //If the ID of a item isn't 0 that means it dropped something of that category.
                                //Weapon drop
                                if (drop.WeaponID != 0)
                                {
                                    WeaponLogic   weaponLogic = new WeaponLogic();
                                    List <Weapon> weapons     = weaponLogic.GetAllWeapons();
                                    foreach (Weapon weapon in weapons)
                                    {
                                        if (weapon.ID == drop.WeaponID)
                                        {
                                            bool added = false;
                                            //If character already has the weapon it needs to up the amount by 1.
                                            foreach (Weapon myWeapon in character.myWeapons)
                                            {
                                                if (myWeapon.Name == weapon.Name)
                                                {
                                                    added = true;
                                                    myWeapon.AddToAmount(1);
                                                }
                                            }

                                            //If the weapon wasn't in the inventory already then add a new one:
                                            if (!added)
                                            {
                                                character.myWeapons.Add(weapon);
                                            }
                                        }
                                    }
                                }

                                //Armour drop
                                if (drop.ArmourID != 0)
                                {
                                    ArmourLogic   armourLogic = new ArmourLogic();
                                    List <Armour> armours     = armourLogic.GetAllArmours();
                                    foreach (Armour armour in armours)
                                    {
                                        if (armour.ID == drop.ArmourID)
                                        {
                                            armour.Amount = 1;
                                            character.myArmours.Add(armour);
                                        }
                                    }
                                }

                                //Fish drop
                                if (drop.FishID != 0)
                                {
                                    FishItemLogic   fishItemLogic = new FishItemLogic();
                                    List <FishItem> fishItems     = fishItemLogic.GetAllFishItems();
                                    foreach (FishItem fish in fishItems)
                                    {
                                        if (fish.ID == drop.FishID)
                                        {
                                            fish.Amount = 1;
                                            character.myFishItems.Add(fish);
                                        }
                                    }
                                }

                                //Smithing item drop
                                if (drop.SmithingItemID != 0)
                                {
                                    SmithingItemLogic   smithingItemLogic = new SmithingItemLogic();
                                    List <SmithingItem> smithingItems     = smithingItemLogic.GetAllSmithingItems();
                                    foreach (SmithingItem smithItem in smithingItems)
                                    {
                                        if (smithItem.ID == drop.SmithingItemID)
                                        {
                                            smithItem.Amount = 1;
                                            character.mySmithingItems.Add(smithItem);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            //Calculate how much experience the player got. This is based on the amount of health the defeated monster had.
            int defeatedHP = monster.Health * 3;

            if (character.AttackStyle == AttackStyles.Attack)
            {
                character.AttackExperience = character.AttackExperience + defeatedHP;
            }
            else if (character.AttackStyle == AttackStyles.Defence)
            {
                character.DefenceExperience = character.DefenceExperience + defeatedHP;
            }
            else if (character.AttackStyle == AttackStyles.Strength)
            {
                character.StrengthExperience = character.StrengthExperience + defeatedHP;
            }

            //You always get hitpoints exp for defeating a monster.
            character.HitpointsExperience = character.HitpointsExperience + monster.Health;

            //See if the killed monster was the slayer task of the player. If so we need to withdraw 1 monster from the amount of kills needed and give slayer experience.
            if (character.SlayerMonsterID == monster.ID)
            {
                character.SlayerExperience     = character.SlayerExperience + defeatedHP;
                character.SlayerMonsterAmount -= 1;
                if (character.SlayerMonsterAmount == 0)
                {
                    character.SlayerMonsterID   = 0;
                    character.SlayerMonsterName = null;
                }
            }

            //Sets correct levels before passing character back. If in the process of defeating a mosnter
            //One on multiple skills levelled up this will also be passed.
            SkillLogic skillLogic = new SkillLogic();

            skillLogic.SetCorrectLevels(character);

            return(character);
        }