//::///////////////////////////////////////////////
//:: Greater Wild Shape, Humanoid Shape
//:: x2_s2_gwildshp
//:: Copyright (c) 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Allows the character to shift into one of these
    forms, gaining special abilities

    Credits must be given to mr_bumpkin from the NWN
    community who had the idea of merging item properties
    from weapon and armor to the creatures new forms.

*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-07-02
//:://////////////////////////////////////////////
//:: Modified By: Deva Winblood
//:: Modified Date: January 26th, 2008
//:://////////////////////////////////////////////
/*
    Modified to insure no shapeshifting spells are castable upon
    mounted targets.  This prevents problems that can occur due
    to dismounting after shape shifting, or other issues that can
    occur due to preserved appearances getting out of synch.

    This can additional check can be disabled by setting the variable
    X3_NO_SHAPESHIFT_SPELL_CHECK to 1 on the module object.  If this
    variable is set then this script will function as it did prior to
    this modification.

Patch 1.71

- allowed to merge any custom non-weapon in left hand slot such as flags or
musical instruments
- added optional feature to stack ability bonuses from multiple items together
- added optional feature to merge bracers (when items are allowed to merge)
- added benefits of being incorporeal to the spectre shape (50% concealment and
the ability to walk through other creatures)
- a spectre polymorph now also release character from the effects of the grappling
- cured from horse include while retaining the shapeshifting horse check
- fixed dying when unpolymorphed as an result of sudden constitution bonus drop
which also could result to the server crash
*/

#include "70_inc_itemprop"
#include "x2_inc_itemprop"
#include "x2_inc_shifter"
#include "x3_inc_horse"


void main()
{
    //--------------------------------------------------------------------------
    // Declare major variables
    //--------------------------------------------------------------------------
    int    nSpell = GetSpellId();
    object oTarget = GetSpellTargetObject();
    effect eVis = EffectVisualEffect(VFX_IMP_POLYMORPH);
    int    nShifter = GetLevelByClass(CLASS_TYPE_SHIFTER);
    effect ePoly;
    int    nPoly;

    if (!GetLocalInt(GetModule(),"X3_NO_SHAPESHIFT_SPELL_CHECK"))
    { // check to see if abort due to being mounted
        switch(GetPhenoType(oTarget))
        {// shape shifting not allowed while mounted
            case 3:
            case 5:
            case 6:
            case 8:
            if(GetIsPC(oTarget))
            {
                FloatingTextStrRefOnCreature(111982,oTarget,FALSE);
            }
            // shape shifting not allowed while mounted
            return;
        }
    } // check to see if abort due to being mounted

    // Feb 13, 2004, Jon: Added scripting to take care of case where it's an NPC
    // using one of the feats. It will randomly pick one of the shapes associated
    // with the feat.
    switch(nSpell)
    {
        // Greater Wildshape I
        case 646: nSpell = Random(5)+658; break;
        // Greater Wildshape II
        case 675: switch(Random(3))
                  {
                    case 0: nSpell = 672; break;
                    case 1: nSpell = 678; break;
                    case 2: nSpell = 680;
                  }
                  break;
        // Greater Wildshape III
        case 676: switch(Random(3))
                  {
                    case 0: nSpell = 670; break;
                    case 1: nSpell = 673; break;
                    case 2: nSpell = 674;
                  }
                  break;
        // Greater Wildshape IV
        case 677: switch(Random(3))
                  {
                    case 0: nSpell = 679; break;
                    case 1: nSpell = 691; break;
                    case 2: nSpell = 694;
                  }
                  break;
        // Humanoid Shape
        case 681:  nSpell = Random(3)+682; break;
        // Undead Shape
        case 685:  nSpell = Random(3)+704; break;
        // Dragon Shape
        case 725:  nSpell = Random(3)+707; break;
        // Outsider Shape
        case 732:  nSpell = Random(3)+733; break;
        // Construct Shape
        case 737:  nSpell = Random(3)+738; break;
    }

    //--------------------------------------------------------------------------
    // Determine which form to use based on spell id, gender and level
    //--------------------------------------------------------------------------
    switch (nSpell)
    {

        //-----------------------------------------------------------------------
        // Greater Wildshape I - Wyrmling Shape
        //-----------------------------------------------------------------------
        case 658:  nPoly = POLYMORPH_TYPE_WYRMLING_RED; break;
        case 659:  nPoly = POLYMORPH_TYPE_WYRMLING_BLUE; break;
        case 660:  nPoly = POLYMORPH_TYPE_WYRMLING_BLACK; break;
        case 661:  nPoly = POLYMORPH_TYPE_WYRMLING_WHITE; break;
        case 662:  nPoly = POLYMORPH_TYPE_WYRMLING_GREEN; break;

        //-----------------------------------------------------------------------
        // Greater Wildshape II  - Minotaur, Gargoyle, Harpy
        //-----------------------------------------------------------------------
        case 672: if (nShifter < X2_GW2_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_HARPY;
                  else
                     nPoly = 97;
                  break;

        case 678: if (nShifter < X2_GW2_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_GARGOYLE;
                  else
                     nPoly = 98;
                  break;

        case 680: if (nShifter < X2_GW2_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_MINOTAUR;
                  else
                     nPoly = 96;
                  break;

        //-----------------------------------------------------------------------
        // Greater Wildshape III  - Drider, Basilisk, Manticore
        //-----------------------------------------------------------------------
        case 670: if (nShifter < X2_GW3_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_BASILISK;
                  else
                     nPoly = 99;
                  break;

        case 673: if (nShifter < X2_GW3_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_DRIDER;
                  else
                     nPoly = 100;
                  break;

        case 674: if (nShifter < X2_GW3_EPIC_THRESHOLD)
                     nPoly = POLYMORPH_TYPE_MANTICORE;
                  else
                     nPoly = 101;
                  break;

       //-----------------------------------------------------------------------
       // Greater Wildshape IV - Dire Tiger, Medusa, MindFlayer
       //-----------------------------------------------------------------------
        case 679: nPoly = POLYMORPH_TYPE_MEDUSA; break;
        case 691: nPoly = 68; break; // Mindflayer
        case 694: nPoly = 69; break; // DireTiger


       //-----------------------------------------------------------------------
       // Humanoid Shape - Kobold Commando, Drow, Lizard Crossbow Specialist
       //-----------------------------------------------------------------------
       case 682:
                 if(nShifter< 17)
                 {
                     if (GetGender(OBJECT_SELF) == GENDER_MALE) //drow
                         nPoly = 59;
                     else
                         nPoly = 70;
                 }
                 else
                 {
                     if (GetGender(OBJECT_SELF) == GENDER_MALE) //drow
                         nPoly = 105;
                     else
                         nPoly = 106;
                 }
                 break;
       case 683:
                 if(nShifter< 17)
                 {
                    nPoly = 82; break; // Lizard
                 }
                 else
                 {
                    nPoly =104; break; // Epic Lizard
                 }
       case 684: if(nShifter< 17)
                 {
                    nPoly = 83; break; // Kobold Commando
                 }
                 else
                 {
                    nPoly = 103; break; // Kobold Commando
                 }

       //-----------------------------------------------------------------------
       // Undead Shape - Spectre, Risen Lord, Vampire
       //-----------------------------------------------------------------------
       case 704: nPoly = 75; break; // Risen lord

       case 705: if (GetGender(OBJECT_SELF) == GENDER_MALE) // vampire
                     nPoly = 74;
                  else
                     nPoly = 77;
                 break;

       case 706: nPoly = 76; break; /// spectre

       //-----------------------------------------------------------------------
       // Dragon Shape - Red Blue and Green Dragons
       //-----------------------------------------------------------------------
       case 707: nPoly = 72; break; // Ancient Red   Dragon
       case 708: nPoly = 71; break; // Ancient Blue  Dragon
       case 709: nPoly = 73; break; // Ancient Green Dragon


       //-----------------------------------------------------------------------
       // Outsider Shape - Rakshasa, Azer Chieftain, Black Slaad
       //-----------------------------------------------------------------------
       case 733:   if (GetGender(OBJECT_SELF) == GENDER_MALE) //azer
                      nPoly = 85;
                    else // anything else is female
                      nPoly = 86;
                    break;

       case 734:   if (GetGender(OBJECT_SELF) == GENDER_MALE) //rakshasa
                      nPoly = 88;
                    else // anything else is female
                      nPoly = 89;
                    break;

       case 735: nPoly =87; break; // slaad

       //-----------------------------------------------------------------------
       // Construct Shape - Stone Golem, Iron Golem, Demonflesh Golem
       //-----------------------------------------------------------------------
       case 738: nPoly =91; break; // stone golem
       case 739: nPoly =92; break; // demonflesh golem
       case 740: nPoly =90; break; // iron golem

    }


    //--------------------------------------------------------------------------
    // Determine which items get their item properties merged onto the shifters
    // new form.
    //--------------------------------------------------------------------------
    int bWeapon = ShifterMergeWeapon(nPoly);
    int bArmor  = ShifterMergeArmor(nPoly);
    int bItems  = ShifterMergeItems(nPoly);
    int bArms = bItems && GetLocalInt(GetModule(),"71_POLYMORPH_MERGE_ARMS");
    //--------------------------------------------------------------------------
    // Store the old objects so we can access them after the character has
    // changed into his new form
    //--------------------------------------------------------------------------
    object oWeaponOld = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,OBJECT_SELF);
    object oArmorOld  = GetItemInSlot(INVENTORY_SLOT_CHEST,OBJECT_SELF);
    object oRing1Old  = GetItemInSlot(INVENTORY_SLOT_LEFTRING,OBJECT_SELF);
    object oRing2Old  = GetItemInSlot(INVENTORY_SLOT_RIGHTRING,OBJECT_SELF);
    object oAmuletOld = GetItemInSlot(INVENTORY_SLOT_NECK,OBJECT_SELF);
    object oCloakOld  = GetItemInSlot(INVENTORY_SLOT_CLOAK,OBJECT_SELF);
    object oBootsOld  = GetItemInSlot(INVENTORY_SLOT_BOOTS,OBJECT_SELF);
    object oBeltOld   = GetItemInSlot(INVENTORY_SLOT_BELT,OBJECT_SELF);
    object oArmsOld   = GetItemInSlot(INVENTORY_SLOT_ARMS,OBJECT_SELF);
    object oHelmetOld = GetItemInSlot(INVENTORY_SLOT_HEAD,OBJECT_SELF);
    object oShield    = GetItemInSlot(INVENTORY_SLOT_LEFTHAND,OBJECT_SELF);

    if (GetIsObjectValid(oShield))
    {   //1.71: this is now custom content compatible, polymorph will merge custom left-hand only items such as flags
        if (GetWeaponRanged(oShield) || IPGetIsMeleeWeapon(oShield))
        {
            oShield = OBJECT_INVALID;
        }
    }

    int nConBonus;
    if (bWeapon)
    {
        nConBonus = IPGetBestConBonus(nConBonus,oWeaponOld);
    }
    if (bArmor)
    {
        nConBonus = IPGetBestConBonus(nConBonus,oArmorOld);
        nConBonus = IPGetBestConBonus(nConBonus,oHelmetOld);
        nConBonus = IPGetBestConBonus(nConBonus,oShield);
    }
    if (bItems)
    {
        nConBonus = IPGetBestConBonus(nConBonus,oRing1Old);
        nConBonus = IPGetBestConBonus(nConBonus,oRing2Old);
        nConBonus = IPGetBestConBonus(nConBonus,oAmuletOld);
        nConBonus = IPGetBestConBonus(nConBonus,oCloakOld);
        nConBonus = IPGetBestConBonus(nConBonus,oBeltOld);
        nConBonus = IPGetBestConBonus(nConBonus,oBootsOld);
    }
    if (bArms)
    {
        nConBonus = IPGetBestConBonus(nConBonus,oArmsOld);
    }

    //--------------------------------------------------------------------------
    // Here the actual polymorphing is done
    //--------------------------------------------------------------------------
    ePoly = EffectPolymorph(nPoly);
     if(nConBonus > 0)
     {//1.70: this fixes dying when unpolymorphed issue as well as server crash related to this
     ePoly = EffectLinkEffects(ePoly,EffectAbilityIncrease(ABILITY_CONSTITUTION,nConBonus));
     }
     if(nPoly == 76)
     {//1.71: added benefits of being incorporeal into polymorph effect for spectre shape
     ePoly = EffectLinkEffects(ePoly,EffectConcealment(50));
     ePoly = EffectLinkEffects(ePoly,EffectCutsceneGhost());
      if(GetHasSpellEffect(SPELL_BIGBYS_CRUSHING_HAND))//in a spectre polymorph, player releases from any kind of grapple
      {
      RemoveEffectsFromSpell(OBJECT_SELF, SPELL_BIGBYS_CRUSHING_HAND);
      }
      if(GetHasSpellEffect(SPELL_BIGBYS_GRASPING_HAND))
      {
      RemoveEffectsFromSpell(OBJECT_SELF, SPELL_BIGBYS_GRASPING_HAND);
      }
     RemoveSpecificEffect(EFFECT_TYPE_ENTANGLE,OBJECT_SELF);
     }


    //This chunk of code makes outsider, undead and construct shapes stronger at shifter lvls 25, 27 and 30.
    if (GetLevelByClass(CLASS_TYPE_SHIFTER) >= 25)
    {
    if (GetLevelByClass(CLASS_TYPE_SHIFTER) >= 30)
        {
        if (nSpell == 738) //Stone golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(20, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectACIncrease(3, AC_NATURAL_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 5), ePoly);
            }
        if (nSpell == 739) //Demonflesh golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(7, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(13), ePoly);
            ePoly = EffectLinkEffects(EffectSpellResistanceIncrease(58), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 5), ePoly);
            }
        if (nSpell == 740) //Iron golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(5, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(13), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 3), ePoly);
            }
        if (nSpell == 733) //Azer
            {
            ePoly = EffectLinkEffects(EffectACIncrease(11, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(11), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 3), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(3, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 735) //Death slaad
            {
            ePoly = EffectLinkEffects(EffectACIncrease(5, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(17), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 3), ePoly);
            }
        if (nSpell == 704) //Risen Lord
            {
            ePoly = EffectLinkEffects(EffectACIncrease(11, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(11), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 3), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(6, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 705) //Vampire
            {
            ePoly = EffectLinkEffects(EffectACIncrease(3, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(15), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 3), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(6, DAMAGE_TYPE_BLUDGEONING), ePoly);
            ePoly = EffectLinkEffects(EffectRegenerate(6, 6.0), ePoly);
            }
        if (nSpell == 706) //Spectre
            {
            ePoly = EffectLinkEffects(EffectACIncrease(16, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(13), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 5), ePoly);
            }
        }
    else if (GetLevelByClass(CLASS_TYPE_SHIFTER) >= 27)
        {
        if (nSpell == 738) //Stone golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(16, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 4), ePoly);
            }
        if (nSpell == 739) //Demonflesh golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(5, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(7), ePoly);
            ePoly = EffectLinkEffects(EffectSpellResistanceIncrease(56), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 4), ePoly);
            }
        if (nSpell == 740) //Iron golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(4, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(9), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            }
        if (nSpell == 733) //Azer
            {
            ePoly = EffectLinkEffects(EffectACIncrease(8, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(8), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(2, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 735) //Death slaad
            {
            ePoly = EffectLinkEffects(EffectACIncrease(4, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(12), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            }
        if (nSpell == 704) //Risen Lord
            {
            ePoly = EffectLinkEffects(EffectACIncrease(7, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(7), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(4, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 705) //Vampire
            {
            ePoly = EffectLinkEffects(EffectACIncrease(2, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(10), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(4, DAMAGE_TYPE_BLUDGEONING), ePoly);
            ePoly = EffectLinkEffects(EffectRegenerate(4, 6.0), ePoly);
            }
        if (nSpell == 706) //Spectre
            {
            ePoly = EffectLinkEffects(EffectACIncrease(11, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(9), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 4), ePoly);
            }
        }
    else
        {
        if (nSpell == 738) //Stone golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(8, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            }
        if (nSpell == 739) //Demonflesh golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(3, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(4), ePoly);
            ePoly = EffectLinkEffects(EffectSpellResistanceIncrease(54), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            }
        if (nSpell == 740) //Iron golem
            {
            ePoly = EffectLinkEffects(EffectACIncrease(2, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(5), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 1), ePoly);
            }
        if (nSpell == 733) //Azer
            {
            ePoly = EffectLinkEffects(EffectACIncrease(4, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(4), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 1), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(1, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 735) //Death slaad
            {
            ePoly = EffectLinkEffects(EffectACIncrease(2, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(6), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 1), ePoly);
            }
        if (nSpell == 704) //Risen Lord
            {
            ePoly = EffectLinkEffects(EffectACIncrease(4, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(4), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 1), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(2, DAMAGE_TYPE_SLASHING), ePoly);
            }
        if (nSpell == 705) //Vampire
            {
            ePoly = EffectLinkEffects(EffectACIncrease(1, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(5), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 1), ePoly);
            ePoly = EffectLinkEffects(EffectDamageIncrease(2, DAMAGE_TYPE_BLUDGEONING), ePoly);
            ePoly = EffectLinkEffects(EffectRegenerate(2, 6.0), ePoly);
            }
        if (nSpell == 706) //Spectre
            {
            ePoly = EffectLinkEffects(EffectACIncrease(6, AC_SHIELD_ENCHANTMENT_BONUS), ePoly);
            ePoly = EffectLinkEffects(EffectAttackIncrease(5), ePoly);
            ePoly = EffectLinkEffects(EffectSavingThrowIncrease(SAVING_THROW_ALL, 2), ePoly);
            }
        if ((nSpell == 707 || nSpell == 708 || nSpell == 709) && GetLevelByClass(CLASS_TYPE_SHIFTER, OBJECT_SELF) < 10) //Dragon nerf for pure druids
            {
            ePoly = EffectLinkEffects(EffectAttackDecrease(5), ePoly);
            }
        }
    }
    if (nSpell == 694) ePoly = EffectLinkEffects(EffectMovementSpeedIncrease(50), ePoly); //A little extra for shifters in dire tiger form :)
    //The end of the shape boosts


    ePoly = ExtraordinaryEffect(ePoly);
    ClearAllActions(); // prevents an exploit
    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, OBJECT_SELF);
    ApplyEffectToObject(DURATION_TYPE_PERMANENT, ePoly, OBJECT_SELF);
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, GetSpellId(), FALSE));

    //--------------------------------------------------------------------------
    // This code handles the merging of item properties
    //--------------------------------------------------------------------------
    object oWeaponNew = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,OBJECT_SELF);
    object oArmorNew = GetItemInSlot(INVENTORY_SLOT_CARMOUR,OBJECT_SELF);

    //identify weapon
    SetIdentified(oWeaponNew, TRUE);

    //--------------------------------------------------------------------------
    // ...Weapons
    //--------------------------------------------------------------------------
    if (bWeapon)
    {
        //----------------------------------------------------------------------
        // GZ: 2003-10-20
        // Sorry, but I was forced to take that out, it was confusing people
        // and there were problems with updating the stats sheet.
        //----------------------------------------------------------------------
        /* if (!GetIsObjectValid(oWeaponOld))
        {
            //------------------------------------------------------------------
            // If we had no weapon equipped before, remove the old weapon
            // to allow monks to change into unarmed forms by not equipping any
            // weapon before polymorphing
            //------------------------------------------------------------------
            DestroyObject(oWeaponNew);
        }
        else*/
        {
            //------------------------------------------------------------------
            // Merge item properties...
            //------------------------------------------------------------------
            IPWildShapeCopyItemProperties(oWeaponOld,oWeaponNew, TRUE);
        }
    }

    //--------------------------------------------------------------------------
    // ...Armor
    //--------------------------------------------------------------------------
    if (bArmor)
    {
        //----------------------------------------------------------------------
        // Merge item properties from armor and helmet...
        //----------------------------------------------------------------------
        IPWildShapeCopyItemProperties(oArmorOld,oArmorNew);
        IPWildShapeCopyItemProperties(oHelmetOld,oArmorNew);
        IPWildShapeCopyItemProperties(oShield,oArmorNew);
    }

    //--------------------------------------------------------------------------
    // ...Magic Items
    //--------------------------------------------------------------------------
    if (bItems)
    {
        //----------------------------------------------------------------------
        // Merge item properties from from rings, amulets, cloak, boots, belt
        //----------------------------------------------------------------------
        IPWildShapeCopyItemProperties(oRing1Old,oArmorNew);
        IPWildShapeCopyItemProperties(oRing2Old,oArmorNew);
        IPWildShapeCopyItemProperties(oAmuletOld,oArmorNew);
        IPWildShapeCopyItemProperties(oCloakOld,oArmorNew);
        IPWildShapeCopyItemProperties(oBootsOld,oArmorNew);
        IPWildShapeCopyItemProperties(oBeltOld,oArmorNew);
    }
    if (bArms)
    {
        IPWildShapeCopyItemProperties(oArmsOld,oArmorNew);
    }
    if (GetLocalInt(GetModule(),"71_POLYMORPH_STACK_ABILITY_BONUSES"))
    {
        IPWildShapeStackAbilityBonuses(oArmorNew);
    }

    //--------------------------------------------------------------------------
    // Set artificial usage limits for special ability spells to work around
    // the engine limitation of not being able to set a number of uses for
    // spells in the polymorph radial
    //--------------------------------------------------------------------------
    ShifterSetGWildshapeSpellLimits(nSpell);

}