--- /dev/null
+import { Knex } from "knex";
+
+
+export async function up(knex: Knex): Promise<void> {
+ return knex.schema.renameTable('shop_items', 'shop_equipment');
+}
+
+
+export async function down(knex: Knex): Promise<void> {
+ return knex.schema.renameTable('shop_equipment', 'shop_items');
+}
+
export async function createShopEquipment(): Promise<void> {
return new Promise(async (resolve) => {
- base('Shop Items').select().eachPage(async (records, next) => {
- await db('shop_items').insert(records.map(r => {
+ base('Shop Equipment').select().eachPage(async (records, next) => {
+ await db('shop_equipment').insert(records.map(r => {
return {
id: r.fields.id,
name: r.fields.Name,
return new Promise(async (resolve) => {
base('Items').select().eachPage(async (records, next) => {
await db('items').insert(records.map(r => {
- console.log(`Creating [${r.fields['Name']}]`);
return {
id: r.fields['Id'],
name: r.fields.Name,
import {FightRound} from '../shared/fight';
import { City, Location, LocationType, Path } from '../shared/map'
import { v4 as uuid } from 'uuid';
-import {EquipmentSlot, ShopItem} from '../shared/inventory';
+import {EquipmentSlot, ShopEquipment} from '../shared/inventory';
import { capitalize, each } from 'lodash';
import {EquippedItemDetails} from '../shared/equipped';
import { Skill, Skills } from '../shared/skills';
</div>`;
}
-function renderShopItem(item: ShopItem, action: (item: ShopItem) => string): string {
+function renderShopItem(item: ShopEquipment, action: (item: ShopEquipment) => string): string {
const player: Player = cache.get('player');
return `<div class="store-list">
<div>
}
-socket.on('city:stores', (data: ShopItem[]) => {
+socket.on('city:stores', (data: ShopEquipment[]) => {
const listing: Record<string, string> = {};
const listingTypes = new Set<string>();
data.forEach(item => {
import {SocketEvent} from "../../server/socket-event.server";
-import {listShopItems} from '../../server/shopItem';
+import {listShopItems} from '../../server/shopEquipment';
import { logger } from '../../server/lib/logger';
export const stores: SocketEvent = {
import {addInventoryItem, deleteInventoryItem, getEquippedItems, getInventory, updateAp} from './inventory';
import { getItemFromPlayer, getPlayersItems } from './items';
import {FightTrigger, MonsterForFight} from '../shared/monsters';
-import {getShopItem } from './shopItem';
+import {getShopItem } from './shopEquipment';
import {EquippedItemDetails} from '../shared/equipped';
import {ArmourEquipmentSlot, EquipmentSlot} from '../shared/inventory';
import { clearTravelPlan, getAllPaths, getAllServices, getCityDetails, getTravelPlan, travel } from './map';
-import {InventoryItem, ShopItem} from "../shared/inventory";
+import {InventoryItem, ShopEquipment} from "../shared/inventory";
import { v4 as uuid } from 'uuid';
import { db} from './lib/db';
import {EquippedItemDetails} from "../shared/equipped";
-export async function addInventoryItem(playerId: string, item: ShopItem) {
+export async function addInventoryItem(playerId: string, item: ShopEquipment) {
const inventoryItem: InventoryItem = {
player_id: playerId,
item_id: uuid(),
import {PlayerItem} from '../shared/items';
export async function getPlayersItems(player_id: string): Promise<PlayerItem[]> {
- const res = await db.raw(`select pi.*, i.name, i.effect_name, i.icon_name, i.description from player_items pi
+ const res = await db.raw(`select pi.*, i.* from player_items pi
join items i on pi.item_id = i.id where pi.player_id = ? and amount > 0`, [player_id]);
return res.rows as PlayerItem[];
}
export async function getItemFromPlayer(player_id: string, item_id: number): Promise<PlayerItem | undefined> {
- const res = await db.raw(`select pi.*, i.name, i.effect_name, i.icon_name, i.description from player_items pi
+ const res = await db.raw(`select pi.*, i.* from player_items pi
join items i on pi.item_id = i.id where pi.player_id = ? and pi.item_id = ?`, [player_id, item_id]);
if(res.rows.length === 1) {
return res.rows[0] as PlayerItem;
--- /dev/null
+import { db } from './lib/db';
+import {ShopEquipment} from '../shared/inventory';
+
+export function listShopItems(where: Partial<ShopEquipment>): Promise<ShopEquipment[]> {
+ return db.select('*').from<ShopEquipment>('shop_equipment')
+ .where(where)
+ .orderBy('type')
+ .orderBy('equipment_slot')
+ .orderByRaw(`requirements->>'level' asc`);
+}
+
+export function getShopItem(id: number): Promise<ShopEquipment> {
+ return db.select('*').from<ShopEquipment>('shop_equipment').where({
+ id
+ }).first();
+}
+++ /dev/null
-import { db } from './lib/db';
-import {ShopItem} from '../shared/inventory';
-
-export function listShopItems(where: Partial<ShopItem>): Promise<ShopItem[]> {
- return db.select('*').from<ShopItem>('shop_items')
- .where(where)
- .orderBy('type')
- .orderBy('equipment_slot')
- .orderByRaw(`requirements->>'level' asc`);
-}
-
-export function getShopItem(id: number): Promise<ShopItem> {
- return db.select('*').from<ShopItem>('shop_items').where({
- id
- }).first();
-}
// shop items have a numeric id since they're tracked in a separate spreadsheet
// and they are also tied to a specific location
-export type ShopItem = Omit<InventoryItem, 'id' | 'player_id'> & {
+export type ShopEquipment = Omit<InventoryItem, 'id' | 'player_id'> & {
id: number;
location_id: number;
};