Skip to content

Commit d50419d

Browse files
Adds weight limit for character, moves calculations to helper classes, enables god mode power run, adds new boss, fixes way Loot works, many code fixes.
1 parent 8808b30 commit d50419d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+281
-169
lines changed

src/Enum/GameIconEnum.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* @method static TIME()
1818
* @method static STATS()
1919
* @method static INVENTORY()
20+
* @method static WEIGHT()
2021
* @method static SKULL()
2122
* @method static GEM()
2223
* @method static POTION()
@@ -35,6 +36,7 @@ class GameIconEnum extends Enum
3536
public const TIME = '';
3637
public const STATS = '🧠';
3738
public const INVENTORY = '🧳';
39+
public const WEIGHT = '🎒';
3840

3941
public const SKULL = '💀';
4042
public const GEM = '💎';

src/Helper/ScaleHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* @TODO add all $scale occurrences
1212
*/
13-
final class ScaleHelper
13+
final class ScaleHelper extends StatsCalculatorHelper
1414
{
1515
/**
1616
* @description Basic scale adds current Map Level to current Player Level
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Helper;
6+
7+
use App\Enum\Creature\CreatureClassEnum;
8+
use App\Model\Stats\StatsInterface;
9+
10+
class StatsCalculatorHelper
11+
{
12+
/**
13+
* @description calculates stat based on base value, used in AbstractCreature
14+
*/
15+
public static function calculateStatWithBaseAndScale(int $baseStat, int $scale, CreatureClassEnum $creatureClass): int
16+
{
17+
return (int) (ceil($baseStat * ($creatureClass->getValue() / 100)) * sqrt($scale));
18+
}
19+
20+
/**
21+
* @description Used in calculating create health during it's spawn (constructor of Creature itself)
22+
*/
23+
public static function calculateCreatureHealthWithScale(int $scale, StatsInterface $stats, CreatureClassEnum $creatureClass): int
24+
{
25+
return (int) ceil($stats->getEndurance() * ceil($scale / 2) * ($creatureClass->getValue() / 100));
26+
}
27+
}

src/Message/PlayerLevelUpMessage.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
class PlayerLevelUpMessage
88
{
99
protected PlayerInterface $player;
10+
protected int $initialPlayerLevel;
1011

11-
public function __construct(PlayerInterface $player)
12+
public function __construct(PlayerInterface $player, int $initialPlayerLevel)
1213
{
1314
$this->player = $player;
15+
$this->initialPlayerLevel = $initialPlayerLevel;
1416
}
1517

1618
public function getPlayer(): PlayerInterface
1719
{
1820
return $this->player;
1921
}
22+
23+
public function getInitialPlayerLevel(): int
24+
{
25+
return $this->initialPlayerLevel;
26+
}
2027
}

src/MessageHandler/CreatureGetsKilledHandler.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@ class CreatureGetsKilledHandler implements MessageHandlerInterface
1717
{
1818
protected LoggerService $loggerService;
1919
protected MessageBusInterface $messageBus;
20-
// TODO rethink PlayerService role in this whole mess.
21-
// state of reference to an object is pretty complicated here
22-
// we should aim at stateless or not?
23-
protected PlayerService $playerService;
2420

25-
public function __construct(LoggerService $loggerService, MessageBusInterface $messageBus, PlayerService $playerService)
21+
public function __construct(LoggerService $loggerService, MessageBusInterface $messageBus)
2622
{
2723
$this->loggerService = $loggerService;
2824
$this->messageBus = $messageBus;
29-
$this->playerService = $playerService;
3025
}
3126

3227
public function __invoke(CreatureGetsKilledMessage $message): void
@@ -46,17 +41,12 @@ public function __invoke(CreatureGetsKilledMessage $message): void
4641

4742
// increase level handler
4843
$initialPlayerLevel = $player->getLevel()->getLevel();
44+
// IDEA FIXME - maybe we should move modifyExperience to EventBus and handle it there?
45+
// makes sense to be honest, as we don't overburden PlayerService
46+
// I think i tend more to Active Record Approach, which is strange..
4947
$player->getLevel()->modifyExperience($creature->getExperience(), LevelActionEnum::INCREASE());
50-
$currentPlayerLevel = $player->getLevel()->getLevel();
5148
$player->increaseKillCount();
52-
53-
// level up handler TODO code duplication, GodModeActivate
54-
if ($currentPlayerLevel > $initialPlayerLevel) {
55-
$levelsToGain = $player->getLevel()->getLevel() - $initialPlayerLevel;
56-
for ($x = 0; $x < $levelsToGain; ++$x) {
57-
$this->messageBus->dispatch(new PlayerLevelUpMessage($player));
58-
}
59-
}
49+
$this->messageBus->dispatch(new PlayerLevelUpMessage($player, $initialPlayerLevel));
6050

6151
if ($player->getHealth()->getHealth() <= $player->getHealth()->getWarningThreshold()) {
6252
$this->messageBus->dispatch(new AddAdventureLogMessage('Your health is low, find a way to heal.', MessageClassEnum::IMPORTANT()));

src/MessageHandler/GodModeActivatedHandler.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,9 @@ public function __invoke(GodModeActivatedMessage $message): void
2727
{
2828
$player = $message->getPlayer();
2929
for ($expBase = 100; $expBase <= 500; ++$expBase) {
30-
$levelBeforeExpBoost = $player->getLevel()->getLevel();
30+
$initialPlayerLevel = $player->getLevel()->getLevel();
3131
$player->getLevel()->modifyExperience((int) ($expBase / sqrt($expBase)), LevelActionEnum::INCREASE());
32-
// this is bad check, fixme
33-
// we need to simply check, how much is a diff and fire up multiple playerlevelup
34-
// FIX ME SOON ITS EASY PLEASE
35-
// TODO
36-
if ($levelBeforeExpBoost < $player->getLevel()->getLevel()) {
37-
$levelsToGain = $player->getLevel()->getLevel() - $levelBeforeExpBoost;
38-
for ($x = 0; $x < $levelsToGain; ++$x) {
39-
$this->messageBus->dispatch(new PlayerLevelUpMessage($player));
40-
}
41-
}
32+
$this->messageBus->dispatch(new PlayerLevelUpMessage($player, $initialPlayerLevel));
4233
}
4334

4435
$this->messageBus->dispatch(new AddAdventureLogMessage('Have fun! :D '.AsciiEmoticonEnum::FLIP_EM_ALL_TABLES().'.', MessageClassEnum::LOOT()));

src/MessageHandler/PlayerLevelUpHandler.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ public function __construct(MessageBusInterface $messageBus)
2323
public function __invoke(PlayerLevelUpMessage $message): void
2424
{
2525
$player = $message->getPlayer();
26-
$statChosen = $this->specialStats[array_rand($this->specialStats)];
27-
$randomSkillBoostMethod = 'modify'.$statChosen;
28-
$player->getStats()->{$randomSkillBoostMethod}(sqrt($player->getStats()->getIntelligence()));
26+
$initialPlayerLevel = $message->getInitialPlayerLevel();
27+
if ($player->getLevel()->getLevel() > $initialPlayerLevel) {
28+
$levelsToGain = $player->getLevel()->getLevel() - $initialPlayerLevel;
29+
for ($x = 0; $x < $levelsToGain; ++$x) {
30+
$statChosen = $this->specialStats[array_rand($this->specialStats)];
31+
$randomSkillBoostMethod = 'modify'.$statChosen;
32+
$player->getStats()->{$randomSkillBoostMethod}(sqrt($player->getStats()->getIntelligence()));
2933

30-
$player->getHealth()->increaseMaxHealth(10);
31-
$player->getHealth()->modifyHealth($player->getHealth()->getMaxHealth(), HealthActionEnum::INCREASE());
32-
$this->messageBus->dispatch(new AddAdventureLogMessage('Player skill leveled up: '.$statChosen, MessageClassEnum::LOOT()));
34+
$player->getHealth()->increaseMaxHealth(10);
35+
$player->getHealth()->modifyHealth($player->getHealth()->getMaxHealth(), HealthActionEnum::INCREASE());
36+
$this->messageBus->dispatch(new AddAdventureLogMessage('Player skill leveled up: '.$statChosen, MessageClassEnum::LOOT()));
37+
}
38+
}
3339
}
3440
}

src/Model/AdventureLog/AdventureLog.php

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace App\Model\AdventureLog;
44

5-
// todo change to repository (it's not stupid idea after all)
6-
use App\Service\LoggerService;
7-
85
class AdventureLog implements AdventureLogInterface
96
{
107
public const MAX_NUMBER_OF_MESSAGES = 12;
@@ -14,11 +11,8 @@ class AdventureLog implements AdventureLogInterface
1411
*/
1512
protected array $messages;
1613

17-
protected LoggerService $loggerService;
18-
19-
public function __construct(LoggerService $loggerService)
14+
public function __construct()
2015
{
21-
$this->loggerService = $loggerService;
2216
$this->messages = [];
2317
}
2418

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Model\Creature;
6+
7+
use App\Enum\GameIconEnum;
8+
use App\Helper\ScaleHelper;
9+
use App\Model\Loot\Armor\CreatureGenericArmor;
10+
use App\Model\Loot\Weapon\CreatureMeleeWeapon;
11+
use App\Model\Stats\Stats;
12+
13+
abstract class AbstractBossCreature extends AbstractCreature
14+
{
15+
public function __construct(string $creatureName, int $scale, int $baseStrength, int $baseEndurance, int $baseLuck)
16+
{
17+
$this->scale = $scale;
18+
parent::__construct();
19+
20+
$this->stats = new Stats();
21+
$this->stats->modifyStrength(ScaleHelper::calculateStatWithBaseAndScale($baseStrength, $scale, $this->creatureClass));
22+
$this->stats->modifyEndurance(ScaleHelper::calculateStatWithBaseAndScale($baseEndurance, $scale, $this->creatureClass));
23+
$this->stats->modifyLuck(ScaleHelper::calculateStatWithBaseAndScale($baseLuck, $scale, $this->creatureClass));
24+
$this->weaponSlot = new CreatureMeleeWeapon($this->stats);
25+
$this->armorSlot = new CreatureGenericArmor($this->stats);
26+
27+
$this->name = '<fg=bright-red>'.GameIconEnum::SKULL().' '.$creatureName.'</>';
28+
$this->health = ScaleHelper::calculateCreatureHealthWithScale($scale, $this->getStats(), $this->getCreatureClass());
29+
}
30+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Model\Creature;
6+
7+
use App\Enum\Creature\CreatureClassEnum;
8+
use App\Enum\GameIconEnum;
9+
use App\Helper\ScaleHelper;
10+
use App\Model\Loot\Armor\CreatureGenericArmor;
11+
use App\Model\Loot\Weapon\CreatureMeleeWeapon;
12+
use App\Model\Stats\Stats;
13+
14+
abstract class AbstractCommonCreature extends AbstractCreature
15+
{
16+
public function __construct(string $creatureName, int $scale, int $baseStrength, int $baseEndurance, int $baseLuck)
17+
{
18+
parent::__construct();
19+
20+
// in fact, those methods should be different to those used in AbstractBossCreature
21+
$this->stats = new Stats();
22+
$this->stats->modifyStrength(ScaleHelper::calculateStatWithBaseAndScale($baseStrength, $scale, $this->creatureClass));
23+
$this->stats->modifyEndurance(ScaleHelper::calculateStatWithBaseAndScale($baseEndurance, $scale, $this->creatureClass));
24+
$this->stats->modifyLuck(ScaleHelper::calculateStatWithBaseAndScale($baseLuck, $scale, $this->creatureClass));
25+
$this->weaponSlot = new CreatureMeleeWeapon($this->stats);
26+
$this->armorSlot = new CreatureGenericArmor($this->stats);
27+
28+
if ($this->creatureClass == CreatureClassEnum::ELITE() || $this->creatureClass == CreatureClassEnum::LEGENDARY()) {
29+
$this->name = '<fg=yellow>'.GameIconEnum::SKULL().' '.$this->creatureClass->getKey().' '.$creatureName.' '.$this->getRawName().'</>';
30+
} else {
31+
$this->name = $creatureName.' - '.$this->getRawName();
32+
}
33+
$this->health = ScaleHelper::calculateCreatureHealthWithScale($scale, $this->getStats(), $this->getCreatureClass());
34+
}
35+
}

0 commit comments

Comments
 (0)