Skip to content

Commit

Permalink
Merge pull request #2142 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v7.6.1 - Updated Atal'dazar total count
  • Loading branch information
Wotuu authored Nov 22, 2023
2 parents 07accbc + b0a3199 commit 01a6892
Show file tree
Hide file tree
Showing 51 changed files with 6,827 additions and 867 deletions.
3 changes: 3 additions & 0 deletions app/Console/Commands/MDT/ImportMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function handle(MappingServiceInterface $mappingService, MDTMappingImport
// Cannot do ->with('npcs') here - it won't load the relationship properly due to orWhere(dungeon_id = -1)
foreach ($season->dungeons as $dungeon) {
try {
$dungeon->setRelation('currentMappingVersion', $dungeon->currentMappingVersion()->first());
$dungeon->setRelation('npcs', $dungeon->npcs()->get());
$mappingImportService->importMappingVersionFromMDT($mappingService, $dungeon, $force);
} catch (\Exception $exception) {
Expand All @@ -62,6 +63,8 @@ public function handle(MappingServiceInterface $mappingService, MDTMappingImport
// Cannot do ->with('npcs') here - it won't load the relationship properly due to orWhere(dungeon_id = -1)
/** @var Dungeon $dungeon */
$dungeon = Dungeon::where('key', $dungeonKey)->firstOrFail();

$dungeon->setRelation('currentMappingVersion', $dungeon->currentMappingVersion()->first());
$dungeon->setRelation('npcs', $dungeon->npcs()->get());

$mappingImportService->importMappingVersionFromMDT($mappingService, $dungeon, $force);
Expand Down
9 changes: 5 additions & 4 deletions app/Http/Controllers/Ajax/AjaxMapIconController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,16 @@ function delete(Request $request, ?DungeonRoute $dungeonRoute, MapIcon $mapIcon)
}

/**
* @param MapIconFormRequest $request
* @param MapIcon|null $mapIcon
* @param MapIconFormRequest $request
* @param CoordinatesServiceInterface $coordinatesService
* @param MapIcon|null $mapIcon
* @return MapIcon
* @throws AuthorizationException
* @throws Throwable
*/
public function adminStore(MapIconFormRequest $request, MapIcon $mapIcon = null): MapIcon
public function adminStore(MapIconFormRequest $request, CoordinatesServiceInterface $coordinatesService, MapIcon $mapIcon = null): MapIcon
{
return $this->store($request, null, $mapIcon);
return $this->store($request, $coordinatesService, null, $mapIcon);
}


Expand Down
24 changes: 2 additions & 22 deletions app/Models/Floor/FloorUnion.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Models\Floor;

use App\Models\CacheModel;
use App\Models\Mapping\CloneForNewMappingVersionNoRelations;
use App\Models\Mapping\MappingModelCloneableInterface;
use App\Models\Mapping\MappingModelInterface;
use App\Models\Mapping\MappingVersion;
Expand Down Expand Up @@ -33,6 +34,7 @@
class FloorUnion extends CacheModel implements MappingModelInterface, MappingModelCloneableInterface
{
use HasLatLng;
use CloneForNewMappingVersionNoRelations;

public $timestamps = false;

Expand Down Expand Up @@ -101,26 +103,4 @@ public function getDungeonId(): ?int
{
return $this->floor->dungeon_id;
}

/**
* @param MappingVersion $mappingVersion
* @param MappingModelInterface|null $newParent
*
* @return FloorUnion
*/
public function cloneForNewMappingVersion(MappingVersion $mappingVersion, ?MappingModelInterface $newParent = null): FloorUnion
{
/** @var FloorUnion|MappingModelInterface $clonedFloorUnion */
$clonedFloorUnion = clone $this;
$clonedFloorUnion->exists = false;
$clonedFloorUnion->id = null;
$clonedFloorUnion->mapping_version_id = $mappingVersion->id;
$clonedFloorUnion->save();

foreach($this->floorUnionAreas as $floorUnionArea){
$floorUnionArea->cloneForNewMappingVersion($mappingVersion, $clonedFloorUnion);
}

return $clonedFloorUnion;
}
}
21 changes: 2 additions & 19 deletions app/Models/Floor/FloorUnionArea.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Logic\Structs\LatLng;
use App\Models\CacheModel;
use App\Models\Interfaces\ConvertsVerticesInterface;
use App\Models\Mapping\CloneForNewMappingVersionNoRelations;
use App\Models\Mapping\MappingModelCloneableInterface;
use App\Models\Mapping\MappingModelInterface;
use App\Models\Mapping\MappingVersion;
Expand All @@ -28,6 +29,7 @@
class FloorUnionArea extends CacheModel implements MappingModelInterface, MappingModelCloneableInterface, ConvertsVerticesInterface
{
use HasVertices;
use CloneForNewMappingVersionNoRelations;

public $timestamps = false;

Expand Down Expand Up @@ -89,23 +91,4 @@ public function getDungeonId(): ?int
{
return $this->floor->dungeon_id;
}

/**
* @param MappingVersion $mappingVersion
* @param MappingModelInterface|null $newParent
*
* @return FloorUnionArea
*/
public function cloneForNewMappingVersion(MappingVersion $mappingVersion, ?MappingModelInterface $newParent = null): FloorUnionArea
{
/** @var FloorUnionArea|MappingModelInterface $clonedFloorUnionArea */
$clonedFloorUnionArea = clone $this;
$clonedFloorUnionArea->exists = false;
$clonedFloorUnionArea->id = null;
$clonedFloorUnionArea->mapping_version_id = $mappingVersion->id;
$clonedFloorUnionArea->floor_union_id = $newParent->id;
$clonedFloorUnionArea->save();

return $clonedFloorUnionArea;
}
}
24 changes: 13 additions & 11 deletions app/Models/Npc.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,17 +327,19 @@ public function createNpcEnemyForcesForExistingMappingVersions(?int $existingEne
{
$result = true;

$this->load('dungeon');
// Create new enemy forces for this enemy for each relevant mapping version
// If no dungeon is found (dungeon_id = -1) we grab all mapping versions instead
$mappingVersions = optional($this->dungeon)->mappingVersions ?? MappingVersion::all();
foreach ($mappingVersions as $mappingVersion) {
$result = $result && NpcEnemyForces::create([
'npc_id' => $this->id,
'mapping_version_id' => $mappingVersion->id,
'enemy_forces' => $existingEnemyForces ?? 0,
'enemy_forces_teeming' => null,
]);
if ($existingEnemyForces > 0) {
$this->load('dungeon');
// Create new enemy forces for this enemy for each relevant mapping version
// If no dungeon is found (dungeon_id = -1) we grab all mapping versions instead
$mappingVersions = optional($this->dungeon)->mappingVersions ?? MappingVersion::all();
foreach ($mappingVersions as $mappingVersion) {
$result = $result && NpcEnemyForces::create([
'npc_id' => $this->id,
'mapping_version_id' => $mappingVersion->id,
'enemy_forces' => $existingEnemyForces ?? 0,
'enemy_forces_teeming' => null,
]);
}
}

return $result;
Expand Down
54 changes: 28 additions & 26 deletions app/Service/MDT/MDTMappingImportService.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,23 @@ private function importNpcs(MappingVersion $newMappingVersion, MDTDungeon $mdtDu

try {
if ($newlyCreated ? $npc->save() : $npc->update()) {
if ($newlyCreated) {
// For new NPCs go back and create enemy forces for all historical mapping versions
$npc->createNpcEnemyForcesForExistingMappingVersions($mdtNpc->getCount());

$this->log->importNpcsSaveNewNpc($npc->id);
} else {
// Create new enemy forces for this NPC for this new mapping version
NpcEnemyForces::create([
'mapping_version_id' => $newMappingVersion->id,
'npc_id' => $npc->id,
'enemy_forces' => $mdtNpc->getCount(),
'enemy_forces_teeming' => null,
]);

$this->log->importNpcsUpdateExistingNpc($npc->id);
if ($mdtNpc->getCount() > 0) {
if ($newlyCreated) {
// For new NPCs go back and create enemy forces for all historical mapping versions
$npc->createNpcEnemyForcesForExistingMappingVersions($mdtNpc->getCount());

$this->log->importNpcsSaveNewNpc($npc->id);
} else {
// Create new enemy forces for this NPC for this new mapping version
NpcEnemyForces::create([
'mapping_version_id' => $newMappingVersion->id,
'npc_id' => $npc->id,
'enemy_forces' => $mdtNpc->getCount(),
'enemy_forces_teeming' => null,
]);

$this->log->importNpcsUpdateExistingNpc($npc->id);
}
}

// If shrouded (zul'gamux) update the mapping version to account for that
Expand Down Expand Up @@ -214,8 +216,8 @@ private function importNpcs(MappingVersion $newMappingVersion, MDTDungeon $mdtDu
* @param MappingVersion $newMappingVersion
* @param MDTDungeon $mdtDungeon
* @param Dungeon $dungeon
* @param bool $forceImport
* @return Collection|Enemy
* @throws InvalidArgumentException
*/
private function importEnemies(
Mappingversion $currentMappingVersion,
Expand Down Expand Up @@ -261,7 +263,7 @@ private function importEnemies(
// We ignore MDT's position - we want to keep agency in the location we place enemies still
// since we value VERY MUCH the enemy location being accurate to where they are in-game
if (!$forceImport) {
$fields = array_merge($fields, ['lat', 'lng']);
$fields = array_merge($fields, ['floor_id', 'lat', 'lng']);
}

$updatedFields = [];
Expand Down Expand Up @@ -313,13 +315,13 @@ private function importEnemyPacks(MappingVersion $newMappingVersion, MDTDungeon
->get();

// Conserve the enemy_pack_id
$enemiesWithGroups = $mdtDungeon->getClonesAsEnemies($newMappingVersion, $dungeon->floors()->active()->get());
$enemyPacks = $enemiesWithGroups->groupBy('enemy_pack_id');
$mdtEnemiesWithGroups = $mdtDungeon->getClonesAsEnemies($newMappingVersion, $dungeon->floors()->active()->get());
$mdtEnemyPacks = $mdtEnemiesWithGroups->groupBy('enemy_pack_id');

// Save enemy packs
foreach ($enemyPacks as $groupIndex => $enemiesWithGroupsByEnemyPack) {
/** @var $enemiesWithGroupsByEnemyPack Collection|Enemy[] */
$enemiesWithGroupsByEnemyPack = $enemiesWithGroupsByEnemyPack
foreach ($mdtEnemyPacks as $groupIndex => $mdtEnemiesWithGroupsByEnemyPack) {
/** @var $mdtEnemiesWithGroupsByEnemyPack Collection|Enemy[] */
$mdtEnemiesWithGroupsByEnemyPack = $mdtEnemiesWithGroupsByEnemyPack
->filter(function (Enemy $enemy) {
return $enemy->teeming === null;
})
Expand All @@ -334,7 +336,7 @@ private function importEnemyPacks(MappingVersion $newMappingVersion, MDTDungeon
// We do not re-import the lat/lng from MDT - we allow ourselves to adjust the lat/lng, so we must
// fetch the adjusted lat/lng by matching enemies with what we actually saved
// 1. Get a list of unique keys which we must look for in the real enemy list
$enemiesWithGroupsByEnemyPackUniqueIds = $enemiesWithGroupsByEnemyPack->map(function (Enemy $enemy) {
$enemiesWithGroupsByEnemyPackUniqueIds = $mdtEnemiesWithGroupsByEnemyPack->map(function (Enemy $enemy) {
return $enemy->getUniqueKey();
});
// 2. Find the enemies that were saved in the database by key
Expand All @@ -344,7 +346,7 @@ private function importEnemyPacks(MappingVersion $newMappingVersion, MDTDungeon

$enemyPack = EnemyPack::create([
'mapping_version_id' => $newMappingVersion->id,
'floor_id' => $enemiesWithGroupsByEnemyPack->first()->floor_id,
'floor_id' => $boundingBoxEnemies->first()->floor_id,
'group' => $groupIndex,
'teeming' => null,
'faction' => Faction::FACTION_ANY,
Expand All @@ -355,13 +357,13 @@ private function importEnemyPacks(MappingVersion $newMappingVersion, MDTDungeon
if ($enemyPack === null) {
throw new Exception('Unable to save enemy pack!');
}
$this->log->importEnemyPacksSaveNewEnemyPackOK($enemyPack->id, $enemiesWithGroupsByEnemyPack->count());
$this->log->importEnemyPacksSaveNewEnemyPackOK($enemyPack->id, $mdtEnemiesWithGroupsByEnemyPack->count());

try {
$this->log->importEnemyPacksCoupleEnemyToPackStart($enemyPack->id);
// logger()->channel('stderr')->info(sprintf('- Enemy Pack %d OK (%d enemies)', $enemyPack->id, $enemiesWithGroupsByEnemyPack->count()));

foreach ($enemiesWithGroupsByEnemyPack as $enemyWithGroup) {
foreach ($mdtEnemiesWithGroupsByEnemyPack as $enemyWithGroup) {
// In the list of enemies that we saved to the database, find the enemy that still had the group intact.
// Write the saved enemy's enemy pack back to the database
$savedEnemy = $this->findSavedEnemyFromCloneEnemy($savedEnemies, $enemyWithGroup->npc_id, $enemyWithGroup->mdt_id);
Expand Down
6 changes: 5 additions & 1 deletion app/Service/Mapping/MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function createNewMappingVersionFromMDTMapping(Dungeon $dungeon, ?string

$newMappingVersion = MappingVersion::find($id);

// Copy all map icons over from the previous mapping version - this allows us to keep adding icons regardless of
// Copy all elements over from the previous mapping version - this allows us to keep adding elements regardless of
// MDT mapping
if ($currentMappingVersion !== null) {
foreach ($currentMappingVersion->mapIcons as $mapIcon) {
Expand All @@ -120,6 +120,10 @@ public function createNewMappingVersionFromMDTMapping(Dungeon $dungeon, ?string
foreach ($currentMappingVersion->floorUnions as $floorUnion) {
$floorUnion->cloneForNewMappingVersion($newMappingVersion);
}

foreach ($currentMappingVersion->floorUnionAreas as $floorUnionArea) {
$floorUnionArea->cloneForNewMappingVersion($newMappingVersion);
}
}

return $newMappingVersion;
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@
"type": "package",
"package": {
"name": "nnoggie/mythicdungeontools",
"version": "4.2.0.4",
"version": "4.2.0.7",
"source": {
"url": "https://github.com/Wotuu/MythicDungeonTools.git",
"type": "git",
"reference": "f49eade2111e160b6d30490766cb6110b2b1bf6b"
"reference": "34bbdddaf1dd277995aad922b166fc4d081263a0"
}
}
}
Expand Down Expand Up @@ -56,7 +56,7 @@
"laravel/ui": "^3.0",
"laravelcollective/html": "6.3.*",
"marvinlabs/laravel-discord-logger": "^1.1",
"nnoggie/mythicdungeontools": "4.2.0.4",
"nnoggie/mythicdungeontools": "4.2.0.7",
"paquettg/php-html-parser": "^3.0",
"patreon/patreon": "^1.0.0",
"phlak/semver": "^4.0",
Expand Down
6 changes: 3 additions & 3 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion database/seeders/AffixSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ public function run()

['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_TYRANNICAL, Affix::AFFIX_AFFLICTED, Affix::AFFIX_BOLSTERING], 'confirmed' => false],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_FORTIFIED, Affix::AFFIX_INCORPOREAL, Affix::AFFIX_SANGUINE]],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_TYRANNICAL, Affix::AFFIX_ENTANGLING, Affix::AFFIX_BURSTING], 'confirmed' => false],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_TYRANNICAL, Affix::AFFIX_ENTANGLING, Affix::AFFIX_BURSTING]],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_FORTIFIED, Affix::AFFIX_VOLCANIC, Affix::AFFIX_SPITEFUL], 'confirmed' => false],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_TYRANNICAL, Affix::AFFIX_STORMING, Affix::AFFIX_RAGING], 'confirmed' => false],
['season_id' => 12, 'expansion_id' => $expansions->get(Expansion::EXPANSION_DRAGONFLIGHT), 'affixes' => [Affix::AFFIX_FORTIFIED, Affix::AFFIX_ENTANGLING, Affix::AFFIX_BOLSTERING], 'confirmed' => false],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,25 @@
"direction": null,
"lat": -155.76,
"lng": 242
},
{
"id": 1009,
"mapping_version_id": 277,
"floor_id": 41,
"source_floor_id": null,
"target_floor_id": 42,
"direction": null,
"lat": -92.51,
"lng": 240.25
},
{
"id": 1010,
"mapping_version_id": 277,
"floor_id": 41,
"source_floor_id": null,
"target_floor_id": 42,
"direction": null,
"lat": -155.76,
"lng": 242
}
]
Loading

0 comments on commit 01a6892

Please sign in to comment.