health groundwork
This commit is contained in:
parent
249390cf5d
commit
5be9dbfe21
|
@ -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');
|
||||
};
|
|
@ -86,4 +86,7 @@ export interface Session {
|
|||
accessToken: string,
|
||||
refreshToken: string,
|
||||
expiresAt: number,
|
||||
}
|
||||
export interface InitHealth {
|
||||
user: string,
|
||||
}
|
|
@ -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
|
||||
},
|
||||
{
|
||||
|
|
|
@ -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 });
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue