mirror of
https://github.com/ION606/selmerBot.git
synced 2026-05-14 21:26:54 +00:00
Added the battle fighting commands, restructured the way hp and mp are stored, and added weapons. NOTE: UPDATING THE HP AND MP DOES NOT WORK
This commit is contained in:
+66
-8
@@ -1,5 +1,7 @@
|
||||
//@ts-check
|
||||
const { STATE } = require('./econ');
|
||||
const { winGame } = require('./external_game_functions.js');
|
||||
|
||||
|
||||
/**
|
||||
* Called by "attack"
|
||||
@@ -9,9 +11,50 @@ function attack_special() {
|
||||
}
|
||||
|
||||
|
||||
function attack(user_dbo, other_dbo, bot, thread, command, mongouri, items) {
|
||||
//Bow special phrase: Σ>―(´・ω・`)→
|
||||
function attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction) {
|
||||
//Get the weapon
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.equipped.weapons;
|
||||
console.log(all_weapons);
|
||||
const weapon = all_weapons.main;
|
||||
|
||||
var dmg = 0;
|
||||
|
||||
//No weapons (punch)
|
||||
if (weapon == null) {
|
||||
dmg = doc.rank;
|
||||
} else {
|
||||
dmg = (doc.rank - 1) + Math.round(weapon.cost/5);
|
||||
}
|
||||
|
||||
other_dbo.find({'equipped': {$exists: true}}).toArray(function (err, docs) {
|
||||
const odoc = docs[0];
|
||||
|
||||
//Handle defending
|
||||
if (odoc.state == STATE.DEFENDING) {
|
||||
var def = odoc.rank - doc.rank;
|
||||
//Make sure we don't go negative
|
||||
if (def < 0) { def = 0; }
|
||||
|
||||
dmg /= 2 + def;
|
||||
}
|
||||
|
||||
var new_hp = odoc.hpmp.hp -= dmg;
|
||||
if (new_hp <= 0) {
|
||||
winGame(client, bot, client.db(user_dbo.s.namespace.db), user_dbo, xp_collection, interaction.message);
|
||||
} else {
|
||||
other_dbo.updateOne({'equipped': {$exists: true}}, { $set: { hp :new_hp }}); //THIS DOES NOT WORK
|
||||
}
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
//Check for a "special" animation
|
||||
|
||||
|
||||
|
||||
postActionBar(thread, other_dbo);
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +62,8 @@ function attack(user_dbo, other_dbo, bot, thread, command, mongouri, items) {
|
||||
* Called by "item"
|
||||
*/
|
||||
function heal(user_dbo, bot, thread, command, mongouri, items) {
|
||||
postActionBar(thread, user_dbo);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +73,15 @@ function item() {
|
||||
}
|
||||
|
||||
|
||||
function defend(user_dbo, bot, thread, command, mongouri, items) {
|
||||
user_dbo.find({'equipped': {$exists: true}}).toArray(function(err, docs) {
|
||||
const doc = docs[0];
|
||||
const all_weapons = doc.get('weapons');
|
||||
const shield = all_weapons.get('secondary');
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
function cast() {
|
||||
|
||||
}
|
||||
@@ -46,6 +99,10 @@ function postActionBar(thread, user_dbo) {
|
||||
.setCustomId('HEAL')
|
||||
.setLabel('HEAL')
|
||||
.setStyle('SUCCESS'),
|
||||
new MessageButton()
|
||||
.setCustomId('DEFEND')
|
||||
.setLabel('DEFEND')
|
||||
.setStyle('PRIMARY'),
|
||||
new MessageButton()
|
||||
.setCustomId('ITEMS')
|
||||
.setLabel('ITEMS')
|
||||
@@ -57,19 +114,20 @@ function postActionBar(thread, user_dbo) {
|
||||
|
||||
|
||||
|
||||
function handle(user_dbo, other_dbo, bot, thread, command, mongouri, items) {
|
||||
|
||||
function handle(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, interaction, xp_collection) {
|
||||
if (command == 'initalize') {
|
||||
postActionBar(thread, user_dbo);
|
||||
return postActionBar(thread, user_dbo);
|
||||
} else if (command == 'attack') {
|
||||
attack(user_dbo, other_dbo, bot, thread, command, mongouri, items);
|
||||
attack(client, user_dbo, other_dbo, bot, thread, command, mongouri, items, xp_collection, interaction);
|
||||
} else if (command == 'items') {
|
||||
item();
|
||||
} else if (command == 'heal') {
|
||||
heal();
|
||||
}
|
||||
|
||||
//Post the action bar for the next person's turn
|
||||
postActionBar(thread, other_dbo);
|
||||
// initiate(user_dbo, other_dbo, command, message);
|
||||
}
|
||||
|
||||
|
||||
module.exports = { handle }
|
||||
|
||||
Reference in New Issue
Block a user