Files
dsrc/sku.0/sys.server/compiled/game/script/player/veteran_rewards.script
T
2015-10-30 13:19:14 -05:00

1750 lines
58 KiB
Plaintext

// ======================================================================
include library.colors_hex;
include library.cts;
include library.features;
include library.player_structure;
include library.static_item;
include library.sui;
include library.utils;
// ======================================================================
const string OBJVAR_NEXT_PROMPT_TIME = "veteran_rewards.next_prompt_time";
const string OBJVAR_SOROSUUB_CLAIMED_ITEMS = "veteran_rewards.items_claimed.sorosuub";
const string OBJVAR_6MOJTL_CONSUMED_EVENTS = "veteran_rewards.events_consumed.6moJTL";
const string OBJVAR_DEPRECATED_ONETIME_ITEMS = "veteran.onetime";
const string SCRIPTVAR_ALREADY_LOGGED_IN = "veteran_rewards.logged_in";
const string SCRIPTVAR_ALREADY_CHECKED_AUTOPROMPT = "veteran_rewards.auto_prompted";
const string SCRIPTVAR_EVENT = "veteran_rewards.event";
const string SCRIPTVAR_ALL_EVENTS = "veteran_rewards.all_events";
const string SCRIPTVAR_ITEM = "veteran_rewards.item";
const string SCRIPTVAR_REWARD_TAGS = "veteran_rewards.rewardTags";
const string SCRIPTVAR_CLAIM_IN_PROGRESS = "veteran_rewards.claim_in_progress";
const int CLAIM_IN_PROGRESS_TIMEOUT = 60; // 1 minute
const string SCRIPTVAR_ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS = "veteran_rewards.account_feature_id_request_in_progress";
const int ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS_TIMEOUT = 60; // 1 minute
const string SCRIPTVAR_REWARD_PID = "veteran_rewards_pid.pid"; //named scriptvar different just in case someone starts removing the entire var tree
const string ANNOUNCEMENT_BOX_TITLE = "@veteran_new:announcement_box_title";
const string CHOICE_CLAIM_NOW = "@veteran_new:claim_now";
const string CHOICE_LAUNCH_BROWSER = "@veteran_new:launch_browser";
const string CHOICE_ASK_NEXT_LOGIN = "@veteran_new:ask_next_login";
const string CHOICE_ASK_ONE_DAY = "@veteran_new:ask_one_day";
const string CHOICE_ASK_ONE_WEEK = "@veteran_new:ask_one_week";
const string ITEM_GRANT_SUCCEEDED = "@veteran_new:item_grant_succeeded";
const string ITEM_GRANT_SUCCEEDED_CAN_TRADE_IN = "@veteran_new:item_grant_succeeded_can_trade_in";
const string ITEM_GRANT_FAILED = "@veteran_new:item_grant_failed";
const string ITEM_GRANT_BOX_TITLE = "@veteran_new:item_grant_box_title";
const string NO_OPTIONS = "@veteran_new:no_options";
const string NO_OPTIONS_BOX_TITLE = "@veteran_new:no_options_box_title";
const string ITEM_AND_EVENT_UNIQUE_ARE_YOU_SURE = "@veteran_new:item_and_event_unique_are_you_sure";
const string ITEM_UNIQUE_ARE_YOU_SURE = "@veteran_new:item_unique_are_you_sure";
const string ITEM_UNIQUE_FEATURE_ID_ARE_YOU_SURE = "@veteran_new:item_unique_feature_id_are_you_sure";
const string EVENT_UNIQUE_ARE_YOU_SURE = "@veteran_new:event_unique_are_you_sure";
const string UNIQUE_ARE_YOU_SURE_BOX_TITLE = "@veteran_new:unique_are_you_sure_box_title";
const string REMIND_NEXT_LOGIN_DESCRIPTION = "@veteran_new:remind_next_login_description";
const string REMIND_ONE_DAY_DESCRIPTION = "@veteran_new:remind_one_day_description";
const string REMIND_ONE_WEEK_DESCRIPTION = "@veteran_new:remind_one_week_description";
const string REMIND_DESCRIPTION_TITLE = "@veteran_new:remind_description_title";
const string MULTIPLE_EVENTS_HELP_TEXT = "@veteran_new:multiple_events_help_text";
const string NO_REWARDS_MESSAGE = "@veteran_new:no_rewards";
const string SCRIPTVAR_REWARD_TRADE_IN_SUI_ID = "rewardTradeInSuiId";
const string SCRIPTVAR_REWARD_TRADE_IN_ITEM_ID = "rewardTradeInItemId";
const string_id SID_SORRY_NO_INFO = new string_id("veteran_new","sorry_no_info");
const string OBJVAR_FREE_CTS_NEXT_PROMPT_TIME = "freeCts.next_prompt_time";
const string SCRIPTVAR_FREE_CTS_SUI_ID = "freeCtsSuiId";
const string SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT = "freeCtsRequestTimeout";
const string SCRIPTVAR_CTS_SUI_ID = "ctsSuiId";
const string SCRIPTVAR_CTS_REQUEST_TIMEOUT = "ctsRequestTimeout";
// ======================================================================
trigger OnLogin()
{
if (!utils.hasScriptVar(self,SCRIPTVAR_ALREADY_LOGGED_IN))
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
int[] onetimes = getIntArrayObjVar(self, OBJVAR_DEPRECATED_ONETIME_ITEMS);
if ( onetimes != null )
{
// Convert old veteran reward records to the new system
boolean hasSoro = false;
for ( int i = 0; i < onetimes.length; ++i )
{
if ( onetimes[i] == ##"object/tangible/space/veteran_reward/sorosuub_space_yacht_deed.iff" )
hasSoro= true;
}
if (hasSoro)
{
setObjVar(self, OBJVAR_SOROSUUB_CLAIMED_ITEMS, (int)1);
setObjVar(self, OBJVAR_6MOJTL_CONSUMED_EVENTS, (int)1);
}
removeObjVar(self, OBJVAR_DEPRECATED_ONETIME_ITEMS);
}
veteranWriteAccountDataToObjvars(self);
if (isFreeCtsPromptTime(self) && (getSecondsUntilCanMakeAnotherFreeCtsRequest(self) <= 0))
checkForFreeCts(self);
utils.setScriptVar(self,SCRIPTVAR_ALREADY_LOGGED_IN,1);
}
if (shouldGetVeteranRewardsMessage(self))
return SCRIPT_CONTINUE;
if (!utils.hasScriptVar(self,SCRIPTVAR_ALREADY_CHECKED_AUTOPROMPT))
{
if (isVeteranRewardsPromptTime(self))
checkForVeteranRewards(self);
utils.setScriptVar(self,SCRIPTVAR_ALREADY_CHECKED_AUTOPROMPT,1);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
trigger OnLogout()
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
utils.removeScriptVar(self,SCRIPTVAR_ALREADY_LOGGED_IN);
utils.removeScriptVar(self,SCRIPTVAR_ALREADY_CHECKED_AUTOPROMPT);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
trigger DoCreateVeteranReward(string[] rewardItemName)
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
// the reward item to be created is at rewardItemName[0]
// return the oid of the created item in rewardItemName[0]
if ((rewardItemName != null) && (rewardItemName.length == 1) && (rewardItemName[0].length() > 0))
{
obj_id createdItem = null;
obj_id playerInventory = utils.getInventoryContainer(self);
if (isIdValid(playerInventory))
{
if (static_item.isStaticItem(rewardItemName[0]))
{
createdItem = static_item.createNewItemFunction(rewardItemName[0], playerInventory);
}
else
{
createdItem = createObjectOverloaded(rewardItemName[0], playerInventory);
}
}
if (isIdValid(createdItem))
{
rewardItemName[0] = "" + createdItem;
// save pertinent info about when the reward item was created/granted
string rewardInfo[] = new string[4];
rewardInfo[0] = "" + getCalendarTime();
rewardInfo[1] = getClusterName();
rewardInfo[2] = "" + self;
rewardInfo[3] = "" + getPlayerStationId(self);
setObjVar(createdItem, "rewardGrantInfo", rewardInfo);
}
else
{
rewardItemName[0] = "0";
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Slash command to claim a veteran reward.
*/
commandHandler cmdClaimVeteranReward()
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if (!hasAccountFeatureIdRequestInProgress(self) && !hasClaimInProgress(self))
{
if (veteranAccountFeatureIdRequest(self))
{
setAccountFeatureIdRequestInProgress(self);
}
else
{
if (!checkForVeteranRewards(self))
sui.msgbox(self, NO_REWARDS_MESSAGE);
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler veteranAccountFeatureIdResponse()
{
clearAccountFeatureIdRequestInProgress(self);
if (!checkForVeteranRewards(self))
sui.msgbox(self, NO_REWARDS_MESSAGE);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Check for available veteran rewards. If any are available, announce them to the player.
*/
boolean checkForVeteranRewards(obj_id self)
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if (!hasClaimInProgress(self)) // don't allow multiple claims at the same time
{
string[] events = veteranGetTriggeredEvents(self);
if ((events != null) && (events.length > 0))
{
Vector choices = new Vector();
choices.addElement(CHOICE_ASK_NEXT_LOGIN);
choices.addElement(CHOICE_ASK_ONE_DAY);
choices.addElement(CHOICE_ASK_ONE_WEEK);
choices.addElement("");
boolean hasMore = false;
for (int i = 0; i < events.length; ++i)
{
if (events[i].startsWith("*"))
{
hasMore = true;
events[i] = events[i].substring(1);
choices.addElement("@veteran_new:color_lime_green " + veteranGetEventAnnouncement(events[i]));
}
else
{
choices.addElement("@veteran_new:empty_string " + veteranGetEventAnnouncement(events[i]));
}
}
utils.setScriptVar(self, SCRIPTVAR_ALL_EVENTS, events);
String announcement = "@veteran_new:announcement";
if (hasMore)
announcement += "\n \n" + MULTIPLE_EVENTS_HELP_TEXT;
//Close other existing Reward UIs. The player should never have
//the ability to get two reward UIs at once.
if(utils.hasScriptVar(self, SCRIPTVAR_REWARD_PID))
{
int oldpid = utils.getIntScriptVar(self, SCRIPTVAR_REWARD_PID);
if(oldpid > 0)
{
forceCloseSUIPage(oldpid);
utils.removeScriptVarTree(self, SCRIPTVAR_REWARD_PID);
}
}
int pid = sui.listbox(self, self, announcement, sui.OK_ONLY, ANNOUNCEMENT_BOX_TITLE, choices, "handleRewardAnnouncement", false, false);
sui.listboxUseOtherButton(pid, CHOICE_LAUNCH_BROWSER); //just adds the More Info button
showSUIPage(pid);
utils.setScriptVar(self, SCRIPTVAR_REWARD_PID, pid);
return true;
}
}
return false;
}
// ----------------------------------------------------------------------
boolean isVeteranRewardsPromptTime(obj_id self)
{
int nextPromptTime = getIntObjVar(self,OBJVAR_NEXT_PROMPT_TIME);
if (nextPromptTime==0 || nextPromptTime < getGameTime())
{
removeObjVar(self,OBJVAR_NEXT_PROMPT_TIME);
return true;
}
return false;
}
// ----------------------------------------------------------------------
/**
* Handle the results of the veteran reward annoucement SUI.
*/
messageHandler handleRewardAnnouncement()
{
string[] events = utils.getStringArrayScriptVar(self, SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if ((events == null) || (events.length == 0))
{
return SCRIPT_CONTINUE;
}
int rowSelected = sui.getListboxSelectedRow(params);
int bp = sui.getIntButtonPressed(params);
if ( ((bp != sui.BP_OK) && (bp != sui.BP_REVERT)) || rowSelected < 0)
{
if (bp == sui.BP_REVERT)
return SCRIPT_CONTINUE;
int nextPromptTime = getIntObjVar(self,OBJVAR_NEXT_PROMPT_TIME);
if (nextPromptTime==0 || nextPromptTime < getGameTime())
{
removeObjVar(self,OBJVAR_NEXT_PROMPT_TIME);
sui.msgbox(self,self, REMIND_NEXT_LOGIN_DESCRIPTION, sui.OK_ONLY, REMIND_DESCRIPTION_TITLE, "noHandler");
}
return SCRIPT_CONTINUE;
}
if (rowSelected==0)
{
if (bp == sui.BP_OK)
{
removeObjVar(self,OBJVAR_NEXT_PROMPT_TIME);
sui.msgbox(self,self, REMIND_NEXT_LOGIN_DESCRIPTION, sui.OK_ONLY, REMIND_DESCRIPTION_TITLE, "noHandler");
}
return SCRIPT_CONTINUE;
}
if ((rowSelected==1) || (rowSelected==2))
{
if (bp == sui.BP_OK)
{
int waitForNextPrompt=0;
if (rowSelected==1)
{
sui.msgbox(self,self, REMIND_ONE_DAY_DESCRIPTION, sui.OK_ONLY, REMIND_DESCRIPTION_TITLE, "noHandler");
waitForNextPrompt=24*60*60;
}
else
{
sui.msgbox(self,self, REMIND_ONE_WEEK_DESCRIPTION, sui.OK_ONLY, REMIND_DESCRIPTION_TITLE, "noHandler");
waitForNextPrompt=7*24*60*60;
}
int gameTime = getGameTime();
int nextPromptTime = gameTime + waitForNextPrompt;
setObjVar(self,OBJVAR_NEXT_PROMPT_TIME,nextPromptTime);
}
return SCRIPT_CONTINUE;
}
if (rowSelected == 3)
{
return SCRIPT_CONTINUE;
}
rowSelected = rowSelected - 4;
if (rowSelected >= events.length)
{
return SCRIPT_CONTINUE;
}
if (bp == sui.BP_OK)
{
chooseRewardForEvent(self, events[rowSelected]);
}
else
{
string webSite = veteranGetEventUrl(events[rowSelected]);
if(webSite != null && !webSite.equals(""))
{
launchClientWebBrowser(self, webSite);
}
else
{
sendSystemMessage(self, SID_SORRY_NO_INFO);
}
checkForVeteranRewards(self);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* The player has asked to claim a reward for a specified event. If there
* is one choice available, give it to him. If there is more than one
* choice available, prompt him to choose what he wants.
*/
void chooseRewardForEvent(obj_id self, string event)
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
string[] rewardChoices = veteranGetRewardChoicesDescriptions( self, event );
string[] rewardChoicesTags = veteranGetRewardChoicesTags( self, event );
if (rewardChoices.length==0)
{
sui.msgbox(self,self, NO_OPTIONS, sui.OK_ONLY, NO_OPTIONS_BOX_TITLE, "noHandler");
}
else if (rewardChoices.length==1)
{
checkForUniquenessAndClaim(self, event, rewardChoicesTags[0]);
}
else
{
// multiple possibilities, display a list box with the choices
utils.setScriptVar(self, SCRIPTVAR_EVENT,event);
utils.setScriptVar(self, SCRIPTVAR_REWARD_TAGS, rewardChoicesTags);
string[] choicesWithLaunchWeb = new string[rewardChoices.length+1];
choicesWithLaunchWeb[0] = CHOICE_LAUNCH_BROWSER;
for (int i=0; i<rewardChoices.length; ++i)
choicesWithLaunchWeb[i+1]=rewardChoices[i];
sui.listbox(self, self, veteranGetEventDescription(event), sui.OK_CANCEL, sui.DEFAULT_TITLE, choicesWithLaunchWeb, "rewardSelectHandler", true, false);
}
}
// ----------------------------------------------------------------------
/**
* Handle the results of the player picking a specific reward item from the
* reward item choice SUI.
*/
messageHandler rewardSelectHandler()
{
string event = utils.getStringScriptVar(self, SCRIPTVAR_EVENT);
string[] rewardChoicesTags = utils.getStringArrayScriptVar(self, SCRIPTVAR_REWARD_TAGS);
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if ((rewardChoicesTags == null) || (rewardChoicesTags.length == 0))
{
return SCRIPT_CONTINUE;
}
if (event == null)
{
return SCRIPT_CONTINUE;
}
if ( (params == null) || (params.isEmpty()) )
{
return SCRIPT_CONTINUE;
}
int bp = sui.getIntButtonPressed(params);
int rowSelected = sui.getListboxSelectedRow(params);
if ( bp == sui.BP_CANCEL || rowSelected < 0)
{
checkForVeteranRewards(self);
return SCRIPT_CONTINUE;
}
if (rowSelected==0)
{
string webSite = veteranGetEventUrl(event);
if(webSite != null && !webSite.equals(""))
{
launchClientWebBrowser(self, webSite);
}
else
{
sendSystemMessage(self, SID_SORRY_NO_INFO);
}
checkForVeteranRewards(self);
}
else
{
if ((rowSelected>0) && ((rowSelected-1) < rewardChoicesTags.length))
{
checkForUniquenessAndClaim(self, event, rewardChoicesTags[rowSelected-1]);
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
void checkForUniquenessAndClaim(obj_id self, String event, String item)
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
boolean itemAccountUnique = veteranIsItemAccountUnique(item);
boolean eventAccountUnique = veteranIsEventAccountUnique(event);
if (itemAccountUnique && eventAccountUnique)
{
utils.setScriptVar(self, SCRIPTVAR_EVENT, event);
utils.setScriptVar(self, SCRIPTVAR_ITEM, item);
sui.msgbox(self,self, ITEM_AND_EVENT_UNIQUE_ARE_YOU_SURE, sui.YES_NO, UNIQUE_ARE_YOU_SURE_BOX_TITLE, "handleUniqueConfirmation");
}
else if (itemAccountUnique)
{
utils.setScriptVar(self, SCRIPTVAR_EVENT, event);
utils.setScriptVar(self, SCRIPTVAR_ITEM, item);
sui.msgbox(self,self, ITEM_UNIQUE_ARE_YOU_SURE, sui.YES_NO, UNIQUE_ARE_YOU_SURE_BOX_TITLE, "handleUniqueConfirmation");
}
else if (eventAccountUnique)
{
utils.setScriptVar(self, SCRIPTVAR_EVENT, event);
utils.setScriptVar(self, SCRIPTVAR_ITEM, item);
sui.msgbox(self,self, EVENT_UNIQUE_ARE_YOU_SURE, sui.YES_NO, UNIQUE_ARE_YOU_SURE_BOX_TITLE, "handleUniqueConfirmation");
}
else if (veteranIsItemAccountUniqueFeatureId(item))
{
utils.setScriptVar(self, SCRIPTVAR_EVENT, event);
utils.setScriptVar(self, SCRIPTVAR_ITEM, item);
sui.msgbox(self,self, ITEM_UNIQUE_FEATURE_ID_ARE_YOU_SURE, sui.YES_NO, UNIQUE_ARE_YOU_SURE_BOX_TITLE, "handleUniqueConfirmation");
}
else
lockAndClaim(self, event, item);
}
// ----------------------------------------------------------------------
/**
* Handler for the "are you sure?" message box that pops up when claiming
* an acocunt-unique reward.
*/
messageHandler handleUniqueConfirmation()
{
string event = utils.getStringScriptVar(self, SCRIPTVAR_EVENT);
string item = utils.getStringScriptVar(self, SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if ((event == null) || (item == null))
return SCRIPT_CONTINUE;
if ( (params == null) || (params.isEmpty()) )
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if ( bp == sui.BP_OK)
lockAndClaim(self,event,item);
else
checkForVeteranRewards(self);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Callback triggered when a veteran reward item has been created and placed
* in the player's inventory.
*/
messageHandler veteranItemGrantSucceeded()
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
boolean canTradeIn = false;
if ((params != null) && params.containsKey("canTradeIn"))
canTradeIn = params.getBoolean("canTradeIn");
if (!canTradeIn)
sui.msgbox(self,self, ITEM_GRANT_SUCCEEDED, sui.OK_ONLY, ITEM_GRANT_BOX_TITLE, "handleGrantAcknowledged");
else
sui.msgbox(self,self, ITEM_GRANT_SUCCEEDED_CAN_TRADE_IN, sui.OK_ONLY, ITEM_GRANT_BOX_TITLE, "handleGrantAcknowledged");
clearClaimInProgress(self);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Callback triggered if the system can't create a veteran reward item, most
* likely due to the player claiming it simultaneously on another cluster.
*/
messageHandler veteranItemGrantFailed()
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
sui.msgbox(self,self, ITEM_GRANT_FAILED, sui.OK_ONLY, ITEM_GRANT_BOX_TITLE, "handleGrantAcknowledged");
clearClaimInProgress(self);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Called when the player clicks "OK" on the message box telling him that a reward is in his inventory.
* Check for any additional available rewards.
*/
messageHandler handleGrantAcknowledged()
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
checkForVeteranRewards(self);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
/**
* Helper function to claim rewards and guarantee that the player can only have one claim going at a time
*/
void lockAndClaim(obj_id self, String event, String item)
{
utils.removeScriptVar(self,SCRIPTVAR_EVENT);
utils.removeScriptVar(self,SCRIPTVAR_ALL_EVENTS);
utils.removeScriptVar(self,SCRIPTVAR_ITEM);
utils.removeScriptVar(self,SCRIPTVAR_REWARD_TAGS);
if (!hasClaimInProgress(self))
{
setClaimInProgress(self);
veteranClaimReward(self,event,item);
}
else
sui.msgbox(self, NO_REWARDS_MESSAGE);
}
// ----------------------------------------------------------------------
boolean shouldGetVeteranRewardsMessage ( obj_id player )
{
string area = getCurrentSceneName();
if ( area != null && area != "" )
{
return ( isInTutorialArea(player) || area.startsWith("space_") );
}
return true;
}
// ----------------------------------------------------------------------
void setClaimInProgress(obj_id player)
{
if (isIdValid(player) && exists(player))
{
int timeOut = getGameTime() + CLAIM_IN_PROGRESS_TIMEOUT;
utils.setScriptVar(player, SCRIPTVAR_CLAIM_IN_PROGRESS, timeOut);
}
}
// ----------------------------------------------------------------------
boolean hasClaimInProgress(obj_id player)
{
if (isIdValid(player) && exists(player) && utils.hasScriptVar(player, SCRIPTVAR_CLAIM_IN_PROGRESS))
{
int timeOut = utils.getIntScriptVar(player, SCRIPTVAR_CLAIM_IN_PROGRESS);
int timeNow = getGameTime();
if (timeOut >= timeNow)
return true;
}
return false;
}
// ----------------------------------------------------------------------
void clearClaimInProgress(obj_id player)
{
if (isIdValid(player) && exists(player))
utils.removeScriptVar(player, SCRIPTVAR_CLAIM_IN_PROGRESS);
}
// ----------------------------------------------------------------------
void setAccountFeatureIdRequestInProgress(obj_id player)
{
if (isIdValid(player) && exists(player))
{
int timeOut = getGameTime() + ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS_TIMEOUT;
utils.setScriptVar(player, SCRIPTVAR_ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS, timeOut);
}
}
// ----------------------------------------------------------------------
boolean hasAccountFeatureIdRequestInProgress(obj_id player)
{
if (isIdValid(player) && exists(player) && utils.hasScriptVar(player, SCRIPTVAR_ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS))
{
int timeOut = utils.getIntScriptVar(player, SCRIPTVAR_ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS);
int timeNow = getGameTime();
if (timeOut >= timeNow)
return true;
}
return false;
}
// ----------------------------------------------------------------------
void clearAccountFeatureIdRequestInProgress(obj_id player)
{
if (isIdValid(player) && exists(player))
utils.removeScriptVar(player, SCRIPTVAR_ACCOUNT_FEATURE_ID_REQUEST_IN_PROGRESS);
}
// ----------------------------------------------------------------------
boolean isFreeCtsPromptTime(obj_id self)
{
int nextPromptTime = getIntObjVar(self,OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
if (nextPromptTime==0 || nextPromptTime < getGameTime())
{
removeObjVar(self,OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
return true;
}
return false;
}
// ----------------------------------------------------------------------
boolean checkForFreeCts(obj_id self)
{
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters != null) && (freeCtsClusters.length > 0))
{
Vector choices = new Vector();
choices.addElement("I am not ready to transfer yet. Remind me at my next login.");
choices.addElement("I am not ready to transfer yet. Remind me tomorrow.");
choices.addElement("I am not ready to transfer yet. Remind me in a week.");
choices.addElement("I am not ready to transfer yet. Remind me in a month.");
choices.addElement("");
choices.addElement("I am ready to transfer now.");
string announcement = "This character is eligible for a Free Character Transfer to one of the following designated galaxy servers:";
announcement += "\n\n";
for (int i = 0; i < freeCtsClusters.length; ++i)
{
announcement += "\t";
announcement += freeCtsClusters[i];
announcement += "\n";
}
announcement += "\n";
announcement += "Please select one of the following options.";
int pid = sui.listbox(self, self, announcement, sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", choices, "handleFreeCtsAnnouncement", true, false);
setFreeCtsSuiId(self, pid);
return true;
}
return false;
}
// ----------------------------------------------------------------------
commandHandler cmdFreeCts()
{
int secondsUntilCanMakeAnotherFreeCtsRequest = getSecondsUntilCanMakeAnotherFreeCtsRequest(self);
if (secondsUntilCanMakeAnotherFreeCtsRequest > 0)
{
int[] convertedTime = player_structure.convertSecondsTime(secondsUntilCanMakeAnotherFreeCtsRequest);
sendSystemMessage(self, "This character currently has a pending Free Character Transfer request. Please wait " + convertedTime[2] + "m:" + convertedTime[3] + "s and try again.", "");
return SCRIPT_CONTINUE;
}
if (utils.hasScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID))
{
int savedPageId = utils.getIntScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID);
utils.removeScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID);
forceCloseSUIPage(savedPageId);
}
if (!checkForFreeCts(self))
sendSystemMessage(self, "This character is not eligible for a Free Character Transfer.", "");
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsAnnouncement()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
int rowSelected = sui.getListboxSelectedRow(params);
if (rowSelected == 0)
{
removeObjVar(self, OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
sui.msgbox(self, self, "You will be reminded the next time you log in. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
}
else if ((rowSelected == 1) || (rowSelected == 2) || (rowSelected == 3))
{
int waitForNextPrompt = 0;
if (rowSelected == 1)
{
sui.msgbox(self, self, "You will be reminded the next time you log in after 24 hours have passed. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
waitForNextPrompt = 24*60*60;
}
else if (rowSelected == 2)
{
sui.msgbox(self, self, "You will be reminded the next time you log in after a week has passed. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
waitForNextPrompt = 7*24*60*60;
}
else
{
sui.msgbox(self, self, "You will be reminded the next time you log in after 30 days have passed. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
waitForNextPrompt = 30*24*60*60;
}
int gameTime = getGameTime();
int nextPromptTime = gameTime + waitForNextPrompt;
setObjVar(self, OBJVAR_FREE_CTS_NEXT_PROMPT_TIME, nextPromptTime);
}
else if (rowSelected == 5)
{
removeObjVar(self, OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
if (isValidLocationForCts(self, true))
{
int pid = sui.msgbox(self, self, "@veteran_new:free_cts_legal", sui.OK_CANCEL, "Guidelines and Restrictions", "handleFreeCtsLegal");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setFreeCtsSuiId(self, pid);
}
}
else
{
removeObjVar(self, OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
sui.msgbox(self, self, "You will be reminded the next time you log in. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
}
}
else
{
removeObjVar(self, OBJVAR_FREE_CTS_NEXT_PROMPT_TIME);
sui.msgbox(self, self, "You will be reminded the next time you log in. You may also type \"/freeCts\" to initiate your character transfer at any time.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
boolean isValidLocationForCts(obj_id self, boolean freeCts)
{
if (!isIdValid(self) || !exists(self))
return false;
// must be on one of the ten original ground planets for CTS
location loc = getLocation(self);
if (loc == null)
return false;
if (loc.area.equals("tatooine") ||
loc.area.equals("naboo") ||
loc.area.equals("corellia") ||
loc.area.equals("rori") ||
loc.area.equals("talus") ||
loc.area.equals("yavin4") ||
loc.area.equals("endor") ||
loc.area.equals("lok") ||
loc.area.equals("dantooine") ||
loc.area.equals("dathomir"))
{
return true;
}
if (freeCts)
sui.msgbox(self, self, "You must be located on one of the original 10 ground planets (Corellia, Dantooine, Dathomir, Endor, Lok, Naboo, Rori, Talus, Tatooine, and Yavin 4) before you can transfer. Type \"/freeCts\" when you are ready to attempt your character transfer again.", sui.OK_ONLY, "Star Wars Galaxies Free Character Transfer Service", "noHandler");
else
sui.msgbox(self, self, "You must be located on one of the original 10 ground planets (Corellia, Dantooine, Dathomir, Endor, Lok, Naboo, Rori, Talus, Tatooine, and Yavin 4) before you can transfer.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsLegal()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
freeCtsDisplayDestGalaxyChoice(self, "");
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
void freeCtsDisplayDestGalaxyChoice(obj_id self, string messageHeader)
{
if (!isIdValid(self) || !exists(self))
return;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return;
Vector choices = new Vector();
for (int i = 0; i < freeCtsClusters.length; ++i)
{
choices.addElement(freeCtsClusters[i]);
}
string announcement = "";
if ((messageHeader != null) && (messageHeader.length() > 0))
{
announcement = messageHeader;
announcement += "\n\n";
}
announcement += "Please select which destination galaxy server you would like to transfer this character to for free and click \"Next\" to proceed.";
int pid = sui.listbox(self, self, announcement, sui.OK_CANCEL, "Galaxy Selection", choices, "handleFreeCtsDestinationGalaxyChoice", false, false);
sui.setSUIProperty(pid, sui.LISTBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.LISTBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setFreeCtsSuiId(self, pid);
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsDestinationGalaxyChoice()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
int rowSelected = sui.getListboxSelectedRow(params);
if (rowSelected < freeCtsClusters.length)
{
validateFreeCts(self, freeCtsClusters[rowSelected], getName(self));
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsValidateFailCannotCreateCharacter()
{
String destinationGalaxy = params.getString("destinationGalaxy");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0))
{
freeCtsDisplayDestGalaxyChoice(self, "\\" + colors_hex.RED + "You cannot create any more characters on the selected destination galaxy " + destinationGalaxy + "." + "\\" + colors_hex.WHITE);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsValidateFailDestGalaxyUnavailable()
{
String destinationGalaxy = params.getString("destinationGalaxy");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0))
{
freeCtsDisplayDestGalaxyChoice(self, "\\" + colors_hex.RED + "The selected destination galaxy " + destinationGalaxy + " is currently unavailable." + "\\" + colors_hex.WHITE);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsValidateFailNameValidation()
{
String destinationGalaxy = params.getString("destinationGalaxy");
String destinationCharacterName = params.getString("destinationCharacterName");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0) && (destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
freeCtsDisplayDestCharacterNameInput(self, destinationGalaxy, destinationCharacterName, params.getString("reason"));
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
void freeCtsDisplayDestCharacterNameInput(obj_id self, string destinationGalaxy, string destinationCharacterName, string reason)
{
if (!isIdValid(self) || !exists(self))
return;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return;
string announcement = "The name of your character, \"";
announcement += destinationCharacterName;
announcement += "\", is not available on ";
announcement += destinationGalaxy;
announcement += ". The name may already be in use or there may be invalid characters used in the name. Please enter a different name for your character.";
if ((reason != null) && (reason.length() > 0))
{
announcement = reason;
}
int pid = sui.inputbox(self, self, announcement, "Please Choose a New Name", "handleFreeCtsDestinationCharacerNameInput", 125, false, "");
sui.setSUIProperty(pid, sui.INPUTBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.INPUTBOX_BTN_OK, sui.PROP_TEXT, "Next");
sui.setSUIProperty(pid, sui.INPUTBOX_INPUT, sui.PROP_TEXT, destinationCharacterName);
setSUIProperty (pid, sui.INPUTBOX_INPUT, "MaxLength", String.valueOf(125));
showSUIPage(pid);
setFreeCtsSuiId(self, pid);
utils.setScriptVar(self, "freeCtsDestinationGalaxy", destinationGalaxy);
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsDestinationCharacerNameInput()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
string destinationGalaxy = utils.getStringScriptVar(self, "freeCtsDestinationGalaxy");
utils.removeScriptVar(self, "freeCtsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
string destinationCharacterName = sui.getInputBoxText(params);
if ((destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
validateFreeCts(self, destinationGalaxy, destinationCharacterName);
}
else
{
freeCtsDisplayDestCharacterNameInput(self, destinationGalaxy, "", "Please enter a name.");
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsValidateSuccess()
{
String destinationGalaxy = params.getString("destinationGalaxy");
String destinationCharacterName = params.getString("destinationCharacterName");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0) && (destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
int pid = sui.msgbox(self, self, "@veteran_new:free_cts_are_you_sure", sui.OK_CANCEL, "Are you sure?", "handleFreeCtsAreYouSure");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setFreeCtsSuiId(self, pid);
utils.setScriptVar(self, "freeCtsDestinationGalaxy", destinationGalaxy);
utils.setScriptVar(self, "freeCtsDestinationCharacterName", destinationCharacterName);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsAreYouSure()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
string destinationGalaxy = utils.getStringScriptVar(self, "freeCtsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
string destinationCharacterName = utils.getStringScriptVar(self, "freeCtsDestinationCharacterName");
if ((destinationCharacterName == null) || (destinationCharacterName.length() <= 0))
return SCRIPT_CONTINUE;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
string sourceCharacterName = getName(self);
string announcement = "Character:\t\t\t" + sourceCharacterName + "\n";
announcement += "Transferring From:\t" + getClusterName() + "\n";
announcement += "\n";
announcement += "Transferring To:\t" + destinationGalaxy;
if (!destinationCharacterName.equals(sourceCharacterName))
{
announcement += ", " + destinationCharacterName;
}
announcement += "\n\n";
announcement += "Click \"Transfer\" to begin the free transfer of this character. Once selected, this action cannot be undone. You will be disconnected when you click the \"Transfer\" button. Please wait at least two (2) hours before logging back in. When you do log back in, your character will be in their new galaxy!";
int pid = sui.msgbox(self, self, announcement, sui.OK_CANCEL, "Free Character Transfer Confirmation", "handleFreeCtsConfirmation");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Transfer");
showSUIPage(pid);
setFreeCtsSuiId(self, pid);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleFreeCtsConfirmation()
{
if (!verifyFreeCtsSuiId(self, params.getInt("pageId")))
return SCRIPT_CONTINUE;
string destinationGalaxy = utils.getStringScriptVar(self, "freeCtsDestinationGalaxy");
utils.removeScriptVar(self, "freeCtsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
string destinationCharacterName = utils.getStringScriptVar(self, "freeCtsDestinationCharacterName");
utils.removeScriptVar(self, "freeCtsDestinationCharacterName");
if ((destinationCharacterName == null) || (destinationCharacterName.length() <= 0))
return SCRIPT_CONTINUE;
string[] freeCtsClusters = qualifyForFreeCts(self);
if ((freeCtsClusters == null) || (freeCtsClusters.length <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if ((bp == sui.BP_OK) && (isValidLocationForCts(self, true)))
{
performFreeCts(self, destinationGalaxy, destinationCharacterName);
utils.setScriptVar(self, SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT, getGameTime() + 300); // 5 minutes
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
boolean verifyFreeCtsSuiId(obj_id self, int pageId)
{
if (!isIdValid(self) || !exists(self))
return false;
if (!utils.hasScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID))
return false;
int savedPageId = utils.getIntScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID);
utils.removeScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID);
if (savedPageId == pageId)
return true;
return false;
}
// ----------------------------------------------------------------------
void setFreeCtsSuiId(obj_id self, int pageId)
{
if (!isIdValid(self) || !exists(self))
return;
utils.setScriptVar(self, SCRIPTVAR_FREE_CTS_SUI_ID, pageId);
utils.removeScriptVar(self, SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT);
}
// ----------------------------------------------------------------------
int getSecondsUntilCanMakeAnotherFreeCtsRequest(obj_id self)
{
if (!isIdValid(self) || !exists(self))
return 0;
if (!utils.hasScriptVar(self, SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT))
return 0;
int gameTimePreviousRequestTimeout = utils.getIntScriptVar(self, SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT);
int gameTimeNow = getGameTime();
if (gameTimeNow >= gameTimePreviousRequestTimeout)
{
utils.removeScriptVar(self, SCRIPTVAR_FREE_CTS_REQUEST_TIMEOUT);
return 0;
}
return (gameTimePreviousRequestTimeout - gameTimeNow);
}
// ----------------------------------------------------------------------
messageHandler handleRewardTradeInConfirmation()
{
if (!utils.hasScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_SUI_ID))
return SCRIPT_CONTINUE;
if (!utils.hasScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_ITEM_ID))
return SCRIPT_CONTINUE;
if (params.getInt("pageId") != utils.getIntScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_SUI_ID))
return SCRIPT_CONTINUE;
obj_id item = utils.getObjIdScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_ITEM_ID);
if (!isIdValid(item) || !exists(item))
return SCRIPT_CONTINUE;
utils.removeScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_SUI_ID);
utils.removeScriptVar(self, SCRIPTVAR_REWARD_TRADE_IN_ITEM_ID);
if (sui.getIntButtonPressed(params) == sui.BP_OK)
veteranTradeInReward(self, item);
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler initiateCtsFromItem()
{
const int secondsUntilCanMakeAnotherCtsRequest = getSecondsUntilCanMakeAnotherCtsRequest(self);
if (secondsUntilCanMakeAnotherCtsRequest > 0)
{
sendSystemMessage(self, "This character currently has a pending Character Transfer request. Please wait " + (secondsUntilCanMakeAnotherCtsRequest / 60) + "m:" + (secondsUntilCanMakeAnotherCtsRequest % 60) + "s and try again.", "");
return SCRIPT_CONTINUE;
}
if (utils.hasScriptVar(self, SCRIPTVAR_CTS_SUI_ID))
{
const int savedPageId = utils.getIntScriptVar(self, SCRIPTVAR_CTS_SUI_ID);
utils.removeScriptVar(self, SCRIPTVAR_CTS_SUI_ID);
forceCloseSUIPage(savedPageId);
}
const obj_id item = params.getObjId("item");
if (!verifyItemForCts(self, item))
return SCRIPT_CONTINUE;
const string[] ctsDestinationClusters = getCtsDestinationClusters();
if ((ctsDestinationClusters == null) || (ctsDestinationClusters.length <= 0))
{
sendSystemMessage(self, "Character Transfer is currently not allowed from this galaxy server.", "");
return SCRIPT_CONTINUE;
}
if (isValidLocationForCts(self, false))
{
const int pid = sui.msgbox(self, self, "@veteran_new:cts_legal", sui.OK_CANCEL, "Guidelines and Restrictions", "handleCtsLegal");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setCtsSuiId(self, item, pid);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsLegal()
{
const obj_id item = verifyCtsSuiId(self, params.getInt("pageId"));
if (!isValidId(item))
return SCRIPT_CONTINUE;
const int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
ctsDisplayDestGalaxyChoice(self, item, "");
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
void ctsDisplayDestGalaxyChoice(obj_id self, obj_id item, string messageHeader)
{
if (!isIdValid(self) || !exists(self) || !isIdValid(item) || !exists(item))
return;
const string[] ctsDestinationClusters = getCtsDestinationClusters();
if ((ctsDestinationClusters == null) || (ctsDestinationClusters.length <= 0))
return;
Vector choices = new Vector();
for (int i = 0; i < ctsDestinationClusters.length; ++i)
{
choices.addElement(ctsDestinationClusters[i]);
}
string announcement = "";
if ((messageHeader != null) && (messageHeader.length() > 0))
{
announcement = messageHeader;
announcement += "\n\n";
}
announcement += "Please select which destination galaxy server you would like to transfer this character to and click \"Next\" to proceed.";
const int pid = sui.listbox(self, self, announcement, sui.OK_CANCEL, "Galaxy Selection", choices, "handleCtsDestinationGalaxyChoice", false, false);
sui.setSUIProperty(pid, sui.LISTBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.LISTBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setCtsSuiId(self, item, pid);
}
// ----------------------------------------------------------------------
messageHandler handleCtsDestinationGalaxyChoice()
{
const obj_id item = verifyCtsSuiId(self, params.getInt("pageId"));
if (!isValidId(item))
return SCRIPT_CONTINUE;
const string[] ctsDestinationClusters = getCtsDestinationClusters();
if ((ctsDestinationClusters == null) || (ctsDestinationClusters.length <= 0))
return SCRIPT_CONTINUE;
const int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
const int rowSelected = sui.getListboxSelectedRow(params);
if (rowSelected < ctsDestinationClusters.length)
{
utils.setScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID, item);
validateCts(self, ctsDestinationClusters[rowSelected], getName(self));
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsValidateFailCannotCreateCharacter()
{
if (!utils.hasScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID))
return SCRIPT_CONTINUE;
const obj_id item = utils.getObjIdScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
utils.removeScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
const String destinationGalaxy = params.getString("destinationGalaxy");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0))
{
ctsDisplayDestGalaxyChoice(self, item, "\\" + colors_hex.RED + "You cannot create any more characters on the selected destination galaxy " + destinationGalaxy + "." + "\\" + colors_hex.WHITE);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsValidateFailDestGalaxyUnavailable()
{
if (!utils.hasScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID))
return SCRIPT_CONTINUE;
const obj_id item = utils.getObjIdScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
utils.removeScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
const String destinationGalaxy = params.getString("destinationGalaxy");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0))
{
ctsDisplayDestGalaxyChoice(self, item, "\\" + colors_hex.RED + "The selected destination galaxy " + destinationGalaxy + " is currently unavailable." + "\\" + colors_hex.WHITE);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsValidateFailNameValidation()
{
if (!utils.hasScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID))
return SCRIPT_CONTINUE;
const obj_id item = utils.getObjIdScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
utils.removeScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
const String destinationGalaxy = params.getString("destinationGalaxy");
const String destinationCharacterName = params.getString("destinationCharacterName");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0) && (destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
ctsDisplayDestCharacterNameInput(self, item, destinationGalaxy, destinationCharacterName, params.getString("reason"));
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
void ctsDisplayDestCharacterNameInput(obj_id self, obj_id item, string destinationGalaxy, string destinationCharacterName, string reason)
{
if (!isIdValid(self) || !exists(self) || !isIdValid(item) || !exists(item))
return;
string announcement = "The name of your character, \"";
announcement += destinationCharacterName;
announcement += "\", is not available on ";
announcement += destinationGalaxy;
announcement += ". The name may already be in use or there may be invalid characters used in the name. Please enter a different name for your character.";
if ((reason != null) && (reason.length() > 0))
{
announcement = reason;
}
const int pid = sui.inputbox(self, self, announcement, "Please Choose a New Name", "handleCtsDestinationCharacerNameInput", 125, false, "");
sui.setSUIProperty(pid, sui.INPUTBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.INPUTBOX_BTN_OK, sui.PROP_TEXT, "Next");
sui.setSUIProperty(pid, sui.INPUTBOX_INPUT, sui.PROP_TEXT, destinationCharacterName);
setSUIProperty (pid, sui.INPUTBOX_INPUT, "MaxLength", String.valueOf(125));
showSUIPage(pid);
setCtsSuiId(self, item, pid);
utils.setScriptVar(self, "ctsDestinationGalaxy", destinationGalaxy);
}
// ----------------------------------------------------------------------
messageHandler handleCtsDestinationCharacerNameInput()
{
const obj_id item = verifyCtsSuiId(self, params.getInt("pageId"));
if (!isValidId(item))
return SCRIPT_CONTINUE;
const string destinationGalaxy = utils.getStringScriptVar(self, "ctsDestinationGalaxy");
utils.removeScriptVar(self, "ctsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
const int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
const string destinationCharacterName = sui.getInputBoxText(params);
if ((destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
utils.setScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID, item);
validateCts(self, destinationGalaxy, destinationCharacterName);
}
else
{
ctsDisplayDestCharacterNameInput(self, item, destinationGalaxy, "", "Please enter a name.");
}
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsValidateSuccess()
{
if (!utils.hasScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID))
return SCRIPT_CONTINUE;
const obj_id item = utils.getObjIdScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
utils.removeScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
const String destinationGalaxy = params.getString("destinationGalaxy");
const String destinationCharacterName = params.getString("destinationCharacterName");
if ((destinationGalaxy != null) && (destinationGalaxy.length() > 0) && (destinationCharacterName != null) && (destinationCharacterName.length() > 0))
{
const int pid = sui.msgbox(self, self, "@veteran_new:free_cts_are_you_sure", sui.OK_CANCEL, "Are you sure?", "handleCtsAreYouSure");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Next");
showSUIPage(pid);
setCtsSuiId(self, item, pid);
utils.setScriptVar(self, "ctsDestinationGalaxy", destinationGalaxy);
utils.setScriptVar(self, "ctsDestinationCharacterName", destinationCharacterName);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsAreYouSure()
{
const obj_id item = verifyCtsSuiId(self, params.getInt("pageId"));
if (!isValidId(item))
return SCRIPT_CONTINUE;
const string destinationGalaxy = utils.getStringScriptVar(self, "ctsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
const string destinationCharacterName = utils.getStringScriptVar(self, "ctsDestinationCharacterName");
if ((destinationCharacterName == null) || (destinationCharacterName.length() <= 0))
return SCRIPT_CONTINUE;
const int bp = sui.getIntButtonPressed(params);
if (bp == sui.BP_OK)
{
const string sourceCharacterName = getName(self);
string announcement = "Character:\t\t\t" + sourceCharacterName + "\n";
announcement += "Transferring From:\t" + getClusterName() + "\n";
announcement += "\n";
announcement += "Transferring To:\t" + destinationGalaxy;
if (!destinationCharacterName.equals(sourceCharacterName))
{
announcement += ", " + destinationCharacterName;
}
announcement += "\n\n";
announcement += "Click \"Transfer\" to begin the transfer of this character. Once selected, this action cannot be undone. You will be disconnected when you click the \"Transfer\" button. Please wait at least two (2) hours before logging back in. When you do log back in, your character will be in their new galaxy!";
const int pid = sui.msgbox(self, self, announcement, sui.OK_CANCEL, "Character Transfer Confirmation", "handleCtsConfirmation");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, "Exit");
sui.setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, "Transfer");
showSUIPage(pid);
setCtsSuiId(self, item, pid);
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
messageHandler handleCtsConfirmation()
{
const obj_id item = verifyCtsSuiId(self, params.getInt("pageId"));
if (!isValidId(item))
return SCRIPT_CONTINUE;
const string destinationGalaxy = utils.getStringScriptVar(self, "ctsDestinationGalaxy");
utils.removeScriptVar(self, "ctsDestinationGalaxy");
if ((destinationGalaxy == null) || (destinationGalaxy.length() <= 0))
return SCRIPT_CONTINUE;
const string destinationCharacterName = utils.getStringScriptVar(self, "ctsDestinationCharacterName");
utils.removeScriptVar(self, "ctsDestinationCharacterName");
if ((destinationCharacterName == null) || (destinationCharacterName.length() <= 0))
return SCRIPT_CONTINUE;
int bp = sui.getIntButtonPressed(params);
if ((bp == sui.BP_OK) && isValidLocationForCts(self, false) && verifyItemForCts(self, item))
{
CustomerServiceLog("CharacterTransfer", "requesting ingame CTS for character " + self + " using item " + item);
performCts(self, destinationGalaxy, destinationCharacterName);
utils.setScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID, item);
utils.setScriptVar(self, SCRIPTVAR_CTS_REQUEST_TIMEOUT, getGameTime() + 300); // 5 minutes
// set objvar on the item to prevent it from being used again
setObjVar(item, "ctsItemUsage.cluster", getClusterName());
setObjVar(item, "ctsItemUsage.user", self);
setObjVar(item, "ctsItemUsage.time", getCalendarTime());
}
return SCRIPT_CONTINUE;
}
// ----------------------------------------------------------------------
boolean verifyItemForCts(obj_id player, obj_id item)
{
if (!isValidId(player))
return false;
// item must be in top level inventory
if (!isValidId(item))
{
sui.msgbox(player, player, "The item to be used for Character Transfer must be in your top level inventory.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
const obj_id itemContainer = getContainedBy(item);
if (!isValidId(itemContainer))
{
sui.msgbox(player, player, "The item to be used for Character Transfer must be in your top level inventory.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
const obj_id playerInventory = getObjectInSlot(player, "inventory");
if (!isValidId(playerInventory))
{
sui.msgbox(player, player, "The item to be used for Character Transfer must be in your top level inventory.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
if (itemContainer != playerInventory)
{
sui.msgbox(player, player, "The item to be used for Character Transfer must be in your top level inventory.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
// see if item has already been used
if (hasObjVar(item, "ctsItemUsage.user"))
{
obj_id user = getObjIdObjVar(item, "ctsItemUsage.user");
if (isValidId(user))
{
// if the same user is trying to use the item again, then it most
// likely means that the CTS attempt failed (or else the item would
// have been deleted), so reset the item's usage
if (user == player)
{
removeObjVar(item, "ctsItemUsage.cluster");
removeObjVar(item, "ctsItemUsage.user");
removeObjVar(item, "ctsItemUsage.time");
}
else
{
// some other player is trying to use the item after it has already been used
sui.msgbox(player, player, "The item has already been used by someone else to perform a Character Transfer.", sui.OK_ONLY, "Star Wars Galaxies Character Transfer Service", "noHandler");
return false;
}
}
}
return true;
}
// ----------------------------------------------------------------------
void setCtsSuiId(obj_id self, obj_id item, int pageId)
{
if (!isIdValid(self) || !exists(self) || !isIdValid(item) || !exists(item))
return;
utils.setScriptVar(self, SCRIPTVAR_CTS_SUI_ID, pageId);
utils.setScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID, item);
utils.removeScriptVar(self, SCRIPTVAR_CTS_REQUEST_TIMEOUT);
}
// ----------------------------------------------------------------------
obj_id verifyCtsSuiId(obj_id self, int pageId)
{
if (!isIdValid(self) || !exists(self))
return null;
if (!utils.hasScriptVar(self, SCRIPTVAR_CTS_SUI_ID))
return null;
const int savedPageId = utils.getIntScriptVar(self, SCRIPTVAR_CTS_SUI_ID);
utils.removeScriptVar(self, SCRIPTVAR_CTS_SUI_ID);
if (savedPageId == pageId)
{
if (!utils.hasScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID))
return null;
const obj_id item = utils.getObjIdScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
utils.removeScriptVar(self, cts.SCRIPTVAR_CTS_ITEM_ID);
return item;
}
return null;
}
// ----------------------------------------------------------------------
int getSecondsUntilCanMakeAnotherCtsRequest(obj_id self)
{
if (!isIdValid(self) || !exists(self))
return 0;
if (!utils.hasScriptVar(self, SCRIPTVAR_CTS_REQUEST_TIMEOUT))
return 0;
const int gameTimePreviousRequestTimeout = utils.getIntScriptVar(self, SCRIPTVAR_CTS_REQUEST_TIMEOUT);
const int gameTimeNow = getGameTime();
if (gameTimeNow >= gameTimePreviousRequestTimeout)
{
utils.removeScriptVar(self, SCRIPTVAR_CTS_REQUEST_TIMEOUT);
return 0;
}
return (gameTimePreviousRequestTimeout - gameTimeNow);
}
// ======================================================================