package com.zivilon.cinder_loe.mixins;

import lotr.common.LOTRMod;
import lotr.common.entity.npc.LOTREntityMountainTrollChieftain;
import lotr.common.entity.npc.LOTREntityMountainTroll;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import net.minecraft.util.DamageSource;
import net.minecraft.entity.SharedMonsterAttributes;
import com.zivilon.cinder_loe.util.IBossEntity;

@Mixin(LOTREntityMountainTrollChieftain.class)
public class MixinLOTREntityMountainTrollChieftain extends LOTREntityMountainTroll implements IBossEntity {
    @Shadow(remap = false)
    public int getTrollArmorLevel() {return 1;}
    @Shadow(remap = false)
    public void setTrollArmorLevel(int i) {}

    public MixinLOTREntityMountainTrollChieftain(World world) {
        super(world);
    }

    /**
     * @author Shinare
     * @reason I don't remember, test later if even necessary
     */
    @Overwrite(remap = false)
    protected void func_70665_d(DamageSource damagesource, float f) { // damageEntity()
        super.damageEntity(damagesource, f);
    }

    public void change_phase() {
        if (!this.worldObj.isRemote) {
            setTrollArmorLevel(getTrollArmorLevel() - 1);
            if (getTrollArmorLevel() == 0) {
                double speed = getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue();
                speed *= 1.5D;
                getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(speed);
            }
            double maxHealth = getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue();
            maxHealth *= 2.0D;
            getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(maxHealth);
            setHealth(getMaxHealth());
            this.worldObj.setEntityState((Entity)this, (byte)21);
        }
    }
}
