/*
    PROJECT Q IV
    (c) 2022 by Pstemarie

    Gizzard Placeble OnDamaged/OnDeath Event Script

    Version: 1.0
    Created: 28 Jan 2003
    Author:  Lacero
    V1.1:    3 Jun 2022 Pstemarie - added GetIsWeaponSmall function and added missing weapon types,
                                    made the feedback messages more generic


*/

int GetIsSmallWeapon(object oWeapon)
{
    switch (GetBaseItemType(oWeapon))
    {
        case BASE_ITEM_CPIERCWEAPON:
        case BASE_ITEM_CSLASHWEAPON:
        case BASE_ITEM_CSLSHPRCWEAP:
        case BASE_ITEM_DAGGER:
        case BASE_ITEM_HANDAXE:
        case BASE_ITEM_KAMA:
        case BASE_ITEM_KUKRI:
        case BASE_ITEM_SHORTSWORD:
        case BASE_ITEM_SICKLE:
        //case BASE_ITEM_DART:                  //* Pstemarie - these weapon types are supported in PnP, but being able to use a ranged attack
        //case BASE_ITEM_SHURIKEN:              //* inside a creature's stomach doesn't make sense to me.
        //case BASE_ITEM_THROWINGAXE:           //* They are included for Builders who want to be true to pnp rules - uncomment to activate
                                                //* as part of the size/type check.
            return TRUE;
    }
    return FALSE;
}

void main()
{
    object oPC     = GetLastDamager();
    object oWeapon = GetLastWeaponUsed(oPC);

    if(GetIsObjectValid(oWeapon))
    {
        // If the pc isn't using a small piercing or slashing weapon, then the worm wasn't damaged.
        if (GetIsSmallWeapon(oWeapon))
        {
            object oWorm = GetLocalObject(oPC,"PW_INSIDE");
            int nDamage = GetLocalInt(oPC,"PW_DAMAGEDEALT");
            int nDam =GetTotalDamageDealt();
            nDamage += nDam;
            SetLocalInt(oPC,"PW_DAMAGEDEALT",nDamage);
            ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectDamage(nDam,DAMAGE_TYPE_SLASHING),oWorm);
            if(nDamage>=25)
            {
                //Escape - teleport player to the place the worm is.
                location lTo = GetLocation(oWorm);
                AssignCommand(oPC,ClearAllActions());
                AssignCommand(oPC,JumpToLocation(lTo));
                SendMessageToPC(oPC,"Violent muscle contractions expel you from the creature's stomach!");
            }
        }
        else
        {
            SendMessageToPC(oPC,"There is not enough space to use that weapon!");
        }

    }
    else
    {
        SendMessageToPC(oPC,"There is not enough space to do that!");
    }

    //ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectResurrection(),OBJECT_SELF);
    ApplyEffectToObject(DURATION_TYPE_INSTANT,EffectHeal(500),OBJECT_SELF);
}
