Files
dsrc/sku.0/sys.server/compiled/game/script/space/quest_logic/piracy.script
T

534 lines
14 KiB
Plaintext

//------------------------------------------------
//
// A system to allow players to board specific ships once disabled and aquire a 'treasure chest' static item.
// 1. Eliminate the target ship's bodyguard.
// 2. Disable the target ship.
// 3. Dock with the ship
//------------------------------------------------
//------------------------------------------------
// Includes
//------------------------------------------------
include library.space_create;
include library.space_quest;
include library.space_utils;
include library.space_crafting;
include library.space_transition;
include library.utils;
include library.ship_ai;
include library.prose;
//------------------------------------------------
//------------------------------------------------
messageHandler startBeacon()
{
if(!isSpaceScene())
{
return SCRIPT_CONTINUE;
}
// Just to be safe.. one hour from now everything is erased.
messageTo(self, "cleanupPiracyEvent", null, 3600.f, false);
if(!hasObjVar(self, "warmUpTimer"))
{
int warmUpTimer = rand(6, 8);
setObjVar(self, "warmUpTimer", warmUpTimer);
}
int timer = getIntObjVar(self, "warmUpTimer");
playClientEffectLoc(self, "appearance/pt_space_interdiction_burst.prt", getLocation(self), 0f);
if(timer > 0)
{
timer--;
messageTo(self, "startBeacon", null, 2.f, false);
setObjVar(self, "warmUpTimer", timer);
return SCRIPT_CONTINUE;
}
messageTo(self, "startPiracyEvent", null, 2.f, false);
return SCRIPT_CONTINUE;
}
messageHandler startPiracyEvent()
{
// Set up quest specific objvars.
obj_id player = getObjIdObjVar(self, "player");
if(!isIdValid(player) || !exists(player))
{
return SCRIPT_CONTINUE;
}
CustomerServiceLog("space_piracy","Player "+player+" is starting a piracy event at location: "+getLocation(self)+" in zone: "+getCurrentSceneName());
clearMissionCriticalObjects(player);
generateShipList(self);
return SCRIPT_CONTINUE;
}
void generateShipList(obj_id self)
{
int difficulty = getIntObjVar(self, "difficulty");
string faction = getStringObjVar(self, "faction");
string targetShipString = "targetship";
string bigEscortString = "bigescort";
string mediumEscortString = "mediumescort";
string smallEscortString = "smallescort";
if(faction != null)
{
targetShipString = faction+targetShipString;
bigEscortString = faction+bigEscortString;
mediumEscortString = faction+mediumEscortString;
smallEscortString = faction+smallEscortString;
}
string table = "/datatables/spacequest/piracy/piracy_spawn_table.iff";
// Find the target ship
string[] targetShipArray = dataTableGetStringColumnNoDefaults(table, targetShipString);
if(targetShipArray == null || targetShipArray.length <= 0)
{
return;
}
//int i = rand(0, targetShipArray.length -1);
int i = rand(0, difficulty -1);
string targetShipType = targetShipArray[i];
if(difficulty == 5)
{
difficulty++;
}
//Find the escort ships
int numBigShips = 1 + (difficulty / 2);
int numMediumShips = rand(0, (difficulty / 2));
int numSmallShips = rand(1, 2) + (difficulty);
int escortSize = numBigShips+numMediumShips+numSmallShips;
string[] escortsArray = new string[escortSize];
string[] bigShipArray = dataTableGetStringColumnNoDefaults(table, bigEscortString);
string[] mediumShipArray = dataTableGetStringColumnNoDefaults(table, mediumEscortString);
string[] smallShipArray = dataTableGetStringColumnNoDefaults(table, smallEscortString);
//int i = 0;
int a = 0;
int b = 0;
int c = 0;
for(a=0; a<numBigShips; a++)
{
int r = rand(0, bigShipArray.length -1);
escortsArray[a] = bigShipArray[r];
}
for(b=0; b<numMediumShips; b++)
{
int r = rand(0, mediumShipArray.length -1);
int s = a+b;
escortsArray[s] = mediumShipArray[r];
}
for(c=0; c<numSmallShips; c++)
{
int r = rand(0, smallShipArray.length -1);
int x = a+b+c;
escortsArray[x] = smallShipArray[r];
}
setObjVar(self, "targetShipType", targetShipType);
setObjVar(self, "escortArray", escortsArray);
warpInTargetShip(self, targetShipType);
warpInEscortShips(self, escortsArray);
}
//------------------------------------------------
// warpInTarget
//------------------------------------------------
void warpInTargetShip(obj_id self, string targetShipType)
{
obj_id player = getObjIdObjVar(self, "player");
if(!isIdValid(player) || !exists(player))
{
return;
}
obj_id playerShip = space_transition.getContainingShip(player);
if(!isIdValid(playerShip) || !exists(playerShip))
{
return;
}
int targetSquad = ship_ai.squadCreateSquadId();
setObjVar(self, "targetSquad", targetSquad);
// Create the target formation.
transform centerLoc = getTransform_o2p(self);
transform spawnTargetLoc = space_quest.getRandomPositionInSphere(centerLoc, 200, 200);
obj_id targetShip = space_create.createShipHyperspace(targetShipType, spawnTargetLoc);
setObjVar(targetShip, "beacon", self);
setObjVar(self, "targetShip", targetShip);
setObjVar(targetShip, "player", player);
int difficulty = getIntObjVar(self, "difficulty");
if(difficulty <= 0 || difficulty > 5)
{
difficulty = 1;
}
setObjVar(targetShip, "difficulty", difficulty);
if(!exists(targetShip) || !isIdValid(targetShip))
{
return;
}
CustomerServiceLog("space_piracy"," Warping in the TargetShip for player "+player+"'s Piracy Event. TargetShip OID: "+targetShip+" TargetShip type: "+targetShipType);
ship_ai.unitSetLeashDistance(targetShip, 16000);
ship_ai.unitSetSquadId(targetShip, targetSquad);
setLookAtTarget(player, targetShip);
attachScript(targetShip, "space.quest_logic.piracy_ship");
ship_ai.unitSetAttackOrders(targetShip, ship_ai.ATTACK_ORDERS_RETURN_FIRE);
ship_ai.unitAddExclusiveAggro(targetShip, player);
addMissionCriticalObject(player, targetShip);
setObjVar(targetShip, "objMissionOwner", player);
setObjVar(targetShip, "piracyEventOwner", player);
// Set the ship's speed limits.
float maxspeed = getShipEngineSpeedMaximum(targetShip);
if (maxspeed < 15.f)
setShipEngineSpeedMaximum(targetShip, 15.f + rand()*10.f);
else if (maxspeed > 25.f)
setShipEngineSpeedMaximum(targetShip, 23.f + rand()*5.f);
// Play the music.
//play2dNonLoopingMusic( player, "clienteffect/ui_quest_spawn_wave.cef");
messageTo(self, "updateTargetWaypoint", null, 1.f, false);
messageTo(self, "startMovement", null, 3.f, false);
messageTo(self, "eventTimer", null, 1.f, false);
return;
}
void warpInEscortShips(obj_id self, string[] escortShips)
{
// Warp in support ships.
//string[] escortShips = getStringArrayObjVar(self, "escortArray");
obj_id player = getObjIdObjVar(self, "player");
if(!isIdValid(player) || !exists(player))
{
return;
}
obj_id playerShip = space_transition.getContainingShip(player);
if(!isIdValid(playerShip) || !exists(playerShip))
{
return;
}
if(!hasObjVar(self, "targetSquad"))
{
return;
}
obj_id targetShip = getObjIdObjVar(self, "targetShip");
if(!isIdValid(targetShip) || !exists(targetShip))
{
return;
}
int targetSquad = getIntObjVar(self, "targetSquad");
int escortSquad = ship_ai.squadCreateSquadId();
if(escortShips != null)
{
obj_id[] escortIdArray = new obj_id[escortShips.length];
for ( int i=0; i<escortShips.length; i++ )
{
if(escortShips[i] == null || escortShips[i].length() <= 0)
{
continue;
}
// Spawn the escorts.
transform t = getTransform_o2w(targetShip);
transform spawnLoc = t.move_l(new vector(rand(-200, 200), rand(-200, 200), rand(-200, 200))) /*.yaw_l( (float) -Math.PI )*/;
escortIdArray[i] = space_create.createShipHyperspace(escortShips[i], spawnLoc);
ship_ai.unitSetLeashDistance(escortIdArray[i], 16000 );
ship_ai.unitSetSquadId(escortIdArray[i], escortSquad );
ship_ai.unitAddExclusiveAggro(escortIdArray[i], player);
addMissionCriticalObject(player, escortIdArray[i]);
setObjVar(escortIdArray[i], "objMissionOwner", player);
setObjVar(escortIdArray[i], "piracyEventOwner", player);
ship_ai.unitSetAutoAggroImmuneTime(playerShip, 5.0f);
setObjVar(escortIdArray[i], "beacon", self);
attachScript(escortIdArray[i], "space.quest_logic.piracy_ship");
CustomerServiceLog("space_piracy"," Warping in an Escort ship for player "+player+"'s Piracy Event. Ship OID: "+escortIdArray[i]+" TargetShip type: "+escortShips[i]);
}
setObjVar(self, "escortIdArray", escortIdArray);
setObjVar(targetShip, "escortIdArray", escortIdArray);
}
obj_id[] squadList = ship_ai.squadGetUnitList(escortSquad);
if(squadList != null)
{
ship_ai.squadSetLeader(escortSquad, squadList[0]);
}
ship_ai.squadFollow(escortSquad, targetShip, new vector(0,0,-25.0f), 100.f);
ship_ai.squadSetGuardTarget(escortSquad, targetSquad);
ship_ai.squadSetAttackOrders(escortSquad, ship_ai.ATTACK_ORDERS_RETURN_FIRE);
ship_ai.squadSetFormation(escortSquad, 5);
return;
}
messageHandler startMovement()
{
// Create a random destination, make sure it's not outside the edges of space
location o = new location(0.f, 0.f, 0.f);
transform randomTransform = space_quest.getRandomPositionInSphere(transform.identity, 4000, 6000);
obj_id targetShip = getObjIdObjVar(self, "targetShip");
if(!exists(targetShip) || !isIdValid(targetShip))
{
//something broke. No target ship, not event, lets cleanup
messageTo(self, "cleanupPiracyEvent", null, 3.f, false);
return SCRIPT_CONTINUE;
}
vector v = randomTransform.getPosition_p();
location loc = new location(v.x, v.y, v.z);
float dist = getDistance(loc, o);
if ( dist >= 7500 )
{
// out of bounds, lets try again
messageTo(self, "startMovement", null, 0.f, false);
return SCRIPT_CONTINUE;
}
ship_ai.unitMoveTo(targetShip, randomTransform);
return SCRIPT_CONTINUE;
}
messageHandler updateTargetWaypoint()
{
obj_id player = getObjIdObjVar(self, "player");
obj_id targetShip = getObjIdObjVar(self, "targetShip");
obj_id waypoint = getObjIdObjVar(self, "spacepiracy.waypoint");
location loc = getLocation(targetShip);
if(!exists(player) || !isIdValid(player))
{
messageTo(self, "cleanupPiracyEvent", null, 0.f, false);
return SCRIPT_CONTINUE;
}
if(!exists(targetShip) || !isIdValid(targetShip))
{
if(waypoint != null)
{
destroyWaypointInDatapad(waypoint, player);
}
return SCRIPT_CONTINUE;
}
if(!isIdValid(waypoint))
waypoint = createWaypointInDatapad(player, loc);
if(isIdValid(waypoint))
{
setWaypointVisible(waypoint, true);
setWaypointActive(waypoint, true);
setWaypointLocation(waypoint, loc);
setWaypointName(waypoint, "Convoy");
setWaypointColor(waypoint, "space");
setObjVar(self, "spacepiracy.waypoint", waypoint);
}
sendSystemMessage(player, "updating waypoint", null);
messageTo(self, "updateTargetWaypoint", null, 30.f, false);
return SCRIPT_CONTINUE;
}
messageHandler cleanupPiracyEvent()
{
obj_id targetShip = getObjIdObjVar(self, "targetShip");
obj_id waypoint = getObjIdObjVar(self, "spacepiracy.waypoint");
obj_id player = getObjIdObjVar(self, "player");
clearMissionCriticalObjects(player);
if(exists(targetShip) && isIdValid(targetShip))
{
messageTo(targetShip, "hyperLeave", null, 0.f, false);
}
obj_id[] escortIdArray = utils.getObjIdArrayObjVar(self, "escortIdArray");
if(escortIdArray != null)
{
for ( int i=0; i<escortIdArray.length; i++ )
{
if(isIdValid(escortIdArray[i]) && exists(escortIdArray[i]))
{
messageTo(escortIdArray[i], "hyperLeave", null, 0.f, false);
}
}
}
if(exists(player) && isIdValid(player))
{
utils.removeScriptVar(player, "interdiction_beacon");
}
if(isIdValid(waypoint) && exists(player) && isIdValid(player))
{
destroyWaypointInDatapad(waypoint, player);
}
CustomerServiceLog("space_piracy","Cleaning up piracy event belongning to player "+player+" Controlling object: "+self);
if(isIdValid(self) && exists(self) && isIdValid(self))
{
destroyObject(self);
}
return SCRIPT_CONTINUE;
}
messageHandler eventTimer()
{
obj_id targetShip = getObjIdObjVar(self, "targetShip");
if(!exists(targetShip) || !isIdValid(targetShip))
{
return SCRIPT_CONTINUE;
}
obj_id player = getObjIdObjVar(self, "player");
if(!exists(player) || !isIdValid(player))
{
messageTo(self, "cleanupPiracyEvent", null, 0.f, false);
return SCRIPT_CONTINUE;
}
string dialog = "space/space_piracy_event";
if(!utils.hasScriptVar(self, "hyperTimer"))
{
utils.setScriptVar(self, "hyperTimer", 0);
string_id arrival = new string_id(dialog, "arrival");
prose_package pp = prose.getPackage(arrival, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(hasObjVar(targetShip, "isDisabled"))
{
if(!utils.hasScriptVar(self, "disabledCounter"))
{
utils.setScriptVar(self, "disabledCounter", 0);
}
int disabledCounter = utils.getIntScriptVar(self, "disabledCounter");
if(disabledCounter == 0)
{
string_id disabled1 = new string_id(dialog, "disabled1");
prose_package pp = prose.getPackage(disabled1, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(disabledCounter == 2)
{
string_id disabled2 = new string_id(dialog, "disabled2");
prose_package pp = prose.getPackage(disabled2, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(disabledCounter == 3)
{
dictionary dctParams = new dictionary();
dctParams.put("objShip", targetShip);
messageTo(targetShip, "megaDamage", dctParams, 0, false);
}
disabledCounter++;
utils.setScriptVar(self, "disabledCounter", disabledCounter);
messageTo(self, "eventTimer", null, 30.f, false);
return SCRIPT_CONTINUE;
}
int hyperTimer = utils.getIntScriptVar(self, "hyperTimer");
if(hyperTimer == 10)
{
string_id hyper1 = new string_id(dialog, "hyper1");
prose_package pp = prose.getPackage(hyper1, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(hyperTimer == 50)
{
string_id hyper2 = new string_id(dialog, "hyper2");
prose_package pp = prose.getPackage(hyper2, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(hyperTimer == 80)
{
string_id hyper3 = new string_id(dialog, "hyper3");
prose_package pp = prose.getPackage(hyper3, 0);
space_quest.groupTaunt(targetShip, player, pp);
}
if(hyperTimer >= 100 && !hasObjVar(targetShip, "isDisabled"))
{
string_id hyperfinished = new string_id(dialog, "hyperfinished");
prose_package pp = prose.getPackage(hyperfinished, 0);
space_quest.groupTaunt(targetShip, player, pp);
CustomerServiceLog("space_piracy","Time expired for piracy event started by "+player+" Starting cleanup.");
sendSystemMessage(player, "You failed to disable your target in time. Your target is making the jump to hyperspace", null);
messageTo(self, "cleanupPiracyEvent", null, 1.f, false);
}
hyperTimer = hyperTimer + 10;
utils.setScriptVar(self, "hyperTimer", hyperTimer);
messageTo(self, "eventTimer", null, 60.f, false);
return SCRIPT_CONTINUE;
}