Some more fixing of processing leveling correctly and challenge processing adding the progress to the wrong user.

This commit is contained in:
Vari
2024-03-06 21:16:34 +01:00
parent 34f40d6dbc
commit 80e736d878
5 changed files with 48 additions and 9 deletions

View File

@@ -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;

View File

@@ -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();

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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)