From b8620285243ee04467705a564f696346e01fa9b5 Mon Sep 17 00:00:00 2001 From: "Jill \"oatmealine\" Monoids" Date: Tue, 21 Nov 2023 22:34:32 +0300 Subject: [PATCH] fix dmg stuff --- src/index.ts | 3 +++ src/lib/rpg/items.ts | 2 +- src/lib/rpg/pvp.ts | 5 ++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index d16e1f9..30dc29f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,6 +8,7 @@ import chalk from 'chalk'; import prettyBytes from 'pretty-bytes'; import { Command } from './types/index'; import { startServer } from './web/web'; +import { init as initPVP } from './lib/rpg/pvp'; const bot = new Client({ intents: [ @@ -40,6 +41,8 @@ async function init() { log.error(`${chalk.bold('emergency mode could not be established.')} shutting down.`); process.exit(1); } + + initPVP(bot); } bot.on(Events.ClientReady, async () => { diff --git a/src/lib/rpg/items.ts b/src/lib/rpg/items.ts index c48cb2d..43f9762 100644 --- a/src/lib/rpg/items.ts +++ b/src/lib/rpg/items.ts @@ -324,7 +324,7 @@ export async function giveItem(user: string, item: Item, quantity = 1): Promise< let inv; if (storedItem) { - if (storedItem.quantity + quantity === 0) { + if (storedItem.quantity + quantity === 0 && item.id !== DefaultItems.BLOOD) { // let blood show as 0x await db('itemInventories') .delete() .where('user', user) diff --git a/src/lib/rpg/pvp.ts b/src/lib/rpg/pvp.ts index 5bd5161..f7a047b 100644 --- a/src/lib/rpg/pvp.ts +++ b/src/lib/rpg/pvp.ts @@ -2,7 +2,7 @@ import { InitHealth, ItemInventory, db } from '../db'; import { DefaultItems, getDefaultItem, giveItem, getItemQuantity, formatItems } from './items'; import { Client } from 'discord.js'; -export const BLOOD_ID = DefaultItems.BLOOD; +export const BLOOD_ID = -DefaultItems.BLOOD; export const BLOOD_ITEM = getDefaultItem(BLOOD_ID); export const MAX_HEALTH = BLOOD_ITEM.maxStack; const BLOOD_GAIN_PER_HOUR = 5; @@ -19,10 +19,12 @@ export async function initHealth(user: string) { } export async function getHealth(user: string) { + await initHealth(user); return await getItemQuantity(user, BLOOD_ID); } export async function dealDamage(user: string, dmg: number) { + await initHealth(user); return await giveItem(user, BLOOD_ITEM, -dmg); } @@ -45,5 +47,6 @@ async function healthCron(bot: Client) { } export function init(bot: Client) { + healthCron(bot); setInterval(() => healthCron(bot), 1_000 * 60 * 60); } \ No newline at end of file