diff --git a/core/src/com/riiablo/ai/AI.java b/core/src/com/riiablo/ai/AI.java index be96d8be..161d61ba 100644 --- a/core/src/com/riiablo/ai/AI.java +++ b/core/src/com/riiablo/ai/AI.java @@ -1,15 +1,40 @@ package com.riiablo.ai; +import com.riiablo.codec.Animation; import com.riiablo.entity.Monster; import com.riiablo.screen.GameScreen; +import org.apache.commons.lang3.ArrayUtils; + public abstract class AI { public static final AI IDLE = new Idle(); + protected final float SLEEP; + protected final int[] params; protected Monster entity; public AI(Monster entity) { this.entity = entity; + + // Special case for Idle AI -- TODO: fix Idle AI to remove this special case + if (entity == null) { + SLEEP = Float.POSITIVE_INFINITY; + params = ArrayUtils.EMPTY_INT_ARRAY; + return; + } + + // TODO: difficulty-based params + params = new int[8]; + params[0] = entity.monstats.aip1[0]; + params[1] = entity.monstats.aip2[0]; + params[2] = entity.monstats.aip3[0]; + params[3] = entity.monstats.aip4[0]; + params[4] = entity.monstats.aip5[0]; + params[5] = entity.monstats.aip6[0]; + params[6] = entity.monstats.aip7[0]; + params[7] = entity.monstats.aip8[0]; + + SLEEP = Animation.FRAME_DURATION * entity.monstats.aidel[0]; } public void interact(GameScreen gameScreen) {} diff --git a/core/src/com/riiablo/ai/Fallen.java b/core/src/com/riiablo/ai/Fallen.java index 60129764..c7618a06 100644 --- a/core/src/com/riiablo/ai/Fallen.java +++ b/core/src/com/riiablo/ai/Fallen.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.ai.msg.Telegram; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.riiablo.Riiablo; -import com.riiablo.codec.Animation; import com.riiablo.entity.Entity; import com.riiablo.entity.Monster; import com.riiablo.entity.Player; @@ -32,28 +31,12 @@ public class Fallen extends AI { } } - private final float SLEEP; - - int[] pa; final StateMachine stateMachine; float nextAction; float time; public Fallen(Monster entity) { super(entity); - - // TODO: difficulty-based params - pa = new int[8]; - pa[0] = entity.monstats.aip1[0]; - pa[1] = entity.monstats.aip2[0]; - pa[2] = entity.monstats.aip3[0]; - pa[3] = entity.monstats.aip4[0]; - pa[4] = entity.monstats.aip5[0]; - pa[5] = entity.monstats.aip6[0]; - pa[6] = entity.monstats.aip7[0]; - pa[7] = entity.monstats.aip8[0]; - - SLEEP = Animation.FRAME_DURATION * entity.monstats.aidel[0]; stateMachine = new DefaultStateMachine<>(entity, State.IDLE); } @@ -76,12 +59,12 @@ public class Fallen extends AI { if (dst < melerng) { entity.setPath(null, null); stateMachine.changeState(State.ATTACK); - entity.sequence(MathUtils.randomBoolean(pa[3] / 100f) ? Monster.MODE_A2 : Monster.MODE_A1, Monster.MODE_NU); + entity.sequence(MathUtils.randomBoolean(params[3] / 100f) ? Monster.MODE_A2 : Monster.MODE_A1, Monster.MODE_NU); Riiablo.audio.play(entity.monstats.MonSound + "_attack_1", true); time = MathUtils.random(1f, 2); return; } else if (dst < 35) { - if (MathUtils.randomBoolean(pa[0] / 100f)) { + if (MathUtils.randomBoolean(params[0] / 100f)) { entity.setPath(entity.map, ent.position()); stateMachine.changeState(State.APPROACH); return; diff --git a/core/src/com/riiablo/ai/QuillRat.java b/core/src/com/riiablo/ai/QuillRat.java index 2a6f2451..85b0b1a5 100644 --- a/core/src/com/riiablo/ai/QuillRat.java +++ b/core/src/com/riiablo/ai/QuillRat.java @@ -6,21 +6,8 @@ import com.riiablo.entity.Monster; public class QuillRat extends AI { - int[] pa; - public QuillRat(Monster entity) { super(entity); - - // TODO: difficulty-based params - pa = new int[8]; - pa[0] = entity.monstats.aip1[0]; - pa[1] = entity.monstats.aip2[0]; - pa[2] = entity.monstats.aip3[0]; - pa[3] = entity.monstats.aip4[0]; - pa[4] = entity.monstats.aip5[0]; - pa[5] = entity.monstats.aip6[0]; - pa[6] = entity.monstats.aip7[0]; - pa[7] = entity.monstats.aip8[0]; } @Override diff --git a/core/src/com/riiablo/ai/Zombie.java b/core/src/com/riiablo/ai/Zombie.java index ef6ff648..291b88bc 100644 --- a/core/src/com/riiablo/ai/Zombie.java +++ b/core/src/com/riiablo/ai/Zombie.java @@ -6,7 +6,6 @@ import com.badlogic.gdx.ai.msg.Telegram; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.riiablo.Riiablo; -import com.riiablo.codec.Animation; import com.riiablo.entity.Entity; import com.riiablo.entity.Monster; import com.riiablo.entity.Player; @@ -32,28 +31,12 @@ public class Zombie extends AI { } } - private final float SLEEP; - - int[] pa; final StateMachine stateMachine; float nextAction; float time; public Zombie(Monster entity) { super(entity); - - // TODO: difficulty-based params - pa = new int[8]; - pa[0] = entity.monstats.aip1[0]; - pa[1] = entity.monstats.aip2[0]; - pa[2] = entity.monstats.aip3[0]; - pa[3] = entity.monstats.aip4[0]; - pa[4] = entity.monstats.aip5[0]; - pa[5] = entity.monstats.aip6[0]; - pa[6] = entity.monstats.aip7[0]; - pa[7] = entity.monstats.aip8[0]; - - SLEEP = Animation.FRAME_DURATION * entity.monstats.aidel[0]; stateMachine = new DefaultStateMachine<>(entity, State.IDLE); } @@ -76,12 +59,12 @@ public class Zombie extends AI { if (dst < melerng) { entity.setPath(null, null); stateMachine.changeState(State.ATTACK); - entity.sequence(MathUtils.randomBoolean(pa[3] / 100f) ? Monster.MODE_A2 : Monster.MODE_A1, Monster.MODE_NU); + entity.sequence(MathUtils.randomBoolean(params[3] / 100f) ? Monster.MODE_A2 : Monster.MODE_A1, Monster.MODE_NU); Riiablo.audio.play(entity.monstats.MonSound + "_attack_1", true); time = MathUtils.random(1f, 2); return; - } else if (dst < pa[1]) { - if (MathUtils.randomBoolean(pa[0] / 100f)) { + } else if (dst < params[1]) { + if (MathUtils.randomBoolean(params[0] / 100f)) { entity.setPath(entity.map, ent.position()); stateMachine.changeState(State.APPROACH); return;