Fixed #3078 + action listeners for player control events
This commit is contained in:
@@ -1770,6 +1770,7 @@ public class UnitTypes implements ContentList{
|
|||||||
health = 1;
|
health = 1;
|
||||||
rotateSpeed = 360f;
|
rotateSpeed = 360f;
|
||||||
itemCapacity = 0;
|
itemCapacity = 0;
|
||||||
|
commandLimit = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -114,13 +114,14 @@ abstract class StatusComp implements Posc, Flyingc{
|
|||||||
StatusEntry entry = statuses.get(index++);
|
StatusEntry entry = statuses.get(index++);
|
||||||
|
|
||||||
entry.time = Math.max(entry.time - Time.delta, 0);
|
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);
|
Pools.free(entry);
|
||||||
index --;
|
index --;
|
||||||
statuses.remove(index);
|
statuses.remove(index);
|
||||||
}else{
|
}else{
|
||||||
|
applied.set(entry.effect.id);
|
||||||
|
|
||||||
speedMultiplier *= entry.effect.speedMultiplier;
|
speedMultiplier *= entry.effect.speedMultiplier;
|
||||||
healthMultiplier *= entry.effect.healthMultiplier;
|
healthMultiplier *= entry.effect.healthMultiplier;
|
||||||
damageMultiplier *= entry.effect.damageMultiplier;
|
damageMultiplier *= entry.effect.damageMultiplier;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public class Objectives{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean complete(){
|
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
|
@Override
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
|
|
||||||
if(isPlacing() && mode == placing){
|
if(isPlacing() && mode == placing){
|
||||||
updateLine(selectX, selectY);
|
updateLine(selectX, selectY);
|
||||||
}else if(!selectRequests.isEmpty()){
|
}else if(!selectRequests.isEmpty() && !ui.chatfrag.shown()){
|
||||||
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate)));
|
rotateRequests(selectRequests, Mathf.sign(Core.input.axisTap(Binding.rotate)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -660,7 +660,7 @@ public class DesktopInput extends InputHandler{
|
|||||||
}
|
}
|
||||||
|
|
||||||
//update commander unit
|
//update commander unit
|
||||||
if(Core.input.keyTap(Binding.command)){
|
if(Core.input.keyTap(Binding.command) && unit.type.commandLimit > 0){
|
||||||
Call.unitCommand(player);
|
Call.unitCommand(player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -336,6 +336,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
public static void unitControl(Player player, @Nullable Unit unit){
|
public static void unitControl(Player player, @Nullable Unit unit){
|
||||||
if(player == null) return;
|
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
|
//clear player unit when they possess a core
|
||||||
if((unit instanceof BlockUnitc && ((BlockUnitc)unit).tile() instanceof CoreBuild)){
|
if((unit instanceof BlockUnitc && ((BlockUnitc)unit).tile() instanceof CoreBuild)){
|
||||||
Fx.spawn.at(player);
|
Fx.spawn.at(player);
|
||||||
@@ -376,6 +381,11 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
|
|||||||
public static void unitCommand(Player player){
|
public static void unitCommand(Player player){
|
||||||
if(player == null || player.dead() || !(player.unit() instanceof Commanderc commander)) return;
|
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()){
|
if(commander.isCommanding()){
|
||||||
commander.clearCommand();
|
commander.clearCommand();
|
||||||
}else if(player.unit().type.commandLimit > 0){
|
}else if(player.unit().type.commandLimit > 0){
|
||||||
|
|||||||
@@ -613,7 +613,7 @@ public class MobileInput extends InputHandler implements GestureListener{
|
|||||||
//reset payload target
|
//reset payload target
|
||||||
payloadTarget = null;
|
payloadTarget = null;
|
||||||
//apply command on double tap when own unit is tapped
|
//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);
|
Call.unitCommand(player);
|
||||||
}else{
|
}else{
|
||||||
//control a unit/block
|
//control a unit/block
|
||||||
|
|||||||
@@ -142,11 +142,18 @@ public class Administration{
|
|||||||
|
|
||||||
/** @return whether this action is allowed by the action filters. */
|
/** @return whether this action is allowed by the action filters. */
|
||||||
public boolean allowAction(Player player, ActionType type, Tile tile, Cons<PlayerAction> setter){
|
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
|
//some actions are done by the server (null player) and thus are always allowed
|
||||||
if(player == null) return true;
|
if(player == null) return true;
|
||||||
|
|
||||||
PlayerAction act = Pools.obtain(PlayerAction.class, PlayerAction::new);
|
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){
|
for(ActionFilter filter : actionFilters){
|
||||||
if(!filter.allow(act)){
|
if(!filter.allow(act)){
|
||||||
Pools.free(act);
|
Pools.free(act);
|
||||||
@@ -699,7 +706,7 @@ public class Administration{
|
|||||||
public static class PlayerAction implements Poolable{
|
public static class PlayerAction implements Poolable{
|
||||||
public Player player;
|
public Player player;
|
||||||
public ActionType type;
|
public ActionType type;
|
||||||
public Tile tile;
|
public @Nullable Tile tile;
|
||||||
|
|
||||||
/** valid for block placement events only */
|
/** valid for block placement events only */
|
||||||
public @Nullable Block block;
|
public @Nullable Block block;
|
||||||
@@ -712,6 +719,9 @@ public class Administration{
|
|||||||
public @Nullable Item item;
|
public @Nullable Item item;
|
||||||
public int itemAmount;
|
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){
|
public PlayerAction set(Player player, ActionType type, Tile tile){
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
@@ -719,6 +729,13 @@ public class Administration{
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayerAction set(Player player, ActionType type, Unit unit){
|
||||||
|
this.player = player;
|
||||||
|
this.type = type;
|
||||||
|
this.unit = unit;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset(){
|
public void reset(){
|
||||||
item = null;
|
item = null;
|
||||||
@@ -728,11 +745,12 @@ public class Administration{
|
|||||||
type = null;
|
type = null;
|
||||||
tile = null;
|
tile = null;
|
||||||
block = null;
|
block = null;
|
||||||
|
unit = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ActionType{
|
public enum ActionType{
|
||||||
breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem
|
breakBlock, placeBlock, rotate, configure, withdrawItem, depositItem, control, command
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user