Files
dsrc/sku.0/sys.server/compiled/game/script/city/bestine/search_item.script
T

123 lines
3.8 KiB
Plaintext

// For quests and events: a player on the quet can search and get an object related to the quest.
/***** INCLUDES ********************************************************/
include library.utils;
/***** CONSTANTS *******************************************************/
const string_id SEARCH_ITEM = new string_id ("bestine", "search_item");
const string_id ALREADY_SEARCHED_MSG = new string_id ("bestine", "already_searched");
const string_id DEFAULT_RECEIVE_MSG = new string_id ("bestine", "default_receive_msg");
const string_id INVENTORY_FULL_MSG = new string_id ("bestine", "inventory_full");
const string GATING_OBJVAR = "gatingObjVar";
const string ALREADY_SEARCHED_OBJVAR = "bestine.already_searched";
const string OBJECT_TEMPLATE_OBJVAR = "template";
const string RECEIVE_OBJECT_MSG_OBJVAR = "receiveMsg";
const string VAR_ITEM_REQUEST_BASE = "item_request";
const string VAR_ITEM_REQUEST_CATEGORY = VAR_ITEM_REQUEST_BASE + ".category";
/***** TRIGGERS ********************************************************/
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if ( canSearch(self, player) )
{
int menuOption = mi.addRootMenu ( menu_info_types.SERVER_ITEM_OPTIONS, SEARCH_ITEM);
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
if ( item == menu_info_types.SERVER_ITEM_OPTIONS)
{
if ( canSearch(self, player) )
{
if ( hasObjVar(player, ALREADY_SEARCHED_OBJVAR) )
{
sendSystemMessage(player, ALREADY_SEARCHED_MSG);
return SCRIPT_CONTINUE;
}
string template = getStringObjVar(self, OBJECT_TEMPLATE_OBJVAR);
if ( (template != null) && (!template.equals("")) )
{
obj_id playerInv = utils.getInventoryContainer(player);
if ( isIdValid(playerInv) )
{
int free_space = getVolumeFree(playerInv);
if (free_space > 0)
{
obj_id objectReceived = createObject(template, playerInv, "");
if ( isIdValid(objectReceived) )
{
string_id receiveObjectMsg = DEFAULT_RECEIVE_MSG;
if ( hasObjVar(self, RECEIVE_OBJECT_MSG_OBJVAR) )
{
string receiveMsgObjvar = getStringObjVar(self, RECEIVE_OBJECT_MSG_OBJVAR);
if ( receiveMsgObjvar.startsWith("@") )
{
receiveObjectMsg = utils.unpackString(receiveMsgObjvar);
}
else
{
// not encoded string_id, so just use as a string.
sendSystemMessage(player, receiveMsgObjvar, null);
setObjVar(player, ALREADY_SEARCHED_OBJVAR, 1);
return SCRIPT_CONTINUE;
}
}
sendSystemMessage(player, receiveObjectMsg);
setObjVar(player, ALREADY_SEARCHED_OBJVAR, 1);
}
}
else
{
sendSystemMessage(player, INVENTORY_FULL_MSG);
}
}
}
}
}
return SCRIPT_CONTINUE;
}
/***** FUNCTIONS *******************************************************/
boolean canSearch(obj_id self, obj_id player)
{
boolean result = false;
if ( hasObjVar(self, GATING_OBJVAR) && hasObjVar(self, OBJECT_TEMPLATE_OBJVAR) )
{
string gatingObjVar = getStringObjVar(self, GATING_OBJVAR);
if ( hasObjVar(player, gatingObjVar) )
{
result = true;
}
}
return result;
}
// Adding fix for incorrect objvar format and value which is in the world snapshot.
trigger OnInitialize()
{
if ( hasObjVar(self, RECEIVE_OBJECT_MSG_OBJVAR) )
{
string receiveMsg = getStringObjVar(self, RECEIVE_OBJECT_MSG_OBJVAR);
if ( receiveMsg.startsWith("=") )
{
string[] subStrings = split(receiveMsg, ':');
string receiveMsgId = subStrings[1];
if ( receiveMsgId.endsWith("\"") )
{
receiveMsgId = receiveMsgId.substring(0, receiveMsgId.length() - 1);
}
string receiveMsgPacked = "@city/bestine/terminal_items:" + receiveMsgId;
setObjVar(self, RECEIVE_OBJECT_MSG_OBJVAR, receiveMsgPacked);
}
}
return SCRIPT_CONTINUE;
}