Skip to content

Commit

Permalink
Merge pull request #35 from sebastianluczak/feature/initiative-rolls-…
Browse files Browse the repository at this point in the history
…and-uncommon-loot-support

Feature/initiative rolls and uncommon loot support
  • Loading branch information
sebastianluczak authored Nov 15, 2021
2 parents a5d0393 + f5a91bf commit c150486
Show file tree
Hide file tree
Showing 42 changed files with 533 additions and 244 deletions.
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ RUN wget -O composer-setup.php https://getcomposer.org/installer
RUN php composer-setup.php --filename=composer.phar
RUN php composer.phar install
RUN chmod +x /app/bin/console
RUN mkdir -p /app/var/log
RUN touch /app/var/log/dev.log
RUN mkdir -p /app/var/cache
RUN chmod +x /app/bin/entrypoint.sh
CMD ['/app/bin/entrypoint.sh']
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ Worst game on the planet.
cd ~
git clone https://github.com/sebastianluczak/php-roguelike.git
cd php-roguelike
sh bin/build.sh
chmod +x bin/*
bin/build.sh
```
Empty file modified bin/build.sh
100644 → 100755
Empty file.
Empty file modified bin/console
100644 → 100755
Empty file.
Empty file modified bin/entrypoint.sh
100644 → 100755
Empty file.
Empty file modified bin/run.sh
100644 → 100755
Empty file.
17 changes: 17 additions & 0 deletions src/Enum/Creature/CreatureClassEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace App\Enum\Creature;

use MyCLabs\Enum\Enum;

/**
* @method static LEGENDARY()
* @method static ELITE()
* @method static NORMAL()
*/
class CreatureClassEnum extends Enum
{
private const LEGENDARY = 150;
private const ELITE = 120;
private const NORMAL = 80;
}
3 changes: 3 additions & 0 deletions src/Enum/GameIconEnum.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @method static TIME()
* @method static STATS()
* @method static INVENTORY()
* @method static SKULL()
*/
class GameIconEnum extends Enum
{
Expand All @@ -32,4 +33,6 @@ class GameIconEnum extends Enum
private const TIME = '';
private const STATS = '🧠';
private const INVENTORY = '🧳';

private const SKULL = '💀';
}
13 changes: 13 additions & 0 deletions src/Enum/Misc/AsciiEmoticonEnum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace App\Enum\Misc;

use MyCLabs\Enum\Enum;

/**
* @method static FLIP_EM_ALL_TABLES()
*/
class AsciiEmoticonEnum extends Enum
{
private const FLIP_EM_ALL_TABLES = '┻━┻︵ \(°□°)/ ︵ ┻━┻ ';
}
12 changes: 12 additions & 0 deletions src/Message/DevRoomSpawnMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Message;

/**
* Used at:
* DevRoomSpawnHandler::__invoke()
*/
class DevRoomSpawnMessage
{

}
6 changes: 2 additions & 4 deletions src/MessageHandler/CreatureGetsKilledHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ public function __invoke(CreatureGetsKilledMessage $message)
$creature = $message->getCreature();

$this->loggerService->logMessage($message);
$this->messageBus->dispatch(new AddAdventureLogMessage("You've killed " . $creature->getName(), MessageClassEnum::SUCCESS()));

$gold = $creature->handleLoot();
$player->addGoldAmount($gold->getAmount());
$this->messageBus->dispatch(new AddAdventureLogMessage("You've earned 💰 " . $gold->getAmount() . " gold", MessageClassEnum::SUCCESS()));
$this->messageBus->dispatch(new AddAdventureLogMessage("You've killed " . $creature->getName() . " earning 💰 " . $gold->getAmount() . " gold and 🧍 " . $creature->getExperience() . " experience points", MessageClassEnum::SUCCESS()));

$player->addGoldAmount($gold->getAmount());
// increase level handler
$initialPlayerLevel = $player->getLevel()->getLevel();
$player->getLevel()->modifyExperience($creature->getExperience(), LevelActionEnum::INCREASE());
$currentPlayerLevel = $player->getLevel()->getLevel();
$this->messageBus->dispatch(new AddAdventureLogMessage("You've earned 🧍 " . $creature->getExperience() . " experience points", MessageClassEnum::SUCCESS()));
$player->increaseKillCount();

// level up handler
Expand Down
30 changes: 30 additions & 0 deletions src/MessageHandler/DevRoomSpawnHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\MessageHandler;

use App\Enum\MessageClassEnum;
use App\Enum\Misc\AsciiEmoticonEnum;
use App\Message\AddAdventureLogMessage;
use App\Message\DevRoomSpawnMessage;
use App\Message\RegenerateMapMessage;
use App\Service\GameService;
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
use Symfony\Component\Messenger\MessageBusInterface;

class DevRoomSpawnHandler implements MessageHandlerInterface
{
protected MessageBusInterface $messageBus;
protected GameService $gameService;

public function __construct(MessageBusInterface $messageBus, GameService $gameService)
{
$this->messageBus = $messageBus;
$this->gameService = $gameService;
}

public function __invoke(DevRoomSpawnMessage $message)
{
$this->messageBus->dispatch(new AddAdventureLogMessage("[ADMIN] " . AsciiEmoticonEnum::FLIP_EM_ALL_TABLES() . " DevRoom generating.", MessageClassEnum::DEVELOPER()));
$this->gameService->getMapService()->generateDevRoomMap();
}
}
27 changes: 0 additions & 27 deletions src/MessageHandler/LootPickupHandler.php

This file was deleted.

2 changes: 1 addition & 1 deletion src/MessageHandler/PlayerLevelUpHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function __invoke(PlayerLevelUpMessage $message)
$player = $message->getPlayer();
$statChosen = $this->specialStats[array_rand($this->specialStats)];
$randomSkillBoostMethod = 'modify' . $statChosen;
$player->getStats()->{$randomSkillBoostMethod}(1);
$player->getStats()->{$randomSkillBoostMethod}(sqrt($player->getStats()->getIntelligence()));

$player->getHealth()->increaseMaxHealth(10);
$player->getHealth()->modifyHealth($player->getHealth()->getMaxHealth(), HealthActionEnum::INCREASE());
Expand Down
6 changes: 1 addition & 5 deletions src/MessageHandler/ShowPlayerInventoryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ public function __invoke(ShowPlayerInventoryMessage $message)
$player = $message->getPlayer();
$inventory = $player->getInventory();

$this->messageBus->dispatch(new AddAdventureLogMessage(
GameIconEnum::INVENTORY() . " Player inventory -> " .
GameIconEnum::WEAPON() . " " . $inventory->getWeaponSlot()->getName() . "+" . $inventory->getWeaponSlot()->getDamage() .
GameIconEnum::SHIELD() . " " . $inventory->getArmorSlot()->getName() . "+" . $inventory->getArmorSlot()->getArmor()
));
// TODO add this - print inventory of player
}
}
57 changes: 39 additions & 18 deletions src/Model/Creature/AbstractCreature.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,42 @@

namespace App\Model\Creature;

use App\Model\Stats\Stats;
use App\Enum\Creature\CreatureClassEnum;
use App\Model\Loot\LootInterface;
use App\Model\Stats\StatsInterface;
use Faker\Factory as FakerFactory;
use Faker\Generator;
use Irfa\Gatcha\Roll;
use RPGFaker\RPGFaker;

abstract class AbstractCreature implements CreatureInterface
{
protected int $health;
protected int $damage;
protected int $armor;
protected string $name;
protected int $experience;
protected int $scale;
protected Generator $faker;
protected string $rawName;
protected StatsInterface $stats;
protected LootInterface $weaponSlot;
protected LootInterface $armorSlot;
protected CreatureClassEnum $creatureClass;
protected float $initiative;

public function __construct()
{
$classEnumChances = [
CreatureClassEnum::NORMAL()->getKey() => 30,
CreatureClassEnum::ELITE()->getKey() => 2,
CreatureClassEnum::LEGENDARY()->getKey() => 1
];

$classEnumChancesSpin = Roll::put($classEnumChances)->spin();
$this->creatureClass = CreatureClassEnum::$classEnumChancesSpin();

$nameFaker = new RPGFaker(['count' => 1]);
$this->faker = FakerFactory::create('ja_JP');
$this->rawName = $nameFaker->name;
$this->stats = new Stats();
}

public function getExperience(): int
Expand All @@ -38,20 +50,6 @@ public function getName(): string
return $this->name;
}

public function getDamage(): int
{
return $this->damage;
}

public function getArmor(): int
{
if ($this->armor >= 80) {
return 80;
}

return $this->armor;
}

public function getHealth(): int
{
return $this->health;
Expand Down Expand Up @@ -81,4 +79,27 @@ public function getStats(): StatsInterface
{
return $this->stats;
}

public function getWeaponSlot(): LootInterface
{
return $this->weaponSlot;
}

public function getArmorSlot(): LootInterface
{
return $this->armorSlot;
}

/**
* @return CreatureClassEnum
*/
public function getCreatureClass(): CreatureClassEnum
{
return $this->creatureClass;
}

public function getInitiative(): float
{
return $this->getStats()->getPerception() * $this->getStats()->getPerception() - $this->getStats()->getPerception() - $this->getScale();
}
}
8 changes: 6 additions & 2 deletions src/Model/Creature/CreatureInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

namespace App\Model\Creature;

use App\Enum\Creature\CreatureClassEnum;
use App\Model\Loot\LootInterface;
use App\Model\Stats\StatsInterface;

interface CreatureInterface
{
public function getName(): string;
public function getDamage(): int;
public function getArmor(): int;
public function getHealth(): int;
public function handleLoot();
public function decreaseHealth(int $playerHitDamage);
public function getExperience(): int;
public function getScale(): int;
public function getStats(): StatsInterface;
public function getWeaponSlot(): LootInterface;
public function getArmorSlot(): LootInterface;
public function getCreatureClass(): CreatureClassEnum;
public function getInitiative(): float;
}
33 changes: 26 additions & 7 deletions src/Model/Creature/Dragon.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@

namespace App\Model\Creature;

use App\Enum\Creature\CreatureClassEnum;
use App\Enum\GameIconEnum;
use App\Model\Loot\Armor\CreatureGenericArmor;
use App\Model\Loot\Gold;
use App\Model\Loot\Weapon\CreatureMeleeWeapon;
use App\Model\Stats\Stats;

class Dragon extends AbstractCreature
{
public function __construct(float $scale)
private const BASE_STRENGTH = 7;
private const BASE_ENDURANCE = 5;
private const BASE_LUCK = 6;
private const COMMON_NAME = 'Dragon';

public function __construct(int $scale)
{
parent::__construct();

$this->scale = $scale;
$this->name = "Dragon - " . $this->getRawName();
$this->damage = $this->createRandomNumberInRangeWithScale(15, 20, $scale);
$this->armor = $this->createRandomNumberInRangeWithScale(45, 70, $scale);
$this->health = $this->createRandomNumberInRangeWithScale(30, 50, $scale);
$this->experience = $this->createRandomNumberInRangeWithScale(50, 70, $scale);

$this->stats = new Stats();
$this->stats->modifyStrength(ceil(self::BASE_STRENGTH * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->stats->modifyEndurance(ceil(self::BASE_ENDURANCE * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->stats->modifyLuck(ceil(self::BASE_LUCK * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->weaponSlot = new CreatureMeleeWeapon($this->stats);
$this->armorSlot = new CreatureGenericArmor($this->stats);

if ($this->creatureClass == CreatureClassEnum::ELITE() || $this->creatureClass == CreatureClassEnum::LEGENDARY()) {
$this->name = "<fg=yellow>" . GameIconEnum::SKULL() . " " . $this->creatureClass->getKey() . " " . self::COMMON_NAME . " " . $this->getRawName() . "</>";
} else {
$this->name = self::COMMON_NAME . " - " . $this->getRawName();
}
$this->health = ceil($this->stats->getEndurance() * ceil($scale/2) * ($this->creatureClass->getValue() / 100));
$this->experience = $this->createRandomNumberInRangeWithScale(20, 50, $scale);
}

public function handleLoot()
Expand Down
31 changes: 25 additions & 6 deletions src/Model/Creature/Goblin.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,39 @@

namespace App\Model\Creature;

use App\Enum\Creature\CreatureClassEnum;
use App\Enum\GameIconEnum;
use App\Model\Loot\Armor\CreatureGenericArmor;
use App\Model\Loot\Gold;
use App\Model\Loot\Weapon\CreatureMeleeWeapon;
use App\Model\Stats\Stats;

class Goblin extends AbstractCreature
{
private const BASE_STRENGTH = 2.5;
private const BASE_ENDURANCE = 2.5;
private const BASE_LUCK = 1;
private const COMMON_NAME = 'Goblin';

public function __construct(int $scale)
{
parent::__construct();

$this->scale = $scale;
$this->name = "Goblin - " . $this->getRawName();
$this->damage = $this->createRandomNumberInRangeWithScale(1, 3, $scale);
$this->armor = $this->createRandomNumberInRangeWithScale(1, 2, $scale);
$this->health = $this->createRandomNumberInRangeWithScale(4, 6, $scale);
$this->experience = $this->createRandomNumberInRangeWithScale(6, 8, $scale);

$this->stats = new Stats();
$this->stats->modifyStrength(ceil(self::BASE_STRENGTH * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->stats->modifyEndurance(ceil(self::BASE_ENDURANCE * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->stats->modifyLuck(ceil(self::BASE_LUCK * ($this->creatureClass->getValue() / 100)) * sqrt($scale));
$this->weaponSlot = new CreatureMeleeWeapon($this->stats);
$this->armorSlot = new CreatureGenericArmor($this->stats);

if ($this->creatureClass == CreatureClassEnum::ELITE() || $this->creatureClass == CreatureClassEnum::LEGENDARY()) {
$this->name = "<fg=yellow>" . GameIconEnum::SKULL() . " " . $this->creatureClass->getKey() . " " . self::COMMON_NAME . " " . $this->getRawName() . "</>";
} else {
$this->name = self::COMMON_NAME . " - " . $this->getRawName();
}
$this->health = ceil($this->stats->getEndurance() * ceil($scale/2) * ($this->creatureClass->getValue() / 100));
$this->experience = $this->createRandomNumberInRangeWithScale(20, 50, $scale);
}

public function handleLoot()
Expand Down
Loading

0 comments on commit c150486

Please sign in to comment.