health groundwork

This commit is contained in:
Jill 2023-11-21 11:40:44 +03:00
parent 249390cf5d
commit 5be9dbfe21
Signed by: oat
GPG Key ID: 33489AA58A955108
4 changed files with 39 additions and 1 deletions

View File

@ -0,0 +1,19 @@
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.up = function(knex) {
return knex.schema
.createTable('initHealth', table =>
table.string('user').notNullable().unique()
);
};
/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
exports.down = function(knex) {
return knex.schema
.dropTable('initHealth');
};

View File

@ -86,4 +86,7 @@ export interface Session {
accessToken: string,
refreshToken: string,
expiresAt: number,
}
export interface InitHealth {
user: string,
}

View File

@ -1,5 +1,6 @@
import { AutocompleteInteraction } from 'discord.js';
import { CustomItem, ItemInventory, db } from '../db';
import { MAX_HEALTH } from './pvp';
export type DefaultItem = Omit<CustomItem, 'guild'>; // uses negative IDs
export type Item = DefaultItem | CustomItem;
@ -117,7 +118,7 @@ export const defaultItems: DefaultItem[] = [
description: 'ow',
emoji: '🩸',
type: 'plain',
maxStack: 1024,
maxStack: MAX_HEALTH,
untradable: false
},
{

15
src/lib/rpg/pvp.ts Normal file
View File

@ -0,0 +1,15 @@
import { InitHealth, db } from '../db';
import { DefaultItems, getDefaultItem, giveItem } from './items';
export const MAX_HEALTH = 100;
export async function initHealth(user: string) {
const isInitialized = await db<InitHealth>('initHealth')
.where('user', user)
.first();
if (!isInitialized) {
giveItem(user, getDefaultItem(DefaultItems.BLOOD), MAX_HEALTH);
await db<InitHealth>('initHealth').insert({ user });
}
}