diff --git a/src/commands/commandList/admin/addAllWeapons.js b/src/commands/commandList/admin/addAllWeapons.js index 05f19f596..4d1dea433 100644 --- a/src/commands/commandList/admin/addAllWeapons.js +++ b/src/commands/commandList/admin/addAllWeapons.js @@ -7,7 +7,6 @@ const CommandInterface = require('../../CommandInterface.js'); const WeaponInterface = require('../battle/WeaponInterface.js'); -const weaponUtil = require('../battle/util/weaponUtil.js'); module.exports = new CommandInterface({ alias: ['addallweapons', 'aaw'], @@ -60,7 +59,7 @@ module.exports = new CommandInterface({ const allWeapons = getAllWeapons(); - addMissingWeapons.bind(this)(formattedWeapons, allWeapons, stat, uid); + addMissingWeapons.bind(this)(formattedWeapons, allWeapons, stat); }, }); @@ -96,12 +95,12 @@ function getAllPassives(count, passives) { return result; } -async function addMissingWeapons(existingWeapons, allWeapons, stat, uid) { +async function addMissingWeapons(existingWeapons, allWeapons, stat) { for (let allWid in allWeapons) { let allPassives = allWeapons[allWid]; if (allPassives.length === 0) { if (!existingWeapons[allWid]) { - await addWeapon.bind(this)(allWid, [], stat, uid); + await addWeapon.bind(this)(allWid, [], stat); } } else { let existingPassives = @@ -121,31 +120,20 @@ async function addMissingWeapons(existingWeapons, allWeapons, stat, uid) { passives = passives.map((passive) => { return parseInt(passive); }); - await addWeapon.bind(this)(allWid, passives, stat, uid); + await addWeapon.bind(this)(allWid, passives, stat); } } } } } -async function addWeapon(wid, passives, stat, uid) { +async function addWeapon(wid, passives, stat) { console.log(`Adding weapon ${wid}: ${passives}`); const weapon = new WeaponInterface.weapons[wid](null, null, null, { passives, statOverride: stat, }); - const sql = weaponUtil.toSql(uid, weapon); - - let result = await this.query(sql.weapon); - let uwid = result.insertId; - if (!uwid) { - this.errorMsg(', Uh oh. Something went wrong! The weapon passive could not be applied'); - console.error('Unable to add weapon passive to: ' + uwid); - } else if (passives.length) { - let uwidList = []; - for (let i = 0; i < passives.length; i++) uwidList.push(uwid); - await this.query(sql.passive, uwidList); - } + await weapon.save(this.msg.author.id); await delay(500); } diff --git a/src/commands/commandList/battle/BuffInterface.js b/src/commands/commandList/battle/BuffInterface.js index debed1d1e..aceba0510 100644 --- a/src/commands/commandList/battle/BuffInterface.js +++ b/src/commands/commandList/battle/BuffInterface.js @@ -6,6 +6,7 @@ */ /* eslint-disable no-unused-vars */ const Tags = require('./util/tags.js'); +const Logs = require('./util/logUtil.js'); const WeaponInterface = require('./WeaponInterface.js'); module.exports = class BuffInterface { @@ -69,6 +70,36 @@ module.exports = class BuffInterface { return stats; } + attemptBind(animal, duration, tags) { + if (!(tags instanceof Tags)) { + tags = new Tags({ + me: tags.me, + allies: tags.allies, + enemies: tags.enemies, + }); + } + + let logs = new Logs(); + let preLogs = new Logs(); + let dontBind = false; + + for (let i in animal.buffs) { + const preBindResult = animal.buffs[i].preBind(animal, duration, tags, this) || {}; + dontBind = dontBind || preBindResult.dontBind; + preLogs.push(preBindResult.logs); + } + + if (!dontBind) { + logs.push(this.bind(animal, duration, tags)); + } + + logs.push(preLogs); + return logs; + } + + /* before buff is binded */ + preBind(animal, duration, tags) {} + /* Bind this buff to an animal */ bind(animal, duration, tags) { if (!(tags instanceof Tags)) { diff --git a/src/commands/commandList/battle/PassiveInterface.js b/src/commands/commandList/battle/PassiveInterface.js index ee72d1c73..fe856cac4 100644 --- a/src/commands/commandList/battle/PassiveInterface.js +++ b/src/commands/commandList/battle/PassiveInterface.js @@ -63,7 +63,7 @@ module.exports = class PassiveInterface { count += ranks[i]; if (quality <= count) return this.emojis[i]; } - return this.emojis[0]; + return this.emojis[6]; } toStats(qualities) { diff --git a/src/commands/commandList/battle/WeaponInterface.js b/src/commands/commandList/battle/WeaponInterface.js index e9e7e3aa1..5a6c183eb 100644 --- a/src/commands/commandList/battle/WeaponInterface.js +++ b/src/commands/commandList/battle/WeaponInterface.js @@ -960,6 +960,18 @@ module.exports = class WeaponInterface { static setWeaponUtil(util) { weaponUtil = util; } + + getBonusXPPassive() { + let bonus = 0; + for (let i in this.passives) { + const passive = this.passives[i]; + // Knowledge passive + if (passive.id === 21) { + bonus += passive.stats[0] / 100; + } + } + return bonus; + } }; const passiveDir = requireDir('./passives'); diff --git a/src/commands/commandList/battle/buffs/Flame.js b/src/commands/commandList/battle/buffs/Flame.js index ffec9dbab..98d766e9b 100644 --- a/src/commands/commandList/battle/buffs/Flame.js +++ b/src/commands/commandList/battle/buffs/Flame.js @@ -41,13 +41,13 @@ module.exports = class Flame extends BuffInterface { if (animal.buffs[i].id == this.id && !animal.buffs[i].markedForDeath) { animal.buffs[i].markedForDeath = true; let damage = WeaponInterface.getDamage(this.from.stats.mag, this.stats[1] / 100); - tags.add('flame', animal); + const tagsCopy = tags.copyAdd('flame', animal); damage = WeaponInterface.inflictDamage( this.from, animal, damage, WeaponInterface.MAGICAL, - tags + tagsCopy ); logs.push( `[FLAME] Exploded and damaged ${animal.nickname} for ${damage.amount} HP`, diff --git a/src/commands/commandList/battle/buffs/Stinky.js b/src/commands/commandList/battle/buffs/Stinky.js new file mode 100644 index 000000000..0409ebcd5 --- /dev/null +++ b/src/commands/commandList/battle/buffs/Stinky.js @@ -0,0 +1,49 @@ +/* + * OwO Bot for Discord + * Copyright (C) 2023 Christopher Thai + * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International + * For more information, see README.md and LICENSE + */ + +const BuffInterface = require('../BuffInterface.js'); +const WeaponInterface = require('../WeaponInterface.js'); +const Logs = require('../util/logUtil.js'); + +module.exports = class Stinky extends BuffInterface { + init() { + this.id = 12; + this.name = 'Stinky'; + this.debuff = true; + this.emoji = '<:stinky:1154636430937698364>'; + this.statDesc = `Prevents any future buffs *AND* debuffs to be applied to this animal. On success, deal **?%** ${WeaponInterface.magEmoji}MAG to the animal.`; + this.qualityList = [[20, 50]]; + } + + // Override + preBind(animal, duration, tags, buffToAdd) { + if (tags.has('stinky', this.from)) return; + + let logs = new Logs(); + + let damage = WeaponInterface.getDamage(this.from.stats.mag, this.stats[0] / 100); + const tagsCopy = tags.copyAdd('stinky', this.from); + damage = WeaponInterface.inflictDamage( + this.from, + animal, + damage, + WeaponInterface.MAGICAL, + tagsCopy + ); + logs.push( + `[STINK] Prevented ${buffToAdd.name} ${buffToAdd.debuff ? 'de' : ''}buff and damaged ${ + animal.nickname + } for ${damage.amount} HP`, + damage.logs + ); + + return { + logs: logs, + dontBind: true, + }; + } +}; diff --git a/src/commands/commandList/battle/passives/Knowledge.js b/src/commands/commandList/battle/passives/Knowledge.js new file mode 100644 index 000000000..f8c72c671 --- /dev/null +++ b/src/commands/commandList/battle/passives/Knowledge.js @@ -0,0 +1,28 @@ +/* + * OwO Bot for Discord + * Copyright (C) 2023 Christopher Thai + * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International + * For more information, see README.md and LICENSE + */ + +const PassiveInterface = require('../PassiveInterface.js'); + +module.exports = class Snail extends PassiveInterface { + init() { + this.id = 21; + this.name = 'Knowledge'; + this.basicDesc = ''; + this.emojis = [ + '<:ckno:1155427304663691294>', + '<:ukno:1155427316000886794>', + '<:rkno:1155427313857605652>', + '<:ekno:1155427306437873848>', + '<:mkno:1155427312234418236>', + '<:lkno:1155427310355353610>', + '<:fkno:1155427308480503808>', + ]; + this.statDesc = + 'This passive does not do anything in battle. However, it will give this animal **?%** extra xp after each battle.'; + this.qualityList = [[5, 15]]; + } +}; diff --git a/src/commands/commandList/battle/util/teamUtil.js b/src/commands/commandList/battle/util/teamUtil.js index eb101b55c..ed7f86e4e 100644 --- a/src/commands/commandList/battle/util/teamUtil.js +++ b/src/commands/commandList/battle/util/teamUtil.js @@ -484,6 +484,7 @@ exports.giveXP = async function (p, team, xp) { let lvl = team.team[i].stats.lvl; if (lvl < highestLvl) mult = 2 + (highestLvl - lvl) / 10; if (mult > 10) mult = 10; + mult += team.team[i].weapon?.getBonusXPPassive() || 0; cases += ` WHEN animal.pid = ${team.team[i].pid} THEN ${Math.round(total * mult)}`; } diff --git a/src/commands/commandList/battle/weapons/CelebrationRune.js b/src/commands/commandList/battle/weapons/CelebrationRune.js index 1c0d235c1..724f3daef 100644 --- a/src/commands/commandList/battle/weapons/CelebrationRune.js +++ b/src/commands/commandList/battle/weapons/CelebrationRune.js @@ -56,7 +56,7 @@ module.exports = class CRune extends WeaponInterface { /* Grab buff and bind it to our animal */ let buff = this.getBuffs(me)[0]; - let buffLogs = buff.bind(lowest, 3, { + let buffLogs = buff.attemptBind(lowest, 3, { me: me, allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/CullingScythe.js b/src/commands/commandList/battle/weapons/CullingScythe.js index 8d91d5e83..deb0d6c11 100644 --- a/src/commands/commandList/battle/weapons/CullingScythe.js +++ b/src/commands/commandList/battle/weapons/CullingScythe.js @@ -74,7 +74,7 @@ module.exports = class CullingScythe extends WeaponInterface { enemies: enemy, }); let buff = this.getBuffs(me)[0]; - let buffLogs = buff.bind(attacking, 2, { + let buffLogs = buff.attemptBind(attacking, 2, { me, allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/FlameStaff.js b/src/commands/commandList/battle/weapons/FlameStaff.js index 9fddb3ea4..7ff0e3960 100644 --- a/src/commands/commandList/battle/weapons/FlameStaff.js +++ b/src/commands/commandList/battle/weapons/FlameStaff.js @@ -74,7 +74,7 @@ module.exports = class FStaff extends WeaponInterface { enemies: enemy, }); let buff = this.getBuffs(me)[0]; - let buffLogs = buff.bind(attacking, 3, { + let buffLogs = buff.attemptBind(attacking, 3, { me, allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/FoulFish.js b/src/commands/commandList/battle/weapons/FoulFish.js new file mode 100644 index 000000000..2aef86017 --- /dev/null +++ b/src/commands/commandList/battle/weapons/FoulFish.js @@ -0,0 +1,89 @@ +/* + * OwO Bot for Discord + * Copyright (C) 2023 Christopher Thai + * This software is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International + * For more information, see README.md and LICENSE + */ + +const WeaponInterface = require('../WeaponInterface.js'); +const Logs = require('../util/logUtil.js'); + +module.exports = class FoulFish extends WeaponInterface { + init() { + this.id = 21; + this.name = 'Foul Fish'; + this.basicDesc = ''; + this.emojis = [ + '<:cffish:1154635938270564403>', + '<:uffish:1154635970637987841>', + '<:rffish:1154635969518129172>', + '<:effish:1154635940535472198>', + '<:mffish:1154635947984552076>', + '<:lffish:1154635946571079770>', + '<:fffish:1154635942397747211>', + ]; + this.pristineEmojis = [ + '<:pcffish:1154635949305778196>', + '<:puffish:1154635967907495946>', + '<:prffish:1154635966007496784>', + '<:peffish:1154635951386153040>', + '<:pmffish:1154635964577234974>', + '<:plffish:1154635961284710410>', + '<:pfffish:1154635953051287642>', + ]; + this.defaultEmoji = '<:ffish:1154635943685394433>'; + this.statDesc = `Deal **?%** of your ${WeaponInterface.strEmoji}STR to a random enemy and apply **Stinky** for 2 turns.`; + this.availablePassives = 'all'; + this.passiveCount = 1; + this.qualityList = [[50, 80]]; + this.manaRange = [280, 180]; + this.buffList = [12]; + } + + attackWeapon(me, team, enemy) { + if (me.stats.hp[0] <= 0) return; + /* No mana */ + if (me.stats.wp[0] < this.manaCost) return this.attackPhysical(me, team, enemy); + + let logs = new Logs(); + + /* Grab an enemy that I'm attacking */ + let attacking = WeaponInterface.getAttacking(me, team, enemy); + if (!attacking) return; + + /* deplete weapon points*/ + let mana = WeaponInterface.useMana(me, this.manaCost, me, { + me, + allies: team, + enemies: enemy, + }); + let manaLogs = new Logs(); + manaLogs.push(`[FFISH] ${me.nickname} used ${mana.amount} WP`, mana.logs); + + /* Calculate damage */ + let damage = WeaponInterface.getDamage(me.stats.att, this.stats[0] / 100); + + /* Deal damage */ + damage = WeaponInterface.inflictDamage(me, attacking, damage, WeaponInterface.PHYSICAL, { + me, + allies: team, + enemies: enemy, + }); + let buff = this.getBuffs(me)[0]; + let buffLogs = buff.attemptBind(attacking, 2, { + me, + allies: team, + enemies: enemy, + }); + + logs.push( + `[FFISH] ${me.nickname} damaged ${attacking.nickname} for ${damage.amount} HP and applied Stinky`, + damage.logs + ); + logs.addSubLogs(buffLogs); + + logs.addSubLogs(manaLogs); + + return logs; + } +}; diff --git a/src/commands/commandList/battle/weapons/GlacialAxe.js b/src/commands/commandList/battle/weapons/GlacialAxe.js index 46f65bad2..916c4fe32 100644 --- a/src/commands/commandList/battle/weapons/GlacialAxe.js +++ b/src/commands/commandList/battle/weapons/GlacialAxe.js @@ -79,7 +79,7 @@ module.exports = class GlacialAxe extends WeaponInterface { enemies: enemy, }); let buff = this.getBuffs(me)[0]; - let buffLogs = buff.bind(attacking, 2, { + let buffLogs = buff.attemptBind(attacking, 2, { me, allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/LeechScythe.js b/src/commands/commandList/battle/weapons/LeechScythe.js index 3c608b42a..5f2ca349b 100644 --- a/src/commands/commandList/battle/weapons/LeechScythe.js +++ b/src/commands/commandList/battle/weapons/LeechScythe.js @@ -69,7 +69,7 @@ module.exports = class LeechingScythe extends WeaponInterface { if (attacking.buffs.findIndex((buff) => buff.id === this.buffList[0]) < 0) { appliedLeech = true; let buff = this.getBuffs(me)[0]; - buffLogs = buff.bind(attacking, 3, { + buffLogs = buff.attemptBind(attacking, 3, { me, allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/PoisonDagger.js b/src/commands/commandList/battle/weapons/PoisonDagger.js index 0b7bc3793..532779544 100644 --- a/src/commands/commandList/battle/weapons/PoisonDagger.js +++ b/src/commands/commandList/battle/weapons/PoisonDagger.js @@ -74,7 +74,7 @@ module.exports = class PDagger extends WeaponInterface { enemies: enemy, }); let buff = this.getBuffs(me)[0]; - buff.bind(attacking, 3, { me, allies: team, enemies: enemy }); + buff.attemptBind(attacking, 3, { me, allies: team, enemies: enemy }); logs.push( `[PDAG] ${me.nickname} damaged ${attacking.nickname} for ${damage.amount} HP and applied poison`, damage.logs diff --git a/src/commands/commandList/battle/weapons/Shield.js b/src/commands/commandList/battle/weapons/Shield.js index 7945085bb..2d634d63c 100644 --- a/src/commands/commandList/battle/weapons/Shield.js +++ b/src/commands/commandList/battle/weapons/Shield.js @@ -59,7 +59,7 @@ module.exports = class Shield extends WeaponInterface { /* Grab buff and bind it to our animal */ let buff = this.getBuffs(animal)[0]; - let buffLogs = buff.bind(animal, 2, { + let buffLogs = buff.attemptBind(animal, 2, { me: animal, allies: ally, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/SpiritStaff.js b/src/commands/commandList/battle/weapons/SpiritStaff.js index 7a2489e82..587c5207b 100644 --- a/src/commands/commandList/battle/weapons/SpiritStaff.js +++ b/src/commands/commandList/battle/weapons/SpiritStaff.js @@ -74,7 +74,7 @@ module.exports = class SpiritStaff extends WeaponInterface { subLogs.push(hl.logs); // Apply buff let buff = this.getBuffs(me)[0]; - let buffLogs = buff.bind(team[i], 2, { + let buffLogs = buff.attemptBind(team[i], 2, { me: team[i], allies: team, enemies: enemy, diff --git a/src/commands/commandList/battle/weapons/VanguardsBanner.js b/src/commands/commandList/battle/weapons/VanguardsBanner.js index bddcfd75b..6dbd355c5 100644 --- a/src/commands/commandList/battle/weapons/VanguardsBanner.js +++ b/src/commands/commandList/battle/weapons/VanguardsBanner.js @@ -88,7 +88,7 @@ module.exports = class VanguardsBanner extends WeaponInterface { for (let i = 0; i < ally.length; i++) { // Add new buff let buff = this.getBuffs(animal)[newBuff]; - buffLogs.push(buff.bind(ally[i], 3, { me: ally[i], allies: ally, enemies: enemy })); + buffLogs.push(buff.attemptBind(ally[i], 3, { me: ally[i], allies: ally, enemies: enemy })); // Remove old buff if (oldBuffId) {