BossHP refactor, untested

This commit is contained in:
BotoX 2019-11-04 11:02:31 +01:00
parent 8b2441866b
commit 6faaed6ca2

View File

@ -21,6 +21,8 @@ ConVar g_hCvar_DebugMode;
char g_sHUDText[256]; char g_sHUDText[256];
char g_aHurtEntityToBossIdx[2048] = {0xFF, ...};
public Plugin myinfo = public Plugin myinfo =
{ {
name = "BossHP", name = "BossHP",
@ -423,83 +425,18 @@ public void OnEntitySpawned(int entity, const char[] classname)
LogDebugMessage("Hooked trigger %s:%s", sTrigger, sOutput); LogDebugMessage("Hooked trigger %s:%s", sTrigger, sOutput);
} }
char sShowTrigger[64];
Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
int iShowTriggerHammerID = -1;
if(sShowTrigger[0] == '#')
iShowTriggerHammerID = StringToInt(sShowTrigger[1]);
if((iShowTriggerHammerID == -1 && sShowTrigger[0] && StrEqual(sTargetname, sShowTrigger)) || iShowTriggerHammerID == iHammerID)
{
char sShowOutput[64];
Config.GetShowOutput(sShowOutput, sizeof(sShowOutput));
if(StrEqual(sShowOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostShow);
}
else
{
bool Once = !Config.bMultiTrigger;
HookSingleEntityOutput(entity, sShowOutput, OnEntityOutputShow, Once);
}
LogDebugMessage("Hooked showtrigger %s:%s", sShowTrigger, sShowOutput);
}
char sKillTrigger[64];
Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
int iKillTriggerHammerID = -1;
if(sKillTrigger[0] == '#')
iKillTriggerHammerID = StringToInt(sKillTrigger[1]);
if((iKillTriggerHammerID == -1 && sKillTrigger[0] && StrEqual(sTargetname, sKillTrigger)) || iKillTriggerHammerID == iHammerID)
{
char sKillOutput[64];
Config.GetKillOutput(sKillOutput, sizeof(sKillOutput));
if(StrEqual(sKillOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostKill);
}
else
{
bool Once = !Config.bMultiTrigger;
HookSingleEntityOutput(entity, sKillOutput, OnEntityOutputKill, Once);
}
LogDebugMessage("Hooked killtrigger %s:%s", sKillTrigger, sKillOutput);
}
char sHurtTrigger[64];
Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
int iHurtTriggerHammerID = -1;
if(sHurtTrigger[0] == '#')
iHurtTriggerHammerID = StringToInt(sHurtTrigger[1]);
if((iHurtTriggerHammerID == -1 && sHurtTrigger[0] && StrEqual(sTargetname, sHurtTrigger)) || iHurtTriggerHammerID == iHammerID)
{
char sHurtOutput[64];
Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
if(StrEqual(sHurtOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostHurt);
}
else
{
HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt);
}
LogDebugMessage("Hooked hurttrigger %s:%s", sHurtTrigger, sHurtOutput);
}
} }
} }
public void OnEntityDestroyed(int entity)
{
if(!g_aConfig)
return;
if(entity >= 0 && entity < sizeof(g_aHurtEntityToBossIdx))
g_aHurtEntityToBossIdx[entity] = 0xFF;
}
void OnTrigger(int entity, const char[] output, SDKHookType HookType = view_as<SDKHookType>(-1)) void OnTrigger(int entity, const char[] output, SDKHookType HookType = view_as<SDKHookType>(-1))
{ {
char sTargetname[64]; char sTargetname[64];
@ -753,71 +690,20 @@ void OnKillTrigger(int entity, const char[] output, SDKHookType HookType = view_
} }
} }
void OnHurtTrigger(int entity, const char[] output, int activator, float damage = 1.0) void OnHurtTrigger(int entity, int activator, float damage = 1.0)
{ {
char sTargetname[64]; int BossIdx = g_aHurtEntityToBossIdx[entity];
GetEntPropString(entity, Prop_Data, "m_iName", sTargetname, sizeof(sTargetname)); if(BossIdx == 0xFF)
return;
int iHammerID = GetEntProp(entity, Prop_Data, "m_iHammerID"); CBoss Boss = g_aBoss.Get(BossIdx);
int iTemplateNum = -1; Call_StartForward(g_hFwd_OnBossDamaged);
int iTemplateLoc = FindCharInString(sTargetname, '&', true); Call_PushCell(Boss);
if(iTemplateLoc != -1) Call_PushCell(Boss.dConfig);
{ Call_PushCell(activator);
iTemplateNum = StringToInt(sTargetname[iTemplateLoc + 1]); Call_PushFloat(damage);
sTargetname[iTemplateLoc] = 0; Call_Finish();
}
for(int i = 0; i < g_aConfig.Length; i++)
{
CConfig Config = g_aConfig.Get(i);
char sHurtTrigger[64];
Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
if(!sHurtTrigger[0])
continue;
int iHurtTriggerHammerID = -1;
if(sHurtTrigger[0] == '#')
{
iHurtTriggerHammerID = StringToInt(sHurtTrigger[1]);
if(iHurtTriggerHammerID != iHammerID)
continue;
}
else if(!sTargetname[0] || !StrEqual(sTargetname, sHurtTrigger))
continue;
char sHurtOutput[64];
Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
if(!StrEqual(output, sHurtOutput))
continue;
if(iHurtTriggerHammerID == -1)
LogDebugMessage("Triggered hurt boss %s(%d) from output %s", sTargetname, entity, output);
else
LogDebugMessage("Triggered hurt boss #%d(%d) from output %s", iHurtTriggerHammerID, entity, output);
for(int j = 0; j < g_aBoss.Length; j++)
{
CBoss Boss = g_aBoss.Get(j);
if(Boss.dConfig != Config)
continue;
if(Boss.iTemplateNum != iTemplateNum)
continue;
Call_StartForward(g_hFwd_OnBossDamaged);
Call_PushCell(Boss);
Call_PushCell(Boss.dConfig);
Call_PushCell(activator);
Call_PushFloat(damage);
Call_Finish();
}
}
} }
public void OnEnvEntityMakerEntitySpawned(const char[] output, int caller, int activator, float delay) public void OnEnvEntityMakerEntitySpawned(const char[] output, int caller, int activator, float delay)
@ -864,7 +750,7 @@ public void OnEntityOutputKill(const char[] output, int caller, int activator, f
public void OnEntityOutputHurt(const char[] output, int caller, int activator, float delay) public void OnEntityOutputHurt(const char[] output, int caller, int activator, float delay)
{ {
OnHurtTrigger(caller, output, activator); OnHurtTrigger(caller, activator);
} }
public void OnTakeDamagePost(int victim, int attacker, int inflictor, float damage, int damagetype) public void OnTakeDamagePost(int victim, int attacker, int inflictor, float damage, int damagetype)
@ -884,7 +770,7 @@ public void OnTakeDamagePostKill(int victim, int attacker, int inflictor, float
public void OnTakeDamagePostHurt(int victim, int attacker, int inflictor, float damage, int damagetype) public void OnTakeDamagePostHurt(int victim, int attacker, int inflictor, float damage, int damagetype)
{ {
OnHurtTrigger(victim, "OnTakeDamage", attacker, damage); OnHurtTrigger(victim, attacker, damage);
} }
public void OnGameFrame() public void OnGameFrame()
@ -925,7 +811,7 @@ public void OnGameFrame()
Boss.fWaitUntil = 0.0; Boss.fWaitUntil = 0.0;
} }
if(!BossInit(Boss)) if(!BossInit(i, Boss))
continue; continue;
} }
@ -985,7 +871,7 @@ public void OnGameFrame()
} }
} }
bool BossInit(CBoss _Boss) bool BossInit(int iBoss, CBoss _Boss)
{ {
CConfig _Config = _Boss.dConfig; CConfig _Config = _Boss.dConfig;
bool bNameFixup = _Config.bNameFixup; bool bNameFixup = _Config.bNameFixup;
@ -1226,88 +1112,99 @@ bool BossInit(CBoss _Boss)
_Boss.bActive = true; _Boss.bActive = true;
char sShowTrigger[64];
_Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
char sKillTrigger[64];
_Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
char sHurtTrigger[64];
_Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
if(iTemplateNum != -1) if(iTemplateNum != -1)
{ {
_Boss.iTemplateNum = iTemplateNum; _Boss.iTemplateNum = iTemplateNum;
char sShowTrigger[64];
_Config.GetShowTrigger(sShowTrigger, sizeof(sShowTrigger));
if(sShowTrigger[0]) if(sShowTrigger[0])
{ {
Format(sShowTrigger, sizeof(sShowTrigger), "%s&%04d", sShowTrigger, iTemplateNum); Format(sShowTrigger, sizeof(sShowTrigger), "%s&%04d", sShowTrigger, iTemplateNum);
char sShowOutput[64];
_Config.GetShowOutput(sShowOutput, sizeof(sShowOutput));
int entity = INVALID_ENT_REFERENCE;
while((entity = FindEntityByTargetname(entity, sShowTrigger)) != INVALID_ENT_REFERENCE)
{
if(StrEqual(sShowOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostShow);
}
else
{
bool Once = !_Config.bMultiTrigger;
HookSingleEntityOutput(entity, sShowOutput, OnEntityOutputShow, Once);
}
LogDebugMessage("Hooked showtrigger %s:%s", sShowTrigger, sShowOutput);
}
} }
char sKillTrigger[64];
_Config.GetKillTrigger(sKillTrigger, sizeof(sKillTrigger));
if(sKillTrigger[0]) if(sKillTrigger[0])
{ {
Format(sKillTrigger, sizeof(sKillTrigger), "%s&%04d", sKillTrigger, iTemplateNum); Format(sKillTrigger, sizeof(sKillTrigger), "%s&%04d", sKillTrigger, iTemplateNum);
char sKillOutput[64];
_Config.GetKillOutput(sKillOutput, sizeof(sKillOutput));
int entity = INVALID_ENT_REFERENCE;
while((entity = FindEntityByTargetname(entity, sKillTrigger)) != INVALID_ENT_REFERENCE)
{
if(StrEqual(sKillOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostKill);
}
else
{
bool Once = !_Config.bMultiTrigger;
HookSingleEntityOutput(entity, sKillOutput, OnEntityOutputKill, Once);
}
LogDebugMessage("Hooked killtrigger %s:%s", sKillTrigger, sKillOutput);
}
} }
char sHurtTrigger[64];
_Config.GetHurtTrigger(sHurtTrigger, sizeof(sHurtTrigger));
if(sHurtTrigger[0]) if(sHurtTrigger[0])
{ {
Format(sHurtTrigger, sizeof(sHurtTrigger), "%s&%04d", sHurtTrigger, iTemplateNum); Format(sHurtTrigger, sizeof(sHurtTrigger), "%s&%04d", sHurtTrigger, iTemplateNum);
}
}
char sHurtOutput[64]; if(sShowTrigger[0])
_Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput)); {
char sShowOutput[64];
_Config.GetShowOutput(sShowOutput, sizeof(sShowOutput));
int entity = INVALID_ENT_REFERENCE; int entity = INVALID_ENT_REFERENCE;
while((entity = FindEntityByTargetname(entity, sHurtTrigger)) != INVALID_ENT_REFERENCE) while((entity = FindEntityByTargetname(entity, sShowTrigger)) != INVALID_ENT_REFERENCE)
{
if(StrEqual(sShowOutput, "OnTakeDamage"))
{ {
if(StrEqual(sHurtOutput, "OnTakeDamage")) SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostShow);
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostHurt);
}
else
{
HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt);
}
LogDebugMessage("Hooked hurttrigger %s:%s", sHurtTrigger, sHurtOutput);
} }
else
{
bool Once = !_Config.bMultiTrigger;
HookSingleEntityOutput(entity, sShowOutput, OnEntityOutputShow, Once);
}
LogDebugMessage("Hooked showtrigger %s:%s", sShowTrigger, sShowOutput);
}
}
if(sKillTrigger[0])
{
char sKillOutput[64];
_Config.GetKillOutput(sKillOutput, sizeof(sKillOutput));
int entity = INVALID_ENT_REFERENCE;
while((entity = FindEntityByTargetname(entity, sKillTrigger)) != INVALID_ENT_REFERENCE)
{
if(StrEqual(sKillOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostKill);
}
else
{
bool Once = !_Config.bMultiTrigger;
HookSingleEntityOutput(entity, sKillOutput, OnEntityOutputKill, Once);
}
LogDebugMessage("Hooked killtrigger %s:%s", sKillTrigger, sKillOutput);
}
}
if(sHurtTrigger[0])
{
char sHurtOutput[64];
_Config.GetHurtOutput(sHurtOutput, sizeof(sHurtOutput));
int entity = INVALID_ENT_REFERENCE;
while((entity = FindEntityByTargetname(entity, sHurtTrigger)) != INVALID_ENT_REFERENCE)
{
g_aHurtEntityToBossIdx[entity] = iBoss;
if(StrEqual(sHurtOutput, "OnTakeDamage"))
{
SDKHook(entity, SDKHook_OnTakeDamagePost, OnTakeDamagePostHurt);
}
else
{
HookSingleEntityOutput(entity, sHurtOutput, OnEntityOutputHurt);
}
LogDebugMessage("Hooked hurttrigger %s:%s", sHurtTrigger, sHurtOutput);
} }
} }