Quests/Cleanup

* render quest objectives on detail page by var type instead of magic number
This commit is contained in:
Sarjuuk 2026-01-07 23:07:37 +01:00
parent 793dc4dfdd
commit a17d4a5528
2 changed files with 34 additions and 37 deletions

View file

@ -335,11 +335,11 @@ class QuestBaseResponse extends TemplateResponse implements ICache
if (!$olItemData->getEntry($itemId))
{
$this->objectiveList[] = [0, new IconElement(0, 0, Util::ucFirst(Lang::game('item')).' #'.$itemId, $qty > 1 ? $qty : '', size: IconElement::SIZE_SMALL, extraText: $provided ? Lang::quest('provided') : null)];
$this->objectiveList[] = new IconElement(0, 0, Util::ucFirst(Lang::game('item')).' #'.$itemId, $qty > 1 ? $qty : '', size: IconElement::SIZE_SMALL, extraText: $provided ? Lang::quest('provided') : null);
continue;
}
$this->objectiveList[] = [0, new IconElement(
$this->objectiveList[] = new IconElement(
Type::ITEM,
$itemId,
Lang::unescapeUISequences($olItemData->json[$itemId]['name'], Lang::FMT_HTML),
@ -348,7 +348,7 @@ class QuestBaseResponse extends TemplateResponse implements ICache
size: IconElement::SIZE_SMALL,
element: 'iconlist-icon',
extraText: $provided ? Lang::quest('provided') : null
)];
);
}
// if providd item is not required by quest, list it below other requirements
@ -414,17 +414,17 @@ class QuestBaseResponse extends TemplateResponse implements ICache
array_slice($proxies, ceil(count($proxies) / 2), null, true)
);
$this->objectiveList[] = [2, array(
$this->objectiveList[] = array(
'id' => $i,
'text' => ($altText ?: Util::localizedString($olNPCData->getEntry($i), 'name')) . ((($_specialFlags & QUEST_FLAG_SPECIAL_SPELLCAST) || $altText) ? '' : ' '.Lang::achievement('slain')),
'qty' => $qty > 1 ? $qty : 0,
'proxy' => array_filter($proxies)
)];
);
}
else if (!$olNPCData->getEntry($i))
$this->objectiveList[] = [0, new IconElement(0, 0, Util::ucFirst(Lang::game('npc')).' #'.$i, $qty > 1 ? $qty : '')];
$this->objectiveList[] = new IconElement(0, 0, Util::ucFirst(Lang::game('npc')).' #'.$i, $qty > 1 ? $qty : '');
else
$this->objectiveList[] = [0, new IconElement(
$this->objectiveList[] = new IconElement(
Type::NPC,
$i,
$altText ?: Util::localizedString($olNPCData->getEntry($i), 'name'),
@ -432,7 +432,7 @@ class QuestBaseResponse extends TemplateResponse implements ICache
size: IconElement::SIZE_SMALL,
element: 'iconlist-icon',
extraText: (($_specialFlags & QUEST_FLAG_SPECIAL_SPELLCAST) || $altText) ? '' : Lang::achievement('slain'),
)];
);
}
}
@ -448,16 +448,16 @@ class QuestBaseResponse extends TemplateResponse implements ICache
continue;
if (!$olGOData->getEntry($i))
$this->objectiveList[] = [0, new IconElement(0, 0, Util::ucFirst(Lang::game('object')).' #'.$i, $qty > 1 ? $qty : '', size: IconElement::SIZE_SMALL)];
$this->objectiveList[] = new IconElement(0, 0, Util::ucFirst(Lang::game('object')).' #'.$i, $qty > 1 ? $qty : '', size: IconElement::SIZE_SMALL);
else
$this->objectiveList[] = [0, new IconElement(
$this->objectiveList[] = new IconElement(
Type::OBJECT,
$i,
$altText ?: Lang::unescapeUISequences(Util::localizedString($olGOData->getEntry($i), 'name'), Lang::FMT_HTML),
$qty > 1 ? $qty : '',
size: IconElement::SIZE_SMALL,
element: 'iconlist-icon',
)];
);
}
}
@ -482,14 +482,14 @@ class QuestBaseResponse extends TemplateResponse implements ICache
if (!$i || !in_array($i, $olFactionsData->getFoundIDs()))
continue;
$this->objectiveList[] = [0, new IconElement(
$this->objectiveList[] = new IconElement(
Type::FACTION,
$i,
Util::localizedString($olFactionsData->getEntry($i), 'name'),
size: IconElement::SIZE_SMALL,
element: 'iconlist-icon',
extraText: sprintf(Util::$dfnString, $val.' '.Lang::achievement('points'), '('.Lang::getReputationLevelForPoints($val).')')
)];
);
}
}
@ -497,16 +497,16 @@ class QuestBaseResponse extends TemplateResponse implements ICache
if ($_ = $this->subject->getField('sourceSpellId'))
{
$this->extendGlobalIds(Type::SPELL, $_);
$this->objectiveList[] = [0, new IconElement(Type::SPELL, $_, SpellList::getName($_), extraText: Lang::quest('provided'), element: 'iconlist-icon', size: IconElement::SIZE_SMALL)];
$this->objectiveList[] = new IconElement(Type::SPELL, $_, SpellList::getName($_), extraText: Lang::quest('provided'), element: 'iconlist-icon', size: IconElement::SIZE_SMALL);
}
// required money
if ($this->subject->getField('rewardOrReqMoney') < 0)
$this->objectiveList[] = [1, Lang::quest('reqMoney', [Util::formatMoney(abs($this->subject->getField('rewardOrReqMoney')))])];
$this->objectiveList[] = Lang::quest('reqMoney', [Util::formatMoney(abs($this->subject->getField('rewardOrReqMoney')))]);
// required pvp kills
if ($_ = $this->subject->getField('reqPlayerKills'))
$this->objectiveList[] = [1, Lang::quest('playerSlain', [$_])];
$this->objectiveList[] = Lang::quest('playerSlain', [$_]);
/**********/

View file

@ -43,26 +43,23 @@ if ($this->end || $this->objectiveList):
?>
<table class="iconlist">
<?php
foreach ($this->objectiveList as [$type, $data]):
switch ($type):
case 1: // just text line
echo ' <tr><th><p style="height: 26px; width: 30px;">&nbsp;</p></th><td>'.$data."</td></tr>\n";
break;
case 2: // proxy npc data
['id' => $id, 'text' => $text, 'qty' => $qty, 'proxy' => $proxies] = $data;
echo ' <tr><th><p style="height: 26px">&nbsp;</p></th><td><a href="javascript:;" onclick="g_disclose($WH.ge(\'npcgroup-'.$id.'\'), this)" class="disclosure-off">'.$text.'</a>'.($qty ? '&nbsp;('.$qty.')' : '').'<div id="npcgroup-'.$id."\" style=\"display: none\">\n";
foreach ($proxies as $block):
echo " <div style=\"float: left\"><table class=\"iconlist\">\n";
foreach ($block as $pId => $pName):
echo ' <tr><th><ul><li><var>&nbsp;</var></li></ul></th><td><a href="?npc='.$pId.'">'.$pName."</a></td></tr>\n";
endforeach;
echo " </table></div>\n";
foreach ($this->objectiveList as $objective):
if (is_string($objective)): // just text line
echo ' <tr><th><p style="height: 26px; width: 30px;">&nbsp;</p></th><td>'.$objective."</td></tr>\n";
elseif (is_array($objective)): // proxy npc data
['id' => $id, 'text' => $text, 'qty' => $qty, 'proxy' => $proxies] = $objective;
echo ' <tr><th><p style="height: 26px">&nbsp;</p></th><td><a href="javascript:;" onclick="g_disclose($WH.ge(\'npcgroup-'.$id.'\'), this)" class="disclosure-off">'.$text.'</a>'.($qty ? '&nbsp;('.$qty.')' : '').'<div id="npcgroup-'.$id."\" style=\"display: none\">\n";
foreach ($proxies as $block):
echo " <div style=\"float: left\"><table class=\"iconlist\">\n";
foreach ($block as $pId => $pName):
echo ' <tr><th><ul><li><var>&nbsp;</var></li></ul></th><td><a href="?npc='.$pId.'">'.$pName."</a></td></tr>\n";
endforeach;
echo " </div></td></tr>\n";
break;
default: // has icon set (spell / item / ...) or unordered linked list
echo $data->renderContainer(20, $iconOffset, true);
endswitch;
echo " </table></div>\n";
endforeach;
echo " </div></td></tr>\n";
elseif (is_object($objective)): // has icon set (spell / item / ...) or unordered linked list
echo $objective?->renderContainer(20, $iconOffset, true);
endif;
endforeach;
if ($this->end):
@ -77,8 +74,8 @@ if ($this->end || $this->objectiveList):
<script type="text/javascript">//<![CDATA[
<?php
foreach (array_filter($this->objectiveList, fn($x) => $x[0] === 0) as $k => [, $data]):
echo $data->renderJS();
foreach (array_filter($this->objectiveList, fn($x) => is_object($x)) as $k => $objective):
echo $objective?->renderJS();
endforeach;
?>
//]]></script>