mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:00:42 +00:00
created PlayerType enum add FakeHuman type
This commit is contained in:
@@ -98,6 +98,7 @@
|
||||
* BUG: attacks speed up DONE 9/6/2024
|
||||
* rebalance income DONE 9/7/2024
|
||||
* Make fake humans
|
||||
* BUG: when clicking on enemy sometimes boat goes all the way around
|
||||
|
||||
--- v3 Release
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import {Executor} from "../core/execution/ExecutionManager";
|
||||
import {Cell, MutableGame, PlayerEvent, PlayerID, MutablePlayer, TileEvent, Player, Game, BoatEvent, Tile} from "../core/Game";
|
||||
import {Cell, MutableGame, PlayerEvent, PlayerID, MutablePlayer, TileEvent, Player, Game, BoatEvent, Tile, PlayerType} from "../core/Game";
|
||||
import {createGame} from "../core/GameImpl";
|
||||
import {EventBus} from "../core/EventBus";
|
||||
import {Config} from "../core/configuration/Config";
|
||||
@@ -248,7 +248,7 @@ export class ClientGame {
|
||||
if (enemyShoreDists.length > 0 && bordersOcean) {
|
||||
enemyShoreClosest = enemyShoreDists[0].dist
|
||||
}
|
||||
if (enemyShoreClosest < borderTileClosest / 4) {
|
||||
if (enemyShoreClosest < borderTileClosest / 6) {
|
||||
this.sendBoatAttackIntent(targetID, enemyShoreDists[0].tile.cell(), this.gs.config().boatAttackAmount(this.myPlayer, owner))
|
||||
} else {
|
||||
this.sendAttackIntent(targetID, cell, this.gs.config().attackAmount(this.myPlayer, owner))
|
||||
@@ -275,7 +275,7 @@ export class ClientGame {
|
||||
type: "spawn",
|
||||
clientID: this.id,
|
||||
name: this.playerName,
|
||||
isBot: false,
|
||||
playerType: PlayerType.Human,
|
||||
x: cell.x,
|
||||
y: cell.y
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Cell, Game, Player} from "../../core/Game"
|
||||
import {Cell, Game, Player, PlayerType} from "../../core/Game"
|
||||
import {PseudoRandom} from "../../core/PseudoRandom"
|
||||
import {calculateBoundingBox} from "../../core/Util"
|
||||
import {Theme} from "../../core/configuration/Config"
|
||||
@@ -85,7 +85,7 @@ export class NameRenderer {
|
||||
|
||||
isVisible(render: RenderInfo, min: Cell, max: Cell): boolean {
|
||||
const ratio = (max.x - min.x) / Math.max(20, (render.boundingBox.max.x - render.boundingBox.min.x))
|
||||
if (render.player.isBot()) {
|
||||
if (render.player.type() == PlayerType.Bot) {
|
||||
if (ratio > 35) {
|
||||
return false
|
||||
}
|
||||
|
||||
+8
-2
@@ -26,6 +26,12 @@ export enum TerrainType {
|
||||
Ocean
|
||||
}
|
||||
|
||||
export enum PlayerType {
|
||||
Bot = "BOT",
|
||||
Human = "HUMAN",
|
||||
FakeHuman = "FAKEHUMAN",
|
||||
}
|
||||
|
||||
export interface ExecutionView {
|
||||
isActive(): boolean
|
||||
owner(): Player
|
||||
@@ -41,7 +47,7 @@ export interface Execution extends ExecutionView {
|
||||
export class PlayerInfo {
|
||||
constructor(
|
||||
public readonly name: string,
|
||||
public readonly isBot: boolean,
|
||||
public readonly playerType: PlayerType,
|
||||
// null if bot.
|
||||
public readonly clientID: ClientID | null,
|
||||
public readonly id: PlayerID
|
||||
@@ -95,7 +101,7 @@ export interface Player {
|
||||
name(): string
|
||||
clientID(): ClientID
|
||||
id(): PlayerID
|
||||
isBot(): boolean
|
||||
type(): PlayerType
|
||||
troops(): number
|
||||
boats(): Boat[]
|
||||
ownsTile(cell: Cell): boolean
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {Config} from "./configuration/Config";
|
||||
import {EventBus} from "./EventBus";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent, TerrainType} from "./Game";
|
||||
import {Cell, Execution, MutableGame, Game, MutablePlayer, PlayerEvent, PlayerID, PlayerInfo, Player, TerraNullius, Tile, TileEvent, Boat, MutableBoat, BoatEvent, TerrainType, PlayerType} from "./Game";
|
||||
import {ClientID} from "./Schemas";
|
||||
import {Terrain, TerrainMap} from "./TerrainMapLoader";
|
||||
import {simpleHash} from "./Util";
|
||||
@@ -179,8 +179,8 @@ export class PlayerImpl implements MutablePlayer {
|
||||
return this.playerInfo.id
|
||||
}
|
||||
|
||||
isBot(): boolean {
|
||||
return this.playerInfo.isBot
|
||||
type(): PlayerType {
|
||||
return this.playerInfo.playerType
|
||||
}
|
||||
|
||||
setName(name: string) {
|
||||
@@ -348,7 +348,7 @@ export class GameImpl implements MutableGame {
|
||||
if (this._ticks % 100 == 0) {
|
||||
let hash = 1;
|
||||
this._players.forEach(p => {
|
||||
if (!p.info().isBot) {
|
||||
if (p.type() == PlayerType.Human) {
|
||||
console.log(`${p.toString()}`)
|
||||
}
|
||||
hash += p.hash()
|
||||
|
||||
+4
-1
@@ -1,4 +1,5 @@
|
||||
import {z} from 'zod';
|
||||
import {PlayerType} from './Game';
|
||||
|
||||
export type GameID = string
|
||||
export type ClientID = string
|
||||
@@ -24,6 +25,8 @@ export type ClientIntentMessage = z.infer<typeof ClientIntentMessageSchema>
|
||||
export type ClientJoinMessage = z.infer<typeof ClientJoinMessageSchema>
|
||||
export type ClientLeaveMessage = z.infer<typeof ClientLeaveMessageSchema>
|
||||
|
||||
const PlayerTypeSchema = z.nativeEnum(PlayerType);
|
||||
|
||||
// TODO: create Cell schema
|
||||
|
||||
export interface Lobby {
|
||||
@@ -53,7 +56,7 @@ export const AttackIntentSchema = BaseIntentSchema.extend({
|
||||
export const SpawnIntentSchema = BaseIntentSchema.extend({
|
||||
type: z.literal('spawn'),
|
||||
name: z.string(),
|
||||
isBot: z.boolean(),
|
||||
playerType: PlayerTypeSchema,
|
||||
x: z.number(),
|
||||
y: z.number(),
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Player, PlayerInfo, TerrainType, TerraNullius, Tile} from "../Game";
|
||||
import {Player, PlayerInfo, PlayerType, TerrainType, TerraNullius, Tile} from "../Game";
|
||||
import {within} from "../Util";
|
||||
import {Config, Theme} from "./Config";
|
||||
import {pastelTheme} from "./PastelTheme";
|
||||
@@ -67,7 +67,7 @@ export class DefaultConfig implements Config {
|
||||
}
|
||||
|
||||
attackAmount(attacker: Player, defender: Player | TerraNullius) {
|
||||
if (attacker.isBot()) {
|
||||
if (attacker.type() == PlayerType.Bot) {
|
||||
return attacker.troops() / 20
|
||||
} else {
|
||||
return attacker.troops() / 5
|
||||
@@ -75,7 +75,7 @@ export class DefaultConfig implements Config {
|
||||
}
|
||||
|
||||
startTroops(playerInfo: PlayerInfo): number {
|
||||
if (playerInfo.isBot) {
|
||||
if (playerInfo.playerType == PlayerType.Bot) {
|
||||
return 10000
|
||||
}
|
||||
return 10000
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Cell, Game, Tile, TileEvent} from "../Game";
|
||||
import {Cell, Game, PlayerType, Tile, TileEvent} from "../Game";
|
||||
import {PseudoRandom} from "../PseudoRandom";
|
||||
import {SpawnIntent} from "../Schemas";
|
||||
import {bfs, dist as dist, manhattanDist} from "../Util";
|
||||
@@ -40,7 +40,7 @@ export class BotSpawner {
|
||||
return {
|
||||
type: 'spawn',
|
||||
name: botName,
|
||||
isBot: true,
|
||||
playerType: PlayerType.Bot,
|
||||
x: tile.cell().x,
|
||||
y: tile.cell().y
|
||||
};
|
||||
|
||||
@@ -33,7 +33,7 @@ export class Executor {
|
||||
)
|
||||
} else if (intent.type == "spawn") {
|
||||
return new SpawnExecution(
|
||||
new PlayerInfo(intent.name, intent.isBot, intent.clientID, this.random.nextID()),
|
||||
new PlayerInfo(intent.name, intent.playerType, intent.clientID, this.random.nextID()),
|
||||
new Cell(intent.x, intent.y)
|
||||
)
|
||||
} else if (intent.type == "boat") {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo} from "../Game"
|
||||
import {Cell, Execution, MutableGame, MutablePlayer, PlayerInfo, PlayerType} from "../Game"
|
||||
import {BotExecution} from "./BotExecution"
|
||||
import {PlayerExecution} from "./PlayerExecution"
|
||||
import {getSpawnCells} from "./Util"
|
||||
@@ -41,7 +41,7 @@ export class SpawnExecution implements Execution {
|
||||
player.conquer(this.mg.tile(c))
|
||||
})
|
||||
this.mg.addExecution(new PlayerExecution(player.id()))
|
||||
if (player.isBot()) {
|
||||
if (player.type() == PlayerType.Bot) {
|
||||
this.mg.addExecution(new BotExecution(player))
|
||||
}
|
||||
this.active = false
|
||||
|
||||
Reference in New Issue
Block a user