mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-23 12:59:09 +00:00
9b2c6cc1f6
## Description: https://github.com/openfrontio/OpenFrontIO/issues/776 I've implemented upgradable structures for cities and ports. As of right now this is just meant as a QOL change for structure stacking that currently happens and no gameplay changes are intended. Structure upgrades cost the same as making a new structure of that type and function the same as making a new structure of that type. I'm putting up a draft PR for this now since adding support for SAMs and Silos will take more time to handle the cooldowns and I want to make sure I'm on the right track for getting this merged. I also still need to add bot behavior for this and re-enable min distance for structures. I didn't see translations for the UnitInfoModal so I've left that out for now. I've tested locally in a single player game so far but will document and test more thoroughly before merging.   ## 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 - [x] I understand that submitting code with bugs that could have been caught through manual testing blocks releases and new features for all contributors ## Please put your Discord username so you can be contacted if a bug or regression is found: # Poutine --------- Co-authored-by: Scott Anderson <scottanderson@users.noreply.github.com>
108 lines
3.6 KiB
TypeScript
108 lines
3.6 KiB
TypeScript
import { z } from "zod";
|
|
import { UnitType } from "./game/Game";
|
|
|
|
export const BombUnitSchema = z.union([
|
|
z.literal("abomb"),
|
|
z.literal("hbomb"),
|
|
z.literal("mirv"),
|
|
z.literal("mirvw"),
|
|
]);
|
|
export type BombUnit = z.infer<typeof BombUnitSchema>;
|
|
export type NukeType =
|
|
| UnitType.AtomBomb
|
|
| UnitType.HydrogenBomb
|
|
| UnitType.MIRV
|
|
| UnitType.MIRVWarhead;
|
|
|
|
export const unitTypeToBombUnit = {
|
|
[UnitType.AtomBomb]: "abomb",
|
|
[UnitType.HydrogenBomb]: "hbomb",
|
|
[UnitType.MIRV]: "mirv",
|
|
[UnitType.MIRVWarhead]: "mirvw",
|
|
} as const satisfies Record<NukeType, BombUnit>;
|
|
|
|
export const BoatUnitSchema = z.union([z.literal("trade"), z.literal("trans")]);
|
|
export type BoatUnit = z.infer<typeof BoatUnitSchema>;
|
|
export type BoatUnitType = UnitType.TradeShip | UnitType.TransportShip;
|
|
|
|
// export const unitTypeToBoatUnit = {
|
|
// [UnitType.TradeShip]: "trade",
|
|
// [UnitType.TransportShip]: "trans",
|
|
// } as const satisfies Record<BoatUnitType, BoatUnit>;
|
|
|
|
export const OtherUnitSchema = z.union([
|
|
z.literal("city"),
|
|
z.literal("defp"),
|
|
z.literal("port"),
|
|
z.literal("wshp"),
|
|
z.literal("silo"),
|
|
z.literal("saml"),
|
|
]);
|
|
export type OtherUnit = z.infer<typeof OtherUnitSchema>;
|
|
export type OtherUnitType =
|
|
| UnitType.City
|
|
| UnitType.DefensePost
|
|
| UnitType.MissileSilo
|
|
| UnitType.Port
|
|
| UnitType.SAMLauncher
|
|
| UnitType.Warship;
|
|
|
|
export const unitTypeToOtherUnit = {
|
|
[UnitType.City]: "city",
|
|
[UnitType.DefensePost]: "defp",
|
|
[UnitType.MissileSilo]: "silo",
|
|
[UnitType.Port]: "port",
|
|
[UnitType.SAMLauncher]: "saml",
|
|
[UnitType.Warship]: "wshp",
|
|
} as const satisfies Record<OtherUnitType, OtherUnit>;
|
|
|
|
// Attacks
|
|
export const ATTACK_INDEX_SENT = 0; // Outgoing attack troops
|
|
export const ATTACK_INDEX_RECV = 1; // Incmoing attack troops
|
|
export const ATTACK_INDEX_CANCEL = 2; // Cancelled attack troops
|
|
|
|
// Boats
|
|
export const BOAT_INDEX_SENT = 0; // Boats launched
|
|
export const BOAT_INDEX_ARRIVE = 1; // Boats arrived
|
|
export const BOAT_INDEX_CAPTURE = 2; // Boats captured
|
|
export const BOAT_INDEX_DESTROY = 3; // Boats destroyed
|
|
|
|
// Bombs
|
|
export const BOMB_INDEX_LAUNCH = 0; // Bombs launched
|
|
export const BOMB_INDEX_LAND = 1; // Bombs landed
|
|
export const BOMB_INDEX_INTERCEPT = 2; // Bombs intercepted
|
|
|
|
// Gold
|
|
export const GOLD_INDEX_WORK = 0; // Gold earned by workers
|
|
export const GOLD_INDEX_WAR = 1; // Gold earned by conquering players
|
|
export const GOLD_INDEX_TRADE = 2; // Gold earned by trade ships
|
|
export const GOLD_INDEX_STEAL = 3; // Gold earned by capturing trade ships
|
|
|
|
// Other Units
|
|
export const OTHER_INDEX_BUILT = 0; // Structures and warships built
|
|
export const OTHER_INDEX_DESTROY = 1; // Structures and warships destroyed
|
|
export const OTHER_INDEX_CAPTURE = 2; // Structures captured
|
|
export const OTHER_INDEX_LOST = 3; // Structures/warships destroyed/captured by others
|
|
export const OTHER_INDEX_UPGRADE = 4; // Structures upgraded
|
|
|
|
const BigIntStringSchema = z.preprocess((val) => {
|
|
if (typeof val === "string" && /^\d+$/.test(val)) return BigInt(val);
|
|
if (typeof val === "bigint") return val;
|
|
return val;
|
|
}, z.bigint());
|
|
|
|
const AtLeastOneNumberSchema = BigIntStringSchema.array().min(1);
|
|
export type AtLeastOneNumber = z.infer<typeof AtLeastOneNumberSchema>;
|
|
|
|
export const PlayerStatsSchema = z
|
|
.object({
|
|
attacks: AtLeastOneNumberSchema.optional(),
|
|
betrayals: BigIntStringSchema.optional(),
|
|
boats: z.record(BoatUnitSchema, AtLeastOneNumberSchema).optional(),
|
|
bombs: z.record(BombUnitSchema, AtLeastOneNumberSchema).optional(),
|
|
gold: AtLeastOneNumberSchema.optional(),
|
|
units: z.record(OtherUnitSchema, AtLeastOneNumberSchema).optional(),
|
|
})
|
|
.optional();
|
|
export type PlayerStats = z.infer<typeof PlayerStatsSchema>;
|