Add log messages when a bomb is exploding
This commit is contained in:
parent
056ca5cca8
commit
27fd73c96b
|
@ -1,10 +1,12 @@
|
|||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from random import randint
|
||||
from typing import Optional
|
||||
|
||||
from .player import Player
|
||||
from ..interfaces import Entity, FightingEntity, Map
|
||||
from ..translations import gettext as _
|
||||
|
||||
|
||||
class Item(Entity):
|
||||
|
@ -90,6 +92,7 @@ class Bomb(Item):
|
|||
A bomb item intended to deal damage to enemies at long range
|
||||
"""
|
||||
damage: int = 5
|
||||
owner: "Player"
|
||||
tick: int
|
||||
exploding: bool
|
||||
|
||||
|
@ -98,13 +101,14 @@ class Bomb(Item):
|
|||
super().__init__(name="bomb", *args, **kwargs)
|
||||
self.damage = damage
|
||||
self.exploding = exploding
|
||||
self.tick = 5
|
||||
self.tick = 4
|
||||
|
||||
def use(self) -> None:
|
||||
"""
|
||||
When the bomb is used, throw it and explodes it.
|
||||
"""
|
||||
if self.held:
|
||||
self.owner = self.held_by
|
||||
super().drop()
|
||||
self.exploding = True
|
||||
|
||||
|
@ -114,12 +118,20 @@ class Bomb(Item):
|
|||
"""
|
||||
if self.exploding:
|
||||
if self.tick > 0:
|
||||
# The bomb will explode in <tick> moves
|
||||
self.tick -= 1
|
||||
else:
|
||||
# The bomb is exploding.
|
||||
# Each entity that is close to the bomb takes damages.
|
||||
# The player earn XP if the entity was killed.
|
||||
log_message = _("Bomb is exploding.")
|
||||
for e in m.entities.copy():
|
||||
if abs(e.x - self.x) + abs(e.y - self.y) <= 1 and \
|
||||
if abs(e.x - self.x) + abs(e.y - self.y) <= 3 and \
|
||||
isinstance(e, FightingEntity):
|
||||
e.take_damage(self, self.damage)
|
||||
log_message += " " + e.take_damage(self, self.damage)
|
||||
if e.dead:
|
||||
self.owner.add_xp(randint(3, 7))
|
||||
m.logs.add_message(log_message)
|
||||
m.entities.remove(self)
|
||||
|
||||
def save_state(self) -> dict:
|
||||
|
|
Loading…
Reference in New Issue