diff options
Diffstat (limited to 'db/areas.php')
-rw-r--r-- | db/areas.php | 26 |
1 files changed, 23 insertions, 3 deletions
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); |