""" سیستم دستاوردها و اهداف شخصی برای بازیکن """ class AchievementsSystem: """سیستم دستاوردها و اهداف شخصی برای بازیکن""" def __init__(self, game_state): """ساخت یک نمونه جدید از سیستم دستاوردها""" self.game_state = game_state self.achievements = [] self.personal_objectives = [] self.completed_achievements = [] def initialize(self): """راه‌اندازی اولیه سیستم دستاوردها""" # بارگیری دستاوردهای پیش‌فرض self._load_default_achievements() # ایجاد اهداف شخصی بر اساس کشور انتخابی self._create_personal_objectives() def _load_default_achievements(self): """بارگیری دستاوردهای پیش‌فرض""" self.achievements = [ { "id": "WORLD_DOMINATION_1", "name": "تسلط بر منطقه", "description": "کنترل 3 کشور همسایه", "category": "Military", "points": 50, "condition": lambda gs: gs.controlled_territories >= 4, "unlocked": False }, { "id": "WORLD_DOMINATION_2", "name": "امپراتور", "description": "کنترل 6 کشور", "category": "Military", "points": 100, "condition": lambda gs: gs.controlled_territories >= 7, "unlocked": False }, { "id": "WORLD_DOMINATION_3", "name": "تسلط جهانی", "description": "کنترل بیش از نصف کشورهای جهان", "category": "Military", "points": 200, "condition": lambda gs: gs.controlled_territories >= 12, "unlocked": False }, { "id": "ECONOMIC_1", "name": "تجارت‌گر ماهر", "description": "درآمد تجاری بیش از 70%", "category": "Economy", "points": 30, "condition": lambda gs: gs.economy["trade"] >= 70, "unlocked": False }, { "id": "ECONOMIC_2", "name": "ثروتمند جهان", "description": "دارایی بیش از 100,000 سکه طلا", "category": "Economy", "points": 75, "condition": lambda gs: gs.gold >= 100000, "unlocked": False }, { "id": "CULTURAL_1", "name": "فرهنگ‌گستر", "description": "نفوذ فرهنگی بیش از 60%", "category": "Culture", "points": 40, "condition": lambda gs: gs.cultural_influence >= 60, "unlocked": False }, { "id": "CULTURAL_2", "name": "فرهنگ جهانی", "description": "نفوذ فرهنگی بیش از 80%", "category": "Culture", "points": 100, "condition": lambda gs: gs.cultural_influence >= 80, "unlocked": False }, { "id": "TECHNOLOGY_1", "name": "پیشرو فناوری", "description": "دستیابی به سطح فناوری 5", "category": "Technology", "points": 50, "condition": lambda gs: gs.technology_level >= 5, "unlocked": False }, { "id": "RELIGIOUS_1", "name": "دین‌گستر", "description": "نفوذ دینی بیش از 50%", "category": "Religion", "points": 40, "condition": lambda gs: gs.religious_influence >= 50, "unlocked": False }, { "id": "RELIGIOUS_2", "name": "دین جهانی", "description": "نفوذ دینی بیش از 75%", "category": "Religion", "points": 100, "condition": lambda gs: gs.religious_influence >= 75, "unlocked": False }, { "id": "STABILITY_1", "name": "پایداری سیاسی", "description": "ثبات سیاسی بیش از 80% برای 10 سال متوالی", "category": "Politics", "points": 60, "condition": lambda gs: gs.political_stability >= 80, "unlocked": False, "consecutive_years": 0 }, { "id": "HAPPINESS_1", "name": "سرزمین شادی", "description": "شادی مردم بیش از 75% برای 5 سال متوالی", "category": "Society", "points": 50, "condition": lambda gs: gs.happiness >= 75, "unlocked": False, "consecutive_years": 0 } ] def _create_personal_objectives(self): """ایجاد اهداف شخصی بر اساس کشور انتخابی""" country = self.game_state.player_country["name"] # اهداف عمومی general_objectives = [ { "id": "GENERAL_1", "name": "توسعه اقتصادی", "description": "افزایش درآمد تجاری به 70%", "target_value": 70, "current_value": self.game_state.economy["trade"], "reward": {"gold": 5000, "culture_score": 5}, "completed": False }, { "id": "GENERAL_2", "name": "تثبیت حکومت", "description": "افزایش ثبات سیاسی به 80%", "target_value": 80, "current_value": self.game_state.political_stability, "reward": {"political_stability": 10, "diplomacy_points": 5}, "completed": False } ] # اهداف خاص کشور country_objectives = [] if country == "پادشاهی ایران": country_objectives = [ { "id": "IRAN_1", "name": "اتحاد با همسایگان", "description": "ارتقای روابط با مصر و چین به سطح متحد", "target_value": 70, "current_value": min( self.game_state.relations.get("مصر", 0), self.game_state.relations.get("چین", 0) ), "reward": {"relations": {"+": 20}, "culture_score": 10}, "completed": False }, { "id": "IRAN_2", "name": "گسترش فرهنگ", "description": "افزایش نفوذ فرهنگی به 60%", "target_value": 60, "current_value": self.game_state.cultural_influence, "reward": {"cultural_influence": 15, "culture_score": 15}, "completed": False } ] elif country == "امپراتوری عثمانی": country_objectives = [ { "id": "OTTOMAN_1", "name": "تسلط بر منطقه", "description": "کنترل 5 کشور همسایه", "target_value": 5, "current_value": self.game_state.controlled_territories - 1, "reward": {"controlled_territories": 2, "military_strength": 15}, "completed": False }, { "id": "OTTOMAN_2", "name": "تقویت نیروی دریایی", "description": "افزایش نیروی دریایی به 70%", "target_value": 70, "current_value": self.game_state.military_strength * 0.6, # فرض می‌کنیم 60% نیروی دریایی است "reward": {"military": {"navy": 20}, "economy": {"trade": 10}}, "completed": False } ] self.personal_objectives = general_objectives + country_objectives def display_achievements(self): """نمایش دستاوردها به بازیکن""" from ui.console_ui import ConsoleUI ConsoleUI.clear_screen() ConsoleUI.display_section_title("دستاوردها") # نمایش دستاوردهای بازشده ConsoleUI.display_section_title("دستاوردهای کسب شده", width=60) unlocked = [a for a in self.achievements if a["unlocked"]] if not unlocked: ConsoleUI.display_message("شما هنوز هیچ دستاوردی کسب نکرده‌اید.", indent=2) else: total_points = sum(a["points"] for a in unlocked) ConsoleUI.display_message(f"مجموع امتیازات: {total_points}", indent=2) for achievement in unlocked: ConsoleUI.display_message(f"✓ {achievement['name']} ({achievement['points']} امتیاز)", indent=2) ConsoleUI.display_message(f" {achievement['description']}", indent=4) # نمایش دستاوردهای قابل کسب ConsoleUI.display_section_title("دستاوردهای قابل کسب", width=60) locked = [a for a in self.achievements if not a["unlocked"]] if not locked: ConsoleUI.display_message("شما تمام دستاوردها را کسب کرده‌اید!", indent=2) else: for achievement in locked: ConsoleUI.display_message(f"□ {achievement['name']} ({achievement['points']} امتیاز)", indent=2) ConsoleUI.display_message(f" {achievement['description']}", indent=4) ConsoleUI.wait_for_enter() def display_personal_objectives(self): """نمایش اهداف شخصی به بازیکن""" from ui.console_ui import ConsoleUI ConsoleUI.clear_screen() ConsoleUI.display_section_title("اهداف شخصی") if not self.personal_objectives: ConsoleUI.display_message("شما هیچ هدف شخصی ندارید.", indent=2) ConsoleUI.wait_for_enter() return for objective in self.personal_objectives: status = "✓" if objective["completed"] else "□" progress = min(100, int((objective["current_value"] / objective["target_value"]) * 100)) ConsoleUI.display_message(f"{status} {objective['name']}", indent=2) ConsoleUI.display_message(f" {objective['description']}", indent=4) ConsoleUI.display_message(f" پیشرفت: {progress}% ({objective['current_value']}/{objective['target_value']})", indent=4) # نمایش پاداش در صورت تکمیل if objective["completed"]: ConsoleUI.display_message(" پاداش کسب شده:", indent=4) for reward, value in objective["reward"].items(): if isinstance(value, dict) and "+" in value: ConsoleUI.display_message(f" • {reward}: +{value['+']}", indent=6) else: ConsoleUI.display_message(f" • {reward}: +{value}", indent=6) ConsoleUI.wait_for_enter() def check_achievements(self): """بررسی و به‌روزرسانی دستاوردها""" for achievement in self.achievements: if achievement["unlocked"]: continue # برای دستاوردهایی که نیاز به سال‌های متوالی دارند if "consecutive_years" in achievement: if achievement["condition"](self.game_state): achievement["consecutive_years"] += 1 if achievement["consecutive_years"] >= 5: # فرض می‌کنیم 5 سال متوالی لازم است self._unlock_achievement(achievement) else: achievement["consecutive_years"] = 0 # برای دستاوردهای معمولی elif achievement["condition"](self.game_state): self._unlock_achievement(achievement) def _unlock_achievement(self, achievement): """باز کردن یک دستاورد""" achievement["unlocked"] = True self.completed_achievements.append(achievement) from ui.console_ui import ConsoleUI ConsoleUI.display_success(f"دستاورد جدید کسب شد: {achievement['name']}!") ConsoleUI.display_message(f"{achievement['description']}") ConsoleUI.display_message(f"امتیاز: {achievement['points']}") ConsoleUI.wait_for_enter() def check_personal_objectives(self): """بررسی و به‌روزرسانی اهداف شخصی""" for objective in self.personal_objectives: if objective["completed"]: continue # به‌روزرسانی مقدار فعلی if objective["id"] == "GENERAL_1": objective["current_value"] = self.game_state.economy["trade"] elif objective["id"] == "GENERAL_2": objective["current_value"] = self.game_state.political_stability elif objective["id"] == "IRAN_1" or objective["id"] == "OTTOMAN_1": objective["current_value"] = self.game_state.controlled_territories - 1 elif objective["id"] == "IRAN_2": objective["current_value"] = self.game_state.cultural_influence # بررسی تکمیل هدف if objective["current_value"] >= objective["target_value"]: self._complete_objective(objective) def _complete_objective(self, objective): """تکمیل یک هدف شخصی و اعمال پاداش""" objective["completed"] = True # اعمال پاداش for reward_type, value in objective["reward"].items(): if reward_type == "relations" and isinstance(value, dict) and "+" in value: for country in self.game_state.relations: if country != self.game_state.player_country["name"]: self.game_state.relations[country] = min(100, self.game_state.relations[country] + value["+"]) elif reward_type in self.game_state: self.game_state[reward_type] = min(100, self.game_state[reward_type] + value) elif reward_type in self.game_state.economy: self.game_state.economy[reward_type] = min(100, self.game_state.economy[reward_type] + value) elif reward_type == "military" and isinstance(value, dict): for tech, val in value.items(): self.game_state.technology[tech] = min(10, self.game_state.technology[tech] + val) elif reward_type == "gold": self.game_state.gold += value from ui.console_ui import ConsoleUI ConsoleUI.display_success(f"هدف شخصی کامل شد: {objective['name']}!") ConsoleUI.display_message("پاداش:") for reward, value in objective["reward"].items(): if isinstance(value, dict) and "+" in value: ConsoleUI.display_message(f"• {reward}: +{value['+']}") else: ConsoleUI.display_message(f"• {reward}: +{value}") ConsoleUI.wait_for_enter() def annual_update(self): """به‌روزرسانی‌های سالانه سیستم دستاوردها""" self.check_achievements() self.check_personal_objectives()