mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-01-19 16:57:20 +07:00
Propagated sleep and params up to AI class
This commit is contained in:
parent
230816cfe2
commit
33e53d0ef1
@ -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) {}
|
||||
|
@ -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<Monster, State> 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;
|
||||
|
@ -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
|
||||
|
@ -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<Monster, State> 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;
|
||||
|
Loading…
Reference in New Issue
Block a user