From 5582c3c07069f7766aabd81f3a4a3f97def134e9 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sun, 27 Aug 2023 14:35:50 +0200 Subject: more areas! --- db/areas.php | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'db/areas.php') diff --git a/db/areas.php b/db/areas.php index c1d97e0..d2c9af9 100644 --- a/db/areas.php +++ b/db/areas.php @@ -7,14 +7,33 @@ foreach (scandir(__DIR__ . '/areas') as $file) { $fileName = pathinfo($file, PATHINFO_FILENAME); $area = json_decode(file_get_contents($filePath), true); + $encounterSlug = $area['modules/tuxemon.encounter'] ?? ''; - $environmentSlug = $area['modules/tuxemon.environment'] ?? ''; $encounters = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/encounter/$encounterSlug.json") ?? '', true); + + $environmentSlug = $area['modules/tuxemon.environment'] ?? ''; $environment = json_decode(@file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/environment/$environmentSlug.json") ?? '', true); + $map = @file_get_contents(__DIR__ . "/maps/$fileName.svg"); $area['encounters'] ??= []; array_push($area['encounters'], ...$encounters['monsters'] ?? []); + if (! empty($area['encounters'])) { + // filter out duplicates, because day/night is ignored for now + $duplicates = []; + $area['encounters'] = array_values(array_filter($area['encounters'], function ($item) use (&$duplicates) { + $isNotDuplicate = ! in_array($item['monster'], $duplicates); + $duplicates[] = $item['monster']; + return $isNotDuplicate; + })); + + $encounterRateTotal = array_sum(array_column($area['encounters'], 'encounter_rate')); + foreach ($area['encounters'] as &$encounter) { + if (empty($encounter['encounter_rate'])) continue; + $encounter['encounter_percent'] = intval(100 / ($encounterRateTotal / $encounter['encounter_rate'])); + } + $area['encounter_percent_total'] = array_sum(array_column($area['encounters'], 'encounter_percent')); + } $area['requiredEncounters'] ??= 0; $area['trainers'] ??= []; @@ -23,10 +42,11 @@ foreach (scandir(__DIR__ . '/areas') as $file) { $area['map'] = $map; foreach ($area['connections'] as $areaSlug => $connection) { - $area['connections'][$areaSlug]['modules/tuxemon.slug'] = json_decode(file_get_contents(__DIR__ . "/areas/$areaSlug.json"), true)['modules/tuxemon.slug']; + $area['connections'][$areaSlug]['modules/tuxemon.slug'] = json_decode(@file_get_contents(__DIR__ . "/areas/$areaSlug.json") ?? '', true)['modules/tuxemon.slug'] ?? ''; } - foreach ($area['locations'] ?? [] as $locationId => $location) { + $area['locations'] ??= []; + foreach ($area['locations'] as $locationId => $location) { if ($location['type'] == 'shop') { $economySlug = $location['modules/tuxemon.economy']; $scoop = json_decode(file_get_contents(dirname(__DIR__) . "/modules/tuxemon/mods/tuxemon/db/economy/$economySlug.json"), true); -- cgit v1.2.3