Commit d8b2e787 authored by AnimeGitB's avatar AnimeGitB Committed by Melledy
Browse files

Commands Targeting rework

parent 5aba7da7
...@@ -7,30 +7,23 @@ import emu.grasscutter.game.player.Player; ...@@ -7,30 +7,23 @@ import emu.grasscutter.game.player.Player;
import java.util.List; import java.util.List;
@Command(label = "say", usage = "say <player> <message>", description = "Sends a message to a player as the server", @Command(label = "say", usage = "say <message>", description = "Sends a message to a player as the server",
aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage") aliases = {"sendservmsg", "sendservermessage", "sendmessage"}, permission = "server.sendmessage")
public final class SendMessageCommand implements CommandHandler { public final class SendMessageCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (args.size() < 2) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return;
}
if (args.size() == 0) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage); CommandHandler.sendMessage(null, Grasscutter.getLanguage().SendMessage_usage);
return; return;
} }
try { String message = String.join(" ", args);
int target = Integer.parseInt(args.get(0)); CommandHandler.sendMessage(targetPlayer, message);
String message = String.join(" ", args.subList(1, args.size())); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SenaMessage_message_sent);
if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found);
return;
}
CommandHandler.sendMessage(targetPlayer, message);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SenaMessage_message_sent);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
}
} }
} }
\ No newline at end of file
...@@ -17,12 +17,12 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -17,12 +17,12 @@ public final class SetFetterLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
if (args.size() < 1) { if (args.size() != 1) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_usage);
return; return;
} }
...@@ -33,7 +33,7 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -33,7 +33,7 @@ public final class SetFetterLevelCommand implements CommandHandler {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_level_must_between_0_and_10); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_level_must_between_0_and_10);
return; return;
} }
Avatar avatar = sender.getTeamManager().getCurrentAvatarEntity().getAvatar(); Avatar avatar = targetPlayer.getTeamManager().getCurrentAvatarEntity().getAvatar();
avatar.setFetterLevel(fetterLevel); avatar.setFetterLevel(fetterLevel);
if (fetterLevel != 10) { if (fetterLevel != 10) {
...@@ -41,7 +41,7 @@ public final class SetFetterLevelCommand implements CommandHandler { ...@@ -41,7 +41,7 @@ public final class SetFetterLevelCommand implements CommandHandler {
} }
avatar.save(); avatar.save();
sender.sendPacket(new PacketAvatarFetterDataNotify(avatar)); targetPlayer.sendPacket(new PacketAvatarFetterDataNotify(avatar));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_set_level.replace("{level}", Integer.toString(fetterLevel))); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_fetter_set_level.replace("{level}", Integer.toString(fetterLevel)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_invalid_fetter_level); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().SetFetterLevel_invalid_fetter_level);
......
...@@ -13,7 +13,7 @@ import emu.grasscutter.game.props.FightProperty; ...@@ -13,7 +13,7 @@ import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.languages.Language; import emu.grasscutter.languages.Language;
import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify; import emu.grasscutter.server.packet.send.PacketEntityFightPropUpdateNotify;
@Command(label = "setstats", usage = "setstats|stats [@UID] <stat> <value>", @Command(label = "setstats", usage = "setstats|stats <stat> <value>",
description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats") description = "Set fight property for your current active character", aliases = {"stats"}, permission = "player.setstats")
public final class SetStatsCommand implements CommandHandler { public final class SetStatsCommand implements CommandHandler {
class Stat { class Stat {
...@@ -182,7 +182,7 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -182,7 +182,7 @@ public final class SetStatsCommand implements CommandHandler {
String valueStr; String valueStr;
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, usage); CommandHandler.sendMessage(sender, lang.Target_needed);
return; return;
} }
...@@ -209,8 +209,6 @@ public final class SetStatsCommand implements CommandHandler { ...@@ -209,8 +209,6 @@ public final class SetStatsCommand implements CommandHandler {
CommandHandler.sendMessage(sender, lang.SetStats_value_error); CommandHandler.sendMessage(sender, lang.SetStats_value_error);
return; return;
} }
if (stats.containsKey(statStr)) { if (stats.containsKey(statStr)) {
Stat stat = stats.get(statStr); Stat stat = stats.get(statStr);
......
...@@ -14,9 +14,9 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -14,9 +14,9 @@ public final class SetWorldLevelCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; // TODO: set player's world level from console or other players return;
} }
if (args.size() < 1) { if (args.size() < 1) {
...@@ -32,8 +32,8 @@ public final class SetWorldLevelCommand implements CommandHandler { ...@@ -32,8 +32,8 @@ public final class SetWorldLevelCommand implements CommandHandler {
} }
// Set in both world and player props // Set in both world and player props
sender.getWorld().setWorldLevel(level); targetPlayer.getWorld().setWorldLevel(level);
sender.setWorldLevel(level); targetPlayer.setWorldLevel(level);
sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_set_world_level.replace("{level}", Integer.toString(level))); sender.dropMessage(Grasscutter.getLanguage().SetWorldLevel_set_world_level.replace("{level}", Integer.toString(level)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
......
...@@ -14,6 +14,7 @@ import emu.grasscutter.game.player.Player; ...@@ -14,6 +14,7 @@ import emu.grasscutter.game.player.Player;
import emu.grasscutter.game.props.EntityType; import emu.grasscutter.game.props.EntityType;
import emu.grasscutter.game.props.FightProperty; import emu.grasscutter.game.props.FightProperty;
import emu.grasscutter.utils.Position; import emu.grasscutter.utils.Position;
import emu.grasscutter.game.world.Scene;
import javax.swing.text.html.parser.Entity; import javax.swing.text.html.parser.Entity;
import java.util.List; import java.util.List;
...@@ -25,64 +26,80 @@ public final class SpawnCommand implements CommandHandler { ...@@ -25,64 +26,80 @@ public final class SpawnCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
if (args.size() < 1) { int id = 0; // This is just to shut up the linter, it's not a real default
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage); int amount = 1;
return; int level = 1;
switch (args.size()) {
case 3:
try {
level = Integer.parseInt(args.get(2));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
} // Fallthrough
case 2:
try {
amount = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_amount);
} // Fallthrough
case 1:
try {
id = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_usage);
return;
} }
try { MonsterData monsterData = GameData.getMonsterDataMap().get(id);
int id = Integer.parseInt(args.get(0)); GadgetData gadgetData = GameData.getGadgetDataMap().get(id);
int amount = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1; ItemData itemData = GameData.getItemDataMap().get(id);
int level = args.size() > 2 ? Integer.parseInt(args.get(2)) : 1; if (monsterData == null && gadgetData == null && itemData == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id);
return;
}
Scene scene = targetPlayer.getScene();
MonsterData monsterData = GameData.getMonsterDataMap().get(id); double maxRadius = Math.sqrt(amount * 0.2 / Math.PI);
GadgetData gadgetData = GameData.getGadgetDataMap().get(id); for (int i = 0; i < amount; i++) {
ItemData itemData = GameData.getItemDataMap().get(id); Position pos = GetRandomPositionInCircle(targetPlayer.getPos(), maxRadius).addY(3);
if (monsterData == null && gadgetData == null && itemData == null) { GameEntity entity = null;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id); if (itemData != null) {
return; entity = new EntityItem(scene, null, itemData, pos, 1, true);
} }
if (gadgetData != null) {
double maxRadius = Math.sqrt(amount * 0.2 / Math.PI); entity = new EntityVehicle(scene, targetPlayer.getSession().getPlayer(), gadgetData.getId(), 0, pos, targetPlayer.getRotation()); // TODO: does targetPlayer.getSession().getPlayer() have some meaning?
for (int i = 0; i < amount; i++) { int gadgetId = gadgetData.getId();
Position pos = GetRandomPositionInCircle(sender.getPos(), maxRadius).addY(3); switch (gadgetId) {
GameEntity entity = null; // TODO: Not hardcode this. Waverider (skiff)
if (itemData != null) { case 45001001, 45001002 -> {
entity = new EntityItem(sender.getScene(), null, itemData, pos, 1, true); entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
} entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
if (gadgetData != null) { entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
entity = new EntityVehicle(sender.getScene(), sender.getSession().getPlayer(), gadgetData.getId(), 0, pos, sender.getRotation()); entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
int gadgetId = gadgetData.getId(); entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
switch (gadgetId) { entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
// TODO: Not hardcode this. Waverider (skiff) entity.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
case 45001001, 45001002 -> { entity.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_BASE_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_ATTACK, 100);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_HP, 10000);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_DEFENSE, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CUR_SPEED, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_CHARGE_EFFICIENCY, 0);
entity.addFightProperty(FightProperty.FIGHT_PROP_MAX_HP, 10000);
}
default -> {}
} }
default -> {}
} }
if (monsterData != null) {
entity = new EntityMonster(sender.getScene(), monsterData, pos, level);
}
sender.getScene().addEntity(entity);
} }
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_message.replace("{amount}", Integer.toString(amount)).replace("{id}", Integer.toString(id))); if (monsterData != null) {
} catch (NumberFormatException ignored) { entity = new EntityMonster(scene, monsterData, pos, level);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_entity_id); }
scene.addEntity(entity);
} }
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Spawn_message.replace("{amount}", Integer.toString(amount)).replace("{id}", Integer.toString(id)));
} }
private Position GetRandomPositionInCircle(Position origin, double radius){ private Position GetRandomPositionInCircle(Position origin, double radius){
......
...@@ -15,11 +15,37 @@ import java.util.List; ...@@ -15,11 +15,37 @@ import java.util.List;
@Command(label = "talent", usage = "talent <talentID> <value>", @Command(label = "talent", usage = "talent <talentID> <value>",
description = "Set talent level for your current active character", permission = "player.settalent") description = "Set talent level for your current active character", permission = "player.settalent")
public final class TalentCommand implements CommandHandler { public final class TalentCommand implements CommandHandler {
private void setTalentLevel(Player sender, Player player, Avatar avatar, int talentId, int talentLevel) {
int oldLevel = avatar.getSkillLevelMap().get(talentId);
if (talentLevel < 0 || talentLevel > 15) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
// Upgrade skill
avatar.getSkillLevelMap().put(talentLevel, talentLevel);
avatar.save();
// Packet
player.sendPacket(new PacketAvatarSkillChangeNotify(avatar, talentId, oldLevel, talentLevel));
player.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, talentId, oldLevel, talentLevel));
String successMessage = Grasscutter.getLanguage().Talent_set_id.replace("{id}", Integer.toString(talentId));
AvatarSkillDepotData depot = avatar.getData().getSkillDepot();
if (talentId == depot.getSkills().get(0)) {
successMessage = Grasscutter.getLanguage().Talent_set_atk;
} else if (talentId == depot.getSkills().get(1)) {
successMessage = Grasscutter.getLanguage().Talent_set_e;
} else if (talentId == depot.getEnergySkill()) {
successMessage = Grasscutter.getLanguage().Talent_set_q;
}
CommandHandler.sendMessage(sender, successMessage.replace("{level}", Integer.toString(talentLevel)));
}
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
...@@ -30,6 +56,8 @@ public final class TalentCommand implements CommandHandler { ...@@ -30,6 +56,8 @@ public final class TalentCommand implements CommandHandler {
return; return;
} }
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity();
Avatar avatar = entity.getAvatar();
String cmdSwitch = args.get(0); String cmdSwitch = args.get(0);
switch (cmdSwitch) { switch (cmdSwitch) {
default: default:
...@@ -38,112 +66,59 @@ public final class TalentCommand implements CommandHandler { ...@@ -38,112 +66,59 @@ public final class TalentCommand implements CommandHandler {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
return; return;
case "set": case "set":
try { if (args.size() < 3){
int skillId = Integer.parseInt(args.get(1)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1);
int nextLevel = Integer.parseInt(args.get(2)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3);
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); return;
Avatar avatar = entity.getAvatar(); }
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1); try {
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill(); int skillId = Integer.parseInt(args.get(1));
int currentLevelNorAtk = avatar.getSkillLevelMap().get(skillIdNorAtk); int newLevel = Integer.parseInt(args.get(2));
int currentLevelE = avatar.getSkillLevelMap().get(skillIdE); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
int currentLevelQ = avatar.getSkillLevelMap().get(skillIdQ); } catch (NumberFormatException ignored) {
if (args.size() < 2){ CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id);
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_1); return;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_3); }
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
if (skillId == skillIdNorAtk){
// Upgrade skill
avatar.getSkillLevelMap().put(skillIdNorAtk, nextLevel);
avatar.save();
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdNorAtk, currentLevelNorAtk, nextLevel));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_atk.replace("{level}", Integer.toString(nextLevel)));
}
if (skillId == skillIdE){
// Upgrade skill
avatar.getSkillLevelMap().put(skillIdE, nextLevel);
avatar.save();
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdE, currentLevelE, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdE, currentLevelE, nextLevel));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_e.replace("{level}", Integer.toString(nextLevel)));
}
if (skillId == skillIdQ){
// Upgrade skill
avatar.getSkillLevelMap().put(skillIdQ, nextLevel);
avatar.save();
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillIdQ, currentLevelQ, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillIdQ, currentLevelQ, nextLevel));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_q.replace("{level}", Integer.toString(nextLevel)));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_skill_id);
return;
}
break; break;
case "n": case "e": case "q": case "n":
case "e":
case "q":
if (args.size() < 2){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
return;
}
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
int skillId;
switch (cmdSwitch) {
default:
skillId = SkillDepot.getSkills().get(0);
break;
case "e":
skillId = SkillDepot.getSkills().get(1);
break;
case "q":
skillId = SkillDepot.getEnergySkill();
break;
}
try { try {
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); int newLevel = Integer.parseInt(args.get(1));
Avatar avatar = entity.getAvatar(); setTalentLevel(sender, targetPlayer, avatar, skillId, newLevel);
AvatarSkillDepotData SkillDepot = avatar.getData().getSkillDepot();
int skillId;
switch (cmdSwitch) {
default:
skillId = SkillDepot.getSkills().get(0);
break;
case "e":
skillId = SkillDepot.getSkills().get(1);
break;
case "q":
skillId = SkillDepot.getEnergySkill();
break;
}
int nextLevel = Integer.parseInt(args.get(1));
int currentLevel = avatar.getSkillLevelMap().get(skillId);
if (args.size() < 1){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_usage_2);
return;
}
if (nextLevel >= 16){
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_lower_16);
return;
}
// Upgrade skill
avatar.getSkillLevelMap().put(skillId, nextLevel);
avatar.save();
// Packet
sender.sendPacket(new PacketAvatarSkillChangeNotify(avatar, skillId, currentLevel, nextLevel));
sender.sendPacket(new PacketAvatarSkillUpgradeRsp(avatar, skillId, currentLevel, nextLevel));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_set_this.replace("{level}", Integer.toString(nextLevel)));
} catch (NumberFormatException ignored) { } catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_invalid_talent_level);
return; return;
} }
break; break;
case "getid": case "getid":
EntityAvatar entity = sender.getTeamManager().getCurrentAvatarEntity(); int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0);
Avatar avatar = entity.getAvatar(); int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdNorAtk = avatar.getData().getSkillDepot().getSkills().get(0); int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
int skillIdE = avatar.getData().getSkillDepot().getSkills().get(1);
int skillIdQ = avatar.getData().getSkillDepot().getEnergySkill();
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_normal_attack_id.replace("{id}", Integer.toString(skillIdNorAtk))); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_normal_attack_id.replace("{id}", Integer.toString(skillIdNorAtk)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_e_skill_id.replace("{id}", Integer.toString(skillIdE))); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_e_skill_id.replace("{id}", Integer.toString(skillIdE)));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_q_skill_id.replace("{id}", Integer.toString(skillIdQ))); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Talent_q_skill_id.replace("{id}", Integer.toString(skillIdQ)));
break; break;
} }
} }
......
...@@ -13,22 +13,22 @@ import java.util.List; ...@@ -13,22 +13,22 @@ import java.util.List;
public final class TeleportAllCommand implements CommandHandler { public final class TeleportAllCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
if (!sender.getWorld().isMultiplayer()) { if (!targetPlayer.getWorld().isMultiplayer()) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().TeleportAll_message);
return; return;
} }
for (Player player : sender.getWorld().getPlayers()) { for (Player player : targetPlayer.getWorld().getPlayers()) {
if (player.equals(sender)) if (player.equals(targetPlayer))
continue; continue;
Position pos = sender.getPos(); Position pos = targetPlayer.getPos();
player.getWorld().transferPlayerToScene(player, sender.getSceneId(), pos); player.getWorld().transferPlayerToScene(player, targetPlayer.getSceneId(), pos);
} }
} }
} }
...@@ -8,83 +8,62 @@ import emu.grasscutter.utils.Position; ...@@ -8,83 +8,62 @@ import emu.grasscutter.utils.Position;
import java.util.List; import java.util.List;
@Command(label = "teleport", usage = "teleport [@player id] <x> <y> <z> [scene id]", aliases = {"tp"}, @Command(label = "teleport", usage = "teleport <x> <y> <z> [scene id]", aliases = {"tp"},
description = "Change the player's position.", permission = "player.teleport") description = "Change the player's position.", permission = "player.teleport")
public final class TeleportCommand implements CommandHandler { public final class TeleportCommand implements CommandHandler {
@Override private float parseRelative(String input, Float current) { // TODO: Maybe this will be useful elsewhere later
public void execute(Player sender, Player targetPlayer, List<String> args) { if (input.contains("~")) { // Relative
int target; if (!input.equals("~")) { // Relative with offset
if (args.size() < (sender == null ? 4 : 3)) { current += Float.parseFloat(input.replace("~", ""));
CommandHandler.sendMessage(sender, sender == null ? Grasscutter.getLanguage().Teleport_usage_server : } // Else no offset, no modification
Grasscutter.getLanguage().Teleport_usage); } else { // Absolute
return; current = Float.parseFloat(input);
}
if (args.get(0).startsWith("@")) {
try {
target = Integer.parseInt(args.get(0).substring(1));
} catch (NumberFormatException e) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_playerId);
return;
}
} else {
if (sender == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Teleport_specify_player_id);
return;
}
target = sender.getUid();
} }
return current;
}
@Override
public void execute(Player sender, Player targetPlayer, List<String> args) {
if (targetPlayer == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Player_not_found_or_offline); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
args = args.subList(args.get(0).startsWith("@") ? 1 : 0, args.size());
try { Position pos = targetPlayer.getPos();
float x = 0f; float x = pos.getX();
float y = 0f; float y = pos.getY();
float z = 0f; float z = pos.getZ();
if (args.get(0).contains("~")) { int sceneId = targetPlayer.getSceneId();
if (args.get(0).equals("~")) {
x = targetPlayer.getPos().getX(); switch (args.size()) {
} else { case 4:
x = Float.parseFloat(args.get(0).replace("~", "")) + targetPlayer.getPos().getX(); try {
} sceneId = Integer.parseInt(args.get(3));
} else { }catch (NumberFormatException ignored) {
x = Float.parseFloat(args.get(0)); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Invalid_arguments);
} } // Fallthrough
if (args.get(1).contains("~")) { case 3:
if (args.get(1).equals("~")) { try {
y = targetPlayer.getPos().getY(); x = parseRelative(args.get(0), x);
} else { y = parseRelative(args.get(0), y);
y = Float.parseFloat(args.get(1).replace("~", "")) + targetPlayer.getPos().getY(); z = parseRelative(args.get(0), z);
} } catch (NumberFormatException ignored) {
} else { CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
y = Float.parseFloat(args.get(1));
}
if (args.get(2).contains("~")) {
if (args.get(2).equals("~")) {
z = targetPlayer.getPos().getZ();
} else {
z = Float.parseFloat(args.get(2).replace("~", "")) + targetPlayer.getPos().getZ();
} }
} else { break;
z = Float.parseFloat(args.get(2)); default:
} CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_usage);
int sceneId = targetPlayer.getSceneId(); return;
if (args.size() == 4){ }
sceneId = Integer.parseInt(args.get(3));
} Position target_pos = new Position(x, y, z);
Position target_pos = new Position(x, y, z); boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos);
boolean result = targetPlayer.getWorld().transferPlayerToScene(targetPlayer, sceneId, target_pos); if (!result) {
if (!result) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_message.replace("{name}", targetPlayer.getNickname()).replace("{x}", Float.toString(x)).replace("{y}", Float.toString(y)).replace("{z}", Float.toString(z)).replace("{id}", Integer.toString(sceneId)));
}
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_invalid_position);
} else {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Teleport_message.replace("{name}", targetPlayer.getNickname()).replace("{x}", Float.toString(x)).replace("{y}", Float.toString(y)).replace("{z}", Float.toString(z)).replace("{id}", Integer.toString(sceneId)));
} }
} }
} }
...@@ -15,28 +15,38 @@ public final class WeatherCommand implements CommandHandler { ...@@ -15,28 +15,38 @@ public final class WeatherCommand implements CommandHandler {
@Override @Override
public void execute(Player sender, Player targetPlayer, List<String> args) { public void execute(Player sender, Player targetPlayer, List<String> args) {
if (sender == null) { if (targetPlayer == null) {
CommandHandler.sendMessage(null, Grasscutter.getLanguage().Run_this_command_in_game); CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Target_needed);
return; return;
} }
if (args.size() < 1) { int weatherId = 0;
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage); int climateId = 1;
return; switch (args.size()) {
case 2:
try {
climateId = Integer.parseInt(args.get(1));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
}
case 1:
try {
weatherId = Integer.parseInt(args.get(0));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
}
break;
default:
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_usage);
return;
} }
try { ClimateType climate = ClimateType.getTypeByValue(climateId);
int weatherId = Integer.parseInt(args.get(0));
int climateId = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1;
ClimateType climate = ClimateType.getTypeByValue(climateId); sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_message.replace("{weatherId}", Integer.toString(weatherId)).replace("{climateId}", Integer.toString(climateId)));
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, Grasscutter.getLanguage().Weather_invalid_id);
}
} }
} }
...@@ -45,21 +45,28 @@ public final class Language { ...@@ -45,21 +45,28 @@ public final class Language {
public String You_not_permission_run_command = "You do not have permission to run this command."; public String You_not_permission_run_command = "You do not have permission to run this command.";
public String This_command_can_only_run_from_console = "This command can only be run from the console."; public String This_command_can_only_run_from_console = "This command can only be run from the console.";
public String Run_this_command_in_game = "Run this command in-game."; public String Run_this_command_in_game = "Run this command in-game.";
public String Invalid_amount = "Invalid amount.";
public String Invalid_arguments = "Invalid arguments.";
public String Invalid_artifact_id = "Invalid artifact ID.";
public String Invalid_avatar_id = "Invalid avatar id.";
public String Invalid_avatar_level = "Invalid avatar level.";
public String Invalid_entity_id = "Invalid entity id.";
public String Invalid_item_id = "Invalid item id.";
public String Invalid_item_level = "Invalid item level.";
public String Invalid_item_refinement = "Invalid item refinement level.";
public String Invalid_playerId = "Invalid playerId."; public String Invalid_playerId = "Invalid playerId.";
public String Invalid_UID = "Invalid UID.";
public String Player_not_found = "Player not found."; public String Player_not_found = "Player not found.";
public String Player_is_offline = "Player is offline."; public String Player_is_offline = "Player is offline.";
public String Invalid_item_id = "Invalid item id.";
public String Invalid_item_or_player_id = "Invalid item or player ID.";
public String Enabled = "enabled"; public String Enabled = "enabled";
public String Disabled = "disabled"; public String Disabled = "disabled";
public String No_command_found = "No command found."; public String No_command_found = "No command found.";
public String Help = "Help"; public String Help = "Help";
public String Player_not_found_or_offline = "Player not found or offline."; public String Player_not_found_or_offline = "Player not found or offline.";
public String Invalid_arguments = "Invalid arguments.";
public String Success = "Success"; public String Success = "Success";
public String Invalid_entity_id = "Invalid entity id.";
public String Target_cleared = "Target cleared."; public String Target_cleared = "Target cleared.";
public String Target_set = "Subsequent commands will target @{uid} by default."; public String Target_set = "Subsequent commands will target @{uid} by default.";
public String Target_needed = "This command requires a target UID. Add a <@UID> argument or set a persistent target with /target @UID.";
// Help // Help
public String Help_usage = " Usage: "; public String Help_usage = " Usage: ";
...@@ -68,7 +75,6 @@ public final class Language { ...@@ -68,7 +75,6 @@ public final class Language {
// Account // Account
public String Modify_user_account = "Modify user accounts"; public String Modify_user_account = "Modify user accounts";
public String Invalid_UID = "Invalid UID.";
public String Account_exists = "Account already exists."; public String Account_exists = "Account already exists.";
public String Account_create_UID = "Account created with UID {uid}."; public String Account_create_UID = "Account created with UID {uid}.";
public String Account_delete = "Account deleted."; public String Account_delete = "Account deleted.";
...@@ -86,6 +92,7 @@ public final class Language { ...@@ -86,6 +92,7 @@ public final class Language {
public String Change_screen_not_exist = "Scene does not exist"; public String Change_screen_not_exist = "Scene does not exist";
// Clear // Clear
public String Clear_usage = "Usage: clear <all|wp|art|mat>";
public String Clear_weapons = "Cleared weapons for {name} ."; public String Clear_weapons = "Cleared weapons for {name} .";
public String Clear_artifacts = "Cleared artifacts for {name} ."; public String Clear_artifacts = "Cleared artifacts for {name} .";
public String Clear_materials = "Cleared materials for {name} ."; public String Clear_materials = "Cleared materials for {name} .";
...@@ -95,7 +102,8 @@ public final class Language { ...@@ -95,7 +102,8 @@ public final class Language {
public String Clear_everything = "Cleared everything for {name} ."; public String Clear_everything = "Cleared everything for {name} .";
// Coop // Coop
public String Coop_usage = "Usage: coop <playerId> <target playerId>"; public String Coop_usage = "Usage: coop <host UID>";
public String Coop_success = "Summoned {target} to {host}'s world.";
// Drop // Drop
public String Drop_usage = "Usage: drop <itemId|itemName> [amount]"; public String Drop_usage = "Usage: drop <itemId|itemName> [amount]";
...@@ -108,22 +116,17 @@ public final class Language { ...@@ -108,22 +116,17 @@ public final class Language {
public String EnterDungeon_you_in_that_dungeon = "You are already in that dungeon"; public String EnterDungeon_you_in_that_dungeon = "You are already in that dungeon";
// GiveAll // GiveAll
public String GiveAll_usage = "Usage: giveall [player] [amount]"; public String GiveAll_usage = "Usage: giveall [amount]";
public String GiveAll_item = "Giving all items..."; public String GiveAll_item = "Giving all items...";
public String GiveAll_done = "Giving all items done"; public String GiveAll_done = "Giving all items done";
public String GiveAll_invalid_amount_or_playerId = "Invalid amount or player ID.";
// GiveArtifact // GiveArtifact
public String GiveArtifact_usage = "Usage: giveart|gart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]"; public String GiveArtifact_usage = "Usage: giveart|gart [player] <artifactId> <mainPropId> [<appendPropId>[,<times>]]... [level]";
public String GiveArtifact_invalid_artifact_id = "Invalid artifact ID.";
public String GiveArtifact_given = "Given {itemId} to {target}."; public String GiveArtifact_given = "Given {itemId} to {target}.";
// GiveChar // GiveChar
public String GiveChar_usage = "Usage: givechar <player> <itemId|itemName> [amount]"; public String GiveChar_usage = "Usage: givechar <player> <itemId|itemName> [amount]";
public String GiveChar_given = "Given {avatarId} with level {level} to {target}."; public String GiveChar_given = "Given {avatarId} with level {level} to {target}.";
public String GiveChar_invalid_avatar_id = "Invalid avatar id.";
public String GiveChar_invalid_avatar_level = "Invalid avatar level.";
public String GiveChar_invalid_avatar_or_player_id = "Invalid avatar or player ID.";
// Give // Give
public String Give_usage = "Usage: give <player> <itemId|itemName> [amount] [level]"; public String Give_usage = "Usage: give <player> <itemId|itemName> [amount] [level]";
...@@ -134,7 +137,8 @@ public final class Language { ...@@ -134,7 +137,8 @@ public final class Language {
public String Give_given_level = "Given {item} with level {lvl} {amount} times to {target}"; public String Give_given_level = "Given {item} with level {lvl} {amount} times to {target}";
// GodMode // GodMode
public String Godmode_status = "Godmode is now {status} for {name} ."; public String Godmode_usage = "Usage: godmode [on|off|toggle]";
public String Godmode_status = "Godmode is now {status} for {name}.";
// Heal // Heal
public String Heal_message = "All characters have been healed."; public String Heal_message = "All characters have been healed.";
...@@ -156,7 +160,7 @@ public final class Language { ...@@ -156,7 +160,7 @@ public final class Language {
public String List_message = "There are {size} player(s) online:"; public String List_message = "There are {size} player(s) online:";
// Permission // Permission
public String Permission_usage = "Usage: permission <add|remove> <username> <permission>"; public String Permission_usage = "Usage: permission <add|remove> <permission>";
public String Permission_add = "Permission added."; public String Permission_add = "Permission added.";
public String Permission_have_permission = "They already have this permission!"; public String Permission_have_permission = "They already have this permission!";
public String Permission_remove = "Permission removed."; public String Permission_remove = "Permission removed.";
...@@ -270,6 +274,7 @@ public final class Language { ...@@ -270,6 +274,7 @@ public final class Language {
public String Talent_usage_2 = "Another way to set talent level: /talent <n or e or q> <value>"; public String Talent_usage_2 = "Another way to set talent level: /talent <n or e or q> <value>";
public String Talent_usage_3 = "To get talent ID: /talent getid"; public String Talent_usage_3 = "To get talent ID: /talent getid";
public String Talent_lower_16 = "Invalid talent level. Level should be lower than 16"; public String Talent_lower_16 = "Invalid talent level. Level should be lower than 16";
public String Talent_set_id = "Set talent {id} to {level}.";
public String Talent_set_atk = "Set talent Normal ATK to {level}."; public String Talent_set_atk = "Set talent Normal ATK to {level}.";
public String Talent_set_e = "Set talent E to {level}."; public String Talent_set_e = "Set talent E to {level}.";
public String Talent_set_q = "Set talent Q to {level}."; public String Talent_set_q = "Set talent Q to {level}.";
...@@ -284,9 +289,7 @@ public final class Language { ...@@ -284,9 +289,7 @@ public final class Language {
public String TeleportAll_message = "You only can use this command in MP mode."; public String TeleportAll_message = "You only can use this command in MP mode.";
// Teleport // Teleport
public String Teleport_usage_server = "Usage: /tp @<player id> <x> <y> <z> [scene id]"; public String Teleport_usage = "Usage: /tp <x> <y> <z> [scene id]";
public String Teleport_usage = "Usage: /tp [@<player id>] <x> <y> <z> [scene id]";
public String Teleport_specify_player_id = "You must specify a player id.";
public String Teleport_invalid_position = "Invalid position."; public String Teleport_invalid_position = "Invalid position.";
public String Teleport_message = "Teleported {name} to {x},{y},{z} in scene {id}"; public String Teleport_message = "Teleported {name} to {x},{y},{z} in scene {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