#include "inc_misc_tools"
#include "inc_room_content"
#include "prc_x2_itemprop"
// Gives a bonus to all skills affected by Armor check penalty.
// This function should be applied by the armor. (AssignCommand)
void ACPBonus(object oPC,int iAmount);
// Returns the ammo slot for that weapon.
int GetAmmoSlot(object oWeapon);
// Applies Special Ammo effects from weapons
void SpecialAmmo(object oWeapon,object oAmmo,int iType);
void main ()
    {
    object oPC = GetPCItemLastEquippedBy();
    object oItem = GetPCItemLastEquipped();
    int iType = GetBaseItemType(oItem);
    string sTag = GetTag(oItem);
    object oTemp;
    object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND ,oPC);
    object oSkin = GetItemInSlot(INVENTORY_SLOT_CARMOUR,oPC);
    object oAmmo;
    int iTemp,iTemp2,iDamageType;
    SetLocalInt(oSkin,sTag,TRUE);
    switch(iType)
        {
        case BASE_ITEM_HELMET:
            {
            if (sTag == "miscc097")
                AssignCommand(oPC,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectAreaOfEffect(AOE_MOB_CIRCGOOD," ", "miscc097", " "),oPC));
            break;
            }
        case BASE_ITEM_CLOAK:
            {
            if (sTag == "miscb083")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectConcealment(20,MISS_CHANCE_TYPE_NORMAL),EffectVisualEffect(VFX_DUR_BLUR)),oPC));
            else if (sTag == "miscc037")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectLinkEffects(EffectConcealment(50,MISS_CHANCE_TYPE_NORMAL),EffectVisualEffect(VFX_DUR_BLUR)),oPC));
            else if (sTag == "miscc026")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectSpellResistanceIncrease(17-GetSpellResistance(oPC)),oPC));
            else if (sTag == "miscc072")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectSpellResistanceIncrease(21-GetSpellResistance(oPC)),oPC));
            break;
            }
        case BASE_ITEM_BRACER:
            {
            if (GetWeaponRanged(oWeapon)
             && sTag == "misca081") // Bracers of Archery
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectAttackIncrease(1),oPC));
            }
        case BASE_ITEM_ARMOR:
            {
            if (sTag == "chains601")
                {
                AssignCommand(oItem,ACPBonus(oPC,2));
                AssignCommand(oItem,AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyArcaneSpellFailure(IP_CONST_ARCANE_SPELL_FAILURE_MINUS_10_PERCENT),oItem));
                SetPlotFlag(oItem,TRUE);
                }
            else if (sTag == "chain601")
                {
                AssignCommand(oItem,ACPBonus(oPC,3));
                AssignCommand(oItem,AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyArcaneSpellFailure(IP_CONST_ARCANE_SPELL_FAILURE_MINUS_10_PERCENT),oItem));
                SetPlotFlag(oItem,TRUE);
                }
            else if (sTag == "hide601")
                {
                AssignCommand(oItem,ACPBonus(oPC,1));
                AssignCommand(oItem,AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyBonusFeat(IP_CONST_FEAT_KNOCKDOWN),oItem));
                SetPlotFlag(oItem,TRUE);
                }
            else if (sTag == "fplate601")
                {
                AssignCommand(oItem,ACPBonus(oPC,4));
                AssignCommand(oItem,AddItemProperty(DURATION_TYPE_PERMANENT,ItemPropertyArcaneSpellFailure(IP_CONST_ARCANE_SPELL_FAILURE_MINUS_20_PERCENT),oItem));
                SetPlotFlag(oItem,TRUE);
                }
            else if (sTag == "breast602")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectAbilityIncrease(ABILITY_CHARISMA,4),oPC));
            else if (sTag == "miscc060")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectSpellResistanceIncrease(17-GetSpellResistance(oPC)),oPC));
            }
        case BASE_ITEM_LARGESHIELD:
        case BASE_ITEM_SMALLSHIELD:
        case BASE_ITEM_TOWERSHIELD:
            {
            if (sTag == "sshield601")
                AssignCommand(oItem,ACPBonus(oPC,1));
            else if (sTag == "lshield601")
                AssignCommand(oItem,ACPBonus(oPC,2));
            }
        case BASE_ITEM_BOOTS:
            {
            if (sTag == "misca049")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectMovementSpeedIncrease(99),oPC)); // Odd that the system doesnt allow 100%
            else if (sTag == "miscb036")
                AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectMovementSpeedIncrease(50),oPC));
            }
        case BASE_ITEM_ARROW:
        case BASE_ITEM_BULLET:
        case BASE_ITEM_BOLT:
            {
            iTemp = GetLocalInt(oWeapon,"SpecialAmmo");
            if (iTemp > 0)
                {
                SpecialAmmo(oWeapon,oItem,iTemp);
                }
            }
        case BASE_ITEM_DART:
        case BASE_ITEM_HEAVYCROSSBOW:
        case BASE_ITEM_LIGHTCROSSBOW:
        case BASE_ITEM_LONGBOW:
        case BASE_ITEM_SHORTBOW:
        case BASE_ITEM_SLING:
        case BASE_ITEM_THROWINGAXE:
            {
            if (GetLocalInt(oSkin,"misca081")) // Special code for Barcer of archery do not include in if/else statements
                {
                oTemp = GetItemInSlot(INVENTORY_SLOT_ARMS,oPC);
                AssignCommand(oTemp,ApplyEffectToObject(DURATION_TYPE_PERMANENT,EffectAttackIncrease(1),oPC));
                }
            iTemp = GetLocalInt(oItem,"SpecialAmmo");
            if (iTemp > 0)
                {
                oAmmo = GetItemInSlot(GetAmmoSlot(oItem),oPC);
                SpecialAmmo(oWeapon,oAmmo,iTemp);
                }
            }
        };
    int iMW = GetLocalInt(oItem,"MW");
    int iEnc = GetEnchantmentBonus(oItem);
    if (GetIsArmor(oItem) && (iMW || iEnc >= 1))
        {
        if (GetItemACValue(oItem) - iEnc > 2)
            AssignCommand(oItem,ACPBonus(oPC,1));
        }
    else if (GetIsWeapon(oItem) && iMW && !iEnc)
        {
        if (GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC) == oItem)
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectAttackIncrease(1,ATTACK_BONUS_ONHAND)),oPC));
        else if (GetItemInSlot(INVENTORY_SLOT_LEFTHAND,oPC) == oItem)
            AssignCommand(oItem,ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectAttackIncrease(1,ATTACK_BONUS_OFFHAND)),oPC));
        }
    }

void ACPBonus(object oPC,int iAmount)
    {
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_HIDE,iAmount)),oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_MOVE_SILENTLY,iAmount)),oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_PARRY,iAmount)),oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_TUMBLE,iAmount)),oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_PICK_POCKET,iAmount)),oPC);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT,SupernaturalEffect(EffectSkillIncrease(SKILL_SET_TRAP,iAmount)),oPC);
    }

int GetAmmoSlot(object oWeapon)
    {
    int iType = GetBaseItemType(oWeapon);
    if (iType == BASE_ITEM_LONGBOW
     || iType == BASE_ITEM_SHORTBOW)
        return INVENTORY_SLOT_ARROWS;
    else if (iType == BASE_ITEM_HEAVYCROSSBOW
          || iType == BASE_ITEM_LIGHTCROSSBOW)
        return INVENTORY_SLOT_BOLTS;
    else if (iType == BASE_ITEM_SLING)
        return INVENTORY_SLOT_BULLETS;
    else if (GetItemInSlot(INVENTORY_SLOT_LEFTHAND) == oWeapon)
        return INVENTORY_SLOT_LEFTHAND;
    return INVENTORY_SLOT_RIGHTHAND;
    }

void SpecialAmmo(object oWeapon,object oAmmo,int iType)
    {
    int iDamageType = GetLocalInt(oWeapon,"DamageType");
    int iTemp;
    if (iType == 1)
        {
        IPSafeAddItemProperty(oAmmo,ItemPropertyDamageBonus(iDamageType,DAMAGE_BONUS_1d6));
        SetLocalInt(oAmmo,"TempEnc",ITEM_PROPERTY_DAMAGE_BONUS);
        }
    else if (iType == 2)
        {
        iTemp = GetLocalInt(oWeapon,"AlignmentTarget");
        IPSafeAddItemProperty(oAmmo,ItemPropertyDamageBonusVsAlign(iTemp,iDamageType,DAMAGE_BONUS_2d6));
        SetLocalInt(oAmmo,"TempEnc",ITEM_PROPERTY_DAMAGE_BONUS_VS_ALIGNMENT_GROUP);
        }
    else if (iType == 3)
        {
        iTemp = GetLocalInt(oWeapon,"Bane");
        IPSafeAddItemProperty(oAmmo,ItemPropertyDamageBonusVsRace(iTemp,iDamageType,DAMAGE_BONUS_2d6));
        SetLocalInt(oAmmo,"TempEnc",ITEM_PROPERTY_DAMAGE_BONUS_VS_RACIAL_GROUP);
        }
    }

