import { io } from 'socket.io-client';
import $ from 'jquery';
-import {expToLevel, maxHp, Player} from '../shared/player';
+import {expToLevel, maxHp, Player, StatDef, StatDisplay} from '../shared/player';
import { authToken, http } from './http';
import { CustomEventManager } from './events';
import {Fight, MonsterForFight, MonsterForList} from '../shared/monsters';
</form></p>`).removeClass('hidden');
}
+ $('#extra-inventory-info').html(renderStatDetails());
}
socket.on('connect', () => {
return html;
}
+function statPointIncreaser(stat: StatDisplay) {
+ return `<button class="increase-stat emit-event" data-event="spend-stat-point" data-args="${stat.id}">+</button>`;
+}
function renderStatDetails() {
const player: Player = cache.get('player');
- const html = `
- <table id="stat-breakdown">
- <tr>
- <th>Strength</th>
- <td class="strength">${player.strength}</td>
- </tr>
- <tr>
- <th>Constitution</th>
- <td class="constitution">${player.constitution}</td>
- </tr>
- <tr>
- <th>Dexterity</th>
- <td class="dexterity">${player.dexterity}</td>
- </tr>
- <tr>
- <th>Intelligence</th>
- <td class="intelligence">${player.intelligence}</td>
- </tr>
- </table>
- `;
+ let html = '<table id="stat-breakdown">';
+
+ StatDef.forEach(stat => {
+ html += `<tr>
+ <th>${stat.display}</th>
+ <td class="${stat.id}">
+ ${player[stat.id]}
+ ${player.stat_points ? statPointIncreaser(stat) : ''}
+ </td>
+ </tr>`;
+ });
+
+ html += `<tr><th>Stat Points</th><td class="stat_points">${player.stat_points}</td></tr>`;
+
+ html += '</table>';
+
return html;
}
$('#map').html(html);
});
-socket.on('city:service:healer', (data: {text: string}) => {
- $('#map').html(data.text);
-});
-
function renderRequirement(name: string, val: number | string, currentVal?: number): string {
let colorIndicator = '';
if(currentVal) {
${item.boosts.dexterity ? renderStatBoost('DEX', item.boosts.dexterity) : ''}
${item.boosts.intelligence ? renderStatBoost('INT', item.boosts.intelligence) : ''}
${item.boosts.damage ? renderStatBoost('DMG', item.boosts.damage) : ''}
+ ${item.boosts.damage_mitigation ? renderStatBoost('MIT', item.boosts.damage_mitigation)+'%' : ''}
${['WEAPON','SPELL'].includes(item.type) ? '': generateProgressBar(item.currentAp, item.maxAp, '#7be67b')}
</div>
${item.hasOwnProperty('id') ? `<div>${item.cost.toLocaleString()}G</div>` : ''}
${item.boosts.dexterity ? renderStatBoost('DEX', item.boosts.dexterity) : ''}
${item.boosts.intelligence ? renderStatBoost('INT', item.boosts.intelligence) : ''}
${item.boosts.damage ? renderStatBoost(item.affectedSkills.includes('restoration_magic') ? 'HP' : 'DMG', item.boosts.damage) : ''}
+ ${item.boosts.damage_mitigation ? renderStatBoost('MIT', item.boosts.damage_mitigation)+'%' : ''}
${['WEAPON','SPELL'].includes(item.type) ? '' : renderStatBoost('AP', item.maxAp)}
</div>
${item.hasOwnProperty('id') ? `<div>${item.cost.toLocaleString()}G</div>` : ''}
}
});
+$('body').on('click', '.emit-event', e => {
+ const $el = $(e.target);
+
+ const eventName = $el.data('event');
+ const args = $el.data('args');
+
+ console.log(`Sending event ${eventName}`, { args });
+ socket.emit(eventName, { args });
+});
+
$('body').on('click', '.city-emit-event', e => {
const $el = $(e.target);
<div class="progress-bar" id="defender-hp-bar" style="background: linear-gradient(to right, red, red ${hpPercent}%, transparent ${hpPercent}%, transparent)" title="${hpPercent}% - ${monster.hp}/${monster.maxHp}">${hpPercent}% - ${monster.hp} / ${monster.maxHp}</div>
</div>
</div>
- <div id="fight-results"></div>
<div id="fight-actions">
<select id="fight-target">
<option value="head">Head</option>
<button type="button" class="fight-action" data-action="cast">Cast</button>
<button type="button" class="fight-action" data-action="flee">Flee</button>
</div>
+ <div id="fight-results"></div>
</div>`;
return html;
if(monsters.length) {
const lastSelectedMonster = cache.get('last-selected-monster');
- html.push('<br><hr><h2>Fight Again</h2>');
- html.push(`<form id="fight-selector"><select id="monster-selector">
+ // put this above the fight details
+ html.unshift(`<h2>Fight Again</h2><form id="fight-selector"><select id="monster-selector">
${monsters.map(monster => {
return `<option value="${monster.id}" ${lastSelectedMonster == monster.id ? 'selected': ''}>${monster.name}</option>`;
}).join("\n")}
</select> <button type="submit">Fight</button></option>
- </select></form>`);
+ </select></form><hr>`);
}
$('#fight-results').html(html.join("\n"));