Skip to content

Commit

Permalink
fix: myo slot tag not working due to lineages
Browse files Browse the repository at this point in the history
  • Loading branch information
ScuffedNewt committed Feb 10, 2024
1 parent 23e0eea commit 5103906
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 11 additions & 5 deletions app/Services/CharacterManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,11 @@ public function createCharacter($data, $user, $isMyo = false) {
}

// Create character lineage
$lineage = $this->handleCharacterLineage($data, $character, $isMyo);
if (!$lineage) {
throw new \Exception('Error happened while trying to create lineage.');
if (isset($data['parent_1_id']) || isset($data['parent_1_name']) || isset($data['parent_2_id']) || isset($data['parent_2_name'])) {
$lineage = $this->handleCharacterLineage($data, $character);
if (!$lineage) {
throw new \Exception('Error happened while trying to create lineage.');
}
}

// Create character image
Expand Down Expand Up @@ -2122,7 +2124,7 @@ public function updateCharacterLineage($data, $character, $user, $isAdmin = fals
if(!$user->hasPower('manage_characters')) throw new \Exception('You do not have the required permissions to do this.');

if (!$character->lineage) {
return $this->handleCharacterLineage($data, $character, $character->is_myo_slot);
return $this->handleCharacterLineage($data, $character);
} else {
$character->lineage->update([
'parent_1_id' => $data['parent_1_id'] ?? null,
Expand All @@ -2149,10 +2151,14 @@ public function updateCharacterLineage($data, $character, $user, $isAdmin = fals
* @param bool $isMyo
* @return \App\Models\Character\CharacterLineage|bool
*/
private function handleCharacterLineage($data, $character, $isMyo = false)
private function handleCharacterLineage($data, $character)
{
try {

if (!isset($data['parent_1_id']) && !isset($data['parent_1_name']) && !isset($data['parent_2_id']) && !isset($data['parent_2_name'])) {
throw new \Exception('No lineage data provided.');
}

// check parent ids if set to see if character exists
if (isset($data['parent_1_id']) && $data['parent_1_id']) {
$parent_1 = Character::find($data['parent_1_id']);
Expand Down
3 changes: 3 additions & 0 deletions app/Services/Item/SlotService.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ public function act($stacks, $user, $data) {
if ($character = $charService->createCharacter($characterData, $user, true)) {
flash('<a href="'.$character->url.'">MYO slot</a> created successfully.')->success();
} else {
foreach ($charService->errors()->getMessages()['error'] as $error) {
flash($error)->error();
}
throw new \Exception('Failed to use slot.');
}
}
Expand Down

0 comments on commit 5103906

Please sign in to comment.