Initial commit for Location Code refactor

This commit is contained in:
danielyxie 2019-03-27 01:31:47 -07:00
parent b4057fcb26
commit 75bc34208c
13 changed files with 541 additions and 117 deletions

@ -3,7 +3,7 @@ import { MaterialSizes } from "./MaterialSizes";
import { ProductRatingWeights,
IProductRatingWeight } from "./ProductRatingWeights";
import { Cities } from "../Locations/Cities";
import { CityName } from "../Locations/data/CityNames";
import { IMap } from "../types";
import { Generic_fromJSON,

@ -11,7 +11,7 @@ import { overviewPage } from "./Routing";
import { OfficeSpace } from "../Corporation";
import { Cities } from "../../Locations/Cities";
import { CityName } from "../../Locations/data/Cities";
export class MainPanel extends BaseReactComponent {
constructor(props) {
@ -19,7 +19,7 @@ export class MainPanel extends BaseReactComponent {
this.state = {
division: "",
city: Cities.Sector12,
city: CityName.Sector12,
}
}

@ -1,90 +0,0 @@
import { IMap } from "./types";
/**
* Display Location Content when visiting somewhere in the World
*/
// tslint:disable-next-line:variable-name
export const Locations: IMap<string> = {
// Cities
Aevum: "Aevum",
Chongqing: "Chongqing",
Ishima: "Ishima",
NewTokyo: "New Tokyo",
Sector12: "Sector-12",
Volhaven: "Volhaven",
// Aevum Locations
AevumAeroCorp: "AeroCorp",
AevumBachmanAndAssociates: "Bachman & Associates",
AevumClarkeIncorporated: "Clarke Incorporated",
AevumCrushFitnessGym: "Crush Fitness Gym",
AevumECorp: "ECorp",
AevumFulcrumTechnologies: "Fulcrum Technologies",
AevumGalacticCybersystems: "Galactic Cybersystems",
AevumNetLinkTechnologies: "NetLink Technologies",
AevumPolice: "Aevum Police Headquarters",
AevumRhoConstruction: "Rho Construction",
AevumSlums: "Aevum Slums",
AevumSnapFitnessGym: "Snap Fitness Gym",
AevumSummitUniversity: "Summit University",
AevumTravelAgency: "Aevum Travel Agency",
AevumWatchdogSecurity: "Watchdog Security",
// Chongqing locations
ChongqingKuaiGongInternational: "KuaiGong International",
ChongqingSlums: "Chongqing Slums",
ChongqingSolarisSpaceSystems: "Solaris Space Systems",
ChongqingTravelAgency: "Chongqing Travel Agency",
// Sector 12
Sector12AlphaEnterprises: "Alpha Enterprises",
Sector12BladeIndustries: "Blade Industries",
Sector12CIA: "Central Intelligence Agency",
Sector12CarmichaelSecurity: "Carmichael Security",
Sector12CityHall: "Sector-12 City Hall",
Sector12DeltaOne: "DeltaOne",
Sector12FoodNStuff: "FoodNStuff",
Sector12FourSigma: "Four Sigma",
Sector12IcarusMicrosystems: "Icarus Microsystems",
Sector12IronGym: "Iron Gym",
Sector12JoesGuns: "Joe's Guns",
Sector12MegaCorp: "MegaCorp",
Sector12NSA: "National Security Agency",
Sector12PowerhouseGym: "Powerhouse Gym",
Sector12RothmanUniversity: "Rothman University",
Sector12Slums: "Sector-12 Slums",
Sector12TravelAgency: "Sector-12 Travel Agency",
Sector12UniversalEnergy: "Universal Energy",
// New Tokyo
NewTokyoDefComm: "DefComm",
NewTokyoGlobalPharmaceuticals: "Global Pharmaceuticals",
NewTokyoNoodleBar: "Noodle Bar",
NewTokyoSlums: "New Tokyo Slums",
NewTokyoTravelAgency: "New Tokyo Travel Agency",
NewTokyoVitaLife: "VitaLife",
// Ishima
IshimaNovaMedical: "Nova Medical",
IshimaOmegaSoftware: "Omega Software",
IshimaSlums: "Ishima Slums",
IshimaStormTechnologies: "Storm Technologies",
IshimaTravelAgency: "Ishima Travel Agency",
// Volhaven
VolhavenCompuTek: "CompuTek",
VolhavenHeliosLabs: "Helios Labs",
VolhavenLexoCorp: "LexoCorp",
VolhavenMilleniumFitnessGym: "Millenium Fitness Gym",
VolhavenNWO: "NWO",
VolhavenOmniTekIncorporated: "OmniTek Incorporated",
VolhavenOmniaCybersystems: "Omnia Cybersystems",
VolhavenSlums: "Volhaven Slums",
VolhavenSysCoreSecurities: "SysCore Securities",
VolhavenTravelAgency: "Volhaven Travel Agency",
VolhavenZBInstituteOfTechnology: "ZB Institute of Technology",
// Generic locations
Hospital: "Hospital",
WorldStockExchange: "World Stock Exchange",
};

@ -1,14 +1,7 @@
import { IMap } from "../types";
/**
* Display Location Content when visiting somewhere in the World
* Map of all Cities in the game
* Key = City Name, Value = City object
*/
// tslint:disable-next-line:variable-name
export const Cities: IMap<string> = {
Aevum: "Aevum",
Chongqing: "Chongqing",
Ishima: "Ishima",
NewTokyo: "New Tokyo",
Sector12: "Sector-12",
Volhaven: "Volhaven",
};
export interface IMetadata = {
name: string;
}

22
src/Locations/City.ts Normal file

@ -0,0 +1,22 @@
/**
* Class representing a City in the game
*/
import { Location } from "./Location";
import { CityName } from "./data/CityNames";
export class City {
/**
* List of all locations in this city
*/
locations: Location[];
/**
* Name of this city
*/
name: CityName;
constructor(name: CityName, locations: Location[]) {
this.name = name;
this.locations = locations;
}
}

38
src/Locations/Location.ts Normal file

@ -0,0 +1,38 @@
/**
* Class representing a visitable location in the world
*/
import { CityName } from "./data/CityNames";
import { LocationName } from "./data/LocationNames";
import { LocationType } from "./LocationTypeEnum";
export interface IConstructorParams {
city?: CityName | null;
name?: LocationName;
types?: LocationType[];
techVendorMaxRam?: number;
}
export class Location {
// Name of city this location is in
// If this property is null, it means this is a generic Location that
// is available in all cities
city: CityName | null = null;
// Identifier for location
name: LocationName = LocationName.Void;
// List of what type(s) this location is
// A location can be multiple types (e.g. company and tech vendor)
types: LocationType[] = [];
// Tech vendors allow you to purchase servers.
// This property defines the max RAM server you can purchase from this vendor
techVendorMaxRam: number = 0;
constructor(p: IConstructorParams) {
if (p.city) { this.city = p.city; }
if (p.name) { this.name = p.name; }
if (p.types) { this.types = p.types; }
if (p.techVendorMaxRam) { this.techVendorMaxRam = p.techVendorMaxRam; }
}
}

@ -0,0 +1,14 @@
/**
* Enum defining the different types of possible locations
*/
export enum LocationType {
CityHall,
Company,
Gym,
Hospital,
Slums,
StockMarket,
TechVendor,
TravelAgency,
University,
}

@ -0,0 +1,27 @@
/**
* Map of all Locations in the game
* Key = Location name, value = Location object
*/
import { Location,
IConstructorParams } from "./Location";
import { LocationsMetadata } from "./data/LocationsMetadata";
import { IMap } from "../types";
export const Locations: IMap<Location> = {};
function constructLocation(p: IConstructorParams) {
if (!p.name) {
throw new Error(`Invalid constructor parameters for Location. No 'name' property`);
}
if (Locations[p.name] instanceof Location) {
console.warn(`Property with name ${p.name} already exists and is being overwritten`);
}
Locations[p.name] = new Location(p);
}
for (const metadata of LocationsMetadata {
constructLocation(metadata);
}

@ -0,0 +1,12 @@
/**
* All possible Cities in the game. Names only, not actual "City" object
* Implemented as an enum for typing purposes
*/
export enum CityName {
Aevum = "Aevum",
Chongqing = "Chongqing",
Ishima = "Ishima",
NewTokyo = "New Tokyo",
Sector12 = "Sector-12",
Volhaven = "Volhaven",
};

@ -0,0 +1,92 @@
/**
* Names of all locations
*/
export enum LocationName {
// Cities
Aevum = "Aevum",
Chongqing = "Chongqing",
Ishima = "Ishima",
NewTokyo = "New Tokyo",
Sector12 = "Sector-12",
Volhaven = "Volhaven",
// Aevum Locations
AevumAeroCorp = "AeroCorp",
AevumBachmanAndAssociates = "Bachman & Associates",
AevumClarkeIncorporated = "Clarke Incorporated",
AevumCrushFitnessGym = "Crush Fitness Gym",
AevumECorp = "ECorp",
AevumFulcrumTechnologies = "Fulcrum Technologies",
AevumGalacticCybersystems = "Galactic Cybersystems",
AevumNetLinkTechnologies = "NetLink Technologies",
AevumPolice = "Aevum Police Headquarters",
AevumRhoConstruction = "Rho Construction",
AevumSlums = "Aevum Slums", // TODO Delete this and other Slums locations
AevumSnapFitnessGym = "Snap Fitness Gym",
AevumSummitUniversity = "Summit University",
AevumTravelAgency = "Aevum Travel Agency", // TODO Delete this and other travel agency locations
AevumWatchdogSecurity = "Watchdog Security",
// Chongqing locations
ChongqingKuaiGongInternational = "KuaiGong International",
ChongqingSlums = "Chongqing Slums",
ChongqingSolarisSpaceSystems = "Solaris Space Systems",
ChongqingTravelAgency = "Chongqing Travel Agency",
// Sector 12
Sector12AlphaEnterprises = "Alpha Enterprises",
Sector12BladeIndustries = "Blade Industries",
Sector12CIA = "Central Intelligence Agency",
Sector12CarmichaelSecurity = "Carmichael Security",
Sector12CityHall = "Sector-12 City Hall",
Sector12DeltaOne = "DeltaOne",
Sector12FoodNStuff = "FoodNStuff",
Sector12FourSigma = "Four Sigma",
Sector12IcarusMicrosystems = "Icarus Microsystems",
Sector12IronGym = "Iron Gym",
Sector12JoesGuns = "Joe's Guns",
Sector12MegaCorp = "MegaCorp",
Sector12NSA = "National Security Agency",
Sector12PowerhouseGym = "Powerhouse Gym",
Sector12RothmanUniversity = "Rothman University",
Sector12Slums = "Sector-12 Slums",
Sector12TravelAgency = "Sector-12 Travel Agency",
Sector12UniversalEnergy = "Universal Energy",
// New Tokyo
NewTokyoDefComm = "DefComm",
NewTokyoGlobalPharmaceuticals = "Global Pharmaceuticals",
NewTokyoNoodleBar = "Noodle Bar",
NewTokyoSlums = "New Tokyo Slums",
NewTokyoTravelAgency = "New Tokyo Travel Agency",
NewTokyoVitaLife = "VitaLife",
// Ishima
IshimaNovaMedical = "Nova Medical",
IshimaOmegaSoftware = "Omega Software",
IshimaSlums = "Ishima Slums",
IshimaStormTechnologies = "Storm Technologies",
IshimaTravelAgency = "Ishima Travel Agency",
// Volhaven
VolhavenCompuTek = "CompuTek",
VolhavenHeliosLabs = "Helios Labs",
VolhavenLexoCorp = "LexoCorp",
VolhavenMilleniumFitnessGym = "Millenium Fitness Gym",
VolhavenNWO = "NWO",
VolhavenOmniTekIncorporated = "OmniTek Incorporated",
VolhavenOmniaCybersystems = "Omnia Cybersystems",
VolhavenSlums = "Volhaven Slums",
VolhavenSysCoreSecurities = "SysCore Securities",
VolhavenTravelAgency = "Volhaven Travel Agency",
VolhavenZBInstituteOfTechnology = "ZB Institute of Technology",
// Generic locations
Hospital = "Hospital",
Slums = "The Slums",
TravelAgency = "Travel Agency",
WorldStockExchange = "World Stock Exchange",
// Default name for Location objects
Void = "The Void",
};

@ -0,0 +1,316 @@
/**
* Metadata for constructing Location objects for all Locations
* in the game
*/
import { CityName } from "./CityNames";
import { LocationName } from "./LocationNames";
import { IConstructorParams } from "../Location";
export const LocationsMetadata: IConstructorParams[] = [
{
city: CityName.Aevum,
name: LocationName.AevumAeroCorp,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumBachmanAndAssociates,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumClarkeIncorporated,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumCrushFitnessGym,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumECorp,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumFulcrumTechnologies,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumGalacticCybersystems,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumNetLinkTechnologies
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumPolice,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumRhoConstruction,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumSnapFitnessGym,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumSummitUniversity,
types:
techVendorMaxRam:
},
{
city: CityName.Aevum,
name: LocationName.AevumWatchdogSecurity,
types:
techVendorMaxRam:
},
{
city: CityName.Chongqing,
name: LocationName.ChongqingKuaiGongInternational,
types:
techVendorMaxRam:
},
{
city: CityName.Chongqing,
name: LocationName.ChongqingSolarisSpaceSystems,
types:
techVendorMaxRam:
},
{
city: CityName.Ishima,
name: LocationName.IshimaNovaMedical,
types:
techVendorMaxRam:
},
{
city: CityName.Ishima,
name: LocationName.IshimaOmegaSoftware,
types:
techVendorMaxRam:
},
{
city: CityName.Ishima,
name: LocationName.IshimaStormTechnologies,
types:
techVendorMaxRam:
},
{
city: CityName.NewTokyo,
name: LocationName.NewTokyoDefComm,
types:
techVendorMaxRam:
},
{
city: CityName.NewTokyo,
name: LocationName.NewTokyoGlobalPharmaceuticals,
types:
techVendorMaxRam:
},
{
city: CityName.NewTokyo,
name: LocationName.NewTokyoNoodleBar,
types:
techVendorMaxRam:
},
{
city: CityName.NewTokyo,
name: LocationName.NewTokyoVitaLife,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12AlphaEnterprises,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12BladeIndustries,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12CIA,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12CarmichaelSecurity,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12CityHall,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12DeltaOne,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12FoodNStuff,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12FourSigma,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12IcarusMicrosystems,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12IronGym,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12JoesGuns,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12MegaCorp,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12NSA,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12PowerhouseGym,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12RothmanUniversity,
types:
techVendorMaxRam:
},
{
city: CityName.Sector12,
name: LocationName.Sector12UniversalEnergy,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenCompuTek,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenHeliosLabs,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenLexoCorp,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenMilleniumFitnessGym,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenNWO,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenOmniTekIncorporated,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenOmniaCybersystems,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenSysCoreSecurities,
types:
techVendorMaxRam:
},
{
city: CityName.Volhaven,
name: LocationName.VolhavenZBInstituteOfTechnology,
types:
techVendorMaxRam:
},
{
city: null,
name: LocationName.Hospital,
types:
techVendorMaxRam:
},
{
city: null,
name: LocationName.Slums,
types:
techVendorMaxRam:
},
{
city: null,
name: LocationName.TravelAgency,
types:
techVendorMaxRam:
},
{
city: null,
name: LocationName.WorldStockExchange,
types:
techVendorMaxRam:
},
];

@ -3,7 +3,7 @@ import { Augmentation } from "../Augmentation/Augmentation";
import { Augmentations } from "../Augmentation/Augmentations";
import { IPlayerOwnedAugmentation } from "../Augmentation/PlayerOwnedAugmentation";
import { BitNodeMultipliers } from "../BitNode/BitNodeMultipliers";
import { Cities } from "../Locations/Cities";
import { CityName } from "../Locations/data/CityNames";
import { CONSTANTS } from "../Constants";
// Interface that defines a generic object used to track experience/money
@ -105,7 +105,7 @@ export abstract class Person {
/**
* City that the person is in
*/
city: string = Cities.Sector12;
city: string = CityName.Sector12;
constructor() {}

@ -20,7 +20,7 @@ import { BitNodeMultipliers } from "../../BitNode/BitNodeMultipliers";
import { Crime } from "../../Crime/Crime";
import { Crimes } from "../../Crime/Crimes";
import { Cities } from "../../Locations/Cities";
import { CityName } from "../../Locations/data/CityNames";
import { Companies } from "../../Company/Companies";
import { Company } from "../../Company/Company";
@ -547,19 +547,19 @@ export class Sleeve extends Person {
let expMult: number = 1;
switch (universityName.toLowerCase()) {
case Locations.AevumSummitUniversity.toLowerCase():
if (this.city !== Cities.Aevum) { return false; }
if (this.city !== CityName.Aevum) { return false; }
this.currentTaskLocation = Locations.AevumSummitUniversity;
costMult = 4;
expMult = 3;
break;
case Locations.Sector12RothmanUniversity.toLowerCase():
if (this.city !== Cities.Sector12) { return false; }
if (this.city !== CityName.Sector12) { return false; }
this.currentTaskLocation = Locations.Sector12RothmanUniversity;
costMult = 3;
expMult = 2;
break;
case Locations.VolhavenZBInstituteOfTechnology.toLowerCase():
if (this.city !== Cities.Volhaven) { return false; }
if (this.city !== CityName.Volhaven) { return false; }
this.currentTaskLocation = Locations.VolhavenZBInstituteOfTechnology;
costMult = 5;
expMult = 4;
@ -613,7 +613,7 @@ export class Sleeve extends Person {
* Travel to another City. Costs money from player
*/
travel(p: IPlayer, newCity: string): boolean {
if (Cities[newCity] == null) {
if (CityName[newCity] == null) {
console.error(`Invalid city ${newCity} passed into Sleeve.travel()`);
return false;
}
@ -747,31 +747,31 @@ export class Sleeve extends Person {
let expMult: number = 1;
switch (gymName.toLowerCase()) {
case Locations.AevumCrushFitnessGym.toLowerCase():
if (this.city != Cities.Aevum) { return false; }
if (this.city != CityName.Aevum) { return false; }
this.currentTaskLocation = Locations.AevumCrushFitnessGym;
costMult = 3;
expMult = 2;
break;
case Locations.AevumSnapFitnessGym.toLowerCase():
if (this.city != Cities.Aevum) { return false; }
if (this.city != CityName.Aevum) { return false; }
this.currentTaskLocation = Locations.AevumSnapFitnessGym;
costMult = 10;
expMult = 5;
break;
case Locations.Sector12IronGym.toLowerCase():
if (this.city != Cities.Sector12) { return false; }
if (this.city != CityName.Sector12) { return false; }
this.currentTaskLocation = Locations.Sector12IronGym;
costMult = 1;
expMult = 1;
break;
case Locations.Sector12PowerhouseGym.toLowerCase():
if (this.city != Cities.Sector12) { return false; }
if (this.city != CityName.Sector12) { return false; }
this.currentTaskLocation = Locations.Sector12PowerhouseGym;
costMult = 20;
expMult = 10;
break;
case Locations.VolhavenMilleniumFitnessGym:
if (this.city != Cities.Volhaven) { return false; }
if (this.city != CityName.Volhaven) { return false; }
this.currentTaskLocation = Locations.VolhavenMilleniumFitnessGym;
costMult = 7;
expMult = 4;