Files
dsrc/sku.0/sys.server/compiled/game/script/library/space_flags.scriptlib
T

427 lines
11 KiB
Plaintext

/*
* This is the SCRIPT LIBRARY which defines, sets and queries the
* flags that Profession Mission/Trainer NPCs use to define and
* determine which Profession Track any given player is on!
*/
/**
*
* WHEN SETTING TRACK-SPECIFIC OBJVARS, ALWAYS ALWAYA ALWAYS
* USE THESE HANDY-DANDY WRAPPERS (for ints)
*
* //SET A FLAG AS A BOOLEAN OR AN INT!
*
* space_flags.setSpaceFlag( player, "yourFlagName", intValue );
* space_flags.setSpaceFlag( player, "yourFlagName", booleanValue );
*
*
* //GET A FLAG AS BOOLEAN OR AN INT!
*
* int x = space_flags.getIntSpaceFlag( player, "yourFlagName" );
* boolean x = space_flags.getBooleanSpaceFlag( player, "yourFlagName" );
*
*
* //SEE IF A PLAYER HAS A FLAG!
*
* boolean x = space_flags.hasSpaceFlag( player, "yourFlagName" );
*
*
* //REMOVE FLAGS!
* space_flags.removeSpaceFlag( player, "yourFlagName" );
*
*/
// CONSTS
//These consts are set on the player as the name of the
// objvar list which all other flags relevant to the
// player's track are set.
const string PRIVATEER_TATOOINE = "tatooinePrivateer";
const string PRIVATEER_NABOO = "nabooPrivateer";
const string PRIVATEER_CORELLIA = "corelliaPrivateer";
const string IMPERIAL_TATOOINE = "tatooineImperial";
const string IMPERIAL_NABOO = "nabooImperial";
const string IMPERIAL_CORELLIA = "corelliaImperial";
const string REBEL_TATOOINE = "tatooineRebel";
const string REBEL_NABOO = "nabooRebel";
const string REBEL_CORELLIA = "corelliaRebel";
//this objvar is set on the player with the value of one
// of the above consts, so we can do a "What track ARE you?"
// sort of query without looking for all of the above
// objvar lists!
const string SPACE_TRACK_FLAG = "spaceTrackFlagListName";
/**
* F U N C T I O N S
*/
//This function sets the player's Profession-Track flag:
void setSpaceTrack( obj_id player, string spaceTrack )
{
clearSpaceTrack( player );//out with the old
//in with the new:
setObjVar( player, SPACE_TRACK_FLAG, spaceTrack );
setObjVar( player, spaceTrack + ".member", true );
}
//this function returns the player's current track
string getSpaceTrack( obj_id player )
{
return getStringObjVar( player, SPACE_TRACK_FLAG );
}
void clearSpaceTrack( obj_id player )
{
string trackName = getSpaceTrack( player );
if ( trackName == null )
return;//you haven't got one
removeObjVar( player, trackName );//removes all the member variables and this objvar list!
removeObjVar( player, SPACE_TRACK_FLAG );
}
//this function query the above:
boolean isSpaceTrack( obj_id player, string spaceTrack )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null && spaceTrack == null )
return true;//they're both null
else if ( currentSpaceTrack == null || spaceTrack == null )
return false;//one is null, the other is not, so that means they are different!
else
return ( spaceTrack == currentSpaceTrack );
}
//Space flag setters, getters and removers!
void setSpaceFlag( obj_id player, string flagName, int flagValue )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return;//don't do anything, this dude isn't on track
setObjVar( player, currentSpaceTrack + ". " + flagName, flagValue );
}
void setSpaceFlag( obj_id player, string flagName, boolean flagValue )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return;//don't do anything, this dude isn't on track
if ( flagValue )
setObjVar( player, currentSpaceTrack + ". " + flagName, 1 );
else
setObjVar( player, currentSpaceTrack + ". " + flagName, 0 );
}
boolean hasSpaceFlag( obj_id player, string flagName )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return false;//Nope!
return hasObjVar( player, currentSpaceTrack + ". " + flagName );
}
int getIntSpaceFlag( obj_id player, string flagName )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return 0;//return 0, this dude isn't on a track
return getIntObjVar( player, currentSpaceTrack + ". " + flagName );
}
boolean getBooleanSpaceFlag( obj_id player, string flagName )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return false;//return 0, this dude isn't on a track
return (getIntObjVar( player, currentSpaceTrack + ". " + flagName ) == 1);
}
void removeSpaceFlag( obj_id player, string flagName )
{
string currentSpaceTrack = getSpaceTrack( player );
if ( currentSpaceTrack == null )
return;//no track, fuck it
removeObjVar( player, currentSpaceTrack + ". " + flagName );
}
/** HERE COME THE FUNCTIONS THAT TEST YOUR PROGRESSION! */
boolean isRebelPilot( obj_id player )
{
return hasSkill( player, "pilot_rebel_navy_novice" );
}
boolean isImperialPilot( obj_id player )
{
return hasSkill( player, "pilot_imperial_navy_novice" );
}
boolean isNeutralPilot( obj_id player )
{
return hasSkill( player, "pilot_neutral_novice" );
}
boolean hasAnyPilotSkill( obj_id player )
{
return ( isRebelPilot(player) || isImperialPilot(player) || isNeutralPilot( player ) );
}
string getProfessionPrefix( obj_id player )
{
if ( isRebelPilot( player ) )
return REBEL_PILOT_PROFESSION;
else if ( isImperialPilot( player ) )
return IMPERIAL_PILOT_PROFESSION;
else if ( isNeutralPilot( player ) )
return NEUTRAL_PILOT_PROFESSION;
return null;
}
boolean isRebelHelperPilot(obj_id player)
{
if(!isIdValid(player) && !exists(player))
{
return false;
}
obj_id ship = space_transition.getContainingShip (player);
if(hasObjVar(ship, "spaceFaction.FactionOverride") && isNeutralPilot(player))
{
int faction = getIntObjVar(ship, "spaceFaction.FactionOverride");
if(faction == ##"rebel")
{
return true;
}
}
return false;
}
boolean isImperialHelperPilot(obj_id player)
{
if(!isIdValid(player) && !exists(player))
{
return false;
}
obj_id ship = space_transition.getContainingShip (player);
if(hasObjVar(ship, "spaceFaction.FactionOverride"))
{
int faction = getIntObjVar(ship, "spaceFaction.FactionOverride");
if(faction == ##"imperial")
{
return true;
}
}
return false;
}
//These consts are just used internally by the functions below, so I hid them here.
// You're very clever to have found them!
const string REBEL_PILOT_PROFESSION = "pilot_rebel_navy";
const string IMPERIAL_PILOT_PROFESSION = "pilot_imperial_navy";
const string NEUTRAL_PILOT_PROFESSION = "pilot_neutral";
const int TIER1_INDEXSTART = 0;
const int TIER1_INDEXSTOP = 3;
const int TIER2_INDEXSTART = 4;
const int TIER2_INDEXSTOP = 7;
const int TIER3_INDEXSTART = 8;
const int TIER3_INDEXSTOP = 11;
const int TIER4_INDEXSTART = 12;
const int TIER4_INDEXSTOP = 15;
const string[] SKILL_NAMES = {
"_starships_01",
"_weapons_01",
"_procedures_01",
"_droid_01",
"_starships_02",
"_weapons_02",
"_procedures_02",
"_droid_02",
"_starships_03",
"_weapons_03",
"_procedures_03",
"_droid_03",
"_starships_04",
"_weapons_04",
"_procedures_04",
"_droid_04"
};
boolean isInTierOne( obj_id player )
{
//you're in tier one if you have a profession...
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
//...but aren't yet in tierTwo
return ( !hasCompletedTierOne( player ) );
}
boolean isInTierTwo( obj_id player )
{
//you're in tier 2 if you have comppleted tier1...
if (!hasCompletedTierOne( player ) )
return false;
//...but have not yet competed tier 2
return ( !hasCompletedTierTwo( player ) );
}
boolean isInTierThree( obj_id player )
{
//you're in tier 3 if you have comppleted tier2...
if (!hasCompletedTierTwo( player ) )
return false;
//...but have not yet competed tier 3
return ( !hasCompletedTierThree( player ) );
}
boolean isInTierFour( obj_id player )
{
//you're in tier 4 if you have comppleted tier3...
if (!hasCompletedTierThree( player ) )
return false;
//...but have not yet competed tier 4
return ( !hasCompletedTierFour( player ) );
}
int getPilotTier(obj_id player)
{
if (!isIdValid(player))
return 0;
if (isInTierOne(player))
return 1;
if (isInTierTwo(player))
return 2;
if (isInTierThree(player))
return 3;
if (isInTierFour(player))
return 4;
if (hasCompletedTierFour(player))
return 5;
return 0;
}
//this function gates XP rewards:
boolean hasOneTierOneSkill( obj_id player)
{
//you're done with tier one if you have all the skills
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
for ( int i = TIER1_INDEXSTART; i <= TIER1_INDEXSTOP; ++i )
{
if ( hasSkill( player, professionPrefix + SKILL_NAMES[i] ) )
{
return true;//you have one of these skills
}
}
return false;
}
boolean hasCompletedTierOne( obj_id player )
{
//you're done with tier one if you have all the skills
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
for ( int i = TIER1_INDEXSTART; i <= TIER1_INDEXSTOP; ++i )
{
if ( !hasSkill( player, professionPrefix + SKILL_NAMES[i] ) )
{
return false;
}
}
return true;
}
boolean hasCompletedTierTwo( obj_id player )
{
//you're done with tier 2 if you have all the tier2 skills
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
for ( int i = TIER2_INDEXSTART; i <= TIER2_INDEXSTOP; ++i )
{
if ( !hasSkill( player, professionPrefix + SKILL_NAMES[i] ) )
{
return false;
}
}
return true;
}
boolean hasCompletedTierThree( obj_id player )
{
//you're done with tier 3 if you have all the tier3 skills
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
for ( int i = TIER3_INDEXSTART; i <= TIER3_INDEXSTOP; ++i )
{
if ( !hasSkill( player, professionPrefix + SKILL_NAMES[i] ) )
{
return false;
}
}
return true;
}
boolean hasCompletedTierFour( obj_id player )
{
//you're done with tier 4 if you have all the tier4 skills
string professionPrefix = getProfessionPrefix( player );
if ( professionPrefix == null )
return false;
for ( int i = TIER4_INDEXSTART; i <= TIER4_INDEXSTOP; ++i )
{
if ( !hasSkill( player, professionPrefix + SKILL_NAMES[i] ) )
{
return false;
}
}
return true;
}
void restoreClientPath( obj_id player )
{
if ( !utils.hasScriptVar( player, "jtlNewbieStartLoc" ) )
return;
location destination = utils.getLocationScriptVar( player, "jtlNewbieStartLoc" );
location origin = utils.getLocationScriptVar( player, "jtlNewbieTrainerLoc" );
destroyClientPath( player );
createClientPath(player, origin, destination);
}
void clearClientPath( obj_id player )
{
if ( !utils.hasScriptVar(player, "hasClientPath"))
destroyClientPath( player );
}