from siege.util import PixelVector, Rect

from core.monster import BaseMonster, MonsterMeleeAttack
from core.template.animation import Frame, Frames
from core.template.item import Loot
from core.template.monster import Monster
from core.tuning.monster import MonsterTuning

from siege.util import seconds


monster = Monster(
    name = "Zabis",
    tuning = MonsterTuning.ZABIS,
    weight = 55,
    experienceYield = 30,
    loot = [
        Loot("feather", dropRates={0: 33, 1: 67}),
        Loot("cloth", dropRates={0: 33, 1: 67})
    ],
    spawnTime = 500,
    biomes = ["Desert", "Scorched"],
    growlSound = "mods/core/audio/sfx/monster/zabis_growl_[1-4].ogg",
    detectionArea = Rect(0, -30, 120, 60),
)

monster.hasPhysics(body=Rect(-15, -12, 25, 24))

idle = monster.getSpriteFrames(Frame(0, 114, size=(26, 52), origin=(9, 38)))
death = monster.getSpriteFrames(Frame(224, 57, size=(26, 52), origin=(9, 38)))

move = monster.getSpriteFrames(
    frames = [
        Frame(107, 114),
        Frame(133, 114),
        Frame(159, 114),
        Frame(185, 114),
        Frame(211, 114)
    ],
    size = PixelVector(26, 52),
    origin = PixelVector(10, 38)
)

jump = monster.getSpriteFrames(
    frames = [
        Frame(26, 114),
        Frame(53, 114),
        Frame(80, 114)
    ],
    size = PixelVector(27, 55),
    origin = PixelVector(11, 41)
)

attack = monster.getSpriteFrames(
    frames = [
        Frame(0, 0),
        Frame(56, 0),
        Frame(112, 0),
        Frame(168, 0),
        Frame(0, 57),
        Frame(56, 57),
        Frame(112, 57),
        Frame(168, 57)
    ],
    size = PixelVector(56, 57),
    origin = PixelVector(20, 43)
)

monster.animations(
    start = 'idle',
    idle = Frames(move(1)),
    move = Frames(move(1, 2, 3, 2), time=100),
    jump = Frames(jump(), time=100),
    land = Frames(jump(2), time=100),
    attack = (
        Frames(attack(1, 2), time=80),
        Frames(attack(3, 4, 5, 6, 7, 8), time=100)
    ),
    death = Frames(move(1) + death() + move(1) + death(), time=200),
    disableLooping = ['idle', 'attack', 'jump', 'land', 'death']
)

meleeAttack = monster.meleeAttack(
    hitFrames = attack.indices(4, 5, 6, 7, 8),
    power = 40,
    detectionArea = Rect(0, -14, 13, 40),
    cooldownTime = seconds(1),
)


@meleeAttack.customize
class BasicZabisAttack(MonsterMeleeAttack):
    def __init__(self):
        MonsterMeleeAttack.__init__(self)


@monster.customize
class ZabisMonster(BaseMonster):
    def __init__(self, entity, component):
        BaseMonster.__init__(self, entity)
        self.actions.append(BasicZabisAttack())

    def update(self, frameTime):
        BaseMonster.update(self, frameTime)

    @staticmethod
    def create(entity, component):
        return ZabisMonster(entity, component)
