mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 15:00:43 +00:00
Prevent players from nuking their teammates structures 💥 (#3105)
## Description: It is possible to hit your teammates while throwing a nuke onto water or enemies. This PR blocks the nuking entirely if you would hit a teammates structure. Because they are valuable. Feature requested by Wonder :) https://github.com/user-attachments/assets/448a3444-cc3d-4e76-acaf-595decab1634 ## Please complete the following: - [X] I have added screenshots for all UI updates - [X] I process any text displayed to the user through translateText() and I've added it to the en.json file - [X] I have added relevant tests to the test directory - [X] I confirm I have thoroughly tested these changes and take full responsibility for any bugs introduced ## Please put your Discord username so you can be contacted if a bug or regression is found: FloPinguin --------- Co-authored-by: Ryan <7389646+ryanbarlow97@users.noreply.github.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import {
|
||||
ColoredTeams,
|
||||
Embargo,
|
||||
EmojiMessage,
|
||||
GameMode,
|
||||
Gold,
|
||||
MessageType,
|
||||
MutableAlliance,
|
||||
@@ -29,6 +30,7 @@ import {
|
||||
PlayerProfile,
|
||||
PlayerType,
|
||||
Relation,
|
||||
StructureTypes,
|
||||
Team,
|
||||
TerraNullius,
|
||||
Tick,
|
||||
@@ -994,10 +996,10 @@ export class PlayerImpl implements Player {
|
||||
if (!this.mg.hasOwner(targetTile)) {
|
||||
return false;
|
||||
}
|
||||
return this.nukeSpawn(targetTile);
|
||||
return this.nukeSpawn(targetTile, unitType);
|
||||
case UnitType.AtomBomb:
|
||||
case UnitType.HydrogenBomb:
|
||||
return this.nukeSpawn(targetTile);
|
||||
return this.nukeSpawn(targetTile, unitType);
|
||||
case UnitType.MIRVWarhead:
|
||||
return targetTile;
|
||||
case UnitType.Port:
|
||||
@@ -1024,7 +1026,7 @@ export class PlayerImpl implements Player {
|
||||
}
|
||||
}
|
||||
|
||||
nukeSpawn(tile: TileRef): TileRef | false {
|
||||
nukeSpawn(tile: TileRef, nukeType: UnitType): TileRef | false {
|
||||
if (this.mg.isSpawnImmunityActive()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1034,6 +1036,24 @@ export class PlayerImpl implements Player {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Prevent launching nukes that would hit teammate structures (only in team games)
|
||||
if (
|
||||
this.mg.config().gameConfig().gameMode === GameMode.Team &&
|
||||
nukeType !== UnitType.MIRV
|
||||
) {
|
||||
const magnitude = this.mg.config().nukeMagnitudes(nukeType);
|
||||
const wouldHitTeammate = this.mg.anyUnitNearby(
|
||||
tile,
|
||||
magnitude.outer,
|
||||
StructureTypes,
|
||||
(unit) => unit.owner().isPlayer() && this.isOnSameTeam(unit.owner()),
|
||||
);
|
||||
if (wouldHitTeammate) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// only get missilesilos that are not on cooldown and not under construction
|
||||
const spawns = this.units(UnitType.MissileSilo)
|
||||
.filter((silo) => {
|
||||
|
||||
Reference in New Issue
Block a user