mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
298 lines
7.6 KiB
Plaintext
298 lines
7.6 KiB
Plaintext
/**
|
|
* Copyright (c)2000-2002 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
*
|
|
* Title: insurance.script
|
|
* Description: script for insurance menu options; to be attached to insurance terminals
|
|
* @author $Author:$
|
|
* @version $Revision:$
|
|
*/
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
|
|
include library.cloninglib;
|
|
include library.money;
|
|
include library.prose;
|
|
include library.sui;
|
|
include library.utils;
|
|
|
|
|
|
/***** INHERITS ********************************************************/
|
|
|
|
inherits terminal.base.base_terminal;
|
|
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
const string_id SID_MNU_REPAIR = new string_id("sui", "mnu_repair");
|
|
const string_id SID_MNU_REPAIR_ALL = new string_id("sui", "mnu_repair_all"); //menu1
|
|
|
|
|
|
/***********************************************************************/
|
|
|
|
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
|
|
{
|
|
if (isMob(self))
|
|
return SCRIPT_CONTINUE;
|
|
|
|
menu_info_data mid = mi.getMenuItemByType(menu_info_types.ITEM_USE);
|
|
if ( mid == null )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int mnu = mid.getId();
|
|
int repair_all = mi.addSubMenu(mnu, menu_info_types.SERVER_MENU1, SID_MNU_REPAIR_ALL);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
trigger OnObjectMenuSelect(obj_id player, int item)
|
|
{
|
|
if ( item == menu_info_types.ITEM_USE)
|
|
{
|
|
openRepairSui(player);
|
|
}
|
|
else if ( item == menu_info_types.SERVER_MENU1)
|
|
{
|
|
confirmRepairAll(player);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
|
|
messageHandler handleConfirmRepairAll()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = params.getObjId("player");
|
|
|
|
if (!isIdValid(player) || !exists(player))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int btn = sui.getIntButtonPressed(params);
|
|
int pid = utils.getIntScriptVar(player, "repair.sui");
|
|
|
|
if (btn == sui.BP_CANCEL)
|
|
{
|
|
closeOldRepairSui(player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int totalCost = utils.getIntScriptVar(player, "repair.totalCost");
|
|
cloninglib.payRepairFee(player, self, totalCost);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
void confirmRepairAll(obj_id player)
|
|
{
|
|
closeOldRepairSui(player);
|
|
|
|
obj_id[] repairList = cloninglib.getAllRepairItems(player);
|
|
int totalCost = cloninglib.getTotalRepairCost(player, repairList);
|
|
if (totalCost == 0)
|
|
{
|
|
sendSystemMessage(player, new string_id("terminal_ui", "no_repair_items"));
|
|
return;
|
|
}
|
|
|
|
prose_package prompt = prose.getPackage(new string_id("terminal_ui", "repair_all_confirm"), totalCost);
|
|
string title = "@terminal_ui:repair_all_title";
|
|
|
|
int pid = sui.msgbox(getSelf(), player, prompt, sui.YES_NO, title, sui.MSG_NORMAL, "handleConfirmRepairAll");
|
|
|
|
utils.setScriptVar(player, "repair.sui", pid);
|
|
utils.setScriptVar(player, "repair.totalCost", totalCost);
|
|
utils.setScriptVar(player, "repair.repairList", repairList);
|
|
}
|
|
|
|
void openRepairSui(obj_id player)
|
|
{
|
|
closeOldRepairSui(player);
|
|
|
|
obj_id[] repairList = cloninglib.getAllRepairItems(player);
|
|
|
|
if (repairList == null || repairList.length == 0)
|
|
{
|
|
sendSystemMessage(player, new string_id("terminal_ui", "no_repair_items"));
|
|
return;
|
|
}
|
|
|
|
int[] costList = cloninglib.getItemRepairCostList(player, repairList);
|
|
int totalCost = 0;
|
|
for (int i = 0; i < costList.length; i++)
|
|
{
|
|
totalCost += costList[i];
|
|
}
|
|
|
|
utils.setScriptVar(player, "repair.itemList", repairList);
|
|
utils.setScriptVar(player, "repair.costList", costList);
|
|
utils.setScriptVar(player, "repair.totalCost", totalCost);
|
|
|
|
string title = "@terminal_ui:repair_title";
|
|
string prompt = buildRepairPrompt(player, -1);
|
|
|
|
int pid = createSUIPage(sui.SUI_LISTBOX, getSelf(), player, "handleRepairSuiSelect");
|
|
|
|
setSUIProperty(pid, sui.LISTBOX_TITLE, sui.PROP_TEXT, title);
|
|
setSUIProperty(pid, sui.LISTBOX_PROMPT, sui.PROP_TEXT, prompt);
|
|
|
|
// Add buttons.
|
|
sui.listboxButtonSetup(pid, sui.OK_CANCEL_REFRESH);
|
|
sui.listboxUseOtherButton(pid, utils.packStringId(SID_MNU_REPAIR_ALL));
|
|
|
|
clearSUIDataSource(pid, sui.LISTBOX_DATASOURCE);
|
|
|
|
for (int i = 0; i < repairList.length; i++)
|
|
{
|
|
addSUIDataItem(pid, sui.LISTBOX_DATASOURCE, "" + i);
|
|
setSUIProperty(pid, sui.LISTBOX_DATASOURCE + "." + i, sui.PROP_TEXT, buildRepairEntry(repairList[i], costList[i]));
|
|
}
|
|
|
|
subscribeToSUIEvent(pid, sui_event_type.SET_onGenericSelection, sui.LISTBOX_LIST, "handleRepairSuiUpdate");
|
|
subscribeToSUIPropertyForEvent(pid, sui_event_type.SET_onGenericSelection, sui.LISTBOX_LIST, sui.LISTBOX_LIST, sui.PROP_SELECTEDROW);
|
|
|
|
subscribeToSUIProperty(pid, sui.LISTBOX_LIST, sui.PROP_SELECTEDROW);
|
|
subscribeToSUIProperty(pid, sui.LISTBOX_TITLE, sui.PROP_TEXT);
|
|
|
|
showSUIPage(pid);
|
|
flushSUIPage(pid);
|
|
|
|
utils.setScriptVar(player, "repair.sui", pid);
|
|
}
|
|
|
|
messageHandler handleRepairSuiUpdate()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
int pid = utils.getIntScriptVar(player, "repair.sui");
|
|
|
|
string prompt = buildRepairPrompt(player, idx);
|
|
|
|
setSUIProperty(pid, sui.LISTBOX_PROMPT, sui.PROP_TEXT, prompt);
|
|
flushSUIPage(pid);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
messageHandler handleRepairSuiSelect()
|
|
{
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id player = sui.getPlayerId(params);
|
|
|
|
if (!isIdValid(player) || !exists(player))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int btn = sui.getIntButtonPressed(params);
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
int pid = utils.getIntScriptVar(player, "repair.sui");
|
|
|
|
if (btn == sui.BP_REVERT)
|
|
{
|
|
confirmRepairAll(player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
if (btn == sui.BP_CANCEL)
|
|
{
|
|
closeOldRepairSui(player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id[] itemList = utils.getObjIdArrayScriptVar(player, "repair.itemList");
|
|
int[] costList = utils.getIntArrayScriptVar(player, "repair.costList");
|
|
|
|
obj_id[] repairList = new obj_id[1];
|
|
repairList[0] = itemList[idx];
|
|
utils.setScriptVar(player, "repair.repairList", repairList);
|
|
|
|
cloninglib.payRepairFee(player, self, costList[idx]);
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
string buildRepairEntry(obj_id item, int cost)
|
|
{
|
|
string entry = getEncodedName(item);
|
|
entry += " \\%070( @terminal_ui:repair_prompt_cost "+cost+")";
|
|
|
|
return entry;
|
|
}
|
|
|
|
string buildRepairPrompt(obj_id player, int index)
|
|
{
|
|
int totalCost = utils.getIntScriptVar(player, "repair.totalCost");
|
|
|
|
string prompt = "@terminal_ui:repair_prompt_header "+totalCost+"\\#.";
|
|
|
|
if (index > -1)
|
|
{
|
|
obj_id[] repairList = utils.getObjIdArrayScriptVar(player, "repair.itemList");
|
|
int[] costList = utils.getIntArrayScriptVar(player, "repair.costList");
|
|
|
|
obj_id item = repairList[index];
|
|
int curHp = getHitpoints(item);
|
|
int maxHp = getMaxHitpoints(item);
|
|
|
|
prompt += "\n\n@terminal_ui:repair_prompt_item "+getEncodedName(item);
|
|
prompt += "\n@terminal_ui:repair_prompt_damage "+(maxHp-curHp)+" ("+curHp+"/"+maxHp+")";
|
|
prompt += "\n@terminal_ui:repair_prompt_cost \\#pcontrast1 "+costList[index]+"\\#.";
|
|
}
|
|
|
|
return prompt;
|
|
}
|
|
|
|
void closeOldRepairSui(obj_id player)
|
|
{
|
|
if (utils.hasScriptVar(player, "repair.sui"))
|
|
{
|
|
int pid = utils.getIntScriptVar(player, "repair.sui");
|
|
sui.closeSUI(player, pid);
|
|
}
|
|
|
|
utils.removeScriptVarTree(player, "repair");
|
|
}
|
|
|
|
messageHandler handlePayRepairSuccess()
|
|
{
|
|
obj_id player = params.getObjId(money.DICT_PLAYER_ID);
|
|
|
|
if (!isIdValid(player) || !exists(player))
|
|
{
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
obj_id[] repairList = utils.getObjIdArrayScriptVar(player, "repair.repairList");
|
|
|
|
dictionary data = new dictionary();
|
|
data.put("items", repairList);
|
|
messageTo(player, "handleRepairItems", data, 0f, true);
|
|
|
|
closeOldRepairSui(player);
|
|
|
|
obj_id[] itemList = cloninglib.getAllRepairItems(player);
|
|
|
|
if (itemList != null && itemList.length > 0)
|
|
{
|
|
openRepairSui(player);
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
} |