mirror of
https://github.com/Deathgarden-Rebirth/Deathgarden_Rebirth-Rewrite.git
synced 2026-09-08 19:25:10 -05:00
Some more fixing of processing leveling correctly and challenge processing adding the progress to the wrong user.
This commit is contained in:
5
dist/app/Enums/Game/Characters.php
vendored
5
dist/app/Enums/Game/Characters.php
vendored
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
18
dist/app/Models/Game/CharacterData.php
vendored
18
dist/app/Models/Game/CharacterData.php
vendored
@@ -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;
|
||||
|
||||
22
dist/app/Models/User/PlayerData.php
vendored
22
dist/app/Models/User/PlayerData.php
vendored
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user