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

195 lines
6.1 KiB
Plaintext

//************************************************************/
// Copyright (c) ©2000,2001 Sony Online Entertainment Inc.
// All Rights Reserved
//
// Title: qacube.script
// Description: Testers can use this tool to test all items that are spawned by the Chu-Gon Dar Cube.
// When using this tool, the player will be:
// 1. Given a Chu-Gon Dar Cube
// 2. Given the ability to choose what item they wish to create
// 3. Given the components needed to create the selected item.
// @author $Author: James Michener $
// @version $1.0.1$
//************************************************************/
/********* Includes ******************************************/
include library.utils;
include library.qa;
include library.sui;
/********* CONSTANTS *****************************************/
const string SCRIPTVAR = "qa_cube";
const string CUBE_DATATABLE_1 = "datatables/item/loot_cube/republic_assembly_tool.iff";
const string CHU_GON_DAR_CUBE = "object/tangible/container/loot/som_cube.iff";
const string CHU_GON_DAR_TITLE = "Chu-Gon Dar Cube Tool";
const string CHU_GON_DAR_PROMPT = "This tool allows you to quickly obtain items needed to create the items listed below.\n**If you do not have a Cube, one will be created for you.**\n\nSelect an item to create.";
/********* Triggers ******************************************/
trigger OnAttach()
{
if(isGod(self))
{
if(getGodLevel(self) < 10)
{
detachScript(self, "test.qa_cube");
sendSystemMessage(self, "You do not have the appropriate access level to use this script.", null);
}
}
else if(!isGod(self))
{
detachScript(self, "test.qa_cube");
}
return SCRIPT_CONTINUE;
}
trigger OnSpeaking(string text)
{
if(isGod(self))
{
if(toLower(text).equals(SCRIPTVAR) || toLower(text).equals("qacube"))
{
getNamesArray(self);
ChuGonMainMenu(self);
return SCRIPT_OVERRIDE;
}
}
return SCRIPT_CONTINUE;
}
/***** MESSAGEHANDLERS *************************************************/
messageHandler handleChuGonOptions()
{
if(isGod(self))
{
obj_id player = sui.getPlayerId(params);
int btn = sui.getIntButtonPressed(params);
if(btn == sui.BP_CANCEL)
{
qa.removePlayer(player, SCRIPTVAR, "");
return SCRIPT_CONTINUE;
}
if(btn == sui.BP_REVERT)
{
qa.qaToolMainMenu(player);
utils.removeScriptVarTree(player, SCRIPTVAR);
return SCRIPT_CONTINUE;
}
int idx = sui.getListboxSelectedRow(params);
if(idx < 0)
{
qa.removePlayer(player, SCRIPTVAR, "");
return SCRIPT_CONTINUE;
}
//retrieve the item list scriptVar
string[] itemList = utils.getStringArrayScriptVar(player, SCRIPTVAR+".codeStringArray");
//get the item to spawn by referencing the index #
string itemToSpawnFor = itemList[idx];
spawnBaseItems(player, itemToSpawnFor, idx);
}
return SCRIPT_CONTINUE;
}
/***** FUNCTIONS *******************************************************/
//BUILDS THE MAIN TOOL MENU
void ChuGonMainMenu(obj_id player)
{
if(utils.hasScriptVar(player, SCRIPTVAR+".codeStringArray") && utils.hasScriptVar(player, SCRIPTVAR+".showNamesArray"))
{
string[] showNamesArray = utils.getStringArrayScriptVar(player, SCRIPTVAR+".showNamesArray");
qa.refreshMenu(player, CHU_GON_DAR_PROMPT, CHU_GON_DAR_TITLE, showNamesArray, "handleChuGonOptions", SCRIPTVAR+".pid", SCRIPTVAR+".ChuGonMainMenu", sui.OK_CANCEL_REFRESH);
}
else
{
sendSystemMessageTestingOnly(player, "An error has occurred, please try again.");
}
}
void getNamesArray(obj_id player)
{
string[] codeStringArray = dataTableGetStringColumn(CUBE_DATATABLE_1, "finalTemplate");
string[] showNamesArray = new string[codeStringArray.length];
for(int i = 0; i < codeStringArray.length; i++)
{
if(codeStringArray[i].endsWith(".iff"))
{
//Get the indexOf the last "/"
int idxSlash = codeStringArray[i].lastIndexOf("/") + 1;
//Get the index of the last "."
int idxPeriod = codeStringArray[i].lastIndexOf(".");
//Place our findings in the string "lookup"
string lookUp = codeStringArray[i].substring(idxSlash, idxPeriod) + "_n";
//sendSystemMessageTestingOnly(player, lookUp);
showNamesArray[i] = localize(new string_id("som/som_item", lookUp));
}
else
{
showNamesArray[i] = localize(new string_id("static_item_n", codeStringArray[i]));
}
showNamesArray[i] = showNamesArray[i] + ": (" + codeStringArray[i] + ")";
}
utils.setScriptVar(player, SCRIPTVAR+".codeStringArray", codeStringArray);
utils.setScriptVar(player, SCRIPTVAR+".showNamesArray", showNamesArray);
}
void checkForCube(obj_id player)
{
//insure the inventory can hold the droid
checkInventory(player);
boolean hasCube = false;
//get all items in the player's inventory
obj_id[] invAndEquip = getInventoryAndEquipment(player);
for(int i = 0; i < invAndEquip.length; i++)
{
string templateName = getTemplateName(invAndEquip[i]);
//check each template name for the Chu-Gon Dar Cube.
if(templateName == "object/tangible/container/loot/som_cube.iff")
{
hasCube = true;
}
}
//if tester does not have a cube, create one.
if(hasCube == false)
{
obj_id myCube = createObjectInInventoryAllowOverload("object/tangible/container/loot/som_cube.iff", player);
}
}
void spawnBaseItems(obj_id player, string itemToSpawnFor, int idx)
{
checkForCube(player);
//get tester's inventory
obj_id inventory = utils.getInventoryContainer(player);
for(int i = 0; i < 3; i++)
{
string subComponent = dataTableGetString(CUBE_DATATABLE_1, idx, i);
//create the items in the tester's inventory
obj_id newObj = createObject(subComponent, inventory, "");
}
sendSystemMessageTestingOnly(player, "The components have been successfully created in your inventory.");
qa.removePlayer(player, SCRIPTVAR, "");
}
void checkInventory(obj_id player)
{
// get player inventory
obj_id inventory = utils.getInventoryContainer(player);
// get array of items in player inventory
obj_id[] invItems = getContents(inventory);
// test for room in backpack
if(invItems.length > 75)
{
// system message: no room in inventory
sendSystemMessageTestingOnly(player, "Please delete some items from your Inventory and try again.");
}
}