Skip to content

Commit

Permalink
misc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Nov 17, 2023
1 parent 49f2a73 commit f133c50
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 31 deletions.
2 changes: 1 addition & 1 deletion app/Services/Item/BoostService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
17 changes: 8 additions & 9 deletions app/Services/Item/PairingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
Expand All @@ -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'];
Expand All @@ -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();
Expand Down
28 changes: 15 additions & 13 deletions app/Services/PairingManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand Down Expand Up @@ -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,
];
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand All @@ -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
}
}

Expand Down
8 changes: 4 additions & 4 deletions resources/views/admin/items/tags/boost.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
</div>
</div>

@section('scripts')
<script>
<script>
$(document).ready(function() {
$('#settingSelect').on('change', function() {
if ($(this).val() == '') {
$('#rarities').css('opacity', '1');
Expand Down Expand Up @@ -71,5 +71,5 @@
$('.setting-percent').prop('disabled', true);
}
});
</script>
@endsection
});
</script>
8 changes: 4 additions & 4 deletions resources/views/admin/items/tags/pairing.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<hr>
<h3>Basics</h3>
<p>Pairings can be restricted to either be between the same species or between subtypes of the same species.
<p>Pairings can be restricted to either be between the same species, or between the same subtypes of the same species.
<br><b>Leave empty if you want to allow all pairings.</b>
</p>
<div class="form-group">
Expand All @@ -24,7 +24,7 @@
<h3>Offspring Traits (Optional)</h3>
<p>
If a trait is set, this trait will be granted to all offspring that are created using this item.
<br><b>Other pairing items can still inherit this trait if present in one or more .</b>
<br><b>Other pairing items can still inherit this trait if present in one or both parents.</b>
<br><br>If a species is set, the offspring will always be that species, but the MYO may have traits of either parent ignoring species restrictions.
<br>If a subtype is set, it will always be passed on if the species matches.
<br>If neither is set, traits and species are chosen solely from the parent characters.
Expand Down Expand Up @@ -85,7 +85,7 @@
</td>
<td class="text-right border-0"><a href="#" class="btn btn-danger remove-species-button">Remove</a></td>
</tr>
@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)
<tr class="loot-row">
<td class="loot-row-select border-0">
Expand Down Expand Up @@ -126,7 +126,7 @@
</td>
<td class="text-right border-0"><a href="#" class="btn btn-danger remove-subtype-button">Remove</a></td>
</tr>
@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)
<tr class="loot-row">
<td class="loot-row-select border-0">
Expand Down

0 comments on commit f133c50

Please sign in to comment.