From 80e736d878471bf45db2ef2dccd3b949e8c0e176 Mon Sep 17 00:00:00 2001 From: Vari Date: Wed, 6 Mar 2024 21:16:34 +0100 Subject: [PATCH] Some more fixing of processing leveling correctly and challenge processing adding the progress to the wrong user. --- dist/app/Enums/Game/Characters.php | 5 +++++ .../Api/Matchmaking/MatchmakingController.php | 8 +------ .../Api/Player/ChallengeController.php | 4 ++-- dist/app/Models/Game/CharacterData.php | 18 +++++++++++++++ dist/app/Models/User/PlayerData.php | 22 +++++++++++++++++++ 5 files changed, 48 insertions(+), 9 deletions(-) diff --git a/dist/app/Enums/Game/Characters.php b/dist/app/Enums/Game/Characters.php index 4c78957..9ef5ade 100644 --- a/dist/app/Enums/Game/Characters.php +++ b/dist/app/Enums/Game/Characters.php @@ -32,6 +32,11 @@ public function getCharacter(): Runner|Hunter return Runner::tryFrom($this->value) ?? Hunter::tryFrom($this->value); } + public function getFaction(): Faction + { + return $this->isRunner() ? Faction::Runner : Faction::Hunter; + } + public function isHunter(): bool { return Hunter::tryFrom($this->value) !== null; diff --git a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php index d29f8df..d30fcdf 100644 --- a/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php +++ b/dist/app/Http/Controllers/Api/Matchmaking/MatchmakingController.php @@ -143,13 +143,7 @@ public function playerEndOfMatch(PlayerEndOfMatchRequest $request) $characterData = $playerData->characterDataForCharacter($request->characterGroup->getCharacter()); foreach ($request->experienceEvents as $experienceEvent) { - $characterData->experience += $experienceEvent['amount']; - - $xpToReach = CharacterData::getExperienceForLevel($characterData->level); - if ($characterData->experience >= $xpToReach) { - ++$characterData->level; - $characterData->experience -= $xpToReach; - } + $characterData->addExperience($experienceEvent['amount']); } $characterData->save(); diff --git a/dist/app/Http/Controllers/Api/Player/ChallengeController.php b/dist/app/Http/Controllers/Api/Player/ChallengeController.php index 003dd17..ce9f515 100644 --- a/dist/app/Http/Controllers/Api/Player/ChallengeController.php +++ b/dist/app/Http/Controllers/Api/Player/ChallengeController.php @@ -90,9 +90,9 @@ public function executeChallengeProgressionBatch(ExecuteChallengeProgressionBatc continue; if($operation['operationName'] === 'complete') - $this->setChallengeAsCompleted($challengeId, $user); + $this->setChallengeAsCompleted($challengeId, $progressUser); else - $this->addProgressToChallenge($challengeId, round($operation['operationData']['value']), $user); + $this->addProgressToChallenge($challengeId, round($operation['operationData']['value']), $progressUser); $processedChallenges[] = $challengeId; } } diff --git a/dist/app/Models/Game/CharacterData.php b/dist/app/Models/Game/CharacterData.php index 0e37bdb..613787f 100644 --- a/dist/app/Models/Game/CharacterData.php +++ b/dist/app/Models/Game/CharacterData.php @@ -76,6 +76,24 @@ public function getPicketChallengeForItem(UuidInterface $uuid): Collection|Picke return $challenges->firstWhere('catalog_item_id', '=', $uuid->toString()); } + public function addExperience(int $experienceToAdd): CharacterData + { + $xpToReach = static::getExperienceForLevel($this->level); + $this->experience += $experienceToAdd; + + // if we reached teh experience threshold, add a level to the character and faction + // Set the new xp to reach and do it again if necessary. + while ($xpToReach >= $this->experience) { + ++$this->level; + $this->experience -= $xpToReach; + $this->playerData->addFactionExperience($this->character->getFaction()); + $xpToReach = static::getExperienceForLevel($this->level); + $this->playerData->save(); + } + + return $this; + } + public static function getExperienceForLevel(int $level): int { --$level; diff --git a/dist/app/Models/User/PlayerData.php b/dist/app/Models/User/PlayerData.php index 1b22de1..1d79636 100644 --- a/dist/app/Models/User/PlayerData.php +++ b/dist/app/Models/User/PlayerData.php @@ -142,6 +142,28 @@ public function getCumulativeExperience(): int return $experience; } + public function addFactionExperience(Faction $faction): PlayerData + { + if($faction === Faction::Runner) { + ++$this->runner_faction_experience; + + if($this->runner_faction_level >= static::getRemainingFactionExperience($this->runner_faction_level)) { + ++$this->runner_faction_level; + $this->runner_faction_experience = 0; + } + } + else if($faction === Faction::Hunter) { + ++$this->hunter_faction_level; + + if($this->hunter_faction_level >= static::getRemainingFactionExperience($this->hunter_faction_level)) { + ++$this->hunter_faction_level; + $this->hunter_faction_experience = 0; + } + } + + return $this; + } + public static function getRemainingFactionExperience(int $level): int { if($level <= 26)