Apply visual HP bars to all combat displays
- Update combat_handlers.py to show visual enemy and player HP bars - Update action_handlers.py combat encounters with progress bars - Update combat.py attack results with visual HP displays - Add UI_EXAMPLES.md with before/after comparisons - All combat displays now use format_stat_bar() for consistency
This commit is contained in:
@@ -8,6 +8,7 @@ import random
|
|||||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
from telegram.ext import ContextTypes
|
from telegram.ext import ContextTypes
|
||||||
from . import database, keyboards, logic
|
from . import database, keyboards, logic
|
||||||
|
from .utils import format_stat_bar
|
||||||
from data.world_loader import game_world
|
from data.world_loader import game_world
|
||||||
from data.items import ITEMS
|
from data.items import ITEMS
|
||||||
|
|
||||||
@@ -20,8 +21,6 @@ logger = logging.getLogger(__name__)
|
|||||||
|
|
||||||
async def get_player_status_text(telegram_id: int) -> str:
|
async def get_player_status_text(telegram_id: int) -> str:
|
||||||
"""Generate player status text with location and stats."""
|
"""Generate player status text with location and stats."""
|
||||||
from .utils import format_stat_bar
|
|
||||||
|
|
||||||
player = await database.get_player(telegram_id)
|
player = await database.get_player(telegram_id)
|
||||||
if not player:
|
if not player:
|
||||||
return "Could not find player data."
|
return "Could not find player data."
|
||||||
@@ -124,8 +123,8 @@ async def handle_attack_wandering(query, user_id: int, player: dict, data: list)
|
|||||||
npc_def = NPCS.get(npc_id)
|
npc_def = NPCS.get(npc_id)
|
||||||
message = f"⚔️ You engage the {npc_def.emoji} {npc_def.name}!\n\n"
|
message = f"⚔️ You engage the {npc_def.emoji} {npc_def.name}!\n\n"
|
||||||
message += f"{npc_def.description}\n\n"
|
message += f"{npc_def.description}\n\n"
|
||||||
message += f"{npc_def.emoji} Enemy HP: {combat_data['npc_hp']}/{combat_data['npc_max_hp']}\n"
|
message += format_stat_bar(f"{npc_def.emoji} Enemy HP", "", combat_data['npc_hp'], combat_data['npc_max_hp']) + "\n"
|
||||||
message += f"❤️ Your HP: {player['hp']}/{player['max_hp']}\n\n"
|
message += format_stat_bar("Your HP", "❤️", player['hp'], player['max_hp']) + "\n\n"
|
||||||
message += "🎯 Your turn! What will you do?"
|
message += "🎯 Your turn! What will you do?"
|
||||||
|
|
||||||
keyboard = await keyboards.combat_keyboard(user_id)
|
keyboard = await keyboards.combat_keyboard(user_id)
|
||||||
@@ -343,8 +342,8 @@ async def handle_move(query, user_id: int, player: dict, data: list):
|
|||||||
npc_def = NPCS.get(npc_id)
|
npc_def = NPCS.get(npc_id)
|
||||||
message = f"⚠️ A {npc_def.emoji} {npc_def.name} appears!\n\n"
|
message = f"⚠️ A {npc_def.emoji} {npc_def.name} appears!\n\n"
|
||||||
message += f"{npc_def.description}\n\n"
|
message += f"{npc_def.description}\n\n"
|
||||||
message += f"{npc_def.emoji} Enemy HP: {combat_data['npc_hp']}/{combat_data['npc_max_hp']}\n"
|
message += format_stat_bar(f"{npc_def.emoji} Enemy HP", "", combat_data['npc_hp'], combat_data['npc_max_hp']) + "\n"
|
||||||
message += f"❤️ Your HP: {player['hp']}/{player['max_hp']}\n\n"
|
message += format_stat_bar("Your HP", "❤️", player['hp'], player['max_hp']) + "\n\n"
|
||||||
message += "🎯 Your turn! What will you do?"
|
message += "🎯 Your turn! What will you do?"
|
||||||
|
|
||||||
keyboard = await keyboards.combat_keyboard(user_id)
|
keyboard = await keyboards.combat_keyboard(user_id)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
from typing import Dict, List, Tuple, Optional
|
from typing import Dict, List, Tuple, Optional
|
||||||
from bot import database
|
from bot import database
|
||||||
|
from bot.utils import format_stat_bar
|
||||||
from data.npcs import NPCS, STATUS_EFFECTS
|
from data.npcs import NPCS, STATUS_EFFECTS
|
||||||
from data.items import ITEMS
|
from data.items import ITEMS
|
||||||
|
|
||||||
@@ -173,7 +174,7 @@ async def player_attack(player_id: int) -> Tuple[str, bool, bool]:
|
|||||||
'player_status_effects': json.dumps(player_effects)
|
'player_status_effects': json.dumps(player_effects)
|
||||||
})
|
})
|
||||||
|
|
||||||
message += f"\n{npc_def.emoji} {npc_def.name}: {new_npc_hp}/{combat['npc_max_hp']} HP"
|
message += "\n" + format_stat_bar(f"{npc_def.emoji} {npc_def.name}", "", new_npc_hp, combat['npc_max_hp'])
|
||||||
|
|
||||||
return (message, False, True)
|
return (message, False, True)
|
||||||
|
|
||||||
@@ -250,8 +251,8 @@ async def npc_attack(player_id: int) -> Tuple[str, bool]:
|
|||||||
'npc_status_effects': json.dumps(npc_effects)
|
'npc_status_effects': json.dumps(npc_effects)
|
||||||
})
|
})
|
||||||
|
|
||||||
message += f"\n❤️ Your HP: {new_player_hp}/{player['max_hp']}"
|
message += "\n" + format_stat_bar("Your HP", "❤️", new_player_hp, player['max_hp'])
|
||||||
message += f"\n{npc_def.emoji} {npc_def.name}: {combat['npc_hp']}/{combat['npc_max_hp']} HP"
|
message += "\n" + format_stat_bar(f"{npc_def.emoji} {npc_def.name}", "", combat['npc_hp'], combat['npc_max_hp'])
|
||||||
|
|
||||||
return (message, False)
|
return (message, False)
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Combat-related action handlers.
|
|||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
from . import database, keyboards
|
from . import database, keyboards
|
||||||
|
from .utils import format_stat_bar
|
||||||
from data.world_loader import game_world
|
from data.world_loader import game_world
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@@ -158,8 +159,8 @@ async def handle_combat_back(query, user_id: int, player: dict):
|
|||||||
keyboard = await keyboards.combat_keyboard(user_id)
|
keyboard = await keyboards.combat_keyboard(user_id)
|
||||||
|
|
||||||
message = f"⚔️ Combat with {npc_def.emoji} {npc_def.name}!\n"
|
message = f"⚔️ Combat with {npc_def.emoji} {npc_def.name}!\n"
|
||||||
message += f"{npc_def.emoji} Enemy HP: {combat_data['npc_hp']}/{combat_data['npc_max_hp']}\n"
|
message += format_stat_bar(f"{npc_def.emoji} Enemy HP", "", combat_data['npc_hp'], combat_data['npc_max_hp']) + "\n"
|
||||||
message += f"❤️ Your HP: {player['hp']}/{player['max_hp']}\n\n"
|
message += format_stat_bar("Your HP", "❤️", player['hp'], player['max_hp']) + "\n\n"
|
||||||
message += "🎯 Your turn!" if combat_data['turn'] == 'player' else "⏳ Enemy's turn..."
|
message += "🎯 Your turn!" if combat_data['turn'] == 'player' else "⏳ Enemy's turn..."
|
||||||
|
|
||||||
from .handlers import send_or_edit_with_image
|
from .handlers import send_or_edit_with_image
|
||||||
|
|||||||
Reference in New Issue
Block a user