package org.egordorichev.lasttry.entity.entities.creature.ai;

import org.egordorichev.lasttry.entity.Entity;
import org.egordorichev.lasttry.entity.entities.creature.Creature;
import org.egordorichev.lasttry.entity.entities.creature.StateComponent;
import org.egordorichev.lasttry.util.log.Log;

import java.lang.reflect.Method;
import java.util.HashMap;

/**
 * Represents entity AI
 */
public class Ai {
	protected HashMap<String, Method> methods = new HashMap<>();

	/**
	 * Updates the AI
	 *
	 * @param entity The entity, that is being updated
	 */
	public void update(Entity entity) {
		StateComponent state = entity.getComponent(StateComponent.class);
		Method method = this.methods.get(state.state);

		if (method != null) {
			try {
				method.invoke((Creature) entity, state.time);
			} catch (Exception exception) {
				Log.error("Failed to call " + state.state + " state");
			}
		}

		state.time += 1;
	}

	/**
	 * Registers new state
	 *
	 * @param state New state
	 */
	protected void register(String state) {
		try {
			this.methods.put(state, this.getClass().getMethod(state, Creature.class, Integer.class));
		} catch (Exception exception) {
			exception.printStackTrace();
			Log.error("Failed to register " + state + " state");
		}
	}

	/**
	 * Registers new states
	 *
	 * @param states New states
	 */
	protected void registerAll(String... states) {
		for (String state : states) {
			this.register(state);
		}
	}
}
@@ -754,16 +754,22 @@
 .invoke(
+this, 
 (Creatur
@@ -827,16 +827,49 @@
 tion) %7B%0A
+%09%09%09%09exception.printStackTrace();%0A
 %09%09%09%09Log.
@@ -1146,15 +1146,11 @@
 ss, 
-I
+i
 nt
-eger
 .cla

Fix states