fix: new players didn't get profession level set
authorxangelo <git@xangelo.ca>
Mon, 3 Jul 2023 11:05:21 +0000 (07:05 -0400)
committerxangelo <git@xangelo.ca>
Mon, 3 Jul 2023 11:05:21 +0000 (07:05 -0400)
Because their profession level wasn't set, they were unable to do
anything because loading a player attempts to join that table.

src/server/player.ts

index 3c95080cc510b901440eb54c560763c9d08e09f9..6683144149bd49cd9a6e53398ba34b1fe5fdd84c 100644 (file)
@@ -3,6 +3,7 @@ import {Player, maxHp} from "../shared/player";
 import { random } from 'lodash';
 import { Skills } from '../shared/skills';
 import {Profession} from 'shared/profession';
+import {logger} from './lib/logger';
 
 export async function loadPlayer(authToken: string): Promise<Player> {
   const res = await db.first()
@@ -35,11 +36,15 @@ export async function createPlayer(): Promise<Player> {
   const res  = await db('players').insert(raw).returning<Player[]>('*');
   const player = res.pop();
 
+  logger.log(`Created player [${player.id}]`);
+
   // await skills!
   const pairs = [];
   const values = [];
   const sql = `insert into player_skills (id, player_id) values `;
 
+  logger.log(`Inserted base skills for [${player.id}]`)
+
   Skills.forEach(skill => {
     pairs.push('(?,?)');
     values.push(skill.id, player.id);
@@ -48,13 +53,15 @@ export async function createPlayer(): Promise<Player> {
   await db.raw(sql + pairs.join(','), values);
 
   // create the profession level
-  db('profession_levels').insert({
+  await db('profession_levels').insert({
     player_id: player.id,
     profession: 'Wanderer',
     level: 1,
     exp: 0
   });
 
+  logger.log(`Inserted base profession level [${player.id}]`);
+
   return player;
 }