from core.player.spell.Spell import Spell


class Action:
    def __init__(self):
        pass

    def do(self, sim):
        raise NotImplementedError()

    def undo(self, sim):
        raise NotImplementedError()


class MoveAction(Action):
    def __init__(self, dst, pa_cost: int, pm_cost: int):
        super(MoveAction, self).__init__()
        self.dst = dst
        self.pa_cost = pa_cost
        self.pm_cost = pm_cost
        self.start = None

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)

    def undo(self, sim):
        sim.move(self.start, -self.pa_cost, -self.pm_cost)


class AttackAction(Action):
    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        # print(self.dmg_value, received_dmg, player_dmg, attack.damages)
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost





192ce6ec8d2f78db9189ffb86a7407dd4fd8e820
<mask token>


class MoveAction(Action):
    <mask token>

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)
    <mask token>


class AttackAction(Action):

    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost

<mask token>


class MoveAction(Action):
    <mask token>

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)

    def undo(self, sim):
        sim.move(self.start, -self.pa_cost, -self.pm_cost)


class AttackAction(Action):

    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost

<mask token>


class Action:
    <mask token>
    <mask token>

    def undo(self, sim):
        raise NotImplementedError()


class MoveAction(Action):

    def __init__(self, dst, pa_cost: int, pm_cost: int):
        super(MoveAction, self).__init__()
        self.dst = dst
        self.pa_cost = pa_cost
        self.pm_cost = pm_cost
        self.start = None

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)

    def undo(self, sim):
        sim.move(self.start, -self.pa_cost, -self.pm_cost)


class AttackAction(Action):

    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost

<mask token>


class Action:

    def __init__(self):
        pass
    <mask token>

    def undo(self, sim):
        raise NotImplementedError()


class MoveAction(Action):

    def __init__(self, dst, pa_cost: int, pm_cost: int):
        super(MoveAction, self).__init__()
        self.dst = dst
        self.pa_cost = pa_cost
        self.pm_cost = pm_cost
        self.start = None

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)

    def undo(self, sim):
        sim.move(self.start, -self.pa_cost, -self.pm_cost)


class AttackAction(Action):

    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost

from core.player.spell.Spell import Spell


class Action:
    def __init__(self):
        pass

    def do(self, sim):
        raise NotImplementedError()

    def undo(self, sim):
        raise NotImplementedError()


class MoveAction(Action):
    def __init__(self, dst, pa_cost: int, pm_cost: int):
        super(MoveAction, self).__init__()
        self.dst = dst
        self.pa_cost = pa_cost
        self.pm_cost = pm_cost
        self.start = None

    def do(self, sim):
        self.start = sim.current_fighter.pos
        sim.move(self.dst, self.pa_cost, self.pm_cost)

    def undo(self, sim):
        sim.move(self.start, -self.pa_cost, -self.pm_cost)


class AttackAction(Action):
    def __init__(self, spell: Spell, pos, sim):
        super(AttackAction, self).__init__()
        self.pos = pos
        target_fighter = sim.get_fighter_at_pos(self.pos)
        player_dmg = sim.current_fighter.send_damages(spell.get_effects())
        received_dmg = target_fighter.receive_damage(player_dmg)
        self.dmg_value = sum([v_min for v_min, v_max in received_dmg.values()])
        # print(self.dmg_value, received_dmg, player_dmg, attack.damages)
        self.pa_cost = spell.get_ap_cost()
        self.spell = spell
        self.start = None

    def do(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health -= self.dmg_value
        sim.current_fighter.pa -= self.pa_cost

    def undo(self, sim):
        target_fighter = sim.get_fighter_at_pos(self.pos)
        target_fighter.health += self.dmg_value
        sim.current_fighter.pa += self.pa_cost




