Item deposit cooldown rule (default: 0.5 sec)

This commit is contained in:
Anuken
2024-06-30 10:28:01 -04:00
parent 400db1b1e8
commit caf0ab581d
4 changed files with 16 additions and 2 deletions

View File

@@ -47,6 +47,7 @@ abstract class PlayerComp implements UnitController, Entityc, Syncc, Timerc, Dra
transient float deathTimer; transient float deathTimer;
transient String lastText = ""; transient String lastText = "";
transient float textFadeTime; transient float textFadeTime;
transient Ratekeeper itemDepositRate = new Ratekeeper();
transient private Unit lastReadUnit = Nulls.unit; transient private Unit lastReadUnit = Nulls.unit;
transient private int wrongReadUnits; transient private int wrongReadUnits;

View File

@@ -107,6 +107,8 @@ public class Rules{
public boolean cleanupDeadTeams = true; public boolean cleanupDeadTeams = true;
/** If true, items can only be deposited in the core. */ /** If true, items can only be deposited in the core. */
public boolean onlyDepositCore = false; public boolean onlyDepositCore = false;
/** Cooldown, in seconds, of item depositing for players. */
public float itemDepositCooldown = 0.5f;
/** If true, every enemy block in the radius of the (enemy) core is destroyed upon death. Used for campaign maps. */ /** If true, every enemy block in the radius of the (enemy) core is destroyed upon death. Used for campaign maps. */
public boolean coreDestroyClear = false; public boolean coreDestroyClear = false;
/** If true, banned blocks are hidden from the build menu. */ /** If true, banned blocks are hidden from the build menu. */

View File

@@ -241,7 +241,9 @@ public class OverlayRenderer{
Draw.reset(); Draw.reset();
Building build = world.buildWorld(v.x, v.y); Building build = world.buildWorld(v.x, v.y);
if(input.canDropItem() && build != null && build.interactable(player.team()) && build.acceptStack(player.unit().item(), player.unit().stack.amount, player.unit()) > 0 && player.within(build, itemTransferRange)){ if(input.canDropItem() && build != null && build.interactable(player.team()) && build.acceptStack(player.unit().item(), player.unit().stack.amount, player.unit()) > 0 && player.within(build, itemTransferRange) &&
input.itemDepositCooldown <= 0f){
boolean invalid = (state.rules.onlyDepositCore && !(build instanceof CoreBuild)); boolean invalid = (state.rules.onlyDepositCore && !(build instanceof CoreBuild));
Lines.stroke(3f, Pal.gray); Lines.stroke(3f, Pal.gray);

View File

@@ -83,6 +83,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
public boolean overrideLineRotation; public boolean overrideLineRotation;
public int rotation; public int rotation;
public boolean droppingItem; public boolean droppingItem;
public float itemDepositCooldown;
public Group uiGroup; public Group uiGroup;
public boolean isBuilding = true, buildWasAutoPaused = false, wasShooting = false; public boolean isBuilding = true, buildWasAutoPaused = false, wasShooting = false;
public @Nullable UnitType controlledType; public @Nullable UnitType controlledType;
@@ -142,6 +143,7 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
Events.on(ResetEvent.class, e -> { Events.on(ResetEvent.class, e -> {
logicCutscene = false; logicCutscene = false;
itemDepositCooldown = 0f;
Arrays.fill(controlGroups, null); Arrays.fill(controlGroups, null);
}); });
} }
@@ -423,6 +425,9 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(player == null || build == null || !player.within(build, itemTransferRange) || build.items == null || player.dead() || (state.rules.onlyDepositCore && !(build instanceof CoreBuild))) return; if(player == null || build == null || !player.within(build, itemTransferRange) || build.items == null || player.dead() || (state.rules.onlyDepositCore && !(build instanceof CoreBuild))) return;
if(net.server() && (player.unit().stack.amount <= 0 || !Units.canInteract(player, build) || if(net.server() && (player.unit().stack.amount <= 0 || !Units.canInteract(player, build) ||
//to avoid rejecting deposit packets that happen to overlap due to packet speed differences, the actual cap is double the cooldown with 2 deposits.
(!player.isLocal() && !player.itemDepositRate.allow((long)(state.rules.itemDepositCooldown * 1000 * 2), 2)) ||
!netServer.admins.allowAction(player, ActionType.depositItem, build.tile, action -> { !netServer.admins.allowAction(player, ActionType.depositItem, build.tile, action -> {
action.itemAmount = player.unit().stack.amount; action.itemAmount = player.unit().stack.amount;
action.item = player.unit().item(); action.item = player.unit().item();
@@ -796,6 +801,8 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
logicCutsceneZoom = -1f; logicCutsceneZoom = -1f;
} }
itemDepositCooldown -= Time.delta / 60f;
commandBuildings.removeAll(b -> !b.isValid()); commandBuildings.removeAll(b -> !b.isValid());
if(!commandMode){ if(!commandMode){
@@ -1859,8 +1866,10 @@ public abstract class InputHandler implements InputProcessor, GestureListener{
if(build != null && build.acceptStack(stack.item, stack.amount, player.unit()) > 0 && build.interactable(player.team()) && 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))){
if(!(state.rules.onlyDepositCore && !(build instanceof CoreBuild)) && itemDepositCooldown <= 0f){
Call.transferInventory(player, build); Call.transferInventory(player, build);
itemDepositCooldown = state.rules.itemDepositCooldown;
} }
}else{ }else{
Call.dropItem(player.angleTo(x, y)); Call.dropItem(player.angleTo(x, y));