Fixed #3078 + action listeners for player control events

This commit is contained in:
Anuken
2020-10-23 15:59:12 -04:00
parent 5512c1817d
commit c8ef7ebafb
7 changed files with 39 additions and 9 deletions

View File

@@ -1770,6 +1770,7 @@ public class UnitTypes implements ContentList{
health = 1;
rotateSpeed = 360f;
itemCapacity = 0;
commandLimit = 0;
}
@Override

View File

@@ -114,13 +114,14 @@ abstract class StatusComp implements Posc, Flyingc{
StatusEntry entry = statuses.get(index++);
entry.time = Math.max(entry.time - Time.delta, 0);
applied.set(entry.effect.id);
if(entry.time <= 0 && !entry.effect.permanent){
if(entry.effect == null || (entry.time <= 0 && !entry.effect.permanent)){
Pools.free(entry);
index --;
statuses.remove(index);
}else{
applied.set(entry.effect.id);
speedMultiplier *= entry.effect.speedMultiplier;
healthMultiplier *= entry.effect.healthMultiplier;
damageMultiplier *= entry.effect.damageMultiplier;

View File

@@ -38,7 +38,7 @@ public class Objectives{
@Override
public boolean complete(){
return preset.sector.save != null && preset.sector.save.meta.wave >= preset.captureWave;
return preset.sector.save != null && !preset.sector.isAttacked() && preset.sector.hasBase();
}
@Override

View File

@@ -279,7 +279,7 @@ public class DesktopInput extends InputHandler{
if(isPlacing() && mode == placing){
updateLine(selectX, selectY);
}else if(!selectRequests.isEmpty()){
}else if(!selectRequests.isEmpty() && !ui.chatfrag.shown()){
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate)));
}
}
@@ -660,7 +660,7 @@ public class DesktopInput extends InputHandler{
}
//update commander unit
if(Core.input.keyTap(Binding.command)){
if(Core.input.keyTap(Binding.command) && unit.type.commandLimit > 0){
Call.unitCommand(player);
}
}

View File

@@ -336,6 +336,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public static void unitControl(Player player, @Nullable Unit unit){
if(player == null) return;
//make sure player is allowed to control the unit
if(net.server() && !netServer.admins.allowAction(player, ActionType.control, action -> action.unit = unit)){
throw new ValidateException(player, "Player cannot control a unit.");
}
//clear player unit when they possess a core
if((unit instanceof BlockUnitc && ((BlockUnitc)unit).tile() instanceof CoreBuild)){
Fx.spawn.at(player);
@@ -376,6 +381,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public static void unitCommand(Player player){
if(player == null || player.dead() || !(player.unit() instanceof Commanderc commander)) return;
//make sure player is allowed to make the command
if(net.server() && !netServer.admins.allowAction(player, ActionType.command, action -> {})){
throw new ValidateException(player, "Player cannot command a unit.");
}
if(commander.isCommanding()){
commander.clearCommand();
}else if(player.unit().type.commandLimit > 0){

View File

@@ -613,7 +613,7 @@ public class MobileInput extends InputHandler implements GestureListener{
//reset payload target
payloadTarget = null;
//apply command on double tap when own unit is tapped
if(Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize * 0.6f + 8f)){
if(!player.dead() && Mathf.within(worldx, worldy, player.unit().x, player.unit().y, player.unit().hitSize * 0.6f + 8f) && player.unit().type.commandLimit > 0){
Call.unitCommand(player);
}else{
//control a unit/block

View File

@@ -142,11 +142,18 @@ public class Administration{
/** @return whether this action is allowed by the action filters. */
public boolean allowAction(Player player, ActionType type, Tile tile, Cons<PlayerAction> setter){
return allowAction(player, type, action -> setter.get(action.set(player, type, tile)));
}
/** @return whether this action is allowed by the action filters. */
public boolean allowAction(Player player, ActionType type, Cons<PlayerAction> setter){
//some actions are done by the server (null player) and thus are always allowed
if(player == null) return true;
PlayerAction act = Pools.obtain(PlayerAction.class, PlayerAction::new);
setter.get(act.set(player, type, tile));
act.player = player;
act.type = type;
setter.get(act);
for(ActionFilter filter : actionFilters){
if(!filter.allow(act)){
Pools.free(act);
@@ -699,7 +706,7 @@ public class Administration{
public static class PlayerAction implements Poolable{
public Player player;
public ActionType type;
public Tile tile;
public @Nullable Tile tile;
/** valid for block placement events only */
public @Nullable Block block;
@@ -712,6 +719,9 @@ public class Administration{
public @Nullable Item item;
public int itemAmount;
/** valid for unit-type events only, and even in that case may be null. */
public @Nullable Unit unit;
public PlayerAction set(Player player, ActionType type, Tile tile){
this.player = player;
this.type = type;
@@ -719,6 +729,13 @@ public class Administration{
return this;
}
public PlayerAction set(Player player, ActionType type, Unit unit){
this.player = player;
this.type = type;
this.unit = unit;
return this;
}
@Override
public void reset(){
item = null;
@@ -728,11 +745,12 @@ public class Administration{
type = null;
tile = null;
block = null;
unit = null;
}
}
public enum ActionType{
breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem
breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem, control, command
}
}