Misc/Cleanup

* create function for num range .. creation
This commit is contained in:
Sarjuuk
2025-11-01 20:12:41 +01:00
parent 1e9e406ff0
commit 8212811970
5 changed files with 29 additions and 35 deletions

View File

@@ -95,15 +95,7 @@ class ItemsetBaseResponse extends TemplateResponse implements ICache
// itemLevel
if ($min = $this->subject->getField('minLevel'))
{
$foo = Lang::game('level').Lang::main('colon').$min;
$max = $this->subject->getField('maxLevel');
if ($min < $max)
$foo .= ' - '.$max;
$infobox[] = $foo;
}
$infobox[] = Lang::game('level').Lang::main('colon').Util::createNumRange($min, $this->subject->getField('maxLevel'), ' - ');
// class
if ($cl = Lang::getClassString($this->subject->getField('classMask'), $jsg, Lang::FMT_MARKUP))

View File

@@ -148,9 +148,7 @@ class ObjectBaseResponse extends TemplateResponse implements ICache
if ($this->subject->getField('lootStack'))
{
[$min, $max, $restock] = $this->subject->getField('lootStack');
$buff = Lang::spell('spellModOp', 4).Lang::main('colon').$min;
if ($min < $max)
$buff .= Lang::game('valueDelim').$max;
$buff = Lang::spell('spellModOp', 4).Lang::main('colon').Util::createNumRange($min, $max);
// since Veins don't have charges anymore, the timer is questionable
$infobox[] = $restock > 1 ? '[tooltip name=restock]'.Lang::gameObject('restock', [Util::formatTime($restock * 1000)]).'[/tooltip][span class=tip tooltip=restock]'.$buff.'[/span]' : $buff;
@@ -163,10 +161,7 @@ class ObjectBaseResponse extends TemplateResponse implements ICache
$this->extendGlobalIds(Type::ZONE, $zone);
$m = Lang::game('meetingStone').'[zone='.$zone.']';
$l = $minLevel;
if ($minLevel > 1 && $maxLevel > $minLevel)
$l .= Lang::game('valueDelim').min($maxLevel, MAX_LEVEL);
$l = Util::createNumRange($minLevel, min($maxLevel, MAX_LEVEL));
$infobox[] = $l ? '[tooltip name=meetingstone]'.Lang::game('reqLevel', [$l]).'[/tooltip][span class=tip tooltip=meetingstone]'.$m.'[/span]' : $m;
}
@@ -181,11 +176,11 @@ class ObjectBaseResponse extends TemplateResponse implements ICache
if ($minTime > 1 || $minPlayer || $radius)
$buff .= Lang::main('colon').'[ul]';
if ($minTime > 1)
$buff .= '[li]'.Lang::game('duration').Lang::main('colon').($maxTime > $minTime ? Util::FormatTime($maxTime * 1000, true).' - ' : '').Util::FormatTime($minTime * 1000, true).'[/li]';
if ($minTime > 1) // sign shenannigans reverse the display order
$buff .= '[li]'.Lang::game('duration').Lang::main('colon').Util::createNumRange(-$maxTime, -$minTime, fn: fn($x) => Util::FormatTime(-$x * 1000, true)).'[/li]';
if ($minPlayer)
$buff .= '[li]'.Lang::main('players').Lang::main('colon').$minPlayer.($maxPlayer > $minPlayer ? ' - '.$maxPlayer : '').'[/li]';
$buff .= '[li]'.Lang::main('players').Lang::main('colon').Util::createNumRange($minPlayer, $maxPlayer).'[/li]';
if ($radius)
$buff .= '[li]'.Lang::spell('range', [$radius]).'[/li]';

View File

@@ -1606,7 +1606,7 @@ class SpellBaseResponse extends TemplateResponse implements ICache
*/
$_nameEffect = $_nameAura = $_nameMV = $_nameMVB = $_markup = '';
$_icon = $_perfItem = $_footer = [];
$_icon = $_perfItem = $_footer = [];
$_footer['value'] = [0, 0];
$valueFmt = '%s';
@@ -1623,7 +1623,7 @@ class SpellBaseResponse extends TemplateResponse implements ICache
Type::ITEM,
$itemId,
$itemEntry ? $this->subject->relItems->getField('name', true) : Util::ucFirst(Lang::game('item')).' #'.$itemId,
($effBP + 1) . ($effDS > 1 ? '-' . ($effBP + $effDS) : ''),
$this->createNumRange($effBP, $effDS),
quality: $itemEntry ? $this->subject->relItems->getField('quality') : '',
link: !empty($itemEntry)
);
@@ -1654,12 +1654,6 @@ class SpellBaseResponse extends TemplateResponse implements ICache
$cndSpell = new SpellList(array(['id', $extraItem['requiredSpecialization']]));
if (!$cndSpell->error)
{
$num = '+'.($effBP + 1);
if ($extraItem['additionalMaxNum'] > 1)
$num .= '-'.($extraItem['additionalMaxNum'] * ($effBP + $effDS));
else if ($effDS > 1)
$num .= '-'.($effBP + $effDS);
$_perfItem = array(
'spellId' => $cndSpell->id,
'spellName' => $cndSpell->getField('name', true),
@@ -1669,7 +1663,7 @@ class SpellBaseResponse extends TemplateResponse implements ICache
Type::ITEM,
$this->subject->relItems->id,
$this->subject->relItems->getField('name', true),
num: $num,
num: '+'.$this->createNumRange($effBP, $effDS, $extraItem['additionalMaxNum']),
quality: $this->subject->relItems->getField('quality')
)
);
@@ -2285,6 +2279,11 @@ class SpellBaseResponse extends TemplateResponse implements ICache
$this->attributes = $list;
}
private function createNumRange(int $bp, int $ds, int $mult = 1) : string
{
return Util::createNumRange($bp + 1, ($bp + $ds) * $mult, '-');
}
private function generatePath()
{
$cat = $this->subject->getField('typeCat');

View File

@@ -21,14 +21,10 @@ trait SmartHelper
private function numRange(int $min, int $max, bool $isTime) : string
{
if (!$min && !$max)
return '';
if ($isTime)
return Util::createNumRange($min, $max, ' &ndash; ', fn($x) => Util::formatTime($x, true));
$str = $isTime ? Util::formatTime($min, true) : $min;
if ($max > $min)
$str .= ' &ndash; '.($isTime ? Util::formatTime($max, true) : $max);
return $str;
return Util::createNumRange($min, $max, ' &ndash; ');
}
private function formatTime(int $time, int $_, bool $isMilliSec) : string

View File

@@ -554,6 +554,18 @@ abstract class Util
}
}
public static function createNumRange(int $min, int $max, string $delim = '', ?callable $fn = null) : string
{
if (!$min && !$max)
return '';
$fn ??= fn($x) => $x;
$_min = $fn($min);
$_max = $fn($max);
return $max > $min ? $_min . ($delim ?: Lang::main('valueDelim')) . $_max : $_min;
}
public static function validateLogin(?string $val) : string
{
if ($_ = self::validateEmail($val))