+ increaseStat(stat) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (this.player === null) {
+ throw new Error('Not authenticated');
+ }
+ const res = yield this.post(`/v1/accounts/${this.player.id}/stat`, {
+ stat: stat
+ });
+ this.setPlayer(res.payload);
+ return res.payload;
+ });
+ }
+ startFight(fightId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (this.player === null) {
+ throw new Error('Not authenticated');
+ }
+ const res = yield this.post(`/v1/accounts/${this.player.id}/fight/${fightId}`);
+ if (!res.payload.id) {
+ throw new Error('Invalid fight!');
+ }
+ return res.payload;
+ });
+ }
+ fight(fightId) {
+ return __awaiter(this, void 0, void 0, function* () {
+ if (this.player === null) {
+ throw new Error('Not authenticated');
+ }
+ yield this.startFight(fightId);
+ const res = yield this.post(`/v1/accounts/${this.player.id}/fight/${fightId}/round`, {
+ action: 'Fight'
+ });
+ const output = res.payload;
+ this.setPlayer(output.player);
+ console.log(output);
+ const participants = {
+ [output.player.id]: output.player.username,
+ [output.monster.id]: output.monster.name
+ };
+ output.roundData.map(round => {
+ const p1 = participants[round.attacker];
+ const p2 = participants[round.defender];
+ const css = round.attacker === output.player.id ? 'text-secondary' : 'text-info';
+ let str = `<span class="${css}">${p1}</span> dealt <span class="text-danger">${round.damage} damage</span> to ${p2}`;
+ return str;
+ }).forEach(a => (0, components_1.actionLog)(a, false));
+ if (output.winner === 'player') {
+ (0, components_1.actionLog)(`<span class="text-success">You defeated the ${output.monster.name}</span>`, false);
+ }
+ else {
+ (0, components_1.actionLog)(`<span class="text-danger">You were defeated by the ${output.monster.name}</span>`, false);
+ }
+ Object.keys(output.reward).forEach(rewardType => {
+ switch (rewardType) {
+ case 'exp':
+ (0, components_1.actionLog)(`You gained <span class="text-info">${output.reward.exp}</span> Exp`, false);
+ break;
+ case 'currency':
+ (0, components_1.actionLog)(`You gained <span class="text-warning">${output.reward.currency}</span> Steel`, false);
+ break;
+ }
+ });
+ (0, dom_1.$fightButton)().prop('disabled', true)
+ .addClass(['disabled', 'hidden'])
+ .attr('data-fight-id', 'unset');
+ return output;
+ });
+ }