Exemplo n.º 1
0
        private int EffectiveArmorClass(EffectiveItemStats stats, NWPlayer player)
        {
            int baseAC  = stats.AC + _customEffect.CalculateEffectAC(player);
            int totalAC = _.GetAC(player) - baseAC;

            // Shield Oath and Precision Targeting affect a percentage of the TOTAL armor class on a creature.
            var stance = _customEffect.GetCurrentStanceType(player);

            if (stance == CustomEffectType.ShieldOath)
            {
                int bonus = (int)(totalAC * 0.2f);
                baseAC = baseAC + bonus;
            }
            else if (stance == CustomEffectType.PrecisionTargeting)
            {
                int penalty = (int)(totalAC * 0.3f);
                baseAC = baseAC - penalty;
            }

            return(baseAC);
        }
Exemplo n.º 2
0
        public int EffectiveArmorClass(NWPlayer player, NWItem ignoreItem)
        {
            int[] skills      = { (int)SkillType.HeavyArmor, (int)SkillType.LightArmor, (int)SkillType.ForceArmor };
            var   armorSkills = _data.Where <PCSkill>(x => x.PlayerID == player.GlobalID && skills.Contains(x.SkillID)).ToList();

            int heavyRank = armorSkills.Single(x => x.SkillID == (int)SkillType.HeavyArmor).Rank;
            int lightRank = armorSkills.Single(x => x.SkillID == (int)SkillType.LightArmor).Rank;
            int forceRank = armorSkills.Single(x => x.SkillID == (int)SkillType.ForceArmor).Rank;

            int baseAC = 0;

            for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
            {
                NWItem oItem = _.GetItemInSlot(slot, player.Object);
                if (oItem.Equals(ignoreItem))
                {
                    continue;
                }

                if (!oItem.IsValid)
                {
                    continue;
                }

                if (!_item.ArmorBaseItemTypes.Contains(oItem.BaseItemType))
                {
                    continue;
                }

                if (oItem.CustomItemType != CustomItemType.HeavyArmor &&
                    oItem.CustomItemType != CustomItemType.LightArmor &&
                    oItem.CustomItemType != CustomItemType.ForceArmor)
                {
                    continue;
                }

                int skillRankToUse = 0;
                if (oItem.CustomItemType == CustomItemType.HeavyArmor &&
                    oItem.RecommendedLevel > heavyRank)
                {
                    skillRankToUse = heavyRank;
                }
                else if (oItem.CustomItemType == CustomItemType.LightArmor &&
                         oItem.RecommendedLevel > lightRank)
                {
                    skillRankToUse = lightRank;
                }
                else if (oItem.CustomItemType == CustomItemType.ForceArmor &&
                         oItem.RecommendedLevel > forceRank)
                {
                    skillRankToUse = forceRank;
                }

                int itemAC = oItem.CustomAC;
                itemAC  = CalculateAdjustedValue(itemAC, oItem.RecommendedLevel, skillRankToUse, 0);
                baseAC += itemAC;
            }
            baseAC = baseAC + _customEffect.CalculateEffectAC(player);
            int totalAC = _.GetAC(player) - baseAC;

            // Shield Oath and Sword Oath affect a percentage of the TOTAL armor class on a creature.
            var stance = _customEffect.GetCurrentStanceType(player);

            if (stance == CustomEffectType.ShieldOath)
            {
                int bonus = (int)(totalAC * 0.2f);
                baseAC = baseAC + bonus;
            }
            else if (stance == CustomEffectType.SwordOath)
            {
                int penalty = (int)(totalAC * 0.3f);
                baseAC = baseAC - penalty;
            }

            return(baseAC);
        }
Exemplo n.º 3
0
        public void ApplyStatChanges(NWPlayer player, NWItem ignoreItem)
        {
            if (!player.IsPlayer)
            {
                return;
            }
            if (!player.IsInitializedAsPlayer)
            {
                return;
            }

            PlayerCharacter pcEntity = _db.PlayerCharacters.Single(x => x.PlayerID == player.GlobalID);
            List <PCSkill>  skills   = _db.PCSkills.Where(x => x.PlayerID == player.GlobalID && x.Skill.IsActive).ToList();
            float           strBonus = 0.0f;
            float           dexBonus = 0.0f;
            float           conBonus = 0.0f;
            float           intBonus = 0.0f;
            float           wisBonus = 0.0f;
            float           chaBonus = 0.0f;

            foreach (PCSkill pcSkill in skills)
            {
                Skill           skill     = pcSkill.Skill;
                CustomAttribute primary   = (CustomAttribute)skill.Primary;
                CustomAttribute secondary = (CustomAttribute)skill.Secondary;
                CustomAttribute tertiary  = (CustomAttribute)skill.Tertiary;

                // Primary Bonuses
                if (primary == CustomAttribute.STR)
                {
                    strBonus += PrimaryIncrease * pcSkill.Rank;
                }
                else if (primary == CustomAttribute.DEX)
                {
                    dexBonus += PrimaryIncrease * pcSkill.Rank;
                }
                else if (primary == CustomAttribute.CON)
                {
                    conBonus += PrimaryIncrease * pcSkill.Rank;
                }
                else if (primary == CustomAttribute.INT)
                {
                    intBonus += PrimaryIncrease * pcSkill.Rank;
                }
                else if (primary == CustomAttribute.WIS)
                {
                    wisBonus += PrimaryIncrease * pcSkill.Rank;
                }
                else if (primary == CustomAttribute.CHA)
                {
                    chaBonus += PrimaryIncrease * pcSkill.Rank;
                }

                // Secondary Bonuses
                if (secondary == CustomAttribute.STR)
                {
                    strBonus += SecondaryIncrease * pcSkill.Rank;
                }
                else if (secondary == CustomAttribute.DEX)
                {
                    dexBonus += SecondaryIncrease * pcSkill.Rank;
                }
                else if (secondary == CustomAttribute.CON)
                {
                    conBonus += SecondaryIncrease * pcSkill.Rank;
                }
                else if (secondary == CustomAttribute.INT)
                {
                    intBonus += SecondaryIncrease * pcSkill.Rank;
                }
                else if (secondary == CustomAttribute.WIS)
                {
                    wisBonus += SecondaryIncrease * pcSkill.Rank;
                }
                else if (secondary == CustomAttribute.CHA)
                {
                    chaBonus += SecondaryIncrease * pcSkill.Rank;
                }

                // Tertiary Bonuses
                if (tertiary == CustomAttribute.STR)
                {
                    strBonus += TertiaryIncrease * pcSkill.Rank;
                }
                else if (tertiary == CustomAttribute.DEX)
                {
                    dexBonus += TertiaryIncrease * pcSkill.Rank;
                }
                else if (tertiary == CustomAttribute.CON)
                {
                    conBonus += TertiaryIncrease * pcSkill.Rank;
                }
                else if (tertiary == CustomAttribute.INT)
                {
                    intBonus += TertiaryIncrease * pcSkill.Rank;
                }
                else if (tertiary == CustomAttribute.WIS)
                {
                    wisBonus += TertiaryIncrease * pcSkill.Rank;
                }
                else if (tertiary == CustomAttribute.CHA)
                {
                    chaBonus += TertiaryIncrease * pcSkill.Rank;
                }
            }

            // Check caps.
            if (strBonus > MaxAttributeBonus)
            {
                strBonus = MaxAttributeBonus;
            }
            if (dexBonus > MaxAttributeBonus)
            {
                dexBonus = MaxAttributeBonus;
            }
            if (conBonus > MaxAttributeBonus)
            {
                conBonus = MaxAttributeBonus;
            }
            if (intBonus > MaxAttributeBonus)
            {
                intBonus = MaxAttributeBonus;
            }
            if (wisBonus > MaxAttributeBonus)
            {
                wisBonus = MaxAttributeBonus;
            }
            if (chaBonus > MaxAttributeBonus)
            {
                chaBonus = MaxAttributeBonus;
            }

            if (pcEntity.BackgroundID == (int)BackgroundType.Archer || pcEntity.BackgroundID == (int)BackgroundType.Crossbowman)
            {
                dexBonus++;
                wisBonus++;
            }
            if (pcEntity.BackgroundID == (int)BackgroundType.Guard || pcEntity.BackgroundID == (int)BackgroundType.Berserker)
            {
                strBonus++;
                conBonus++;
            }

            if (pcEntity.BackgroundID == (int)BackgroundType.TwinBladeSpecialist)
            {
                dexBonus++;
                conBonus++;
            }

            if (pcEntity.BackgroundID == (int)BackgroundType.MartialArtist)
            {
                strBonus++;
                dexBonus++;
            }

            // Apply attributes
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_STRENGTH, (int)strBonus + pcEntity.STRBase);
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_DEXTERITY, (int)dexBonus + pcEntity.DEXBase);
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_CONSTITUTION, (int)conBonus + pcEntity.CONBase);
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_INTELLIGENCE, (int)intBonus + pcEntity.INTBase);
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_WISDOM, (int)wisBonus + pcEntity.WISBase);
            _nwnxCreature.SetRawAbilityScore(player, ABILITY_CHARISMA, (int)chaBonus + pcEntity.CHABase);

            // Apply AC
            int ac = CalculateItemAC(player, ignoreItem) + _customEffect.CalculateEffectAC(player);

            _nwnxCreature.SetBaseAC(player, ac);

            // Apply BAB
            int bab = CalculateBAB(player, ignoreItem);

            _nwnxCreature.SetBaseAttackBonus(player, bab);


            int equippedItemHPBonus   = 0;
            int equippedItemManaBonus = 0;

            for (int slot = 0; slot < NUM_INVENTORY_SLOTS; slot++)
            {
                NWItem item = NWItem.Wrap(_.GetItemInSlot(slot, player.Object));
                if (item.Equals(ignoreItem))
                {
                    continue;
                }

                equippedItemHPBonus   += item.HPBonus;
                equippedItemManaBonus += item.ManaBonus;
            }

            // Apply HP
            int hp = 30 + player.ConstitutionModifier * 5;

            hp += _perk.GetPCPerkLevel(player, PerkType.Health) * 5;
            hp += equippedItemHPBonus;
            if (pcEntity.BackgroundID == (int)BackgroundType.Knight)
            {
                hp += 10;
            }

            if (hp > 255)
            {
                hp = 255;
            }
            if (hp < 20)
            {
                hp = 20;
            }
            _nwnxCreature.SetMaxHitPointsByLevel(player, 1, hp);
            if (player.CurrentHP > player.MaxHP)
            {
                int    amount = player.CurrentHP - player.MaxHP;
                Effect damage = _.EffectDamage(amount);
                _.ApplyEffectToObject(DURATION_TYPE_INSTANT, damage, player.Object);
            }

            // Apply Mana
            int mana = 20;

            mana += (player.IntelligenceModifier + player.WisdomModifier + player.CharismaModifier) * 5;
            mana += _perk.GetPCPerkLevel(player, PerkType.Mana) * 5;
            mana += equippedItemManaBonus;
            if (pcEntity.BackgroundID == (int)BackgroundType.Wizard || pcEntity.BackgroundID == (int)BackgroundType.Cleric)
            {
                mana += 10;
            }

            if (mana < 0)
            {
                mana = 0;
            }
            pcEntity.MaxMana = mana;

            _db.SaveChanges();
        }