Exemplo n.º 1
0
        public void GetCharacterEquipped(Character character)
        {
            List <Equipped> equippeds = GetAllEquipped();

            foreach (var equipped in equippeds)
            {
                if (equipped.EquppedID == character.ID)
                {
                    //sets weapon
                    WeaponLogic   weaponLogic = new WeaponLogic();
                    List <Weapon> weapons     = weaponLogic.GetAllWeapons();
                    foreach (Weapon weapon in weapons)
                    {
                        if (weapon.ID == equipped.WeaponID)
                        {
                            character.EquipedWeapon = weapon;
                        }
                    }

                    //sets armour
                    ArmourLogic   armourLogic = new ArmourLogic();
                    List <Armour> armours     = armourLogic.GetAllArmours();
                    foreach (Armour armour in armours)
                    {
                        if (armour.ID == equipped.HelmetID)
                        {
                            character.EquipedHelmet = armour;
                        }
                        if (armour.ID == equipped.BodyID)
                        {
                            character.EquipedBody = armour;
                        }
                        if (armour.ID == equipped.LegsID)
                        {
                            character.EquipedLegs = armour;
                        }
                        if (armour.ID == equipped.FeetID)
                        {
                            character.EquipedFeet = armour;
                        }
                    }
                }
            }
        }
        public void GetCharacterArmours(Character character)
        {
            List <Inventory> inventories = GetAllInventories();
            ArmourLogic      armourLogic = new ArmourLogic();
            List <Armour>    armours     = armourLogic.GetAllArmours();

            foreach (var inventory in inventories)
            {
                if (inventory.CharacterID == character.ID)
                {
                    foreach (var armour in armours)
                    {
                        if (armour.ID == inventory.ArmourID)
                        {
                            armour.Amount = inventory.Amount;
                            character.myArmours.Add(armour);
                        }
                    }
                }
            }
        }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
0
        public Character SmithItem(Character character, string barName, string itemCraftName, int barAmountToDistract)
        {
            //First we need to remove the amount of bars from the player that is needed to craft this item.
            bool removedBars = false;

            foreach (SmithingItem mySmithingItem in character.mySmithingItems)
            {
                if (mySmithingItem.Name == barName)
                {
                    if (mySmithingItem.Amount >= barAmountToDistract)
                    {
                        mySmithingItem.AddToAmount(-barAmountToDistract);
                        removedBars = true;
                    }
                }
            }

            if (removedBars)
            {
                string itemToMake = barName.Replace(" bar", "");
                itemToMake = itemToMake + " " + itemCraftName;

                //If the removal of the bars from the player was a succes we can now make and add the item to the players inventory.
                //This can either be a piece of armour or a weapon so we need to check both.
                WeaponLogic weaponLogic = new WeaponLogic();
                bool        weaponAdded = false;
                foreach (Weapon weapon in weaponLogic.GetAllWeapons())
                {
                    //First we check if this is the item that we need to add to our inventory for every weapon.
                    if (weapon.Name == itemToMake)
                    {
                        //If the player already has this item we can add 1 to the amount.
                        foreach (Weapon myWeapon in character.myWeapons)
                        {
                            //We already have this weapon
                            if (myWeapon.Name == itemToMake)
                            {
                                myWeapon.Amount += 1;
                                character.SmithingExperience += 10;
                                weaponAdded = true;
                            }
                        }

                        //If the player doesn't have this item yet we can create it.
                        if (weapon.Name == itemToMake && !weaponAdded)
                        {
                            weapon.Amount = 1;
                            character.myWeapons.Add(weapon);
                            weaponAdded = true;
                        }
                    }
                }

                bool        armourAdded = false;
                ArmourLogic armourLogic = new ArmourLogic();
                foreach (Armour armour in armourLogic.GetAllArmours())
                {
                    //First we check if this is the item that we need to add to our inventory for every piece of armour.
                    if (armour.Name == itemToMake)
                    {
                        //If the player already has this item we can add 1 to the amount.
                        foreach (Armour myArmour in character.myArmours)
                        {
                            //We already have this weapon
                            if (myArmour.Name == itemToMake)
                            {
                                myArmour.Amount += 1;
                                character.SmithingExperience += 10;
                                armourAdded = true;
                            }
                        }

                        //If the player doesn't have this item yet we can create it.
                        if (armour.Name == itemToMake && !armourAdded)
                        {
                            armour.Amount = 1;
                            character.myArmours.Add(armour);
                            armourAdded = true;
                        }
                    }
                }
            }

            return(character);
        }