-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_usage.py
More file actions
348 lines (275 loc) · 12.7 KB
/
Copy pathexample_usage.py
File metadata and controls
348 lines (275 loc) · 12.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
"""
RPG Library Example Usage
=========================
This script demonstrates how to use the RPG library with all its features:
- Creating players with leveling system
- Creating customizable enemies with abilities and drops
- Setting up shops with easy item addition
- Combat system with abilities and status effects
- Item management and equipment
- Status effects and their interactions
"""
from rpg_core import Player, Shop, ItemType, AbilityType, StatusEffectType
from rpg_factory import ItemFactory, AbilityFactory, EnemyFactory, ShopFactory
import random
def demonstrate_player_creation():
"""Demonstrate player creation and leveling."""
print("=== Player Creation and Leveling ===")
# Create a player
player = Player("Hero", hp=120, mana=60, attack=12, defense=6)
print(f"Created player: {player.name}")
print(f"Level: {player.level}, HP: {player.hp}/{player.max_hp}, MP: {player.mana}/{player.max_mana}")
print(f"Attack: {player.attack}, Defense: {player.defense}")
print(f"Experience: {player.experience}/{player.experience_to_next_level}")
# Add some abilities to the player (including status effect abilities)
player.add_ability(AbilityFactory.slash())
player.add_ability(AbilityFactory.heal())
player.add_ability(AbilityFactory.fireball())
player.add_ability(AbilityFactory.poison_dart())
player.add_ability(AbilityFactory.battle_cry())
print(f"Added abilities: {[ability.name for ability in player.abilities]}")
# Simulate gaining experience and leveling up
print("\n--- Gaining Experience ---")
for i in range(3):
exp_gain = random.randint(80, 120)
print(f"Gained {exp_gain} experience!")
result = player.gain_experience(exp_gain)
if result:
print(result)
print(f"Level: {player.level}, Experience: {player.experience}/{player.experience_to_next_level}")
print()
def demonstrate_enemy_creation():
"""Demonstrate enemy creation with abilities and drops."""
print("=== Enemy Creation and Customization ===")
# Create enemies using factory
goblin = EnemyFactory.goblin(level=2)
orc = EnemyFactory.orc(level=4)
dragon = EnemyFactory.dragon(level=8)
enemies = [goblin, orc, dragon]
for enemy in enemies:
print(f"\n{enemy.name}:")
print(f" HP: {enemy.hp}, MP: {enemy.mana}")
print(f" Attack: {enemy.attack}, Defense: {enemy.defense}")
print(f" Abilities: {[ability.name for ability in enemy.abilities]}")
print(f" Rewards: {enemy.exp_reward} EXP, {enemy.gold_reward} Gold")
print(f" Drop Table: {len(enemy.drop_table)} possible drops")
# Create a custom enemy
print("\n--- Custom Enemy Creation ---")
custom_abilities = [
AbilityFactory.create_attack_ability("Shadow Strike", 20, 8, 1, "A dark energy attack"),
AbilityFactory.heal()
]
custom_drops = [
(ItemFactory.create_weapon("Shadow Blade", 15, 200), 0.5),
(ItemFactory.create_consumable("Dark Crystal", 100), 0.8)
]
shadow_beast = EnemyFactory.create_custom_enemy(
name="Shadow Beast",
hp=80,
mana=40,
attack=18,
defense=8,
level=6,
abilities=custom_abilities,
drops=custom_drops
)
print(f"Created custom enemy: {shadow_beast.name}")
print(f" Abilities: {[ability.name for ability in shadow_beast.abilities]}")
print(f" Custom drops: {len(shadow_beast.drop_table)} items")
print()
def demonstrate_shops():
"""Demonstrate shop system with easy item addition."""
print("=== Shop System ===")
# Create different types of shops
weapon_shop = ShopFactory.create_weapon_shop()
armor_shop = ShopFactory.create_armor_shop()
potion_shop = ShopFactory.create_potion_shop()
shops = [weapon_shop, armor_shop, potion_shop]
for shop in shops:
print(f"\n{shop.name}:")
items = shop.list_items()
for item in items[:3]: # Show first 3 items
print(f" {item}")
if len(items) > 3:
print(f" ... and {len(items) - 3} more items")
# Create a custom shop and add items easily
print("\n--- Custom Shop Creation ---")
custom_shop = Shop("Rare Items Emporium")
custom_shop.buy_price_multiplier = 1.5 # More expensive
custom_shop.sell_price_multiplier = 0.7 # Better sell prices
# Add custom items
rare_items = [
ItemFactory.create_weapon("Excalibur", 25, 1000, "Legendary sword"),
ItemFactory.create_armor("Divine Shield", 20, 800, "Blessed protection"),
ItemFactory.create_consumable("Elixir of Life", 500, "Grants temporary immortality")
]
for item in rare_items:
custom_shop.add_item(item)
print(f"{custom_shop.name}:")
for item_desc in custom_shop.list_items():
print(f" {item_desc}")
print()
def demonstrate_combat():
"""Demonstrate combat system with abilities and status effects."""
print("=== Combat System with Status Effects ===")
# Create player and enemy
player = Player("Warrior", hp=100, mana=50, attack=15, defense=8)
player.add_ability(AbilityFactory.slash())
player.add_ability(AbilityFactory.power_strike())
player.add_ability(AbilityFactory.heal())
player.add_ability(AbilityFactory.poison_dart())
player.add_ability(AbilityFactory.battle_cry())
player.add_gold(100)
enemy = EnemyFactory.orc(level=3)
print(f"Combat: {player.name} vs {enemy.name}")
print(f"Player: {player.hp} HP, {player.mana} MP")
print(f"Enemy: {enemy.hp} HP, {enemy.mana} MP")
# Simulate a few rounds of combat
round_num = 1
while player.is_alive() and enemy.is_alive() and round_num <= 8:
print(f"\n--- Round {round_num} ---")
# Process status effects at the start of each round
player.process_status_effects()
enemy.process_status_effects()
# Player turn
if player.abilities and not player.has_status_effect(StatusEffectType.STUN):
ability = random.choice(player.abilities)
if ability.can_use(player):
result = ability.use(player, enemy)
print(result)
else:
print(f"{player.name} cannot use {ability.name}")
elif player.has_status_effect(StatusEffectType.STUN):
print(f"{player.name} is stunned and cannot act!")
# Enemy turn (if still alive)
if enemy.is_alive() and not enemy.has_status_effect(StatusEffectType.STUN):
enemy_ability = enemy.ai_choose_ability(player)
if enemy_ability:
result = enemy_ability.use(enemy, player)
print(result)
else:
# Basic attack if no abilities available
damage = enemy.get_total_attack() + random.randint(-3, 3)
actual_damage = player.take_damage(damage)
print(f"{enemy.name} attacks {player.name} for {actual_damage} damage!")
elif enemy.has_status_effect(StatusEffectType.STUN):
print(f"{enemy.name} is stunned and cannot act!")
# Update cooldowns
player.update_cooldowns()
enemy.update_cooldowns()
# Show current status effects
player_effects = [effect.effect_type.name for effect in player.status_effects]
enemy_effects = [effect.effect_type.name for effect in enemy.status_effects]
status_info = f"Player HP: {player.hp}/{player.max_hp}, Enemy HP: {enemy.hp}/{enemy.max_hp}"
if player_effects:
status_info += f" | Player Effects: {', '.join(player_effects)}"
if enemy_effects:
status_info += f" | Enemy Effects: {', '.join(enemy_effects)}"
print(status_info)
round_num += 1
# Determine winner and rewards
if not enemy.is_alive():
print(f"\n{player.name} wins!")
player.gain_experience(enemy.exp_reward)
player.add_gold(enemy.gold_reward)
print(f"Gained {enemy.exp_reward} EXP and {enemy.gold_reward} gold!")
# Get drops
drops = enemy.get_drops()
if drops:
print("Drops received:")
for drop in drops:
player.add_item(drop)
print(f" {drop.name}")
else:
print("No drops this time.")
print()
def demonstrate_status_effects():
"""Demonstrate status effects in detail."""
print("=== Status Effects Demonstration ===")
# Create test characters
player = Player("Mage", hp=80, mana=100, attack=10, defense=5)
enemy = Player("Test Dummy", hp=100, mana=50, attack=8, defense=3) # Using Player as test dummy
# Add status effect abilities
player.add_ability(AbilityFactory.poison_dart())
player.add_ability(AbilityFactory.flame_strike())
player.add_ability(AbilityFactory.ice_shard())
player.add_ability(AbilityFactory.weakness_curse())
player.add_ability(AbilityFactory.battle_cry())
print(f"Testing status effects with {player.name} vs {enemy.name}")
print(f"Initial stats - Player: {player.get_total_attack()} ATK, {player.get_total_defense()} DEF")
print(f"Initial stats - Enemy: {enemy.get_total_attack()} ATK, {enemy.get_total_defense()} DEF")
# Test different status effects
status_abilities = [
AbilityFactory.poison_dart(),
AbilityFactory.flame_strike(),
AbilityFactory.ice_shard(),
AbilityFactory.weakness_curse(),
AbilityFactory.battle_cry()
]
for i, ability in enumerate(status_abilities):
print(f"\n--- Testing {ability.name} ---")
if ability.ability_type == AbilityType.BUFF:
result = ability.use(player, player) # Self-buff
else:
result = ability.use(player, enemy)
print(result)
# Show status effects
if ability.ability_type == AbilityType.BUFF:
effects = [f"{effect.effect_type.name} ({effect.duration} turns)" for effect in player.status_effects]
if effects:
print(f"Player status effects: {', '.join(effects)}")
print(f"Modified stats - Player: {player.get_total_attack()} ATK, {player.get_total_defense()} DEF")
else:
effects = [f"{effect.effect_type.name} ({effect.duration} turns)" for effect in enemy.status_effects]
if effects:
print(f"Enemy status effects: {', '.join(effects)}")
print(f"Modified stats - Enemy: {enemy.get_total_attack()} ATK, {enemy.get_total_defense()} DEF")
# Process one turn of status effects
print("Processing status effects...")
player.process_status_effects()
enemy.process_status_effects()
print(f"After processing - Player HP: {player.hp}, Enemy HP: {enemy.hp}")
print()
def demonstrate_item_management():
"""Demonstrate item management and equipment."""
print("=== Item Management and Equipment ===")
player = Player("Knight")
# Create and add items
sword = ItemFactory.create_weapon("Steel Sword", 10, 50)
armor = ItemFactory.create_armor("Chain Mail", 5, 40)
potion = ItemFactory.create_health_potion(50)
player.add_item(sword)
player.add_item(armor)
player.add_item(potion)
print(f"Player inventory: {[item.name for item in player.inventory]}")
print(f"Base stats - Attack: {player.attack}, Defense: {player.defense}")
# Equip items
player.equip_item(sword, "weapon")
player.equip_item(armor, "armor")
print(f"After equipping items:")
print(f" Total Attack: {player.get_total_attack()}")
print(f" Total Defense: {player.get_total_defense()}")
print(f" Equipped: {list(player.equipped.keys())}")
print(f" Inventory: {[item.name for item in player.inventory]}")
print()
def main():
"""Run all demonstrations."""
print("RPG Library Demonstration")
print("=" * 50)
demonstrate_player_creation()
demonstrate_enemy_creation()
demonstrate_shops()
demonstrate_status_effects()
demonstrate_combat()
demonstrate_item_management()
print("=" * 50)
print("Demonstration complete! The RPG library supports:")
print("✓ Player creation and leveling")
print("✓ Customizable enemies with abilities and drops")
print("✓ Shop system with easy item management")
print("✓ Status effects and abilities that inflict them")
print("✓ Combat system with status effect interactions")
print("✓ Item management and equipment system")
print("✓ Easy factory classes for quick content creation")
if __name__ == "__main__":
main()