/*
    PROJECT Q IV
    (c) 2022 by Pstemarie

    Mimic Chest Placeable OnUsed Event Script

        Turns a placeable into a mimic and copies its inventory (if any) over
        to the mimic.

        To Use: Place this script in the OnUsed slot of any useable chest (best
        used with model type A)

    Version: 1.0
    Created: 10 Oct 2020
    Author:  Pstemarie

*/

void main()
{
    // Declare major variables
    object oPC    = GetLastUsedBy();
    object oMimic = CreateObject(OBJECT_TYPE_CREATURE, "q_mimic", GetLocation(OBJECT_SELF));
    object oItem  = GetFirstItemInInventory(OBJECT_SELF);

    while (GetIsObjectValid(oItem) )
    {
        // Transfer any inventory in the placeable to the mimic
        CopyItem(oItem, oMimic, TRUE);
        DestroyObject(oItem, 0.1);

        oItem = GetNextItemInInventory(OBJECT_SELF);
    }

    // Kill the placeable
    SetPlotFlag(OBJECT_SELF, FALSE);
    ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(1000), OBJECT_SELF);

    AssignCommand(oMimic, ActionAttack(GetLastUsedBy()));
}
