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

package com.hypixel.hytale.server.spawning.wrappers;

import javax.annotation.Nullable;
import java.util.Random;
import com.hypixel.hytale.common.map.WeightedMap;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.spawning.assets.spawns.config.RoleSpawnParameters;
import com.hypixel.hytale.common.map.IWeightedMap;
import com.hypixel.hytale.server.spawning.assets.spawns.config.BeaconNPCSpawn;

public class BeaconSpawnWrapper extends SpawnWrapper<BeaconNPCSpawn>
{
    @Nonnull
    private final IWeightedMap<RoleSpawnParameters> weightedRoles;
    private final double minDistanceFromPlayerSquared;
    private final double targetDistanceFromPlayerSquared;
    
    public BeaconSpawnWrapper(@Nonnull final BeaconNPCSpawn spawn) {
        super(BeaconNPCSpawn.getAssetMap().getIndex(spawn.getId()), spawn);
        final WeightedMap.Builder<RoleSpawnParameters> mapBuilder = WeightedMap.builder(RoleSpawnParameters.EMPTY_ARRAY);
        for (final RoleSpawnParameters npc : spawn.getNPCs()) {
            if (!this.hasInvalidNPC(npc.getId())) {
                mapBuilder.put(npc, npc.getWeight());
            }
        }
        this.weightedRoles = mapBuilder.build();
        final double minDistance = spawn.getMinDistanceFromPlayer();
        this.minDistanceFromPlayerSquared = minDistance * minDistance;
        final double targetDistance = spawn.getTargetDistanceFromPlayer();
        this.targetDistanceFromPlayerSquared = targetDistance * targetDistance;
    }
    
    public double getMinDistanceFromPlayerSquared() {
        return this.minDistanceFromPlayerSquared;
    }
    
    public double getTargetDistanceFromPlayerSquared() {
        return this.targetDistanceFromPlayerSquared;
    }
    
    public double getBeaconRadius() {
        return ((BeaconNPCSpawn)this.spawn).getBeaconRadius();
    }
    
    public double getSpawnRadius() {
        return ((BeaconNPCSpawn)this.spawn).getSpawnRadius();
    }
    
    @Nullable
    public RoleSpawnParameters pickRole(final Random chanceProvider) {
        if (this.weightedRoles.size() == 0) {
            return null;
        }
        return this.weightedRoles.get(chanceProvider);
    }
}
