Skip to content

Commit 8808b30

Browse files
Adds additional rooms and logic for city. Improves handling of scaling by gradually moving to external helper - in future to become API microservice (bold idea)
1 parent 4cf9e7f commit 8808b30

File tree

15 files changed

+217
-71
lines changed

15 files changed

+217
-71
lines changed

resources/levels/Rivermouth_city.yaml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,29 @@ size:
44
width: 140
55

66
places:
7+
shop:
8+
generation_class: App\Generator\Level\DefaultBoxRoomGenerator
9+
logic_tile: App\Model\Tile\City\ShopTile
10+
size: [ 7, 7 ]
11+
starting_point: [ 21, 49 ]
12+
713
church:
814
generation_class: App\Generator\Level\DefaultBoxRoomGenerator
915
logic_tile: App\Model\Tile\City\AltarTile
10-
size: [ 8, 8 ]
11-
starting_point: [ 9, 13 ]
16+
size: [ 9, 9 ]
17+
starting_point: [ 3, 6 ]
1218

1319
stables:
1420
generation_class: App\Generator\Level\DefaultBoxRoomGenerator
15-
logic_tile: App\Model\Tile\City\AltarTile
16-
size: [ 8, 8 ]
21+
size: [ 9, 9 ]
1722
starting_point: [ 2, 49 ]
1823

1924
tavern:
2025
generation_class: App\Generator\Level\DefaultBoxRoomGenerator
21-
logic_tile: App\Model\Tile\City\AltarTile
22-
size: [ 8, 8 ]
26+
size: [ 9, 9 ]
2327
starting_point: [ 21, 12 ]
2428

2529
cathedral:
2630
generation_class: App\Generator\Level\DefaultBoxRoomGenerator
27-
logic_tile: App\Model\Tile\City\AltarTile
28-
size: [ 8, 8 ]
29-
starting_point: [ 11, 82 ]
31+
size: [ 9, 9 ]
32+
starting_point: [ 11, 82 ]

src/Generator/Level/DefaultBoxRoomGenerator.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@ public function createRooms(): void
2525
for ($y = $this->roomDefinition['starting_point'][1]; $y < $this->roomDefinition['starting_point'][1] + $this->roomDefinition['size'][1]; ++$y) {
2626
if ($this->isSpawnableArea($x, $y) && !empty($this->roomDefinition['logic_tile'])) {
2727
$roomLogicTile = $this->roomDefinition['logic_tile'];
28-
$tileToAdd = new $roomLogicTile();
29-
if ($tileToAdd instanceof AbstractTile) {
30-
$this->map->replaceTile($tileToAdd, $x, $y);
31-
} else {
32-
throw new \LogicException('Tile should always extend AbstractTile, in: '.__METHOD__);
28+
if (is_string($roomLogicTile)) {
29+
$tileToAdd = new $roomLogicTile();
30+
if ($tileToAdd instanceof AbstractTile) {
31+
$this->map->replaceTile($tileToAdd, $x - 1, $y);
32+
} else {
33+
throw new \LogicException('Tile should always extend AbstractTile, in: '.__METHOD__);
34+
}
3335
}
3436
}
3537
if ($this->isEdgeOfRoom($x, $y)) {

src/Helper/ScaleHelper.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Helper;
6+
7+
use Symfony\Component\Validator\ConstraintViolationList;
8+
use Symfony\Component\Validator\Exception\ValidationFailedException;
9+
10+
/**
11+
* @TODO add all $scale occurrences
12+
*/
13+
final class ScaleHelper
14+
{
15+
/**
16+
* @description Basic scale adds current Map Level to current Player Level
17+
*/
18+
public static function basicScale(int $mapLevel, int $playerLevel): int
19+
{
20+
return $mapLevel + $playerLevel;
21+
}
22+
23+
/**
24+
* @description Multiplies base scale by some number
25+
* which should be in range {0.5, 1.5}
26+
* to avoid game breaking balance errors
27+
*
28+
* @throws ValidationFailedException
29+
*/
30+
public static function bossEncounterScale(int $scale, float $bossOwnScaleVariable): int
31+
{
32+
if ($bossOwnScaleVariable < 0.5 || $bossOwnScaleVariable > 1.5) {
33+
throw new ValidationFailedException($bossOwnScaleVariable, new ConstraintViolationList());
34+
}
35+
36+
return (int) ceil($scale * $bossOwnScaleVariable);
37+
}
38+
}

src/Model/CityMap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use App\Model\Tile\City\PavementTile;
66

7-
class CityMap extends Map
7+
final class CityMap extends Map
88
{
99
protected function createMapInstance(): void
1010
{

src/Model/Map.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
namespace App\Model;
66

7+
use App\Model\Map\MapInterface;
78
use App\Model\Tile\AbstractTile;
89
use App\Model\Tile\EmptyTile;
910

10-
class Map
11+
class Map implements MapInterface
1112
{
1213
protected string $name;
1314
protected int $width;

src/Model/Map/MapInterface.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace App\Model\Map;
6+
7+
interface MapInterface
8+
{
9+
}

src/Model/Tile/City/AltarTile.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22

33
namespace App\Model\Tile\City;
44

5-
use App\Model\Npc\City\Shopkeeper;
65
use App\Model\Player\PlayerInterface;
76
use App\Model\Stats\StatsInterface;
87
use App\Model\Tile\AbstractTile;
9-
use App\Model\Tile\TileInteraction\NpcTileInteraction;
8+
use App\Model\Tile\TileInteraction\EmptyTileInteraction;
109
use App\Model\Tile\TileInteraction\TileInteractionInterface;
1110
use App\Model\Tile\TileLogic\NoLogic;
1211
use App\Model\Tile\TileLogic\TileLogicInterface;
12+
use App\Traits\Tile\PermanentTileTrait;
1313

1414
class AltarTile extends AbstractTile
1515
{
16+
use PermanentTileTrait;
17+
1618
public function isInteractable(): bool
1719
{
1820
return true;
@@ -40,11 +42,11 @@ public function handleLogic(int $scale, StatsInterface $stats): TileLogicInterfa
4042

4143
public function handleInteraction(PlayerInterface $player): TileInteractionInterface
4244
{
43-
return new NpcTileInteraction($player, new Shopkeeper());
45+
return new EmptyTileInteraction();
4446
}
4547

4648
public function draw(): string
4749
{
48-
return '<fg=bright-white>O</>';
50+
return '<fg=red>¥</>';
4951
}
5052
}

src/Model/Tile/City/ShopTile.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
namespace App\Model\Tile\City;
4+
5+
use App\Model\Npc\City\Shopkeeper;
6+
use App\Model\Player\PlayerInterface;
7+
use App\Model\Stats\StatsInterface;
8+
use App\Model\Tile\AbstractTile;
9+
use App\Model\Tile\TileInteraction\NpcTileInteraction;
10+
use App\Model\Tile\TileInteraction\TileInteractionInterface;
11+
use App\Model\Tile\TileLogic\NoLogic;
12+
use App\Model\Tile\TileLogic\TileLogicInterface;
13+
use App\Traits\Tile\PermanentTileTrait;
14+
15+
class ShopTile extends AbstractTile
16+
{
17+
use PermanentTileTrait;
18+
19+
public function isInteractable(): bool
20+
{
21+
return true;
22+
}
23+
24+
public function isPassable(): bool
25+
{
26+
return true;
27+
}
28+
29+
public function isSpawn(): bool
30+
{
31+
return false;
32+
}
33+
34+
public function hasLogic(): bool
35+
{
36+
return false;
37+
}
38+
39+
public function handleLogic(int $scale, StatsInterface $stats): TileLogicInterface
40+
{
41+
return new NoLogic();
42+
}
43+
44+
public function handleInteraction(PlayerInterface $player): TileInteractionInterface
45+
{
46+
return new NpcTileInteraction($player, new Shopkeeper());
47+
}
48+
49+
public function draw(): string
50+
{
51+
return '<fg=yellow>æ</>';
52+
}
53+
}

src/Model/Tile/SpawnTile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public function isInteractable(): bool
1515

1616
public function isPassable(): bool
1717
{
18-
return true;
18+
return false;
1919
}
2020

2121
public function isSpawn(): bool

src/Model/Tile/ShopTile.php renamed to src/Model/Tile/StrangeManTile.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace App\Model\Tile;
44

55
use App\Model\Stats\StatsInterface;
6-
use App\Model\Tile\TileLogic\ShopTileLogic;
6+
use App\Model\Tile\TileLogic\StrangeManTileLogic;
77
use App\Model\Tile\TileLogic\TileLogicInterface;
88

9-
class ShopTile extends AbstractTile
9+
class StrangeManTile extends AbstractTile
1010
{
1111
public function isInteractable(): bool
1212
{
@@ -30,7 +30,7 @@ public function hasLogic(): bool
3030

3131
public function handleLogic(int $scale, StatsInterface $stats): TileLogicInterface
3232
{
33-
return new ShopTileLogic($scale, $stats);
33+
return new StrangeManTileLogic($scale, $stats);
3434
}
3535

3636
public function draw(): string

0 commit comments

Comments
 (0)