2019-04-01 11:23:25 +02:00
|
|
|
/**
|
|
|
|
* React Subcomponent for displaying a location's UI, when that location is a gym
|
|
|
|
*
|
|
|
|
* This subcomponent renders all of the buttons for training at the gym
|
|
|
|
*/
|
|
|
|
import * as React from "react";
|
|
|
|
|
|
|
|
import { Location } from "../Location";
|
|
|
|
|
2021-04-20 03:26:51 +02:00
|
|
|
import { CONSTANTS } from "../../Constants";
|
|
|
|
import { IPlayer } from "../../PersonObjects/IPlayer";
|
|
|
|
import { getServer } from "../../Server/ServerHelpers";
|
|
|
|
import { Server } from "../../Server/Server";
|
|
|
|
import { SpecialServerIps } from "../../Server/SpecialServerIps";
|
2019-04-01 11:23:25 +02:00
|
|
|
|
|
|
|
import { numeralWrapper } from "../../ui/numeralFormat";
|
|
|
|
import { StdButton } from "../../ui/React/StdButton";
|
2021-03-31 06:45:21 +02:00
|
|
|
import { Money } from "../../ui/React/Money";
|
2019-04-01 11:23:25 +02:00
|
|
|
|
|
|
|
type IProps = {
|
|
|
|
loc: Location;
|
|
|
|
p: IPlayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class GymLocation extends React.Component<IProps, any> {
|
2019-04-04 02:08:11 +02:00
|
|
|
/**
|
|
|
|
* Stores button styling that sets them all to block display
|
|
|
|
*/
|
|
|
|
btnStyle: object;
|
|
|
|
|
2019-04-01 11:23:25 +02:00
|
|
|
constructor(props: IProps) {
|
|
|
|
super(props);
|
|
|
|
|
2019-04-04 02:08:11 +02:00
|
|
|
this.btnStyle = { display: "block" };
|
|
|
|
|
2019-04-01 11:23:25 +02:00
|
|
|
this.trainStrength = this.trainStrength.bind(this);
|
|
|
|
this.trainDefense = this.trainDefense.bind(this);
|
|
|
|
this.trainDexterity = this.trainDexterity.bind(this);
|
|
|
|
this.trainAgility = this.trainAgility.bind(this);
|
2021-04-20 03:26:51 +02:00
|
|
|
|
|
|
|
this.calculateCost = this.calculateCost.bind(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
calculateCost(): number {
|
|
|
|
const ip = SpecialServerIps.getIp(this.props.loc.name);
|
|
|
|
console.log(`ip: ${ip}`);
|
|
|
|
const server = getServer(ip);
|
|
|
|
if(server == null || !server.hasOwnProperty('manuallyHacked')) return this.props.loc.costMult;
|
|
|
|
const discount = (server as Server).manuallyHacked? 0.9 : 1;
|
|
|
|
return this.props.loc.costMult * discount;
|
2019-04-01 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
train(stat: string) {
|
|
|
|
const loc = this.props.loc;
|
2021-04-20 03:26:51 +02:00
|
|
|
this.props.p.startClass(this.calculateCost(), loc.expMult, stat);
|
2019-04-01 11:23:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
trainStrength() {
|
|
|
|
return this.train(CONSTANTS.ClassGymStrength);
|
|
|
|
}
|
|
|
|
|
|
|
|
trainDefense() {
|
|
|
|
return this.train(CONSTANTS.ClassGymDefense);
|
|
|
|
}
|
|
|
|
|
|
|
|
trainDexterity() {
|
|
|
|
return this.train(CONSTANTS.ClassGymDexterity);
|
|
|
|
}
|
|
|
|
|
|
|
|
trainAgility() {
|
|
|
|
return this.train(CONSTANTS.ClassGymAgility);
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2021-04-20 03:26:51 +02:00
|
|
|
const cost = CONSTANTS.ClassGymBaseCost * this.calculateCost();
|
2019-04-01 11:23:25 +02:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div>
|
|
|
|
<StdButton
|
|
|
|
onClick={this.trainStrength}
|
2019-04-04 02:08:11 +02:00
|
|
|
style={this.btnStyle}
|
2021-03-31 06:45:21 +02:00
|
|
|
text={<>Train Strength ({Money(cost)} / sec)</>}
|
2019-04-01 11:23:25 +02:00
|
|
|
/>
|
|
|
|
<StdButton
|
|
|
|
onClick={this.trainDefense}
|
2019-04-04 02:08:11 +02:00
|
|
|
style={this.btnStyle}
|
2021-03-31 06:45:21 +02:00
|
|
|
text={<>Train Defense ({Money(cost)} / sec)</>}
|
2019-04-01 11:23:25 +02:00
|
|
|
/>
|
|
|
|
<StdButton
|
|
|
|
onClick={this.trainDexterity}
|
2019-04-04 02:08:11 +02:00
|
|
|
style={this.btnStyle}
|
2021-03-31 06:45:21 +02:00
|
|
|
text={<>Train Dexterity ({Money(cost)} / sec)</>}
|
2019-04-01 11:23:25 +02:00
|
|
|
/>
|
|
|
|
<StdButton
|
|
|
|
onClick={this.trainAgility}
|
2019-04-04 02:08:11 +02:00
|
|
|
style={this.btnStyle}
|
2021-03-31 06:45:21 +02:00
|
|
|
text={<>Train Agility ({Money(cost)} / sec)</>}
|
2019-04-01 11:23:25 +02:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|