-import {ShopItem, InventoryType, EquipmentSlot} from "../src/shared/inventory";
-import { Knex } from "knex";
-import { join } from 'path';
-import { readFile } from 'fs';
-import { promisify } from 'util';
-import {Profession} from "../src/shared/profession";
-import {SkillID} from "../src/shared/skills";
-import { parse } from "csv-parse/sync";
+import { config as dotenv } from 'dotenv';
+import { db } from "../src/server/lib/db";
+import Airtable from 'airtable';
-const read = promisify(readFile);
+dotenv();
-export async function seed(knex: Knex): Promise<void> {
- // Deletes ALL existing entries
- await knex("shop_items").del();
- await knex("equipped").del();
- await knex("inventory").del();
+Airtable.configure({
+ apiKey: process.env.AIRTABLE_API_KEY
+});
- const raw = await read(join(__dirname, '..', 'data', 'inventory.csv'), 'utf8');
- const stats = {
- created: 0,
- skipped: 0
- };
+const base = Airtable.base('appDfPLPajPNog5Iw');
- const items: Omit<ShopItem, 'id'>[] = [];
+export async function createShopItems(): Promise<void> {
+ return new Promise(async (resolve) => {
+ base('Shop Items').select().eachPage(async (records, next) => {
+ await db('shop_items').insert(records.map(r => {
+ return {
+ id: r.fields.id,
+ name: r.fields.Name,
+ type: r.fields['Equipment Type'],
+ equipment_slot: r.fields['Equipment Slot'],
+ cost: r.fields.Cost,
+ count: 1,
+ requirements: {
+ level: r.fields['Required Level'],
+ strength: r.fields['Required STR'],
+ constitution: r.fields['Required CON'],
+ dexterity: r.fields['Required DEX'],
+ intelligence: r.fields['Required INT']
+ },
+ boosts: {
+ strength: r.fields['Boost STR'],
+ constitution: r.fields['Boost CON'],
+ dexterity: r.fields['Boost DEX'],
+ intelligence: r.fields['Boost INT'],
+ damage: r.fields['Boost DMG']
+ },
+ currentAp: r.fields['Armour Points'],
+ maxAp: r.fields['Armour Points'],
+ affectedSkills: JSON.stringify(r.fields['Affected Skills']),
+ location_id: r.fields.location_id[0]
+ };
- const records = parse(raw, { bom: true, skip_empty_lines: true });
- records.slice(1).forEach((pieces: string[]) => {
- if(pieces.length === 17 && pieces[0].length) {
- console.log('Adding', pieces[0]);
- stats.created++;
- const [
- name,
- type,
- equipment_slot,
- profession,
- affectedSkills,
- cost,
- requirement_level,
- requirement_strength,
- requirement_constitution,
- requirement_dexterity,
- requirement_intelligence,
- boost_strength,
- boost_constitution,
- boost_dexterity,
- boost_intelligence,
- boost_damage,
- maxAp
- ] = pieces;
- items.push({
- name,
- type: type as InventoryType,
- equipment_slot: equipment_slot as EquipmentSlot,
- profession: profession as Profession,
- cost: parseInt(cost),
- count: 1,
- requirements: {
- level: parseInt(requirement_level),
- strength: parseInt(requirement_strength),
- constitution: parseInt(requirement_constitution),
- dexterity: parseInt(requirement_dexterity),
- intelligence: parseInt(requirement_intelligence)
- },
- boosts: {
- strength: parseInt(boost_strength),
- constitution: parseInt(boost_constitution),
- dexterity: parseInt(boost_dexterity),
- intelligence: parseInt(boost_intelligence),
- damage: parseInt(boost_damage),
- },
- currentAp: parseInt(maxAp),
- maxAp: parseInt(maxAp),
- affectedSkills: JSON.stringify(affectedSkills.split(',')) as unknown as SkillID[]
- });
-
- }
- else {
- stats.skipped++;
- }
+ })).onConflict('id').merge();
+ next();
+ }).finally(() => resolve());
});
+}
- await knex('shop_items').insert(items);
- console.log(stats);
-};
+createShopItems().then(() => {
+ console.log('Complete');
+ process.exit(0);
+}).catch(e => {
+ console.log(e);
+ process.exit(1);
+})
eventName: 'city:stores:armourer',
handler: async (api) => {
const shopItems = await listShopItems({
- type: 'ARMOUR'
+ type: 'ARMOUR',
+ location_id: 'armourer'
})
api.socket.emit('city:store:armourer', shopItems);
}
eventName: 'city:stores:blacksmith',
handler: async (api) => {
const shopItems = await listShopItems({
- type: 'WEAPON'
- })
+ type: 'WEAPON',
+ location_id: 'blacksmith'
+ });
api.socket.emit('city:store:blacksmith', shopItems);
}
}
eventName: 'city:stores:mageshop',
handler: async (api) => {
const shopItems = await listShopItems({
- type: 'SPELL'
+ type: 'SPELL',
+ location_id: 'mageshop'
})
api.socket.emit('city:store:mageshop', shopItems);
}
import {addInventoryItem, deleteInventoryItem, getEquippedItems, getInventory, updateAp} from './inventory';
import {Monster, MonsterForFight, MonsterForList} from '../shared/monsters';
import {getShopItem } from './shopItem';
-import { v4 as uuid } from 'uuid';
import {EquippedItemDetails} from '../shared/equipped';
import {ArmourEquipmentSlot, EquipmentSlot} from '../shared/inventory';
import { getAllPaths, getAllServices, getCityDetails } from './map';
const shopItem = await getShopItem(data.id);
if(shopItem) {
- shopItem.id = uuid();
if(player.gold < shopItem.cost) {
socket.emit('alert', {
type: 'error',
const playerFinalHeal = Math.floor(boost.hp + hpHealAfterMasteries);
roundData.roundDetails.push(`You targeted the monsters ${data.target.toUpperCase()} with ${attackType} damage!`);
- console.log(monster);
if(data.target === 'arms') {
if(monster.armsAp > 0) {
monster.armsAp -= playerFinalDamage;