import { Events } from './events';
import { LoginOutputType, AccountCreateType, MoveOutputType, FightStartType, FightRoundOutput } from 'src/routes';
import {actionLog} from './components';
-import {$fightButton} from './dom';
+import {disableFightButton, disablePickItemButton, enableFightButton, enablePickItemButton} from './dom';
+import {pickWorldDropOutput} from 'src/routes/inventory';
type ApiResponse<T> = {
status: 'ok' | 'error',
$('body').removeClass().addClass(`sky-gradient-${str}`);
}
- async getPlayerInfo() {
+ async syncPlayerInfo() {
if(!this.player) {
throw new Error('Not authenticated');
}
// this also sets the background based on the time!
this.setGameTime(res.meta.gameTime);
+
+ setTimeout(this.syncPlayerInfo.bind(this), 10000);
}
async login(username: string, password: string): Promise<LoginOutputType> {
this.setGameTime(res.meta.gameTime);
- setInterval(this.getPlayerInfo.bind(this), 5000);
+ this.syncPlayerInfo();
return res.payload;
}
if(res.payload.generatedMonster !== null) {
actionLog(`You see a ${res.payload.generatedMonster.name}`);
if(this.player.hp > 0 && this.player.stamina > 0) {
- $fightButton().prop('disabled', false)
- .removeClass(['disabled', 'hidden'])
- .attr('data-fight-id', res.payload.generatedMonster.id);
+ enableFightButton({fightId: res.payload.generatedMonster.id});
}
}
else {
actionLog(res.payload.displayText, true);
- $fightButton().prop('disabled', true)
- .addClass(['disabled', 'hidden'])
- .attr('data-fight-id', 'unset');
+ disableFightButton();
}
return res.payload;
return res.payload;
}
+ async pickItem(dropId: string): Promise<void> {
+ if(this.player === null) {
+ throw new Error('Not authenticated');
+ }
+
+ disablePickItemButton();
+
+ const res = await this.post<pickWorldDropOutput>(`/v1/accounts/${this.player.id}/pick/${dropId}`);
+
+ actionLog(`You picked up the item!`, false);
+ }
+
async fight(fightId: string): Promise<FightRoundOutput> {
if(this.player === null) {
throw new Error('Not authenticated');
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;
- }
- });
+ if(output.reward.exp) {
+ actionLog(`You gained <span class="text-info">${output.reward.exp}</span> Exp`, false);
+ }
+
+ if(output.reward.currency) {
+ actionLog(`You gained <span class="text-warning">${output.reward.currency}</span> Steel`, false);
+ }
+
+ if(output.reward.worldDrop) {
+ enablePickItemButton({itemId: output.reward.worldDrop.id}, output.reward.worldDrop.name);
+ }
- $fightButton().prop('disabled', true)
- .addClass(['disabled', 'hidden'])
- .attr('data-fight-id', 'unset');
+ disableFightButton();
return output;
}