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

639 lines
16 KiB
Plaintext

include library.ai_lib;
include library.buff;
include library.chat;
include library.create;
include library.factions;
include library.gcw;
include library.groundquests;
include library.restuss_event;
include library.resource;
include library.static_item;
include library.sui;
include library.stealth;
include library.trial;
include library.utils;
const string_id SID_THERE_IS_NO_GUARD = new string_id("gcw", "there_is_no_guard_to_entertain");
const string_id SID_PATROL_ALREADY_ENTERTAINED = new string_id("gcw", "patrol_point_already_entertained");
const int ENTERTAINMENT_TIMER = 300;
const string[] lowImperials =
{
"gcw_city_imperial_1"
};
const string[] normalImperials =
{
"gcw_city_imperial_black",
"gcw_city_imperial_2",
"gcw_city_imperial_sandtrooper"
};
const string[] eliteImperials =
{
"gcw_city_imperial_3",
"gcw_city_imperial_black_sgt",
"gcw_city_imperial_black_darkt",
"gcw_city_imperial_sandtrooper_sgt"
};
const string[] lowRebels =
{
"gcw_city_rebel_grunt_assault",
"gcw_city_rebel_grunt_defense"
};
const string[] normalRebels =
{
"gcw_city_rebel_commando_assault",
"gcw_city_rebel_commando_defense"
};
const string[] eliteRebels =
{
"gcw_city_rebel_specforce_assault",
"gcw_city_rebel_specforce_defense"
};
trigger OnAttach()
{
setObjVar(self, gcw.GCW_DEF_TOOL_TEMPLATE_OBJVAR, "object/tangible/gcw/crafting_quest/gcw_spawner_tool.iff");
setObjVar(self, gcw.GCW_OFF_TOOL_TEMPLATE_OBJVAR, "object/tangible/gcw/crafting_quest/gcw_patrol_tool.iff");
return SCRIPT_CONTINUE;
}
trigger OnInitialize()
{
//This object has the script defined in the template
//OnAttach() will not fire properly.
messageTo(self, "handleGCWPatrol", null, rand(5, 10), false);
dictionary params = new dictionary();
location loc = getLocation(self);
params.put("particleLoc", loc);
int playIconTime = getGameTime();
params.put("iconMessageTime", playIconTime);
utils.setScriptVar(self, "iconMessageTime", playIconTime);
messageTo(self, "playQuestIcon", params, 2.0f, false);
return SCRIPT_CONTINUE;
};
trigger OnGetAttributes(obj_id player, string[] names, string[] attribs)
{
if(!exists(self))
{
return SCRIPT_CONTINUE;
}
int idx = utils.getValidAttributeIndex(names);
if(idx == -1)
{
return SCRIPT_CONTINUE;
}
names[idx] = "patrol_entertained";
string status = "No";
if(utils.getBooleanScriptVar(self, "entertained"))
{
status = "Yes";
}
attribs[idx] = status;
idx++;
names[idx] = "object_repaired";
int repairCount = getIntObjVar(self, gcw.GCW_OBJECT_REPAIR_COUNT);
if(repairCount > 0)
{
attribs[idx] = ""+repairCount+" out of "+gcw.REPAIR_COUNT_MAX;
}
else
{
attribs[idx] = "Never Repaired";
}
idx++;
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuRequest(obj_id player, menu_info mi)
{
if(!utils.hasScriptVar(self, "faction"))
{
LOG("gcw_patrol_point","no faction on patrol obj");
return SCRIPT_CONTINUE;
}
if(!factions.isPlayerSameGcwFactionAsSchedulerObject(player, self))
{
LOG("gcw_patrol_point","player not my faction");
if(!groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_SCOUT_QUEST)
&& !groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_DESTROY_QUEST))
{
LOG("gcw_patrol_point","player doesn't have a quest that works with patrol point");
return SCRIPT_CONTINUE;
}
LOG("gcw_patrol_point","OnObjectMenuRequest: Opposing player has a quest that works with patrol point");
menu_info_data data = mi.getMenuItemByType(menu_info_types.ITEM_USE);
if(data != null)
data.setServerNotify (true);
}
else
{
if(utils.isProfession(player, utils.ENTERTAINER))
{
LOG("gcw_patrol_point","player is entertainer");
if(utils.hasScriptVar(self, "entertained") && utils.getBooleanScriptVar(self, "entertained"))
{
return SCRIPT_CONTINUE;
}
}
else if(utils.isProfession(player, utils.TRADER))
{
LOG("gcw_patrol_point","OnObjectMenuRequest player is trader");
if(!gcw.canGcwObjectBeRepaired(self))
{
LOG("gcw_patrol_point","OnObjectMenuRequest no repair needed");
return SCRIPT_CONTINUE;
}
if(!gcw.hasConstructionOrRepairTool(player, self))
{
LOG("gcw_patrol_point","OnObjectMenuRequest no resources");
return SCRIPT_CONTINUE;
}
}
menu_info_data data = mi.getMenuItemByType(menu_info_types.ITEM_USE);
if(data != null)
data.setServerNotify(true);
}
return SCRIPT_CONTINUE;
}
trigger OnObjectMenuSelect(obj_id player, int item)
{
LOG("gcw_patrol_point", "OnObjectMenuSelect");
if(!isIdValid(player) || !exists(player) || isIncapacitated(player) || isDead(player) || factions.isOnLeave(player))
{
return SCRIPT_CONTINUE;
}
if(!utils.hasScriptVar(self, "faction"))
{
LOG("gcw_patrol_point","no faction on patrol obj");
return SCRIPT_CONTINUE;
}
int faction = utils.getIntScriptVar(self, "faction");
if(faction < 0)
{
LOG("gcw_patrol_point","faction invalid on patrol obj");
return SCRIPT_CONTINUE;
}
if(item != menu_info_types.ITEM_USE)
return SCRIPT_CONTINUE;
if(!factions.isPlayerSameGcwFactionAsSchedulerObject(player, self))
{
LOG("gcw_patrol_point","OnObjectMenuSelect - player not my faction");
if(!groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_SCOUT_QUEST)
&& !groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_DESTROY_QUEST))
{
LOG("gcw_patrol_point","player doesn't have a quest that works with patrol point");
return SCRIPT_CONTINUE;
}
LOG("gcw_patrol_point","OnObjectMenuSelect - Opposing player has a quest that works with patrol point");
if(groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_SCOUT_QUEST))
{
LOG("gcw_patrol_point","gcw_spy_scout_patrol");
gcw.useGcwObjectForQuest(player, self, gcw.GCW_SPY_PATROL_SCOUT_QUEST);
return SCRIPT_CONTINUE;
}
else if(groundquests.isQuestActive(player, gcw.GCW_SPY_PATROL_DESTROY_QUEST))
{
LOG("gcw_patrol_point","gcw_spy_destroy_patrol");
if(!buff.hasBuff(player, gcw.BUFF_SPY_EXPLOSIVES))
return SCRIPT_CONTINUE;
long counter = buff.getBuffStackCount(player, gcw.BUFF_SPY_EXPLOSIVES);
if(counter <= 0)
return SCRIPT_CONTINUE;
gcw.useGcwObjectForQuest(player, self, gcw.GCW_SPY_PATROL_DESTROY_QUEST);
return SCRIPT_CONTINUE;
}
LOG("gcw_patrol_point","could not find a valid quest!!!");
return SCRIPT_CONTINUE;
}
else
{
LOG("gcw_patrol_point","OnObjectMenuSelect - player is my faction");
if(utils.isProfession(player, utils.ENTERTAINER))
{
LOG("gcw_patrol_point", "is entertainer");
if(utils.hasScriptVar(self, "entertained") && utils.getBooleanScriptVar(self, "entertained"))
{
sendSystemMessage(player, SID_PATROL_ALREADY_ENTERTAINED);
return SCRIPT_CONTINUE;
}
obj_id kit = utils.getObjIdScriptVar(self, "creator");
if(!isIdValid(kit) || !exists(kit))
{
return SCRIPT_CONTINUE;
}
int patrolType = getIntObjVar(kit, "patrolType");
if(patrolType == 0) //defensive patrol point
{
LOG("gcw_patrol_point","patrol is defensive");
obj_id guardToEntertain = utils.getObjIdScriptVar(self, gcw.GCW_NPC_SCRIPTVAR_FLAG);
if(!isValidId(guardToEntertain) || !exists(guardToEntertain))
{
//There is no Guard to entertain
sendSystemMessage(player, SID_THERE_IS_NO_GUARD);
return SCRIPT_CONTINUE;
}
}
else if(patrolType == 1) //offensive
{
LOG("gcw_patrol_point","patrol is offensive");
if(utils.hasScriptVar(self, gcw.GCW_NPC_BEING_ENTERTAINED))
{
LOG("gcw_patrol_point","GCW_NPC_BEING_ENTERTAINED scriptvar found");
obj_id npcBeingEntertained = utils.getObjIdScriptVar(self, gcw.GCW_NPC_BEING_ENTERTAINED);
if(isValidId(npcBeingEntertained) && exists(npcBeingEntertained) && !ai_lib.isDead(npcBeingEntertained))
{
return SCRIPT_CONTINUE;
}
}
string npcName = lowRebels[rand(0, lowRebels.length - 1)];
if(faction == factions.FACTION_FLAG_IMPERIAL)
{
npcName = lowImperials[rand(0, lowImperials.length - 1)];
}
obj_id npc = create.object(npcName, getLocation(self));
if(!isIdValid(npc) || !exists(npc))
{
return SCRIPT_CONTINUE;
}
//Put a scriptvar on the patrol to find the npc later.
//utils.setScriptVar(self, gcw.GCW_NPC_SCRIPTVAR_FLAG, npc);
//flag the spawned npc for clean up once the quest is done
utils.setScriptVar(self, gcw.GCW_NPC_BEING_ENTERTAINED, npc);
utils.setScriptVar(npc, gcw.GCW_NPC_CLEANUP_FLAG, 1);
setObjVar(npc, gcw.GCW_PATROL_OBJ, self);
pathTo(npc, getLocation(player));
//You have 30 seconds to entertain me!
chat.chat(npc, new string_id("gcw", "you_have_thirty_seconds"));
//clean up the npc if not entertained in 30 secs
dictionary webster = new dictionary();
webster.put("npc",npc);
webster.put("player",player);
messageTo(self, "handleOffensiveEntertainedNpcCleanUp", webster, 30.0f, false);
}
if(groundquests.hasCompletedQuest(player, gcw.GCW_ENTERTAINER_PATROL_QUEST))
{
groundquests.clearQuest(player, gcw.GCW_ENTERTAINER_PATROL_QUEST);
}
if(!groundquests.isQuestActive(player, gcw.GCW_ENTERTAINER_PATROL_QUEST))
{
groundquests.grantQuest(player, gcw.GCW_ENTERTAINER_PATROL_QUEST);
}
}
else if(utils.isProfession(player, utils.TRADER))
{
LOG("gcw_patrol_point","OnObjectMenuSelect player is trader");
if(!gcw.canGcwObjectBeRepaired(self))
{
LOG("gcw_patrol_point", "OnObjectMenuSelect Patrol not repairable.");
sendSystemMessage(player, gcw.SID_DOESNT_NEED_REPAIR);
return SCRIPT_CONTINUE;
}
if(!gcw.hasConstructionOrRepairTool(player, self))
{
LOG("gcw_patrol_point", "OnObjectMenuSelect No repair tool.");
gcw.playerSystemMessageResourceNeeded(player, self, false);
return SCRIPT_CONTINUE;
}
LOG("gcw_patrol_point", "OnObjectMenuSelect Quest check.");
if(groundquests.isQuestActive(player, gcw.GCW_REPAIR_PATROL_QUEST))
{
if(gcw.useGcwObjectForQuest(player, self, gcw.GCW_REPAIR_PATROL_QUEST))
{
LOG("gcw_patrol_point", "OnObjectMenuSelect useConstructionOrRepairTool.");
gcw.useConstructionOrRepairTool(player, self);
}
return SCRIPT_CONTINUE;
}
if(groundquests.hasCompletedQuest(player, gcw.GCW_REPAIR_PATROL_QUEST))
{
LOG("gcw_patrol_point", "OnObjectMenuSelect Clear repair patrol quest.");
groundquests.clearQuest(player, gcw.GCW_REPAIR_PATROL_QUEST);
}
if(!groundquests.isQuestActive(player, gcw.GCW_REPAIR_PATROL_QUEST))
{
LOG("gcw_patrol_point", "OnObjectMenuSelect Grant repair patrol quest.");
groundquests.grantQuest(player, gcw.GCW_REPAIR_PATROL_QUEST);
}
}
}
return SCRIPT_CONTINUE;
}
int getConstructionQuestsCompleted(obj_id pylon)
{
int completed = 0;
if(!isIdValid(pylon) || !exists(pylon))
{
return 0;
}
if(hasObjVar(pylon, "gcw.constructionQuestsCompleted"))
{
completed = getIntObjVar(pylon, "gcw.constructionQuestsCompleted");
}
return completed;
}
messageHandler handleGCWPatrol()
{
int faction = -1;
if(utils.hasScriptVar(self, "faction"))
{
faction = utils.getIntScriptVar(self, "faction");
}
obj_id kit = utils.getObjIdScriptVar(self, "creator");
if(!isIdValid(kit) || !exists(kit))
{
return SCRIPT_CONTINUE;
}
int patrolType = getIntObjVar(kit, "patrolType");
int construction = getConstructionQuestsCompleted(kit);
string npcName = "";
if(construction < 1)
{
return SCRIPT_CONTINUE;
}
else if(construction < gcw.GCW_CONSTRUCTION_MAXIMUM / 2)
{
if(faction == factions.FACTION_FLAG_REBEL)
{
npcName = lowRebels[rand(0, lowRebels.length - 1)];
}
else if(faction == factions.FACTION_FLAG_IMPERIAL)
{
npcName = lowImperials[rand(0, lowImperials.length - 1)];
}
}
else if(construction < gcw.GCW_CONSTRUCTION_MAXIMUM)
{
if(faction == factions.FACTION_FLAG_REBEL)
{
npcName = normalRebels[rand(0, normalRebels.length - 1)];
}
else if(faction == factions.FACTION_FLAG_IMPERIAL)
{
npcName = normalImperials[rand(0, normalImperials.length - 1)];
}
}
else if(construction >= gcw.GCW_CONSTRUCTION_MAXIMUM)
{
if(faction == factions.FACTION_FLAG_REBEL)
{
npcName = eliteRebels[rand(0, eliteRebels.length - 1)];
}
else if(faction == factions.FACTION_FLAG_IMPERIAL)
{
npcName = eliteImperials[rand(0, eliteImperials.length - 1)];
}
}
if(getSchedulerNPCs(kit, "gcwPatrol") < 0)
{
return SCRIPT_CONTINUE;
}
obj_id npc = null;
//DEFENSIVE PATROL POINT THIS BLOCK
if(patrolType == 0 && getSchedulerNPCs(kit, "gcwPatrol") < 500)
{
obj_id currentPatrol = utils.getObjIdScriptVar(kit, "currentPatrol");
if(!isIdValid(currentPatrol) || !exists(currentPatrol) || isIncapacitated(currentPatrol) || isDead(currentPatrol))
{
npc = trial.createSchedulerNPC(kit, self, npcName);
utils.setScriptVar(kit, "currentPatrol", npc);
}
else
{
//this is so we can perform operations on the existing patrol NPC below
npc = currentPatrol;
}
// Set NPC's movement to 0
if(isIdValid(npc) && exists(npc))
{
setBaseRunSpeed(npc, 0);
setBaseWalkSpeed(npc, 0);
setObjVar(npc, "forceNoMovement", 1);
}
}
//OFFENSIVE PATROL POINT THIS BLOCK
if(patrolType == 1 && getSchedulerNPCs(kit, "gcwPatrol") < 500)
{
npc = trial.createSchedulerNPC(kit, self, npcName);
}
//set the patrol object on the NPC
setObjVar(npc, gcw.GCW_PATROL_OBJ, self);
if(utils.hasScriptVar(self, "entertained") && isValidId(npc))
{
buff.applyBuff(npc, gcw.GCW_NPC_ENTERTAINED_BUFF, -1.0f);
}
messageTo(self, "handleGCWPatrol", null, 60.0f + rand(0, 30), false);
return SCRIPT_CONTINUE;
}
int getSchedulerNPCs(obj_id kit, string npcID)
{
if(!isIdValid(kit) || !exists(kit))
{
return -1;
}
obj_id kitParent = trial.getParent(kit);
if(!isIdValid(kitParent) || !exists(kitParent))
{
return -1;
}
obj_id[] npcs = trial.getObjectsInInstanceBySpawnId(trial.getParent(kit), npcID);
if(npcs == null)
{
return 0;
}
return npcs.length;
}
messageHandler destroyGCWPatrol()
{
trial.cleanupObject(self);
return SCRIPT_CONTINUE;
}
messageHandler handleOffensiveEntertainedNpcCleanUp()
{
if(params == null)
{
return SCRIPT_CONTINUE;
}
obj_id npc = params.getObjId("npc");
if(!isValidId(npc) || !exists(npc))
return SCRIPT_CONTINUE;
obj_id player = params.getObjId("player");
if(isValidId(player) || exists(player))
{
//NPC being entertained
if(utils.hasScriptVar(npc, "ai.listeningTo"))
{
obj_id entertainedBy = utils.getObjIdScriptVar(npc, "ai.listeningTo");
if(isValidId(entertainedBy) && exists(entertainedBy))
{
if(entertainedBy == player)
return SCRIPT_CONTINUE;
}
}
}
int pid = getIntObjVar(player, sui.COUNTDOWNTIMER_SUI_VAR);
if(pid > 0)
{
forceCloseSUIPage(pid);
}
trial.cleanupObject(npc);
return SCRIPT_CONTINUE;
}
messageHandler flagGCWPatrolEntertained()
{
obj_id kit = utils.getObjIdScriptVar(self, "creator");
if(!isValidId(kit))
{
return SCRIPT_CONTINUE;
}
int construction = getConstructionQuestsCompleted(kit);
if(construction < 1)
{
return SCRIPT_CONTINUE;
}
int patrolType = getIntObjVar(kit, "patrolType");
if(patrolType == 0)
{
obj_id currentPatrol = utils.getObjIdScriptVar(kit, "currentPatrol");
if(isValidId(currentPatrol) && exists(currentPatrol))
{
buff.applyBuff(currentPatrol, gcw.GCW_NPC_ENTERTAINED_BUFF, -1.0f);
}
}
utils.setScriptVar(self, "entertained", true);
messageTo(self, "removeGCWPatrolEntertained", null, ENTERTAINMENT_TIMER, false);
return SCRIPT_CONTINUE;
}
messageHandler removeGCWPatrolEntertained()
{
utils.removeScriptVar(self, "entertained");
utils.removeScriptVar(self, "entertainment_locked");
return SCRIPT_CONTINUE;
}
messageHandler playQuestIcon()
{
gcw.playQuestIconHandler(self, params);
return SCRIPT_CONTINUE;
}
trigger OnDeath(obj_id killer, obj_id corpseId)
{
handleDestroyPatrol(self, killer);
return SCRIPT_CONTINUE;
}
trigger OnObjectDisabled(obj_id killer)
{
handleDestroyPatrol(self, killer);
return SCRIPT_CONTINUE;
}
void handleDestroyPatrol(obj_id self, obj_id killer)
{
playClientEffectLoc(self, "clienteffect/combat_explosion_lair_large.cef", getLocation(self), 0);
setInvulnerable(self, true);
messageTo(self, "destroyGCWPatrol", null, 1f, false);
gcw.gcwInvasionCreditForDestroy(killer);
return;
}