From ecf52cd2534a2cf4c9bba6664434651f6468df1f Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Fri, 1 Nov 2024 13:11:02 +0900 Subject: [PATCH] Allow Players to have "attack effect" --- .../client/ClientProxy.java | 32 +++++----- .../TurnBasedMinecraft/common/Battle.java | 7 +++ .../TurnBasedMinecraft/common/Config.java | 58 ++++++++++--------- 3 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java index 541be84..75071f1 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ClientProxy.java @@ -514,28 +514,30 @@ public class ClientProxy extends CommonProxy { 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")))); + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackVariance")))); value = Component.literal("(" + pkt.getEntityInfo().attackVariance + ") "); value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); option.getSiblings().add(value); text.getSiblings().add(option); + } - option = Component.literal("AE"); - option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffect")))); - value = Component.literal("(" + pkt.getEntityInfo().attackEffect.toString() + ") "); - value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); - option.getSiblings().add(value); - text.getSiblings().add(option); + option = Component.literal("AE"); + option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffect")))); + value = Component.literal("(" + pkt.getEntityInfo().attackEffect.toString() + ") "); + value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); + option.getSiblings().add(value); + text.getSiblings().add(option); - option = Component.literal("AEPr"); - option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability")) - .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffectProbability")))); - value = Component.literal("(" + pkt.getEntityInfo().attackEffectProbability + "%) "); - value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); - option.getSiblings().add(value); - text.getSiblings().add(option); + option = Component.literal("AEPr"); + option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability")) + .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffectProbability")))); + value = Component.literal("(" + pkt.getEntityInfo().attackEffectProbability + "%) "); + value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); + option.getSiblings().add(value); + text.getSiblings().add(option); + if (pkt.getEntityInfo().playerName.isEmpty()) { option = Component.literal("DD"); option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage")) .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("DefenseDamage")))); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java index 863572c..5ae3965 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Battle.java @@ -898,6 +898,13 @@ public class Battle { ((Player) nextEntity).attack(targetEntity); TurnBasedMinecraftMod.proxy.setAttackingEntity(null); sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), TurnBasedMinecraftMod.proxy.getAttackingDamage()); + // Attack effect + if (next.entityInfo != null && next.entityInfo.attackEffect != EntityInfo.Effect.UNKNOWN && next.entityInfo.attackEffectProbability > 0) { + if (random.nextInt(100) < next.entityInfo.attackEffectProbability) { + next.entityInfo.attackEffect.applyEffectToEntity((LivingEntity)targetEntity); + sendMessageToAllPlayers(PacketBattleMessage.MessageType.WAS_AFFECTED, nextEntity.getId(), targetEntity.getId(), 0, next.entityInfo.attackEffect.getAffectedString()); + } + } if (defenseDamageTriggered) { // defense damage DamageSource defenseDamageSource = targetEntity.damageSources().mobAttack((LivingEntity) targetEntity); diff --git a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java index a9a5db9..256b19f 100644 --- a/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java +++ b/src/main/java/com/burnedkirby/TurnBasedMinecraft/common/Config.java @@ -565,35 +565,35 @@ public class Config eInfo.attackProbability = 30; } - if (eInfo.playerName.isEmpty()) { - try { - eInfo.attackEffect = EntityInfo.Effect.fromString(nestedConf.get("attack_effect")); - if(eInfo.attackEffect != EntityInfo.Effect.UNKNOWN) { - try { - eInfo.attackEffectProbability = nestedConf.getInt("attack_effect_probability"); - if(eInfo.attackEffectProbability < 0) { - logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "1"); - eInfo.attackEffectProbability = 1; - } else if(eInfo.attackEffectProbability > 100) { - logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "100"); - eInfo.attackEffectProbability = 100; - } - } catch (ClassCastException e) { - eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; - logger.warn("Entity \"" + name + "\" has specified attack_effect but attack_effect_probability is invalid, unsetting attack_effect"); - } catch (NullPointerException e) { - eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; - logger.warn("Entity \"" + name + "\" has specified attack_effect but attack_effect_probability is missing, unsetting attack_effect"); + try { + eInfo.attackEffect = EntityInfo.Effect.fromString(nestedConf.get("attack_effect")); + if(eInfo.attackEffect != EntityInfo.Effect.UNKNOWN) { + try { + eInfo.attackEffectProbability = nestedConf.getInt("attack_effect_probability"); + if(eInfo.attackEffectProbability < 0) { + logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "1"); + eInfo.attackEffectProbability = 1; + } else if(eInfo.attackEffectProbability > 100) { + logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "100"); + eInfo.attackEffectProbability = 100; } + } catch (ClassCastException e) { + eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; + logger.warn("Entity \"" + name + "\" has specified attack_effect but attack_effect_probability is invalid, unsetting attack_effect"); + } catch (NullPointerException e) { + eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; + logger.warn("Entity \"" + name + "\" has specified attack_effect but attack_effect_probability is missing, unsetting attack_effect"); } - } catch (ClassCastException e) { - eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; - logEntityInvalidValue("attack_effect", name, "unknown"); - } catch (NullPointerException e) { - eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; - logEntityMissingOptionalValue("attack_effect", name, "unknown"); } + } catch (ClassCastException e) { + eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; + logEntityInvalidValue("attack_effect", name, "unknown"); + } catch (NullPointerException e) { + eInfo.attackEffect = EntityInfo.Effect.UNKNOWN; + logEntityMissingOptionalValue("attack_effect", name, "unknown"); + } + if (eInfo.playerName.isEmpty()) { try { eInfo.attackVariance = nestedConf.getInt("attack_variance"); if (eInfo.attackVariance < 0) { @@ -909,6 +909,8 @@ public class Config break; } else if (!eInfo.playerName.isEmpty() && playerName != null && playerName.equals(eInfo.playerName)) { entity.set("attack_probability", eInfo.attackProbability); + entity.set("attack_effect", eInfo.attackEffect.toString()); + entity.set("attack_effect_probability", eInfo.attackEffectProbability); entity.set("evasion", eInfo.evasion); entity.set("speed", eInfo.speed); entity.set("haste_speed", eInfo.hasteSpeed); @@ -937,8 +939,10 @@ public class Config newEntry.set("attack_probability", eInfo.attackProbability); if (eInfo.playerName.isEmpty()) { newEntry.set("attack_variance", eInfo.attackVariance); - newEntry.set("attack_effect", eInfo.attackEffect.toString()); - newEntry.set("attack_effect_probability", eInfo.attackEffectProbability); + } + newEntry.set("attack_effect", eInfo.attackEffect.toString()); + newEntry.set("attack_effect_probability", eInfo.attackEffectProbability); + if (eInfo.playerName.isEmpty()) { newEntry.set("defense_damage", eInfo.defenseDamage); newEntry.set("defense_damage_probability", eInfo.defenseDamageProbability); }