Allow Players to have "attack effect"

This commit is contained in:
Stephen Seo 2024-11-01 13:11:02 +09:00
parent 6625a495ca
commit 676955503c
3 changed files with 55 additions and 42 deletions

View file

@ -514,28 +514,30 @@ public class ClientProxy extends CommonProxy {
if (pkt.getEntityInfo().playerName.isEmpty()) { if (pkt.getEntityInfo().playerName.isEmpty()) {
option = Component.literal("AV"); option = Component.literal("AV");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackVariance")) 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 = Component.literal("(" + pkt.getEntityInfo().attackVariance + ") ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value); option.getSiblings().add(value);
text.getSiblings().add(option); text.getSiblings().add(option);
}
option = Component.literal("AE"); option = Component.literal("AE");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect")) 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")))); .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffect"))));
value = Component.literal("(" + pkt.getEntityInfo().attackEffect.toString() + ") "); value = Component.literal("(" + pkt.getEntityInfo().attackEffect.toString() + ") ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value); option.getSiblings().add(value);
text.getSiblings().add(option); text.getSiblings().add(option);
option = Component.literal("AEPr"); option = Component.literal("AEPr");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffectProbability")) 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")))); .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("AttackEffectProbability"))));
value = Component.literal("(" + pkt.getEntityInfo().attackEffectProbability + "%) "); value = Component.literal("(" + pkt.getEntityInfo().attackEffectProbability + "%) ");
value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF))); value.setStyle(value.getStyle().withColor(TextColor.fromRgb(0xFFFFFFFF)));
option.getSiblings().add(value); option.getSiblings().add(value);
text.getSiblings().add(option); text.getSiblings().add(option);
if (pkt.getEntityInfo().playerName.isEmpty()) {
option = Component.literal("DD"); option = Component.literal("DD");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit defenseDamage")) 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")))); .withHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, Component.literal("DefenseDamage"))));

View file

@ -897,6 +897,13 @@ public class Battle {
((Player) nextEntity).attack(targetEntity); ((Player) nextEntity).attack(targetEntity);
TurnBasedMinecraftMod.proxy.setAttackingEntity(null); TurnBasedMinecraftMod.proxy.setAttackingEntity(null);
sendMessageToAllPlayers(PacketBattleMessage.MessageType.ATTACK, nextEntity.getId(), targetEntity.getId(), TurnBasedMinecraftMod.proxy.getAttackingDamage()); 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) { if (defenseDamageTriggered) {
// defense damage // defense damage
DamageSource defenseDamageSource = targetEntity.damageSources().mobAttack((LivingEntity) targetEntity); DamageSource defenseDamageSource = targetEntity.damageSources().mobAttack((LivingEntity) targetEntity);

View file

@ -565,35 +565,35 @@ public class Config
eInfo.attackProbability = 30; eInfo.attackProbability = 30;
} }
if (eInfo.playerName.isEmpty()) { try {
try { eInfo.attackEffect = EntityInfo.Effect.fromString(nestedConf.get("attack_effect"));
eInfo.attackEffect = EntityInfo.Effect.fromString(nestedConf.get("attack_effect")); if(eInfo.attackEffect != EntityInfo.Effect.UNKNOWN) {
if(eInfo.attackEffect != EntityInfo.Effect.UNKNOWN) { try {
try { eInfo.attackEffectProbability = nestedConf.getInt("attack_effect_probability");
eInfo.attackEffectProbability = nestedConf.getInt("attack_effect_probability"); if(eInfo.attackEffectProbability < 0) {
if(eInfo.attackEffectProbability < 0) { logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "1");
logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "1"); eInfo.attackEffectProbability = 1;
eInfo.attackEffectProbability = 1; } else if(eInfo.attackEffectProbability > 100) {
} else if(eInfo.attackEffectProbability > 100) { logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "100");
logClampedValueEntity("attack_effect_probability", name, Integer.toString(eInfo.attackEffectProbability), "100"); 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;
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 { try {
eInfo.attackVariance = nestedConf.getInt("attack_variance"); eInfo.attackVariance = nestedConf.getInt("attack_variance");
if (eInfo.attackVariance < 0) { if (eInfo.attackVariance < 0) {
@ -909,6 +909,8 @@ public class Config
break; break;
} else if (!eInfo.playerName.isEmpty() && playerName != null && playerName.equals(eInfo.playerName)) { } else if (!eInfo.playerName.isEmpty() && playerName != null && playerName.equals(eInfo.playerName)) {
entity.set("attack_probability", eInfo.attackProbability); 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("evasion", eInfo.evasion);
entity.set("speed", eInfo.speed); entity.set("speed", eInfo.speed);
entity.set("haste_speed", eInfo.hasteSpeed); entity.set("haste_speed", eInfo.hasteSpeed);
@ -937,8 +939,10 @@ public class Config
newEntry.set("attack_probability", eInfo.attackProbability); newEntry.set("attack_probability", eInfo.attackProbability);
if (eInfo.playerName.isEmpty()) { if (eInfo.playerName.isEmpty()) {
newEntry.set("attack_variance", eInfo.attackVariance); 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", eInfo.defenseDamage);
newEntry.set("defense_damage_probability", eInfo.defenseDamageProbability); newEntry.set("defense_damage_probability", eInfo.defenseDamageProbability);
} }