mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
154 lines
4.0 KiB
Plaintext
154 lines
4.0 KiB
Plaintext
include library.utils;
|
|
include library.prose;
|
|
include library.trial;
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
menu_info_data mid = mi.getMenuItemByType(menu_info_types.ITEM_USE);
|
|
|
|
int menuStoreToken = mi.addRootMenu(menu_info_types.ITEM_USE, new string_id("spam", "heroic_token_store"));
|
|
|
|
if( getCount(self) > 1 )
|
|
mi.addSubMenu(menuStoreToken, menu_info_types.SERVER_MENU1, new string_id("spam", "heroic_token_store_all"));
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if(isDead(player) || isIncapacitated(player))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if(getContainedBy(self) != utils.getInventoryContainer(player))
|
|
{
|
|
sendSystemMessage(player, new string_id("spam", "use_top_level_only"));
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if(item == menu_info_types.ITEM_USE)
|
|
{
|
|
findAndUpdateTokenBox(self, player, 1);
|
|
}
|
|
else if ( item == menu_info_types.SERVER_MENU1 )
|
|
{
|
|
findAndUpdateTokenBox(self, player, getCount(self));
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void findAndUpdateTokenBox(obj_id self, obj_id player, int amount)
|
|
{
|
|
obj_id inventory = utils.getInventoryContainer(player);
|
|
obj_id[] inventoryContents = getContents(inventory);
|
|
int myId = findMyId(self);
|
|
|
|
if(myId < 0)
|
|
{
|
|
//You have an invalid token.
|
|
sendSystemMessage(player, new string_id("set_bonus", "heroic_token_token_error"));
|
|
return;
|
|
}
|
|
|
|
for(int i = 0; i < inventoryContents.length; i++)
|
|
{
|
|
obj_id inventoryItem = inventoryContents[i];
|
|
if ( !isIdValid(inventoryItem) )
|
|
{
|
|
continue;
|
|
}
|
|
|
|
string itemName = getStaticItemName(inventoryItem);
|
|
// Found a box!
|
|
if (itemName != null && itemName != "" && itemName.equals("item_heroic_token_box_01_01"))
|
|
{
|
|
// Make sure the box is actually setup correctly
|
|
if( hasObjVar(inventoryItem, "item.set.tokens_held") )
|
|
{
|
|
updateTokenBox(myId, inventoryItem, self, player, amount);
|
|
break;
|
|
}
|
|
else
|
|
{
|
|
// attempt to initialize the token box
|
|
trial.initializeBox(self);
|
|
if ( hasObjVar(inventoryItem, "item.set.tokens_held") )
|
|
{
|
|
updateTokenBox(myId, inventoryItem, self, player, amount);
|
|
}
|
|
else
|
|
{
|
|
// Your box is hosed
|
|
sendSystemMessage(player, new string_id("spam", "heroic_token_box_error"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
int findMyId(obj_id self)
|
|
{
|
|
int failId = -1;
|
|
string myName = getStaticItemName(self);
|
|
|
|
for(int i = 0; i < trial.HEROIC_TOKENS.length; i++)
|
|
{
|
|
if(myName.equals(trial.HEROIC_TOKENS[i]))
|
|
return i;
|
|
}
|
|
|
|
return failId;
|
|
}
|
|
|
|
void updateTokenBox(int myId, obj_id tokenBox, obj_id self, obj_id player, int amount)
|
|
{
|
|
// Get the array containing our token total. Increment our value.
|
|
int[] currentHeroicTokens = getIntArrayObjVar(tokenBox, "item.set.tokens_held");
|
|
if(currentHeroicTokens != null && currentHeroicTokens.length == trial.NUM_HEROIC_TOKEN_TYPES)
|
|
{
|
|
updateTokenCount(currentHeroicTokens, myId, self, tokenBox, player, amount);
|
|
}
|
|
else
|
|
{
|
|
// attempt to correct the token box array length
|
|
trial.verifyBox(self);
|
|
currentHeroicTokens = getIntArrayObjVar(tokenBox, "item.set.tokens_held");
|
|
if(currentHeroicTokens != null && currentHeroicTokens.length == trial.NUM_HEROIC_TOKEN_TYPES)
|
|
{
|
|
updateTokenCount(currentHeroicTokens, myId, self, tokenBox, player, amount);
|
|
}
|
|
else
|
|
{
|
|
// Your box is hosed
|
|
sendSystemMessage(player, new string_id("spam", "heroic_token_box_error"));
|
|
}
|
|
}
|
|
|
|
return;
|
|
}
|
|
|
|
void updateTokenCount(int[] currentHeroicTokens, int myId, obj_id self, obj_id tokenBox, obj_id player, int amount)
|
|
{
|
|
currentHeroicTokens[myId] += amount;
|
|
setObjVar(tokenBox, "item.set.tokens_held", currentHeroicTokens);
|
|
decrementTokenCount(self, player, amount);
|
|
|
|
return;
|
|
}
|
|
|
|
//Decrement our count or destroy ourself if count is 1.
|
|
void decrementTokenCount(obj_id self, obj_id player, int amount)
|
|
{
|
|
prose_package pp = new prose_package();
|
|
pp = prose.setStringId(pp, new string_id("spam", "heroic_token_box_success"));
|
|
pp = prose.setTT(pp, self);
|
|
sendSystemMessageProse(player, pp);
|
|
|
|
if(getCount(self) > amount)
|
|
setCount(self, getCount(self) - amount);
|
|
else
|
|
destroyObject(self);
|
|
} |