Files
dsrc/sku.0/sys.server/compiled/game/script/ai/ai_combat_assist.scriptlib
T

158 lines
3.6 KiB
Plaintext

include library.ai_lib;
include library.beast_lib;
include library.colors;
include library.factions;
void clearAssist()
{
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
dict.remove("ai.combat.assist");
}
void clearNoAssistCall()
{
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
dict.remove("ai.combat.assist.noAssistCall");
}
boolean isWaiting()
{
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
return dict.getBoolean("ai.combat.assist");
}
int getWaitTime()
{
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
return dict.getInt("ai.combat.assist.waitTime");
}
// This code would fire based on the observer and seemed to ignore line of sight checks. It is disabled
// in favor of the defender calling for help explicitly (below in callForAssist).
void assist(obj_id defender, obj_id target)
{
/**
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
if (!ai_lib.isInCombat(self))
{
//showFlyText(self, new string_id("npc_reaction/flytext", "alert"), 2.0f, colors.ORANGERED);
faceTo(self, target);
dict.put("ai.combat.assist.waitTime", isPlayer(defender) ? rand(1.0f, 2.0f) : rand(3.0f, 4.0f));
dict.put("ai.combat.assist", true);
dict.put("ai.combat.assist.noAssistCall", true);
}
startCombat(self, target);
**/
}
boolean canCallForAssist()
{
const obj_id self = getSelf();
deltadictionary dict = self.getScriptVars();
return !dict.getBoolean("ai.combat.assist.noAssistCall");
}
boolean callForAssist()
{
obj_id self = getSelf();
//we dont want beasts asking for help
if(beast_lib.isBeast(self))
return false;
//we dont want decoys or holograms asking for help
if(hasObjVar(self, "hologram_performer"))
return false;
obj_id target = getTarget(self);
if (!isIdValid(target) || !exists(target))
return false;
string type = getStringObjVar(self, "creature_type");
dictionary aiData = dataTableGetRow("datatables/mob/creatures.iff", type);
float assistRange = aiData.getFloat("assist");
string socialGroup = aiData.getString("socialGroup");
string pvpFaction = aiData.getString("pvpFaction");
if (assistRange == 0.0f)
return false;
obj_id[] creatures = getNPCsInRange(self, assistRange);
if (creatures == null || creatures.length == 0)
return false;
resizeable obj_id[] callToList = new obj_id[0];
for (int i=0;i<creatures.length;i++)
{
if (creatures[i] == self)
continue;
if (!isIdValid(creatures[i]) || !exists(creatures[i]))
continue;
if (isInvulnerable(creatures[i]))
continue;
if (isPlayer(target) && factions.ignorePlayer(target, creatures[i]))
continue;
if (isDead(creatures[i]))
continue;
if (isIdValid(getMaster(creatures[i])))
continue;
if (!canSee(self, creatures[i]))
continue;
if (!factions.shareSocialGroup(self, creatures[i]) && !factions.areCreaturesAllied(self, creatures[i]))
continue;
if (Math.abs(getLocation(self).y - getLocation(creatures[i]).y) > 6.0f)
continue;
callToList.add(creatures[i]);
}
if (callToList == null || callToList.length == 0)
return false;
for (int q=0;q<callToList.length;q++)
{
startAssistedCombat(callToList[q], target);
}
return true;
}
void startAssistedCombat(obj_id creature, obj_id target)
{
deltadictionary dict = creature.getScriptVars();
if (!ai_lib.isInCombat(creature))
{
faceTo(creature, target);
dict.put("ai.combat.assist.waitTime", isPlayer(target) ? rand(1.0f, 2.0f) : rand(3.0f, 4.0f));
dict.put("ai.combat.assist", true);
dict.put("ai.combat.assist.noAssistCall", true);
}
startCombat(creature, target);
}