Fix magazine and bullet usage limits
- Fixed bug where players could use magazines beyond their level's maximum limit - Added validation to prevent using bullets when magazine is already full - Magazine items now respect level-based limits (e.g., 3 magazines at level 1) - Items are not consumed from inventory if they can't be used due to limits - Added proper error messages for when limits are reached - Updated ShopManager to work with LevelManager for limit validation
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"players": {
|
||||
"computertech": {
|
||||
"nick": "computertech",
|
||||
"xp": 67,
|
||||
"nick": "ComputerTech",
|
||||
"xp": 2,
|
||||
"ducks_shot": 6,
|
||||
"ducks_befriended": 2,
|
||||
"shots_fired": 2,
|
||||
@@ -10,14 +10,30 @@
|
||||
"accuracy": 63,
|
||||
"gun_confiscated": false,
|
||||
"current_ammo": 6,
|
||||
"magazines": 3,
|
||||
"magazines": 7,
|
||||
"bullets_per_magazine": 6,
|
||||
"jam_chance": 5,
|
||||
"inventory": {
|
||||
"1": 1
|
||||
},
|
||||
"temporary_effects": []
|
||||
},
|
||||
"seokly": {
|
||||
"nick": "seokly",
|
||||
"xp": 0,
|
||||
"ducks_shot": 0,
|
||||
"ducks_befriended": 0,
|
||||
"shots_fired": 0,
|
||||
"shots_missed": 0,
|
||||
"accuracy": 75,
|
||||
"gun_confiscated": false,
|
||||
"current_ammo": 6,
|
||||
"magazines": 3,
|
||||
"bullets_per_magazine": 6,
|
||||
"jam_chance": 15,
|
||||
"inventory": {},
|
||||
"temporary_effects": []
|
||||
}
|
||||
},
|
||||
"last_save": "1758909688.9995604"
|
||||
"last_save": "1758910394.7242796"
|
||||
}
|
||||
@@ -410,3 +410,93 @@
|
||||
19:04:05.573 📘 INFO DuckHuntBot.Game Normal duck spawned in #ct
|
||||
19:05:15.648 📘 INFO DuckHuntBot.Game Fast duck (hidden) spawned in #ct
|
||||
19:05:39.670 📘 INFO DuckHuntBot.Game Normal duck spawned in #ct
|
||||
19:06:48.726 📘 INFO DuckHuntBot.Game Normal duck spawned in #ct
|
||||
19:06:49.141 📘 INFO DuckHuntBot 🛑 Received SIGINT (Ctrl+C), shutting down immediately...
|
||||
19:06:49.151 📘 INFO DuckHuntBot 🔄 Cancelled 5 running tasks
|
||||
19:06:49.158 📘 INFO DuckHuntBot Message loop cancelled
|
||||
19:06:49.159 📘 INFO DuckHuntBot Message loop ended
|
||||
19:06:49.159 📘 INFO DuckHuntBot 🛑 Main loop cancelled
|
||||
19:06:49.160 📘 INFO DuckHuntBot.Game Duck spawning loop cancelled
|
||||
19:06:49.161 📘 INFO DuckHuntBot.Game Duck timeout loop cancelled
|
||||
19:06:49.161 📘 INFO DuckHuntBot.Game Game loops cancelled
|
||||
19:06:49.185 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:06:49.186 📘 INFO DuckHuntBot 💾 Database saved
|
||||
19:06:49.398 📘 INFO DuckHuntBot 🔌 IRC connection closed
|
||||
19:06:49.399 📘 INFO DuckHuntBot ✅ Bot shutdown complete
|
||||
19:06:57.707 📘 INFO DuckHuntBot Unified logging system initialized: all logs in duckhunt.log
|
||||
19:06:57.707 📘 INFO DuckHuntBot Debug mode: ON
|
||||
19:06:57.707 📘 INFO DuckHuntBot Log everything: YES
|
||||
19:06:57.707 📘 INFO DuckHuntBot Unified format: YES
|
||||
19:06:57.707 📘 INFO DuckHuntBot Console level: INFO
|
||||
19:06:57.707 📘 INFO DuckHuntBot File level: DEBUG
|
||||
19:06:57.708 📘 INFO DuckHuntBot Main log: /home/colby/duckhunt/logs/duckhunt.log
|
||||
19:06:57.708 📘 INFO DuckHuntBot 🤖 Initializing DuckHunt Bot components...
|
||||
19:06:57.708 📘 INFO DuckHuntBot.DB Loaded 1 players from duckhunt.json
|
||||
19:06:57.715 📘 INFO SASL Unified logging system initialized: all logs in duckhunt.log
|
||||
19:06:57.715 📘 INFO SASL Debug mode: ON
|
||||
19:06:57.716 📘 INFO SASL Log everything: YES
|
||||
19:06:57.716 📘 INFO SASL Unified format: YES
|
||||
19:06:57.717 📘 INFO SASL Console level: INFO
|
||||
19:06:57.717 📘 INFO SASL File level: DEBUG
|
||||
19:06:57.717 📘 INFO SASL Main log: /home/colby/duckhunt/logs/duckhunt.log
|
||||
19:06:57.717 📘 INFO DuckHuntBot 👑 Configured 3 admin(s): peorth, computertech, colby
|
||||
19:06:57.718 📘 INFO DuckHuntBot.Shop Loaded 9 shop items from /home/colby/duckhunt/shop.json
|
||||
19:06:57.718 📘 INFO DuckHuntBot.Levels Loaded 8 levels from /home/colby/duckhunt/levels.json
|
||||
19:06:57.719 📘 INFO DuckHuntBot 🦆 Starting DuckHunt Bot...
|
||||
19:06:57.767 📘 INFO DuckHuntBot Attempting to connect to irc.rizon.net:6697 (attempt 1/3)
|
||||
19:06:57.944 📘 INFO DuckHuntBot ✅ Successfully connected to irc.rizon.net:6697
|
||||
19:06:57.944 📘 INFO DuckHuntBot 🔐 Sending server password
|
||||
19:06:57.945 📘 INFO DuckHuntBot 🦆 Bot is now running! Press Ctrl+C to stop.
|
||||
19:06:59.122 📘 INFO DuckHuntBot Successfully registered with IRC server
|
||||
19:07:02.131 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:10.467 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:12.307 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:29.690 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:32.598 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:39.223 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:41.056 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:45.298 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:07:46.350 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 1 players [save_database:142]
|
||||
19:12:52.027 📘 INFO DuckHuntBot 🛑 Received SIGINT (Ctrl+C), shutting down immediately...
|
||||
19:12:52.066 📘 INFO DuckHuntBot 🔄 Cancelled 5 running tasks
|
||||
19:12:51.888 📘 INFO DuckHuntBot 🛑 Received SIGINT (Ctrl+C), shutting down immediately...
|
||||
19:12:52.067 📘 INFO DuckHuntBot 🔄 Cancelled 5 running tasks
|
||||
19:12:52.069 📘 INFO DuckHuntBot Message loop cancelled
|
||||
19:12:52.071 📘 INFO DuckHuntBot Message loop ended
|
||||
19:12:52.080 📘 INFO DuckHuntBot.Game Duck spawning loop cancelled
|
||||
19:12:52.082 📘 INFO DuckHuntBot.Game Duck timeout loop cancelled
|
||||
19:12:52.082 📘 INFO DuckHuntBot 🛑 Main loop cancelled
|
||||
19:12:52.085 📘 INFO DuckHuntBot.Game Game loops cancelled
|
||||
19:12:52.306 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 2 players [save_database:142]
|
||||
19:12:52.309 📘 INFO DuckHuntBot 💾 Database saved
|
||||
19:12:53.133 📘 INFO DuckHuntBot 🔌 IRC connection closed
|
||||
19:12:53.136 📘 INFO DuckHuntBot ✅ Bot shutdown complete
|
||||
19:12:53.597 📘 INFO DuckHuntBot Unified logging system initialized: all logs in duckhunt.log
|
||||
19:12:53.597 📘 INFO DuckHuntBot Debug mode: ON
|
||||
19:12:53.597 📘 INFO DuckHuntBot Log everything: YES
|
||||
19:12:53.598 📘 INFO DuckHuntBot Unified format: YES
|
||||
19:12:53.598 📘 INFO DuckHuntBot Console level: INFO
|
||||
19:12:53.598 📘 INFO DuckHuntBot File level: DEBUG
|
||||
19:12:53.598 📘 INFO DuckHuntBot Main log: /home/colby/duckhunt/logs/duckhunt.log
|
||||
19:12:53.598 📘 INFO DuckHuntBot 🤖 Initializing DuckHunt Bot components...
|
||||
19:12:53.599 📘 INFO DuckHuntBot.DB Loaded 2 players from duckhunt.json
|
||||
19:12:53.605 📘 INFO SASL Unified logging system initialized: all logs in duckhunt.log
|
||||
19:12:53.606 📘 INFO SASL Debug mode: ON
|
||||
19:12:53.606 📘 INFO SASL Log everything: YES
|
||||
19:12:53.606 📘 INFO SASL Unified format: YES
|
||||
19:12:53.606 📘 INFO SASL Console level: INFO
|
||||
19:12:53.606 📘 INFO SASL File level: DEBUG
|
||||
19:12:53.606 📘 INFO SASL Main log: /home/colby/duckhunt/logs/duckhunt.log
|
||||
19:12:53.607 📘 INFO DuckHuntBot 👑 Configured 3 admin(s): peorth, computertech, colby
|
||||
19:12:53.607 📘 INFO DuckHuntBot.Levels Loaded 8 levels from /home/colby/duckhunt/levels.json
|
||||
19:12:53.608 📘 INFO DuckHuntBot.Shop Loaded 9 shop items from /home/colby/duckhunt/shop.json
|
||||
19:12:53.608 📘 INFO DuckHuntBot 🦆 Starting DuckHunt Bot...
|
||||
19:12:53.660 📘 INFO DuckHuntBot Attempting to connect to irc.rizon.net:6697 (attempt 1/3)
|
||||
19:12:53.826 📘 INFO DuckHuntBot ✅ Successfully connected to irc.rizon.net:6697
|
||||
19:12:53.826 📘 INFO DuckHuntBot 🔐 Sending server password
|
||||
19:12:53.827 📘 INFO DuckHuntBot 🦆 Bot is now running! Press Ctrl+C to stop.
|
||||
19:12:55.118 📘 INFO DuckHuntBot Successfully registered with IRC server
|
||||
19:13:06.811 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 2 players [save_database:142]
|
||||
19:13:10.747 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 2 players [save_database:142]
|
||||
19:13:13.374 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 2 players [save_database:142]
|
||||
19:13:14.741 🔍 DEBUG DuckHuntBot.DB Database saved successfully with 2 players [save_database:142]
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -38,14 +38,14 @@ class DuckHuntBot:
|
||||
self.admins = [admin.lower() for admin in admins_list]
|
||||
self.logger.info(f"👑 Configured {len(self.admins)} admin(s): {', '.join(self.admins)}")
|
||||
|
||||
# Initialize shop manager
|
||||
shop_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'shop.json')
|
||||
self.shop = ShopManager(shop_file)
|
||||
|
||||
# Initialize level manager
|
||||
# Initialize level manager first
|
||||
levels_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'levels.json')
|
||||
self.levels = LevelManager(levels_file)
|
||||
|
||||
# Initialize shop manager with levels reference
|
||||
shop_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'shop.json')
|
||||
self.shop = ShopManager(shop_file, self.levels)
|
||||
|
||||
def get_config(self, path, default=None):
|
||||
"""Get configuration value using dot notation"""
|
||||
keys = path.split('.')
|
||||
|
||||
46
src/shop.py
46
src/shop.py
@@ -13,8 +13,9 @@ from typing import Dict, Any, Optional
|
||||
class ShopManager:
|
||||
"""Manages the DuckHunt shop system"""
|
||||
|
||||
def __init__(self, shop_file: str = "shop.json"):
|
||||
def __init__(self, shop_file: str = "shop.json", levels_manager=None):
|
||||
self.shop_file = shop_file
|
||||
self.levels = levels_manager
|
||||
self.items = {}
|
||||
self.logger = logging.getLogger('DuckHuntBot.Shop')
|
||||
self.load_items()
|
||||
@@ -198,13 +199,23 @@ class ShopManager:
|
||||
}
|
||||
|
||||
elif item_type == 'magazine':
|
||||
# Add magazines to player's inventory
|
||||
# Add magazines (limit checking is done before this function is called)
|
||||
current_magazines = player.get('magazines', 1)
|
||||
new_magazines = current_magazines + amount
|
||||
|
||||
if self.levels:
|
||||
level_info = self.levels.get_player_level_info(player)
|
||||
max_magazines = level_info.get('magazines', 3)
|
||||
# Don't exceed maximum magazines for level
|
||||
magazines_to_add = min(amount, max_magazines - current_magazines)
|
||||
else:
|
||||
# Fallback if levels not available
|
||||
magazines_to_add = amount
|
||||
|
||||
new_magazines = current_magazines + magazines_to_add
|
||||
player['magazines'] = new_magazines
|
||||
return {
|
||||
"type": "magazine",
|
||||
"added": amount,
|
||||
"added": magazines_to_add,
|
||||
"new_total": new_magazines
|
||||
}
|
||||
|
||||
@@ -520,6 +531,33 @@ class ShopManager:
|
||||
"item_name": item['name']
|
||||
}
|
||||
|
||||
# Special checks for ammo/magazine limits
|
||||
if item['type'] == 'magazine' and self.levels:
|
||||
affected_player = target_player if target_player else player
|
||||
current_magazines = affected_player.get('magazines', 1)
|
||||
level_info = self.levels.get_player_level_info(affected_player)
|
||||
max_magazines = level_info.get('magazines', 3)
|
||||
|
||||
if current_magazines >= max_magazines:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "max_magazines_reached",
|
||||
"message": f"Already at maximum magazines ({max_magazines}) for current level!",
|
||||
"item_name": item['name']
|
||||
}
|
||||
elif item['type'] == 'ammo':
|
||||
affected_player = target_player if target_player else player
|
||||
current_ammo = affected_player.get('current_ammo', 0)
|
||||
bullets_per_mag = affected_player.get('bullets_per_magazine', 6)
|
||||
|
||||
if current_ammo >= bullets_per_mag:
|
||||
return {
|
||||
"success": False,
|
||||
"error": "magazine_full",
|
||||
"message": f"Current magazine is already full ({bullets_per_mag}/{bullets_per_mag})!",
|
||||
"item_name": item['name']
|
||||
}
|
||||
|
||||
# Remove item from inventory
|
||||
inventory[item_id_str] -= 1
|
||||
if inventory[item_id_str] <= 0:
|
||||
|
||||
Reference in New Issue
Block a user