From f133c50f1caf621345009b139dc2ca8be73ebb01 Mon Sep 17 00:00:00 2001 From: ScuffedNewt Date: Fri, 17 Nov 2023 13:00:11 +0000 Subject: [PATCH] misc bugs --- app/Services/Item/BoostService.php | 2 +- app/Services/Item/PairingService.php | 17 ++++++----- app/Services/PairingManager.php | 28 ++++++++++--------- .../views/admin/items/tags/boost.blade.php | 8 +++--- .../views/admin/items/tags/pairing.blade.php | 8 +++--- 5 files changed, 32 insertions(+), 31 deletions(-) diff --git a/app/Services/Item/BoostService.php b/app/Services/Item/BoostService.php index 12922d28f4..9a733f89df 100644 --- a/app/Services/Item/BoostService.php +++ b/app/Services/Item/BoostService.php @@ -73,7 +73,7 @@ public function updateData($tag, $data) { } $boostData = []; - if (isset($data['setting']) || $data['setting'] == 0) { + if (isset($data['setting'])) { $boostData['setting'] = $data['setting']; $boostData['setting_chance'] = $data['setting_chance']; } diff --git a/app/Services/Item/PairingService.php b/app/Services/Item/PairingService.php index 61483b6e0a..52495ac920 100644 --- a/app/Services/Item/PairingService.php +++ b/app/Services/Item/PairingService.php @@ -29,14 +29,13 @@ public function getEditData() { 'features' => Feature::orderBy('name')->pluck('name', 'id'), 'specieses' => Species::orderBy('name')->pluck('name', 'id'), 'subtypes' => Subtype::orderBy('name')->pluck('name', 'id'), - ]; } /** * Processes the data attribute of the tag and returns it in the preferred format. * - * @param string $tag + * @param mixed $tag * * @return mixed */ @@ -47,7 +46,7 @@ public function getTagData($tag) { /** * Processes the data attribute of the tag and returns it in the preferred format. * - * @param string $tag + * @param mixed $tag * @param array $data * * @return bool @@ -66,9 +65,9 @@ public function updateData($tag, $data) { $pairingData = []; - $specieses = isset($data['illegal_species_id']) ? array_filter($data['illegal_species_id']) : []; - $features = isset($data['illegal_feature_id']) ? array_filter($data['illegal_feature_id']) : []; - $subtypes = isset($data['illegal_subtype_id']) ? array_filter($data['illegal_subtype_id']) : []; + $specieses = isset($data['illegal_species_ids']) ? array_filter($data['illegal_species_ids']) : []; + $features = isset($data['illegal_feature_ids']) ? array_filter($data['illegal_feature_ids']) : []; + $subtypes = isset($data['illegal_subtype_ids']) ? array_filter($data['illegal_subtype_ids']) : []; if (isset($data['feature_id'])) { $pairingData['feature_id'] = $data['feature_id']; @@ -92,13 +91,13 @@ public function updateData($tag, $data) { $pairingData['max'] = $data['max']; if (count($specieses) > 0) { - $pairingData['illegal_species_id'] = $specieses; + $pairingData['illegal_species_ids'] = $specieses; } if (count($features) > 0) { - $pairingData['illegal_feature_id'] = $features; + $pairingData['illegal_feature_ids'] = $features; } if (count($subtypes) > 0) { - $pairingData['illegal_subtype_id'] = $subtypes; + $pairingData['illegal_subtype_ids'] = $subtypes; } DB::beginTransaction(); diff --git a/app/Services/PairingManager.php b/app/Services/PairingManager.php index 4c269944c0..9071b80e93 100644 --- a/app/Services/PairingManager.php +++ b/app/Services/PairingManager.php @@ -211,17 +211,17 @@ public function validatePairingBasics($character_codes, $pairing_item) { //pairing type 0 = species, 1 = subtype $pairing_type = $tag->getData()['pairing_type'] ?? null; if (isset($pairing_type)) { - if ($pairing_type && $species_1->id != $species_2->id) { - throw new \Exception('A subtype pairing can only be done with characters of the same species.'); + if ($pairing_type && $character_1->image->subtype_id != $character_2->image->subtype_id) { + throw new \Exception('A subtype pairing can only be done with characters of the same subtype.'); } - if (!$pairing_type && $species_1->id == $species_2->id) { + if (!$pairing_type && $species_1->id != $species_2->id) { throw new \Exception('A species pairing can only be done with characters of the same species.'); } } // check if correct species was used for the characters - $illegal_species = (isset($tag->getData()['illegal_species_id'])) ? $tag->getData()['illegal_species_id'] : null; - $valid_species_ids = array_diff([$species_1->id, $species_2->id], $illegal_species ?? []); + $illegal_species_ids = (isset($tag->getData()['illegal_species_ids'])) ? $tag->getData()['illegal_species_ids'] : null; + $valid_species_ids = array_unique(array_diff([$species_1->id, $species_2->id], $illegal_species_ids ?? [])); if (count($valid_species_ids) < 1 && !isset($tag->getData()['default_species_id'])) { throw new \Exception('This item cannot create a pairing from the specieses of the chosen characters.'); @@ -564,9 +564,9 @@ public function rollTestMyos($data, $user) { $test_myos[] = [ 'user' => $user, 'sex' => $sex, - 'species' => Species::where('id', $species_id)->first()->displayName, - 'subtype' => Subtype::where('id', $subtype_id)->first()?->displayName, - 'rarity' => Rarity::where('id', $rarity_id)->first()->displayName, + 'species' => Species::find($species_id)->displayName, + 'subtype' => Subtype::find($subtype_id)?->displayName, + 'rarity' => Rarity::find($rarity_id)->displayName, 'features' => $chosen_features_ids, 'feature_data' => $feature_data, ]; @@ -749,9 +749,8 @@ private function getChosenFeatures($tag, $characters, $feature_pool, $boosts) { } } - //set pairing feature if parents are of different subtypes or species - if (isset($tag->getData()['feature_id']) && - ($characters[0]->image->subtype_id != $characters[1]->image->subtype_id || $characters[0]->image->species_id != $characters[1]->image->species_id)) { + // set pairing feature + if (isset($tag->getData()['feature_id'])) { $pairing_feature = Feature::where('id', $tag->getData()['feature_id'])->first(); $chosen_features[$pairing_feature->id] = $pairing_feature; } @@ -826,7 +825,7 @@ private function getSpeciesId($tag, $species, $inherit) { $illegal_species_ids = $tag->getData()['illegal_species_ids'] ?? null; $default_species_id = $tag->getData()['default_species_id'] ?? null; - $valid_species_ids = array_diff([$species[0]->id, $species[1]->id], $illegal_species_ids ?? []); + $valid_species_ids = array_unique(array_diff([$species[0]->id, $species[1]->id], $illegal_species_ids ?? [])); if (count($valid_species_ids) > 1) { // chance of inheriting either species when both are valid @@ -839,7 +838,10 @@ private function getSpeciesId($tag, $species, $inherit) { } elseif (count($valid_species_ids) == 1) { return $valid_species_ids[0]; } else { - return $default_species_id; //should never be null as pairing gets rejected when no default is set and no species is valid + if (!$default_species_id) { + throw new \Exception('No default species was set for this item.'); + } + return $default_species_id; // should never be null as pairing gets rejected when no default is set and no species is valid } } diff --git a/resources/views/admin/items/tags/boost.blade.php b/resources/views/admin/items/tags/boost.blade.php index 20cfa78cca..e3ef0b47f2 100644 --- a/resources/views/admin/items/tags/boost.blade.php +++ b/resources/views/admin/items/tags/boost.blade.php @@ -38,8 +38,8 @@ -@section('scripts') - -@endsection + }); + diff --git a/resources/views/admin/items/tags/pairing.blade.php b/resources/views/admin/items/tags/pairing.blade.php index dc62b7039d..069fded56c 100644 --- a/resources/views/admin/items/tags/pairing.blade.php +++ b/resources/views/admin/items/tags/pairing.blade.php @@ -3,7 +3,7 @@

Basics

-

Pairings can be restricted to either be between the same species or between subtypes of the same species. +

Pairings can be restricted to either be between the same species, or between the same subtypes of the same species.
Leave empty if you want to allow all pairings.

@@ -24,7 +24,7 @@

Offspring Traits (Optional)

If a trait is set, this trait will be granted to all offspring that are created using this item. -
Other pairing items can still inherit this trait if present in one or more . +
Other pairing items can still inherit this trait if present in one or both parents.

If a species is set, the offspring will always be that species, but the MYO may have traits of either parent ignoring species restrictions.
If a subtype is set, it will always be passed on if the species matches.
If neither is set, traits and species are chosen solely from the parent characters. @@ -85,7 +85,7 @@ Remove - @if (isset($tag->getData()['illegal_species_ids']) && count($tag->getData()['illegal_species_id']) > 0) + @if (isset($tag->getData()['illegal_species_ids']) && count($tag->getData()['illegal_species_ids']) > 0) @foreach ($tag->getData()['illegal_species_ids'] as $illegal_species_id) @@ -126,7 +126,7 @@ Remove - @if (isset($tag->getData()['illegal_subtype_ids']) && count($tag->getData()['illegal_subtype_id']) > 0) + @if (isset($tag->getData()['illegal_subtype_ids']) && count($tag->getData()['illegal_subtype_ids']) > 0) @foreach ($tag->getData()['illegal_subtype_ids'] as $illegal_subtype_id)