mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-28 22:15:54 -04:00
528 lines
17 KiB
Plaintext
528 lines
17 KiB
Plaintext
/**
|
|
* Copyright (c)2005 Sony Online Entertainment Inc.
|
|
* All Rights Reserved
|
|
*
|
|
* Title: qawearables.script
|
|
* Description: script to dynamically spawn all clothing based on a datatable
|
|
* @author Jeff W. Haskell
|
|
* @version $Revision:2$
|
|
*/
|
|
|
|
include library.sui;
|
|
include library.utils;
|
|
include java.util.Arrays;
|
|
include java.util.Vector;
|
|
include java.util.HashSet;
|
|
include java.util.StringTokenizer;
|
|
include library.qa;
|
|
|
|
/**** CONSTANTS ******************************************************/
|
|
|
|
const string DATATABLE_LOCATION = "datatables/test/qa_wearables.iff";
|
|
|
|
/**** FUNCTIONS ******************************************************/
|
|
/*********************************************************************/
|
|
/*********************************************************************/
|
|
/*********************************************************************/
|
|
/*********************************************************************/
|
|
|
|
String[] populateArray(obj_id player, string datatableName, string choice, string column1, string column2, boolean filtered, boolean allFunction)
|
|
{
|
|
|
|
//boolean #2 is the switch to add the "all items displayed" option to spawn all of the wearables
|
|
|
|
|
|
String[] errorZeroLengthArray = {"The Array was empty, could be that you passed the wrong type"};
|
|
string[] firstColumnArray = dataTableGetStringColumn(datatableName,column1);
|
|
string[] secondColumnArray = dataTableGetStringColumn(datatableName,column2);
|
|
|
|
int listingLength = firstColumnArray.length;
|
|
Vector rowNumVector = new Vector();
|
|
Vector wearablesListVector = new Vector();
|
|
int listCounter = 0;
|
|
|
|
if (listingLength == 0)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Tool Not Functioning because the Datatable Rows equal ZERO!");
|
|
Thread.dumpStack();
|
|
return errorZeroLengthArray;
|
|
}
|
|
else
|
|
{
|
|
for (int y = 0; y < listingLength; y++)
|
|
{
|
|
if (firstColumnArray[y] == choice)
|
|
{
|
|
// string intVar = ""+y;
|
|
rowNumVector.addElement(new Integer(y));
|
|
listCounter++;
|
|
}
|
|
}
|
|
}
|
|
Integer[] rowNumArray = (Integer[]) rowNumVector.toArray(new Integer[listCounter]);
|
|
int arrayLength = rowNumArray.length;
|
|
|
|
if (!filtered)
|
|
{
|
|
string previousString = secondColumnArray[ rowNumArray[0].intValue() ];
|
|
wearablesListVector.addElement( previousString );
|
|
for (int i = 0; i < arrayLength; i++)
|
|
{
|
|
if (secondColumnArray[ rowNumArray[i].intValue() ] != previousString)
|
|
{
|
|
wearablesListVector.addElement( secondColumnArray[ rowNumArray[i].intValue() ] );
|
|
previousString = secondColumnArray[ rowNumArray[i].intValue() ];
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (int i = 0; i < arrayLength; i++)
|
|
{
|
|
wearablesListVector.addElement( secondColumnArray[ rowNumArray[i].intValue() ]+" Ref.# "+rowNumArray[i] );
|
|
}
|
|
|
|
if (!allFunction)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
wearablesListVector.addElement("All Items Displayed");
|
|
}
|
|
}
|
|
String[] wearablesArray = (String[]) wearablesListVector.toArray(new String[wearablesListVector.size()]);
|
|
return wearablesArray;
|
|
}
|
|
|
|
String[] populateArray(obj_id player, string datatableName, string column)
|
|
{
|
|
String[] errorZeroLengthArray = {"The Array was empty, could be that you passed the wrong type"};
|
|
string[] columnArray = dataTableGetStringColumn(datatableName,column);
|
|
|
|
int listingLength = columnArray.length;
|
|
|
|
if (listingLength == 0)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Tool Not Functioning because the Datatable Rows equal ZERO!");
|
|
return errorZeroLengthArray;
|
|
}
|
|
else
|
|
{
|
|
|
|
HashSet theSet = new HashSet();
|
|
for (int y = 0; y < listingLength; y++)
|
|
{
|
|
theSet.add(columnArray[y]);
|
|
}
|
|
string[] menuArray = new string[theSet.size()];
|
|
theSet.toArray(menuArray);
|
|
Arrays.sort(menuArray);
|
|
return menuArray;
|
|
}
|
|
}
|
|
|
|
void constructSUI(obj_id player, string prompt, string title, string[] menuArray, string nextHandler, string scriptVarName, boolean backButton)
|
|
{
|
|
if (!backButton)
|
|
{
|
|
int pid = sui.listbox(player, player, prompt, sui.OK_CANCEL, title, menuArray, nextHandler, true, false);
|
|
setWindowPid(player, pid);
|
|
utils.setScriptVar( player, scriptVarName, menuArray );
|
|
}
|
|
else
|
|
{
|
|
int pid = sui.listbox(player, player, prompt, sui.OK_CANCEL_REFRESH, title, menuArray, nextHandler, false, false);
|
|
sui.listboxUseOtherButton(pid, "Back");
|
|
sui.showSUIPage(pid);
|
|
setWindowPid(player, pid);
|
|
utils.setScriptVar( player, scriptVarName, menuArray );
|
|
}
|
|
}
|
|
|
|
/***** TRIGGERS *******************************************************/
|
|
trigger OnAttach()
|
|
{
|
|
if (isGod(self))
|
|
{
|
|
if(getGodLevel(self) < 10)
|
|
{
|
|
detachScript(self, "test.qawearables");
|
|
sendSystemMessage(self, "You do not have the appropriate access level to use this script.", null);
|
|
}
|
|
}
|
|
else if (!isGod(self))
|
|
{
|
|
detachScript(self, "test.qawearables");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** 1st MENU - DISPLAY SPECIES DATA IN SUI *******************************************************/
|
|
trigger OnSpeaking(string text)
|
|
{
|
|
obj_id player = self;
|
|
if(isGod(player))
|
|
{
|
|
if (toLower(text).equals("qawearables") )
|
|
{
|
|
String[] mainMenuArray = populateArray (player, DATATABLE_LOCATION, "wearable_specie");
|
|
if (mainMenuArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Species UI creation failed.");
|
|
}
|
|
else
|
|
{
|
|
constructSUI(player, "Choose the species", "Wearables Spawner", mainMenuArray, "wearableTypeOptionSelect", "qawearable.mainMenu", false);
|
|
}
|
|
return SCRIPT_OVERRIDE;
|
|
}
|
|
}
|
|
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** 2nd MENU - WEARABLE TYPE SUI *******************************************************/
|
|
messageHandler wearableTypeOptionSelect()
|
|
{
|
|
obj_id player = sui.getPlayerId(params);
|
|
|
|
if(isGod(player))
|
|
{
|
|
if ( utils.hasScriptVar( self, "qawearable.pid"))
|
|
{
|
|
string previousMainMenuArray[] = utils.getStringArrayScriptVar( self, "qawearable.mainMenu" );
|
|
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
sendSystemMessageTestingOnly(player,"Failing, params empty");
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
int btn = sui.getIntButtonPressed(params);
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
switch (btn)
|
|
{
|
|
case sui.BP_CANCEL:
|
|
//this means we are done, and we need to clean the scriptvars
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
closeOldWindow(player);
|
|
return SCRIPT_CONTINUE;
|
|
case sui.BP_REVERT:
|
|
//Go back to tool Mainmenu
|
|
string[] options = utils.getStringArrayScriptVar(player, "qatool.toolMainMenu");
|
|
string mainTitle = utils.getStringScriptVar(player, "qatool.title");
|
|
string mainPrompt = utils.getStringScriptVar(player, "qatool.prompt");
|
|
if(options == null)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "You didn't start from the main tool menu");
|
|
String[] mainMenuArray = populateArray (player, DATATABLE_LOCATION, "wearable_specie");
|
|
qa.refreshMenu(player, "Choose the species", "Wearables Spawner", mainMenuArray, "wearableTypeOptionSelect", true, "qawearable.pid");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
qa.refreshMenu( self, mainPrompt, mainTitle, options, "toolMainMenu", true, "qatool.pid");
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
case sui.BP_OK:
|
|
if (idx < 0 ) //this means you didnt have anything selected and the window disappeared
|
|
{
|
|
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
sendSystemMessageTestingOnly(player, "You didnt have anything selected");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
break;
|
|
|
|
|
|
}
|
|
string specieChoice = previousMainMenuArray[idx];
|
|
|
|
if (specieChoice == "")
|
|
{
|
|
sendSystemMessageTestingOnly(self, "The Script failed because the previous menu did not pass a string.");
|
|
}
|
|
else
|
|
{
|
|
//SET A SCRIPT VARIABLE NEEDED LATER FOR BACK BUTTON
|
|
utils.setScriptVar(player, "qawearable.specieChoiceVar", specieChoice);
|
|
//CALL A FUNCTION TO CREATE THE MENU
|
|
String[] wearablesArray = populateArray (player, DATATABLE_LOCATION, specieChoice, "wearable_specie", "wearable_type", false, false);
|
|
if (wearablesArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Wearables UI creation failed.");
|
|
}
|
|
else
|
|
{
|
|
//CALL A FUNCTION TO CREATE THE SUI
|
|
constructSUI(player, "Choose the wearable type", "Wearables Spawner", wearablesArray, "wearablesOptionSelect", "qawearable.wearablesMenu", true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Godmode needed for this command.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** 3rd MENU - WEARABLES ITEM SUI *******************************************************/
|
|
messageHandler wearablesOptionSelect()
|
|
{
|
|
obj_id player = sui.getPlayerId(params);
|
|
if(isGod(player))
|
|
{
|
|
if ( utils.hasScriptVar( self, "qawearable.pid"))
|
|
{
|
|
string previousWearablesArray[] = utils.getStringArrayScriptVar( self, "qawearable.wearablesMenu" );
|
|
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
sendSystemMessageTestingOnly(player,"Failing, params empty");
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
int btn = sui.getIntButtonPressed(params);
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
|
|
switch (btn)
|
|
{
|
|
case sui.BP_REVERT:
|
|
//CALL A FUNCTION TO CREATE THE MENU
|
|
String[] mainMenuArray = populateArray (player, DATATABLE_LOCATION, "wearable_specie");
|
|
if (mainMenuArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Specie UI creation failed.");
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
else
|
|
{
|
|
//CALL A FUNCTION TO CREATE THE SUI
|
|
qa.refreshMenu(player, "Choose the species", "Wearables Spawner", mainMenuArray, "wearableTypeOptionSelect", "qabadge.pid", sui.OK_CANCEL_REFRESH);
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
case sui.BP_OK:
|
|
if (idx < 0 ) //this means you didnt have anything selected and the window disappeared
|
|
{
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
sendSystemMessageTestingOnly(player, "You didnt have anything selected");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
break;
|
|
case sui.BP_CANCEL:
|
|
//this means we are done, and we need to clean the scriptvars
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
closeOldWindow(player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
string wearableChoice = previousWearablesArray[idx];
|
|
|
|
if (wearableChoice != "")
|
|
{
|
|
//CALL A FUNCTION TO CREATE THE MENU
|
|
String[] wearablesNameArray = populateArray (player, DATATABLE_LOCATION, wearableChoice, "wearable_type", "wearable_name", true, true);
|
|
if (wearablesNameArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Wearables Name UI creation failed.");
|
|
}
|
|
else
|
|
{
|
|
//CALL A FUNCTION TO CREATE THE SUI
|
|
constructSUI(player, "Choose the wearable item", "Wearables Spawner", wearablesNameArray, "wearablesTemplateSelect", "qawearable.spawnItem", true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Godmode needed for this command.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
/***** WEARABLES TEMPLATE SPAWNER *******************************************************/
|
|
messageHandler wearablesTemplateSelect()
|
|
{
|
|
obj_id player = sui.getPlayerId(params);
|
|
if(isGod(player))
|
|
{
|
|
if ( utils.hasScriptVar( self, "qawearable.pid"))
|
|
{
|
|
string previousWearablesNameArray[] = utils.getStringArrayScriptVar( self, "qawearable.spawnItem" );
|
|
|
|
if ( (params == null) || (params.isEmpty()) )
|
|
{
|
|
sendSystemMessageTestingOnly(player,"Failing, params empty");
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
obj_id pInv = utils.getInventoryContainer(player);
|
|
int btn = sui.getIntButtonPressed(params);
|
|
int idx = sui.getListboxSelectedRow(params);
|
|
|
|
switch (btn)
|
|
{
|
|
case sui.BP_REVERT:
|
|
//RETRIEVE OLD SPECIE CHOICE TO CREATE THE CORRECT PREVIOUS MENU
|
|
string specieChoice = utils.getStringScriptVar(player, "qawearable.specieChoiceVar");
|
|
//CALL A FUNCTION TO CREATE THE MENU
|
|
|
|
if (specieChoice != null)
|
|
{
|
|
String[] wearablesArray = populateArray (player, DATATABLE_LOCATION, specieChoice, "wearable_specie", "wearable_type", false, false);
|
|
if (wearablesArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Specie UI creation failed.");
|
|
}
|
|
else
|
|
{
|
|
constructSUI(player, "Choose the wearable type", "Wearables Spawner", wearablesArray, "wearablesOptionSelect", "qawearable.wearablesMenu", true);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
sendSystemMessageTestingOnly(player,"The previous specie selection could not be retrieved.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
//break;
|
|
case sui.BP_OK:
|
|
if (idx < 0 ) //this means you didnt have anything selected and the window disappeared
|
|
{
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
sendSystemMessageTestingOnly(player, "You didnt have anything selected");
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
break;
|
|
case sui.BP_CANCEL:
|
|
//this means we are done, and we need to clean the scriptvars
|
|
utils.removeScriptVarTree(player,"qawearable");
|
|
utils.removeScriptVarTree(player,"qatool");
|
|
closeOldWindow(player);
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
string wearableNameChoice = previousWearablesNameArray[idx];
|
|
string wearablesName = new string();
|
|
string indexNum = new string();
|
|
string refString = new string();
|
|
string templateData = new string();
|
|
|
|
//TAKE THE PREVIOUS MENU SELECTION AND
|
|
//PARSE THE STRING TO GET THE REFERENCE NUMBER AND USE IT AS AN INDEX TO FIND ONLY THE WEARABLE DESIRED
|
|
if(wearableNameChoice != "")
|
|
{
|
|
string[] wearable_name = dataTableGetStringColumn(DATATABLE_LOCATION, 2);
|
|
string[] wearable_template = dataTableGetStringColumn(DATATABLE_LOCATION, 3);
|
|
|
|
//DIVIDE UP THE STRING INTO TOKENS AND GET INDEX NUMBER
|
|
StringTokenizer stg = new StringTokenizer(wearableNameChoice);
|
|
wearablesName = stg.nextToken();
|
|
refString = stg.nextToken();
|
|
indexNum = stg.nextToken();
|
|
int listingLength = wearable_name.length;
|
|
|
|
//WHILE LOOP INSTEAD OF FOR LOOP TO STOP ONCE THE ITEM IS FOUND
|
|
int z = 0;
|
|
boolean haveFound = false;
|
|
boolean allSelected = false;
|
|
while ( haveFound == false )
|
|
{
|
|
if ( z < listingLength )
|
|
{
|
|
if ( z == utils.stringToInt( indexNum ) )
|
|
{
|
|
templateData = wearable_template[z];
|
|
haveFound = true;
|
|
}
|
|
z++;
|
|
}
|
|
else
|
|
{
|
|
//THE ALL ABOVE ITEMS WAS SELECTED
|
|
allSelected = true;
|
|
haveFound = true;
|
|
}
|
|
}
|
|
|
|
//ITEM SENT TO FUNCTION TO CHECK INVENTORY FULL AND TO SPAWN
|
|
if (templateData != "")
|
|
{
|
|
qa.templateObjectSpawner(player, templateData);
|
|
}
|
|
else if (allSelected == true)
|
|
{
|
|
for (int x = 0; x < ( previousWearablesNameArray.length - 1 ); x++)
|
|
{
|
|
StringTokenizer sto = new StringTokenizer(previousWearablesNameArray[x]);
|
|
wearablesName = sto.nextToken();
|
|
refString = sto.nextToken();
|
|
indexNum = sto.nextToken();
|
|
int theIndex = utils.stringToInt( indexNum );
|
|
qa.templateObjectSpawner(player, wearable_template[theIndex]);
|
|
}
|
|
}
|
|
//CREATE A MAIN MENU AGAIN
|
|
//CALL A FUNCTION TO CREATE THE MENU
|
|
String[] mainMenuArray = populateArray (player, DATATABLE_LOCATION, "wearable_specie");
|
|
|
|
if (mainMenuArray.length < 1)
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Specie UI creation failed.");
|
|
}
|
|
else
|
|
{
|
|
//CALL A FUNCTION TO CREATE THE SUI
|
|
qa.refreshMenu(player, "Choose the species", "Wearables Spawner", mainMenuArray, "wearableTypeOptionSelect", "qabadge.pid", sui.OK_CANCEL_REFRESH);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(player, "The script failed to pass the string from the previous menu." );
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
sendSystemMessageTestingOnly(player, "Godmode needed for this command.");
|
|
}
|
|
return SCRIPT_CONTINUE;
|
|
}
|
|
|
|
//******** Misc Functions **************************************
|
|
void cleanScriptVars(obj_id player)
|
|
{
|
|
obj_id self = getSelf();
|
|
utils.removeScriptVarTree(player, "qawearable");
|
|
utils.removeScriptVarTree(self, "qawearable");
|
|
setObjVar(player, "qawearable", true);
|
|
}
|
|
|
|
void closeOldWindow(obj_id player)
|
|
{
|
|
string playerPath = "qawearable.";
|
|
if ( utils.hasScriptVar(player, "qawearable.pid"))
|
|
{
|
|
int oldpid = utils.getIntScriptVar(player, "qawearable.pid");
|
|
forceCloseSUIPage (oldpid);
|
|
utils.removeScriptVar(player, "qawearable.pid");
|
|
}
|
|
}
|
|
|
|
void setWindowPid(obj_id player, int pid)
|
|
{
|
|
if (pid > -1) utils.setScriptVar(player, "qawearable.pid", pid);
|
|
} |