Skip to content

Commit

Permalink
Merge pull request #2115 from Wotuu/development
Browse files Browse the repository at this point in the history
Release v7.4.6 - MDT string export for combined floors now works properly.
  • Loading branch information
Wotuu authored Nov 13, 2023
2 parents dfc2ac4 + b55cb71 commit fa9dd51
Show file tree
Hide file tree
Showing 31 changed files with 400 additions and 143 deletions.
34 changes: 30 additions & 4 deletions app/Http/Controllers/DungeonRouteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ public function viewfloor(
DungeonRoute $dungeonroute,
string $title,
string $floorIndex
)
{
) {
$this->authorize('view', $dungeonroute);

if (!is_numeric($floorIndex)) {
Expand Down Expand Up @@ -139,6 +138,15 @@ public function viewfloor(
'floorindex' => optional($defaultFloor)->index ?? '1',
]);
} else {
if ($floor->index !== (int)$floorIndex) {
return redirect()->route('dungeonroute.view.floor', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
'title' => $dungeonroute->getTitleSlug(),
'floorindex' => $floor->index,
]);
}

return view('dungeonroute.view', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
Expand Down Expand Up @@ -237,6 +245,15 @@ public function presentFloor(
'floorindex' => optional($defaultFloor)->index ?? '1',
]);
} else {
if ($floor->index !== (int)$floorIndex) {
return redirect()->route('dungeonroute.present.floor', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
'title' => $dungeonroute->getTitleSlug(),
'floorindex' => $floor->index,
]);
}

return view('dungeonroute.present', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
Expand Down Expand Up @@ -265,8 +282,7 @@ public function preview(
DungeonRoute $dungeonroute,
string $title,
string $floorIndex
)
{
) {
$this->authorize('preview', [$dungeonroute, $request->get('secret', '') ?? '']);

if (!is_numeric($floorIndex)) {
Expand All @@ -285,6 +301,7 @@ public function preview(

/** @var FLoor $floor */
$floor = Floor::where('dungeon_id', $dungeonroute->dungeon_id)->where('index', $floorIndex)->first();

return view('dungeonroute.preview', [
'dungeonroute' => $dungeonroute,
'floorId' => $floor->id,
Expand Down Expand Up @@ -490,6 +507,15 @@ public function editfloor(
'floorindex' => optional($defaultFloor)->index ?? '1',
]);
} else {
if ($floor->index !== (int)$floorIndex) {
return redirect()->route('dungeonroute.edit.floor', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
'title' => $dungeonroute->getTitleSlug(),
'floorindex' => $floor->index,
]);
}

return view('dungeonroute.edit', [
'dungeon' => $dungeonroute->dungeon,
'dungeonroute' => $dungeonroute,
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/DungeonFormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public function rules(): array
return [
'active' => 'nullable|boolean',
'speedrun_enabled' => 'nullable|boolean',
'facade_enabled' => 'nullable|boolean',
'game_version_id' => Rule::exists(GameVersion::class, 'id'),
'zone_id' => 'int',
'map_id' => 'int',
Expand Down
3 changes: 1 addition & 2 deletions app/Logic/MapContext/MapContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,9 @@ public abstract function getEchoChannelName(): string;

public function getMapFacadeStyle(): string
{
return $_COOKIE['map_facade_style'] ?? 'facade';
return $_COOKIE['map_facade_style'] ?? 'split_floors';
}


/**
* @return Model
*/
Expand Down
153 changes: 74 additions & 79 deletions app/Models/Dungeon.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* @property string $slug The url friendly slug of the dungeon.
* @property string $key Shorthand key of the dungeon
* @property boolean $speedrun_enabled True if this dungeon has a speedrun enabled, false if it does not.
* @property boolean $facade_enabled True if this dungeon uses facades, false if it does not.
* @property boolean $active True if this dungeon is active, false if it is not.
*
* @property Expansion $expansion
Expand Down Expand Up @@ -74,6 +75,7 @@ class Dungeon extends CacheModel implements MappingModelInterface
'game_version_id',
'active',
'speedrun_enabled',
'facade_enabled',
'zone_id',
'map_id',
'challenge_mode_id',
Expand Down Expand Up @@ -420,15 +422,6 @@ class Dungeon extends CacheModel implements MappingModelInterface
],
];

// @TODO Revamp this
const USES_FACADE = [
105, // self::DUNGEON_DAWN_OF_THE_INFINITE_GALAKRONDS_FALL
106, // self::DUNGEON_DAWN_OF_THE_INFINITE_MUROZONDS_RISE
103, // self::DUNGEON_THRONE_OF_THE_TIDES
2, // self::DUNGEON_BLACK_ROOK_HOLD
23, // self::DUNGEON_WAYCREST_MANOR
];

/**
* https://stackoverflow.com/a/34485411/771270
* @return string
Expand Down Expand Up @@ -530,20 +523,22 @@ public function floorsForMapFacade(bool $useFacade): HasMany
// Otherwise, return all non-facade floors

return $this->hasMany(Floor::class)
->where(function (Builder $builder) use ($useFacade) {
$builder->when(!$useFacade, function (Builder $builder) use ($useFacade) {
$builder->where('facade', 0);
})->when($useFacade, function (Builder $builder) use ($useFacade) {
$builder->where(function (Builder $builder) use ($useFacade) {
$builder->whereIn('dungeon_id', self::USES_FACADE)
->where('facade', $useFacade);
})->orWhere(function (Builder $builder) use ($useFacade) {
$builder->whereNotIn('dungeon_id', self::USES_FACADE)
->where('facade', 0);
});
});
})
->orderBy('index');
->select('floors.*')
->join('dungeons', 'floors.dungeon_id', 'dungeons.id')
->where(function (Builder $builder) use ($useFacade) {
$builder->when(!$useFacade, function (Builder $builder) use ($useFacade) {
$builder->where('facade', 0);
})->when($useFacade, function (Builder $builder) use ($useFacade) {
$builder->where(function (Builder $builder) use ($useFacade) {
$builder->where('facade_enabled', true)
->where('facade', $useFacade);
})->orWhere(function (Builder $builder) use ($useFacade) {
$builder->where('facade_enabled', false)
->where('facade', 0);
});
});
})
->orderBy('index');
}

/**
Expand All @@ -562,9 +557,9 @@ public function dungeonRoutes(): HasMany
public function npcs(bool $includeGlobalNpcs = true): HasMany
{
return $this->hasMany(Npc::class)
->when($includeGlobalNpcs, function (Builder $builder) {
$builder->orWhere('dungeon_id', -1);
});
->when($includeGlobalNpcs, function (Builder $builder) {
$builder->orWhere('dungeon_id', -1);
});
}

/**
Expand Down Expand Up @@ -597,10 +592,10 @@ public function enemypatrols(): HasManyThrough
public function mapicons(): HasManyThrough
{
return $this->hasManyThrough(MapIcon::class, Floor::class)
->where(function (Builder $builder) {
return $builder
->whereNull('dungeon_route_id');
});
->where(function (Builder $builder) {
return $builder
->whereNull('dungeon_route_id');
});
}

/**
Expand All @@ -625,7 +620,7 @@ public function mountableareas(): HasManyThrough
public function dungeonSpeedrunRequiredNpcs10Man(): HasManyThrough
{
return $this->hasManyThrough(DungeonSpeedrunRequiredNpc::class, Floor::class)
->where('difficulty', Dungeon::DIFFICULTY_10_MAN);
->where('difficulty', Dungeon::DIFFICULTY_10_MAN);
}

/**
Expand All @@ -634,7 +629,7 @@ public function dungeonSpeedrunRequiredNpcs10Man(): HasManyThrough
public function dungeonSpeedrunRequiredNpcs25Man(): HasManyThrough
{
return $this->hasManyThrough(DungeonSpeedrunRequiredNpc::class, Floor::class)
->where('difficulty', Dungeon::DIFFICULTY_25_MAN);
->where('difficulty', Dungeon::DIFFICULTY_25_MAN);
}

/**
Expand Down Expand Up @@ -766,18 +761,18 @@ private function getNpcsHealthBuilder(MappingVersion $mappingVersion): HasMany
{
return $this->npcs(false)
// Ensure that there's at least one enemy by having this join
->join('enemies', 'enemies.npc_id', 'npcs.id')
->where('enemies.mapping_version_id', $mappingVersion->id)
->where('classification_id', '<', NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_BOSS])
->where('npc_type_id', '!=', NpcType::CRITTER)
->whereIn('aggressiveness', [Npc::AGGRESSIVENESS_AGGRESSIVE, Npc::AGGRESSIVENESS_UNFRIENDLY, Npc::AGGRESSIVENESS_AWAKENED])
->when(!in_array($this->key, $this->getNpcsHealthBuilderEnemyForcesDungeonExclusionList()),
function (Builder $builder) use ($mappingVersion) {
return $builder
->join('npc_enemy_forces', 'npc_enemy_forces.npc_id', 'npcs.id')
->where('npc_enemy_forces.mapping_version_id', $mappingVersion->id);
})
->groupBy('enemies.npc_id');
->join('enemies', 'enemies.npc_id', 'npcs.id')
->where('enemies.mapping_version_id', $mappingVersion->id)
->where('classification_id', '<', NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_BOSS])
->where('npc_type_id', '!=', NpcType::CRITTER)
->whereIn('aggressiveness', [Npc::AGGRESSIVENESS_AGGRESSIVE, Npc::AGGRESSIVENESS_UNFRIENDLY, Npc::AGGRESSIVENESS_AWAKENED])
->when(!in_array($this->key, $this->getNpcsHealthBuilderEnemyForcesDungeonExclusionList()),
function (Builder $builder) use ($mappingVersion) {
return $builder
->join('npc_enemy_forces', 'npc_enemy_forces.npc_id', 'npcs.id')
->where('npc_enemy_forces.mapping_version_id', $mappingVersion->id);
})
->groupBy('enemies.npc_id');
}

/**
Expand Down Expand Up @@ -810,39 +805,39 @@ public function getNpcsMaxHealth(MappingVersion $mappingVersion): int
public function getInUseNpcs(): Collection
{
return Npc::select('npcs.*')
->leftJoin('npc_enemy_forces', 'npcs.id', 'npc_enemy_forces.npc_id')
->where(function (Builder $builder) {
return $builder->where('npcs.dungeon_id', $this->id)
->orWhere('npcs.dungeon_id', -1);
})
->where('npc_enemy_forces.mapping_version_id', $this->getCurrentMappingVersion()->id)
->where(function (Builder $builder) {
$builder->whereNotNull('npc_enemy_forces.enemy_forces')
->orWhereIn('npcs.classification_id', [
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_BOSS],
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_FINAL_BOSS],
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_RARE],
])
->orWhereIn('npcs.id', [
// Neltharion's Lair Burning Geodes are in the mapping but give 0 enemy forces.
// They're in the mapping because they're dangerous af
101437,
// Halls of Infusion: Aqua Ragers are in the mapping but give 0 enemy forces - so would be excluded.
// They're in the mapping because they are a significant drain on time and excluding them would raise questions about why they're gone
190407,
// Brackenhide Hollow: Witherlings that are a significant nuisance to be included in the mapping. They give 0 enemy forces.
194273,
// Rotfang Hyena are part of Gutshot boss but, they are part of the mapping. They give 0 enemy forces.
194745,
// Wild Lashers give 0 enemy forces but are in the mapping regardless
191243,
// Wither Slashers give 0 enemy forces but are in the mapping regardless
194469,
// Gutstabbers give 0 enemy forces but are in the mapping regardless
197857,
]);
})
->get();
->leftJoin('npc_enemy_forces', 'npcs.id', 'npc_enemy_forces.npc_id')
->where(function (Builder $builder) {
return $builder->where('npcs.dungeon_id', $this->id)
->orWhere('npcs.dungeon_id', -1);
})
->where('npc_enemy_forces.mapping_version_id', $this->getCurrentMappingVersion()->id)
->where(function (Builder $builder) {
$builder->whereNotNull('npc_enemy_forces.enemy_forces')
->orWhereIn('npcs.classification_id', [
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_BOSS],
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_FINAL_BOSS],
NpcClassification::ALL[NpcClassification::NPC_CLASSIFICATION_RARE],
])
->orWhereIn('npcs.id', [
// Neltharion's Lair Burning Geodes are in the mapping but give 0 enemy forces.
// They're in the mapping because they're dangerous af
101437,
// Halls of Infusion: Aqua Ragers are in the mapping but give 0 enemy forces - so would be excluded.
// They're in the mapping because they are a significant drain on time and excluding them would raise questions about why they're gone
190407,
// Brackenhide Hollow: Witherlings that are a significant nuisance to be included in the mapping. They give 0 enemy forces.
194273,
// Rotfang Hyena are part of Gutshot boss but, they are part of the mapping. They give 0 enemy forces.
194745,
// Wild Lashers give 0 enemy forces but are in the mapping regardless
191243,
// Wither Slashers give 0 enemy forces but are in the mapping regardless
194469,
// Gutstabbers give 0 enemy forces but are in the mapping regardless
197857,
]);
})
->get();
}


Expand All @@ -852,12 +847,12 @@ public function getInUseNpcs(): Collection
public function getInUseNpcIds(): Collection
{
return $this->getInUseNpcs()
->pluck('id')
->pluck('id')
// Brackenhide Hollow: Odd exception to make Brackenhide Gnolls show up. They aren't in the MDT mapping, so
// they don't get npc_enemy_forces pushed. But we do need them to show up for us since they convert
// into Witherlings which ARE on the mapping. Without this exception, they wouldn't turn up and the
// Witherlings would never get mapped properly
->push(194373);
->push(194373);
}

/**
Expand Down
21 changes: 17 additions & 4 deletions app/Models/Floor/Floor.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,23 @@ public function scopeIndexOrFacade(Builder $builder, int $floorIndex): Builder
{
$useFacade = ($_COOKIE['map_facade_style'] ?? 'split_floors') === 'facade';

// @TODO prevent navigation to facade floor when NOT in facade mode
return $builder->where(function (Builder $builder) use ($floorIndex) {
$builder->where('facade', 1)
->orWhere('index', $floorIndex);
// Facade should be FORCED to use floor index 1
if ($useFacade && $floorIndex > 1) {
$floorIndex = 1;
}

// Either grab the facade floor, or grab the requested floor _as long as it's not the facade floor_, otherwise return the default floor
return $builder->where(function (Builder $builder) use ($useFacade, $floorIndex) {
return $builder->when($useFacade, function (Builder $builder) {
return $builder->where('facade', 1);
})->when(!$useFacade, function (Builder $builder) use ($floorIndex) {
return $builder->where('facade', 0)
->where(function (Builder $builder) use ($floorIndex) {
// Either try to resolve the actual floor, or revert to the default if not found
$builder->where('index', $floorIndex)
->orWhere('default', 1);
});
});
})->orderByDesc($useFacade ? 'facade' : 'default')
->limit(1);
}
Expand Down
Loading

0 comments on commit fa9dd51

Please sign in to comment.