@@ -2,7 +2,6 @@ import { percentChance } from '@oldschoolgg/rng';
22import { calcWhatPercent , cleanUsername , Emoji , isObject , sumArr , UserError , uniqueArr } from '@oldschoolgg/toolkit' ;
33import { escapeMarkdown , userMention } from 'discord.js' ;
44import {
5- addItemToBank ,
65 Bank ,
76 convertXPtoLVL ,
87 EMonster ,
@@ -534,11 +533,27 @@ RETURNING (monster_scores->>'${monsterID}')::int AS new_kc;
534533 return ActivityManager . minionIsBusy ( this . id ) ;
535534 }
536535
537- async incrementCreatureScore ( creatureID : number , amountToAdd = 1 ) {
538- const stats = await this . fetchStats ( ) ;
539- await this . statsUpdate ( {
540- creature_scores : addItemToBank ( stats . creature_scores as ItemBank , creatureID , amountToAdd )
541- } ) ;
536+ async getCreatureScore ( creatureID : number ) : Promise < number > {
537+ if ( ! Number . isInteger ( creatureID ) ) throw new Error ( 'Invalid monsterID' ) ;
538+ const query = `
539+ SELECT COALESCE((creature_scores->>'${ creatureID } ')::int, 0) AS creature_kc
540+ FROM user_stats
541+ WHERE user_id = ${ this . id } ;` ;
542+ const stats = await prisma . $queryRawUnsafe < { creature_kc : number } [ ] > ( query ) ;
543+ return stats [ 0 ] ?. creature_kc ?? 0 ;
544+ }
545+
546+ async incrementCreatureScore ( creatureID : number , quantityToAdd = 1 ) : Promise < { newKC : number } > {
547+ if ( ! Number . isInteger ( creatureID ) ) throw new Error ( 'Invalid creatureID' ) ;
548+ if ( ! Number . isInteger ( quantityToAdd ) || quantityToAdd < 1 ) throw new Error ( 'Invalid quantityToAdd' ) ;
549+ const query = `
550+ UPDATE user_stats
551+ SET creature_scores = add_item_to_bank(creature_scores, '${ creatureID } ', ${ quantityToAdd } )
552+ WHERE user_id = ${ this . id }
553+ RETURNING (creature_scores->>'${ creatureID } ')::int AS new_kc;
554+ ` ;
555+ const res = await prisma . $queryRawUnsafe < { new_kc : number } [ ] > ( query ) ;
556+ return { newKC : res [ 0 ] ?. new_kc ?? 0 } ;
542557 }
543558
544559 get blowpipe ( ) {
@@ -714,11 +729,6 @@ Charge your items using ${mentionCommand('minion', 'charge')}.`
714729 } ;
715730 }
716731
717- async getCreatureScore ( creatureID : number ) {
718- const stats = await this . fetchStats ( ) ;
719- return ( stats . creature_scores as ItemBank ) [ creatureID ] ?? 0 ;
720- }
721-
722732 calculateAddItemsToCLUpdates ( {
723733 items,
724734 dontAddToTempCL = false
0 commit comments