fix dmg stuff

This commit is contained in:
Jill 2023-11-21 22:34:32 +03:00
parent 783af8652c
commit b862028524
Signed by: oat
GPG Key ID: 33489AA58A955108
3 changed files with 8 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import chalk from 'chalk';
import prettyBytes from 'pretty-bytes'; import prettyBytes from 'pretty-bytes';
import { Command } from './types/index'; import { Command } from './types/index';
import { startServer } from './web/web'; import { startServer } from './web/web';
import { init as initPVP } from './lib/rpg/pvp';
const bot = new Client({ const bot = new Client({
intents: [ intents: [
@ -40,6 +41,8 @@ async function init() {
log.error(`${chalk.bold('emergency mode could not be established.')} shutting down.`); log.error(`${chalk.bold('emergency mode could not be established.')} shutting down.`);
process.exit(1); process.exit(1);
} }
initPVP(bot);
} }
bot.on(Events.ClientReady, async () => { bot.on(Events.ClientReady, async () => {

View File

@ -324,7 +324,7 @@ export async function giveItem(user: string, item: Item, quantity = 1): Promise<
let inv; let inv;
if (storedItem) { if (storedItem) {
if (storedItem.quantity + quantity === 0) { if (storedItem.quantity + quantity === 0 && item.id !== DefaultItems.BLOOD) { // let blood show as 0x
await db<ItemInventory>('itemInventories') await db<ItemInventory>('itemInventories')
.delete() .delete()
.where('user', user) .where('user', user)

View File

@ -2,7 +2,7 @@ import { InitHealth, ItemInventory, db } from '../db';
import { DefaultItems, getDefaultItem, giveItem, getItemQuantity, formatItems } from './items'; import { DefaultItems, getDefaultItem, giveItem, getItemQuantity, formatItems } from './items';
import { Client } from 'discord.js'; 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 BLOOD_ITEM = getDefaultItem(BLOOD_ID);
export const MAX_HEALTH = BLOOD_ITEM.maxStack; export const MAX_HEALTH = BLOOD_ITEM.maxStack;
const BLOOD_GAIN_PER_HOUR = 5; const BLOOD_GAIN_PER_HOUR = 5;
@ -19,10 +19,12 @@ export async function initHealth(user: string) {
} }
export async function getHealth(user: string) { export async function getHealth(user: string) {
await initHealth(user);
return await getItemQuantity(user, BLOOD_ID); return await getItemQuantity(user, BLOOD_ID);
} }
export async function dealDamage(user: string, dmg: number) { export async function dealDamage(user: string, dmg: number) {
await initHealth(user);
return await giveItem(user, BLOOD_ITEM, -dmg); return await giveItem(user, BLOOD_ITEM, -dmg);
} }
@ -45,5 +47,6 @@ async function healthCron(bot: Client) {
} }
export function init(bot: Client) { export function init(bot: Client) {
healthCron(bot);
setInterval(() => healthCron(bot), 1_000 * 60 * 60); setInterval(() => healthCron(bot), 1_000 * 60 * 60);
} }