mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-13 16:57:10 +00:00
give Battleships & Destroyers health, make shells more frequent & larger
This commit is contained in:
@@ -35,6 +35,8 @@ export interface UnitInfo {
|
||||
cost: (player: Player) => Gold
|
||||
// Determines if its owner changes when its tile is conquered.
|
||||
territoryBound: boolean
|
||||
maxHealth?: number,
|
||||
damage?: number
|
||||
}
|
||||
|
||||
export enum UnitType {
|
||||
@@ -193,6 +195,8 @@ export interface Unit {
|
||||
owner(): Player
|
||||
isActive(): boolean
|
||||
info(): UnitInfo
|
||||
hasHealth(): boolean
|
||||
health(): number
|
||||
}
|
||||
|
||||
export interface MutableUnit extends Unit {
|
||||
@@ -200,6 +204,7 @@ export interface MutableUnit extends Unit {
|
||||
owner(): MutablePlayer
|
||||
setTroops(troops: number): void
|
||||
delete(displayerMessage?: boolean): void
|
||||
modifyHealth(delta: number): void
|
||||
}
|
||||
|
||||
export interface TerraNullius {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { MessageType } from "../../client/graphics/layers/EventsDisplay";
|
||||
import { simpleHash } from "../Util";
|
||||
import { simpleHash, within } from "../Util";
|
||||
import { MutableUnit, Tile, TerraNullius, UnitType, Player, UnitInfo } from "./Game";
|
||||
import { GameImpl } from "./GameImpl";
|
||||
import { PlayerImpl } from "./PlayerImpl";
|
||||
@@ -8,6 +8,7 @@ import { TerraNulliusImpl } from "./TerraNulliusImpl";
|
||||
|
||||
export class UnitImpl implements MutableUnit {
|
||||
private _active = true;
|
||||
private _health: number
|
||||
|
||||
constructor(
|
||||
private _type: UnitType,
|
||||
@@ -15,7 +16,10 @@ export class UnitImpl implements MutableUnit {
|
||||
private _tile: Tile,
|
||||
private _troops: number,
|
||||
public _owner: PlayerImpl,
|
||||
) { }
|
||||
) {
|
||||
// default to half health (or 1 is no health specified)
|
||||
this._health = (this.g.unitInfo(_type).maxHealth ?? 2) / 2
|
||||
}
|
||||
|
||||
type(): UnitType {
|
||||
return this._type
|
||||
@@ -35,6 +39,12 @@ export class UnitImpl implements MutableUnit {
|
||||
troops(): number {
|
||||
return this._troops;
|
||||
}
|
||||
health(): number {
|
||||
return this._health
|
||||
}
|
||||
hasHealth(): boolean {
|
||||
return this.info().maxHealth != undefined
|
||||
}
|
||||
tile(): Tile {
|
||||
return this._tile;
|
||||
}
|
||||
@@ -57,6 +67,15 @@ export class UnitImpl implements MutableUnit {
|
||||
)
|
||||
}
|
||||
|
||||
modifyHealth(delta: number): void {
|
||||
this._health = within(
|
||||
this._health + delta,
|
||||
0,
|
||||
this.info().maxHealth ?? 1
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
delete(displayMessage: boolean = true): void {
|
||||
if (!this.isActive()) {
|
||||
throw new Error(`cannot delete ${this} not active`)
|
||||
|
||||
Reference in New Issue
Block a user