v0.6.2: improved ai logic for piranhas and guards
This commit is contained in:
parent
933b2b5b89
commit
ab847c9e1b
|
@ -57,6 +57,8 @@ public class Guard extends Mob {
|
||||||
lootChance = 0.25f;
|
lootChance = 0.25f;
|
||||||
|
|
||||||
properties.add(Property.DEMONIC);
|
properties.add(Property.DEMONIC);
|
||||||
|
|
||||||
|
HUNTING = new Hunting();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -64,29 +66,6 @@ public class Guard extends Mob {
|
||||||
return Random.NormalIntRange(4, 12);
|
return Random.NormalIntRange(4, 12);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected boolean act() {
|
|
||||||
//FIXME should handle chaining in an extended hunting aistate
|
|
||||||
/*Dungeon.level.updateFieldOfView( this, fieldOfView );
|
|
||||||
|
|
||||||
if (state == HUNTING &&
|
|
||||||
paralysed <= 0 &&
|
|
||||||
enemy != null &&
|
|
||||||
enemy.invisible == 0 &&
|
|
||||||
Level.fieldOfView[enemy.pos] &&
|
|
||||||
Dungeon.level.distance( pos, enemy.pos ) < 5 &&
|
|
||||||
!Dungeon.level.adjacent( pos, enemy.pos ) &&
|
|
||||||
Random.Int(3) == 0 &&
|
|
||||||
|
|
||||||
chain(enemy.pos)) {
|
|
||||||
|
|
||||||
return false;
|
|
||||||
|
|
||||||
} else {*/
|
|
||||||
return super.act();
|
|
||||||
//}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean chain(int target){
|
private boolean chain(int target){
|
||||||
if (chainsUsed || enemy.properties().contains(Property.IMMOVABLE))
|
if (chainsUsed || enemy.properties().contains(Property.IMMOVABLE))
|
||||||
return false;
|
return false;
|
||||||
|
@ -180,4 +159,25 @@ public class Guard extends Mob {
|
||||||
super.restoreFromBundle(bundle);
|
super.restoreFromBundle(bundle);
|
||||||
chainsUsed = bundle.getBoolean(CHAINSUSED);
|
chainsUsed = bundle.getBoolean(CHAINSUSED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Hunting extends Mob.Hunting{
|
||||||
|
@Override
|
||||||
|
public boolean act( boolean enemyInFOV, boolean justAlerted ) {
|
||||||
|
enemySeen = enemyInFOV;
|
||||||
|
|
||||||
|
if (!chainsUsed
|
||||||
|
&& enemyInFOV
|
||||||
|
&& !isCharmedBy( enemy )
|
||||||
|
&& !canAttack( enemy )
|
||||||
|
&& Dungeon.level.distance( pos, enemy.pos ) < 5
|
||||||
|
&& Random.Int(3) == 0
|
||||||
|
|
||||||
|
&& chain(enemy.pos)){
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
return super.act( enemyInFOV, justAlerted );
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,9 @@ import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Frost;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Paralysis;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots;
|
import com.shatteredpixel.shatteredpixeldungeon.actors.buffs.Roots;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
|
import com.shatteredpixel.shatteredpixeldungeon.items.food.MysteryMeat;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.RegularLevel;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.Room;
|
||||||
|
import com.shatteredpixel.shatteredpixeldungeon.levels.rooms.special.PoolRoom;
|
||||||
import com.shatteredpixel.shatteredpixeldungeon.sprites.PiranhaSprite;
|
import com.shatteredpixel.shatteredpixeldungeon.sprites.PiranhaSprite;
|
||||||
import com.watabou.utils.Random;
|
import com.watabou.utils.Random;
|
||||||
|
|
||||||
|
@ -45,6 +48,8 @@ public class Piranha extends Mob {
|
||||||
baseSpeed = 2f;
|
baseSpeed = 2f;
|
||||||
|
|
||||||
EXP = 0;
|
EXP = 0;
|
||||||
|
|
||||||
|
HUNTING = new Hunting();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Piranha() {
|
public Piranha() {
|
||||||
|
@ -62,24 +67,6 @@ public class Piranha extends Mob {
|
||||||
sprite.killAndErase();
|
sprite.killAndErase();
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
//FIXME should handle this is an extended hunting
|
|
||||||
//this causes pirahna to move away when a door is closed on them.
|
|
||||||
/*Dungeon.level.updateFieldOfView( this, Level.fieldOfView );
|
|
||||||
enemy = chooseEnemy();
|
|
||||||
if (state == this.HUNTING &&
|
|
||||||
!(enemy != null && enemy.isAlive() && Level.fieldOfView[enemy.pos] && enemy.invisible <= 0)){
|
|
||||||
state = this.WANDERING;
|
|
||||||
int oldPos = pos;
|
|
||||||
int i = 0;
|
|
||||||
do {
|
|
||||||
i++;
|
|
||||||
target = Dungeon.level.randomDestination();
|
|
||||||
if (i == 100) return true;
|
|
||||||
} while (!getCloser(target));
|
|
||||||
moveSprite( oldPos, pos );
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return super.act();
|
return super.act();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,4 +145,20 @@ public class Piranha extends Mob {
|
||||||
public HashSet<Class<?>> immunities() {
|
public HashSet<Class<?>> immunities() {
|
||||||
return IMMUNITIES;
|
return IMMUNITIES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class Hunting extends Mob.Hunting{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean act(boolean enemyInFOV, boolean justAlerted) {
|
||||||
|
boolean result = super.act(enemyInFOV, justAlerted);
|
||||||
|
//this causes piranha to move away when a door is closed on them in a pool room.
|
||||||
|
if (state == WANDERING && Dungeon.level instanceof RegularLevel){
|
||||||
|
Room curRoom = ((RegularLevel)Dungeon.level).room(pos);
|
||||||
|
if (curRoom instanceof PoolRoom) {
|
||||||
|
target = Dungeon.level.pointToCell(curRoom.random(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user