Spell packets, cancels and the cast slot follow 1.12.1, with no timers (#2186)
Spell packets and cast state went wrong: - A start or go with no record, or a non-unit's start, drew a cast. - An enemy casting at you never became your target. - Cooldown packets for other guids were dropped. - Esc and move cancels reaped the wrong spell. - Timers freed the cast slot. - Spell state outlived a relog. - Openers were scanned by id. The reference: - Both handlers exit first (`0x6e7876`, `0x6e7cd7`). - A start aimed at you selects its caster (`0x6e799c`). - Only the pet's guid routes to the pet (`0x6e9696`). - The cancel reaps the record's spell (`0x6e4a8e`). - No timer frees the slot; an inventory refusal cancels its item's cast (`0x5e3ab3`). - World entry zeroes the spell state (`0x6e7150`). - Openers keep the server's order (`0x5f83d0`). Hold stops are now keyed by spell (`0x614167`). Each fact is tested against its address. Fixes #2162 Fixes #1302 Fixes #1292 Fixes #1301 Fixes #2163 Fixes #2025 Fixes #1327 Fixes #293 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -247,7 +247,8 @@ fn chest_probe(
|
||||
.find(|(g, ..)| g.0 == guid)
|
||||
.map(|(_, _, store, _, anim)| (store, crate::go_anim::go_state(anim, store)));
|
||||
let me_store = self_store.single().ok();
|
||||
match resolve_go_action(guid, &mut go_inputs, &actions.spells, go, me_store, &net) {
|
||||
match resolve_go_action(guid, &mut go_inputs, &actions.openers, go, me_store, &net)
|
||||
{
|
||||
GoAction::Use => {
|
||||
info!("PROBE_CHEST: lockless — CMSG_GAMEOBJ_USE on {guid:#x}");
|
||||
let _ = net.0.send(ClientCommand::GameObjUse { guid });
|
||||
|
||||
@@ -251,10 +251,14 @@ pub(crate) fn start_attack_local(
|
||||
// A ranged spell's precast (`Attributes & 0x2`, `0x5ecc79`) cancels what is in flight,
|
||||
// `CancelCast(1, 1, 0x1c)` (`0x5ecc85`), and the attack goes on.
|
||||
if precast_record().is_some_and(|d| d.ranged_slot()) {
|
||||
if let Some(spell_id) = core.cancel_reaping(true, true, crate::spell::REASON_ERROR, spells)
|
||||
{
|
||||
edits.push(UnitEdit::AbortCasting { entity, spell_id });
|
||||
}
|
||||
core.cancel_reaping(
|
||||
true,
|
||||
true,
|
||||
crate::spell::REASON_ERROR,
|
||||
spells,
|
||||
Some(entity),
|
||||
edits,
|
||||
);
|
||||
}
|
||||
let net = core.net;
|
||||
// Starting an attack stands you up (`0x5ecc9b`), after the attackability check but before
|
||||
@@ -1095,7 +1099,6 @@ mod attack_stand_tests {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
std::time::Instant::now(),
|
||||
);
|
||||
},
|
||||
)
|
||||
|
||||
@@ -28,9 +28,9 @@ pub(crate) enum UnitEdit {
|
||||
/// The cast's reap (`0x614150(spellId, 0)`, keyed by the spell): its [`Casting`], while that
|
||||
/// is still this spell's.
|
||||
ReapCasting { entity: Entity, spell_id: u32 },
|
||||
/// `CancelCast`'s reap, from a seam with no message writer (StartAttack's, `0x5ecc85`): the
|
||||
/// record's spell as its tail keys and gates it ([`crate::spell::CastCore::cancel_reaping`]),
|
||||
/// and the failed cast event the server's echo would bring, stamped as it applies.
|
||||
/// `CancelCast`'s reap (`0x614150` at `0x6e4ab7`): the record's spell as its tail keys and
|
||||
/// gates it ([`crate::spell::CastCore::cancel_reaping`]), and the failed cast event the
|
||||
/// server's echo would bring, stamped as it applies.
|
||||
AbortCasting { entity: Entity, spell_id: u32 },
|
||||
/// The sticky auto-repeat arm (`0x6e593b`, `|= 0x200`).
|
||||
ArmAutoRepeat(Entity),
|
||||
|
||||
@@ -69,11 +69,22 @@ pub(crate) struct SpellVisuals(pub(crate) SpellVisualCatalog);
|
||||
/// `crate::sound` in emission order.
|
||||
#[derive(Message, Clone, Copy, Debug)]
|
||||
pub(crate) enum SpellKitSound {
|
||||
/// Ring this kit at the unit; a looping kit (`SoundEntries` flag 0x200) becomes the unit's
|
||||
/// tracked hold loop until [`Self::StopHold`] (`0x458830` → `0x61fec0`, one-shot `0x458870`).
|
||||
Play { entity: Entity, kit_sound: u32 },
|
||||
/// The cast or channel hold ended: stop the unit's hold loop (`0x614150`).
|
||||
StopHold { entity: Entity },
|
||||
/// Ring this kit at the unit for `spell_id`'s kit, 0 for a kit push; a looping kit
|
||||
/// (`SoundEntries` flag 0x200) becomes the unit's tracked hold loop until [`Self::StopHold`]
|
||||
/// (`0x458830` → `0x61fec0`, one-shot `0x458870`). The effect it rides carries the spell
|
||||
/// (`+0x18`), which the stop keys on.
|
||||
Play {
|
||||
entity: Entity,
|
||||
spell_id: u32,
|
||||
kit_sound: u32,
|
||||
},
|
||||
/// 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.
|
||||
StopHold {
|
||||
entity: Entity,
|
||||
spell_id: Option<u32>,
|
||||
},
|
||||
/// Ring this kit at a world point, the kit play's `extra` override (`0x60f49e`): a missile's
|
||||
/// ground arrival. Always a one-shot: no shipped ground-arrival kit loops.
|
||||
PlayAt { pos: Vec3, kit_sound: u32 },
|
||||
@@ -540,7 +551,11 @@ fn play_kit(
|
||||
}
|
||||
}
|
||||
if let Some(kit_sound) = kit.sound.filter(|_| play.sound) {
|
||||
out.sounds.write(SpellKitSound::Play { entity, kit_sound });
|
||||
out.sounds.write(SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
});
|
||||
}
|
||||
// The camera shake plays at every stage, gated on nothing.
|
||||
if let Some(group) = kit.shake {
|
||||
@@ -631,8 +646,9 @@ fn play_impact(
|
||||
/// The cast-edge router: wire [`CastEvent`]s and the public channel field → animation intents.
|
||||
///
|
||||
/// - Start: the precast kit's anim becomes the [`CastHold`] (stage 4) and its sound rings.
|
||||
/// - Go: the hold drops and the cast kit plays; the GO's targets play their impacts inline when
|
||||
/// `Spell.dbc` Speed is 0 (`0x6e8bf0`), else fly a [`MissileSpawn`] (`0x6e8a50`).
|
||||
/// - Go: the hold drops, its spell's and the running auto-repeat spell's, and the cast kit plays;
|
||||
/// the GO's targets play their impacts inline when `Spell.dbc` Speed is 0 (`0x6e8bf0`), else
|
||||
/// fly a [`MissileSpawn`] (`0x6e8a50`).
|
||||
/// - Impact: a missile arrived on this unit ([`play_impact`]).
|
||||
/// - Fail: the hold drops silently.
|
||||
/// - Channel: `UNIT_CHANNEL_SPELL` polled per frame (`0x612a30`); observers have no packet. A set
|
||||
@@ -649,7 +665,11 @@ pub(super) fn route_cast_visuals(
|
||||
mut sheaths: MessageWriter<super::SheathRequest>,
|
||||
mut spawns: KitSpawnWriters,
|
||||
visuals: Option<Res<SpellVisuals>>,
|
||||
spells: Option<Res<crate::ui_action::Spells>>,
|
||||
// The running auto-repeat spell `[0xceac30]`, whose kits every go stops on its caster.
|
||||
(spells, auto_repeat): (
|
||||
Option<Res<crate::ui_action::Spells>>,
|
||||
Option<Res<crate::spell::AutoRepeatActive>>,
|
||||
),
|
||||
mut weapon_src: WeaponVisualSrc,
|
||||
units: Query<(Entity, &ObjectStore), Without<ItemObject>>,
|
||||
holds: Query<&CastHold>,
|
||||
@@ -713,8 +733,10 @@ pub(super) fn route_cast_visuals(
|
||||
match ev.kind {
|
||||
CastEventKind::Start => {
|
||||
// A replacing cast reaps the prior hold's loop and persistent models first.
|
||||
out.sounds
|
||||
.write(SpellKitSound::StopHold { entity: ev.entity });
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity: ev.entity,
|
||||
spell_id: None,
|
||||
});
|
||||
if let Some(prior) = held_spell(&pending, ev.entity) {
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
entity: ev.entity,
|
||||
@@ -762,6 +784,7 @@ pub(super) fn route_cast_visuals(
|
||||
if let Some(kit_sound) = kit.sound {
|
||||
out.sounds.write(SpellKitSound::Play {
|
||||
entity: ev.entity,
|
||||
spell_id: ev.spell_id,
|
||||
kit_sound,
|
||||
});
|
||||
}
|
||||
@@ -785,14 +808,35 @@ pub(super) fn route_cast_visuals(
|
||||
commands.entity(ev.entity).try_remove::<CastHold>();
|
||||
pending.insert(ev.entity, None);
|
||||
}
|
||||
// Reaped whatever the hold: a precast kit with no anim still starts a loop.
|
||||
out.sounds
|
||||
.write(SpellKitSound::StopHold { entity: ev.entity });
|
||||
// The spell's own loop (`0x614150(spellId, 0)`), whatever the hold: a precast kit
|
||||
// with no anim still starts a loop.
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity: ev.entity,
|
||||
spell_id: Some(ev.spell_id),
|
||||
});
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
entity: ev.entity,
|
||||
spell_id: ev.spell_id,
|
||||
class: FxClass::Hold,
|
||||
});
|
||||
// Then the running auto-repeat spell's on the same unit, `0x614150([0xceac30], 0)`
|
||||
// whenever it is set (`0x6e7fed`-`0x6e7ffb`), whoever casts the go: the gate of
|
||||
// the go's own stop (`0x6e7fca`) does not reach it.
|
||||
if let Some(repeat) = auto_repeat.as_ref().and_then(|a| a.0) {
|
||||
if held_spell(&pending, ev.entity) == Some(repeat) {
|
||||
commands.entity(ev.entity).try_remove::<CastHold>();
|
||||
pending.insert(ev.entity, None);
|
||||
}
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity: ev.entity,
|
||||
spell_id: Some(repeat),
|
||||
});
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
entity: ev.entity,
|
||||
spell_id: repeat,
|
||||
class: FxClass::Hold,
|
||||
});
|
||||
}
|
||||
// A ranged-slot GO redraws ranged before the cast kit (`0x60f34c`, gate
|
||||
// `Attributes & 0x2`, stages 0 and 4): what redraws a bow an emote lowered.
|
||||
if spells
|
||||
@@ -860,8 +904,12 @@ pub(super) fn route_cast_visuals(
|
||||
commands.entity(ev.entity).try_remove::<CastHold>();
|
||||
pending.insert(ev.entity, None);
|
||||
}
|
||||
out.sounds
|
||||
.write(SpellKitSound::StopHold { entity: ev.entity });
|
||||
// The spell's own loop only (`0x614167`): a cancel's reap of the record's
|
||||
// spell spares a channel another spell runs.
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity: ev.entity,
|
||||
spell_id: Some(ev.spell_id),
|
||||
});
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
entity: ev.entity,
|
||||
spell_id: ev.spell_id,
|
||||
@@ -968,7 +1016,10 @@ pub(super) fn route_cast_visuals(
|
||||
}
|
||||
channel_cache.insert(entity, cur);
|
||||
if cur != 0 {
|
||||
out.sounds.write(SpellKitSound::StopHold { entity });
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity,
|
||||
spell_id: None,
|
||||
});
|
||||
if prev != 0 {
|
||||
// A channel replacing a channel reaps the old spell's effects first.
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
@@ -990,7 +1041,11 @@ pub(super) fn route_cast_visuals(
|
||||
pending.insert(entity, Some(cur));
|
||||
}
|
||||
if let Some(kit_sound) = kit.sound {
|
||||
out.sounds.write(SpellKitSound::Play { entity, kit_sound });
|
||||
out.sounds.write(SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id: cur,
|
||||
kit_sound,
|
||||
});
|
||||
}
|
||||
// The CharProc dispatcher's second caller (`0x612b18`): Drain Life's beam is
|
||||
// reached only here, on the rising edge, and lives until the field clears.
|
||||
@@ -1025,7 +1080,10 @@ pub(super) fn route_cast_visuals(
|
||||
commands.entity(entity).try_remove::<CastHold>();
|
||||
pending.insert(entity, None);
|
||||
}
|
||||
out.sounds.write(SpellKitSound::StopHold { entity });
|
||||
out.sounds.write(SpellKitSound::StopHold {
|
||||
entity,
|
||||
spell_id: Some(prev),
|
||||
});
|
||||
out.fx.write(SpellKitFx::Reap {
|
||||
entity,
|
||||
spell_id: prev,
|
||||
@@ -1166,7 +1224,11 @@ pub(crate) fn arm_aura_state_fx(
|
||||
}
|
||||
// Ungated; a same-frame duplicate of the impact hand-off's collapses downstream.
|
||||
if let Some(kit_sound) = kit.sound {
|
||||
sounds.write(SpellKitSound::Play { entity, kit_sound });
|
||||
sounds.write(SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
});
|
||||
}
|
||||
// The stage-2 anim leg, on the add edge only: an aura refreshed in place keeps its id,
|
||||
// and `0x604d00` fires neither arm.
|
||||
|
||||
@@ -2133,3 +2133,280 @@ fn a_sweeps_pins_arm_in_slot_order() {
|
||||
"slot 33's kit armed last, so it is the head"
|
||||
);
|
||||
}
|
||||
|
||||
/// `CancelCast`'s reap is `0x614150` on the record's spell (`0x6e4a8e`-`0x6e4ab7`), which stops
|
||||
/// only the effects that spell's kits made (`0x614167`): Esc with Blizzard's cursor up over a
|
||||
/// running Arcane Missiles channel ends the cursor and leaves the channel's hold and its loop.
|
||||
#[test]
|
||||
fn esc_with_a_cursor_up_leaves_the_running_channels_hold_and_loop() {
|
||||
use benilla_protocol::messages::{ObjectFields, ObjectType};
|
||||
use bevy::ecs::system::RunSystemOnce;
|
||||
|
||||
const ARCANE_MISSILES: u32 = 5143;
|
||||
const AM_VISUAL: u32 = 225;
|
||||
const AM_CHANNEL_KIT: u32 = 436;
|
||||
const AM_HUM: u32 = 3136;
|
||||
const BLIZZARD: u32 = 10;
|
||||
const ME: u64 = 10;
|
||||
|
||||
let mut app = app();
|
||||
app.insert_resource(SpellVisuals(SpellVisualCatalog::from_tables(
|
||||
HashMap::from([(
|
||||
AM_VISUAL,
|
||||
VisualStages {
|
||||
channel: AM_CHANNEL_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
HashMap::from([(
|
||||
AM_CHANNEL_KIT,
|
||||
VisualKit {
|
||||
anim_id: Some(HOLD_ANIM),
|
||||
sound: Some(AM_HUM),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
)));
|
||||
app.insert_resource(crate::ui_action::Spells {
|
||||
catalog: SpellCatalog::from_displays(HashMap::from([
|
||||
(
|
||||
ARCANE_MISSILES,
|
||||
SpellDisplay {
|
||||
visual: AM_VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(BLIZZARD, SpellDisplay::default()),
|
||||
])),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
});
|
||||
// What the cancel reads and writes.
|
||||
let (tx, _rx) = crossbeam_channel::unbounded();
|
||||
app.insert_resource(crate::net::NetCommands(tx))
|
||||
.init_resource::<crate::spell::PendingCast>()
|
||||
.init_resource::<crate::spell::QueuedMeleeSpell>()
|
||||
.init_resource::<crate::spell::ActiveChannel>()
|
||||
.init_resource::<crate::spell::AutoRepeatActive>()
|
||||
.init_resource::<crate::spell::SpellTargeting>()
|
||||
.init_resource::<crate::ui_cast::CastReports>()
|
||||
.init_resource::<crate::creature_anim::UnitEdits>()
|
||||
.init_resource::<crate::creature_anim::PlaySeq>()
|
||||
.init_resource::<crate::net::GuidIndex>()
|
||||
.init_resource::<crate::net::SelfGuid>();
|
||||
// The player, channelling: `UNIT_CHANNEL_SPELL` (144) holds Arcane Missiles.
|
||||
let me = app
|
||||
.world_mut()
|
||||
.spawn((
|
||||
crate::net::Guid(ME),
|
||||
crate::net::SelfPlayer,
|
||||
crate::net::ObjectStore(
|
||||
ObjectFields::from_pairs(&[(144, ARCANE_MISSILES)])
|
||||
.into_created(ObjectType::Player),
|
||||
),
|
||||
))
|
||||
.id();
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::net::GuidIndex>()
|
||||
.0
|
||||
.insert(ME, me);
|
||||
app.world_mut().resource_mut::<crate::net::SelfGuid>().0 = Some(ME);
|
||||
let sounds = |app: &mut App| -> Vec<SpellKitSound> {
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.collect()
|
||||
};
|
||||
|
||||
// The channel poll's rising edge holds the channel and rings its hum.
|
||||
app.update();
|
||||
let rise = sounds(&mut app);
|
||||
assert!(
|
||||
rise.iter().any(|s| matches!(
|
||||
s,
|
||||
SpellKitSound::Play { entity, kit_sound, .. } if *entity == me && *kit_sound == AM_HUM
|
||||
)),
|
||||
"the channel's loop (got {rise:?})"
|
||||
);
|
||||
assert_eq!(hold(&app, me), Some(ARCANE_MISSILES));
|
||||
|
||||
// Blizzard's attempt fills the record (`0x6e4f88`, `0x6e4fb1`) and raises its cursor.
|
||||
{
|
||||
let world = app.world_mut();
|
||||
let mut pending = world.resource_mut::<crate::spell::PendingCast>();
|
||||
pending.fill_record();
|
||||
pending.fill_record_spell(BLIZZARD);
|
||||
world.resource_mut::<crate::spell::SpellTargeting>().enter(
|
||||
BLIZZARD,
|
||||
crate::spell::CastCommit::Spell,
|
||||
0x40,
|
||||
);
|
||||
}
|
||||
// Esc: `SpellStopCasting` (`0x6e6e80` → `0x6e4940(0, 1, 0x1c)`).
|
||||
app.world_mut()
|
||||
.run_system_once(|mut cancel: crate::spell::SelfCancel| cancel.stop_casting())
|
||||
.unwrap();
|
||||
crate::creature_anim::apply_unit_edits(app.world_mut());
|
||||
app.update();
|
||||
|
||||
assert!(
|
||||
!app.world()
|
||||
.resource::<crate::spell::SpellTargeting>()
|
||||
.active(),
|
||||
"the cursor is down"
|
||||
);
|
||||
assert_eq!(hold(&app, me), Some(ARCANE_MISSILES), "the channel's hold");
|
||||
let after = sounds(&mut app);
|
||||
// The sound router's books over both frames, the hum a looping kit.
|
||||
let mut loops = crate::sound::HoldLoops::default();
|
||||
for ev in rise.iter().chain(&after) {
|
||||
match *ev {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound: AM_HUM,
|
||||
} => loops.rang(entity, spell_id, AM_HUM),
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
loops.stop_hold(entity, spell_id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
loops.held(me),
|
||||
Some((ARCANE_MISSILES, AM_HUM)),
|
||||
"Blizzard's reap stops none of the channel's sound (got {after:?})"
|
||||
);
|
||||
}
|
||||
|
||||
/// Beside its own stop, a spell go stops its caster's kits of the running auto-repeat spell
|
||||
/// `[0xceac30]` (`0x6e7fed` when set, `0x6e7ffb` with force 0): another spell's go ends an Auto
|
||||
/// Shot hold and its loop on its caster and on no other unit, and with no auto-repeat running it
|
||||
/// ends neither.
|
||||
#[test]
|
||||
fn a_go_stops_the_running_auto_repeat_spells_hold_and_loop_on_its_caster() {
|
||||
use crate::sound::HoldLoops;
|
||||
|
||||
const AUTO_SHOT: u32 = 75;
|
||||
const AUTO_SHOT_VISUAL: u32 = 2003;
|
||||
const AUTO_SHOT_PRECAST_KIT: u32 = 3030;
|
||||
const AUTO_SHOT_LOOP: u32 = 4040;
|
||||
const ARCANE_SHOT: u32 = 3044;
|
||||
|
||||
/// One frame of `events` through the router, its sounds through the sound router's books (the
|
||||
/// Auto Shot sound a looping kit); returns the hold reaps it wrote.
|
||||
fn frame(app: &mut App, loops: &mut HoldLoops, events: &[CastEvent]) -> Vec<(Entity, u32)> {
|
||||
for &ev in events {
|
||||
app.world_mut().write_message(ev);
|
||||
}
|
||||
app.update();
|
||||
let sounds: Vec<SpellKitSound> = app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<SpellKitSound>>()
|
||||
.drain()
|
||||
.collect();
|
||||
for ev in sounds {
|
||||
match ev {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound: AUTO_SHOT_LOOP,
|
||||
} => loops.rang(entity, spell_id, AUTO_SHOT_LOOP),
|
||||
SpellKitSound::StopHold { entity, spell_id } => {
|
||||
loops.stop_hold(entity, spell_id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<SpellKitFx>>()
|
||||
.drain()
|
||||
.filter_map(|fx| match fx {
|
||||
SpellKitFx::Reap {
|
||||
entity, spell_id, ..
|
||||
} => Some((entity, spell_id)),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
let mut app = app();
|
||||
app.insert_resource(SpellVisuals(SpellVisualCatalog::from_tables(
|
||||
HashMap::from([(
|
||||
AUTO_SHOT_VISUAL,
|
||||
VisualStages {
|
||||
precast: AUTO_SHOT_PRECAST_KIT,
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
HashMap::from([(
|
||||
AUTO_SHOT_PRECAST_KIT,
|
||||
VisualKit {
|
||||
anim_id: Some(HOLD_ANIM),
|
||||
sound: Some(AUTO_SHOT_LOOP),
|
||||
..Default::default()
|
||||
},
|
||||
)]),
|
||||
)));
|
||||
app.insert_resource(crate::ui_action::Spells {
|
||||
catalog: SpellCatalog::from_displays(HashMap::from([
|
||||
(
|
||||
AUTO_SHOT,
|
||||
SpellDisplay {
|
||||
visual: AUTO_SHOT_VISUAL,
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
(ARCANE_SHOT, SpellDisplay::default()),
|
||||
])),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
});
|
||||
app.insert_resource(crate::spell::AutoRepeatActive(Some(AUTO_SHOT)));
|
||||
let hunter = app.world_mut().spawn_empty().id();
|
||||
let other = app.world_mut().spawn_empty().id();
|
||||
let mut loops = HoldLoops::default();
|
||||
|
||||
frame(
|
||||
&mut app,
|
||||
&mut loops,
|
||||
&[
|
||||
cast_event(hunter, AUTO_SHOT, CastEventKind::Start),
|
||||
cast_event(other, AUTO_SHOT, CastEventKind::Start),
|
||||
],
|
||||
);
|
||||
assert_eq!(hold(&app, hunter), Some(AUTO_SHOT));
|
||||
assert_eq!(loops.held(hunter), Some((AUTO_SHOT, AUTO_SHOT_LOOP)));
|
||||
|
||||
let reaped = frame(
|
||||
&mut app,
|
||||
&mut loops,
|
||||
&[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!(
|
||||
reaped,
|
||||
vec![(hunter, ARCANE_SHOT), (hunter, AUTO_SHOT)],
|
||||
"the go's own spell, then the auto-repeat spell, on the caster alone"
|
||||
);
|
||||
assert_eq!(hold(&app, other), Some(AUTO_SHOT), "another unit's hold");
|
||||
assert_eq!(
|
||||
loops.held(other),
|
||||
Some((AUTO_SHOT, AUTO_SHOT_LOOP)),
|
||||
"and its loop"
|
||||
);
|
||||
|
||||
// With no auto-repeat running, another spell's go leaves both.
|
||||
app.insert_resource(crate::spell::AutoRepeatActive(None));
|
||||
frame(
|
||||
&mut app,
|
||||
&mut loops,
|
||||
&[cast_event(hunter, AUTO_SHOT, CastEventKind::Start)],
|
||||
);
|
||||
frame(
|
||||
&mut app,
|
||||
&mut loops,
|
||||
&[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)));
|
||||
}
|
||||
|
||||
@@ -164,6 +164,7 @@ pub(super) fn arm_ground_effects(
|
||||
if let Some(kit_sound) = kit.sound {
|
||||
sounds.write(SpellKitSound::Play {
|
||||
entity: anchor,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -56,6 +56,8 @@ pub(crate) use greeting::NpcGreetingRequest;
|
||||
pub(crate) use kit::SoundKits;
|
||||
pub(crate) use message::MessageSounds;
|
||||
pub(crate) use mixer::Mixer;
|
||||
#[cfg(test)]
|
||||
pub(crate) use spell::HoldLoops;
|
||||
pub(crate) use ui::{AutoEquipSound, LootPickupSound};
|
||||
pub(crate) use zone::ExplorationSounds;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
//! field 13) played at the casting unit, split as the reference's looping test (`0x458830`)
|
||||
//! splits it. A plain kit is a positioned one-shot (`0x458870`); a looping kit (Fireball's
|
||||
//! buildup 702, Arcane Missiles' hum 3136) is a channel tracked to the caster (`0x61fec0`),
|
||||
//! reaped by [`SpellKitSound::StopHold`] as the reference kills the effect's sound at `0x614150`.
|
||||
//! reaped by [`SpellKitSound::StopHold`] as the reference kills the effect's sound at `0x614150`,
|
||||
//! keyed by the spell whose kit rang it ([`HoldLoops`]).
|
||||
|
||||
use bevy::ecs::entity::EntityHashMap;
|
||||
use bevy::prelude::*;
|
||||
@@ -17,6 +18,43 @@ 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.
|
||||
#[derive(Default)]
|
||||
pub(crate) struct HoldLoops(EntityHashMap<(u32, u32)>);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/// [`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)
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
self.0.remove(&entity);
|
||||
}
|
||||
}
|
||||
|
||||
/// The loop the unit holds: its spell and kit.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn held(&self, entity: Entity) -> Option<(u32, u32)> {
|
||||
self.0.get(&entity).copied()
|
||||
}
|
||||
}
|
||||
|
||||
fn route_spell_kit_sounds(
|
||||
mut events: MessageReader<SpellKitSound>,
|
||||
transforms: Query<&Transform, Without<Camera3d>>,
|
||||
@@ -25,12 +63,12 @@ fn route_spell_kit_sounds(
|
||||
mut out: NonSendMut<SoundOutput>,
|
||||
config: Res<SoundConfig>,
|
||||
listener: Res<AudioListener>,
|
||||
// Each unit's live hold-loop kit, so StopHold reaps only that kit's channels.
|
||||
mut hold_loops: Local<EntityHashMap<u32>>,
|
||||
// Each unit's live hold loop, so StopHold reaps only that kit's channels.
|
||||
mut hold_loops: Local<HoldLoops>,
|
||||
mut despawned: RemovedComponents<NetEntity>,
|
||||
) {
|
||||
for entity in despawned.read() {
|
||||
hold_loops.remove(&entity); // the channel dies with the source-channel despawn reaper
|
||||
hold_loops.0.remove(&entity); // the channel dies with the source-channel despawn reaper
|
||||
}
|
||||
if events.is_empty() {
|
||||
return;
|
||||
@@ -44,7 +82,11 @@ fn route_spell_kit_sounds(
|
||||
let mut played_now: Vec<(Entity, u32)> = Vec::new();
|
||||
for ev in events.read() {
|
||||
match *ev {
|
||||
SpellKitSound::Play { entity, kit_sound } => {
|
||||
SpellKitSound::Play {
|
||||
entity,
|
||||
spell_id,
|
||||
kit_sound,
|
||||
} => {
|
||||
if played_now.contains(&(entity, kit_sound)) {
|
||||
continue;
|
||||
}
|
||||
@@ -81,9 +123,7 @@ fn route_spell_kit_sounds(
|
||||
)
|
||||
};
|
||||
match played {
|
||||
Ok(_) if looping => {
|
||||
hold_loops.insert(entity, kit_sound);
|
||||
}
|
||||
Ok(_) if looping => hold_loops.rang(entity, spell_id, kit_sound),
|
||||
Ok(_) => {}
|
||||
Err(e) => warn!("spell kit sound {kit_sound}: {e:#}"),
|
||||
}
|
||||
@@ -105,16 +145,14 @@ fn route_spell_kit_sounds(
|
||||
warn!("spell kit sound {kit_sound}: {e:#}");
|
||||
}
|
||||
}
|
||||
SpellKitSound::StopHold { entity } => {
|
||||
if let Some(kit_sound) = hold_loops.remove(&entity) {
|
||||
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.
|
||||
if hold_loops.get(&entity) == Some(&kit_sound) {
|
||||
hold_loops.remove(&entity);
|
||||
}
|
||||
hold_loops.stopped_kit(entity, kit_sound);
|
||||
super::kit::stop_source_kit(&mut out, entity, kit_sound);
|
||||
}
|
||||
}
|
||||
@@ -125,3 +163,26 @@ fn route_spell_kit_sounds(
|
||||
pub(super) fn plugin(app: &mut App) {
|
||||
app.add_systems(Update, route_spell_kit_sounds.in_set(WorldStage::Present));
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// `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.
|
||||
#[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));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,14 +330,13 @@ impl CastLadder<'_, '_> {
|
||||
},
|
||||
};
|
||||
let now = Instant::now();
|
||||
// The spell its attempt pushed stays in the slot through the send; the guard holds it from
|
||||
// here, as for a cast sent at its attempt.
|
||||
// The spell its attempt pushed stays in the slot through the send, as for a cast sent at
|
||||
// its attempt.
|
||||
if self.ground.in_slot() == Some(spell_id) {
|
||||
self.pending.push_cast(
|
||||
spell_id,
|
||||
item_flags(&self.items, commit),
|
||||
commit.item_guid(),
|
||||
now,
|
||||
);
|
||||
}
|
||||
// The bind emptied the word, and signals before it sends (`0x6e60cb`, `0x6e615d`).
|
||||
@@ -973,7 +972,7 @@ fn send_spell_cast(
|
||||
// never holds it here. The arm signals whatever it then decides (`0x6e5333`).
|
||||
let held = held(items, commit, def, pending_word.is_some());
|
||||
if let Some(held) = held {
|
||||
core.push(spell_id, held, now);
|
||||
core.push(spell_id, held);
|
||||
}
|
||||
core.reports.changed();
|
||||
// The deferred ArmCast-false refusal (`6e5045`-`6e50a9`): every rung passed and nothing
|
||||
@@ -2179,8 +2178,8 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The attempt's in-flight rungs and the report's tail read one slot (`0xceca88`): a cast
|
||||
/// running outside it (an item's without `ITEM_FLAG_PLAYERCAST`, or a guard that lapsed) is no
|
||||
/// same-spell bail for a press of its spell (`0x6e4d43`), and that press's refusal finds
|
||||
/// running outside it (an item's without `ITEM_FLAG_PLAYERCAST`) is no same-spell bail for a
|
||||
/// press of its spell (`0x6e4d43`), and that press's refusal finds
|
||||
/// nothing in flight (`0x6e2201`): `SPELLCAST_FAILED`, and no `CMSG_CANCEL_CAST`.
|
||||
#[test]
|
||||
fn a_refusal_of_a_cast_outside_the_slot_sends_no_cancel() {
|
||||
|
||||
@@ -7,26 +7,12 @@ use std::time::{Duration, Instant};
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::SpellTargeting;
|
||||
use crate::creature_anim::{CastEvent, CastEventKind, PlaySeq};
|
||||
use crate::net::{ClientCommand, GuidIndex, NetCommands, SelfGuid};
|
||||
use crate::ui_action::Spells;
|
||||
use crate::ui_cast::CastReports;
|
||||
use benilla_protocol::messages::ITEM_FLAG_PLAYERCAST;
|
||||
use benilla_ui::script::CastView;
|
||||
|
||||
/// The in-flight window from send until `SMSG_SPELL_START` names the cast time; the server
|
||||
/// answers every `CMSG_CAST_SPELL`, so a packet always clears it first.
|
||||
const SEND_PROVISIONAL: Duration = Duration::from_secs(5);
|
||||
|
||||
/// The same for an item use, kept short: vmangos refuses some `CMSG_USE_ITEM`s with only
|
||||
/// `SMSG_INVENTORY_CHANGE_FAILURE` and no cast result (`HandleUseItemOpcode`), so this deadline
|
||||
/// is what reopens casting.
|
||||
const ITEM_SEND_PROVISIONAL: Duration = Duration::from_millis(1_500);
|
||||
|
||||
/// Pushback slack added to the server's cast time at `SMSG_SPELL_START`, so a cast the server
|
||||
/// delays (`SMSG_SPELL_DELAYED`) still guards past its stretched end.
|
||||
const CAST_SLACK: Duration = Duration::from_secs(2);
|
||||
|
||||
/// Our outstanding cast: the reference's in-flight slot `0xceca88` for everything that is sent.
|
||||
///
|
||||
/// The attempt pushes the cast at `0x6e5026` (`SetInFlightSpell 0x6e4ad0`) whenever the caster's
|
||||
@@ -40,9 +26,10 @@ const CAST_SLACK: Duration = Duration::from_secs(2);
|
||||
/// [`inflight`] joins the three into the reference's one slot.
|
||||
///
|
||||
/// Cleared by the spell's `SMSG_CAST_RESULT`, success or failure (`0x6e7408` → `0x6e741a`), keyed
|
||||
/// on the spell id, or by [`local_self_cancel`]. `deadline` covers a lost result, which the
|
||||
/// reference has no answer for: [`reap_lapsed_cast`] pops a cast past it as its result would,
|
||||
/// once a frame, so every reader in between sees the slot the same.
|
||||
/// on the spell id, by a cancel (`CancelCast 0x6e4940`: [`local_self_cancel`], Esc, an inventory
|
||||
/// refusal naming its item), or by the world entry's reset. Nothing times it out: `0xceca88` is
|
||||
/// written by the push `0x6e4af8`, the pop `0x6e4b3d` and the world-entry zero `0x6e72e7` alone,
|
||||
/// so a cast whose answer never comes holds the slot until a cancel.
|
||||
///
|
||||
/// It also carries the pending record's caster word (`0xceac48 + 0x08`, `0xceac50`), the one gate
|
||||
/// on the cancel's events: see [`Self::fill_record`] and [`Self::take_caster_event`]; and its
|
||||
@@ -56,7 +43,6 @@ pub(crate) struct PendingCast {
|
||||
|
||||
struct PendingCastState {
|
||||
spell_id: u32,
|
||||
deadline: Instant,
|
||||
/// The guid of the item the cast came from (`0xcecab0`), `None` for a spell's own cast.
|
||||
item: Option<u64>,
|
||||
}
|
||||
@@ -74,47 +60,23 @@ impl PendingCast {
|
||||
self.slot.as_ref().map(|p| p.spell_id)
|
||||
}
|
||||
|
||||
/// The outstanding cast, when its deadline has passed at `now`.
|
||||
pub(crate) fn lapsed(&self, now: Instant) -> Option<u32> {
|
||||
self.slot
|
||||
.as_ref()
|
||||
.filter(|p| now >= p.deadline)
|
||||
.map(|p| p.spell_id)
|
||||
}
|
||||
|
||||
/// `SetInFlightSpell(spell, item)` as the attempt calls it (`0x6e5026`). `item_flags` is the
|
||||
/// used item's template flags, `None` for a cast with no item: an item whose flags lack
|
||||
/// [`ITEM_FLAG_PLAYERCAST`] never enters the slot (a potion, food, a healthstone), so it
|
||||
/// blocks nothing. `item` is the item object's guid, which the slot keeps beside the spell
|
||||
/// (`0x6e4b00`). An item's deadline is short: vmangos refuses some `CMSG_USE_ITEM`s with
|
||||
/// only `SMSG_INVENTORY_CHANGE_FAILURE` and no cast result (`HandleUseItemOpcode`), and this
|
||||
/// deadline is what reopens casting.
|
||||
pub(crate) fn push_cast(
|
||||
&mut self,
|
||||
spell_id: u32,
|
||||
item_flags: Option<u32>,
|
||||
item: Option<u64>,
|
||||
now: Instant,
|
||||
) {
|
||||
/// (`0x6e4b00`).
|
||||
pub(crate) fn push_cast(&mut self, spell_id: u32, item_flags: Option<u32>, item: Option<u64>) {
|
||||
if item_flags.is_some_and(|flags| flags & ITEM_FLAG_PLAYERCAST == 0) {
|
||||
return;
|
||||
}
|
||||
let window = if item_flags.is_some() {
|
||||
ITEM_SEND_PROVISIONAL
|
||||
} else {
|
||||
SEND_PROVISIONAL
|
||||
};
|
||||
self.slot = Some(PendingCastState {
|
||||
spell_id,
|
||||
item,
|
||||
deadline: now + window,
|
||||
});
|
||||
self.slot = Some(PendingCastState { spell_id, item });
|
||||
}
|
||||
|
||||
/// [`Self::push_cast`] with no item object.
|
||||
/// [`Self::push_cast`] with no item object. `_sent` is the press time its callers stamp,
|
||||
/// which the slot does not keep.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn push(&mut self, spell_id: u32, item_flags: Option<u32>, now: Instant) {
|
||||
self.push_cast(spell_id, item_flags, None, now);
|
||||
pub(crate) fn push(&mut self, spell_id: u32, item_flags: Option<u32>, _sent: Instant) {
|
||||
self.push_cast(spell_id, item_flags, None);
|
||||
}
|
||||
|
||||
/// The guid of the item the outstanding cast came from.
|
||||
@@ -122,21 +84,6 @@ impl PendingCast {
|
||||
self.slot.as_ref().and_then(|p| p.item)
|
||||
}
|
||||
|
||||
/// Tighten the deadline to the server's real cast time once `SMSG_SPELL_START` names it.
|
||||
pub(crate) fn refine(&mut self, cast_time_ms: u32, now: Instant) {
|
||||
if let Some(p) = &mut self.slot {
|
||||
p.deadline = now + Duration::from_millis(u64::from(cast_time_ms)) + CAST_SLACK;
|
||||
}
|
||||
}
|
||||
|
||||
/// `SMSG_SPELL_DELAYED`: extend from the later of the deadline and now, so a lapsed deadline
|
||||
/// re-arms.
|
||||
pub(crate) fn delay(&mut self, delay_ms: u32, now: Instant) {
|
||||
if let Some(p) = &mut self.slot {
|
||||
p.deadline = p.deadline.max(now) + Duration::from_millis(u64::from(delay_ms));
|
||||
}
|
||||
}
|
||||
|
||||
/// Clear on a resolution for our spell only: a proc's `SMSG_SPELL_GO` mid-cast must not.
|
||||
pub(crate) fn clear_if(&mut self, spell_id: u32) {
|
||||
if self.slot.as_ref().is_some_and(|p| p.spell_id == spell_id) {
|
||||
@@ -144,6 +91,12 @@ impl PendingCast {
|
||||
}
|
||||
}
|
||||
|
||||
/// The world entry's zero of the slot and its item guid (`0x6e72e7`, `0x6e72ed`). The pending
|
||||
/// record is not `0x6e7150`'s to zero, so its caster word and spell stay.
|
||||
pub(crate) fn clear_slot(&mut self) {
|
||||
self.slot = None;
|
||||
}
|
||||
|
||||
/// The attempt's record fill (`0x6e4fb1`, once every rung has passed and before the arm, so a
|
||||
/// cursor spell and an arm refusal have it too), and the re-arm's (`0x6e748f`): the caster
|
||||
/// word names the active player. Every player commit fills it, an item use without
|
||||
@@ -185,7 +138,7 @@ impl PendingCast {
|
||||
/// strike a cast popped back over is in both. Only a strike's save matters: the attempt refuses or
|
||||
/// cancels anything else in flight before it pushes (`0x6e4d62`, `0x6e4d97`).
|
||||
///
|
||||
/// No deadline. The handler clears the save for its spell (`0x6e73ee`) and pops the slot for it
|
||||
/// The handler clears the save for its spell (`0x6e73ee`) and pops the slot for it
|
||||
/// (`0x6e7408`); vmangos answers a dead melee slot with `SMSG_SPELL_FAILED_OTHER`, which touches
|
||||
/// neither (`0x6e8e40`), then a failing `SMSG_CAST_RESULT` 0x23 (`Spell::cancel`). A re-arm
|
||||
/// replaces it (the server's one `CURRENT_MELEE_SPELL`). Re-pressing the queued spell bails with
|
||||
@@ -293,7 +246,7 @@ pub(crate) fn inflight(
|
||||
/// with the slot's own precedence: the cursor's commit, else the outstanding cast's. A strike has
|
||||
/// none, and a cast pushed over one keeps its own, the strike's coming back with the pop
|
||||
/// (`0x6e4ad0`, the save at `0xcecb20`).
|
||||
fn inflight_item(
|
||||
pub(super) fn inflight_item(
|
||||
pending: &PendingCast,
|
||||
queued_melee: &QueuedMeleeSpell,
|
||||
targeting: &SpellTargeting,
|
||||
@@ -418,9 +371,10 @@ pub(crate) struct LocalMoveStart {
|
||||
///
|
||||
/// - Esc first stops a running auto-repeat (`SpellStopCasting 0x6e6e80`, then `0x6ea080`),
|
||||
/// and that spends the press; the cast survives to the next one.
|
||||
/// - The cast: `CMSG_CANCEL_CAST`, the self `Casting` reaped with a `Fail` cast event, and the
|
||||
/// `Stop` bar edge the cancel's own event fires ([`super::CastCore::cancel`]). Movement tests
|
||||
/// the spell's `InterruptFlags`; Esc does not.
|
||||
/// - The cast: `CMSG_CANCEL_CAST`, the `Stop` bar edge the cancel's own event fires, and the
|
||||
/// record's cast reaped with a `Fail` cast event as the cancel's tail gates it
|
||||
/// ([`super::CastCore::cancel_reaping`]). Movement tests the spell's `InterruptFlags`; Esc does
|
||||
/// not.
|
||||
/// - The channel, on movement only and only while the player is the mover (`0x515180`):
|
||||
/// `CMSG_CANCEL_CHANNELLING` (`0x6e9b70`) and nothing local; the bar and [`ActiveChannel`] close
|
||||
/// on `MSG_CHANNEL_UPDATE(0)` (`0x6e75f0`). Esc cannot stop a channel: `0x6e6e80` never calls
|
||||
@@ -438,12 +392,6 @@ pub(super) fn local_self_cancel(mut moved: ResMut<LocalMoveStart>, mut cancel: S
|
||||
}
|
||||
}
|
||||
|
||||
/// The guard's deadline, once a frame ahead of the local cancel, so a move that frame reads the
|
||||
/// slot the lapse left: a cast past it pops ([`super::CastCore::reap_lapsed`]).
|
||||
pub(super) fn reap_lapsed_cast(mut slots: super::CastSlots, net: Res<NetCommands>) {
|
||||
slots.core(&net).reap_lapsed(Instant::now());
|
||||
}
|
||||
|
||||
/// What [`local_self_cancel`] reads and writes, shared with the Esc cancel, which is a script call
|
||||
/// (`SpellStopCasting`) and lands in call order ([`crate::script_calls`]).
|
||||
#[derive(bevy::ecs::system::SystemParam)]
|
||||
@@ -457,8 +405,6 @@ pub(crate) struct SelfCancel<'w> {
|
||||
net: Res<'w, NetCommands>,
|
||||
self_guid: Res<'w, SelfGuid>,
|
||||
index: Res<'w, GuidIndex>,
|
||||
cast_events: MessageWriter<'w, CastEvent>,
|
||||
play_seq: ResMut<'w, PlaySeq>,
|
||||
/// The reap and the auto-repeat clear, applied after the pass.
|
||||
edits: Res<'w, crate::creature_anim::UnitEdits>,
|
||||
ground: ResMut<'w, super::targeting::SpellTargeting>,
|
||||
@@ -488,11 +434,11 @@ impl SelfCancel<'_> {
|
||||
.copied()
|
||||
}
|
||||
|
||||
/// `CancelCast(failed, 1, 0x1c)` ([`super::CastCore::cancel`]), then a popped cast's local
|
||||
/// teardown: its self `Casting` reaped with a `Fail` cast event, as `spell_failed_other`'s
|
||||
/// echo would, run early so the echo finds it done. A strike a cast popped back over is in the
|
||||
/// slot and the save, so its pop copies it back (`0x6e4b2c`): it stays in flight, and each
|
||||
/// press until the server's echo sends its cancel again (`0x6e6eb4`).
|
||||
/// `CancelCast(failed, 1, 0x1c)` with its tail's reap ([`super::CastCore::cancel_reaping`]):
|
||||
/// the record's cast on the player, as `spell_failed_other`'s echo would end it, run early so
|
||||
/// the echo finds it done. A strike a cast popped back over is in the slot and the save, so its
|
||||
/// pop copies it back (`0x6e4b2c`): it stays in flight, and each press until the server's echo
|
||||
/// sends its cancel again (`0x6e6eb4`).
|
||||
fn cancel_inflight(&mut self, failed: bool, why: &str) {
|
||||
let self_e = self.self_entity();
|
||||
let Self {
|
||||
@@ -500,8 +446,7 @@ impl SelfCancel<'_> {
|
||||
queued_melee,
|
||||
reports,
|
||||
net,
|
||||
cast_events,
|
||||
play_seq,
|
||||
spells,
|
||||
edits,
|
||||
ground,
|
||||
..
|
||||
@@ -513,24 +458,17 @@ impl SelfCancel<'_> {
|
||||
reports,
|
||||
net,
|
||||
}
|
||||
.cancel(failed, true, super::REASON_ERROR);
|
||||
.cancel_reaping(
|
||||
failed,
|
||||
true,
|
||||
super::REASON_ERROR,
|
||||
spells.as_deref(),
|
||||
self_e,
|
||||
edits,
|
||||
);
|
||||
if *crate::net::CAST_TRACE {
|
||||
info!("cast-trace: LOCAL self-cancel — {popped:?} ({why})");
|
||||
}
|
||||
if let (Some(Inflight::Cast(spell_id)), Some(e)) = (popped, self_e) {
|
||||
edits.push(crate::creature_anim::UnitEdit::ReapCasting {
|
||||
entity: e,
|
||||
spell_id,
|
||||
});
|
||||
cast_events.write(CastEvent {
|
||||
entity: e,
|
||||
spell_id,
|
||||
kind: CastEventKind::Fail,
|
||||
cast_flags: 0,
|
||||
item_cast: false,
|
||||
seq: play_seq.next(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn cancel(&mut self, esc: bool, moved: bool, mover_is_player: bool) {
|
||||
@@ -607,7 +545,7 @@ impl SelfCancel<'_> {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::creature_anim::Casting;
|
||||
use crate::creature_anim::{CastEvent, Casting};
|
||||
|
||||
const FIREBALL: u32 = 133;
|
||||
|
||||
@@ -680,7 +618,6 @@ mod tests {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
Instant::now(),
|
||||
);
|
||||
},
|
||||
)
|
||||
@@ -748,7 +685,6 @@ mod tests {
|
||||
HEARTH,
|
||||
Some(ITEM_FLAG_PLAYERCAST),
|
||||
Some(ITEM),
|
||||
Instant::now(),
|
||||
);
|
||||
assert_eq!(item_of(&mut app), Some(HEARTHSTONE));
|
||||
app.world_mut().entity_mut(item).despawn();
|
||||
@@ -779,8 +715,7 @@ mod tests {
|
||||
}
|
||||
|
||||
/// `0x6e500b`–`0x6e501f`: an item use is pushed only when its template flags carry
|
||||
/// `ITEM_FLAG_PLAYERCAST` (`0x40`); a spell has no item and is always pushed. The item's
|
||||
/// window is the short one.
|
||||
/// `ITEM_FLAG_PLAYERCAST` (`0x40`); a spell has no item and is always pushed.
|
||||
#[test]
|
||||
fn an_item_use_enters_the_slot_only_with_the_playercast_flag() {
|
||||
let t0 = Instant::now();
|
||||
@@ -791,14 +726,9 @@ mod tests {
|
||||
assert!(!g.in_flight(), "other bits do not count");
|
||||
g.push(FIREBALL, Some(0x40), t0);
|
||||
assert!(g.in_flight(), "the flag pushes");
|
||||
let past_item = t0 + ITEM_SEND_PROVISIONAL + Duration::from_millis(1);
|
||||
assert_eq!(
|
||||
g.lapsed(past_item),
|
||||
Some(FIREBALL),
|
||||
"on the item's own deadline"
|
||||
);
|
||||
g.clear_if(FIREBALL);
|
||||
g.push(FIREBALL, None, t0);
|
||||
assert_eq!(g.lapsed(past_item), None);
|
||||
assert!(g.in_flight(), "a spell's own cast");
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -813,108 +743,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_guard_lapses_at_its_safety_deadline() {
|
||||
let t0 = Instant::now();
|
||||
let mut g = PendingCast::default();
|
||||
g.push(FIREBALL, None, t0);
|
||||
assert_eq!(
|
||||
g.lapsed(t0 + SEND_PROVISIONAL - Duration::from_secs(1)),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
g.lapsed(t0 + SEND_PROVISIONAL + Duration::from_secs(1)),
|
||||
Some(FIREBALL)
|
||||
);
|
||||
assert!(g.in_flight(), "until the reaper pops it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_pushback_extends_the_guard_so_it_holds_past_the_stretched_cast() {
|
||||
let t0 = Instant::now();
|
||||
let mut g = PendingCast::default();
|
||||
g.push(FIREBALL, None, t0);
|
||||
g.refine(1_000, t0); // deadline t0 + 1 s + 2 s slack
|
||||
g.delay(500, t0); // pushed to t0 + 3.5 s
|
||||
assert_eq!(
|
||||
g.lapsed(t0 + Duration::from_millis(3_200)),
|
||||
None,
|
||||
"the pushback kept the guard shut past the original refined deadline"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn spell_start_tightens_the_deadline_to_the_real_cast_time() {
|
||||
let t0 = Instant::now();
|
||||
let mut g = PendingCast::default();
|
||||
g.push(FIREBALL, None, t0);
|
||||
g.refine(1_500, t0); // SMSG_SPELL_START: 1.5 s + 2 s slack
|
||||
let at_four = t0 + Duration::from_secs(4);
|
||||
assert_eq!(
|
||||
g.lapsed(at_four),
|
||||
Some(FIREBALL),
|
||||
"refined to 1.5s + slack, the guard has lapsed by t+4s (it would still hold at the \
|
||||
5s provisional)"
|
||||
);
|
||||
}
|
||||
|
||||
/// A lapsed cast leaves the slot as its result's pop would (`0x6e4b2c`): a strike the push
|
||||
/// saved under it comes back to the slot, signalled, so the late result finds it queued and
|
||||
/// the strike survives. Inside its deadline the reaper leaves the cast alone.
|
||||
#[test]
|
||||
fn a_lapsed_cast_pops_back_the_strike_it_was_pushed_over() {
|
||||
use bevy::ecs::system::RunSystemOnce;
|
||||
const HEROIC_STRIKE: u32 = 78;
|
||||
let mut app = App::new();
|
||||
let (tx, _rx) = crossbeam_channel::unbounded();
|
||||
app.init_resource::<PendingCast>()
|
||||
.init_resource::<QueuedMeleeSpell>()
|
||||
.init_resource::<SpellTargeting>()
|
||||
.init_resource::<CastReports>()
|
||||
.insert_resource(NetCommands(tx));
|
||||
let t0 = Instant::now();
|
||||
let reap = |app: &mut App, now: Instant| {
|
||||
app.world_mut()
|
||||
.run_system_once(
|
||||
move |mut slots: super::super::CastSlots, net: Res<NetCommands>| {
|
||||
slots.core(&net).reap_lapsed(now);
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
std::mem::take(&mut app.world_mut().resource_mut::<CastReports>().0).len()
|
||||
};
|
||||
app.world_mut()
|
||||
.run_system_once(
|
||||
move |mut slots: super::super::CastSlots, net: Res<NetCommands>| {
|
||||
let mut core = slots.core(&net);
|
||||
core.push(HEROIC_STRIKE, super::super::Held::Strike, t0);
|
||||
core.push(
|
||||
FIREBALL,
|
||||
super::super::Held::Cast {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
t0,
|
||||
);
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
app.world_mut().resource_mut::<CastReports>().0.clear();
|
||||
assert_eq!(reap(&mut app, t0), 0, "inside its deadline");
|
||||
assert!(app.world().resource::<PendingCast>().in_flight());
|
||||
assert_eq!(
|
||||
reap(&mut app, t0 + SEND_PROVISIONAL + Duration::from_millis(1)),
|
||||
1,
|
||||
"one pop, signalled"
|
||||
);
|
||||
assert!(!app.world().resource::<PendingCast>().in_flight());
|
||||
assert_eq!(
|
||||
app.world().resource::<QueuedMeleeSpell>().current(),
|
||||
Some(HEROIC_STRIKE),
|
||||
"the strike is back in the slot"
|
||||
);
|
||||
}
|
||||
|
||||
/// [`local_self_cancel`] in a small App, and the Esc cancel: the Esc tests insert a VM, call
|
||||
/// the real `SpellStopCasting()` and apply what it queued.
|
||||
mod local_cancel {
|
||||
@@ -986,7 +814,7 @@ mod tests {
|
||||
app.world_mut()
|
||||
.run_system_once(
|
||||
move |mut slots: crate::spell::CastSlots, net: Res<NetCommands>| {
|
||||
slots.core(&net).push(spell_id, held, Instant::now());
|
||||
slots.core(&net).push(spell_id, held);
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1036,6 +864,9 @@ mod tests {
|
||||
},
|
||||
)]));
|
||||
fill_record(&mut app);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.fill_record_spell(FIREBALL);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.push(FIREBALL, None, Instant::now());
|
||||
@@ -1567,6 +1398,145 @@ mod tests {
|
||||
"no local bar edge — the bar closes on the wire's SPELLCAST_CHANNEL_STOP"
|
||||
);
|
||||
}
|
||||
|
||||
/// The failed cast events written since the last look, by spell.
|
||||
fn fails(app: &mut App) -> Vec<u32> {
|
||||
app.world_mut()
|
||||
.resource_mut::<Messages<CastEvent>>()
|
||||
.drain()
|
||||
.filter(|e| e.kind == crate::creature_anim::CastEventKind::Fail)
|
||||
.map(|e| e.spell_id)
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The cancel's reap is its tail's (`0x6e4a04`-`0x6e4ab7`): the record's spell
|
||||
/// `[0xceac58]` (`0x6e4a8e`), whatever the slot popped. A cast nested over another
|
||||
/// record's leaves that record's cast reaped and its own running.
|
||||
#[test]
|
||||
fn esc_reaps_the_records_spell_not_the_popped_one() {
|
||||
const FROSTBOLT: u32 = 116;
|
||||
let (mut app, _rx) = harness(HashMap::from([
|
||||
(FIREBALL, SpellDisplay::default()),
|
||||
(FROSTBOLT, SpellDisplay::default()),
|
||||
]));
|
||||
app.insert_non_send_resource(UiScript::new().unwrap());
|
||||
fill_record(&mut app);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.fill_record_spell(FROSTBOLT);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.push(FIREBALL, None, Instant::now());
|
||||
mark_casting(&mut app, FROSTBOLT);
|
||||
|
||||
app.world_mut().run_system_once(feed_cast_reports).unwrap();
|
||||
assert_eq!(stop_casting(&mut app), Some(1));
|
||||
crate::creature_anim::apply_unit_edits(app.world_mut());
|
||||
|
||||
let self_e = app.world().resource::<GuidIndex>().0[&10];
|
||||
assert!(
|
||||
app.world().get::<Casting>(self_e).is_none(),
|
||||
"the record's cast"
|
||||
);
|
||||
assert_eq!(fails(&mut app), vec![FROSTBOLT]);
|
||||
}
|
||||
|
||||
/// The tail spares a record spell with `AttributesEx & 0x4` (`0x6e4aad`): the cancel goes
|
||||
/// out and the cast keeps running locally.
|
||||
#[test]
|
||||
fn a_move_cancel_spares_an_attributes_ex_4_cast() {
|
||||
let (mut app, rx) = harness(HashMap::from([(
|
||||
FIREBALL,
|
||||
SpellDisplay {
|
||||
interrupt_flags: 0xf,
|
||||
attributes_ex: 0x4,
|
||||
..Default::default()
|
||||
},
|
||||
)]));
|
||||
fill_record(&mut app);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.fill_record_spell(FIREBALL);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.push(FIREBALL, None, Instant::now());
|
||||
mark_casting(&mut app, FIREBALL);
|
||||
run(&mut app, true);
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(crate::net::ClientCommand::CancelCast { spell_id: FIREBALL })
|
||||
));
|
||||
let self_e = app.world().resource::<GuidIndex>().0[&10];
|
||||
assert!(
|
||||
app.world().get::<Casting>(self_e).is_some(),
|
||||
"AttributesEx & 0x4"
|
||||
);
|
||||
assert!(fails(&mut app).is_empty());
|
||||
}
|
||||
|
||||
/// The tail reaps nothing unless the record's caster is the active player (`0x6e4a11`).
|
||||
#[test]
|
||||
fn a_move_cancel_reaps_nothing_for_another_casters_record() {
|
||||
let (mut app, rx) = harness(HashMap::from([(
|
||||
FIREBALL,
|
||||
SpellDisplay {
|
||||
interrupt_flags: 0xf,
|
||||
..Default::default()
|
||||
},
|
||||
)]));
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.fill_record_spell(FIREBALL);
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.push(FIREBALL, None, Instant::now());
|
||||
mark_casting(&mut app, FIREBALL);
|
||||
run(&mut app, true);
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(crate::net::ClientCommand::CancelCast { spell_id: FIREBALL })
|
||||
));
|
||||
let self_e = app.world().resource::<GuidIndex>().0[&10];
|
||||
assert!(
|
||||
app.world().get::<Casting>(self_e).is_some(),
|
||||
"no record caster"
|
||||
);
|
||||
assert!(fails(&mut app).is_empty());
|
||||
}
|
||||
|
||||
/// The frame's pass over the slot with no press: the systems the plugin chains in
|
||||
/// [`super::super::LocalCancel`].
|
||||
fn quiet_frame(app: &mut App) {
|
||||
run(app, false);
|
||||
}
|
||||
|
||||
/// Nothing times the slot out (`0xceca88`'s writers are the push `0x6e4af8`, the pop
|
||||
/// `0x6e4b3d` and the world-entry zero `0x6e72e7`): a cast whose answer never comes holds
|
||||
/// it, refusing the next press, until `SpellStopCasting` (`0x6e6e80` → `0x6e4940`) frees it.
|
||||
#[test]
|
||||
fn a_cast_with_no_answer_holds_the_slot_until_esc() {
|
||||
let (mut app, rx) = harness(HashMap::from([(FIREBALL, SpellDisplay::default())]));
|
||||
app.insert_non_send_resource(UiScript::new().unwrap());
|
||||
let sent = Instant::now()
|
||||
.checked_sub(Duration::from_secs(60))
|
||||
.expect("a clock a minute old");
|
||||
app.world_mut()
|
||||
.resource_mut::<PendingCast>()
|
||||
.push(FIREBALL, None, sent);
|
||||
quiet_frame(&mut app);
|
||||
assert_eq!(
|
||||
app.world().resource::<PendingCast>().current(),
|
||||
Some(FIREBALL),
|
||||
"a minute on, still in flight"
|
||||
);
|
||||
app.world_mut().run_system_once(feed_cast_reports).unwrap();
|
||||
assert_eq!(stop_casting(&mut app), Some(1));
|
||||
assert!(matches!(
|
||||
rx.try_recv(),
|
||||
Ok(crate::net::ClientCommand::CancelCast { spell_id: FIREBALL })
|
||||
));
|
||||
assert_eq!(app.world().resource::<PendingCast>().current(), None);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -7,7 +7,6 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::client_state::ClientState;
|
||||
use crate::ui_script::UiFeed;
|
||||
use crate::ui_unit::UnitFeed;
|
||||
|
||||
@@ -93,8 +92,7 @@ impl Plugin for SpellPlugin {
|
||||
.add_systems(
|
||||
Update,
|
||||
(
|
||||
(inflight::reap_lapsed_cast, inflight::local_self_cancel)
|
||||
.chain()
|
||||
inflight::local_self_cancel
|
||||
.in_set(UnitFeed)
|
||||
.in_set(LocalCancel),
|
||||
mods::track_class_family
|
||||
@@ -124,8 +122,7 @@ impl Plugin for SpellPlugin {
|
||||
.in_set(UiFeed)
|
||||
.before(UnitFeed),
|
||||
),
|
||||
)
|
||||
.add_systems(OnEnter(ClientState::InWorld), mods::clear_on_world_enter);
|
||||
);
|
||||
net::register(app);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -313,13 +313,6 @@ impl benilla_formats::SpellMods for SpellModifiers {
|
||||
}
|
||||
}
|
||||
|
||||
/// Entering the world clears the tables and class family: `Spell_C::SystemInitialize 0x6e7150`,
|
||||
/// run once per world entry from `CGlueMgr::Update 0x46b930`. The teardown `0x6e99e0` leaves
|
||||
/// them, and there is no talent-change clear.
|
||||
pub(super) fn clear_on_world_enter(mut mods: ResMut<SpellModifiers>) {
|
||||
mods.clear();
|
||||
}
|
||||
|
||||
/// Keep the class family in step with the avatar (`0x6e6ca0`, called from `0x5debcc`: byte 1, the
|
||||
/// class, of `UNIT_FIELD_BYTES_0` into `ChrClasses` field 15). An absent avatar keeps the last
|
||||
/// value, as a cross-map worldport drops the entity mid-session; only world-enter zeroes it.
|
||||
@@ -342,7 +335,6 @@ pub(super) fn track_class_family(
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::client_state::ClientState;
|
||||
|
||||
/// A mage spell (family 3) with the given bits set, against a mage player.
|
||||
fn mage(bits: &[u8]) -> SpellDisplay {
|
||||
@@ -471,32 +463,6 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn world_enter_clears_both_tables_and_the_family() {
|
||||
let mut app = App::new();
|
||||
app.add_plugins((MinimalPlugins, bevy::state::app::StatesPlugin))
|
||||
.insert_state(ClientState::Login)
|
||||
.init_resource::<SpellModifiers>()
|
||||
.add_systems(OnEnter(ClientState::InWorld), clear_on_world_enter);
|
||||
|
||||
{
|
||||
let mut mods = app.world_mut().resource_mut::<SpellModifiers>();
|
||||
mods.set_class_family(3);
|
||||
mods.set(true, 5, OP_COST, -30);
|
||||
mods.set(false, 35, OP_COST, -50);
|
||||
assert_eq!(mods.apply(&mage(&[5]), OP_COST, 100), 70);
|
||||
}
|
||||
|
||||
app.world_mut()
|
||||
.resource_mut::<NextState<ClientState>>()
|
||||
.set(ClientState::InWorld);
|
||||
app.update();
|
||||
|
||||
let mods = app.world().resource::<SpellModifiers>();
|
||||
assert_eq!(mods.class_family, 0);
|
||||
assert!(mods.flat.iter().chain(mods.pct.iter()).all(|&v| v == 0));
|
||||
}
|
||||
|
||||
/// Real `Spell.dbc` family masks; Cleanse 4987 sets bits 12 and 33, across both dwords.
|
||||
#[test]
|
||||
fn real_spells_sum_their_own_family_bits() {
|
||||
|
||||
+397
-140
@@ -26,10 +26,21 @@ use bevy::ecs::system::SystemParam;
|
||||
use crate::net::{GuidIndex, NetCommands, NetHandlerApp, ObjectStore, SelfGuid, SelfPlayer};
|
||||
use crate::query_cache::Ask;
|
||||
|
||||
/// Another unit's `SMSG_SPELL_START` aimed at the player (`0x6e790d`-`0x6e7947`), for the target
|
||||
/// chain's select of its caster (`0x6e799c`), which holds the selection
|
||||
/// ([`crate::target`]). `seq` is the packet's [`crate::creature_anim::PlaySeq`] stamp.
|
||||
#[derive(Message, Clone, Copy, Debug)]
|
||||
pub(crate) struct CastAtPlayer {
|
||||
pub(crate) caster: Entity,
|
||||
pub(crate) seq: u64,
|
||||
}
|
||||
|
||||
/// Register the spell's handlers; called from [`super::SpellPlugin`].
|
||||
pub(super) fn register(app: &mut App) {
|
||||
use SessionEventKind as K;
|
||||
app.net_handler(K::SpellBook, on_spell_book)
|
||||
app.add_message::<CastAtPlayer>();
|
||||
app.net_handler(K::Connected, on_world_enter)
|
||||
.net_handler(K::SpellBook, on_spell_book)
|
||||
.net_handler(K::ActionButtons, on_action_buttons)
|
||||
.net_handler(K::SpellLearned, on_spell_learned)
|
||||
.net_handler(K::SpellRemoved, on_spell_removed)
|
||||
@@ -46,6 +57,7 @@ pub(super) fn register(app: &mut App) {
|
||||
.net_handler(K::ClearCooldown, on_cooldown_packet)
|
||||
.net_handler(K::CooldownCheat, on_cooldown_packet)
|
||||
.net_handler(K::ItemCooldown, on_item_cooldown)
|
||||
.net_handler(K::InventoryFailure, on_inventory_refusal)
|
||||
.net_handler(K::ItemTemplate, on_item_record)
|
||||
.net_handler(K::ChannelStart, on_channel)
|
||||
.net_handler(K::ChannelUpdate, on_channel)
|
||||
@@ -244,6 +256,7 @@ fn on_spell_start(
|
||||
mut l: Lifecycle,
|
||||
mut sc: Scene,
|
||||
precast: crate::creature_anim::PrecastTables,
|
||||
mut cast_at_player: MessageWriter<CastAtPlayer>,
|
||||
) {
|
||||
if let SessionEvent::SpellStart {
|
||||
caster,
|
||||
@@ -264,6 +277,7 @@ fn on_spell_start(
|
||||
&mut sc.commands,
|
||||
&l.index,
|
||||
&mut sc.cast_events,
|
||||
&mut cast_at_player,
|
||||
&l.self_guid,
|
||||
&mut l.reports,
|
||||
&mut l.pending,
|
||||
@@ -278,6 +292,7 @@ fn on_spell_start(
|
||||
spell_id,
|
||||
)
|
||||
},
|
||||
&|e| sc.stores.get(e).is_ok_and(|s| s.is_unit()),
|
||||
l.play_seq.next(),
|
||||
);
|
||||
}
|
||||
@@ -384,13 +399,7 @@ fn on_spell_failed_other(In(ev): In<SessionEvent>, mut l: Lifecycle, mut sc: Sce
|
||||
|
||||
fn on_spell_delayed(In(ev): In<SessionEvent>, mut l: Lifecycle) {
|
||||
if let SessionEvent::SpellDelayed { caster, delay_ms } = ev {
|
||||
spell_delayed(
|
||||
caster,
|
||||
delay_ms,
|
||||
&l.self_guid,
|
||||
&mut l.reports,
|
||||
&mut l.pending,
|
||||
);
|
||||
spell_delayed(caster, delay_ms, &l.self_guid, &mut l.reports);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -406,7 +415,8 @@ fn on_cancel_auto_repeat(In(ev): In<SessionEvent>, mut l: Lifecycle, sc: Scene)
|
||||
}
|
||||
}
|
||||
|
||||
/// The four cooldown packets, each routed through [`addressed_store`] by the caster guid.
|
||||
/// The four cooldown packets, each routed to a list by the caster guid: [`addressed_store`] for
|
||||
/// `SMSG_SPELL_COOLDOWN` and the cheat, [`event_store`] for the event and the clear.
|
||||
fn on_cooldown_packet(In(ev): In<SessionEvent>, mut l: Lifecycle, sc: Scene) {
|
||||
let player = active_player(&l.self_guid, &l.index, &sc.stores);
|
||||
let Lifecycle {
|
||||
@@ -429,14 +439,10 @@ fn on_cooldown_packet(In(ev): In<SessionEvent>, mut l: Lifecycle, sc: Scene) {
|
||||
}
|
||||
}
|
||||
SessionEvent::CooldownEvent { spell_id, caster } => {
|
||||
if let Some(store) = addressed_store(caster, self_guid, cooldowns, pet_bar) {
|
||||
cooldown_event(spell_id, caster, store);
|
||||
}
|
||||
cooldown_event(spell_id, caster, event_store(caster, cooldowns, pet_bar));
|
||||
}
|
||||
SessionEvent::ClearCooldown { spell_id, caster } => {
|
||||
if let Some(store) = addressed_store(caster, self_guid, cooldowns, pet_bar) {
|
||||
clear_cooldown(spell_id, caster, store);
|
||||
}
|
||||
clear_cooldown(spell_id, caster, event_store(caster, cooldowns, pet_bar));
|
||||
}
|
||||
SessionEvent::CooldownCheat { caster } => {
|
||||
if let Some(store) = addressed_store(caster, self_guid, cooldowns, pet_bar) {
|
||||
@@ -457,6 +463,67 @@ fn on_item_record(In(ev): In<SessionEvent>, mut l: Lifecycle) {
|
||||
}
|
||||
}
|
||||
|
||||
/// `SMSG_INVENTORY_CHANGE_FAILURE`'s cast leg (`0x5e3a45`-`0x5e3ab3`): a refusal whose first item
|
||||
/// is the in-flight cast's (`0x6e3d20` → `[0xcecab0]`, compared at `0x5e3aa1`) cancels it as
|
||||
/// `CancelCast(1, 0, 0x17)` with the tail's reap, while the active player's object is held
|
||||
/// (`0x5e3a63`). The line, the loot and the unlocks are the item handler's
|
||||
/// ([`crate::ui_items`]).
|
||||
fn on_inventory_refusal(
|
||||
In(ev): In<SessionEvent>,
|
||||
mut slots: super::CastSlots,
|
||||
net: Res<NetCommands>,
|
||||
spells: Option<Res<Spells>>,
|
||||
edits: Res<crate::creature_anim::UnitEdits>,
|
||||
self_guid: Res<SelfGuid>,
|
||||
index: Res<GuidIndex>,
|
||||
) {
|
||||
let SessionEvent::InventoryFailure { item_guid, .. } = ev else {
|
||||
return;
|
||||
};
|
||||
let Some(&me) = self_guid.0.and_then(|g| index.0.get(&g)) else {
|
||||
return;
|
||||
};
|
||||
let mut core = slots.core(&net);
|
||||
if item_guid == 0 || core.slot_item() != Some(item_guid) {
|
||||
return;
|
||||
}
|
||||
debug!("net: inventory refusal names the in-flight cast's item {item_guid:#x} — cancel");
|
||||
core.cancel_reaping(
|
||||
true,
|
||||
false,
|
||||
super::report::REASON_DONT_REPORT,
|
||||
spells.as_deref(),
|
||||
Some(me),
|
||||
&edits,
|
||||
);
|
||||
}
|
||||
|
||||
/// `Spell_C::SystemInitialize 0x6e7150`, which every world entry runs, a reconnect's too
|
||||
/// (`ClientInitializeGame 0x401570` → `0x6033c0` at `0x401639` → `0x6038da`), in packet order: it
|
||||
/// zeroes both modifier tables (`0x6e72c4`, `0x6e72d6`), the targeting word (`0x6e72e0`), the
|
||||
/// in-flight slot and its item (`0x6e72e7`, `0x6e72ed`), the queued strike's save (`0x6e72f9`),
|
||||
/// the auto-repeat spell (`0x6e730b`), the Feed Pet spell (`0x6e7311`) and the class family
|
||||
/// (`0x6e7317`). The pending record `0xceac48` is not its to zero. It fires no event; the teardown
|
||||
/// `0x6e99e0` zeroes none of these, and there is no talent-change clear.
|
||||
fn on_world_enter(
|
||||
In(ev): In<SessionEvent>,
|
||||
mut pending: ResMut<PendingCast>,
|
||||
mut queued: ResMut<QueuedMeleeSpell>,
|
||||
mut targeting: ResMut<super::SpellTargeting>,
|
||||
mut auto_repeat: ResMut<AutoRepeatActive>,
|
||||
mut spell_mods: ResMut<crate::spell::SpellModifiers>,
|
||||
mut learned: ResMut<crate::ui_action::LearnedAbilities>,
|
||||
) {
|
||||
if let SessionEvent::Connected { .. } = ev {
|
||||
spell_mods.clear();
|
||||
targeting.clear();
|
||||
pending.clear_slot();
|
||||
*queued = QueuedMeleeSpell::default();
|
||||
auto_repeat.0 = None;
|
||||
learned.feed_pet = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn on_item_cooldown(In(ev): In<SessionEvent>, mut l: Lifecycle, sc: Scene) {
|
||||
if let SessionEvent::ItemCooldown {
|
||||
item_guid,
|
||||
@@ -503,9 +570,9 @@ fn on_spell_modifier(In(ev): In<SessionEvent>, mut l: Lifecycle) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Which cooldown store a cooldown packet's caster guid addresses: ours or our pet's (the server
|
||||
/// sends a pet's cooldowns on the pet's guid). Any other guid is dropped, as the reference drops
|
||||
/// it; its `SMSG_COOLDOWN_CHEAT` handler wipes the self or pet list on this same test.
|
||||
/// Which cooldown store `SMSG_SPELL_COOLDOWN` (`0x6e947e`, `0x6e948d`) and `SMSG_COOLDOWN_CHEAT`
|
||||
/// (`0x6e974a`, `0x6e9767`) address by the caster guid: ours or our pet's (the server sends a pet's
|
||||
/// cooldowns on the pet's guid). Any other guid ends the handler.
|
||||
fn addressed_store<'a>(
|
||||
caster: u64,
|
||||
self_guid: &SelfGuid,
|
||||
@@ -521,6 +588,20 @@ fn addressed_store<'a>(
|
||||
}
|
||||
}
|
||||
|
||||
/// The store `SMSG_COOLDOWN_EVENT` and `SMSG_CLEAR_COOLDOWN` (`0x6e9670`) address: the pet's for
|
||||
/// the pet bar's guid `[0xb714a0]`, the player's for any other (`0x6e9696`, the one compare).
|
||||
fn event_store<'a>(
|
||||
caster: u64,
|
||||
player: &'a mut crate::spell::Cooldowns,
|
||||
pet: &'a mut crate::ui_pet::PetBar,
|
||||
) -> &'a mut crate::spell::Cooldowns {
|
||||
if pet.spells.pet_guid == caster {
|
||||
&mut pet.cooldowns
|
||||
} else {
|
||||
player
|
||||
}
|
||||
}
|
||||
|
||||
/// `SMSG_INITIAL_SPELLS`: the book into the action store, and the active cooldowns, whose wire
|
||||
/// value is remaining ms, into the cooldown store ([`Cooldowns::seed_initial`]). `seed` is what
|
||||
/// the seed reads: the catalog, the item cache, the modifiers and the category pad.
|
||||
@@ -541,9 +622,15 @@ fn spell_book(
|
||||
spell_ids.len(),
|
||||
initial_cooldowns.len()
|
||||
);
|
||||
let (spells, items, mods, pad) = seed;
|
||||
// `ResetSpellBook 0x4b23a0` empties the opener list (`0x4b2464`-`0x4b2470`) before the
|
||||
// arrival's replay learns the list in wire order (`0x5dea8b`-`0x5deab9`).
|
||||
actions.openers.clear();
|
||||
for &spell_id in &spell_ids {
|
||||
list_opener(spell_id, spells, actions);
|
||||
}
|
||||
actions.spells = spell_ids.into_iter().collect();
|
||||
actions.dirty = true;
|
||||
let (spells, items, mods, pad) = seed;
|
||||
let now = Instant::now();
|
||||
for cd in &initial_cooldowns {
|
||||
let spell_id = u32::from(cd.spell_id);
|
||||
@@ -578,10 +665,34 @@ fn learned_spell(
|
||||
if actions.spells.insert(spell_id) {
|
||||
actions.dirty = true;
|
||||
}
|
||||
list_opener(spell_id, spells, actions);
|
||||
announce_learn(spell_id, spells, errors);
|
||||
tab_flash.0.push(spell_id);
|
||||
}
|
||||
|
||||
/// `SPELL_EFFECT_OPEN_LOCK` in `Effect[0]`, the registrar's test for the opener list (`0x4b265e`).
|
||||
const SPELL_EFFECT_OPEN_LOCK: u32 = 0x21;
|
||||
|
||||
/// The registrar's opener leg (`0x4b265e`-`0x4b2689`): a spell whose `Effect[0]` is
|
||||
/// `SPELL_EFFECT_OPEN_LOCK` goes to the tail of [`PlayerActions::openers`], already listed or not.
|
||||
/// An id with no record is not registered (`0x4b25c6`-`0x4b25e5`).
|
||||
fn list_opener(spell_id: u32, spells: Option<&Spells>, actions: &mut PlayerActions) {
|
||||
if spells
|
||||
.and_then(|s| s.catalog.get(spell_id))
|
||||
.is_some_and(|d| d.effects[0] == SPELL_EFFECT_OPEN_LOCK)
|
||||
{
|
||||
actions.openers.push(spell_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// The unlearn's opener leg (`0x4b2d4a`-`0x4b2dae`): the last copy of `spell_id` leaves
|
||||
/// [`PlayerActions::openers`], and the ones after it move up a place.
|
||||
fn unlist_opener(spell_id: u32, actions: &mut PlayerActions) {
|
||||
if let Some(at) = actions.openers.iter().rposition(|&id| id == spell_id) {
|
||||
actions.openers.remove(at);
|
||||
}
|
||||
}
|
||||
|
||||
/// The `ERR_LEARN_*` chat line the registrar `0x4b25b0` prints at `0x4b2909` for a spell learned
|
||||
/// mid-session; which line, and whether it carries the rank, is
|
||||
/// [`benilla_formats::SpellDisplay::learn_announcement`]'s. Ids `0x37`/`0x38`/`0x39` are chat
|
||||
@@ -623,6 +734,8 @@ fn removed_spell(
|
||||
if actions.spells.remove(&spell_id) {
|
||||
actions.dirty = true;
|
||||
}
|
||||
// `0x5ea24c`: every unlearn runs `0x4b2c50`.
|
||||
unlist_opener(spell_id, actions);
|
||||
announce_unlearn(spell_id, spells, errors);
|
||||
}
|
||||
|
||||
@@ -654,6 +767,12 @@ fn superceded_spell(
|
||||
actions.spells.remove(&old_spell_id);
|
||||
actions.spells.insert(new_spell_id);
|
||||
actions.dirty = true;
|
||||
// `0x4b2f50` unlists the old rank and registers the new one at the tail; the player's own
|
||||
// unlearn of the old rank (`0x5e6392` → `0x5ea24c`) then runs the removal once more, and its
|
||||
// learn of the new one (`0x5e63a4`) skips the registrar (`0x5e9c5a`).
|
||||
unlist_opener(old_spell_id, actions);
|
||||
list_opener(new_spell_id, spells, actions);
|
||||
unlist_opener(old_spell_id, actions);
|
||||
// A rank-up announces once, like a first learn: the supersede pair `0x4b2f50` calls the
|
||||
// unlearn `0x4b2c50`, which prints nothing, then the registrar `0x4b25b0` with `edx = 1`
|
||||
// (`0x4b2f61`).
|
||||
@@ -840,6 +959,8 @@ fn spell_start(
|
||||
commands: &mut Commands,
|
||||
index: &GuidIndex,
|
||||
cast_events: &mut MessageWriter<CastEvent>,
|
||||
// The select of a caster aiming at the player, the target chain's.
|
||||
cast_at_player: &mut MessageWriter<CastAtPlayer>,
|
||||
self_guid: &SelfGuid,
|
||||
reports: &mut CastReports,
|
||||
pending: &mut PendingCast,
|
||||
@@ -847,6 +968,8 @@ fn spell_start(
|
||||
edits: &crate::creature_anim::UnitEdits,
|
||||
// Whether a spell resolves a visual for a caster, which its precast needs (`0x6ec220`).
|
||||
precasts: &dyn Fn(Entity, u32) -> bool,
|
||||
// Whether a streamed object is a unit or a player (`ObjectStore::is_unit`).
|
||||
is_unit: &dyn Fn(Entity) -> bool,
|
||||
seq: u64,
|
||||
) {
|
||||
// A nonzero cast time marks the caster `Casting`; an instant gets none, its GO follows at once.
|
||||
@@ -854,35 +977,37 @@ fn spell_start(
|
||||
"net: spell start {spell_id} by {caster:#x} ({cast_time_ms}ms, flags \
|
||||
{cast_flags:#x}, target {target:?}, ammo {ammo_display_id:?})"
|
||||
);
|
||||
// A spell with no record does nothing (`0x6e7856`-`0x6e7876`, all to `0x6e7a5b`).
|
||||
let Some(display) = spells.and_then(|s| s.catalog.get(spell_id)) else {
|
||||
return;
|
||||
};
|
||||
// The caster slot looked up as a unit (`0x468460` with type mask 8, `0x6e7892`); none ends
|
||||
// the handler too (`0x6e789b je 0x6e7a5b`). vmangos writes a GameObject's caster slot as 0, so
|
||||
// the decode names the object itself, which this refuses.
|
||||
let Some(e) = index.0.get(&caster).copied().filter(|&e| is_unit(e)) else {
|
||||
return;
|
||||
};
|
||||
// The nocked-ammo refresh (`0x60ba30` at `0x6e78b6`, gated at `0x6e78a1` on `SpellRec+0x20 &
|
||||
// 0x20` or `+0x18 & 0x2`, for any caster): a ranged START attaches the wire's ammo display id,
|
||||
// or detaches without one. The model persists through Load/Hold and the fire clip.
|
||||
if spells
|
||||
.and_then(|s| s.catalog.get(spell_id))
|
||||
.is_some_and(|d| d.ranged_attack())
|
||||
{
|
||||
if let Some(&e) = index.0.get(&caster) {
|
||||
match ammo_display_id.filter(|id| *id != 0) {
|
||||
Some(display_id) => {
|
||||
commands
|
||||
.entity(e)
|
||||
.insert(crate::creature_anim::NockedAmmo { display_id });
|
||||
}
|
||||
None => {
|
||||
commands
|
||||
.entity(e)
|
||||
.remove::<crate::creature_anim::NockedAmmo>();
|
||||
}
|
||||
if display.ranged_attack() {
|
||||
match ammo_display_id.filter(|id| *id != 0) {
|
||||
Some(display_id) => {
|
||||
commands
|
||||
.entity(e)
|
||||
.insert(crate::creature_anim::NockedAmmo { display_id });
|
||||
}
|
||||
None => {
|
||||
commands
|
||||
.entity(e)
|
||||
.remove::<crate::creature_anim::NockedAmmo>();
|
||||
}
|
||||
}
|
||||
}
|
||||
// SPELLCAST_START fires only on `cast_time > 0 && !(SpellRec+0x18 & 2)` (`0x6e7700`): a
|
||||
// ranged-slot spell never opens a bar. vmangos pads a non-auto-repeat ranged cast by 500 ms
|
||||
// (`SpellEntry::GetCastTime`), so Throw arrives as a 500 ms cast with no bar. An unknown spell
|
||||
// keeps the bar.
|
||||
let ranged_slot = spells
|
||||
.and_then(|s| s.catalog.get(spell_id))
|
||||
.is_some_and(|d| d.ranged_slot());
|
||||
// SPELLCAST_START fires only on `cast_time > 0 && !(SpellRec+0x18 & 2)` (`0x6e7a1d`,
|
||||
// `0x6e7a27`): a ranged-slot spell never opens a bar. vmangos pads a non-auto-repeat ranged
|
||||
// cast by 500 ms (`SpellEntry::GetCastTime`), so Throw arrives as a 500 ms cast with no bar.
|
||||
let ranged_slot = display.ranged_slot();
|
||||
if *crate::net::CAST_TRACE && self_guid.0 == Some(caster) {
|
||||
info!(
|
||||
"cast-trace: RECV SPELL_START — spell {spell_id} cast_time={cast_time_ms}ms \
|
||||
@@ -895,47 +1020,47 @@ fn spell_start(
|
||||
);
|
||||
}
|
||||
// Our own timed cast opens the bar.
|
||||
if self_guid.0 == Some(caster) && cast_time_ms > 0 {
|
||||
if !ranged_slot {
|
||||
reports.bar(CastBarEdge::Start {
|
||||
spell_id,
|
||||
cast_time_ms,
|
||||
});
|
||||
}
|
||||
// The real cast time replaces the guard's send-time deadline, ranged casts included.
|
||||
pending.refine(cast_time_ms, Instant::now());
|
||||
}
|
||||
if let Some(&e) = index.0.get(&caster) {
|
||||
if cast_time_ms > 0 {
|
||||
commands.entity(e).insert(Casting {
|
||||
spell_id,
|
||||
until: Some(Instant::now() + Duration::from_millis(u64::from(cast_time_ms))),
|
||||
});
|
||||
}
|
||||
// `0x6ec220`'s precast: another unit's unless the packet's flag bit 0 is set (`0x6e78f8`,
|
||||
// vmangos's `CAST_FLAG_HIDDEN_COMBATLOG`), ours unless the spell is the pending record's
|
||||
// (`0x6e79af`), whose send started it.
|
||||
let starts = if self_guid.0 == Some(caster) {
|
||||
pending.record_spell() != spell_id
|
||||
} else {
|
||||
cast_flags & 0x1 == 0
|
||||
};
|
||||
if starts && precasts(e, spell_id) {
|
||||
edits.push(crate::creature_anim::UnitEdit::StartPrecast {
|
||||
entity: e,
|
||||
spell_id,
|
||||
});
|
||||
}
|
||||
// The precast edge, instants included: their GO follows at once and reaps the hold.
|
||||
cast_events.write(CastEvent {
|
||||
entity: e,
|
||||
if self_guid.0 == Some(caster) && cast_time_ms > 0 && !ranged_slot {
|
||||
reports.bar(CastBarEdge::Start {
|
||||
spell_id,
|
||||
kind: CastEventKind::Start,
|
||||
cast_flags: 0,
|
||||
item_cast: false,
|
||||
seq,
|
||||
cast_time_ms,
|
||||
});
|
||||
}
|
||||
if cast_time_ms > 0 {
|
||||
commands.entity(e).insert(Casting {
|
||||
spell_id,
|
||||
until: Some(Instant::now() + Duration::from_millis(u64::from(cast_time_ms))),
|
||||
});
|
||||
}
|
||||
// `0x6ec220`'s precast: another unit's unless the packet's flag bit 0 is set (`0x6e78f8`,
|
||||
// vmangos's `CAST_FLAG_HIDDEN_COMBATLOG`), ours unless the spell is the pending record's
|
||||
// (`0x6e79af`), whose send started it.
|
||||
let starts = if self_guid.0 == Some(caster) {
|
||||
pending.record_spell() != spell_id
|
||||
} else {
|
||||
cast_flags & 0x1 == 0
|
||||
};
|
||||
if starts && precasts(e, spell_id) {
|
||||
edits.push(crate::creature_anim::UnitEdit::StartPrecast {
|
||||
entity: e,
|
||||
spell_id,
|
||||
});
|
||||
}
|
||||
// Another unit's cast whose unit target is the player (`0x6e790d` mask bit `0x2`,
|
||||
// `0x6e7926` a guid, `0x6e7939`/`0x6e7947` the player's) selects its caster when the
|
||||
// target chain's gates pass ([`crate::target`]).
|
||||
if self_guid.0 != Some(caster) && target.is_some() && target == self_guid.0 {
|
||||
cast_at_player.write(CastAtPlayer { caster: e, seq });
|
||||
}
|
||||
// The precast edge, instants included: their GO follows at once and reaps the hold.
|
||||
cast_events.write(CastEvent {
|
||||
entity: e,
|
||||
spell_id,
|
||||
kind: CastEventKind::Start,
|
||||
cast_flags: 0,
|
||||
item_cast: false,
|
||||
seq,
|
||||
});
|
||||
}
|
||||
|
||||
/// `GAMEOBJECT_TYPE_ID` 3, `CHEST`: the only GameObject type whose `OPEN_LOCK` cast arms the
|
||||
@@ -1010,17 +1135,21 @@ fn spell_go(
|
||||
),
|
||||
);
|
||||
}
|
||||
let (cooldowns, spells, items, pet_bar, spell_mods) = cooldown_ctx;
|
||||
// A spell with no record does nothing (`0x6e7cd7 jl`, `0x6e7ce3 jg` and `0x6e7cf7 je`, all to
|
||||
// the end `0x6e8647`), ahead of the caster's lookup and every leg.
|
||||
let Some(display) = spells.and_then(|s| s.catalog.get(spell_id)) else {
|
||||
return;
|
||||
};
|
||||
// A cast naming a GameObject goes to the GameObject animation driver, which opens the lid on
|
||||
// an open-lock cast, streamed caster or not.
|
||||
if let Some(go_guid) = go_target {
|
||||
go_lid.write(crate::go_anim::GoLidOpen { go_guid, spell_id });
|
||||
}
|
||||
let (cooldowns, spells, items, pet_bar, spell_mods) = cooldown_ctx;
|
||||
// The item leg held the cooldown for its record ([`item_go_cooldown`]).
|
||||
let mut pended = false;
|
||||
let (auto_repeat, sheath, stand, edits, engaged, start_gate, core) = attack_ctx;
|
||||
let now = Instant::now();
|
||||
let display = spells.and_then(|s| s.catalog.get(spell_id));
|
||||
// A chest becomes the loot target at this packet, not at the loot response: `HandleSpellGo
|
||||
// 0x6e7a70` reaches `0x6e831b call SetLootTarget 0x5ed5f0`, which writes `[player+0x1d28]` and
|
||||
// plays Loot 50. Gates: the local player cast it (`0x6e81b6`), the spell has `OPEN_LOCK`
|
||||
@@ -1031,7 +1160,7 @@ fn spell_go(
|
||||
// [`crate::ui_loot::LootKneel`] recomputes every frame.
|
||||
if self_guid.0 == Some(caster) {
|
||||
if let Some(go_guid) = go_target {
|
||||
let is_open_lock = display.is_some_and(|d| d.open_lock.is_some());
|
||||
let is_open_lock = display.open_lock.is_some();
|
||||
let is_chest = index
|
||||
.0
|
||||
.get(&go_guid)
|
||||
@@ -1060,7 +1189,7 @@ fn spell_go(
|
||||
// resolves to the selection or else the nearest hostile. Deviation: the fallback is the
|
||||
// packet's target guid, never the nearest-hostile acquire, because that would attack
|
||||
// something the player never named. Gated on `[player+0xc48] == 0` (`0x6e83e7`).
|
||||
if display.is_some_and(|d| d.initiates_auto_attack_at_go()) && !engaged {
|
||||
if display.initiates_auto_attack_at_go() && !engaged {
|
||||
if let (Some(&me), Some(guid)) =
|
||||
(index.0.get(&caster), hits.first().copied().or(target))
|
||||
{
|
||||
@@ -1087,59 +1216,54 @@ fn spell_go(
|
||||
// 25) or the item leg ([`item_go_cooldown`]). `SMSG_SPELL_COOLDOWN` is the server's
|
||||
// override; vmangos sends none for a plain cast. A ranged-slot cast folds
|
||||
// `UNIT_FIELD_RANGEDATTACKTIME` into the category recovery (`0x6e2b60`).
|
||||
let ranged_ms = display
|
||||
.filter(|d| d.ranged_speed_cooldown())
|
||||
.and_then(|_| {
|
||||
let e = index.0.get(&caster)?;
|
||||
stores.get(*e).ok()?.0.unit_ranged_attack_time()
|
||||
})
|
||||
.unwrap_or(0);
|
||||
let ranged_ms = if display.ranged_speed_cooldown() {
|
||||
index
|
||||
.0
|
||||
.get(&caster)
|
||||
.and_then(|&e| stores.get(e).ok())
|
||||
.and_then(|s| s.0.unit_ranged_attack_time())
|
||||
.unwrap_or(0)
|
||||
} else {
|
||||
0
|
||||
};
|
||||
match item_caster {
|
||||
Some(item) => {
|
||||
pended = item_go_cooldown(
|
||||
item, spell_id, display, now, index, stores, items, core.net, cooldowns,
|
||||
);
|
||||
}
|
||||
None => {
|
||||
if let Some(d) = display {
|
||||
cooldowns.start_spell(spell_id, d, ranged_ms, now, Some(spell_mods));
|
||||
}
|
||||
}
|
||||
None => cooldowns.start_spell(spell_id, display, ranged_ms, now, Some(spell_mods)),
|
||||
}
|
||||
if benilla_assets::trace::enabled() {
|
||||
if let Some(d) = display {
|
||||
let (recovery_ms, category_ms) = spell_mods.spell_cooldowns(d, ranged_ms);
|
||||
benilla_assets::trace::line(
|
||||
"cd",
|
||||
&format!(
|
||||
"arm spell={spell_id} rec={}ms cat={}:{}ms (GO self-insert)",
|
||||
recovery_ms, d.category, category_ms
|
||||
),
|
||||
);
|
||||
}
|
||||
let (recovery_ms, category_ms) = spell_mods.spell_cooldowns(display, ranged_ms);
|
||||
benilla_assets::trace::line(
|
||||
"cd",
|
||||
&format!(
|
||||
"arm spell={spell_id} rec={}ms cat={}:{}ms (GO self-insert)",
|
||||
recovery_ms, display.category, category_ms
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
// The pet leg of the same insert: an independent `if`, not an else, which a held item cooldown
|
||||
// skips, as it ends the handler (`0x6e84dd`).
|
||||
if let Some(d) =
|
||||
display.filter(|_| !pended && pet_go_cooldown(caster, self_guid, index, stores))
|
||||
{
|
||||
if !pended && pet_go_cooldown(caster, self_guid, index, stores) {
|
||||
// No ranged pad: `0x6e2b60` is called on the self leg only (`0x6e845d`). Op 11 still
|
||||
// applies to both columns (`0x6e85c5`, `0x6e85d1`) off the player's tables, which gate
|
||||
// on the spell's family and never the caster (`0x6e6b30`).
|
||||
pet_bar
|
||||
.cooldowns
|
||||
.start_spell(spell_id, d, 0, now, Some(spell_mods));
|
||||
.start_spell(spell_id, display, 0, now, Some(spell_mods));
|
||||
// Its flush follows, inserted or not (`0x6e85fc` `0x4b31b0`, `0x6e8601` `0x4bce90`):
|
||||
// `ACTIONBAR_UPDATE_COOLDOWN`, `SPELL_UPDATE_COOLDOWN`, `PET_BAR_UPDATE_COOLDOWN`, and no
|
||||
// `PET_BAR_UPDATE`.
|
||||
if benilla_assets::trace::enabled() {
|
||||
let (recovery_ms, category_ms) = spell_mods.spell_cooldowns(d, 0);
|
||||
let (recovery_ms, category_ms) = spell_mods.spell_cooldowns(display, 0);
|
||||
benilla_assets::trace::line(
|
||||
"cd",
|
||||
&format!(
|
||||
"arm spell={spell_id} rec={}ms cat={}:{}ms (GO pet-insert)",
|
||||
recovery_ms, d.category, category_ms
|
||||
recovery_ms, display.category, category_ms
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -1154,14 +1278,11 @@ fn spell_go(
|
||||
}
|
||||
// The precast ends with its own spell's GO (`0x60d040` at `0x6e7fc5`), its tail run as
|
||||
// `0x6e4870` answers for the record and the cast flags (`0x6e7fa1`, pushed at `0x6e7fbd`).
|
||||
// A spell with no record returns long before (`0x6e7cd7`-`0x6e7cf7`).
|
||||
if let Some(d) = display {
|
||||
edits.push(crate::creature_anim::UnitEdit::EndPrecast {
|
||||
entity: e,
|
||||
spell_id: Some(spell_id),
|
||||
tail: d.test_attributes_and_flags(u32::from(cast_flags)),
|
||||
});
|
||||
}
|
||||
edits.push(crate::creature_anim::UnitEdit::EndPrecast {
|
||||
entity: e,
|
||||
spell_id: Some(spell_id),
|
||||
tail: display.test_attributes_and_flags(u32::from(cast_flags)),
|
||||
});
|
||||
// The GO's chain-hop fill (`0x6e800d`), the producer for non-channelled chain spells. It
|
||||
// must precede the CastEvent: the cast kit's chain proc consumes it the same frame. The
|
||||
// reference gates it on the attribute predicate `0x6e4870`, whose role here is untraced;
|
||||
@@ -1246,21 +1367,13 @@ fn spell_failed_other(
|
||||
/// `SMSG_SPELL_DELAYED`: pushback. A hit on our cast extends its timer by `delay_ms` (vmangos
|
||||
/// `Spell::Delayed`), and the bar's window slides out by the same (`SPELLCAST_DELAYED`). Sent
|
||||
/// only to the caster, but gated on the caster guid like every own-cast edge.
|
||||
fn spell_delayed(
|
||||
caster: u64,
|
||||
delay_ms: u32,
|
||||
self_guid: &SelfGuid,
|
||||
reports: &mut CastReports,
|
||||
pending: &mut PendingCast,
|
||||
) {
|
||||
fn spell_delayed(caster: u64, delay_ms: u32, self_guid: &SelfGuid, reports: &mut CastReports) {
|
||||
debug!("net: spell delayed by {caster:#x} (+{delay_ms}ms pushback)");
|
||||
if self_guid.0 == Some(caster) {
|
||||
if *crate::net::CAST_TRACE {
|
||||
info!("cast-trace: RECV SPELL_DELAYED — +{delay_ms}ms pushback (bar extends, does NOT vanish)");
|
||||
}
|
||||
reports.bar(CastBarEdge::Delayed { delay_ms });
|
||||
// The in-flight guard holds past the stretched end.
|
||||
pending.delay(delay_ms, Instant::now());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1297,7 +1410,7 @@ fn cancel_auto_repeat(
|
||||
fn item_go_cooldown(
|
||||
item: u64,
|
||||
spell_id: u32,
|
||||
display: Option<&benilla_formats::SpellDisplay>,
|
||||
display: &benilla_formats::SpellDisplay,
|
||||
now: Instant,
|
||||
index: &GuidIndex,
|
||||
stores: &Query<&mut ObjectStore>,
|
||||
@@ -1316,7 +1429,7 @@ fn item_go_cooldown(
|
||||
return false;
|
||||
};
|
||||
let Some(record) = items.template(entry, item, Ask::Event(net)) else {
|
||||
let on_hold = display.is_some_and(|d| d.cooldown_on_event());
|
||||
let on_hold = display.cooldown_on_event();
|
||||
cooldowns.pend_item(entry, spell_id, now, on_hold);
|
||||
return true;
|
||||
};
|
||||
@@ -1328,7 +1441,7 @@ fn item_go_cooldown(
|
||||
category: block.category,
|
||||
category_cooldown_ms: block.category_cooldown_ms,
|
||||
};
|
||||
cooldowns.start_item(entry, &block, display, now);
|
||||
cooldowns.start_item(entry, &block, Some(display), now);
|
||||
}
|
||||
None => cooldowns.flush_item_leg(),
|
||||
}
|
||||
@@ -1509,9 +1622,11 @@ fn spell_chain_targets(
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::spell::QueuedMeleeSpell;
|
||||
use benilla_protocol::messages::ACTION_KIND_SPELL;
|
||||
use benilla_protocol::messages::{ObjectType, ACTION_KIND_SPELL};
|
||||
|
||||
mod cooldown_sites;
|
||||
mod dispatch;
|
||||
mod openers;
|
||||
|
||||
/// `SMSG_COOLDOWN_EVENT` (`0x6e9670`): the event moves the held record's one start, which the
|
||||
/// GCD leg reads (`0x6e15d8`), so the global cooldown runs again from the packet.
|
||||
@@ -1816,6 +1931,7 @@ mod tests {
|
||||
let mut app = App::new();
|
||||
app.add_message::<CastEvent>()
|
||||
.add_message::<SpellGoTargets>()
|
||||
.add_message::<CastAtPlayer>()
|
||||
.add_message::<CombatTextSpawn>()
|
||||
.add_message::<GoLidOpen>()
|
||||
.add_message::<crate::creature_anim::SheathRequest>()
|
||||
@@ -1837,13 +1953,35 @@ mod tests {
|
||||
app.insert_resource(crate::net::NetCommands(tx));
|
||||
let self_e = app
|
||||
.world_mut()
|
||||
.spawn((Guid(Self::SELF), SelfPlayer, ObjectStore::default()))
|
||||
.spawn((
|
||||
Guid(Self::SELF),
|
||||
SelfPlayer,
|
||||
Self::store(ObjectType::Player),
|
||||
))
|
||||
.id();
|
||||
app.world_mut()
|
||||
.resource_mut::<GuidIndex>()
|
||||
.0
|
||||
.insert(Self::SELF, self_e);
|
||||
app.world_mut().resource_mut::<SelfGuid>().0 = Some(Self::SELF);
|
||||
// Every spell the sequences cast has a record, as a shipped spell does: a packet
|
||||
// naming one without does nothing (`0x6e7876`, `0x6e7cf7`).
|
||||
app.insert_resource(Spells {
|
||||
catalog: benilla_formats::SpellCatalog::from_displays(
|
||||
[
|
||||
FIREBALL,
|
||||
FROSTBOLT,
|
||||
FORTITUDE,
|
||||
ARCANE_MISSILES,
|
||||
HEARTHSTONE,
|
||||
MINOR_HEALING,
|
||||
]
|
||||
.into_iter()
|
||||
.map(|id| (id, Default::default()))
|
||||
.collect(),
|
||||
),
|
||||
..Spells::empty_for_tests()
|
||||
});
|
||||
Self { app, self_e, sent }
|
||||
}
|
||||
|
||||
@@ -1881,7 +2019,7 @@ mod tests {
|
||||
.run_system_once(
|
||||
move |mut slots: crate::spell::CastSlots,
|
||||
net: Res<crate::net::NetCommands>| {
|
||||
slots.core(&net).push(spell_id, held, Instant::now());
|
||||
slots.core(&net).push(spell_id, held);
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
@@ -1900,33 +2038,50 @@ mod tests {
|
||||
|
||||
/// `SMSG_SPELL_START` by `caster` with the packet's `cast_flags`.
|
||||
fn start_by(&mut self, caster: u64, spell_id: u32, cast_time_ms: u32, cast_flags: u16) {
|
||||
self.start_at(caster, spell_id, cast_time_ms, cast_flags, None);
|
||||
}
|
||||
|
||||
/// The same with the packet's unit target, read against the world's spell records.
|
||||
fn start_at(
|
||||
&mut self,
|
||||
caster: u64,
|
||||
spell_id: u32,
|
||||
cast_time_ms: u32,
|
||||
cast_flags: u16,
|
||||
target: Option<u64>,
|
||||
) {
|
||||
self.app
|
||||
.world_mut()
|
||||
.run_system_once(
|
||||
move |mut commands: Commands,
|
||||
index: Res<GuidIndex>,
|
||||
mut cast_events: MessageWriter<CastEvent>,
|
||||
mut cast_at_player: MessageWriter<CastAtPlayer>,
|
||||
self_guid: Res<SelfGuid>,
|
||||
mut reports: ResMut<CastReports>,
|
||||
mut pending: ResMut<PendingCast>,
|
||||
edits: Res<crate::creature_anim::UnitEdits>,
|
||||
visuals: crate::creature_anim::PrecastVisuals| {
|
||||
spells: Option<Res<Spells>>,
|
||||
visuals: crate::creature_anim::PrecastVisuals,
|
||||
stores: Query<&ObjectStore>| {
|
||||
spell_start(
|
||||
caster,
|
||||
spell_id,
|
||||
cast_flags,
|
||||
cast_time_ms,
|
||||
None,
|
||||
target,
|
||||
None,
|
||||
&mut commands,
|
||||
&index,
|
||||
&mut cast_events,
|
||||
&mut cast_at_player,
|
||||
&self_guid,
|
||||
&mut reports,
|
||||
&mut pending,
|
||||
None,
|
||||
spells.as_deref(),
|
||||
&edits,
|
||||
&|e, spell_id| visuals.resolves(e, spell_id),
|
||||
&|e| stores.get(e).is_ok_and(|s| s.is_unit()),
|
||||
1,
|
||||
);
|
||||
},
|
||||
@@ -1935,12 +2090,28 @@ mod tests {
|
||||
crate::creature_anim::apply_unit_edits(self.app.world_mut());
|
||||
}
|
||||
|
||||
/// A streamed object of `kind` with no field but its `OBJECT_FIELD_TYPE` mask (2).
|
||||
fn store(kind: ObjectType) -> ObjectStore {
|
||||
let mask = match kind {
|
||||
ObjectType::Player => 0x19,
|
||||
ObjectType::Unit => 0x9,
|
||||
ObjectType::GameObject => 0x21,
|
||||
_ => 0x1,
|
||||
};
|
||||
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(2, mask)]).into_created(kind))
|
||||
}
|
||||
|
||||
/// A unit `guid` streamed beside us.
|
||||
fn other_unit(&mut self, guid: u64) -> Entity {
|
||||
self.other(guid, ObjectType::Unit)
|
||||
}
|
||||
|
||||
/// An object of `kind` streamed beside us as `guid`.
|
||||
fn other(&mut self, guid: u64, kind: ObjectType) -> Entity {
|
||||
let e = self
|
||||
.app
|
||||
.world_mut()
|
||||
.spawn((crate::net::Guid(guid), ObjectStore::default()))
|
||||
.spawn((crate::net::Guid(guid), Self::store(kind)))
|
||||
.id();
|
||||
self.app
|
||||
.world_mut()
|
||||
@@ -2297,6 +2468,91 @@ mod tests {
|
||||
assert_eq!(s.precast(me), Some((FIREBALL, true)));
|
||||
}
|
||||
|
||||
/// The cast events written since the last look, by spell and kind.
|
||||
fn drain_cast_events(s: &mut CastSeq) -> Vec<(u32, CastEventKind)> {
|
||||
s.app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<CastEvent>>()
|
||||
.drain()
|
||||
.map(|e| (e.spell_id, e.kind))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Nor does it reap the caster's cast or write the cast event: `0x6e7cd7 jl`, `0x6e7ce3 jg`
|
||||
/// and `0x6e7cf7 je` all reach the handler's end `0x6e8647`.
|
||||
#[test]
|
||||
fn a_go_with_no_spell_record_reaps_no_cast_and_writes_no_event() {
|
||||
let mut s = CastSeq::new();
|
||||
let me = s.self_e;
|
||||
s.app.world_mut().insert_resource(Spells::empty_for_tests());
|
||||
s.app.world_mut().entity_mut(me).insert(Casting {
|
||||
spell_id: FIREBALL,
|
||||
until: None,
|
||||
});
|
||||
s.go(FIREBALL);
|
||||
assert!(s.app.world().get::<Casting>(me).is_some(), "no reap");
|
||||
assert_eq!(drain_cast_events(&mut s), vec![], "no cast event");
|
||||
}
|
||||
|
||||
/// `SMSG_SPELL_START` for a spell with no record returns before anything (`0x6e7876 je
|
||||
/// 0x6e7a5b`): ours opens no bar, and no caster is marked casting or given a cast event.
|
||||
#[test]
|
||||
fn a_start_with_no_spell_record_does_nothing() {
|
||||
const OTHER: u64 = 20;
|
||||
let mut s = CastSeq::new();
|
||||
let me = s.self_e;
|
||||
let other = s.other_unit(OTHER);
|
||||
s.app.world_mut().insert_resource(Spells::empty_for_tests());
|
||||
s.start(FIREBALL, 3_000);
|
||||
s.start_by(OTHER, FIREBALL, 3_000, 0);
|
||||
assert_eq!(s.events(), Vec::<&str>::new(), "no bar");
|
||||
assert!(s.app.world().get::<Casting>(me).is_none());
|
||||
assert!(s.app.world().get::<Casting>(other).is_none());
|
||||
assert_eq!(drain_cast_events(&mut s), vec![], "no cast event");
|
||||
}
|
||||
|
||||
/// `SMSG_SPELL_START` looks its caster up as a unit (`0x468460` with type mask 8 at
|
||||
/// `0x6e7892`) and ends without one (`0x6e789b je 0x6e7a5b`): a GameObject's cast, whose
|
||||
/// caster slot vmangos leaves 0 so the first slot names the object, gets no `Casting`, no
|
||||
/// precast and no cast event.
|
||||
#[test]
|
||||
fn a_start_by_a_game_object_does_nothing() {
|
||||
const LIGHTWELL: u64 = 0xf110_002c_3600_0042;
|
||||
let mut s = CastSeq::new();
|
||||
crate::creature_anim::install_visuals_for_tests(s.app.world_mut(), &[FIREBALL], &[]);
|
||||
let well = s.other(LIGHTWELL, ObjectType::GameObject);
|
||||
s.start_by(LIGHTWELL, FIREBALL, 3_000, 0);
|
||||
assert!(s.app.world().get::<Casting>(well).is_none());
|
||||
assert_eq!(s.precast(well), None);
|
||||
assert_eq!(drain_cast_events(&mut s), vec![], "no cast event");
|
||||
}
|
||||
|
||||
/// Another unit's start whose unit target is the player asks the target chain for the
|
||||
/// caster's select (`0x6e790d` mask bit `0x2`, `0x6e7926` a guid, `0x6e7939`/`0x6e7947` the
|
||||
/// player's); the player's own start (`0x6e78d6`) and a start at anyone else do not.
|
||||
#[test]
|
||||
fn another_units_start_at_the_player_asks_for_its_casters_select() {
|
||||
const OTHER: u64 = 20;
|
||||
const THIRD: u64 = 30;
|
||||
let mut s = CastSeq::new();
|
||||
crate::creature_anim::install_visuals_for_tests(s.app.world_mut(), &[FROSTBOLT], &[]);
|
||||
let other = s.other_unit(OTHER);
|
||||
let asks = |s: &mut CastSeq| -> Vec<Entity> {
|
||||
s.app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<CastAtPlayer>>()
|
||||
.drain()
|
||||
.map(|m| m.caster)
|
||||
.collect()
|
||||
};
|
||||
s.start_at(OTHER, FROSTBOLT, 3_000, 0, Some(CastSeq::SELF));
|
||||
assert_eq!(asks(&mut s), vec![other], "at us");
|
||||
s.start_at(OTHER, FROSTBOLT, 3_000, 0, Some(THIRD));
|
||||
s.start_at(OTHER, FROSTBOLT, 3_000, 0, None);
|
||||
s.start_at(CastSeq::SELF, FROSTBOLT, 3_000, 0, Some(CastSeq::SELF));
|
||||
assert_eq!(asks(&mut s), vec![], "at another, at no unit, or ours");
|
||||
}
|
||||
|
||||
/// The GO's end runs its tail as `0x6e4870` answers for the record and the cast flags
|
||||
/// (`0x6e7fa1`, pushed at `0x6e7fbd`), its last step our loot's release; a failure's always
|
||||
/// runs it (`0x6e8e8c` and `0x6e1c8e` push `b` 1).
|
||||
@@ -3111,6 +3367,7 @@ mod tests {
|
||||
mut stand: MessageWriter<crate::player::StandStateRequest>,
|
||||
edits: Res<crate::creature_anim::UnitEdits>| {
|
||||
let net_commands = crate::net::NetCommands(tx.clone());
|
||||
let spells = catalog_with(421, Default::default());
|
||||
spell_go(
|
||||
10,
|
||||
421, // Chain Lightning
|
||||
@@ -3133,7 +3390,7 @@ mod tests {
|
||||
&mut crate::ui_loot::LootLatch::default(),
|
||||
(
|
||||
&mut cooldowns,
|
||||
None,
|
||||
Some(&spells),
|
||||
&mut items,
|
||||
&mut pet_bar,
|
||||
&crate::spell::SpellModifiers::default(),
|
||||
|
||||
@@ -0,0 +1,282 @@
|
||||
//! The spell's handlers as the whole client registers them, each packet run through the net
|
||||
//! drain's dispatch: the cooldown lists a guid addresses, the inventory refusal's cast cancel and
|
||||
//! the world entry's reset of the cast slots.
|
||||
|
||||
use super::*;
|
||||
use crate::net::handlers::dispatch;
|
||||
use crate::net::{ClientCommand, Guid};
|
||||
use benilla_formats::SpellDisplay;
|
||||
|
||||
const ME: u64 = 10;
|
||||
|
||||
/// The whole client, headless, with us streamed in.
|
||||
fn client() -> (App, crossbeam_channel::Receiver<ClientCommand>) {
|
||||
let mut app = crate::game_plugins::schedule_tests::headless_client();
|
||||
let (tx, rx) = crossbeam_channel::unbounded();
|
||||
app.insert_resource(NetCommands(tx));
|
||||
let world = app.world_mut();
|
||||
let me = world
|
||||
.spawn((Guid(ME), SelfPlayer, ObjectStore::default()))
|
||||
.id();
|
||||
world.resource_mut::<GuidIndex>().0.insert(ME, me);
|
||||
world.resource_mut::<SelfGuid>().0 = Some(ME);
|
||||
(app, rx)
|
||||
}
|
||||
|
||||
/// `SMSG_COOLDOWN_EVENT` and `SMSG_CLEAR_COOLDOWN` (`0x6e9670`) take the pet's list for the pet
|
||||
/// bar's guid `[0xb714a0]` and the player's for any other (`0x6e9696`): a guid that is neither
|
||||
/// ours nor the pet's reaches our list, and the pet's does not.
|
||||
#[test]
|
||||
fn a_cooldown_event_and_clear_on_any_guid_but_the_pets_reach_our_list() {
|
||||
const STEALTH: u32 = 1784;
|
||||
const STRANGER: u64 = 0x77;
|
||||
const PET: u64 = 0xf140_0000_0000_0042;
|
||||
// Bit 25 holds the record until its event (`0x6e3050`).
|
||||
let held = || SpellDisplay {
|
||||
recovery_ms: 10_000,
|
||||
attributes: 0x0200_0000,
|
||||
..Default::default()
|
||||
};
|
||||
let (mut app, _rx) = client();
|
||||
let info = |app: &App| {
|
||||
app.world()
|
||||
.resource::<Cooldowns>()
|
||||
.info(STEALTH, 0, Some(&held()), Instant::now())
|
||||
};
|
||||
let seed = |app: &mut App| {
|
||||
app.world_mut().resource_mut::<Cooldowns>().start_spell(
|
||||
STEALTH,
|
||||
&held(),
|
||||
0,
|
||||
Instant::now(),
|
||||
None,
|
||||
);
|
||||
};
|
||||
|
||||
seed(&mut app);
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::ui_pet::PetBar>()
|
||||
.spells
|
||||
.pet_guid = PET;
|
||||
dispatch(
|
||||
app.world_mut(),
|
||||
vec![SessionEvent::CooldownEvent {
|
||||
spell_id: STEALTH,
|
||||
caster: PET,
|
||||
}],
|
||||
);
|
||||
assert!(!info(&app).enabled, "the pet's guid is the pet's list");
|
||||
|
||||
dispatch(
|
||||
app.world_mut(),
|
||||
vec![SessionEvent::CooldownEvent {
|
||||
spell_id: STEALTH,
|
||||
caster: STRANGER,
|
||||
}],
|
||||
);
|
||||
let started = info(&app);
|
||||
assert!(
|
||||
started.enabled && started.remaining_ms > 0,
|
||||
"another guid's event starts our held record"
|
||||
);
|
||||
dispatch(
|
||||
app.world_mut(),
|
||||
vec![SessionEvent::ClearCooldown {
|
||||
spell_id: STEALTH,
|
||||
caster: STRANGER,
|
||||
}],
|
||||
);
|
||||
assert_eq!(info(&app).remaining_ms, 0, "and its clear removes it");
|
||||
}
|
||||
|
||||
/// `SMSG_INVENTORY_CHANGE_FAILURE` naming the in-flight cast's item (`0x5e3a99`-`0x5e3aab`, the
|
||||
/// guid `[0xcecab0]`) cancels it as `CancelCast(1, 0, 0x17)` (`0x5e3ab3`): the slot pops with no
|
||||
/// packet and the failure's event fires. A refusal naming another item leaves the cast in flight.
|
||||
#[test]
|
||||
fn an_inventory_refusal_pops_the_cast_of_its_item_and_no_other() {
|
||||
const HEARTH: u32 = 8690;
|
||||
const STONE: u64 = 0x4000_0000_0000_0101;
|
||||
const BAG: u64 = 0x4000_0000_0000_0102;
|
||||
let (mut app, rx) = client();
|
||||
app.world_mut().insert_resource(Spells {
|
||||
catalog: benilla_formats::SpellCatalog::from_displays(
|
||||
[(HEARTH, SpellDisplay::default())].into_iter().collect(),
|
||||
),
|
||||
..Spells::empty_for_tests()
|
||||
});
|
||||
{
|
||||
let mut pending = app.world_mut().resource_mut::<PendingCast>();
|
||||
pending.fill_record();
|
||||
pending.fill_record_spell(HEARTH);
|
||||
pending.push_cast(
|
||||
HEARTH,
|
||||
Some(benilla_protocol::messages::ITEM_FLAG_PLAYERCAST),
|
||||
Some(STONE),
|
||||
);
|
||||
}
|
||||
let refusal = |item_guid| SessionEvent::InventoryFailure {
|
||||
reason: 0x16,
|
||||
required_level: None,
|
||||
item_guid,
|
||||
item2_guid: 0,
|
||||
bag_slot: 0xff,
|
||||
};
|
||||
|
||||
dispatch(app.world_mut(), vec![refusal(BAG)]);
|
||||
assert_eq!(
|
||||
app.world().resource::<PendingCast>().current(),
|
||||
Some(HEARTH),
|
||||
"another item's refusal"
|
||||
);
|
||||
assert!(app.world().resource::<CastReports>().edges().is_empty());
|
||||
|
||||
dispatch(app.world_mut(), vec![refusal(STONE)]);
|
||||
assert_eq!(app.world().resource::<PendingCast>().current(), None);
|
||||
assert!(matches!(
|
||||
app.world().resource::<CastReports>().edges()[..],
|
||||
[CastBarEdge::Failed]
|
||||
));
|
||||
assert!(
|
||||
!rx.try_iter()
|
||||
.any(|c| matches!(c, ClientCommand::CancelCast { .. })),
|
||||
"`send` 0: no CMSG_CANCEL_CAST"
|
||||
);
|
||||
}
|
||||
|
||||
/// Every world entry runs `Spell_C::SystemInitialize 0x6e7150` (`ClientInitializeGame 0x401570`
|
||||
/// → `CGUnit_C::Initialize 0x6033c0`, `0x6038da`), which empties the in-flight slot and its save
|
||||
/// (`0x6e72e7`-`0x6e7305`), the targeting word (`0x6e72e0`) and the auto-repeat spell
|
||||
/// (`0x6e730b`): a cast, a queued strike or a cursor the last character left is gone.
|
||||
#[test]
|
||||
fn a_world_entry_empties_the_cast_slots() {
|
||||
const FIREBALL: u32 = 133;
|
||||
const HEROIC_STRIKE: u32 = 78;
|
||||
const BLIZZARD: u32 = 10;
|
||||
const AUTO_SHOT: u32 = 75;
|
||||
let (mut app, _rx) = client();
|
||||
{
|
||||
let world = app.world_mut();
|
||||
world.resource_mut::<QueuedMeleeSpell>().arm(HEROIC_STRIKE);
|
||||
// A cast pushed over the strike saves it (`0x6e4adf`).
|
||||
world
|
||||
.run_system_once(
|
||||
|mut slots: crate::spell::CastSlots, net: Res<NetCommands>| {
|
||||
slots.core(&net).push(
|
||||
FIREBALL,
|
||||
crate::spell::Held::Cast {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
);
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
world.resource_mut::<crate::spell::SpellTargeting>().enter(
|
||||
BLIZZARD,
|
||||
crate::spell::CastCommit::Spell,
|
||||
0x40,
|
||||
);
|
||||
world.resource_mut::<AutoRepeatActive>().0 = Some(AUTO_SHOT);
|
||||
assert_eq!(
|
||||
world.resource::<QueuedMeleeSpell>().saved(),
|
||||
Some(HEROIC_STRIKE)
|
||||
);
|
||||
assert_eq!(world.resource::<PendingCast>().current(), Some(FIREBALL));
|
||||
}
|
||||
|
||||
dispatch(
|
||||
app.world_mut(),
|
||||
vec![SessionEvent::Connected {
|
||||
self_guid: ME,
|
||||
name: "Probethree".to_string(),
|
||||
billing: Default::default(),
|
||||
tutorial_flags: None,
|
||||
addon_info: None,
|
||||
}],
|
||||
);
|
||||
|
||||
let world = app.world();
|
||||
assert_eq!(world.resource::<PendingCast>().current(), None);
|
||||
assert_eq!(world.resource::<QueuedMeleeSpell>().current(), None);
|
||||
assert_eq!(world.resource::<QueuedMeleeSpell>().saved(), None);
|
||||
assert!(!world.resource::<crate::spell::SpellTargeting>().active());
|
||||
assert_eq!(world.resource::<AutoRepeatActive>().0, None);
|
||||
}
|
||||
|
||||
/// The entry itself, in packet order.
|
||||
fn enter_world() -> SessionEvent {
|
||||
SessionEvent::Connected {
|
||||
self_guid: ME,
|
||||
name: "Probethree".to_string(),
|
||||
billing: Default::default(),
|
||||
tutorial_flags: None,
|
||||
addon_info: None,
|
||||
}
|
||||
}
|
||||
|
||||
/// The same entry zeroes both modifier tables (`0x6e72c4`, `0x6e72d6`) and the class family
|
||||
/// (`0x6e7317`) at the entry and in packet order: a modifier the same drain brings after it
|
||||
/// stands.
|
||||
#[test]
|
||||
fn a_world_entry_clears_the_modifiers_in_packet_order() {
|
||||
use crate::spell::{SpellModifiers, OP_COST};
|
||||
/// A mage spell (family 3) with one family bit.
|
||||
fn mage(bit: u8) -> SpellDisplay {
|
||||
SpellDisplay {
|
||||
spell_family: 3,
|
||||
spell_family_flags: 1 << bit,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
let (mut app, _rx) = client();
|
||||
{
|
||||
let mut mods = app.world_mut().resource_mut::<SpellModifiers>();
|
||||
mods.set_class_family(3);
|
||||
mods.set(true, 5, OP_COST, -30);
|
||||
assert_eq!(mods.apply(&mage(5), OP_COST, 100), 70);
|
||||
}
|
||||
|
||||
dispatch(
|
||||
app.world_mut(),
|
||||
vec![
|
||||
enter_world(),
|
||||
SessionEvent::SpellModifier {
|
||||
flat: true,
|
||||
mask_bit: 6,
|
||||
op: OP_COST,
|
||||
value: -20,
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
let mut mods = app.world_mut().resource_mut::<SpellModifiers>();
|
||||
assert_eq!(
|
||||
mods.apply(&mage(6), OP_COST, 100),
|
||||
100,
|
||||
"the class family is 0 until the avatar names it"
|
||||
);
|
||||
mods.set_class_family(3);
|
||||
assert_eq!(mods.apply(&mage(5), OP_COST, 100), 100, "cleared");
|
||||
assert_eq!(
|
||||
mods.apply(&mage(6), OP_COST, 100),
|
||||
80,
|
||||
"the packet after the entry"
|
||||
);
|
||||
}
|
||||
|
||||
/// The entry zeroes the Feed Pet spell `[0xcecad8]` (`0x6e7311`); the next spell list latches it
|
||||
/// again.
|
||||
#[test]
|
||||
fn a_world_entry_clears_the_feed_pet_spell() {
|
||||
let (mut app, _rx) = client();
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::ui_action::LearnedAbilities>()
|
||||
.feed_pet = Some(6991);
|
||||
dispatch(app.world_mut(), vec![enter_world()]);
|
||||
assert_eq!(
|
||||
app.world()
|
||||
.resource::<crate::ui_action::LearnedAbilities>()
|
||||
.feed_pet,
|
||||
None
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
//! The opener list `0xb700b0` that the lock resolver `0x5f83d0` scans from index 0: the known
|
||||
//! spells whose `Effect[0]` is `OPEN_LOCK` (`0x4b265e`), in the order the server taught them.
|
||||
//! Lock 43, the Hyacinth Mushroom's, has one slot that both 6478 "Opening" and 22810 "Opening -
|
||||
//! No Text" clear, so the order alone picks the spell the click casts.
|
||||
|
||||
use super::*;
|
||||
use crate::target::lock::{resolve_lock, GoFacts, LockOutcome};
|
||||
use benilla_formats::{LockSlot, OpenLock, SpellDisplay, GO_STATE_READY, LOCK_KEY_SKILL};
|
||||
|
||||
const OPENING: u32 = 6478;
|
||||
const OPENING_NO_TEXT: u32 = 22810;
|
||||
/// A second rank of "Opening", made up, between the two ids.
|
||||
const OPENING_2: u32 = 6479;
|
||||
/// A spell with no lock effect.
|
||||
const FIREBALL: u32 = 133;
|
||||
|
||||
/// `Effect[0]` `OPEN_LOCK` (0x21) on LockType 13.
|
||||
fn opener() -> SpellDisplay {
|
||||
SpellDisplay {
|
||||
effects: [0x21, 0, 0],
|
||||
open_lock: Some(OpenLock {
|
||||
lock_type: 13,
|
||||
effect: 0,
|
||||
}),
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
fn spells() -> Spells {
|
||||
let mut spells = Spells::empty_for_tests();
|
||||
spells.catalog = benilla_formats::SpellCatalog::from_displays(
|
||||
[
|
||||
(OPENING, opener()),
|
||||
(OPENING_NO_TEXT, opener()),
|
||||
(OPENING_2, opener()),
|
||||
(FIREBALL, SpellDisplay::default()),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
);
|
||||
spells
|
||||
}
|
||||
|
||||
/// `SMSG_INITIAL_SPELLS` with `ids` in wire order.
|
||||
fn book(ids: &[u32], spells: &Spells) -> PlayerActions {
|
||||
let mut actions = PlayerActions::default();
|
||||
spell_book(
|
||||
ids.to_vec(),
|
||||
vec![],
|
||||
&mut actions,
|
||||
&mut Cooldowns::default(),
|
||||
(
|
||||
Some(spells),
|
||||
&crate::items::Items::default(),
|
||||
&crate::spell::SpellModifiers::default(),
|
||||
crate::spell::CategoryPad::for_list(false, None),
|
||||
),
|
||||
);
|
||||
actions
|
||||
}
|
||||
|
||||
/// What the resolver casts for lock 43: its one slot, LockType 13 at skill 0, on a closed object.
|
||||
fn opens(actions: &PlayerActions, spells: &Spells) -> LockOutcome {
|
||||
let slot = [LockSlot {
|
||||
key_type: LOCK_KEY_SKILL,
|
||||
index: 13,
|
||||
skill: 0,
|
||||
action: 0,
|
||||
}];
|
||||
let mut objects = crate::ui_items::TestObjects::new();
|
||||
resolve_lock(
|
||||
&slot,
|
||||
&actions.openers,
|
||||
Some(spells),
|
||||
None,
|
||||
None,
|
||||
&objects.get(),
|
||||
GoFacts {
|
||||
state: GO_STATE_READY,
|
||||
flag_locked: false,
|
||||
level: 0,
|
||||
},
|
||||
&mut None,
|
||||
)
|
||||
}
|
||||
|
||||
/// The replay learns the list in wire order (`0x5dea8b`-`0x5deab9`), each opener appended
|
||||
/// (`0x4b2675`-`0x4b2689`), and the resolver takes the first that clears the slot (`0x5f8511`).
|
||||
#[test]
|
||||
fn the_first_opener_the_server_listed_opens_the_lock() {
|
||||
let spells = spells();
|
||||
let actions = book(&[OPENING_NO_TEXT, FIREBALL, OPENING], &spells);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_NO_TEXT)
|
||||
);
|
||||
let actions = book(&[OPENING, OPENING_NO_TEXT], &spells);
|
||||
assert_eq!(opens(&actions, &spells), LockOutcome::OpenBySpell(OPENING));
|
||||
}
|
||||
|
||||
/// `SMSG_LEARNED_SPELL` appends at the tail (`0x5e620d` → `0x5e9c20` → `0x4b25b0`).
|
||||
#[test]
|
||||
fn a_learned_opener_goes_to_the_tail() {
|
||||
let spells = spells();
|
||||
let mut actions = book(&[FIREBALL], &spells);
|
||||
let errors = UiErrorKeys::default();
|
||||
let mut tab = LearnedInTab::default();
|
||||
learned_spell(
|
||||
OPENING_NO_TEXT,
|
||||
&mut actions,
|
||||
Some(&spells),
|
||||
&errors,
|
||||
&mut tab,
|
||||
);
|
||||
learned_spell(OPENING, &mut actions, Some(&spells), &errors, &mut tab);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_NO_TEXT)
|
||||
);
|
||||
}
|
||||
|
||||
/// `SMSG_SUPERCEDED_SPELL` removes the old rank (`0x4b2f5b` → `0x4b2c50`) and appends the new
|
||||
/// one (`0x4b2f68` → `0x4b25b0`), so the new rank goes behind every other opener.
|
||||
#[test]
|
||||
fn a_superseded_opener_moves_its_new_rank_to_the_tail() {
|
||||
let spells = spells();
|
||||
let mut actions = book(&[OPENING, OPENING_NO_TEXT], &spells);
|
||||
superceded_spell(
|
||||
OPENING,
|
||||
OPENING_2,
|
||||
&mut actions,
|
||||
Some(&spells),
|
||||
&UiErrorKeys::default(),
|
||||
&mut LearnedInTab::default(),
|
||||
);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_NO_TEXT)
|
||||
);
|
||||
}
|
||||
|
||||
/// `SMSG_REMOVED_SPELL` takes the spell out (`0x5e43e3` → `0x5e9fe0` → `0x4b2c50`), closing the
|
||||
/// gap without reordering the rest (`0x4b2d74`-`0x4b2d8e`).
|
||||
#[test]
|
||||
fn an_unlearned_opener_leaves_the_rest_in_order() {
|
||||
let spells = spells();
|
||||
let mut actions = book(&[OPENING_2, OPENING_NO_TEXT, OPENING], &spells);
|
||||
removed_spell(
|
||||
OPENING_2,
|
||||
&mut actions,
|
||||
Some(&spells),
|
||||
&UiErrorKeys::default(),
|
||||
);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_NO_TEXT)
|
||||
);
|
||||
}
|
||||
|
||||
/// The registrar appends with no duplicate check (`0x4b2665`-`0x4b2689`) and the unlearn takes
|
||||
/// the last copy (`0x4b2d60`-`0x4b2d67`), so an opener learned twice keeps its first place.
|
||||
#[test]
|
||||
fn a_relearned_opener_is_listed_twice_and_an_unlearn_takes_the_last_copy() {
|
||||
let spells = spells();
|
||||
let mut actions = book(&[OPENING_NO_TEXT, OPENING], &spells);
|
||||
let errors = UiErrorKeys::default();
|
||||
learned_spell(
|
||||
OPENING_NO_TEXT,
|
||||
&mut actions,
|
||||
Some(&spells),
|
||||
&errors,
|
||||
&mut LearnedInTab::default(),
|
||||
);
|
||||
assert_eq!(actions.openers, [OPENING_NO_TEXT, OPENING, OPENING_NO_TEXT]);
|
||||
removed_spell(OPENING_NO_TEXT, &mut actions, Some(&spells), &errors);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_NO_TEXT)
|
||||
);
|
||||
}
|
||||
|
||||
/// The supersede unlists the old rank twice: in `0x4b2f50` (`0x4b2f5b`), then in the player's
|
||||
/// unlearn of it (`0x5e6392` → `0x5ea24c`), so an old rank listed twice leaves no copy.
|
||||
#[test]
|
||||
fn a_supersede_unlists_the_old_rank_twice() {
|
||||
let spells = spells();
|
||||
let mut actions = book(&[OPENING], &spells);
|
||||
let errors = UiErrorKeys::default();
|
||||
let mut tab = LearnedInTab::default();
|
||||
learned_spell(OPENING, &mut actions, Some(&spells), &errors, &mut tab);
|
||||
superceded_spell(
|
||||
OPENING,
|
||||
OPENING_2,
|
||||
&mut actions,
|
||||
Some(&spells),
|
||||
&errors,
|
||||
&mut tab,
|
||||
);
|
||||
assert_eq!(actions.openers, [OPENING_2]);
|
||||
assert_eq!(
|
||||
opens(&actions, &spells),
|
||||
LockOutcome::OpenBySpell(OPENING_2)
|
||||
);
|
||||
}
|
||||
@@ -4,11 +4,9 @@
|
||||
//! reaches them, so what they signal is queued in order on [`CastReports`] and signalled inside
|
||||
//! that call ([`crate::script_calls`]), or by the frame's feed for a packet's.
|
||||
|
||||
use std::time::Instant;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::inflight::{inflight, Inflight};
|
||||
use super::inflight::{inflight, inflight_item, Inflight};
|
||||
use super::{PendingCast, QueuedMeleeSpell, SpellTargeting};
|
||||
use crate::net::{ClientCommand, NetCommands};
|
||||
use crate::ui_action::CastFail;
|
||||
@@ -22,6 +20,9 @@ const ATTR_EX_NOT_REAPED: u32 = 0x4;
|
||||
/// `0x6e6f62`).
|
||||
pub(crate) const REASON_ERROR: u8 = 0x1c;
|
||||
|
||||
/// The reason the inventory refusal's cancel passes (`0x5e3aad`): `SPELL_FAILED_DONT_REPORT`.
|
||||
pub(crate) const REASON_DONT_REPORT: u8 = 0x17;
|
||||
|
||||
/// The failure the reporter fires no event for: `SPELL_FAILED_SPELL_IN_PROGRESS` (`0x6e2234`).
|
||||
const REASON_IN_PROGRESS: u8 = 0x61;
|
||||
|
||||
@@ -65,10 +66,15 @@ impl CastCore<'_> {
|
||||
inflight(self.pending, self.queued_melee, self.ground)
|
||||
}
|
||||
|
||||
/// The guid of the item the in-flight cast came from (`0x6e3d20` → `0xcecab0`).
|
||||
pub(crate) fn slot_item(&self) -> Option<u64> {
|
||||
inflight_item(self.pending, self.queued_melee, self.ground)
|
||||
}
|
||||
|
||||
/// `SetInFlightSpell(spell)` as the attempt calls it (`0x6e5026`): the same spell leaves the
|
||||
/// slot as it is, unsignalled (`0x6e4ad7`); another saves what the slot held (`0x6e4adf`, of
|
||||
/// which only a strike is kept), takes its place and signals (`0x6e4b13` → `0x4b3250`).
|
||||
pub(crate) fn push(&mut self, spell_id: u32, held: Held, now: Instant) {
|
||||
pub(crate) fn push(&mut self, spell_id: u32, held: Held) {
|
||||
let slot = self.slot();
|
||||
if slot.map(Inflight::spell_id) == Some(spell_id) {
|
||||
return;
|
||||
@@ -81,7 +87,7 @@ impl CastCore<'_> {
|
||||
Held::Strike => self.queued_melee.push(strike, Some(spell_id)),
|
||||
Held::Cast { item_flags, item } => {
|
||||
self.queued_melee.push(strike, None);
|
||||
self.pending.push_cast(spell_id, item_flags, item, now);
|
||||
self.pending.push_cast(spell_id, item_flags, item);
|
||||
}
|
||||
Held::Cursor => self.queued_melee.push(strike, None),
|
||||
}
|
||||
@@ -103,22 +109,6 @@ impl CastCore<'_> {
|
||||
self.reports.changed();
|
||||
}
|
||||
|
||||
/// A cast whose deadline passed with no result ([`PendingCast::lapsed`]) leaves the slot as
|
||||
/// its result's pop takes it (`0x6e4b2c`): the save copied back, a strike under it included,
|
||||
/// and signalled. The deadline is benilla's own net for a lost result, which the reference
|
||||
/// waits on.
|
||||
pub(crate) fn reap_lapsed(&mut self, now: Instant) {
|
||||
let Some(spell_id) = self.pending.lapsed(now) else {
|
||||
return;
|
||||
};
|
||||
let slot = self.slot();
|
||||
if slot == Some(Inflight::Cast(spell_id)) {
|
||||
self.pop(slot);
|
||||
} else {
|
||||
self.pending.clear_if(spell_id);
|
||||
}
|
||||
}
|
||||
|
||||
/// The send's pop of an auto-repeat spell once its packet is out (`0x6e597d`-`0x6e5989`): only
|
||||
/// while the slot holds it, so a ranged shot that is not auto-repeat (Aimed Shot, Arcane Shot,
|
||||
/// Throw) stays in flight until its result. The send's other pop (`0x6e58a2`-`0x6e58bd`) is for
|
||||
@@ -175,24 +165,34 @@ impl CastCore<'_> {
|
||||
(slot, caster)
|
||||
}
|
||||
|
||||
/// [`Self::cancel`], answering the spell its tail reaps on the player, for a caller that
|
||||
/// applies the reap itself (StartAttack's, `0x5ecc85`): the record's `[0xceac58]`
|
||||
/// (`0x6e4a8e`), whatever was popped, while the record's caster was the active player, and
|
||||
/// not for a record with `AttributesEx & 0x4` (`0x6e4aad`); a spell with no record is reaped
|
||||
/// (`0x6e4ab3`).
|
||||
/// [`Self::cancel`] with its tail's reap of the player's cast (`0x614150` at `0x6e4ab7`),
|
||||
/// queued on `edits` for `player`, the active player's object (`0x6e4a77`-`0x6e4a8c`): the
|
||||
/// record's spell `[0xceac58]` (`0x6e4a8e`), whatever was popped, while the record's caster
|
||||
/// was the active player (`0x6e4a11`), and not for a record with `AttributesEx & 0x4`
|
||||
/// (`0x6e4aad`); a spell with no record is reaped (`0x6e4ab3`). Every caller that tears its
|
||||
/// cast down locally takes this one tail: StartAttack's (`0x5ecc85`), the self cancel's and the
|
||||
/// inventory refusal's (`0x5e3ab3`).
|
||||
pub(crate) fn cancel_reaping(
|
||||
&mut self,
|
||||
failed: bool,
|
||||
send: bool,
|
||||
reason: u8,
|
||||
spells: Option<&crate::ui_action::Spells>,
|
||||
) -> Option<u32> {
|
||||
player: Option<Entity>,
|
||||
edits: &crate::creature_anim::UnitEdits,
|
||||
) -> Option<Inflight> {
|
||||
let record = self.pending.record_spell();
|
||||
let (_, caster) = self.cancel_for_caster(failed, send, reason);
|
||||
let (slot, caster) = self.cancel_for_caster(failed, send, reason);
|
||||
let kept = spells
|
||||
.and_then(|s| s.catalog.get(record))
|
||||
.is_some_and(|d| d.attributes_ex & ATTR_EX_NOT_REAPED != 0);
|
||||
(caster && !kept && record != 0).then_some(record)
|
||||
if let (true, Some(entity)) = (caster && !kept && record != 0, player) {
|
||||
edits.push(crate::creature_anim::UnitEdit::AbortCasting {
|
||||
entity,
|
||||
spell_id: record,
|
||||
});
|
||||
}
|
||||
slot
|
||||
}
|
||||
|
||||
/// The merge's range refusal re-arms the cursor as its attempt left it
|
||||
@@ -389,14 +389,12 @@ mod tests {
|
||||
let (net, _rx) = wire();
|
||||
let mut s = Slots::default();
|
||||
s.queued_melee.arm(HEROIC_STRIKE);
|
||||
let now = Instant::now();
|
||||
s.core(&net).push(
|
||||
FIREBALL,
|
||||
Held::Cast {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
now,
|
||||
);
|
||||
s.core(&net).push(
|
||||
FIREBALL,
|
||||
@@ -404,7 +402,6 @@ mod tests {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
now,
|
||||
);
|
||||
assert_eq!(s.core(&net).slot(), Some(Inflight::Cast(FIREBALL)));
|
||||
assert_eq!(s.queued_melee.saved(), Some(HEROIC_STRIKE));
|
||||
@@ -448,7 +445,6 @@ mod tests {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
Instant::now(),
|
||||
);
|
||||
s.stream();
|
||||
s.core(&net).cancel_queued();
|
||||
@@ -472,7 +468,6 @@ mod tests {
|
||||
item_flags: None,
|
||||
item: None,
|
||||
},
|
||||
Instant::now(),
|
||||
);
|
||||
s.core(&net).cancel(false, false, REASON_ERROR);
|
||||
s.stream();
|
||||
|
||||
@@ -511,7 +511,7 @@ impl Dispatch<'_, '_> {
|
||||
match resolve_go_action(
|
||||
guid,
|
||||
&mut self.go_inputs,
|
||||
&self.player_actions.spells,
|
||||
&self.player_actions.openers,
|
||||
go,
|
||||
self_store,
|
||||
&self.seam.net,
|
||||
@@ -1302,7 +1302,7 @@ enum KeyFact {
|
||||
pub(crate) fn resolve_go_action(
|
||||
guid: u64,
|
||||
inputs: &mut GoLockInputs,
|
||||
known: &std::collections::BTreeSet<u32>,
|
||||
openers: &[u32],
|
||||
go: Option<(&ObjectStore, u32)>,
|
||||
me_store: Option<&ObjectStore>,
|
||||
net: &NetCommands,
|
||||
@@ -1321,7 +1321,7 @@ pub(crate) fn resolve_go_action(
|
||||
let mut matched = None;
|
||||
let outcome = super::lock::resolve_lock(
|
||||
slots,
|
||||
known,
|
||||
openers,
|
||||
inputs.spells.as_deref(),
|
||||
inputs.skill_lines.as_ref().map(|s| &s.catalog),
|
||||
me_store,
|
||||
|
||||
@@ -688,7 +688,7 @@ pub(super) fn classify(
|
||||
.is_some_and(|slots| {
|
||||
super::lock::resolve_lock(
|
||||
slots,
|
||||
&player_actions.spells,
|
||||
&player_actions.openers,
|
||||
go_inputs.spells.as_deref(),
|
||||
go_inputs.skill_lines.as_ref().map(|s| &s.catalog),
|
||||
Some(self_store),
|
||||
|
||||
@@ -147,6 +147,40 @@ impl Fix {
|
||||
}
|
||||
}
|
||||
|
||||
/// `entity` held as a unit (`OBJECT_FIELD_TYPE` 0x9), alive, with `more` fields.
|
||||
pub(super) fn make_unit_with(&mut self, entity: Entity, more: &[(u16, u32)]) {
|
||||
let mut fields = vec![(2, 0x9), (22, 100), (28, 100)];
|
||||
fields.extend_from_slice(more);
|
||||
self.app.world_mut().entity_mut(entity).insert(ObjectStore(
|
||||
benilla_protocol::ObjectFields::from_pairs(&fields),
|
||||
));
|
||||
}
|
||||
|
||||
pub(super) fn make_unit(&mut self, entity: Entity) {
|
||||
self.make_unit_with(entity, &[]);
|
||||
}
|
||||
|
||||
/// `SMSG_SPELL_START` by `caster` aimed at us, as the spell handler hands it on.
|
||||
pub(super) fn cast_at_us(&mut self, caster: Entity) {
|
||||
self.app
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<crate::spell::net::CastAtPlayer>>()
|
||||
.write(crate::spell::net::CastAtPlayer { caster, seq: 0 });
|
||||
}
|
||||
|
||||
/// The frame's acquire over the swings and casts written since the last, which it consumes as
|
||||
/// the frame's reader does.
|
||||
pub(super) fn acquire(&mut self) {
|
||||
let world = self.app.world_mut();
|
||||
world
|
||||
.run_system_once(scan::auto_acquire)
|
||||
.expect("the acquire runs");
|
||||
world
|
||||
.resource_mut::<Messages<crate::spell::net::CastAtPlayer>>()
|
||||
.clear();
|
||||
world.resource_mut::<Messages<SwingMessage>>().clear();
|
||||
}
|
||||
|
||||
/// The target chain's bind of what the writers parked.
|
||||
pub(super) fn bind(&mut self) {
|
||||
self.app
|
||||
@@ -219,7 +253,7 @@ fn a_plate_click_with_the_cursor_up_binds_its_unit() {
|
||||
#[test]
|
||||
fn a_charmed_player_is_refused_by_every_selector() {
|
||||
type Run = fn(&mut Fix);
|
||||
let writers: [(&str, bool, Run, Option<u64>, bool); 6] = [
|
||||
let writers: [(&str, bool, Run, Option<u64>, bool); 7] = [
|
||||
(
|
||||
"a plate click",
|
||||
false,
|
||||
@@ -299,7 +333,23 @@ fn a_charmed_player_is_refused_by_every_selector() {
|
||||
});
|
||||
f.app
|
||||
.world_mut()
|
||||
.run_system_once(scan::auto_acquire_attacker)
|
||||
.run_system_once(scan::auto_acquire)
|
||||
.unwrap();
|
||||
},
|
||||
Some(MOB),
|
||||
false,
|
||||
),
|
||||
(
|
||||
"a caster at us acquired",
|
||||
false,
|
||||
|f| {
|
||||
*f.app.world_mut().resource_mut::<Selection>() = Selection::default();
|
||||
let mob = f.mob;
|
||||
f.make_unit(mob);
|
||||
f.cast_at_us(mob);
|
||||
f.app
|
||||
.world_mut()
|
||||
.run_system_once(scan::auto_acquire)
|
||||
.unwrap();
|
||||
},
|
||||
Some(MOB),
|
||||
@@ -327,7 +377,7 @@ fn a_charmed_player_is_refused_by_every_selector() {
|
||||
if cursor {
|
||||
f.cursor_up();
|
||||
}
|
||||
let before = if what == "an attacker acquired" {
|
||||
let before = if what == "an attacker acquired" || what == "a caster at us acquired" {
|
||||
None
|
||||
} else {
|
||||
Some(OLD)
|
||||
@@ -369,7 +419,7 @@ fn an_attacker_acquired_with_the_cursor_up_is_bound() {
|
||||
});
|
||||
f.app
|
||||
.world_mut()
|
||||
.run_system_once(scan::auto_acquire_attacker)
|
||||
.run_system_once(scan::auto_acquire)
|
||||
.expect("the acquire runs");
|
||||
f.bind();
|
||||
assert_eq!(f.wire(), (vec![Some(MOB)], vec![]));
|
||||
@@ -377,6 +427,62 @@ fn an_attacker_acquired_with_the_cursor_up_is_bound() {
|
||||
assert!(!f.cursor_is_up());
|
||||
}
|
||||
|
||||
/// Another unit casting at us is selected through `SelectTarget` (`0x6e799c`) when it cannot
|
||||
/// assist us (`CanAssist 0x6066f0` at `0x6e7973`) and nothing is selected (`[0xb4e2d8]`,
|
||||
/// `0x6e7980`); `PLAYER_TARGET_CHANGED` follows the selection. Our own pet, which can assist us,
|
||||
/// is not selected, nor is a caster the object manager does not hold as a unit, nor anyone while
|
||||
/// a target is held.
|
||||
#[test]
|
||||
fn a_caster_at_us_is_selected_when_it_cannot_assist_and_nothing_is() {
|
||||
const PET: u64 = 0x41;
|
||||
let mut f = fix(false);
|
||||
let mob = f.mob;
|
||||
f.make_unit(mob);
|
||||
f.cast_at_us(mob);
|
||||
f.acquire();
|
||||
assert_eq!(f.selected(), Some(OLD), "a target is held");
|
||||
assert_eq!(f.wire(), (vec![], vec![]));
|
||||
|
||||
*f.app.world_mut().resource_mut::<Selection>() = Selection::default();
|
||||
// `UNIT_FLAG_PLAYER_CONTROLLED` and `UNIT_FIELD_CREATEDBY` us: friendly, as the party rung
|
||||
// counts the active player (`0x6062b0`).
|
||||
let pet = f.scannable_at(PET, 5.0);
|
||||
f.make_unit_with(pet, &[(46, 0x8), (14, ME as u32), (15, 0)]);
|
||||
f.cast_at_us(pet);
|
||||
let old = f.app.world().resource::<GuidIndex>().0[&OLD];
|
||||
f.cast_at_us(old);
|
||||
f.acquire();
|
||||
assert_eq!(
|
||||
f.selected(),
|
||||
None,
|
||||
"the pet can assist us, and OLD is no unit"
|
||||
);
|
||||
assert_eq!(f.wire(), (vec![], vec![]));
|
||||
|
||||
f.cast_at_us(mob);
|
||||
f.acquire();
|
||||
assert_eq!(f.selected(), Some(MOB));
|
||||
assert_eq!(f.wire(), (vec![], vec![MOB]), "CMSG_SET_SELECTION");
|
||||
}
|
||||
|
||||
/// The caster's select is `SelectTarget` too, so a standing cursor binds it to the cast instead.
|
||||
#[test]
|
||||
fn a_caster_acquired_with_the_cursor_up_is_bound() {
|
||||
let mut f = fix(false);
|
||||
f.cursor_up();
|
||||
*f.app.world_mut().resource_mut::<Selection>() = Selection::default();
|
||||
let mob = f.mob;
|
||||
f.make_unit(mob);
|
||||
f.cast_at_us(mob);
|
||||
f.app
|
||||
.world_mut()
|
||||
.run_system_once(scan::auto_acquire)
|
||||
.expect("the acquire runs");
|
||||
f.bind();
|
||||
assert_eq!(f.wire(), (vec![Some(MOB)], vec![]));
|
||||
assert_eq!(f.selected(), None);
|
||||
}
|
||||
|
||||
/// 1.12.1 stores the cycle's index before `SelectTarget` (`0x4941d4`, `0x4941e6`), so a pick the
|
||||
/// cursor took, or refused, is behind the next press. Here the nearest enemy is inside the spell's
|
||||
/// minimum range, which the bind refuses with the cursor standing; the second press must go on
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
//! the player's skill in the spell's own line (`0x6e384d → 0x6e3130 → [vtbl+0xa8] = 0x5ea690`,
|
||||
//! [`crate::spell::spell_skill_value`]), not the character level.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use benilla_formats::{LockSlot, LOCK_KEY_ITEM, LOCK_KEY_SKILL};
|
||||
use bevy::prelude::*;
|
||||
|
||||
@@ -109,7 +107,7 @@ pub(crate) fn go_facts(go: Option<(&ObjectStore, u32)>) -> GoFacts {
|
||||
pub(crate) const GO_FLAG_LOCKED: u32 = 0x2;
|
||||
|
||||
/// The reference's lock resolver `0x5f83d0`. Walks the eight `Lock.dbc` slots in order:
|
||||
/// - SKILL (2): past the Action gate, scan the known spells for an `OPEN_LOCK` effect whose
|
||||
/// - SKILL (2): past the Action gate, scan the opener list for an `OPEN_LOCK` effect whose
|
||||
/// `EffectMiscValue` is the slot's `Index`; a match writes `matched` before the value test
|
||||
/// (`0x5f84f8`-`0x5f850d`), then its effect value is compared to the requirement (`0x5f850f`).
|
||||
/// - KEY (1): past the Action gate, look for the key item in our bags and keyring.
|
||||
@@ -122,13 +120,13 @@ pub(crate) const GO_FLAG_LOCKED: u32 = 0x2;
|
||||
///
|
||||
/// The first sufficient match is cast, so the scan order picks between two sufficient openers,
|
||||
/// such as 6478 "Opening" and 22810 "Opening - No Text" on LockType 13, which every character
|
||||
/// knows. `known` is a [`BTreeSet`], so ours scans in ascending spell id; the reference scans its
|
||||
/// opener list (`0xb700b0`) in the order `SMSG_INITIAL_SPELLS` listed them, later learns at the
|
||||
/// tail, and vmangos sends that packet in `std::unordered_map` order (`Player.cpp:3458`,
|
||||
/// `Player.h:113`).
|
||||
/// knows. `openers` is the opener list `0xb700b0` ([`crate::ui_action::PlayerActions::openers`]),
|
||||
/// scanned from the front (`0x5f845d`-`0x5f851f`): the order `SMSG_INITIAL_SPELLS` listed them,
|
||||
/// later learns at the tail. vmangos sends that packet in `std::unordered_map` order
|
||||
/// (`Player.cpp:3458`, `Player.h:113`), so which of the two is cast varies by character.
|
||||
pub(crate) fn resolve_lock(
|
||||
slots: &[LockSlot],
|
||||
known: &BTreeSet<u32>,
|
||||
openers: &[u32],
|
||||
spells: Option<&crate::ui_action::Spells>,
|
||||
skill_lines: Option<&benilla_formats::SkillLineCatalog>,
|
||||
me: Option<&ObjectStore>,
|
||||
@@ -145,7 +143,7 @@ pub(crate) fn resolve_lock(
|
||||
continue;
|
||||
}
|
||||
let Some(spells) = spells else { continue };
|
||||
for &id in known {
|
||||
for &id in openers {
|
||||
let Some(spell) = spells.catalog.get(id) else {
|
||||
continue;
|
||||
};
|
||||
@@ -355,7 +353,7 @@ mod tests {
|
||||
};
|
||||
// Spell → line: Mining is SkillLine 186.
|
||||
let lines = SkillLineCatalog::from_spell_lines([(2575, 186)]);
|
||||
let known = BTreeSet::from([2575]);
|
||||
let known = [2575];
|
||||
let mut objs = crate::ui_items::TestObjects::new();
|
||||
let objects = objs.get();
|
||||
// A 250-skill vein, available (Action 0, READY, not flagged).
|
||||
@@ -423,7 +421,7 @@ mod tests {
|
||||
let mut matched = None;
|
||||
let out = resolve_lock(
|
||||
&slots,
|
||||
&BTreeSet::new(),
|
||||
&[],
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
@@ -506,7 +504,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&scholomance,
|
||||
&BTreeSet::from([6247]),
|
||||
&[6247],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -526,7 +524,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&scholomance,
|
||||
&BTreeSet::from([6247]),
|
||||
&[6247],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -546,7 +544,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&scholomance,
|
||||
&BTreeSet::from([1804]),
|
||||
&[1804],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -578,7 +576,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&searing_gorge,
|
||||
&BTreeSet::from([6247]),
|
||||
&[6247],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -610,7 +608,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&vein,
|
||||
&BTreeSet::from([2575]),
|
||||
&[2575],
|
||||
Some(&with_mining),
|
||||
None,
|
||||
None,
|
||||
@@ -626,12 +624,12 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// Two sufficient openers on one LockType: the lower spell id wins, `known` being ordered.
|
||||
/// Lock 43 (a Hyacinth Mushroom's) has one SKILL slot, LockType 13 "Open Kneeling", Skill 0,
|
||||
/// Action 0, and `playercreateinfo_spell` grants both 6478 "Opening" and 22810 "Opening - No
|
||||
/// Text" to every race and class.
|
||||
/// Two sufficient openers on one LockType: the first in the opener list wins (`0x5f845d`),
|
||||
/// whatever its id. Lock 43 (a Hyacinth Mushroom's) has one SKILL slot, LockType 13 "Open
|
||||
/// Kneeling", Skill 0, Action 0, and `playercreateinfo_spell` grants both 6478 "Opening" and
|
||||
/// 22810 "Opening - No Text" to every race and class.
|
||||
#[test]
|
||||
fn two_sufficient_openers_pick_the_lower_spell_id() {
|
||||
fn two_sufficient_openers_pick_the_first_listed() {
|
||||
use benilla_formats::{OpenLock, SpellCatalog, SpellDisplay};
|
||||
|
||||
let mut mushroom = [LockSlot::default(); 8];
|
||||
@@ -668,7 +666,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&mushroom,
|
||||
&BTreeSet::from([6478, 22810]),
|
||||
&[6478, 22810],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -677,7 +675,6 @@ mod tests {
|
||||
&mut matched,
|
||||
),
|
||||
LockOutcome::OpenBySpell(6478),
|
||||
"6478 \"Opening\", never 22810 \"Opening - No Text\""
|
||||
);
|
||||
assert_eq!(
|
||||
matched.map(|m| m.spell),
|
||||
@@ -685,12 +682,12 @@ mod tests {
|
||||
"the toast's out-param agrees"
|
||||
);
|
||||
|
||||
// Insertion order cannot change it: the set is ordered.
|
||||
// The retail capture's order, 22810 ahead: the untitled bar's spell is cast.
|
||||
let mut matched = None;
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&mushroom,
|
||||
&BTreeSet::from([22810, 6478]),
|
||||
&[22810, 6478],
|
||||
Some(&spells),
|
||||
None,
|
||||
None,
|
||||
@@ -698,8 +695,9 @@ mod tests {
|
||||
unlocked,
|
||||
&mut matched,
|
||||
),
|
||||
LockOutcome::OpenBySpell(6478),
|
||||
LockOutcome::OpenBySpell(22810),
|
||||
);
|
||||
assert_eq!(matched.map(|m| m.spell), Some(22810));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -711,7 +709,7 @@ mod tests {
|
||||
assert_eq!(
|
||||
resolve_lock(
|
||||
&slots,
|
||||
&BTreeSet::new(),
|
||||
&[],
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
|
||||
@@ -383,7 +383,7 @@ impl Plugin for TargetPlugin {
|
||||
.after(crate::ui_follow::drain_follow),
|
||||
)
|
||||
.chain(),
|
||||
scan::auto_acquire_attacker,
|
||||
scan::auto_acquire,
|
||||
// The melee probe's press, the player's Attack; the TAB keys and ATTACKTARGET
|
||||
// run their bodies' `TargetNearestEnemy` and `AttackTarget` as script calls.
|
||||
crate::ui_action::attack_nearest_probe,
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
//!
|
||||
//! Kept from 1.12: the validity filters (`0x493e40`, `CanAttack 0x606980`, critters), the
|
||||
//! [`commit`] through `SetSelection` (`0x493540`), the attack acquire (`0x612df0` at `0x6130b5`),
|
||||
//! the ATTACKERSTATEUPDATE acquire (`0x6259c9`–`0x6259fe`) and the 41 yd range.
|
||||
//! the ATTACKERSTATEUPDATE and spell start acquires (`0x6259c9`–`0x6259fe`, `0x6e7963`-`0x6e799c`)
|
||||
//! and the 41 yd range.
|
||||
|
||||
use benilla_formats::CreatureTypeTable;
|
||||
use benilla_protocol::{guid, EntityKind};
|
||||
@@ -794,47 +795,82 @@ pub(super) fn remember_last_enemy(
|
||||
}
|
||||
}
|
||||
|
||||
/// The ATTACKERSTATEUPDATE self-defence acquire (`0x6259c9`–`0x6259fe`): when we are the victim
|
||||
/// and hold no selection, select the attacker, with no counter-attack.
|
||||
pub(super) fn auto_acquire_attacker(
|
||||
/// What asked [`auto_acquire`] for a unit.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
enum Acquire {
|
||||
/// A swing at us (`SMSG_ATTACKERSTATEUPDATE`).
|
||||
Attacker,
|
||||
/// A spell start aimed at us (`SMSG_SPELL_START`).
|
||||
Caster,
|
||||
}
|
||||
|
||||
/// The two packet acquires, in packet order by their [`crate::creature_anim::PlaySeq`] stamps:
|
||||
/// - the ATTACKERSTATEUPDATE self-defence acquire (`0x6259c9`–`0x6259fe`): when we are the victim
|
||||
/// and hold no selection, select the attacker, with no counter-attack;
|
||||
/// - the spell start's (`0x6e7963`-`0x6e799c`): another unit casting at us, which
|
||||
/// [`crate::spell::net::CastAtPlayer`] names, is selected when the active player's object is
|
||||
/// held (`0x6e796a`), the caster cannot assist it (`CanAssist 0x6066f0` at `0x6e7973`) and
|
||||
/// nothing is selected (`[0xb4e2d8]`, `0x6e7980`). The caster is looked up as a unit
|
||||
/// (`0x468460` with mask 8, `0x6e7892`).
|
||||
///
|
||||
/// Each is `SelectTarget` (`0x6259fe`, `0x6e799c`), whose front may bind the unit to a standing
|
||||
/// cursor's cast instead; a packet handler runs in no script, whose gate context passes tag 2.
|
||||
pub(super) fn auto_acquire(
|
||||
mut swings: MessageReader<SwingMessage>,
|
||||
mut casts: MessageReader<crate::spell::net::CastAtPlayer>,
|
||||
self_player: Query<(Entity, &Guid), With<SelfPlayer>>,
|
||||
guids: Query<&Guid>,
|
||||
// For `IsSelectable`: a `NOT_SELECTABLE` attacker is not acquired.
|
||||
stores: Query<&ObjectStore>,
|
||||
relations: RelationWorld,
|
||||
mut selection: ResMut<Selection>,
|
||||
mut seam: crate::creature_anim::AttackSeam,
|
||||
mut front: super::front::SelectFront,
|
||||
) {
|
||||
for s in swings.read() {
|
||||
if selection.target.is_some() {
|
||||
continue;
|
||||
}
|
||||
let Ok((me, my_guid)) = self_player.single() else {
|
||||
let Ok((me, my_guid)) = self_player.single() else {
|
||||
return;
|
||||
};
|
||||
let mut asks: Vec<(u64, Entity, Acquire)> = swings
|
||||
.read()
|
||||
.filter(|s| s.victim == Some(me))
|
||||
.map(|s| (s.seq, s.attacker, Acquire::Attacker))
|
||||
.chain(casts.read().map(|c| (c.seq, c.caster, Acquire::Caster)))
|
||||
.collect();
|
||||
asks.sort_by_key(|&(seq, ..)| seq);
|
||||
for (_, unit, why) in asks {
|
||||
let Ok(guid) = guids.get(unit) else {
|
||||
continue;
|
||||
};
|
||||
if s.victim != Some(me) {
|
||||
continue;
|
||||
let guid = guid.0;
|
||||
match why {
|
||||
Acquire::Attacker => {
|
||||
if selection.target.is_some() {
|
||||
continue;
|
||||
}
|
||||
debug!("auto-target: attacker {guid:#x} (victim = me, no target)");
|
||||
}
|
||||
Acquire::Caster => {
|
||||
let rel = relations.get();
|
||||
let assists = match (relations.unit(guid), relations.me()) {
|
||||
(Some(caster), Some(player)) => rel.can_assist(&caster, &player),
|
||||
_ => continue,
|
||||
};
|
||||
if assists || selection.guid.is_some() {
|
||||
continue;
|
||||
}
|
||||
debug!("auto-target: caster {guid:#x} (casting at me, no target)");
|
||||
}
|
||||
}
|
||||
let Ok(guid) = guids.get(s.attacker) else {
|
||||
continue;
|
||||
};
|
||||
debug!(
|
||||
"auto-target: attacker {:#x} (victim = me, no target)",
|
||||
guid.0
|
||||
);
|
||||
// `0x6259fe` is `SelectTarget`, whose front may bind the attacker to a standing cursor's
|
||||
// cast instead; the packet handler runs in no script, whose gate context passes tag 2.
|
||||
if front.takes(s.attacker, guid.0, seam.slots.targeting()) {
|
||||
if front.takes(unit, guid, seam.slots.targeting()) {
|
||||
continue;
|
||||
}
|
||||
// The selection was empty, so no switch law: selection only.
|
||||
commit(
|
||||
&mut selection,
|
||||
&mut seam,
|
||||
s.attacker,
|
||||
guid.0,
|
||||
stores.get(s.attacker).ok(),
|
||||
unit,
|
||||
guid,
|
||||
stores.get(unit).ok(),
|
||||
false,
|
||||
Some(my_guid.0),
|
||||
false,
|
||||
|
||||
@@ -75,10 +75,16 @@ pub(crate) const SPELL_ATTACK: u32 = 6603;
|
||||
pub(crate) struct PlayerActions {
|
||||
/// Wire slot (0-based) to its packed action; the Lua action id is slot + 1.
|
||||
pub buttons: HashMap<u8, ActionButton>,
|
||||
/// The spell book (`SMSG_INITIAL_SPELLS`), ordered on purpose: the reference's first-hit
|
||||
/// scans (the lock resolver `0x5f83d0`) pick between equal spells, 6478 and 22810 "Opening",
|
||||
/// by array order, which is ascending id: the server sends the book from a `std::map`.
|
||||
/// The known spells (`SMSG_INITIAL_SPELLS` and the learns since), the reference's known-spell
|
||||
/// bits `0xb710fc` (`0x4b2603`): a set, which keeps no learn order.
|
||||
pub spells: BTreeSet<u32>,
|
||||
/// `[0xb700b0]`: the known spells whose `Effect[0]` is `SPELL_EFFECT_OPEN_LOCK`, in learn
|
||||
/// order. The login list enters in wire order (`0x5dea8b`-`0x5deab9`), each learn appends at
|
||||
/// the tail with no duplicate check (`0x4b2665`-`0x4b2689`), and an unlearn removes the last
|
||||
/// copy and closes the gap (`0x4b2d60`-`0x4b2d87`). The lock resolver `0x5f83d0` and the
|
||||
/// item tooltip's lock walk `0x5da5e0` scan it from the front, so its order picks between
|
||||
/// 6478 "Opening" and 22810 "Opening - No Text", which open the same locks.
|
||||
pub openers: Vec<u32>,
|
||||
/// Set by every book or bar change, cleared once the feed re-resolves slot identity, which a
|
||||
/// landed item template ([`crate::items::Items::template_epoch`]) also triggers. Between
|
||||
/// resolves an item slot's count moves only by the item watchers' recount (`recount`).
|
||||
|
||||
@@ -93,6 +93,7 @@ mod tests {
|
||||
app.insert_resource(PlayerActions {
|
||||
buttons: buttons.iter().map(|b| (b.slot, *b)).collect(),
|
||||
spells: spells.iter().copied().collect(),
|
||||
openers: Vec::new(),
|
||||
dirty: true,
|
||||
})
|
||||
.insert_resource(SkillLines { catalog })
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
//! pushed whole once, and what the active player opens locks with, pushed on change. The walk and
|
||||
//! the colour are the engine's ([`benilla_ui::script::check_lock`]).
|
||||
|
||||
use std::collections::{BTreeSet, HashMap, HashSet};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
@@ -61,16 +61,16 @@ fn row_views(catalog: &LockCatalog) -> HashMap<u32, Vec<LockSlotView>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// What the player opens a lock with: each known spell with an open-lock effect, in the scan order
|
||||
/// of the known-spell list, with the skill it provides now (`0x6e3760`), and the item entries
|
||||
/// carried (`0x622270`, mode 0). `skill` is the player's skill in a spell's own line.
|
||||
/// What the player opens a lock with: each spell of the opener list `0xb700b0`, in the order the
|
||||
/// walk scans it (`0x5da644`-`0x5da712`), with the skill it provides now (`0x6e3760`), and the
|
||||
/// item entries carried (`0x622270`, mode 0). `skill` is the player's skill in a spell's own line.
|
||||
fn lock_openers(
|
||||
known: &BTreeSet<u32>,
|
||||
openers: &[u32],
|
||||
spells: Option<&SpellCatalog>,
|
||||
skill: &dyn Fn(u32) -> u32,
|
||||
held: HashSet<u32>,
|
||||
) -> LockOpeners {
|
||||
let opening = known.iter().filter_map(|&id| {
|
||||
let opening = openers.iter().filter_map(|&id| {
|
||||
let spell = spells?.get(id)?;
|
||||
Some(LockOpener {
|
||||
lock_type: spell.open_lock_type()?,
|
||||
@@ -129,7 +129,7 @@ pub(super) fn feed_lock_openers(
|
||||
.into_keys()
|
||||
.collect();
|
||||
let state = lock_openers(
|
||||
&actions.spells,
|
||||
&actions.openers,
|
||||
spells.as_deref().map(|s| &s.catalog),
|
||||
&|id| crate::spell::spell_skill_value(Some(store), skill_catalog, id),
|
||||
held,
|
||||
@@ -159,14 +159,23 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// The walk reads the opener list from the front (`0x5da644`-`0x5da712`), so the openers go
|
||||
/// in its order, not by spell id.
|
||||
#[test]
|
||||
fn the_openers_are_the_known_open_lock_spells_with_their_current_points() {
|
||||
fn the_openers_are_the_listed_open_lock_spells_in_order_with_their_current_points() {
|
||||
let herbs = SpellDisplay {
|
||||
open_lock: Some(OpenLock {
|
||||
effect: 0,
|
||||
lock_type: 2,
|
||||
}),
|
||||
..pick_lock()
|
||||
};
|
||||
let catalog = SpellCatalog::from_displays(HashMap::from([
|
||||
(1804, pick_lock()),
|
||||
(133, SpellDisplay::default()),
|
||||
(6477, pick_lock()),
|
||||
(6477, herbs),
|
||||
]));
|
||||
let known = BTreeSet::from([133, 1804, 6477, 9999]);
|
||||
let known = [6477, 133, 1804, 9999];
|
||||
let at =
|
||||
|skill: u32| lock_openers(&known, Some(&catalog), &|_| skill, HashSet::from([5060]));
|
||||
let openers = at(150);
|
||||
@@ -174,7 +183,7 @@ mod tests {
|
||||
openers.spells,
|
||||
[
|
||||
LockOpener {
|
||||
lock_type: 1,
|
||||
lock_type: 2,
|
||||
points: 150
|
||||
},
|
||||
LockOpener {
|
||||
@@ -182,7 +191,7 @@ mod tests {
|
||||
points: 150
|
||||
}
|
||||
],
|
||||
"ascending spell id, Fireball and the unknown id left out"
|
||||
"in list order, Fireball and the unknown id left out"
|
||||
);
|
||||
assert_eq!(openers.held, HashSet::from([5060]));
|
||||
// The value follows the skill, so a skill-up changes the state and re-pushes it.
|
||||
|
||||
@@ -450,7 +450,7 @@ fn drive_mouseover_tooltip(
|
||||
let outcome = slots.map(|slots| {
|
||||
crate::target::lock::resolve_lock(
|
||||
slots,
|
||||
&player_actions.spells,
|
||||
&player_actions.openers,
|
||||
go_inputs.spells.as_deref(),
|
||||
go_inputs.skill_lines.as_ref().map(|s| &s.catalog),
|
||||
self_store,
|
||||
|
||||
+9
-9
@@ -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:744`](../crates/benilla-app/src/creature_anim/driver.rs#L744))
|
||||
- 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:1063`](../crates/benilla-app/src/creature_anim/driver.rs#L1063))
|
||||
- A time-based rate, because the reference's per-frame step changes with the frame rate. ([`src/creature_anim/select.rs:134`](../crates/benilla-app/src/creature_anim/select.rs#L134))
|
||||
- A spell's state kit and body procs are reaped only once no slot holds the spell. ([`src/creature_anim/spell_visual.rs:1099`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1099))
|
||||
- A spell's state kit and body procs are reaped only once no slot holds the spell. ([`src/creature_anim/spell_visual.rs:1157`](../crates/benilla-app/src/creature_anim/spell_visual.rs#L1157))
|
||||
|
||||
#### cvars
|
||||
|
||||
@@ -263,10 +263,10 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
- The reference never steals. Every WoW voice is an `FSOUND_Stream` at priority 256 (`fmod.dll 0x1002be47`) and FMOD's steal scan skips `>= 256` (`0x100268e9`), so its 13th sound is dropped. ([`src/sound/kit.rs:259`](../crates/benilla-app/src/sound/kit.rs#L259))
|
||||
- The reference sums at full scale and clips (a close 1.0 kit reaches `FSOUND_SetVolume(255)` through `0x7a5dc0`, FMOD's MMX mixers saturate with `paddsw`, and no gain depends on the live voice count); this limits, because every WoW SFX is mastered to full scale, so overlapping kits clip into broadband distortion, as when a mass buff lands five sample-aligned copies of one 0 dBFS file. `SoundOutputLimiter 0` turns it off. ([`src/sound/limiter.rs:3`](../crates/benilla-app/src/sound/limiter.rs#L3))
|
||||
- The mantissa-bit volume curve (`0x7a5d70`, `(v·255+512.5).bits >> 14 & 0xff`) and the `__ftol` truncations are dropped, because they only quantized to FMOD's integer levels and our backend takes float amplitudes. ([`src/sound/math.rs:4`](../crates/benilla-app/src/sound/math.rs#L4))
|
||||
- The reference also refuses to open a new non-music stream while inactive (`0x7a52bf`); benilla starts everything and gates the output, because a refusal at kit start would make an unattended capture record silence. ([`src/sound/mod.rs:93`](../crates/benilla-app/src/sound/mod.rs#L93))
|
||||
- Default off where the reference registers "1". Its reverb is FMOD 3's EAX API, which renders only with hardware 3D mixing, so off is what the reference is heard to produce (inferred: `fmod.dll`'s render side is untraced). ([`src/sound/mod.rs:101`](../crates/benilla-app/src/sound/mod.rs#L101))
|
||||
- `SoundOutputLimiter`, not a 1.12 CVar, default on, so overlapping full-scale kits are limited rather than clipped. ([`src/sound/mod.rs:119`](../crates/benilla-app/src/sound/mod.rs#L119))
|
||||
- With no character the reference leaves the listener where it was; benilla seats it on the camera, where the view is. ([`src/sound/mod.rs:470`](../crates/benilla-app/src/sound/mod.rs#L470))
|
||||
- The reference also refuses to open a new non-music stream while inactive (`0x7a52bf`); benilla starts everything and gates the output, because a refusal at kit start would make an unattended capture record silence. ([`src/sound/mod.rs:95`](../crates/benilla-app/src/sound/mod.rs#L95))
|
||||
- Default off where the reference registers "1". Its reverb is FMOD 3's EAX API, which renders only with hardware 3D mixing, so off is what the reference is heard to produce (inferred: `fmod.dll`'s render side is untraced). ([`src/sound/mod.rs:103`](../crates/benilla-app/src/sound/mod.rs#L103))
|
||||
- `SoundOutputLimiter`, not a 1.12 CVar, default on, so overlapping full-scale kits are limited rather than clipped. ([`src/sound/mod.rs:121`](../crates/benilla-app/src/sound/mod.rs#L121))
|
||||
- With no character the reference leaves the listener where it was; benilla seats it on the camera, where the view is. ([`src/sound/mod.rs:472`](../crates/benilla-app/src/sound/mod.rs#L472))
|
||||
- The reference also plays an optimistic coin at the loot-money click, so looted money sounds twice; benilla plays the watcher's coin alone, because one coin on the confirmed change reads cleanly and the round trip the early coin hides is imperceptible on a local server. ([`src/sound/money.rs:7`](../crates/benilla-app/src/sound/money.rs#L7))
|
||||
- 1.12.1 sets FMOD up on driver 0 and, when that fails, runs silent for the session (`Sound::Initialize` `0x7a4330`, the driver −1 → 0 at `0x7a445f`); here another output stands in, because on Linux the default is often a stock `dmix` whose card a sound server holds. ([`src/sound/output/cpal.rs:193`](../crates/benilla-app/src/sound/output/cpal.rs#L193))
|
||||
- A change of the default output device is followed (here and in `coreaudio.rs`), where 1.12.1 initialises its sound device once and never again (`Sound::Initialize` `0x7a4330` refuses a second call; the driver-enumeration functions `0x7a6320`-`0x7a6380` have no caller), because a headset plugged in mid-session should play at once. ([`src/sound/output/cpal.rs:544`](../crates/benilla-app/src/sound/output/cpal.rs#L544))
|
||||
@@ -274,7 +274,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:132`](../crates/benilla-app/src/spell/mods.rs#L132))
|
||||
- The fallback is the packet's target guid, never the nearest-hostile acquire, because that would attack something the player never named. ([`src/spell/net.rs:1060`](../crates/benilla-app/src/spell/net.rs#L1060))
|
||||
- The fallback is the packet's target guid, never the nearest-hostile acquire, because that would attack something the player never named. ([`src/spell/net.rs:1189`](../crates/benilla-app/src/spell/net.rs#L1189))
|
||||
- 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:564`](../crates/benilla-app/src/spell/targeting/mod.rs#L564))
|
||||
|
||||
#### target
|
||||
@@ -283,9 +283,9 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
- It runs on the first frame with none, so an arrival that sends no stop (mid-air, rooted, under a held turn key) acts at once or on landing or release, where the reference waits for the next ground stop and can act long after, wherever the player then is. ([`src/target/click.rs:1211`](../crates/benilla-app/src/target/click.rs#L1211))
|
||||
- The rank is held to 7, the top of the ring scale's eight entries (`0..=7`), where the reference keeps any value; a server rank past 7 would index outside our palette. ([`src/target/relations.rs:491`](../crates/benilla-app/src/target/relations.rs#L491))
|
||||
- TAB uses Classic Era's screen-space priority, not 1.12's ±30° facing cone and snapshot cursor (`0x493f60`), because the cone skips a close mob in front of the camera, which sits behind the character. ([`src/target/scan.rs:3`](../crates/benilla-app/src/target/scan.rs#L3))
|
||||
- Our own body is never a candidate. The reference's friendly scan picks the player at some facings (`CanAssist(P, P)` is true, `0x6061e0`; the cone test `0x47f220`), but our scoring always puts the player dead centre at distance 0, so CTRL-TAB would pick us on every press. ([`src/target/scan.rs:193`](../crates/benilla-app/src/target/scan.rs#L193))
|
||||
- No scene-attach gate (the reference's `0x6704c0`), because the draw election hides every body outside the frustum, which would empty the off-screen tier. ([`src/target/scan.rs:367`](../crates/benilla-app/src/target/scan.rs#L367))
|
||||
- Sampled each frame, not stamped in `SetSelection`, so every selection writer is covered; a selected unit that turns hostile is remembered, where the reference's is not. ([`src/target/scan.rs:761`](../crates/benilla-app/src/target/scan.rs#L761))
|
||||
- Our own body is never a candidate. The reference's friendly scan picks the player at some facings (`CanAssist(P, P)` is true, `0x6061e0`; the cone test `0x47f220`), but our scoring always puts the player dead centre at distance 0, so CTRL-TAB would pick us on every press. ([`src/target/scan.rs:194`](../crates/benilla-app/src/target/scan.rs#L194))
|
||||
- No scene-attach gate (the reference's `0x6704c0`), because the draw election hides every body outside the frustum, which would empty the off-screen tier. ([`src/target/scan.rs:368`](../crates/benilla-app/src/target/scan.rs#L368))
|
||||
- Sampled each frame, not stamped in `SetSelection`, so every selection writer is covered; a selected unit that turns hostile is remembered, where the reference's is not. ([`src/target/scan.rs:762`](../crates/benilla-app/src/target/scan.rs#L762))
|
||||
|
||||
#### textinput
|
||||
|
||||
|
||||
Reference in New Issue
Block a user