SmartAI/Misc

* make errors more verbose if SAI tries to set unexpected flags
 * do not escape strings. By now thats handled by Frontend/Markup
This commit is contained in:
Sarjuuk
2025-11-04 19:36:49 +01:00
parent 597898450d
commit 9020e36db6
10 changed files with 115 additions and 52 deletions

View File

@@ -37,6 +37,12 @@ trait SmartHelper
private function castFlags(int $flags) : string
{
if ($x = ($flags & ~SmartAI::CAST_FLAG_VALIDATE))
{
trigger_error('SmartAI::castFlags - unknown SmartCastFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= SmartAI::CAST_FLAG_VALIDATE;
}
$cf = [];
for ($i = 1; $i <= SmartAI::CAST_FLAG_COMBAT_MOVE; $i <<= 1)
if (($flags & $i) && ($x = Lang::smartAI('castFlags', $i)))
@@ -47,6 +53,12 @@ trait SmartHelper
private function npcFlags(int $flags) : string
{
if ($x = ($flags & ~NPC_FLAG_VALIDATE))
{
trigger_error('SmartAI::npcFlags - unknown NpcFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= NPC_FLAG_VALIDATE;
}
$nf = [];
for ($i = 1; $i <= NPC_FLAG_MAILBOX; $i <<= 1)
if (($flags & $i) && ($x = Lang::npc('npcFlags', $i)))
@@ -57,6 +69,12 @@ trait SmartHelper
private function dynFlags(int $flags) : string
{
if ($x = ($flags & ~UNIT_DYNFLAG_VALIDATE))
{
trigger_error('SmartAI::dynFlags - unknown unit dynFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= UNIT_DYNFLAG_VALIDATE;
}
$df = [];
for ($i = 1; $i <= UNIT_DYNFLAG_TAPPED_BY_ALL_THREAT_LIST; $i <<= 1)
if (($flags & $i) && ($x = Lang::unit('dynFlags', $i)))
@@ -67,6 +85,12 @@ trait SmartHelper
private function goFlags(int $flags) : string
{
if ($x = ($flags & ~GO_FLAG_VALIDATE))
{
trigger_error('SmartAI::goFlags - unknown GameobjectFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= GO_FLAG_VALIDATE;
}
$gf = [];
for ($i = 1; $i <= GO_FLAG_DESTROYED; $i <<= 1)
if (($flags & $i) && ($x = Lang::gameObject('goFlags', $i)))
@@ -77,6 +101,12 @@ trait SmartHelper
private function spawnFlags(int $flags) : string
{
if ($x = ($flags & ~SmartAI::SPAWN_FLAG_VALIDATE))
{
trigger_error('SmartAI::spawnFlags - unknown SmartSpawnFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= SmartAI::SPAWN_FLAG_VALIDATE;
}
$sf = [];
for ($i = 1; $i <= SmartAI::SPAWN_FLAG_NOSAVE_RESPAWN; $i <<= 1)
if (($flags & $i) && ($x = Lang::smartAI('spawnFlags', $i)))
@@ -87,6 +117,18 @@ trait SmartHelper
private function unitFlags(int $flags, int $flags2) : string
{
if ($x = ($flags & ~UNIT_FLAG_VALIDATE))
{
trigger_error('SmartAI::unitFlags - unknown UnitFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= UNIT_FLAG_VALIDATE;
}
if ($x = ($flags2 & ~UNIT_FLAG2_VALIDATE))
{
trigger_error('SmartAI::unitFlags - unknown UnitFlags2 '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags2 &= UNIT_FLAG2_VALIDATE;
}
$field = $flags2 ? 'flags2' : 'flags';
$max = $flags2 ? UNIT_FLAG2_ALLOW_CHEAT_SPELLS : UNIT_FLAG_UNK_31;
$uf = [];
@@ -181,6 +223,7 @@ class SmartAI
// public const CAST_FORCE_TARGET_SELF = 0x10; // the target to cast this spell on itself
public const CAST_FLAG_AURA_MISSING = 0x20; // Only casts the spell if the target does not have an aura from the spell
public const CAST_FLAG_COMBAT_MOVE = 0x40; // Prevents combat movement if cast successful. Allows movement on range, OOM, LOS
public const CAST_FLAG_VALIDATE = self::CAST_FLAG_INTERRUPT_PREV | self::CAST_FLAG_TRIGGERED | self::CAST_FLAG_AURA_MISSING | self::CAST_FLAG_COMBAT_MOVE;
public const REACT_PASSIVE = 0;
public const REACT_DEFENSIVE = 1;
@@ -207,6 +250,7 @@ class SmartAI
public const SPAWN_FLAG_IGNORE_RESPAWN = 0x01; // onSpawnIn - ignore & reset respawn timer
public const SPAWN_FLAG_FORCE_SPAWN = 0x02; // onSpawnIn - force additional spawn if already in world
public const SPAWN_FLAG_NOSAVE_RESPAWN = 0x04; // onDespawn - remove respawn time
public const SPAWN_FLAG_VALIDATE = self::SPAWN_FLAG_IGNORE_RESPAWN | self::SPAWN_FLAG_FORCE_SPAWN | self::SPAWN_FLAG_NOSAVE_RESPAWN;
private array $jsGlobals = [];
private array $rawData = [];

View File

@@ -467,8 +467,8 @@ class SmartAction
WHERE tp.`id` = ?d',
Lang::getLocale()->value, Lang::getLocale()->value, Lang::getLocale()->value, Lang::getLocale()->value, $this->param[0]
);
$this->param[10] = Util::jsEscape(Util::localizedString($nodes, 'start'));
$this->param[11] = Util::jsEscape(Util::localizedString($nodes, 'end'));
$this->param[10] = Util::localizedString($nodes, 'start');
$this->param[11] = Util::localizedString($nodes, 'end');
break;
case self::ACTION_SET_INGAME_PHASE_MASK: // 44 -> any target
if ($this->param[0])

View File

@@ -112,6 +112,7 @@ class SmartEvent
public const FLAG_NO_RESET = 0x0100;
public const FLAG_WHILE_CHARMED = 0x0200;
public const FLAG_ALL_DIFFICULTIES = self::FLAG_DIFFICULTY_0 | self::FLAG_DIFFICULTY_1 | self::FLAG_DIFFICULTY_2 | self::FLAG_DIFFICULTY_3;
public const FLAG_VALIDATE = self::FLAG_NO_REPEAT | self::FLAG_DEBUG_ONLY | self::FLAG_NO_RESET | self::FLAG_WHILE_CHARMED | self::FLAG_ALL_DIFFICULTIES;
private const EVENT_CELL_TPL = '[tooltip name=e-#rowIdx#]%1$s[/tooltip][span tooltip=e-#rowIdx#]%2$s[/span]';
@@ -304,7 +305,7 @@ class SmartEvent
);
if ($gmo)
$this->param[10] = Util::jsEscape(Util::localizedString($gmo, 'text'));
$this->param[10] = Util::localizedString($gmo, 'text');
else
trigger_error('SmartAI::event - could not find gossip menu option for event #'.$this->type);
break;
@@ -374,6 +375,12 @@ class SmartEvent
{
$flags = $this->flags;
if ($x = ($flags & ~self::FLAG_VALIDATE))
{
trigger_error('SmartEvent::formatFlags - unused SmartEventFlags '.Util::asBin($x).' set on id #'.$this->id, E_USER_NOTICE);
$flags &= self::FLAG_VALIDATE;
}
if (($flags & self::FLAG_ALL_DIFFICULTIES) == self::FLAG_ALL_DIFFICULTIES)
$flags &= ~self::FLAG_ALL_DIFFICULTIES;