mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-07-09 12:55:44 +00:00
@@ -4,16 +4,11 @@ import { PseudoRandom } from "../PseudoRandom";
|
||||
import { GameID } from "../Schemas";
|
||||
import { simpleHash } from "../Util";
|
||||
import { SpawnExecution } from "./SpawnExecution";
|
||||
import {
|
||||
COMMUNITY_FULL_ELF_NAMES,
|
||||
COMMUNITY_PREFIXES,
|
||||
SPECIAL_FULL_ELF_NAMES,
|
||||
} from "./utils/BotNames";
|
||||
import { BOT_NAME_PREFIXES, BOT_NAME_SUFFIXES } from "./utils/BotNames";
|
||||
|
||||
export class BotSpawner {
|
||||
private random: PseudoRandom;
|
||||
private bots: SpawnExecution[] = [];
|
||||
private nameIndex = 0;
|
||||
|
||||
constructor(
|
||||
private gs: Game,
|
||||
@@ -29,13 +24,9 @@ export class BotSpawner {
|
||||
console.log("too many retries while spawning bots, giving up");
|
||||
return this.bots;
|
||||
}
|
||||
const candidate = this.nextCandidateName();
|
||||
const spawn = this.spawnBot(candidate.name);
|
||||
const botName = this.randomBotName();
|
||||
const spawn = this.spawnBot(botName);
|
||||
if (spawn !== null) {
|
||||
// Only use candidate name once bot successfully spawned
|
||||
if (candidate.source === "list") {
|
||||
this.nameIndex++;
|
||||
}
|
||||
this.bots.push(spawn);
|
||||
} else {
|
||||
tries++;
|
||||
@@ -60,42 +51,10 @@ export class BotSpawner {
|
||||
);
|
||||
}
|
||||
|
||||
private nextCandidateName(): {
|
||||
name: string;
|
||||
source: "list" | "random";
|
||||
} {
|
||||
if (this.bots.length < 20) {
|
||||
//first few usually overwritten by Nation spawn
|
||||
return { name: this.getRandomElf(), source: "random" };
|
||||
}
|
||||
|
||||
if (this.nameIndex < COMMUNITY_FULL_ELF_NAMES.length) {
|
||||
return {
|
||||
name: COMMUNITY_FULL_ELF_NAMES[this.nameIndex],
|
||||
source: "list",
|
||||
};
|
||||
}
|
||||
const specialOffset = COMMUNITY_FULL_ELF_NAMES.length;
|
||||
if (this.nameIndex < specialOffset + SPECIAL_FULL_ELF_NAMES.length) {
|
||||
return {
|
||||
name: SPECIAL_FULL_ELF_NAMES[this.nameIndex - specialOffset],
|
||||
source: "list",
|
||||
};
|
||||
}
|
||||
const prefixOffset = specialOffset + SPECIAL_FULL_ELF_NAMES.length;
|
||||
if (this.nameIndex < prefixOffset + COMMUNITY_PREFIXES.length) {
|
||||
return {
|
||||
name: `${COMMUNITY_PREFIXES[this.nameIndex - prefixOffset]} the Elf`,
|
||||
source: "list",
|
||||
};
|
||||
}
|
||||
|
||||
return { name: this.getRandomElf(), source: "random" };
|
||||
}
|
||||
|
||||
private getRandomElf(): string {
|
||||
const suffixNumber = this.random.nextInt(1, 10001);
|
||||
return `Elf ${suffixNumber}`;
|
||||
private randomBotName(): string {
|
||||
const prefixIndex = this.random.nextInt(0, BOT_NAME_PREFIXES.length);
|
||||
const suffixIndex = this.random.nextInt(0, BOT_NAME_SUFFIXES.length);
|
||||
return `${BOT_NAME_PREFIXES[prefixIndex]} ${BOT_NAME_SUFFIXES[suffixIndex]}`;
|
||||
}
|
||||
|
||||
private randTile(): TileRef {
|
||||
|
||||
Reference in New Issue
Block a user