From 0c43629cd7fad8c023898a10c324e9a39555b02e Mon Sep 17 00:00:00 2001 From: Alex Mudd Date: Sat, 9 Oct 2021 21:41:23 -0500 Subject: [PATCH 1/2] ability to mark weapons as favorite to disable sell / sac --- .../commandList/battle/util/weaponUtil.js | 70 ++++++++++++++++--- src/commands/commandList/battle/weapon.js | 4 ++ .../commandList/battle/weaponshards.js | 8 ++- 3 files changed, 73 insertions(+), 9 deletions(-) diff --git a/src/commands/commandList/battle/util/weaponUtil.js b/src/commands/commandList/battle/util/weaponUtil.js index 94033cb14..83a2c477d 100644 --- a/src/commands/commandList/battle/util/weaponUtil.js +++ b/src/commands/commandList/battle/util/weaponUtil.js @@ -22,6 +22,7 @@ const prevPageEmoji = '⬅️'; const rewindEmoji = '⏪'; const fastForwardEmoji = '⏩'; const sortEmoji = '🔃'; +const favoriteEmoji = '⭐'; /* All weapons */ var weapons = {}; @@ -106,6 +107,7 @@ var parseWeapon = exports.parseWeapon = function(data){ weapon.ruwid = data.ruwid; weapon.pid = data.pid; weapon.animal = data.animal; + weapon.favorite = data.favorite; return weapon; } @@ -123,6 +125,7 @@ var parseWeaponQuery = exports.parseWeaponQuery = function(query){ pid:query[i].pid, id:query[i].wid, stat:query[i].stat, + favorite:query[i].favorite, animal:{ name:query[i].name, nickname:query[i].nickname @@ -276,7 +279,7 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ /* Query all weapons */ let sql = `SELECT temp.*,user_weapon_passive.wpid,user_weapon_passive.pcount,user_weapon_passive.stat as pstat FROM - (SELECT user_weapon.uwid,user_weapon.wid,user_weapon.stat,animal.name,animal.nickname + (SELECT user_weapon.uwid,user_weapon.wid,user_weapon.stat,user_weapon.favorite,animal.name,animal.nickname FROM user INNER JOIN user_weapon ON user.uid = user_weapon.uid LEFT JOIN animal ON animal.pid = user_weapon.pid @@ -325,7 +328,7 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ let user_weapons = parseWeaponQuery(result[0]); /* Parse actual weapon data for each weapon */ - let descHelp = "Description: `owo weapon {weaponID}`\nEquip: `owo weapon {weaponID} {animal}`\nUnequip: `owo weapon unequip {weaponID}`\nReroll: `owo w rr {weaponID} [passive|stat]`\nSell: `owo sell {weaponID|commonweapons,rareweapons...}`\nDismantle: `owo dismantle {weaponID|commonweapons,rareweapons...}`\n"; + let descHelp = "Description: `owo weapon {weaponID}`\nEquip: `owo weapon {weaponID} {animal}`\nUnequip: `owo weapon unequip {weaponID}`\nReroll: `owo w rr {weaponID} [passive|stat]`\nSell: `owo sell {weaponID|commonweapons,rareweapons...}`\nDismantle: `owo dismantle {weaponID|commonweapons,rareweapons...}`\nFavorite: `owo w favorite|unfavorite {weaponID}`\n"; let desc = ''; let fieldText; let fields = [] @@ -339,6 +342,9 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ emoji += passive.emoji; } row += `\n\`${user_weapons[key].uwid}\` ${emoji} **${weapon.name}** | Quality: ${weapon.avgQuality}%`; + if(user_weapons[key].favorite) { + row += ` | ${favoriteEmoji}`; + } if(user_weapons[key].animal.name){ let animal = p.global.validAnimal(user_weapons[key].animal.name); row += p.replaceMentions(` | ${(animal.uni)?animal.uni:animal.value} ${(user_weapons[key].animal.nickname)?user_weapons[key].animal.nickname:""}`); @@ -401,7 +407,7 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ return {sql,embed,totalCount,nextPage,prevPage,maxPage} } -exports.describe = async function(p,uwid){ +var describe = exports.describe = async function(p,uwid){ uwid = expandUWID(uwid); /* Check if valid */ @@ -411,7 +417,7 @@ exports.describe = async function(p,uwid){ } /* sql query */ - let sql = `SELECT user.id,a.uwid,a.wid,a.stat,b.pcount,b.wpid,b.stat as pstat FROM user INNER JOIN user_weapon a ON user.uid = a.uid LEFT JOIN user_weapon_passive b ON a.uwid = b.uwid WHERE a.uwid = ${uwid};`; + let sql = `SELECT user.id,a.uwid,a.wid,a.stat,a.favorite,b.pcount,b.wpid,b.stat as pstat FROM user INNER JOIN user_weapon a ON user.uid = a.uid LEFT JOIN user_weapon_passive b ON a.uwid = b.uwid WHERE a.uwid = ${uwid};`; let result = await p.query(sql); /* Check if valid */ @@ -421,9 +427,9 @@ exports.describe = async function(p,uwid){ } /* parse weapon to get info */ - let weapon = this.parseWeaponQuery(result); + let weapon = parseWeaponQuery(result); weapon = weapon[Object.keys(weapon)[0]]; - weapon = this.parseWeapon(weapon); + weapon = parseWeapon(weapon); /* If no weapon */ if(!weapon){ @@ -452,6 +458,10 @@ exports.describe = async function(p,uwid){ desc += `**Owner:** ${username}\n`; desc += `**ID:** \`${shortenUWID(uwid)}\`\n`; desc += `**Sell Value:** ${weapon.unsellable?"UNSELLABLE":prices[weapon.rank.name]}\n`; + // mark as favorite if you're looking at your own weapon + if (user && user.id === p.msg.author.id && weapon.favorite) { + desc += `**Favorite:** ${favoriteEmoji}\n`; + } desc += `**Quality:** ${weapon.rank.emoji} ${weapon.avgQuality}%\n`; desc += `**WP Cost:** ${Math.ceil(weapon.manaCost)} <:wp:531620120976687114>`; desc += `\n**Description:** ${weapon.desc}\n`; @@ -607,7 +617,7 @@ exports.sell = async function(p,uwid){ } /* Grab the item we will sell */ - let sql = `SELECT a.uwid,a.wid,a.stat,b.pcount,b.wpid,b.stat as pstat,c.name,c.nickname + let sql = `SELECT a.uwid,a.wid,a.stat,a.favorite,b.pcount,b.wpid,b.stat as pstat,c.name,c.nickname FROM user LEFT JOIN user_weapon a ON user.uid = a.uid LEFT JOIN user_weapon_passive b ON a.uwid = b.uwid @@ -622,6 +632,12 @@ exports.sell = async function(p,uwid){ return; } + /* If the weapon is marked as favorite */ + if(result[0]&&result[0].favorite){ + p.errorMsg(", please unfavorite the weapon to sell it!",3000); + return; + } + /* If an animal is using the weapon */ if(result[0]&&result[0].name){ p.errorMsg(", please unequip the weapon to sell it!",3000); @@ -696,7 +712,7 @@ var sellRank = exports.sellRank = async function(p,rankLoc){ FROM user LEFT JOIN user_weapon a ON user.uid = a.uid LEFT JOIN user_weapon_passive b ON a.uwid = b.uwid - WHERE user.id = ${p.msg.author.id} AND avg > ${min} AND avg <= ${max} AND a.pid IS NULL LIMIT 500;` + WHERE user.id = ${p.msg.author.id} AND avg > ${min} AND avg <= ${max} AND a.pid IS NULL AND a.favorite = 0 LIMIT 500;` let result = await p.query(sql); @@ -767,6 +783,44 @@ var sellRank = exports.sellRank = async function(p,rankLoc){ p.logger.incr(`cowoncy`, price, {type:'sell'}, p.msg); } +/* marks a weapon as favorite to prevent selling / sharding */ +exports.favoriteUnfavorite = async function(p) { + let uwid = expandUWID(p.args[1]); + + /* Check if valid */ + if (!uwid) { + p.errorMsg(", I could not find a weapon with that unique weapon id! Please use `owo weapon` for the weapon ID!"); + return; + } + + /* sql query */ + let sql = `SELECT uwid FROM user_weapon INNER JOIN user ON user_weapon.uid = user.uid WHERE uwid = ${uwid} and user.id = ${p.msg.author.id};`; + let result = await p.query(sql); + + /* Check if valid */ + if (!result[0]){ + p.errorMsg(", I could not find a weapon with that unique weapon id! Please use `owo weapon` for the weapon ID!"); + return; + } + /* update favorite status */ + let favorite = false; + if (p.args[0].toLowerCase() == "favorite") { + favorite = true; + } + + sql = `UPDATE user_weapon SET favorite = ${favorite} WHERE uwid = ${uwid};`; + result = await p.query(sql); + + /* Check if updated */ + if(result.affectedRows==0){ + p.errorMsg(", you do not have a weapon with this id!",3000); + return; + } + + /* show weapon */ + await describe(p, p.args[1]); +} + /* Shorten a uwid to base36 */ var shortenUWID = exports.shortenUWID = function(uwid){ if(!uwid) return; diff --git a/src/commands/commandList/battle/weapon.js b/src/commands/commandList/battle/weapon.js index 8186d96ce..c557df756 100644 --- a/src/commands/commandList/battle/weapon.js +++ b/src/commands/commandList/battle/weapon.js @@ -43,6 +43,10 @@ module.exports = new CommandInterface({ }else if(["rr","reroll"].includes(p.args[0])){ await rerollUtil.reroll(p); + /* favorite / unfavorite weapon */ + }else if(["favorite", "unfavorite"].includes(p.args[0])) { + await weaponUtil.favoriteUnfavorite(p); + /* Describe weapon */ }else if(p.args.length==1){ diff --git a/src/commands/commandList/battle/weaponshards.js b/src/commands/commandList/battle/weaponshards.js index 786e95d9f..813ae4ee2 100644 --- a/src/commands/commandList/battle/weaponshards.js +++ b/src/commands/commandList/battle/weaponshards.js @@ -154,7 +154,7 @@ async function dismantleId(p,uwid){ } /* Grab the item we will dismantle */ - let sql = `SELECT user.uid,a.uwid,a.wid,a.stat,b.pcount,b.wpid,b.stat as pstat,c.name,c.nickname + let sql = `SELECT user.uid,a.uwid,a.wid,a.stat,a.favorite,b.pcount,b.wpid,b.stat as pstat,c.name,c.nickname FROM user LEFT JOIN user_weapon a ON user.uid = a.uid LEFT JOIN user_weapon_passive b ON a.uwid = b.uwid @@ -169,6 +169,12 @@ async function dismantleId(p,uwid){ return; } + /* If the weapon is marked as favorite */ + if(result[0]&&result[0].favorite){ + p.errorMsg(", please unfavorite the weapon to dismantle it!",3000); + return; + } + /* If an animal is using the weapon */ if(result[0]&&result[0].name){ p.errorMsg(", please unequip the weapon to dismantle it!",3000); From 7774398a881f60103c5e7fc85feaf12854bc9e09 Mon Sep 17 00:00:00 2001 From: Alex Mudd Date: Sat, 9 Oct 2021 21:51:39 -0500 Subject: [PATCH 2/2] sort by favorite --- src/commands/commandList/battle/util/weaponUtil.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/commands/commandList/battle/util/weaponUtil.js b/src/commands/commandList/battle/util/weaponUtil.js index 83a2c477d..aeaa3fd8b 100644 --- a/src/commands/commandList/battle/util/weaponUtil.js +++ b/src/commands/commandList/battle/util/weaponUtil.js @@ -185,7 +185,7 @@ var display = exports.display = async function(p,pageNum=0,sort=0,opt){ page = await getDisplayPage(p,user,pageNum,sort,opt); if(page) await msg.edit({embed:page.embed}); }else if(emoji.name===sortEmoji){ - sort = (sort+1)%4; + sort = (sort+1)%5; page = await getDisplayPage(p,user,pageNum,sort,opt); if(page) await msg.edit({embed:page.embed}); }else if(emoji.name===rewindEmoji){ @@ -295,6 +295,8 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ sql += 'user_weapon.wid DESC, user_weapon.avg DESC,'; else if(sort===3) sql += 'user_weapon.pid DESC,'; + else if(sort===4) + sql += 'user_weapon.favorite DESC, user_weapon.avg DESC, '; sql += ` user_weapon.uwid DESC LIMIT ${weaponPerPage} @@ -396,6 +398,8 @@ var getDisplayPage = async function(p,user,page,sort,opt={}){ embed.footer.text += "Sorting by type"; else if(sort===3) embed.footer.text += "Sorting by equipped"; + else if(sort===4) + embed.footer.text += "Sorting by favorite"; embed = alterWeapon.alter(user.id, embed, { page: page+1,