Removing Nulls.unit
This commit is contained in:
@@ -116,7 +116,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
private WidgetGroup group = new WidgetGroup();
|
||||
|
||||
private final Eachable<BuildPlan> allPlans = cons -> {
|
||||
player.unit().plans().each(cons);
|
||||
if(!player.dead()){
|
||||
player.unit().plans().each(cons);
|
||||
}
|
||||
selectPlans.each(cons);
|
||||
linePlans.each(cons);
|
||||
};
|
||||
@@ -236,9 +238,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
public static void commandUnits(Player player, int[] unitIds, @Nullable Building buildTarget, @Nullable Unit unitTarget, @Nullable Vec2 posTarget, boolean queueCommand, boolean finalBatch){
|
||||
if(player == null || unitIds == null) return;
|
||||
|
||||
//why did I ever think this was a good idea
|
||||
if(unitTarget != null && unitTarget.isNull()) unitTarget = null;
|
||||
|
||||
if(net.server() && !netServer.admins.allowAction(player, ActionType.commandUnits, event -> {
|
||||
event.unitIDs = unitIds;
|
||||
})){
|
||||
@@ -260,7 +259,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
if(teamTarget != null && teamTarget.team() != player.team() &&
|
||||
!(teamTarget instanceof Unit u && !unit.canTarget(u)) && !(teamTarget instanceof Building && !unit.type.targetGround)){
|
||||
!(teamTarget instanceof Unit u && !unit.canTarget(u)) && !(teamTarget instanceof Building && !unit.type.targetGround)){
|
||||
|
||||
anyCommandedTarget = true;
|
||||
if(queueCommand){
|
||||
@@ -282,7 +281,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
if(ai.commandQueue.size <= 0){
|
||||
ai.group = null;
|
||||
}
|
||||
|
||||
|
||||
//remove when other player command
|
||||
if(!headless && player != Vars.player){
|
||||
control.input.selectedUnits.remove(unit);
|
||||
@@ -489,8 +488,6 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
@Remote(targets = Loc.server, called = Loc.server)
|
||||
public static void pickedUnitPayload(Unit unit, Unit target){
|
||||
if(target == Nulls.unit) return;
|
||||
|
||||
if(target != null && unit instanceof Payloadc pay){
|
||||
pay.pickup(target);
|
||||
}else if(target != null){
|
||||
@@ -599,7 +596,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
if(build == null) return;
|
||||
|
||||
if(net.server() && (!Units.canInteract(player, build) ||
|
||||
!netServer.admins.allowAction(player, ActionType.rotate, build.tile(), action -> action.rotation = Mathf.mod(build.rotation + Mathf.sign(direction), 4)))){
|
||||
!netServer.admins.allowAction(player, ActionType.rotate, build.tile(), action -> action.rotation = Mathf.mod(build.rotation + Mathf.sign(direction), 4)))){
|
||||
throw new ValidateException(player, "Player cannot rotate a block.");
|
||||
}
|
||||
|
||||
@@ -618,7 +615,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
if(build == null) return;
|
||||
|
||||
if(net.server() && (!Units.canInteract(player, build) ||
|
||||
!netServer.admins.allowAction(player, ActionType.configure, build.tile, action -> action.config = value))){
|
||||
!netServer.admins.allowAction(player, ActionType.configure, build.tile, action -> action.config = value))){
|
||||
|
||||
if(player.con != null){
|
||||
var packet = new TileConfigCallPacket(); //undo the config on the client
|
||||
@@ -697,7 +694,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
player.unit(unit);
|
||||
|
||||
if(before != null && !before.isNull()){
|
||||
if(before != null){
|
||||
if(before.spawnedByCore){
|
||||
unit.dockedType = before.type;
|
||||
}else if(before.dockedType != null && before.dockedType.coreUnitDock){
|
||||
@@ -812,7 +809,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
}
|
||||
|
||||
playerPlanTree.clear();
|
||||
player.unit().plans.each(playerPlanTree::insert);
|
||||
if(!player.dead()){
|
||||
player.unit().plans.each(playerPlanTree::insert);
|
||||
}
|
||||
|
||||
player.typing = ui.chatfrag.shown();
|
||||
|
||||
@@ -824,7 +823,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
player.unit().updateBuilding(isBuilding);
|
||||
}
|
||||
|
||||
if(player.shooting && !wasShooting && player.unit().hasWeapons() && state.rules.unitAmmo && !player.team().rules().infiniteAmmo && player.unit().ammo <= 0){
|
||||
if(!player.dead() && player.shooting && !wasShooting && player.unit().hasWeapons() && state.rules.unitAmmo && !player.team().rules().infiniteAmmo && player.unit().ammo <= 0){
|
||||
player.unit().type.weapons.first().noAmmoSound.at(player.unit());
|
||||
}
|
||||
|
||||
@@ -1673,9 +1672,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
boolean canMine(Tile tile){
|
||||
return !Core.scene.hasMouse()
|
||||
&& player.unit().validMine(tile)
|
||||
&& player.unit().acceptsItem(player.unit().getMineResult(tile))
|
||||
&& !((!Core.settings.getBool("doubletapmine") && tile.floor().playerUnmineable) && tile.overlay().itemDrop == null);
|
||||
&& player.unit().validMine(tile)
|
||||
&& player.unit().acceptsItem(player.unit().getMineResult(tile))
|
||||
&& !((!Core.settings.getBool("doubletapmine") && tile.floor().playerUnmineable) && tile.overlay().itemDrop == null);
|
||||
}
|
||||
|
||||
/** Returns the tile at the specified MOUSE coordinates. */
|
||||
@@ -1841,7 +1840,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
|
||||
public boolean canShoot(){
|
||||
return block == null && !onConfigurable() && !isDroppingItem() && !player.unit().activelyBuilding() &&
|
||||
!(player.unit() instanceof Mechc && player.unit().isFlying()) && !player.unit().mining() && !commandMode;
|
||||
!(player.unit() instanceof Mechc && player.unit().isFlying()) && !player.unit().mining() && !commandMode;
|
||||
}
|
||||
|
||||
public boolean onConfigurable(){
|
||||
@@ -1867,7 +1866,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
||||
ItemStack stack = player.unit().stack;
|
||||
|
||||
if(build != null && build.acceptStack(stack.item, stack.amount, player.unit()) > 0 && build.interactable(player.team()) &&
|
||||
build.block.hasItems && player.unit().stack().amount > 0 && build.interactable(player.team())){
|
||||
build.block.hasItems && player.unit().stack().amount > 0 && build.interactable(player.team())){
|
||||
|
||||
if(!(state.rules.onlyDepositCore && !(build instanceof CoreBuild)) && itemDepositCooldown <= 0f){
|
||||
Call.transferInventory(player, build);
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
void checkTargets(float x, float y){
|
||||
Unit unit = Units.closestEnemy(player.team(), x, y, 20f, u -> !u.dead);
|
||||
|
||||
if(unit != null && player.unit().type.canAttack){
|
||||
if(unit != null && !player.dead() && player.unit().type.canAttack){
|
||||
player.unit().mineTile = null;
|
||||
target = unit;
|
||||
}else{
|
||||
@@ -126,18 +126,21 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
for(var plan : player.unit().plans()){
|
||||
Tile other = world.tile(plan.x, plan.y);
|
||||
if(!player.dead()){
|
||||
for(var plan : player.unit().plans()){
|
||||
Tile other = world.tile(plan.x, plan.y);
|
||||
|
||||
if(other == null || plan.breaking) continue;
|
||||
if(other == null || plan.breaking) continue;
|
||||
|
||||
r1.setSize(plan.block.size * tilesize);
|
||||
r1.setCenter(other.worldx() + plan.block.offset, other.worldy() + plan.block.offset);
|
||||
r1.setSize(plan.block.size * tilesize);
|
||||
r1.setCenter(other.worldx() + plan.block.offset, other.worldy() + plan.block.offset);
|
||||
|
||||
if(r2.overlaps(r1)){
|
||||
return true;
|
||||
if(r2.overlaps(r1)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -263,7 +266,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
|
||||
boolean showCancel(){
|
||||
return (player.unit().isBuilding() || block != null || mode == breaking || !selectPlans.isEmpty()) && !hasSchem();
|
||||
return !player.dead() && (player.unit().isBuilding() || block != null || mode == breaking || !selectPlans.isEmpty()) && !hasSchem();
|
||||
}
|
||||
|
||||
boolean hasSchem(){
|
||||
@@ -277,7 +280,9 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
t.visible(this::showCancel);
|
||||
t.bottom().left();
|
||||
t.button("@cancel", Icon.cancel, () -> {
|
||||
player.unit().clearBuilding();
|
||||
if(!player.dead()){
|
||||
player.unit().clearBuilding();
|
||||
}
|
||||
selectPlans.clear();
|
||||
mode = none;
|
||||
block = null;
|
||||
@@ -864,7 +869,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}
|
||||
}
|
||||
|
||||
if(player.shooting && (player.unit().activelyBuilding() || player.unit().mining())){
|
||||
if(player.shooting && !player.dead() && (player.unit().activelyBuilding() || player.unit().mining())){
|
||||
player.shooting = false;
|
||||
}
|
||||
}
|
||||
@@ -1037,7 +1042,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
unit.movePref(movement);
|
||||
|
||||
//update shooting if not building + not mining
|
||||
if(!player.unit().activelyBuilding() && player.unit().mineTile == null){
|
||||
if(!unit.activelyBuilding() && unit.mineTile == null){
|
||||
|
||||
//autofire targeting
|
||||
if(manualShooting){
|
||||
@@ -1046,7 +1051,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
||||
}else if(target == null){
|
||||
player.shooting = false;
|
||||
if(Core.settings.getBool("autotarget") && !(player.unit() instanceof BlockUnitUnit u && u.tile() instanceof ControlBlock c && !c.shouldAutoTarget())){
|
||||
if(player.unit().type.canAttack){
|
||||
if(unit.type.canAttack){
|
||||
target = Units.closestTarget(unit.team, unit.x, unit.y, range, u -> u.checkTarget(type.targetAir, type.targetGround), u -> type.targetGround);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user