import { generateUrl } from '../components/server/fetchers'; // Ethics Data should be stored differently after Game 15, class will stil be needed for compat reasons afterwards export class EthicsDataG15 { // Array index determines fanatic or regular, Index value represents number of occurences private data: Array = [0] constructor(data: Array) { this.data[Scale.normal] = data[0], this.data[Scale.fanatic] = data[1] } sum(weigthed: boolean): number { let sum = 0; // skip 0 index since it isn't used this.data.slice(1, this.data.length).forEach((value, index) => { // Since the index is accessed via scale enum this works, if not weighted override to 1 let factor = index + 1; if (!weigthed) { factor = 1; } sum = sum + value * factor; }); return sum; } sumRegular(): number { return this.data[Scale.normal]; } } export enum Ethics { Egalitarian = 0, Authoritarian = 1, Militarist = 2, Pacifist = 3, Xenophobe = 4, Xenophile = 5, Competitive = 6, Cooperative = 7, Elitist = 8, Pluralist = 9, Materialist = 10, Spiritualist = 11, Ecologist = 12, Industrialist = 13, } export enum Scale { normal = 1, fanatic = 2, } export enum Species { Humanoid = 0, Mammalian = 1, Reptilian = 2, Avian = 3, Arthropod = 4, Molluscoid = 5, Fungoid = 6, Plantoid = 7, Lithoid = 8, Necroid = 9, Aquatic = 10, Toxoid = 11, Machine = 12, } export type Game = { id: number, name: string } export type GameGroup = { id: number, game_id: number, name: string } export class Empire { id: number = 0; group_id: number = 0; group_game_id: number = 0; private discord_user: string | undefined; private empire_name: string | undefined; gestalt: boolean = false; empire_portrait_group_id: number = 0; empire_portrait_id: number = 0; ethic_ids: number[] = []; async getEthics() { let tmpEthics = await fetch( generateUrl('/empire_ethics', [ { key: "empires_id", val: this.id }, { key: "empires_group_id", val: this.group_id }, { key: "empires_group_game_id", val: this.group_game_id }] )).then((res) => res.json()); tmpEthics.forEach((empireEthic: { empires_id: number, empires_group_id: number, empires_group_name_id: number, ethics_id: number }) => { this.ethic_ids.push(empireEthic.ethics_id) }); } } export type Ethic = { id: number, name: string, fanatic: boolean } export type GameData = { info: Game; groups: GameGroup[]; empires: Empire[]; }