+
+ async startFight(fightId: string): Promise<FightStartType> {
+ if(this.player === null) {
+ throw new Error('Not authenticated');
+ }
+
+ const res = await this.post<FightStartType>(`/v1/accounts/${this.player.id}/fight/${fightId}`);
+
+ if(!res.payload.id) {
+ throw new Error('Invalid fight!');
+ }
+
+ return res.payload;
+ }
+
+ async fight(fightId: string): Promise<FightRoundOutput> {
+ if(this.player === null) {
+ throw new Error('Not authenticated');
+ }
+
+ await this.startFight(fightId);
+
+ const res = await this.post<FightRoundOutput>(`/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 => actionLog(a, false));
+
+ if(output.winner === 'player') {
+ actionLog(`<span class="text-success">You defeated the ${output.monster.name}</span>`, false);
+ }
+ else {
+ 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':
+ actionLog(`You gained <span class="text-info">${output.reward.exp}</span> Exp`, false);
+ break;
+ case 'currency':
+ actionLog(`You gained <span class="text-warning">${output.reward.currency}</span> Steel`, false);
+ break;
+ }
+ });
+
+ $fightButton().prop('disabled', true)
+ .addClass(['disabled', 'hidden'])
+ .attr('data-fight-id', 'unset');
+
+ return output;
+ }