// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.flock;

import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.component.ComponentAccessor;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.flock.config.FlockAsset;
import com.hypixel.hytale.component.ComponentType;
import com.hypixel.hytale.server.npc.util.DamageData;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Component;

public class Flock implements Component<EntityStore>
{
    private boolean trace;
    private PersistentFlockData flockData;
    private DamageData nextDamageData;
    private DamageData currentDamageData;
    private DamageData nextLeaderDamageData;
    private DamageData currentLeaderDamageData;
    private FlockRemovedStatus removedStatus;
    
    public static ComponentType<EntityStore, Flock> getComponentType() {
        return FlockPlugin.get().getFlockComponentType();
    }
    
    public Flock() {
        this.nextDamageData = new DamageData();
        this.currentDamageData = new DamageData();
        this.nextLeaderDamageData = new DamageData();
        this.currentLeaderDamageData = new DamageData();
        this.removedStatus = FlockRemovedStatus.NOT_REMOVED;
    }
    
    public Flock(@Nullable final FlockAsset flockDefinition, @Nonnull final String[] allowedRoles) {
        this.nextDamageData = new DamageData();
        this.currentDamageData = new DamageData();
        this.nextLeaderDamageData = new DamageData();
        this.currentLeaderDamageData = new DamageData();
        this.removedStatus = FlockRemovedStatus.NOT_REMOVED;
        this.flockData = new PersistentFlockData(flockDefinition, allowedRoles);
    }
    
    public DamageData getDamageData() {
        return this.currentDamageData;
    }
    
    public DamageData getNextDamageData() {
        return this.nextDamageData;
    }
    
    public DamageData getLeaderDamageData() {
        return this.currentLeaderDamageData;
    }
    
    public DamageData getNextLeaderDamageData() {
        return this.nextLeaderDamageData;
    }
    
    public boolean isTrace() {
        return this.trace;
    }
    
    public void setTrace(final boolean trace) {
        this.trace = trace;
    }
    
    public PersistentFlockData getFlockData() {
        return this.flockData;
    }
    
    public void setFlockData(final PersistentFlockData flockData) {
        this.flockData = flockData;
    }
    
    public FlockRemovedStatus getRemovedStatus() {
        return this.removedStatus;
    }
    
    public void setRemovedStatus(final FlockRemovedStatus status) {
        this.removedStatus = status;
    }
    
    public void onTargetKilled(@Nonnull final ComponentAccessor<EntityStore> componentAccessor, @Nonnull final Ref<EntityStore> targetEntityReference) {
        final TransformComponent targetTransformComponent = componentAccessor.getComponent(targetEntityReference, TransformComponent.getComponentType());
        if (targetTransformComponent != null) {
            this.nextDamageData.onKill(targetEntityReference, targetTransformComponent.getPosition().clone());
        }
    }
    
    public void swapDamageDataBuffers() {
        final DamageData nextData = this.nextDamageData;
        this.nextDamageData = this.currentDamageData;
        this.currentDamageData = nextData;
        final DamageData nextLeaderData = this.nextLeaderDamageData;
        this.nextLeaderDamageData = this.currentLeaderDamageData;
        this.currentLeaderDamageData = nextLeaderData;
        this.nextDamageData.reset();
        this.nextLeaderDamageData.reset();
    }
    
    @Nonnull
    @Override
    public Component<EntityStore> clone() {
        final Flock flock = new Flock();
        flock.trace = this.trace;
        flock.flockData = (PersistentFlockData)this.flockData.clone();
        flock.nextDamageData = this.nextDamageData.clone();
        flock.currentDamageData = this.currentDamageData.clone();
        flock.nextLeaderDamageData = this.nextLeaderDamageData.clone();
        flock.currentLeaderDamageData = this.currentLeaderDamageData.clone();
        flock.removedStatus = this.removedStatus;
        return flock;
    }
    
    @Nonnull
    @Override
    public String toString() {
        return "Flock{trace=" + this.trace + ", flockData=" + String.valueOf(this.flockData) + ", nextDamageData=" + String.valueOf(this.nextDamageData) + ", currentDamageData=" + String.valueOf(this.currentDamageData) + ", nextLeaderDamageData=" + String.valueOf(this.nextLeaderDamageData) + ", currentLeaderDamageData=" + String.valueOf(this.currentLeaderDamageData) + ", removedStatus=" + String.valueOf(this.removedStatus);
    }
    
    public enum FlockRemovedStatus
    {
        NOT_REMOVED, 
        DISSOLVED, 
        UNLOADED;
    }
}
