Add body snatch potion
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
# Copyright (C) 2020 by ÿnérant, eichhornchen, nicomarg, charlse
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from random import randint
|
||||
from random import choice, randint
|
||||
from typing import Optional
|
||||
|
||||
from .player import Player
|
||||
@ -143,3 +143,29 @@ class Bomb(Item):
|
||||
d["exploding"] = self.exploding
|
||||
d["damage"] = self.damage
|
||||
return d
|
||||
|
||||
|
||||
class BodySnatchPotion(Item):
|
||||
"""
|
||||
The body-snatch potion allows to exchange all characteristics with a random
|
||||
other entity.
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(name="body_snatch_potion", *args, **kwargs)
|
||||
|
||||
def use(self) -> None:
|
||||
"""
|
||||
Find a valid random entity, then exchange characteristics.
|
||||
"""
|
||||
valid_entities = self.held_by.map.find_entities(FightingEntity)
|
||||
valid_entities.remove(self.held_by)
|
||||
entity = choice(valid_entities)
|
||||
entity_state = entity.save_state()
|
||||
player_state = self.held_by.save_state()
|
||||
self.held_by.__dict__.update(entity_state)
|
||||
entity.__dict__.update(player_state)
|
||||
self.held_by.map.currenty, self.held_by.map.currentx = self.held_by.y,\
|
||||
self.held_by.x
|
||||
|
||||
self.held_by.inventory.remove(self)
|
||||
|
Reference in New Issue
Block a user