diff --git a/.gitignore b/.gitignore index d34d2a2..11d83bd 100644 --- a/.gitignore +++ b/.gitignore @@ -55,3 +55,7 @@ logs/ .env .env.local *.local + +# Phase 4 — temporary asset sources (not committed) +*.zip +note diff --git a/src/main/java/com/mythlane/chainlightning/chain/ParticleTrail.java b/src/main/java/com/mythlane/chainlightning/chain/ParticleTrail.java index 99944a0..70815fa 100644 --- a/src/main/java/com/mythlane/chainlightning/chain/ParticleTrail.java +++ b/src/main/java/com/mythlane/chainlightning/chain/ParticleTrail.java @@ -18,8 +18,10 @@ import java.util.List; */ public final class ParticleTrail { - /** Default trail density in particles per block. */ - public static final double TRAIL_DENSITY = 4.0; + /** Default trail density in particles per block. Reduced from 4.0 (post 14:37 UAT) to keep + * total per-click emit count low enough that the client doesn't throttle at the particle + * budget. With 5-hop chain at 5 blocks each: 1.0 = ~25 arcs total instead of ~100. */ + public static final double TRAIL_DENSITY = 1.0; private ParticleTrail() { // utility class — no instances diff --git a/src/main/java/com/mythlane/chainlightning/sceptre/ChainLightningSceptreInteraction.java b/src/main/java/com/mythlane/chainlightning/sceptre/ChainLightningSceptreInteraction.java index e621c4c..f491b6c 100644 --- a/src/main/java/com/mythlane/chainlightning/sceptre/ChainLightningSceptreInteraction.java +++ b/src/main/java/com/mythlane/chainlightning/sceptre/ChainLightningSceptreInteraction.java @@ -136,6 +136,17 @@ public final class ChainLightningSceptreInteraction extends SimpleInstantInterac ChainDamageApplier.apply(hits, playerRef, commandBuffer, commandBuffer); LOGGER.info("[ChainLightning][7/9] damage application returned"); + // --- Étape 7.5 : émettre VFX/SFX (best-effort) --- + // CONTEXT failure-mode decision : damage déjà appliqué — si l'emit échoue, log + continue + // vers le cooldown. Pas de propagation : le tick serveur ne doit pas crash sur un bug VFX. + try { + LOGGER.info(String.format("[ChainLightning][7.5/9] vfx emit START hits=%d", hits.size())); + HytaleVfxEmitter.playChainEffects(hits, playerRef, commandBuffer); + LOGGER.info("[ChainLightning][7.5/9] vfx emit DONE"); + } catch (Throwable t) { + LOGGER.log(Level.WARNING, "[ChainLightning][7.5/9] vfx emit failed (damage already applied)", t); + } + // --- Étape 8 : démarrer le cooldown APRÈS succès --- cooldown.deductCharge(); LOGGER.info(String.format("[ChainLightning][8/9] cooldown deducted (next available in %.1fs)", COOLDOWN_TIME)); diff --git a/src/main/java/com/mythlane/chainlightning/sceptre/HytaleVfxEmitter.java b/src/main/java/com/mythlane/chainlightning/sceptre/HytaleVfxEmitter.java new file mode 100644 index 0000000..70cef6b --- /dev/null +++ b/src/main/java/com/mythlane/chainlightning/sceptre/HytaleVfxEmitter.java @@ -0,0 +1,93 @@ +package com.mythlane.chainlightning.sceptre; + +import com.hypixel.hytale.component.CommandBuffer; +import com.hypixel.hytale.component.ComponentAccessor; +import com.hypixel.hytale.component.Ref; +import com.hypixel.hytale.server.core.asset.type.entityeffect.config.EntityEffect; +import com.hypixel.hytale.server.core.entity.effect.EffectControllerComponent; +import com.hypixel.hytale.server.core.universe.world.storage.EntityStore; +import com.mythlane.chainlightning.chain.ChainHit; + +import javax.annotation.Nonnull; +import java.util.List; +import java.util.logging.Logger; + +/** + * Phase 4 — Adapter VFX/SFX qui applique un EntityEffect custom à chaque cible touchée. + * + *

Pivot 14:52 (POC EntityEffect bridge) : les tentatives précédentes via + * {@code ParticleUtil.spawnParticleEffect("Splash", ...)} ne rendaient pas les particles côté + * client (asset sync plugin custom + budget client → 0/5 visible). On utilise maintenant le + * pattern canonique Cleric-Rod : on déclare un {@code EntityEffect} JSON (Server/Entity/Effects/ + * Chain_Hit_Effect.json) qui contient des particles vanilla inline + EntityTopTint/BottomTint, + * et on applique cet effect à chaque target via {@link EffectControllerComponent#addEffect}. + * + *

Le rendu passe par la réplication ECS (le ECS state du target propage l'effet aux clients + * automatiquement), pas par un packet SpawnParticleSystem standalone. C'est le path éprouvé. + * + *

Fallback : si le lookup de l'EntityEffect échoue (asset pas chargé), on log et skip. + * Pas de propagation : damage déjà appliqué côté caller, l'emit failure ne doit pas crash. + * + *

Hop-index ignoré pour POC : l'EntityEffect est uniforme sur les 5 cibles. La courbe + * de volume (VFX-02) reste implémentée dans {@code VolumeCurve} mais n'est pas utilisée ici -- + * une variante future pourrait définir 5 EntityEffects {@code Chain_Hit_Effect_0..4} avec des + * intensités décroissantes, ou patcher l'EntityEffect existant runtime (non supporté par l'API). + */ +public final class HytaleVfxEmitter { + + private static final Logger LOGGER = Logger.getLogger(HytaleVfxEmitter.class.getName()); + + /** Asset id du EntityEffect appliqué à chaque target touchée par la chaîne. */ + private static final String EFFECT_ID = "Chain_Hit_Effect"; + + private HytaleVfxEmitter() {} + + /** + * Applique l'EntityEffect {@code Chain_Hit_Effect} à chaque hit de la chaîne. + * + * @param hits liste résolue par ChainResolver, ordre BFS + * @param playerRef ref du caster (présent pour symétrie d'API future, non utilisé ici -- + * l'EntityEffect rend automatiquement à tous les viewers en range) + * @param commandBuffer le CommandBuffer du tick courant (sert pour {@code getComponent} et + * pour propager les changes d'état ECS au tick end) + */ + public static void playChainEffects(@Nonnull List hits, + @Nonnull Ref playerRef, + @Nonnull CommandBuffer commandBuffer) { + if (hits.isEmpty()) return; + + EntityEffect entityEffect = EntityEffect.getAssetMap().getAsset(EFFECT_ID); + if (entityEffect == null) { + LOGGER.warning(String.format( + "[ChainLightning][Vfx] EntityEffect '%s' not registered -- VFX skipped (damage already applied)", + EFFECT_ID)); + return; + } + + ComponentAccessor accessor = commandBuffer; + int applied = 0; + int skipped = 0; + for (int i = 0; i < hits.size(); i++) { + Ref targetRef = ((HytaleEntityAdapter) hits.get(i).target()).ref(); + if (targetRef == null || !targetRef.isValid()) { + skipped++; + continue; + } + EffectControllerComponent ecc = accessor.getComponent(targetRef, EffectControllerComponent.getComponentType()); + if (ecc == null) { + skipped++; + continue; + } + boolean ok = ecc.addEffect(targetRef, entityEffect, accessor); + if (ok) { + applied++; + } else { + skipped++; + } + } + + LOGGER.info(String.format( + "[ChainLightning][Vfx] EntityEffect '%s' applied to %d/%d targets (skipped=%d, caster=%s)", + EFFECT_ID, applied, hits.size(), skipped, playerRef)); + } +} diff --git a/src/main/resources/Common/Particles/Chain_Spark.png b/src/main/resources/Common/Particles/Chain_Spark.png deleted file mode 100644 index 28e5c8a..0000000 Binary files a/src/main/resources/Common/Particles/Chain_Spark.png and /dev/null differ diff --git a/src/main/resources/Server/Entity/Effects/Chain_Hit_Effect.json b/src/main/resources/Server/Entity/Effects/Chain_Hit_Effect.json new file mode 100644 index 0000000..2fc21d4 --- /dev/null +++ b/src/main/resources/Server/Entity/Effects/Chain_Hit_Effect.json @@ -0,0 +1,19 @@ +{ + "Name": "entity_effect.chain_lightning.hit", + "Duration": 0.6, + "OverlapBehavior": "Overwrite", + "Debuff": true, + "ApplicationEffects": { + "EntityTopTint": "#B0DCFF", + "EntityBottomTint": "#66B3FF", + "Particles": [ + { + "SystemId": "Splash", + "TargetEntityPart": "Entity", + "Scale": 4.0, + "Color": "#B0DCFF", + "DetachedFromModel": false + } + ] + } +} diff --git a/src/main/resources/Server/Particles/Chain_Spark.particlespawner b/src/main/resources/Server/Particles/Chain_Spark.particlespawner deleted file mode 100644 index 276dcab..0000000 --- a/src/main/resources/Server/Particles/Chain_Spark.particlespawner +++ /dev/null @@ -1,32 +0,0 @@ -{ - "Shape": "Sphere", - "ParticleRotationInfluence": "Billboard", - "RenderMode": "BlendAdd", - "TotalParticles": { "Min": 1, "Max": 1 }, - "LifeSpan": 0.5, - "MaxConcurrentParticles": 16, - "ParticleLifeSpan": { "Min": 0.3, "Max": 0.5 }, - "SpawnRate": { "Min": 50.0, "Max": 50.0 }, - "Particle": { - "Texture": "Particles/Chain_Spark.png", - "FrameSize": { "Width": 4, "Height": 4 }, - "SoftParticles": "Enable", - "SoftParticlesFadeFactor": 1.0, - "UVOption": "None", - "ScaleRatioConstraint": "OneToOne", - "Animation": { - "0": { - "FrameIndex": { "Min": 0, "Max": 0 }, - "Scale": { "X": { "Min": 0.3, "Max": 0.3 }, "Y": { "Min": 0.3, "Max": 0.3 } }, - "Color": "#B0DCFF", - "Opacity": 1.0 - }, - "100": { - "FrameIndex": { "Min": 0, "Max": 0 }, - "Scale": { "X": { "Min": 0.0, "Max": 0.0 }, "Y": { "Min": 0.0, "Max": 0.0 } }, - "Color": "#B0DCFF", - "Opacity": 0.0 - } - } - } -} diff --git a/src/main/resources/Server/Particles/Chain_Spark.particlesystem b/src/main/resources/Server/Particles/Chain_Spark.particlesystem deleted file mode 100644 index 58e414c..0000000 --- a/src/main/resources/Server/Particles/Chain_Spark.particlesystem +++ /dev/null @@ -1,10 +0,0 @@ -{ - "LifeSpan": 0.5, - "CullDistance": 64.0, - "BoundingRadius": 1.0, - "Spawners": [ - { - "SpawnerId": "Chain_Spark" - } - ] -}