Files
dsrc/sku.0/sys.server/compiled/game/script/object/onewayunstack.script
T

118 lines
3.1 KiB
Plaintext

/**
* Copyright (c) ©2004-2005 Sony Online Entertainment Inc.
* All Rights Reserved
*
* Title: object.onewayunstack
* Description: Allows "stacked" loot items. An item can be extracted from the stack for use in crafting.
* @author $Author: $
* @version $Revision: 0$
*/
/***************************!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!*****************************/
/***************************!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!*****************************/
// The name of this script is used in the serverGame file PlayerObject.cpp to reject components that have this script attached.
// When we have more time, we should make these items work the same as crates (FactoryObject.cpp).
/***************************!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!*****************************/
/***************************!!!!!!!!!!!IMPORTANT!!!!!!!!!!!!!!!!*****************************/
include library.utils;
include library.craftinglib;
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if (!canUnstack(player))
{
// can't unstack unless inside of your inventory and we actually have a "stack"
return SCRIPT_CONTINUE;
}
mi.addRootMenu (menu_info_types.SERVER_MENU10, new string_id("sui","unstack"));
menu_info_data mid = mi.getMenuItemByType(menu_info_types.SERVER_MENU10);
if(mid == null)
{
return SCRIPT_CONTINUE;
}
mid.setServerNotify(true);
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if(!canUnstack(player))
{
return SCRIPT_CONTINUE;
}
if(item == menu_info_types.SERVER_MENU10)
{
unstackIt(self, player);
}
return SCRIPT_CONTINUE;
}
void unstackIt(obj_id stackedItem, obj_id player)
{
obj_id self = getSelf();
obj_id container = utils.getInventoryContainer(player);
if(getVolumeFree(container) < getVolume(stackedItem)) // do we have room for another item like the the stack item?
{
sendSystemMessage(player, new string_id("sui", "unstack_noroom")); // ~ No room in inventory, try again...
return;
}
string template = getTemplateName(stackedItem);
obj_id copy_item = createObject(template, container, "");
if(!isIdValid(copy_item))
{
return;
}
copyObjVar(stackedItem, copy_item, "crafting");
copyObjVar(stackedItem, copy_item, craftinglib.COMPONENT_ATTRIBUTE_OBJVAR_NAME);
copyObjVar(stackedItem, copy_item, "attribute");
setCraftedId(copy_item, getObjIdObjVar(stackedItem, "unstack.serialNumber"));
setCrafter(copy_item, getCrafter(stackedItem));
setAttributeBonuses(copy_item, getAttributeBonuses(stackedItem));
// decrement count
incrementCount(stackedItem, -1);
int count = getCount(stackedItem);
if(count == 1)
{
removeObjVar(stackedItem, "unstack.serialNumber");
detachScript(stackedItem, "object.onewayunstack");
sendDirtyObjectMenuNotification(stackedItem);
}
return;
}
boolean canUnstack(obj_id player)
{
obj_id self = getSelf();
obj_id playerInventory = utils.getInventoryContainer(player);
int count = getCount(self);
if(count < 2)
{
return false;
}
if(!hasObjVar(self, "unstack.serialNumber"))
{
return false;
}
return utils.isNestedWithin(getSelf(), playerInventory);
}