public DaggerfallEntity(DaggerfallEntityBehaviour entityBehaviour)
        {
            this.entityBehaviour = entityBehaviour;
            equipTable           = new ItemEquipTable(this);

            // Allow for resetting specific player state on new game or when game starts loading
            SaveLoadManager.OnStartLoad  += SaveLoadManager_OnStartLoad;
            StartGameBehaviour.OnNewGame += StartGameBehaviour_OnNewGame;
        }
        /// <summary>
        /// Update armor values after equipping or unequipping a piece of armor.
        /// </summary>
        public void UpdateEquippedArmorValues(DaggerfallUnityItem armor, bool equipping)
        {
            if (armor.ItemGroup == ItemGroups.Armor ||
                (armor.ItemGroup == ItemGroups.MensClothing && armor.GroupIndex >= 6 && armor.GroupIndex <= 8) ||
                (armor.ItemGroup == ItemGroups.WomensClothing && armor.GroupIndex >= 4 && armor.GroupIndex <= 6)
                )
            {
                if (!armor.IsShield)
                {
                    // Get slot used by this armor
                    EquipSlots slot = ItemEquipTable.GetEquipSlot(armor);

                    // Get equip index with out of range check
                    int index = (int)DaggerfallUnityItem.GetBodyPartForEquipSlot(slot);
                    if (armorValues == null || index < 0 || index >= armorValues.Length)
                    {
                        return;
                    }

                    if (equipping)
                    {
                        armorValues[index] -= (sbyte)(armor.GetMaterialArmorValue() * 5);
                    }
                    else
                    {
                        armorValues[index] += (sbyte)(armor.GetMaterialArmorValue() * 5);
                    }
                }
                else
                {
                    // Shield armor values in classic are unaffected by their material type.
                    int[]       values             = { 0, 0, 0, 0, 0, 0, 0 }; // shield's effect on the 7 armor values
                    int         armorBonus         = armor.GetShieldArmorValue();
                    BodyParts[] protectedBodyParts = armor.GetShieldProtectedBodyParts();

                    foreach (var BodyPart in protectedBodyParts)
                    {
                        values[(int)BodyPart] = armorBonus;
                    }

                    for (int i = 0; i < armorValues.Length; i++)
                    {
                        if (equipping)
                        {
                            armorValues[i] -= (sbyte)(values[i] * 5);
                        }
                        else
                        {
                            armorValues[i] += (sbyte)(values[i] * 5);
                        }
                    }
                }
            }
        }
        void SetWeapon(FPSWeapon target, DaggerfallUnityItem weapon)
        {
            // Must be a weapon
            if (weapon.ItemGroup != ItemGroups.Weapons)
            {
                return;
            }

            // Setup target
            target.WeaponType       = DaggerfallUnity.Instance.ItemHelper.ConvertItemToAPIWeaponType(weapon);
            target.MetalType        = DaggerfallUnity.Instance.ItemHelper.ConvertItemMaterialToAPIMetalType(weapon);
            target.WeaponHands      = ItemEquipTable.GetItemHands(weapon);
            target.DrawWeaponSound  = weapon.GetEquipSound();
            target.SwingWeaponSound = weapon.GetSwingSound();
        }
Exemplo n.º 4
0
        public void SetEnemyEquipment(int variant)
        {
            // Assign the enemies starting equipment.
            AssignEnemyEquipment(GameManager.Instance.PlayerEntity, this, variant);

            // Initialize armor values to 100 (no armor)
            for (int i = 0; i < ArmorValues.Length; i++)
            {
                ArmorValues[i] = 100;
            }
            // Calculate armor values from equipment
            for (int i = (int)Game.Items.EquipSlots.Head; i < (int)Game.Items.EquipSlots.Feet; i++)
            {
                Items.DaggerfallUnityItem item = ItemEquipTable.GetItem((Items.EquipSlots)i);
                if (item != null && item.ItemGroup == Game.Items.ItemGroups.Armor)
                {
                    UpdateEquippedArmorValues(item, true);
                }
            }

            if (entityType == EntityTypes.EnemyClass)
            {
                // Clamp to maximum armor value of 60. In classic this also applies for monsters.
                // Note: Classic sets the value to 60 if it is > 50, which seems like an oversight.
                for (int i = 0; i < ArmorValues.Length; i++)
                {
                    if (ArmorValues[i] > 60)
                    {
                        ArmorValues[i] = 60;
                    }
                }
            }
            else
            {
                // Note: In classic, the above applies for equipment-using monsters as well as enemy classes.
                // The resulting armor values are often 60. Due to the +40 to hit against monsters this makes
                // monsters with equipment very easy to hit, and 60 is a worse value than any value monsters
                // have in their definition. To avoid this, in DF Unity the equipment values are only used if
                // they are better than the value in the definition.
                for (int i = 0; i < ArmorValues.Length; i++)
                {
                    if (ArmorValues[i] > (sbyte)(mobileEnemy.ArmorValue * 5))
                    {
                        ArmorValues[i] = (sbyte)(mobileEnemy.ArmorValue * 5);
                    }
                }
            }
        }
Exemplo n.º 5
0
        public void SetEnemyEquipment(int variant)
        {
            PlayerEntity player    = GameManager.Instance.PlayerEntity;
            int          itemLevel = player.Level;
            Genders      gender    = player.Gender;
            Races        race      = player.Race;
            int          chance    = 0;

            if (variant == 0)
            {
                // right-hand weapon
                int item = UnityEngine.Random.Range((int)Game.Items.Weapons.Broadsword, (int)(Game.Items.Weapons.Longsword) + 1);
                Items.DaggerfallUnityItem weapon = Game.Items.ItemBuilder.CreateWeapon((Items.Weapons)item, Game.Items.ItemBuilder.RandomMaterial(itemLevel));
                ItemEquipTable.EquipItem(weapon, true, false);
                items.AddItem(weapon);

                chance = 50;

                // left-hand shield
                item = UnityEngine.Random.Range((int)Game.Items.Armor.Buckler, (int)(Game.Items.Armor.Round_Shield) + 1);
                if (UnityEngine.Random.Range(1, 101) <= chance)
                {
                    Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, (Items.Armor)item, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                    ItemEquipTable.EquipItem(armor, true, false);
                    items.AddItem(armor);
                }
                // left-hand weapon
                else if (UnityEngine.Random.Range(1, 101) <= chance)
                {
                    item   = UnityEngine.Random.Range((int)Game.Items.Weapons.Dagger, (int)(Game.Items.Weapons.Shortsword) + 1);
                    weapon = Game.Items.ItemBuilder.CreateWeapon((Items.Weapons)item, Game.Items.ItemBuilder.RandomMaterial(itemLevel));
                    ItemEquipTable.EquipItem(weapon, true, false);
                    items.AddItem(weapon);
                }
            }
            else
            {
                // right-hand weapon
                int item = UnityEngine.Random.Range((int)Game.Items.Weapons.Claymore, (int)(Game.Items.Weapons.Battle_Axe) + 1);
                Items.DaggerfallUnityItem weapon = Game.Items.ItemBuilder.CreateWeapon((Items.Weapons)item, Game.Items.ItemBuilder.RandomMaterial(itemLevel));
                ItemEquipTable.EquipItem(weapon, true, false);
                items.AddItem(weapon);

                if (variant == 1)
                {
                    chance = 75;
                }
                else if (variant == 2)
                {
                    chance = 90;
                }
            }
            // helm
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Helm, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }
            // right pauldron
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Right_Pauldron, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }
            // left pauldron
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Left_Pauldron, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }
            // cuirass
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Cuirass, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }
            // greaves
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Greaves, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }
            // boots
            if (UnityEngine.Random.Range(1, 101) <= chance)
            {
                Items.DaggerfallUnityItem armor = Game.Items.ItemBuilder.CreateArmor(gender, race, Game.Items.Armor.Boots, Game.Items.ItemBuilder.RandomArmorMaterial(itemLevel));
                ItemEquipTable.EquipItem(armor, true, false);
                items.AddItem(armor);
            }

            // Initialize armor values to 100 (no armor)
            for (int i = 0; i < ArmorValues.Length; i++)
            {
                ArmorValues[i] = 100;
            }
            // Calculate armor values from equipment
            for (int i = (int)Game.Items.EquipSlots.Head; i < (int)Game.Items.EquipSlots.Feet; i++)
            {
                Items.DaggerfallUnityItem item = ItemEquipTable.GetItem((Items.EquipSlots)i);
                if (item != null && item.ItemGroup == Game.Items.ItemGroups.Armor)
                {
                    UpdateEquippedArmorValues(item, true);
                }
            }

            if (entityType == EntityTypes.EnemyClass)
            {
                // Clamp to maximum armor value of 60. In classic this also applies for monsters.
                // Note: Classic sets the value to 60 if it is > 50, which seems like an oversight.
                for (int i = 0; i < ArmorValues.Length; i++)
                {
                    if (ArmorValues[i] > 60)
                    {
                        ArmorValues[i] = 60;
                    }
                }
            }
            else
            {
                // Note: In classic, the above applies for equipment-using monsters as well as enemy classes.
                // The resulting armor values are often 60. Due to the +40 to hit against monsters this makes
                // monsters with equipment very easy to hit, and 60 is a worse value than any value monsters
                // have in their definition. To avoid this, in DF Unity the equipment values are only used if
                // they are better than the value in the definition.
                for (int i = 0; i < ArmorValues.Length; i++)
                {
                    if (ArmorValues[i] > (sbyte)(mobileEnemy.ArmorValue * 5))
                    {
                        ArmorValues[i] = (sbyte)(mobileEnemy.ArmorValue * 5);
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Update armor values after equipping or unequipping a piece of armor.
        /// </summary>
        public void UpdateEquippedArmorValues(DaggerfallUnityItem armor, bool equipping)
        {
            if (!armor.IsShield)
            {
                // Get slot used by this armor
                EquipSlots slot = ItemEquipTable.GetEquipSlot(armor);

                // This array maps equip slots to the order of the 7 armor values
                EquipSlots[] equipSlots = { EquipSlots.Head,       EquipSlots.RightArm, EquipSlots.LeftArm,
                                            EquipSlots.ChestArmor, EquipSlots.Gloves,   EquipSlots.LegsArmor,
                                            EquipSlots.Feet };

                // Get the index for the correct armor value and update the armor value.
                // Armor value is 100 when no armor is equipped. For every point of armor as shown on the inventory screen, 5 is subtracted.
                int index = System.Array.IndexOf(equipSlots, slot);

                if (equipping)
                {
                    armorValues[index] -= (sbyte)(armor.GetMaterialArmorValue() * 5);
                }
                else
                {
                    armorValues[index] += (sbyte)(armor.GetMaterialArmorValue() * 5);
                }
            }
            else
            {
                // Shields armor values in classic are unaffected by their material type.
                int[] values = { 0, 0, 0, 0, 0, 0, 0 }; // shield's effect on the 7 armor values

                if (armor.TemplateIndex == (int)Armor.Buckler)
                {
                    values[2] = 1; // left arm
                    values[4] = 1; // gloves
                }
                else if (armor.TemplateIndex == (int)Armor.Round_Shield)
                {
                    values[2] = 2; // left arm
                    values[4] = 2; // gloves
                    values[5] = 2; // legs armor
                }
                else if (armor.TemplateIndex == (int)Armor.Kite_Shield)
                {
                    values[2] = 3; // left arm
                    values[4] = 3; // gloves
                    values[5] = 3; // legs armor
                }
                else if (armor.TemplateIndex == (int)Armor.Tower_Shield)
                {
                    values[0] = 4; // head
                    values[2] = 4; // left arm
                    values[4] = 4; // gloves
                    values[5] = 4; // legs armor
                }

                for (int i = 0; i < armorValues.Length; i++)
                {
                    if (equipping)
                    {
                        armorValues[i] -= (sbyte)(values[i] * 5);
                    }
                    else
                    {
                        armorValues[i] += (sbyte)(values[i] * 5);
                    }
                }
            }
        }