From 40c2c63d1b953485cb74d54ac3595773ec7d0533 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Mon, 27 Jan 2025 10:25:44 +0100 Subject: [PATCH] NPC/MapModes * try to improve map mode detection for NPCs again... --- localization/locale_dede.php | 2 +- localization/locale_enus.php | 2 +- localization/locale_eses.php | 2 +- localization/locale_frfr.php | 2 +- localization/locale_ruru.php | 2 +- localization/locale_zhcn.php | 2 +- pages/npc.php | 60 +++++++++++++++++------------------- template/pages/npc.tpl.php | 4 +-- 8 files changed, 37 insertions(+), 39 deletions(-) diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 36196a91..cebf446b 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -1004,7 +1004,7 @@ $lang = array( 'react' => "Reaktion", 'worth' => "Wert", 'unkPosition' => "Der Aufenthaltsort dieses NPCs ist nicht bekannt.", - 'difficultyPH' => "Dieser NPC ist ein Platzhalter für einen anderen Modus von", + 'difficultyPH' => 'Dieser NPC ist ein Platzhalter für einen anderen Modus von %2$s.', 'seat' => "Sitz", 'accessory' => "Zusätze", 'accessoryFor' => "Dieser NPC ist Zusatz für Fahrzeug", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index 2e1a6161..ba09873c 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -1005,7 +1005,7 @@ $lang = array( 'react' => "React", 'worth' => "Worth", 'unkPosition' => "The location of this NPC is unknown.", - 'difficultyPH' => "This NPC is a placeholder for a different mode of", + 'difficultyPH' => 'This NPC is a placeholder for a different mode of %2$s.', 'seat' => "Seat", 'accessory' => "Accessories", 'accessoryFor' => "This NPC is an accessory for vehicle", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index 07bf91ef..7734c8ef 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -1004,7 +1004,7 @@ $lang = array( 'react' => "Reacción", 'worth' => "Valor", 'unkPosition' => "No se conoce la ubicación de este PNJ.", - 'difficultyPH' => "Este PNJ es un marcador de posición para un modo diferente de", + 'difficultyPH' => 'Este PNJ es un marcador de posición para un modo diferente de %2$s.', 'seat' => "Asiento", 'accessory' => "Accesorio", 'accessoryFor' => "Esta criatura es una accesorio para vehículo", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 0eef2072..08bef730 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -1004,7 +1004,7 @@ $lang = array( 'react' => "Réaction", 'worth' => "Vaut", 'unkPosition' => "L'emplacement de ce PNJ est inconnu.", - 'difficultyPH' => "Ce PNJ est un espace réservé pour un autre mode de difficulté.", + 'difficultyPH' => 'Ce PNJ est un espace réservé pour un autre mode de difficulté %2$s.', 'seat' => "Siège", 'accessory' => "Passager", 'accessoryFor' => "Ce PNJ est un passager pour un véhicule.", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 2d206d85..d0f76aba 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -1004,7 +1004,7 @@ $lang = array( 'react' => "Реакция", 'worth' => "Деньги", 'unkPosition' => "Местоположение этого НИП неизвестно.", - 'difficultyPH' => "[Этот НИП является прототипом для другого режима]", + 'difficultyPH' => '[Этот НИП является прототипом для другого режима %2$s.]', 'seat' => "[Seat]", 'accessory' => "[Accessory]", 'accessoryFor' => "[This creature is an accessory for vehicle]", diff --git a/localization/locale_zhcn.php b/localization/locale_zhcn.php index 242ded31..26196b87 100644 --- a/localization/locale_zhcn.php +++ b/localization/locale_zhcn.php @@ -1004,7 +1004,7 @@ $lang = array( 'react' => "反应", 'worth' => "价值", 'unkPosition' => "这个NPC的位置未知。", - 'difficultyPH' => "这个NPC是不同模式下的占位符,是", + 'difficultyPH' => '这个NPC是不同模式下的占位符,是 %2$s.', 'seat' => "Seat", 'accessory' => "附件", 'accessoryFor' => "这个NPC是载具的附件", diff --git a/pages/npc.php b/pages/npc.php index 394f75dd..4a61cde5 100644 --- a/pages/npc.php +++ b/pages/npc.php @@ -10,7 +10,7 @@ class NpcPage extends GenericPage { use TrDetailPage; - protected $placeholder = null; + protected $placeholder = []; protected $accessory = []; protected $quotes = []; protected $reputation = []; @@ -67,7 +67,7 @@ class NpcPage extends GenericPage $_typeFlags = $this->subject->getField('typeFlags'); $_altIds = []; $_altNPCs = null; - $placeholder = null; + $placeholder = []; $accessory = []; // difficulty entries of self @@ -83,7 +83,7 @@ class NpcPage extends GenericPage $_altNPCs = new CreatureList(array(['id', array_keys($_altIds)])); } - if ($_ = DB::World()->selectCol('SELECT DISTINCT entry FROM vehicle_template_accessory WHERE accessory_entry = ?d', $this->typeId)) + if ($_ = DB::World()->selectCol('SELECT DISTINCT `entry` FROM vehicle_template_accessory WHERE `accessory_entry` = ?d', $this->typeId)) { $vehicles = new CreatureList(array(['id', $_])); foreach ($vehicles->iterate() as $id => $__) @@ -92,11 +92,11 @@ class NpcPage extends GenericPage // try to determine, if it's spawned in a dungeon or raid (shaky at best, if spawned by script) $mapType = 0; - if ($maps = DB::Aowow()->selectCol('SELECT DISTINCT areaId from ?_spawns WHERE type = ?d AND typeId = ?d', Type::NPC, $this->typeId)) + if ($maps = DB::Aowow()->selectCol('SELECT DISTINCT `areaId` FROM ?_spawns WHERE `type` = ?d AND `typeId` = ?d', Type::NPC, $this->typeId)) { if (count($maps) == 1) // should only exist in one instance { - switch (DB::Aowow()->selectCell('SELECT `type` FROM ?_zones WHERE id = ?d', $maps[0])) + switch (DB::Aowow()->selectCell('SELECT `type` FROM ?_zones WHERE `id` = ?d', $maps[0])) { // case MAP_TYPE_DUNGEON: case MAP_TYPE_DUNGEON_HC: @@ -108,17 +108,15 @@ class NpcPage extends GenericPage } } } - else if ($d = DB::Aowow()->selectCell('SELECT MAX(`difficulty`) FROM ?_loot_link WHERE `npcId` = ?d', $this->typeId)) - $mapType = $d > 2 ? 2 : 1; - else if ($mt = DB::Aowow()->selectCell('SELECT IF(`difficultyEntry1` = ?d, 1, 2) FROM ?_creature WHERE `difficultyEntry1` = ?d OR `difficultyEntry2` = ?d OR `difficultyEntry3` = ?d', $this->typeId, $this->typeId, $this->typeId, $this->typeId)) - $mapType = $mt; - else if ($_altIds) // not spawned, but has difficultyDummies - { - if (count($_altIds) > 1) // 3 or more version -> definitly raid (10/25 + hc) - $mapType = 2; - else // 2 versions; may be Heroic (use this), but may also be 10/25-raid - $mapType = 1; - } + // npc is difficulty dummy: get max difficulty from parent npc + if ($placeholder && ($mt = DB::Aowow()->selectCell('SELECT IF(`difficultyEntry1` = ?d, 1, 2) FROM ?_creature WHERE `difficultyEntry1` = ?d OR `difficultyEntry2` = ?d OR `difficultyEntry3` = ?d', $this->typeId, $this->typeId, $this->typeId, $this->typeId))) + $mapType = max($mapType, $mt); + // npc has difficulty dummys: 2+ dummies -> definitely raid (10/25 + hc); 1 dummy -> may be heroic (used here), but may also be 10/25-raid + if ($_altIds) + $mapType = max($mapType, count($_altIds) > 1 ? 2 : 1); + // for event encounters a single npc may be reused over multiple difficulties but have different chests assigned + if ($d = DB::Aowow()->selectCell('SELECT MAX(`difficulty`) FROM ?_loot_link WHERE `npcId` IN (?a)', array_merge($_altIds, [$this->typeId]))) + $mapType = max($mapType, $d > 2 ? 2 : 1); /***********/ @@ -128,7 +126,7 @@ class NpcPage extends GenericPage $infobox = Lang::getInfoBoxForFlags($this->subject->getField('cuFlags')); // Event (ignore events, where the object only gets removed) - if ($_ = DB::World()->selectCol('SELECT DISTINCT ge.eventEntry FROM game_event ge, game_event_creature gec, creature c WHERE ge.eventEntry = gec.eventEntry AND c.guid = gec.guid AND c.id = ?d', $this->typeId)) + if ($_ = DB::World()->selectCol('SELECT DISTINCT ge.`eventEntry` FROM game_event ge, game_event_creature gec, creature c WHERE ge.`eventEntry` = gec.`eventEntry` AND c.`guid` = gec.`guid` AND c.`id` = ?d', $this->typeId)) { $this->extendGlobalIds(Type::WORLDEVENT, ...$_); $ev = []; @@ -725,7 +723,7 @@ class NpcPage extends GenericPage ksort($sourceFor); - foreach ($sourceFor as $i => [$lootTpl, $lootId, $tabName, $tabId, $hiddenCols, $note]) + foreach ($sourceFor as [$lootTpl, $lootId, $tabName, $tabId, $hiddenCols, $note]) { $creatureLoot = new Loot(); if ($creatureLoot->getByContainer($lootTpl, $lootId)) @@ -828,7 +826,7 @@ class NpcPage extends GenericPage } // tab: passengers - if ($_ = DB::World()->selectCol('SELECT accessory_entry AS ARRAY_KEY, GROUP_CONCAT(seat_id) FROM vehicle_template_accessory WHERE entry = ?d GROUP BY accessory_entry', $this->typeId)) + if ($_ = DB::World()->selectCol('SELECT `accessory_entry` AS ARRAY_KEY, GROUP_CONCAT(`seat_id`) FROM vehicle_template_accessory WHERE `entry` = ?d GROUP BY `accessory_entry`', $this->typeId)) { $passengers = new CreatureList(array(['id', array_keys($_)])); if (!$passengers->error) @@ -863,7 +861,7 @@ class NpcPage extends GenericPage $this->soundIds = array_merge($this->soundIds, SmartAI::getSoundsPlayedForOwner($this->typeId, SAI_SRC_TYPE_CREATURE)); // up to 4 possible displayIds .. for the love of things betwixt, just use the first! - $activitySounds = DB::Aowow()->selectRow('SELECT * FROM ?_creature_sounds WHERE id = ?d', $this->subject->getField('displayId1')); + $activitySounds = DB::Aowow()->selectRow('SELECT * FROM ?_creature_sounds WHERE `id` = ?d', $this->subject->getField('displayId1')); array_shift($activitySounds); // remove id-column $this->soundIds = array_merge($this->soundIds, array_values($activitySounds)); @@ -912,14 +910,14 @@ class NpcPage extends GenericPage return sprintf($this->powerTpl, $this->typeId, User::$localeId, Util::toJSON($power, JSON_AOWOW_POWER)); } - private function getRepForId($entries, &$spillover) + private function getRepForId(array $entries, array &$spillover) : array { - $rows = DB::World()->select(' - SELECT creature_id AS npc, RewOnKillRepFaction1 AS faction, RewOnKillRepValue1 AS qty, MaxStanding1 AS maxRank, isTeamAward1 AS spillover - FROM creature_onkill_reputation WHERE creature_id IN (?a) AND RewOnKillRepFaction1 > 0 UNION - SELECT creature_id AS npc, RewOnKillRepFaction2 As faction, RewOnKillRepValue2 AS qty, MaxStanding2 AS maxRank, isTeamAward2 AS spillover - FROM creature_onkill_reputation WHERE creature_id IN (?a) AND RewOnKillRepFaction2 > 0', - (array)$entries, (array)$entries + $rows = DB::World()->select( + 'SELECT `creature_id` AS "npc", `RewOnKillRepFaction1` AS "faction", `RewOnKillRepValue1` AS "qty", `MaxStanding1` AS "maxRank", `isTeamAward1` AS "spillover" + FROM creature_onkill_reputation WHERE `creature_id` IN (?a) AND `RewOnKillRepFaction1` > 0 UNION + SELECT `creature_id` AS "npc", `RewOnKillRepFaction2` AS "faction", `RewOnKillRepValue2` AS "qty", `MaxStanding2` AS "maxRank", `isTeamAward2` AS "spillover" + FROM creature_onkill_reputation WHERE `creature_id` IN (?a) AND `RewOnKillRepFaction2` > 0', + $entries, $entries ); $factions = new FactionList(array(['id', array_column($rows, 'faction')])); @@ -938,7 +936,7 @@ class NpcPage extends GenericPage 'cap' => $row['maxRank'] && $row['maxRank'] < REP_EXALTED ? Lang::game('rep', $row['maxRank']) : null ); - $cuRate = DB::World()->selectCell('SELECT creature_rate FROM reputation_reward_rate WHERE creature_rate <> 1 AND faction = ?d', $row['faction']); + $cuRate = DB::World()->selectCell('SELECT `creature_rate` FROM reputation_reward_rate WHERE `creature_rate` <> 1 AND `faction` = ?d', $row['faction']); if ($cuRate !== null) $set['qty'][1] = $set['qty'][0] * ($cuRate - 1); @@ -957,13 +955,13 @@ class NpcPage extends GenericPage return $result; } - private function getOnKillRep($dummyIds, $mapType) + private function getOnKillRep(array $dummyIds, int $mapType) : array { $spilledParents = []; $reputation = []; // base NPC - if ($base = $this->getRepForId($this->typeId, $spilledParents)) + if ($base = $this->getRepForId([$this->typeId], $spilledParents)) $reputation[] = [Lang::npc('modes', 1, 0), $base]; // difficulty dummys @@ -1019,7 +1017,7 @@ class NpcPage extends GenericPage return $reputation; } - private function getQuotes() + private function getQuotes() : array { [$quotes, $nQuotes, $soundIds] = Game::getQuotesForCreature($this->typeId, true, $this->subject->getField('name', true)); diff --git a/template/pages/npc.tpl.php b/template/pages/npc.tpl.php index 9c9851db..e9bfb664 100644 --- a/template/pages/npc.tpl.php +++ b/template/pages/npc.tpl.php @@ -26,8 +26,8 @@ if ($this->accessory): echo ".\n"; endif; -if (is_array($this->placeholder)): - echo '
'.Lang::npc('difficultyPH').' '.$this->placeholder[1].".
\n"; +if ($this->placeholder): + echo '
'.Lang::npc('difficultyPH', $this->placeholder)."
\n"; ?>