2/2 Player-specific TBMM battle config

Add support for custom stats per-player by player username.
This commit is contained in:
Stephen Seo 2024-10-31 14:35:34 +09:00
parent 2d52e898f4
commit 2572190b07
2 changed files with 237 additions and 78 deletions

View file

@ -482,11 +482,15 @@ public class ClientProxy extends CommonProxy {
MutableComponent text = Component.literal("Edit what value? ");
text.setStyle(text.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)).withBold(false));
MutableComponent option = Component.literal("IgB");
MutableComponent option;
MutableComponent value;
if (pkt.getEntityInfo().playerName.isEmpty()) {
option = Component.literal("IgB");
// HoverEvent.Action.SHOW_TEXT is probably SHOW_TEXT
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit ignoreBattle"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("IgnoreBattle"))));
MutableComponent value = Component.literal("(" + pkt.getEntityInfo().ignoreBattle + ") ");
value = Component.literal("(" + pkt.getEntityInfo().ignoreBattle + ") ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
@ -498,6 +502,7 @@ public class ClientProxy extends CommonProxy {
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
}
option = Component.literal("APr");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackProbability"))
@ -507,6 +512,7 @@ public class ClientProxy extends CommonProxy {
option.getSiblings().add(value);
text.getSiblings().add(option);
if (pkt.getEntityInfo().playerName.isEmpty()) {
option = Component.literal("AV");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackVariance"))));
@ -546,6 +552,7 @@ public class ClientProxy extends CommonProxy {
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
}
option = Component.literal("E");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit evasion"))
@ -563,6 +570,23 @@ public class ClientProxy extends CommonProxy {
option.getSiblings().add(value);
text.getSiblings().add(option);
option = Component.literal("HS");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit hasteSpeed"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("HasteSpeed"))));
value = Component.literal("(" + pkt.getEntityInfo().hasteSpeed + ") ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
option = Component.literal("SS");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit slowSpeed"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("SlowSpeed"))));
value = Component.literal("(" + pkt.getEntityInfo().slowSpeed + ") ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
if (pkt.getEntityInfo().playerName.isEmpty()) {
option = Component.literal("C");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit category"))
.withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("Category"))));
@ -594,6 +618,7 @@ public class ClientProxy extends CommonProxy {
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value);
text.getSiblings().add(option);
}
option = Component.literal("Finished Editing");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFF00FF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit finish")));
@ -1303,6 +1328,44 @@ public class ClientProxy extends CommonProxy {
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
break;
}
case EDIT_HASTE_SPEED: {
MutableComponent text = Component.literal("haste speed: ");
text.setStyle(text.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)).withBold(false));
for (int i = 0; i <= 100; i += 10) {
MutableComponent option = Component.literal(Integer.toString(i));
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit hasteSpeed " + Integer.toString(i))));
text.getSiblings().add(option);
if (i < 100) {
text.getSiblings().add(Component.literal(", "));
}
}
text.getSiblings().add(Component.literal(" (or use command \"/tbm-edit edit hasteSpeed <integer>\")"));
parentComponent.getSiblings().add(text);
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
break;
}
case EDIT_SLOW_SPEED: {
MutableComponent text = Component.literal("slow speed: ");
text.setStyle(text.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)).withBold(false));
for (int i = 0; i <= 100; i += 10) {
MutableComponent option = Component.literal(Integer.toString(i));
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit slowSpeed " + Integer.toString(i))));
text.getSiblings().add(option);
if (i < 100) {
text.getSiblings().add(Component.literal(", "));
}
}
text.getSiblings().add(Component.literal(" (or use command \"/tbm-edit edit slowSpeed <integer>\")"));
parentComponent.getSiblings().add(text);
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
break;
}
case EDIT_CATEGORY: {
MutableComponent text = Component.literal("category: ");
text.setStyle(text.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)).withBold(false));
@ -1473,6 +1536,10 @@ public class ClientProxy extends CommonProxy {
TurnBasedMinecraftMod.proxy.displayComponent(parentComponent);
break;
}
case PICK_PLAYER: {
TurnBasedMinecraftMod.proxy.displayString("Use \"/tbm-edit player <player_name>\"");
break;
}
default:
break;
}

View file

@ -292,6 +292,30 @@ public class TurnBasedMinecraftMod {
}
return 1;
}))
.then(Commands.literal("player")
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_PLAYER), PacketDistributor.PLAYER.with(player));
return 1;
})
.then(Commands.argument("playerName", StringArgumentType.greedyString()).executes(c -> {
String name = StringArgumentType.getString(c, "playerName");
ServerPlayer player = c.getSource().getPlayerOrException();
getHandler().send(new PacketGeneralMessage("Editing player \"" + name + "\""), PacketDistributor.PLAYER.with(player));
TurnBasedMinecraftMod.logger.info("Begin editing player \"" + name + "\"");
proxy.setEditingPlayer(player);
EditingInfo editInfo = proxy.getEditingInfo(player.getId());
editInfo.isEditingPlayer = true;
editInfo.entityInfo = TurnBasedMinecraftMod.proxy.getConfig().getPlayerInfo(name);
if (editInfo.entityInfo == null) {
editInfo.entityInfo = new EntityInfo();
}
editInfo.entityInfo.playerName = name;
editInfo.isPendingEntitySelection = false;
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editInfo.entityInfo), PacketDistributor.PLAYER.with(player));
return 1;
}))
)
.then(Commands.literal("edit")
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
@ -648,6 +672,74 @@ public class TurnBasedMinecraftMod {
return 1;
}))
)
.then(Commands.literal("hasteSpeed")
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_HASTE_SPEED), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
})
.then(Commands.argument("hasteSpeed", IntegerArgumentType.integer())
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
int hasteSpeed = IntegerArgumentType.getInteger(c, "hasteSpeed");
if (hasteSpeed < 0) {
hasteSpeed = 0;
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.hasteSpeed = hasteSpeed;
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
}))
)
.then(Commands.literal("slowSpeed")
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.EDIT_SLOW_SPEED), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
})
.then(Commands.argument("slowSpeed", IntegerArgumentType.integer())
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();
EditingInfo editingInfo = TurnBasedMinecraftMod.proxy.getEditingInfo(player.getId());
int slowSpeed = IntegerArgumentType.getInteger(c, "slowSpeed");
if (slowSpeed < 0) {
slowSpeed = 0;
}
if (editingInfo != null && !editingInfo.isPendingEntitySelection) {
editingInfo.entityInfo.slowSpeed = slowSpeed;
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.PICK_EDIT, editingInfo.entityInfo), PacketDistributor.PLAYER.with(player));
} else if (editingInfo != null) {
getHandler().send(new PacketEditingMessage(PacketEditingMessage.Type.ATTACK_ENTITY), PacketDistributor.PLAYER.with(player));
} else {
Message exceptionMessage = new LiteralMessage("Cannot edit entity without starting editing (use \"/tbm-edit\").");
throw new CommandSyntaxException(new SimpleCommandExceptionType(exceptionMessage), exceptionMessage);
}
return 1;
}))
)
.then(Commands.literal("category")
.executes(c -> {
ServerPlayer player = c.getSource().getPlayerOrException();