MISC: Refactor code of traveling and going to location (#1365)

This commit is contained in:
catloversg
2024-06-09 03:52:10 +07:00
committed by GitHub
parent b8f03cb50b
commit a354867fc4
8 changed files with 38 additions and 34 deletions
@@ -531,20 +531,23 @@ export function gainCodingContractReward(
}
}
export function travel(this: PlayerObject, to: CityName): boolean {
if (Cities[to] == null) {
console.warn(`Player.travel() called with invalid city: ${to}`);
export function travel(this: PlayerObject, cityName: CityName): boolean {
if (Cities[cityName] == null) {
throw new Error(`Player.travel() was called with an invalid city: ${cityName}`);
}
if (!this.canAfford(CONSTANTS.TravelCost)) {
return false;
}
this.city = to;
this.loseMoney(CONSTANTS.TravelCost, "other");
this.city = cityName;
return true;
}
export function gotoLocation(this: PlayerObject, to: LocationName): boolean {
if (Locations[to] == null) {
console.warn(`Player.gotoLocation() called with invalid location: ${to}`);
return false;
throw new Error(`Player.gotoLocation() was called with an invalid location: ${to}`);
}
this.location = to;