Skip to content

Commit

Permalink
Merge branch 'master' into winter-event
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKyle committed Nov 4, 2023
2 parents 3d1378f + aaa0124 commit 960a883
Show file tree
Hide file tree
Showing 13 changed files with 764 additions and 508 deletions.
16 changes: 8 additions & 8 deletions app/Flare/ServerFight/Fight/Ambush.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public function __construct(CharacterCacheData $characterCacheData) {
public function handleAmbush(Character $character, ServerMonster $monster, bool $isCharacterVoided = false, bool $isRankFight = false): Ambush {

$this->healthObject = [
'character_health' => $this->characterCacheData->getCachedCharacterData($character, 'health'),
'monster_health' => $monster->getHealth(),
'current_character_health' => $this->characterCacheData->getCachedCharacterData($character, 'health'),
'current_monster_health' => $monster->getHealth(),
];

if ($character->map->gameMap->mapType()->isPurgatory() && !$isRankFight) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public function playerAmbushesMonster(Character $character, ServerMonster $serve
$baseStat = $this->characterCacheData->getCachedCharacterData($character, $isPlayerVoided ? 'voided_base_stat' : 'base_stat');
$damage = $baseStat * 2;

$this->healthObject['monster_health'] -= $damage;
$this->healthObject['current_monster_health'] -= $damage;

$this->addMessage('You strike the enemy in an ambush doing: ' . number_format($damage) . ' damage!', 'player-action');
} else if ($this->canMonsterAmbushPlayer($serverMonster->getMonsterStat('ambush_chance'), $characterAmbushResistance)) {
Expand All @@ -84,7 +84,7 @@ public function playerAmbushesMonster(Character $character, ServerMonster $serve
$damageStat = $serverMonster->getMonsterStat('damage_stat');
$damage = $serverMonster->getMonsterStat($damageStat) * 2;

$this->healthObject['character_health'] -= $damage;
$this->healthObject['current_character_health'] -= $damage;

$this->addMessage($serverMonster->getName() . ' strikes you in an ambush doing: ' . number_format($damage) . ' damage!', 'enemy-action');
}
Expand All @@ -100,7 +100,7 @@ public function monsterAmbushesPlayer(Character $character, ServerMonster $serve
$damageStat = $serverMonster->getMonsterStat('damage_stat');
$damage = $serverMonster->getMonsterStat($damageStat) * 2;

$this->healthObject['character_health'] -= $damage;
$this->healthObject['current_character_health'] -= $damage;

$this->addMessage($serverMonster->getName() . ' strikes you in an ambush doing: ' . number_format($damage) . ' damage!', 'enemy-action');
} else if ($this->canPlayerAmbushMonster($characterAmbushChance, $serverMonster->getMonsterStat('ambush_resistance_chance'))) {
Expand All @@ -109,7 +109,7 @@ public function monsterAmbushesPlayer(Character $character, ServerMonster $serve
$baseStat = $this->characterCacheData->getCachedCharacterData($character, $isPlayerVoided ? 'voided_base_stat' : 'base_stat');
$damage = $baseStat * 2;

$this->healthObject['monster_health'] -= $damage;
$this->healthObject['current_monster_health'] -= $damage;

$this->addMessage('You strike the enemy in an ambush doing: ' . number_format($damage) . ' damage!', 'player-action');
}
Expand All @@ -134,7 +134,7 @@ public function canPlayerAmbushMonster(float $ambushChance, float $monsterAmbush
$chance = 0.05;
}

return rand (1, 100) > (100 - 100 * $chance);
return rand(1, 100) > (100 - 100 * $chance);
}

public function canMonsterAmbushPlayer(float $ambushChance, float $playerAmbushResistance): bool {
Expand All @@ -148,6 +148,6 @@ public function canMonsterAmbushPlayer(float $ambushChance, float $playerAmbushR

$chance = $ambushChance - $playerAmbushResistance;

return rand (1, 100) > (100 - 100 * $chance);
return rand(1, 100) > (100 - 100 * $chance);
}
}
4 changes: 2 additions & 2 deletions app/Flare/ServerFight/Fight/Attack.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public function setIsEnemyVoided(bool $isVoided): Attack {
}

public function setHealth(array $healthObject): Attack {
$this->characterHealth = $healthObject['character_health'];
$this->monsterHealth = $healthObject['monster_health'];
$this->characterHealth = $healthObject['current_character_health'];
$this->monsterHealth = $healthObject['current_monster_health'];

return $this;
}
Expand Down
10 changes: 5 additions & 5 deletions app/Flare/ServerFight/MonsterPlayerFight.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,9 +280,9 @@ public function fightSetUp(int $rank = 0, bool $isRankFight = false): array {
$health = $ambush->getHealthObject();

$health['max_character_health'] = (int) $this->characterCacheData->getCachedCharacterData($this->character, 'health');
$health['current_character_health'] = (int) $this->characterCacheData->getCachedCharacterData($this->character, 'health');
$health['current_character_health'] = $health['current_character_health'] <= 0 ? 0 : $health['current_character_health'];
$health['max_monster_health'] = $monster->getHealth();
$health['current_monster_health'] = $monster->getHealth();
$health['current_monster_health'] = $health['current_monster_health'] <= 0 ? 0 : $health['current_monster_health'];

$data = [
'health' => $health,
Expand All @@ -293,7 +293,7 @@ public function fightSetUp(int $rank = 0, bool $isRankFight = false): array {
'rank' => $rank,
];

if ($isRankFight && ($data['health']['character_health'] > 0 && $data['health']['monster_health'] > 0)) {
if ($isRankFight && ($data['health']['current_character_health'] > 0 && $data['health']['current_monster_health'] > 0)) {
Cache::put('rank-fight-for-character-' . $this->character->id, $data);
}

Expand Down Expand Up @@ -359,7 +359,7 @@ public function processAttack(array $data, bool $onlyOnce = false, $isRankFight
$isPlayerVoided = $data['player_voided'];
$isEnemyVoided = $data['enemy_voided'];

if ($health['character_health'] <= 0) {
if ($health['current_character_health'] <= 0) {
$this->battleMessages[] = [
'message' => 'The enemies ambush has slaughtered you!',
'type' => 'enemy-action',
Expand All @@ -368,7 +368,7 @@ public function processAttack(array $data, bool $onlyOnce = false, $isRankFight
return false;
}

if ($health['monster_health'] <= 0) {
if ($health['current_monster_health'] <= 0) {
$this->battleMessages[] = [
'message' => 'Your ambush has slaughtered the enemy!',
'type' => 'enemy-action',
Expand Down
10 changes: 4 additions & 6 deletions app/Game/Battle/Controllers/Api/RankFightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public function setUpRankFight(RankFightSetUpRequest $request, Character $charac
]
],
'health' => [
'character_health' => 0,
'monster_health' => 0,
'current_character_health' => 0,
'current_monster_health' => 0,
],
]);
}
Expand Down Expand Up @@ -79,8 +79,8 @@ public function fightRankedMonster(AttackTypeRequest $request, Character $charac
]
],
'health' => [
'character_health' => 0,
'monster_health' => 0,
'current_character_health' => 0,
'current_monster_health' => 0,
],
]);
}
Expand All @@ -92,6 +92,4 @@ public function fightRankedMonster(AttackTypeRequest $request, Character $charac

return response()->json($result, $status);
}


}
1 change: 0 additions & 1 deletion app/Game/Battle/Handlers/BattleEventHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ public function processRevive(Character $character): Character {
$monsterFightCache = Cache::get('monster-fight-' . $character->id);

if (!is_null($monsterFightCache)) {
$monsterFightCache['health']['character_health'] = $characterHealth;
$monsterFightCache['health']['current_character_health'] = $characterHealth;

Cache::put('monster-fight-' . $character->id, $monsterFightCache, 900);
Expand Down
16 changes: 8 additions & 8 deletions app/Game/Battle/Services/CelestialFightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function joinFight(Character $character, CelestialFight $celestialFight):
'celestial_fight_id' => $celestialFight->id,
'character_id' => $character->id,
'character_max_health' => $health,
'character_current_health'=> $health,
'character_current_health' => $health,
]);
} else {
if (now()->diffInMinutes($characterInCelestialFight->updated_at) > 5) {
Expand Down Expand Up @@ -83,8 +83,8 @@ public function fight(Character $character, CelestialFight $celestialFight, Char
return $this->successResult([
'logs' => $messages,
'health' => [
'character_health' => $characterHealth,
'monster_health' => 0,
'current_character_health' => $characterHealth,
'current_monster_health' => 0,
]
]);
}
Expand Down Expand Up @@ -113,8 +113,8 @@ public function fight(Character $character, CelestialFight $celestialFight, Char
return $this->successResult([
'logs' => $this->monsterPlayerFight->getBattleMessages(),
'health' => [
'character_health' => $characterHealth,
'monster_health' => $this->monsterPlayerFight->getMonsterHealth(),
'current_character_health' => $characterHealth,
'current_monster_health' => $this->monsterPlayerFight->getMonsterHealth(),
]
]);
}
Expand All @@ -127,7 +127,7 @@ public function revive(Character $character) {

return $this->successResult([
'fight' => [
'character' =>[
'character' => [
'max_health' => $characterInCelestialFight->character_max_health,
'current_health' => $characterInCelestialFight->character_current_health,
],
Expand All @@ -153,7 +153,7 @@ protected function handleMonsterDeath(Character $character, CelestialFight $cele
if ($celestialFightType->isPublic()) {
event(new GlobalMessageEvent($character->name . ' has slain the ' . $celestialFight->monster->name . '! They have been rewarded with a godly gift!'));
} else {
event(new ServerMessageEvent($character->user,'You have slain the ' . $celestialFight->monster->name . '! They have been rewarded with a godly gift!'));
event(new ServerMessageEvent($character->user, 'You have slain the ' . $celestialFight->monster->name . '! They have been rewarded with a godly gift!'));
}

$this->characterCacheData->deleteCharacterSheet($character);
Expand Down Expand Up @@ -209,7 +209,7 @@ protected function updateCharacterInFight(Character $character, CharacterInCeles

$characterInCelestialFight->update([
'character_max_health' => $health,
'character_current_health'=> $health,
'character_current_health' => $health,
]);

return $characterInCelestialFight->refresh();
Expand Down
10 changes: 7 additions & 3 deletions app/Game/Battle/Services/MonsterFightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ public function setupMonster(Character $character, array $params): array {

$data = $this->monsterPlayerFight->setUpFight($character, $params)->fightSetUp();

Cache::put('monster-fight-' . $character->id, $data, 900);
if ($data['health']['current_character_health'] <= 0) {
$this->battleEventHandler->processDeadCharacter($character);
} else {
Cache::put('monster-fight-' . $character->id, $data, 900);
}

return $this->successResult($data);
}
Expand All @@ -52,8 +56,8 @@ public function fightMonster(Character $character, string $attackType): array {

$cache['health']['current_character_health'] = $characterHealth;
$cache['health']['current_monster_health'] = $monsterHealth;
$cache['health']['character_health'] = $characterHealth;
$cache['health']['monster_health'] = $monsterHealth;
$cache['health']['current_character_health'] = $characterHealth;
$cache['health']['current_monster_health'] = $monsterHealth;

if ($monsterHealth >= 0) {
Cache::put('monster-fight-' . $character->id, $cache, 900);
Expand Down
18 changes: 9 additions & 9 deletions app/Game/Battle/Services/RaidBattleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ protected function buildBaseResultData(): array {
protected function getFightData(Character $character, ServerMonster $serverMonster, int $monsterId, array $monster, string $attackType, bool $isRaidBoss): array {
if (!$isRaidBoss && $this->hasCachedHealth($character->id, $monsterId)) {
$fightData = $this->getCachedFightData($character->id, $monsterId);
$fightData['health']['monster_health'] = $serverMonster->getHealth();
$fightData['health']['current_monster_health'] = $serverMonster->getHealth();

$this->monsterPlayerFight->setUpRaidFight($character, $monster, $attackType);
} else {
Expand All @@ -283,7 +283,7 @@ protected function getFightData(Character $character, ServerMonster $serverMonst

$fightData['monster'] = resolve(ServerMonster::class)->setMonster($raidBoss->raid_boss_deatils)
->setHealth($raidBoss->boss_current_hp);
$fightData['health']['monster_health'] = $raidBoss->boss_current_hp;
$fightData['health']['current_monster_health'] = $raidBoss->boss_current_hp;
}

return $fightData;
Expand All @@ -302,8 +302,8 @@ protected function getFightData(Character $character, ServerMonster $serverMonst
* @return array
*/
protected function handlePreAttack(Character $character, array $health, array $messages, int $monsterId, bool $isRaidBoss = false): array {
if ($health['character_health'] <= 0) {
$health['character_health'] = 0;
if ($health['current_character_health'] <= 0) {
$health['current_character_health'] = 0;

$messages[] = [
'message' => 'The enemies ambush has slaughtered you!',
Expand All @@ -316,13 +316,13 @@ protected function handlePreAttack(Character $character, array $health, array $m

return $this->successResult([
'character_current_health' => 0,
'monster_current_health' => $health['monster_health'],
'monster_current_health' => $health['current_monster_health'],
'messages' => $messages,
]);
}

if ($health['monster_health'] <= 0) {
$health['monster_health'] = 0;
if ($health['current_monster_health'] <= 0) {
$health['current_monster_health'] = 0;

$messages[] = [
'message' => 'Your ambush has slaughtered the enemy!',
Expand All @@ -336,7 +336,7 @@ protected function handlePreAttack(Character $character, array $health, array $m
RaidBossRewardHandler::dispatch($character->id, $raid->id, $monsterId);

return $this->successResult([
'character_current_health' => $health['character_health'],
'character_current_health' => $health['current_character_health'],
'monster_current_health' => 0,
'messages' => $messages,
]);
Expand Down Expand Up @@ -379,7 +379,7 @@ protected function handleRaidBossHealth(Character $character, int $monsterId, bo
$raidBoss = RaidBoss::where('raid_boss_id', $monsterId)->first();
$oldHealth = $raidBoss->boss_current_hp;

$currentHealth = empty($health) ? $this->monsterPlayerFight->getMonsterHealth() : $health['monster_health'];
$currentHealth = empty($health) ? $this->monsterPlayerFight->getMonsterHealth() : $health['current_monster_health'];

$this->updateRaidBossHealth($raidBoss, $currentHealth);

Expand Down
24 changes: 12 additions & 12 deletions app/Game/Battle/Services/RankFightService.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public function setupFight(Character $character, Monster $monster, int $rank): a

$messages = $monsterPlayerFight->getBattleMessages();

if ($health['character_health'] <= 0) {
$health['character_health'] = 0;
if ($health['current_character_health'] <= 0) {
$health['current_character_health'] = 0;

$messages[] = [
'message' => 'The enemies ambush has slaughtered you!',
Expand All @@ -128,8 +128,8 @@ public function setupFight(Character $character, Monster $monster, int $rank): a
]);
}

if ($health['monster_health'] <= 0) {
$health['monster_health'] = 0;
if ($health['current_monster_health'] <= 0) {
$health['current_monster_health'] = 0;

$messages[] = [
'message' => 'Your ambush has slaughtered the enemy!',
Expand Down Expand Up @@ -184,8 +184,8 @@ public function fight(Character $character, string $attackType): array {
return $this->successResult([
'messages' => $messages,
'health' => [
'character_health' => $characterHealth,
'monster_health' => 0,
'current_character_health' => $characterHealth,
'current_monster_health' => 0,
],
'is_dead' => false,
]);
Expand All @@ -204,8 +204,8 @@ public function fight(Character $character, string $attackType): array {

return $this->successResult([
'health' => [
'character_health' => 0,
'monster_health' => $monsterHealth,
'current_character_health' => 0,
'current_monster_health' => $monsterHealth,
],
'messages' => $this->monsterPlayerFight->getBattleMessages(),
'is_dead' => true,
Expand All @@ -217,8 +217,8 @@ public function fight(Character $character, string $attackType): array {
return $this->successResult([
'messages' => $this->monsterPlayerFight->getBattleMessages(),
'health' => [
'character_health' => $characterHealth,
'monster_health' => $this->monsterPlayerFight->getMonsterHealth(),
'current_character_health' => $characterHealth,
'current_monster_health' => $this->monsterPlayerFight->getMonsterHealth(),
]
]);
}
Expand All @@ -233,8 +233,8 @@ protected function updateAttackCache(Character $character): void {
$cacheData = Cache::get('rank-fight-for-character-' . $character->id);

if (!is_null($cacheData)) {
$cacheData['health']['character_health'] = $this->monsterPlayerFight->getCharacterHealth();
$cacheData['health']['monster_health'] = $this->monsterPlayerFight->getMonsterHealth();
$cacheData['health']['current_character_health'] = $this->monsterPlayerFight->getCharacterHealth();
$cacheData['health']['current_monster_health'] = $this->monsterPlayerFight->getMonsterHealth();

Cache::put('rank-fight-for-character-' . $character->id, $cacheData);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Game/GuideQuests/Services/GuideQuestService.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function canHandInQuest(Character $character, GuideQuest $quest, bool $ig
$difference = array_diff($requiredAttributes, $this->completedAttributes);

$this->guideQuestRequirementsService->resetFinishedRequirements();
dump($difference);

if (empty($difference)) {
return true;
}
Expand Down
Loading

0 comments on commit 960a883

Please sign in to comment.