Allow Players to have "attack effect"

This commit is contained in:
Stephen Seo 2024-11-01 13:11:02 +09:00
parent 2572190b07
commit 42c69e8983
3 changed files with 55 additions and 42 deletions

View file

@ -520,6 +520,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("AE");
option.setStyle(option.getStyle().withColor(TextColor.fromRgb(0xFFFFFF00)).withClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/tbm-edit edit attackEffect"))
@ -537,6 +538,7 @@ public class ClientProxy extends CommonProxy {
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"))));

View file

@ -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);

View file

@ -566,7 +566,6 @@ 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) {
@ -595,6 +594,7 @@ public class Config
logEntityMissingOptionalValue("attack_effect", name, "unknown");
}
if (eInfo.playerName.isEmpty()) {
try {
eInfo.attackVariance = nestedConf.getInt("attack_variance");
if (eInfo.attackVariance < 0) {
@ -910,6 +910,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);
@ -938,8 +940,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);
if (eInfo.playerName.isEmpty()) {
newEntry.set("defense_damage", eInfo.defenseDamage);
newEntry.set("defense_damage_probability", eInfo.defenseDamageProbability);
}