Commit 934fb587 authored by liizfq's avatar liizfq Committed by GitHub
Browse files

add new command (unlimitenergy):toggle energyusage for each player (#1186)

* add new command (unlimitenergy):toggle energyusage for each player while  energyusage is ture in config.json

* Solve the problem of layout and naming errors

* make currentActiveTeam's Avatar full-energy while turn on the ule.

* Resolve language document errors

* add config_error message while player try to execute UnlimitEnergyCommand in GAME_OPTIONS.energyUsage == false
parent fa2ab598
package emu.grasscutter.command.commands;
import emu.grasscutter.Grasscutter;
import emu.grasscutter.command.Command;
import emu.grasscutter.command.CommandHandler;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar;
import emu.grasscutter.game.managers.EnergyManager.EnergyManager;
import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.player.TeamManager;
import emu.grasscutter.game.props.ElementType;
import emu.grasscutter.net.proto.PropChangeReasonOuterClass;
import emu.grasscutter.utils.Position;
import java.util.List;
import static emu.grasscutter.Configuration.GAME_OPTIONS;
import static emu.grasscutter.utils.Language.translate;
@Command(label = "unlimitenergy", usage = "unlimitenergy [on|off|toggle]", aliases = {"ule"}, permission = "player.unlimitenergy", permissionTargeted = "player.unlimitenergy.others", description = "commands.unlimitenergy.description")
public final class UnlimitEnergyCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if(!GAME_OPTIONS.energyUsage){
CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.config_error"));
return;
}
Boolean status = targetPlayer.getEnergyManager().getEnergyUsage();
if (args.size() == 1) {
switch (args.get(0).toLowerCase()) {
case "on":
status = true;
break;
case "off":
status = false;
break;
default:
status = !status;
break;
}
}
EnergyManager energyManager=targetPlayer.getEnergyManager();
energyManager.setEnergyUsage(!status);
// if unlimitEnergy is enable , make currentActiveTeam's Avatar full-energy
if (status) {
for (EntityAvatar entityAvatar : targetPlayer.getTeamManager().getActiveTeam()) {
entityAvatar.addEnergy(1000,
PropChangeReasonOuterClass.PropChangeReason.PROP_CHANGE_REASON_GM,true);
}
}
CommandHandler.sendMessage(sender, translate(sender, "commands.unlimitenergy.success", (status ? translate(sender, "commands.status.enabled") : translate(sender, "commands.status.disabled")), targetPlayer.getNickname()));
}
}
...@@ -48,13 +48,15 @@ import com.google.protobuf.InvalidProtocolBufferException; ...@@ -48,13 +48,15 @@ import com.google.protobuf.InvalidProtocolBufferException;
public class EnergyManager { public class EnergyManager {
private final Player player; private final Player player;
private final Map<EntityAvatar, Integer> avatarNormalProbabilities; private final Map<EntityAvatar, Integer> avatarNormalProbabilities;
// energyUsage for each player
private Boolean energyUsage;
private final static Int2ObjectMap<List<EnergyDropInfo>> energyDropData = new Int2ObjectOpenHashMap<>(); private final static Int2ObjectMap<List<EnergyDropInfo>> energyDropData = new Int2ObjectOpenHashMap<>();
private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>(); private final static Int2ObjectMap<List<SkillParticleGenerationInfo>> skillParticleGenerationData = new Int2ObjectOpenHashMap<>();
public EnergyManager(Player player) { public EnergyManager(Player player) {
this.player = player; this.player = player;
this.avatarNormalProbabilities = new HashMap<>(); this.avatarNormalProbabilities = new HashMap<>();
this.energyUsage=GAME_OPTIONS.energyUsage;
} }
public Player getPlayer() { public Player getPlayer() {
...@@ -326,7 +328,7 @@ public class EnergyManager { ...@@ -326,7 +328,7 @@ public class EnergyManager {
**********/ **********/
private void handleBurstCast(Avatar avatar, int skillId) { private void handleBurstCast(Avatar avatar, int skillId) {
// Don't do anything if energy usage is disabled. // Don't do anything if energy usage is disabled.
if (!GAME_OPTIONS.energyUsage) { if (!GAME_OPTIONS.energyUsage || !this.energyUsage) {
return; return;
} }
...@@ -436,4 +438,12 @@ public class EnergyManager { ...@@ -436,4 +438,12 @@ public class EnergyManager {
.filter(character -> character.getId() == avatarEntityId) .filter(character -> character.getId() == avatarEntityId)
.findFirst(); .findFirst();
} }
public Boolean getEnergyUsage() {
return energyUsage;
}
public void setEnergyUsage(Boolean energyUsage) {
this.energyUsage = energyUsage;
}
} }
\ No newline at end of file
...@@ -184,6 +184,12 @@ ...@@ -184,6 +184,12 @@
"success": "NoStamina is now %s for %s.", "success": "NoStamina is now %s for %s.",
"description": "Keep your endurance to the maximum." "description": "Keep your endurance to the maximum."
}, },
"unlimitenergy": {
"usage": "unlimitenergy [targetUID] [on | off | toggle ]",
"success": "unlimitenergy is now %s for %s.",
"description": "Use the element does not waste energy in unlimitenergy on",
"config_error": "Command is disable,because energyUsage is false in config.json."
},
"heal": { "heal": {
"success": "All characters have been healed.", "success": "All characters have been healed.",
"description": "Heal all characters in your current team." "description": "Heal all characters in your current team."
......
...@@ -157,6 +157,12 @@ ...@@ -157,6 +157,12 @@
"success": "NoStamina 已设为 %s。[用户:%s]", "success": "NoStamina 已设为 %s。[用户:%s]",
"description": "保持你的体力处于最高状态" "description": "保持你的体力处于最高状态"
}, },
"unlimitenergy": {
"usage": "用法:unlimitenergy [目标玩家] [on | off | toggle ]",
"success": "unlimitEnergy 已设为 %s。[用户:%s]",
"description": "使用元素爆发不消耗能量",
"config_error": "当前命令不可用,需要在config.json中配置 energyUsage : true 才可生效"
},
"giveArtifact": { "giveArtifact": {
"usage": "用法:giveart|gart [玩家] <圣遗物ID> <主词条ID> [<副词条ID>[,<强化次数>]]... [等级]", "usage": "用法:giveart|gart [玩家] <圣遗物ID> <主词条ID> [<副词条ID>[,<强化次数>]]... [等级]",
"id_error": "无效的圣遗物ID。", "id_error": "无效的圣遗物ID。",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment