diff --git a/.VSCodeCounter/2025-05-22_13-27-44/details.md b/.VSCodeCounter/2025-05-22_13-27-44/details.md deleted file mode 100644 index c04fd04..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/details.md +++ /dev/null @@ -1,49 +0,0 @@ -# Details - -Date : 2025-05-22 13:27:44 - -Directory /home/valentin/Home/Koc/Semester2/KUTowerDefense/src - -Total : 34 files, 8397 codes, 978 comments, 1473 blanks, all 10848 lines - -[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md) - -## Files -| filename | language | code | comment | blank | total | -| :--- | :--- | ---: | ---: | ---: | ---: | -| [src/main/java/com/ku/towerdefense/Main.java](/src/main/java/com/ku/towerdefense/Main.java) | java | 77 | 5 | 13 | 95 | -| [src/main/java/com/ku/towerdefense/controller/GameController.java](/src/main/java/com/ku/towerdefense/controller/GameController.java) | java | 787 | 129 | 114 | 1,030 | -| [src/main/java/com/ku/towerdefense/controller/GamePlayScreen.java](/src/main/java/com/ku/towerdefense/controller/GamePlayScreen.java) | java | 239 | 16 | 49 | 304 | -| [src/main/java/com/ku/towerdefense/model/GamePath.java](/src/main/java/com/ku/towerdefense/model/GamePath.java) | java | 64 | 6 | 10 | 80 | -| [src/main/java/com/ku/towerdefense/model/GameSettings.java](/src/main/java/com/ku/towerdefense/model/GameSettings.java) | java | 342 | 25 | 76 | 443 | -| [src/main/java/com/ku/towerdefense/model/Path.java](/src/main/java/com/ku/towerdefense/model/Path.java) | java | 123 | 14 | 29 | 166 | -| [src/main/java/com/ku/towerdefense/model/PathPoint.java](/src/main/java/com/ku/towerdefense/model/PathPoint.java) | java | 72 | 0 | 10 | 82 | -| [src/main/java/com/ku/towerdefense/model/effects/AnimatedEffect.java](/src/main/java/com/ku/towerdefense/model/effects/AnimatedEffect.java) | java | 65 | 2 | 9 | 76 | -| [src/main/java/com/ku/towerdefense/model/entity/ArcherTower.java](/src/main/java/com/ku/towerdefense/model/entity/ArcherTower.java) | java | 86 | 7 | 14 | 107 | -| [src/main/java/com/ku/towerdefense/model/entity/ArtilleryTower.java](/src/main/java/com/ku/towerdefense/model/entity/ArtilleryTower.java) | java | 91 | 5 | 14 | 110 | -| [src/main/java/com/ku/towerdefense/model/entity/DamageType.java](/src/main/java/com/ku/towerdefense/model/entity/DamageType.java) | java | 22 | 0 | 4 | 26 | -| [src/main/java/com/ku/towerdefense/model/entity/DroppedGold.java](/src/main/java/com/ku/towerdefense/model/entity/DroppedGold.java) | java | 63 | 5 | 13 | 81 | -| [src/main/java/com/ku/towerdefense/model/entity/Enemy.java](/src/main/java/com/ku/towerdefense/model/entity/Enemy.java) | java | 503 | 76 | 77 | 656 | -| [src/main/java/com/ku/towerdefense/model/entity/Entity.java](/src/main/java/com/ku/towerdefense/model/entity/Entity.java) | java | 157 | 4 | 27 | 188 | -| [src/main/java/com/ku/towerdefense/model/entity/Goblin.java](/src/main/java/com/ku/towerdefense/model/entity/Goblin.java) | java | 44 | 8 | 9 | 61 | -| [src/main/java/com/ku/towerdefense/model/entity/Knight.java](/src/main/java/com/ku/towerdefense/model/entity/Knight.java) | java | 70 | 11 | 14 | 95 | -| [src/main/java/com/ku/towerdefense/model/entity/MageTower.java](/src/main/java/com/ku/towerdefense/model/entity/MageTower.java) | java | 73 | 0 | 13 | 86 | -| [src/main/java/com/ku/towerdefense/model/entity/Projectile.java](/src/main/java/com/ku/towerdefense/model/entity/Projectile.java) | java | 261 | 27 | 53 | 341 | -| [src/main/java/com/ku/towerdefense/model/entity/Tower.java](/src/main/java/com/ku/towerdefense/model/entity/Tower.java) | java | 305 | 39 | 58 | 402 | -| [src/main/java/com/ku/towerdefense/model/map/GameMap.java](/src/main/java/com/ku/towerdefense/model/map/GameMap.java) | java | 430 | 57 | 68 | 555 | -| [src/main/java/com/ku/towerdefense/model/map/Tile.java](/src/main/java/com/ku/towerdefense/model/map/Tile.java) | java | 419 | 47 | 58 | 524 | -| [src/main/java/com/ku/towerdefense/model/map/TileType.java](/src/main/java/com/ku/towerdefense/model/map/TileType.java) | java | 47 | 1 | 11 | 59 | -| [src/main/java/com/ku/towerdefense/model/wave/Wave.java](/src/main/java/com/ku/towerdefense/model/wave/Wave.java) | java | 52 | 1 | 13 | 66 | -| [src/main/java/com/ku/towerdefense/model/wave/WaveConfig.java](/src/main/java/com/ku/towerdefense/model/wave/WaveConfig.java) | java | 37 | 7 | 10 | 54 | -| [src/main/java/com/ku/towerdefense/ui/GameScreen.java](/src/main/java/com/ku/towerdefense/ui/GameScreen.java) | java | 749 | 124 | 124 | 997 | -| [src/main/java/com/ku/towerdefense/ui/MainMenuScreen.java](/src/main/java/com/ku/towerdefense/ui/MainMenuScreen.java) | java | 141 | 16 | 20 | 177 | -| [src/main/java/com/ku/towerdefense/ui/MapEditorCanvasView.java](/src/main/java/com/ku/towerdefense/ui/MapEditorCanvasView.java) | java | 625 | 96 | 118 | 839 | -| [src/main/java/com/ku/towerdefense/ui/MapEditorScreen.java](/src/main/java/com/ku/towerdefense/ui/MapEditorScreen.java) | java | 627 | 31 | 100 | 758 | -| [src/main/java/com/ku/towerdefense/ui/MapEditorTilePalette.java](/src/main/java/com/ku/towerdefense/ui/MapEditorTilePalette.java) | java | 448 | 53 | 62 | 563 | -| [src/main/java/com/ku/towerdefense/ui/MapEditorTopToolbar.java](/src/main/java/com/ku/towerdefense/ui/MapEditorTopToolbar.java) | java | 150 | 28 | 25 | 203 | -| [src/main/java/com/ku/towerdefense/ui/MapSelectionScreen.java](/src/main/java/com/ku/towerdefense/ui/MapSelectionScreen.java) | java | 292 | 43 | 60 | 395 | -| [src/main/java/com/ku/towerdefense/ui/OptionsScreen.java](/src/main/java/com/ku/towerdefense/ui/OptionsScreen.java) | java | 262 | 20 | 42 | 324 | -| [src/main/java/com/ku/towerdefense/ui/UIAssets.java](/src/main/java/com/ku/towerdefense/ui/UIAssets.java) | java | 315 | 28 | 51 | 394 | -| [src/main/java/com/ku/towerdefense/util/GameSettings.java](/src/main/java/com/ku/towerdefense/util/GameSettings.java) | java | 359 | 47 | 105 | 511 | - -[Summary](results.md) / Details / [Diff Summary](diff.md) / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/diff-details.md b/.VSCodeCounter/2025-05-22_13-27-44/diff-details.md deleted file mode 100644 index f55d14c..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/diff-details.md +++ /dev/null @@ -1,15 +0,0 @@ -# Diff Details - -Date : 2025-05-22 13:27:44 - -Directory /home/valentin/Home/Koc/Semester2/KUTowerDefense/src - -Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines - -[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details - -## Files -| filename | language | code | comment | blank | total | -| :--- | :--- | ---: | ---: | ---: | ---: | - -[Summary](results.md) / [Details](details.md) / [Diff Summary](diff.md) / Diff Details \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/diff.csv b/.VSCodeCounter/2025-05-22_13-27-44/diff.csv deleted file mode 100644 index b7d8d75..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/diff.csv +++ /dev/null @@ -1,2 +0,0 @@ -"filename", "language", "", "comment", "blank", "total" -"Total", "-", , 0, 0, 0 \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/diff.md b/.VSCodeCounter/2025-05-22_13-27-44/diff.md deleted file mode 100644 index a4badc3..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/diff.md +++ /dev/null @@ -1,19 +0,0 @@ -# Diff Summary - -Date : 2025-05-22 13:27:44 - -Directory /home/valentin/Home/Koc/Semester2/KUTowerDefense/src - -Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines - -[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md) - -## Languages -| language | files | code | comment | blank | total | -| :--- | ---: | ---: | ---: | ---: | ---: | - -## Directories -| path | files | code | comment | blank | total | -| :--- | ---: | ---: | ---: | ---: | ---: | - -[Summary](results.md) / [Details](details.md) / Diff Summary / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/diff.txt b/.VSCodeCounter/2025-05-22_13-27-44/diff.txt deleted file mode 100644 index 80c98a1..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/diff.txt +++ /dev/null @@ -1,22 +0,0 @@ -Date : 2025-05-22 13:27:44 -Directory : /home/valentin/Home/Koc/Semester2/KUTowerDefense/src -Total : 0 files, 0 codes, 0 comments, 0 blanks, all 0 lines - -Languages -+----------+------------+------------+------------+------------+------------+ -| language | files | code | comment | blank | total | -+----------+------------+------------+------------+------------+------------+ -+----------+------------+------------+------------+------------+------------+ - -Directories -+------+------------+------------+------------+------------+------------+ -| path | files | code | comment | blank | total | -+------+------------+------------+------------+------------+------------+ -+------+------------+------------+------------+------------+------------+ - -Files -+----------+----------+------------+------------+------------+------------+ -| filename | language | code | comment | blank | total | -+----------+----------+------------+------------+------------+------------+ -| Total | | 0 | 0 | 0 | 0 | -+----------+----------+------------+------------+------------+------------+ \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/results.csv b/.VSCodeCounter/2025-05-22_13-27-44/results.csv deleted file mode 100644 index f3b7654..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/results.csv +++ /dev/null @@ -1,36 +0,0 @@ -"filename", "language", "java", "comment", "blank", "total" -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/Main.java", "java", 77, 5, 13, 95 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GameController.java", "java", 787, 129, 114, 1030 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GamePlayScreen.java", "java", 239, 16, 49, 304 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GamePath.java", "java", 64, 6, 10, 80 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GameSettings.java", "java", 342, 25, 76, 443 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/Path.java", "java", 123, 14, 29, 166 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/PathPoint.java", "java", 72, 0, 10, 82 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/effects/AnimatedEffect.java", "java", 65, 2, 9, 76 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArcherTower.java", "java", 86, 7, 14, 107 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArtilleryTower.java", "java", 91, 5, 14, 110 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DamageType.java", "java", 22, 0, 4, 26 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DroppedGold.java", "java", 63, 5, 13, 81 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Enemy.java", "java", 503, 76, 77, 656 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Entity.java", "java", 157, 4, 27, 188 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Goblin.java", "java", 44, 8, 9, 61 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Knight.java", "java", 70, 11, 14, 95 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/MageTower.java", "java", 73, 0, 13, 86 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Projectile.java", "java", 261, 27, 53, 341 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Tower.java", "java", 305, 39, 58, 402 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/GameMap.java", "java", 430, 57, 68, 555 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/Tile.java", "java", 419, 47, 58, 524 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/TileType.java", "java", 47, 1, 11, 59 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/Wave.java", "java", 52, 1, 13, 66 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/WaveConfig.java", "java", 37, 7, 10, 54 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/GameScreen.java", "java", 749, 124, 124, 997 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MainMenuScreen.java", "java", 141, 16, 20, 177 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorCanvasView.java", "java", 625, 96, 118, 839 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorScreen.java", "java", 627, 31, 100, 758 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTilePalette.java", "java", 448, 53, 62, 563 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTopToolbar.java", "java", 150, 28, 25, 203 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapSelectionScreen.java", "java", 292, 43, 60, 395 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/OptionsScreen.java", "java", 262, 20, 42, 324 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/UIAssets.java", "java", 315, 28, 51, 394 -"/home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/util/GameSettings.java", "java", 359, 47, 105, 511 -"Total", "-", 8397, 978, 1473, 10848 \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/results.json b/.VSCodeCounter/2025-05-22_13-27-44/results.json deleted file mode 100644 index 2ffbc9d..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/results.json +++ /dev/null @@ -1 +0,0 @@ -{"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MainMenuScreen.java":{"language":"java","code":141,"comment":16,"blank":20},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTopToolbar.java":{"language":"java","code":150,"comment":28,"blank":25},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapSelectionScreen.java":{"language":"java","code":292,"comment":43,"blank":60},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/UIAssets.java":{"language":"java","code":315,"comment":28,"blank":51},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTilePalette.java":{"language":"java","code":448,"comment":53,"blank":62},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorScreen.java":{"language":"java","code":627,"comment":31,"blank":100},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorCanvasView.java":{"language":"java","code":625,"comment":96,"blank":118},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/OptionsScreen.java":{"language":"java","code":262,"comment":20,"blank":42},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/Main.java":{"language":"java","code":77,"comment":5,"blank":13},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/util/GameSettings.java":{"language":"java","code":359,"comment":47,"blank":105},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/GameScreen.java":{"language":"java","code":749,"comment":124,"blank":124},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GamePlayScreen.java":{"language":"java","code":239,"comment":16,"blank":49},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GamePath.java":{"language":"java","code":64,"comment":6,"blank":10},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/Path.java":{"language":"java","code":123,"comment":14,"blank":29},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/PathPoint.java":{"language":"java","code":72,"comment":0,"blank":10},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Goblin.java":{"language":"java","code":44,"comment":8,"blank":9},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DamageType.java":{"language":"java","code":22,"comment":0,"blank":4},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArtilleryTower.java":{"language":"java","code":91,"comment":5,"blank":14},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GameController.java":{"language":"java","code":787,"comment":129,"blank":114},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DroppedGold.java":{"language":"java","code":63,"comment":5,"blank":13},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Projectile.java":{"language":"java","code":261,"comment":27,"blank":53},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/MageTower.java":{"language":"java","code":73,"comment":0,"blank":13},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Knight.java":{"language":"java","code":70,"comment":11,"blank":14},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Entity.java":{"language":"java","code":157,"comment":4,"blank":27},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Tower.java":{"language":"java","code":305,"comment":39,"blank":58},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Enemy.java":{"language":"java","code":503,"comment":76,"blank":77},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArcherTower.java":{"language":"java","code":86,"comment":7,"blank":14},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/WaveConfig.java":{"language":"java","code":37,"comment":7,"blank":10},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/Wave.java":{"language":"java","code":52,"comment":1,"blank":13},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GameSettings.java":{"language":"java","code":342,"comment":25,"blank":76},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/GameMap.java":{"language":"java","code":430,"comment":57,"blank":68},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/TileType.java":{"language":"java","code":47,"comment":1,"blank":11},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/Tile.java":{"language":"java","code":419,"comment":47,"blank":58},"file:///home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/effects/AnimatedEffect.java":{"language":"java","code":65,"comment":2,"blank":9}} \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/results.md b/.VSCodeCounter/2025-05-22_13-27-44/results.md deleted file mode 100644 index bea9344..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/results.md +++ /dev/null @@ -1,36 +0,0 @@ -# Summary - -Date : 2025-05-22 13:27:44 - -Directory /home/valentin/Home/Koc/Semester2/KUTowerDefense/src - -Total : 34 files, 8397 codes, 978 comments, 1473 blanks, all 10848 lines - -Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md) - -## Languages -| language | files | code | comment | blank | total | -| :--- | ---: | ---: | ---: | ---: | ---: | -| java | 34 | 8,397 | 978 | 1,473 | 10,848 | - -## Directories -| path | files | code | comment | blank | total | -| :--- | ---: | ---: | ---: | ---: | ---: | -| . | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku/towerdefense | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku/towerdefense (Files) | 1 | 77 | 5 | 13 | 95 | -| main/java/com/ku/towerdefense/controller | 2 | 1,026 | 145 | 163 | 1,334 | -| main/java/com/ku/towerdefense/model | 21 | 3,326 | 342 | 590 | 4,258 | -| main/java/com/ku/towerdefense/model (Files) | 4 | 601 | 45 | 125 | 771 | -| main/java/com/ku/towerdefense/model/effects | 1 | 65 | 2 | 9 | 76 | -| main/java/com/ku/towerdefense/model/entity | 11 | 1,675 | 182 | 296 | 2,153 | -| main/java/com/ku/towerdefense/model/map | 3 | 896 | 105 | 137 | 1,138 | -| main/java/com/ku/towerdefense/model/wave | 2 | 89 | 8 | 23 | 120 | -| main/java/com/ku/towerdefense/ui | 9 | 3,609 | 439 | 602 | 4,650 | -| main/java/com/ku/towerdefense/util | 1 | 359 | 47 | 105 | 511 | - -Summary / [Details](details.md) / [Diff Summary](diff.md) / [Diff Details](diff-details.md) \ No newline at end of file diff --git a/.VSCodeCounter/2025-05-22_13-27-44/results.txt b/.VSCodeCounter/2025-05-22_13-27-44/results.txt deleted file mode 100644 index 0fb8193..0000000 --- a/.VSCodeCounter/2025-05-22_13-27-44/results.txt +++ /dev/null @@ -1,73 +0,0 @@ -Date : 2025-05-22 13:27:44 -Directory : /home/valentin/Home/Koc/Semester2/KUTowerDefense/src -Total : 34 files, 8397 codes, 978 comments, 1473 blanks, all 10848 lines - -Languages -+----------+------------+------------+------------+------------+------------+ -| language | files | code | comment | blank | total | -+----------+------------+------------+------------+------------+------------+ -| java | 34 | 8,397 | 978 | 1,473 | 10,848 | -+----------+------------+------------+------------+------------+------------+ - -Directories -+----------------------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ -| path | files | code | comment | blank | total | -+----------------------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ -| . | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku/towerdefense | 34 | 8,397 | 978 | 1,473 | 10,848 | -| main/java/com/ku/towerdefense (Files) | 1 | 77 | 5 | 13 | 95 | -| main/java/com/ku/towerdefense/controller | 2 | 1,026 | 145 | 163 | 1,334 | -| main/java/com/ku/towerdefense/model | 21 | 3,326 | 342 | 590 | 4,258 | -| main/java/com/ku/towerdefense/model (Files) | 4 | 601 | 45 | 125 | 771 | -| main/java/com/ku/towerdefense/model/effects | 1 | 65 | 2 | 9 | 76 | -| main/java/com/ku/towerdefense/model/entity | 11 | 1,675 | 182 | 296 | 2,153 | -| main/java/com/ku/towerdefense/model/map | 3 | 896 | 105 | 137 | 1,138 | -| main/java/com/ku/towerdefense/model/wave | 2 | 89 | 8 | 23 | 120 | -| main/java/com/ku/towerdefense/ui | 9 | 3,609 | 439 | 602 | 4,650 | -| main/java/com/ku/towerdefense/util | 1 | 359 | 47 | 105 | 511 | -+----------------------------------------------------------------------------------------------------------------------+------------+------------+------------+------------+------------+ - -Files -+----------------------------------------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ -| filename | language | code | comment | blank | total | -+----------------------------------------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/Main.java | java | 77 | 5 | 13 | 95 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GameController.java | java | 787 | 129 | 114 | 1,030 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/controller/GamePlayScreen.java | java | 239 | 16 | 49 | 304 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GamePath.java | java | 64 | 6 | 10 | 80 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/GameSettings.java | java | 342 | 25 | 76 | 443 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/Path.java | java | 123 | 14 | 29 | 166 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/PathPoint.java | java | 72 | 0 | 10 | 82 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/effects/AnimatedEffect.java | java | 65 | 2 | 9 | 76 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArcherTower.java | java | 86 | 7 | 14 | 107 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/ArtilleryTower.java | java | 91 | 5 | 14 | 110 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DamageType.java | java | 22 | 0 | 4 | 26 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/DroppedGold.java | java | 63 | 5 | 13 | 81 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Enemy.java | java | 503 | 76 | 77 | 656 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Entity.java | java | 157 | 4 | 27 | 188 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Goblin.java | java | 44 | 8 | 9 | 61 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Knight.java | java | 70 | 11 | 14 | 95 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/MageTower.java | java | 73 | 0 | 13 | 86 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Projectile.java | java | 261 | 27 | 53 | 341 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/entity/Tower.java | java | 305 | 39 | 58 | 402 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/GameMap.java | java | 430 | 57 | 68 | 555 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/Tile.java | java | 419 | 47 | 58 | 524 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/map/TileType.java | java | 47 | 1 | 11 | 59 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/Wave.java | java | 52 | 1 | 13 | 66 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/model/wave/WaveConfig.java | java | 37 | 7 | 10 | 54 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/GameScreen.java | java | 749 | 124 | 124 | 997 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MainMenuScreen.java | java | 141 | 16 | 20 | 177 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorCanvasView.java | java | 625 | 96 | 118 | 839 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorScreen.java | java | 627 | 31 | 100 | 758 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTilePalette.java | java | 448 | 53 | 62 | 563 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapEditorTopToolbar.java | java | 150 | 28 | 25 | 203 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/MapSelectionScreen.java | java | 292 | 43 | 60 | 395 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/OptionsScreen.java | java | 262 | 20 | 42 | 324 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/ui/UIAssets.java | java | 315 | 28 | 51 | 394 | -| /home/valentin/Home/Koc/Semester2/KUTowerDefense/src/main/java/com/ku/towerdefense/util/GameSettings.java | java | 359 | 47 | 105 | 511 | -| Total | | 8,397 | 978 | 1,473 | 10,848 | -+----------------------------------------------------------------------------------------------------------------------+----------+------------+------------+------------+------------+ \ No newline at end of file diff --git a/.github/workflows/foundation.yml b/.github/workflows/foundation.yml new file mode 100644 index 0000000..9e11fe7 --- /dev/null +++ b/.github/workflows/foundation.yml @@ -0,0 +1,24 @@ +name: Foundation +on: [push, pull_request] +jobs: + windows: + runs-on: windows-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-dotnet@v4 + with: + dotnet-version: | + 10.0.400 + 8.0.x + - name: Install pinned Godot and restore locked dependencies + run: ./scripts/dev.ps1 setup + - name: Build and test + run: ./scripts/dev.ps1 test + - name: Engine integration + run: ./scripts/dev.ps1 smoke + - name: Export Windows build + run: ./scripts/dev.ps1 export + - uses: actions/upload-artifact@v4 + with: + name: Emberwatch-Windows + path: .artifacts/windows/ diff --git a/.gitignore b/.gitignore index 2f7896d..f197404 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,9 @@ target/ +.tools/ +.artifacts/ +**/bin/ +**/obj/ +**/.godot/ +**/TestResults/ +*.user +*.suo diff --git a/.idea/KUTowerDefense.iml b/.idea/KUTowerDefense.iml deleted file mode 100644 index d6ebd48..0000000 --- a/.idea/KUTowerDefense.iml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 29f296a..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml deleted file mode 100644 index 712ab9d..0000000 --- a/.idea/jarRepositories.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index c2f272f..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Comp 302 - Project Design Document - Spring 2025.pdf b/Comp 302 - Project Design Document - Spring 2025.pdf deleted file mode 100644 index c08b138..0000000 Binary files a/Comp 302 - Project Design Document - Spring 2025.pdf and /dev/null differ diff --git a/README.md b/README.md index 9aef57d..f6ed2b3 100644 --- a/README.md +++ b/README.md @@ -1,28 +1,39 @@ -# KuTowerDefense - -## 🎮 Overview -KuTowerDefense is a classic Tower Defense game where players strategically place towers to stop waves of enemies from reaching their base. The game blends real-time strategy and planning, offering increasing difficulty and diverse tower types. - -## 🧩 Features -- Multiple enemy types with different abilities -- Several tower types with upgrade paths -- Wave-based enemy spawning system -- Custom maps and dynamic level progression -- Game-over and scoring system - -## 🛠️ Tech Stack -- **Language:** Java -- **Framework:** JavaFX -- **Testing:** JUnit -- **Build Tool:** Maven - -## 🚀 Getting Started - -### Prerequisites -Make sure you have: -- Java 11+ installed -- IDE like IntelliJ or Eclipse (optional but recommended) -## How To Play? -- Just run pom.xml with Maven - -## More Updates to come! +# REDESIGN: EVOLUTION + +A new PC tower defense game about elemental reactions and connected defenses. Active implementation: Godot 4.7.2 .NET with independent C# simulation. Course requirements and legacy formats are retired. + +## Play and develop + +Windows x64; .NET SDK **10.0.400** and .NET 8 runtime. Setup downloads pinned Godot/tools into ignored `.tools/`, with no global engine installation. + +```powershell +.\dev.cmd setup +.\dev.cmd test +.\dev.cmd run +.\dev.cmd export +``` + +Exports: `.artifacts/windows/`. The exported executable includes its runtime; no Java/development tools required. + +`dev.cmd` invokes the repository script with a process-local execution policy; it does not change the machine's PowerShell policy. `smoke`, `sim`, `benchmark` and `capture` are additional developer commands. Export also runs the packaged game's integration check. Distribute the entire export directory, including its `.pck` and runtime folder. + +Current slice: **Emberwatch Expedition**, twelve waves across four stages on one map, three tower families and six exclusive specializations. Earn a choice of three relics after waves 3, 6 and 9 from seven behavior/recovery rewards. Optional Overruns offer extra income for holding against forecast Raiders without a breach. Menders sustain formations; armored Captains test specialization; the Bellwarden rallies reinforcements and drops its guard while ringing. At half health it advances and rallies faster. + +Start with 180 gold and 12 lives. Click a tower card then a foundation; select towers to inspect, evolve, change priorities or sell. B/P/C selects Boltworks/Prism/Crucible, U opens paths, T cycles targeting, N starts a wave, Space pauses, 1/2/4 sets speed, I reviews relics, Escape closes/cancels, M mutes and R starts a new expedition after a result. While choosing a relic, 1/2/3 selects its card. Path/relic review pauses combat and leaves it paused until you resume. See [play instructions](docs/PLAYABLE_BUILD.md). + +Active content lives in `Redesign-Evolution/Game/Content/expedition.json` (format 2). The prior six-wave `emberwatch.json` and three-wave `foundation.json` remain unchanged as regression scenarios. Circuits, additional maps, save/resume, final art and full 25–40-minute runs remain planned. This iteration prioritizes earned progression and encounter pressure over another isolated combat system. + +`dev.cmd sim` runs the expedition through ordinary commands. After building, use `dotnet Redesign-Evolution/SimRunner/bin/Debug/net8.0/Redesign.SimRunner.dll --balance` for frost/fire/steel and passive controls across seeds 1/7/42; add `--risk` to accept every Overrun. Individual runs accept `--strategy fire --seed 42`. `--roster`, `--evolution` and `--foundation` select the earlier scenarios; `--no-build` verifies defeat. `dev.cmd benchmark` measures reference scans versus spatial queries, not graphics FPS. Automated victories establish feasibility; human difficulty/enjoyment playtesting remains necessary. + +## Project + +- `Redesign-Evolution/Core`: independent authoritative simulation. +- `Redesign-Evolution/Infrastructure`: content loading/validation. +- `Redesign-Evolution/Game`: Godot presentation/input/audio. +- `Redesign-Evolution/SimRunner`: seeded display-free runs. +- `Redesign-Evolution/Tests`: regression coverage. +- [Progress](docs/DEVELOPMENT_PROGRESS.md), [roadmap](docs/REDESIGN_EVOLUTION_ROADMAP.md), [design](docs/GAME_DESIGN_DOCUMENT.md), [architecture](docs/ARCHITECTURE_DECISION.md). + +## History + +Original Java source/assets: Git commit `be87036f68d752d98d096f8f7c7f1a3ad6e082d6`. [Inventory](docs/FEATURE_INVENTORY.md) records the audit and baseline evidence; hash/retirement manifests accompany it. No branch switch, history rewrite or remote operation is part of this rebuild. Unrelated local files are preserved. diff --git a/Redesign-Evolution/Core/AssemblyInfo.cs b/Redesign-Evolution/Core/AssemblyInfo.cs new file mode 100644 index 0000000..a3ebaf9 --- /dev/null +++ b/Redesign-Evolution/Core/AssemblyInfo.cs @@ -0,0 +1,4 @@ +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Redesign.Tests")] +[assembly: InternalsVisibleTo("Redesign.SimRunner")] diff --git a/Redesign-Evolution/Core/CombatDefinitions.cs b/Redesign-Evolution/Core/CombatDefinitions.cs new file mode 100644 index 0000000..f362e5b --- /dev/null +++ b/Redesign-Evolution/Core/CombatDefinitions.cs @@ -0,0 +1,93 @@ +namespace Redesign.Core; + +public enum ReactionEffect { Burst, BurningGround } +public sealed record StatusApplication(string StatusId, int Stacks = 1); +public sealed record StatusDefinition(string Id, string Name, int MaxStacks, int DurationTicks, + int SlowPercentPerStack = 0, int ArmorReductionPerStack = 0); +public sealed record EchoDefinition(int DelayTicks, int Damage, double Radius, DamageKind DamageKind = DamageKind.Impact); +public sealed record ReactionDefinition(string Id, string Name, string StatusId, int RequiredStacks, + DamageKind Trigger, ReactionEffect Effect, int Damage, double Radius, DamageKind DamageKind, + int CooldownTicks, int DurationTicks = 0, int IntervalTicks = 0, int MaxAreas = 0); +// Upgrade.Id is the branch ID. Upgrade.Cost retains the base build price; Cost is the additional investment. +public sealed record BranchDefinition(string TowerId, int Cost, TowerDefinition Upgrade); +public sealed record CombatDefinition(StatusDefinition[] Statuses, ReactionDefinition[] Reactions, BranchDefinition[] Branches) +{ + public CombatDefinition Copy() => new([.. Statuses], [.. Reactions], [.. Branches]); +} + +internal static class CombatContent +{ + public static void Validate(GameDefinition game) + { + static void Require(bool valid, string message) + { if (!valid) throw new ArgumentException("Invalid combat content: " + message); } + var combat = game.Combat ?? new([], [], []); + Require(combat.Statuses is { Length: <= 32 } && combat.Reactions is { Length: <= 16 } && + combat.Branches is { Length: <= 64 }, "statuses/reactions/branches arrays and limits"); + if (combat.Statuses is null || combat.Reactions is null || combat.Branches is null) return; + var statuses = new Dictionary(StringComparer.Ordinal); + foreach (var status in combat.Statuses) + { + Require(status is not null, "null status"); + if (status is null) return; + Require(!string.IsNullOrWhiteSpace(status.Id) && !string.IsNullOrWhiteSpace(status.Name), "status identity"); + Require(statuses.TryAdd(status.Id, status), $"duplicate status '{status.Id}'"); + Require(status.MaxStacks is >= 1 and <= 8 && status.DurationTicks is >= 1 and <= 36000 && + status.SlowPercentPerStack >= 0 && (long)status.SlowPercentPerStack * status.MaxStacks <= 80 && + status.ArmorReductionPerStack is >= 0 and <= 10000, $"status '{status.Id}' duration/stacks/modifiers"); + } + var reactions = new HashSet(StringComparer.Ordinal); + var triggers = new HashSet<(string, DamageKind)>(); + foreach (var reaction in combat.Reactions) + { + Require(reaction is not null, "null reaction"); + if (reaction is null) return; + Require(!string.IsNullOrWhiteSpace(reaction.Id) && !string.IsNullOrWhiteSpace(reaction.Name) && + reactions.Add(reaction.Id), $"reaction '{reaction.Id}' identity/duplicate"); + Require(reaction.StatusId is not null && statuses.ContainsKey(reaction.StatusId), + $"reaction '{reaction.Id}' unknown status '{reaction.StatusId}'"); + Require(reaction.RequiredStacks > 0 && reaction.RequiredStacks <= statuses[reaction.StatusId!].MaxStacks && + reaction.Damage > 0 && double.IsFinite(reaction.Radius) && reaction.Radius > 0 && + reaction.CooldownTicks is >= 1 and <= 36000 && Enum.IsDefined(reaction.Trigger) && + Enum.IsDefined(reaction.Effect) && Enum.IsDefined(reaction.DamageKind), $"reaction '{reaction.Id}' values"); + Require(triggers.Add((reaction.StatusId!, reaction.Trigger)), $"ambiguous reaction for '{reaction.StatusId}' + {reaction.Trigger}"); + Require(reaction.Effect == ReactionEffect.BurningGround + ? reaction.DurationTicks is > 0 and <= 36000 && reaction.IntervalTicks > 0 && + reaction.IntervalTicks <= reaction.DurationTicks && reaction.MaxAreas is >= 1 and <= 16 + : reaction.DurationTicks == 0 && reaction.IntervalTicks == 0 && reaction.MaxAreas == 0, + $"reaction '{reaction.Id}' area timing/cap"); + } + void ValidateAttack(TowerDefinition tower) + { + Require(double.IsFinite(tower.ForkRadius) && tower.ForkRadius >= 0 && + tower.ForkDamagePercent is >= 1 and <= 100 && (tower.ForkRadius == 0 || tower.Attack != AttackKind.Shell), $"tower '{tower.Id}' fork"); + if (tower.OnHit is { } onHit) + Require(onHit.StatusId is not null && statuses.TryGetValue(onHit.StatusId, out var status) && + onHit.Stacks > 0 && onHit.Stacks <= status.MaxStacks, $"tower '{tower.Id}' onHit status/stacks"); + if (tower.Echo is { } echo) + Require(tower.Attack == AttackKind.Shell && echo.DelayTicks is >= 1 and <= 3600 && + echo.Damage > 0 && double.IsFinite(echo.Radius) && echo.Radius > 0 && + Enum.IsDefined(echo.DamageKind), $"tower '{tower.Id}' echo"); + } + foreach (var tower in game.Towers) ValidateAttack(tower); + var ids = game.Towers.Select(t => t.Id).ToHashSet(StringComparer.Ordinal); + foreach (var branch in combat.Branches) + { + Require(branch is not null && branch.Upgrade is not null, "null branch/upgrade"); + if (branch is null || branch.Upgrade is null) return; + var parent = game.Towers.FirstOrDefault(t => t.Id == branch.TowerId); + Require(parent is not null, $"branch '{branch.Upgrade.Id}' unknown family '{branch.TowerId}'"); + var upgrade = branch.Upgrade; + Require(!string.IsNullOrWhiteSpace(upgrade.Id) && ids.Add(upgrade.Id) && + !string.IsNullOrWhiteSpace(upgrade.Name) && !string.IsNullOrWhiteSpace(upgrade.Description), $"branch '{upgrade.Id}' identity/duplicate"); + Require(branch.Cost > 0 && upgrade.Cost == parent!.Cost && + upgrade.Damage > 0 && upgrade.CooldownTicks > 0 && + double.IsFinite(upgrade.Range) && upgrade.Range > 0 && + double.IsFinite(upgrade.ProjectileSpeed) && upgrade.ProjectileSpeed > 0 && + double.IsFinite(upgrade.SplashRadius) && upgrade.SplashRadius >= 0 && + Enum.IsDefined(upgrade.Attack) && Enum.IsDefined(upgrade.DamageKind) && + (upgrade.Attack != AttackKind.Beam || upgrade.SplashRadius == 0), $"branch '{upgrade.Id}' attack/cost"); + ValidateAttack(upgrade); + } + } +} diff --git a/Redesign-Evolution/Core/Definitions.cs b/Redesign-Evolution/Core/Definitions.cs new file mode 100644 index 0000000..317ef09 --- /dev/null +++ b/Redesign-Evolution/Core/Definitions.cs @@ -0,0 +1,122 @@ +namespace Redesign.Core; + +public readonly record struct Cell(int X, int Y); + +public readonly record struct Point(double X, double Y) +{ + public static Point operator +(Point a, Point b) => new(a.X + b.X, a.Y + b.Y); + public static Point operator -(Point a, Point b) => new(a.X - b.X, a.Y - b.Y); + public static Point operator *(Point a, double scale) => new(a.X * scale, a.Y * scale); + public double LengthSquared => X * X + Y * Y; + public double Length => Math.Sqrt(LengthSquared); +} + +public enum AttackKind { Bolt, Beam, Shell } +public enum DamageKind { Impact, Energy, Frost, Fire } +public enum TargetPriority { First, Strongest, Support, Primed } + +public sealed record TowerDefinition(string Id, int Cost, int Damage, double Range, + int CooldownTicks, double ProjectileSpeed, double SplashRadius = 0, + AttackKind Attack = AttackKind.Bolt, DamageKind DamageKind = DamageKind.Impact, + string Name = "", string Description = "", StatusApplication? OnHit = null, EchoDefinition? Echo = null, + double ForkRadius = 0, int ForkDamagePercent = 50); +public sealed record EnemyDefinition(string Id, int Health, double Speed, int Bounty, int LeakDamage, + int Armor = 0, double ShieldRadius = 0, int ShieldPercent = 0, string Name = "", + HealingDefinition? Healing = null, BossDefinition? Boss = null, int SlowResistancePercent = 0); +public sealed record SpawnGroup(string EnemyId, int Count, int IntervalTicks, int DelayTicks = 0); +public sealed record WaveDefinition(string Title, string Briefing, SpawnGroup[] Groups, int ClearGold = 0, int HealthPercent = 100); +public sealed record MapDefinition(string Id, string Title, int Width, int Height, int TileSize, + Cell[] Route, Cell[] Foundations) +{ + public Point Center(Cell cell) => new((cell.X + .5) * TileSize, (cell.Y + .5) * TileSize); +} + +public sealed record GameDefinition(int FormatVersion, string Id, int StartingGold, int StartingLives, + MapDefinition Map, TowerDefinition[] Towers, EnemyDefinition[] Enemies, WaveDefinition[] Waves, + CombatDefinition? Combat = null, ExpeditionDefinition? Expedition = null) +{ + public GameDefinition Copy() => this with + { + Map = Map with { Route = [.. Map.Route], Foundations = [.. Map.Foundations] }, + Towers = [.. Towers], Enemies = [.. Enemies], + Waves = Waves.Select(w => w with { Groups = [.. w.Groups] }).ToArray(), + Combat = Combat?.Copy(), Expedition = Expedition?.Copy() + }; + + public void Validate() + { + void Require(bool valid, string field) { if (!valid) throw new ArgumentException($"Invalid content: {field}"); } + static bool Positive(double value) => double.IsFinite(value) && value > 0; + Require(FormatVersion == 2, "formatVersion must be 2"); + Require(!string.IsNullOrWhiteSpace(Id), "id"); + Require(StartingGold >= 0 && StartingLives > 0, "starting resources"); + Require(Map is not null && Towers is { Length: > 0 and <= 64 } && + Enemies is { Length: > 0 and <= 128 } && Waves is not null, "required map/towers/enemies/waves definitions"); + if (Map is null || Towers is null || Enemies is null || Waves is null) return; + Require(!string.IsNullOrWhiteSpace(Map.Id) && !string.IsNullOrWhiteSpace(Map.Title), "map identity"); + Require(Map.Width is > 1 and <= 128 && Map.Height is > 1 and <= 128 && Map.TileSize is >= 8 and <= 256, "map dimensions"); + Require(Map.Route is { Length: >= 2 } && Map.Foundations is { Length: > 0 }, "route/foundations"); + if (Map.Route is null || Map.Foundations is null) return; + bool Inside(Cell c) => c.X >= 0 && c.Y >= 0 && c.X < Map.Width && c.Y < Map.Height; + Require(Map.Route.All(Inside) && Map.Foundations.All(Inside), "map cell bounds"); + var pathCells = new HashSet(); + pathCells.Add(Map.Route[0]); + for (var i = 1; i < Map.Route.Length; i++) + { + var a = Map.Route[i - 1]; var b = Map.Route[i]; + Require(a != b && (a.X == b.X || a.Y == b.Y), "route must have nonzero orthogonal segments"); + var dx = Math.Sign(b.X - a.X); var dy = Math.Sign(b.Y - a.Y); + for (var c = new Cell(a.X + dx, a.Y + dy); ; c = new Cell(c.X + dx, c.Y + dy)) + { + Require(pathCells.Add(c), "route must not overlap itself"); + if (c == b) break; + } + } + Require(Map.Foundations.Distinct().Count() == Map.Foundations.Length, "duplicate foundations"); + Require(Map.Foundations.All(c => !pathCells.Contains(c)), "foundation overlaps route"); + foreach (var tower in Towers) + { + Require(tower is not null, "null tower"); + if (tower is null) return; + Require(!string.IsNullOrWhiteSpace(tower.Id) && tower.Cost > 0 && tower.Damage > 0 && + tower.CooldownTicks > 0 && Positive(tower.Range) && Positive(tower.ProjectileSpeed) && + double.IsFinite(tower.SplashRadius) && tower.SplashRadius >= 0 && + Enum.IsDefined(tower.Attack) && Enum.IsDefined(tower.DamageKind), $"tower '{tower.Id}' values"); + Require(tower.Attack != AttackKind.Beam || tower.SplashRadius == 0, $"tower '{tower.Id}': beams cannot splash"); + } + Require(Towers.Select(t => t.Id).Distinct(StringComparer.Ordinal).Count() == Towers.Length, "duplicate tower id"); + CombatContent.Validate(this); + foreach (var enemy in Enemies) + { + Require(enemy is not null, "null enemy"); + if (enemy is null) return; + Require(!string.IsNullOrWhiteSpace(enemy.Id) && enemy.Health > 0 && Positive(enemy.Speed) && + enemy.Bounty >= 0 && enemy.LeakDamage > 0 && enemy.Armor >= 0 && + double.IsFinite(enemy.ShieldRadius) && enemy.ShieldRadius >= 0 && + enemy.ShieldPercent is >= 0 and <= 80 && + (enemy.ShieldRadius > 0) == (enemy.ShieldPercent > 0), $"enemy '{enemy.Id}' values"); + } + var enemyIds = Enemies.Select(e => e.Id).ToHashSet(StringComparer.Ordinal); + Require(enemyIds.Count == Enemies.Length, "duplicate enemy id"); + Require(Waves.Length is > 0 and <= 1000, "waves"); + for (var i = 0; i < Waves.Length; i++) + { + var wave = Waves[i]; + Require(wave is not null && !string.IsNullOrWhiteSpace(wave.Title) && + wave.Groups is { Length: > 0 and <= 32 }, $"wave {i + 1}: title/groups"); + if (wave is null || wave.Groups is null) return; + foreach (var group in wave.Groups) + { + Require(group is not null, $"wave {i + 1}: null spawn group"); + if (group is null) return; + Require(enemyIds.Contains(group.EnemyId), $"wave {i + 1}: unknown enemy '{group.EnemyId}'"); + Require(group.Count is > 0 and <= 10000 && group.IntervalTicks is > 0 and <= 36000 && + group.DelayTicks is >= 0 and <= 216000, $"wave {i + 1}: spawn count/timing"); + } + Require(wave.Groups.Sum(g => g.Count) <= 10000, $"wave {i + 1}: maximum 10000 spawns"); + Require(wave.ClearGold is >= 0 and <= 10000, $"wave {i + 1}: clear reward"); + Require(wave.HealthPercent is >= 25 and <= 300, $"wave {i + 1}: health percentage"); + } + ExpeditionContent.Validate(this); + } +} diff --git a/Redesign-Evolution/Core/EffectState.cs b/Redesign-Evolution/Core/EffectState.cs new file mode 100644 index 0000000..705e520 --- /dev/null +++ b/Redesign-Evolution/Core/EffectState.cs @@ -0,0 +1,96 @@ +using System.Collections; +using System.Collections.ObjectModel; + +namespace Redesign.Core; + +public readonly record struct StatusStack(int SourceId, long ExpiresAt); +public sealed class StatusState +{ + public StatusDefinition Definition { get; } + internal List MutableStacks { get; } = []; + public ReadOnlyCollection Stacks { get; } + public int Count => MutableStacks.Count; + internal StatusState(StatusDefinition definition) + { Definition = definition; Stacks = MutableStacks.AsReadOnly(); } +} + +/// Independent stack expiry; at capacity, replace the oldest stack. Consumption is oldest-first. +internal sealed class StatusSet : IReadOnlyList +{ + private readonly List states = []; + public int Count => states.Count; + public StatusState this[int index] => states[index]; + public IEnumerator GetEnumerator() => states.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + public int SlowPercent + { + get + { + var strongest = 0; + foreach (var status in states) strongest = Math.Max(strongest, status.Definition.SlowPercentPerStack * status.Count); + return strongest; // Validated at <=80%; independent slowing effects never add together. + } + } + public int ArmorReduction + { + get + { + var total = 0; + foreach (var status in states) total += status.Definition.ArmorReductionPerStack * status.Count; + return total; // Catalog caps bound the sum well below int.MaxValue. + } + } + public StatusState? Find(string id) + { + foreach (var status in states) if (status.Definition.Id == id) return status; + return null; + } + public void Apply(StatusDefinition definition, int count, int source, long tick) + { + var status = Find(definition.Id); + if (status is null) { status = new(definition); states.Add(status); } + for (var i = 0; i < count; i++) + { + if (status.Count == definition.MaxStacks) status.MutableStacks.RemoveAt(0); + status.MutableStacks.Add(new(source, tick + definition.DurationTicks)); + } + } + public void Expire(long tick) + { + for (var i = states.Count - 1; i >= 0; i--) + { + var stacks = states[i].MutableStacks; + // This runs for every enemy every tick; avoid a captured predicate even for empty sets. + for (var stack = stacks.Count - 1; stack >= 0; stack--) + if (stacks[stack].ExpiresAt <= tick) stacks.RemoveAt(stack); + if (states[i].Count == 0) states.RemoveAt(i); + } + } + public int[] Consume(StatusState status, int count) + { + var sources = status.MutableStacks.Take(count).Select(s => s.SourceId).Distinct().Order().ToArray(); + status.MutableStacks.RemoveRange(0, count); + if (status.Count == 0) states.Remove(status); + return sources; + } +} + +public sealed class ReactionStatistics(ReactionDefinition definition) +{ + public ReactionDefinition Definition { get; internal set; } = definition; + public long Triggers { get; internal set; } + public long Damage { get; internal set; } +} + +public sealed class BurningAreaState(int id, Point position, int sourceId, ReactionDefinition definition, long tick) +{ + public int Id { get; } = id; + public Point Position { get; } = position; + public int SourceId { get; } = sourceId; + public ReactionDefinition Definition { get; } = definition; + public long ExpiresAt { get; } = tick + definition.DurationTicks; + public long NextPulseTick { get; internal set; } = tick; +} + +public sealed record PendingImpactState(int Id, Point Position, int SourceId, EchoDefinition Definition, + long CreatedAt, long ResolveAt); diff --git a/Redesign-Evolution/Core/EnemySpatialIndex.cs b/Redesign-Evolution/Core/EnemySpatialIndex.cs new file mode 100644 index 0000000..08bc3be --- /dev/null +++ b/Redesign-Evolution/Core/EnemySpatialIndex.cs @@ -0,0 +1,50 @@ +namespace Redesign.Core; + +/// +/// Bounded broad phase rebuilt after movement. Buckets retain capacity across ticks. +/// Queries include the radius boundary and filter deaths occurring after the rebuild. +/// Callers must define resolution order; bucket order is not gameplay order. +/// +internal sealed class EnemySpatialIndex +{ + private readonly List[] buckets; + private readonly int columns, rows, cellSize; + + public EnemySpatialIndex(MapDefinition map) + { + cellSize = map.TileSize * 2; + columns = (map.Width * map.TileSize + cellSize - 1) / cellSize; + rows = (map.Height * map.TileSize + cellSize - 1) / cellSize; + buckets = Enumerable.Range(0, columns * rows).Select(_ => new List()).ToArray(); + } + + public void Rebuild(IReadOnlyList enemies) + { + foreach (var bucket in buckets) bucket.Clear(); + foreach (var enemy in enemies) + { + if (!enemy.Alive) continue; + var x = Coordinate(enemy.Position.X, columns); + var y = Coordinate(enemy.Position.Y, rows); + buckets[y * columns + x].Add(enemy); + } + } + + public void Query(Point center, double radius, List result) + { + result.Clear(); + var minX = Coordinate(center.X - radius, columns); + var maxX = Coordinate(center.X + radius, columns); + var minY = Coordinate(center.Y - radius, rows); + var maxY = Coordinate(center.Y + radius, rows); + var squared = radius * radius; + for (var y = minY; y <= maxY; y++) + for (var x = minX; x <= maxX; x++) + foreach (var enemy in buckets[y * columns + x]) + if (enemy.Alive && (enemy.Position - center).LengthSquared <= squared) + result.Add(enemy); + } + + private int Coordinate(double value, int count) => + (int)Math.Clamp(Math.Floor(value / cellSize), 0, count - 1); +} diff --git a/Redesign-Evolution/Core/ExpeditionDefinitions.cs b/Redesign-Evolution/Core/ExpeditionDefinitions.cs new file mode 100644 index 0000000..9ab5595 --- /dev/null +++ b/Redesign-Evolution/Core/ExpeditionDefinitions.cs @@ -0,0 +1,62 @@ +namespace Redesign.Core; + +public enum RelicKind { ExtraChill, BeamFork, BoltFork, ShellEcho, LongBurn, WarChest, ReinforcedGate } +public sealed record RelicDefinition(string Id, string Name, string Description, RelicKind Kind, int Power, double Radius = 0); +public sealed record ExpeditionDefinition(int[] RewardWaves, RelicDefinition[] Relics, string ChallengeEnemyId, + int ChallengeBaseCount, int ChallengeBonusGold, int ChallengeGrowthPerStage = 1) +{ + public ExpeditionDefinition Copy() => this with { RewardWaves = [.. RewardWaves], Relics = [.. Relics] }; +} +public sealed record HealingDefinition(int Amount, double Radius, int IntervalTicks, int WindupTicks); +public sealed record BossDefinition(string SummonEnemyId, int SummonsPerPulse, int MaxSummons, + int IntervalTicks, int WindupTicks, int GuardPercent, int EnrageHealthPercent, int EnrageSpeedPercent); + +internal static class ExpeditionContent +{ + public static void Validate(GameDefinition game) + { + static void Require(bool ok, string message) { if (!ok) throw new ArgumentException("Invalid expedition content: " + message); } + foreach (var enemy in game.Enemies) + { + Require(enemy.SlowResistancePercent is >= 0 and <= 80, $"'{enemy.Id}' slow resistance"); + Require(enemy.Healing is null || enemy.Boss is null, $"'{enemy.Id}' cannot combine healing and boss abilities"); + if (enemy.Healing is { } heal) + Require(heal.Amount is > 0 and <= 10000 && double.IsFinite(heal.Radius) && heal.Radius > 0 && + heal.IntervalTicks is >= 30 and <= 36000 && heal.WindupTicks > 0 && heal.WindupTicks < heal.IntervalTicks, + $"'{enemy.Id}' healing values"); + if (enemy.Boss is { } boss) + { + var summon = game.Enemies.FirstOrDefault(e => e.Id == boss.SummonEnemyId); + Require(summon is not null && summon.Boss is null && summon.Healing is null && summon.Bounty == 0, + $"'{enemy.Id}' summons must reference a non-support enemy with zero bounty"); + Require(boss.SummonsPerPulse is >= 1 and <= 8 && boss.MaxSummons >= boss.SummonsPerPulse && boss.MaxSummons <= 64 && + boss.IntervalTicks is >= 120 and <= 36000 && boss.WindupTicks >= 30 && boss.WindupTicks < boss.IntervalTicks / 2 && + boss.GuardPercent is >= 0 and <= 80 && boss.EnrageHealthPercent is > 0 and < 100 && boss.EnrageSpeedPercent is >= 0 and <= 100, + $"'{enemy.Id}' boss values"); + } + } + if (game.Expedition is not { } expedition) return; + Require(expedition.RewardWaves is { Length: > 0 and <= 8 } && expedition.Relics is { Length: >= 3 and <= 32 }, "reward waves/relic catalogs"); + if (expedition.RewardWaves is null || expedition.Relics is null) return; + Require(expedition.RewardWaves.All(w => w > 0 && w < game.Waves.Length) && + expedition.RewardWaves.SequenceEqual(expedition.RewardWaves.Distinct().Order()), "reward waves must be ordered, unique and before the final wave"); + Require(expedition.Relics.Length >= expedition.RewardWaves.Length + 2, "not enough distinct relics for three offers at every reward"); + var ids = new HashSet(StringComparer.Ordinal); + foreach (var relic in expedition.Relics) + { + Require(relic is not null, "null relic"); if (relic is null) return; + Require(!string.IsNullOrWhiteSpace(relic.Id) && ids.Add(relic.Id) && !string.IsNullOrWhiteSpace(relic.Name) && + !string.IsNullOrWhiteSpace(relic.Description) && Enum.IsDefined(relic.Kind) && relic.Power is > 0 and <= 1000 && + double.IsFinite(relic.Radius) && relic.Radius >= 0 && relic.Radius <= 512, $"relic '{relic.Id}' identity/values"); + if (relic.Kind is RelicKind.BeamFork or RelicKind.BoltFork) + Require(relic.Power <= 100 && relic.Radius > 0, $"relic '{relic.Id}' fork values"); + if (relic.Kind == RelicKind.ExtraChill) + Require(relic.Power <= 3 && (game.Combat?.Statuses.Any(s => s.Id == "chill") ?? false), $"relic '{relic.Id}' requires chill"); + if (relic.Kind == RelicKind.LongBurn) + Require(game.Combat?.Reactions.Any(r => r.Effect == ReactionEffect.BurningGround) ?? false, $"relic '{relic.Id}' requires burning ground"); + } + Require(game.Enemies.Any(e => e.Id == expedition.ChallengeEnemyId && e.Bounty == 0 && e.Boss is null && e.Healing is null) && + expedition.ChallengeBaseCount is > 0 and <= 20 && expedition.ChallengeBonusGold is > 0 and <= 1000 && + expedition.ChallengeGrowthPerStage is >= 0 and <= 8, "challenge enemy/count/reward"); + } +} diff --git a/Redesign-Evolution/Core/Redesign.Core.csproj b/Redesign-Evolution/Core/Redesign.Core.csproj new file mode 100644 index 0000000..6b512ec --- /dev/null +++ b/Redesign-Evolution/Core/Redesign.Core.csproj @@ -0,0 +1 @@ + diff --git a/Redesign-Evolution/Core/Route.cs b/Redesign-Evolution/Core/Route.cs new file mode 100644 index 0000000..c7c86f6 --- /dev/null +++ b/Redesign-Evolution/Core/Route.cs @@ -0,0 +1,26 @@ +namespace Redesign.Core; + +/// Immutable authored route; rendering never calculates or mutates navigation. +public sealed class Route +{ + private readonly Point[] points; + private readonly double[] ends; + public double Length => ends[^1]; + + public Route(MapDefinition map) + { + points = map.Route.Select(map.Center).ToArray(); + ends = new double[points.Length]; + for (var i = 1; i < points.Length; i++) ends[i] = ends[i - 1] + (points[i] - points[i - 1]).Length; + } + + public Point At(double distance) + { + if (distance <= 0) return points[0]; + if (distance >= Length) return points[^1]; + var i = Array.BinarySearch(ends, distance); + if (i >= 0) return points[i]; + i = ~i; + return points[i - 1] + (points[i] - points[i - 1]) * ((distance - ends[i - 1]) / (ends[i] - ends[i - 1])); + } +} diff --git a/Redesign-Evolution/Core/Simulation.Effects.cs b/Redesign-Evolution/Core/Simulation.Effects.cs new file mode 100644 index 0000000..99e9bcb --- /dev/null +++ b/Redesign-Evolution/Core/Simulation.Effects.cs @@ -0,0 +1,150 @@ +using System.Collections.ObjectModel; + +namespace Redesign.Core; + +public sealed partial class Simulation +{ + private Dictionary statusDefinitions = null!; + private Dictionary reactionStatistics = null!; + private readonly List burningAreas = []; + private readonly List pendingImpacts = []; + private readonly List impactCandidates = [], reactionCandidates = [], areaCandidates = []; + public ReadOnlyCollection BurningAreas { get; private set; } = null!; + public ReadOnlyCollection PendingImpacts { get; private set; } = null!; + public ReadOnlyCollection Reactions { get; private set; } = null!; + public long ReactionDamage { get; private set; } + + private void InitializeEffects() + { + statusDefinitions = (definition.Combat?.Statuses ?? []).ToDictionary(s => s.Id, StringComparer.Ordinal); + var stats = (definition.Combat?.Reactions ?? []).Select(r => new ReactionStatistics(r)).ToArray(); + reactionStatistics = stats.ToDictionary(s => s.Definition.Id, StringComparer.Ordinal); + Reactions = Array.AsReadOnly(stats); + BurningAreas = burningAreas.AsReadOnly(); PendingImpacts = pendingImpacts.AsReadOnly(); + } + + private void Strike(EnemyState enemy, int amount, int source, TowerDefinition attack) + { + if (!enemy.Alive) return; + // Consume existing setup before this hit can apply new stacks. Lethal hits still produce the reaction. + List? triggered = null; + foreach (var stats in Reactions) + { + var reaction = stats.Definition; + if (reaction.Trigger != attack.DamageKind || + enemy.ReactionReady.GetValueOrDefault(reaction.Id) > Tick) continue; + var status = enemy.StatusSet.Find(reaction.StatusId); + if (status is null || status.Count < reaction.RequiredStacks) continue; + var providers = enemy.StatusSet.Consume(status, reaction.RequiredStacks); + enemy.ReactionReady[reaction.Id] = Tick + reaction.CooldownTicks; + stats.Triggers++; towerHistory[source].ReactionsTriggered++; + foreach (var provider in providers) + if (towerHistory.TryGetValue(provider, out var setup)) setup.ReactionsPrepared++; + (triggered ??= []).Add(stats); + } + if (attack.OnHit is { } application) + enemy.StatusSet.Apply(statusDefinitions[application.StatusId], application.Stacks, source, Tick); + DealDamage(enemy, amount, source, attack.DamageKind, attack.Attack); + if (triggered is null) return; + foreach (var stats in triggered) + { + var reaction = stats.Definition; + Emit(EventKind.Reaction, enemy.Position, source, (int)Math.Min(reaction.Radius, int.MaxValue), + damageKind: reaction.DamageKind, effectId: reaction.Id); + if (reaction.Effect == ReactionEffect.Burst) + { + QueryEnemies(enemy.Position, reaction.Radius, reactionCandidates); + reactionCandidates.Sort(static (a, b) => a.Id.CompareTo(b.Id)); + foreach (var victim in reactionCandidates) + DealDamage(victim, reaction.Damage, source, reaction.DamageKind, reaction: stats); + } + else + { + // Recycle the oldest area of this reaction at the configured cap. + if (burningAreas.Count(a => a.Definition.Id == reaction.Id) >= reaction.MaxAreas) + burningAreas.RemoveAt(burningAreas.FindIndex(a => a.Definition.Id == reaction.Id)); + burningAreas.Add(new(nextId++, enemy.Position, source, reaction, Tick)); + } + } + } + + private bool IsPrimed(EnemyState enemy, DamageKind kind) + { + foreach (var stats in Reactions) + { + var reaction = stats.Definition; + if (reaction.Trigger == kind && enemy.ReactionReady.GetValueOrDefault(reaction.Id) <= Tick && + enemy.StatusSet.Find(reaction.StatusId) is { } status && status.Count >= reaction.RequiredStacks) return true; + } + return false; + } + + private void ResolvePersistentEffects() + { + foreach (var impact in pendingImpacts) + { + if (impact.ResolveAt > Tick) continue; + QueryEnemies(impact.Position, impact.Definition.Radius, impactCandidates); + impactCandidates.Sort(static (a, b) => a.Id.CompareTo(b.Id)); + foreach (var enemy in impactCandidates) + DealDamage(enemy, impact.Definition.Damage, impact.SourceId, impact.Definition.DamageKind, AttackKind.Shell); + Emit(EventKind.Blast, impact.Position, impact.SourceId, (int)Math.Min(impact.Definition.Radius, int.MaxValue), + AttackKind.Shell, damageKind: impact.Definition.DamageKind, effectId: "echo"); + } + pendingImpacts.RemoveAll(i => i.ResolveAt <= Tick); + burningAreas.RemoveAll(a => a.ExpiresAt <= Tick); + foreach (var area in burningAreas) + { + if (area.NextPulseTick > Tick) continue; + area.NextPulseTick += area.Definition.IntervalTicks; + QueryEnemies(area.Position, area.Definition.Radius, areaCandidates); + areaCandidates.Sort(static (a, b) => a.Id.CompareTo(b.Id)); + foreach (var enemy in areaCandidates) + { + // Per-enemy cadence also prevents staggered, overlapping fields from multiplying damage. + if (enemy.AreaDamageReady.GetValueOrDefault(area.Definition.Id) > Tick) continue; + enemy.AreaDamageReady[area.Definition.Id] = Tick + area.Definition.IntervalTicks; + DealDamage(enemy, area.Definition.Damage, area.SourceId, area.Definition.DamageKind, + reaction: reactionStatistics[area.Definition.Id]); + } + } + // Reaction damage and echoes use DealDamage directly: no new status, reaction or delayed effect. + } + + private static void WriteEnemyEffects(BinaryWriter writer, EnemyState enemy) + { + writer.Write(enemy.NextAbilityTick); writer.Write(enemy.WindingUp); writer.Write(enemy.Enraged); writer.Write(enemy.SummonsCreated); + writer.Write(enemy.Statuses.Count); + foreach (var status in enemy.Statuses.OrderBy(s => s.Definition.Id, StringComparer.Ordinal)) + { + writer.Write(status.Definition.Id); writer.Write(status.Count); + foreach (var stack in status.Stacks) { writer.Write(stack.SourceId); writer.Write(stack.ExpiresAt); } + } + foreach (var cooldowns in new[] { enemy.ReactionReady, enemy.AreaDamageReady }) + { + writer.Write(cooldowns.Count); + foreach (var entry in cooldowns.OrderBy(e => e.Key, StringComparer.Ordinal)) + { writer.Write(entry.Key); writer.Write(entry.Value); } + } + } + private void WriteEffects(BinaryWriter writer) + { + writer.Write(ReactionDamage); writer.Write(Reactions.Count); + foreach (var stats in Reactions) + { writer.Write(stats.Definition.Id); writer.Write(stats.Triggers); writer.Write(stats.Damage); } + writer.Write(burningAreas.Count); + foreach (var area in burningAreas) + { + writer.Write(area.Id); writer.Write(area.Definition.Id); writer.Write(area.SourceId); + writer.Write(area.Position.X); writer.Write(area.Position.Y); + writer.Write(area.ExpiresAt); writer.Write(area.NextPulseTick); + } + writer.Write(pendingImpacts.Count); + foreach (var impact in pendingImpacts) + { + writer.Write(impact.Id); writer.Write(impact.SourceId); writer.Write(impact.Position.X); writer.Write(impact.Position.Y); + writer.Write(impact.CreatedAt); writer.Write(impact.ResolveAt); + writer.Write(impact.Definition.Damage); writer.Write(impact.Definition.Radius); writer.Write((int)impact.Definition.DamageKind); + } + } +} diff --git a/Redesign-Evolution/Core/Simulation.Enemies.cs b/Redesign-Evolution/Core/Simulation.Enemies.cs new file mode 100644 index 0000000..d29bdd1 --- /dev/null +++ b/Redesign-Evolution/Core/Simulation.Enemies.cs @@ -0,0 +1,66 @@ +namespace Redesign.Core; + +public sealed partial class Simulation +{ + private EnemyDefinition WaveEnemy(EnemyDefinition enemy) + { + var percent = definition.Waves[WaveNumber - 1].HealthPercent; + return percent == 100 ? enemy : enemy with { Health = Math.Max(1, (int)Math.Min(int.MaxValue, (long)enemy.Health * percent / 100)) }; + } + private readonly List healingCandidates = []; + private readonly HashSet healedThisTick = []; + + private void PrepareAbility(EnemyState enemy) + { + var windup = enemy.Definition.Healing?.WindupTicks ?? enemy.Definition.Boss?.WindupTicks ?? 0; + enemy.WindingUp = windup > 0 && Tick >= enemy.NextAbilityTick - windup; + if (enemy.Definition.Boss is not { } boss) return; + if (!enemy.Enraged && (long)enemy.Health * 100 <= (long)enemy.Definition.Health * boss.EnrageHealthPercent) + { + enemy.Enraged = true; + // The phase transition never skips the advertised warning window. + enemy.NextAbilityTick = Math.Min(enemy.NextAbilityTick, Tick + boss.WindupTicks + 1); + Emit(EventKind.BossEnraged, enemy.Position, enemy.Id); + } + enemy.WindingUp = enemy.SummonsCreated < boss.MaxSummons && Tick >= enemy.NextAbilityTick - boss.WindupTicks; + } + + private void ResolveEnemyAbilities() + { + healedThisTick.Clear(); + // Heal before adding summons so grid and reference scans see the same population. + foreach (var healer in enemies) + { + if (!healer.Alive || healer.Definition.Healing is not { } heal || Tick < healer.NextAbilityTick) continue; + healer.NextAbilityTick = Tick + heal.IntervalTicks; healer.WindingUp = false; + QueryEnemies(healer.Position, heal.Radius, healingCandidates); + healingCandidates.Sort(static (a, b) => a.Id.CompareTo(b.Id)); + foreach (var target in healingCandidates) + { + // Cannot resurrect or heal itself/other healers. Simultaneous pulses do not multiply healing. + if (target.Definition.Healing is not null || !healedThisTick.Add(target.Id)) continue; + var restored = Math.Min(heal.Amount, target.Definition.Health - target.Health); + if (restored <= 0) continue; + target.Health += restored; + Emit(EventKind.Healed, target.Position, healer.Id, restored); + } + } + var countBeforeSummons = enemies.Count; + for (var i = 0; i < countBeforeSummons; i++) + { + var leader = enemies[i]; + if (!leader.Alive || leader.Definition.Boss is not { } boss || leader.SummonsCreated >= boss.MaxSummons || Tick < leader.NextAbilityTick) continue; + var count = Math.Min(boss.SummonsPerPulse, boss.MaxSummons - leader.SummonsCreated); + for (var j = 0; j < count; j++) + { + var progress = Math.Max(0, leader.Progress - 24 * (j + 1)); + var minion = new EnemyState(nextId++, Route.At(progress), WaveEnemy(enemyDefinitions[boss.SummonEnemyId]), Tick) { Progress = progress }; + enemies.Add(minion); enemyById.Add(minion.Id, minion); + } + leader.SummonsCreated += count; + leader.NextAbilityTick = Tick + (leader.Enraged ? boss.IntervalTicks / 2 : boss.IntervalTicks); + leader.WindingUp = false; + Emit(EventKind.Rally, leader.Position, leader.Id, count); + } + } +} diff --git a/Redesign-Evolution/Core/Simulation.Expedition.cs b/Redesign-Evolution/Core/Simulation.Expedition.cs new file mode 100644 index 0000000..f49fa4d --- /dev/null +++ b/Redesign-Evolution/Core/Simulation.Expedition.cs @@ -0,0 +1,123 @@ +using System.Collections.ObjectModel; + +namespace Redesign.Core; + +public sealed partial class Simulation +{ + private readonly List rewardOffers = [], relics = []; + private readonly List waveReports = []; + private int waveKillsAtStart, waveLeaksAtStart; + private long waveIncomeAtStart; + public ReadOnlyCollection RewardOffers { get; private set; } = null!; + public ReadOnlyCollection Relics { get; private set; } = null!; + public ReadOnlyCollection WaveReports { get; private set; } = null!; + public int MaxLives { get; private set; } + public bool ChallengeEnabled { get; private set; } + public int ChallengeCount => ChallengeCountAt(Phase == RunPhase.Planning ? WaveNumber + 1 : WaveNumber); + private int ChallengeCountAt(int wave) => definition.Expedition is { } d ? d.ChallengeBaseCount + wave / 3 * d.ChallengeGrowthPerStage : 0; + public int ChallengeReward => definition.Expedition is { } d ? d.ChallengeBonusGold + 2 * (Phase == RunPhase.Planning ? WaveNumber + 1 : WaveNumber) : 0; + public TowerDefinition? PreviewUpgrade(string branchId) => branches.TryGetValue(branchId, out var branch) ? ApplyRelics(branch.Upgrade) : null; + + private void InitializeExpedition() + { + RewardOffers = rewardOffers.AsReadOnly(); Relics = relics.AsReadOnly(); WaveReports = waveReports.AsReadOnly(); + MaxLives = definition.StartingLives; + } + + private void CompleteWaveRewards() + { + var flawless = Leaks == waveLeaksAtStart; + var clearGold = definition.Waves[WaveNumber - 1].ClearGold + (ChallengeEnabled && flawless ? ChallengeReward : 0); + Gold += clearGold; GoldEarned += clearGold; + waveReports.Add(new(WaveNumber, Kills - waveKillsAtStart, Leaks - waveLeaksAtStart, Tick - waveStartTick + 1, + GoldEarned - waveIncomeAtStart, clearGold, ChallengeEnabled, ChallengeEnabled && flawless)); + ChallengeEnabled = false; + if (definition.Expedition is not { } expedition || !expedition.RewardWaves.Contains(WaveNumber)) return; + var pool = expedition.Relics.Where(r => !relics.Any(owned => owned.Id == r.Id)).ToList(); + // Specified SplitMix64 shuffle. Offers depend on seed, earned checkpoint and prior choices, never rendering. + var state = Seed ^ ((ulong)WaveNumber * 0x9E3779B97F4A7C15UL); + ulong Next() + { + state = unchecked(state + 0x9E3779B97F4A7C15UL); + var z = state; z = (z ^ (z >> 30)) * 0xBF58476D1CE4E5B9UL; + z = (z ^ (z >> 27)) * 0x94D049BB133111EBUL; return z ^ (z >> 31); + } + for (var i = pool.Count - 1; i > 0; i--) { var j = (int)(Next() % (ulong)(i + 1)); (pool[i], pool[j]) = (pool[j], pool[i]); } + // Favor one payoff for the current build, plus an economy/recovery alternative when available. + var relevant = pool.FirstOrDefault(IsRelevantRelic); + if (relevant is not null) { rewardOffers.Add(relevant); pool.Remove(relevant); } + var recovery = pool.FirstOrDefault(r => r.Kind is RelicKind.ReinforcedGate or RelicKind.WarChest); + if (recovery is not null) { rewardOffers.Add(recovery); pool.Remove(recovery); } + rewardOffers.AddRange(pool.Take(3 - rewardOffers.Count)); + } + + private bool IsRelevantRelic(RelicDefinition relic) => relic.Kind switch + { + RelicKind.ExtraChill => towers.Any(t => t.Definition.OnHit?.StatusId == "chill"), + RelicKind.LongBurn => towers.Any(t => t.Definition.DamageKind == DamageKind.Fire), + RelicKind.BoltFork => towers.Any(t => t.Definition.Attack == AttackKind.Bolt), + RelicKind.BeamFork => towers.Any(t => t.Definition.Attack == AttackKind.Beam), + RelicKind.ShellEcho => towers.Any(t => t.Definition.Attack == AttackKind.Shell), + _ => false + }; + + private CommandResult ClaimRelic(string id) + { + if (Phase != RunPhase.Planning) return new(false, "Relics are chosen between waves."); + var chosen = rewardOffers.FirstOrDefault(r => r.Id == id); + if (chosen is null) return new(false, "Choose one of the earned relic offers."); + relics.Add(chosen); rewardOffers.Clear(); + if (chosen.Kind == RelicKind.WarChest) { Gold += chosen.Power; GoldEarned += chosen.Power; } + if (chosen.Kind == RelicKind.ReinforcedGate) + { MaxLives = (int)Math.Min(int.MaxValue, (long)MaxLives + Math.Max(1, chosen.Power / 2)); Lives = (int)Math.Min(MaxLives, (long)Lives + chosen.Power); } + foreach (var tower in towers) + tower.Definition = ApplyRelics(tower.BranchId is { } branch ? branches[branch].Upgrade : towerDefinitions[tower.FamilyId]); + foreach (var stats in Reactions) + { + var original = definition.Combat!.Reactions.First(r => r.Id == stats.Definition.Id); + stats.Definition = original; + foreach (var relic in relics) + if (relic.Kind == RelicKind.LongBurn && original.Effect == ReactionEffect.BurningGround) + stats.Definition = stats.Definition with { Radius = stats.Definition.Radius + relic.Radius, DurationTicks = stats.Definition.DurationTicks + relic.Power }; + } + Emit(EventKind.RelicChosen, Route.At(Route.Length), effectId: chosen.Id); + return new(true, $"{chosen.Name} claimed. {chosen.Description}"); + } + + private TowerDefinition ApplyRelics(TowerDefinition spec) + { + foreach (var relic in relics) + { + if (relic.Kind == RelicKind.ExtraChill && spec.OnHit is { StatusId: "chill" } chill) + spec = spec with { OnHit = chill with { Stacks = Math.Min(statusDefinitions["chill"].MaxStacks, chill.Stacks + relic.Power) } }; + if (relic.Kind == RelicKind.BeamFork && spec.Attack == AttackKind.Beam || relic.Kind == RelicKind.BoltFork && spec.Attack == AttackKind.Bolt) + spec = spec with { ForkRadius = Math.Max(spec.ForkRadius, relic.Radius), ForkDamagePercent = relic.Power }; + if (relic.Kind == RelicKind.ShellEcho && spec.Attack == AttackKind.Shell) + spec = spec with { Echo = new(spec.Echo?.DelayTicks ?? 30, + (int)Math.Min(int.MaxValue, (long)(spec.Echo?.Damage ?? 0) + relic.Power), Math.Max(spec.Echo?.Radius ?? 0, relic.Radius)) }; + } + return spec; + } + + private readonly List forkCandidates = []; + private void ForkAttack(int primaryId, Point center, int source, TowerDefinition attack) + { + if (attack.ForkRadius <= 0) return; + QueryEnemies(center, attack.ForkRadius, forkCandidates); + var target = forkCandidates.Where(e => e.Id != primaryId).MinBy(e => ((e.Position - center).LengthSquared, e.Id)); + if (target is null) return; + Emit(EventKind.Fired, center, source, attack: AttackKind.Beam, destination: target.Position, damageKind: attack.DamageKind, effectId: "fork"); + Strike(target, Math.Max(1, (int)((long)attack.Damage * attack.ForkDamagePercent / 100)), source, attack); + // A fork calls Strike, never ForkAttack: at most one secondary target per ordinary attack. + } + + private void WriteExpedition(BinaryWriter writer) + { + writer.Write(MaxLives); writer.Write(ChallengeEnabled); writer.Write(waveKillsAtStart); writer.Write(waveLeaksAtStart); writer.Write(waveIncomeAtStart); + writer.Write(relics.Count); foreach (var r in relics) writer.Write(r.Id); + writer.Write(rewardOffers.Count); foreach (var r in rewardOffers) writer.Write(r.Id); + writer.Write(waveReports.Count); + foreach (var w in waveReports) + { writer.Write(w.Wave); writer.Write(w.Kills); writer.Write(w.Leaks); writer.Write(w.DurationTicks); writer.Write(w.Income); writer.Write(w.ClearGold); writer.Write(w.Challenged); writer.Write(w.ChallengeWon); } + } +} diff --git a/Redesign-Evolution/Core/Simulation.cs b/Redesign-Evolution/Core/Simulation.cs new file mode 100644 index 0000000..3d795d5 --- /dev/null +++ b/Redesign-Evolution/Core/Simulation.cs @@ -0,0 +1,317 @@ +using System.Collections.ObjectModel; +using System.Security.Cryptography; +using System.Text; + +namespace Redesign.Core; + +/// Authoritative single-threaded simulation. All gameplay timers are integer ticks. +public sealed partial class Simulation +{ + public const int TicksPerSecond = 60; + private readonly List towers = []; + private readonly List enemies = []; + private readonly List projectiles = []; + private readonly Dictionary towerHistory = []; + private readonly Dictionary enemyById = []; + private readonly List events = []; + private readonly GameDefinition definition; + private readonly EnemySpatialIndex spatial; + private readonly bool referenceQueries; + private readonly List candidates = []; + private readonly Dictionary towerDefinitions; + private readonly Dictionary enemyDefinitions; + private readonly Dictionary branches; + private int nextId = 1; + private long waveStartTick; + private int nextSpawn; + private ScheduledSpawn[] spawnPlan = []; + private readonly record struct ScheduledSpawn(long Offset, int Group, int Ordinal, EnemyDefinition Enemy); + + public GameDefinition Definition => definition.Copy(); + public Route Route { get; } + public ReadOnlyCollection Towers { get; } + public ReadOnlyCollection Enemies { get; } + public ReadOnlyCollection Projectiles { get; } + public RunPhase Phase { get; private set; } = RunPhase.Planning; + public bool IsPaused { get; private set; } + public long Tick { get; private set; } + public ulong Seed { get; } + public long Gold { get; private set; } + public int Lives { get; private set; } + public int WaveNumber { get; private set; } + public int PendingSpawns { get; private set; } + public int Kills { get; private set; } + public int Leaks { get; private set; } + public long DamageDealt { get; private set; } + public long GoldEarned { get; private set; } + public long GoldSpent { get; private set; } + + public Simulation(GameDefinition definition, ulong seed = 1) : this(definition, seed, false) { } + + // Reference scans are accessible only to tests and the profiling executable. + internal Simulation(GameDefinition definition, ulong seed, bool referenceQueries) + { + definition.Validate(); + this.definition = definition.Copy(); + towerDefinitions = this.definition.Towers.ToDictionary(t => t.Id, StringComparer.Ordinal); + enemyDefinitions = this.definition.Enemies.ToDictionary(e => e.Id, StringComparer.Ordinal); + branches = (this.definition.Combat?.Branches ?? []).ToDictionary(b => b.Upgrade.Id, StringComparer.Ordinal); + InitializeEffects(); + InitializeExpedition(); + Seed = seed; + this.referenceQueries = referenceQueries; + spatial = new EnemySpatialIndex(this.definition.Map); + Route = new Route(this.definition.Map); + Gold = definition.StartingGold; Lives = definition.StartingLives; + Towers = towers.AsReadOnly(); Enemies = enemies.AsReadOnly(); Projectiles = projectiles.AsReadOnly(); + } + + public CommandResult Apply(GameCommand command) + { + if (Phase is RunPhase.Victory or RunPhase.Defeat) return new(false, "The run has ended. Start a new defense."); + switch (command) + { + case PlaceTower placement: + if (placement.Foundation < 0 || placement.Foundation >= definition.Map.Foundations.Length) + return new(false, "Choose a marked foundation."); + if (towers.Any(t => t.Foundation == placement.Foundation)) return new(false, "This foundation is occupied."); + if (!towerDefinitions.TryGetValue(placement.TowerId ?? definition.Towers[0].Id, out var spec)) + return new(false, "Unknown tower type."); + if (Gold < spec.Cost) return new(false, "Not enough gold."); + var tower = new TowerState(nextId++, placement.Foundation, definition.Map.Center(definition.Map.Foundations[placement.Foundation]), ApplyRelics(spec)); + Gold -= tower.Cost; GoldSpent += tower.Cost; + towers.Add(tower); towerHistory.Add(tower.Id, tower); + Emit(EventKind.Built, tower.Position, tower.Id, tower.Cost); + return new(true, $"{(string.IsNullOrWhiteSpace(spec.Name) ? spec.Id : spec.Name)} ready.", tower.Id); + case SellTower sell: + if (!towerHistory.TryGetValue(sell.TowerId, out var sold) || sold.Sold) return new(false, "Tower no longer available."); + sold.Sold = true; towers.Remove(sold); + var refund = sold.SellValue; + Gold += refund; Emit(EventKind.Sold, sold.Position, sold.Id, refund); + return new(true, $"Recovered {refund} gold."); + case SetTargetPriority targeting: + if (!towerHistory.TryGetValue(targeting.TowerId, out var selected) || selected.Sold || + !Enum.IsDefined(targeting.Priority)) return new(false, "Choose an active tower and valid priority."); + selected.Priority = targeting.Priority; + return new(true, $"Target priority: {targeting.Priority}."); + case UpgradeTower upgrade: + if (!towerHistory.TryGetValue(upgrade.TowerId, out var evolving) || evolving.Sold) + return new(false, "Choose an active tower."); + if (evolving.BranchId is not null) return new(false, "This tower has already chosen its path."); + if (string.IsNullOrWhiteSpace(upgrade.BranchId) || !branches.TryGetValue(upgrade.BranchId, out var branch) || + branch.TowerId != evolving.FamilyId) return new(false, "That path does not belong to this tower."); + if (Gold < branch.Cost) return new(false, "Not enough gold for this path."); + Gold -= branch.Cost; GoldSpent += branch.Cost; evolving.Cost += branch.Cost; + evolving.BranchId = branch.Upgrade.Id; evolving.Definition = ApplyRelics(branch.Upgrade); + // Preserve cooldown, target priority, statistics and in-flight attack snapshots. + Emit(EventKind.Upgraded, evolving.Position, evolving.Id, branch.Cost, effectId: evolving.BranchId); + return new(true, $"{branch.Upgrade.Name} ready.", evolving.Id); + case StartWave: + if (Phase != RunPhase.Planning || WaveNumber >= definition.Waves.Length) return new(false, "A wave is already active."); + if (rewardOffers.Count > 0) return new(false, "Choose your earned relic before the next wave."); + waveKillsAtStart = Kills; waveLeaksAtStart = Leaks; waveIncomeAtStart = GoldEarned; + WaveNumber++; + var wave = definition.Waves[WaveNumber - 1]; + var groups = wave.Groups.AsEnumerable(); + if (ChallengeEnabled && definition.Expedition is { } expedition) + groups = groups.Append(new(expedition.ChallengeEnemyId, ChallengeCountAt(WaveNumber), 45, 90)); + spawnPlan = groups.SelectMany((g, group) => + { + var enemy = WaveEnemy(enemyDefinitions[g.EnemyId]); + return Enumerable.Range(0, g.Count).Select(ordinal => new ScheduledSpawn(g.DelayTicks + (long)ordinal * g.IntervalTicks, group, ordinal, enemy)); + }) + .OrderBy(s => s.Offset).ThenBy(s => s.Group).ThenBy(s => s.Ordinal).ToArray(); + PendingSpawns = spawnPlan.Length; nextSpawn = 0; + waveStartTick = Tick + 1; Phase = RunPhase.Wave; IsPaused = false; + Emit(EventKind.WaveStarted, Route.At(0)); + return new(true, $"Wave {WaveNumber} approaching."); + case Pause pause: + if (Phase != RunPhase.Wave) return new(false, "Pause is available during a wave."); + IsPaused = pause.Paused; + return new(true, IsPaused ? "Tactical pause — you can still build." : "Defense resumed."); + case ChooseRelic choice: return ClaimRelic(choice.RelicId); + case SetChallenge challenge: + if (definition.Expedition is null || Phase != RunPhase.Planning || rewardOffers.Count > 0) + return new(false, "Choose reinforcements during planning, after your relic."); + ChallengeEnabled = challenge.Enabled; + return new(true, ChallengeEnabled ? $"Overrun accepted: {ChallengeCount} extra raiders; +{ChallengeReward} gold only with zero breaches." : "Standard encounter selected."); + default: return new(false, "Unknown command."); + } + } + + public void Step() + { + if (Phase != RunPhase.Wave || IsPaused) return; + Tick++; + while (PendingSpawns > 0 && Tick >= waveStartTick + spawnPlan[nextSpawn].Offset) + { + var enemy = new EnemyState(nextId++, Route.At(0), spawnPlan[nextSpawn++].Enemy, Tick); + enemies.Add(enemy); enemyById.Add(enemy.Id, enemy); + PendingSpawns--; + } + foreach (var enemy in enemies) + { + PrepareAbility(enemy); + enemy.StatusSet.Expire(Tick); + enemy.PreviousPosition = enemy.Position; + var speed = enemy.Definition.Speed * (enemy.Enraged ? 1 + (enemy.Definition.Boss?.EnrageSpeedPercent ?? 0) / 100d : 1); + enemy.Progress = Math.Min(Route.Length, enemy.Progress + speed * (100 - enemy.SlowPercent) / (100d * TicksPerSecond)); + enemy.Position = Route.At(enemy.Progress); + } + if (!referenceQueries) spatial.Rebuild(enemies); + foreach (var enemy in enemies) enemy.Protectors.Clear(); + foreach (var escort in enemies) + { + if (escort.Definition.ShieldRadius <= 0) continue; + QueryEnemies(escort.Position, escort.Definition.ShieldRadius); + foreach (var ally in candidates) + if (ally.Definition.ShieldRadius == 0) ally.Protectors.Add(escort); + } + foreach (var tower in towers) + { + var attack = tower.Definition; + EnemyState? target = null; + QueryEnemies(tower.Position, attack.Range); + foreach (var enemy in candidates) + { + if (target is null || Preferred(enemy, target, tower.Priority, attack.DamageKind)) target = enemy; + } + tower.TargetId = target?.Id ?? 0; + if (target is null || Tick < tower.NextFireTick) continue; + Emit(EventKind.Fired, tower.Position, tower.Id, attack: attack.Attack, destination: target.Position, damageKind: attack.DamageKind); + if (attack.Attack == AttackKind.Beam) + { + Strike(target, attack.Damage, tower.Id, attack); + ForkAttack(target.Id, target.Position, tower.Id, attack); + } + else projectiles.Add(new ProjectileState(nextId++, tower.Id, target.Id, tower.Position, target.Position, attack)); + tower.NextFireTick = Tick + attack.CooldownTicks; + } + foreach (var projectile in projectiles) + { + projectile.PreviousPosition = projectile.Position; + var attack = projectile.Definition; + enemyById.TryGetValue(projectile.TargetId, out var target); + if (target is { Alive: true }) projectile.AimPosition = target.Position; + else if (attack.Attack != AttackKind.Shell) { projectile.Active = false; continue; } + // A shell still detonates at its last tracked position if another tower kills its target. + var difference = projectile.AimPosition - projectile.Position; + var travel = attack.ProjectileSpeed / TicksPerSecond; + if (difference.LengthSquared <= travel * travel) + { + projectile.Position = projectile.AimPosition; projectile.Active = false; + if (target is { Alive: true }) Strike(target, attack.Damage, projectile.SourceId, attack); + ForkAttack(projectile.TargetId, projectile.Position, projectile.SourceId, attack); + if (attack.SplashRadius > 0) + { + Emit(EventKind.Blast, projectile.Position, projectile.SourceId, + (int)Math.Min(attack.SplashRadius, int.MaxValue), attack.Attack, damageKind: attack.DamageKind); + QueryEnemies(projectile.Position, attack.SplashRadius, impactCandidates); + impactCandidates.Sort(static (a, b) => a.Id.CompareTo(b.Id)); + foreach (var secondary in impactCandidates) + if (secondary.Id != projectile.TargetId) + Strike(secondary, Math.Max(1, attack.Damage / 2), projectile.SourceId, attack); + } + if (attack.Echo is { } echo) + pendingImpacts.Add(new(nextId++, projectile.Position, projectile.SourceId, echo, Tick, Tick + echo.DelayTicks)); + } + else projectile.Position += difference * (travel / difference.Length); + } + ResolvePersistentEffects(); + ResolveEnemyAbilities(); + // Resolve deaths first: a killed enemy at the gate cannot also leak. + foreach (var enemy in enemies) + { + if (!enemy.Alive || enemy.Progress < Route.Length) continue; + enemy.Alive = false; Leaks++; + Lives = Math.Max(0, Lives - enemy.Definition.LeakDamage); + Emit(EventKind.Leaked, enemy.Position, enemy.Id, enemy.Definition.LeakDamage); + } + foreach (var enemy in enemies) if (!enemy.Alive) enemyById.Remove(enemy.Id); + enemies.RemoveAll(e => !e.Alive); projectiles.RemoveAll(p => !p.Active); + if (Lives == 0) + { + Phase = RunPhase.Defeat; IsPaused = false; + Emit(EventKind.Defeat, Route.At(Route.Length)); + } + else if (PendingSpawns == 0 && enemies.Count == 0) + { + projectiles.Clear(); burningAreas.Clear(); pendingImpacts.Clear(); + CompleteWaveRewards(); + Phase = WaveNumber == definition.Waves.Length ? RunPhase.Victory : RunPhase.Planning; + Emit(Phase == RunPhase.Victory ? EventKind.Victory : EventKind.WaveCleared, Route.At(Route.Length)); + } + } + + private void QueryEnemies(Point position, double radius, List? result = null) + { + result ??= candidates; + if (!referenceQueries) { spatial.Query(position, radius, result); return; } + result.Clear(); + foreach (var enemy in enemies) + if (enemy.Alive && (enemy.Position - position).LengthSquared <= radius * radius) + result.Add(enemy); + } + + private bool Preferred(EnemyState candidate, EnemyState current, TargetPriority priority, DamageKind kind) + { + var rank = priority switch + { + TargetPriority.Strongest => candidate.Health.CompareTo(current.Health), + TargetPriority.Support => candidate.IsSupport.CompareTo(current.IsSupport), + TargetPriority.Primed => IsPrimed(candidate, kind).CompareTo(IsPrimed(current, kind)), + _ => 0 + }; + return rank != 0 ? rank > 0 : candidate.Progress > current.Progress || + (candidate.Progress == current.Progress && candidate.Id < current.Id); + } + + private void DealDamage(EnemyState enemy, int amount, int towerId, DamageKind kind, + AttackKind attack = AttackKind.Bolt, ReactionStatistics? reaction = null) + { + if (!enemy.Alive) return; + var afterArmor = kind != DamageKind.Impact ? amount : Math.Max(1, amount - enemy.EffectiveArmor); + var afterShield = Math.Max(1, (int)((long)afterArmor * (100 - enemy.ShieldPercent) / 100)); + var damage = Math.Min(afterShield, enemy.Health); + enemy.Health -= damage; DamageDealt += damage; + var tower = towerHistory[towerId]; tower.DamageDealt += damage; + if (reaction is not null) { reaction.Damage += damage; tower.ReactionDamage += damage; ReactionDamage += damage; } + Emit(EventKind.Hit, enemy.Position, enemy.Id, damage, attack, damageKind: kind); + if (enemy.Health > 0) return; + enemy.Alive = false; Kills++; tower.Kills++; + Gold += enemy.Definition.Bounty; GoldEarned += enemy.Definition.Bounty; + Emit(EventKind.Killed, enemy.Position, enemy.Id, enemy.Definition.Bounty); + } + + private void Emit(EventKind kind, Point position, int id = 0, long amount = 0, + AttackKind attack = AttackKind.Bolt, Point? destination = null, + DamageKind damageKind = DamageKind.Impact, string? effectId = null) => + events.Add(new(Tick, kind, position, id, amount, attack, destination, damageKind, effectId)); + public GameEvent[] DrainEvents() { var result = events.ToArray(); events.Clear(); return result; } + + /// Gameplay-only digest: event consumption/rendering cannot change it. + public string Checksum() + { + using var stream = new MemoryStream(); + using (var writer = new BinaryWriter(stream, Encoding.UTF8, true)) + { + writer.Write(Seed); writer.Write(Tick); writer.Write((int)Phase); writer.Write(IsPaused); + writer.Write(Gold); writer.Write(Lives); writer.Write(WaveNumber); writer.Write(PendingSpawns); + writer.Write(nextId); writer.Write(waveStartTick); writer.Write(nextSpawn); writer.Write(Kills); writer.Write(Leaks); + writer.Write(DamageDealt); writer.Write(GoldEarned); writer.Write(GoldSpent); + writer.Write(towerHistory.Count); + foreach (var t in towerHistory.Values.OrderBy(t => t.Id)) + { writer.Write(t.Id); writer.Write(t.Definition.Id); writer.Write((int)t.Priority); writer.Write(t.Foundation); writer.Write(t.Sold); writer.Write(t.NextFireTick); writer.Write(t.TargetId); writer.Write(t.DamageDealt); writer.Write(t.Kills); + writer.Write(t.FamilyId); writer.Write(t.BranchId ?? ""); writer.Write(t.Cost); writer.Write(t.ReactionsTriggered); writer.Write(t.ReactionsPrepared); writer.Write(t.ReactionDamage); } + writer.Write(enemies.Count); + foreach (var e in enemies) + { writer.Write(e.Id); writer.Write(e.Definition.Id); writer.Write(e.Progress); writer.Write(e.Health); WriteEnemyEffects(writer, e); } + writer.Write(projectiles.Count); + foreach (var p in projectiles) + { writer.Write(p.Id); writer.Write(p.SourceId); writer.Write(p.TargetId); writer.Write(p.Position.X); writer.Write(p.Position.Y); writer.Write(p.AimPosition.X); writer.Write(p.AimPosition.Y); writer.Write(p.Definition.Id); } + WriteEffects(writer); + WriteExpedition(writer); + } + return Convert.ToHexString(SHA256.HashData(stream.ToArray())).ToLowerInvariant(); + } +} diff --git a/Redesign-Evolution/Core/SimulationClock.cs b/Redesign-Evolution/Core/SimulationClock.cs new file mode 100644 index 0000000..dc6cdfb --- /dev/null +++ b/Redesign-Evolution/Core/SimulationClock.cs @@ -0,0 +1,22 @@ +namespace Redesign.Core; + +/// Bounded work per rendered frame; carries debt instead of changing simulation dt. +public sealed class SimulationClock +{ + private double accumulatedTicks; + public double Interpolation => Math.Clamp(accumulatedTicks, 0, 1); + public int Advance(Simulation simulation, double elapsedSeconds, int speed) + { + if (!double.IsFinite(elapsedSeconds) || elapsedSeconds < 0) throw new ArgumentOutOfRangeException(nameof(elapsedSeconds)); + if (speed is not (1 or 2 or 4)) throw new ArgumentOutOfRangeException(nameof(speed)); + if (simulation.IsPaused || simulation.Phase != RunPhase.Wave) { accumulatedTicks = 0; return 0; } + accumulatedTicks += elapsedSeconds * Simulation.TicksPerSecond * speed; + var count = 0; + while (accumulatedTicks + 1e-9 >= 1 && count < 32 && simulation.Phase == RunPhase.Wave && !simulation.IsPaused) + { simulation.Step(); accumulatedTicks -= 1; count++; } + // Unused time belongs to the completed wave, not to a wave started by a later input. + if (simulation.Phase != RunPhase.Wave || simulation.IsPaused) accumulatedTicks = 0; + if (accumulatedTicks < 0) accumulatedTicks = 0; + return count; + } +} diff --git a/Redesign-Evolution/Core/State.cs b/Redesign-Evolution/Core/State.cs new file mode 100644 index 0000000..ec7d2b4 --- /dev/null +++ b/Redesign-Evolution/Core/State.cs @@ -0,0 +1,86 @@ +namespace Redesign.Core; + +public enum RunPhase { Planning, Wave, Victory, Defeat } +public enum EventKind { Built, Sold, Fired, Hit, Killed, Leaked, WaveStarted, WaveCleared, Victory, Defeat, Blast, Upgraded, Reaction, RelicChosen, Healed, Rally, BossEnraged } +public readonly record struct GameEvent(long Tick, EventKind Kind, Point Position, int EntityId = 0, + long Amount = 0, AttackKind Attack = AttackKind.Bolt, Point? Destination = null, + DamageKind DamageKind = DamageKind.Impact, string? EffectId = null); +public readonly record struct CommandResult(bool Success, string Message, int EntityId = 0); +public abstract record GameCommand; +public sealed record PlaceTower(int Foundation, string? TowerId = null) : GameCommand; +public sealed record SellTower(int TowerId) : GameCommand; +public sealed record SetTargetPriority(int TowerId, TargetPriority Priority) : GameCommand; +public sealed record UpgradeTower(int TowerId, string BranchId) : GameCommand; +public sealed record StartWave : GameCommand; +public sealed record Pause(bool Paused) : GameCommand; +public sealed record ChooseRelic(string RelicId) : GameCommand; +public sealed record SetChallenge(bool Enabled) : GameCommand; +public sealed record WaveReport(int Wave, int Kills, int Leaks, long DurationTicks, long Income, int ClearGold, bool Challenged, bool ChallengeWon); + +public sealed class TowerState(int id, int foundation, Point position, TowerDefinition definition) +{ + public int Id { get; } = id; + public int Foundation { get; } = foundation; + public Point Position { get; } = position; + public string FamilyId { get; } = definition.Id; + public string? BranchId { get; internal set; } + public TowerDefinition Definition { get; internal set; } = definition; + public long Cost { get; internal set; } = definition.Cost; + public long SellValue => Cost * 70 / 100; + public long DamageDealt { get; internal set; } + public int Kills { get; internal set; } + public int TargetId { get; internal set; } + public long NextFireTick { get; internal set; } + public bool Sold { get; internal set; } + public TargetPriority Priority { get; internal set; } + public long ReactionsTriggered { get; internal set; } + public long ReactionsPrepared { get; internal set; } + public long ReactionDamage { get; internal set; } +} + +public sealed class EnemyState(int id, Point position, EnemyDefinition definition, long spawnTick = 0) +{ + public EnemyDefinition Definition { get; } = definition; + public int Id { get; } = id; + public Point Position { get; internal set; } = position; + public Point PreviousPosition { get; internal set; } = position; + public double Progress { get; internal set; } + public int Health { get; internal set; } = definition.Health; + public bool Alive { get; internal set; } = true; + public long NextAbilityTick { get; internal set; } = spawnTick + (definition.Healing?.IntervalTicks ?? definition.Boss?.IntervalTicks ?? 0); + public bool WindingUp { get; internal set; } + public bool Enraged { get; internal set; } + public int SummonsCreated { get; internal set; } + public bool BossVulnerable => Definition.Boss is { } boss && (WindingUp || SummonsCreated >= boss.MaxSummons); + public bool IsSupport => Definition.ShieldRadius > 0 || Definition.Healing is not null; + internal StatusSet StatusSet { get; } = new(); + public IReadOnlyList Statuses => StatusSet; + internal Dictionary ReactionReady { get; } = new(StringComparer.Ordinal); + internal Dictionary AreaDamageReady { get; } = new(StringComparer.Ordinal); + public int SlowPercent => StatusSet.SlowPercent * (100 - Definition.SlowResistancePercent) / 100; + public int EffectiveArmor => BossVulnerable ? 0 : Math.Max(0, Definition.Armor - StatusSet.ArmorReduction); + internal List Protectors { get; } = []; + // Protection stops immediately when an escort dies; overlapping auras never stack. + public int ShieldPercent + { + get + { + var strongest = Definition.Boss is { } boss && !BossVulnerable ? boss.GuardPercent : 0; + foreach (var escort in Protectors) + if (escort.Alive) strongest = Math.Max(strongest, escort.Definition.ShieldPercent); + return strongest; + } + } +} + +public sealed class ProjectileState(int id, int sourceId, int targetId, Point position, Point aimPosition, TowerDefinition definition) +{ + public TowerDefinition Definition { get; } = definition; + public int Id { get; } = id; + public int SourceId { get; } = sourceId; + public int TargetId { get; } = targetId; + public Point Position { get; internal set; } = position; + public Point PreviousPosition { get; internal set; } = position; + public Point AimPosition { get; internal set; } = aimPosition; + public bool Active { get; internal set; } = true; +} diff --git a/Redesign-Evolution/Core/packages.Debug.lock.json b/Redesign-Evolution/Core/packages.Debug.lock.json new file mode 100644 index 0000000..e02fcb7 --- /dev/null +++ b/Redesign-Evolution/Core/packages.Debug.lock.json @@ -0,0 +1,7 @@ +{ + "version": 1, + "dependencies": { + "net8.0": {}, + "net8.0/win-x64": {} + } +} \ No newline at end of file diff --git a/Redesign-Evolution/Core/packages.ExportRelease.lock.json b/Redesign-Evolution/Core/packages.ExportRelease.lock.json new file mode 100644 index 0000000..e02fcb7 --- /dev/null +++ b/Redesign-Evolution/Core/packages.ExportRelease.lock.json @@ -0,0 +1,7 @@ +{ + "version": 1, + "dependencies": { + "net8.0": {}, + "net8.0/win-x64": {} + } +} \ No newline at end of file diff --git a/Redesign-Evolution/Directory.Build.props b/Redesign-Evolution/Directory.Build.props new file mode 100644 index 0000000..12aec5b --- /dev/null +++ b/Redesign-Evolution/Directory.Build.props @@ -0,0 +1,14 @@ + + + Debug + net8.0 + win-x64 + 12 + enable + enable + true + true + $(MSBuildProjectDirectory)/packages.$(Configuration).lock.json + true + + diff --git a/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs b/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs new file mode 100644 index 0000000..baabfdf --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs @@ -0,0 +1,101 @@ +using Godot; +using Redesign.Core; + +namespace Redesign.Game; + +public partial class ArenaCanvas +{ + private void TerrainEffects() + { + foreach (var area in Game.Run.BurningAreas) + { + var p = V(area.Position); var radius = (float)area.Definition.Radius; + var life = Math.Min(1f, (area.ExpiresAt - Game.Run.Tick) / 30f); + DrawCircle(p, radius, new Color("d77b42", .17f * life)); + DrawArc(p, radius, 0, Mathf.Tau, 32, new Color("f6b36f", .5f * life), 1); + for (var i = 0; i < 7; i++) + { + var ember = p + Vector2.FromAngle(i * 2.4f + area.Id) * radius * (.2f + i * .09f); + var height = 8 + (float)Math.Sin(visualTime * 9 + i + area.Id) * 3; + DrawColoredPolygon([ember + new Vector2(-4, 3), ember + new Vector2(0, -height), ember + new Vector2(5, 3)], new("efaa69", .8f * life)); + DrawLine(ember, ember + new Vector2(0, -height / 2), new("ffe4ae", life), 2); + } + } + foreach (var echo in Game.Run.PendingImpacts) + { + var p = V(echo.Position); var radius = (float)echo.Definition.Radius; + var remaining = (echo.ResolveAt - Game.Run.Tick) / (float)(echo.ResolveAt - echo.CreatedAt); + for (var i = 0; i < 8; i++) DrawArc(p, radius, i * Mathf.Tau / 8, (i + .6f) * Mathf.Tau / 8, 6, new("c7b2eb", .6f), 2); + DrawArc(p, 12, -Mathf.Pi / 2, -Mathf.Pi / 2 + Mathf.Tau * remaining, 24, new("e2d3ff"), 2); + DrawString(font, p + new Vector2(-18, -radius - 5), "ECHO", HorizontalAlignment.Left, -1, 11, new("e2d3ff")); + } + } + + private void EnemyStatuses(EnemyState enemy, Vector2 p) + { + if (enemy.Statuses.Count == 0) return; + var x = p.X - enemy.Statuses.Count * 12; + foreach (var status in enemy.Statuses) + { + var color = status.Definition.Id switch + { "chill" => new Color("b4e7ff"), "oil" => new("e4b4e9"), "fracture" => new("f1bb86"), _ => GameRoot.Mint }; + DrawRect(new(x - 2, p.Y - 58, 23, 15), new Color("14292e", .95f)); + DrawString(font, new(x, p.Y - 46), $"{status.Definition.Name[0]}{status.Count}", HorizontalAlignment.Left, -1, 12, color); + x += 24; + } + if (enemy.SlowPercent > 0) DrawArc(p, 19, 0, Mathf.Tau, 6, new("b4e7ff", .65f), 1); + } + + // Visual identities are independent of the data-driven combat rules. + private void BranchSilhouette(TowerState tower, Vector2 top, Vector2 dir, Vector2 side) + { + switch (tower.BranchId) + { + case "ballista": + DrawLine(top - side * 23 + dir * 4, top + side * 23 + dir * 4, new("d6c295"), 5); + DrawLine(top - side * 21 + dir * 4, top - dir * 7, GameRoot.Gold, 1); + DrawLine(top + side * 21 + dir * 4, top - dir * 7, GameRoot.Gold, 1); + DrawLine(top - dir * 10, top + dir * 30, new("f0ddaa"), 4); + break; + case "pitchbow": + foreach (var sign in new[] { -1, 1 }) + { + var tank = top + side * 15 * sign - dir * 5; + DrawCircle(tank, 7, new("3e2949")); DrawCircle(tank, 4, new("cb8bc8")); + } + break; + case "rime": + for (var i = -1; i <= 1; i++) + { + var crystal = top + new Vector2(i * 13, Math.Abs(i) * 5); + DrawColoredPolygon([crystal + new Vector2(-5, 0), crystal + new Vector2(0, -33 + Math.Abs(i) * 9), crystal + new Vector2(5, 0)], new("c6efff")); + } + DrawArc(top, 22, 0, Mathf.Tau, 6, new("9bd5ef"), 2); + break; + case "sun": + DrawCircle(top + new Vector2(0, -8), 18, new("68402b")); + DrawCircle(top + new Vector2(0, -8), 12, new("ffc67e")); + DrawCircle(top + new Vector2(0, -8), 6, new("fff2c9")); + for (var i = 0; i < 8; i++) + { + var ray = Vector2.FromAngle(i * Mathf.Tau / 8); + DrawLine(top + new Vector2(0, -8) + ray * 20, top + new Vector2(0, -8) + ray * 26, new("e5ac6a"), 2); + } + break; + case "breach": + DrawLine(top - dir * 8, top + dir * 24, new("4a6262"), 24); + DrawLine(top - side * 9, top + side * 9, new("d3b285"), 5); + DrawLine(top + dir * 24 - side * 10, top + dir * 24 + side * 10, new("1a2932"), 8); + break; + case "echo": + foreach (var sign in new[] { -1, 1 }) + { + var barrel = top + side * 8 * sign; + DrawLine(barrel - dir * 7, barrel + dir * 21, new("504763"), 12); + DrawLine(barrel - dir * 5, barrel + dir * 17, new("b1a1cf"), 3); + DrawCircle(barrel + dir * 21, 4, new("1b2838")); + } + break; + } + } +} diff --git a/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs.uid b/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs.uid new file mode 100644 index 0000000..d9077e0 --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.Evolution.cs.uid @@ -0,0 +1 @@ +uid://blgfx4lgetlvn diff --git a/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs b/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs new file mode 100644 index 0000000..02bdf06 --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs @@ -0,0 +1,53 @@ +using Godot; +using Redesign.Core; + +namespace Redesign.Game; + +public partial class ArenaCanvas +{ + private void AbilityTelegraphs() + { + foreach (var enemy in Game.Run.Enemies) + { + if (!enemy.WindingUp) continue; + var p = V(enemy.PreviousPosition).Lerp(V(enemy.Position), (float)Game.Alpha); + var windup = enemy.Definition.Healing?.WindupTicks ?? enemy.Definition.Boss!.WindupTicks; + var progress = 1 - Math.Clamp((enemy.NextAbilityTick - Game.Run.Tick) / (float)windup, 0, 1); + var radius = (float)(enemy.Definition.Healing?.Radius ?? 70); + var color = enemy.Definition.Healing is not null ? GameRoot.Mint : GameRoot.Gold; + DrawCircle(p, radius, new Color(color, .045f)); + DrawArc(p, radius, -Mathf.Pi / 2, -Mathf.Pi / 2 + Mathf.Tau * progress, 48, new Color(color, .8f), 2); + DrawString(font, p + new Vector2(-27, -radius - 7), enemy.Definition.Healing is not null ? "MENDING" : "EXPOSED", HorizontalAlignment.Left, -1, 12, color); + } + } + + private void DrawBellwarden(EnemyState enemy, Vector2 p) + { + var trim = enemy.Enraged ? GameRoot.Red : GameRoot.Gold; + DrawEllipseShadow(p + new Vector2(0, 14), 33); + DrawColoredPolygon([p + new Vector2(-24, -27), p + new Vector2(0, -42), p + new Vector2(24, -27), p + new Vector2(29, 17), p + new Vector2(-29, 17)], new("453b4f")); + DrawColoredPolygon([p + new Vector2(-17, -25), p + new Vector2(17, -25), p + new Vector2(24, 10), p + new Vector2(-24, 10)], new("93755e")); + DrawLine(p + new Vector2(-28, 11), p + new Vector2(28, 11), trim, 5); + DrawCircle(p + new Vector2(0, 13), 5, trim); + DrawLine(p + new Vector2(-18, -21), p + new Vector2(18, -21), trim, 4); + DrawCircle(p + new Vector2(0, -35), 7, new("d8bd8e")); + DrawLine(p + new Vector2(-11, -5), p + new Vector2(11, -5), new("2c263b"), 5); + if (enemy.BossVulnerable) DrawCircle(p + new Vector2(0, -5), 6, new("fff0be")); + else DrawArc(p, 34, 0, Mathf.Tau, 8, new Color(trim, .8f), 3); + } + + private void DrawBossReadout() + { + var boss = Game.Run.Enemies.FirstOrDefault(e => e.Definition.Boss is not null); + if (boss is null) return; + var ability = boss.Definition.Boss!; + DrawRect(new(18, 564, 924, 60), new Color("101c26", .97f)); + var color = boss.BossVulnerable ? GameRoot.Gold : boss.Enraged ? GameRoot.Red : new Color("c7b1de"); + DrawString(font, new(30, 588), $"BELLWARDEN / {(boss.Enraged ? "PHASE II" : "PHASE I")} {boss.Health} / {boss.Definition.Health}", HorizontalAlignment.Left, -1, 17, color); + var state = boss.SummonsCreated >= ability.MaxSummons ? "RALLIES EXHAUSTED / EXPOSED" : boss.WindingUp + ? $"EXPOSED / RALLY IN {(boss.NextAbilityTick - Game.Run.Tick) / 60d:0.0}s" : $"GUARDED / {ability.MaxSummons - boss.SummonsCreated} RAIDERS REMAIN"; + DrawString(font, new(490, 588), state, HorizontalAlignment.Left, -1, 15, color); + DrawRect(new(30, 601, 900, 10), new Color("29323b")); + DrawRect(new(30, 601, 900f * boss.Health / boss.Definition.Health, 10), color); + } +} diff --git a/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs.uid b/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs.uid new file mode 100644 index 0000000..85a3d71 --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.Expedition.cs.uid @@ -0,0 +1 @@ +uid://bgfvur5sjggk1 diff --git a/Redesign-Evolution/Game/ArenaCanvas.cs b/Redesign-Evolution/Game/ArenaCanvas.cs new file mode 100644 index 0000000..e5f55d4 --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.cs @@ -0,0 +1,366 @@ +using Godot; +using Redesign.Core; + +namespace Redesign.Game; + +/// Disposable presentation. Effects never modify authoritative gameplay. +public partial class ArenaCanvas : Control +{ + public GameRoot Game { get; init; } = null!; + private readonly List effects = []; + private readonly HashSet road = []; + private int hover = -1; + private double visualTime; + private Font font = null!; + private Vector2[] drawnRoute = []; + private sealed class VisualEffect(GameEvent e) { public GameEvent Event = e; public float Age; } + public override void _Ready() + { + font = ThemeDB.FallbackFont; + var route = Game.Content.Map.Route; + drawnRoute = route.Select(c => V(Game.Content.Map.Center(c))).ToArray(); + for (var i = 1; i < route.Length; i++) + { + var a = route[i - 1]; var b = route[i]; var dx = Math.Sign(b.X - a.X); var dy = Math.Sign(b.Y - a.Y); + for (var c = a; ; c = new(c.X + dx, c.Y + dy)) { road.Add(c); if (c == b) break; } + } + GuiInput += HandleInput; + MouseExited += () => hover = -1; + } + private void HandleInput(InputEvent e) + { + if (e is InputEventMouseMotion motion) + { + hover = FoundationAt(motion.Position); + var enemy = Game.Run.Enemies.FirstOrDefault(enemy => V(enemy.Position).DistanceSquaredTo(motion.Position) < 24 * 24); + TooltipText = enemy is null ? "" : $"{enemy.Definition.Name}: {enemy.Health}/{enemy.Definition.Health} health, {enemy.EffectiveArmor} armor, {enemy.SlowPercent}% slow.\n" + + (enemy.Definition.ShieldRadius > 0 + ? $"Protects nearby allies from {enemy.Definition.ShieldPercent}% damage. Wardens cannot shield each other." + : enemy.ShieldPercent > 0 ? $"Warded: {enemy.ShieldPercent}% less damage. Defeat the nearby escort." : $"Breach costs {enemy.Definition.LeakDamage} citadel lives."); + if (enemy is not null) foreach (var status in enemy.Statuses) + TooltipText += $"\n{status.Definition.Name} x{status.Count}: next stack expires in {(status.Stacks.Min(s => s.ExpiresAt) - Game.Run.Tick) / 60d:0.0}s."; + if (enemy?.Definition.Healing is { } heal) + TooltipText += $"\nMends {heal.Amount} health in radius {heal.Radius:0} every {heal.IntervalTicks / 60d:0.0}s. Kill it before its green ring completes."; + if (enemy?.Definition.Boss is { } boss) + TooltipText += $"\n{(enemy.BossVulnerable ? "EXPOSED: no armor or personal guard." : $"Guarded: {boss.GuardPercent}% damage reduction.")}\nRallies {boss.SummonsPerPulse} Raiders; {boss.MaxSummons - enemy.SummonsCreated} remain. Half-health enrage doubles rally frequency."; + } + if (e is InputEventMouseButton { Pressed: true, ButtonIndex: MouseButton.Left } click) + { + var index = FoundationAt(click.Position); + if (index >= 0) Game.SelectFoundation(index); + AcceptEvent(); + } + } + public int FoundationAt(Vector2 position) + { + for (var i = 0; i < Game.Content.Map.Foundations.Length; i++) + if (position.DistanceSquaredTo(V(Game.Content.Map.Center(Game.Content.Map.Foundations[i]))) <= 28 * 28) return i; + return -1; + } + public void Receive(GameEvent e) + { + if (e.Kind is EventKind.Hit or EventKind.Killed or EventKind.Leaked or EventKind.Built or EventKind.Fired or EventKind.Blast or EventKind.Reaction or EventKind.Upgraded or EventKind.Healed or EventKind.Rally or EventKind.BossEnraged) + { if (effects.Count == 160) effects.RemoveAt(0); effects.Add(new(e)); } + } + public void ClearEffects() { effects.Clear(); hover = -1; } + public override void _Process(double delta) + { + visualTime += delta; + foreach (var e in effects) e.Age += (float)delta; + effects.RemoveAll(e => e.Age > .85f); + } + public override void _Draw() + { + var map = Game.Content.Map; + DrawRect(new(0, 0, 960, 640), new Color("203c37")); + for (var y = 0; y < map.Height; y++) for (var x = 0; x < map.Width; x++) + { + var hash = (x * 7349 + y * 9277 + x * y * 71) & 255; + var ground = new Color(hash % 3 == 0 ? "244239" : hash % 3 == 1 ? "213d36" : "223f38"); + DrawRect(new(x * 64, y * 64, 64, 64), ground); + if (road.Contains(new(x, y))) continue; + var p = new Vector2(x * 64 + 16 + hash % 31, y * 64 + 12 + hash % 37); + DrawLine(p, p + new Vector2(2, -5), new("38604a"), 2); + DrawLine(p + new Vector2(5, 1), p + new Vector2(5, -3), new("315340"), 2); + if (map.Foundations.Contains(new(x, y))) continue; + if (y is 0 or 9 || x == 0 || (hash % 7 == 0 && !road.Contains(new(x, y + 1)))) Tree(p, .65f + hash % 4 * .1f); + else if (hash % 9 == 0) Rock(p); + } + DrawPolyline(drawnRoute, new("142b2b"), 62, false); + DrawPolyline(drawnRoute, new("675d45"), 52, false); + DrawPolyline(drawnRoute, new("847455"), 42, false); + foreach (var cell in road) + { + var p = V(map.Center(cell)); var hash = cell.X * 7 + cell.Y * 13; + DrawRect(new(p.X - 16 + hash % 9, p.Y - 12, 18, 9), new Color("91805e")); + DrawRect(new(p.X + 3, p.Y + 8, 14, 6), new Color("776a4e")); + } + TerrainEffects(); + AbilityTelegraphs(); + DrawString(font, new(8, 292), "INBOUND", HorizontalAlignment.Left, -1, 12, GameRoot.Gold); + DrawLine(new(10, 307), new(44, 307), GameRoot.Gold, 2); + DrawLine(new(36, 301), new(44, 307), GameRoot.Gold, 2); + DrawLine(new(36, 313), new(44, 307), GameRoot.Gold, 2); + for (var i = 0; i < map.Foundations.Length; i++) + { + var p = V(map.Center(map.Foundations[i])); + var occupied = Game.Run.Towers.Any(t => t.Foundation == i); + DrawRect(new(p.X - 23, p.Y - 15, 46, 36), new Color("132a28")); + DrawRect(new(p.X - 21, p.Y - 19, 42, 36), new Color("5b6d60")); + DrawRect(new(p.X - 17, p.Y - 15, 34, 28), new Color("394e47")); + var color = Game.Building && !occupied ? GameRoot.Mint : new Color("8a9c7a"); + if (!occupied) + { + DrawLine(p + new Vector2(-7, -1), p + new Vector2(7, -1), color, 2); + DrawLine(p + new Vector2(0, -8), p + new Vector2(0, 6), color, 2); + } + foreach (var offset in new[] { new Vector2(-18, -16), new Vector2(16, -16), new Vector2(-18, 12), new Vector2(16, 12) }) + DrawRect(new(p + offset, new(3, 3)), new Color("aab28a")); + } + var selected = Game.Run.Towers.FirstOrDefault(t => t.Id == Game.SelectedTower); + Vector2? range = selected is null ? null : V(selected.Position); + var rangeSpec = selected?.Definition ?? Game.BuildDefinition; + if (Game.Building && hover >= 0) + { + range = V(map.Center(map.Foundations[hover])); rangeSpec = Game.BuildDefinition; + } + if (range is Vector2 center) + { + var color = AttackColor(rangeSpec.Attack, rangeSpec.DamageKind); + DrawCircle(center, (float)rangeSpec.Range, new Color(color, .065f)); + DrawArc(center, (float)rangeSpec.Range, 0, Mathf.Tau, 96, new Color(color, .42f), 1, true); + } + foreach (var enemy in Game.Run.Enemies) + if (enemy.Definition.ShieldRadius > 0) + { + var p = V(enemy.PreviousPosition).Lerp(V(enemy.Position), (float)Game.Alpha); + DrawCircle(p, (float)enemy.Definition.ShieldRadius, new Color("988bd0", .045f)); + DrawArc(p, (float)enemy.Definition.ShieldRadius, 0, Mathf.Tau, 48, new Color("b2a3dd", .25f), 1); + } + Castle(V(map.Center(map.Route[^1]))); + foreach (var tower in Game.Run.Towers) Tower(tower); + foreach (var enemy in Game.Run.Enemies) + if (!enemy.IsSupport && enemy.Definition.Boss is null) Enemy(enemy); + // Keep escort silhouettes/staves readable when fast units overlap their formation. + foreach (var enemy in Game.Run.Enemies) + if (enemy.IsSupport && enemy.Definition.Boss is null) Enemy(enemy); + foreach (var enemy in Game.Run.Enemies) + if (enemy.Definition.Boss is not null) Enemy(enemy); + foreach (var shot in Game.Run.Projectiles) + { + var p = V(shot.PreviousPosition).Lerp(V(shot.Position), (float)Game.Alpha); + var direction = V(shot.Position - shot.PreviousPosition).Normalized(); + var color = AttackColor(shot.Definition.Attack, shot.Definition.DamageKind); + DrawLine(p - direction * 15, p, new Color(color, .25f), 5); + if (shot.Definition.Attack == AttackKind.Shell) + { DrawCircle(p, 5, new("563d34")); DrawCircle(p, 3, color); } + else { DrawLine(p - direction * 8, p, color, 2); DrawCircle(p, 2, new("fff6cf")); } + } + foreach (var effect in effects) Effect(effect); + DrawBossReadout(); + if (Game.Run.IsPaused) + { + DrawRect(new(285, 18, 390, 46), new Color("10262a")); + DrawRect(new(285, 18, 390, 46), GameRoot.Mint, false, 1); + DrawString(font, new(323, 48), "TACTICAL PAUSE · BUILD & PLAN", HorizontalAlignment.Left, -1, 17, GameRoot.Mint); + } + } + private void Enemy(EnemyState enemy) + { + var p = V(enemy.PreviousPosition).Lerp(V(enemy.Position), (float)Game.Alpha); + var spec = enemy.Definition; + var stride = MathF.Sin((float)(Game.Run.Tick * .3 + enemy.Id)) * 3; + DrawEllipseShadow(p + new Vector2(0, 9), spec.Armor > 0 ? 20 : 15); + DrawLine(p + new Vector2(-8, 3), p + new Vector2(-13, 12 + stride), new("262433"), 4); + DrawLine(p + new Vector2(8, 3), p + new Vector2(13, 12 - stride), new("262433"), 4); + if (spec.Boss is not null) DrawBellwarden(enemy, p); + else if (spec.Healing is not null) + { + DrawColoredPolygon([p + new Vector2(0, -26), p + new Vector2(-15, 12), p + new Vector2(15, 12)], new("355d53")); + DrawCircle(p + new Vector2(0, -16), 8, new("a3c1a1")); + DrawLine(p + new Vector2(19, 10), p + new Vector2(19, -23), new("d0d9ac"), 3); + DrawLine(p + new Vector2(13, -20), p + new Vector2(25, -20), GameRoot.Mint, 4); + DrawLine(p + new Vector2(19, -26), p + new Vector2(19, -14), GameRoot.Mint, 4); + } + else if (spec.ShieldRadius > 0) + { + DrawColoredPolygon([p + new Vector2(0, -24), p + new Vector2(-15, 10), p + new Vector2(15, 10)], new("554b77")); + DrawColoredPolygon([p + new Vector2(0, -23), p + new Vector2(-8, -11), p + new Vector2(0, -2), p + new Vector2(8, -11)], new("b2a3dd")); + DrawLine(p + new Vector2(20, 12), p + new Vector2(20, -27), new("ddd1b3"), 3); + DrawArc(p + new Vector2(20, -28), 6, 0, Mathf.Tau, 6, new("d7c9f6"), 2); + for (var i = -1; i <= 1; i++) DrawRect(new(p.X + i * 6 - 1, p.Y - 17 - (i == 0 ? 4 : 0), 3, 6), new Color("e3dafa")); + } + else if (spec.Armor > 0) + { + DrawRect(new(p.X - 16, p.Y - 17, 32, 29), new Color("343f4b")); + DrawRect(new(p.X - 13, p.Y - 23, 26, 21), new Color("a49c86")); + DrawRect(new(p.X - 9, p.Y - 15, 18, 4), new Color("302a2f")); + DrawColoredPolygon([p + new Vector2(-19, -5), p + new Vector2(1, -5), p + new Vector2(1, 14), p + new Vector2(-9, 21), p + new Vector2(-19, 14)], new("b57b58")); + DrawLine(p + new Vector2(-9, -2), p + new Vector2(-9, 16), GameRoot.Gold, 3); + DrawLine(p + new Vector2(-15, 5), p + new Vector2(-3, 5), GameRoot.Gold, 2); + if (spec.LeakDamage >= 3) + { + DrawLine(p + new Vector2(18, 10), p + new Vector2(18, -45), new("dfc99b"), 3); + DrawColoredPolygon([p + new Vector2(18, -45), p + new Vector2(40, -39), p + new Vector2(18, -28)], new("c97e60")); + } + } + else + { + DrawColoredPolygon([p + new Vector2(-12, 2), p + new Vector2(-9, -10), p + new Vector2(0, -17), p + new Vector2(10, -9), p + new Vector2(13, 3), p + new Vector2(0, 12)], new("493d57")); + DrawColoredPolygon([p + new Vector2(-9, -7), p + new Vector2(0, -14), p + new Vector2(9, -7), p + new Vector2(0, 2)], new("8c6c83")); + DrawRect(new(p.X - 6, p.Y - 3, 4, 3), GameRoot.Red); DrawRect(new(p.X + 2, p.Y - 3, 4, 3), GameRoot.Red); + if (spec.Speed >= 80) + { + DrawLine(p + new Vector2(-18, 5), p + new Vector2(-26, -7), new("eed6a9"), 2); + DrawLine(p + new Vector2(18, 5), p + new Vector2(26, -7), new("eed6a9"), 2); + } + } + if (enemy.Health < spec.Health) + { + DrawRect(new(p.X - 15, p.Y - 33, 30, 4), new Color("12242a")); + DrawRect(new(p.X - 15, p.Y - 33, 30f * enemy.Health / spec.Health, 4), GameRoot.Red); + } + if (enemy.ShieldPercent > 0) + { + DrawArc(p, 22, 0, Mathf.Tau, 6, new("d2baf0"), 2); + DrawString(font, p + new Vector2(-5, -39), "+", HorizontalAlignment.Left, -1, 14, new("e0cef7")); + } + EnemyStatuses(enemy, p); + } + + private void Tower(TowerState tower) + { + var p = V(tower.Position); DrawEllipseShadow(p + new Vector2(0, 17), 24); + DrawRect(new(p.X - 17, p.Y - 2, 34, 26), new Color("263e40")); + DrawRect(new(p.X - 15, p.Y - 7, 30, 26), new Color("8c8f73")); + DrawRect(new(p.X - 12, p.Y - 5, 24, 17), new Color("5f7265")); + DrawRect(new(p.X - 3, p.Y + 6, 6, 9), GameRoot.Mint); + var top = p + new Vector2(0, -10); + var enemy = Game.Run.Enemies.FirstOrDefault(e => e.Id == tower.TargetId); + var dir = enemy is null ? new Vector2(0, -1) : (V(enemy.Position) - top).Normalized(); + var side = new Vector2(-dir.Y, dir.X); + if (tower.Definition.Attack == AttackKind.Beam) + { + DrawCircle(top, 25, new Color("8bdfec", .08f)); + DrawArc(top, 18, 0, Mathf.Tau, 8, new("7cbdc7"), 2); + DrawColoredPolygon([top + new Vector2(0, -26), top + new Vector2(-10, -8), top + new Vector2(0, 9), top + new Vector2(10, -8)], new("65b9cf")); + DrawColoredPolygon([top + new Vector2(0, -26), top + new Vector2(0, 9), top + new Vector2(10, -8)], new("c4f1e9")); + } + else if (tower.Definition.Attack == AttackKind.Shell) + { + DrawCircle(top, 17, new("8a5c49")); DrawCircle(top, 13, new("c39566")); + DrawLine(top - dir * 5, top + dir * 19, new("293f46"), 18); + DrawLine(top - dir * 4 - side * 4, top + dir * 18 - side * 4, new("728b88"), 3); + DrawCircle(top + dir * 19, 7, new("172930")); DrawCircle(top + dir * 19, 3, new("ea9c69")); + DrawRect(new(p.X - 8, p.Y + 5, 16, 8), new Color("ea9c69")); + for (var x = -6; x <= 6; x += 6) DrawLine(p + new Vector2(x, 4), p + new Vector2(x, 14), new("273d40"), 2); + } + else + { + DrawCircle(top, 12, new("20363a")); DrawCircle(top, 9, new("c4a766")); + DrawLine(top - dir * 8, top + dir * 23, new("1b3034"), 8); + DrawLine(top - dir * 6, top + dir * 22, GameRoot.Gold, 3); + DrawLine(top - side * 15 + dir * 7, top + side * 15 + dir * 7, new("9ba589"), 4); + DrawLine(top - side * 15 + dir * 7, top - dir * 3, new("d2d1a4"), 1); + DrawLine(top + side * 15 + dir * 7, top - dir * 3, new("d2d1a4"), 1); + } + BranchSilhouette(tower, top, dir, side); + if (tower.Id == Game.SelectedTower) DrawArc(p, 29, 0, Mathf.Tau, 40, GameRoot.Mint, 2); + } + private void Castle(Vector2 p) + { + DrawEllipseShadow(p + new Vector2(-4, 15), 33); + DrawRect(new(p.X - 29, p.Y - 43, 56, 58), new Color("344d50")); + DrawRect(new(p.X - 25, p.Y - 40, 48, 51), new Color("849488")); + DrawRect(new(p.X - 22, p.Y - 35, 42, 16), new Color("a5ad94")); + DrawColoredPolygon([p + new Vector2(-34, -44), p + new Vector2(-3, -71), p + new Vector2(32, -44)], new("385761")); + DrawLine(p + new Vector2(-34, -44), p + new Vector2(-3, -71), GameRoot.Mint, 2); + DrawRect(new(p.X - 12, p.Y - 12, 20, 29), new Color("182e32")); + DrawRect(new(p.X - 6, p.Y - 7, 7, 14), GameRoot.Mint); + DrawLine(p + new Vector2(-3, -71), p + new Vector2(-3, -101), new("c1ba86"), 2); + var flutter = (float)Math.Sin(visualTime * 2) * 3; + DrawColoredPolygon([p + new Vector2(-2, -100), p + new Vector2(21, -97 + flutter), p + new Vector2(17, -84 + flutter), p + new Vector2(-2, -86)], GameRoot.Mint); + DrawCircle(p + new Vector2(-27, -16), 9, new Color(GameRoot.Gold, .08f)); + DrawRect(new(p.X - 29, p.Y - 20, 4, 7), GameRoot.Gold); + } + private void Effect(VisualEffect effect) + { + var p = V(effect.Event.Position); var fade = 1 - effect.Age / .85f; + var color = effect.Event.Kind == EventKind.Leaked ? GameRoot.Red : effect.Event.EffectId == "echo" ? new Color("c3acf3") : AttackColor(effect.Event.Attack, effect.Event.DamageKind); + if (effect.Event.Kind == EventKind.Healed) + { + DrawString(font, p + new Vector2(-15, -30 - effect.Age * 24), $"+{effect.Event.Amount} HP", HorizontalAlignment.Left, -1, 12, new Color(GameRoot.Mint, fade)); + } + else if (effect.Event.Kind is EventKind.Rally or EventKind.BossEnraged) + { + DrawArc(p, 30 + effect.Age * 110, 0, Mathf.Tau, 12, new Color(GameRoot.Red, fade), 3); + DrawString(font, p + new Vector2(-28, -65 - effect.Age * 15), effect.Event.Kind == EventKind.Rally ? "RALLY" : "ENRAGED", HorizontalAlignment.Left, -1, 18, new Color(GameRoot.Red, fade)); + } + else if (effect.Event.Kind == EventKind.Reaction) + { + var radius = 12 + Math.Min(effect.Event.Amount, 75) * Math.Min(1, effect.Age / .4f); + DrawArc(p, radius, 0, Mathf.Tau, effect.Event.DamageKind == DamageKind.Frost ? 6 : 32, new Color(color, fade * .8f), 2); + for (var i = 0; i < 8; i++) + { + var d = Vector2.FromAngle(i * Mathf.Tau / 8); + DrawLine(p + d * radius * .4f, p + d * radius * .85f, new Color(color, fade), 3); + } + var name = Game.Content.Combat?.Reactions.FirstOrDefault(r => r.Id == effect.Event.EffectId)?.Name ?? "REACTION"; + DrawString(font, p + new Vector2(-32, -42 - effect.Age * 22), name.ToUpperInvariant(), HorizontalAlignment.Left, -1, 13, new Color(color, fade)); + } + else if (effect.Event.Kind == EventKind.Fired && effect.Event.Attack == AttackKind.Beam) + { + if (effect.Age > .18f || effect.Event.Destination is not { } destination) return; + var end = V(destination); var start = p + new Vector2(0, -18); + DrawLine(start, end, new Color(color, (1 - effect.Age / .18f) * .24f), 10, true); + DrawLine(start, end, new Color(color, 1 - effect.Age / .18f), 2, true); + } + else if (effect.Event.Kind == EventKind.Blast) + { + if (effect.Age > .35f) return; + var radius = effect.Event.Amount * Math.Min(1, effect.Age / .18f); + DrawCircle(p, radius, new Color(color, .10f * (1 - effect.Age / .35f))); + DrawArc(p, radius, 0, Mathf.Tau, 32, new Color(color, .65f * (1 - effect.Age / .35f)), 2); + } + else if (effect.Event.Kind == EventKind.Killed) + { + for (var i = 0; i < 6; i++) + { + var d = Vector2.FromAngle(i * Mathf.Tau / 6); + DrawRect(new(p + d * (8 + effect.Age * 35), new(3, 3)), new Color(color, fade)); + } + DrawString(font, p + new Vector2(-10, -25 - effect.Age * 25), $"+{effect.Event.Amount}", HorizontalAlignment.Left, -1, 14, new Color(color, fade)); + } + else if (effect.Event.Kind is EventKind.Built or EventKind.Upgraded) + DrawArc(p, 20 + effect.Age * 28, 0, Mathf.Tau, 32, new Color(GameRoot.Mint, fade), 2); + else if (effect.Age < .22f) + { + var size = 5 + effect.Age * 35; + DrawLine(p + new Vector2(-size, -size), p + new Vector2(size, size), new Color(color, fade), 2); + DrawLine(p + new Vector2(-size, size), p + new Vector2(size, -size), new Color(color, fade), 2); + } + } + private void Tree(Vector2 p, float scale) + { + DrawEllipseShadow(p + new Vector2(0, 7), 18 * scale); + DrawRect(new(p.X - 3, p.Y - 8, 6, 20), new Color("3e4635")); + for (var i = 0; i < 3; i++) + { + var width = (24 - i * 5) * scale; var y = p.Y - i * 13 * scale; + DrawColoredPolygon([new(p.X - width, y), new(p.X, y - 32 * scale), new(p.X + width, y)], new(i % 2 == 0 ? "18382f" : "214b3b")); + DrawLine(new(p.X, y - 30 * scale), new(p.X + width - 2, y - 1), new("315a41"), 2); + } + } + private void Rock(Vector2 p) + { + DrawColoredPolygon([p + new Vector2(-12, 7), p + new Vector2(-9, -6), p + new Vector2(3, -11), p + new Vector2(14, -2), p + new Vector2(11, 7)], new("52635a")); + DrawLine(p + new Vector2(-9, -6), p + new Vector2(3, -11), new("80907a"), 3); + } + private void DrawEllipseShadow(Vector2 p, float radius) => DrawRect(new(p.X - radius, p.Y - 4, radius * 2, 9), new Color(0, .05f, .06f, .25f)); + internal static Vector2 V(Redesign.Core.Point p) => new((float)p.X, (float)p.Y); + private static Color AttackColor(AttackKind attack, DamageKind kind = DamageKind.Impact) => kind switch + { + DamageKind.Frost => new("b4e7ff"), DamageKind.Fire => new("ffae64"), + _ => attack switch { AttackKind.Beam => new("95dfeb"), AttackKind.Shell => new("eeaa76"), _ => GameRoot.Gold } + }; +} diff --git a/Redesign-Evolution/Game/ArenaCanvas.cs.uid b/Redesign-Evolution/Game/ArenaCanvas.cs.uid new file mode 100644 index 0000000..a5f188c --- /dev/null +++ b/Redesign-Evolution/Game/ArenaCanvas.cs.uid @@ -0,0 +1 @@ +uid://cd0oixp1nbnxv diff --git a/Redesign-Evolution/Game/AudioCues.cs b/Redesign-Evolution/Game/AudioCues.cs new file mode 100644 index 0000000..23c88bf --- /dev/null +++ b/Redesign-Evolution/Game/AudioCues.cs @@ -0,0 +1,71 @@ +using Godot; +using Redesign.Core; + +namespace Redesign.Game; + +/// Original synthesized PCM cues; no external audio or gameplay timing. +public partial class AudioCues : Node +{ + private readonly AudioStreamPlayer[] voices = new AudioStreamPlayer[4]; + private readonly Dictionary sounds = []; + private readonly Dictionary attacks = []; + private readonly Dictionary reactions = []; + private ulong lastReaction; + private int nextVoice; + private readonly ulong[] lastShot = new ulong[3]; + public bool Muted { get; set; } + public override void _Ready() + { + for (var i = 0; i < voices.Length; i++) { voices[i] = new() { VolumeDb = -20 }; AddChild(voices[i]); } + attacks[AttackKind.Bolt] = Tone(520, .055, -.65); + attacks[AttackKind.Beam] = Tone(940, .095, .4); + attacks[AttackKind.Shell] = Tone(180, .14, -.7); + sounds[EventKind.Blast] = Tone(100, .12, -.8); + sounds[EventKind.Killed] = Tone(780, .09, .3); + sounds[EventKind.Built] = Tone(440, .16, .65); + sounds[EventKind.Upgraded] = Tone(600, .28, .8); + sounds[EventKind.RelicChosen] = Tone(720, .45, .7); + sounds[EventKind.Rally] = Tone(105, .4, -.2); + sounds[EventKind.BossEnraged] = Tone(180, .5, -.7); + reactions["shatter"] = Tone(1350, .15, -.8); + reactions["ignition"] = Tone(130, .24, .8); + sounds[EventKind.Leaked] = Tone(150, .22, -.3); + sounds[EventKind.WaveStarted] = Tone(270, .25, .5); + sounds[EventKind.Victory] = Tone(660, .5, .6); + sounds[EventKind.Defeat] = Tone(180, .5, -.5); + } + public void Receive(GameEvent e) + { + if (Muted) return; + AudioStreamWav? sound; + if (e.Kind == EventKind.Fired) + { + var now = Time.GetTicksMsec(); var kind = (int)e.Attack; + if (now - lastShot[kind] < 80) return; lastShot[kind] = now; + sound = attacks[e.Attack]; + } + else if (e.Kind == EventKind.Reaction) + { + if (e.EffectId is null || !reactions.TryGetValue(e.EffectId, out sound)) return; + var now = Time.GetTicksMsec(); + if (now - lastReaction < 100) return; lastReaction = now; + } + else if (!sounds.TryGetValue(e.Kind, out sound)) return; + var voice = voices[nextVoice++ % voices.Length]; voice.Stream = sound; voice.Play(); + } + public void StopAll() { foreach (var voice in voices) voice.Stop(); } + private static AudioStreamWav Tone(double frequency, double seconds, double sweep) + { + const int sampleRate = 22050; + var samples = (int)(sampleRate * seconds); var data = new byte[samples * 2]; + for (var i = 0; i < samples; i++) + { + var t = (double)i / sampleRate; var normalized = (double)i / samples; + var envelope = Math.Min(1, normalized * 25) * Math.Pow(1 - normalized, 2); + var phase = Math.Tau * frequency * (t + sweep * t * t / (2 * seconds)); + var value = (short)(Math.Sin(phase) * envelope * 9000); + data[i * 2] = (byte)(value & 255); data[i * 2 + 1] = (byte)(value >> 8); + } + return new AudioStreamWav { Format = AudioStreamWav.FormatEnum.Format16Bits, MixRate = sampleRate, Stereo = false, Data = data }; + } +} diff --git a/Redesign-Evolution/Game/AudioCues.cs.uid b/Redesign-Evolution/Game/AudioCues.cs.uid new file mode 100644 index 0000000..c656f00 --- /dev/null +++ b/Redesign-Evolution/Game/AudioCues.cs.uid @@ -0,0 +1 @@ +uid://df58pfqgf2mf diff --git a/Redesign-Evolution/Game/Content/emberwatch.json b/Redesign-Evolution/Game/Content/emberwatch.json new file mode 100644 index 0000000..4192ffa --- /dev/null +++ b/Redesign-Evolution/Game/Content/emberwatch.json @@ -0,0 +1,445 @@ +{ + "formatVersion": 2, + "id": "emberwatch-evolution-v3", + "startingGold": 245, + "startingLives": 12, + "map": { + "id": "emberwatch", + "title": "Emberwatch", + "width": 15, + "height": 10, + "tileSize": 64, + "route": [ + { + "x": 0, + "y": 5 + }, + { + "x": 3, + "y": 5 + }, + { + "x": 3, + "y": 2 + }, + { + "x": 8, + "y": 2 + }, + { + "x": 8, + "y": 7 + }, + { + "x": 12, + "y": 7 + }, + { + "x": 12, + "y": 4 + }, + { + "x": 14, + "y": 4 + } + ], + "foundations": [ + { + "x": 2, + "y": 4 + }, + { + "x": 4, + "y": 3 + }, + { + "x": 6, + "y": 3 + }, + { + "x": 7, + "y": 1 + }, + { + "x": 9, + "y": 4 + }, + { + "x": 7, + "y": 6 + }, + { + "x": 11, + "y": 6 + }, + { + "x": 13, + "y": 5 + } + ] + }, + "waves": [ + { + "title": "First watch", + "briefing": "Runners test the road. Cover its bends.", + "groups": [ + { + "enemyId": "runner", + "count": 8, + "intervalTicks": 60, + "delayTicks": 0 + } + ] + }, + { + "title": "Iron footsteps", + "briefing": "Bulwark armor blocks 9 impact. Prism bypasses it.", + "groups": [ + { + "enemyId": "runner", + "count": 12, + "intervalTicks": 36, + "delayTicks": 0 + }, + { + "enemyId": "bulwark", + "count": 3, + "intervalTicks": 140, + "delayTicks": 140 + } + ] + }, + { + "title": "The rush", + "briefing": "A tight pack. Crucible splash hits nearby foes.", + "groups": [ + { + "enemyId": "runner", + "count": 18, + "intervalTicks": 12, + "delayTicks": 0 + } + ] + }, + { + "title": "Under the ward", + "briefing": "Wardens shield allies. Try Support targeting.", + "groups": [ + { + "enemyId": "warden", + "count": 2, + "intervalTicks": 420, + "delayTicks": 0 + }, + { + "enemyId": "runner", + "count": 16, + "intervalTicks": 32, + "delayTicks": 40 + }, + { + "enemyId": "bulwark", + "count": 4, + "intervalTicks": 140, + "delayTicks": 90 + } + ] + }, + { + "title": "Braided assault", + "briefing": "Armor, shields and speed arrive together.", + "groups": [ + { + "enemyId": "runner", + "count": 28, + "intervalTicks": 16, + "delayTicks": 0 + }, + { + "enemyId": "bulwark", + "count": 7, + "intervalTicks": 90, + "delayTicks": 60 + }, + { + "enemyId": "warden", + "count": 3, + "intervalTicks": 200, + "delayTicks": 0 + } + ] + }, + { + "title": "Last light", + "briefing": "Break the escorts, then hold the final rush.", + "groups": [ + { + "enemyId": "runner", + "count": 36, + "intervalTicks": 12, + "delayTicks": 0 + }, + { + "enemyId": "bulwark", + "count": 10, + "intervalTicks": 70, + "delayTicks": 20 + }, + { + "enemyId": "warden", + "count": 4, + "intervalTicks": 170, + "delayTicks": 0 + } + ] + } + ], + "towers": [ + { + "id": "boltworks", + "cost": 60, + "damage": 18, + "range": 190, + "cooldownTicks": 42, + "projectileSpeed": 480, + "splashRadius": 0, + "name": "Boltworks", + "description": "Fast bolts. Reliable road coverage.", + "attack": "Bolt", + "damageKind": "Impact" + }, + { + "id": "prism", + "name": "Prism", + "description": "Instant energy beams bypass armor.", + "cost": 85, + "damage": 25, + "range": 175, + "cooldownTicks": 64, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Energy" + }, + { + "id": "crucible", + "name": "Crucible", + "description": "Slow shells. Half damage to nearby foes.", + "cost": 100, + "damage": 36, + "range": 220, + "cooldownTicks": 96, + "projectileSpeed": 270, + "splashRadius": 76, + "attack": "Shell", + "damageKind": "Impact" + } + ], + "enemies": [ + { + "id": "runner", + "health": 44, + "speed": 48, + "bounty": 10, + "leakDamage": 1, + "name": "Runner" + }, + { + "id": "bulwark", + "name": "Bulwark", + "health": 130, + "speed": 32, + "bounty": 18, + "leakDamage": 2, + "armor": 9 + }, + { + "id": "warden", + "name": "Warden", + "health": 95, + "speed": 38, + "bounty": 22, + "leakDamage": 2, + "shieldRadius": 100, + "shieldPercent": 40 + } + ], + "combat": { + "statuses": [ + { + "id": "chill", + "name": "Chill", + "maxStacks": 3, + "durationTicks": 180, + "slowPercentPerStack": 15 + }, + { + "id": "oil", + "name": "Oil", + "maxStacks": 1, + "durationTicks": 240 + }, + { + "id": "pin", + "name": "Pin", + "maxStacks": 1, + "durationTicks": 30, + "slowPercentPerStack": 80 + }, + { + "id": "fracture", + "name": "Fracture", + "maxStacks": 2, + "durationTicks": 180, + "armorReductionPerStack": 6 + } + ], + "reactions": [ + { + "id": "shatter", + "name": "Shatter", + "statusId": "chill", + "requiredStacks": 2, + "trigger": "Impact", + "effect": "Burst", + "damage": 24, + "radius": 64, + "damageKind": "Frost", + "cooldownTicks": 60 + }, + { + "id": "ignition", + "name": "Ignition", + "statusId": "oil", + "requiredStacks": 1, + "trigger": "Fire", + "effect": "BurningGround", + "damage": 6, + "radius": 72, + "damageKind": "Fire", + "cooldownTicks": 120, + "durationTicks": 180, + "intervalTicks": 30, + "maxAreas": 6 + } + ], + "branches": [ + { + "towerId": "boltworks", + "cost": 110, + "upgrade": { + "id": "ballista", + "cost": 60, + "damage": 38, + "range": 245, + "cooldownTicks": 78, + "projectileSpeed": 650, + "splashRadius": 0, + "name": "Pinning Ballista", + "description": "Heavy bolts pin for 0.5s. Longer reach, slower firing.", + "attack": "Bolt", + "damageKind": "Impact", + "onHit": { + "statusId": "pin" + } + } + }, + { + "towerId": "boltworks", + "cost": 70, + "upgrade": { + "id": "pitchbow", + "cost": 60, + "damage": 8, + "range": 195, + "cooldownTicks": 32, + "projectileSpeed": 480, + "splashRadius": 0, + "name": "Pitchbow", + "description": "Low-damage bolts coat foes in oil. Pair with a Sun Lens.", + "attack": "Bolt", + "damageKind": "Impact", + "onHit": { + "statusId": "oil" + } + } + }, + { + "towerId": "prism", + "cost": 80, + "upgrade": { + "id": "rime", + "name": "Rime Lens", + "description": "Chills and slows. Two chill stacks + impact cause Shatter.", + "cost": 85, + "damage": 10, + "range": 180, + "cooldownTicks": 36, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Frost", + "onHit": { + "statusId": "chill" + } + } + }, + { + "towerId": "prism", + "cost": 100, + "upgrade": { + "id": "sun", + "name": "Sun Lens", + "description": "Fire beams ignite oiled foes into burning ground.", + "cost": 85, + "damage": 24, + "range": 200, + "cooldownTicks": 64, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Fire" + } + }, + { + "towerId": "crucible", + "cost": 110, + "upgrade": { + "id": "breach", + "name": "Breach Mortar", + "description": "Shells fracture armor across the blast. Supports physical towers.", + "cost": 100, + "damage": 34, + "range": 220, + "cooldownTicks": 102, + "projectileSpeed": 270, + "splashRadius": 82, + "attack": "Shell", + "damageKind": "Impact", + "onHit": { + "statusId": "fracture" + } + } + }, + { + "towerId": "crucible", + "cost": 120, + "upgrade": { + "id": "echo", + "name": "Echo Mortar", + "description": "A marked second impact lands after 0.5s. Lower direct damage.", + "cost": 100, + "damage": 28, + "range": 235, + "cooldownTicks": 108, + "projectileSpeed": 270, + "splashRadius": 76, + "attack": "Shell", + "damageKind": "Impact", + "echo": { + "delayTicks": 30, + "damage": 16, + "radius": 76 + } + } + } + ] + } +} diff --git a/Redesign-Evolution/Game/Content/expedition.json b/Redesign-Evolution/Game/Content/expedition.json new file mode 100644 index 0000000..1f2b7d0 --- /dev/null +++ b/Redesign-Evolution/Game/Content/expedition.json @@ -0,0 +1,803 @@ +{ + "formatVersion": 2, + "id": "emberwatch-expedition-v1", + "startingGold": 180, + "startingLives": 12, + "map": { + "id": "emberwatch", + "title": "Emberwatch", + "width": 15, + "height": 10, + "tileSize": 64, + "route": [ + { + "x": 0, + "y": 5 + }, + { + "x": 3, + "y": 5 + }, + { + "x": 3, + "y": 2 + }, + { + "x": 8, + "y": 2 + }, + { + "x": 8, + "y": 7 + }, + { + "x": 12, + "y": 7 + }, + { + "x": 12, + "y": 4 + }, + { + "x": 14, + "y": 4 + } + ], + "foundations": [ + { + "x": 2, + "y": 4 + }, + { + "x": 4, + "y": 3 + }, + { + "x": 6, + "y": 3 + }, + { + "x": 7, + "y": 1 + }, + { + "x": 9, + "y": 4 + }, + { + "x": 7, + "y": 6 + }, + { + "x": 11, + "y": 6 + }, + { + "x": 13, + "y": 5 + } + ] + }, + "waves": [ + { + "title": "First watch", + "briefing": "Start with two towers. Save for a path or wider coverage.", + "groups": [ + { + "intervalTicks": 65, + "delayTicks": 0, + "count": 10, + "enemyId": "runner" + } + ], + "clearGold": 50, + "healthPercent": 100 + }, + { + "title": "Iron footsteps", + "briefing": "Armor arrives behind the runners. Energy or Shatter breaks it.", + "groups": [ + { + "intervalTicks": 34, + "delayTicks": 0, + "count": 12, + "enemyId": "runner" + }, + { + "intervalTicks": 160, + "delayTicks": 150, + "count": 2, + "enemyId": "bulwark" + } + ], + "clearGold": 74, + "healthPercent": 100 + }, + { + "title": "The iron standard", + "briefing": "Elite: a Captain follows the escort. A relic awaits this victory.", + "groups": [ + { + "intervalTicks": 30, + "delayTicks": 0, + "count": 14, + "enemyId": "runner" + }, + { + "intervalTicks": 140, + "delayTicks": 80, + "count": 3, + "enemyId": "bulwark" + }, + { + "intervalTicks": 1, + "delayTicks": 360, + "count": 1, + "enemyId": "captain" + } + ], + "clearGold": 32, + "healthPercent": 100 + }, + { + "title": "Mending march", + "briefing": "Menders heal nearby allies. Support targeting interrupts their pulse.", + "groups": [ + { + "intervalTicks": 240, + "delayTicks": 0, + "count": 2, + "enemyId": "mender" + }, + { + "intervalTicks": 40, + "delayTicks": 40, + "count": 14, + "enemyId": "runner" + }, + { + "intervalTicks": 180, + "delayTicks": 100, + "count": 3, + "enemyId": "bulwark" + } + ], + "clearGold": 24, + "healthPercent": 115 + }, + { + "title": "The sheltered rush", + "briefing": "Shields escort a dense pack. Burst damage and focus fire matter.", + "groups": [ + { + "intervalTicks": 280, + "delayTicks": 0, + "count": 2, + "enemyId": "warden" + }, + { + "intervalTicks": 18, + "delayTicks": 30, + "count": 20, + "enemyId": "runner" + }, + { + "intervalTicks": 130, + "delayTicks": 90, + "count": 4, + "enemyId": "bulwark" + } + ], + "clearGold": 24, + "healthPercent": 115 + }, + { + "title": "Break the convoy", + "briefing": "Elite: healing and armor together. Win your second relic.", + "groups": [ + { + "intervalTicks": 1, + "delayTicks": 280, + "count": 1, + "enemyId": "captain" + }, + { + "intervalTicks": 220, + "delayTicks": 0, + "count": 2, + "enemyId": "mender" + }, + { + "intervalTicks": 260, + "delayTicks": 60, + "count": 2, + "enemyId": "warden" + }, + { + "intervalTicks": 120, + "delayTicks": 90, + "count": 4, + "enemyId": "bulwark" + }, + { + "intervalTicks": 26, + "delayTicks": 50, + "count": 18, + "enemyId": "runner" + } + ], + "clearGold": 32, + "healthPercent": 115 + }, + { + "title": "Outriders", + "briefing": "Fast raiders overtake the column. Keep some coverage downstream.", + "groups": [ + { + "intervalTicks": 30, + "delayTicks": 0, + "count": 16, + "enemyId": "runner" + }, + { + "intervalTicks": 22, + "delayTicks": 220, + "count": 6, + "enemyId": "raider" + }, + { + "intervalTicks": 170, + "delayTicks": 80, + "count": 3, + "enemyId": "bulwark" + }, + { + "intervalTicks": 280, + "delayTicks": 30, + "count": 2, + "enemyId": "mender" + } + ], + "clearGold": 24, + "healthPercent": 140 + }, + { + "title": "The long siege", + "briefing": "A staggered escort tests sustained damage, not only a single burst.", + "groups": [ + { + "intervalTicks": 40, + "delayTicks": 0, + "count": 20, + "enemyId": "runner" + }, + { + "intervalTicks": 130, + "delayTicks": 90, + "count": 6, + "enemyId": "bulwark" + }, + { + "intervalTicks": 250, + "delayTicks": 40, + "count": 3, + "enemyId": "warden" + }, + { + "intervalTicks": 330, + "delayTicks": 170, + "count": 2, + "enemyId": "mender" + } + ], + "clearGold": 24, + "healthPercent": 140 + }, + { + "title": "Twin standards", + "briefing": "Two Captains and three Menders. Your final relic follows.", + "groups": [ + { + "intervalTicks": 350, + "delayTicks": 200, + "count": 2, + "enemyId": "captain" + }, + { + "intervalTicks": 30, + "delayTicks": 0, + "count": 20, + "enemyId": "runner" + }, + { + "intervalTicks": 160, + "delayTicks": 60, + "count": 5, + "enemyId": "bulwark" + }, + { + "intervalTicks": 260, + "delayTicks": 20, + "count": 3, + "enemyId": "mender" + } + ], + "clearGold": 36, + "healthPercent": 140 + }, + { + "title": "Black procession", + "briefing": "A full escort line. Switch priorities as support units fall.", + "groups": [ + { + "intervalTicks": 22, + "delayTicks": 0, + "count": 30, + "enemyId": "runner" + }, + { + "intervalTicks": 110, + "delayTicks": 80, + "count": 6, + "enemyId": "bulwark" + }, + { + "intervalTicks": 240, + "delayTicks": 0, + "count": 3, + "enemyId": "warden" + }, + { + "intervalTicks": 240, + "delayTicks": 120, + "count": 3, + "enemyId": "mender" + } + ], + "clearGold": 28, + "healthPercent": 165 + }, + { + "title": "The last breach", + "briefing": "Raiders follow the heaviest column. Prepare a second killing ground.", + "groups": [ + { + "intervalTicks": 20, + "delayTicks": 0, + "count": 28, + "enemyId": "runner" + }, + { + "intervalTicks": 30, + "delayTicks": 400, + "count": 6, + "enemyId": "raider" + }, + { + "intervalTicks": 100, + "delayTicks": 60, + "count": 7, + "enemyId": "bulwark" + }, + { + "intervalTicks": 230, + "delayTicks": 0, + "count": 3, + "enemyId": "warden" + }, + { + "intervalTicks": 230, + "delayTicks": 110, + "count": 3, + "enemyId": "mender" + } + ], + "clearGold": 40, + "healthPercent": 165 + }, + { + "title": "Bellwarden", + "briefing": "Boss: exposed while ringing. At half health it rallies faster.", + "groups": [ + { + "intervalTicks": 1, + "delayTicks": 120, + "count": 1, + "enemyId": "bellwarden" + }, + { + "intervalTicks": 35, + "delayTicks": 0, + "count": 16, + "enemyId": "runner" + }, + { + "intervalTicks": 180, + "delayTicks": 60, + "count": 4, + "enemyId": "bulwark" + }, + { + "intervalTicks": 400, + "delayTicks": 180, + "count": 2, + "enemyId": "mender" + }, + { + "intervalTicks": 400, + "delayTicks": 90, + "count": 2, + "enemyId": "warden" + } + ], + "clearGold": 50, + "healthPercent": 165 + } + ], + "towers": [ + { + "id": "boltworks", + "cost": 60, + "damage": 18, + "range": 190, + "cooldownTicks": 42, + "projectileSpeed": 480, + "splashRadius": 0, + "name": "Boltworks", + "description": "Fast bolts. Reliable road coverage.", + "attack": "Bolt", + "damageKind": "Impact" + }, + { + "id": "prism", + "name": "Prism", + "description": "Instant energy beams bypass armor.", + "cost": 85, + "damage": 25, + "range": 175, + "cooldownTicks": 64, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Energy" + }, + { + "id": "crucible", + "name": "Crucible", + "description": "Slow shells. Half damage to nearby foes.", + "cost": 100, + "damage": 36, + "range": 220, + "cooldownTicks": 96, + "projectileSpeed": 270, + "splashRadius": 76, + "attack": "Shell", + "damageKind": "Impact" + } + ], + "enemies": [ + { + "id": "runner", + "name": "Runner", + "health": 55, + "bounty": 2, + "leakDamage": 1, + "speed": 54 + }, + { + "id": "bulwark", + "name": "Bulwark", + "health": 180, + "bounty": 5, + "leakDamage": 2, + "armor": 14, + "speed": 38 + }, + { + "id": "warden", + "leakDamage": 2, + "shieldRadius": 100, + "speed": 43, + "health": 160, + "name": "Warden", + "bounty": 7, + "shieldPercent": 40 + }, + { + "id": "mender", + "name": "Mender", + "health": 135, + "bounty": 6, + "healing": { + "amount": 12, + "intervalTicks": 150, + "radius": 105, + "windupTicks": 45 + }, + "leakDamage": 2, + "speed": 36 + }, + { + "id": "raider", + "name": "Raider", + "health": 65, + "bounty": 0, + "leakDamage": 1, + "speed": 94 + }, + { + "id": "captain", + "health": 400, + "leakDamage": 3, + "slowResistancePercent": 25, + "speed": 28, + "armor": 20, + "name": "Iron Captain", + "bounty": 15 + }, + { + "armor": 20, + "id": "bellwarden", + "boss": { + "maxSummons": 12, + "intervalTicks": 300, + "guardPercent": 45, + "windupTicks": 90, + "summonsPerPulse": 2, + "summonEnemyId": "raider", + "enrageSpeedPercent": 25, + "enrageHealthPercent": 50 + }, + "bounty": 50, + "leakDamage": 12, + "name": "Bellwarden", + "health": 3200, + "slowResistancePercent": 50, + "speed": 19 + } + ], + "combat": { + "statuses": [ + { + "id": "chill", + "name": "Chill", + "maxStacks": 3, + "durationTicks": 180, + "slowPercentPerStack": 15 + }, + { + "id": "oil", + "name": "Oil", + "maxStacks": 1, + "durationTicks": 240 + }, + { + "id": "pin", + "name": "Pin", + "maxStacks": 1, + "durationTicks": 30, + "slowPercentPerStack": 80 + }, + { + "id": "fracture", + "name": "Fracture", + "maxStacks": 2, + "durationTicks": 180, + "armorReductionPerStack": 6 + } + ], + "reactions": [ + { + "id": "shatter", + "name": "Shatter", + "statusId": "chill", + "requiredStacks": 2, + "trigger": "Impact", + "effect": "Burst", + "damage": 32, + "radius": 64, + "damageKind": "Frost", + "cooldownTicks": 60 + }, + { + "id": "ignition", + "name": "Ignition", + "statusId": "oil", + "requiredStacks": 1, + "trigger": "Fire", + "effect": "BurningGround", + "damage": 8, + "radius": 72, + "damageKind": "Fire", + "cooldownTicks": 120, + "durationTicks": 180, + "intervalTicks": 30, + "maxAreas": 6 + } + ], + "branches": [ + { + "towerId": "boltworks", + "cost": 110, + "upgrade": { + "id": "ballista", + "cost": 60, + "damage": 55, + "range": 245, + "cooldownTicks": 78, + "projectileSpeed": 650, + "splashRadius": 0, + "name": "Pinning Ballista", + "description": "Heavy bolts pin for 0.5s. Longer reach, slower firing.", + "attack": "Bolt", + "damageKind": "Impact", + "onHit": { + "statusId": "pin" + } + } + }, + { + "towerId": "boltworks", + "cost": 70, + "upgrade": { + "id": "pitchbow", + "cost": 60, + "damage": 12, + "range": 195, + "cooldownTicks": 32, + "projectileSpeed": 480, + "splashRadius": 0, + "name": "Pitchbow", + "description": "Low-damage bolts coat foes in oil. Pair with a Sun Lens.", + "attack": "Bolt", + "damageKind": "Impact", + "onHit": { + "statusId": "oil" + } + } + }, + { + "towerId": "prism", + "cost": 80, + "upgrade": { + "id": "rime", + "name": "Rime Lens", + "description": "Chills and slows. Two chill stacks + impact cause Shatter.", + "cost": 85, + "damage": 14, + "range": 180, + "cooldownTicks": 36, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Frost", + "onHit": { + "statusId": "chill" + } + } + }, + { + "towerId": "prism", + "cost": 100, + "upgrade": { + "id": "sun", + "name": "Sun Lens", + "description": "Fire beams ignite oiled foes into burning ground.", + "cost": 85, + "damage": 32, + "range": 200, + "cooldownTicks": 54, + "projectileSpeed": 880, + "attack": "Beam", + "damageKind": "Fire" + } + }, + { + "towerId": "crucible", + "cost": 110, + "upgrade": { + "id": "breach", + "name": "Breach Mortar", + "description": "Shells fracture armor across the blast. Supports physical towers.", + "cost": 100, + "damage": 44, + "range": 220, + "cooldownTicks": 102, + "projectileSpeed": 270, + "splashRadius": 82, + "attack": "Shell", + "damageKind": "Impact", + "onHit": { + "statusId": "fracture" + } + } + }, + { + "towerId": "crucible", + "cost": 120, + "upgrade": { + "id": "echo", + "name": "Echo Mortar", + "description": "A marked second impact lands after 0.5s. Lower direct damage.", + "cost": 100, + "damage": 34, + "range": 235, + "cooldownTicks": 108, + "projectileSpeed": 270, + "splashRadius": 76, + "attack": "Shell", + "damageKind": "Impact", + "echo": { + "delayTicks": 30, + "damage": 22, + "radius": 88 + } + } + } + ] + }, + "expedition": { + "challengeBaseCount": 2, + "challengeGrowthPerStage": 3, + "challengeEnemyId": "raider", + "challengeBonusGold": 20, + "rewardWaves": [ + 3, + 6, + 9 + ], + "relics": [ + { + "power": 1, + "description": "Chill attacks apply one extra stack. A Rime hit can prime Shatter immediately.", + "name": "Winter Glass", + "id": "winter-glass", + "kind": "ExtraChill" + }, + { + "id": "split-lens", + "name": "Split Lens", + "power": 50, + "description": "Each beam forks once to a nearby enemy for 50% damage and carries its status or reaction.", + "kind": "BeamFork", + "radius": 72 + }, + { + "id": "barbed-relay", + "name": "Barbed Relay", + "power": 50, + "description": "Bolts arc once to a nearby foe for 50% damage. Oil and pin travel with the second hit.", + "kind": "BoltFork", + "radius": 72 + }, + { + "id": "echo-spindle", + "name": "Echo Spindle", + "power": 10, + "description": "Every shell leaves a 10-damage delayed blast. Existing Echo Mortars add 10 echo damage.", + "kind": "ShellEcho", + "radius": 76 + }, + { + "id": "kiln-heart", + "name": "Kiln Heart", + "power": 60, + "description": "Ignition burns for one extra second and reaches 24 units farther. Overlap limits still apply.", + "kind": "LongBurn", + "radius": 24 + }, + { + "power": 90, + "description": "Gain 90 gold now. Expand the defense or complete a combination sooner.", + "name": "War Chest", + "id": "war-chest", + "kind": "WarChest" + }, + { + "power": 4, + "description": "Restore 4 citadel lives and raise maximum lives by 2. A recovery choice for a damaged run.", + "name": "Reinforced Gate", + "id": "reinforced-gate", + "kind": "ReinforcedGate" + } + ] + } +} diff --git a/Redesign-Evolution/Game/Content/foundation.json b/Redesign-Evolution/Game/Content/foundation.json new file mode 100644 index 0000000..49f506f --- /dev/null +++ b/Redesign-Evolution/Game/Content/foundation.json @@ -0,0 +1,141 @@ +{ + "formatVersion": 2, + "id": "emberwatch-foundation-v1", + "startingGold": 180, + "startingLives": 12, + "map": { + "id": "emberwatch", + "title": "Emberwatch", + "width": 15, + "height": 10, + "tileSize": 64, + "route": [ + { + "x": 0, + "y": 5 + }, + { + "x": 3, + "y": 5 + }, + { + "x": 3, + "y": 2 + }, + { + "x": 8, + "y": 2 + }, + { + "x": 8, + "y": 7 + }, + { + "x": 12, + "y": 7 + }, + { + "x": 12, + "y": 4 + }, + { + "x": 14, + "y": 4 + } + ], + "foundations": [ + { + "x": 2, + "y": 4 + }, + { + "x": 4, + "y": 3 + }, + { + "x": 6, + "y": 3 + }, + { + "x": 7, + "y": 1 + }, + { + "x": 9, + "y": 4 + }, + { + "x": 7, + "y": 6 + }, + { + "x": 11, + "y": 6 + }, + { + "x": 13, + "y": 5 + } + ] + }, + "waves": [ + { + "title": "First watch", + "briefing": "Cover several stretches of road.", + "groups": [ + { + "enemyId": "runner", + "count": 8, + "intervalTicks": 60 + } + ] + }, + { + "title": "First watch", + "briefing": "Cover several stretches of road.", + "groups": [ + { + "enemyId": "runner", + "count": 12, + "intervalTicks": 48 + } + ] + }, + { + "title": "First watch", + "briefing": "Cover several stretches of road.", + "groups": [ + { + "enemyId": "runner", + "count": 16, + "intervalTicks": 36 + } + ] + } + ], + "towers": [ + { + "id": "boltworks", + "cost": 60, + "damage": 18, + "range": 190, + "cooldownTicks": 42, + "projectileSpeed": 480, + "splashRadius": 0, + "name": "Boltworks", + "description": "Fast bolts. Reliable road coverage.", + "attack": "Bolt", + "damageKind": "Impact" + } + ], + "enemies": [ + { + "id": "runner", + "health": 44, + "speed": 48, + "bounty": 10, + "leakDamage": 1, + "name": "Runner" + } + ] +} diff --git a/Redesign-Evolution/Game/GameRoot.Evolution.cs b/Redesign-Evolution/Game/GameRoot.Evolution.cs new file mode 100644 index 0000000..7581af8 --- /dev/null +++ b/Redesign-Evolution/Game/GameRoot.Evolution.cs @@ -0,0 +1,97 @@ +using Godot; +using Redesign.Core; + +namespace Redesign.Game; + +public partial class GameRoot +{ + public Button EvolveButton { get; private set; } = null!; + public Button CloseEvolutionButton { get; private set; } = null!; + public Control EvolutionPanel { get; private set; } = null!; + public Button[] BranchButtons { get; private set; } = []; + public BranchDefinition[] BranchChoices { get; private set; } = []; + private Label evolutionTitle = null!, evolutionHint = null!; + private Control branchCards = null!; + + private void BuildEvolutionInterface() + { + EvolutionPanel = new Control { Size = new(1440, 900), Visible = false, MouseFilter = MouseFilterEnum.Stop }; + AddChild(EvolutionPanel); + EvolutionPanel.AddChild(new ColorRect { Color = new(0.02f, .05f, .07f, .84f), Size = new(1440, 900), MouseFilter = MouseFilterEnum.Ignore }); + var window = new Panel { Position = new(240, 180), Size = new(960, 540) }; + window.AddThemeStyleboxOverride("panel", Box(Panel, Mint)); EvolutionPanel.AddChild(window); + evolutionTitle = AddLabel(window, "", new(28, 24), new(904, 40), 28, Text); + evolutionHint = AddLabel(window, "", new(28, 72), new(904, 44), 16, Muted); + var scroll = new ScrollContainer { Position = new(28, 130), Size = new(904, 320), HorizontalScrollMode = ScrollContainer.ScrollMode.Disabled }; + window.AddChild(scroll); + branchCards = new Control(); scroll.AddChild(branchCards); + CloseEvolutionButton = AddButton(window, "KEEP CURRENT TOWER [ESC]", new(28, 474), new(904, 42), CloseEvolution); + } + + private void OpenEvolution() + { + var tower = Run.Towers.FirstOrDefault(t => t.Id == SelectedTower); + if (tower is null || tower.BranchId is not null || Run.Phase is RunPhase.Victory or RunPhase.Defeat) return; + BranchChoices = Content.Combat?.Branches.Where(b => b.TowerId == tower.FamilyId).ToArray() ?? []; + if (BranchChoices.Length == 0) return; + if (Run.Phase == RunPhase.Wave) Run.Apply(new Pause(true)); + Building = false; + evolutionTitle.Text = $"EVOLVE / {tower.Definition.Name.ToUpperInvariant()}"; + evolutionHint.Text = $"{Run.Gold} gold available. Choose one permanent specialization for this tower.\n" + + (Run.Phase == RunPhase.Wave ? "Battle paused. After choosing or closing, press Space to resume." : "Paths change how a tower fights. Pair a setup tower with a finisher."); + foreach (var child in branchCards.GetChildren()) { branchCards.RemoveChild(child); child.QueueFree(); } + branchCards.CustomMinimumSize = new(884, ((BranchChoices.Length + 1) / 2) * 302); + BranchButtons = BranchChoices.Select((branch, i) => + { + var spec = Run.PreviewUpgrade(branch.Upgrade.Id)!; + var card = new Panel { Position = new(i % 2 * 450, i / 2 * 302), Size = new(434, 286) }; + card.TooltipText = DescribeEffects(spec); + card.AddThemeStyleboxOverride("panel", Box(new("192e37"), Border)); branchCards.AddChild(card); + AddLabel(card, spec.Name.ToUpperInvariant(), new(22, 18), new(390, 34), 23, Text); + AddLabel(card, $"{spec.Damage} {spec.DamageKind.ToString().ToLowerInvariant()} / {spec.CooldownTicks / 60d:0.00}s / range {spec.Range:0}", + new(22, 62), new(390, 26), 16, Gold); + AddLabel(card, spec.Description, new(22, 108), new(390, 94), 17, Text, wrap: true); + var button = AddButton(card, Run.Gold >= branch.Cost ? $"CHOOSE PATH / {branch.Cost} G" : $"NEED {branch.Cost - Run.Gold} MORE GOLD / {branch.Cost} G", + new(22, 224), new(390, 42), () => PurchaseBranch(branch.Upgrade.Id), true); + button.Disabled = Run.Gold < branch.Cost; + button.TooltipText = card.TooltipText; + return button; + }).ToArray(); + EvolutionPanel.Visible = true; RefreshInterface(); + } + + private string DescribeEffects(TowerDefinition spec) + { + var lines = new List { spec.Description }; + if (spec.SplashRadius > 0) lines.Add($"Splash: radius {spec.SplashRadius:0}, half damage to other enemies."); + if (spec.OnHit is { } application && Content.Combat?.Statuses.FirstOrDefault(s => s.Id == application.StatusId) is { } status) + { + lines.Add($"{status.Name}: +{application.Stacks} per hit, {status.DurationTicks / 60d:0.0}s per stack, maximum {status.MaxStacks}."); + if (status.SlowPercentPerStack > 0) lines.Add($"{status.SlowPercentPerStack}% slow per stack; only the strongest slow applies."); + if (status.ArmorReductionPerStack > 0) lines.Add($"-{status.ArmorReductionPerStack} armor per stack, minimum zero. Applies before this hit."); + } + if (spec.Echo is { } echo) lines.Add($"Echo: {echo.Damage} {echo.DamageKind.ToString().ToLowerInvariant()} damage in radius {echo.Radius:0} after {echo.DelayTicks / 60d:0.0}s. Cannot trigger reactions."); + if (spec.ForkRadius > 0) lines.Add($"Relic fork: one nearby enemy in radius {spec.ForkRadius:0} takes {spec.ForkDamagePercent}% damage and receives the attack's status/reaction."); + foreach (var reaction in Run.Reactions.Select(r => r.Definition)) + if (reaction.Trigger == spec.DamageKind || reaction.StatusId == spec.OnHit?.StatusId) + lines.Add($"{reaction.Name}: consumes {reaction.RequiredStacks} {reaction.StatusId} on {reaction.Trigger.ToString().ToLowerInvariant()} hit. " + + (reaction.Effect == ReactionEffect.Burst ? $"{reaction.Damage} damage in radius {reaction.Radius:0}." : + $"{reaction.Damage} damage every {reaction.IntervalTicks / 60d:0.0}s for {reaction.DurationTicks / 60d:0.0}s, radius {reaction.Radius:0}; overlapping fields share a damage timer.")); + return string.Join("\n", lines); + } + + private void PurchaseBranch(string branchId) + { + var result = Run.Apply(new UpgradeTower(SelectedTower, branchId)); + Message(result.Message + (Run.IsPaused ? " Press Space to resume." : "")); + if (result.Success) EvolutionPanel.Visible = false; + RefreshInterface(); + } + + private void CloseEvolution() + { + EvolutionPanel.Visible = false; + Message(Run.IsPaused ? "Defense paused. Press Space when your plan is ready." : "Current tower kept. Choose a path whenever you are ready."); + RefreshInterface(); + } +} diff --git a/Redesign-Evolution/Game/GameRoot.Evolution.cs.uid b/Redesign-Evolution/Game/GameRoot.Evolution.cs.uid new file mode 100644 index 0000000..239529f --- /dev/null +++ b/Redesign-Evolution/Game/GameRoot.Evolution.cs.uid @@ -0,0 +1 @@ +uid://bo682gyvhcqix diff --git a/Redesign-Evolution/Game/GameRoot.Expedition.cs b/Redesign-Evolution/Game/GameRoot.Expedition.cs new file mode 100644 index 0000000..68d34f3 --- /dev/null +++ b/Redesign-Evolution/Game/GameRoot.Expedition.cs @@ -0,0 +1,122 @@ +using Godot; +using Redesign.Core; +using Redesign.Infrastructure; + +namespace Redesign.Game; + +public partial class GameRoot +{ + public Control RewardPanel { get; private set; } = null!; + public Button[] RewardButtons { get; private set; } = []; + public Button ChallengeButton { get; private set; } = null!; + private Label stageLabel = null!, rewardTitle = null!, rewardHint = null!; + private Button relicButton = null!, closeRelics = null!; + private Control rewardCards = null!; + + private void BuildExpeditionInterface() + { + RewardPanel = new Control { Size = new(1440, 900), Visible = false, MouseFilter = MouseFilterEnum.Stop }; AddChild(RewardPanel); + RewardPanel.AddChild(new ColorRect { Size = new(1440, 900), Color = new(.02f, .04f, .06f, .88f), MouseFilter = MouseFilterEnum.Ignore }); + var window = new Panel { Position = new(150, 160), Size = new(1140, 580) }; + window.AddThemeStyleboxOverride("panel", Box(Panel, Gold)); RewardPanel.AddChild(window); + rewardTitle = AddLabel(window, "", new(28, 24), new(1084, 48), 30, Gold); + rewardHint = AddLabel(window, "", new(28, 80), new(1084, 64), 16, Text, wrap: true); + rewardCards = new Control { Position = new(28, 164), Size = new(1084, 330) }; window.AddChild(rewardCards); + closeRelics = AddButton(window, "RETURN TO THE ROAD [I / ESC]", new(28, 518), new(1084, 38), CloseRelicReview); + } + + private void RefreshExpeditionInterface() + { + var shownWave = Math.Clamp(Run.WaveNumber + (Run.Phase == RunPhase.Planning ? 1 : 0), 1, 12); + var stage = (shownWave - 1) / 3; + stageLabel.Text = $"{new[] { "I / OUTPOST", "II / CONVOY", "III / BREACH", "IV / LAST LIGHT" }[stage]} · " + + string.Join(" ", Enumerable.Range(1, 12).Select(w => w <= Run.WaveReports.Count ? "◆" : w == shownWave ? $"[{w}]" : w.ToString())); + relicButton.Text = $"RELICS / {Run.Relics.Count} [I]"; + relicButton.TooltipText = $"Seed {Run.Seed}\n" + (Run.Relics.Count == 0 ? "Earn a choice after waves 3, 6 and 9." : string.Join("\n", Run.Relics.Select(r => r.Name + ": " + r.Description))); + ChallengeButton.Disabled = Run.Phase != RunPhase.Planning || Run.RewardOffers.Count > 0; + ChallengeButton.Text = Run.Phase == RunPhase.Wave + ? Run.ChallengeEnabled ? "OVERRUN ACTIVE" : "STANDARD ENCOUNTER" + : $"OVERRUN {(Run.ChallengeEnabled ? "ON" : "OFF")} / +{Run.ChallengeReward} G"; + ChallengeButton.Modulate = Run.ChallengeEnabled ? Gold : Colors.White; + ChallengeButton.TooltipText = $"Optional: {Run.ChallengeCount} extra Raiders arrive 1.5s after the wave starts, 0.75s apart.\nEarn {Run.ChallengeReward} bonus gold only if nobody breaches. Raiders give no bounty.\nYou can change this choice until starting the wave. Normal clear reward is always paid on victory."; + if (Run.Phase == RunPhase.Planning && Run.ChallengeEnabled) + forecastBody.Text += $" + {Run.ChallengeCount} Raiders (Overrun)"; + if (Run.RewardOffers.Count > 0 && !RewardPanel.Visible) ShowRelics(true); + } + + private void ToggleChallenge() + { Message(Run.Apply(new SetChallenge(!Run.ChallengeEnabled)).Message); RefreshInterface(); } + private void OpenRelicReview() + { + if (EvolutionPanel.Visible) return; + if (Run.Phase == RunPhase.Wave) Run.Apply(new Pause(true)); + ShowRelics(Run.RewardOffers.Count > 0); + } + private void ShowRelics(bool choosing) + { + EvolutionPanel.Visible = false; Building = false; + var offers = choosing ? Run.RewardOffers : Run.Relics; + rewardTitle.Text = choosing ? $"WAVE {Run.WaveNumber} HELD / CLAIM A RELIC" : "YOUR EXPEDITION / RELICS"; + rewardHint.Text = choosing ? "Choose one. It lasts for this run and changes existing and future towers. The other two are left behind.\n" + + $"Your defense: {string.Join(", ", Run.Towers.Select(t => t.Definition.Name).Distinct())}. {Run.Lives}/{Run.MaxLives} lives · {Run.Gold} gold." + : $"Seed {Run.Seed} · Rewards after waves 3, 6 and 9. A new expedition brings different offers.\n" + + (Run.IsPaused ? "Combat is paused. After closing, press Space to resume." : "Combine relics with your paths. Recovering the citadel can be worth more than another attack effect."); + foreach (var child in rewardCards.GetChildren()) { rewardCards.RemoveChild(child); child.QueueFree(); } + var buttons = new List