/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  com.jme3.asset.AssetManager
 *  com.jme3.audio.AudioNode
 *  com.jme3.bullet.collision.shapes.CapsuleCollisionShape
 *  com.jme3.bullet.collision.shapes.CollisionShape
 *  com.jme3.bullet.control.BetterCharacterControl
 *  com.jme3.bullet.control.GhostControl
 *  com.jme3.effect.ParticleEmitter
 *  com.jme3.effect.ParticleMesh$Type
 *  com.jme3.light.Light
 *  com.jme3.light.PointLight
 *  com.jme3.material.Material
 *  com.jme3.math.ColorRGBA
 *  com.jme3.math.Vector3f
 *  com.jme3.post.SceneProcessor
 *  com.jme3.scene.Node
 *  com.jme3.scene.Spatial
 *  com.jme3.scene.control.Control
 *  com.jme3.scene.control.LightControl
 *  com.jme3.shadow.EdgeFilteringMode
 *  com.jme3.shadow.PointLightShadowFilter
 *  com.jme3.shadow.PointLightShadowRenderer
 */
package mygame;

import com.jme3.asset.AssetManager;
import com.jme3.audio.AudioNode;
import com.jme3.bullet.collision.shapes.CapsuleCollisionShape;
import com.jme3.bullet.collision.shapes.CollisionShape;
import com.jme3.bullet.control.BetterCharacterControl;
import com.jme3.bullet.control.GhostControl;
import com.jme3.effect.ParticleEmitter;
import com.jme3.effect.ParticleMesh;
import com.jme3.light.Light;
import com.jme3.light.PointLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.post.SceneProcessor;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.control.Control;
import com.jme3.scene.control.LightControl;
import com.jme3.shadow.EdgeFilteringMode;
import com.jme3.shadow.PointLightShadowFilter;
import com.jme3.shadow.PointLightShadowRenderer;
import mygame.Exchange;
import mygame.FireballControl;

public class Fireball
extends Node {
    ParticleEmitter fire;
    PointLight light;
    LightControl lightControl;
    GhostControl collisionGhost;
    GhostControl damageAreaGhost;
    BetterCharacterControl bodyControl;
    PointLightShadowRenderer dlsr;
    PointLightShadowFilter dlsf;
    FireballControl fireballControl;
    private AssetManager assetManager;
    Vector3f direction;
    Exchange exchange;
    boolean explode;
    float timer;
    float lifetime = 1.0f;

    public Fireball(AssetManager assetManager, Vector3f finish, Vector3f start, Exchange ex) {
        this.direction = finish;
        this.exchange = ex;
        assetManager = Exchange.assetManager;
        this.setLocalTranslation(start.add(new Vector3f(1.0f, 1.0f, 1.0f)));
        this.fire = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 30);
        Material mat_red = new Material(assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat_red.setTexture("Texture", assetManager.loadTexture("Effects/flame.png"));
        this.fire.setMaterial(mat_red);
        this.fire.setImagesX(2);
        this.fire.setImagesY(2);
        this.fire.setEndColor(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
        this.fire.setStartColor(new ColorRGBA(1.0f, 1.0f, 0.0f, 0.5f));
        this.fire.getParticleInfluencer().setInitialVelocity(new Vector3f(0.0f, 2.0f, 0.0f));
        this.fire.setStartSize(1.5f);
        this.fire.setEndSize(0.1f);
        this.fire.setGravity(0.0f, 0.0f, 0.0f);
        this.fire.setLowLife(1.0f);
        this.fire.setHighLife(3.0f);
        this.fire.getParticleInfluencer().setVelocityVariation(0.3f);
        this.attachChild((Spatial)this.fire);
        this.light = new PointLight();
        this.light.setColor(new ColorRGBA(1.0f, 0.5f, 0.0f, 1.0f));
        this.light.setPosition(this.getLocalTranslation());
        this.light.setRadius(100.0f);
        Exchange.rootNode.addLight((Light)this.light);
        this.dlsr = new PointLightShadowRenderer(assetManager, 128);
        this.dlsr.setLight(this.light);
        this.dlsr.setShadowIntensity(0.2f);
        this.dlsr.setEdgeFilteringMode(EdgeFilteringMode.Dither);
        Exchange.viewPort.addProcessor((SceneProcessor)this.dlsr);
        this.dlsf = new PointLightShadowFilter(assetManager, 128);
        this.dlsf.setLight(this.light);
        this.dlsf.setShadowIntensity(0.2f);
        this.dlsf.setEdgeFilteringMode(EdgeFilteringMode.Dither);
        this.dlsf.setEnabled(false);
        this.collisionGhost = new GhostControl((CollisionShape)new CapsuleCollisionShape(1.0f, 0.5f));
        this.collisionGhost.setSpatial((Spatial)this);
        this.collisionGhost.addCollideWithGroup(1);
        this.addControl((Control)this.collisionGhost);
        this.damageAreaGhost = new GhostControl((CollisionShape)new CapsuleCollisionShape(5.0f, 1.0f));
        this.damageAreaGhost.addCollideWithGroup(1);
        this.addControl((Control)this.damageAreaGhost);
        this.bodyControl = new BetterCharacterControl(0.1f, 0.1f, 1.0f);
        this.addControl((Control)this.bodyControl);
        this.fireballControl = new FireballControl();
        this.addControl((Control)this.fireballControl);
        Exchange.rootNode.attachChild((Spatial)this);
        Exchange.bulletAppState.getPhysicsSpace().add((Object)this.damageAreaGhost);
        Exchange.bulletAppState.getPhysicsSpace().add((Object)this.collisionGhost);
        Exchange.bulletAppState.getPhysicsSpace().add((Object)this.bodyControl);
        AudioNode hit = new AudioNode(assetManager, "Sounds/Effects/fireball.ogg", false);
        hit.setLooping(false);
        hit.setPositional(true);
        hit.setLocalTranslation(this.getLocalTranslation());
        hit.setVolume(5.0f);
        this.attachChild((Spatial)hit);
        hit.play();
    }

    public void explode() {
        ParticleEmitter xplosion = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 50);
        Material mat_red = new Material(Exchange.assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat_red.setTexture("Texture", Exchange.assetManager.loadTexture("Effects/flame.png"));
        xplosion.setMaterial(mat_red);
        xplosion.setImagesX(2);
        xplosion.setParticlesPerSec(0.0f);
        xplosion.setImagesY(2);
        xplosion.setEndColor(new ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f));
        xplosion.setStartColor(new ColorRGBA(1.0f, 1.0f, 0.0f, 0.5f));
        xplosion.getParticleInfluencer().setInitialVelocity(new Vector3f(0.5f, 0.5f, 0.5f));
        xplosion.setStartSize(1.5f);
        xplosion.setEndSize(2.0f);
        xplosion.setGravity(0.0f, 1.0f, 0.0f);
        xplosion.setLowLife(1.0f);
        xplosion.setHighLife(2.0f);
        xplosion.getParticleInfluencer().setVelocityVariation(2.0f);
        this.attachChild((Spatial)xplosion);
        xplosion.emitAllParticles();
        ParticleEmitter stones = new ParticleEmitter("Emitter", ParticleMesh.Type.Triangle, 20);
        Material mat_stones = new Material(Exchange.assetManager, "Common/MatDefs/Misc/Particle.j3md");
        mat_stones.setTexture("Texture", Exchange.assetManager.loadTexture("Effects/stein.png"));
        mat_stones.setTexture("GlowMap", Exchange.assetManager.loadTexture("Effects/stein.png"));
        mat_stones.setTexture("DepthTexture", Exchange.assetManager.loadTexture("Effects/stein.png"));
        stones.setMaterial(mat_stones);
        stones.setImagesX(2);
        stones.setParticlesPerSec(0.0f);
        stones.setImagesY(2);
        stones.setEndColor(new ColorRGBA(0.1f, 0.1f, 0.1f, 1.0f));
        stones.setStartColor(new ColorRGBA(0.0f, 0.0f, 0.0f, 1.0f));
        stones.getParticleInfluencer().setInitialVelocity(new Vector3f(2.0f, 0.0f, 2.0f));
        stones.setStartSize(0.1f);
        stones.setEndSize(0.5f);
        stones.setGravity(2.0f, 0.0f, 2.0f);
        stones.setLowLife(1.0f);
        stones.setHighLife(1.0f);
        stones.getParticleInfluencer().setVelocityVariation(5.0f);
        this.attachChild((Spatial)stones);
        stones.emitAllParticles();
        AudioNode explode = new AudioNode(Exchange.assetManager, "Sounds/Effects/explosion.ogg", false);
        explode.setLooping(false);
        explode.setPositional(true);
        explode.setLocalTranslation(this.getLocalTranslation());
        explode.setVolume(5.0f);
        this.attachChild((Spatial)explode);
        explode.play();
        this.explode = true;
        this.fire.emitAllParticles();
        this.timer = 0.1f;
    }
}
