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

package com.hypixel.hytale.builtin.adventure.camera.command;

import com.hypixel.hytale.protocol.Packet;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.modules.entity.damage.DamageSystems;
import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
import com.hypixel.hytale.server.core.modules.entity.damage.DamageCause;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractTargetPlayerCommand;
import com.hypixel.hytale.assetstore.map.JsonAssetWithMap;
import com.hypixel.hytale.server.core.command.system.arguments.types.AssetArgumentType;
import com.hypixel.hytale.server.core.command.system.AbstractCommand;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.asset.type.camera.CameraEffect;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;

public class CameraEffectCommand extends AbstractCommandCollection
{
    @Nonnull
    protected static final ArgumentType<CameraEffect> CAMERA_EFFECT_ARGUMENT_TYPE;
    
    public CameraEffectCommand() {
        super("camshake", "server.commands.camshake.desc");
        this.addSubCommand(new DamageCommand());
        this.addSubCommand(new DebugCommand());
    }
    
    static {
        CAMERA_EFFECT_ARGUMENT_TYPE = new AssetArgumentType("CameraEffect", (Class<JsonAssetWithMap>)CameraEffect.class, "");
    }
    
    protected static class DamageCommand extends AbstractTargetPlayerCommand
    {
        @Nonnull
        protected static final ArgumentType<DamageCause> DAMAGE_CAUSE_ARGUMENT_TYPE;
        @Nonnull
        protected final OptionalArg<CameraEffect> effectArg;
        @Nonnull
        protected final RequiredArg<DamageCause> causeArg;
        @Nonnull
        protected final RequiredArg<Float> damageArg;
        
        public DamageCommand() {
            super("damage", "server.commands.camshake.damage.desc");
            this.effectArg = this.withOptionalArg("effect", "server.commands.camshake.effect.desc", CameraEffectCommand.CAMERA_EFFECT_ARGUMENT_TYPE);
            this.causeArg = this.withRequiredArg("cause", "server.commands.camshake.damage.cause.desc", DamageCommand.DAMAGE_CAUSE_ARGUMENT_TYPE);
            this.damageArg = this.withRequiredArg("amount", "server.commands.camshake.damage.amount.desc", ArgTypes.FLOAT);
        }
        
        @Override
        protected void execute(@Nonnull final CommandContext context, @Nullable final Ref<EntityStore> sourceRef, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
            final DamageCause damageCause = context.get((Argument<?, DamageCause>)this.causeArg);
            final float damageAmount = context.get((Argument<?, Float>)this.damageArg);
            final Damage.CommandSource damageSource = new Damage.CommandSource(context.sender(), this.getName());
            final Damage damageEvent = new Damage(damageSource, damageCause, damageAmount);
            String cameraEffectId = "Default";
            if (this.effectArg.provided(context)) {
                cameraEffectId = context.get((Argument<?, CameraEffect>)this.effectArg).getId();
                final Damage.CameraEffect damageEffect = new Damage.CameraEffect(CameraEffect.getAssetMap().getIndex(cameraEffectId));
                damageEvent.getMetaStore().putMetaObject(Damage.CAMERA_EFFECT, damageEffect);
            }
            DamageSystems.executeDamage(ref, store, damageEvent);
            context.sendMessage(Message.translation("server.commands.camshake.damage.success").param("effect", cameraEffectId).param("cause", damageCause.getId()).param("amount", damageAmount));
        }
        
        static {
            DAMAGE_CAUSE_ARGUMENT_TYPE = new AssetArgumentType("DamageCause", (Class<JsonAssetWithMap>)DamageCause.class, "");
        }
    }
    
    protected static class DebugCommand extends AbstractTargetPlayerCommand
    {
        private static final String MESSAGE_SUCCESS = "server.commands.camshake.debug.success";
        @Nonnull
        protected final RequiredArg<CameraEffect> effectArg;
        @Nonnull
        protected final RequiredArg<Float> intensityArg;
        
        public DebugCommand() {
            super("debug", "server.commands.camshake.debug.desc");
            this.effectArg = this.withRequiredArg("effect", "server.commands.camshake.effect.desc", CameraEffectCommand.CAMERA_EFFECT_ARGUMENT_TYPE);
            this.intensityArg = this.withRequiredArg("intensity", "server.commands.camshake.debug.intensity.desc", ArgTypes.FLOAT);
        }
        
        @Override
        protected void execute(@Nonnull final CommandContext context, @Nullable final Ref<EntityStore> sourceRef, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
            final CameraEffect cameraEffect = context.get((Argument<?, CameraEffect>)this.effectArg);
            final float intensity = context.get((Argument<?, Float>)this.intensityArg);
            final PlayerRef playerRefComponent = store.getComponent(ref, PlayerRef.getComponentType());
            assert playerRefComponent != null;
            playerRefComponent.getPacketHandler().writeNoCache(cameraEffect.createCameraShakePacket(intensity));
            context.sendMessage(Message.translation("server.commands.camshake.debug.success").param("effect", cameraEffect.getId()).param("intensity", intensity));
        }
    }
}
