mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-22 12:46:30 +00:00
Update TradeShipExecution.ts
This commit is contained in:
@@ -57,12 +57,12 @@ export class TradeShipExecution implements Execution {
|
||||
}
|
||||
|
||||
if (this.origOwner != this.tradeShip.owner()) {
|
||||
// Store as variable in case ship is recaptured by previous owner
|
||||
|
||||
this.wasCaptured = true;
|
||||
}
|
||||
|
||||
// If a player captures another player's port while trading we should delete
|
||||
// the ship.
|
||||
// the ship
|
||||
if (this._dstPort.owner().id() == this.srcPort.owner().id()) {
|
||||
this.tradeShip.delete(false);
|
||||
this.active = false;
|
||||
@@ -94,21 +94,48 @@ export class TradeShipExecution implements Execution {
|
||||
}
|
||||
}
|
||||
|
||||
const result = this.pathFinder.nextTile(
|
||||
this.tradeShip.tile(),
|
||||
this._dstPort.tile(),
|
||||
);
|
||||
const currentTile = this.tradeShip.tile();
|
||||
const dstPort = this._dstPort;
|
||||
|
||||
|
||||
if (!dstPort.data) {
|
||||
dstPort.data = {};
|
||||
}
|
||||
|
||||
|
||||
if (dstPort.data.pathCache) {
|
||||
const key = `${this.mg.x(currentTile)},${this.mg.y(currentTile)}`;
|
||||
const cachedNextTile = dstPort.data.pathCache.get(key);
|
||||
if (cachedNextTile) {
|
||||
|
||||
if (this.mg.isWater(cachedNextTile) && this.mg.isShoreline(cachedNextTile)) {
|
||||
this.tradeShip.setSafeFromPirates();
|
||||
}
|
||||
this.tradeShip.move(cachedNextTile);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
const result = this.pathFinder.nextTile(currentTile, dstPort.tile());
|
||||
|
||||
switch (result.type) {
|
||||
case PathFindResultType.Completed:
|
||||
this.complete();
|
||||
break;
|
||||
case PathFindResultType.Pending:
|
||||
// Fire unit event to rerender.
|
||||
// Fire unit event to rerender
|
||||
this.tradeShip.move(this.tradeShip.tile());
|
||||
break;
|
||||
case PathFindResultType.NextTile:
|
||||
// Update safeFromPirates status
|
||||
|
||||
if (!dstPort.data.pathCache) {
|
||||
dstPort.data.pathCache = new Map<string, TileRef>();
|
||||
}
|
||||
|
||||
const key = `${this.mg.x(currentTile)},${this.mg.y(currentTile)}`;
|
||||
dstPort.data.pathCache.set(key, result.tile);
|
||||
|
||||
if (this.mg.isWater(result.tile) && this.mg.isShoreline(result.tile)) {
|
||||
this.tradeShip.setSafeFromPirates();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user