A display rebuild ends a unit's spell effects before its body goes (#2864)
A display swap despawned a unit's spell effects with its old visual while their instances still named them, so a later teardown despawned a dead entity. 1.12.1's rebuild ends every effect on the unit first (`0x60abe0`, `0x60ac10`), then replays the auras' and the channel's kits. **Changed** - A rebuild runs only when `0x60ae10` says the display changed. It ends the effects started before it on the wire, and replays the auras' and the channel's kits on the new body. - Kit sounds fade over 0.15 s as they stop (`0x6204b6`), and each loop is tracked per kit. - benilla's rig heal keeps what the unit had. **Tests:** a swap and a heal with effects up, the wire order within a frame, the gate, the replays, the fade. The swap tests fail on main. Fixes #2843 Found in Adrinalin4ik/manila@cd8790bc 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -710,6 +710,9 @@ pub(crate) struct CastEvent {
|
||||
pub(crate) kind: CastEventKind,
|
||||
/// `PlaySeq` stamp, carried to the kit's `EmoteAnim`.
|
||||
pub(crate) seq: u64,
|
||||
/// The cast packet's place among what the packets queue ([`crate::lanes::stamp`]); `None` for
|
||||
/// an edge the frame raised (a missile's arrival, a probe line), after every packet.
|
||||
pub(crate) at: Option<crate::lanes::Stamp>,
|
||||
}
|
||||
|
||||
/// Which cast edge fired.
|
||||
@@ -889,6 +892,9 @@ pub(crate) struct SpellGoTargets {
|
||||
pub(crate) ammo_display_id: Option<u32>,
|
||||
/// `PlaySeq` stamp, the GO's `CastEvent`'s.
|
||||
pub(crate) seq: u64,
|
||||
/// The GO packet's place, its `CastEvent`'s, which its impact kits carry; `None` for a GO the
|
||||
/// frame raised, after every packet.
|
||||
pub(crate) at: Option<crate::lanes::Stamp>,
|
||||
}
|
||||
|
||||
/// The sheath policy: requests, ceremony overlays, the `AnimationData.dbc` table.
|
||||
@@ -956,8 +962,9 @@ use spell_visual::{
|
||||
#[cfg(test)]
|
||||
pub(crate) use spell_visual::arm_aura_state_fx as arm_aura_state_fx_for_test;
|
||||
pub(crate) use spell_visual::{
|
||||
held_strike_sound, ChainProcPlay, FxClass, FxStage, GroundList, KitPush, MissileSpawn,
|
||||
PrecastTables, PrecastVisuals, SpellKitFx, SpellKitShake, SpellKitSound, SpellVisuals,
|
||||
held_strike_sound, replay_rebuilt_kit_sounds, ChainProcPlay, FxClass, FxStage, GroundList,
|
||||
KitPush, MissileSpawn, PrecastTables, PrecastVisuals, SpellKitFx, SpellKitShake, SpellKitSound,
|
||||
SpellVisuals,
|
||||
};
|
||||
|
||||
/// The per-unit animation state machine; `Transform` is required, its scale divides the rate, and
|
||||
|
||||
@@ -130,6 +130,8 @@ pub(super) fn blood_spurts(
|
||||
effect,
|
||||
path: path.to_string(),
|
||||
}],
|
||||
// A swing's impact, presented in the frame after every packet.
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,6 +180,8 @@ pub(super) fn fire_breath(
|
||||
effect,
|
||||
path: path.clone(),
|
||||
}],
|
||||
// A model event of the frame, after every packet.
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
// Forget despawned units.
|
||||
|
||||
@@ -437,6 +437,7 @@ fn cast_event(world: &mut World, entity: Entity, spell_id: u32, kind: CastEventK
|
||||
spell_id,
|
||||
kind,
|
||||
seq,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,8 @@ pub(super) fn hard_landing_dust(
|
||||
entity: l.entity,
|
||||
kit_id,
|
||||
seq: seq.next(),
|
||||
// The landing frame's own prediction, after every packet.
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -449,6 +449,7 @@ fn play_spell_visual(
|
||||
entity: e,
|
||||
kit_id,
|
||||
seq: play_seq.next(),
|
||||
at: Some(crate::lanes::stamp()),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -473,6 +474,7 @@ fn environmental_damage_log(
|
||||
entity: ent,
|
||||
kit_id,
|
||||
seq: play_seq.next(),
|
||||
at: Some(crate::lanes::stamp()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,7 @@ pub(crate) fn meeting_stone_join_fx(visuals: &SpellVisuals, entity: Entity) -> O
|
||||
effect,
|
||||
path: path.to_string(),
|
||||
}],
|
||||
at: None,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -77,10 +78,16 @@ pub(crate) enum SpellKitSound {
|
||||
entity: Entity,
|
||||
spell_id: u32,
|
||||
kit_sound: u32,
|
||||
/// Rung by a cast's hold, a precast's or a channel's kit, which a replacing hold stops
|
||||
/// ([`Self::StopHold`] with no spell).
|
||||
cast_hold: bool,
|
||||
/// Its packet's place ([`SpellKitFx::at`]), which a hold loop keeps for
|
||||
/// [`Self::Rebuilt`].
|
||||
at: Option<crate::lanes::Stamp>,
|
||||
},
|
||||
/// Stop the unit's hold loop: for `Some(spell)`, only a loop that spell's kit rang, as
|
||||
/// `0x614150(spell, 0)` stops only the effects whose spell matches (`0x614167`); for `None`,
|
||||
/// whatever loop it holds, as a new hold replaces the old.
|
||||
/// Stop the unit's hold loops: for `Some(spell)`, every loop that spell's kits rang, as
|
||||
/// `0x614150(spell, 0)` stops every effect whose spell matches (`0x614167`); for `None`, every
|
||||
/// loop a cast's hold rang, as a new hold replaces the old.
|
||||
StopHold {
|
||||
entity: Entity,
|
||||
spell_id: Option<u32>,
|
||||
@@ -90,6 +97,24 @@ pub(crate) enum SpellKitSound {
|
||||
PlayAt { pos: Vec3, kit_sound: u32 },
|
||||
/// Stop this kit's sound on the unit as its aura leaves (`0x614150`, 0.15 s fade).
|
||||
StopKit { entity: Entity, kit_sound: u32 },
|
||||
/// A display rebuild at `at` (`0x60abe0`): its loop `0x60ac10` stops each of the unit's
|
||||
/// effects, fading each one's sound over 0.15 s (`0x6203e0`, `0x6204b6` → `0x7a5a10`), so the
|
||||
/// unit's hold loop fades if it rang before `at`.
|
||||
Rebuilt {
|
||||
entity: Entity,
|
||||
at: crate::lanes::Stamp,
|
||||
},
|
||||
/// The rebuild's replay at its place `at` of a kit it plays again, an aura slot's state kit
|
||||
/// (`0x5ff130` at `0x60ada6`) or the channel's (`0x612a30` at `0x60adad`): the unit's sound
|
||||
/// on that kit fades as the rebuild stopped its effect, and the kit rings afresh.
|
||||
Replay {
|
||||
entity: Entity,
|
||||
spell_id: u32,
|
||||
kit_sound: u32,
|
||||
/// The channel's, a cast's hold ([`Self::Play`]).
|
||||
cast_hold: bool,
|
||||
at: crate::lanes::Stamp,
|
||||
},
|
||||
}
|
||||
|
||||
/// A kit's camera shake (kit field 14 → `SpellEffectCameraShakes.dbc`), consumed by
|
||||
@@ -156,6 +181,8 @@ pub(crate) enum SpellKitFx {
|
||||
/// The models' animation lifecycle ([`FxStage`]).
|
||||
stage: FxStage,
|
||||
effects: Vec<FxSlot>,
|
||||
/// Its packet's place ([`SpellKitFx::at`]).
|
||||
at: Option<crate::lanes::Stamp>,
|
||||
},
|
||||
/// Despawn the unit's persistent effects matching `(spell_id, class)` (`0x614150`).
|
||||
Reap {
|
||||
@@ -165,9 +192,29 @@ pub(crate) enum SpellKitFx {
|
||||
/// `0x614150`'s `force`: the cast edges stop unforced, sparing the spell's state effects
|
||||
/// (kind 2), which the aura's removal and the channel's change stop forced.
|
||||
force: bool,
|
||||
/// Its packet's place ([`SpellKitFx::at`]).
|
||||
at: Option<crate::lanes::Stamp>,
|
||||
},
|
||||
}
|
||||
|
||||
impl SpellKitFx {
|
||||
/// The unit the edge plays on.
|
||||
pub(crate) fn entity(&self) -> Entity {
|
||||
match self {
|
||||
Self::Begin { entity, .. } | Self::Reap { entity, .. } => *entity,
|
||||
}
|
||||
}
|
||||
|
||||
/// The place of the packet that raised the edge among what the packets queue (a field
|
||||
/// edge's or a cast packet's [`crate::lanes::Stamp`]), by which a display rebuild in the same
|
||||
/// frame ends it or not; `None` for an edge the frame raised, after every packet.
|
||||
pub(crate) fn at(&self) -> Option<crate::lanes::Stamp> {
|
||||
match self {
|
||||
Self::Begin { at, .. } | Self::Reap { at, .. } => *at,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A kit play whose `CharProc` slots name a beam, the dispatcher's chain case (`0x60da79`), run at
|
||||
/// the kit tail (`0x60f35c`) and from the channel poll (`0x612b18`). Consumed by
|
||||
/// `crate::entities::chain_beam`.
|
||||
@@ -493,6 +540,9 @@ pub(crate) struct KitPush {
|
||||
pub(crate) kit_id: u32,
|
||||
/// [`super::PlaySeq`] stamp at the wire drain, in packet order.
|
||||
pub(crate) seq: u64,
|
||||
/// The packet's place ([`SpellKitFx::at`]); `None` for a push the frame raised, after every
|
||||
/// packet.
|
||||
pub(crate) at: Option<crate::lanes::Stamp>,
|
||||
}
|
||||
|
||||
/// The kit lanes [`route_cast_visuals`] writes but does not own, bundled into one param because
|
||||
@@ -519,6 +569,8 @@ struct KitOut<'a, 'w1, 'w2, 'w3, 'w4, 'w5, 'w6, 'w7, 'w8> {
|
||||
trails: &'a mut MessageWriter<'w7, crate::weapon_trail::TrailArm>,
|
||||
/// The base recompute a stage-2 kit's anim id spends itself on.
|
||||
recomputes: &'a mut MessageWriter<'w8, BaseAnimRecompute>,
|
||||
/// The place of the packet the plays come from ([`SpellKitFx::at`]).
|
||||
at: Option<crate::lanes::Stamp>,
|
||||
}
|
||||
|
||||
/// One kit play's policy on the reference's `PlaySpellVisualKit` (`0x60edf0`):
|
||||
@@ -583,6 +635,8 @@ fn play_kit(
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold: false,
|
||||
at: out.at,
|
||||
});
|
||||
}
|
||||
// The camera shake plays at every stage, gated on nothing.
|
||||
@@ -615,6 +669,7 @@ fn play_kit(
|
||||
class: FxClass::Hold,
|
||||
stage: play.stage,
|
||||
effects,
|
||||
at: out.at,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -790,6 +845,7 @@ pub(super) fn route_cast_visuals(
|
||||
shakes,
|
||||
trails,
|
||||
recomputes,
|
||||
at: None,
|
||||
};
|
||||
|
||||
// `holds` lags one command flush and an instant cast's START and GO drain together, so
|
||||
@@ -803,6 +859,7 @@ pub(super) fn route_cast_visuals(
|
||||
};
|
||||
|
||||
for p in pushes.read() {
|
||||
out.at = p.at;
|
||||
// No kit-level scan, but each slot's same-(record, tag) replace (`0x6208e0`) swaps the old
|
||||
// batch out; the driver's same-id dedup (`0x5fdba0`) keeps a looping clip running.
|
||||
if let Some(kit) = visuals.0.kit(p.kit_id) {
|
||||
@@ -824,6 +881,7 @@ pub(super) fn route_cast_visuals(
|
||||
if commands.get_entity(ev.entity).is_err() {
|
||||
continue;
|
||||
}
|
||||
out.at = ev.at;
|
||||
match ev.kind {
|
||||
CastEventKind::Start => {
|
||||
// A replacing cast reaps the prior hold's loop and persistent models first.
|
||||
@@ -837,6 +895,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: prior,
|
||||
class: FxClass::Hold,
|
||||
force: true,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
// A ranged-attribute START draws the ranged weapon (`0x6e78f3`); vmangos sends
|
||||
@@ -881,6 +940,8 @@ pub(super) fn route_cast_visuals(
|
||||
entity: ev.entity,
|
||||
spell_id: ev.spell_id,
|
||||
kit_sound,
|
||||
cast_hold: true,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
// Persistent until the cast resolves, re-armed forever (stage 4).
|
||||
@@ -893,6 +954,7 @@ pub(super) fn route_cast_visuals(
|
||||
class: FxClass::Hold,
|
||||
stage: FxStage::Relive,
|
||||
effects,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -925,6 +987,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: ev.spell_id,
|
||||
class: FxClass::Hold,
|
||||
force: false,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
// Then the running auto-repeat spell's on the same unit, `0x614150([0xceac30], 0)`
|
||||
@@ -944,6 +1007,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: repeat,
|
||||
class: FxClass::Hold,
|
||||
force: false,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
// A ranged-slot GO redraws ranged before the cast kit (`0x60f34c`, gate
|
||||
@@ -1027,6 +1091,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: ev.spell_id,
|
||||
class: FxClass::Hold,
|
||||
force: false,
|
||||
at: ev.at,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1035,6 +1100,8 @@ pub(super) fn route_cast_visuals(
|
||||
// Speed 0 plays every impact now (`0x6e8bf0`), with or without a caster unit (`0x6e816b`);
|
||||
// Speed > 0 flies the launcher's missiles from a caster unit ([`launcher_shots`]).
|
||||
for go in go_targets.read() {
|
||||
// The GO's own place, not the frame's last cast edge's.
|
||||
out.at = go.at;
|
||||
let Some(display) = spells.catalog.get(go.spell_id) else {
|
||||
continue;
|
||||
};
|
||||
@@ -1123,7 +1190,11 @@ pub(super) fn route_cast_visuals(
|
||||
}
|
||||
|
||||
// The channel poll: `UNIT_CHANNEL_SPELL` edges drive an observed unit's channel (the self-only
|
||||
// `MSG_CHANNEL_*` do not); a cleared field drops the hold even with no other wire trace.
|
||||
// `MSG_CHANNEL_*` do not); a cleared field drops the hold even with no other wire trace. Its
|
||||
// kits carry no place, falling after every packet's: the channel's watcher (field 144) runs
|
||||
// after the display's (131) in an update, and across packets the rebuild replays the
|
||||
// channel's kit (`0x612a30`), so either side of a rebuild leaves it on the new body once.
|
||||
out.at = None;
|
||||
for (entity, store) in &units {
|
||||
let cur = store.0.unit_channel_spell();
|
||||
let prev = channel_cache.get(&entity).copied().unwrap_or(0);
|
||||
@@ -1143,6 +1214,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: prev,
|
||||
class: FxClass::Hold,
|
||||
force: true,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
// No ranged fallback on the channel poll (`0x612a30`).
|
||||
@@ -1162,6 +1234,8 @@ pub(super) fn route_cast_visuals(
|
||||
entity,
|
||||
spell_id: cur,
|
||||
kit_sound,
|
||||
cast_hold: true,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
// The CharProc dispatcher's second caller (`0x612b18`): Drain Life's beam is
|
||||
@@ -1188,6 +1262,7 @@ pub(super) fn route_cast_visuals(
|
||||
class: FxClass::Hold,
|
||||
stage: FxStage::State,
|
||||
effects,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1206,6 +1281,7 @@ pub(super) fn route_cast_visuals(
|
||||
spell_id: prev,
|
||||
class: FxClass::Hold,
|
||||
force: true,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1249,19 +1325,19 @@ pub(crate) fn arm_aura_state_fx(
|
||||
let (Some(visuals), Some(spells)) = (visuals.as_deref(), spells.as_deref()) else {
|
||||
return; // no client data
|
||||
};
|
||||
// Each unit's kits carry the aura watcher's place, its first edge in the span (`0x604d00`).
|
||||
let mut aura_at: EntityHashMap<crate::lanes::Stamp> = EntityHashMap::default();
|
||||
let scan = if full_sweep {
|
||||
units.iter().collect::<Vec<_>>()
|
||||
} else {
|
||||
let mut due: EntityHashSet = arrived.iter().collect();
|
||||
due.extend(
|
||||
edges
|
||||
.read()
|
||||
.filter(|e| {
|
||||
e.unit_array_slot(AURA_WATCH_BASE, AURA_WATCH_SPAN)
|
||||
.is_some()
|
||||
})
|
||||
.map(|e| e.entity),
|
||||
);
|
||||
for e in edges.read().filter(|e| {
|
||||
e.unit_array_slot(AURA_WATCH_BASE, AURA_WATCH_SPAN)
|
||||
.is_some()
|
||||
}) {
|
||||
due.insert(e.entity);
|
||||
aura_at.entry(e.entity).or_insert(e.at);
|
||||
}
|
||||
due.into_iter().filter_map(|e| units.get(e).ok()).collect()
|
||||
};
|
||||
for (entity, store) in scan {
|
||||
@@ -1290,6 +1366,7 @@ pub(crate) fn arm_aura_state_fx(
|
||||
spell_id,
|
||||
class: FxClass::AuraState,
|
||||
force: true,
|
||||
at: aura_at.get(&entity).copied(),
|
||||
});
|
||||
procs.write(AuraProc::Reap { entity, spell_id });
|
||||
// The forced stop takes the 0x1000 effect too (`0x614179`).
|
||||
@@ -1332,6 +1409,7 @@ pub(crate) fn arm_aura_state_fx(
|
||||
class: FxClass::AuraState,
|
||||
stage: FxStage::State,
|
||||
effects,
|
||||
at: aura_at.get(&entity).copied(),
|
||||
});
|
||||
}
|
||||
if !nodes.is_empty() {
|
||||
@@ -1347,6 +1425,8 @@ pub(crate) fn arm_aura_state_fx(
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold: false,
|
||||
at: aura_at.get(&entity).copied(),
|
||||
});
|
||||
}
|
||||
// The stage-2 anim leg, on the add edge only: an aura refreshed in place keeps its id,
|
||||
@@ -1395,6 +1475,7 @@ pub(super) fn arm_loot_fx(
|
||||
let Some((effect, path)) = visuals.as_ref().and_then(|v| v.0.loot_art_effect()) else {
|
||||
return; // no client data or no such row
|
||||
};
|
||||
let mut loot_at: EntityHashMap<crate::lanes::Stamp> = EntityHashMap::default();
|
||||
let scan = if full_sweep {
|
||||
units.iter().collect::<Vec<_>>()
|
||||
} else {
|
||||
@@ -1403,18 +1484,18 @@ pub(super) fn arm_loot_fx(
|
||||
FIELD_UNIT_MAXHEALTH,
|
||||
};
|
||||
let mut due: EntityHashSet = arrived.iter().collect();
|
||||
due.extend(
|
||||
edges
|
||||
.read()
|
||||
.filter(|e| {
|
||||
e.unit_field(FIELD_UNIT_DYNAMIC_FLAGS)
|
||||
|| e.unit_field(FIELD_UNIT_HEALTH)
|
||||
|| e.unit_field(FIELD_UNIT_MAXHEALTH)
|
||||
|| (e.kind == benilla_protocol::messages::ObjectType::Corpse
|
||||
&& e.index == FIELD_CORPSE_DYNAMIC_FLAGS)
|
||||
})
|
||||
.map(|e| e.entity),
|
||||
);
|
||||
for e in edges.read().filter(|e| {
|
||||
e.unit_field(FIELD_UNIT_DYNAMIC_FLAGS)
|
||||
|| e.unit_field(FIELD_UNIT_HEALTH)
|
||||
|| e.unit_field(FIELD_UNIT_MAXHEALTH)
|
||||
|| (e.kind == benilla_protocol::messages::ObjectType::Corpse
|
||||
&& e.index == FIELD_CORPSE_DYNAMIC_FLAGS)
|
||||
}) {
|
||||
due.insert(e.entity);
|
||||
// The last of the fields to move, after which the unit reads dead and lootable.
|
||||
let at = loot_at.entry(e.entity).or_insert(e.at);
|
||||
*at = (*at).max(e.at);
|
||||
}
|
||||
due.into_iter().filter_map(|e| units.get(e).ok()).collect()
|
||||
};
|
||||
for (entity, store, net) in scan {
|
||||
@@ -1443,6 +1524,7 @@ pub(super) fn arm_loot_fx(
|
||||
effect,
|
||||
path: path.to_string(),
|
||||
}],
|
||||
at: loot_at.get(&entity).copied(),
|
||||
});
|
||||
} else if !lootable && armed.remove(&entity) {
|
||||
fx.write(SpellKitFx::Reap {
|
||||
@@ -1450,6 +1532,7 @@ pub(super) fn arm_loot_fx(
|
||||
spell_id: LOOT_FX_KEY,
|
||||
class: FxClass::Hold,
|
||||
force: true,
|
||||
at: loot_at.get(&entity).copied(),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1491,6 +1574,7 @@ pub(super) fn arm_level_up_fx(
|
||||
effect,
|
||||
path: path.to_string(),
|
||||
}],
|
||||
at: Some(e.at),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1531,6 +1615,7 @@ pub(super) fn arm_mount_poof_fx(
|
||||
effect,
|
||||
path: path.to_string(),
|
||||
}],
|
||||
at: Some(e.at),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1587,6 +1672,54 @@ pub(super) fn arm_morph_latch(
|
||||
latch.0.retain(|e, _| units.contains(*e));
|
||||
}
|
||||
|
||||
/// The sound half of the rebuild's replay (`0x60abe0`): the aura slots' state kits (`0x5ff130` at
|
||||
/// `0x60ada6`), then the channel's kit (`0x612a30` at `0x60adad`), played again as kind 2, ring
|
||||
/// afresh at the rebuild's place over the sounds its loop faded. Their models re-arm in
|
||||
/// `crate::entities::spell_fx`.
|
||||
pub(crate) fn replay_rebuilt_kit_sounds(
|
||||
mut swaps: MessageReader<crate::entities::DisplaySwapped>,
|
||||
units: Query<&ObjectStore>,
|
||||
visuals: Option<Res<SpellVisuals>>,
|
||||
spells: Option<Res<crate::ui_action::Spells>>,
|
||||
mut sounds: MessageWriter<SpellKitSound>,
|
||||
) {
|
||||
for swap in swaps.read() {
|
||||
let (Some(at), Ok(store)) = (swap.at, units.get(swap.entity)) else {
|
||||
continue; // a game object's or corpse's new id, or a unit gone
|
||||
};
|
||||
let (Some(visuals), Some(spells)) = (visuals.as_deref(), spells.as_deref()) else {
|
||||
continue; // no client data
|
||||
};
|
||||
let mut auras: Vec<u32> = Vec::new();
|
||||
for spell_id in store.0.unit_aura_ids().filter(|&s| s != 0) {
|
||||
if !auras.contains(&spell_id) {
|
||||
auras.push(spell_id);
|
||||
}
|
||||
}
|
||||
let state = auras.into_iter().map(|spell_id| {
|
||||
let kit = resolve_kit(spells, &visuals.0, spell_id, |s| s.state, || None);
|
||||
(spell_id, kit, false)
|
||||
});
|
||||
let channel = Some(store.0.unit_channel_spell())
|
||||
.filter(|&c| c != 0)
|
||||
.map(|spell_id| {
|
||||
let kit = resolve_kit(spells, &visuals.0, spell_id, |s| s.channel, || None);
|
||||
(spell_id, kit, true)
|
||||
});
|
||||
for (spell_id, kit, cast_hold) in state.chain(channel) {
|
||||
if let Some(kit_sound) = kit.and_then(|k| k.sound) {
|
||||
sounds.write(SpellKitSound::Replay {
|
||||
entity: swap.entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The rebuild's impact-kit replay (the tail of `0x60abe0`): a display swap with the latch armed
|
||||
/// plays the latched impact kit and clears it, a frame later on the rebuilt body. The same-record,
|
||||
/// same-tag replace (`0x6208e0`) is not built, so a cold-cache shift-in briefly shows two clouds.
|
||||
@@ -1626,6 +1759,8 @@ pub(super) fn replay_morph_kit(
|
||||
shakes: &mut shakes,
|
||||
trails: &mut trails,
|
||||
recomputes: &mut recomputes,
|
||||
// The replay rides the rebuild that was the frame before: after every packet.
|
||||
at: None,
|
||||
};
|
||||
play_kit(
|
||||
swap.entity,
|
||||
|
||||
@@ -108,6 +108,7 @@ fn cast_event(entity: Entity, spell_id: u32, kind: CastEventKind) -> CastEvent {
|
||||
spell_id,
|
||||
kind,
|
||||
seq: 1,
|
||||
at: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -529,6 +530,7 @@ fn a_go_with_no_caster_unit_plays_its_instant_impacts() {
|
||||
target_mask: 0x2,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
let wounds: Vec<Entity> = app
|
||||
@@ -540,6 +542,259 @@ fn a_go_with_no_caster_unit_plays_its_instant_impacts() {
|
||||
assert_eq!(wounds, [target]);
|
||||
}
|
||||
|
||||
/// A GO's impact kits carry the GO packet's place, not the frame's last cast edge's: a display
|
||||
/// rebuild between the two (`0x60abe0`) ends the impact the wire put before it and spares the
|
||||
/// cast after it, with or without a caster unit.
|
||||
#[test]
|
||||
fn a_gos_impact_kits_carry_the_gos_own_place() {
|
||||
const BOLT: u32 = 5143;
|
||||
const BOLT_VISUAL: u32 = 140;
|
||||
const IMPACT_KIT: u32 = 301;
|
||||
const IMPACT_SOUND: u32 = 3001;
|
||||
let mut app = app();
|
||||
app.insert_resource(SpellVisuals(SpellVisualCatalog::from_tables(
|
||||
HashMap::from([
|
||||
(
|
||||
BOLT_VISUAL,
|
||||
VisualStages {
|
||||
impact: IMPACT_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
VISUAL,
|
||||
VisualStages {
|
||||
precast: PRECAST_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
]),
|
||||
HashMap::from([
|
||||
(
|
||||
IMPACT_KIT,
|
||||
VisualKit {
|
||||
sound: Some(IMPACT_SOUND),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(PRECAST_KIT, VisualKit::default()),
|
||||
]),
|
||||
)));
|
||||
app.insert_resource(crate::ui_action::Spells {
|
||||
catalog: SpellCatalog::from_displays(HashMap::from([
|
||||
(
|
||||
BOLT,
|
||||
SpellDisplay {
|
||||
visual: BOLT_VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
SPELL,
|
||||
SpellDisplay {
|
||||
visual: VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
});
|
||||
let target = app.world_mut().spawn_empty().id();
|
||||
let later_caster = app.world_mut().spawn_empty().id();
|
||||
let go = crate::lanes::stamp();
|
||||
let later = crate::lanes::stamp();
|
||||
app.world_mut().write_message(SpellGoTargets {
|
||||
caster: None,
|
||||
spell_id: BOLT,
|
||||
hits: vec![target],
|
||||
misses: Vec::new(),
|
||||
source: None,
|
||||
dest: None,
|
||||
target_mask: 0x2,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: Some(go),
|
||||
});
|
||||
app.world_mut().write_message(CastEvent {
|
||||
at: Some(later),
|
||||
..cast_event(later_caster, SPELL, CastEventKind::Start)
|
||||
});
|
||||
app.update();
|
||||
let impacts: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.filter_map(|ev| match ev {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
kit_sound: IMPACT_SOUND,
|
||||
at,
|
||||
..
|
||||
} => Some((entity, at)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(impacts, [(target, Some(go))]);
|
||||
}
|
||||
|
||||
/// A pushed kit (`SMSG_PLAY_SPELL_VISUAL`, an environmental hit's) carries its packet's place, so
|
||||
/// a display rebuild after it (`0x60abe0`) ends it, and one before it spares it.
|
||||
#[test]
|
||||
fn a_pushed_kit_carries_its_packets_place() {
|
||||
const PUSHED_KIT: u32 = 302;
|
||||
const PUSHED_SOUND: u32 = 3002;
|
||||
let mut app = app();
|
||||
app.insert_resource(SpellVisuals(SpellVisualCatalog::from_tables(
|
||||
HashMap::new(),
|
||||
HashMap::from([(
|
||||
PUSHED_KIT,
|
||||
VisualKit {
|
||||
sound: Some(PUSHED_SOUND),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
)));
|
||||
let unit = app.world_mut().spawn_empty().id();
|
||||
let at = crate::lanes::stamp();
|
||||
app.world_mut().write_message(KitPush {
|
||||
entity: unit,
|
||||
kit_id: PUSHED_KIT,
|
||||
seq: 1,
|
||||
at: Some(at),
|
||||
});
|
||||
app.update();
|
||||
let places: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.filter_map(|ev| match ev {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
kit_sound: PUSHED_SOUND,
|
||||
at,
|
||||
..
|
||||
} => Some((entity, at)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(places, [(unit, Some(at))]);
|
||||
}
|
||||
|
||||
/// The rebuild replays the aura slots' state kits (`0x5ff130` at `0x60ada6`), then the channel's
|
||||
/// (`0x612a30` at `0x60adad`), as kind 2: each sound rings afresh at the rebuild's place, an aura
|
||||
/// in two slots once. A game object's new id replays nothing.
|
||||
#[test]
|
||||
fn a_rebuild_rings_the_aura_and_channel_kits_again() {
|
||||
use benilla_protocol::field::{FIELD_UNIT_AURA, FIELD_UNIT_CHANNEL_SPELL};
|
||||
const AURA: u32 = 1459; // Arcane Intellect
|
||||
const AURA_VISUAL: u32 = 150;
|
||||
const AURA_KIT: u32 = 401;
|
||||
const AURA_SOUND: u32 = 4001;
|
||||
const CHANNEL: u32 = 5143; // Arcane Missiles
|
||||
const CHANNEL_VISUAL: u32 = 151;
|
||||
const CHANNEL_KIT: u32 = 402;
|
||||
const AM_HUM: u32 = 3136;
|
||||
let mut app = App::new();
|
||||
app.add_message::<crate::entities::DisplaySwapped>()
|
||||
.add_message::<SpellKitSound>()
|
||||
.insert_resource(SpellVisuals(SpellVisualCatalog::from_tables(
|
||||
HashMap::from([
|
||||
(
|
||||
AURA_VISUAL,
|
||||
VisualStages {
|
||||
state: AURA_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
CHANNEL_VISUAL,
|
||||
VisualStages {
|
||||
channel: CHANNEL_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
]),
|
||||
HashMap::from([
|
||||
(
|
||||
AURA_KIT,
|
||||
VisualKit {
|
||||
sound: Some(AURA_SOUND),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
CHANNEL_KIT,
|
||||
VisualKit {
|
||||
sound: Some(AM_HUM),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
]),
|
||||
)))
|
||||
.insert_resource(crate::ui_action::Spells {
|
||||
catalog: SpellCatalog::from_displays(HashMap::from([
|
||||
(
|
||||
AURA,
|
||||
SpellDisplay {
|
||||
visual: AURA_VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(
|
||||
CHANNEL,
|
||||
SpellDisplay {
|
||||
visual: CHANNEL_VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
])),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
})
|
||||
.add_systems(Update, super::replay_rebuilt_kit_sounds);
|
||||
let unit = app
|
||||
.world_mut()
|
||||
.spawn(crate::net::ObjectStore(
|
||||
benilla_protocol::ObjectFields::from_pairs(&[
|
||||
(FIELD_UNIT_AURA, AURA),
|
||||
(FIELD_UNIT_AURA + 1, AURA),
|
||||
(FIELD_UNIT_CHANNEL_SPELL, CHANNEL),
|
||||
]),
|
||||
))
|
||||
.id();
|
||||
let at = crate::lanes::stamp();
|
||||
let mut swaps = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<crate::entities::DisplaySwapped>>();
|
||||
swaps.write(crate::entities::DisplaySwapped {
|
||||
entity: unit,
|
||||
at: Some(at),
|
||||
});
|
||||
swaps.write(crate::entities::DisplaySwapped {
|
||||
entity: unit,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
let replays: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.filter_map(|ev| match ev {
|
||||
SpellKitSound::Replay {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
at,
|
||||
..
|
||||
} => Some((entity, spell_id, kit_sound, at)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
replays,
|
||||
[(unit, AURA, AURA_SOUND, at), (unit, CHANNEL, AM_HUM, at)]
|
||||
);
|
||||
}
|
||||
|
||||
/// The ranged weapon-visual merge (`0x60d450`): a spell with `Attributes & 0x2` fills every zero
|
||||
/// slot of its own row from the caster's weapon visual; a non-ranged spell never looks.
|
||||
#[test]
|
||||
@@ -897,6 +1152,7 @@ fn a_harmful_go_wounds_each_hit_once_and_a_missile_arrival_always() {
|
||||
target_mask: 0x2,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
assert_eq!(wounds(&mut app), expected, "instant GO of spell {spell_id}");
|
||||
@@ -1040,6 +1296,7 @@ fn missile_spawn_defers_iff_the_cast_kit_animates() {
|
||||
target_mask: 0x2,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
app.update();
|
||||
@@ -1126,6 +1383,7 @@ fn a_targetless_dest_go_spawns_a_ground_missile_whose_arrival_sounds_at_the_poin
|
||||
target_mask: 0x40,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
let spawns: Vec<_> = app
|
||||
@@ -1157,6 +1415,7 @@ fn a_targetless_dest_go_spawns_a_ground_missile_whose_arrival_sounds_at_the_poin
|
||||
spell_id: GROUND,
|
||||
kind: CastEventKind::GroundImpact { pos: at },
|
||||
seq: 2,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
let sounds: Vec<_> = app
|
||||
@@ -1950,6 +2209,7 @@ fn a_state_kits_anim_is_a_recompute_and_never_a_second_play() {
|
||||
target_mask: 0x2,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
|
||||
@@ -2485,7 +2745,9 @@ fn esc_with_a_cursor_up_leaves_the_running_channels_hold_and_loop() {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound: AM_HUM,
|
||||
} => loops.rang(entity, spell_id, AM_HUM),
|
||||
cast_hold,
|
||||
at,
|
||||
} => loops.rang(entity, (spell_id, AM_HUM), cast_hold, at),
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
loops.stop_hold(entity, spell_id);
|
||||
}
|
||||
@@ -2494,7 +2756,7 @@ fn esc_with_a_cursor_up_leaves_the_running_channels_hold_and_loop() {
|
||||
}
|
||||
assert_eq!(
|
||||
loops.held(me),
|
||||
Some((ARCANE_MISSILES, AM_HUM)),
|
||||
[(ARCANE_MISSILES, AM_HUM)],
|
||||
"Blizzard's reap stops none of the channel's sound (got {after:?})"
|
||||
);
|
||||
}
|
||||
@@ -2531,7 +2793,9 @@ fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound: AUTO_SHOT_LOOP,
|
||||
} => loops.rang(entity, spell_id, AUTO_SHOT_LOOP),
|
||||
cast_hold,
|
||||
at,
|
||||
} => loops.rang(entity, (spell_id, AUTO_SHOT_LOOP), cast_hold, at),
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
loops.stop_hold(entity, spell_id);
|
||||
}
|
||||
@@ -2595,7 +2859,7 @@ fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
],
|
||||
);
|
||||
assert_eq!(hold(&app, hunter), Some(AUTO_SHOT));
|
||||
assert_eq!(loops.held(hunter), Some((AUTO_SHOT, AUTO_SHOT_LOOP)));
|
||||
assert_eq!(loops.held(hunter), [(AUTO_SHOT, AUTO_SHOT_LOOP)]);
|
||||
|
||||
let reaped = frame(
|
||||
&mut app,
|
||||
@@ -2603,7 +2867,7 @@ fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
&[cast_event(hunter, ARCANE_SHOT, CastEventKind::Go)],
|
||||
);
|
||||
assert_eq!(hold(&app, hunter), None, "the caster's Auto Shot hold");
|
||||
assert_eq!(loops.held(hunter), None, "and its loop");
|
||||
assert_eq!(loops.held(hunter), [], "and its loop");
|
||||
assert_eq!(
|
||||
reaped,
|
||||
vec![(hunter, ARCANE_SHOT), (hunter, AUTO_SHOT)],
|
||||
@@ -2612,7 +2876,7 @@ fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
assert_eq!(hold(&app, other), Some(AUTO_SHOT), "another unit's hold");
|
||||
assert_eq!(
|
||||
loops.held(other),
|
||||
Some((AUTO_SHOT, AUTO_SHOT_LOOP)),
|
||||
[(AUTO_SHOT, AUTO_SHOT_LOOP)],
|
||||
"and its loop"
|
||||
);
|
||||
|
||||
@@ -2629,7 +2893,7 @@ fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
&[cast_event(hunter, ARCANE_SHOT, CastEventKind::Go)],
|
||||
);
|
||||
assert_eq!(hold(&app, hunter), Some(AUTO_SHOT));
|
||||
assert_eq!(loops.held(hunter), Some((AUTO_SHOT, AUTO_SHOT_LOOP)));
|
||||
assert_eq!(loops.held(hunter), [(AUTO_SHOT, AUTO_SHOT_LOOP)]);
|
||||
}
|
||||
|
||||
/// A GO of `hits` and `misses` (target, code, reflect byte) under `target_mask`, at `dest`.
|
||||
@@ -2649,6 +2913,7 @@ fn launcher_go(
|
||||
target_mask,
|
||||
ammo_display_id: None,
|
||||
seq: 1,
|
||||
at: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2789,6 +3054,7 @@ fn a_travelling_spell_without_a_missile_or_ammo_flies_nothing() {
|
||||
target_mask: 0x2,
|
||||
ammo_display_id,
|
||||
seq: 1,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
let spawns = app
|
||||
|
||||
@@ -10,6 +10,8 @@ use benilla_formats::{
|
||||
CharSections, CharacterGeosets, CreatureCatalog, GameObjectCatalog,
|
||||
};
|
||||
use benilla_protocol::EntityKind;
|
||||
use bevy::ecs::schedule::ScheduleConfigs;
|
||||
use bevy::ecs::system::ScheduleSystem;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::net::NetEntity;
|
||||
@@ -54,7 +56,7 @@ pub(crate) mod corpse;
|
||||
|
||||
mod live_display;
|
||||
use live_display::{refresh_live_display, tick_scale_ease};
|
||||
pub(crate) use live_display::{AppliedDisplay, DisplaySwapped};
|
||||
pub(crate) use live_display::{AppliedDisplay, DisplayRebuilt, DisplaySwapped};
|
||||
|
||||
/// Terrain conform: a model flagged `GlobalModelFlags & 3 ∈ {1,3}` tilts to the ground.
|
||||
mod conform;
|
||||
@@ -646,6 +648,22 @@ fn publish_world_units(
|
||||
}
|
||||
}
|
||||
|
||||
/// A display swap and a rig heal, then the frame's kit starts. A swap or heal ends what the unit
|
||||
/// held before its visual goes, so none of this frame's starts spawns on the body it takes; the
|
||||
/// starts then go in wire order, and those the packets put before the rebuild end at its place
|
||||
/// ([`spell_fx::resolve_spell_fx`]). The rebuild's replayed kits ring in the same frame, after the
|
||||
/// stop it raised ([`crate::creature_anim::replay_rebuilt_kit_sounds`]).
|
||||
fn rebuild_then_start_kits() -> ScheduleConfigs<ScheduleSystem> {
|
||||
(
|
||||
(refresh_live_display, live_display::heal_rig_starved).chain(),
|
||||
(
|
||||
resolve_spell_fx,
|
||||
crate::creature_anim::replay_rebuilt_kit_sounds,
|
||||
),
|
||||
)
|
||||
.chain()
|
||||
}
|
||||
|
||||
/// Loads the display catalogs at startup and each frame gives every net entity its visual.
|
||||
pub(crate) struct EntitiesPlugin;
|
||||
|
||||
@@ -671,6 +689,7 @@ impl Plugin for EntitiesPlugin {
|
||||
// A display swap's rebuild edge, for the impact-kit replay the reference runs at the end
|
||||
// of `0x60abe0`.
|
||||
.add_message::<live_display::DisplaySwapped>()
|
||||
.add_message::<live_display::DisplayRebuilt>()
|
||||
.add_systems(Startup, setup_entities.after(AssetSet::Open))
|
||||
// The eviction ahead of the VM pass, whose sends read the item displays for a ranged
|
||||
// spell's precast visual (`0x60d450`).
|
||||
@@ -709,7 +728,7 @@ impl Plugin for EntitiesPlugin {
|
||||
// 20-element ceiling.
|
||||
(resolve_equipment, resolve_corpse_equipment),
|
||||
// Spell effects and missiles create `SpellFx` entries too.
|
||||
resolve_spell_fx,
|
||||
rebuild_then_start_kits(),
|
||||
move_missiles,
|
||||
spawn_missiles,
|
||||
// The dest-anchored lane's three independent producers also create entries.
|
||||
@@ -745,14 +764,9 @@ impl Plugin for EntitiesPlugin {
|
||||
// A mount change re-seats the rig on the mount's attachment 0 or back, as the
|
||||
// reference re-parents the body model (`0x712f70`, `0x713020`).
|
||||
reseat_mounts,
|
||||
// A display swap rebuilds, a scale change eases over the reference's 2 s, and a
|
||||
// unit denied a palette rig rebuilds once the table has room.
|
||||
(
|
||||
refresh_live_display,
|
||||
tick_scale_ease,
|
||||
live_display::heal_rig_starved,
|
||||
)
|
||||
.chain(),
|
||||
// A scale change eases over the reference's 2 s, after attach so a rebuild's snap
|
||||
// never draws.
|
||||
tick_scale_ease,
|
||||
)
|
||||
.chain()
|
||||
.in_set(EntityVisualsSet)
|
||||
|
||||
@@ -891,6 +891,7 @@ mod tests {
|
||||
spell_id: CHAIN_SPELL,
|
||||
class: FxClass::Hold,
|
||||
force: true,
|
||||
at: None,
|
||||
});
|
||||
app.update();
|
||||
assert_eq!(
|
||||
|
||||
@@ -166,6 +166,9 @@ pub(super) fn arm_ground_effects(
|
||||
entity: anchor,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold: false,
|
||||
// A ground arrival of the frame, after every packet.
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,12 @@
|
||||
//! The reference's display handler rebuilds the model (`0x60abe0`) when the display record changed
|
||||
//! (`0x60ae10`, against `[unit+0xb34]`), re-resolving its model facts (`0x60afb0`) and the stand or
|
||||
//! ride animation (`0x60ce70`): an instant swap, a ghost's revive too. Its scale handler eases
|
||||
//! over 2 s with a cosine smoothstep (`0x614bbf`). Here a swap tears the visual down for
|
||||
//! `attach_entity_visuals` to rebuild without the spawn fade; the unit's
|
||||
//! [`super::spell_fx::FxAttached`] list outlives it, as the reference's per-unit `+0xb4` effect
|
||||
//! list does, so persistent effects re-spawn on the new body.
|
||||
//! over 2 s with a cosine smoothstep (`0x614bbf`). A unit swaps on the update's own rebuild
|
||||
//! ([`DisplayRebuilt`]), so a new display naming the same records keeps the body, as `0x60ae10`
|
||||
//! keeps it; a game object or corpse swaps on any new id. Here a swap tears the visual down for
|
||||
//! `attach_entity_visuals` to rebuild without the spawn fade, first ending the unit's spell effects
|
||||
//! as the rebuild's `0x60ac10` loop does ([`super::spell_fx::RebuildFx`]); the auras' and the
|
||||
//! channel's re-spawn on the new body.
|
||||
|
||||
use benilla_protocol::EntityKind;
|
||||
use bevy::prelude::*;
|
||||
@@ -21,16 +23,32 @@ use super::{Creatures, VisualAttached};
|
||||
/// The reference's scale-ease window: 2 s, cosine smoothstep (`0x614bbf`).
|
||||
const SCALE_EASE_SECS: f32 = 2.0;
|
||||
|
||||
/// The display id the visual was built with, cube included: [`refresh_live_display`]'s diff key.
|
||||
/// The display id the visual was built with, cube included: [`refresh_live_display`]'s diff key
|
||||
/// for a game object or corpse.
|
||||
#[derive(Component)]
|
||||
pub(crate) struct AppliedDisplay(pub(crate) Option<u32>);
|
||||
|
||||
/// A live display swap tore this entity's visual down. The reference's rebuild ends by replaying
|
||||
/// the pending morph's impact kit (`0x60ad67`), which `crate::creature_anim`'s morph-latch watcher
|
||||
/// does on this edge.
|
||||
/// The reference rebuilt this unit's display (`0x60abe0`): the display watcher (`0x6049b5`), the
|
||||
/// health watcher's return to life (`0x604835`) or slot 3 (`0x5fbe28`) found a new record set
|
||||
/// (`0x60ae10`). `at` is that watcher's place among the packet's edges.
|
||||
#[derive(Message, Clone, Copy, Debug)]
|
||||
pub(crate) struct DisplayRebuilt {
|
||||
pub(crate) entity: Entity,
|
||||
pub(crate) at: crate::lanes::Stamp,
|
||||
/// The row it resolved (`+0xb34`, `0x60afb0`), which the body is built from: a later
|
||||
/// packet's id naming the same records (`0x60ae10`) leaves it.
|
||||
pub(crate) display_id: u32,
|
||||
}
|
||||
|
||||
/// A unit's display rebuild, or a game object's or corpse's new display id, which tore down the
|
||||
/// visual it had. The reference's rebuild ends by replaying the pending morph's impact kit
|
||||
/// (`0x60ad67`), which `crate::creature_anim`'s morph-latch watcher does on this edge.
|
||||
#[derive(Message, Clone, Copy)]
|
||||
pub(crate) struct DisplaySwapped {
|
||||
pub(crate) entity: Entity,
|
||||
/// A unit's rebuild's place ([`DisplayRebuilt::at`]), at which `spell_fx` ends the kit starts
|
||||
/// the wire put before it; `None` for a game object's or corpse's new id.
|
||||
pub(crate) at: Option<crate::lanes::Stamp>,
|
||||
}
|
||||
|
||||
/// A render-scale ease toward [`NetEntity::scale`], written absolutely each tick so a mid-ease
|
||||
@@ -64,10 +82,31 @@ fn live_display_id(kind: EntityKind, store: &ObjectStore) -> Option<u32> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Diff each attached entity's live appearance against what its visual was built with: a display
|
||||
/// move swaps the model, a scale move arms the 2 s ease, and a change of the native display or
|
||||
/// `SCALE_X` restamps [`CollisionHeight`]. Mount children carry no [`ObjectStore`]: their display
|
||||
/// is the host's field, diffed by `mount::reseat_mounts`.
|
||||
/// A unit's rebuild at `at` (`0x60abe0`), short of its body: the loop `0x60ac10` stops every
|
||||
/// effect the unit holds, kit sounds included (`0x61fedc`), and the tail replays the morph latch
|
||||
/// (`0x60ad67`) off [`DisplaySwapped`].
|
||||
fn rebuild_edges(
|
||||
commands: &mut Commands,
|
||||
fx: &mut super::spell_fx::RebuildFx,
|
||||
swapped: &mut MessageWriter<DisplaySwapped>,
|
||||
kit_sounds: &mut MessageWriter<crate::creature_anim::SpellKitSound>,
|
||||
entity: Entity,
|
||||
at: crate::lanes::Stamp,
|
||||
) {
|
||||
swapped.write(DisplaySwapped {
|
||||
entity,
|
||||
at: Some(at),
|
||||
});
|
||||
fx.end_all(commands, entity, super::spell_fx::Rebuild::Display);
|
||||
kit_sounds.write(crate::creature_anim::SpellKitSound::Rebuilt { entity, at });
|
||||
}
|
||||
|
||||
/// Each attached entity's live appearance against what its visual was built with: a unit's
|
||||
/// rebuild ([`DisplayRebuilt`]) or a game object's or corpse's new display id swaps the model, a
|
||||
/// scale move arms the 2 s ease, and a change of the native display or `SCALE_X` restamps
|
||||
/// [`CollisionHeight`]. A unit rebuilt before its visual attached builds the new display.
|
||||
/// Mount children carry no [`ObjectStore`]: their display is the host's field, diffed by
|
||||
/// `mount::reseat_mounts`.
|
||||
#[allow(clippy::type_complexity)]
|
||||
pub(super) fn refresh_live_display(
|
||||
mut commands: Commands,
|
||||
@@ -88,45 +127,98 @@ pub(super) fn refresh_live_display(
|
||||
Without<benilla_world::model_fade::DespawnFade>,
|
||||
),
|
||||
>,
|
||||
mut unattached: Query<
|
||||
&mut NetEntity,
|
||||
(
|
||||
Without<VisualAttached>,
|
||||
Without<benilla_world::model_fade::DespawnFade>,
|
||||
),
|
||||
>,
|
||||
mut rebuilds: MessageReader<DisplayRebuilt>,
|
||||
mut swapped: MessageWriter<DisplaySwapped>,
|
||||
mut fx: super::spell_fx::RebuildFx,
|
||||
mut kit_sounds: MessageWriter<crate::creature_anim::SpellKitSound>,
|
||||
) {
|
||||
// This frame's unit rebuilds, the latest of each unit's with the row it resolved: it ends
|
||||
// whatever came before it.
|
||||
let mut rebuilt: bevy::ecs::entity::EntityHashMap<(crate::lanes::Stamp, u32)> = default();
|
||||
for r in rebuilds.read() {
|
||||
let latest = rebuilt.entry(r.entity).or_insert((r.at, r.display_id));
|
||||
if r.at >= latest.0 {
|
||||
*latest = (r.at, r.display_id);
|
||||
}
|
||||
}
|
||||
for (&entity, &(at, row)) in &rebuilt {
|
||||
// A unit with no body yet rebuilds all the same, short of the teardown: what it held
|
||||
// ends, the morph latch replays, and the body built later is the row's.
|
||||
if let Ok(mut net) = unattached.get_mut(entity) {
|
||||
net.display_id = Some(row);
|
||||
rebuild_edges(
|
||||
&mut commands,
|
||||
&mut fx,
|
||||
&mut swapped,
|
||||
&mut kit_sounds,
|
||||
entity,
|
||||
at,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (entity, guid, mut net, store, applied, height, tf) in &mut entities {
|
||||
// ── The display-id swap ──────────────────────────────────────────────────────────────
|
||||
let live = live_display_id(net.kind, store);
|
||||
if let Some(live) = live {
|
||||
if applied.0 != Some(live) {
|
||||
info!(
|
||||
"display swap: guid {:016x} {:?} {:?} -> {} (instant, the 0x60abe0 rebuild)",
|
||||
guid.0, net.kind, applied.0, live
|
||||
);
|
||||
net.display_id = Some(live);
|
||||
swapped.write(DisplaySwapped { entity });
|
||||
// `attach_entity_visuals` rebuilds from scratch, fade-skipped by `Reattached`.
|
||||
commands
|
||||
.entity(entity)
|
||||
.despawn_related::<Children>()
|
||||
.remove::<(
|
||||
VisualAttached,
|
||||
AppliedDisplay,
|
||||
super::equipment::AppliedEquipment,
|
||||
super::mount::AppliedMount,
|
||||
super::mount::MountChild,
|
||||
AnimationPlayer,
|
||||
bevy::animation::transition::AnimationTransitions,
|
||||
AnimationGraphHandle,
|
||||
benilla_assets::ModelAnimations,
|
||||
crate::creature_anim::AnimDriver,
|
||||
(
|
||||
benilla_world::rig_anim::RigPose,
|
||||
crate::creature_anim::BodyTwist,
|
||||
benilla_world::rig_anim::GlobalSeqDrive,
|
||||
),
|
||||
benilla_world::rig_palette::RigSkin,
|
||||
super::BoneAttach,
|
||||
super::equipment::HeldAttached,
|
||||
)>()
|
||||
.insert(super::equipment::Reattached);
|
||||
// ── The display swap ─────────────────────────────────────────────────────────────────
|
||||
// A unit takes the row its update's rebuild resolved; any other kind, a new field.
|
||||
let swap = match net.kind {
|
||||
EntityKind::Unit | EntityKind::Player => {
|
||||
rebuilt.get(&entity).map(|&(at, row)| (row, Some(at)))
|
||||
}
|
||||
_ => live_display_id(net.kind, store)
|
||||
.filter(|&live| applied.0 != Some(live))
|
||||
.map(|live| (live, None)),
|
||||
};
|
||||
if let Some((to, at)) = swap {
|
||||
info!(
|
||||
"display swap: guid {:016x} {:?} {:?} -> {} (instant, the 0x60abe0 rebuild)",
|
||||
guid.0, net.kind, applied.0, to
|
||||
);
|
||||
net.display_id = Some(to);
|
||||
match at {
|
||||
Some(at) => rebuild_edges(
|
||||
&mut commands,
|
||||
&mut fx,
|
||||
&mut swapped,
|
||||
&mut kit_sounds,
|
||||
entity,
|
||||
at,
|
||||
),
|
||||
None => {
|
||||
swapped.write(DisplaySwapped { entity, at: None });
|
||||
fx.end_all(&mut commands, entity, super::spell_fx::Rebuild::Display);
|
||||
}
|
||||
}
|
||||
// `attach_entity_visuals` rebuilds from scratch, fade-skipped by `Reattached`.
|
||||
commands
|
||||
.entity(entity)
|
||||
.despawn_related::<Children>()
|
||||
.remove::<(
|
||||
VisualAttached,
|
||||
AppliedDisplay,
|
||||
super::equipment::AppliedEquipment,
|
||||
super::mount::AppliedMount,
|
||||
super::mount::MountChild,
|
||||
AnimationPlayer,
|
||||
bevy::animation::transition::AnimationTransitions,
|
||||
AnimationGraphHandle,
|
||||
benilla_assets::ModelAnimations,
|
||||
crate::creature_anim::AnimDriver,
|
||||
(
|
||||
benilla_world::rig_anim::RigPose,
|
||||
crate::creature_anim::BodyTwist,
|
||||
benilla_world::rig_anim::GlobalSeqDrive,
|
||||
),
|
||||
benilla_world::rig_palette::RigSkin,
|
||||
super::BoneAttach,
|
||||
super::equipment::HeldAttached,
|
||||
)>()
|
||||
.insert(super::equipment::Reattached);
|
||||
}
|
||||
|
||||
// ── The scale ease ───────────────────────────────────────────────────────────────────
|
||||
@@ -218,6 +310,7 @@ pub(super) fn heal_rig_starved(
|
||||
Without<benilla_world::model_fade::DespawnFade>,
|
||||
),
|
||||
>,
|
||||
mut fx: super::spell_fx::RebuildFx,
|
||||
) {
|
||||
if starved.is_empty() || palettes.slot_headroom() < HEAL_MIN_HEADROOM {
|
||||
return;
|
||||
@@ -227,6 +320,7 @@ pub(super) fn heal_rig_starved(
|
||||
"rig heal: guid {:016x} was denied a palette rig at attach — rebuilding (0x60abe0 shape)",
|
||||
guid.0
|
||||
);
|
||||
fx.end_all(&mut commands, entity, super::spell_fx::Rebuild::Heal);
|
||||
commands
|
||||
.entity(entity)
|
||||
.despawn_related::<Children>()
|
||||
@@ -331,6 +425,8 @@ mod tests {
|
||||
let mut app = App::new();
|
||||
app.init_resource::<benilla_world::rig_palette::RigPalettes>();
|
||||
app.add_message::<DisplaySwapped>();
|
||||
app.add_message::<DisplayRebuilt>();
|
||||
app.add_message::<crate::creature_anim::SpellKitSound>();
|
||||
app.add_systems(Update, (refresh_live_display, heal_rig_starved));
|
||||
let unit = |app: &mut App, display: u32| {
|
||||
app.world_mut()
|
||||
@@ -356,6 +452,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.entity_mut(healed)
|
||||
.insert(benilla_world::rig_palette::RigStarved);
|
||||
rebuild(&mut app, swapped);
|
||||
app.update();
|
||||
for (e, what) in [(swapped, "the swap"), (healed, "the heal")] {
|
||||
let e = app.world().entity(e);
|
||||
@@ -374,6 +471,150 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The update's rebuild of `unit` to the descriptor's display, as its display watcher
|
||||
/// announces it, at its stamp.
|
||||
fn rebuild(app: &mut App, unit: Entity) -> crate::lanes::Stamp {
|
||||
rebuild_to(app, unit, 8)
|
||||
}
|
||||
|
||||
/// [`rebuild`] to the row `display_id`.
|
||||
fn rebuild_to(app: &mut App, unit: Entity, display_id: u32) -> crate::lanes::Stamp {
|
||||
let at = crate::lanes::stamp();
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<DisplayRebuilt>>()
|
||||
.write(DisplayRebuilt {
|
||||
entity: unit,
|
||||
at,
|
||||
display_id,
|
||||
});
|
||||
at
|
||||
}
|
||||
|
||||
/// An app running the swap, and a unit built in display 7 whose descriptor now says 8.
|
||||
fn displayed_unit(attached: bool) -> (App, Entity) {
|
||||
let mut app = App::new();
|
||||
app.init_resource::<benilla_world::rig_palette::RigPalettes>();
|
||||
app.add_message::<DisplaySwapped>();
|
||||
app.add_message::<DisplayRebuilt>();
|
||||
app.add_message::<crate::creature_anim::SpellKitSound>();
|
||||
app.add_systems(Update, refresh_live_display);
|
||||
let unit = app
|
||||
.world_mut()
|
||||
.spawn((
|
||||
crate::net::Guid(0xB0B),
|
||||
NetEntity {
|
||||
kind: EntityKind::Unit,
|
||||
display_id: Some(7),
|
||||
scale: 1.0,
|
||||
},
|
||||
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(
|
||||
benilla_protocol::field::FIELD_UNIT_DISPLAYID,
|
||||
8,
|
||||
)])),
|
||||
Transform::default(),
|
||||
))
|
||||
.id();
|
||||
if attached {
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert((VisualAttached, AppliedDisplay(Some(7))));
|
||||
}
|
||||
(app, unit)
|
||||
}
|
||||
|
||||
/// `0x60abe0` rebuilds only when `0x60ae10` finds a new record set (`0x60abeb`): a display
|
||||
/// naming the same extra, model and sound rows keeps the body, so a new id alone swaps nothing.
|
||||
#[test]
|
||||
fn a_unit_swaps_only_on_the_updates_rebuild_not_on_a_new_id() {
|
||||
let (mut app, unit) = displayed_unit(true);
|
||||
app.update();
|
||||
assert!(
|
||||
app.world().entity(unit).contains::<VisualAttached>(),
|
||||
"a new id the rebuild's gate passed over keeps the body"
|
||||
);
|
||||
rebuild(&mut app, unit);
|
||||
app.update();
|
||||
let e = app.world().entity(unit);
|
||||
assert!(!e.contains::<VisualAttached>(), "the rebuild swaps it");
|
||||
assert_eq!(e.get::<NetEntity>().unwrap().display_id, Some(8));
|
||||
}
|
||||
|
||||
/// The rebuild's loop `0x60ac10` stops the kit sounds it links (`0x61fedc`) with the rest:
|
||||
/// the swap hands the sound side the rebuild's stamp, to stop the hold loops rung before it.
|
||||
#[test]
|
||||
fn a_units_rebuild_hands_its_stamp_to_the_kit_sounds() {
|
||||
use crate::creature_anim::SpellKitSound;
|
||||
let (mut app, unit) = displayed_unit(true);
|
||||
let at = rebuild(&mut app, unit);
|
||||
app.update();
|
||||
let edges: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.filter_map(|ev| match ev {
|
||||
SpellKitSound::Rebuilt { entity, at } => Some((entity, at)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(edges, [(unit, at)]);
|
||||
}
|
||||
|
||||
/// The rebuild resolves its row at its watcher (`0x60afb0`), and a later packet's id naming
|
||||
/// the same records leaves it (`0x60ae10`): the body is the rebuilt row's, not the frame's
|
||||
/// last field's, built or not.
|
||||
#[test]
|
||||
fn a_rebuild_builds_the_row_it_resolved_not_the_frames_last_field() {
|
||||
for attached in [true, false] {
|
||||
let (mut app, unit) = displayed_unit(attached);
|
||||
rebuild_to(&mut app, unit, 9);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
app.world().get::<NetEntity>(unit).unwrap().display_id,
|
||||
Some(9),
|
||||
"attached: {attached}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The reference rebuilds the unit, built or not (`0x60abe0`): with no body yet only the
|
||||
/// teardown is moot, so the effects end, the kit sounds stop and the morph latch replays.
|
||||
#[test]
|
||||
fn a_unit_with_no_body_yet_rebuilds_short_of_the_teardown() {
|
||||
use crate::creature_anim::SpellKitSound;
|
||||
let (mut app, unit) = displayed_unit(false);
|
||||
let at = rebuild(&mut app, unit);
|
||||
app.update();
|
||||
let swaps: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<DisplaySwapped>>()
|
||||
.drain()
|
||||
.map(|s| (s.entity, s.at))
|
||||
.collect();
|
||||
assert_eq!(swaps, [(unit, Some(at))], "the morph latch's replay edge");
|
||||
let stops: Vec<_> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.filter_map(|ev| match ev {
|
||||
SpellKitSound::Rebuilt { entity, at } => Some((entity, at)),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(stops, [(unit, at)], "the kit sounds' stop");
|
||||
}
|
||||
|
||||
/// A unit rebuilt before its visual attached builds the new display, not its create's.
|
||||
#[test]
|
||||
fn a_unit_rebuilt_before_its_visual_attached_builds_the_new_display() {
|
||||
let (mut app, unit) = displayed_unit(false);
|
||||
rebuild(&mut app, unit);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
app.world().get::<NetEntity>(unit).unwrap().display_id,
|
||||
Some(8)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_torn_down_starved_unit_is_not_rebuilt() {
|
||||
let mut app = App::new();
|
||||
|
||||
@@ -446,6 +446,7 @@ fn arrival_handoff(
|
||||
spell_id,
|
||||
kind,
|
||||
seq: play_seq.next(),
|
||||
at: None,
|
||||
};
|
||||
match missile.aim {
|
||||
Aim::Unit {
|
||||
|
||||
@@ -9,7 +9,8 @@
|
||||
//!
|
||||
//! A persistent instance lives until its spell's [`SpellKitFx::Reap`] (`0x614150`); a
|
||||
//! self-terminating one despawns after one pass of its model's sequence 0, a span clock standing in
|
||||
//! for the client's completion callback.
|
||||
//! for the client's completion callback. A rebuild of the unit's visual ends both first
|
||||
//! ([`RebuildFx`]).
|
||||
|
||||
mod lifecycle;
|
||||
|
||||
@@ -527,11 +528,17 @@ pub(super) fn tend_world_plants(
|
||||
}
|
||||
}
|
||||
|
||||
/// Apply the router's [`SpellKitFx`] edges per unit in emission order: `Begin` records instances,
|
||||
/// `Reap` decays the spell's persistent ones, so a GO's precast dies before its release flash.
|
||||
/// Apply the routers' [`SpellKitFx`] edges per unit in the order the packets raised them
|
||||
/// ([`SpellKitFx::at`], the frame's own last): `Begin` records instances, `Reap` decays the
|
||||
/// spell's persistent ones, so a GO's precast dies before its release flash. A display rebuild
|
||||
/// this frame ([`crate::entities::DisplaySwapped::at`]) has already ended what the unit held; the
|
||||
/// edges the wire put before it end there too, as the rebuild's loop `0x60ac10` stops what was
|
||||
/// started before the display's watcher ran ([`Rebuild::Display`]), and those after it stand.
|
||||
#[allow(clippy::too_many_arguments)] // one Bevy system's full input set
|
||||
pub(super) fn resolve_spell_fx(
|
||||
mut commands: Commands,
|
||||
mut events: MessageReader<SpellKitFx>,
|
||||
mut swaps: MessageReader<crate::entities::DisplaySwapped>,
|
||||
mut units: Query<&mut FxAttached>,
|
||||
fx: Option<ResMut<SpellFx>>,
|
||||
time: Res<Time>,
|
||||
@@ -540,14 +547,18 @@ pub(super) fn resolve_spell_fx(
|
||||
) {
|
||||
let Some(mut fx) = fx else { return };
|
||||
let now = time.elapsed_secs();
|
||||
let mut rebuilt: EntityHashMap<crate::lanes::Stamp> = EntityHashMap::default();
|
||||
for swap in swaps.read() {
|
||||
if let Some(at) = swap.at {
|
||||
let latest = rebuilt.entry(swap.entity).or_insert(at);
|
||||
*latest = (*latest).max(at);
|
||||
}
|
||||
}
|
||||
let mut ops: EntityHashMap<Vec<&SpellKitFx>> = EntityHashMap::default();
|
||||
for ev in events.read() {
|
||||
let entity = match ev {
|
||||
SpellKitFx::Begin { entity, .. } | SpellKitFx::Reap { entity, .. } => *entity,
|
||||
};
|
||||
ops.entry(entity).or_default().push(ev);
|
||||
ops.entry(ev.entity()).or_default().push(ev);
|
||||
}
|
||||
for (entity, edges) in ops {
|
||||
for (entity, mut edges) in ops {
|
||||
if commands.get_entity(entity).is_err() {
|
||||
continue;
|
||||
}
|
||||
@@ -556,7 +567,22 @@ pub(super) fn resolve_spell_fx(
|
||||
Some(mut att) => std::mem::take(&mut att.instances),
|
||||
None => Vec::new(),
|
||||
};
|
||||
for edge in edges {
|
||||
// Wire order, stable within a packet; an edge the frame raised comes after every packet.
|
||||
edges.sort_by_key(|e| (e.at().is_none(), e.at()));
|
||||
let cut = rebuilt
|
||||
.get(&entity)
|
||||
.map(|&rebuild| edges.partition_point(|e| e.at().is_some_and(|at| at < rebuild)));
|
||||
let len = edges.len();
|
||||
for (i, edge) in edges.into_iter().enumerate() {
|
||||
if cut == Some(i) {
|
||||
end_for_rebuild(
|
||||
&mut instances,
|
||||
Rebuild::Display,
|
||||
entity,
|
||||
&mut commands,
|
||||
&mut emitters,
|
||||
);
|
||||
}
|
||||
match edge {
|
||||
SpellKitFx::Begin {
|
||||
spell_id,
|
||||
@@ -623,6 +649,15 @@ pub(super) fn resolve_spell_fx(
|
||||
}
|
||||
}
|
||||
}
|
||||
if cut == Some(len) {
|
||||
end_for_rebuild(
|
||||
&mut instances,
|
||||
Rebuild::Display,
|
||||
entity,
|
||||
&mut commands,
|
||||
&mut emitters,
|
||||
);
|
||||
}
|
||||
match units.get_mut(entity) {
|
||||
Ok(mut att) => att.instances = instances,
|
||||
Err(_) => {
|
||||
@@ -632,10 +667,11 @@ pub(super) fn resolve_spell_fx(
|
||||
}
|
||||
}
|
||||
|
||||
/// Hand an ending instance's emitters to the drain, the half of the teardown `0x6203e0` that is not
|
||||
/// a despawn: emission stops and live particles age out, since the reference gates the particle
|
||||
/// draw on the live count (`0x7b4b46`) while the meshes leave the draw list at once (`0x719207`).
|
||||
fn drain_instance_emitters(
|
||||
/// The teardown `0x6203e0` of a spawned instance: the root and its meshes leave the draw list at
|
||||
/// once (`0x719207`), while its emitters drain, emission stopping and live particles ageing out,
|
||||
/// as the reference gates the particle draw on the live count (`0x7b4b46`).
|
||||
fn end_root(
|
||||
commands: &mut Commands,
|
||||
emitters: &mut Query<&mut benilla_world::particles::ParticleEmitter>,
|
||||
root: Entity,
|
||||
) {
|
||||
@@ -644,6 +680,75 @@ fn drain_instance_emitters(
|
||||
e.drain_on_owner_loss();
|
||||
}
|
||||
}
|
||||
commands.entity(root).despawn();
|
||||
}
|
||||
|
||||
/// Which rebuild of a unit's visual ends its instances, and so which come back on the new body.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
|
||||
pub(super) enum Rebuild {
|
||||
/// The reference's display rebuild `0x60abe0`. It stops every effect on the unit's list through
|
||||
/// `0x6203e0` (`0x60ac10`), a world plant too, which `0x61fcf0` links on the same list
|
||||
/// (`0x61fdbf`), then plays kind 2 again and nothing else that lives on: the aura slots' state
|
||||
/// kits (`0x5ff130` at `0x60ada6`) and the channel kit (`0x612a30` at `0x60adad`, kind 2 at
|
||||
/// `0x612b2b`). A [`FxStage::State`] instance re-arms; a precast loop, the loot sparkle (hung
|
||||
/// again only by `0x6005d0`'s own callers), a one-shot or a decaying one is dropped.
|
||||
Display,
|
||||
/// benilla's rig heal, a rebuild the reference never runs: what the unit had comes back, every
|
||||
/// persistent instance that is not decaying.
|
||||
Heal,
|
||||
}
|
||||
|
||||
/// End `instances` for `rebuild`: each spawned root goes through the teardown, and only what the
|
||||
/// rebuild brings back stays, pending its new body.
|
||||
fn end_for_rebuild(
|
||||
instances: &mut Vec<FxInstance>,
|
||||
rebuild: Rebuild,
|
||||
unit: Entity,
|
||||
commands: &mut Commands,
|
||||
emitters: &mut Query<&mut benilla_world::particles::ParticleEmitter>,
|
||||
) {
|
||||
instances.retain_mut(|inst| {
|
||||
if let Some(root) = inst.root.take() {
|
||||
end_root(commands, emitters, root);
|
||||
}
|
||||
let re_arm = inst.persistent
|
||||
&& !inst.decaying
|
||||
&& (rebuild == Rebuild::Heal || inst.stage == FxStage::State);
|
||||
if benilla_assets::trace::enabled() {
|
||||
benilla_assets::trace::line(
|
||||
"fx",
|
||||
&format!(
|
||||
"kit rebuild end unit={unit} path={} {rebuild:?} re_arm={re_arm}",
|
||||
inst.path
|
||||
),
|
||||
);
|
||||
}
|
||||
re_arm
|
||||
});
|
||||
}
|
||||
|
||||
/// What a rebuild of a unit's visual needs to end the unit's instances first ([`Self::end_all`]).
|
||||
#[derive(bevy::ecs::system::SystemParam)]
|
||||
pub(super) struct RebuildFx<'w, 's> {
|
||||
lists: Query<'w, 's, &'static mut FxAttached>,
|
||||
emitters: Query<'w, 's, &'static mut benilla_world::particles::ParticleEmitter>,
|
||||
}
|
||||
|
||||
impl RebuildFx<'_, '_> {
|
||||
/// End `unit`'s instances for `rebuild` ([`end_for_rebuild`]). Called before the visual's
|
||||
/// despawn, so each root goes first and no later teardown meets a dead one.
|
||||
pub(super) fn end_all(&mut self, commands: &mut Commands, unit: Entity, rebuild: Rebuild) {
|
||||
let Ok(mut att) = self.lists.get_mut(unit) else {
|
||||
return;
|
||||
};
|
||||
end_for_rebuild(
|
||||
&mut att.instances,
|
||||
rebuild,
|
||||
unit,
|
||||
commands,
|
||||
&mut self.emitters,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The same-slot replace (`0x6208e0`): destroy each live node with the same `SpellVisualEffectName`
|
||||
@@ -664,9 +769,7 @@ fn replace_same_slot(
|
||||
return true;
|
||||
}
|
||||
if let Some(root) = i.root {
|
||||
// Through the shared teardown `0x6203e0`, so its particles finish.
|
||||
drain_instance_emitters(emitters, root);
|
||||
commands.entity(root).despawn();
|
||||
end_root(commands, emitters, root);
|
||||
}
|
||||
false
|
||||
});
|
||||
@@ -700,9 +803,7 @@ fn reap_matching(
|
||||
.and_then(|dm| decay_span(dm.animations.as_ref()));
|
||||
let (Some(root), Some(span)) = (i.root, span) else {
|
||||
if let Some(root) = i.root {
|
||||
// Destroyed at once, through `0x6203e0` like any other, so its particles drain.
|
||||
drain_instance_emitters(emitters, root);
|
||||
commands.entity(root).despawn();
|
||||
end_root(commands, emitters, root); // destroyed at once
|
||||
}
|
||||
return false;
|
||||
};
|
||||
@@ -749,9 +850,7 @@ pub(super) fn attach_spell_fx(
|
||||
if let Some(expires) = inst.expires {
|
||||
if now >= expires {
|
||||
if let Some(root) = inst.root {
|
||||
// The `0x6203e0` teardown: the particles outlive the flash.
|
||||
drain_instance_emitters(&mut emitters, root);
|
||||
commands.entity(root).despawn();
|
||||
end_root(&mut commands, &mut emitters, root);
|
||||
}
|
||||
if benilla_assets::trace::enabled() {
|
||||
benilla_assets::trace::line(
|
||||
@@ -762,32 +861,9 @@ pub(super) fn attach_spell_fx(
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// A root lost with the unit's visual: the reference's rebuild `0x60abe0` drains the
|
||||
// effect list and re-creates what persists (`0x5ff130` auras, `0x612a30` channels), so
|
||||
// a persistent instance re-arms here and a one-shot or decaying one goes.
|
||||
if let Some(root) = inst.root {
|
||||
if commands.get_entity(root).is_ok() {
|
||||
return true;
|
||||
}
|
||||
if !inst.persistent || inst.decaying {
|
||||
if benilla_assets::trace::enabled() {
|
||||
benilla_assets::trace::line(
|
||||
"fx",
|
||||
&format!(
|
||||
"kit collateral drain unit={unit} path={} decaying={}",
|
||||
inst.path, inst.decaying
|
||||
),
|
||||
);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
inst.root = None;
|
||||
if benilla_assets::trace::enabled() {
|
||||
benilla_assets::trace::line(
|
||||
"fx",
|
||||
&format!("kit collateral re-create unit={unit} path={}", inst.path),
|
||||
);
|
||||
}
|
||||
// Spawned: only its own teardown or the rebuild's ([`RebuildFx`]) ends it.
|
||||
if inst.root.is_some() {
|
||||
return true;
|
||||
}
|
||||
// Pending: unspawnable flashes time out; a spawn sets the real span.
|
||||
if !inst.persistent && inst.expires.is_none() {
|
||||
@@ -955,6 +1031,7 @@ pub(super) fn fire_fx_anim_events(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::lanes::Stamp;
|
||||
use bevy::asset::AssetPlugin;
|
||||
use bevy::mesh::skinning::SkinnedMeshInverseBindposes;
|
||||
|
||||
@@ -1018,27 +1095,641 @@ mod tests {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The reference's rebuild (`0x60abe0`) drains every effect node and re-creates what persists.
|
||||
#[test]
|
||||
fn a_persistent_instance_whose_root_died_as_collateral_is_re_armed() {
|
||||
let (mut app, unit, roots) = standing(&[true, false]);
|
||||
// A display swap despawns the unit's whole visual.
|
||||
for root in roots {
|
||||
app.world_mut().entity_mut(root).despawn();
|
||||
// ---- the rebuild (`0x60abe0`): a display swap, and the rig heal that takes its shape ----
|
||||
|
||||
/// The cast flash's record, tag and model: a one-shot release kit at a hand.
|
||||
const FLASH: (u32, u16, &str) = (7, 0x16, "Spells\\CastFlash.mdx");
|
||||
/// A one-shot planted at the unit's feet (kit field 12), standing free of its visual.
|
||||
const PLANT: (u32, u16, &str) = (8, benilla_formats::WORLD_EFFECT_TAG, "Spells\\Ring.mdx");
|
||||
|
||||
/// The frame's rebuilds, kit starts and spawn pass in the plugin's order (its own
|
||||
/// `rebuild_then_start_kits`), on a clock the test advances.
|
||||
fn rebuilding() -> App {
|
||||
let mut app = App::new();
|
||||
app.add_plugins((
|
||||
MinimalPlugins.build().disable::<bevy::time::TimePlugin>(),
|
||||
AssetPlugin::default(),
|
||||
))
|
||||
.init_asset::<WowModelMaterial>()
|
||||
.init_asset::<benilla_assets::M2Model>()
|
||||
.init_asset::<SkinnedMeshInverseBindposes>()
|
||||
.init_resource::<Time>()
|
||||
.init_resource::<SpellFx>()
|
||||
.init_resource::<FxTintAnims>()
|
||||
.init_resource::<benilla_world::doodad_anim::UvAnimMaterials>()
|
||||
.init_resource::<benilla_world::mat_anim_table::MatAnimTable>()
|
||||
.init_resource::<benilla_world::rig_palette::RigPalettes>()
|
||||
.add_message::<SpellKitFx>()
|
||||
.add_message::<crate::entities::live_display::DisplaySwapped>()
|
||||
.add_message::<crate::entities::DisplayRebuilt>()
|
||||
.add_message::<crate::creature_anim::SpellKitSound>()
|
||||
.add_systems(
|
||||
Update,
|
||||
(crate::entities::rebuild_then_start_kits(), attach_spell_fx).chain(),
|
||||
);
|
||||
app
|
||||
}
|
||||
|
||||
/// One emitter anchored on `root`, spawned `Free` as every attached instance's is.
|
||||
fn emitter_on(app: &mut App, root: Entity) -> Entity {
|
||||
let em = benilla_assets::ModelEmitter {
|
||||
def: benilla_world::testing::plain_particle_def(),
|
||||
texture: Some(Handle::default()),
|
||||
bone_pivot: [0.0; 3],
|
||||
billboard: None,
|
||||
recursion: None,
|
||||
geometry: None,
|
||||
owner_reach: 0.0,
|
||||
water_bound: (Vec3::ZERO, 0.0),
|
||||
idle_seq: 0,
|
||||
};
|
||||
let world = app.world_mut();
|
||||
let e = particles::spawn_emitter(
|
||||
&mut world.commands(),
|
||||
&em,
|
||||
Transform::IDENTITY,
|
||||
particles::EmitterFrames {
|
||||
owner: Some((root, [0.0; 3])),
|
||||
anchor: Some(root),
|
||||
on_owner_loss: particles::OwnerLoss::Free,
|
||||
alpha: Some(root),
|
||||
light_node: None,
|
||||
},
|
||||
particles::EmitClock::Effect(None),
|
||||
)
|
||||
.expect("an emitter");
|
||||
world.flush();
|
||||
e
|
||||
}
|
||||
|
||||
/// A unit in display 7 with a built visual, `body` standing for its rig: a cast flash ending at
|
||||
/// 1 s and Ice Barrier's state hang under `body`, a ground plant stands free, and each root has
|
||||
/// one emitter. Returns the unit, the three roots and their emitters.
|
||||
fn mid_cast() -> (App, Entity, [Entity; 3], [Entity; 3]) {
|
||||
let mut app = rebuilding();
|
||||
let world = app.world_mut();
|
||||
let body = world
|
||||
.spawn((Transform::default(), GlobalTransform::default()))
|
||||
.id();
|
||||
let [flash_root, aura_root] = [(); 2].map(|_| {
|
||||
let root = world
|
||||
.spawn((Transform::default(), GlobalTransform::default()))
|
||||
.id();
|
||||
world.entity_mut(body).add_child(root);
|
||||
root
|
||||
});
|
||||
let plant_root = world.spawn(Transform::default()).id();
|
||||
let one_shot = |(effect, tag, path): (u32, u16, &str), root| FxInstance {
|
||||
spell_id: 116, // Frostbolt
|
||||
persistent: false,
|
||||
class: FxClass::Hold,
|
||||
stage: FxStage::OneShot,
|
||||
tag,
|
||||
effect,
|
||||
path: path.into(),
|
||||
root: Some(root),
|
||||
expires: Some(1.0),
|
||||
decaying: false,
|
||||
};
|
||||
let unit = built_unit(
|
||||
world,
|
||||
body,
|
||||
vec![
|
||||
one_shot(FLASH, flash_root),
|
||||
instance(aura_root, true),
|
||||
one_shot(PLANT, plant_root),
|
||||
],
|
||||
);
|
||||
world.entity_mut(plant_root).insert(WorldPlantFx {
|
||||
owner: unit,
|
||||
follow: false,
|
||||
});
|
||||
let roots = [flash_root, aura_root, plant_root];
|
||||
let emitters = roots.map(|root| emitter_on(&mut app, root));
|
||||
(app, unit, roots, emitters)
|
||||
}
|
||||
|
||||
/// A unit in display 7 whose visual is built, `body` standing for its rig, wearing `instances`.
|
||||
fn built_unit(world: &mut World, body: Entity, instances: Vec<FxInstance>) -> Entity {
|
||||
world
|
||||
.spawn((
|
||||
Transform::default(),
|
||||
GlobalTransform::default(),
|
||||
crate::entities::VisualAttached,
|
||||
crate::net::Guid(0xB0B),
|
||||
crate::net::NetEntity {
|
||||
kind: benilla_protocol::EntityKind::Unit,
|
||||
display_id: Some(7),
|
||||
scale: 1.0,
|
||||
},
|
||||
display_field(7),
|
||||
crate::entities::live_display::AppliedDisplay(Some(7)),
|
||||
FxAttached { instances },
|
||||
))
|
||||
.add_child(body)
|
||||
.id()
|
||||
}
|
||||
|
||||
/// A built unit wearing `kits`, each spawned on a root under its visual, every model ready.
|
||||
fn wearing(kits: Vec<FxInstance>) -> (App, Entity) {
|
||||
let mut app = rebuilding();
|
||||
let world = app.world_mut();
|
||||
for kit in &kits {
|
||||
world.resource_mut::<SpellFx>().models.insert(
|
||||
kit.path.clone(),
|
||||
DisplayModel {
|
||||
parts: Some(Vec::new()),
|
||||
..crate::entities::display::empty_shell()
|
||||
},
|
||||
);
|
||||
}
|
||||
let body = world
|
||||
.spawn((Transform::default(), GlobalTransform::default()))
|
||||
.id();
|
||||
let kits = kits
|
||||
.into_iter()
|
||||
.map(|mut kit| {
|
||||
let root = world
|
||||
.spawn((Transform::default(), GlobalTransform::default()))
|
||||
.id();
|
||||
world.entity_mut(body).add_child(root);
|
||||
kit.root = Some(root);
|
||||
kit
|
||||
})
|
||||
.collect();
|
||||
let unit = built_unit(world, body, kits);
|
||||
(app, unit)
|
||||
}
|
||||
|
||||
/// Swap the display, then build the new body, as `attach_entity_visuals` would a frame on.
|
||||
fn swap_then_build(app: &mut App, unit: Entity) {
|
||||
swap_display(app, unit);
|
||||
app.update();
|
||||
assert_names_no_dead_root(app, unit);
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert(crate::entities::VisualAttached);
|
||||
app.update();
|
||||
app.update();
|
||||
assert_names_no_dead_root(app, unit);
|
||||
}
|
||||
|
||||
/// A persistent hand kit of `spell_id` running `stage`.
|
||||
fn held(spell_id: u32, stage: FxStage, effect: u32, path: &str) -> FxInstance {
|
||||
FxInstance {
|
||||
spell_id,
|
||||
persistent: true,
|
||||
class: FxClass::Hold,
|
||||
stage,
|
||||
tag: 0x15,
|
||||
effect,
|
||||
path: path.into(),
|
||||
root: None,
|
||||
expires: None,
|
||||
decaying: false,
|
||||
}
|
||||
}
|
||||
|
||||
fn roots_of(app: &App, unit: Entity) -> Vec<(u32, Option<Entity>)> {
|
||||
app.world()
|
||||
.get::<FxAttached>(unit)
|
||||
.unwrap()
|
||||
.instances
|
||||
.iter()
|
||||
.map(|i| (i.spell_id, i.root))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The rebuild replays the aura slots (`0x5ff130` at `0x60ada6`) and the channel kit
|
||||
/// (`0x612a30` at `0x60adad`, kind 2 at `0x612b2b`), so both come back on the new body, each
|
||||
/// on a fresh root.
|
||||
#[test]
|
||||
fn the_rebuild_replays_the_aura_and_the_channel_on_the_new_body() {
|
||||
let channel = held(5143, FxStage::State, 9, "Spells\\Channel_Hand.mdx"); // Arcane Missiles
|
||||
let (mut app, unit) = wearing(vec![instance(Entity::PLACEHOLDER, true), channel]);
|
||||
let before = roots_of(&app, unit);
|
||||
swap_then_build(&mut app, unit);
|
||||
let after = roots_of(&app, unit);
|
||||
assert_eq!(
|
||||
after.iter().map(|&(spell, _)| spell).collect::<Vec<_>>(),
|
||||
[13033, 5143],
|
||||
"the aura and the channel come back"
|
||||
);
|
||||
for ((_, old), (spell, new)) in before.into_iter().zip(after) {
|
||||
assert!(
|
||||
new.is_some() && new != old,
|
||||
"spell {spell} spawns afresh on the new body"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The rebuild runs on the unit, built or not (`0x60abe0`): with its body still to come, what
|
||||
/// it held ends all the same, the aura re-arming for the body and the precast loop and the
|
||||
/// flash gone.
|
||||
#[test]
|
||||
fn a_rebuild_before_the_body_attached_ends_what_the_unit_held() {
|
||||
let mut app = rebuilding();
|
||||
let flash = FxInstance {
|
||||
persistent: false,
|
||||
..held(7, FxStage::OneShot, FLASH.0, FLASH.2)
|
||||
};
|
||||
let precast = held(116, FxStage::Relive, 10, "Spells\\Precast_Hand.mdx");
|
||||
let aura = held(13033, FxStage::State, 9, "Spells\\Aura.mdx");
|
||||
let unit = app
|
||||
.world_mut()
|
||||
.spawn((
|
||||
Transform::default(),
|
||||
GlobalTransform::default(),
|
||||
crate::net::Guid(0xB0B),
|
||||
crate::net::NetEntity {
|
||||
kind: benilla_protocol::EntityKind::Unit,
|
||||
display_id: Some(7),
|
||||
scale: 1.0,
|
||||
},
|
||||
display_field(7),
|
||||
FxAttached {
|
||||
instances: vec![flash, precast, aura],
|
||||
},
|
||||
))
|
||||
.id();
|
||||
swap_display(&mut app, unit);
|
||||
app.update();
|
||||
assert_eq!(
|
||||
roots_of(&app, unit),
|
||||
[(13033, None)],
|
||||
"the aura waits for the body"
|
||||
);
|
||||
}
|
||||
|
||||
/// A precast loop is kind 4 (`0x60ee7e`), which nothing in the rebuild plays again: it ends
|
||||
/// and stays gone.
|
||||
#[test]
|
||||
fn a_precast_loop_ends_at_the_rebuild_and_stays_gone() {
|
||||
let precast = held(116, FxStage::Relive, 10, "Spells\\Precast_Hand.mdx"); // Frostbolt
|
||||
let (mut app, unit) = wearing(vec![precast]);
|
||||
swap_then_build(&mut app, unit);
|
||||
assert_eq!(instances_of(&app, unit), vec![]);
|
||||
}
|
||||
|
||||
/// The loot sparkle (`0x6005d0`) is hung only by its own triggers: the death stamp (`0x5fbe6d`,
|
||||
/// `0x5fc962`), a dynamic-flags write (`0x60058e`), a return (`0x5fbde2`) or a create
|
||||
/// (`0x5fba33`). The rebuild reaches none of them, and the new model plays no death to finish,
|
||||
/// as a dead unit's base pick is 6 or 132 (`0x5fcff0`): the sparkle ends and stays gone.
|
||||
#[test]
|
||||
fn the_loot_sparkle_ends_at_the_rebuild_and_stays_gone() {
|
||||
let sparkle = FxInstance {
|
||||
spell_id: u32::MAX, // the router's loot key
|
||||
tag: 0x13,
|
||||
..held(0, FxStage::Relive, 11, "Spells\\LootSparkle.mdx")
|
||||
};
|
||||
let (mut app, unit) = wearing(vec![sparkle]);
|
||||
swap_then_build(&mut app, unit);
|
||||
assert_eq!(instances_of(&app, unit), vec![]);
|
||||
}
|
||||
|
||||
/// The rig heal is benilla's own: the reference never rebuilds there, so everything the unit
|
||||
/// had comes back on the healed body, the precast loop and the loot sparkle too, which the
|
||||
/// loot router hangs only on its rising edge and so would never hang again.
|
||||
#[test]
|
||||
fn a_rig_heal_brings_back_every_persistent_effect() {
|
||||
let precast = held(116, FxStage::Relive, 10, "Spells\\Precast_Hand.mdx"); // Frostbolt
|
||||
let sparkle = FxInstance {
|
||||
spell_id: u32::MAX, // the router's loot key
|
||||
tag: 0x13,
|
||||
..held(0, FxStage::Relive, 11, "Spells\\LootSparkle.mdx")
|
||||
};
|
||||
let (mut app, unit) = wearing(vec![instance(Entity::PLACEHOLDER, true), precast, sparkle]);
|
||||
let before = roots_of(&app, unit);
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert(benilla_world::rig_palette::RigStarved);
|
||||
app.update();
|
||||
assert_names_no_dead_root(&app, unit);
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert(crate::entities::VisualAttached);
|
||||
app.update();
|
||||
let after = roots_of(&app, unit);
|
||||
assert_eq!(
|
||||
after.iter().map(|&(spell, _)| spell).collect::<Vec<_>>(),
|
||||
[13033, 116, u32::MAX],
|
||||
"the aura, the precast loop and the sparkle all come back"
|
||||
);
|
||||
for ((_, old), (spell, new)) in before.into_iter().zip(after) {
|
||||
assert!(
|
||||
new.is_some() && new != old,
|
||||
"spell {spell} spawns afresh on the healed body"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Write `starts` as this frame's kit edges, beside a display rebuild at `rebuild`.
|
||||
fn swap_with(app: &mut App, unit: Entity, starts: Vec<SpellKitFx>, rebuild: Stamp) {
|
||||
let mut messages = app.world_mut().resource_mut::<Messages<SpellKitFx>>();
|
||||
for start in starts {
|
||||
messages.write(start);
|
||||
}
|
||||
swap_display_at(app, unit, rebuild);
|
||||
}
|
||||
|
||||
/// `n` places in wire order.
|
||||
fn places<const N: usize>() -> [Stamp; N] {
|
||||
[(); N].map(|_| crate::lanes::stamp())
|
||||
}
|
||||
|
||||
/// A start of one model at `tag`, ready to spawn.
|
||||
fn start(
|
||||
app: &mut App,
|
||||
unit: Entity,
|
||||
(spell_id, persistent, stage): (u32, bool, FxStage),
|
||||
(effect, tag, path): (u32, u16, &str),
|
||||
at: Option<Stamp>,
|
||||
) -> SpellKitFx {
|
||||
app.world_mut().resource_mut::<SpellFx>().models.insert(
|
||||
path.into(),
|
||||
DisplayModel {
|
||||
parts: Some(Vec::new()),
|
||||
..crate::entities::display::empty_shell()
|
||||
},
|
||||
);
|
||||
SpellKitFx::Begin {
|
||||
entity: unit,
|
||||
spell_id,
|
||||
persistent,
|
||||
class: if stage == FxStage::State {
|
||||
FxClass::AuraState
|
||||
} else {
|
||||
FxClass::Hold
|
||||
},
|
||||
stage,
|
||||
effects: vec![FxSlot {
|
||||
tag,
|
||||
effect,
|
||||
path: path.into(),
|
||||
}],
|
||||
at,
|
||||
}
|
||||
}
|
||||
|
||||
fn paths_of(app: &App, unit: Entity) -> Vec<(String, bool)> {
|
||||
app.world()
|
||||
.get::<FxAttached>(unit)
|
||||
.unwrap()
|
||||
.instances
|
||||
.iter()
|
||||
.map(|i| (i.path.clone(), i.root.is_some()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Build the new body a frame on, then let the spawn pass run.
|
||||
fn build_body(app: &mut App, unit: Entity) {
|
||||
app.update();
|
||||
assert_names_no_dead_root(app, unit);
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert(crate::entities::VisualAttached);
|
||||
app.update();
|
||||
assert_names_no_dead_root(app, unit);
|
||||
}
|
||||
|
||||
/// A unit that dies in a form leaves the form and turns lootable in one update. The display
|
||||
/// watcher (131, `0x604990`) rebuilds before the dynamic flags' (143, `0x604b30`), whose
|
||||
/// sparkle (`0x60058e`), or the one the death's end hangs (`0x5fc962`), comes after it.
|
||||
/// So the sparkle starts on the new body and stays.
|
||||
#[test]
|
||||
fn a_unit_that_dies_in_a_form_and_turns_lootable_in_one_update_keeps_its_sparkle() {
|
||||
let (mut app, unit) = wearing(vec![]);
|
||||
let [rebuild, flags] = places();
|
||||
let sparkle = start(
|
||||
&mut app,
|
||||
unit,
|
||||
(u32::MAX, true, FxStage::Relive), // as the loot router writes it
|
||||
(11, 0x13, "Spells\\LootSparkle.mdx"),
|
||||
Some(flags),
|
||||
);
|
||||
swap_with(&mut app, unit, vec![sparkle], rebuild);
|
||||
build_body(&mut app, unit);
|
||||
assert!(
|
||||
matches!(roots_of(&app, unit)[..], [(u32::MAX, Some(_))]),
|
||||
"the sparkle hangs on the new body: {:?}",
|
||||
roots_of(&app, unit)
|
||||
);
|
||||
}
|
||||
|
||||
/// A form's aura added in the update that swaps the display: the aura watcher (fields 47 to
|
||||
/// 100, `0x604d00`) starts its state kit before the rebuild, which stops it and replays the
|
||||
/// slot (`0x5ff130`). One instance, on the new body.
|
||||
#[test]
|
||||
fn an_aura_added_with_a_swap_lands_once_on_the_new_body() {
|
||||
let (mut app, unit) = wearing(vec![]);
|
||||
let [aura_watch, rebuild] = places();
|
||||
let aura = start(
|
||||
&mut app,
|
||||
unit,
|
||||
(13033, true, FxStage::State),
|
||||
(1499, 0x13, "Spells\\IceShield_State.mdx"),
|
||||
Some(aura_watch),
|
||||
);
|
||||
swap_with(&mut app, unit, vec![aura], rebuild);
|
||||
build_body(&mut app, unit);
|
||||
assert!(
|
||||
matches!(roots_of(&app, unit)[..], [(13033, Some(_))]),
|
||||
"one aura instance, spawned on the new body: {:?}",
|
||||
roots_of(&app, unit)
|
||||
);
|
||||
}
|
||||
|
||||
/// One update and the packets before it, as 1.12.1 orders them: the fields are written first
|
||||
/// and their watchers run after in field order, so the display's rebuild (131, `0x604990`)
|
||||
/// stops at `0x60ac10` what was started before it: a precast loop from an earlier
|
||||
/// `SMSG_SPELL_START`, the cast kit of the `SMSG_SPELL_GO` a shapeshift's update follows, a
|
||||
/// level-up ding (34, `0x6045b0`). What the mount (133, `0x604570`) and dynamic flags (143,
|
||||
/// `0x604b30`) watchers start after it stands, as does what the frame starts after every
|
||||
/// packet, a breath puff.
|
||||
#[test]
|
||||
fn a_rebuild_ends_the_starts_the_wire_put_before_it_and_keeps_those_after() {
|
||||
let (mut app, unit) = wearing(vec![]);
|
||||
let [spell_start, spell_go, level, rebuild, mount, flags] = places();
|
||||
let starts = vec![
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(116, true, FxStage::Relive),
|
||||
(10, 0x15, "Spells\\Precast_Hand.mdx"),
|
||||
Some(spell_start),
|
||||
),
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(768, false, FxStage::OneShot), // Cat Form
|
||||
(7, 0x16, "Spells\\CastFlash.mdx"),
|
||||
Some(spell_go),
|
||||
),
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(0, false, FxStage::OneShot),
|
||||
(12, 0x13, "Spells\\LevelUp.mdx"),
|
||||
Some(level),
|
||||
),
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(0, false, FxStage::OneShot),
|
||||
(13, 0x13, "Spells\\MountPoof.mdx"),
|
||||
Some(mount),
|
||||
),
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(u32::MAX, true, FxStage::Relive),
|
||||
(11, 0x13, "Spells\\LootSparkle.mdx"),
|
||||
Some(flags),
|
||||
),
|
||||
start(
|
||||
&mut app,
|
||||
unit,
|
||||
(0, false, FxStage::OneShot),
|
||||
(14, 0x11, "Spells\\Breath.mdx"),
|
||||
None,
|
||||
),
|
||||
];
|
||||
swap_with(&mut app, unit, starts, rebuild);
|
||||
build_body(&mut app, unit);
|
||||
assert_eq!(
|
||||
paths_of(&app, unit),
|
||||
[
|
||||
("Spells\\MountPoof.mdx".to_string(), true),
|
||||
("Spells\\LootSparkle.mdx".to_string(), true),
|
||||
("Spells\\Breath.mdx".to_string(), true),
|
||||
],
|
||||
"the precast loop, the cast kit and the ding end; the rest spawn on the new body",
|
||||
);
|
||||
}
|
||||
|
||||
/// A new display naming new records, whose rebuild the update announces (`0x60abe0`).
|
||||
fn swap_display(app: &mut App, unit: Entity) {
|
||||
swap_display_at(app, unit, crate::lanes::stamp());
|
||||
}
|
||||
|
||||
/// [`swap_display`] with the rebuild at `at` among the packets' edges.
|
||||
fn swap_display_at(app: &mut App, unit: Entity, at: Stamp) {
|
||||
app.world_mut().entity_mut(unit).insert(display_field(8));
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<crate::entities::DisplayRebuilt>>()
|
||||
.write(crate::entities::DisplayRebuilt {
|
||||
entity: unit,
|
||||
at,
|
||||
display_id: 8,
|
||||
});
|
||||
}
|
||||
|
||||
fn display_field(display: u32) -> crate::net::ObjectStore {
|
||||
crate::net::ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(
|
||||
benilla_protocol::field::FIELD_UNIT_DISPLAYID,
|
||||
display,
|
||||
)]))
|
||||
}
|
||||
|
||||
/// Every root the list names is live. Each teardown site despawns only a named root, so a list
|
||||
/// naming a dead one is a despawn of a dead entity waiting for the next reap, replace or expiry.
|
||||
fn assert_names_no_dead_root(app: &App, unit: Entity) {
|
||||
for inst in &app.world().get::<FxAttached>(unit).unwrap().instances {
|
||||
if let Some(root) = inst.root {
|
||||
assert!(
|
||||
app.world().get_entity(root).is_ok(),
|
||||
"{} still names its root {root}, which is already despawned",
|
||||
inst.path
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The rebuild's effect leg, as `0x60abe0` runs it: the `0x60ac10` loop stops every effect on
|
||||
/// the unit's list `+0xb4` through `0x6203e0` (`0x61fcf0` links a planted one there too,
|
||||
/// `0x61fdbf`), so each root goes and each emitter drains; the aura's state kit re-arms for the
|
||||
/// new body (`0x5ff130`). Then the flash's expiry, a forced reap of the aura and a replay of the
|
||||
/// flash's slot all run with nothing dead to despawn.
|
||||
fn assert_the_rebuild_ended_every_effect(
|
||||
mut app: App,
|
||||
unit: Entity,
|
||||
roots: [Entity; 3],
|
||||
emitters: [Entity; 3],
|
||||
) {
|
||||
assert_names_no_dead_root(&app, unit);
|
||||
assert_eq!(
|
||||
instances_of(&app, unit),
|
||||
vec![(true, None)],
|
||||
"the aura's instance re-arms for the spawn pass; the one-shot drains",
|
||||
"the flash and the plant end; the aura's state re-arms, pending the new body",
|
||||
);
|
||||
for (root, emitter) in roots.into_iter().zip(emitters) {
|
||||
assert!(app.world().get_entity(root).is_err(), "{root} ends");
|
||||
assert_eq!(
|
||||
app.world()
|
||||
.get::<particles::ParticleEmitter>(emitter)
|
||||
.expect("a stopped instance's emitter outlives its root")
|
||||
.on_owner_loss(),
|
||||
particles::OwnerLoss::Drain,
|
||||
"the particles finish their lives (`0x61f680`), not pop",
|
||||
);
|
||||
}
|
||||
|
||||
app.world_mut()
|
||||
.resource_mut::<Time>()
|
||||
.advance_by(std::time::Duration::from_secs(2));
|
||||
let mut messages = app.world_mut().resource_mut::<Messages<SpellKitFx>>();
|
||||
messages.write(SpellKitFx::Reap {
|
||||
entity: unit,
|
||||
spell_id: 13033,
|
||||
class: FxClass::AuraState,
|
||||
force: true,
|
||||
at: None,
|
||||
});
|
||||
messages.write(begin(unit, FLASH.0, FLASH.1, FLASH.2));
|
||||
app.update();
|
||||
assert_names_no_dead_root(&app, unit);
|
||||
assert_eq!(
|
||||
instances_of(&app, unit),
|
||||
vec![(false, None)],
|
||||
"the reap takes the pending aura; the replayed flash waits for its model",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_display_swap_ends_the_units_effects_before_its_visual_goes() {
|
||||
let (mut app, unit, roots, emitters) = mid_cast();
|
||||
swap_display(&mut app, unit);
|
||||
app.update();
|
||||
assert!(
|
||||
!app.world()
|
||||
.entity(unit)
|
||||
.contains::<crate::entities::VisualAttached>(),
|
||||
"the swap tore the visual down"
|
||||
);
|
||||
assert_the_rebuild_ended_every_effect(app, unit, roots, emitters);
|
||||
}
|
||||
|
||||
/// The rig heal rebuilds through the display swap's teardown, so it ends the effects the same way.
|
||||
#[test]
|
||||
fn a_rig_heal_ends_the_units_effects_before_its_visual_goes() {
|
||||
let (mut app, unit, roots, emitters) = mid_cast();
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.insert(benilla_world::rig_palette::RigStarved);
|
||||
app.update();
|
||||
assert!(
|
||||
!app.world()
|
||||
.entity(unit)
|
||||
.contains::<crate::entities::VisualAttached>(),
|
||||
"the heal tore the visual down"
|
||||
);
|
||||
assert_the_rebuild_ended_every_effect(app, unit, roots, emitters);
|
||||
}
|
||||
|
||||
/// With the new body still loading, a re-armed instance waits rather than spawn at the root.
|
||||
#[test]
|
||||
fn a_re_armed_instance_waits_for_the_body_before_it_spawns() {
|
||||
let (mut app, unit, roots) = standing(&[true]);
|
||||
app.world_mut().entity_mut(roots[0]).despawn();
|
||||
let (mut app, unit, ..) = mid_cast();
|
||||
app.world_mut().resource_mut::<SpellFx>().models.insert(
|
||||
"Spells\\IceShield_State.mdx".into(),
|
||||
DisplayModel {
|
||||
@@ -1046,6 +1737,7 @@ mod tests {
|
||||
..crate::entities::display::empty_shell()
|
||||
},
|
||||
);
|
||||
swap_display(&mut app, unit);
|
||||
app.update();
|
||||
app.update();
|
||||
assert_eq!(
|
||||
@@ -1063,18 +1755,19 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// A decaying instance was already ending, so the drain takes it too.
|
||||
/// A decaying instance was already ending, so the rebuild takes it too.
|
||||
#[test]
|
||||
fn a_decaying_instance_whose_root_died_as_collateral_is_dropped() {
|
||||
let (mut app, unit, roots) = standing(&[true]);
|
||||
fn a_decaying_instance_ends_at_the_rebuild() {
|
||||
let (mut app, unit, ..) = mid_cast();
|
||||
app.world_mut()
|
||||
.entity_mut(unit)
|
||||
.get_mut::<FxAttached>()
|
||||
.unwrap()
|
||||
.instances[0]
|
||||
.instances[1]
|
||||
.decaying = true;
|
||||
app.world_mut().entity_mut(roots[0]).despawn();
|
||||
swap_display(&mut app, unit);
|
||||
app.update();
|
||||
assert_names_no_dead_root(&app, unit);
|
||||
assert_eq!(instances_of(&app, unit), vec![]);
|
||||
}
|
||||
|
||||
@@ -1100,6 +1793,7 @@ mod tests {
|
||||
.init_asset::<benilla_assets::M2Model>()
|
||||
.init_resource::<SpellFx>()
|
||||
.add_message::<SpellKitFx>()
|
||||
.add_message::<crate::entities::DisplaySwapped>()
|
||||
.add_systems(Update, resolve_spell_fx);
|
||||
let unit = app.world_mut().spawn_empty().id();
|
||||
(app, unit)
|
||||
@@ -1118,6 +1812,7 @@ mod tests {
|
||||
effect,
|
||||
path: path.into(),
|
||||
}],
|
||||
at: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1210,6 +1905,7 @@ mod tests {
|
||||
spell_id: 13033,
|
||||
class: FxClass::Hold,
|
||||
force,
|
||||
at: None,
|
||||
};
|
||||
let roots = |app: &App| {
|
||||
app.world()
|
||||
|
||||
@@ -109,6 +109,7 @@ impl Plugin for NetPlugin {
|
||||
.add_message::<TeleportMessage>()
|
||||
.add_message::<FieldChanged>()
|
||||
.add_message::<AuraFieldsChanged>()
|
||||
.add_message::<crate::entities::DisplayRebuilt>()
|
||||
.init_resource::<crate::item_lane::ItemLane>()
|
||||
.init_resource::<crate::item_watch::BagCache>()
|
||||
.init_resource::<crate::field_watch::NoticeLane>()
|
||||
|
||||
@@ -94,6 +94,8 @@ pub(crate) struct Scene<'w, 's> {
|
||||
anchors: Query<'w, 's, &'static crate::transport::TransportAnchor>,
|
||||
speeds: Query<'w, 's, &'static mut UnitSpeeds>,
|
||||
field_changes: MessageWriter<'w, FieldChanged>,
|
||||
/// The display rebuilds (`0x60abe0`) the watchers run, at their places.
|
||||
rebuilds: MessageWriter<'w, crate::entities::DisplayRebuilt>,
|
||||
/// The aura watcher's calls ([`super::AuraFieldsChanged`]), one per block.
|
||||
aura_watch: MessageWriter<'w, super::AuraFieldsChanged>,
|
||||
/// The item watchers' runs ([`crate::item_lane`]).
|
||||
@@ -2624,6 +2626,74 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The display rebuild (`0x60abe0`) is announced at its watcher's place among the update's
|
||||
/// edges, the fields written first and the watchers run after in field order: behind the
|
||||
/// level's (34), at the display's (131, `0x6049b5`), ahead of the dynamic flags' (143). A
|
||||
/// display naming the held row's records rebuilds nothing (`0x60ae10`).
|
||||
#[test]
|
||||
fn a_display_rebuild_is_announced_at_its_watchers_place() {
|
||||
use benilla_protocol::field::{
|
||||
FIELD_UNIT_DISPLAYID, FIELD_UNIT_DYNAMIC_FLAGS, FIELD_UNIT_LEVEL,
|
||||
};
|
||||
const ENTRY: u32 = 1234;
|
||||
let mob = (u64::from(ENTRY) << 24) | (u64::from(guid::HIGH_UNIT) << 48) | 1;
|
||||
let mut app = crate::game_plugins::schedule_tests::headless_client_unrun();
|
||||
let (tx, _rx) = crossbeam_channel::unbounded();
|
||||
app.world_mut().insert_resource(NetCommands(tx));
|
||||
app.world_mut().insert_resource(display_tables());
|
||||
let world = app.world_mut();
|
||||
super::super::handlers::dispatch(
|
||||
world,
|
||||
super::wire(vec![displayed(mob, EntityKind::Unit, 9, 10)]),
|
||||
);
|
||||
let values = |world: &mut World, pairs: &[(u16, u32)]| {
|
||||
world.resource_mut::<Messages<FieldChanged>>().clear();
|
||||
world
|
||||
.resource_mut::<Messages<crate::entities::DisplayRebuilt>>()
|
||||
.clear();
|
||||
super::super::handlers::dispatch(
|
||||
world,
|
||||
super::wire(vec![SessionEvent::ObjectValues {
|
||||
guid: mob,
|
||||
fields: ObjectFields::from_pairs(pairs),
|
||||
}]),
|
||||
);
|
||||
let edges: Vec<FieldChanged> = world
|
||||
.resource_mut::<Messages<FieldChanged>>()
|
||||
.drain()
|
||||
.collect();
|
||||
let rebuilds: Vec<crate::entities::DisplayRebuilt> = world
|
||||
.resource_mut::<Messages<crate::entities::DisplayRebuilt>>()
|
||||
.drain()
|
||||
.collect();
|
||||
(edges, rebuilds)
|
||||
};
|
||||
|
||||
let (_, rebuilds) = values(world, &[(FIELD_UNIT_DISPLAYID, 12)]);
|
||||
assert!(rebuilds.is_empty(), "display 12 names display 10's records");
|
||||
|
||||
let (edges, rebuilds) = values(
|
||||
world,
|
||||
&[
|
||||
(FIELD_UNIT_LEVEL, 2),
|
||||
(FIELD_UNIT_DISPLAYID, 11),
|
||||
(FIELD_UNIT_DYNAMIC_FLAGS, 1),
|
||||
],
|
||||
);
|
||||
let at = |index| edges.iter().find(|e| e.index == index).unwrap().at;
|
||||
let [rebuild] = rebuilds[..] else {
|
||||
panic!("one rebuild: {rebuilds:?}");
|
||||
};
|
||||
assert_eq!(rebuild.entity, world.resource::<GuidIndex>().0[&mob]);
|
||||
assert_eq!(rebuild.display_id, 11, "the row it resolved");
|
||||
assert_eq!(
|
||||
rebuild.at,
|
||||
at(FIELD_UNIT_DISPLAYID),
|
||||
"at the display's watcher"
|
||||
);
|
||||
assert!(at(FIELD_UNIT_LEVEL) < rebuild.at && rebuild.at < at(FIELD_UNIT_DYNAMIC_FLAGS));
|
||||
}
|
||||
|
||||
/// A creature asks its record again when its display names a new record set: the display
|
||||
/// watcher (`0x6049b5`) runs `0x60abe0`, whose `0x60ae10` finds the records changed, and the
|
||||
/// resolve asks (`0x60ac21` → `0x60b15b`). A display with the same records, or one with no
|
||||
|
||||
@@ -1132,17 +1132,22 @@ fn notify(sc: &mut Scene, guid: u64, block: Notified, bridged: bool) {
|
||||
return;
|
||||
};
|
||||
// The `UNIT_FIELD_DISPLAYID` watcher (`0x604990`) and the health watcher's return to life
|
||||
// (`0x6046f0`: old health not above 0, new above, `0x6047ee`-`0x604835`) rebuild the display.
|
||||
// (`0x6046f0`: old health not above 0, new above, `0x6047ee`-`0x604835`) rebuild the display;
|
||||
// the rebuild is announced at the first of the two edges the walk below writes.
|
||||
let rebuilds = |index: u16, old: u32, new: u32| {
|
||||
index == benilla_protocol::field::FIELD_UNIT_DISPLAYID
|
||||
|| (index == benilla_protocol::field::FIELD_UNIT_HEALTH
|
||||
&& old as i32 <= 0
|
||||
&& new as i32 > 0)
|
||||
};
|
||||
let mut rebuild_owed = None;
|
||||
if matches!(kind, ObjectType::Unit | ObjectType::Player)
|
||||
&& block.edges().any(|(index, old, new)| {
|
||||
index == benilla_protocol::field::FIELD_UNIT_DISPLAYID
|
||||
|| (index == benilla_protocol::field::FIELD_UNIT_HEALTH
|
||||
&& old as i32 <= 0
|
||||
&& new as i32 > 0)
|
||||
})
|
||||
&& block
|
||||
.edges()
|
||||
.any(|(index, old, new)| rebuilds(index, old, new))
|
||||
{
|
||||
let fields = fields.clone();
|
||||
display_changed(sc, e, guid, &fields);
|
||||
rebuild_owed = display_changed(sc, e, guid, &fields);
|
||||
}
|
||||
let Some(fields) = sc.stores.get(e).ok().map(|s| &s.0) else {
|
||||
return;
|
||||
@@ -1274,6 +1279,14 @@ fn notify(sc: &mut Scene, guid: u64, block: Notified, bridged: bool) {
|
||||
old,
|
||||
new,
|
||||
});
|
||||
if let Some(display_id) = rebuild_owed.filter(|_| rebuilds(index, old, new)) {
|
||||
sc.rebuilds.write(crate::entities::DisplayRebuilt {
|
||||
entity: e,
|
||||
at,
|
||||
display_id,
|
||||
});
|
||||
rebuild_owed = None;
|
||||
}
|
||||
// The watcher runs at its range's place, where its first edge is written.
|
||||
if crate::net::in_aura_watch(index) {
|
||||
if let Some((old, new, health)) = aura_call.take() {
|
||||
@@ -1396,6 +1409,15 @@ fn notify(sc: &mut Scene, guid: u64, block: Notified, bridged: bool) {
|
||||
crate::field_watch::Step::Item(run) => sc.item_lane.push(run),
|
||||
}
|
||||
}
|
||||
// A walk that wrote neither edge still owes its rebuild, after what it wrote.
|
||||
if let Some(display_id) = rebuild_owed {
|
||||
let at = crate::lanes::stamp();
|
||||
sc.rebuilds.write(crate::entities::DisplayRebuilt {
|
||||
entity: e,
|
||||
at,
|
||||
display_id,
|
||||
});
|
||||
}
|
||||
// The active player's coinage watcher `OnMoneyChanged` (`0x5ddf30`), registered on its own
|
||||
// object (`0x5dd8a0`): the trade offer's trim (`0x5ddfda`), at the packet, behind the
|
||||
// `PLAYER_MONEY` its notice stamped (`0x5ddf4b`); the trim signals nothing.
|
||||
@@ -1544,11 +1566,11 @@ fn reactivated_end(sc: &mut Scene, guid: u64, script: Option<&UiScript>) {
|
||||
};
|
||||
match fields.created_as() {
|
||||
Some(ObjectType::Unit) => {
|
||||
display_changed(sc, e, guid, &fields);
|
||||
reactivated_rebuild(sc, e, guid, &fields);
|
||||
sc.field_notices.write(token_update(guid));
|
||||
}
|
||||
Some(ObjectType::Player) => {
|
||||
display_changed(sc, e, guid, &fields);
|
||||
reactivated_rebuild(sc, e, guid, &fields);
|
||||
sc.field_notices.write(token_update(guid));
|
||||
// `0x5deca1` → `0x4e85d0` mode 1.
|
||||
sc.group.member_object(guid, true);
|
||||
@@ -1611,30 +1633,39 @@ fn resolve_display_records(sc: &mut Scene, guid: u64, fields: &ObjectFields) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Slot 3's rebuild (`0x5fbe28`), after the packet's walk: announced with a stamp of its own.
|
||||
fn reactivated_rebuild(sc: &mut Scene, e: Entity, guid: u64, fields: &ObjectFields) {
|
||||
if let Some(display_id) = display_changed(sc, e, guid, fields) {
|
||||
let at = crate::lanes::stamp();
|
||||
sc.rebuilds.write(crate::entities::DisplayRebuilt {
|
||||
entity: e,
|
||||
at,
|
||||
display_id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// `CGUnit_C::OnDisplayChanged` (`0x60abe0`), from the `UNIT_FIELD_DISPLAYID` watcher
|
||||
/// (`0x6049b5`), the health watcher's return to life (`0x604835`) and slot 3 (`0x5fbe28`): when
|
||||
/// `0x60ae10` sees a new record set the unit resolves its records again (`0x60ac21`), and a
|
||||
/// creature asks its record (`0x60b15b`).
|
||||
fn display_changed(sc: &mut Scene, e: Entity, guid: u64, fields: &ObjectFields) {
|
||||
let Some(creatures) = sc.creatures.as_deref() else {
|
||||
return;
|
||||
};
|
||||
let Ok(mut held) = sc.held_displays.get_mut(e) else {
|
||||
return;
|
||||
};
|
||||
/// creature asks its record (`0x60b15b`). The row it rebuilt from, which the caller announces
|
||||
/// ([`crate::entities::DisplayRebuilt`]) at the watcher's place; `None` for no rebuild.
|
||||
fn display_changed(sc: &mut Scene, e: Entity, guid: u64, fields: &ObjectFields) -> Option<u32> {
|
||||
let creatures = sc.creatures.as_deref()?;
|
||||
let mut held = sc.held_displays.get_mut(e).ok()?;
|
||||
let display = unit_display(fields);
|
||||
let Some(was) = held.0 else {
|
||||
return;
|
||||
};
|
||||
let was = held.0?;
|
||||
if !creatures.display_records_differ(display, was) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
held.0 = creatures.records_row(display);
|
||||
let row = creatures.records_row(display);
|
||||
held.0 = row;
|
||||
// The body rebuilt (`0x60abe0`) dresses both pieces by the flag (`0x5ed802`, `0x5ed81a`).
|
||||
if let Ok(mut pins) = sc.worn_pins.get_mut(e) {
|
||||
pins.rebuilt();
|
||||
}
|
||||
sc.names.ask_creature_record(guid, fields, &sc.net);
|
||||
row
|
||||
}
|
||||
|
||||
/// `UNIT_FIELD_DISPLAYID` as the resolve reads it, absent as 0 (vmangos omits zero fields).
|
||||
|
||||
@@ -698,12 +698,23 @@ pub(super) fn set_source_kit_gain(out: &mut SoundOutput, source: Entity, kit_id:
|
||||
}
|
||||
}
|
||||
|
||||
/// Force-stop `source`'s channels on kit `kit_id`: a looping spell kit rides the tracked play
|
||||
/// `0x61fec0` and dies with its effect (`0x614150`). Kit-scoped so the caster's greeting survives.
|
||||
/// Force-stop `source`'s channels on kit `kit_id` with the de-click, kit-scoped so the source's
|
||||
/// other sounds survive.
|
||||
pub(super) fn stop_source_kit(out: &mut SoundOutput, source: Entity, kit_id: u32) {
|
||||
stop_source_kit_with(out, source, kit_id, mixer::declick());
|
||||
}
|
||||
|
||||
/// [`stop_source_kit`] over `fade`: a spell kit's sound rides the tracked play `0x61fec0` and
|
||||
/// fades with its effect (`0x6203e0`).
|
||||
pub(super) fn stop_source_kit_with(
|
||||
out: &mut SoundOutput,
|
||||
source: Entity,
|
||||
kit_id: u32,
|
||||
fade: kira::Tween,
|
||||
) {
|
||||
out.channels.retain_mut(|c| {
|
||||
if c.source == Some(source) && c.kit == kit_id {
|
||||
c.handle.stop(mixer::declick());
|
||||
c.handle.stop(fade);
|
||||
false
|
||||
} else {
|
||||
true
|
||||
|
||||
@@ -9,6 +9,7 @@ use bevy::ecs::entity::EntityHashMap;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::creature_anim::SpellKitSound;
|
||||
use crate::lanes::Stamp;
|
||||
use crate::net::NetEntity;
|
||||
use benilla_assets::WorldAssets;
|
||||
use benilla_world::schedule::WorldStage;
|
||||
@@ -18,43 +19,126 @@ use super::kit::{
|
||||
};
|
||||
use super::{AudioListener, SoundConfig, SoundOutput};
|
||||
|
||||
/// Each unit's live hold loop: the spell whose kit rang it and the kit. The reference's sound
|
||||
/// rides the kit's effect, which carries its spell (`+0x18`), and `0x614150(spell, 0)` takes only
|
||||
/// a matching effect (`0x614167`), so one spell's stop spares another spell's loop.
|
||||
/// Each unit's live looping kit sounds, one per kit, as each rides an effect of its own on the
|
||||
/// unit's list (`0x61fedc`). The effect carries its spell (`+0x18`), and `0x614150(spell, 0)` takes
|
||||
/// every matching effect (`0x614167`), so one spell's stop spares another spell's loops.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct HoldLoops(EntityHashMap<(u32, u32)>);
|
||||
pub(crate) struct HoldLoops(EntityHashMap<Vec<Hold>>);
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
struct Hold {
|
||||
/// The spell whose kit rang it, and the kit.
|
||||
kit: (u32, u32),
|
||||
/// Rung by a cast's hold ([`SpellKitSound::Play`]'s `cast_hold`).
|
||||
cast_hold: bool,
|
||||
/// Its packet's place, which a display rebuild compares.
|
||||
at: Stamp,
|
||||
}
|
||||
|
||||
/// One kit sound an edge stops on its unit, and how it fades.
|
||||
pub(crate) struct KitStop {
|
||||
pub(crate) entity: Entity,
|
||||
pub(crate) kit_sound: u32,
|
||||
pub(crate) fade: kira::Tween,
|
||||
}
|
||||
|
||||
impl HoldLoops {
|
||||
/// A looping kit rang on `entity` for `spell_id`: the unit's hold loop now.
|
||||
pub(crate) fn rang(&mut self, entity: Entity, spell_id: u32, kit_sound: u32) {
|
||||
self.0.insert(entity, (spell_id, kit_sound));
|
||||
/// A looping kit (`spell_id`, `kit_sound`) rang on `entity`, one of its loops now; a kit rung
|
||||
/// again is the same loop, as a stop takes every channel on it. A play without a packet
|
||||
/// stamp rang now, after every packet already read.
|
||||
pub(crate) fn rang(
|
||||
&mut self,
|
||||
entity: Entity,
|
||||
kit: (u32, u32),
|
||||
cast_hold: bool,
|
||||
at: Option<Stamp>,
|
||||
) {
|
||||
let at = at.unwrap_or_else(crate::lanes::stamp);
|
||||
let holds = self.0.entry(entity).or_default();
|
||||
holds.retain(|h| h.kit.1 != kit.1);
|
||||
holds.push(Hold { kit, cast_hold, at });
|
||||
}
|
||||
|
||||
/// [`SpellKitSound::StopHold`]: the kit to stop, the unit's loop when `spell_id` names its
|
||||
/// spell or is `None`.
|
||||
pub(crate) fn stop_hold(&mut self, entity: Entity, spell_id: Option<u32>) -> Option<u32> {
|
||||
let &(held, kit_sound) = self.0.get(&entity)?;
|
||||
if spell_id.is_some_and(|s| s != held) {
|
||||
return None;
|
||||
}
|
||||
self.0.remove(&entity);
|
||||
Some(kit_sound)
|
||||
/// The kit sounds `edge` stops on its unit, the books moved to match: a hold's stop and a
|
||||
/// rebuild take the loops they name, an aura's stop and a replay their kit, a play nothing.
|
||||
/// Each fades as `0x6203e0` stops an effect's sound ([`kit_stop_fade`]).
|
||||
pub(crate) fn stops(&mut self, edge: &SpellKitSound) -> Vec<KitStop> {
|
||||
let (entity, kits) = match *edge {
|
||||
SpellKitSound::Play { .. } | SpellKitSound::PlayAt { .. } => return Vec::new(),
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
(entity, self.stop_hold(entity, spell_id))
|
||||
}
|
||||
SpellKitSound::StopKit { entity, kit_sound } => {
|
||||
// An aura-drop reap stops the kit's channels; an unrelated loop survives.
|
||||
self.take(entity, |h| h.kit.1 == kit_sound);
|
||||
(entity, vec![kit_sound])
|
||||
}
|
||||
SpellKitSound::Rebuilt { entity, at } => (entity, self.take(entity, |h| h.at < at)),
|
||||
SpellKitSound::Replay {
|
||||
entity, kit_sound, ..
|
||||
} => {
|
||||
// Whatever the unit still sounds on the kit fades as the rebuild stopped its
|
||||
// effect; the replay rings afresh.
|
||||
self.take(entity, |h| h.kit.1 == kit_sound);
|
||||
(entity, vec![kit_sound])
|
||||
}
|
||||
};
|
||||
kits.into_iter()
|
||||
.map(|kit_sound| KitStop {
|
||||
entity,
|
||||
kit_sound,
|
||||
fade: kit_stop_fade(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// An aura's kit sound stopped by id: the loop is gone when it was that kit.
|
||||
fn stopped_kit(&mut self, entity: Entity, kit_sound: u32) {
|
||||
if self.0.get(&entity).is_some_and(|&(_, k)| k == kit_sound) {
|
||||
/// [`SpellKitSound::StopHold`]: the kits to stop, every loop `spell_id`'s kits rang, or with
|
||||
/// none every loop a cast's hold rang.
|
||||
pub(crate) fn stop_hold(&mut self, entity: Entity, spell_id: Option<u32>) -> Vec<u32> {
|
||||
self.take(entity, |h| match spell_id {
|
||||
Some(spell_id) => h.kit.0 == spell_id,
|
||||
None => h.cast_hold,
|
||||
})
|
||||
}
|
||||
|
||||
/// Drop `entity`'s loops that are `gone`, returning their kits.
|
||||
fn take(&mut self, entity: Entity, mut gone: impl FnMut(&Hold) -> bool) -> Vec<u32> {
|
||||
let Some(holds) = self.0.get_mut(&entity) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let mut kits = Vec::new();
|
||||
holds.retain(|h| {
|
||||
let stop = gone(h);
|
||||
if stop {
|
||||
kits.push(h.kit.1);
|
||||
}
|
||||
!stop
|
||||
});
|
||||
if holds.is_empty() {
|
||||
self.0.remove(&entity);
|
||||
}
|
||||
kits
|
||||
}
|
||||
|
||||
/// The loop the unit holds: its spell and kit.
|
||||
/// The loops the unit holds, in ring order: each one's spell and kit.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn held(&self, entity: Entity) -> Option<(u32, u32)> {
|
||||
self.0.get(&entity).copied()
|
||||
pub(crate) fn held(&self, entity: Entity) -> Vec<(u32, u32)> {
|
||||
self.0
|
||||
.get(&entity)
|
||||
.map_or_else(Vec::new, |holds| holds.iter().map(|h| h.kit).collect())
|
||||
}
|
||||
}
|
||||
|
||||
/// `0x6203e0`'s stop of an effect's sound, a 0.15 s fade (`0x6204b6` → `0x7a5a10`): every kit
|
||||
/// sound's stop, a hold's and an aura's through `0x614150` (`0x6141d8`, as a kit sound's effect
|
||||
/// from `0x61fec0` has no model) and the rebuild's through its loop `0x60ac10`.
|
||||
fn kit_stop_fade() -> kira::Tween {
|
||||
super::mixer::fade(KIT_STOP_FADE_MS)
|
||||
}
|
||||
|
||||
/// [`kit_stop_fade`]'s length.
|
||||
const KIT_STOP_FADE_MS: u64 = 150;
|
||||
|
||||
fn route_spell_kit_sounds(
|
||||
mut events: MessageReader<SpellKitSound>,
|
||||
transforms: Query<&Transform, Without<Camera3d>>,
|
||||
@@ -63,12 +147,12 @@ fn route_spell_kit_sounds(
|
||||
mut out: NonSendMut<SoundOutput>,
|
||||
config: Res<SoundConfig>,
|
||||
listener: Res<AudioListener>,
|
||||
// Each unit's live hold loop, so StopHold reaps only that kit's channels.
|
||||
// Each unit's live loops, so a stop reaps only the kits it names.
|
||||
mut hold_loops: Local<HoldLoops>,
|
||||
mut despawned: RemovedComponents<NetEntity>,
|
||||
) {
|
||||
for entity in despawned.read() {
|
||||
hold_loops.0.remove(&entity); // the channel dies with the source-channel despawn reaper
|
||||
hold_loops.0.remove(&entity); // the channels die with the source-channel despawn reaper
|
||||
}
|
||||
if events.is_empty() {
|
||||
return;
|
||||
@@ -80,54 +164,33 @@ fn route_spell_kit_sounds(
|
||||
// One ring per unit and kit per frame: the impact flash and the aura watcher's add edge can
|
||||
// both play a state kit in one packet burst. Plays in different frames both ring.
|
||||
let mut played_now: Vec<(Entity, u32)> = Vec::new();
|
||||
// Each edge where it falls: every play a router stamps is written ahead of the visuals set
|
||||
// that raises a rebuild, and the rebuild's replay after it.
|
||||
for ev in events.read() {
|
||||
match *ev {
|
||||
for stop in hold_loops.stops(ev) {
|
||||
super::kit::stop_source_kit_with(&mut out, stop.entity, stop.kit_sound, stop.fade);
|
||||
}
|
||||
let (entity, spell_id, kit_sound, cast_hold, at) = match *ev {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
} => {
|
||||
if played_now.contains(&(entity, kit_sound)) {
|
||||
continue;
|
||||
}
|
||||
played_now.push((entity, kit_sound));
|
||||
let pos = transforms.get(entity).map(|t| t.translation).ok();
|
||||
let looping = kit_looping(&kits, kit_sound);
|
||||
// The line a headless probe greps to prove a spell's sound fired.
|
||||
debug!("spell kit sound {kit_sound} on {entity:?} (looping {looping})");
|
||||
let played = if looping {
|
||||
play_kit_ext(
|
||||
&mut kits,
|
||||
&assets,
|
||||
&mut out,
|
||||
&config,
|
||||
listener,
|
||||
KitRef::Id(kit_sound),
|
||||
pos,
|
||||
SoundCategory::Sfx,
|
||||
PlayExtras {
|
||||
source: Some(entity),
|
||||
..default()
|
||||
},
|
||||
)
|
||||
} else {
|
||||
play_kit(
|
||||
&mut kits,
|
||||
&assets,
|
||||
&mut out,
|
||||
&config,
|
||||
listener,
|
||||
KitRef::Id(kit_sound),
|
||||
pos,
|
||||
SoundCategory::Sfx,
|
||||
)
|
||||
};
|
||||
match played {
|
||||
Ok(_) if looping => hold_loops.rang(entity, spell_id, kit_sound),
|
||||
Ok(_) => {}
|
||||
Err(e) => warn!("spell kit sound {kit_sound}: {e:#}"),
|
||||
}
|
||||
(entity, spell_id, kit_sound, cast_hold, at)
|
||||
}
|
||||
// The replay rings afresh, a ring this frame or not.
|
||||
SpellKitSound::Replay {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
} => (entity, spell_id, kit_sound, cast_hold, Some(at)),
|
||||
SpellKitSound::PlayAt { pos, kit_sound } => {
|
||||
// A bare positional one-shot with no owner or dedup: its one caller is a
|
||||
// missile's ground arrival.
|
||||
@@ -144,17 +207,48 @@ fn route_spell_kit_sounds(
|
||||
) {
|
||||
warn!("spell kit sound {kit_sound}: {e:#}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
if let Some(kit_sound) = hold_loops.stop_hold(entity, spell_id) {
|
||||
super::kit::stop_source_kit(&mut out, entity, kit_sound);
|
||||
}
|
||||
}
|
||||
SpellKitSound::StopKit { entity, kit_sound } => {
|
||||
// An aura-drop reap: stop this kit's channels; an unrelated hold loop survives.
|
||||
hold_loops.stopped_kit(entity, kit_sound);
|
||||
super::kit::stop_source_kit(&mut out, entity, kit_sound);
|
||||
}
|
||||
SpellKitSound::StopHold { .. }
|
||||
| SpellKitSound::StopKit { .. }
|
||||
| SpellKitSound::Rebuilt { .. } => continue,
|
||||
};
|
||||
played_now.push((entity, kit_sound));
|
||||
let pos = transforms.get(entity).map(|t| t.translation).ok();
|
||||
let looping = kit_looping(&kits, kit_sound);
|
||||
// The line a headless probe greps to prove a spell's sound fired.
|
||||
debug!("spell kit sound {kit_sound} on {entity:?} (looping {looping})");
|
||||
let played = if looping {
|
||||
play_kit_ext(
|
||||
&mut kits,
|
||||
&assets,
|
||||
&mut out,
|
||||
&config,
|
||||
listener,
|
||||
KitRef::Id(kit_sound),
|
||||
pos,
|
||||
SoundCategory::Sfx,
|
||||
PlayExtras {
|
||||
source: Some(entity),
|
||||
..default()
|
||||
},
|
||||
)
|
||||
} else {
|
||||
play_kit(
|
||||
&mut kits,
|
||||
&assets,
|
||||
&mut out,
|
||||
&config,
|
||||
listener,
|
||||
KitRef::Id(kit_sound),
|
||||
pos,
|
||||
SoundCategory::Sfx,
|
||||
)
|
||||
};
|
||||
match played {
|
||||
Ok(_) if looping => hold_loops.rang(entity, (spell_id, kit_sound), cast_hold, at),
|
||||
Ok(_) => {}
|
||||
Err(e) => warn!("spell kit sound {kit_sound}: {e:#}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -168,21 +262,186 @@ pub(super) fn plugin(app: &mut App) {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const ARCANE_MISSILES: u32 = 5143;
|
||||
const AM_HUM: u32 = 3136;
|
||||
const FIREBALL: u32 = 133;
|
||||
const BUILDUP: u32 = 702;
|
||||
const ARCANE_INTELLECT: u32 = 1459;
|
||||
const AURA_LOOP: u32 = 4001;
|
||||
const NONE: [u32; 0] = [];
|
||||
|
||||
/// The router's books over one edge: the kits it stops, then its ring, every kit a loop.
|
||||
fn edge(loops: &mut HoldLoops, edge: SpellKitSound) -> Vec<u32> {
|
||||
let stopped = loops
|
||||
.stops(&edge)
|
||||
.into_iter()
|
||||
.map(|s| s.kit_sound)
|
||||
.collect();
|
||||
match edge {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
} => loops.rang(entity, (spell_id, kit_sound), cast_hold, at),
|
||||
SpellKitSound::Replay {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
} => loops.rang(entity, (spell_id, kit_sound), cast_hold, Some(at)),
|
||||
_ => {}
|
||||
}
|
||||
stopped
|
||||
}
|
||||
|
||||
fn play(spell_id: u32, kit_sound: u32, cast_hold: bool, at: Option<Stamp>) -> SpellKitSound {
|
||||
SpellKitSound::Play {
|
||||
entity: Entity::PLACEHOLDER,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
cast_hold,
|
||||
at,
|
||||
}
|
||||
}
|
||||
|
||||
/// `0x614150(spell, 0)` takes only its own spell's effects (`0x614167`): a stop keyed to
|
||||
/// another spell leaves the loop, its own takes it, and a replacing hold takes any.
|
||||
/// another spell leaves the loop, its own takes it, and a replacing hold takes any cast's.
|
||||
#[test]
|
||||
fn a_hold_stop_takes_only_its_own_spells_loop() {
|
||||
const ARCANE_MISSILES: u32 = 5143;
|
||||
const AM_HUM: u32 = 3136;
|
||||
const BLIZZARD: u32 = 10;
|
||||
let unit = Entity::PLACEHOLDER;
|
||||
let mut loops = HoldLoops::default();
|
||||
loops.rang(unit, ARCANE_MISSILES, AM_HUM);
|
||||
assert_eq!(loops.stop_hold(unit, Some(BLIZZARD)), None);
|
||||
assert_eq!(loops.held(unit), Some((ARCANE_MISSILES, AM_HUM)));
|
||||
assert_eq!(loops.stop_hold(unit, Some(ARCANE_MISSILES)), Some(AM_HUM));
|
||||
assert_eq!(loops.held(unit), None);
|
||||
loops.rang(unit, ARCANE_MISSILES, AM_HUM);
|
||||
assert_eq!(loops.stop_hold(unit, None), Some(AM_HUM));
|
||||
edge(&mut loops, play(ARCANE_MISSILES, AM_HUM, true, None));
|
||||
assert_eq!(loops.stop_hold(unit, Some(10)), NONE, "Blizzard's stop");
|
||||
assert_eq!(loops.held(unit), [(ARCANE_MISSILES, AM_HUM)]);
|
||||
assert_eq!(loops.stop_hold(unit, Some(ARCANE_MISSILES)), [AM_HUM]);
|
||||
assert_eq!(loops.held(unit), []);
|
||||
edge(&mut loops, play(ARCANE_MISSILES, AM_HUM, true, None));
|
||||
assert_eq!(loops.stop_hold(unit, None), [AM_HUM]);
|
||||
}
|
||||
|
||||
/// Each loop is an effect of its own on the unit's list (`0x61fedc`): a precast rung after a
|
||||
/// rebuild, in the frame the rebuild replays an aura's loop, still stops at its spell's go
|
||||
/// (`0x614150`), and the aura's at its removal; a replacing hold spares the aura's.
|
||||
#[test]
|
||||
fn each_loop_stops_with_its_own_kit() {
|
||||
let unit = Entity::PLACEHOLDER;
|
||||
let mut loops = HoldLoops::default();
|
||||
edge(
|
||||
&mut loops,
|
||||
play(
|
||||
ARCANE_INTELLECT,
|
||||
AURA_LOOP,
|
||||
false,
|
||||
Some(crate::lanes::stamp()),
|
||||
),
|
||||
);
|
||||
let rebuild = crate::lanes::stamp();
|
||||
// The rebuild's frame in the router's order: a later packet's precast, then the rebuild
|
||||
// and its replay.
|
||||
let precast = play(FIREBALL, BUILDUP, true, Some(crate::lanes::stamp()));
|
||||
assert_eq!(edge(&mut loops, precast), NONE);
|
||||
let rebuilt = SpellKitSound::Rebuilt {
|
||||
entity: unit,
|
||||
at: rebuild,
|
||||
};
|
||||
assert_eq!(edge(&mut loops, rebuilt), [AURA_LOOP], "rang before it");
|
||||
let replay = SpellKitSound::Replay {
|
||||
entity: unit,
|
||||
spell_id: ARCANE_INTELLECT,
|
||||
kit_sound: AURA_LOOP,
|
||||
cast_hold: false,
|
||||
at: rebuild,
|
||||
};
|
||||
edge(&mut loops, replay);
|
||||
assert_eq!(
|
||||
loops.held(unit),
|
||||
[(FIREBALL, BUILDUP), (ARCANE_INTELLECT, AURA_LOOP)]
|
||||
);
|
||||
|
||||
let replacing = SpellKitSound::StopHold {
|
||||
entity: unit,
|
||||
spell_id: None,
|
||||
};
|
||||
assert_eq!(edge(&mut loops, replacing), [BUILDUP], "a new cast's");
|
||||
edge(&mut loops, precast);
|
||||
let go = SpellKitSound::StopHold {
|
||||
entity: unit,
|
||||
spell_id: Some(FIREBALL),
|
||||
};
|
||||
assert_eq!(edge(&mut loops, go), [BUILDUP], "the precast's go");
|
||||
let removal = SpellKitSound::StopKit {
|
||||
entity: unit,
|
||||
kit_sound: AURA_LOOP,
|
||||
};
|
||||
assert_eq!(edge(&mut loops, removal), [AURA_LOOP], "the aura's removal");
|
||||
assert_eq!(loops.held(unit), []);
|
||||
}
|
||||
|
||||
/// The rebuild's loop `0x60ac10` stops every effect the unit holds, kit sounds included
|
||||
/// (`0x61fedc` links them there): a loop rung before the swap stops, the channel's too, whose
|
||||
/// kit the replay rings afresh; one rung after it plays on.
|
||||
#[test]
|
||||
fn a_rebuild_stops_every_hold_loop_rung_before_it() {
|
||||
let unit = Entity::PLACEHOLDER;
|
||||
let mut loops = HoldLoops::default();
|
||||
let rebuilt = |at| SpellKitSound::Rebuilt { entity: unit, at };
|
||||
|
||||
edge(&mut loops, play(ARCANE_MISSILES, AM_HUM, true, None));
|
||||
let swap = crate::lanes::stamp();
|
||||
let precast = play(FIREBALL, BUILDUP, true, Some(crate::lanes::stamp()));
|
||||
edge(&mut loops, precast);
|
||||
assert_eq!(edge(&mut loops, rebuilt(swap)), [AM_HUM], "the channel's");
|
||||
assert_eq!(loops.held(unit), [(FIREBALL, BUILDUP)], "rang after");
|
||||
}
|
||||
|
||||
/// Every stop of a kit's sound is `0x6203e0`'s, a 0.15 s fade (`0x6204b6` → `0x7a5a10`): a
|
||||
/// hold's and an aura's through `0x614150` (`0x6141d8`), the rebuild's through its loop
|
||||
/// `0x60ac10`, never the 15 ms de-click of a force-stop.
|
||||
#[test]
|
||||
fn every_kit_stop_fades_over_0_15_s() {
|
||||
let unit = Entity::PLACEHOLDER;
|
||||
for i in 0..5 {
|
||||
let mut loops = HoldLoops::default();
|
||||
edge(&mut loops, play(FIREBALL, BUILDUP, true, None));
|
||||
edge(&mut loops, play(ARCANE_INTELLECT, AURA_LOOP, false, None));
|
||||
let at = crate::lanes::stamp();
|
||||
let stop = [
|
||||
SpellKitSound::StopHold {
|
||||
entity: unit,
|
||||
spell_id: Some(FIREBALL),
|
||||
},
|
||||
SpellKitSound::StopHold {
|
||||
entity: unit,
|
||||
spell_id: None,
|
||||
},
|
||||
SpellKitSound::StopKit {
|
||||
entity: unit,
|
||||
kit_sound: AURA_LOOP,
|
||||
},
|
||||
SpellKitSound::Rebuilt { entity: unit, at },
|
||||
SpellKitSound::Replay {
|
||||
entity: unit,
|
||||
spell_id: ARCANE_INTELLECT,
|
||||
kit_sound: AURA_LOOP,
|
||||
cast_hold: false,
|
||||
at,
|
||||
},
|
||||
][i];
|
||||
let fades: Vec<_> = loops
|
||||
.stops(&stop)
|
||||
.into_iter()
|
||||
.map(|s| s.fade.duration)
|
||||
.collect();
|
||||
assert!(
|
||||
!fades.is_empty()
|
||||
&& fades
|
||||
.iter()
|
||||
.all(|&d| d == std::time::Duration::from_millis(150)),
|
||||
"{stop:?}: {fades:?}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1364,6 +1364,7 @@ fn cast_result_rest(
|
||||
spell_id,
|
||||
kind: CastEventKind::Fail,
|
||||
seq,
|
||||
at: Some(crate::lanes::stamp()),
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1544,6 +1545,7 @@ fn spell_start(
|
||||
spell_id,
|
||||
kind: CastEventKind::Start,
|
||||
seq,
|
||||
at: Some(crate::lanes::stamp()),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1698,6 +1700,8 @@ fn spell_go(
|
||||
})
|
||||
.collect();
|
||||
|
||||
// The GO's place among the packets, one for every leg it plays: the cast kit, the impacts.
|
||||
let at = crate::lanes::stamp();
|
||||
// The caster slot is the second guid looked up as a unit (`0x6e7f8b`, mask 8): a game object's
|
||||
// cast writes it 0, so it finds none and skips every leg that needs one.
|
||||
let unit = index
|
||||
@@ -1720,6 +1724,7 @@ fn spell_go(
|
||||
target_mask: mask,
|
||||
ammo_display_id,
|
||||
seq,
|
||||
at: Some(at),
|
||||
});
|
||||
}
|
||||
return deferred;
|
||||
@@ -1747,6 +1752,7 @@ fn spell_go(
|
||||
spell_id,
|
||||
kind: CastEventKind::Go,
|
||||
seq,
|
||||
at: Some(at),
|
||||
});
|
||||
// A pure point cast (ground AoE, empty lists) rides the same message: the point is a target.
|
||||
let source = source.map(benilla_assets::coords::wow_to_bevy);
|
||||
@@ -1762,6 +1768,7 @@ fn spell_go(
|
||||
target_mask: mask,
|
||||
ammo_display_id,
|
||||
seq,
|
||||
at: Some(at),
|
||||
});
|
||||
}
|
||||
deferred
|
||||
@@ -1811,6 +1818,7 @@ fn spell_failed_other(
|
||||
spell_id,
|
||||
kind: CastEventKind::Fail,
|
||||
seq,
|
||||
at: Some(crate::lanes::stamp()),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -670,6 +670,7 @@ pub(super) fn drain_chat_input(
|
||||
spell_id,
|
||||
kind,
|
||||
seq: play_seq.next(),
|
||||
at: None,
|
||||
});
|
||||
// A selected caster's GO hits us, so a missile flies end to end; a
|
||||
// self-cast has no target. `ground` sends the pure dest shape instead,
|
||||
@@ -691,6 +692,7 @@ pub(super) fn drain_chat_input(
|
||||
target_mask: 0x40,
|
||||
ammo_display_id: None,
|
||||
seq: play_seq.next(),
|
||||
at: None,
|
||||
});
|
||||
} else if let Some(me) = me.filter(|&m| m != entity) {
|
||||
go_targets.write(crate::creature_anim::SpellGoTargets {
|
||||
@@ -705,6 +707,7 @@ pub(super) fn drain_chat_input(
|
||||
// Rough Arrow, display id 5996.
|
||||
ammo_display_id: Some(5996),
|
||||
seq: play_seq.next(),
|
||||
at: None,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -308,6 +308,11 @@ impl ParticleEmitter {
|
||||
self.on_owner_loss = OwnerLoss::Drain;
|
||||
}
|
||||
|
||||
/// What losing the owner does to this pool ([`Self::drain_on_owner_loss`]).
|
||||
pub fn on_owner_loss(&self) -> OwnerLoss {
|
||||
self.on_owner_loss
|
||||
}
|
||||
|
||||
/// The cloud's live world anchor, the census probe's distance subject.
|
||||
pub fn anchor_world(&self) -> Vec3 {
|
||||
self.anchor_pos
|
||||
|
||||
+2
-2
@@ -115,7 +115,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
- A mounted draw is refused at the setter, because our rider track never replays the reference's per-play force-stow (`0x5fdf80`); the result is the same. ([`src/creature_anim/driver.rs:769`](../crates/benilla-app/src/creature_anim/driver.rs#L769))
|
||||
- The reference writes bone 0's rate blindly; we scope it to the swing's own node, because a moving attacker's gait would otherwise slow too. ([`src/creature_anim/driver.rs:1088`](../crates/benilla-app/src/creature_anim/driver.rs#L1088))
|
||||
- A time-based rate, because the reference's per-frame step changes with the frame rate. ([`src/creature_anim/select.rs:137`](../crates/benilla-app/src/creature_anim/select.rs#L137))
|
||||
- A spell's state kit and body procs are reaped only once no slot holds the spell. ([`src/creature_anim/spell_visual.rs:1275`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1275))
|
||||
- A spell's state kit and body procs are reaped only once no slot holds the spell. ([`src/creature_anim/spell_visual.rs:1351`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1351))
|
||||
|
||||
#### cvars
|
||||
|
||||
@@ -278,7 +278,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
#### spell
|
||||
|
||||
- An out-of-range byte drops the packet, because the reference's unchecked write overruns the table (`(64, 19)` lands on the class family at `0xcecaac`). ([`src/spell/mods.rs:131`](../crates/benilla-app/src/spell/mods.rs#L131))
|
||||
- The fallback is the packet's target guid, started only when the validator keeps it (`on_spell_go`), and with none there is no start, never the nearest-hostile acquire, because that would attack something the player never named. ([`src/spell/net.rs:1670`](../crates/benilla-app/src/spell/net.rs#L1670))
|
||||
- The fallback is the packet's target guid, started only when the validator keeps it (`on_spell_go`), and with none there is no start, never the nearest-hostile acquire, because that would attack something the player never named. ([`src/spell/net.rs:1672`](../crates/benilla-app/src/spell/net.rs#L1672))
|
||||
- A range failure leaves targeting armed and working. The reference's report cancels the cast (`0x6e2218` → `0x6e4940`): its line, `SPELLCAST_FAILED` and the tradeskill disarm, which benilla keeps; with the word the bind emptied it also sends `CMSG_CANCEL_CAST` for the unsent spell (`0x6e4970`) and clears the caster, then restores the pre-click word (`0x6e6096`), so every later click fails the caster test (`0x6e5b93`) and the cursor is stranded until a cancel. ([`src/spell/targeting/mod.rs:661`](../crates/benilla-app/src/spell/targeting/mod.rs#L661))
|
||||
|
||||
#### target
|
||||
|
||||
Reference in New Issue
Block a user