Files
dsrc/sku.0/sys.server/compiled/game/script/ai/smuggler_medic.script
T
2015-10-30 13:30:22 -05:00

217 lines
4.4 KiB
Plaintext

include library.ai_lib;
include library.buff;
include library.chat;
include library.prose;
include library.utils;
include library.xp;
// This is the length of time that the buddy stays around before running away.
const float BUDDY_DURATION = 62.0f;
trigger OnAttach()
{
messageTo(self, "handleGreeting", null, 2.0f, false);
messageTo(self, "handleRunAway", null, BUDDY_DURATION, false);
messageTo(self, "castOnMaster", null, 1.0f, false);
setObjVar( self, "ai.pet", true );
return SCRIPT_CONTINUE;
}
trigger OnExitedCombat()
{
if(utils.hasScriptVar(self, "runningaway"))
return SCRIPT_CONTINUE;
messageTo(self, "handleNewTarget", null, 2.0f, false);
return SCRIPT_CONTINUE;
}
// This function does not need to take into account current action, as the summoned medic only lasts for a short time.
messageHandler castOnMaster()
{
obj_id master = getMaster(self);
if(isIdValid(master))
{
float healthPercent = (float)getAttrib(master, HEALTH) / (float)getMaxAttrib(master, HEALTH);
int myLevel = getLevel(self);
if(healthPercent < 0.50f)
{
if(myLevel < 10)
{
queueCommand(self, ##"me_bacta_grenade_1", master, "", COMMAND_PRIORITY_FRONT);
}
else
if(myLevel < 30)
{
queueCommand(self, ##"me_bacta_grenade_2", master, "", COMMAND_PRIORITY_FRONT);
}
else
if(myLevel < 58)
{
queueCommand(self, ##"me_bacta_grenade_3", master, "", COMMAND_PRIORITY_FRONT);
}
else
if(myLevel < 78)
{
queueCommand(self, ##"me_bacta_grenade_4", master, "", COMMAND_PRIORITY_FRONT);
}
else
if(myLevel < 91)
{
queueCommand(self, ##"me_bacta_grenade_5", master, "", COMMAND_PRIORITY_FRONT);
}
}
else
{
// Medic's Health Buff is gained at level 46.
if(myLevel >= 46 && !buff.hasBuff(master, "me_buff_health"))
{
queueCommand(self, ##"me_buff_health_1", master, "", COMMAND_PRIORITY_FRONT);
}
}
}
messageTo(self, "castOnMaster", null, 2.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler handleGreeting()
{
obj_id master = getMaster(self);
if(isIdValid(master))
{
string name = getFirstName(master);
int phraseId = rand(1, 6);
string greeting = "smuggler_medic_greeting_" + phraseId;
prose_package pp = new prose_package();
pp = prose.setStringId(pp, new string_id("combat_effects", greeting));
pp = prose.setTU(pp, name);
chat.chat(self, master, chat.CHAT_SAY, null, chat.ChatFlag_targetGroupOnly, pp);
}
return SCRIPT_CONTINUE;
}
messageHandler handleNewTarget()
{
obj_id master = getMaster(self);
if(isIdValid(master))
{
obj_id newTarget = getHateTarget(master);
if(isIdValid(newTarget))
startCombat(self, newTarget);
else
messageTo(self, "handleRunAway", null, 2.0f, false);
}
else
{
messageTo(self, "handleRunAway", null, 2.0f, false);
}
return SCRIPT_CONTINUE;
}
messageHandler handleRunAway()
{
if(isDead(self))
{
messageTo(self, "handleCleanUp", null, 15.0f, false);
return SCRIPT_CONTINUE;
}
if(utils.hasScriptVar(self, "runningaway"))
return SCRIPT_CONTINUE;
obj_id master = getMaster(self);
if(isIdValid(master))
{
string name = getFirstName(master);
int phraseId = rand(1, 6);
string goodbye = "smuggler_medic_goodbye_" + phraseId;
prose_package pp = new prose_package();
pp = prose.setStringId(pp, new string_id("combat_effects", goodbye));
pp = prose.setTU(pp, name);
chat.chat(self, master, chat.CHAT_SAY, null, chat.ChatFlag_targetGroupOnly, pp);
}
stopCombat(self);
setMaster(self, null);
setInvulnerable(self, true);
if(isIdValid(master))
ai_lib.pathAwayFrom(self, master);
utils.setScriptVar(self, "runningaway", 1);
messageTo(self, "handleCleanUp", null, 15.0f, false);
return SCRIPT_CONTINUE;
}
messageHandler handleCleanUp()
{
destroyObject(self);
return SCRIPT_CONTINUE;
}
trigger OnIncapacitated(obj_id attacker)
{
obj_id weapon = getCurrentWeapon(self);
if( isIdValid(weapon) && !isDefaultWeapon(weapon) )
{
destroyObject(weapon);
}
//clear corpse inventory
obj_id cInv = utils.getInventoryContainer(self);
if(isIdValid(cInv))
{
utils.emptyContainerExceptStorytellerLoot(cInv);
}
ai_lib.clearCombatData();
setObjVar(self, xp.VAR_LANDED_DEATHBLOW, attacker);
if(!kill(self))
{
obj_id[] haters = getHateList(self);
if (haters.length > 0)
{
for(int i=0;i<haters.length;i++)
{
removeHateTarget(haters[i], self);
}
}
destroyObject(self);
}
clearCondition(self, CONDITION_INTERESTING);
return SCRIPT_CONTINUE;
}