Files
dsrc/sku.0/sys.server/compiled/game/script/npc/converse/junk_dealer.script
T
2013-09-10 23:17:15 -07:00

205 lines
5.4 KiB
Plaintext

include library.sui;
include library.chat;
include library.group;
include library.prose;
include library.money;
include library.ai_lib;
include library.utils;
include library.luck;
include library.static_item
include library.smuggler;
const boolean LOGGING_ON = true;
const string LOGNAME = "junk_log";
///////////////////////////////////////////////////////////////////////////
// Set sentinal behavior and attach conversation script when this script is attached
trigger OnAttach()
{
ai_lib.setDefaultCalmBehavior(self, ai_lib.BEHAVIOR_SENTINEL);
string creatureName = getCreatureName(self);
if(creatureName.equals("junk_jawa"))
{
//Jawa has own conversation attached in creatures table.
return SCRIPT_CONTINUE;
}
if(!creatureName.equals("junk_dealer_smuggler"))
{
attachScript(self, "conversation.junk_dealer_generic");
}
else
{
attachScript(self, "conversation.junk_dealer_smuggler");
}
return SCRIPT_CONTINUE;
}
///////////////////////////////////////////////////////////////////////////
// This is the message handler that gets called from the conversation. This method starts the dealing procedure.
messageHandler startDealing()
{
// Get the obj id of the player we're dealing with
obj_id player = params.getObjId("player");
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
// Show that player the sui
smuggler.showSellJunkSui(player, self, false, false);
return SCRIPT_CONTINUE;
}
///////////////////////////////////////////////////////////////////////////
// Figure out what to do when the player responds to the sui
messageHandler handleSellJunkSui()
{
// Get the obj id of the player that hit a button
obj_id player = sui.getPlayerId(params);
// If the player is not valid, quit out
if(!isIdValid(player))
return SCRIPT_CONTINUE;
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
utils.setScriptVar(player, "fence", false);
messageTo(player, "handleSellJunkSui", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
///////////////////////////////////////////////////////////////////////////
// Handles the cleanup after one item is sold
/*This captures the message and forwards it back to the base_player handler under the same name
so we aren't fixing 2 different systems that basically do the same thing when updating the junk dealer and
Smuggler Fence special.*/
messageHandler handleSoldJunk()
{
// If the parameters we've passed don't exist, quit out
if(params == null || params.isEmpty())
{
return SCRIPT_CONTINUE;
}
// Get the obj id of the player we paid. If they don't exist, quit out
obj_id player = params.getObjId(money.DICT_TARGET_ID);
if(!isIdValid(player))
{
return SCRIPT_CONTINUE;
}
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
blog("junk_dealer.handleSoldJunk() - setting fence to false");
params.put("fence",false);
messageTo(player, "handleSoldJunk", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler startBuyBack()
{
// Get the obj id of the player we're dealing with
obj_id player = params.getObjId("player");
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
// Show that player the sui
smuggler.showBuyBackSui(player, self);
return SCRIPT_CONTINUE;
}
messageHandler startFlaggingItemsNoSale()
{
// Get the obj id of the player we're dealing with
obj_id player = params.getObjId("player");
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
// Show that player the sui
smuggler.flagJunkSaleSui(player, self);
return SCRIPT_CONTINUE;
}
messageHandler handleBuyBackSui()
{
// Get the obj id of the player that hit a button
obj_id player = sui.getPlayerId(params);
// If the player is not valid, quit out
if(!isIdValid(player))
return SCRIPT_CONTINUE;
//range check
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
params.put("dealer",self);
messageTo(player, "handleBuyBackSui", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler handleTheBuyBack()
{
if(params == null || params.isEmpty())
{
return SCRIPT_CONTINUE;
}
// Get the obj id of the player we paid. If they don't exist, quit out
obj_id player = params.getObjId(money.DICT_PLAYER_ID);
if(!isIdValid(player))
{
CustomerServiceLog("Junk_Dealer: ", "junk_dealer.handleTheBuyBack() - Failed to sell back object because player was invalid.");
return SCRIPT_CONTINUE;
}
//range check
if(utils.outOfRange(self, player, 10.0f, true))
{
CustomerServiceLog("Junk_Dealer: ", "junk_dealer.handleTheBuyBack() - Player: "+player+" cannot buy back an item because they walked too far from the Junk Dealer: "+self);
return SCRIPT_CONTINUE;
}
blog("junk_dealer.handleTheBuyBack() - sending params to player.");
params.put("dealer",self);
messageTo(player, "handleTheBuyBack", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler handleFlagJunkSui()
{
obj_id player = sui.getPlayerId(params);
if(!isIdValid(player))
return SCRIPT_CONTINUE;
// Get the row of the list box that was highlighted, and get the button that was pushed
if (utils.outOfRange(self, player, 10.0f, true))
return SCRIPT_CONTINUE;
blog("junk_dealer.handleFlagJunkSui() - sending params to player.");
params.put("dealer",self);
messageTo(player, "handleFlagJunkSui", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
boolean blog(string txt)
{
if(LOGGING_ON)
{
LOG(LOGNAME, txt);
}
return true;
}