feat: revise monster scaling
This commit is contained in:
+42
-29
@@ -338,49 +338,50 @@ class GameWorld:
|
||||
player.last_hp_regen = current_time
|
||||
|
||||
def _spawn_monster(self):
|
||||
"""Spawn a random monster on the map"""
|
||||
"""Spawn a random monster on the map with level 1-10"""
|
||||
monster_id = f"monster_{len(self.monsters)}_{self.generation}"
|
||||
level = random.randint(1, 5)
|
||||
level = random.randint(1, 10)
|
||||
x = random.randint(-GRID_SIZE // 2, GRID_SIZE // 2)
|
||||
y = random.randint(-GRID_SIZE // 2, GRID_SIZE // 2)
|
||||
health = 20 + level * 10
|
||||
# HP scales with level: base 15 + 5 per level = 20-65 for levels 1-10
|
||||
health = 15 + level * 5
|
||||
self.monsters[monster_id] = Monster(
|
||||
id=monster_id,
|
||||
position=Position(x, y, 0),
|
||||
health=health,
|
||||
max_health=health,
|
||||
level=level,
|
||||
attack=3 + level,
|
||||
defense=1 + level // 2,
|
||||
attack=2 + level,
|
||||
defense=1 + level // 3,
|
||||
is_boss=False,
|
||||
)
|
||||
|
||||
def _spawn_boss(self):
|
||||
"""Spawn the boss monster"""
|
||||
boss_id = f"boss_{self.generation}"
|
||||
active_players = [p for p in self.players.values() if p.active]
|
||||
avg_level = sum(p.level for p in active_players) / len(active_players)
|
||||
health = int(BOSS_HEALTH_BASE + avg_level * 500)
|
||||
"""Spawn the boss monster"""
|
||||
boss_id = f"boss_{self.generation}"
|
||||
active_players = [p for p in self.players.values() if p.active]
|
||||
avg_level = sum(p.level for p in active_players) / len(active_players)
|
||||
health = int(BOSS_HEALTH_BASE + avg_level * 500)
|
||||
|
||||
# Spawn boss at a distance from players
|
||||
if active_players:
|
||||
player_pos = active_players[0].position
|
||||
angle = random.random() * 2 * 3.14159
|
||||
x = player_pos.x + BOSS_SPAWN_DISTANCE * (angle ** 0.5) * (1 if random.random() > 0.5 else -1)
|
||||
y = player_pos.y + BOSS_SPAWN_DISTANCE * (1 - angle ** 0.5) * (1 if random.random() > 0.5 else -1)
|
||||
else:
|
||||
x = y = 0
|
||||
# Spawn boss at a distance from players
|
||||
if active_players:
|
||||
player_pos = active_players[0].position
|
||||
angle = random.random() * 2 * 3.14159
|
||||
x = player_pos.x + BOSS_SPAWN_DISTANCE * (angle ** 0.5) * (1 if random.random() > 0.5 else -1)
|
||||
y = player_pos.y + BOSS_SPAWN_DISTANCE * (1 - angle ** 0.5) * (1 if random.random() > 0.5 else -1)
|
||||
else:
|
||||
x = y = 0
|
||||
|
||||
self.boss = Monster(
|
||||
id=boss_id,
|
||||
position=Position(x, y, 0),
|
||||
health=health,
|
||||
max_health=health,
|
||||
level=int(avg_level) + 5,
|
||||
attack=15 + int(avg_level),
|
||||
defense=4 + int(avg_level // 2),
|
||||
is_boss=True,
|
||||
)
|
||||
self.boss = Monster(
|
||||
id=boss_id,
|
||||
position=Position(x, y, 0),
|
||||
health=health,
|
||||
max_health=health,
|
||||
level=int(avg_level) + 5,
|
||||
attack=15 + int(avg_level),
|
||||
defense=4 + int(avg_level // 2),
|
||||
is_boss=True,
|
||||
)
|
||||
|
||||
def _player_effective_attack(player: Player) -> int:
|
||||
if 0 <= player.equipped_weapon_slot < len(player.weapon_slots):
|
||||
@@ -699,7 +700,13 @@ def _handle_attack(player: Player, target_id: str) -> Dict:
|
||||
if monster.health <= 0:
|
||||
del game_world.monsters[target_id]
|
||||
player.exp += monster.level * 10
|
||||
player.level = 1 + int(player.exp / 100)
|
||||
# Calculate level based on XP: 30 for level 1, +20 per additional level
|
||||
# Level N requires: 30 + 20*(N-1) total XP
|
||||
player.level = 1
|
||||
xp_needed = 30
|
||||
while player.exp >= xp_needed and player.level < 100:
|
||||
player.level += 1
|
||||
xp_needed += 20
|
||||
return {"success": True, "damage": damage, "exp": monster.level * 10, "monster_killed": True}
|
||||
|
||||
retaliation = apply_retaliation(monster.attack)
|
||||
@@ -934,3 +941,9 @@ async def health():
|
||||
return {"status": "ok"}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user