Added logic payEnter command

This commit is contained in:
Anuken 2021-10-13 10:18:34 -04:00
parent 1a839bce86
commit 4a4b336814
8 changed files with 48 additions and 25 deletions

View File

@ -1765,6 +1765,7 @@ lenum.itemdrop = Drop an item.
lenum.itemtake = Take an item from a building.
lenum.paydrop = Drop current payload.
lenum.paytake = Pick up payload at current location.
lenum.payenter = Enter/land on the payload block the unit is on.
lenum.flag = Numeric unit flag.
lenum.mine = Mine at a position.
lenum.build = Build a structure.

View File

@ -404,25 +404,27 @@ abstract class BuildingComp implements Posc, Teamc, Healthc, Buildingc, Timerc,
//region handler methods
/** @return whether the player can select (but not actually control) this building. */
public boolean canControlSelect(Player player){
public boolean canControlSelect(Unit player){
return false;
}
/** Called when a player control-selects this building - not called for ControlBlock subclasses. */
public void onControlSelect(Player player){
public void onControlSelect(Unit player){
}
public void acceptPlayerPayload(Player player, Cons<Payload> grabber){
public void handleUnitPayload(Unit player, Cons<Payload> grabber){
Fx.spawn.at(player);
var unit = player.unit();
player.clearUnit();
//player.deathTimer = Player.deathDelay + 1f; //for instant respawn
unit.remove();
grabber.get(new UnitPayload(unit));
Fx.unitDrop.at(unit);
if(player.isPlayer()){
player.getPlayer().clearUnit();
}
player.remove();
grabber.get(new UnitPayload(player));
Fx.unitDrop.at(player);
if(Vars.net.client()){
Vars.netClient.clearRemovedEntity(unit.id);
Vars.netClient.clearRemovedEntity(player.id);
}
}

View File

@ -367,8 +367,18 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
throw new ValidateException(player, "Player cannot control a building.");
}
if(player.team() == build.team && build.canControlSelect(player)){
build.onControlSelect(player);
if(player.team() == build.team && build.canControlSelect(player.unit())){
build.onControlSelect(player.unit());
}
}
@Remote(called = Loc.server)
public static void unitBuildingControlSelect(Unit unit, Building build){
if(unit == null || unit.dead()) return;
//client skips checks to prevent ghost units
if(unit.team() == build.team && (net.client() || build.canControlSelect(unit))){
build.onControlSelect(unit);
}
}
@ -1112,7 +1122,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public @Nullable Building selectedControlBuild(){
Building build = world.buildWorld(Core.input.mouseWorld().x, Core.input.mouseWorld().y);
if(build != null && !player.dead() && build.canControlSelect(player) && build.team == player.team()){
if(build != null && !player.dead() && build.canControlSelect(player.unit()) && build.team == player.team()){
return build;
}
return null;

View File

@ -448,6 +448,12 @@ public class LExecutor{
ai.payTimer = LogicAI.transferDelay;
}
}
case payEnter -> {
Building build = world.buildWorld(unit.x, unit.y);
if(build != null && unit.team() == build.team && build.canControlSelect(unit)){
Call.unitBuildingControlSelect(unit, build);
}
}
case build -> {
if(state.rules.logicUnitBuild && unit.canBuild() && exec.obj(p3) instanceof Block block && block.canBeBuilt()){
int x = World.toTile(x1 - block.offset/tilesize), y = World.toTile(y1 - block.offset/tilesize);

View File

@ -13,6 +13,7 @@ public enum LUnitControl{
itemTake("from", "item", "amount"),
payDrop,
payTake("takeUnits"),
payEnter,
mine("x", "y"),
flag("value"),
build("x", "y", "block", "rotation", "config"),

View File

@ -74,13 +74,13 @@ public class PayloadConveyor extends Block{
public int step = -1, stepAccepted = -1;
@Override
public boolean canControlSelect(Player player){
return this.item == null && !player.unit().spawnedByCore && player.unit().hitSize / tilesize <= payloadLimit && player.tileOn() != null && player.tileOn().build == this;
public boolean canControlSelect(Unit player){
return this.item == null && !player.spawnedByCore && player.hitSize / tilesize <= payloadLimit && player.tileOn() != null && player.tileOn().build == this;
}
@Override
public void onControlSelect(Player player){
acceptPlayerPayload(player, p -> item = p);
public void onControlSelect(Unit player){
handleUnitPayload(player, p -> item = p);
}
@Override

View File

@ -78,16 +78,16 @@ public class PayloadBlock extends Block{
}
@Override
public boolean canControlSelect(Player player){
return !player.unit().spawnedByCore && this.payload == null && acceptUnitPayload(player.unit()) && player.tileOn() != null && player.tileOn().build == this;
public boolean canControlSelect(Unit player){
return !player.spawnedByCore && this.payload == null && acceptUnitPayload(player) && player.tileOn() != null && player.tileOn().build == this;
}
@Override
public void onControlSelect(Player player){
public void onControlSelect(Unit player){
float x = player.x, y = player.y;
acceptPlayerPayload(player, p -> payload = (T)p);
handleUnitPayload(player, p -> payload = (T)p);
this.payVector.set(x, y).sub(this).clamp(-size * tilesize / 2f, -size * tilesize / 2f, size * tilesize / 2f, size * tilesize / 2f);
this.payRotation = player.unit().rotation;
this.payRotation = player.rotation;
}
@Override

View File

@ -242,12 +242,15 @@ public class CoreBlock extends StorageBlock{
}
@Override
public boolean canControlSelect(Player player){
return true;
public boolean canControlSelect(Unit player){
return player.isPlayer();
}
@Override
public void onControlSelect(Player player){
public void onControlSelect(Unit unit){
if(!unit.isPlayer()) return;
Player player = unit.getPlayer();
Fx.spawn.at(player);
if(net.client() && player == Vars.player){
control.input.controlledType = null;