Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add attack mission and battle report logic #265

Merged
merged 33 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4484d79
Add attack mission scaffolding, add espionage logic planet update and…
lanedirt Jul 14, 2024
05a9e53
Small refactor
lanedirt Jul 15, 2024
3105611
Add battle reports database migrations table
lanedirt Jul 17, 2024
8513d07
Add battle report model scaffolding and battle report message object …
lanedirt Jul 17, 2024
8bba60a
Add battle report message preview template
lanedirt Aug 3, 2024
82ed0b5
Update MessagesTest.php to include battle report explicit test
lanedirt Aug 3, 2024
5273f52
Add all params for battle report message preview
lanedirt Aug 4, 2024
e685817
Add BattleEngine scaffolding, refactor return mission parameters
lanedirt Aug 4, 2024
7730a09
Add loot percentage to battle report
lanedirt Aug 4, 2024
2d2aa9b
Add unit tests for BattleEngine loot capacity calculation, small refa…
lanedirt Aug 6, 2024
179f24f
Add battle report full message template
lanedirt Aug 11, 2024
25b92cf
Add attacker and defender fleet unit collections, add tests
lanedirt Aug 11, 2024
3add35e
Refactor BattleEngine structure, add service classes, save user tech …
lanedirt Aug 12, 2024
6736dab
Implement battle engine rounds scaffolding
lanedirt Aug 13, 2024
fbe3a2a
Update battle report div structure to fix JS errors
lanedirt Aug 18, 2024
30ca015
Add dynamic round JSON to battle report
lanedirt Aug 18, 2024
67b3bb7
Add logic for zero defense battle which is an immediate win with no r…
lanedirt Aug 18, 2024
8b44617
Fix starting/result ship count for attacker and defender
lanedirt Aug 18, 2024
1893c06
Add winner conditional overmark/undermark formatting
lanedirt Aug 18, 2024
82ab105
Add two simulated battle engine unit tests
lanedirt Aug 18, 2024
3c22868
Add BattleUnit class to hold current values for each unit during battle
lanedirt Aug 19, 2024
865dc6a
Implement full battle logic including rapidfire
lanedirt Aug 19, 2024
4998d8a
Add battle engine shield bounce test, fix unit collection bug
lanedirt Aug 19, 2024
33253c1
Add battle engine unit test for user tech levels
lanedirt Aug 19, 2024
e79174d
Add feature test to ensure lost units are removed from database after…
lanedirt Aug 19, 2024
85010c5
Add feature test to ensure no return mission is launched if attacker …
lanedirt Aug 19, 2024
642b595
Send battle report to both attacker and defender
lanedirt Aug 19, 2024
d2995e0
Add resource loss for both players to battle report
lanedirt Aug 19, 2024
b621047
Update fleet events to show incoming hostile and neutral missions
lanedirt Aug 19, 2024
30ddd01
Add feature test for under attack warning
lanedirt Aug 19, 2024
22aad0e
Update README.md
lanedirt Aug 19, 2024
02e262c
Fix tests, code style refactor
lanedirt Aug 19, 2024
2c7295c
Update fleet mission update logic to prevent race conditions
lanedirt Aug 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ $ php artisan test:race-condition-unitqueue
$ php artisan test:race-condition-game-mission
```

### 5. Keep it simple
If your PR is too big, it will be hard to review. Try to keep it simple and small. If you want to do more than one thing, send multiple pull requests.
### 5. Run CSS and JS build
OGameX uses Laravel Mix to compile the CSS and JS assets. Before submitting a PR, make sure to run the following command to compile the assets.
This command can be run in watch mode to automatically recompile the assets when changes are made which is useful during development.

### 6. Keep it clean
Please remove any unrelated changes from your PR. If you have changes in your branch that are not related to the PR, please create a new branch for them.

If you have any questions, feel free to reach out to the maintainer(s). Thank you in advance for your contributions! 🎉
```
$ npm run dev watch
```
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,25 @@ OGameX is under active development with several core features already implemente
- Planet switching
- Highscore system
- Basic messages system
- Battle system
- Fleet dispatch missions
- Transport
- Deployment
- Colonisation
- Espionage
- Attack
- Basic admin panel

### <a name="upcoming-features"></a> a) Upcoming Features

New features are continuously being added. Upcoming features:
- Remaining fleet dispatch missions (recycling, attack, ACS)
- Battlesystem
- Support for Moons
- Moon destruction fleet dispatch mission
New features are continuously being added. Upcoming major features:
- Recycle fleet dispatch mission
- Support for Moons
- Moon creation through debris field after battle
- Moon buildings
- Phalanx
- Moon destruction fleet dispatch mission
- ACS fleet dispatch missions
- Alliance system
- Improve galaxy overview
- Improve message system
Expand Down
8 changes: 7 additions & 1 deletion app/Console/Commands/Tests/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,13 @@ protected function setup(): void
// Delete user if it already exists.
$user = User::where('email', '=', $this->email)->first();
if ($user) {
$playerServiceFactory->make($user->id)->delete();
try {
$playerServiceFactory->make($user->id)->delete();
} catch (Exception $e) {
$this->error("Failed to delete existing user: " . $e->getMessage());
// Try to delete the user directly from the database.
$user->delete();
}
}

// Create a test user
Expand Down
2 changes: 2 additions & 0 deletions app/Factories/GameMessageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Container\BindingResolutionException;
use OGame\GameMessages\Abstracts\GameMessage;
use OGame\GameMessages\BattleReport;
use OGame\GameMessages\ColonyEstablished;
use OGame\GameMessages\ColonyEstablishFailAstrophysics;
use OGame\GameMessages\EspionageReport;
Expand Down Expand Up @@ -37,6 +38,7 @@ class GameMessageFactory
'fleet_deployment' => FleetDeployment::class,
'fleet_deployment_with_resources' => FleetDeploymentWithResources::class,
'espionage_report' => EspionageReport::class,
'battle_report' => BattleReport::class,
];

/**
Expand Down
4 changes: 4 additions & 0 deletions app/Factories/GameMissionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Contracts\Container\BindingResolutionException;
use OGame\GameMissions\Abstracts\GameMission;
use OGame\GameMissions\AttackMission;
use OGame\GameMissions\ColonisationMission;
use OGame\GameMissions\DeploymentMission;
use OGame\GameMissions\EspionageMission;
Expand Down Expand Up @@ -33,6 +34,7 @@ public static function getAllMissions(): array
*/
try {
return [
1 => app()->make(AttackMission::class),
3 => app()->make(TransportMission::class),
4 => app()->make(DeploymentMission::class),
6 => app()->make(EspionageMission::class),
Expand All @@ -53,6 +55,8 @@ public static function getMissionById(int $missionId, array $dependencies): Game
{
try {
switch ($missionId) {
case 1:
return app()->make(AttackMission::class, $dependencies);
case 3:
return app()->make(TransportMission::class, $dependencies);
case 4:
Expand Down
9 changes: 7 additions & 2 deletions app/GameMessages/Abstracts/GameMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OGame\Factories\PlayerServiceFactory;
use OGame\Models\Message;
use OGame\Models\Planet\Coordinate;
use OGame\Services\ObjectService;

/**
* GameMessage class which contains unique parsing logic for a specific message type.
Expand Down Expand Up @@ -42,21 +43,25 @@ abstract class GameMessage

protected PlayerServiceFactory $playerServiceFactory;

protected ObjectService $objects;

/**
* GameMessage constructor.
*
* @param Message $message
* @param PlanetServiceFactory $planetServiceFactory
* @param PlayerServiceFactory $playerServiceFactory
* @param Message $message
* @param ObjectService $objectService
*/
public function __construct(Message $message, PlanetServiceFactory $planetServiceFactory, PlayerServiceFactory $playerServiceFactory)
public function __construct(Message $message, PlanetServiceFactory $planetServiceFactory, PlayerServiceFactory $playerServiceFactory, ObjectService $objectService)
{
// Clone the message to prevent any changes to the original message affecting this object.
// This is important because otherwise mutations such as setting the viewed flag after loading this object
// would affect this object's state as well.
$this->message = clone $message;
$this->planetServiceFactory = $planetServiceFactory;
$this->playerServiceFactory = $playerServiceFactory;
$this->objects = $objectService;
$this->initialize();
}

Expand Down
Loading
Loading