mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
220 lines
6.5 KiB
Plaintext
220 lines
6.5 KiB
Plaintext
/* Title: cloning.script
|
|
* Description: script for cloning menu options; to be attached to cloning terminals
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.structure;
|
|
include library.utils;
|
|
include library.sui;
|
|
include library.money;
|
|
include library.cloninglib;
|
|
include library.prose;
|
|
|
|
/***** INHERITS ********************************************************/
|
|
|
|
inherits terminal.base.base_terminal;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string HANDLER_CLONE_CONFIRM = "handleCloneConfirm";
|
|
const string HANDLER_CLONE_COUPON_CONFIRM = "handleCloneCouponConfirm";
|
|
|
|
const string_id SID_SET_BIND_PT = new string_id ("sui", "mnu_clone");
|
|
|
|
const string_id SID_CONFIRM_PROMPT = new string_id ("base_player", "clone_confirm_prompt");
|
|
const string_id SID_CONFIRM_TITLE = new string_id ("base_player", "clone_confirm_title");
|
|
|
|
const string_id SID_CONFIRM_COUPON_PROMPT = new string_id ("base_player", "clone_confirm_coupon_prompt");
|
|
const string_id SID_CONFIRM_COUPON_TITLE = new string_id ("base_player", "clone_confirm_coupon_title");
|
|
|
|
const string_id SID_ALREADY_HAVE_CLONE_DATA = new string_id ("base_player", "already_have_clone_data");
|
|
const string_id SID_HAVE_COUPON_NOT_AUTH = new string_id ("base_player", "have_coupon_not_auth");
|
|
const string_id SID_HAVE_COUPON_NOT_VALID = new string_id ("base_player", "have_coupon_not_valid");
|
|
|
|
const string CLONING_COUPON = "object/tangible/item/new_player/new_player_cloning_coupon.iff";
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if ( item == menu_info_types.ITEM_USE )
|
|
{
|
|
obj_id bound = getObjIdObjVar(player, cloninglib.VAR_BIND_FACILITY);
|
|
if (isIdValid(bound))
|
|
{
|
|
obj_id topMost = structure.getContainingBuilding(player);
|
|
if (!isIdValid(topMost))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
if ( topMost == bound )
|
|
{
|
|
sendSystemMessage(player, SID_ALREADY_HAVE_CLONE_DATA);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
}
|
|
}
|
|
|
|
obj_id clone_coupon = utils.getItemPlayerHasByTemplate(player, CLONING_COUPON);
|
|
if ( isIdValid(clone_coupon) )
|
|
{
|
|
if ( hasObjVar(clone_coupon, "owner") )
|
|
{
|
|
obj_id owner = getObjIdObjVar(clone_coupon, "owner");
|
|
if ( isIdValid(owner) )
|
|
{
|
|
if ( player == owner )
|
|
{
|
|
utils.setScriptVar(player, cloninglib.SCRVAR_CLONE_COUPON, clone_coupon);
|
|
|
|
string promptCoupon = utils.packStringId(SID_CONFIRM_COUPON_PROMPT);
|
|
string titleCoupon = utils.packStringId(SID_CONFIRM_COUPON_TITLE);
|
|
sui.msgbox(self, player, promptCoupon, sui.YES_NO, titleCoupon, HANDLER_CLONE_COUPON_CONFIRM);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
string custLogMsg = "New Player Rewards: %TU tried to use a cloning facility coupon but isn't the owner. Rightful owner is %TT";
|
|
CustomerServiceLog("NEW_PLAYER_QUESTS", custLogMsg, player, owner);
|
|
|
|
if ( isGod(player) )
|
|
{
|
|
sendSystemMessage(player, SID_HAVE_COUPON_NOT_AUTH);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
string custLogMsg = "New Player Rewards: %TU tried to use a cloning facility coupon it is invalid - does not have an owner.";
|
|
CustomerServiceLog("NEW_PLAYER_QUESTS", custLogMsg, player);
|
|
|
|
if ( isGod(player) )
|
|
{
|
|
sendSystemMessage(player, SID_HAVE_COUPON_NOT_VALID);
|
|
}
|
|
}
|
|
}
|
|
|
|
if ( !cloninglib.verifyFundsForCloning(player) )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
int cloneCost = cloninglib.getRegisterCloneCost(player);
|
|
prose_package pp = prose.getPackage(SID_CONFIRM_PROMPT, cloneCost);
|
|
string prompt = "\0"+packOutOfBandProsePackage(null, pp);
|
|
string title = utils.packStringId(SID_CONFIRM_TITLE);
|
|
|
|
int pid = utils.getIntScriptVar(player, "cloningTerminal.pid");
|
|
if (pid != 0) forceCloseSUIPage(pid);
|
|
|
|
pid = sui.msgbox(self, player, prompt, sui.YES_NO, title, HANDLER_CLONE_CONFIRM);
|
|
utils.setScriptVar(player, "cloningTerminal.pid", pid);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
messageHandler handleCloneCouponConfirm()
|
|
{
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( (player == null) || (player == obj_id.NULL_ID) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int btnPressed = sui.getIntButtonPressed(params);
|
|
switch(btnPressed)
|
|
{
|
|
case sui.BP_OK:
|
|
queueCommand(player, ##"clone", self, "", COMMAND_PRIORITY_DEFAULT);
|
|
break;
|
|
case sui.BP_CANCEL:
|
|
utils.removeScriptVar(player, cloninglib.SCRVAR_CLONE_COUPON);
|
|
|
|
if ( !cloninglib.verifyFundsForCloning(player) )
|
|
return SCRIPT_CONTINUE;
|
|
|
|
string prompt = utils.packStringId(SID_CONFIRM_PROMPT);
|
|
string title = utils.packStringId(SID_CONFIRM_TITLE);
|
|
sui.msgbox(self, player, prompt, sui.YES_NO, title, HANDLER_CLONE_CONFIRM);
|
|
break;
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleCloneConfirm()
|
|
{
|
|
int btnPressed = sui.getIntButtonPressed(params);
|
|
switch(btnPressed)
|
|
{
|
|
case sui.BP_CANCEL:
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
if ( (player == null) || (player == obj_id.NULL_ID) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
queueCommand(player, ##"clone", self, "", COMMAND_PRIORITY_DEFAULT);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** BIND/CLONE HANDLERS *************************************************/
|
|
messageHandler handleRequestedClone()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = params.getObjId(money.DICT_PLAYER_ID);
|
|
if (!isIdValid(player))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id facility = structure.getContainingBuilding(player);
|
|
if (!isIdValid(facility) || !hasScript(facility, cloninglib.SCRIPT_CLONING_FACILITY))
|
|
{
|
|
sendSystemMessage(player, cloninglib.SID_BAD_CLONE_LOCATION);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if ( utils.hasScriptVar(player, cloninglib.SCRVAR_CLONE_COUPON) )
|
|
{
|
|
obj_id clone_coupon = utils.getObjIdScriptVar(player, cloninglib.SCRVAR_CLONE_COUPON);
|
|
if ( !isIdValid(clone_coupon) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
utils.removeScriptVar(player, cloninglib.SCRVAR_CLONE_COUPON);
|
|
destroyObject(clone_coupon);
|
|
|
|
string custLogMsg = "New Player Rewards: %TU sucessfully used a cloning facility coupon.";
|
|
CustomerServiceLog("NEW_PLAYER_QUESTS", custLogMsg, player);
|
|
|
|
cloninglib.setBind(player, facility);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int retVal = money.getReturnCode(params);
|
|
|
|
int total = params.getInt(money.DICT_TOTAL);
|
|
|
|
if ( retVal == money.RET_SUCCESS )
|
|
{
|
|
if (money.bankTo(self, money.ACCT_CLONING, total))
|
|
{
|
|
cloninglib.setBind(player, facility);
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|