Skip to content

Commit 92c4324

Browse files
committed
Better ship handling for AFK player
1 parent 349e7ac commit 92c4324

File tree

6 files changed

+39
-6
lines changed

6 files changed

+39
-6
lines changed

src/core/execution/ExecutionManager.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export class Executor {
7575
intent.dst,
7676
intent.troops,
7777
intent.src,
78+
player,
7879
);
7980
case "allianceRequest":
8081
return new AllianceRequestExecution(player, intent.recipient);

src/core/execution/FakeHumanExecution.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ export class FakeHumanExecution implements Execution {
397397
closest.y,
398398
this.player.troops() / 5,
399399
null,
400+
this.player,
400401
),
401402
);
402403
}
@@ -598,6 +599,7 @@ export class FakeHumanExecution implements Execution {
598599
dst,
599600
this.player.troops() / 5,
600601
null,
602+
this.player,
601603
),
602604
);
603605
return;

src/core/execution/TransportShipExecution.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export class TransportShipExecution implements Execution {
3939
private ref: TileRef,
4040
private startTroops: number,
4141
private src: TileRef | null,
42+
private originalOwner: Player,
4243
) {}
4344

4445
activeDuringSpawnPhase(): boolean {
@@ -181,6 +182,17 @@ export class TransportShipExecution implements Execution {
181182
}
182183
}
183184

185+
// Team member can conquer disconnected player and gets their ships
186+
// captureUnit has changed the owner of the unit, now update attacker
187+
if (
188+
this.originalOwner.isDisconnected() &&
189+
this.boat.owner() !== this.originalOwner &&
190+
this.boat.owner().isOnSameTeam(this.originalOwner)
191+
) {
192+
this.attacker = this.boat.owner();
193+
this.originalOwner = this.boat.owner(); // for when this owner disconnects too
194+
}
195+
184196
const result = this.pathFinder.nextTile(this.boat.tile(), this.dst);
185197
switch (result.type) {
186198
case PathFindResultType.Completed:

src/core/execution/WarshipExecution.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ export class WarshipExecution implements Execution {
5555
this.warship.delete();
5656
return;
5757
}
58-
if (this.warship.owner().isDisconnected()) {
59-
this.warship.delete();
60-
return;
61-
}
6258

6359
const hasPort = this.warship.owner().unitCount(UnitType.Port) > 0;
6460
if (hasPort) {
@@ -93,7 +89,8 @@ export class WarshipExecution implements Execution {
9389
if (
9490
unit.owner() === this.warship.owner() ||
9591
unit === this.warship ||
96-
unit.owner().isFriendly(this.warship.owner()) ||
92+
// Keep below order so if warship owner is disconnected, isFriendly still returns true
93+
this.warship.owner().isFriendly(unit.owner()) ||
9794
this.alreadySentShell.has(unit)
9895
) {
9996
continue;

src/core/game/GameImpl.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,20 @@ export class GameImpl implements Game {
877877
return this._railNetwork;
878878
}
879879
conquerPlayer(conqueror: Player, conquered: Player) {
880+
if (conquered.isDisconnected() && conqueror.isOnSameTeam(conquered)) {
881+
const ships = conquered
882+
.units()
883+
.filter(
884+
(u) =>
885+
u.type() === UnitType.Warship ||
886+
u.type() === UnitType.TransportShip,
887+
);
888+
889+
for (const ship of ships) {
890+
conqueror.captureUnit(ship);
891+
}
892+
}
893+
880894
const gold = conquered.gold();
881895
this.displayMessage(
882896
`Conquered ${conquered.displayName()} received ${renderNumber(

tests/Attack.test.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ let attackerSpawn: TileRef;
2121

2222
function sendBoat(target: TileRef, source: TileRef, troops: number) {
2323
game.addExecution(
24-
new TransportShipExecution(defender, null, target, troops, source),
24+
new TransportShipExecution(
25+
defender,
26+
null,
27+
target,
28+
troops,
29+
source,
30+
defender,
31+
),
2532
);
2633
}
2734

0 commit comments

Comments
 (0)