fixed knight robot
This commit is contained in:
parent
99309b381a
commit
487b0cc7e6
4 changed files with 53 additions and 49 deletions
|
@ -26,10 +26,13 @@ public class AIRobotAttack extends AIRobot {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
robot.setItemActive(true);
|
||||
robot.aimItemAt((int) Math.floor(target.posX), (int) Math.floor(target.posY),
|
||||
(int) Math.floor(target.posZ));
|
||||
public void preempt(AIRobot ai) {
|
||||
if (ai instanceof AIRobotGotoBlock) {
|
||||
if (robot.getDistanceToEntity(target) <= 2.0) {
|
||||
abortDelegateAI();
|
||||
robot.setItemActive(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -40,7 +43,11 @@ public class AIRobotAttack extends AIRobot {
|
|||
}
|
||||
|
||||
if (robot.getDistanceToEntity(target) > 2.0) {
|
||||
terminate();
|
||||
startDelegateAI(new AIRobotGotoBlock(robot, (int) Math.floor(target.posX),
|
||||
(int) Math.floor(target.posY), (int) Math.floor(target.posZ)));
|
||||
robot.setItemActive(false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
delay++;
|
||||
|
@ -57,4 +64,17 @@ public class AIRobotAttack extends AIRobot {
|
|||
public void end() {
|
||||
robot.setItemActive(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotGotoBlock) {
|
||||
AIRobotGotoBlock aiGoto = (AIRobotGotoBlock) ai;
|
||||
|
||||
if (((AIRobotGotoBlock) ai).unreachable) {
|
||||
robot.unreachableEntityDetected(target);
|
||||
}
|
||||
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,14 +16,14 @@ import buildcraft.api.robots.AIRobot;
|
|||
import buildcraft.api.robots.EntityRobotBase;
|
||||
import buildcraft.core.inventory.TransactorSimple;
|
||||
|
||||
public class AIRobotGotoMob extends AIRobot {
|
||||
public class AIRobotFindMob extends AIRobot {
|
||||
|
||||
public EntityMob target;
|
||||
|
||||
private float maxRange;
|
||||
private IBox box;
|
||||
|
||||
public AIRobotGotoMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) {
|
||||
public AIRobotFindMob(EntityRobotBase iRobot, float iMaxRange, IBox iBox) {
|
||||
super(iRobot, 0);
|
||||
|
||||
maxRange = iMaxRange;
|
||||
|
@ -40,7 +40,8 @@ public class AIRobotGotoMob extends AIRobot {
|
|||
|
||||
if (!e.isDead
|
||||
&& e instanceof EntityMob
|
||||
&& (box == null || box.contains(e.posX, e.posY, e.posZ))) {
|
||||
&& (box == null || box.contains(e.posX, e.posY, e.posZ))
|
||||
&& (!robot.isKnownUnreachable(e))) {
|
||||
double dx = e.posX - robot.posX;
|
||||
double dy = e.posY - robot.posY;
|
||||
double dz = e.posZ - robot.posZ;
|
||||
|
@ -64,30 +65,6 @@ public class AIRobotGotoMob extends AIRobot {
|
|||
}
|
||||
}
|
||||
|
||||
if (target != null) {
|
||||
startDelegateAI(new AIRobotGotoBlock(robot, (int) Math.floor(target.posX),
|
||||
(int) Math.floor(target.posY), (int) Math.floor(target.posZ)));
|
||||
|
||||
} else {
|
||||
// No mob was found, terminate this AI
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preempt(AIRobot ai) {
|
||||
if (target.isDead) {
|
||||
terminate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (target.isDead) {
|
||||
terminate();
|
||||
} else {
|
||||
// fight
|
||||
terminate();
|
||||
}
|
||||
terminate();
|
||||
}
|
||||
}
|
|
@ -57,7 +57,7 @@ public class AIRobotGotoStationToLoad extends AIRobot {
|
|||
|
||||
@Override
|
||||
public boolean matches(DockingStation station) {
|
||||
boolean found = false;
|
||||
boolean actionFound = false;
|
||||
|
||||
Pipe pipe = station.pipe.pipe;
|
||||
|
||||
|
@ -66,13 +66,13 @@ public class AIRobotGotoStationToLoad extends AIRobot {
|
|||
StatementParameterStackFilter param = new StatementParameterStackFilter(s.parameters);
|
||||
|
||||
if (!param.hasFilter() || param.matches(filter)) {
|
||||
found = true;
|
||||
actionFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
if (!actionFound) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,8 @@ import buildcraft.api.robots.EntityRobotBase;
|
|||
import buildcraft.core.inventory.filters.IStackFilter;
|
||||
import buildcraft.core.robots.AIRobotAttack;
|
||||
import buildcraft.core.robots.AIRobotFetchAndEquipItemStack;
|
||||
import buildcraft.core.robots.AIRobotGotoMob;
|
||||
import buildcraft.core.robots.AIRobotFindMob;
|
||||
import buildcraft.core.robots.AIRobotGotoSleep;
|
||||
|
||||
public class BoardRobotKnight extends RedstoneBoardRobot {
|
||||
|
||||
|
@ -31,17 +32,6 @@ public class BoardRobotKnight extends RedstoneBoardRobot {
|
|||
return BoardRobotKnightNBT.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preempt(AIRobot ai) {
|
||||
if (ai instanceof AIRobotGotoMob) {
|
||||
AIRobotGotoMob mobAI = (AIRobotGotoMob) ai;
|
||||
|
||||
if (robot.getDistanceToEntity(mobAI.target) < 2.0) {
|
||||
startDelegateAI(new AIRobotAttack(robot, mobAI.target));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void update() {
|
||||
if (robot.getItemInUse() == null) {
|
||||
|
@ -52,7 +42,24 @@ public class BoardRobotKnight extends RedstoneBoardRobot {
|
|||
}
|
||||
}));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotGotoMob(robot, 250, robot.getAreaToWork()));
|
||||
startDelegateAI(new AIRobotFindMob(robot, 250, robot.getAreaToWork()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void delegateAIEnded(AIRobot ai) {
|
||||
if (ai instanceof AIRobotFetchAndEquipItemStack) {
|
||||
if (robot.getItemInUse() == null) {
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
}
|
||||
} else if (ai instanceof AIRobotFindMob) {
|
||||
AIRobotFindMob mobAI = (AIRobotFindMob) ai;
|
||||
|
||||
if (mobAI.target != null) {
|
||||
startDelegateAI(new AIRobotAttack(robot, ((AIRobotFindMob) ai).target));
|
||||
} else {
|
||||
startDelegateAI(new AIRobotGotoSleep(robot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue