Package com.teamjmonkey.ai.aggro

Source Code of com.teamjmonkey.ai.aggro.AggroBehaviorEat

package com.teamjmonkey.ai.aggro;

import com.jme3.scene.Spatial;
import com.teamjmonkey.animation.AnimType;
import com.teamjmonkey.controls.FoodControl;
import com.teamjmonkey.entity.Creature;
import com.teamjmonkey.entity.food.FoodEntity;

public class AggroBehaviorEat extends AggroBehaviorBase {

    private Creature creature;
    private Spatial target;
    private boolean done;

    public AggroBehaviorEat(Creature creature) {
        this.creature = creature;
    }

    public void update(float tpf, Spatial target, boolean hasOtherAggroType) {
        if (done) {
            return;
        }
        if (!creature.getAnimComponent().getCurAnim().equals(AnimType.EAT)) {
            this.target = target;
            eat();
        }
    }

    public void onAggro(Spatial target) {
        done = false;
        creature.stop();
        creature.eatAnim();
        this.target = target;
    }

    private void eat() {
        FoodControl fc = target.getControl(FoodControl.class);
        FoodEntity fe = (FoodEntity)target.getUserData("entity");
        if (fc != null && fe != null) {
            creature.stop();
            creature.eat(fc);
            fe.remove();
            done = true;
        }
    }

    public void onAggroLoss() {
    }
}
TOP

Related Classes of com.teamjmonkey.ai.aggro.AggroBehaviorEat

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.