ysn-rfd's picture
Upload 22 files
89dc309 verified
raw
history blame
18.8 kB
"""
پلاگین دیپلماسی پیشرفته برای افزودن سیستم‌های دیپلماسی پیچیده‌تر
"""
from plugins.base_plugin import BasePlugin
from data.events.event_definitions import EVENTS
class AdvancedDiplomacyPlugin(BasePlugin):
"""پلاگین برای گسترش سیستم دیپلماسی"""
def __init__(self):
"""ساخت یک نمونه جدید از پلاگین"""
super().__init__()
self.name = "دیپلماسی پیشرفته"
self.description = "سیستم دیپلماسی پیچیده‌تر با امکانات بیشتر و سازمان‌های بین‌المللی"
self.version = "2.0.0"
self.compatible_versions = ["1.0.0"]
def apply(self, game):
"""
اعمال پلاگین به بازی
:param game: نمونه بازی که پلاگین باید به آن اعمال شود
"""
# افزودن ویژگی‌های جدید به وضعیت بازی
if not hasattr(game.game_state, 'diplomacy_relations'):
game.game_state.diplomacy_relations = {}
if not hasattr(game.game_state, 'international_orgs'):
game.game_state.international_orgs = []
# افزودن رویدادهای جدید
self._add_diplomatic_events()
# افزودن روش‌های جدید به سیستم دیپلماسی
self._extend_diplomacy_system(game)
# افزودن سازمان‌های بین‌المللی
self._add_international_organizations(game)
print(f"{self.name} با موفقیت اعمال شد.")
def _add_diplomatic_events(self):
"""افزودن رویدادهای دیپلماتیک جدید"""
new_events = [
{
"id": 100,
"name": "جنگ سایبری",
"description": "یک کشور دشمن اقدام به حمله سایبری به سیستم‌های کشور شما کرده است.",
"trigger": lambda state: state.diplomacy_points > 15,
"choices": [
{
"text": "پاسخ سریع با تیم سایبری",
"effects": {
"gold": -3000,
"diplomacy_points": -5,
"political_stability": 5,
"technology": {"military": 1}
},
"description": "استفاده از تیم متخصص برای مقابله با حمله سایبری."
},
{
"text": "مذاکره برای پایان دادن به تنش‌ها",
"effects": {
"gold": -1000,
"diplomacy_points": -3,
"relations": {"+": 10},
"political_stability": 3
},
"description": "مذاکره برای کاهش تنش‌های سایبری."
}
]
},
{
"id": 101,
"name": "بحران دیپلماتیک",
"description": "یک اشتباه دیپلماتیک باعث ایجاد تنش شدید با یک کشور متحد شده است.",
"trigger": lambda state: max(state.relations.values()) > 80 and min(state.relations.values()) < -40,
"choices": [
{
"text": "اصلاح فوری اشتباه",
"effects": {
"gold": -2000,
"relations": {"-": 15},
"diplomacy_points": 5
},
"description": "پرداخت غرامت و اصلاح فوری اشتباه دیپلماتیک."
},
{
"text": "اصرار بر مواضع فعلی",
"effects": {
"relations": {"-": 30},
"political_stability": -10
},
"description": "اصرار بر مواضع فعلی با خطر از دست دادن متحد."
}
]
}
]
# اضافه کردن رویدادها به لیست رویدادها
for event in new_events:
if event not in EVENTS:
EVENTS.append(event)
def _extend_diplomacy_system(self, game):
"""گسترش سیستم دیپلماسی با روش‌های جدید"""
# افزودن روش برای پیوستن به سازمان‌های بین‌المللی
def join_international_orgs(self):
"""عضویت در سازمان‌های بین‌المللی"""
from ui.console_ui import ConsoleUI
ConsoleUI.clear_screen()
ConsoleUI.display_section_title("سازمان‌های بین‌المللی")
# لیست سازمان‌های موجود
orgs = [
"سازمان ملل متحد (UN)",
"سازمان تجارت جهانی (WTO)",
"سازمان بهداشت جهانی (WHO)",
"سازمان نفت (OPEC)",
"سازمان کشورهای صادرکننده نفت",
"ناتو (NATO)"
]
# نمایش گزینه‌ها
orgs.append("برگشت")
choice = ConsoleUI.get_menu_choice(orgs)
if choice == len(orgs):
return # برگشت
org = orgs[choice-1]
# محاسبه هزینه و تأثیرات
costs = {
"سازمان ملل متحد (UN)": 5000,
"سازمان تجارت جهانی (WTO)": 8000,
"سازمان بهداشت جهانی (WHO)": 6000,
"سازمان نفت (OPEC)": 10000,
"سازمان کشورهای صادرکننده نفت": 9000,
"ناتو (NATO)": 12000
}
effects = {
"سازمان ملل متحد (UN)": {
"relations": {"+": 10},
"political_stability": 5,
"diplomacy_points": 10
},
"سازمان تجارت جهانی (WTO)": {
"economy": {"trade": 15},
"gold": -500 # هزینه نگهداری سالانه
},
"سازمان بهداشت جهانی (WHO)": {
"health_index": 10,
"relations": {"+": 5}
},
"سازمان نفت (OPEC)": {
"resources": {"oil": 20},
"economy": {"industry": 10}
},
"سازمان کشورهای صادرکننده نفت": {
"resources": {"oil": 25},
"relations": {"+": 15}
},
"ناتو (NATO)": {
"military_strength": 20,
"relations": {"+": 25}
}
}
cost = costs[org]
effect = effects[org]
ConsoleUI.display_message(f"عضویت در {org}")
ConsoleUI.display_message(f"هزینه: {cost} سکه طلا")
ConsoleUI.display_message("تأثیرات:")
# نمایش تأثیرات
for effect_type, value in effect.items():
if effect_type == "relations":
ConsoleUI.display_message(f"• روابط بین‌المللی: +{value['+']}")
elif effect_type == "economy":
for sector, val in value.items():
ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}")
elif effect_type == "resources":
for resource, val in value.items():
ConsoleUI.display_message(f"• منابع {resource}: +{val}")
else:
ConsoleUI.display_message(f"• {effect_type}: +{value}")
if ConsoleUI.confirm_action("آیا مایل به عضویت در این سازمان هستید؟"):
self._join_organization(org, cost, effect)
# افزودن روش به سیستم دیپلماسی
from game.diplomacy.diplomacy_system import DiplomacySystem
DiplomacySystem.join_international_orgs = join_international_orgs
# افزودن روش برای مذاکره پیشرفته
def advanced_negotiation(self):
"""مذاکره پیشرفته با کشورهای دیگر"""
from ui.console_ui import ConsoleUI
ConsoleUI.clear_screen()
ConsoleUI.display_section_title("مذاکره پیشرفته")
# فیلتر کشورهایی که روابط خوبی داریم
potential_partners = []
for country, relation in self.game_state.relations.items():
if 20 < relation < 80 and country != self.game_state.player_country["name"]:
potential_partners.append(country)
if not potential_partners:
ConsoleUI.display_warning("هیچ کشوری برای مذاکره پیشرفته در دسترس نیست.")
ConsoleUI.wait_for_enter()
return
# نمایش گزینه‌ها
potential_partners.append("برگشت")
choice = ConsoleUI.get_menu_choice(potential_partners)
if choice == len(potential_partners):
return # برگشت
partner = potential_partners[choice-1]
# انتخاب نوع مذاکره
negotiation_types = [
"مذاکره برای اتحاد نظامی",
"مذاکره برای پیمان تجاری",
"مذاکره برای همکاری فناوری",
"برگشت"
]
neg_choice = ConsoleUI.get_menu_choice(negotiation_types)
if neg_choice == 4:
return # برگشت
# محاسبه هزینه و تأثیرات
costs = [7000, 5000, 6000]
effects = [
{"military_strength": 15, "relations": {"+": 20}},
{"economy": {"trade": 15}, "relations": {"+": 15}},
{"technology": {"trade": 1}, "relations": {"+": 10}}
]
cost = costs[neg_choice-1]
effect = effects[neg_choice-1]
ConsoleUI.display_message(f"مذاکره با {partner} برای {negotiation_types[neg_choice-1]}")
ConsoleUI.display_message(f"هزینه: {cost} سکه طلا")
ConsoleUI.display_message("تأثیرات:")
# نمایش تأثیرات
for effect_type, value in effect.items():
if effect_type == "relations":
ConsoleUI.display_message(f"• روابط با {partner}: +{value['+']}")
elif effect_type == "economy":
for sector, val in value.items():
ConsoleUI.display_message(f"• اقتصاد {sector}: +{val}")
elif effect_type == "technology":
for tech, val in value.items():
ConsoleUI.display_message(f"• فناوری {tech}: +{val}")
else:
ConsoleUI.display_message(f"• {effect_type}: +{value}")
if ConsoleUI.confirm_action("آیا مایل به انجام این مذاکره هستید؟"):
self._perform_advanced_negotiation(partner, cost, effect)
# افزودن روش به سیستم دیپلماسی
DiplomacySystem.advanced_negotiation = advanced_negotiation
def _join_organization(self, org, cost, effect):
"""عضویت در یک سازمان بین‌المللی"""
from ui.console_ui import ConsoleUI
# بررسی موجودی
if self.game_state.gold < cost:
ConsoleUI.display_error("موجودی طلا کافی نیست!")
ConsoleUI.wait_for_enter()
return
# اعمال تغییرات
self.game_state.gold -= cost
self.game_state.international_orgs.append(org)
# اعمال تأثیرات
for effect_type, value in effect.items():
if effect_type == "relations":
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 effect_type == "economy":
for sector, val in value.items():
self.game_state.economy[sector] = min(100, self.game_state.economy[sector] + val)
elif effect_type == "resources":
for resource, val in value.items():
self.game_state.resources[resource] = min(100, self.game_state.resources[resource] + val)
else:
if effect_type in self.game_state:
self.game_state[effect_type] = min(100, self.game_state[effect_type] + value)
elif effect_type in self.game_state.economy:
self.game_state.economy[effect_type] = min(100, self.game_state.economy[effect_type] + value)
ConsoleUI.display_success(f"شما عضو {org} شدید.")
ConsoleUI.wait_for_enter()
def _perform_advanced_negotiation(self, partner, cost, effect):
"""انجام مذاکره پیشرفته با یک کشور"""
from ui.console_ui import ConsoleUI
# بررسی موجودی
if self.game_state.gold < cost:
ConsoleUI.display_error("موجودی طلا کافی نیست!")
ConsoleUI.wait_for_enter()
return
# اعمال تغییرات
self.game_state.gold -= cost
# اعمال تأثیرات
for effect_type, value in effect.items():
if effect_type == "relations":
self.game_state.relations[partner] = min(100, self.game_state.relations[partner] + value["+"])
elif effect_type == "economy":
for sector, val in value.items():
self.game_state.economy[sector] = min(100, self.game_state.economy[sector] + val)
elif effect_type == "technology":
for tech, val in value.items():
self.game_state.technology[tech] = min(10, self.game_state.technology[tech] + val)
else:
if effect_type in self.game_state:
self.game_state[effect_type] = min(100, self.game_state[effect_type] + value)
elif effect_type in self.game_state.economy:
self.game_state.economy[effect_type] = min(100, self.game_state.economy[effect_type] + value)
ConsoleUI.display_success(f"مذاکره با {partner} موفقیت‌آمیز بود.")
ConsoleUI.wait_for_enter()
def _add_international_organizations(self, game):
"""افزودن سازمان‌های بین‌المللی به بازی"""
# افزودن سازمان‌ها به وضعیت بازی
game.game_state.international_orgs = []
# افزودن روش برای نمایش سازمان‌ها
def display_international_orgs(self):
"""نمایش سازمان‌های بین‌المللی عضو شده"""
from ui.console_ui import ConsoleUI
ConsoleUI.clear_screen()
ConsoleUI.display_section_title("سازمان‌های بین‌المللی")
if not self.game_state.international_orgs:
ConsoleUI.display_message("شما عضو هیچ سازمان بین‌المللی نیستید.", indent=2)
else:
ConsoleUI.display_message("شما عضو سازمان‌های زیر هستید:", indent=2)
for org in self.game_state.international_orgs:
ConsoleUI.display_message(f"• {org}", indent=4)
ConsoleUI.wait_for_enter()
# افزودن روش به سیستم دیپلماسی
from game.diplomacy.diplomacy_system import DiplomacySystem
DiplomacySystem.display_international_orgs = display_international_orgs
def remove(self, game):
"""
حذف اثرات پلاگین از بازی
:param game: نمونه بازی که پلاگین باید از آن حذف شود
"""
# حذف ویژگی‌های اضافه شده
if hasattr(game.game_state, 'diplomacy_relations'):
del game.game_state.diplomacy_relations
if hasattr(game.game_state, 'international_orgs'):
del game.game_state.international_orgs
# حذف رویدادهای جدید
global EVENTS
EVENTS = [e for e in EVENTS if e.get("id") not in [100, 101]]
# حذف روش‌های جدید
if hasattr(game.diplomacy, 'join_international_orgs'):
del game.diplomacy.join_international_orgs
if hasattr(game.diplomacy, 'advanced_negotiation'):
del game.diplomacy.advanced_negotiation
if hasattr(game.diplomacy, 'display_international_orgs'):
del game.diplomacy.display_international_orgs
print(f"{self.name} با موفقیت حذف شد.")