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

979 lines
32 KiB
Plaintext

//------------------------------------------------
// Includes
//------------------------------------------------
include library.chat;
include library.create;
include library.force_rank;
include library.fs_quests;
include library.group;
include library.jedi;
include library.prose;
include library.sui;
include library.utils;
include library.xp;
//------------------------------------------------
// Constants
//------------------------------------------------
const string PADAWAN_TRIALS_DATATABLE = "datatables/jedi_trials/padawan_trials.iff";
const string KNIGHT_TRIALS_DATATABLE = "datatables/jedi_trials/knight_trials.iff";
const string FORCE_SHRINES_DATATABLE = "datatables/jedi_trials/force_shrine_loc.iff";
const string PADAWAN_TRIALS_SCRIPT = "theme_park.jedi_trials.padawan_trials";
const string KNIGHT_TRIALS_SCRIPT = "theme_park.jedi_trials.knight_trials";
// objvars
const string PADAWAN_TRIALS_ELIGIBLE_OBJVAR = "padawan_trials.padawanEligible";
const string JEDI_TRIALS_BASE_OBJVAR = "jedi_trials";
const string PADAWAN_TRIALS_BASE_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".padawan_trials";
const string PADAWAN_QUESTLIST_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".questList";
const string PADAWAN_TRIALS_TEMP_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp";
const string PADAWAN_TARGET_PLANET_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.targetPlanet";
const string PADAWAN_TARGET_CITY_ROW_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.targetCityRow";
const string PADAWAN_TARGET_LOC_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.targetLoc";
const string PADAWAN_SECOND_LOC_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.secondLoc";
const string PADAWAN_THIRD_LOC_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.thirdLoc";
const string SECOND_LOC_OBJECT_OBJID_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.secondLocObject";
const string THIRD_LOC_OBJECT_OBJID_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.thirdLocObject";
const string PADAWAN_TRIAL_PLAYER_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.trialPlayer";
const string PADAWAN_TRIAL_NPC_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.trialNpc";
const string PADAWAN_WAYPOINT_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.waypoint";
const string PADAWAN_SABER_CRAFTED_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".temp.lightsaberCrafted";
const string PADAWAN_SHRINE_WAYPOINT_OBJVAR = PADAWAN_TRIALS_BASE_OBJVAR + ".shrineWaypoint";
const string KNIGHT_TRIALS_BASE_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".knight_trials";
const string KNIGHT_QUESTLIST_OBJVAR = KNIGHT_TRIALS_BASE_OBJVAR + ".questList";
const string KNIGHT_COUNCIL_CHOICE_OBJVAR = KNIGHT_TRIALS_BASE_OBJVAR + ".councilChoice";
const string JEDI_TRIALS_TRIALNUMBER_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".trialNumber";
const string JEDI_TRIALS_INELIGIBLE_WARNING_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".ineligibleWarning";
const string JEDI_TRIALS_TRIALS_FAILED_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".trialsFailed";
const string JEDI_TRIALS_CUR_TRIAL_TOTAL_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".currentTrialTotal";
const string JEDI_TRIALS_SHRINELOC_OBJVAR = JEDI_TRIALS_BASE_OBJVAR + ".forceShrineLoc";
// string_ids
// Padawan Trials
const string_id SID_PADAWAN_TRIALS_TITLE = new string_id("jedi_trials", "padawan_trials_title");
const string_id SID_PADAWAN_INTRO_MSG = new string_id("jedi_trials", "padawan_trials_intro_msg");
const string_id SID_PADAWAN_START_TRIALS_Q = new string_id("jedi_trials", "padawan_trials_start_query");
const string_id SID_PADAWAN_NEXT_TRIAL = new string_id("jedi_trials", "padawan_trials_next_trial");
const string_id SID_PADAWAN_TELL_ABOUT_RESTART = new string_id("jedi_trials", "padawan_trials_tell_about_restart");
const string_id SID_PADAWAN_TRIAL_FAILED_FIRST = new string_id("jedi_trials", "padawan_trials_trial_failed_first");
const string_id SID_PADAWAN_TRIAL_FAILED_SECOND = new string_id("jedi_trials", "padawan_trials_trial_failed_second");
const string_id SID_PADAWAN_TRIAL_FAILED_FINAL = new string_id("jedi_trials", "padawan_trials_trial_failed_final");
const string_id SID_PADAWAN_TRIALS_COMPLETED = new string_id("jedi_trials", "padawan_trials_completed");
const string_id SID_PADAWAN_RETURN_TO_NPC = new string_id("jedi_trials", "padawan_trials_return_to_npc");
const string_id SID_PADAWAN_RECEIVED_THE_RING = new string_id("jedi_trials", "padawan_trials_received_the_ring");
const string_id SID_PADAWAN_TRIALS_PROGRESS = new string_id("jedi_trials", "padawan_trials_progress");
const string_id SID_PADAWAN_TRIALS_NO_LONGER_ELIGIBLE = new string_id("jedi_trials", "padawan_trials_no_longer_eligible");
const string_id SID_PADAWAN_TRIALS_STARTED_NOT_ELIGIBLE = new string_id("jedi_trials", "padawan_trials_started_not_eligible");
const string_id SID_PADAWAN_TRIALS_BEING_REMOVED = new string_id("jedi_trials", "padawan_trials_being_removed");
const string_id SID_PADAWAN_TRIALS_BEING_REMOVED_REVOKED = new string_id("jedi_trials", "padawan_trials_being_removed_revoked");
const string_id SID_PADAWAN_TRIALS_ABORTED = new string_id("jedi_trials", "padawan_trials_aborted");
const string_id SID_PADAWAN_TRIAL_RESTARTED = new string_id("jedi_trials", "padawan_trials_trial_restarted");
const string_id SID_PADAWAN_ABORTED_CONFIRMATION = new string_id("jedi_trials", "padawan_trials_abort_confirmation");
const string_id SID_PADAWAN_RESTART_CONFIRMATION = new string_id("jedi_trials", "padawan_trials_restart_confirmation");
// Knight Trials
const string_id SID_KNIGHT_EMPTY = new string_id("jedi_trials", "empty");
const string_id SID_FROM_UNKOWN = new string_id("jedi_trials", "from_unknown");
const string_id SID_KNIGHT_INTRO_MSG = new string_id("jedi_trials", "knight_trials_intro_msg");
const string_id SID_KNIGHT_INTRO_MSG_END = new string_id("jedi_trials", "knight_trials_intro_msg_end");
const string_id SID_KNIGHT_START_TRIALS_Q = new string_id("jedi_trials", "knight_trials_start_query");
const string_id SID_KNIGHT_TRIALS_TITLE = new string_id("jedi_trials", "knight_trials_title");
const string_id SID_KNIGHT_CURRENT_TRIAL_COMPLETE = new string_id("jedi_trials", "knight_trials_current_trial_complete");
const string_id SID_KNIGHT_NEXT_TRIAL_TITLE = new string_id("jedi_trials", "knight_trials_next_trial_title");
const string_id SID_KNIGHT_NEXT_TRIAL_MSG = new string_id("jedi_trials", "knight_trials_next_trial_msg");
const string_id SID_KNIGHT_NEXT_TRIAL_MSG_END = new string_id("jedi_trials", "knight_trials_next_trial_msg_end");
const string_id SID_KNIGHT_TRIALS_PROGRESS = new string_id("jedi_trials", "knight_trials_progress");
const string_id SID_KNIGHT_TRIALS_NO_LONGER_ELIGIBLE = new string_id("jedi_trials", "knight_trials_no_longer_eligible");
const string_id SID_KNIGHT_TRIALS_BEING_REMOVED = new string_id("jedi_trials", "knight_trials_being_removed");
const string_id SID_KNIGHT_TRIALS_COMPLETED_LIGHT = new string_id("jedi_trials", "knight_trials_completed_light");
const string_id SID_KNIGHT_TRIALS_COMPLETED_DARK = new string_id("jedi_trials", "knight_trials_completed_dark");
const string_id SID_FORCE_SHRINE_WRONG = new string_id("jedi_trials", "knight_shrine_wrong");
const string_id SID_FORCE_SHRINE_REMIND = new string_id("jedi_trials", "knight_shrine_reminder");
const string_id SID_FORCE_SHRINE_TITLE = new string_id("jedi_trials", "force_shrine_title");
const string_id SID_COUNCIL_CHOICE_MSG = new string_id ("jedi_trials", "council_choice_msg");
const string_id SID_LIGHT_SIDE_CHOSEN = new string_id ("jedi_trials", "council_chosen_light");
const string_id SID_DARK_SIDE_CHOSEN = new string_id ("jedi_trials", "council_chosen_dark");
const string_id SID_DELAYED_COUNCIL_CHOICE = new string_id ("jedi_trials", "council_choice_delayed");
const string_id SID_FACTION_WRONG_CHOICE_LIGHT = new string_id ("jedi_trials", "faction_wrong_choice_light");
const string_id SID_FACTION_WRONG_CHOICE_DARK = new string_id ("jedi_trials", "faction_wrong_choice_dark");
const string_id SID_FACTION_WRONG_LIGHT = new string_id ("jedi_trials", "faction_wrong_light");
const string_id SID_FACTION_WRONG_DARK = new string_id ("jedi_trials", "faction_wrong_dark");
const string_id SID_OK_BUTTON = new string_id ("jedi_trials", "button_okay");
const string_id SID_CLOSE_BUTTON = new string_id ("jedi_trials", "button_close");
const string_id SID_NEXT_PAGE_BUTTON = new string_id ("jedi_trials", "button_next_page");
const string_id SID_CANCEL_BUTTON = new string_id ("jedi_trials", "button_cancel");
const string_id SID_YES_BUTTON = new string_id ("jedi_trials", "button_yes");
const string_id SID_NO_BUTTON = new string_id ("jedi_trials", "button_no");
const string_id SID_LIGHTSIDE_BUTTON = new string_id ("jedi_trials", "button_lightside");
const string_id SID_DARKSIDE_BUTTON = new string_id ("jedi_trials", "button_darkside");
const string_id SID_RESTART_BUTTON = new string_id ("jedi_trials", "button_restart");
const string_id SID_ABORT_BUTTON = new string_id ("jedi_trials", "button_abort_padawan");
// other
const int PADAWAN_TRIALS_TREES_REQ = 6;
const int KNIGHT_TRIALS_PTS_SPENT_REQ = 206;
const int KNIGHT_TRIALS_TREES_REQ = 2;
const string SUI_STARTING_SIZE = "500,250";
const string PADAWAN_INITIATE_SKBOX = "force_title_jedi_rank_01";
const string JEDI_PADAWAN_SKBOX = "force_title_jedi_rank_02";
const string JEDI_KNIGHT_SKBOX = "force_title_jedi_rank_03";
const string PADAWAN_ROBE_STRING = "item_jedi_robe_padawan_04_01";
const string PADAWAN_TRIALS_LOG = "PADAWAN_TRIALS_LOG";
const string KNIGHT_TRIALS_LOG = "KNIGHT_TRIALS_LOG";
//------------------------------------------------
// Functions
//------------------------------------------------
// ***** Padawan trials
boolean isEligibleForJediPadawanTrials(obj_id player)
{
if ( isIdValid(player) )
{
// testing override
if ( hasObjVar(player, "overridePTEligibility") )
{
if ( isGod(player) )
{
return true;
}
}
if ( !hasSkill(player, JEDI_PADAWAN_SKBOX) )
{
int numFSBranchesComplete = fs_quests.getBranchesLearned(player);
if ( numFSBranchesComplete >= 6 && hasObjVar(player, PADAWAN_TRIALS_ELIGIBLE_OBJVAR) )
{
return true;
}
}
}
return false;
}
void initializePadawanTrials(obj_id player)
{
setObjVar(player, PADAWAN_TRIALS_ELIGIBLE_OBJVAR, true);
if ( !hasScript(player, PADAWAN_TRIALS_SCRIPT) )
{
attachScript(player, PADAWAN_TRIALS_SCRIPT);
}
else
{
messageTo(player, "handleDoPadawanTrialsSetup", null, 2, false);
}
return;
}
void doPadawanTrialsSetup(obj_id player)
{
if ( isIdValid(player) )
{
if ( hasObjVar(player, JEDI_TRIALS_BASE_OBJVAR) )
{
removeObjVar(player, JEDI_TRIALS_BASE_OBJVAR);
}
int[] questList = getQuestOrderFromDatatable(PADAWAN_TRIALS_DATATABLE);
if ( questList != null && questList.length > 0 )
{
setClosestForceShrineWaypoint(player);
setObjVar(player, PADAWAN_QUESTLIST_OBJVAR, questList);
setObjVar(player, JEDI_TRIALS_TRIALNUMBER_OBJVAR, 0);
string str_message = utils.packStringId(SID_PADAWAN_INTRO_MSG);
oneButtonMsgBox(player, player, "noHandler", SID_PADAWAN_TRIALS_TITLE, str_message, SID_CLOSE_BUTTON);
string custLogMsg = "Padawan trials (library.jedi_trials): Player %TU has begun the Jedi Padawan trials.";
CustomerServiceLog(PADAWAN_TRIALS_LOG, custLogMsg, player);
string questListSting = getJediTrialsQuestListAsString(player, questList);
string custQuestListLogMsg = "Padawan trials quest list: Padawan trials quest list for Player %TU is: " + questListSting + ".";
CustomerServiceLog(PADAWAN_TRIALS_LOG, custQuestListLogMsg, player);
}
else
{
string custLogMsg = "Padawan trials (library.jedi_trials): FATAL - failed to generate questList - initialization aborted.";
CustomerServiceLog(PADAWAN_TRIALS_LOG, custLogMsg, player);
}
}
return;
}
// ***** Knight trials
boolean isEligibleForJediKnightTrials(obj_id player)
{
string frsConfig = getConfigSetting("GameServer", "enableFRS");
if(frsConfig == null || frsConfig.length() < 1)
{
return false;
}
string darkRankSkill = force_rank.getForceRankSkill(0, force_rank.DARK_COUNCIL);
string lightRankSkill = force_rank.getForceRankSkill(0, force_rank.LIGHT_COUNCIL);
if ( darkRankSkill != null && lightRankSkill != null )
{
if ( !hasSkill(player, darkRankSkill) && !hasSkill(player, lightRankSkill) )
{
return (isEligibleForJediKnightTrialsPointsRemaining(player) >= 0);
}
}
return false;
}
int isEligibleForJediKnightTrialsPointsRemaining(obj_id player)
{
if ( isIdValid(player) )
{
string[] skillList = getSkillListingForPlayer( player );
int jediSkillPtsSpent = 0;
int jediDisciplineSkillTrees = 0;
for ( int j = 0; j < skillList.length; j++ )
{
string skillName = skillList[j];
if ( skillName.startsWith("force_discipline") )
{
// DISABLED
int cost = 0; //getSkillPointCost(skillName);
jediSkillPtsSpent = jediSkillPtsSpent + cost;
if ( skillName.endsWith("_04") )
{
jediDisciplineSkillTrees = jediDisciplineSkillTrees + 1;
}
}
}
//sendSystemMessage(player, "jedi_trials.isEligibleForJediKnightTrials: Points spent on force disciplines: " + jediSkillPtsSpent, "");
//sendSystemMessage(player, "jedi_trials.isEligibleForJediKnightTrials: Number of force disciplines lines complete: " + jediDisciplineSkillTrees, "");
if ( jediSkillPtsSpent >= KNIGHT_TRIALS_PTS_SPENT_REQ && jediDisciplineSkillTrees >= KNIGHT_TRIALS_TREES_REQ )
{
return (jediSkillPtsSpent - KNIGHT_TRIALS_PTS_SPENT_REQ);
}
}
return -1;
}
void initializeKnightTrials(obj_id player)
{
int[] questList = getQuestOrderFromDatatable(KNIGHT_TRIALS_DATATABLE);
if ( questList != null && questList.length > 0 )
{
location forceShrineLoc = getRandomForceShrineLocation(player);
setObjVar(player, KNIGHT_QUESTLIST_OBJVAR, questList);
setObjVar(player, JEDI_TRIALS_TRIALNUMBER_OBJVAR, 0);
setObjVar(player, JEDI_TRIALS_SHRINELOC_OBJVAR, forceShrineLoc);
string str_msgFirstPart = utils.packStringId(SID_KNIGHT_INTRO_MSG);
string str_msgSecondPart = utils.packStringId(new string_id("jedi_trials", forceShrineLoc.area));
string str_msgThirdPart = utils.packStringId(SID_KNIGHT_INTRO_MSG_END);
string str_message = str_msgFirstPart + " " + str_msgSecondPart + " " + str_msgThirdPart;
oneButtonMsgBox(player, player, "noHandler", SID_KNIGHT_TRIALS_TITLE, str_message, SID_CLOSE_BUTTON);
string custLogMsg = "Knight trials initialization (library.jedi_trials): Player %TU has begun the Jedi Knight trials.";
CustomerServiceLog(KNIGHT_TRIALS_LOG, custLogMsg, player);
}
else
{
string custLogMsg = "Knight trials initialization (library.jedi_trials): FATAL - failed to generate questList - initialization aborted.";
CustomerServiceLog(KNIGHT_TRIALS_LOG, custLogMsg, player);
}
return;
}
// ***** General
void doJediTrialsCleanup(obj_id player)
{
removeObjVar(player, JEDI_TRIALS_BASE_OBJVAR);
if ( hasObjVar(player, "handlePlayerCombatKill") )
{
removeObjVar(player, "handlePlayerCombatKill");
}
if ( hasScript( player, PADAWAN_TRIALS_SCRIPT) )
{
detachScript(player, PADAWAN_TRIALS_SCRIPT);
}
else if ( hasScript( player, KNIGHT_TRIALS_SCRIPT) )
{
detachScript(player, KNIGHT_TRIALS_SCRIPT);
}
return;
}
int getJediTrialRow (obj_id player)
{
int[] questList = getIntArrayObjVar(player, PADAWAN_QUESTLIST_OBJVAR);
if ( questList == null || questList.length < 1 )
{
return -1;
}
int trialNum = getIntObjVar(player, JEDI_TRIALS_TRIALNUMBER_OBJVAR);
int datatableRow = questList[trialNum];
return datatableRow;
}
string getJediTrialName(obj_id player)
{
int trialRow = getJediTrialRow (player);
if ( trialRow < 0 )
{
return null;
}
string trialName = dataTableGetString(PADAWAN_TRIALS_DATATABLE, trialRow, "trialName");
return trialName;
}
location getRandomForceShrineLocation(obj_id player)
{
string shrinePlanet = chooseRandomPlanet(player);
location shrineLoc = chooseForceShrineOnPlanet(shrinePlanet);
return shrineLoc;
}
// Chooses a random planet other than the one the player is currently on.
string chooseRandomPlanet(obj_id player)
{
string planet = "";
string[] allPlanets = {"rori", "talus","tatooine", "naboo", "corellia", "yavin4", "dathomir", "dantooine", "endor", "lok"};
location playerLoc = getLocation(player);
if ( playerLoc != null )
{
string playerPlanet = playerLoc.area;
while( planet.equals("") )
{
int foo = rand(0, (allPlanets.length-1));
string randomPlanet = allPlanets[foo];
if ( !randomPlanet.equals(playerPlanet) )
{
planet = randomPlanet;
}
}
}
return planet;
}
// Chooses a random settled or civilized planet other than the one the player is currently on.
string chooseRandomCivilizedPlanet(obj_id player)
{
string planet = "";
string[] allPlanets = {"rori", "talus", "tatooine", "naboo", "corellia"};
location playerLoc = getLocation(player);
if ( playerLoc != null )
{
string playerPlanet = playerLoc.area;
while( planet.equals("") )
{
int foo = rand(0, (allPlanets.length-1));
string randomPlanet = allPlanets[foo];
if ( !randomPlanet.equals(playerPlanet) )
{
planet = randomPlanet;
}
}
}
return planet;
}
// Chooses a random adventure or advanced planet other than the one the player is currently on.
string chooseRandomAdventurePlanet(obj_id player)
{
string planet = "";
string[] allPlanets = {"yavin4", "dathomir", "dantooine", "endor", "lok"};
location playerLoc = getLocation(player);
if ( playerLoc != null )
{
string playerPlanet = playerLoc.area;
while( planet.equals("") )
{
int foo = rand(0, (allPlanets.length-1));
string randomPlanet = allPlanets[foo];
if ( !randomPlanet.equals(playerPlanet) )
{
planet = randomPlanet;
}
}
}
return planet;
}
void setClosestForceShrineWaypoint(obj_id player)
{
if ( hasObjVar(player, PADAWAN_SHRINE_WAYPOINT_OBJVAR) )
{
obj_id oldWaypoint = getObjIdObjVar(player, PADAWAN_SHRINE_WAYPOINT_OBJVAR);
removeObjVar(player, PADAWAN_SHRINE_WAYPOINT_OBJVAR);
if ( isIdValid(oldWaypoint) )
{
destroyWaypointInDatapad(oldWaypoint, player);
}
}
location closestShrineLoc = getclosetForceShrineLocation(player);
location here = getLocation(player);
if ( utils.getDistance2D(closestShrineLoc, here) > 20 )
{
obj_id waypoint = createWaypointInDatapad(player, closestShrineLoc);
string_id sid_planet = new string_id("jedi_trials", here.area);
string str_planet = getString(sid_planet);
string waypointName = str_planet + " " + " Force Shrine";
setWaypointName(waypoint, waypointName);
setWaypointActive(waypoint, true);
setObjVar(player, PADAWAN_SHRINE_WAYPOINT_OBJVAR, waypoint);
}
return;
}
location getclosetForceShrineLocation(obj_id player)
{
location here = getLocation(player);
string planet = here.area;
location shrineLoc = null;
int index = getPlanetForceShrineDatatableIndex(planet);
if ( index != -1 )
{
int numShrines = dataTableGetInt(FORCE_SHRINES_DATATABLE, index, "numShrines");
float closestDistance = 99999;
for ( int i = 1; i <= numShrines; i++ )
{
int shrinedex = index + i;
float locX = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locX");
float locY = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locY");
float locZ = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locZ");
location tempShrineLoc = new location(locX, locY, locZ, planet, null);
float shrineDistance = utils.getDistance2D(tempShrineLoc, here);
if ( shrineDistance < closestDistance )
{
closestDistance = shrineDistance;
shrineLoc = tempShrineLoc;
}
}
}
return shrineLoc;
}
location chooseForceShrineOnPlanet(string planet)
{
// default set to force shrine location on dathomir
location shrineLoc = new location(3087.47f, 124.22f, 4887.14f, "dathomir", null);
int index = getPlanetForceShrineDatatableIndex(planet);
if ( index != -1 )
{
int numShrines = dataTableGetInt(FORCE_SHRINES_DATATABLE, index, "numShrines");
int shrinedex = index + rand(1, numShrines);
float locX = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locX");
float locY = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locY");
float locZ = dataTableGetFloat(FORCE_SHRINES_DATATABLE, shrinedex, "locZ");
shrineLoc = new location(locX, locY, locZ, planet, null);
}
return shrineLoc;
}
int getPlanetForceShrineDatatableIndex(string planet)
{
int numItems = dataTableGetNumRows(FORCE_SHRINES_DATATABLE);
int index = -1;
for (int i = 0; i < numItems; i++)
{
string areaName = dataTableGetString(FORCE_SHRINES_DATATABLE, i, "planet");
if (areaName.equals(planet))
{
index = i;
break;
}
}
return index;
}
boolean isValidShrineLocObjVar(obj_id player)
{
location currentShrineLoc = getLocationObjVar(player, JEDI_TRIALS_SHRINELOC_OBJVAR);
if ( currentShrineLoc == null )
{
return false;
}
string shrinePlanet = currentShrineLoc.area;
float curX = currentShrineLoc.x;
float curY = currentShrineLoc.y;
float curZ = currentShrineLoc.z;
int planetIndex = getPlanetForceShrineDatatableIndex(shrinePlanet);
int numShrines = dataTableGetInt(FORCE_SHRINES_DATATABLE, planetIndex, "numShrines");
for ( int i = 1; i <= numShrines; i++ )
{
float locX = dataTableGetFloat(FORCE_SHRINES_DATATABLE, (planetIndex + i), "locX");
float locY = dataTableGetFloat(FORCE_SHRINES_DATATABLE, (planetIndex + i), "locY");
float locZ = dataTableGetFloat(FORCE_SHRINES_DATATABLE, (planetIndex + i), "locZ");
if ( curX == locX && curY == locY && curZ == locZ )
{
return true;
}
}
return false;
}
int[] getQuestOrderFromDatatable(string datatable)
{
int numTrials = dataTableGetNumRows(datatable);
int[] questList = new int[numTrials];
// initialize questList
for ( int q = 0; q < questList.length; q++ )
{
questList[q] = -1;
}
// each row of the datatable is a trial.
// If trialNum in the datatable is not -1, then use the trialNum specifid to determine
// when to give the quest - otherwise put that row into the unused list.
resizeable int[] unusedRows = new int[0];
for ( int datatableRow = 0; datatableRow < numTrials; datatableRow++ )
{
int questNum = dataTableGetInt(datatable, datatableRow, "trialNum");
if ( questNum != -1 )
{
questList[questNum] = datatableRow;
}
else
{
utils.addElement(unusedRows, datatableRow);
}
}
// add the unused trials (datatable rows) to the questList in random order.
for ( int questNum = 0; questNum < numTrials; questNum++ )
{
int foo = questList[questNum];
if ( foo == -1 )
{
int index = rand(0, (unusedRows.length-1));
int datatableRow = unusedRows[index];
questList[questNum] = datatableRow;
utils.removeElementAt(unusedRows, index);
}
}
return questList;
}
string getJediTrialsQuestListAsString(obj_id player, int[] questList)
{
string questListString = "{ ";
for ( int i = 0; i < questList.length; i++ )
{
int questNum = questList[i];
if ( i > 0 )
{
questListString = questListString + ", ";
}
questListString = questListString + questNum;
}
questListString = questListString + " }";
return questListString;
}
string getJediTrialsDatatableString(obj_id player, string column)
{
string jediTrialString = "";
string datatable = "";
string trialObjVar = "";
if ( hasObjVar(player, PADAWAN_QUESTLIST_OBJVAR) )
{
datatable = PADAWAN_TRIALS_DATATABLE;
trialObjVar = PADAWAN_QUESTLIST_OBJVAR;
}
else if ( hasObjVar(player, KNIGHT_QUESTLIST_OBJVAR) )
{
datatable = KNIGHT_TRIALS_DATATABLE;
trialObjVar = KNIGHT_QUESTLIST_OBJVAR;
}
if ( !datatable.equals("") && !trialObjVar.equals("") )
{
int[] questList = getIntArrayObjVar(player, trialObjVar);
if ( questList != null && questList.length > 0 )
{
int trialNum = getIntObjVar(player, JEDI_TRIALS_TRIALNUMBER_OBJVAR);
int datatableRow = questList[trialNum];
jediTrialString = dataTableGetString(datatable, datatableRow, column);
}
}
return jediTrialString;
}
int getJediTrialsDatatableInt(obj_id player, string column)
{
int jediTrialInt = Integer.MIN_VALUE;
string datatable = "";
string trialObjVar = "";
if ( hasObjVar(player, PADAWAN_QUESTLIST_OBJVAR) )
{
datatable = PADAWAN_TRIALS_DATATABLE;
trialObjVar = PADAWAN_QUESTLIST_OBJVAR;
}
else if ( hasObjVar(player, KNIGHT_QUESTLIST_OBJVAR) )
{
datatable = KNIGHT_TRIALS_DATATABLE;
trialObjVar = KNIGHT_QUESTLIST_OBJVAR;
}
if ( !datatable.equals("") && !trialObjVar.equals("") )
{
int[] questList = getIntArrayObjVar(player, trialObjVar);
if ( questList != null && questList.length > 0 )
{
int trialNum = getIntObjVar(player, JEDI_TRIALS_TRIALNUMBER_OBJVAR);
int datatableRow = questList[trialNum];
jediTrialInt = dataTableGetInt(datatable, datatableRow, column);
}
}
return jediTrialInt;
}
void giveGenericForceShrineMessage(obj_id player)
{
int chance = rand(1,15);
string str_reference = "force_shrine_wisdom_" + chance;
string_id sid_msg = new string_id("jedi_trials", str_reference);
sendSystemMessage(player, sid_msg);
return;
}
// quest functions
boolean checkForGroupCombatQuestKill(obj_id player, dictionary params, string datatableColumn)
{
obj_id creature = params.getObjId("target");
if ( isIdValid(creature) )
{
obj_id topGroup = getObjIdObjVar(creature, xp.VAR_TOP_GROUP);
obj_id[] killers = null;
if ( isIdValid(topGroup))
{
if ( group.isGroupObject(topGroup) )
{
killers = getGroupMemberIds(topGroup);
}
else
{
killers = new obj_id[1];
killers[0] = topGroup;
}
if ( (killers == null) || (killers.length == 0) )
{
return false;
}
if ( utils.getElementPositionInArray(killers, player) > -1)
{
string creatureType = ai_lib.getCreatureName(creature);
if ( creatureType == null || creatureType.equals("") )
{
return false;
}
string[] validTargets = getValidQuestTargets(player, datatableColumn);
if ( validTargets != null )
{
for ( int i = 0; i < validTargets.length; i++ )
{
string targetName = validTargets[i];
//if ( creatureType.equals(targetName) )
int stringCheck = creatureType.indexOf(targetName);
if ( stringCheck > -1 )
{
return true;
}
}
}
}
}
}
return false;
}
boolean checkForIndividualCombatQuestKill(obj_id player, dictionary params, string datatableColumn)
{
obj_id creature = params.getObjId("target");
if ( isIdValid(creature) )
{
obj_id primaryKiller = getObjIdObjVar(creature, xp.VAR_TOP_GROUP);
obj_id landedDeathBlow = getObjIdObjVar(creature, xp.VAR_LANDED_DEATHBLOW);
obj_id[] topDamagers = getObjIdArrayObjVar(creature, xp.VAR_TOP_DAMAGERS);
if ( isIdValid(primaryKiller) && isIdValid(landedDeathBlow) && topDamagers != null )
{
if ( primaryKiller == player || landedDeathBlow == player || utils.isObjIdInArray(topDamagers, player) )
{
string creatureType = ai_lib.getCreatureName(creature);
if ( creatureType == null || creatureType.equals("") )
{
return false;
}
string[] validTargets = getValidQuestTargets(player, datatableColumn);
if ( validTargets != null )
{
for ( int i = 0; i < validTargets.length; i++ )
{
string targetName = validTargets[i];
//if ( creatureType.equals(targetName) )
int stringCheck = creatureType.indexOf(targetName);
if ( stringCheck > -1 )
{
return true;
}
}
}
}
}
}
return false;
}
string[] getValidQuestTargets(obj_id player, string datatableColumn)
{
string targets = getJediTrialsDatatableString(player, datatableColumn);
if ( targets == null || targets.equals("") || targets.equals("null") )
{
return null;
}
java.util.StringTokenizer foo = new java.util.StringTokenizer(targets, ";");
int numTokens = foo.countTokens();
string[] validTargets = new string[numTokens];
int j = 0;
while ( foo.hasMoreTokens() )
{
string temp = foo.nextToken();
validTargets[j] = temp;
j++;
}
return validTargets;
}
// SUI functions
int oneButtonMsgBox(obj_id controller, obj_id player, string handler, string_id title, string_id textMsg, string_id okButton)
{
string newTextMsg = utils.packStringId(textMsg);
return oneButtonMsgBox(controller, player, handler, title, newTextMsg, okButton);
}
int oneButtonMsgBox(obj_id controller, obj_id player, string handler, string_id title, string textMsg, string_id okButton)
{
if ( utils.hasScriptVar(player, "jedi_trials.openSui") )
{
int oldSui = utils.getIntScriptVar(player, "jedi_trials.openSui");
utils.removeScriptVar(player, "jedi_trials.openSui");
if ( oldSui > -1 )
{
forceCloseSUIPage(oldSui);
}
}
string TITLE_TXT = utils.packStringId(title);
string OK_BUTTON = utils.packStringId(okButton);
// Create the dialog page.
int pid = sui.createSUIPage( sui.SUI_MSGBOX, controller, player, handler );
// Add elements text.
setSUIProperty(pid, "", "Location", "500,75");
setSUIProperty(pid, "", "Size", SUI_STARTING_SIZE);
setSUIProperty(pid, sui.MSGBOX_TITLE, sui.PROP_TEXT, TITLE_TXT );
setSUIProperty(pid, sui.MSGBOX_PROMPT, sui.PROP_TEXT, textMsg);
// Add buttons.
sui.msgboxButtonSetup(pid, sui.OK_ONLY);
setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, OK_BUTTON);
// Show dialog.
utils.setScriptVar(player, "jedi_trials.openSui", pid);
sui.showSUIPage( pid );
return pid;
}
int twoButtonMsgBox(obj_id controller, obj_id player, string handler, string_id title, string textMsg, string_id okButton, string_id cancelButton)
{
if ( utils.hasScriptVar(player, "jedi_trials.openSui") )
{
int oldSui = utils.getIntScriptVar(player, "jedi_trials.openSui");
utils.removeScriptVar(player, "jedi_trials.openSui");
if ( oldSui > -1 )
{
forceCloseSUIPage(oldSui);
}
}
string TITLE_TXT = utils.packStringId(title);
string OK_BUTTON = utils.packStringId(okButton);
string CANCEL_BUTTON = utils.packStringId(cancelButton);
// Create the dialog page.
int pid = sui.createSUIPage( sui.SUI_MSGBOX, controller, player, handler );
// Add elements text.
setSUIProperty(pid, "", "Location", "500,75");
setSUIProperty(pid, "", "Size", SUI_STARTING_SIZE);
setSUIProperty(pid, sui.MSGBOX_TITLE, sui.PROP_TEXT, TITLE_TXT );
setSUIProperty(pid, sui.MSGBOX_PROMPT, sui.PROP_TEXT, textMsg);
// Add buttons.
sui.msgboxButtonSetup(pid, sui.YES_NO);
setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, OK_BUTTON);
setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, CANCEL_BUTTON);
// Show dialog.
utils.setScriptVar(player, "jedi_trials.openSui", pid);
sui.showSUIPage( pid );
return pid;
}
int threeButtonMsgBox(obj_id controller, obj_id player, string handler, string_id title, string_id textMsg, string_id okButton, string_id cancelButton, string_id revertButton)
{
string TEXT_MSG = utils.packStringId(textMsg);
return threeButtonMsgBox(controller, player, handler, title, TEXT_MSG, okButton, cancelButton, revertButton);
}
int threeButtonMsgBox(obj_id controller, obj_id player, string handler, string_id title, string textMsg, string_id okButton, string_id cancelButton, string_id revertButton)
{
if ( utils.hasScriptVar(player, "jedi_trials.openSui") )
{
int oldSui = utils.getIntScriptVar(player, "jedi_trials.openSui");
utils.removeScriptVar(player, "jedi_trials.openSui");
if ( oldSui > -1 )
{
forceCloseSUIPage(oldSui);
}
}
string TITLE_TXT = utils.packStringId(title);
string OK_BUTTON = utils.packStringId(okButton);
string CANCEL_BUTTON = utils.packStringId(cancelButton);
string REVERT_BUTTON = utils.packStringId(revertButton);
// Create the dialog page.
int pid = sui.createSUIPage( sui.SUI_MSGBOX, controller, player, handler);
// Add elements text.
setSUIProperty(pid, "", "Location", "500,75");
setSUIProperty(pid, "", "Size", SUI_STARTING_SIZE);
setSUIProperty(pid, sui.MSGBOX_TITLE, sui.PROP_TEXT, TITLE_TXT);
setSUIProperty(pid, sui.MSGBOX_PROMPT, sui.PROP_TEXT, textMsg);
// Add buttons.
sui.msgboxButtonSetup(pid, sui.YES_NO_CANCEL);
setSUIProperty(pid, sui.MSGBOX_BTN_REVERT, sui.PROP_TEXT, REVERT_BUTTON);
setSUIProperty(pid, sui.MSGBOX_BTN_OK, sui.PROP_TEXT, OK_BUTTON);
setSUIProperty(pid, sui.MSGBOX_BTN_CANCEL, sui.PROP_TEXT, CANCEL_BUTTON);
setSUIProperty(pid, sui.MSGBOX_BTN_REVERT, "OnPress", "RevertWasPressed=1\r\nparent.btnOk.press=t");
subscribeToSUIProperty(pid, sui.MSGBOX_BTN_REVERT, "RevertWasPressed");
// Show dialog.
utils.setScriptVar(player, "jedi_trials.openSui", pid);
sui.showSUIPage( pid );
return pid;
}