diff --git a/COMPLETE_INIT.js b/COMPLETE_INIT.js index 4637fbf..23a81aa 100644 --- a/COMPLETE_INIT.js +++ b/COMPLETE_INIT.js @@ -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(); \ No newline at end of file +client.close(); + +const END = d.getTime(); + +console.log(`Total time in SECONDS: ${(((END - START) % 60000) / 1000).toFixed(0)} ms!`); \ No newline at end of file diff --git a/commands/db/battle.js b/commands/db/battle.js index 572f145..bb80292 100644 --- a/commands/db/battle.js +++ b/commands/db/battle.js @@ -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 } diff --git a/commands/db/econ.js b/commands/db/econ.js index 000f7b2..729bd96 100644 --- a/commands/db/econ.js +++ b/commands/db/econ.js @@ -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}}); diff --git a/commands/db/external_game_functions.js b/commands/db/external_game_functions.js new file mode 100644 index 0000000..0e03536 --- /dev/null +++ b/commands/db/external_game_functions.js @@ -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 } \ No newline at end of file diff --git a/commands/db/game.js b/commands/db/game.js index bdb9bc9..ccf03b2 100644 --- a/commands/db/game.js +++ b/commands/db/game.js @@ -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); diff --git a/main.js b/main.js index 3273270..215671f 100644 --- a/main.js +++ b/main.js @@ -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);