b3fbaa86d4
Clicks and attack starts passed gates 1.12.1 refuses at: - A right press with a cursor payload went on to the world. - StartAttack ran without control or while pacified. - A charmed player's right-click selected and interacted. - Talk ignored shapeshift forms. - A plate right-click while targeting skipped the interact. - A `/target` miss said nothing. - `/follow` read the cast slot. Reference: `0x7662c0` runs the press pre-hook `0x492b50` before any hit-test, which drops a payload and consumes the press. StartAttack returns on `0x20000` or lost control (`0x5ecbaa`, `0x5ecbc0`) for every caller. The router tests `CHARMEDBY` first (`0x481f98`), which plates skip (`0x4949f0`). Talk tests form flag `0x8` (`0x5f0150`). `0x489dbd` picks the miss message, and `/follow` reads `UNIT_CHANNEL_SPELL` (`0x60ffb9`). Changed: each gate follows these, and tests pin each. Fixes #321 Fixes #381 Fixes #785 Fixes #1305 Fixes #1397 Fixes #52 Fixes #1326 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
586 lines
24 KiB
Rust
586 lines
24 KiB
Rust
//! The selection calls of the script call stream ([`crate::script_calls`]), each committed through
|
|
//! the one SetSelection path when its turn comes, so a later call in the same pass reads it.
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use benilla_ui::script::SelectionRequest;
|
|
|
|
use super::by_name::{self, ByNameScan, SelectCommit};
|
|
use super::scan;
|
|
|
|
/// Everything the selection calls read and write.
|
|
#[derive(bevy::ecs::system::SystemParam)]
|
|
pub(crate) struct ScriptSelect<'w, 's> {
|
|
/// The app's unit-token resolver. The VM's own reads the same grammar
|
|
/// ([`benilla_ui::script::parse_unit_token`]), so `TargetUnit("party1target")` and
|
|
/// `CheckInteractDistance("party1target", …)` name the same unit.
|
|
tokens: crate::ui_unit::UnitTokens<'w, 's>,
|
|
/// `TargetLastEnemy`'s memory (`[0xb4e2e8]`), stamped by `scan::remember_last_enemy`.
|
|
last_enemy: Res<'w, scan::LastEnemy>,
|
|
/// The SetSelection tail shared with the world click, `/target` and `/assist`, classification
|
|
/// included.
|
|
commit: SelectCommit<'w, 's>,
|
|
by_name: ByNameScan<'w, 's>,
|
|
/// Where a name that finds nobody shows its line.
|
|
errors: ResMut<'w, crate::ui_action::UiErrorKeys>,
|
|
/// The TAB cycler's inputs, for the `TargetNearest*` calls.
|
|
scan: scan::TargetScan<'w, 's>,
|
|
history: ResMut<'w, scan::TabHistory>,
|
|
time: Res<'w, Time>,
|
|
}
|
|
|
|
impl ScriptSelect<'_, '_> {
|
|
/// The guid selected now.
|
|
pub(crate) fn selected(&self) -> Option<u64> {
|
|
self.commit.selection.guid
|
|
}
|
|
|
|
/// `TargetUnit` (`0x4899d0`), `AssistUnit` (`0x489b80`) and `TargetLastEnemy` share the
|
|
/// reference's helper `0x489a40`: a resolved unit or a roster member is committed, anything
|
|
/// else is a no-op, never a deselect. Here a token must name a streamed unit, so an
|
|
/// out-of-range roster member is a no-op (the guid-only selection is not built).
|
|
pub(crate) fn select(&mut self, request: SelectionRequest) {
|
|
match request {
|
|
SelectionRequest::Unit(token) => {
|
|
if let Some((entity, guid)) = self.tokens.resolve(&token, &self.commit.selection) {
|
|
self.commit.commit(entity, guid);
|
|
}
|
|
}
|
|
// `0x489ba9 call 0x515940(token)`, then the shared tail. An unresolvable token is
|
|
// silent here; the reference shows message `0xb8` `ERR_GENERIC_NO_TARGET` (`0x489c0e`).
|
|
SelectionRequest::Assist(token) => {
|
|
match self.tokens.resolve(&token, &self.commit.selection) {
|
|
Some((basis, _)) => self.commit.assist(basis, "AssistUnit"),
|
|
None => info!("assist (AssistUnit): \"{token}\" names nothing; silent no-op"),
|
|
}
|
|
}
|
|
// `0x489c40`, `/assist <name>`: a player name, prefix-matched by the app's name scan.
|
|
SelectionRequest::AssistByName(name) => {
|
|
by_name::assist_named(&self.by_name, &mut self.commit, Some(&name), "AssistByName");
|
|
}
|
|
// `0x489b45` → `0x489a40`. Empty memory is a no-op (the shim `0x489b40` tests nothing),
|
|
// unlike `TargetLastTarget 0x489b00`, which reaches `0x493540(0,0)` and deselects.
|
|
SelectionRequest::LastEnemy => {
|
|
let Some(guid) = self.last_enemy.0 else {
|
|
info!("TargetLastEnemy: nothing hostile has been targeted yet; no-op");
|
|
return;
|
|
};
|
|
match self.tokens.held(guid) {
|
|
Some((entity, guid)) => self.commit.commit(entity, guid),
|
|
// Stale: a no-op, and the memory stays, as the reference never clears it.
|
|
None => info!(
|
|
"TargetLastEnemy: {guid:#x} is no longer streamed; target left untouched"
|
|
),
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/// `TargetByName(name, exactMatch)` (`0x489d60`), the stock `/target`.
|
|
pub(crate) fn target_by_name(&mut self, name: &str, exact: bool) {
|
|
by_name::target_named(
|
|
&self.by_name,
|
|
&mut self.commit,
|
|
&mut self.errors,
|
|
name,
|
|
exact,
|
|
);
|
|
}
|
|
|
|
/// `TargetNearest*([reverse])` (`0x489a80`/`0x489aa0`/`0x489ac0`/`0x489ae0` →
|
|
/// `0x493f60(reverse, mode)`), one cycle of the cycler the TAB key runs.
|
|
pub(crate) fn target_nearest(&mut self, mode: benilla_ui::script::NearestMode, reverse: bool) {
|
|
let engaged = self.commit.engaged();
|
|
scan::cycle(
|
|
scan::ScanSide::of(mode),
|
|
reverse,
|
|
self.time.elapsed_secs_f64(),
|
|
&self.scan,
|
|
&mut self.history,
|
|
&mut self.commit.selection,
|
|
&mut self.commit.seam,
|
|
&mut self.commit.front,
|
|
engaged,
|
|
);
|
|
}
|
|
|
|
/// `TargetLastTarget()` (`0x489b00`): a held last-target pair goes to `0x489a40` as a stack
|
|
/// copy, so a streamed unit is committed (which stamps the outgoing target, swapping the two)
|
|
/// and an unstreamed one is a no-op (the roster fallback is not built, as for
|
|
/// `TargetLastEnemy`); an empty pair deselects through `0x493540(0,0)` (`0x489b2d`).
|
|
pub(crate) fn target_last_target(&mut self) {
|
|
match self.commit.selection.last {
|
|
Some(guid) => match self.tokens.held(guid) {
|
|
Some((entity, guid)) => self.commit.commit(entity, guid),
|
|
None => info!("TargetLastTarget: {guid:#x} is no longer streamed; no-op"),
|
|
},
|
|
None => self.commit.clear(),
|
|
}
|
|
}
|
|
|
|
/// `ClearTarget()` (`0x489ff0`): deselect whatever the calls before it left selected.
|
|
pub(crate) fn clear_target(&mut self) {
|
|
self.commit.clear();
|
|
}
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use super::*;
|
|
|
|
/// A world holding what [`ScriptSelect`] reads, with a bare VM and no units.
|
|
fn script_world() -> World {
|
|
use crate::net::NetCommands;
|
|
use benilla_ui::script::UiScript;
|
|
|
|
let (tx, _rx) = crossbeam_channel::unbounded();
|
|
let mut world = World::new();
|
|
world.insert_resource(NetCommands(tx));
|
|
world.init_resource::<crate::spell::QueuedMeleeSpell>();
|
|
world.init_resource::<crate::spell::PendingCast>();
|
|
world.init_resource::<crate::ui_cast::CastReports>();
|
|
world.init_resource::<crate::ui_action::UiErrorKeys>();
|
|
world.init_resource::<crate::spell::AutoRepeatActive>();
|
|
world.init_resource::<crate::ui_loot::LootState>();
|
|
world.init_resource::<crate::ui_loot::LootLatch>();
|
|
world.init_resource::<Messages<crate::creature_anim::SheathRequest>>();
|
|
world.init_resource::<crate::ui_party::GroupState>();
|
|
world.init_resource::<crate::net::GuidIndex>();
|
|
world.init_resource::<crate::net::Reputations>();
|
|
world.init_resource::<super::super::AssistAttack>();
|
|
world.init_resource::<super::super::Selection>();
|
|
world.init_resource::<crate::spell::SpellTargeting>();
|
|
world.init_resource::<crate::spell::CursorPicks>();
|
|
world.init_resource::<scan::LastEnemy>();
|
|
world.init_resource::<crate::names::NameCache>();
|
|
world.init_resource::<scan::TabHistory>();
|
|
world.init_resource::<Time>();
|
|
world.insert_non_send_resource(UiScript::new().expect("a bare VM"));
|
|
world
|
|
}
|
|
|
|
/// The selection calls from Lua, through the binding bodies of ASSISTTARGET (`AssistUnit`) and
|
|
/// TARGETLASTHOSTILE (`TargetLastEnemy`): an empty basis, a garbage token and a stale memory
|
|
/// are each a no-op (`0x489a40`'s bare `ret`), never a deselect or a panic.
|
|
#[test]
|
|
fn the_selection_calls_run_assist_and_last_enemy_without_ever_deselecting() {
|
|
use crate::net::{Guid, ObjectStore, SelfPlayer};
|
|
use benilla_ui::script::UiScript;
|
|
use bevy::ecs::system::RunSystemOnce;
|
|
|
|
const ME: u64 = 1;
|
|
const BASIS: u64 = 0xB0A2;
|
|
const VICTIM: u64 = 0xC0DE;
|
|
const GONE: u64 = 0x6017;
|
|
// `UNIT_FIELD_TARGET` is a 2-field guid at index 16; HEALTH/MAXHEALTH keep the units live.
|
|
let store =
|
|
|pairs: &[(u16, u32)]| ObjectStore(benilla_protocol::ObjectFields::from_pairs(pairs));
|
|
|
|
let mut world = script_world();
|
|
|
|
world.spawn((SelfPlayer, Guid(ME), store(&[(22, 100), (28, 100)])));
|
|
// The basis is pointing at the victim; the victim points at nobody.
|
|
let basis = world
|
|
.spawn((
|
|
Guid(BASIS),
|
|
store(&[(22, 100), (28, 100), (16, VICTIM as u32)]),
|
|
))
|
|
.id();
|
|
let victim = world
|
|
.spawn((Guid(VICTIM), store(&[(22, 100), (28, 100)])))
|
|
.id();
|
|
let index = &mut world.resource_mut::<crate::net::GuidIndex>().0;
|
|
index.insert(BASIS, basis);
|
|
index.insert(VICTIM, victim);
|
|
|
|
let run = |world: &mut World, lua: &str| {
|
|
world
|
|
.non_send_resource_mut::<UiScript>()
|
|
.eval::<()>(lua)
|
|
.expect("the binding runs");
|
|
world
|
|
.run_system_once(
|
|
|mut script: NonSendMut<UiScript>, mut select: ScriptSelect| {
|
|
for request in script.take_selection_requests() {
|
|
select.select(request);
|
|
}
|
|
},
|
|
)
|
|
.expect("the applier runs as a one-shot system");
|
|
world.resource::<super::super::Selection>().guid
|
|
};
|
|
let set = |world: &mut World, target: Option<(Entity, u64)>| {
|
|
let mut sel = world.resource_mut::<super::super::Selection>();
|
|
sel.target = target.map(|(e, _)| e);
|
|
sel.guid = target.map(|(_, g)| g);
|
|
};
|
|
|
|
// Assist the current target: one hop onto its target.
|
|
set(&mut world, Some((basis, BASIS)));
|
|
assert_eq!(run(&mut world, r#"AssistUnit("target")"#), Some(VICTIM));
|
|
|
|
// The victim targets nobody: assisting it is a no-op, not a deselect.
|
|
assert_eq!(run(&mut world, r#"AssistUnit("target")"#), Some(VICTIM));
|
|
|
|
assert_eq!(run(&mut world, r#"AssistUnit("nosuchunit")"#), Some(VICTIM));
|
|
assert_eq!(run(&mut world, r#"TargetUnit("nosuchunit")"#), Some(VICTIM));
|
|
|
|
// TargetLastEnemy with nothing remembered: also a no-op.
|
|
assert_eq!(run(&mut world, "TargetLastEnemy()"), Some(VICTIM));
|
|
|
|
world.resource_mut::<scan::LastEnemy>().0 = Some(VICTIM);
|
|
set(&mut world, None);
|
|
assert_eq!(run(&mut world, "TargetLastEnemy()"), Some(VICTIM));
|
|
|
|
// A stale memory (the unit despawned, so its guid is in no index) leaves the target alone.
|
|
world.resource_mut::<scan::LastEnemy>().0 = Some(GONE);
|
|
assert_eq!(run(&mut world, "TargetLastEnemy()"), Some(VICTIM));
|
|
set(&mut world, None);
|
|
assert_eq!(run(&mut world, "TargetLastEnemy()"), None);
|
|
}
|
|
|
|
/// `TargetUnit("partypet1")`, the TARGETPARTYPET1 binding and the pet half of
|
|
/// TARGETPARTYMEMBER1, commits the pet the member's descriptor names (`0x515970` to `0x4e81d0`);
|
|
/// a slot with no member, or one whose pet is not held, is a no-op, never a deselect.
|
|
#[test]
|
|
fn target_unit_selects_a_party_pet() {
|
|
use crate::net::{Guid, ObjectStore, SelfPlayer};
|
|
use benilla_protocol::messages::{member_status, GroupMemberEntry};
|
|
use benilla_ui::script::UiScript;
|
|
use bevy::ecs::system::RunSystemOnce;
|
|
|
|
const ME: u64 = 1;
|
|
const MEMBER: u64 = 0x1234;
|
|
const PET: u64 = 0xF140_0000_0000_0077;
|
|
// HEALTH/MAXHEALTH keep the units live; `UNIT_FIELD_SUMMON` is the 2-field guid at 8.
|
|
let store =
|
|
|pairs: &[(u16, u32)]| ObjectStore(benilla_protocol::ObjectFields::from_pairs(pairs));
|
|
|
|
let mut world = script_world();
|
|
world.spawn((SelfPlayer, Guid(ME), store(&[(22, 100), (28, 100)])));
|
|
let pet = world
|
|
.spawn((Guid(PET), store(&[(22, 100), (28, 100)])))
|
|
.id();
|
|
let member = world
|
|
.spawn((
|
|
Guid(MEMBER),
|
|
store(&[
|
|
(22, 100),
|
|
(28, 100),
|
|
(8, PET as u32),
|
|
(9, (PET >> 32) as u32),
|
|
]),
|
|
))
|
|
.id();
|
|
let index = &mut world.resource_mut::<crate::net::GuidIndex>().0;
|
|
index.insert(PET, pet);
|
|
index.insert(MEMBER, member);
|
|
world
|
|
.resource_mut::<crate::ui_party::GroupState>()
|
|
.apply_list(
|
|
0,
|
|
0,
|
|
vec![GroupMemberEntry {
|
|
name: "Brisca".into(),
|
|
guid: MEMBER,
|
|
status: member_status::ONLINE,
|
|
flags: 0,
|
|
}],
|
|
ME,
|
|
None,
|
|
Some(ME),
|
|
);
|
|
|
|
let run = |world: &mut World, lua: &str| {
|
|
world
|
|
.non_send_resource_mut::<UiScript>()
|
|
.eval::<()>(lua)
|
|
.expect("the binding runs");
|
|
world
|
|
.run_system_once(
|
|
|mut script: NonSendMut<UiScript>, mut select: ScriptSelect| {
|
|
for request in script.take_selection_requests() {
|
|
select.select(request);
|
|
}
|
|
},
|
|
)
|
|
.expect("the applier runs as a one-shot system");
|
|
world.resource::<super::super::Selection>().guid
|
|
};
|
|
|
|
assert_eq!(run(&mut world, r#"TargetUnit("party1")"#), Some(MEMBER));
|
|
assert_eq!(run(&mut world, r#"TargetUnit("partypet1")"#), Some(PET));
|
|
assert_eq!(run(&mut world, r#"TargetUnit("PartyPet1")"#), Some(PET));
|
|
// No second member, and slot 0 and 5 are no slot: each leaves the selection alone.
|
|
for token in ["partypet2", "partypet0", "partypet5"] {
|
|
assert_eq!(
|
|
run(&mut world, &format!(r#"TargetUnit("{token}")"#)),
|
|
Some(PET),
|
|
"{token}"
|
|
);
|
|
}
|
|
// Out of view, the pet is named but not held: nothing to select, no deselect.
|
|
world.resource_mut::<crate::net::GuidIndex>().0.remove(&PET);
|
|
assert_eq!(run(&mut world, r#"TargetUnit("party1")"#), Some(MEMBER));
|
|
assert_eq!(run(&mut world, r#"TargetUnit("partypet1")"#), Some(MEMBER));
|
|
}
|
|
|
|
/// `TargetUnit` and `AssistUnit` take the tokens the reference's resolver takes (`0x515970`,
|
|
/// from `0x489a08` and `0x489ba9`): a base then a hop off each held unit's target, so
|
|
/// `party1target` names the unit party1 targets and `AssistUnit("party1target")` its target's.
|
|
/// A chain that breaks, and text that is not a hop, is a no-op, never a deselect.
|
|
#[test]
|
|
fn target_and_assist_unit_follow_a_target_chain() {
|
|
use crate::net::{Guid, ObjectStore, SelfPlayer};
|
|
use benilla_protocol::messages::{member_status, GroupMemberEntry};
|
|
use benilla_ui::script::UiScript;
|
|
use bevy::ecs::system::RunSystemOnce;
|
|
|
|
const ME: u64 = 1;
|
|
const MEMBER: u64 = 0x1234;
|
|
const PET: u64 = 0xF140_0000_0000_0077;
|
|
const VICTIM: u64 = 0xC0DE;
|
|
const THIRD: u64 = 0xF130_0000_0000_0003;
|
|
// `OBJECT_FIELD_TYPE` 2 (a hop is off a unit, typemask 8), `UNIT_FIELD_SUMMON` 8 and
|
|
// `UNIT_FIELD_TARGET` 16, the latter two each a 2-field guid.
|
|
let unit = |kind: u32, summon: u64, target: u64| {
|
|
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[
|
|
(2, kind),
|
|
(8, summon as u32),
|
|
(9, (summon >> 32) as u32),
|
|
(16, target as u32),
|
|
(17, (target >> 32) as u32),
|
|
]))
|
|
};
|
|
const PLAYER: u32 = 0x19;
|
|
const CREATURE: u32 = 0x09;
|
|
|
|
let mut world = script_world();
|
|
// We target the victim, party1 targets the victim, the victim targets `THIRD`, our pet
|
|
// targets `THIRD`; `THIRD` targets nobody.
|
|
world.spawn((SelfPlayer, Guid(ME), unit(PLAYER, PET, VICTIM)));
|
|
let member = world.spawn((Guid(MEMBER), unit(PLAYER, 0, VICTIM))).id();
|
|
let victim = world.spawn((Guid(VICTIM), unit(CREATURE, 0, THIRD))).id();
|
|
let third = world.spawn((Guid(THIRD), unit(CREATURE, 0, 0))).id();
|
|
let pet = world.spawn((Guid(PET), unit(CREATURE, 0, THIRD))).id();
|
|
let index = &mut world.resource_mut::<crate::net::GuidIndex>().0;
|
|
index.insert(MEMBER, member);
|
|
index.insert(VICTIM, victim);
|
|
index.insert(THIRD, third);
|
|
index.insert(PET, pet);
|
|
world
|
|
.resource_mut::<crate::ui_party::GroupState>()
|
|
.apply_list(
|
|
0,
|
|
0,
|
|
vec![GroupMemberEntry {
|
|
name: "Brisca".into(),
|
|
guid: MEMBER,
|
|
status: member_status::ONLINE,
|
|
flags: 0,
|
|
}],
|
|
ME,
|
|
None,
|
|
Some(ME),
|
|
);
|
|
let mut bar = crate::ui_pet::PetBar::default();
|
|
bar.spells.pet_guid = PET;
|
|
world.insert_resource(bar);
|
|
|
|
let run = |world: &mut World, lua: &str| {
|
|
world
|
|
.non_send_resource_mut::<UiScript>()
|
|
.eval::<()>(lua)
|
|
.expect("the binding runs");
|
|
world
|
|
.run_system_once(
|
|
|mut script: NonSendMut<UiScript>, mut select: ScriptSelect| {
|
|
for request in script.take_selection_requests() {
|
|
select.select(request);
|
|
}
|
|
},
|
|
)
|
|
.expect("the applier runs as a one-shot system");
|
|
world.resource::<super::super::Selection>().guid
|
|
};
|
|
let reset = |world: &mut World| {
|
|
let mut sel = world.resource_mut::<super::super::Selection>();
|
|
sel.target = None;
|
|
sel.guid = None;
|
|
};
|
|
|
|
assert_eq!(run(&mut world, r#"TargetUnit("party1")"#), Some(MEMBER));
|
|
assert_eq!(
|
|
run(&mut world, r#"TargetUnit("party1target")"#),
|
|
Some(VICTIM)
|
|
);
|
|
assert_eq!(
|
|
run(&mut world, r#"TargetUnit("party1targettarget")"#),
|
|
Some(THIRD)
|
|
);
|
|
// `THIRD` targets nobody: the chain ends there, and the selection stays.
|
|
for token in [
|
|
"party1targettargettarget",
|
|
"party1targetfoo",
|
|
"party1foo",
|
|
"party2target",
|
|
"npctarget",
|
|
] {
|
|
assert_eq!(
|
|
run(&mut world, &format!(r#"TargetUnit("{token}")"#)),
|
|
Some(THIRD),
|
|
"{token}"
|
|
);
|
|
}
|
|
|
|
reset(&mut world);
|
|
assert_eq!(
|
|
run(&mut world, r#"TargetUnit("PARTY1TARGET")"#),
|
|
Some(VICTIM)
|
|
);
|
|
reset(&mut world);
|
|
assert_eq!(
|
|
run(&mut world, r#"TargetUnit("playertarget")"#),
|
|
Some(VICTIM)
|
|
);
|
|
reset(&mut world);
|
|
assert_eq!(run(&mut world, r#"TargetUnit("pettarget")"#), Some(THIRD));
|
|
reset(&mut world);
|
|
assert_eq!(run(&mut world, r#"TargetUnit("partypet1target")"#), None);
|
|
|
|
// Assisting a unit selects its target; its target is a chain's end, so one hop further.
|
|
reset(&mut world);
|
|
assert_eq!(run(&mut world, r#"AssistUnit("party1")"#), Some(VICTIM));
|
|
reset(&mut world);
|
|
assert_eq!(
|
|
run(&mut world, r#"AssistUnit("party1target")"#),
|
|
Some(THIRD)
|
|
);
|
|
assert_eq!(
|
|
run(&mut world, r#"AssistUnit("party1targettarget")"#),
|
|
Some(THIRD),
|
|
"THIRD targets nobody: silent, nothing deselected"
|
|
);
|
|
}
|
|
|
|
/// `TargetUnit("npc")` and `AssistUnit("npc")` name the interaction NPC, `[0xb4e2d0]`, which
|
|
/// `0x515970` reads on a whole-token `npc` compare (`0x515bec`-`0x515c00`): the vendor whose
|
|
/// window is open, and for an assist the unit it targets. With no window open, or the NPC no
|
|
/// longer held, `npc` names nobody and the selection stays.
|
|
#[test]
|
|
fn target_and_assist_unit_name_the_interaction_npc() {
|
|
use crate::net::{Guid, ObjectStore, SelfPlayer};
|
|
use crate::ui_session::InteractNpc;
|
|
use benilla_ui::script::UiScript;
|
|
use bevy::ecs::system::RunSystemOnce;
|
|
|
|
const ME: u64 = 1;
|
|
const VENDOR: u64 = 0xF130_0000_9800_0001;
|
|
const GUARD: u64 = 0xF130_0000_0000_0002;
|
|
// `OBJECT_FIELD_TYPE` 2 and `UNIT_FIELD_TARGET` 16, a 2-field guid.
|
|
let unit = |target: u64| {
|
|
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[
|
|
(2, 0x09),
|
|
(16, target as u32),
|
|
(17, (target >> 32) as u32),
|
|
]))
|
|
};
|
|
|
|
let mut world = script_world();
|
|
world.spawn((SelfPlayer, Guid(ME), unit(0)));
|
|
let vendor = world.spawn((Guid(VENDOR), unit(GUARD))).id();
|
|
let guard = world.spawn((Guid(GUARD), unit(0))).id();
|
|
let index = &mut world.resource_mut::<crate::net::GuidIndex>().0;
|
|
index.insert(VENDOR, vendor);
|
|
index.insert(GUARD, guard);
|
|
world.insert_resource(InteractNpc(Some(vendor), Some(VENDOR)));
|
|
|
|
let run = |world: &mut World, lua: &str| {
|
|
world
|
|
.non_send_resource_mut::<UiScript>()
|
|
.eval::<()>(lua)
|
|
.expect("the binding runs");
|
|
world
|
|
.run_system_once(
|
|
|mut script: NonSendMut<UiScript>, mut select: ScriptSelect| {
|
|
for request in script.take_selection_requests() {
|
|
select.select(request);
|
|
}
|
|
},
|
|
)
|
|
.expect("the applier runs as a one-shot system");
|
|
world.resource::<super::super::Selection>().guid
|
|
};
|
|
let reset = |world: &mut World| {
|
|
let mut sel = world.resource_mut::<super::super::Selection>();
|
|
sel.target = None;
|
|
sel.guid = None;
|
|
};
|
|
|
|
assert_eq!(run(&mut world, r#"TargetUnit("npc")"#), Some(VENDOR));
|
|
reset(&mut world);
|
|
assert_eq!(run(&mut world, r#"TargetUnit("NPC")"#), Some(VENDOR));
|
|
reset(&mut world);
|
|
assert_eq!(run(&mut world, r#"AssistUnit("npc")"#), Some(GUARD));
|
|
|
|
// The NPC streamed out with its window still up: the object manager holds no unit.
|
|
world
|
|
.resource_mut::<crate::net::GuidIndex>()
|
|
.0
|
|
.remove(&VENDOR);
|
|
assert_eq!(run(&mut world, r#"TargetUnit("npc")"#), Some(GUARD));
|
|
|
|
// The window closed: nobody, and the selection stays.
|
|
world
|
|
.resource_mut::<crate::net::GuidIndex>()
|
|
.0
|
|
.insert(VENDOR, vendor);
|
|
world.insert_resource(InteractNpc::default());
|
|
assert_eq!(run(&mut world, r#"TargetUnit("npc")"#), Some(GUARD));
|
|
}
|
|
|
|
/// The path a player takes: `/script TargetUnit("npc")` typed into the stock chat box runs
|
|
/// `SlashCmdList["SCRIPT"]` (`ChatFrame.lua:1074-1075`) and selects the vendor whose window is
|
|
/// open.
|
|
#[test]
|
|
fn typing_target_unit_npc_in_the_stock_chat_box_selects_the_vendor() {
|
|
benilla_formats::wow_data_or_skip!();
|
|
use crate::net::{Guid, ObjectStore, SelfPlayer};
|
|
use crate::ui_session::InteractNpc;
|
|
use benilla_ui::script::UiScript;
|
|
use bevy::ecs::system::RunSystemOnce;
|
|
|
|
const ME: u64 = 1;
|
|
const VENDOR: u64 = 0xF130_0000_9800_0001;
|
|
let unit = || ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(2, 0x09)]));
|
|
|
|
let mut world = script_world();
|
|
world.insert_non_send_resource(crate::ui_script::chat_tests::chat_frame());
|
|
world.spawn((SelfPlayer, Guid(ME), unit()));
|
|
let vendor = world.spawn((Guid(VENDOR), unit())).id();
|
|
world
|
|
.resource_mut::<crate::net::GuidIndex>()
|
|
.0
|
|
.insert(VENDOR, vendor);
|
|
world.insert_resource(InteractNpc(Some(vendor), Some(VENDOR)));
|
|
|
|
let mut script = world.non_send_resource_mut::<UiScript>();
|
|
assert!(script.focus_editbox("ChatFrameEditBox"));
|
|
script.char_input(r#"/script TargetUnit("npc")"#);
|
|
assert!(script.key_input("ENTER"), "the box consumes ENTER");
|
|
world
|
|
.run_system_once(
|
|
|mut script: NonSendMut<UiScript>, mut select: ScriptSelect| {
|
|
for request in script.take_selection_requests() {
|
|
select.select(request);
|
|
}
|
|
},
|
|
)
|
|
.expect("the applier runs as a one-shot system");
|
|
assert_eq!(
|
|
world.resource::<super::super::Selection>().guid,
|
|
Some(VENDOR)
|
|
);
|
|
}
|
|
}
|