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:
ION606
2022-05-29 20:59:39 +03:00
parent 7fa6b85f10
commit 69a5a2e18d
6 changed files with 288 additions and 185 deletions
+134 -113
View File
@@ -1,3 +1,7 @@
let d = new Date();
const START = d.getTime();
const { MongoClient, ServerApiVersion } = require('mongodb');
const mongouri = process.env.MONGODB_URI; //DO NOT RUN LOCALLY (no process.env)
@@ -7,118 +11,135 @@ client.connect(err => {
collectiontemp = client.db("main").collection("shop");
// perform actions on the collection object
collectiontemp.insertMany(
[{ name: 'Grapes', cost: 2, icon: '🍇', sect: 'Food' },
{ name: 'Melon', cost: 5, icon: '🍈', sect: 'Food' },
{ name: 'Watermelon', cost: 5, icon: '🍉', sect: 'Food' },
{ name: 'Tangerine', cost: 3, icon: '🍊', sect: 'Food' },
{ name: 'Lemon', cost: 3, icon: '🍋', sect: 'Food' },
{ name: 'Banana', cost: 4, icon: '🍌', sect: 'Food' },
{ name: 'Pineapple', cost: 4, icon: '🍍', sect: 'Food' },
{ name: 'Mango', cost: 3, icon: '🥭', sect: 'Food' },
{ name: 'Red Apple', cost: 3, icon: '🍎', sect: 'Food' },
{ name: 'Green Apple', cost: 3, icon: '🍏', sect: 'Food' },
{ name: 'Pear', cost: 3, icon: '🍐', sect: 'Food' },
{ name: 'Peach', cost: 3, icon: '🍑', sect: 'Food' },
{ name: 'Cherries', cost: 4, icon: '🍒', sect: 'Food' },
{ name: 'Strawberry', cost: 3, icon: '🍓', sect: 'Food' },
{ name: 'Blueberries', cost: 3, icon: '🫐', sect: 'Food' },
{ name: 'Kiwi', cost: 3, icon: '🥝', sect: 'Food' },
{ name: 'Tomato', cost: 4, icon: '🍅', sect: 'Food' },
{ name: 'Olive', cost: 4, icon: '🫒', sect: 'Food' },
{ name: 'Coconut', cost: 3, icon: '🥥', sect: 'Food' },
{ name: 'Avocado', cost: 3, icon: '🥑', sect: 'Food' },
{ name: 'Eggplant', cost: 10, icon: '🍆', sect: 'Food' },
{ name: 'Potato', cost: 3, icon: '🥔', sect: 'Food' },
{ name: 'Carrot', cost: 3, icon: '🥕', sect: 'Food' },
{ name: 'Ear of Corn', cost: 3, icon: '🌽', sect: 'Food' },
{ name: 'Hot Pepper', cost: 3, icon: '🌶️', sect: 'Food' },
{ name: 'Bell Pepper', cost: 3, icon: '🫑', sect: 'Food' },
{ name: 'Cucumber', cost: 3, icon: '🥒', sect: 'Food' },
{ name: 'Leafy Green', cost: 3, icon: '🥬', sect: 'Food' },
{ name: 'Broccoli', cost: 2, icon: '🥦', sect: 'Food' },
{ name: 'Garlic', cost: 3, icon: '🧄', sect: 'Food' },
{ name: 'Onion', cost: 3, icon: '🧅', sect: 'Food' },
{ name: 'Mushroom', cost: 3, icon: '🍄', sect: 'Food' },
{ name: 'Peanuts', cost: 4, icon: '🥜', sect: 'Food' },
{ name: 'Chestnut', cost: 3, icon: '🌰', sect: 'Food' },
{ name: 'Bread', cost: 5, icon: '🍞', sect: 'Food' },
{ name: 'Croissant', cost: 7, icon: '🥐', sect: 'Food' },
{ name: 'Baguette Bread', cost: 10, icon: '🥖', sect: 'Food' },
{ name: 'Flatbread', cost: 9, icon: '🫓', sect: 'Food' },
{ name: 'Pretzel', cost: 5, icon: '🥨', sect: 'Food' },
{ name: 'Bagel', cost: 4, icon: '🥯', sect: 'Food' },
{ name: 'Pancakes', cost: 5, icon: '🥞', sect: 'Food' },
{ name: 'Waffle', cost: 5, icon: '🧇', sect: 'Food' },
{ name: 'Cheese Wedge', cost: 3, icon: '🧀', sect: 'Food' },
{ name: 'Meat on the Bone', cost: 5, icon: '🍖', sect: 'Food' },
{ name: 'Checken Leg', cost: 5, icon: '🍗', sect: 'Food' },
{ name: 'Cut of Meat', cost: 4, icon: '🥩', sect: 'Food' },
{ name: 'Bacon', cost: 4, icon: '🥓', sect: 'Food' },
{ name: 'Hamburger', cost: 5, icon: '🍔', sect: 'Food' },
{ name: 'French Fries', cost: 3, icon: '🍟', sect: 'Food' },
{ name: 'Pizza', cost: 6, icon: '🍕', sect: 'Food' },
{ name: 'Hot Dog', cost: 3, icon: '🌭', sect: 'Food' },
{ name: 'Sandwich', cost: 3, icon: '🥪', sect: 'Food' },
{ name: 'Taco', cost: 3, icon: '🌮', sect: 'Food' },
{ name: 'Burrito', cost: 5, icon: '🌯', sect: 'Food' },
{ name: 'Tamale', cost: 5, icon: '🫔', sect: 'Food' },
{ name: 'Stuffed Flatbread', cost: 5, icon: '🥙', sect: 'Food' },
{ name: 'Falafel', cost: 4, icon: '🧆', sect: 'Food' },
{ name: 'Egg', cost: 3, icon: '🥚', sect: 'Food' },
{ name: 'Hot Pot', cost: 12, icon: '🍲', sect: 'Food' },
{ name: 'Fondue', cost: 8, icon: '🫕', sect: 'Food' },
{ name: 'Green Salad', cost: 3, icon: '🥗', sect: 'Food' },
{ name: 'Popcorn', cost: 3, icon: '🍿', sect: 'Food' },
{ name: 'Butter', cost: 2, icon: '🧈', sect: 'Food' },
{ name: 'Salt', cost: 2, icon: '🧂', sect: 'Food' },
{ name: 'Canned Food', cost: 3, icon: '🥫', sect: 'Food' },
{ name: 'Bento Box', cost: 7, icon: '🍱', sect: 'Food' },
{ name: 'Rice Cracker', cost: 1, icon: '🍘', sect: 'Food' },
{ name: 'Rice Ball', cost: 3, icon: '🍙', sect: 'Food' },
{ name: 'Cooked Rice', cost: 3, icon: '🍚', sect: 'Food' },
{ name: 'Curry Rice', cost: 4, icon: '🍛', sect: 'Food' },
{ name: 'Ramen', cost: 4, icon: '🍜', sect: 'Food' },
{ name: 'Spaghetti', cost: 5, icon: '🍝', sect: 'Food' },
{ name: 'Roasted Sweet Potato', cost: 3, icon: '🍠', sect: 'Food' },
{ name: 'Oden', cost: 3, icon: '🍢', sect: 'Food' },
{ name: 'Sushi', cost: 4, icon: '🍣', sect: 'Food' },
{ name: 'Fried Shrimp', cost: 3, icon: '🍤', sect: 'Food' },
{ name: 'Fish Cake', cost: 3, icon: '🍥', sect: 'Food' },
{ name: 'Moon Cake', cost: 3, icon: '🥮', sect: 'Food' },
{ name: 'Dango', cost: 3, icon: '🍡', sect: 'Food' },
{ name: 'Dumpling', cost: 3, icon: '🥟', sect: 'Food' },
{ name: 'Fortune Cookie', cost: 3, icon: '🥠', sect: 'Food' },
{ name: 'Oyster', cost: 4, icon: '🦪', sect: 'Food' },
{ name: 'Ice Cream Cone', cost: 3, icon: '🍦', sect: 'Food' },
{ name: 'Shaved Ice', cost: 3, icon: '🍧', sect: 'Food' },
{ name: 'Ice Cream', cost: 3, icon: '🍨', sect: 'Food' },
{ name: 'Doughnut', cost: 3, icon: '🍩', sect: 'Food' },
{ name: 'Cookie', cost: 3, icon: '🍪', sect: 'Food' },
{ name: 'Birthday Cake', cost: 7, icon: '🎂', sect: 'Food' },
{ name: 'Shortcake', cost: 4, icon: '🍰', sect: 'Food' },
{ name: 'Cupcake', cost: 3, icon: '🧁', sect: 'Food' },
{ name: 'Pie', cost: 4, icon: '🥧', sect: 'Food' },
{ name: 'Chocolate Bar', cost: 2, icon: '🍫', sect: 'Food' },
{ name: 'Candy', cost: 1, icon: '🍬', sect: 'Food' },
{ name: 'Lollipop', cost: 1, icon: '🍭', sect: 'Food' },
{ name: 'Custard', cost: 3, icon: '🍮', sect: 'Food' },
{ name: 'Honey Pot', cost: 3, icon: '🍯', sect: 'Food' },
{ name: 'Baby Bottle', cost: 3, icon: '🍼', sect: 'Food' },
{ name: 'Glass of Milk', cost: 3, icon: '🥛', sect: 'Food' },
{ name: 'Coffee', cost: 3, icon: '', sect: 'Food' },
{ name: 'Teapot', cost: 3, icon: '🫖', sect: 'Food' },
{ name: 'Tea', cost: 3, icon: '🍵', sect: 'Food' },
{ name: 'Sake', cost: 3, icon: '🍶', sect: 'Food' },
{ name: 'Champagne', cost: 3, icon: '🍾', sect: 'Food' },
{ name: 'Wine Glass', cost: 3, icon: '🍷', sect: 'Food' },
{ name: 'Cocktail Glass', cost: 3, icon: '🍸', sect: 'Food' },
{ name: 'Tropical Drink', cost: 3, icon: '🍹', sect: 'Food' },
{ name: 'Beer Mug', cost: 3, icon: '🍺', sect: 'Food' },
{ name: 'Tumbler', cost: 3, icon: '🥃', sect: 'Food' },
{ name: 'Soda', cost: 3, icon: '🥤', sect: 'Food' },
{ name: 'Bubble Tea', cost: 3, icon: '🧋', sect: 'Food' },
{ name: 'Beverage Box', cost: 30, icon: '🧃', sect: 'Food' },
{ name: 'Mate', cost: 3, icon: '🧉', sect: 'Food' }]);
[
{ name: 'Grapes', cost: 2, icon: '🍇', sect: 'Food' },
{ name: 'Melon', cost: 5, icon: '🍈', sect: 'Food' },
{ name: 'Watermelon', cost: 5, icon: '🍉', sect: 'Food' },
{ name: 'Tangerine', cost: 3, icon: '🍊', sect: 'Food' },
{ name: 'Lemon', cost: 3, icon: '🍋', sect: 'Food' },
{ name: 'Banana', cost: 4, icon: '🍌', sect: 'Food' },
{ name: 'Pineapple', cost: 4, icon: '🍍', sect: 'Food' },
{ name: 'Mango', cost: 3, icon: '🥭', sect: 'Food' },
{ name: 'Red Apple', cost: 3, icon: '🍎', sect: 'Food' },
{ name: 'Green Apple', cost: 3, icon: '🍏', sect: 'Food' },
{ name: 'Pear', cost: 3, icon: '🍐', sect: 'Food' },
{ name: 'Peach', cost: 3, icon: '🍑', sect: 'Food' },
{ name: 'Cherries', cost: 4, icon: '🍒', sect: 'Food' },
{ name: 'Strawberry', cost: 3, icon: '🍓', sect: 'Food' },
{ name: 'Blueberries', cost: 3, icon: '🫐', sect: 'Food' },
{ name: 'Kiwi', cost: 3, icon: '🥝', sect: 'Food' },
{ name: 'Tomato', cost: 4, icon: '🍅', sect: 'Food' },
{ name: 'Olive', cost: 4, icon: '🫒', sect: 'Food' },
{ name: 'Coconut', cost: 3, icon: '🥥', sect: 'Food' },
{ name: 'Avocado', cost: 3, icon: '🥑', sect: 'Food' },
{ name: 'Eggplant', cost: 10, icon: '🍆', sect: 'Food' },
{ name: 'Potato', cost: 3, icon: '🥔', sect: 'Food' },
{ name: 'Carrot', cost: 3, icon: '🥕', sect: 'Food' },
{ name: 'Ear of Corn', cost: 3, icon: '🌽', sect: 'Food' },
{ name: 'Hot Pepper', cost: 3, icon: '🌶️', sect: 'Food' },
{ name: 'Bell Pepper', cost: 3, icon: '🫑', sect: 'Food' },
{ name: 'Cucumber', cost: 3, icon: '🥒', sect: 'Food' },
{ name: 'Leafy Green', cost: 3, icon: '🥬', sect: 'Food' },
{ name: 'Broccoli', cost: 2, icon: '🥦', sect: 'Food' },
{ name: 'Garlic', cost: 3, icon: '🧄', sect: 'Food' },
{ name: 'Onion', cost: 3, icon: '🧅', sect: 'Food' },
{ name: 'Mushroom', cost: 3, icon: '🍄', sect: 'Food' },
{ name: 'Peanuts', cost: 4, icon: '🥜', sect: 'Food' },
{ name: 'Chestnut', cost: 3, icon: '🌰', sect: 'Food' },
{ name: 'Bread', cost: 5, icon: '🍞', sect: 'Food' },
{ name: 'Croissant', cost: 7, icon: '🥐', sect: 'Food' },
{ name: 'Baguette Bread', cost: 10, icon: '🥖', sect: 'Food' },
{ name: 'Flatbread', cost: 9, icon: '🫓', sect: 'Food' },
{ name: 'Pretzel', cost: 5, icon: '🥨', sect: 'Food' },
{ name: 'Bagel', cost: 4, icon: '🥯', sect: 'Food' },
{ name: 'Pancakes', cost: 5, icon: '🥞', sect: 'Food' },
{ name: 'Waffle', cost: 5, icon: '🧇', sect: 'Food' },
{ name: 'Cheese Wedge', cost: 3, icon: '🧀', sect: 'Food' },
{ name: 'Meat on the Bone', cost: 5, icon: '🍖', sect: 'Food' },
{ name: 'Checken Leg', cost: 5, icon: '🍗', sect: 'Food' },
{ name: 'Cut of Meat', cost: 4, icon: '🥩', sect: 'Food' },
{ name: 'Bacon', cost: 4, icon: '🥓', sect: 'Food' },
{ name: 'Hamburger', cost: 5, icon: '🍔', sect: 'Food' },
{ name: 'French Fries', cost: 3, icon: '🍟', sect: 'Food' },
{ name: 'Pizza', cost: 6, icon: '🍕', sect: 'Food' },
{ name: 'Hot Dog', cost: 3, icon: '🌭', sect: 'Food' },
{ name: 'Sandwich', cost: 3, icon: '🥪', sect: 'Food' },
{ name: 'Taco', cost: 3, icon: '🌮', sect: 'Food' },
{ name: 'Burrito', cost: 5, icon: '🌯', sect: 'Food' },
{ name: 'Tamale', cost: 5, icon: '🫔', sect: 'Food' },
{ name: 'Stuffed Flatbread', cost: 5, icon: '🥙', sect: 'Food' },
{ name: 'Falafel', cost: 4, icon: '🧆', sect: 'Food' },
{ name: 'Egg', cost: 3, icon: '🥚', sect: 'Food' },
{ name: 'Hot Pot', cost: 12, icon: '🍲', sect: 'Food' },
{ name: 'Fondue', cost: 8, icon: '🫕', sect: 'Food' },
{ name: 'Green Salad', cost: 3, icon: '🥗', sect: 'Food' },
{ name: 'Popcorn', cost: 3, icon: '🍿', sect: 'Food' },
{ name: 'Butter', cost: 2, icon: '🧈', sect: 'Food' },
{ name: 'Salt', cost: 2, icon: '🧂', sect: 'Food' },
{ name: 'Canned Food', cost: 3, icon: '🥫', sect: 'Food' },
{ name: 'Bento Box', cost: 7, icon: '🍱', sect: 'Food' },
{ name: 'Rice Cracker', cost: 1, icon: '🍘', sect: 'Food' },
{ name: 'Rice Ball', cost: 3, icon: '🍙', sect: 'Food' },
{ name: 'Cooked Rice', cost: 3, icon: '🍚', sect: 'Food' },
{ name: 'Curry Rice', cost: 4, icon: '🍛', sect: 'Food' },
{ name: 'Ramen', cost: 4, icon: '🍜', sect: 'Food' },
{ name: 'Spaghetti', cost: 5, icon: '🍝', sect: 'Food' },
{ name: 'Roasted Sweet Potato', cost: 3, icon: '🍠', sect: 'Food' },
{ name: 'Oden', cost: 3, icon: '🍢', sect: 'Food' },
{ name: 'Sushi', cost: 4, icon: '🍣', sect: 'Food' },
{ name: 'Fried Shrimp', cost: 3, icon: '🍤', sect: 'Food' },
{ name: 'Fish Cake', cost: 3, icon: '🍥', sect: 'Food' },
{ name: 'Moon Cake', cost: 3, icon: '🥮', sect: 'Food' },
{ name: 'Dango', cost: 3, icon: '🍡', sect: 'Food' },
{ name: 'Dumpling', cost: 3, icon: '🥟', sect: 'Food' },
{ name: 'Fortune Cookie', cost: 3, icon: '🥠', sect: 'Food' },
{ name: 'Oyster', cost: 4, icon: '🦪', sect: 'Food' },
{ name: 'Ice Cream Cone', cost: 3, icon: '🍦', sect: 'Food' },
{ name: 'Shaved Ice', cost: 3, icon: '🍧', sect: 'Food' },
{ name: 'Ice Cream', cost: 3, icon: '🍨', sect: 'Food' },
{ name: 'Doughnut', cost: 3, icon: '🍩', sect: 'Food' },
{ name: 'Cookie', cost: 3, icon: '🍪', sect: 'Food' },
{ name: 'Birthday Cake', cost: 7, icon: '🎂', sect: 'Food' },
{ name: 'Shortcake', cost: 4, icon: '🍰', sect: 'Food' },
{ name: 'Cupcake', cost: 3, icon: '🧁', sect: 'Food' },
{ name: 'Pie', cost: 4, icon: '🥧', sect: 'Food' },
{ name: 'Chocolate Bar', cost: 2, icon: '🍫', sect: 'Food' },
{ name: 'Candy', cost: 1, icon: '🍬', sect: 'Food' },
{ name: 'Lollipop', cost: 1, icon: '🍭', sect: 'Food' },
{ name: 'Custard', cost: 3, icon: '🍮', sect: 'Food' },
{ name: 'Honey Pot', cost: 3, icon: '🍯', sect: 'Food' },
{ name: 'Baby Bottle', cost: 3, icon: '🍼', sect: 'Food' },
{ name: 'Glass of Milk', cost: 3, icon: '🥛', sect: 'Food' },
{ name: 'Coffee', cost: 3, icon: '', sect: 'Food' },
{ name: 'Teapot', cost: 3, icon: '🫖', sect: 'Food' },
{ name: 'Tea', cost: 3, icon: '🍵', sect: 'Food' },
{ name: 'Sake', cost: 3, icon: '🍶', sect: 'Food' },
{ name: 'Champagne', cost: 3, icon: '🍾', sect: 'Food' },
{ name: 'Wine Glass', cost: 3, icon: '🍷', sect: 'Food' },
{ name: 'Cocktail Glass', cost: 3, icon: '🍸', sect: 'Food' },
{ name: 'Tropical Drink', cost: 3, icon: '🍹', sect: 'Food' },
{ name: 'Beer Mug', cost: 3, icon: '🍺', sect: 'Food' },
{ name: 'Tumbler', cost: 3, icon: '🥃', sect: 'Food' },
{ name: 'Soda', cost: 3, icon: '🥤', sect: 'Food' },
{ name: 'Bubble Tea', cost: 3, icon: '🧋', sect: 'Food' },
{ name: 'Beverage Box', cost: 30, icon: '🧃', sect: 'Food' },
{ name: 'Mate', cost: 3, icon: '🧉', sect: 'Food' },
//Weapons
{ name: 'Swords_special', cost: 3, icon: '⚔️', sect: 'Weapons' },
{ name: 'Boomerang', cost: 300, icon: '🪃', sect: 'Weapons' },
{ name: 'Boomerang', cost: 200, icon: '🏹', sect: 'Weapons' },
{ name: 'Knife', cost: 20, icon: '🔪', sect: 'Weapons' },
{ name: 'Dagger', cost: 60, icon: '🗡', sect: 'Weapons' },
{ name: 'Shield', cost: 100, icon: '🛡', sect: 'Weapons' },
{ name: 'Axe', cost: 40, icon: '🪓', sect: 'Weapons' },
{ name: 'Trident', cost: 140, icon: '🔱', sect: 'Weapons' },
{ name: 'Scissors', cost: 10, icon: '✂️', sect: 'Weapons' }
]);
});
client.close();
client.close();
const END = d.getTime();
console.log(`Total time in SECONDS: ${(((END - START) % 60000) / 1000).toFixed(0)} ms!`);
+66 -8
View File
@@ -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 }
+18 -4
View File
@@ -14,8 +14,9 @@ const BASE = {
const STATE = {
IDLE: 0,
FIGHTING: 1,
PRONE: 2,
WAITING: 3
DEFENDING: 2,
PRONE: 3,
WAITING: 4 //For items ONLY
}
//Note that leveling up to the next level takes 10% more xp than the previous one
@@ -37,7 +38,8 @@ function CreateNewCollection(message, client, server, id, opponent = null, game
if (err) { return console.log(err); }
if (!collinfo) {
message.reply("You didn't have a place in my databases, so I created one for you!\nPlease try your command again!")
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hp: BASE.HP, mp: BASE.MP, game: game, opponent: opponent, state: STATE.IDLE});
let hp_mp = {maxhp: BASE.HP, hp: BASE.HP, maxmp: BASE.MP, mp: BASE.MP}
dbo.insertOne({balance: 10, rank: 1, lastdayworked: 0, xp: 0, hpmp: hp_mp, game: game, opponent: opponent, state: STATE.IDLE, equipped: { weapons: {main: null, secondary: null}, items: {}}});
}
});
});
@@ -65,9 +67,21 @@ function addxp(message, dbo, amt, xp_list) {
needed = xp_list.get(rank);
}
rank --; //Maybe?
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank }});
let newhp;
if (newhp < 200) {
newhp = BASE.HP * rank;
} else {
newhp = temp.hpmp.hp + 50;
}
let newmp = temp.mp + 5;
dbo.updateOne({balance: temp.balance, rank: temp.rank, lastdayworked: temp.lastdayworked}, { $set: { rank: rank, hpmp: {maxhp: newhp, maxmp: newmp} }});
message.channel.send('Congradulations <@' + message.author.id + '> for reaching rank ' + String(rank) + '!');
}
} else {
message.reply("You've already reached max level!");
}
dbo.updateOne({balance: temp.balance}, { $set: { xp: txp}});
+61
View File
@@ -0,0 +1,61 @@
//@ts-check
const { addxp, STATE, BASE } = require("./econ.js");
//#region game lose/win
function loseGame(user_dbo, xp_collection, message, bot = null) {
return new Promise(function(resolve, reject) {
user_dbo.find({"game": {$exists: true}}).toArray(function(err, docs){
const doc = docs[0];
if (doc == undefined) { return message.reply("Oops! There's been an error! Please contact support if this problem persists!"); }
if (doc.game == null) { return message.reply("You're not even in a game and you're trying to quit! Sad..."); }
//If this function was called from "winGame", return
if (doc.opponent) {
//If remove some money (looting) [maybe implement a "friendly" game setting later with no looting]
var addbal = doc.rank * 2;
if (doc.balance - addbal < 5) { addbal = addbal - doc.balance; }
if (doc.balance > 5) {
user_dbo.updateOne(doc, { $set: { balance: doc.balance - addbal}});
}
} else { message.channel.delete(); }
//Update the player's xp
addxp(message, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection)
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, hp: doc.hpmp.maxhp, mp: doc.hpmp.maxmp }});
resolve(addbal);
});
});
}
function winGame(client, bot, db, user_dbo, xp_collection, message) {
user_dbo.find({"game": {$exists: true}}).toArray(function(err, docs){
const doc = docs[0];
//Check for an opponent
if (doc.opponent != null) {
let other = db.collection(doc.opponent);
let promise_temp = loseGame(other, xp_collection, message);
promise_temp.then(function(result) {
var amt_taken = result;
user_dbo.updateOne({'balance': {$exists: true}}, { $set: { balance: doc.balance + amt_taken}});
});
}
//Delete the bot's record of the game
client.db('B|S' + bot.user.id).collection(user_dbo.s.namespace.db.substr(0, user_dbo.s.namespace.db.length - 6)).drop();
//Update the player with xp
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, xp: doc.xp + (BASE.XP * doc.rank), hp: doc.hpmp.maxhp, mp: doc.hpmp.maxmp }});
message.channel.delete();
});
}
module.exports = { winGame, loseGame }
+7 -59
View File
@@ -2,11 +2,13 @@
const { MongoClient, ServerApiVersion } = require('mongodb');
let ecoimport = require("./econ.js");
let battle = require("./battle.js");
let { handle } = require("./battle.js"); //PROBLEM (CIRCULAR DEPENDANCY)
let snowflake = require("./addons/snowflake.js");
const STATE = ecoimport.STATE;
const BASE = ecoimport.BASE;
const { winGame, loseGame } = require('./external_game_functions.js');
//Has a list of all games (used to change player state)
const allGames = ['battle'];
// const { NULL } = require('mysql/lib/protocol/constants/types');
@@ -56,59 +58,6 @@ async function Initialize(bot, user_dbo, command, message, first, second, other_
});
}
//#region game lose/win
function loseGame(user_dbo, xp_collection, message, bot = null) {
return new Promise(function(resolve, reject) {
user_dbo.find({"game": {$exists: true}}).toArray(function(err, docs){
const doc = docs[0];
if (doc == undefined) { return message.reply("Oops! There's been an error! Please contact support if this problem persists!"); }
if (doc.game == null) { return message.reply("You're not even in a game and you're trying to quit! Sad..."); }
//If this function was not called from "winGame", return
if (doc.opponent) {
//If remove some money (looting) [maybe implement a "friendly" game setting later with no looting]
var addbal = doc.rank * 2;
if (doc.balance - addbal < 5) { addbal = addbal - doc.balance; }
if (doc.balance > 5) {
user_dbo.updateOne(doc, { $set: { balance: doc.balance - addbal}});
}
}
//Update the player's xp
ecoimport.addxp(message, user_dbo, Math.ceil((BASE.XP * doc.rank)/2),xp_collection)
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE }});
resolve(addbal);
});
});
}
function winGame(client, bot, db, user_dbo, xp_collection, message) {
user_dbo.find({"game": {$exists: true}}).toArray(function(err, docs){
const doc = docs[0];
//Check for an opponent
if (doc.opponent != null) {
let other = db.collection(doc.opponent);
let promise_temp = loseGame(other, xp_collection, message);
promise_temp.then(function(result) {
var amt_taken = result;
user_dbo.updateOne({'balance': {$exists: true}}, { $set: { balance: doc.balance + amt_taken}});
});
}
//Delete the bot's record of the game
client.db('B|S' + bot.user.id).collection(user_dbo.s.namespace.db.substr(0, user_dbo.s.namespace.db.length - 6)).drop();
//Update the player with xp
user_dbo.updateOne({"game": {$exists: true}}, { $set: { game: null, opponent: null, state: STATE.IDLE, xp: doc.xp + (BASE.XP * doc.rank) }});
});
}
//#endregion
//replies to the message with current game specifics
@@ -168,6 +117,7 @@ function acceptIsValid(bot, other_discord, message, msg, tag_len) {
function hpmp(message, command, dbo) {
throw 'THIS HAS NOT BEEN UPDATED WITH THE MOST RECENT VERSION OF THE MONGODB STRUCTURE!';
if (command == 'hp') {
dbo.find({"hp": {$exists: true}}).toArray(function(err, doc) {
return message.reply(`You have ${String(doc[0].hp)} hp left!`);
@@ -183,7 +133,7 @@ function hpmp(message, command, dbo) {
//#region GAME SPECIFIC
function in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items) {
function in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection) {
//Maybe fix this later......
let turn = doc.turn;
@@ -197,7 +147,7 @@ function in_game_redirector(bot, interaction, threadname, doc, client, mongouri,
dbo.find({'game': {$exists: true}}).toArray(function (err, docs) {
const game = docs[0].game
switch (game) {
case 'battle': battle.handle(dbo, other, bot, thread, interaction.customId.toLowerCase(), mongouri, items);
case 'battle': handle(client, dbo, other, bot, thread, interaction.customId.toLowerCase(), mongouri, items, interaction, xp_collection);
}
});
}
@@ -296,7 +246,7 @@ module.exports ={
if (newCommand == 'battle') {
const result = Initialize(bot, dbo, newCommand, msg, id, other_discord.id, other);
result.then(function (thread) {
battle.handle(dbo, other, bot, thread, 'initalize', mongouri, items);
handle(client, dbo, other, bot, thread, 'initalize', mongouri, items, null, xp_collection);
});
}
} else if (command == 'quit') {
@@ -313,8 +263,6 @@ module.exports ={
loseGame(dbo, xp_collection, message, bot);
channel.send(`<@${message.author.id}> has quit a game of "${game}"!`);
}
message.channel.delete();
}
else if (command == 'status') {
getGame(message, args, db);
+2 -1
View File
@@ -147,6 +147,7 @@ bot.on('interactionCreate', async interaction => {
const doc = result[1];
const threadname = doc.thread;
const dbo = client.db(interaction.guildId + '[ECON]').collection(id);
dbo.find({ 'state': {$exists: true} }).toArray(async function (err, docs) {
if (interaction.user.id == id) {
await interaction.deferReply();
@@ -154,7 +155,7 @@ bot.on('interactionCreate', async interaction => {
//Check State
if (docs[0].state == STATE.FIGHTING) {
//Do turn stuff
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items);
bot.commands.get('game').in_game_redirector(bot, interaction, threadname, doc, client, mongouri, items, xp_collection);
}
turnManager.changeTurn(client, bot, interaction);