Files
dsrc/sku.0/sys.server/compiled/game/script/systems/gcw/player_pvp.script
T

1833 lines
53 KiB
Plaintext

/********************************************************************************************
* Title: pvp_damage_tracker
*
* Description: tracks pvp damage done to a player to determine gcw point allotment
*
* @changelog $This script used to track an abstract pvp rating
* and now serves as a Credit For Kills tracker in the GCW Rank System.
********************************************************************************************
/***** INCLUDES *****************************************************************************/
include library.beast_lib;
include library.buff;
include library.colors_hex;
include library.factions;
include library.gcw;
include library.group;
include library.instance;
include library.locations;
include library.pclib;
include library.pet_lib;
include library.prose;
include library.pvp;
include library.restuss_event;
include library.skill;
include library.static_item;
include library.sui;
include library.utils;
/***** CONSTANTS ****************************************************************************/
///Legacy Constant, only used to remove old data
const string VAR_PVP_LAST_UPDATE = "pvp_tracker.lastupdate";
const string VAR_PVP_LAST_KILLS = "pvp_tracker.lastkills";
const string_id SID_PVP_BATTLEFIELD_KICK_OUT_INVALID = new string_id("spam", "pvp_battlefield_kick_out_invalid");
const string_id SID_PVP_BATTLEFIELD_KICK_OUT_GODMODE = new string_id("spam", "pvp_battlefield_kick_out_godmode");
const int BATTLEFIELD_QUEUE = 1;
const int BATTLEFIELD_DEQUEUE = 2;
const int BATTLEFIELD_STATUS = 3;
const int BATTLEFIELD_QUEUE_GROUP = 4;
const int BATTLEFIELD_DEQUEUE_GROUP = 5;
const int BATTLEFIELD_NUM = 4;
const string_id SID_BATTLEFIELD_QUEUE = new string_id("spam", "battlefield_queue_individual");
const string_id SID_BATTLEFIELD_QUEUE_GROUP = new string_id("spam", "battlefield_queue_group");
const string_id SID_BATTLEFIELD_DEQUEUE = new string_id("spam", "battlefield_dequeue_individual");
const string_id SID_BATTLEFIELD_DEQUEUE_GROUP = new string_id("spam", "battlefield_dequeue_group");
const string_id SID_BATTLEFIELD_STATUS = new string_id("spam", "battlefield_status");
const string_id SID_BATTLEFIELD_QUEUE_PROMPT = new string_id("spam", "battlefield_queue_prompt");
const string_id SID_BATTLEFIELD_STATUS_PROMPT = new string_id("spam", "battlefield_status_prompt");
const string_id SID_BATTLEFIELD_FACTION_UNDECLARED = new string_id("spam", "battlefield_faction_undeclared");
const string_id SID_BATTLEFIELD_LEVEL_TOO_LOW = new string_id("spam", "battlefield_level_too_low");
const string_id SID_BATTLEFIELD_OPPOSITE_FACTION_GROUP = new string_id("spam", "battlefield_opposite_faction_group");
const string_id SID_BATTLEFIELD_JOIN_NOT_IN_A_GROUP = new string_id("spam", "battlefield_join_not_in_a_group");
const string_id SID_BATTLEFIELD_ADDING_GROUP_TO_QUEUE = new string_id("spam", "battlefield_adding_group_to_queue");
const string_id SID_BATTLEFIELD_NONE_FOUND = new string_id("spam", "battlefield_none_found");
const string_id SID_BATTLEFIELD_CANNOT_ENTER_BAD_FACTION = new string_id("spam", "battlefield_cannot_enter_bad_faction");
const string_id SID_BATTLEFIELD_INVITATION_EXPIRED = new string_id("spam", "battlefield_invitation_expired");
const string_id SID_BATTLEFIELD_REMOVE_FROM_QUEUE = new string_id("spam", "battlefield_remove_from_queue");
const string_id SID_BATTLEFIELD_REMOVE_GROUP_FROM_QUEUE = new string_id("spam", "battlefield_remove_group_from_queue");
const string_id SID_BATTLEFIELD_REWARD_RECEIVED_TOKENS = new string_id("spam", "battlefield_reward_received_tokens");
const string_id SID_BATTLEFIELD_QUEUE_ACCEPTANCE = new string_id("spam", "battlefield_queue_acceptance");
const string_id SID_BATTLEFIELD_OVER_REMOVAL = new string_id("spam", "battlefield_over_removal");
const string_id SID_BATTLEFIELD_QUEUE_REFUSAL = new string_id("spam", "battlefield_queue_refusal");
const string_id SID_BATTLEFIELD_QUEUE_ACCEPTED = new string_id("spam", "battlefield_queue_accepted");
const string_id SID_BATTLEFIELD_QUEUE_REMOVAL = new string_id("spam", "battlefield_queue_removal");
const string_id SID_BATTLEFIELD_REFUSED = new string_id("spam", "battlefield_refused");
const string_id SID_BATTLEFIELD_REQUEST_IN_PROGRESS = new string_id("spam", "battlefield_request_in_progress");
const string_id SID_BATTLEFIELD_QUEUE_NOT_LEADER = new string_id("spam", "battlefield_queue_not_leader");
const string_id SID_BATTLEFIELD_COMBAT_PROFESSION_ONLY = new string_id("spam", "battlefield_combat_profession_only");
const string_id SID_BATTLEFIELD_QUEUE_ATTEMPTED_RECENTLY = new string_id("spam", "battlefield_queue_attempted_recently");
const string_id SID_BATTLEFIELD_QUEUE_ATTEMPT = new string_id("spam", "battlefield_queue_attempt");
const string_id SID_BATTLEFIELD_QUEUE_GROUP_REMOVAL = new string_id("spam", "battlefield_queue_group_removal");
const string_id SID_BATTLEFIELD_QUEUE_REJECTED = new string_id("spam", "battlefield_queue_rejected");
const string [] BATTLEFIELD_NAMES =
{
"massassi_isle",
"battlefield2",
"battlefield3",
"battlefield4",
"battlefield5"
};
const string COLOR_REBELS = "\\" + colors_hex.COLOR_REBELS;
const string COLOR_IMPERIALS = "\\" + colors_hex.COLOR_IMPERIALS;
void blog(obj_id controller, string text)
{
string battlefieldName = "none";
if(isIdValid(controller) && exists(controller) && !isPlayer(controller))
{
battlefieldName = getStringObjVar(controller, "battlefieldName");
}
if(isPlayer(controller))
{
if(utils.hasScriptVar(controller, "battlefield.queue"))
{
battlefieldName = utils.getStringScriptVar(controller, "battlefield.queue");
}
if(utils.hasScriptVar(controller, "battlefield.active"))
{
controller = utils.getObjIdScriptVar(controller, "battlefield.active");
if(isIdValid(controller) && exists(controller) && !isPlayer(controller))
{
battlefieldName = getStringObjVar(controller, "battlefieldName");
}
}
}
CustomerServiceLog("battlefield_" + battlefieldName, text);
}
obj_id getBattlefieldController(obj_id self)
{
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.active");
if(!isIdValid(controller) && isGod(self))
{
controller = gcw.getPvpRegionControllerIdByPlayer(self);
}
if(!isIdValid(controller))
{
controller = utils.getObjIdScriptVar(self, "battlefield.invitation.controller");
}
if(!isIdValid(controller))
{
controller = utils.getObjIdScriptVar(self, "battlefield.invited");
}
if(!isIdValid(controller))
{
string battlefieldName = utils.getStringScriptVar(self, "battlefield.queue");
controller = utils.getObjIdScriptVar(self, "battlefield." + battlefieldName);
}
if(!isIdValid(controller))
{
return null;
}
return controller;
}
/***** TRIGGERS *****************************************************************************/
trigger OnSpeaking(string text)
{
if(!isGod(self))
{
return SCRIPT_CONTINUE;
}
string[] words = split(text, ' ');
obj_id controller = null;
int bfRequest = 0;
// bfreset will remove all the battlefield information from a player's object. If it is stated next to the battlefield controller,
// bfreset also resets the battlefield (OnSpeaking is on the controller object for the same command).
if(words[0].equals("bfreset"))
{
utils.removeScriptVarTree(self, "battlefield");
}
if(words[0].equals("bfwarp"))
{
controller = getBattlefieldController(self);
if(!isIdValid(controller) || !exists(controller))
{
return SCRIPT_CONTINUE;
}
int bfState = utils.getIntScriptVar(controller, "battlefield.state");
sendSystemMessageTestingOnly(self, "bfState: " + bfState);
if(bfState == pvp.PVP_STATE_INVITE_QUEUE)
{
sendSystemMessageTestingOnly(self, "Attempting to end invitations...");
utils.setScriptVar(controller, "battlefield.state", pvp.PVP_STATE_INVITE_OVER);
}
}
if(words[0].equals("bfengage"))
{
controller = getBattlefieldController(self);
if(!isIdValid(controller) || !exists(controller))
{
return SCRIPT_CONTINUE;
}
int bfState = utils.getIntScriptVar(controller, "battlefield.state");
if(bfState == pvp.PVP_STATE_BATTLE_SETUP)
{
sendSystemMessageTestingOnly(self, "Attempting to end setup...");
utils.setScriptVar(controller, "battlefield.state", pvp.PVP_STATE_BATTLE_START);
}
}
if(words[0].equals("bfend"))
{
controller = getBattlefieldController(self);
if(!isIdValid(controller) || !exists(controller))
{
return SCRIPT_CONTINUE;
}
utils.removeScriptVar(controller, "battlefield.battleTime");
sendSystemMessageTestingOnly(self, "Attempting to end battlefield...");
}
return SCRIPT_CONTINUE;
}
trigger OnLogin()
{
cleanupOldSystemObjVar(self);
gcw.clearCreditForKills(self);
return SCRIPT_CONTINUE;
}
trigger OnEnteredCombat()
{
float ratio = getHealth(self) / getMaxHealth(self);
if (ratio > .9)
gcw.clearCreditForKills(self);
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
return SCRIPT_CONTINUE;
}
trigger OnDetach()
{
return SCRIPT_CONTINUE;
}
trigger OnAddedToGroup(obj_id groupId)
{
// We only want to check active battlefield players to force them to leave their group.
if(!utils.hasScriptVar(self, "battlefield.active"))
{
return SCRIPT_CONTINUE;
}
if(group.isMixedFactionGroup(groupId))
{
messageTo(self, "receiveLeaveGroup", null, 1.0f, false);
}
return SCRIPT_CONTINUE;
}
messageHandler receiveLeaveGroup()
{
group.leaveGroup(self);
sendSystemMessage(self, SID_BATTLEFIELD_OPPOSITE_FACTION_GROUP);
return SCRIPT_CONTINUE;
}
// Command handler for the /battlefield command to show the battlefield sui.
commandHandler cmdBattlefield()
{
battlefieldCommandSui(self);
return SCRIPT_CONTINUE;
}
messageHandler displayBattlefieldSui()
{
battlefieldCommandSui(self);
return SCRIPT_CONTINUE;
}
// If a player does not have a battlefield scriptvar tree, then the player has no clusterwide data cached on them.
void battlefieldCommandSui(obj_id self)
{
if(!isIdValid(self))
{
return;
}
if(!factions.isRebel(self) && !factions.isImperial(self))
{
sendSystemMessage(self, SID_BATTLEFIELD_FACTION_UNDECLARED);
return;
}
if(getLevel(self) < 75)
{
sendSystemMessage(self, SID_BATTLEFIELD_LEVEL_TOO_LOW);
return;
}
if(utils.hasScriptVar(self, "battlefield.requestInProgress"))
{
int lastTime = utils.getIntScriptVar(self, "battlefield.requestInProgress");
if(getGameTime() - lastTime < 60)
{
sendSystemMessage(self, SID_BATTLEFIELD_REQUEST_IN_PROGRESS);
return;
}
}
utils.removeScriptVarTree(self, "battlefield.status");
if(!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[0]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[1]) ||
!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[2]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[3]))
{
getClusterWideData("pvp", "*", true, self);
blog(null, "battlefieldCommandSui player: " + getName(self) + "(" + self + ") getClusterWideData requested.");
}
else
{
requestBattlefieldStatus(self);
}
}
void requestBattlefieldStatus(obj_id self)
{
if(!isIdValid(self) || !exists(self))
{
return;
}
// If you are in a battlefield, the battlefield command shows you the battlefield status.
if(utils.hasScriptVar(self, "battlefield.active"))
{
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.active");
if(isIdValid(controller) && exists(controller))
{
showBattlefieldScoreboard(self);
return;
}
}
if(!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[0]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[1]) ||
!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[2]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[3]))
{
getClusterWideData("pvp", "*", true, self);
blog(null, "requestBattlefieldStatus player: " + getName(self) + "(" + self + ") getClusterWideData requested.");
return;
}
blog(null, "requestBattlefieldStatus player: " + getName(self) + "(" + self + ") all battlefields accounted for.");
obj_id bf1 = utils.getObjIdScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[0]);
obj_id bf2 = utils.getObjIdScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[1]);
obj_id bf3 = utils.getObjIdScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[2]);
obj_id bf4 = utils.getObjIdScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[3]);
dictionary params = new dictionary();
params.put("player", self);
params.put("faction", factions.getFactionFlag(self));
utils.setScriptVar(self, "battlefield.requestInProgress", true);
messageTo(bf1, "getBattlefieldStatus", params, 1.0f, false);
messageTo(bf2, "getBattlefieldStatus", params, 1.0f, false);
messageTo(bf3, "getBattlefieldStatus", params, 1.0f, false);
messageTo(bf4, "getBattlefieldStatus", params, 1.0f, false);
sendSystemMessage(self, SID_BATTLEFIELD_REQUEST_IN_PROGRESS);
}
// This displays the status of individual battlefields, which can be requested through the /battlefield command sui.
messageHandler receiveBattlefieldStatus()
{
string status = params.getString("battlefieldStatus");
int battlefieldState = params.getInt("battlefieldState");
int battlefieldTime = params.getInt("battlefieldTime");
int battlefieldInvitationTime = params.getInt("battlefieldInvitationTime");
int battlefieldSetupTime = params.getInt("battlefieldSetupTime");
string battlefieldName = params.getString("battlefieldName");
string battlefieldNameUnlocalized = params.getString("battlefieldNameUnlocalized");
int rebelPlayers = params.getInt("rebelPlayers");
int rebelGroups = params.getInt("rebelGroups");
int imperialPlayers = params.getInt("imperialPlayers");
int imperialGroups = params.getInt("imperialGroups");
int rebelPlayersActive = params.getInt("rebelPlayersActive");
int imperialPlayersActive = params.getInt("imperialPlayersActive");
string playerInfo = params.getString("playerInfo");
int index = 0;
for(int i = 1, j = BATTLEFIELD_NAMES.length; i < j; i++)
{
if(battlefieldNameUnlocalized.equals(BATTLEFIELD_NAMES[i]))
{
index = i;
break;
}
}
string bfStats = status + "*" + // 0
battlefieldState + "*" + // 1
battlefieldTime + "*" + // 2
battlefieldInvitationTime + "*" + // 3
battlefieldSetupTime + "*" + // 4
battlefieldName + "*" + // 5
battlefieldNameUnlocalized + "*" + // 6
rebelPlayers + "*" + // 7
rebelGroups + "*" + // 8
imperialPlayers + "*" + // 9
imperialGroups + "*" + // 10
rebelPlayersActive + "*" + // 11
imperialPlayersActive + "*" + // 12
playerInfo; // 13
utils.setScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[index], bfStats);
// Do we have all the stats from all the battlefields?
if(!utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[0]) ||
!utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[1]) ||
!utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[2]) ||
!utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[3]))
{
blog(null, "receiveBattlefieldStatus player: " + getName(self) + "(" + self + ") battlefield stats accumilating. " +
BATTLEFIELD_NAMES[0] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[0]) + " " +
BATTLEFIELD_NAMES[1] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[1]) + " " +
BATTLEFIELD_NAMES[2] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[2]) + " " +
BATTLEFIELD_NAMES[3] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[3]) + " ");
return SCRIPT_CONTINUE;
}
blog(null, "receiveBattlefieldStatus player: " + getName(self) + "(" + self + ") all battlefield stats accounted for. " +
BATTLEFIELD_NAMES[0] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[0]) + " " +
BATTLEFIELD_NAMES[1] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[1]) + " " +
BATTLEFIELD_NAMES[2] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[2]) + " " +
BATTLEFIELD_NAMES[3] + ": " + utils.hasScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[3]) + " ");
utils.removeScriptVar(self, "battlefield.requestInProgress");
string bfPlayerInfo = "";
string[][] statusData = new string[4][7];
int bfQueuedFor = -1;
string bfNameQueuedFor = "";
for(int i = 0; i < 4; i++)
{
bfStats = utils.getStringScriptVar(self, "battlefield.status." + BATTLEFIELD_NAMES[i]);
if(bfStats == null || bfStats.length() < 1)
{
return SCRIPT_CONTINUE;
}
string[] bfStatArray = split(bfStats, '*');
if(bfStatArray == null || bfStatArray.length != 14)
{
return SCRIPT_CONTINUE;
}
statusData[i][0] = bfStatArray[5]; // Battlefield's Name
statusData[i][1] = bfStatArray[0]; // What phase the battlefield is in
battlefieldState = utils.stringToInt(bfStatArray[1]);
battlefieldTime = utils.stringToInt(bfStatArray[2]);
battlefieldInvitationTime = utils.stringToInt(bfStatArray[3]);
battlefieldSetupTime = utils.stringToInt(bfStatArray[4]);
battlefieldNameUnlocalized = bfStatArray[6];
rebelPlayers = utils.stringToInt(bfStatArray[7]);
rebelGroups = utils.stringToInt(bfStatArray[8]);
imperialPlayers = utils.stringToInt(bfStatArray[9]);
imperialGroups = utils.stringToInt(bfStatArray[10]);
statusData[i][3] = "" + (rebelPlayers + rebelGroups); // Rebels Queued
statusData[i][4] = "" + (imperialPlayers + imperialGroups); // Imperials Queued
statusData[i][5] = bfStatArray[11]; // Rebels Accepted Invite or Rebels on the battlefield
statusData[i][6] = bfStatArray[12]; // Imperials Accepted Invite or Imperials on the battlefield
playerInfo = bfStatArray[13];
if(playerInfo != null && !playerInfo.equals("null"))
{
bfPlayerInfo = playerInfo;
bfQueuedFor = i;
bfNameQueuedFor = statusData[i][0];
}
// BF Name; Status; Time Left; Rebels Queued; Imperials Queued; Rebels Accepted; Imperials Accepted
if(battlefieldState == pvp.PVP_STATE_BATTLE_ENGAGED)
{
int time = ((int)(pvp.BATTLEFIELD_DURATION + battlefieldTime) - getGameTime());
if(time < 0)
{
time = 0;
}
statusData[i][2] = "" + time + " seconds";
}
else if(battlefieldState == pvp.PVP_STATE_BATTLE_SETUP)
{
int time = ((int)(pvp.BATTLEFIELD_SETUP_WAIT_TIME + battlefieldSetupTime) - getGameTime());
if(time < 0)
{
time = 0;
}
statusData[i][2] = "" + time + " seconds";
}
else if(battlefieldState == pvp.PVP_STATE_INVITE_QUEUE)
{
int time = ((int)(pvp.BATTLEFIELD_INVITATION_WAIT_TIME + battlefieldInvitationTime) - getGameTime());
if(time < 0)
{
time = 0;
}
statusData[i][2] = "" + time + " seconds";
}
else
{
statusData[i][2] = "";
}
}
int faction = factions.getFactionFlag(self);
string[] playerData = new string[0];
if(bfPlayerInfo != null && bfPlayerInfo.length() > 0)
{
playerData = split(bfPlayerInfo, '^');
}
int queuePlace = -1;
int waitTime = 0;
if(playerData != null && playerData.length > 1)
{
if(!playerData[playerData.length - 1].equals("topQueue"))
{
if(faction == factions.FACTION_FLAG_REBEL)
{
queuePlace = rebelGroups;
}
else if(faction == factions.FACTION_FLAG_IMPERIAL)
{
queuePlace = imperialGroups;
}
queuePlace += utils.stringToInt(playerData[playerData.length - 2]);
}
else
{
queuePlace = utils.stringToInt(playerData[playerData.length - 2]);
}
if(playerData.length > 4) // Grouped?
{
int bfTime = utils.stringToInt(playerData[2]);
if(bfTime <= 0)
{
waitTime = 0;
}
else
{
waitTime = getCalendarTime() - bfTime;
}
}
else // Not grouped
{
int bfTime = utils.stringToInt(playerData[1]);
if(bfTime <= 0)
{
waitTime = 0;
}
else
{
waitTime = getCalendarTime() - bfTime;
}
}
}
string queuePosition = "";
string prompt = "";
if(queuePlace > -1)
{
if(bfQueuedFor > -1)
{
prompt = "Queued for: " + bfNameQueuedFor + "\n";
}
prompt += "Your Queue Position: " + (queuePlace + 1) + "\n";
}
if(waitTime > 0)
{
prompt += "Time Waited: " + utils.padTimeDHMS(waitTime);
}
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
string [] table_titles = { "@guild:table_title_name", "@spam:table_title_status", "@spam:table_title_time",
"@spam:table_title_rebels_queued", "@spam:table_title_imperials_queued",
"@spam:table_title_rebels_accepted", "@spam:table_title_imperials_accepted" };
string [] table_types = { "text", "text", "text", "integer", "integer", "integer", "integer" };
int pid = sui.tableRowMajor(self, self, sui.OK_CANCEL, "Battlefield Status", "onBattlefieldCommandResponse", prompt, table_titles, table_types, statusData, false);
utils.setScriptVar(self, "battlefield.pid", pid);
utils.setScriptVar(self, "battlefield.queuedFor", bfQueuedFor);
return SCRIPT_CONTINUE;
}
// This is the /battlefield command's sui messageHandler
messageHandler onBattlefieldCommandResponse()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
int btn = sui.getIntButtonPressed(params);
int index = sui.getTableLogicalIndex(params);
int bfQueuedFor = utils.getIntScriptVar(self, "battlefield.queuedFor");
utils.removeScriptVar(self, "battlefield.queuedFor");
if(btn == sui.BP_OK)
{
if(index < 0 || index > 3)
{
return SCRIPT_CONTINUE;
}
obj_id controller = utils.getObjIdScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[index]);
if(!isIdValid(controller))
{
return SCRIPT_CONTINUE;
}
params = new dictionary();
params.put("player", self);
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
else if(factions.isImperial(self))
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
obj_id group = getGroupObject(self);
obj_id[] members = getGroupMemberIds(group);
boolean grouped = false;
boolean groupLeader = false;
// Initialize option length in the sui for groups
if(isIdValid(group) && members != null && members.length > 1)
{
grouped = true;
groupLeader = (getGroupLeaderId(group) == self);
}
if(utils.hasScriptVar(self, "battlefield.invited"))
{
return SCRIPT_CONTINUE;
}
if(utils.hasScriptVar(self, "battlefield.active"))
{
return SCRIPT_CONTINUE;
}
if(utils.hasScriptVar(self, "battlefield.queue"))
{
string battlefieldName = utils.getStringScriptVar(self, "battlefield.queue");
if(battlefieldName != null || battlefieldName.length() > 0)
{
controller = utils.getObjIdScriptVar(self, "battlefield." + battlefieldName);
}
// Unqueue from battlefield
if(bfQueuedFor == index)
{
if(!groupLeader)
{
sendSystemMessage(self, SID_BATTLEFIELD_REMOVE_FROM_QUEUE);
}
else
{
sendSystemMessage(self, SID_BATTLEFIELD_QUEUE_GROUP_REMOVAL);
params.put("members", members);
}
messageTo(controller, "removePlayerFromQueue", params, 1.0f, false);
return SCRIPT_CONTINUE;
}
return SCRIPT_CONTINUE;
}
int queuing = utils.getIntScriptVar(self, "battlefield.queueing");
if(queuing + 60 < getGameTime())
{
// Not in the battlefield system yet? Then you want to join!
if(!grouped)
{
sendSystemMessage(self, SID_BATTLEFIELD_QUEUE_ATTEMPT);
messageTo(controller, "addPlayerToQueue", params, 1.0f, false);
utils.setScriptVar(self, "battlefield.queuing", getGameTime());
}
else
{
if(!groupLeader)
{
sendSystemMessage(self, SID_BATTLEFIELD_QUEUE_NOT_LEADER);
return SCRIPT_CONTINUE;
}
else
{
params.put("group", group);
params.put("members", members);
sendSystemMessage(self, SID_BATTLEFIELD_ADDING_GROUP_TO_QUEUE);
messageTo(controller, "addGroupToQueue", params, 1.0f, false);
utils.setScriptVar(self, "battlefield.queuing", getGameTime());
}
}
}
else
{
sendSystemMessage(self, SID_BATTLEFIELD_QUEUE_ATTEMPTED_RECENTLY);
}
}
return SCRIPT_CONTINUE;
}
string formatBattlefieldCountdown(int seconds)
{
if(seconds < 0)
{
return "0 seconds";
}
int minutes = seconds / 60;
if(minutes < 0)
{
minutes = 0;
}
string minutesInfo = "" + minutes;
seconds = seconds % 60;
if(seconds < 0)
{
seconds = 0;
}
string secondsInfo = "" + seconds;
if(minutes == 1)
{
minutesInfo += " minute ";
}
else if(minutes == 0)
{
minutesInfo = "";
}
else
{
minutesInfo += " minutes ";
}
if(seconds == 1)
{
secondsInfo += " second";
}
else
{
secondsInfo += " seconds";
}
return minutesInfo + secondsInfo;
}
// Shows the scoreboard for the battle that is currently raging.
void showBattlefieldScoreboard(obj_id self)
{
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
if(!utils.hasScriptVar(self, "battlefield.active"))
{
return;
}
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.active");
if(!isIdValid(controller) || !exists(controller))
{
return;
}
resizeable dictionary [] battlefieldPlayers = pvp.bfActiveGetStatistics(controller);
if(battlefieldPlayers == null || battlefieldPlayers.length < 1)
{
return;
}
string[][] scoreData = pvp.bfStatisticsToArray(battlefieldPlayers, true);
int rebelCount = battlefieldPlayers[0].getInt(pvp.BATTLEFIELD_ACTIVE_REBEL_PLAYERS);
int imperialCount = battlefieldPlayers[0].getInt(pvp.BATTLEFIELD_ACTIVE_IMPERIAL_PLAYERS);
string [] table_titles = { "@guild:table_title_name", "@spam:table_title_faction", "@spam:table_title_kills", "@spam:table_title_assists",
"@spam:table_title_deaths", "@spam:table_title_damage", "@spam:table_title_healing", "@spam:table_title_captures" };
string [] table_types = { "text", "text", "integer", "integer", "integer", "integer", "integer", "integer" };
string statisticsTitle = "Battlefield Statistics";
int battlefieldInvitationTime = utils.getIntScriptVar(controller, "battlefield.queueTime");
int battlefieldTime = utils.getIntScriptVar(controller, "battlefield.battleTime");
int bfState = utils.getIntScriptVar(controller, "battlefield.state");
int imperialScore = utils.getIntScriptVar(controller, "battlefield.imperialScore");
int rebelScore = utils.getIntScriptVar(controller, "battlefield.rebelScore");
string battlefieldStatus = pvp.BATTLEFIELD_STATUS[bfState];
if(battlefieldTime < 0)
{
battlefieldTime = 0;
}
string statisticsInfoStr = COLOR_REBELS + "Rebels: " + rebelCount + "\\#DFDFDF vs. " + COLOR_IMPERIALS + "Imperials: " + imperialCount +
"\n" + COLOR_REBELS + "Rebel Score: " + rebelScore + " " + COLOR_IMPERIALS + "Imperial Score: " + imperialScore +
"\n\\#DFDFDFBattlefield Status: " + battlefieldStatus;
if(bfState == pvp.PVP_STATE_BATTLE_ENGAGED)
{
statisticsInfoStr += "\nBattle Time Left: " + formatBattlefieldCountdown((pvp.BATTLEFIELD_DURATION + battlefieldTime) - getGameTime());
}
else if(bfState == pvp.PVP_STATE_INVITE_QUEUE)
{
statisticsInfoStr += "\nInvitation Time Left: " + formatBattlefieldCountdown((int)((pvp.BATTLEFIELD_INVITATION_WAIT_TIME + battlefieldInvitationTime) - getGameTime()));
}
int pid = sui.tableRowMajor(self, self, sui.OK_CANCEL, statisticsTitle, "onStatisticsMembersResponse", statisticsInfoStr, table_titles, table_types, scoreData, true);
utils.setScriptVar(self, "battlefield.pid", pid);
}
boolean canReceiveReward(obj_id self)
{
if(!isPlayerActive(self))
{
return false;
}
int damage = utils.getIntScriptVar(self, "battlefield.damage");
int healing = utils.getIntScriptVar(self, "battlefield.healing");
int captures = utils.getIntScriptVar(self, "battlefield.captures");
if(damage == 0 && healing == 0 && captures == 0)
{
return false;
}
return true;
}
// Shows the scoreboard for the end of the battle.
void showBattlefieldFinalScoreboard(obj_id self, string battlefieldName)
{
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
if(!utils.hasScriptVar(self, "battlefield.active"))
{
return;
}
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.active");
if(!isIdValid(controller) || !exists(controller))
{
return;
}
resizeable dictionary [] battlefieldPlayers = pvp.bfActiveGetStatistics(controller);
if(battlefieldPlayers == null || battlefieldPlayers.length < 1)
{
return;
}
string[][] scoreData = pvp.bfStatisticsToArray(battlefieldPlayers, true);
int rebelCount = battlefieldPlayers[0].getInt(pvp.BATTLEFIELD_ACTIVE_REBEL_PLAYERS);
int imperialCount = battlefieldPlayers[0].getInt(pvp.BATTLEFIELD_ACTIVE_IMPERIAL_PLAYERS);
string [] table_titles = { "@guild:table_title_name", "@spam:table_title_faction", "@spam:table_title_kills", "@spam:table_title_assists",
"@spam:table_title_deaths", "@spam:table_title_damage", "@spam:table_title_healing", "@spam:table_title_captures" };
string [] table_types = { "text", "text", "integer", "integer", "integer", "integer", "integer", "integer" };
string statisticsTitle = "Battlefield Over";
int imperialScore = utils.getIntScriptVar(controller, "battlefield.imperialScore");
int rebelScore = utils.getIntScriptVar(controller, "battlefield.rebelScore");
string battlefieldStatus = "Unknown";
int gcwCredits = 0;
int tokens = 2; // Loss is 2, Tie is 3, Win is 5
int faction = factions.getFactionFlag(self);
// Tie!
if(imperialScore == rebelScore)
{
// Battle undecided!
battlefieldStatus = "Battle Undecided!";
gcwCredits = gcw.BATTLEFIELD_TIE_POINT_VALUE;
tokens = 3;
}
// Rebels won!
else if(rebelScore > imperialScore)
{
if(faction == factions.FACTION_FLAG_REBEL)
{
// Victory!
battlefieldStatus = COLOR_REBELS + "Rebel Victory!";
gcwCredits = gcw.BATTLEFIELD_VICTORY_POINT_VALUE;
tokens = 5;
}
else
{
// Retreat!
battlefieldStatus = COLOR_IMPERIALS + "Imperials Defeated!";
gcwCredits = gcw.BATTLEFIELD_DEFEAT_POINT_VALUE;
tokens = 2;
}
}
// Imperials Won!
else
{
if(faction == factions.FACTION_FLAG_REBEL)
{
// Retreat!
battlefieldStatus = COLOR_REBELS + "Rebels Defeated!";
gcwCredits = gcw.BATTLEFIELD_DEFEAT_POINT_VALUE;
tokens = 2;
}
else
{
// Victory!
battlefieldStatus = COLOR_IMPERIALS + "Imperial Victory!";
gcwCredits = gcw.BATTLEFIELD_VICTORY_POINT_VALUE;
tokens = 5;
}
}
float multiplier = utils.stringToFloat(getConfigSetting("GameServer", "gcwTokenBonus"));
if(multiplier > 1)
{
tokens *= multiplier; // Precision lost.
}
if(canReceiveReward(self))
{
gcw._grantGcwPoints(null, self, gcwCredits, false, gcw.GCW_POINT_TYPE_GROUND_PVP_REGION, "");
blog(self, "Player: " + self + " Name: " + getName(self) + " GCW Reward: " + gcwCredits + " Token reward: " + tokens);
// Give out battlefield tokens.
obj_id container = utils.getInventoryContainer(self);
if(isIdValid(container) && exists(container))
{
for(int i = 0; i < tokens; i++)
{
if(faction == factions.FACTION_FLAG_REBEL)
{
static_item.createNewItemFunction("item_battlefield_rebel_token_" + battlefieldName, container);
}
else
{
static_item.createNewItemFunction("item_battlefield_imperial_token_" + battlefieldName, container);
}
}
}
if(tokens > 0)
{
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_REWARD_RECEIVED_TOKENS);
pp = prose.setDI(pp, tokens);
sendSystemMessageProse(self, pp);
}
}
else
{
blog(self, "Player: " + self + " Name: " + getName(self) + " did not participate and is not getting rewards.");
}
string statisticsInfoStr = battlefieldStatus +
"\n" + COLOR_REBELS + "Rebel Score: " + rebelScore + " " + COLOR_IMPERIALS + "Imperial Score: " + imperialScore;
int pid = sui.tableRowMajor(self, self, sui.OK_CANCEL, statisticsTitle, "onStatisticsMembersResponse", statisticsInfoStr, table_titles, table_types, scoreData, true);
utils.setScriptVar(self, "battlefield.pid", pid);
}
messageHandler receiveBattlefieldFinale()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
string battlefieldName = params.getString("battlefieldName");
showBattlefieldFinalScoreboard(self, battlefieldName);
return SCRIPT_CONTINUE;
}
// Cluster wide data is a central object that stores the battlefield information. We request what battlefield objects have registered with
// cluster wide data, so we can communicate with them and know what battlefields are active.
trigger OnClusterWideDataResponse(string manage_name, string name, int request_id, string[] element_name_list, dictionary[] data, int lock_key)
{
if(!manage_name.equals("pvp"))
{
return SCRIPT_CONTINUE;
}
LOG("gcw_", "OnClusterWideDataResponse begin manage_name: " + manage_name + " name: " + name);
if(element_name_list != null && element_name_list.length > 0 && data != null && data.length > 0)
{
LOG("gcw_", "OnClusterWideDataResponse manage_name: " + manage_name + " name: " + name + " element_name_list.length: " + element_name_list.length + " data.length: " + data.length);
for(int i = 0, j = element_name_list.length; i < j; i++)
{
for(int k = 0; k < BATTLEFIELD_NUM; k++)
{
if(element_name_list[i].equals(BATTLEFIELD_NAMES[k]))
{
obj_id controller = data[i].getObjId("battlefield");
// Keep this controller on the player, so we can avoid future cluster wide requests.
if(isIdValid(controller))
{
utils.setScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[k], controller);
}
}
}
}
}
else
{
sendSystemMessage(self, SID_BATTLEFIELD_NONE_FOUND);
return SCRIPT_CONTINUE;
}
requestBattlefieldStatus(self);
return SCRIPT_CONTINUE;
}
messageHandler receiveBattlefieldTerminalCapture()
{
int gcwCredits = params.getInt("gcwCredits");
if(gcwCredits <= 0)
{
return SCRIPT_CONTINUE;
}
if(canReceiveReward(self))
{
gcw._grantGcwPoints(null, self, gcwCredits, false, gcw.GCW_POINT_TYPE_GROUND_PVP, "battlefield terminal");
}
return SCRIPT_CONTINUE;
}
// Queue acceptance is sent from the battlefield controller, after it has added you to the queue.
messageHandler receiveBattlefieldQueueAcceptance()
{
if(params == null || params.isEmpty())
{
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[0]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[1]) ||
!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[2]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[3]))
{
getClusterWideData("pvp", "*", true, self);
}
string battlefieldName = params.getString("battlefieldName");
if(battlefieldName == null || battlefieldName.length() < 1)
{
return SCRIPT_CONTINUE;
}
if(utils.hasScriptVar(self, "battlefield.queue") || utils.hasScriptVar(self, "battlefield.invited") || utils.hasScriptVar(self, "battlefield.active"))
{
obj_id controllerWithMessage = params.getObjId("controller");
obj_id controllerQueuedFor = getBattlefieldController(self);
if(isIdValid(controllerWithMessage))
{
params.put("player", self);
// I am a rebel
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
else if(factions.isImperial(self)) // I am an imperial
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_QUEUE_REJECTED);
pp = prose.setTO(pp, localize(new string_id("spam", battlefieldName)));
sendSystemMessageProse(self, pp);
if(controllerWithMessage != controllerQueuedFor)
{
debugSpeakMsg(self, "refuseBattlefieldInvitation controller: " + controllerWithMessage);
messageTo(controllerWithMessage, "refuseBattlefieldInvitation", params, 0.0f, false);
}
return SCRIPT_CONTINUE;
}
}
utils.setScriptVar(self, "battlefield.queue", battlefieldName);
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_QUEUE_ACCEPTANCE);
pp = prose.setTO(pp, localize(new string_id("spam", battlefieldName)));
sendSystemMessageProse(self, pp);
return SCRIPT_CONTINUE;
}
// Make the Yes/No invitation for the player to accept or reject.
messageHandler receiveBattlefieldInvitation()
{
obj_id controller = params.getObjId("battlefieldController");
location loc = params.getLocation("warpInLocation");
string battlefieldName = params.getString("battlefieldName");
int factionToMatch = params.getInt("factionToMatch");
if(loc == null)
{
return SCRIPT_CONTINUE;
}
// Make sure there isn't another invitation on the screen already.
if(utils.hasScriptVar(self, "battlefield.invitation.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.invitation.pid");
utils.removeScriptVar(self, "battlefield.invitation.pid");
forceCloseSUIPage(pid);
}
params.put("player", self);
// This player is already on a battlefield or has been invited to a battlefield. Do not display another invite.
if(utils.hasScriptVar(self, "battlefield.invited") || utils.hasScriptVar(self, "battlefield.active"))
{
obj_id controllerQueuedFor = getBattlefieldController(self);
// I am a rebel
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
else if(factions.isImperial(self)) // I am an imperial
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
if(controller != controllerQueuedFor)
{
messageTo(controller, "refuseBattlefieldInvitation", params, 0.0f, false);
}
return SCRIPT_CONTINUE;
}
// Matching factions should get an invitation. Factions that do not match should not.
if(((factions.isRebel(self) && factionToMatch == factions.FACTION_FLAG_REBEL) ||
(factions.isImperial(self) && factionToMatch == factions.FACTION_FLAG_IMPERIAL)))
{
utils.setScriptVar(self, "battlefield.invitation.controller", controller);
utils.setScriptVar(self, "battlefield.invitation.warpInLocation", loc);
utils.setScriptVar(self, "battlefield.invitation.battlefieldName", battlefieldName);
play2dNonLoopingSound(self, "sound/ui_incoming_im.snd");
int pid = sui.msgbox(self, self, "Your battlefield is ready! Do you wish to go to " + battlefieldName + "?", sui.YES_NO, "@spam:battlefield_invitation_accept_t", sui.MSG_QUESTION, "onBattlefieldInvitationAccept");
utils.setScriptVar(self, "battlefield.invitation.pid", pid);
// The invitation expires after 30 seconds, which is before the reinvitation phase on the battlefield occurs.
messageTo(self, "onBattlefieldInvitationExpire", params, 30.0f, false);
return SCRIPT_CONTINUE;
}
// I am a rebel in an imperial queue
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
else if(factions.isImperial(self)) // I am an imperial in a rebel queue
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
// A rebel being invited into an imperial team?
// An imperial being invited into a rebel team?
// Someone not in either faction?
sendSystemMessage(self, SID_BATTLEFIELD_CANNOT_ENTER_BAD_FACTION);
utils.removeScriptVarTree(self, "battlefield");
messageTo(controller, "refuseBattlefieldInvitation", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
// The battle is over. Clean up the battlefield information on the player and warp them out.
messageHandler receiveBattlefieldOver()
{
// Cleanup scriptvars
buff.removeBuff(self, "battlefield_communication_run");
buff.removeBuff(self, "battlefield_radar_invisibility");
utils.removeScriptVarTree(self, "battlefield");
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
string battlefieldName = params.getString("battlefieldName");
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_OVER_REMOVAL);
pp = prose.setTO(pp, localize(new string_id("spam", battlefieldName)));
sendSystemMessageProse(self, pp);
location loc = params.getLocation("warpLocation");
if(loc == null)
{
return SCRIPT_CONTINUE;
}
utils.setScriptVar(self, "battlefield.kicked_out", true);
pvp.battlefieldWarp(self, loc);
return SCRIPT_CONTINUE;
}
// Once a battlefield has invited you, this handles the invitiation sui options.
messageHandler onBattlefieldInvitationAccept()
{
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.invitation.controller");
string battlefieldName = utils.getStringScriptVar(self, "battlefield.invitation.battlefieldName");
int btn = sui.getIntButtonPressed(params);
params.put("player", self);
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
else if(factions.isImperial(self))
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
params.put("name", getName(self));
if(isIdValid(controller))
{
// Cancelling the invitation removes you from the queue and cleans battlefield information off you.
if(btn == sui.BP_CANCEL)
{
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_QUEUE_REFUSAL);
pp = prose.setTO(pp, battlefieldName);
sendSystemMessageProse(self, pp);
utils.removeScriptVarTree(self, "battlefield");
messageTo(controller, "refuseBattlefieldInvitation", params, 1.0f, false);
}
else // Accepting the battlefield invitation
{
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_QUEUE_ACCEPTED);
pp = prose.setTO(pp, battlefieldName);
sendSystemMessageProse(self, pp);
messageTo(controller, "acceptBattlefieldInvitation", params, 1.0f, false);
utils.setScriptVar(self, "battlefield.invited", controller);
}
}
return SCRIPT_CONTINUE;
}
messageHandler receiveBattlefieldSetupWarp()
{
if(!utils.hasScriptVar(self, "battlefield.invited"))
{
return SCRIPT_CONTINUE;
}
obj_id controller = utils.getObjIdScriptVar(self, "battlefield.invited");
if(!isIdValid(controller))
{
return SCRIPT_CONTINUE;
}
utils.setScriptVar(self, "battlefield.active", controller);
group.leaveGroup(self);
return SCRIPT_CONTINUE;
}
// If you have not selected an option on the invitation in the time allotted, this will handle the expiration of the sui.
messageHandler onBattlefieldInvitationExpire()
{
// Having the battlefield.active scriptvar means you accepted the invitation before it expired.
if(utils.hasScriptVar(self, "battlefield.invited") || !utils.hasScriptVar(self, "battlefield.queue"))
{
blog(self, "onBattlefieldInvitationExpire for self: " + self + " battlefield.invited: " + utils.getObjIdScriptVar(self, "battlefield.invited") + " battlefield.queue: " + utils.getStringScriptVar(self, "battlefield.queue"));
return SCRIPT_CONTINUE;
}
// Cleanup the sui
if(utils.hasScriptVar(self, "battlefield.invitation.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.invitation.pid");
forceCloseSUIPage(pid);
}
obj_id controller = params.getObjId("battlefieldController");
sendSystemMessage(self, SID_BATTLEFIELD_INVITATION_EXPIRED);
utils.removeScriptVarTree(self, "battlefield");
params.put("player", self);
if(factions.isRebel(self))
{
params.put("faction", factions.FACTION_FLAG_REBEL);
}
else if(factions.isImperial(self))
{
params.put("faction", factions.FACTION_FLAG_IMPERIAL);
}
// The refusal has to be done quickly, due to a player possibly sending in a request before the expiration.
messageTo(controller, "refuseBattlefieldInvitation", params, 0.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler receiveBattlefieldQueueRemoval()
{
if(!utils.hasScriptVar(self, "battlefield.queue"))
{
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[0]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[1]) ||
!utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[2]) || !utils.hasScriptVar(self, "battlefield." + BATTLEFIELD_NAMES[3]))
{
getClusterWideData("pvp", "*", true, self);
}
obj_id controllerWithMessage = params.getObjId("battlefieldController");
obj_id controllerQueuedFor = getBattlefieldController(self);
if(controllerWithMessage != controllerQueuedFor)
{
return SCRIPT_CONTINUE;
}
// Cleanup the invitation sui
if(utils.hasScriptVar(self, "battlefield.invitation.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.invitation.pid");
forceCloseSUIPage(pid);
}
// Cleanup the general battlefield sui
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
string battlefieldName = params.getString("battlefieldName");
if(battlefieldName != null && battlefieldName.length() > 0)
{
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_QUEUE_REMOVAL);
pp = prose.setTO(pp, localize(new string_id("spam", battlefieldName)));
sendSystemMessageProse(self, pp);
}
utils.removeScriptVarTree(self, "battlefield");
return SCRIPT_CONTINUE;
}
// If the battlefield didn't meet the team requirements, the battlefield refuses the invitations it sent out.
messageHandler receiveBattlefieldRefusePlayers()
{
// Cleanup the invitation sui
if(utils.hasScriptVar(self, "battlefield.invitation.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.invitation.pid");
forceCloseSUIPage(pid);
}
// Cleanup the general battlefield sui
if(utils.hasScriptVar(self, "battlefield.pid"))
{
int pid = utils.getIntScriptVar(self, "battlefield.pid");
utils.removeScriptVar(self, "battlefield.pid");
forceCloseSUIPage(pid);
}
string battlefieldName = params.getString("battlefieldName");
prose_package pp = new prose_package();
pp = prose.setStringId(pp, SID_BATTLEFIELD_REFUSED);
pp = prose.setTO(pp, localize(new string_id("spam", battlefieldName)));
sendSystemMessageProse(self, pp);
utils.setScriptVar(self, "battlefield.queue", battlefieldName);
utils.removeScriptVar(self, "battlefield.invited");
utils.removeScriptVar(self, "battlefield.active");
return SCRIPT_CONTINUE;
}
// Play the particle for picking up the player
messageHandler receiveBattlefieldPlayParticlePickup()
{
obj_id containedBy = getTopMostContainer(self);
// No playing a spaceship particle inside an object.
if(isIdValid(containedBy) && containedBy != self)
{
return SCRIPT_CONTINUE;
}
location loc = getLocation(self);
obj_id newObject = createObject("object/tangible/theme_park/invisible_object.iff", loc);
setObjVar(newObject, restuss_event.EFFECT_NAME, "republic_gunship_itv_touch_and_go.prt");
setObjVar(newObject, restuss_event.EFFECT_VISABILITY, "visibility-100");
setObjVar(newObject, restuss_event.EFFECT_DELTA, "0");
obj_id[] playerList = { self };
utils.setScriptVar(newObject, instance.PLAYER_ID_LIST, playerList);
attachScript(newObject, "theme_park.restuss_event.restuss_clientfx_controller");
return SCRIPT_CONTINUE;
}
// A controller may force a player to a location.
messageHandler receiveBattlefieldWarpLocation()
{
utils.removeBatchObjVar(self, gcw.LIST_DAILY_KILL_VALUES);
messageTo(self, "battlefieldWarp", params, 1.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler battlefieldWarp()
{
if(params == null || params.isEmpty())
{
blog(self, "Null Params passed in to battlefieldWarp.");
return SCRIPT_CONTINUE;
}
int bfState = params.getInt("bfState");
if(group.isGrouped(self) && bfState != pvp.PVP_STATE_BATTLE_START)
{
obj_id groupObj = getGroupObject(self);
boolean isLeader = false;
if(isIdValid(groupObj))
{
isLeader = group.isLeader(groupObj);
}
blog(self, "Player still grouped. Leader: " + isLeader);
group.leaveGroup(self);
}
location loc = params.getLocation("warpLocation");
obj_id controller = params.getObjId("controller");
if(loc == null)
{
blog(self, "Bad warp location.");
return SCRIPT_CONTINUE;
}
if(isIdValid(controller) && !utils.hasScriptVar(self, "battlefield.active"))
{
utils.setScriptVar(self, "battlefield.active", controller);
blog(controller, "receiveBattlefieldWarpLocation player " + getPlayerName(self) + "("+self+") did not have the scriptvar 'battlefield.active' when they were warping to the battlefield. It has now been set.");
}
pvp.battlefieldWarp(self, loc);
return SCRIPT_CONTINUE;
}
messageHandler receiveBattlefieldAnnouncement()
{
string_id message = params.getStringId("announceId");
sendSystemMessage(self, message);
return SCRIPT_CONTINUE;
}
trigger OnCreatureDamaged(obj_id attacker, obj_id weapon, int[] damage)
{
if(beast_lib.isBeast(attacker) || pet_lib.isPet(attacker))
attacker = getMaster(attacker);
if (!isIdValid(attacker) || !exists(attacker) || !isPlayer(attacker))
{
doLogging("OnCreatureDamaged", "Attacker was invalid");
return SCRIPT_CONTINUE;
}
string selfFac = factions.getFaction(self);
string attFac = factions.getFaction(attacker);
if (selfFac == null || attFac == null)
{
doLogging("OnCreatureDamage", "Self or attacker faction was null");
return SCRIPT_CONTINUE;
}
if (selfFac.equals("Rebel") && !attFac.equals("Imperial"))
{
doLogging("OnCreatureDamage", "I am a rebel and my attacker is not imperial");
return SCRIPT_CONTINUE;
}
if (selfFac.equals("Imperial") && !attFac.equals("Rebel"))
{
doLogging("OnCreatureDamaged", "I am an Imperial and my attcker is not Rebel");
return SCRIPT_CONTINUE;
}
int combinedDamage = 0;
for (int i=0;i<damage.length;i++)
{
combinedDamage += damage[i];
}
resizeable string[] attackList = new string[0];
if (utils.hasResizeableStringBatchScriptVar(self, gcw.LIST_CREDIT_FOR_KILLS))
{
attackList = utils.getResizeableStringBatchScriptVar(self, gcw.LIST_CREDIT_FOR_KILLS);
gcw.clearCreditForKills(self);
}
int arrayPosition = gcw.findAttackerInArray(attackList, attacker);
doLogging("OnCreatureDamaged", "Attackers position in the array is "+arrayPosition);
string damageUpdate = null;
if (arrayPosition == -1)
{
damageUpdate = gcw.packAttackerDamage(attacker, combinedDamage);
doLogging("OnCreatureDamaged", "New entry string: "+damageUpdate);
utils.addElement(attackList, damageUpdate);
}
else
{
int newDamage = combinedDamage + gcw.getDamageFromAttacker(attackList, attacker);
damageUpdate = gcw.packAttackerDamage(attacker, newDamage);
doLogging("OnCreatureDamgaed", "Updated damage string: "+damageUpdate);
attackList[arrayPosition] = damageUpdate;
}
utils.setBatchScriptVar(self, gcw.LIST_CREDIT_FOR_KILLS, attackList);
pvp.bfCreditForDamage(attacker, combinedDamage);
return SCRIPT_CONTINUE;
}
/***** FUNCTIONS **********************************************************************/
void cleanupOldSystemObjVar(obj_id self)
{
if (hasObjVar(self, VAR_PVP_LAST_UPDATE))
removeObjVar(self, VAR_PVP_LAST_UPDATE);
if (hasObjVar(self, VAR_PVP_LAST_KILLS))
removeObjVar(self, VAR_PVP_LAST_KILLS);
}
void doLogging(string section, string message)
{
//LOG("doLogging/player_pvp/"+section, message);
}
// If a player should not be on a battlefield, this messageHandler handles kicking them out.
messageHandler invalidBattlefieldPlayer()
{
location loc = params.getLocation("kickOutLocation");
location goodLoc = locations.getGoodLocationAroundLocation(loc, 1f, 1f, 1.5f, 1.5f);
// debugSpeakMsg(self, "I am being warped out by the battlefield due to not being on the teams.");
if(isGod(self))
{
sendSystemMessage(self, SID_PVP_BATTLEFIELD_KICK_OUT_GODMODE);
return SCRIPT_CONTINUE;
}
sendSystemMessage(self, SID_PVP_BATTLEFIELD_KICK_OUT_INVALID);
if(goodLoc != null)
{
utils.warpPlayer(self, goodLoc);
}
else
{
utils.warpPlayer(self, loc);
}
return SCRIPT_CONTINUE;
}
/********** handlers for battlefield waypoints **************/
messageHandler createBattlefieldWaypoint()
{
if(params == null || params.isEmpty())
return SCRIPT_CONTINUE;
location loc = params.getLocation("terminal_location");
obj_id terminal = params.getObjId("terminal");
if(loc == null)
return SCRIPT_CONTINUE;
obj_id waypoint = createWaypointInDatapad(self, loc);
setWaypointName(waypoint, "Terminal Being Captured");
setWaypointActive(waypoint, true);
setWaypointColor(waypoint, "purple");
//this scriptvar is used to tell the system what waypoint to destroy later
utils.setScriptVar(self, "battlefield.waypoint." + terminal, waypoint);
int gameTime = getGameTime();
utils.setScriptVar(self, "battlefield.waypointTime." + terminal, gameTime);
params.put("gameTime", gameTime);
params.put("timeout", 1);
messageTo(self, "destroyBattlefieldWaypoint", params, 90.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler destroyBattlefieldWaypoint()
{
if(params == null || params.isEmpty())
{
return SCRIPT_CONTINUE;
}
obj_id terminal = params.getObjId("terminal");
obj_id waypoint = obj_id.NULL_ID;
int waypointTime = utils.getIntScriptVar(self, "battlefield.waypointTime." + terminal);
int messageTime = params.getInt("gameTime");
int timeout = params.getInt("timeout");
// If a waypoint has been created that is newer than the old one, don't do this timeout.
if(timeout == 1 && waypointTime != messageTime)
{
return SCRIPT_CONTINUE;
}
//we should have a scriptvar for the waypoints id
if(utils.hasScriptVar(self, "battlefield.waypoint." + terminal))
{
waypoint = utils.getObjIdScriptVar(self, "battlefield.waypoint." + terminal);
}
if(isIdValid(waypoint))
{
destroyWaypointInDatapad(waypoint, self);
}
//dont need to track the scriptvar anymore
utils.removeScriptVar(self, "battlefield.waypoint." + terminal);
utils.removeScriptVar(self, "battlefield.waypointTime." + terminal);
return SCRIPT_CONTINUE;
}