mirror of
https://github.com/SWG-Source/dsrc.git
synced 2026-07-31 00:15:54 -04:00
412 lines
12 KiB
Plaintext
412 lines
12 KiB
Plaintext
/**********************************************************************
|
|
* Title: space_dungeon
|
|
* Description: Handles reading of datatable info for space dungeons
|
|
**********************************************************************/
|
|
|
|
|
|
/***** INCLUDES ********************************************************/
|
|
include library.player_structure;
|
|
include library.utils;
|
|
include library.space_dungeon;
|
|
include library.sui;
|
|
include library.prose;
|
|
|
|
/***** CONSTANTS *******************************************************/
|
|
|
|
// Ticket Template
|
|
const string TEMPLATE_TICKET = "object/tangible/travel/travel_ticket/dungeon_ticket.iff";
|
|
|
|
// Dungeon Datatable
|
|
const string DUNGEON_DATATABLE = "datatables/dungeon/space_dungeon.iff";
|
|
|
|
// Scripts
|
|
const string TRAVEL_DUNGEON = "item.travel_ticket.travel_space_dungeon";
|
|
const string DUNGEON_CONTROLLER = "theme_park.dungeon.space_dungeon_controller";
|
|
|
|
|
|
|
|
// ObjVars / ScriptVars ******************
|
|
|
|
// Player
|
|
|
|
|
|
/***** TRIGGERS ********************************************************/
|
|
|
|
|
|
/***** MESSAGEHANDLERS *************************************************/
|
|
|
|
|
|
/***** COMMANDHANDLERS *************************************************/
|
|
|
|
|
|
/***** FUNCTIONS *******************************************************/
|
|
|
|
/***********************************************************************
|
|
* @brief gets the dungeon's travel success string_id
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return string_id
|
|
***********************************************************************/
|
|
string_id getDungeonSuccessString(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonSuccessString -- name is null");
|
|
return null;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
string success_string = dataTableGetString(space_dungeon_data.DUNGEON_DATATABLE, idx, "success_string");
|
|
return utils.unpackString(success_string);
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonSuccessString -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief gets the dungeon's travel failure string_id
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return string_id
|
|
***********************************************************************/
|
|
string_id getDungeonFailureString(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonFailureString -- name is null");
|
|
return null;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
string failure_string = dataTableGetString(space_dungeon_data.DUNGEON_DATATABLE, idx, "failure_string");
|
|
return utils.unpackString(failure_string);
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonFailureString -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief gets the maximum number of players allowed in a dungeon
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return int -1 on failure
|
|
***********************************************************************/
|
|
int getDungeonMaxPlayers(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonFailureString -- name is null");
|
|
return -1;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
int max_players = dataTableGetInt(space_dungeon_data.DUNGEON_DATATABLE, idx, "max_players");
|
|
return max_players;
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonMaxPlayers -- Unable to find a datatable entry for " + name);
|
|
return -1;
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* @brief gets the starting location for a dungeon. It does not return
|
|
* the cell obj_id. Use getDungeonStartCell to get the cell name.
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
location getDungeonStartLocation(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartLocation -- name is null");
|
|
return null;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
dictionary row = dataTableGetRow(space_dungeon_data.DUNGEON_DATATABLE, idx);
|
|
|
|
// note - the ONLY place the planet is used for is ticket validation
|
|
// the actual scene of the dungeon is what determines where the player teleports to
|
|
string planet = row.getString("planet");
|
|
float loc_x = row.getFloat("start_loc_x");
|
|
float loc_y = row.getFloat("start_loc_y");
|
|
float loc_z = row.getFloat("start_loc_z");
|
|
location start_loc = new location(loc_x, loc_y, loc_z, planet);
|
|
|
|
return start_loc;
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartLocation -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
float getDungeonStartLocationRadius(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartLocationRadius -- name is null");
|
|
return 0.0f;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
dictionary row = dataTableGetRow(space_dungeon_data.DUNGEON_DATATABLE, idx);
|
|
return row.getFloat("start_loc_radius");
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartLocationRadius -- Unable to find a datatable entry for " + name);
|
|
}
|
|
return 0.0f;
|
|
}
|
|
/***********************************************************************
|
|
* @brief gets the starting location for a dungeon. It does not return
|
|
* the cell obj_id. Use getDungeonStartCell to get the cell name.
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
location getDungeonStartLocationRandomized(string name)
|
|
{
|
|
location loc = getDungeonStartLocation(name);
|
|
|
|
if (null == loc)
|
|
return null;
|
|
|
|
float startLocationRadius = getDungeonStartLocationRadius(name);
|
|
|
|
loc.x += (-1.0f + (2.0f * random.rand())) * startLocationRadius;
|
|
loc.z += (-1.0f + (2.0f * random.rand())) * startLocationRadius;
|
|
|
|
return loc;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief Gets the location to which to dump the player, after leaving
|
|
* the dungeon.
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
location getDungeonExitLocation(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonExitLocation -- name is null");
|
|
return null;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
dictionary row = dataTableGetRow(space_dungeon_data.DUNGEON_DATATABLE, idx);
|
|
string planet = row.getString("exit_planet");
|
|
float loc_x = row.getFloat("exit_loc_x");
|
|
float loc_y = row.getFloat("exit_loc_y");
|
|
float loc_z = row.getFloat("exit_loc_z");
|
|
|
|
location start_loc = new location(loc_x, loc_y, loc_z, planet);
|
|
return start_loc;
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonExitLocation -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
float getDungeonExitLocationRadius(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonExitLocation -- name is null");
|
|
return 0.0f;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
dictionary row = dataTableGetRow(space_dungeon_data.DUNGEON_DATATABLE, idx);
|
|
return row.getFloat("exit_loc_radius");
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonExitLocation -- Unable to find a datatable entry for " + name);
|
|
}
|
|
return 0.0f;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief Gets the location to which to dump the player, after leaving
|
|
* the dungeon.
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
location getDungeonExitLocationRandomized(string name)
|
|
{
|
|
location loc = getDungeonExitLocation(name);
|
|
if (null == loc)
|
|
return null;
|
|
|
|
float exitLocationRadius = getDungeonExitLocationRadius(name);
|
|
|
|
loc.x += (-1.0f + (2.0f * random.rand())) * exitLocationRadius;
|
|
loc.z += (-1.0f + (2.0f * random.rand())) * exitLocationRadius;
|
|
|
|
return loc;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief Gets the location to which to dump the player, after leaving
|
|
* the dungeon.
|
|
*
|
|
* @param string dungeon_name
|
|
*
|
|
* @return location null on failure
|
|
***********************************************************************/
|
|
string getDungeonStartCellName(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartCellName -- name is null");
|
|
return null;
|
|
}
|
|
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
string cell_name = dataTableGetString(space_dungeon_data.DUNGEON_DATATABLE, idx, "start_cell_name");
|
|
return cell_name;
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonStartCellName -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief Returns the script that is to be attached on players that
|
|
* are in the dungeon.
|
|
*
|
|
* @param string name
|
|
*
|
|
* @return string null on failure or no script
|
|
***********************************************************************/
|
|
string getDungeonPlayerScript(string name)
|
|
{
|
|
if (name == null)
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonPlayerScript -- name is null.");
|
|
return null;
|
|
}
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
string script = dataTableGetString(space_dungeon_data.DUNGEON_DATATABLE, idx, "player_script");
|
|
if (script != null)
|
|
{
|
|
if (script.length() < 1)
|
|
return null;
|
|
}
|
|
return script;
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "space_dungeon.getDungeonPlayerScript -- Unable to find a datatable entry for " + name);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* @brief
|
|
*
|
|
* @param
|
|
*
|
|
* @return
|
|
***********************************************************************/
|
|
boolean isValidDungeon(string name)
|
|
{
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx == -1)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
/** --------------------------------------------------------------------------
|
|
Use: Get the maximum time allowed for a single session of a private instance to be active as
|
|
defined in space_dungeon_data.DUNGEON_DATATABLE column "time_limit"
|
|
|
|
params: The string name of the private instance time you are checking
|
|
|
|
return: the maximum time allowed for the dungeon as a float
|
|
----------------------------------------------------------------------------------**/
|
|
|
|
int getMaxDungeonSesssionTime(string name)
|
|
{
|
|
int idx = dataTableSearchColumnForString(name, "dungeon", space_dungeon_data.DUNGEON_DATATABLE);
|
|
if (idx > -1)
|
|
{
|
|
int maxSessionTime = dataTableGetInt(space_dungeon_data.DUNGEON_DATATABLE, idx, "time_limit");
|
|
if (maxSessionTime > 36000 || maxSessionTime < 600)
|
|
{
|
|
LOG("space_dungeon", "spaceDungeonData.getMaxDungeonSessionTime:: maxSessionTime was greater than 10 hours or less than 10 minutes. Setting to 30 minutes");
|
|
maxSessionTime = 3600;
|
|
}
|
|
return maxSessionTime;
|
|
|
|
}
|
|
else
|
|
{
|
|
LOG("space_dungeon", "spaceDungeonData.getMaxDungeonSessionTime:: dungeon was not found in the table, returning 30 minutes");
|
|
return 3600;
|
|
}
|
|
}
|
|
|