});
});
- await updatePlayerSkills(player.id, skillsUsed);
+ await updatePlayerSkills(player.id, playerSkills, skillsUsed);
const playerFinalDamage = (data.action === 'cast' && !anyDamageSpells) ? 0 : Math.floor(playerDamage + playerDamageAfterMasteries);
const playerFinalHeal = Math.floor(boost.hp + hpHealAfterMasteries);
-import {Skill, SkillID} from '../shared/skills';
+import {Skills, Skill, SkillID} from '../shared/skills';
import { db } from './lib/db';
import { each } from 'lodash';
return skillMap;
}
-export async function updatePlayerSkills(playerId: string, skills: Record<SkillID, number>) {
+export async function updatePlayerSkills(playerId: string, playerSkills:Map<SkillID, Skill>, skillExpDiff: Record<SkillID, number>) {
const sql = [];
- each(skills, (val, skillId) => {
- sql.push(`update player_skills set exp = exp + ${val} where id = '${skillId}' and player_id = '${playerId}'`);
+ each(skillExpDiff, (val, skillId: SkillID) => {
+ const skill = playerSkills.get(skillId);
+ const def = Skills.get(skillId);
+ if(skill && def) {
+ skill.exp += val;
+ if(skill.exp >= def.expToLevel(skill.level + 1)) {
+ skill.level++;
+ skill.exp -= def.expToLevel(skill.level);
+ sql.push(`update player_skills set exp = ${skill.exp}, level = ${skill.level} where id = '${skillId}' and player_id = '${playerId}'`);
+ }
+ }
+
});
if(sql.length) {