Filters/Misc

* be a bit more lenient on level inputs
 * fix displaying array of requirements on error
This commit is contained in:
Sarjuuk
2025-10-06 15:50:33 +02:00
parent 704894c1e3
commit 452615a92d
7 changed files with 44 additions and 25 deletions

View File

@@ -452,20 +452,18 @@ abstract class Filter
if (!Util::checkNumeric($val, NUM_CAST_INT))
return false;
foreach ($valid as $k => $v)
if (in_array($val, $valid))
return true;
foreach ($valid as $v)
{
if (gettype($v) != 'array')
continue;
if ($this->checkInput(self::V_RANGE, $v, $val, true))
return true;
unset($valid[$k]);
}
if (in_array($val, $valid))
return true;
break;
case self::V_RANGE:
if (Util::checkNumeric($val, NUM_CAST_INT) && $val >= $valid[0] && $val <= $valid[1])
@@ -486,7 +484,7 @@ abstract class Filter
if (!$recursive)
{
trigger_error('Filter::checkInput - check failed [type: '.$type.' valid: '.((string)$valid).' val: '.((string)$val).']', E_USER_NOTICE);
trigger_error('Filter::checkInput - check failed [type: '.$type.' valid: '.Util::toString($valid).' val: '.((string)$val).']', E_USER_NOTICE);
$this->error = true;
}

View File

@@ -332,8 +332,8 @@ class CreatureListFilter extends Filter
'ex' => [parent::V_EQUAL, 'on', false], // also match subname
'ma' => [parent::V_EQUAL, 1, false], // match any / all filter
'fa' => [parent::V_CALLBACK, 'cbPetFamily', true ], // pet family [list] - cat[0] == 1
'minle' => [parent::V_RANGE, [1, 99], false], // min level [int]
'maxle' => [parent::V_RANGE, [1, 99], false], // max level [int]
'minle' => [parent::V_RANGE, [0, 99], false], // min level [int]
'maxle' => [parent::V_RANGE, [0, 99], false], // max level [int]
'cl' => [parent::V_RANGE, [0, 4], true ], // classification [list]
'ra' => [parent::V_LIST, [-1, 0, 1], false], // react alliance [int]
'rh' => [parent::V_LIST, [-1, 0, 1], false] // react horde [int]

View File

@@ -2021,10 +2021,10 @@ class ItemListFilter extends Filter
'ty' => [parent::V_CALLBACK, 'cbTypeCheck', true ], // item type - dynamic by current group
'sl' => [parent::V_CALLBACK, 'cbSlotCheck', true ], // item slot - dynamic by current group
'si' => [parent::V_LIST, [-SIDE_HORDE, -SIDE_ALLIANCE, SIDE_ALLIANCE, SIDE_HORDE, SIDE_BOTH], false], // side
'minle' => [parent::V_RANGE, [1, 999], false], // item level min
'maxle' => [parent::V_RANGE, [1, 999], false], // item level max
'minrl' => [parent::V_RANGE, [1, MAX_LEVEL], false], // required level min
'maxrl' => [parent::V_RANGE, [1, MAX_LEVEL], false] // required level max
'minle' => [parent::V_RANGE, [0, 999], false], // item level min
'maxle' => [parent::V_RANGE, [0, 999], false], // item level max
'minrl' => [parent::V_RANGE, [0, MAX_LEVEL], false], // required level min
'maxrl' => [parent::V_RANGE, [0, MAX_LEVEL], false] // required level max
);
public array $extraOpts = []; // score for statWeights

View File

@@ -187,10 +187,10 @@ class ItemsetListFilter extends Filter
'ma' => [parent::V_EQUAL, 1, false], // match any / all filter
'qu' => [parent::V_RANGE, [0, 7], true ], // quality
'ty' => [parent::V_RANGE, [1, 12], true ], // set type
'minle' => [parent::V_RANGE, [1, 999], false], // min item level
'maxle' => [parent::V_RANGE, [1, 999], false], // max itemlevel
'minrl' => [parent::V_RANGE, [1, MAX_LEVEL], false], // min required level
'maxrl' => [parent::V_RANGE, [1, MAX_LEVEL], false], // max required level
'minle' => [parent::V_RANGE, [0, 999], false], // min item level
'maxle' => [parent::V_RANGE, [0, 999], false], // max itemlevel
'minrl' => [parent::V_RANGE, [0, MAX_LEVEL], false], // min required level
'maxrl' => [parent::V_RANGE, [0, MAX_LEVEL], false], // max required level
'cl' => [parent::V_LIST, [[1, 9], 11], false], // class
'ta' => [parent::V_RANGE, [1, 30], false] // tag / content group
);

View File

@@ -478,10 +478,10 @@ class QuestListFilter extends Filter
'na' => [parent::V_REGEX, parent::PATTERN_NAME, false], // name / text - only printable chars, no delimiter
'ex' => [parent::V_EQUAL, 'on', false], // also match subname
'ma' => [parent::V_EQUAL, 1, false], // match any / all filter
'minle' => [parent::V_RANGE, [1, 99], false], // min quest level
'maxle' => [parent::V_RANGE, [1, 99], false], // max quest level
'minrl' => [parent::V_RANGE, [1, 99], false], // min required level
'maxrl' => [parent::V_RANGE, [1, 99], false], // max required level
'minle' => [parent::V_RANGE, [0, 99], false], // min quest level
'maxle' => [parent::V_RANGE, [0, 99], false], // max quest level
'minrl' => [parent::V_RANGE, [0, 99], false], // min required level
'maxrl' => [parent::V_RANGE, [0, 99], false], // max required level
'si' => [parent::V_LIST, [-SIDE_HORDE, -SIDE_ALLIANCE, SIDE_ALLIANCE, SIDE_HORDE, SIDE_BOTH], false], // side
'ty' => [parent::V_LIST, [0, 1, 21, 41, 62, [81, 85], 88, 89], true ] // type
);

View File

@@ -2527,10 +2527,10 @@ class SpellListFilter extends Filter
'na' => [parent::V_REGEX, parent::PATTERN_NAME, false], // name / text - only printable chars, no delimiter
'ex' => [parent::V_EQUAL, 'on', false], // extended name search
'ma' => [parent::V_EQUAL, 1, false], // match any / all filter
'minle' => [parent::V_RANGE, [1, 99], false], // spell level min
'maxle' => [parent::V_RANGE, [1, 99], false], // spell level max
'minrs' => [parent::V_RANGE, [1, 999], false], // required skill level min
'maxrs' => [parent::V_RANGE, [1, 999], false], // required skill level max
'minle' => [parent::V_RANGE, [0, 99], false], // spell level min
'maxle' => [parent::V_RANGE, [0, 99], false], // spell level max
'minrs' => [parent::V_RANGE, [0, 999], false], // required skill level min
'maxrs' => [parent::V_RANGE, [0, 999], false], // required skill level max
'ra' => [parent::V_LIST, [[1, 8], 10, 11], false], // races
'cl' => [parent::V_CALLBACK, 'cbClasses', true ], // classes
'gl' => [parent::V_CALLBACK, 'cbGlyphs', true ], // glyph type

View File

@@ -1142,6 +1142,27 @@ abstract class Util
return $bits;
}
public static function toString(mixed $var) : string
{
if (is_array($var))
return '[' . implode(', ', array_map(self::toString(...), $var)) . ']';
if (is_object($var))
{
// hm, respect object stringability?
// if ($var instanceof Stringable)
// return (string)$var;
$buff = [];
foreach ($var as $k => $v)
$buff[] = $k.':'.self::toString($v);
return '{' . implode(', ', $buff) . '}';
}
return (string)$var;
}
public static function buildPosFixMenu(int $mapId, float $posX, float $posY, int $type, int $guid, int $parentArea = 0, int $parentFloor = 0) : array
{
$points = WorldPosition::toZonePos($mapId, $posX, $posY);