Combat text raises 1.12.1's words, SPELL_ACTIVE and swing actions (#2081)
Combat text missed most of the words 1.12.1 raises. A damage shield, an interrupt, extra attacks, a resisted proc, an immunity, a dispel, an aura, environmental damage, a drain and a reputation change about you wrote their log line but no `COMBAT_TEXT_UPDATE`. `SPELL_ACTIVE` never fired, and a swing's `UNIT_COMBAT` skipped the victim-state table. Reference: each formatter raises its word at its own unit test after the line (`0x62cb5d`, `0x626b53`, `0x62db7d`, `0x628b8a`, `0x62d3ab`, `0x628daa`, `0x62d5ce`, `0x62b74f`, `0x62ac74`, `0x627b94`, `0x62c661`). The usable refresh walks the reactive list `[0xb71150]` (`0x4b31c0`). A swing's action comes from `0x83de28`, environmental damage sends a WOUND (`0x624f83`), and the float resolves its global (`0x703bf0`). Each word rides the existing line path. The reactive list lives from arrival to arrival. Tests pin each word and gate. Fixes #2027 Fixes #2028 Fixes #2029 Fixes #2030 Fixes #81 Fixes #82 Fixes #370 Fixes #2032 Fixes #2040 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -151,8 +151,9 @@ pub(super) fn attacker_state(
|
||||
/// the packet's `victim`, who wears the shield; `attacker` struck it and takes the damage
|
||||
/// (`DAMAGESHIELDSELFOTHER` is "You reflect %d %s damage to %s."). The chat type is a two-way on
|
||||
/// the bearer: `0x62c140` returns `0x3f` `SPELL_DAMAGESHIELDS_ON_SELF` for class 0 or 1, else
|
||||
/// `0x40` `…ON_OTHERS`. After the line (`0x5e8552`), `UNIT_COMBAT` `WOUND` on the attacker, with
|
||||
/// no flags and no gate (`0x5e858c`).
|
||||
/// `0x40` `…ON_OTHERS`. The line (`0x62ca20`, from `0x5e8552`) is worded `DAMAGE_SHIELD` with the
|
||||
/// damage when the struck unit is you (`0x62cb5d`-`0x62cb6b`), and written for no damage not at all
|
||||
/// (`0x62ca50`). Then `UNIT_COMBAT` `WOUND` on the attacker, with no flags and no gate (`0x5e858c`).
|
||||
pub(super) fn damage_shield(
|
||||
s: DamageShield,
|
||||
ctx: &ChatCtx,
|
||||
@@ -160,24 +161,27 @@ pub(super) fn damage_shield(
|
||||
poses: &impl Poses,
|
||||
log: &mut ChatLog,
|
||||
) {
|
||||
let bearer = ctx.classify(s.victim, stores);
|
||||
let struck = ctx.classify(s.attacker, stores);
|
||||
let kind = combat::damage_shield_kind(bearer);
|
||||
let fills = Fills {
|
||||
school: u8::try_from(s.school).ok(),
|
||||
amount: i64::from(s.damage),
|
||||
..Default::default()
|
||||
};
|
||||
queue(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
kind,
|
||||
combat::DAMAGESHIELD,
|
||||
(s.victim, bearer),
|
||||
(s.attacker, struck),
|
||||
fills,
|
||||
);
|
||||
if s.damage != 0 {
|
||||
let bearer = ctx.classify(s.victim, stores);
|
||||
let struck = ctx.classify(s.attacker, stores);
|
||||
let kind = combat::damage_shield_kind(bearer);
|
||||
let fills = Fills {
|
||||
school: u8::try_from(s.school).ok(),
|
||||
amount: i64::from(s.damage),
|
||||
..Default::default()
|
||||
};
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
kind,
|
||||
combat::DAMAGESHIELD,
|
||||
(s.victim, bearer),
|
||||
(s.attacker, struck),
|
||||
fills,
|
||||
to_me(struck, LineWord::with("DAMAGE_SHIELD", s.damage)),
|
||||
);
|
||||
}
|
||||
super::feedback::wound(log, s.attacker, s.damage, 0, s.school);
|
||||
}
|
||||
|
||||
@@ -242,7 +246,9 @@ pub(super) fn spell_insta_kill_log(
|
||||
}
|
||||
|
||||
/// `SMSG_PROCRESIST` ("%s resists %s's %s.") and `SMSG_SPELLORDAMAGE_IMMUNE` ("%s is immune to
|
||||
/// %s's %s."), both worded target first and typed off the (caster, target) pair.
|
||||
/// %s's %s."), both worded target first and typed off the (caster, target) pair. When the target,
|
||||
/// the second unit, is you, each line raises its word with the spell's name: `PROC_RESISTED`
|
||||
/// (`0x628b8a`-`0x628b96`) or `SPELL_IMMUNE` (`0x62d3ab`-`0x62d3b9`).
|
||||
///
|
||||
/// `IMMUNESPELL`'s `log_format` byte is the periodic flag: `0x62d25f` in `0x62d240` gates that
|
||||
/// formatter alone on `CombatLogPeriodicSpells` when the byte is set; `PROCRESIST` is ungated.
|
||||
@@ -269,28 +275,32 @@ pub(super) fn spell_outcome_log(
|
||||
let Some(kind) = combat::spell_kind(caster, target, buff) else {
|
||||
return;
|
||||
};
|
||||
queue(
|
||||
let (family, word) = if immune {
|
||||
(combat::IMMUNESPELL, "SPELL_IMMUNE")
|
||||
} else {
|
||||
(combat::PROCRESIST, "PROC_RESISTED")
|
||||
};
|
||||
let word = to_me(target, LineWord::with(word, &spell));
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
kind,
|
||||
if immune {
|
||||
combat::IMMUNESPELL
|
||||
} else {
|
||||
combat::PROCRESIST
|
||||
},
|
||||
family,
|
||||
(s.caster, caster),
|
||||
(s.target, target),
|
||||
Fills {
|
||||
spell,
|
||||
..Default::default()
|
||||
},
|
||||
word,
|
||||
);
|
||||
}
|
||||
|
||||
/// `SMSG_SPELLDISPELLOG`: "Your %s is removed." or "%s's %s is removed.", one line per aura. The
|
||||
/// chat type is the literal `0x45` `SPELL_BREAK_AURA` (`0x62d480`); the dispeller is classified
|
||||
/// only for the range gate.
|
||||
/// only for the range gate. An `AURADISPELSELF` line raises `SPELL_DISPELLED` with the spell's name
|
||||
/// (`0x62d5ce`-`0x62d5e8`).
|
||||
pub(super) fn spell_dispel_log(
|
||||
s: &SpellDispelLog,
|
||||
ctx: &ChatCtx,
|
||||
@@ -304,7 +314,8 @@ pub(super) fn spell_dispel_log(
|
||||
let Some(spell) = ctx.spell_name(spell_id) else {
|
||||
continue;
|
||||
};
|
||||
queue(
|
||||
let word = to_me(bearer, LineWord::with("SPELL_DISPELLED", &spell));
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
@@ -316,12 +327,15 @@ pub(super) fn spell_dispel_log(
|
||||
spell,
|
||||
..Default::default()
|
||||
},
|
||||
word,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// `SMSG_DISPEL_FAILED`: "You fail to dispel %s's %s.", one line per aura. The format variant is
|
||||
/// picked once per packet (`0x628c20`); the chat type per line, since `0x627d30` asks the spell.
|
||||
/// When the second unit is you, each line raises `DISPEL_FAILED` with its spell's name
|
||||
/// (`0x628daa`-`0x628db8`).
|
||||
pub(super) fn dispel_failed(
|
||||
s: &DispelFailed,
|
||||
ctx: &ChatCtx,
|
||||
@@ -339,7 +353,8 @@ pub(super) fn dispel_failed(
|
||||
let Some(kind) = combat::spell_kind(caster, victim, !ctx.spell_harmful(spell_id)) else {
|
||||
continue;
|
||||
};
|
||||
queue(
|
||||
let word = to_me(victim, LineWord::with("DISPEL_FAILED", &spell));
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
@@ -351,6 +366,7 @@ pub(super) fn dispel_failed(
|
||||
spell,
|
||||
..Default::default()
|
||||
},
|
||||
word,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -489,14 +505,18 @@ pub(super) fn spell_log_execute(
|
||||
);
|
||||
}
|
||||
// Effect 19 ADD_EXTRA_ATTACKS: no caster in the sentence (`0x62d9f0`), only the
|
||||
// unit that gained the attacks.
|
||||
// unit that gained the attacks, worded `EXTRA_ATTACKS` with the count when that is
|
||||
// you (`0x62db7d`-`0x62dba9`); a count of 0 writes neither (`0x62da2a`).
|
||||
E::ExtraAttacks { target, count } => {
|
||||
if count == 0 {
|
||||
continue;
|
||||
}
|
||||
let Some(spell) = spell() else { continue };
|
||||
let victim = ctx.classify(target, stores);
|
||||
let Some(kind) = combat::spell_kind(victim, victim, false) else {
|
||||
continue;
|
||||
};
|
||||
queue(
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
@@ -513,6 +533,7 @@ pub(super) fn spell_log_execute(
|
||||
amount: i64::from(count),
|
||||
..Default::default()
|
||||
},
|
||||
to_me(victim, LineWord::with("EXTRA_ATTACKS", count)),
|
||||
);
|
||||
}
|
||||
// Effect 24 CREATE_ITEM: the tradeskill line, literal type `0x3e`, split on the
|
||||
@@ -541,7 +562,8 @@ pub(super) fn spell_log_execute(
|
||||
combat::Named::Item(item_entry),
|
||||
),
|
||||
// Effect 68 INTERRUPT_CAST: the sentence names the interrupted spell, off the row,
|
||||
// not the packet's own.
|
||||
// not the packet's own, and so does the `INTERRUPT` word when the interrupted unit
|
||||
// is you (`0x626b53`-`0x626b69`).
|
||||
E::InterruptCast { target, spell_id } => {
|
||||
let victim = ctx.classify(target, stores);
|
||||
let Some(interrupted) = ctx.spell_name(spell_id) else {
|
||||
@@ -550,7 +572,8 @@ pub(super) fn spell_log_execute(
|
||||
let Some(kind) = combat::spell_kind(caster, victim, false) else {
|
||||
continue;
|
||||
};
|
||||
queue(
|
||||
let word = to_me(victim, LineWord::with("INTERRUPT", &interrupted));
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
@@ -562,6 +585,7 @@ pub(super) fn spell_log_execute(
|
||||
spell: interrupted,
|
||||
..Default::default()
|
||||
},
|
||||
word,
|
||||
);
|
||||
}
|
||||
// Effect 111 DURABILITY_DAMAGE: both fields `-1` is the "all items" form.
|
||||
@@ -755,11 +779,14 @@ fn spell_cast_line(
|
||||
}
|
||||
}
|
||||
|
||||
/// `SMSG_ENVIRONMENTALDAMAGELOG`: "You fall and lose %d health." and its five siblings.
|
||||
/// `0x62aac0` builds the key from a six-entry damage-type table and SELF/OTHER, and calls the
|
||||
/// melee HITS selector with the victim's class in both positions, so a party member's fall types
|
||||
/// as `HOSTILEPLAYER_HITS` through the selector's tgt<=3 override, as in the reference. It takes
|
||||
/// absorb and resist trailers.
|
||||
/// `SMSG_ENVIRONMENTALDAMAGELOG`'s handler `0x624f30`, which writes and signals nothing for a hit
|
||||
/// of all zeros (`0x624f4c`-`0x624f60`). The line, "You fall and lose %d health." and its five
|
||||
/// siblings: `0x62aac0` builds the key from a six-entry damage-type table and SELF/OTHER, and calls
|
||||
/// the melee HITS selector with the victim's class in both positions, so a party member's fall
|
||||
/// types as `HOSTILEPLAYER_HITS` through the selector's tgt<=3 override, as in the reference. It
|
||||
/// takes absorb and resist trailers, and on you raises [`combat::damage_word`] (`0x62ac74`). Then,
|
||||
/// for the active player (`0x624f83`), `UNIT_COMBAT` `WOUND` in the type's school, marked `0x20`
|
||||
/// for an absorb and `0x40` for a resist (`0x624f8c`-`0x624fc4`).
|
||||
pub(super) fn environmental_damage_log(
|
||||
e: EnvironmentalDamageLog,
|
||||
ctx: &ChatCtx,
|
||||
@@ -767,42 +794,56 @@ pub(super) fn environmental_damage_log(
|
||||
poses: &impl Poses,
|
||||
log: &mut ChatLog,
|
||||
) {
|
||||
if e.damage == 0 && e.absorb == 0 && e.resist == 0 {
|
||||
return;
|
||||
}
|
||||
let victim = ctx.classify(e.victim, stores);
|
||||
let Some(family) = combat::env_family(e.damage_type) else {
|
||||
return;
|
||||
};
|
||||
let Some(kind) = combat::combat_kind(victim, victim, false) else {
|
||||
return;
|
||||
};
|
||||
queue(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
kind,
|
||||
family,
|
||||
(e.victim, victim),
|
||||
(e.victim, victim),
|
||||
Fills {
|
||||
amount: i64::from(e.damage),
|
||||
trailers: Some(combat::Trailers {
|
||||
absorbed: e.absorb,
|
||||
resisted: e.resist,
|
||||
// The environmental call site passes zero for both.
|
||||
blocked: 0,
|
||||
hit_info: 0,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
);
|
||||
let kind = combat::combat_kind(victim, victim, false);
|
||||
if let (Some(family), Some(kind)) = (combat::env_family(e.damage_type), kind) {
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
kind,
|
||||
family,
|
||||
(e.victim, victim),
|
||||
(e.victim, victim),
|
||||
Fills {
|
||||
amount: i64::from(e.damage),
|
||||
trailers: Some(combat::Trailers {
|
||||
absorbed: e.absorb,
|
||||
resisted: e.resist,
|
||||
// The environmental call site passes zero for both.
|
||||
blocked: 0,
|
||||
hit_info: 0,
|
||||
}),
|
||||
..Default::default()
|
||||
},
|
||||
to_me(victim, combat::damage_word(e.damage, e.absorb, e.resist)),
|
||||
);
|
||||
}
|
||||
let school = ENV_DAMAGE_SCHOOLS.get(usize::from(e.damage_type));
|
||||
if let (Some(&school), true) = (school, ctx.self_guid.0 == Some(e.victim)) {
|
||||
let marks = super::feedback::hit_flags(false, e.absorb, e.resist, 0);
|
||||
super::feedback::wound(log, e.victim, e.damage, marks, school);
|
||||
}
|
||||
}
|
||||
|
||||
/// The school of each environmental damage type 0 to 5, the table `0x809274` that `0x624fb3`
|
||||
/// indexes: fatigue, drowning and falling physical, lava and fire fire, slime nature. The index has
|
||||
/// no bound; a type past it, which no server sends (vmangos maps its void fall to 2,
|
||||
/// `Objects/Unit.cpp:5396`), signals nothing here.
|
||||
const ENV_DAMAGE_SCHOOLS: [u32; 6] = [0, 0, 0, 2, 3, 2];
|
||||
|
||||
/// `SMSG_SET_FACTION_STANDING`: "Your %s reputation has increased by %d.". The wire carries the
|
||||
/// new total and the sentence the delta, so this runs before the store is overwritten, and an
|
||||
/// unchanged value prints nothing (`0x4d6344`). Only the packet's first entry prints, and only if
|
||||
/// its faction is not `HIDDEN`: the handler passes `0x4d6330` its print argument as
|
||||
/// `index == 0 && !(flags & 4)` (`0x4d57dd`-`0x4d57ea`), so the spill-over entries of one kill
|
||||
/// update silently. No range gate or classifier: the chat type is the literal `0x55`
|
||||
/// `COMBAT_FACTION_CHANGE`. The wire's list id is `Faction.dbc`'s `rep_index`.
|
||||
/// `COMBAT_FACTION_CHANGE`. The wire's list id is `Faction.dbc`'s `rep_index`. The line
|
||||
/// (`0x62c5f0`) raises `FACTION` with the faction's name and the signed change, whoever's line it
|
||||
/// is (`0x62c661`-`0x62c667`).
|
||||
pub(crate) fn faction_standing(
|
||||
deltas: &[(u32, i32)],
|
||||
reputations: &Reputations,
|
||||
@@ -853,7 +894,7 @@ pub(crate) fn faction_standing(
|
||||
},
|
||||
named: combat::Named::Ready,
|
||||
tries: 0,
|
||||
word: None,
|
||||
word: Some(LineWord::text_number("FACTION", name, delta)),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use benilla_protocol::messages::{
|
||||
SpellHealLog, SpellLogMiss,
|
||||
};
|
||||
|
||||
use super::{queue, queue_reported, queue_worded, to_me, ChatCtx};
|
||||
use super::{queue_reported, queue_worded, to_me, ChatCtx};
|
||||
use crate::combat_log::feedback;
|
||||
use crate::ui_chat::combat::{self, Family, Fills, LineWord, Poses, Stores, UnitClass};
|
||||
use crate::ui_chat::ChatLog;
|
||||
@@ -183,7 +183,7 @@ pub(in crate::combat_log) struct PeriodicHit {
|
||||
/// `SMSG_SPELLNONMELEEDAMAGELOG` alike. Nothing through is worded absorbed, then resisted, on the
|
||||
/// periodic types (`0x6281e5`, `0x62820e`), or not at all; damage through takes
|
||||
/// `PERIODICAURADAMAGE`, typed off the target (`0x628235`), with absorb and resist trailers
|
||||
/// (`0x628341` passes zero for blocked and HitInfo) and [`combat::periodic_hit_word`].
|
||||
/// (`0x628341` passes zero for blocked and HitInfo) and [`combat::damage_word`].
|
||||
fn periodic_damage(
|
||||
log: &mut ChatLog,
|
||||
ctx: &ChatCtx,
|
||||
@@ -217,7 +217,7 @@ fn periodic_damage(
|
||||
}),
|
||||
..Default::default()
|
||||
};
|
||||
let word = combat::periodic_hit_word(hit.damage, hit.absorbed, hit.resisted);
|
||||
let word = combat::damage_word(hit.damage, hit.absorbed, hit.resisted);
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
@@ -563,7 +563,7 @@ fn power_gain_line(
|
||||
return;
|
||||
};
|
||||
let amount = power_gain(power, amount);
|
||||
let word = combat::power_gain_word(power, amount).filter(|_| !periodic);
|
||||
let word = combat::power_amount_word(power, amount).filter(|_| !periodic);
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
@@ -810,10 +810,13 @@ fn periodic_leech_amount(power: u32, amount: u32) -> u32 {
|
||||
/// (`0x627955`); otherwise a happiness drain words the generic line with `HAPPINESS_POINTS`.
|
||||
/// 2. `powerType >= 5`, unsigned, has no power noun (`0x6278f0`, `0x627966`): no line.
|
||||
/// 3. The spell gates, the caller's [`ChatCtx::spell_name`].
|
||||
/// 4. The resolve and range gate `0x626630`, [`queue`]'s.
|
||||
/// 4. The resolve and range gate `0x626630`, [`queue_reported`]'s.
|
||||
/// 5. The leech/drain fork, [`leech_family`].
|
||||
/// 6. The periodic flag picks the chat-type stub, `0x627d60` periodic or `0x627d30` direct.
|
||||
/// 7. `drained == 0` drops the line (`0x627ae5`), after the divide.
|
||||
///
|
||||
/// The line raises the power's word with minus the amount drained when its target is you
|
||||
/// (`0x627b94`-`0x627c5c`), [`combat::power_amount_word`], periodic or not.
|
||||
pub(super) fn power_drain_line(
|
||||
log: &mut ChatLog,
|
||||
ctx: &ChatCtx,
|
||||
@@ -853,7 +856,8 @@ pub(super) fn power_drain_line(
|
||||
let Some(kind) = kind else {
|
||||
return;
|
||||
};
|
||||
queue(
|
||||
let word = combat::power_amount_word(power, -drained).and_then(|w| to_me(target.1, w));
|
||||
queue_worded(
|
||||
log,
|
||||
ctx,
|
||||
poses,
|
||||
@@ -869,6 +873,7 @@ pub(super) fn power_drain_line(
|
||||
amount2: gained,
|
||||
..Default::default()
|
||||
},
|
||||
word,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,6 +117,8 @@ mod emitters {
|
||||
|
||||
use super::super::ChatCtx;
|
||||
|
||||
mod words;
|
||||
|
||||
const ME: u64 = 1;
|
||||
const MOB: u64 = 2;
|
||||
const FIREBALL: u32 = 133;
|
||||
|
||||
@@ -0,0 +1,305 @@
|
||||
//! The `COMBAT_TEXT_UPDATE` words the remaining formatters raise after their lines, each under the
|
||||
//! formatter's own you-only test, and the environmental log's `UNIT_COMBAT`.
|
||||
|
||||
use benilla_protocol::messages::{
|
||||
DamageShield, DispelFailed, EnvironmentalDamageLog, ExecuteLog, PeriodicTick, SpellDispelLog,
|
||||
SpellOutcomeLog,
|
||||
};
|
||||
|
||||
use super::{execute, periodic, stems, words, Bench, CLEANSE, FIREBALL, ME, MOB, RENEW};
|
||||
use crate::ui_chat::combat::{LineWord, PendingCombat};
|
||||
|
||||
fn shield(victim: u64, attacker: u64, damage: u32) -> Vec<PendingCombat> {
|
||||
let s = DamageShield {
|
||||
victim,
|
||||
attacker,
|
||||
damage,
|
||||
school: 3,
|
||||
};
|
||||
Bench::new().lines(|ctx, st, po, log| super::super::super::damage_shield(s, ctx, st, po, log))
|
||||
}
|
||||
|
||||
/// `0x62ca20` raises `DAMAGE_SHIELD` with the damage after its line when the unit that struck the
|
||||
/// shield, its second unit, is you (`0x62cb5d`-`0x62cb6b`), and writes neither for no damage
|
||||
/// (`0x62ca50`).
|
||||
#[test]
|
||||
fn a_damage_shields_hit_on_you_raises_damage_shield() {
|
||||
let on_me = shield(MOB, ME, 12);
|
||||
assert_eq!(stems(&on_me), ["DAMAGESHIELD"]);
|
||||
assert_eq!(words(&on_me), [Some(LineWord::with("DAMAGE_SHIELD", 12))]);
|
||||
assert_eq!(words(&shield(ME, MOB, 12)), [None], "your shield's hit");
|
||||
assert!(shield(MOB, ME, 0).is_empty(), "no damage");
|
||||
}
|
||||
|
||||
/// `0x626a10` raises `INTERRUPT` with the interrupted spell's name when the interrupted unit is you
|
||||
/// (`0x626b53`-`0x626b69`); `0x62d9f0` raises `EXTRA_ATTACKS` with the count when the unit that gains
|
||||
/// them is you (`0x62db7d`-`0x62dba9`), and writes neither for a count of 0 (`0x62da2a`).
|
||||
#[test]
|
||||
fn an_interrupt_and_extra_attacks_on_you_raise_their_words() {
|
||||
let interrupt = |target| {
|
||||
execute(
|
||||
CLEANSE,
|
||||
MOB,
|
||||
vec![(
|
||||
68,
|
||||
vec![ExecuteLog::InterruptCast {
|
||||
target,
|
||||
spell_id: FIREBALL,
|
||||
}],
|
||||
)],
|
||||
)
|
||||
};
|
||||
let on_me = interrupt(ME);
|
||||
assert_eq!(stems(&on_me), ["SPELLINTERRUPT"]);
|
||||
assert_eq!(
|
||||
words(&on_me),
|
||||
[Some(LineWord::with("INTERRUPT", "Fireball"))]
|
||||
);
|
||||
assert_eq!(words(&interrupt(MOB)), [None]);
|
||||
|
||||
let extra = |target, count| {
|
||||
execute(
|
||||
FIREBALL,
|
||||
target,
|
||||
vec![(19, vec![ExecuteLog::ExtraAttacks { target, count }])],
|
||||
)
|
||||
};
|
||||
let mine = extra(ME, 2);
|
||||
assert_eq!(stems(&mine), ["SPELLEXTRAATTACKS"]);
|
||||
assert_eq!(words(&mine), [Some(LineWord::with("EXTRA_ATTACKS", 2))]);
|
||||
assert_eq!(words(&extra(MOB, 2)), [None]);
|
||||
assert!(extra(ME, 0).is_empty(), "no attacks: no line, no word");
|
||||
}
|
||||
|
||||
fn outcome(immune: bool, caster: u64, target: u64, log_format: u8) -> Vec<PendingCombat> {
|
||||
let s = SpellOutcomeLog {
|
||||
caster,
|
||||
target,
|
||||
spell_id: FIREBALL,
|
||||
log_format,
|
||||
};
|
||||
Bench::new().lines(|ctx, st, po, log| {
|
||||
super::super::super::spell_outcome_log(s, immune, ctx, st, po, log)
|
||||
})
|
||||
}
|
||||
|
||||
/// `SMSG_PROCRESIST` raises `PROC_RESISTED` (`0x628b8a`-`0x628b96`) and `SMSG_SPELLORDAMAGE_IMMUNE`
|
||||
/// `SPELL_IMMUNE` (`0x62d3ab`-`0x62d3b9`), each with the spell's name, when the second unit is you.
|
||||
#[test]
|
||||
fn a_resisted_proc_and_an_immunity_on_you_raise_their_words() {
|
||||
let named = |message_type| Some(LineWord::with(message_type, "Fireball"));
|
||||
assert_eq!(words(&outcome(false, MOB, ME, 0)), [named("PROC_RESISTED")]);
|
||||
assert_eq!(words(&outcome(false, ME, MOB, 0)), [None]);
|
||||
assert_eq!(words(&outcome(true, MOB, ME, 0)), [named("SPELL_IMMUNE")]);
|
||||
assert_eq!(words(&outcome(true, ME, MOB, 0)), [None]);
|
||||
}
|
||||
|
||||
/// `SMSG_DISPEL_FAILED` raises `DISPEL_FAILED` after each spell's line when its second unit is you
|
||||
/// (`0x628daa`-`0x628db8`); `SMSG_SPELLDISPELLOG` raises `SPELL_DISPELLED` after each
|
||||
/// `AURADISPELSELF` line (`0x62d5ce`-`0x62d5e8`).
|
||||
#[test]
|
||||
fn a_failed_dispel_and_a_dispelled_aura_on_you_raise_their_words() {
|
||||
let failed = |caster, victim| {
|
||||
let s = DispelFailed {
|
||||
caster,
|
||||
victim,
|
||||
spell_ids: vec![FIREBALL, RENEW],
|
||||
};
|
||||
Bench::new()
|
||||
.lines(|ctx, st, po, log| super::super::super::dispel_failed(&s, ctx, st, po, log))
|
||||
};
|
||||
assert_eq!(
|
||||
words(&failed(MOB, ME)),
|
||||
[
|
||||
Some(LineWord::with("DISPEL_FAILED", "Fireball")),
|
||||
Some(LineWord::with("DISPEL_FAILED", "Renew"))
|
||||
]
|
||||
);
|
||||
assert_eq!(words(&failed(ME, MOB)), [None, None]);
|
||||
|
||||
let dispelled = |victim, caster| {
|
||||
let s = SpellDispelLog {
|
||||
victim,
|
||||
caster,
|
||||
spell_ids: vec![FIREBALL],
|
||||
};
|
||||
Bench::new()
|
||||
.lines(|ctx, st, po, log| super::super::super::spell_dispel_log(&s, ctx, st, po, log))
|
||||
};
|
||||
assert_eq!(
|
||||
words(&dispelled(ME, MOB)),
|
||||
[Some(LineWord::with("SPELL_DISPELLED", "Fireball"))]
|
||||
);
|
||||
assert_eq!(words(&dispelled(MOB, ME)), [None]);
|
||||
}
|
||||
|
||||
fn environment(
|
||||
victim: u64,
|
||||
damage_type: u8,
|
||||
damage: u32,
|
||||
absorb: u32,
|
||||
resist: i32,
|
||||
) -> EnvironmentalDamageLog {
|
||||
EnvironmentalDamageLog {
|
||||
victim,
|
||||
damage_type,
|
||||
damage,
|
||||
absorb,
|
||||
resist,
|
||||
}
|
||||
}
|
||||
|
||||
fn env_lines(e: EnvironmentalDamageLog) -> Vec<PendingCombat> {
|
||||
Bench::new().lines(|ctx, st, po, log| {
|
||||
super::super::super::environmental_damage_log(e, ctx, st, po, log)
|
||||
})
|
||||
}
|
||||
|
||||
/// `0x62aac0` raises its word when the victim is you (`0x62ac74`): `RESIST` with the damage and a
|
||||
/// resisted amount above 0 (`0x62ac7e`), else `ABSORB` with an absorbed one (`0x62ac99`), else
|
||||
/// `DAMAGE` (`0x62acad`).
|
||||
#[test]
|
||||
fn environmental_damage_on_you_raises_its_word() {
|
||||
let word = |e| words(&env_lines(e));
|
||||
assert_eq!(
|
||||
word(environment(ME, 2, 245, 0, 0)),
|
||||
[Some(LineWord::with("DAMAGE", 245))]
|
||||
);
|
||||
assert_eq!(
|
||||
word(environment(ME, 3, 50, 20, 10)),
|
||||
[Some(LineWord::pair("RESIST", 50, 10))]
|
||||
);
|
||||
assert_eq!(
|
||||
word(environment(ME, 3, 50, 20, -10)),
|
||||
[Some(LineWord::pair("ABSORB", 50, 20))],
|
||||
"a negative resist is no resist"
|
||||
);
|
||||
assert_eq!(word(environment(MOB, 2, 245, 0, 0)), [None]);
|
||||
}
|
||||
|
||||
/// `0x624f30` writes the line (`0x624f7c`), then for the active player (`0x624f83`) signals
|
||||
/// `UNIT_COMBAT` `WOUND` (`0x624fc4`) in the type's school from `0x809274` (0, 0, 0, 2, 3, 2), marked
|
||||
/// `0x20` for an absorb and `0x40` for a resist; a hit of all zeros writes and signals nothing
|
||||
/// (`0x624f4c`-`0x624f60`).
|
||||
#[test]
|
||||
fn environmental_damage_on_you_flashes_wound_after_its_line() {
|
||||
let run = |e: EnvironmentalDamageLog| {
|
||||
Bench::new().run(|ctx, st, po, log| {
|
||||
super::super::super::environmental_damage_log(e, ctx, st, po, log)
|
||||
})
|
||||
};
|
||||
let lava = run(environment(ME, 3, 50, 0, 0));
|
||||
assert_eq!(
|
||||
lava.pending_combat_order(),
|
||||
["VSENVIRONMENTALDAMAGE_LAVA_", "UNIT_COMBAT WOUND"]
|
||||
);
|
||||
let flash = |e| {
|
||||
run(e)
|
||||
.pending_unit_combat()
|
||||
.into_iter()
|
||||
.map(|f| (f.guid, f.action, f.flags, f.amount, f.school))
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
assert_eq!(
|
||||
flash(environment(ME, 3, 50, 0, 0)),
|
||||
[(ME, "WOUND", "", 50, 2)]
|
||||
);
|
||||
assert_eq!(
|
||||
flash(environment(ME, 4, 50, 0, 0)),
|
||||
[(ME, "WOUND", "", 50, 3)]
|
||||
);
|
||||
assert_eq!(
|
||||
flash(environment(ME, 5, 50, 0, 0)),
|
||||
[(ME, "WOUND", "", 50, 2)]
|
||||
);
|
||||
assert_eq!(
|
||||
flash(environment(ME, 2, 0, 30, 0)),
|
||||
[(ME, "WOUND", "ABSORB", 0, 0)]
|
||||
);
|
||||
assert_eq!(
|
||||
flash(environment(ME, 1, 0, 0, 30)),
|
||||
[(ME, "WOUND", "RESIST", 0, 0)]
|
||||
);
|
||||
assert_eq!(
|
||||
flash(environment(ME, 0, 0, 30, 30)),
|
||||
[(ME, "WOUND", "ABSORB", 0, 0)]
|
||||
);
|
||||
assert!(flash(environment(MOB, 3, 50, 0, 0)).is_empty(), "not you");
|
||||
let nothing = run(environment(ME, 2, 0, 0, 0));
|
||||
assert!(nothing.pending_combat_order().is_empty(), "all zeros");
|
||||
}
|
||||
|
||||
/// `0x627930` raises the drained power's word with minus the amount drained when the target is you
|
||||
/// (`0x627b94`-`0x627c5c`), from the execute log's drain and the periodic leech alike.
|
||||
#[test]
|
||||
fn power_drained_from_you_raises_its_power_word() {
|
||||
let drain = |target, power, amount| {
|
||||
execute(
|
||||
FIREBALL,
|
||||
MOB,
|
||||
vec![(
|
||||
8,
|
||||
vec![ExecuteLog::PowerDrain {
|
||||
target,
|
||||
amount,
|
||||
power,
|
||||
multiplier: 0.0,
|
||||
}],
|
||||
)],
|
||||
)
|
||||
};
|
||||
let mana = drain(ME, 0, 45);
|
||||
assert_eq!(stems(&mana), ["SPELLPOWERDRAIN"]);
|
||||
assert_eq!(words(&mana), [Some(LineWord::with("MANA", -45))]);
|
||||
assert_eq!(
|
||||
words(&drain(ME, 1, 100)),
|
||||
[Some(LineWord::with("RAGE", -10))]
|
||||
);
|
||||
assert_eq!(words(&drain(MOB, 0, 45)), [None]);
|
||||
let leech = periodic(vec![PeriodicTick::ManaLeech {
|
||||
power: 0,
|
||||
amount: 30,
|
||||
multiplier: 1.0,
|
||||
}]);
|
||||
assert_eq!(stems(&leech), ["SPELLPOWERLEECH"]);
|
||||
assert_eq!(words(&leech), [Some(LineWord::with("MANA", -30))]);
|
||||
}
|
||||
|
||||
/// `0x62c5f0` raises `FACTION` with the faction's name and the signed change after its line, with
|
||||
/// no class test (`0x62c661`-`0x62c667`). On the real DBC, Booty Bay.
|
||||
#[test]
|
||||
fn a_standing_change_raises_faction() {
|
||||
use crate::net::Reputations;
|
||||
use crate::target::ring::Factions;
|
||||
use crate::ui_chat::ChatLog;
|
||||
|
||||
let data = benilla_formats::wow_data_or_skip!();
|
||||
let mut chain = benilla_formats::open_chain(&data).expect("open chain");
|
||||
let catalog = benilla_formats::load_faction_catalog(&mut chain).expect("factions");
|
||||
let booty = u32::try_from(catalog.reputation_faction(21).unwrap().rep_index).unwrap();
|
||||
let name = catalog.faction_name(21).unwrap().to_string();
|
||||
let factions = Factions::from_catalog(catalog);
|
||||
let word = |standing| {
|
||||
let mut log = ChatLog::default();
|
||||
crate::combat_log::chat::faction_standing(
|
||||
&[(booty, standing)],
|
||||
&Reputations::default(),
|
||||
Some(&factions),
|
||||
&mut log,
|
||||
);
|
||||
words(
|
||||
&log.pending_combat()
|
||||
.into_iter()
|
||||
.cloned()
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
};
|
||||
assert_eq!(
|
||||
word(25),
|
||||
[Some(LineWord::text_number("FACTION", &name, 25))]
|
||||
);
|
||||
assert_eq!(
|
||||
word(-40),
|
||||
[Some(LineWord::text_number("FACTION", &name, -40))]
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
//! `UNIT_COMBAT`, the portrait hit indicator, as the packet handlers raise it through `0x494600`:
|
||||
//! `0x4946b0` a wound, `0x494720` a miss, `0x494740` a heal. Each is queued in the chat drain
|
||||
//! ([`ChatLog::push_unit_combat`]) at the point its handler calls it, before or after that
|
||||
//! handler's line, so Lua sees the two in the handler's order.
|
||||
//! `UNIT_COMBAT`, the portrait hit indicator, as the handlers raise it through `0x494600`:
|
||||
//! `0x4946b0` a wound, `0x4946d0` a swing, `0x494720` a miss, `0x494740` a heal. Each is queued in
|
||||
//! the chat drain ([`ChatLog::push_unit_combat`]) at the point its handler calls it, before or after
|
||||
//! that handler's line, so Lua sees the two in the handler's order.
|
||||
|
||||
use crate::ui_chat::ChatLog;
|
||||
use crate::ui_unit::UnitCombatFeedback;
|
||||
@@ -28,7 +28,8 @@ pub(crate) fn wound_descriptor(amount: u32, flags: u32) -> &'static str {
|
||||
}
|
||||
|
||||
/// The flags a spell hit hands `0x494600`: crit `0x80`, and each partial nonzero, absorbed `0x20`,
|
||||
/// blocked `0x800`, resisted `0x40` (`0x5e87fa`-`0x5e8825`).
|
||||
/// blocked `0x800`, resisted `0x40` (`0x5e87fa`-`0x5e8825`); an environmental hit marks the two it
|
||||
/// has the same way (`0x624f8c`-`0x624fa1`).
|
||||
pub(super) fn hit_flags(crit: bool, absorb: u32, resist: i32, blocked: u32) -> u32 {
|
||||
let bit = |set: bool, bit: u32| if set { bit } else { 0 };
|
||||
bit(crit, 0x80) | bit(absorb != 0, 0x20) | bit(blocked != 0, 0x800) | bit(resist != 0, 0x40)
|
||||
@@ -56,6 +57,37 @@ pub(super) fn heal(log: &mut ChatLog, guid: u64, amount: u32, crit: bool) {
|
||||
});
|
||||
}
|
||||
|
||||
/// A swing's `UNIT_COMBAT` action by its victim state, the nine-word table `0x83de28`.
|
||||
const SWING_ACTIONS: [&str; 9] = [
|
||||
"MISS",
|
||||
"WOUND",
|
||||
"DODGE",
|
||||
"PARRY",
|
||||
"INTERRUPT",
|
||||
"BLOCK",
|
||||
"EVADE",
|
||||
"IMMUNE",
|
||||
"DEFLECT",
|
||||
];
|
||||
|
||||
/// `0x4946d0(record)`: a swing's `UNIT_COMBAT`, its action the victim state's word (`0x494706`), its
|
||||
/// descriptor off the damage and hit info like every wrapper's. The table index has no bound: a
|
||||
/// state past it, which no server sends (vmangos `VictimState` ends at 8,
|
||||
/// `Objects/UnitDefines.h:247`), signals nothing here.
|
||||
pub(crate) fn swing(log: &mut ChatLog, guid: u64, victim_state: u32, hit_info: u32, damage: u32) {
|
||||
let Some(&action) = SWING_ACTIONS.get(victim_state as usize) else {
|
||||
return;
|
||||
};
|
||||
log.push_unit_combat(UnitCombatFeedback {
|
||||
guid,
|
||||
action,
|
||||
flags: wound_descriptor(damage, hit_info),
|
||||
amount: damage,
|
||||
// The reference passes sub-damage 0's school (`0x4946fc`), which the swing does not carry.
|
||||
school: 0,
|
||||
});
|
||||
}
|
||||
|
||||
/// Miss code (vmangos `SpellMissInfo`) to the `UNIT_COMBAT` action word, the table `0x86582c` that
|
||||
/// `0x494720` indexes for a code from 0 to 11, `NONE` first; any other code fires nothing.
|
||||
fn miss_action(code: u8) -> Option<&'static str> {
|
||||
@@ -87,3 +119,51 @@ pub(super) fn miss(log: &mut ChatLog, guid: u64, code: u8) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::ui_chat::ChatLog;
|
||||
|
||||
/// A displayed swing on a held player, as `(action, descriptor)` of its `UNIT_COMBAT`.
|
||||
fn swing(victim_state: u32, hit_info: u32, damage: u32) -> Vec<(&'static str, &'static str)> {
|
||||
let mut log = ChatLog::default();
|
||||
let s = crate::creature_anim::SwingMessage {
|
||||
attacker: bevy::prelude::Entity::PLACEHOLDER,
|
||||
victim: None,
|
||||
hit_info,
|
||||
victim_state,
|
||||
damage,
|
||||
displayed: true,
|
||||
seq: 0,
|
||||
};
|
||||
let player =
|
||||
crate::net::ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[(2, 0x19)]));
|
||||
crate::ui_unit::melee_unit_combat(&mut log, &s, Some((1, &player)));
|
||||
log.pending_unit_combat()
|
||||
.into_iter()
|
||||
.map(|f| (f.action, f.flags))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `0x4946d0` takes its action from the victim state through the nine-word table `0x83de28`
|
||||
/// (`0x494706`) and its descriptor from the amount and hit info alone (`0x494600`): an interrupt
|
||||
/// is `INTERRUPT`, state 0 `MISS` whatever the damage, state 1 `WOUND` with none, and a dodge
|
||||
/// keeps an absorb mark.
|
||||
#[test]
|
||||
fn a_swings_action_is_its_victim_states_word() {
|
||||
assert_eq!(swing(4, 0, 30), [("INTERRUPT", "")]);
|
||||
assert_eq!(swing(0, 0x80, 30), [("MISS", "CRITICAL")]);
|
||||
assert_eq!(swing(0, 0x10, 0), [("MISS", "")]);
|
||||
assert_eq!(swing(1, 0, 0), [("WOUND", "")]);
|
||||
assert_eq!(swing(1, 0x4000, 30), [("WOUND", "GLANCING")]);
|
||||
assert_eq!(swing(1, 0x40, 0), [("WOUND", "RESIST")]);
|
||||
assert_eq!(swing(2, 0x20, 0), [("DODGE", "ABSORB")]);
|
||||
assert_eq!(swing(3, 0, 0), [("PARRY", "")]);
|
||||
assert_eq!(swing(5, 0x800, 0), [("BLOCK", "BLOCK")]);
|
||||
assert_eq!(swing(6, 0, 0), [("EVADE", "")]);
|
||||
assert_eq!(swing(7, 0, 0), [("IMMUNE", "")]);
|
||||
assert_eq!(swing(8, 0, 0), [("DEFLECT", "")]);
|
||||
// Past the table, which `0x494706` indexes unbounded and no server sends.
|
||||
assert!(swing(9, 0, 0).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ use crate::ui_chat::combat::{CombatLogRanges, LogPeriodicSpells};
|
||||
use crate::ui_chat::ChatLog;
|
||||
|
||||
pub(crate) mod chat;
|
||||
mod feedback;
|
||||
pub(crate) mod feedback;
|
||||
pub(crate) mod text;
|
||||
|
||||
/// `SMSG_ATTACKERSTATEUPDATE`'s swing as every consumer reads it: the record read runs
|
||||
|
||||
@@ -13,7 +13,7 @@ use benilla_protocol::messages::{
|
||||
};
|
||||
|
||||
use crate::combat_text::{
|
||||
damage_color, miss_word, spell_text, CombatTextSpawn, DamageSource, DamageTextGates,
|
||||
damage_color, miss_word, spell_text, CombatTextSpawn, DamageSource, DamageTextGates, TextBody,
|
||||
};
|
||||
use crate::ui_chat::{combat, ChatLog};
|
||||
|
||||
@@ -189,7 +189,7 @@ pub(super) fn damage_shield(
|
||||
if let Some(anchor) = gated_anchor(s.attacker, index, self_guid, stores) {
|
||||
text.write(CombatTextSpawn {
|
||||
anchor,
|
||||
text: s.damage.to_string(),
|
||||
text: TextBody::Literal(s.damage.to_string()),
|
||||
category: 0,
|
||||
color,
|
||||
});
|
||||
@@ -226,14 +226,14 @@ fn miss_float(
|
||||
stores: &Query<&mut ObjectStore>,
|
||||
text: &mut MessageWriter<CombatTextSpawn>,
|
||||
) {
|
||||
if let (Some(color), Some(anchor), Some((word, category))) = (
|
||||
if let (Some(color), Some(anchor), Some((key, category))) = (
|
||||
color,
|
||||
gated_anchor(guid, index, self_guid, stores),
|
||||
miss_word(code),
|
||||
) {
|
||||
text.write(CombatTextSpawn {
|
||||
anchor,
|
||||
text: word.to_string(),
|
||||
text: TextBody::Word(key),
|
||||
category,
|
||||
color,
|
||||
});
|
||||
@@ -341,7 +341,7 @@ pub(super) fn xp_gain(
|
||||
if let Some(&me) = self_guid.0.as_ref().and_then(|g| index.0.get(g)) {
|
||||
text.write(CombatTextSpawn {
|
||||
anchor: me,
|
||||
text: format!("XP: {}", x.total),
|
||||
text: TextBody::Literal(format!("XP: {}", x.total)),
|
||||
category: 4,
|
||||
color: None, // row 4's own purple: XP skips the damage colour law
|
||||
});
|
||||
@@ -489,7 +489,12 @@ mod tests {
|
||||
.collect();
|
||||
assert_eq!(
|
||||
spawned,
|
||||
vec![("Immune".to_string(), 3, Some(COLOR_SPELL_GOLD), victim_e)],
|
||||
vec![(
|
||||
TextBody::Word("IMMUNE"),
|
||||
3,
|
||||
Some(COLOR_SPELL_GOLD),
|
||||
victim_e
|
||||
)],
|
||||
"gold, category 3, over the immune target"
|
||||
);
|
||||
}
|
||||
@@ -547,7 +552,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Run one packet through the leg; the floats' text.
|
||||
/// Run one packet through the leg; the floats' text, a word by its key.
|
||||
fn run(&mut self, packet: impl Packet) -> Vec<String> {
|
||||
let spells = self.spells.clone();
|
||||
let mut packet = Some(packet);
|
||||
@@ -568,7 +573,10 @@ mod tests {
|
||||
.world_mut()
|
||||
.resource_mut::<Messages<CombatTextSpawn>>()
|
||||
.drain()
|
||||
.map(|t| t.text)
|
||||
.map(|t| match t.text {
|
||||
TextBody::Literal(text) => text,
|
||||
TextBody::Word(key) => key.to_string(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
@@ -649,8 +657,8 @@ mod tests {
|
||||
#[test]
|
||||
fn a_stopped_spell_hit_floats_its_reason() {
|
||||
let mut leg = Leg::new();
|
||||
assert_eq!(leg.run(hit(FIREBALL, 0, 0, 30, 40)), ["Block"]);
|
||||
assert_eq!(leg.run(hit(FIREBALL, 0, 50, 30, 40)), ["Absorb"]);
|
||||
assert_eq!(leg.run(hit(FIREBALL, 0, 0, 30, 40)), ["BLOCK"]);
|
||||
assert_eq!(leg.run(hit(FIREBALL, 0, 50, 30, 40)), ["ABSORB"]);
|
||||
assert!(leg.run(hit(FIREBALL, 0, 0, 0, 0)).is_empty());
|
||||
let crit = SpellDamageLog {
|
||||
hit_info: 0x2,
|
||||
@@ -692,7 +700,7 @@ mod tests {
|
||||
PeriodicTick::Heal { amount: 9 },
|
||||
],
|
||||
};
|
||||
assert_eq!(leg.run(tick(FIREBALL)), ["Resist"]);
|
||||
assert_eq!(leg.run(tick(FIREBALL)), ["RESIST"]);
|
||||
assert!(leg.run(tick(HIDDEN)).is_empty());
|
||||
}
|
||||
|
||||
@@ -757,11 +765,11 @@ mod tests {
|
||||
};
|
||||
assert_eq!(
|
||||
leg.run(GoMisses(ME, FIREBALL, vec![entry(MOB, 11, 2)])),
|
||||
["Reflect"]
|
||||
["REFLECT"]
|
||||
);
|
||||
assert_eq!(
|
||||
leg.run(GoMisses(ME, FIREBALL, vec![entry(MOB, 3, 0)])),
|
||||
["Dodge"]
|
||||
["DODGE"]
|
||||
);
|
||||
assert!(leg
|
||||
.run(GoMisses(ME, HIDDEN, vec![entry(MOB, 3, 0)]))
|
||||
@@ -815,7 +823,7 @@ mod tests {
|
||||
};
|
||||
assert_eq!(
|
||||
float(true),
|
||||
[("Miss".to_string(), 3, Some(COLOR_SPELL_GOLD))]
|
||||
[(TextBody::Word("MISS"), 3, Some(COLOR_SPELL_GOLD))]
|
||||
);
|
||||
assert!(float(false).is_empty());
|
||||
}
|
||||
@@ -830,7 +838,7 @@ mod tests {
|
||||
extended: false,
|
||||
misses: vec![(MOB, code)],
|
||||
};
|
||||
assert_eq!(leg.run(miss(FIREBALL, 7)), ["Immune"]);
|
||||
assert_eq!(leg.run(miss(FIREBALL, 7)), ["IMMUNE"]);
|
||||
assert!(leg.run(miss(HIDDEN, 7)).is_empty());
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use super::TextBody;
|
||||
|
||||
/// One config-table row (`0xce8828`, stride 0x1c, filled by `0x6c79a0`): rise in world units over
|
||||
/// the whole life, fade-in end, fade-out start and duration in ms, the scale pair (equal except
|
||||
/// the crit row, whose keyframes ramp `valueHi`) and the ARGB default colour (`0x4a2c10`).
|
||||
@@ -87,17 +89,19 @@ const CRIT_KEYFRAMES: [(f32, f32, f32, f32); 3] = [
|
||||
(0.2, 1.0, 1.0, 1.0),
|
||||
];
|
||||
|
||||
/// The outcome words by code 1-11 (`0x86582c` keys for `FrameScript_GetText`), vmangos
|
||||
/// `SpellMissInfo` (`SpellDefines.h:160`); the enUS `GlobalStrings.lua` values.
|
||||
const WORDS: [&str; 11] = [
|
||||
"Miss", "Resist", "Dodge", "Parry", "Block", "Evade", "Immune", "Immune", "Deflect", "Absorb",
|
||||
"Reflect",
|
||||
/// The outcome words' `GlobalStrings.lua` keys by code 1-11, vmangos `SpellMissInfo`
|
||||
/// (`SpellDefines.h:160`): the table `0x86582c` that `0x607140` reads its word through
|
||||
/// (`0x6071e7`).
|
||||
const WORD_KEYS: [&str; 11] = [
|
||||
"MISS", "RESIST", "DODGE", "PARRY", "BLOCK", "EVADE", "IMMUNE", "IMMUNE", "DEFLECT", "ABSORB",
|
||||
"REFLECT",
|
||||
];
|
||||
|
||||
/// Outcome code 1-11 to `(word, category)`: category 3, except ABSORB's 1 (`0x80c48c`).
|
||||
/// Outcome code 1-11 to `(word key, category)`: category 3, except ABSORB's 1 (`0x80c48c`). The
|
||||
/// table's entry 0, `NONE` at category 6, is past the six category rows and floats nothing here.
|
||||
pub(crate) fn miss_word(code: u8) -> Option<(&'static str, u8)> {
|
||||
let word = *WORDS.get((code as usize).checked_sub(1)?)?;
|
||||
Some((word, if code == 10 { 1 } else { 3 }))
|
||||
let key = *WORD_KEYS.get((code as usize).checked_sub(1)?)?;
|
||||
Some((key, if code == 10 { 1 } else { 3 }))
|
||||
}
|
||||
|
||||
/// The emitter override colours (`0x5fa0b0`/`0x5fa0f0`): spell damage gold `[0xc4d8a0]`, pet melee
|
||||
@@ -168,9 +172,9 @@ pub(crate) fn damage_color(
|
||||
|
||||
/// The melee emitter split, `0x6243e0`'s branch order: victim states 2, 3, 5, 6, 7, 8 float their
|
||||
/// word whatever the damage; otherwise damage floats the bare number (category 2 on
|
||||
/// `HITINFO_CRITICALHIT 0x80`), and zero damage is "Absorb" on `0x20`, "Resist" on `0x40`, else
|
||||
/// "Miss" (`HITINFO_MISS` is never tested).
|
||||
pub(crate) fn melee_text(hit_info: u32, victim_state: u32, damage: u32) -> Option<(u8, String)> {
|
||||
/// `HITINFO_CRITICALHIT 0x80`), and zero damage is the `ABSORB` word on `0x20`, `RESIST` on
|
||||
/// `0x40`, else `MISS` (`HITINFO_MISS` is never tested).
|
||||
pub(crate) fn melee_text(hit_info: u32, victim_state: u32, damage: u32) -> Option<(u8, TextBody)> {
|
||||
let code = match victim_state {
|
||||
2 => 3, // DODGE
|
||||
3 => 4, // PARRY
|
||||
@@ -182,7 +186,7 @@ pub(crate) fn melee_text(hit_info: u32, victim_state: u32, damage: u32) -> Optio
|
||||
// 0 UNAFFECTED, 1 NORMAL, 4 INTERRUPT: keyed on damage.
|
||||
if damage > 0 {
|
||||
let category = if hit_info & 0x80 != 0 { 2 } else { 0 };
|
||||
return Some((category, damage.to_string()));
|
||||
return Some((category, TextBody::Literal(damage.to_string())));
|
||||
}
|
||||
if hit_info & 0x20 != 0 {
|
||||
10 // ABSORB, full; a partial one shows only the number
|
||||
@@ -193,7 +197,7 @@ pub(crate) fn melee_text(hit_info: u32, victim_state: u32, damage: u32) -> Optio
|
||||
}
|
||||
}
|
||||
};
|
||||
miss_word(code).map(|(w, c)| (c, w.to_string()))
|
||||
miss_word(code).map(|(key, c)| (c, TextBody::Word(key)))
|
||||
}
|
||||
|
||||
/// The spell and periodic emitter split (`0x5e85e0`/`0x626dd0`): damage floats a number, category
|
||||
@@ -206,9 +210,12 @@ pub(crate) fn spell_text(
|
||||
resist: i32,
|
||||
blocked: u32,
|
||||
crit: bool,
|
||||
) -> Option<(u8, String)> {
|
||||
) -> Option<(u8, TextBody)> {
|
||||
let code = if damage != 0 {
|
||||
return Some((if crit { 2 } else { 0 }, damage.to_string()));
|
||||
return Some((
|
||||
if crit { 2 } else { 0 },
|
||||
TextBody::Literal(damage.to_string()),
|
||||
));
|
||||
} else if absorb != 0 {
|
||||
10
|
||||
} else if blocked != 0 {
|
||||
@@ -218,7 +225,7 @@ pub(crate) fn spell_text(
|
||||
} else {
|
||||
return None;
|
||||
};
|
||||
miss_word(code).map(|(w, c)| (c, w.to_string()))
|
||||
miss_word(code).map(|(key, c)| (c, TextBody::Word(key)))
|
||||
}
|
||||
|
||||
/// The gx pixel round (`0x5c7010`/`0x5c6fa0`): add 0.5 and truncate, half away from zero.
|
||||
@@ -406,29 +413,34 @@ mod tests {
|
||||
assert!((scale_value(2, 0.5) / scale_value(0, 0.5) - 1.5).abs() < 1e-3);
|
||||
}
|
||||
|
||||
fn n(text: &str) -> TextBody {
|
||||
TextBody::Literal(text.into())
|
||||
}
|
||||
|
||||
/// The melee (`0x6243e0`) and spell splits; ABSORB is the one category-1 word.
|
||||
#[test]
|
||||
fn emitters_split_numbers_and_words() {
|
||||
assert_eq!(melee_text(0x2, 1, 37), Some((0, "37".into())));
|
||||
assert_eq!(melee_text(0x82, 1, 99), Some((2, "99".into()))); // crit bit 0x80
|
||||
assert_eq!(melee_text(0x10, 0, 0), Some((3, "Miss".into())));
|
||||
assert_eq!(melee_text(0x0, 2, 0), Some((3, "Dodge".into())));
|
||||
assert_eq!(melee_text(0x0, 3, 0), Some((3, "Parry".into())));
|
||||
assert_eq!(melee_text(0x0, 5, 0), Some((3, "Block".into())));
|
||||
assert_eq!(melee_text(0x0, 6, 0), Some((3, "Evade".into())));
|
||||
use TextBody::Word;
|
||||
assert_eq!(melee_text(0x2, 1, 37), Some((0, n("37"))));
|
||||
assert_eq!(melee_text(0x82, 1, 99), Some((2, n("99")))); // crit bit 0x80
|
||||
assert_eq!(melee_text(0x10, 0, 0), Some((3, Word("MISS"))));
|
||||
assert_eq!(melee_text(0x0, 2, 0), Some((3, Word("DODGE"))));
|
||||
assert_eq!(melee_text(0x0, 3, 0), Some((3, Word("PARRY"))));
|
||||
assert_eq!(melee_text(0x0, 5, 0), Some((3, Word("BLOCK"))));
|
||||
assert_eq!(melee_text(0x0, 6, 0), Some((3, Word("EVADE"))));
|
||||
// A word state ignores damage.
|
||||
assert_eq!(melee_text(0x2, 3, 25), Some((3, "Parry".into())));
|
||||
assert_eq!(melee_text(0x22, 1, 0), Some((1, "Absorb".into()))); // full absorb: bit 0x20
|
||||
assert_eq!(melee_text(0x42, 1, 0), Some((3, "Resist".into()))); // full resist: bit 0x40
|
||||
// Zero damage: Miss.
|
||||
assert_eq!(melee_text(0x2, 1, 0), Some((3, "Miss".into())));
|
||||
assert_eq!(spell_text(120, 0, 0, 0, false), Some((0, "120".into())));
|
||||
assert_eq!(spell_text(240, 0, 0, 0, true), Some((2, "240".into())));
|
||||
assert_eq!(spell_text(0, 50, 80, 40, false), Some((1, "Absorb".into())));
|
||||
assert_eq!(spell_text(0, 0, 80, 40, false), Some((3, "Block".into())));
|
||||
assert_eq!(spell_text(0, 0, 80, 0, false), Some((3, "Resist".into())));
|
||||
assert_eq!(melee_text(0x2, 3, 25), Some((3, Word("PARRY"))));
|
||||
assert_eq!(melee_text(0x22, 1, 0), Some((1, Word("ABSORB")))); // full absorb: bit 0x20
|
||||
assert_eq!(melee_text(0x42, 1, 0), Some((3, Word("RESIST")))); // full resist: bit 0x40
|
||||
// Zero damage: Miss.
|
||||
assert_eq!(melee_text(0x2, 1, 0), Some((3, Word("MISS"))));
|
||||
assert_eq!(spell_text(120, 0, 0, 0, false), Some((0, n("120"))));
|
||||
assert_eq!(spell_text(240, 0, 0, 0, true), Some((2, n("240"))));
|
||||
assert_eq!(spell_text(0, 50, 80, 40, false), Some((1, Word("ABSORB"))));
|
||||
assert_eq!(spell_text(0, 0, 80, 40, false), Some((3, Word("BLOCK"))));
|
||||
assert_eq!(spell_text(0, 0, 80, 0, false), Some((3, Word("RESIST"))));
|
||||
assert_eq!(spell_text(0, 0, 0, 0, false), None);
|
||||
assert_eq!(miss_word(11), Some(("Reflect", 3)));
|
||||
assert_eq!(miss_word(11), Some(("REFLECT", 3)));
|
||||
assert_eq!(miss_word(0), None);
|
||||
assert_eq!(miss_word(12), None);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
//! world-anchored: the unit's overhead anchor is snapshotted at spawn (`0x6c73f0` to `0x608640`:
|
||||
//! the PlayerName attachment, slot 18, else `feet + scale × bbox_z × 1.25`), moved `z − 1/3`, and
|
||||
//! re-projected every frame (`0x483ee0`), rising and fading per its row of `0xce8828`. Numbers
|
||||
//! are bare `"%d"`, misses localized words; at most 4 texts per unit, a hard drop (`0x6c73f0`).
|
||||
//! are bare `"%d"`, misses the `GlobalStrings.lua` words their keys read as they float
|
||||
//! ([`TextBody`]); at most 4 texts per unit, a hard drop (`0x6c73f0`).
|
||||
//! Damage over yourself is suppressed at the emitters (Gate A, `0x607140`/`0x6128b0`); the XP
|
||||
//! emitter (category 4) is self-anchored and skips it. Heals and energize never float in 1.12.
|
||||
//!
|
||||
@@ -63,17 +64,28 @@ use crate::ui_text::{layout_text_quads, FontSpec, Justify, UiFontAtlas};
|
||||
use benilla_world::view::WorldCamera;
|
||||
|
||||
/// Spawn one floating text over `anchor`. The producer applies Gate A, so a spawn here shows
|
||||
/// unless the cap drops it.
|
||||
/// unless the cap drops it or its word has no string.
|
||||
#[derive(Message)]
|
||||
pub(crate) struct CombatTextSpawn {
|
||||
pub(crate) anchor: Entity,
|
||||
pub(crate) text: String,
|
||||
pub(crate) text: TextBody,
|
||||
/// Config category 0-5 ([`CATEGORIES`]).
|
||||
pub(crate) category: u8,
|
||||
/// The emitter override ([`damage_color`]); `None` is the row's default.
|
||||
pub(crate) color: Option<u32>,
|
||||
}
|
||||
|
||||
/// What a floating text shows.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) enum TextBody {
|
||||
/// The text itself: a `"%d"` number, the XP line.
|
||||
Literal(String),
|
||||
/// An outcome word's `GlobalStrings.lua` key, which `0x607140` reads through
|
||||
/// `FrameScript_GetText` as it floats the word (`0x6071f3`); a missing or empty string floats
|
||||
/// nothing (`0x6071f8`-`0x6071ff`).
|
||||
Word(&'static str),
|
||||
}
|
||||
|
||||
/// One live WORLDTEXTSTRING. `pos` is a spawn-time snapshot, so a unit that walks away leaves its
|
||||
/// numbers behind; `anchor` is kept for the per-unit cap.
|
||||
struct WorldText {
|
||||
@@ -147,6 +159,8 @@ pub(crate) fn float_combat_text(
|
||||
mut bucket: Local<crate::smart_rect::SmartBucket>,
|
||||
// Absent in a bare test world, which draws the default face.
|
||||
font: Option<Res<DamageTextFont>>,
|
||||
// The globals a word is read from; with no VM a word has no string.
|
||||
script: Option<NonSend<benilla_ui::script::UiScript>>,
|
||||
) {
|
||||
let now = time.elapsed_secs_f64();
|
||||
// Headless there is no camera: spawns and expiry run, nothing draws.
|
||||
@@ -156,6 +170,18 @@ pub(crate) fn float_combat_text(
|
||||
.map(|(c, pose)| (c, GlobalTransform::from(*pose)));
|
||||
let viewport = cam.as_ref().and_then(|(c, _)| c.logical_viewport_size());
|
||||
for spawn in spawns.read() {
|
||||
let text = match &spawn.text {
|
||||
TextBody::Literal(text) => text.clone(),
|
||||
TextBody::Word(key) => {
|
||||
match script
|
||||
.as_deref()
|
||||
.and_then(|s| crate::ui_chat::combat::global_string(s, key))
|
||||
{
|
||||
Some(text) => text,
|
||||
None => continue,
|
||||
}
|
||||
}
|
||||
};
|
||||
let Some(slot) = free_slot(&texts.0, spawn.anchor) else {
|
||||
continue; // the 4-slot hard drop
|
||||
};
|
||||
@@ -173,8 +199,8 @@ pub(crate) fn float_combat_text(
|
||||
&mounts,
|
||||
);
|
||||
debug!(
|
||||
"fct: \"{}\" (cat {}) over {:?}",
|
||||
spawn.text, spawn.category, spawn.anchor
|
||||
"fct: \"{text}\" (cat {}) over {:?}",
|
||||
spawn.category, spawn.anchor
|
||||
);
|
||||
if benilla_assets::trace::enabled() {
|
||||
let via_attach = anchors
|
||||
@@ -183,14 +209,8 @@ pub(crate) fn float_combat_text(
|
||||
benilla_assets::trace::line(
|
||||
"fct",
|
||||
&format!(
|
||||
"spawn \"{}\" cat={} anchor={:?} pos=({:.3},{:.3},{:.3}) attach18={}",
|
||||
spawn.text,
|
||||
spawn.category,
|
||||
spawn.anchor,
|
||||
overhead.x,
|
||||
overhead.y,
|
||||
overhead.z,
|
||||
via_attach
|
||||
"spawn \"{text}\" cat={} anchor={:?} pos=({:.3},{:.3},{:.3}) attach18={}",
|
||||
spawn.category, spawn.anchor, overhead.x, overhead.y, overhead.z, via_attach
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -199,7 +219,7 @@ pub(crate) fn float_combat_text(
|
||||
anchor: spawn.anchor,
|
||||
pos,
|
||||
born: now,
|
||||
text: spawn.text.clone(),
|
||||
text,
|
||||
category: spawn.category,
|
||||
color: spawn
|
||||
.color
|
||||
@@ -385,10 +405,10 @@ fn missile_miss_text(
|
||||
let Some(color) = damage_color(*gates, source, melee_styled(Some(display))) else {
|
||||
continue; // the CombatDamage and Pet* gates, read inside `0x607140`
|
||||
};
|
||||
if let Some((word, category)) = miss_word(arrival.code) {
|
||||
if let Some((key, category)) = miss_word(arrival.code) {
|
||||
text.write(CombatTextSpawn {
|
||||
anchor: arrival.anchor,
|
||||
text: word.to_string(),
|
||||
text: TextBody::Word(key),
|
||||
category,
|
||||
color,
|
||||
});
|
||||
@@ -484,14 +504,14 @@ mod tests {
|
||||
for i in 0..6 {
|
||||
app.world_mut().write_message(CombatTextSpawn {
|
||||
anchor: unit,
|
||||
text: format!("{i}"),
|
||||
text: TextBody::Literal(format!("{i}")),
|
||||
category: 0,
|
||||
color: None,
|
||||
});
|
||||
}
|
||||
app.world_mut().write_message(CombatTextSpawn {
|
||||
anchor: other,
|
||||
text: "7".into(),
|
||||
text: TextBody::Literal("7".into()),
|
||||
category: 0,
|
||||
color: Some(COLOR_SPELL_GOLD),
|
||||
});
|
||||
@@ -586,12 +606,12 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
fire(FIREBALL, false, true),
|
||||
vec![("Resist".to_string(), 3, Some(law::COLOR_SPELL_GOLD))],
|
||||
vec![(TextBody::Word("RESIST"), 3, Some(law::COLOR_SPELL_GOLD))],
|
||||
"my Fireball's resist word is spell gold, category 3, over the victim"
|
||||
);
|
||||
assert_eq!(
|
||||
fire(AUTO_SHOT, false, true),
|
||||
vec![("Resist".to_string(), 3, None)],
|
||||
vec![(TextBody::Word("RESIST"), 3, None)],
|
||||
"AttributesEx3 bit 15 keeps a ranged basic shot's word melee-white"
|
||||
);
|
||||
assert!(
|
||||
@@ -604,6 +624,71 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
/// `0x607140` reads the outcome's word through `FrameScript_GetText`, by its key in `0x86582c`
|
||||
/// (`0x6071e7`-`0x6071f3`), as it floats it, and floats nothing for a missing or empty string
|
||||
/// (`0x6071f8`-`0x6071ff`): an addon's or a locale's word is what shows.
|
||||
#[test]
|
||||
fn a_miss_word_is_its_global_string_and_an_empty_one_floats_nothing() {
|
||||
use crate::entities::MissileMiss;
|
||||
use crate::net::{ObjectStore, SelfGuid, SelfPlayer};
|
||||
use benilla_ui::script::UiScript;
|
||||
|
||||
const FIREBALL: u32 = 133;
|
||||
let float = |assign: &str| -> Vec<String> {
|
||||
let mut app = App::new();
|
||||
app.add_plugins(bevy::time::TimePlugin)
|
||||
.init_resource::<UiQuads>()
|
||||
.init_resource::<WorldTexts>()
|
||||
.add_message::<MissileMiss>()
|
||||
.add_message::<CombatTextSpawn>()
|
||||
.init_resource::<SelfGuid>()
|
||||
.init_resource::<DamageTextGates>()
|
||||
.insert_resource(crate::ui_action::Spells {
|
||||
catalog: benilla_formats::SpellCatalog::from_displays(
|
||||
[(
|
||||
FIREBALL,
|
||||
benilla_formats::SpellDisplay {
|
||||
name: "Fireball".into(),
|
||||
speed: 24.0,
|
||||
..Default::default()
|
||||
},
|
||||
)]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
})
|
||||
.add_systems(Update, (missile_miss_text, float_combat_text).chain());
|
||||
let script = UiScript::new().expect("VM");
|
||||
script.run(assign).expect("assign RESIST");
|
||||
app.insert_non_send_resource(script);
|
||||
let me = app
|
||||
.world_mut()
|
||||
.spawn((SelfPlayer, ObjectStore::default(), Transform::default()))
|
||||
.id();
|
||||
let victim = app
|
||||
.world_mut()
|
||||
.spawn((ObjectStore::default(), Transform::default()))
|
||||
.id();
|
||||
app.world_mut().write_message(MissileMiss {
|
||||
caster: me,
|
||||
anchor: victim,
|
||||
spell_id: FIREBALL,
|
||||
code: 2, // RESIST
|
||||
});
|
||||
app.update();
|
||||
app.world()
|
||||
.resource::<WorldTexts>()
|
||||
.0
|
||||
.iter()
|
||||
.map(|t| t.text.clone())
|
||||
.collect()
|
||||
};
|
||||
assert_eq!(float("RESIST = 'Résiste'"), ["Résiste"]);
|
||||
assert!(float("RESIST = ''").is_empty(), "an empty string");
|
||||
assert!(float("RESIST = nil").is_empty(), "no string");
|
||||
}
|
||||
|
||||
/// The cull's walk collects indices unsorted, against the list before removal.
|
||||
#[test]
|
||||
fn drop_indices_takes_exactly_those() {
|
||||
|
||||
@@ -943,16 +943,16 @@ mod tests {
|
||||
}
|
||||
|
||||
/// The `0x61dd50` arm: a miss plays the victim's dodge or block clip, never the impact, and
|
||||
/// floats its word over the target. A parry reads Deflect, rewritten at launch; a Reflect
|
||||
/// floats its word over the target. A parry reads `DEFLECT`, rewritten at launch; a Reflect
|
||||
/// floats over the target, where the inline site re-anchors it to the caster (`0x6e7e51`).
|
||||
#[test]
|
||||
fn missed_arrival_words_the_target_deflects_a_parry_and_plays_dodge_or_block() {
|
||||
for (code, expect_state, expect_word) in [
|
||||
(3u8, Some(2u32), "Dodge"),
|
||||
(5, Some(5), "Block"),
|
||||
(1, None, "Miss"),
|
||||
(4, None, "Deflect"),
|
||||
(11, None, "Reflect"),
|
||||
(3u8, Some(2u32), "DODGE"),
|
||||
(5, Some(5), "BLOCK"),
|
||||
(1, None, "MISS"),
|
||||
(4, None, "DEFLECT"),
|
||||
(11, None, "REFLECT"),
|
||||
] {
|
||||
let mut app = app();
|
||||
let caster = caster(&mut app, Vec3::ZERO);
|
||||
|
||||
@@ -33,6 +33,9 @@ pub(crate) use feed::{spell_action_icon, MISSING_ITEM_ICON};
|
||||
mod feed_tests;
|
||||
mod net;
|
||||
mod ranks;
|
||||
mod reactive;
|
||||
#[cfg(test)]
|
||||
mod reactive_tests;
|
||||
mod recount;
|
||||
pub(crate) use recount::recount_item_actions;
|
||||
mod state;
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
//! The reactive spells behind `SPELL_ACTIVE`: the list `[0xb71150]` (count `[0xb7114c]`) of known
|
||||
//! spells with `AttributesEx4 & 0x200`, which the usable refresh `0x4b31c0` re-checks after the bar
|
||||
//! (`0x4b31d7`-`0x4b323d`), raising `COMBAT_TEXT_UPDATE` `SPELL_ACTIVE` with the spell's name for
|
||||
//! each that turns usable (`0x4b320b`-`0x4b3226`), whether or not a bar holds it.
|
||||
|
||||
use std::collections::BTreeSet;
|
||||
|
||||
use benilla_formats::{SpellCatalog, SpellDisplay};
|
||||
|
||||
/// `AttributesEx4` bit 9 (`SpellRec+0x28`), which enters a learned spell in the list
|
||||
/// (`0x4b2702`-`0x4b270b`).
|
||||
const ATTR_EX4_REACTIVE: u32 = 0x200;
|
||||
|
||||
/// One entry: the spell it checks and the usable answer it last stored (`0x4b3231`).
|
||||
struct Entry {
|
||||
spell_id: u32,
|
||||
name: String,
|
||||
usable: bool,
|
||||
}
|
||||
|
||||
/// The list, one entry per spell name, the highest rank (`0x4b2720`-`0x4b2844`), each answer 0 when
|
||||
/// it enters (`0x4b27c7`). `0x4b23a0` empties it at the game's start (`0x48f59f` → `0x4b21c0`) and
|
||||
/// at the active player's arrival (`0x5dea86`); a `/reload` (`0x495664`) reaches neither.
|
||||
#[derive(Default)]
|
||||
pub(super) struct ReactiveList {
|
||||
entries: Vec<Entry>,
|
||||
}
|
||||
|
||||
/// One refresh's outcome.
|
||||
#[derive(Default)]
|
||||
pub(super) struct Refresh {
|
||||
/// Some entry's answer moved, either way: the refresh's `SPELL_UPDATE_USABLE` is due.
|
||||
pub(super) changed: bool,
|
||||
/// The names that turned usable, in list order, each a `SPELL_ACTIVE`.
|
||||
pub(super) activated: Vec<String>,
|
||||
}
|
||||
|
||||
impl ReactiveList {
|
||||
/// Empty the list: `0x4b23a0` at the active player's arrival.
|
||||
pub(super) fn arrive(&mut self) {
|
||||
self.entries.clear();
|
||||
}
|
||||
|
||||
/// Take in the book's reactive spells: a name the list lacks enters (`0x4b27b3`-`0x4b27c7`),
|
||||
/// and a held name moves to a strictly higher rank by `ParseSpellRank` (`0x4b3c30`, `0x4b2838`),
|
||||
/// keeping its answer (`0x4b2844`). Nothing leaves before the next arrival: unlearning
|
||||
/// (`0x4b2c50`) never touches the list.
|
||||
pub(super) fn sync(&mut self, book: &BTreeSet<u32>, catalog: &SpellCatalog) {
|
||||
for (id, d) in book
|
||||
.iter()
|
||||
.filter_map(|&id| catalog.get(id).map(|d| (id, d)))
|
||||
.filter(|(_, d)| d.attributes_ex4 & ATTR_EX4_REACTIVE != 0)
|
||||
{
|
||||
// `SStrCmp` (`0x64a480`) of the two names: case counts.
|
||||
match self.entries.iter_mut().find(|e| e.name == d.name) {
|
||||
Some(e) => {
|
||||
if catalog
|
||||
.get(e.spell_id)
|
||||
.is_none_or(|held| parse_rank(d) > parse_rank(held))
|
||||
{
|
||||
e.spell_id = id;
|
||||
}
|
||||
}
|
||||
None => self.entries.push(Entry {
|
||||
spell_id: id,
|
||||
name: d.name.clone(),
|
||||
usable: false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `0x4b31c0`'s loop: each entry's answer from `usable`, stored when it moved (`0x4b320b`,
|
||||
/// `0x4b3231`), and the names that turned usable.
|
||||
pub(super) fn refresh(&mut self, mut usable: impl FnMut(u32) -> bool) -> Refresh {
|
||||
let mut out = Refresh::default();
|
||||
for e in &mut self.entries {
|
||||
let now = usable(e.spell_id);
|
||||
if now == e.usable {
|
||||
continue;
|
||||
}
|
||||
out.changed = true;
|
||||
if now {
|
||||
out.activated.push(e.name.clone());
|
||||
}
|
||||
e.usable = now;
|
||||
}
|
||||
out
|
||||
}
|
||||
}
|
||||
|
||||
/// `ParseSpellRank` (`0x4b3c30`): the rank string's digits read as a number, ending at the first
|
||||
/// other character once the number is not 0 (`0x4b3c7e`), else the spell's `SpellLevel` (`+0x74`).
|
||||
fn parse_rank(d: &SpellDisplay) -> u32 {
|
||||
let mut n: u32 = 0;
|
||||
for c in d.rank.as_deref().unwrap_or_default().bytes() {
|
||||
if c.is_ascii_digit() {
|
||||
// `lea`, `lea`: 32-bit and wrapping.
|
||||
n = n.wrapping_mul(10).wrapping_add(u32::from(c - b'0'));
|
||||
} else if n != 0 {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
if n != 0 {
|
||||
n
|
||||
} else {
|
||||
d.spell_level
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,215 @@
|
||||
//! `SPELL_ACTIVE`, the reactive list's word (`0x4b31c0`), off the usable feed.
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
use benilla_formats::SpellDisplay;
|
||||
use benilla_protocol::ObjectFields;
|
||||
use benilla_ui::script::UiScript;
|
||||
|
||||
use super::{PlayerActions, Spells};
|
||||
use crate::net::{NetCommands, ObjectStore, SelfPlayer};
|
||||
|
||||
/// Two ranks of a reactive spell (`AttributesEx4 & 0x200`) that needs the defense aura state,
|
||||
/// and a plain spell.
|
||||
const REVENGE: u32 = 6572;
|
||||
const REVENGE_2: u32 = 6574;
|
||||
const FIREBALL: u32 = 133;
|
||||
|
||||
/// `UNIT_FIELD_AURASTATE`, whose bit 0 is the defense state Revenge needs.
|
||||
const AURA_STATE: u16 = 125;
|
||||
|
||||
/// The book holds the three, the bar nothing; the player alive, its aura state `aura_state`.
|
||||
fn app() -> App {
|
||||
let revenge = |id, rank: &str| {
|
||||
(
|
||||
id,
|
||||
SpellDisplay {
|
||||
id,
|
||||
name: "Revenge".into(),
|
||||
rank: Some(rank.into()),
|
||||
attributes_ex4: 0x200,
|
||||
caster_aura_state: 1,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
};
|
||||
let (tx, _rx) = crossbeam_channel::unbounded();
|
||||
let mut app = App::new();
|
||||
let mut actions = PlayerActions::default();
|
||||
actions.spells.extend([REVENGE, REVENGE_2, FIREBALL]);
|
||||
app.insert_resource(actions)
|
||||
.insert_resource(crate::ui_macro::MacroBoundSpells::default())
|
||||
.insert_resource(Spells {
|
||||
catalog: benilla_formats::SpellCatalog::from_displays(
|
||||
[
|
||||
revenge(REVENGE, "Rank 1"),
|
||||
revenge(REVENGE_2, "Rank 2"),
|
||||
(
|
||||
FIREBALL,
|
||||
SpellDisplay {
|
||||
id: FIREBALL,
|
||||
name: "Fireball".into(),
|
||||
..Default::default()
|
||||
},
|
||||
),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
..Spells::empty_for_tests()
|
||||
})
|
||||
.init_resource::<crate::player::Player>()
|
||||
.init_resource::<crate::spell::Cooldowns>()
|
||||
.init_resource::<crate::spell::SpellModifiers>()
|
||||
.init_resource::<crate::ui_script::UiClock>()
|
||||
.init_resource::<crate::spell::AutoRepeatActive>()
|
||||
.init_resource::<crate::spell::PendingCast>()
|
||||
.init_resource::<crate::spell::QueuedMeleeSpell>()
|
||||
.init_resource::<crate::spell::ActiveChannel>()
|
||||
.init_resource::<crate::spell::SpellTargeting>()
|
||||
.init_resource::<crate::spell::HeldForPick>()
|
||||
.init_resource::<crate::target::Selection>()
|
||||
.init_resource::<crate::net::GuidIndex>()
|
||||
.init_resource::<crate::net::Reputations>()
|
||||
.init_resource::<crate::items::Items>()
|
||||
// The leave-world sweep's latch and count, as the app holds them.
|
||||
.init_resource::<crate::ui_script::LeavingWorldArmed>()
|
||||
.init_resource::<crate::ui_script::SweptWorlds>()
|
||||
.insert_resource(NetCommands(tx));
|
||||
seat(&mut app);
|
||||
app.insert_non_send_resource(listener());
|
||||
app.add_systems(Update, super::state::feed_action_state);
|
||||
app
|
||||
}
|
||||
|
||||
/// Create the active player, as its arrival does, its world latch armed.
|
||||
fn seat(app: &mut App) {
|
||||
app.world_mut().spawn((
|
||||
SelfPlayer,
|
||||
Transform::default(),
|
||||
ObjectStore(ObjectFields::from_pairs(&[(22, 100), (23, 500)])),
|
||||
));
|
||||
app.world_mut()
|
||||
.resource_mut::<crate::ui_script::LeavingWorldArmed>()
|
||||
.arm();
|
||||
}
|
||||
|
||||
/// A VM that records the reactive word and the spells' usable event.
|
||||
fn listener() -> UiScript {
|
||||
let script = UiScript::new().unwrap();
|
||||
script
|
||||
.run(
|
||||
r#"
|
||||
HEARD = {}
|
||||
local f = CreateFrame("Frame")
|
||||
f:RegisterEvent("COMBAT_TEXT_UPDATE")
|
||||
f:RegisterEvent("SPELL_UPDATE_USABLE")
|
||||
f:SetScript("OnEvent", function()
|
||||
if event == "COMBAT_TEXT_UPDATE" then
|
||||
table.insert(HEARD, arg1 .. " " .. tostring(arg2))
|
||||
else
|
||||
table.insert(HEARD, event)
|
||||
end
|
||||
end)
|
||||
"#,
|
||||
)
|
||||
.unwrap();
|
||||
script
|
||||
}
|
||||
|
||||
/// Set the player's aura state and run the feed once: what the VM heard.
|
||||
fn step(app: &mut App, aura_state: u32) -> Vec<String> {
|
||||
let mut q = app
|
||||
.world_mut()
|
||||
.query_filtered::<&mut ObjectStore, With<SelfPlayer>>();
|
||||
let mut store = q.single_mut(app.world_mut()).unwrap();
|
||||
store.0 = ObjectFields::from_pairs(&[(22, 100), (23, 500), (AURA_STATE, aura_state)]);
|
||||
app.update();
|
||||
let mut s = app.world_mut().non_send_resource_mut::<UiScript>();
|
||||
s.resolve();
|
||||
s.eval::<Vec<String>>("local h = HEARD; HEARD = {}; return h")
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
/// `0x4b31c0` re-checks each reactive spell the book holds, one per name (`0x4b2720`-`0x4b2844`),
|
||||
/// whether or not a bar carries it, and raises `SPELL_ACTIVE` with its name on each turn to usable
|
||||
/// (`0x4b320b`-`0x4b3226`), ahead of `SPELL_UPDATE_USABLE` (`0x4b3246`); a plain spell never does.
|
||||
#[test]
|
||||
fn a_reactive_spell_turning_usable_raises_spell_active() {
|
||||
let mut app = app();
|
||||
assert!(
|
||||
!step(&mut app, 0)
|
||||
.iter()
|
||||
.any(|e| e.starts_with("SPELL_ACTIVE")),
|
||||
"not usable yet"
|
||||
);
|
||||
assert_eq!(
|
||||
step(&mut app, 0x1),
|
||||
["SPELL_ACTIVE Revenge", "SPELL_UPDATE_USABLE"],
|
||||
"one word for the two ranks, before the usable event"
|
||||
);
|
||||
assert!(step(&mut app, 0x1).is_empty(), "still usable: nothing");
|
||||
assert_eq!(
|
||||
step(&mut app, 0),
|
||||
["SPELL_UPDATE_USABLE"],
|
||||
"unusable again: the event, no word"
|
||||
);
|
||||
assert_eq!(
|
||||
step(&mut app, 0x1),
|
||||
["SPELL_ACTIVE Revenge", "SPELL_UPDATE_USABLE"]
|
||||
);
|
||||
}
|
||||
|
||||
/// A `/reload` (`0x495664` → `0x490bd0`, `0x48fbf0`) reaches neither of `0x4b23a0`'s callers, the
|
||||
/// game's start (`0x48f59f` → `0x4b21c0`) and the active player's arrival (`0x5dea86`), so the new
|
||||
/// VM hears no `SPELL_ACTIVE` for a spell already usable; a new arrival empties the list.
|
||||
#[test]
|
||||
fn a_reload_keeps_the_reactive_list_and_an_arrival_empties_it() {
|
||||
let mut app = app();
|
||||
assert_eq!(
|
||||
step(&mut app, 0x1),
|
||||
["SPELL_ACTIVE Revenge", "SPELL_UPDATE_USABLE"]
|
||||
);
|
||||
// The seated `/reload`: the leave-world sweep, then a new VM.
|
||||
assert!(crate::ui_script::run_leave_world_sweep(app.world_mut()));
|
||||
app.insert_non_send_resource(listener());
|
||||
assert!(step(&mut app, 0x1).is_empty(), "the list kept its answer");
|
||||
|
||||
let mut me = app.world_mut().query_filtered::<Entity, With<SelfPlayer>>();
|
||||
let me = me.single(app.world()).unwrap();
|
||||
app.world_mut().despawn(me);
|
||||
seat(&mut app);
|
||||
assert_eq!(
|
||||
step(&mut app, 0x1),
|
||||
["SPELL_ACTIVE Revenge", "SPELL_UPDATE_USABLE"],
|
||||
"a new arrival starts the list over"
|
||||
);
|
||||
}
|
||||
|
||||
/// The list's only writers are its clear, its add (`0x4b27b3`-`0x4b27c7`), its rank move
|
||||
/// (`0x4b2844`) and the refresh (`0x4b3231`); unlearning (`0x4b2c50`) never touches it, so an
|
||||
/// entry and its answer outlive the spell leaving the book, and relearning a rank no higher moves
|
||||
/// nothing (`0x4b2838`).
|
||||
#[test]
|
||||
fn the_reactive_list_keeps_a_spell_the_book_lost() {
|
||||
let mut app = app();
|
||||
assert_eq!(
|
||||
step(&mut app, 0x1),
|
||||
["SPELL_ACTIVE Revenge", "SPELL_UPDATE_USABLE"]
|
||||
);
|
||||
fn spells(app: &mut App) -> Mut<'_, PlayerActions> {
|
||||
app.world_mut().resource_mut::<PlayerActions>()
|
||||
}
|
||||
spells(&mut app).spells.retain(|id| *id == FIREBALL);
|
||||
assert!(step(&mut app, 0x1).is_empty(), "both ranks unlearned");
|
||||
spells(&mut app).spells.insert(REVENGE);
|
||||
assert!(
|
||||
step(&mut app, 0x1).is_empty(),
|
||||
"rank 1 relearned: the entry kept its answer, no second word"
|
||||
);
|
||||
assert_eq!(
|
||||
step(&mut app, 0),
|
||||
["SPELL_UPDATE_USABLE"],
|
||||
"the kept entry still checks"
|
||||
);
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
//! `IsCurrentAction` and `GetActionCooldown`, diff-pushed into the VM with the reference's events
|
||||
//! on each change: the cooldown trio (`0x4b31b0`, `0x4f93d0`), the usable pair (`0x4b31c0`, on a
|
||||
//! cache change only, `0x4e5c00`), combat enter and leave (`0x6256ff`, `0x625778`), and
|
||||
//! autorepeat start and stop (`0x6e5952`, `0x6ea170`). `IsCurrentAction` reads the cast state
|
||||
//! autorepeat start and stop (`0x6e5952`, `0x6ea170`), and between the usable pair each reactive
|
||||
//! spell's `SPELL_ACTIVE` ([`super::reactive`]). `IsCurrentAction` reads the cast state
|
||||
//! live, and its pair (`0x4b3250`) is signalled where the cast changes ([`crate::ui_cast`]).
|
||||
//! Usability is `IsSpellUsableNow 0x6e3d60` ([`crate::spell::usable`]), auto-repeat the `0xceac30`
|
||||
//! key, and range the squared distance against `GetMinMaxRange 0x6e3480`.
|
||||
@@ -101,7 +102,7 @@ pub(super) fn feed_action_state(
|
||||
clock: Res<crate::ui_script::UiClock>,
|
||||
auto_repeat: Res<AutoRepeatActive>,
|
||||
// One tuple for Bevy's 16-param ceiling: macro bindings, spell mods, the range units, the
|
||||
// control flag and the skill lines.
|
||||
// control flag, the skill lines and the active player's creation.
|
||||
cast_state: (
|
||||
Res<crate::ui_macro::MacroBoundSpells>,
|
||||
Res<crate::spell::SpellModifiers>,
|
||||
@@ -112,6 +113,8 @@ pub(super) fn feed_action_state(
|
||||
// A profession opener's line (`0x6de040`), which the checked test reads, and the skill
|
||||
// lines the walk's cost finds its level through.
|
||||
Option<Res<crate::ui_spellbook::SkillLines>>,
|
||||
// The active player's creation, whose arrival (`0x5dea86`) empties the reactive list.
|
||||
Query<(), Added<SelfPlayer>>,
|
||||
),
|
||||
self_q: Query<(&ObjectStore, &Transform, Has<Engaged>), With<SelfPlayer>>,
|
||||
selection: Res<Selection>,
|
||||
@@ -122,6 +125,8 @@ pub(super) fn feed_action_state(
|
||||
items: Res<Items>,
|
||||
commands: Res<NetCommands>,
|
||||
mut memory: Local<crate::ui_script::VmMemo<StateMemory>>,
|
||||
// The reactive list, which lives from one arrival to the next, not for a VM.
|
||||
mut reactive: Local<super::reactive::ReactiveList>,
|
||||
) {
|
||||
let Some(mut script) = script else {
|
||||
return;
|
||||
@@ -143,7 +148,7 @@ pub(super) fn feed_action_state(
|
||||
memory.last_cd_trace = Some(now);
|
||||
}
|
||||
|
||||
let (bound, spell_mods, range_units, player, skill_lines) = &cast_state;
|
||||
let (bound, spell_mods, range_units, player, skill_lines, created) = &cast_state;
|
||||
let skill_catalog = skill_lines.as_deref().map(|s| &s.catalog);
|
||||
let me = self_q.iter().next();
|
||||
let control_lost = player.as_ref().is_some_and(|p| p.own_control_lost);
|
||||
@@ -353,14 +358,53 @@ pub(super) fn feed_action_state(
|
||||
}
|
||||
memory.pushed = fresh;
|
||||
|
||||
// The reactive list's re-check (`0x4b31d7`-`0x4b323d`), on the walk the bar takes.
|
||||
let list = &mut *reactive;
|
||||
let arrived = !created.is_empty();
|
||||
if arrived {
|
||||
list.arrive();
|
||||
}
|
||||
if let Some(sp) = spells.as_deref() {
|
||||
if arrived || actions.is_changed() || spells.as_ref().is_some_and(|s| s.is_changed()) {
|
||||
list.sync(&actions.spells, &sp.catalog);
|
||||
}
|
||||
}
|
||||
let reactive = match (me, spells.as_deref()) {
|
||||
(Some((store, _, _)), Some(sp)) => {
|
||||
let ctx = usable::UsableCtx {
|
||||
store,
|
||||
target: selection.guid.zip(target.map(|(s, _)| s)),
|
||||
rel: relations.get(),
|
||||
cooldowns: &cooldowns,
|
||||
stacks: &stacks,
|
||||
spell_mods,
|
||||
control_lost,
|
||||
skill_lines: skill_catalog,
|
||||
};
|
||||
list.refresh(|id| {
|
||||
sp.catalog
|
||||
.get(id)
|
||||
.is_some_and(|d| usable::spell_usable(id, d, sp, &ctx, &objects, &items).0)
|
||||
})
|
||||
}
|
||||
_ => super::reactive::Refresh::default(),
|
||||
};
|
||||
|
||||
// The events in the reference's flush order, the `ACTIONBAR_*` one first.
|
||||
if gen_changed {
|
||||
script.fire_event("ACTIONBAR_UPDATE_COOLDOWN", vec![]);
|
||||
script.fire_event("SPELL_UPDATE_COOLDOWN", vec![]);
|
||||
script.fire_event("BAG_UPDATE_COOLDOWN", vec![]);
|
||||
}
|
||||
// `0x4b31c0`: the bar's event on a slot change (`0x4e5c53`), each reactive spell's word as it
|
||||
// turns usable (`0x4b3226`), then the spells' event (`0x4b3246`).
|
||||
if usable_changed {
|
||||
script.fire_event("ACTIONBAR_UPDATE_USABLE", vec![]);
|
||||
}
|
||||
for name in reactive.activated {
|
||||
crate::ui_unit::fire_combat_text(&mut script, "SPELL_ACTIVE", Some(name), None);
|
||||
}
|
||||
if usable_changed || reactive.changed {
|
||||
script.fire_event("SPELL_UPDATE_USABLE", vec![]);
|
||||
}
|
||||
if engaged != memory.engaged {
|
||||
|
||||
@@ -1019,6 +1019,19 @@ impl LineWord {
|
||||
}
|
||||
}
|
||||
|
||||
/// The type, a text and a number (`0x626890`).
|
||||
pub(crate) fn text_number(
|
||||
message_type: &'static str,
|
||||
text: impl ToString,
|
||||
n: impl ToString,
|
||||
) -> Self {
|
||||
Self {
|
||||
message_type,
|
||||
data: WordText::Text(Some(text.to_string())),
|
||||
extra: Some(n.to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
/// The type, the name the line gives its subject, and a number (`0x626890`).
|
||||
pub(crate) fn named(message_type: &'static str, extra: impl ToString) -> Self {
|
||||
Self {
|
||||
|
||||
@@ -120,9 +120,10 @@ pub(crate) fn spell_hit_word(damage: u32, absorbed: u32, resisted: i32, blocked:
|
||||
}
|
||||
}
|
||||
|
||||
/// A periodic damage tick's word, once damage got through (`0x628100`), in the melee types: the
|
||||
/// first of resisted (`0x628354`) and absorbed (`0x62836c`), else the damage (`0x62837f`).
|
||||
pub(crate) fn periodic_hit_word(damage: u32, absorbed: u32, resisted: i32) -> LineWord {
|
||||
/// The word of a hit taken in the melee types, a periodic damage tick once damage got through
|
||||
/// (`0x628100`) and an environmental hit (`0x62aac0`): the first of resisted above 0 (`0x628354`,
|
||||
/// `0x62ac78`) and absorbed (`0x62836c`, `0x62ac95`), else the damage (`0x62837f`, `0x62acad`).
|
||||
pub(crate) fn damage_word(damage: u32, absorbed: u32, resisted: i32) -> LineWord {
|
||||
if resisted > 0 {
|
||||
LineWord::pair("RESIST", damage, resisted)
|
||||
} else if absorbed != 0 {
|
||||
@@ -132,10 +133,11 @@ pub(crate) fn periodic_hit_word(damage: u32, absorbed: u32, resisted: i32) -> Li
|
||||
}
|
||||
}
|
||||
|
||||
/// A power gain's word (`0x627520`): the power's noun key (table `0x85645c`) compared against
|
||||
/// `MANA_POINTS`, `RAGE_POINTS`, `FOCUS_POINTS` and `ENERGY_POINTS` (`0x6276f0`-`0x62779d`), each
|
||||
/// its own type; `HAPPINESS_POINTS` matches none and has no word.
|
||||
pub(crate) fn power_gain_word(power: u32, amount: i64) -> Option<LineWord> {
|
||||
/// A power gain's word with the amount gained (`0x627520`), and a drain's or leech's with minus
|
||||
/// the amount drained (`0x627930`): the power's noun key (table `0x85645c`) compared against
|
||||
/// `MANA_POINTS`, `RAGE_POINTS`, `FOCUS_POINTS` and `ENERGY_POINTS` (`0x6276f0`-`0x62779d`,
|
||||
/// `0x627b9f`-`0x627c5c`), each its own type; `HAPPINESS_POINTS` matches none and has no word.
|
||||
pub(crate) fn power_amount_word(power: u32, amount: i64) -> Option<LineWord> {
|
||||
let message_type = match power {
|
||||
0 => "MANA",
|
||||
1 => "RAGE",
|
||||
|
||||
@@ -139,14 +139,11 @@ fn a_direct_spell_hit_words_its_first_partial() {
|
||||
#[test]
|
||||
fn a_periodic_tick_words_resist_absorb_damage() {
|
||||
assert_eq!(
|
||||
periodic_hit_word(300, 50, 100),
|
||||
damage_word(300, 50, 100),
|
||||
LineWord::pair("RESIST", 300, 100)
|
||||
);
|
||||
assert_eq!(
|
||||
periodic_hit_word(300, 50, 0),
|
||||
LineWord::pair("ABSORB", 300, 50)
|
||||
);
|
||||
assert_eq!(periodic_hit_word(300, 0, 0), LineWord::with("DAMAGE", 300));
|
||||
assert_eq!(damage_word(300, 50, 0), LineWord::pair("ABSORB", 300, 50));
|
||||
assert_eq!(damage_word(300, 0, 0), LineWord::with("DAMAGE", 300));
|
||||
}
|
||||
|
||||
/// The spell-miss word per code, as the jump table `0x62be10`, carrying the spell's name: absorb
|
||||
@@ -184,7 +181,7 @@ fn a_spell_miss_words_its_code_with_the_spell_name() {
|
||||
/// `HAPPINESS_POINTS` is no type of `0x862920`: a happiness gain has a line and no word.
|
||||
#[test]
|
||||
fn a_happiness_gain_has_no_word() {
|
||||
assert_eq!(power_gain_word(0, 300), Some(LineWord::with("MANA", 300)));
|
||||
assert_eq!(power_gain_word(3, 20), Some(LineWord::with("ENERGY", 20)));
|
||||
assert_eq!(power_gain_word(4, 1), None);
|
||||
assert_eq!(power_amount_word(0, 300), Some(LineWord::with("MANA", 300)));
|
||||
assert_eq!(power_amount_word(3, 20), Some(LineWord::with("ENERGY", 20)));
|
||||
assert_eq!(power_amount_word(4, 1), None);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ use bevy::prelude::*;
|
||||
|
||||
use super::{
|
||||
aura_gone_kind, classify, death_kind, in_range, periodic_kind, CombatLogRanges, Family, Fills,
|
||||
Named, PendingCombat, UnitClass, Variant,
|
||||
LineWord, Named, PendingCombat, UnitClass, Variant,
|
||||
};
|
||||
use crate::net::{FieldChanged, GuidIndex, ObjectStore, Reputations, SelfGuid};
|
||||
use crate::target::ring::Factions;
|
||||
@@ -49,6 +49,14 @@ impl WatchCtx<'_> {
|
||||
super::logged_spell(self.spells.as_deref(), spell_id).map(|d| d.name.clone())
|
||||
}
|
||||
|
||||
/// [`Self::spell_name`] for the aura formatter `0x62b480`, which also writes nothing for a
|
||||
/// passive spell (`Attributes & 0x40`, `0x62b4fb`).
|
||||
fn aura_spell_name(&self, spell_id: u32) -> Option<String> {
|
||||
super::logged_spell(self.spells.as_deref(), spell_id)
|
||||
.filter(|d| d.attributes & ATTR_PASSIVE == 0)
|
||||
.map(|d| d.name.clone())
|
||||
}
|
||||
|
||||
/// The one-sided range test 15 reference formatters run in place of the two-ended `0x626630`.
|
||||
/// The death line passes `CombatDeathLogRange`, which `0x62c160` reads at `0x62c19c`; the aura
|
||||
/// lines pass their class's range.
|
||||
@@ -57,7 +65,11 @@ impl WatchCtx<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Queue one single-endpoint line, gated the way its formatter gates.
|
||||
/// `SPELL_ATTR_PASSIVE`, `Attributes` bit 6 (vmangos `SpellDefines.h:798`).
|
||||
const ATTR_PASSIVE: u32 = 0x40;
|
||||
|
||||
/// Queue one single-endpoint line, gated the way its formatter gates, with the word it raises once
|
||||
/// written.
|
||||
fn queue_one(
|
||||
log: &mut ChatLog,
|
||||
ctx: &WatchCtx,
|
||||
@@ -67,7 +79,7 @@ fn queue_one(
|
||||
subject: (u64, UnitClass),
|
||||
range: f32,
|
||||
fills: Fills,
|
||||
named: Named,
|
||||
word: Option<LineWord>,
|
||||
) {
|
||||
if !ctx.in_range(subject.0, range, poses) {
|
||||
return;
|
||||
@@ -79,9 +91,9 @@ fn queue_one(
|
||||
subject: subject.0,
|
||||
object: 0,
|
||||
fills,
|
||||
named,
|
||||
named: Named::Ready,
|
||||
tries: 0,
|
||||
word: None,
|
||||
word,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -133,7 +145,7 @@ pub(crate) fn death_lines(
|
||||
(guid, class),
|
||||
ctx.ranges.death(),
|
||||
Fills::default(),
|
||||
Named::Ready,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -148,7 +160,11 @@ pub(crate) fn death_lines(
|
||||
/// `AURAAPPLICATIONADDED*` (`0x604ea0`). The reference gates it on `StackAmount > 1`, which
|
||||
/// holds for any count that rises; a first application moves the spell, so it is skipped.
|
||||
///
|
||||
/// Harmful is the slot index, `0x20`-`0x2f` (`0x61238e`), not `UNIT_FIELD_AURAFLAGS`.
|
||||
/// Harmful is the slot index, `0x20`-`0x2f` (`0x61238e`), not `UNIT_FIELD_AURAFLAGS`. A line on
|
||||
/// you raises `AURA_START` or `AURA_START_HARMFUL` for an arrival and `AURA_END` or
|
||||
/// `AURA_END_HARMFUL` for a loss, with the spell's name (`0x62b74f`-`0x62b7ac`); a stack line
|
||||
/// raises none. An arrival or a loss writes nothing for a passive spell, and a loss nothing on a
|
||||
/// unit with no health (`0x62b503`-`0x62b515`), so the auras death strips leave silently.
|
||||
pub(crate) fn aura_lines(
|
||||
ctx: WatchCtx,
|
||||
stores: Query<(Entity, &ObjectStore)>,
|
||||
@@ -178,33 +194,49 @@ pub(crate) fn aura_lines(
|
||||
for e in &slot_edges {
|
||||
let slot = e.index - FIELD_UNIT_AURA;
|
||||
let class = ctx.classify(e.guid, &stores);
|
||||
let word = |message_type: &'static str, spell: &str| {
|
||||
(class == UnitClass::Me).then(|| LineWord::with(message_type, spell))
|
||||
};
|
||||
// Arrival first, so a replace words the new aura before the old one's removal.
|
||||
if e.new != 0 {
|
||||
if let (Some(spell), Some(kind)) =
|
||||
(ctx.spell_name(e.new), periodic_kind(class, !harmful(slot)))
|
||||
{
|
||||
if let (Some(spell), Some(kind)) = (
|
||||
ctx.aura_spell_name(e.new),
|
||||
periodic_kind(class, !harmful(slot)),
|
||||
) {
|
||||
let (family, message_type) = if harmful(slot) {
|
||||
(super::AURAADDED_HARMFUL, "AURA_START_HARMFUL")
|
||||
} else {
|
||||
(super::AURAADDED_HELPFUL, "AURA_START")
|
||||
};
|
||||
let word = word(message_type, &spell);
|
||||
queue_one(
|
||||
&mut log,
|
||||
&ctx,
|
||||
&poses,
|
||||
kind,
|
||||
if harmful(slot) {
|
||||
super::AURAADDED_HARMFUL
|
||||
} else {
|
||||
super::AURAADDED_HELPFUL
|
||||
},
|
||||
family,
|
||||
(e.guid, class),
|
||||
ctx.ranges.class(class),
|
||||
Fills {
|
||||
spell,
|
||||
..Default::default()
|
||||
},
|
||||
Named::Ready,
|
||||
word,
|
||||
);
|
||||
}
|
||||
}
|
||||
if e.old != 0 {
|
||||
if let Some(spell) = ctx.spell_name(e.old) {
|
||||
// The health is read signed (`0x62b50e`, `jg`).
|
||||
let alive = stores
|
||||
.get(e.entity)
|
||||
.is_ok_and(|(_, st)| st.0.unit_health().unwrap_or(0) as i32 > 0);
|
||||
if e.old != 0 && alive {
|
||||
if let Some(spell) = ctx.aura_spell_name(e.old) {
|
||||
let message_type = if harmful(slot) {
|
||||
"AURA_END_HARMFUL"
|
||||
} else {
|
||||
"AURA_END"
|
||||
};
|
||||
let word = word(message_type, &spell);
|
||||
queue_one(
|
||||
&mut log,
|
||||
&ctx,
|
||||
@@ -217,7 +249,7 @@ pub(crate) fn aura_lines(
|
||||
spell,
|
||||
..Default::default()
|
||||
},
|
||||
Named::Ready,
|
||||
word,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -266,7 +298,7 @@ pub(crate) fn aura_lines(
|
||||
amount: i64::from(now + 1),
|
||||
..Default::default()
|
||||
},
|
||||
Named::Ready,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -310,3 +342,6 @@ pub(crate) fn pet_loyalty_lines(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
@@ -0,0 +1,149 @@
|
||||
//! The aura lines' words and gates (`0x62b480`).
|
||||
|
||||
use bevy::ecs::system::RunSystemOnce;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use benilla_protocol::field::FIELD_UNIT_AURA;
|
||||
use benilla_protocol::messages::ObjectType;
|
||||
|
||||
use crate::net::{FieldChanged, GuidIndex, ObjectStore, Reputations, SelfGuid};
|
||||
use crate::ui_chat::combat::{CombatLogRanges, LineWord};
|
||||
use crate::ui_chat::ChatLog;
|
||||
|
||||
const ME: u64 = 1;
|
||||
const MOB: u64 = 2;
|
||||
const FORTITUDE: u32 = 1243;
|
||||
const CORRUPTION: u32 = 172;
|
||||
/// `Attributes & 0x40`, a passive spell that a slot can still hold.
|
||||
const PASSIVE: u32 = 20_000;
|
||||
|
||||
/// You and a creature, alive or dead, the three spells known, the log empty.
|
||||
fn world(health: u32) -> App {
|
||||
let display = |id, name: &str, attributes| {
|
||||
(
|
||||
id,
|
||||
benilla_formats::SpellDisplay {
|
||||
id,
|
||||
name: name.into(),
|
||||
attributes,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
};
|
||||
let mut app = App::new();
|
||||
app.add_message::<FieldChanged>()
|
||||
.init_resource::<GuidIndex>()
|
||||
.init_resource::<crate::ui_party::GroupState>()
|
||||
.init_resource::<Reputations>()
|
||||
.init_resource::<CombatLogRanges>()
|
||||
.init_resource::<ChatLog>()
|
||||
.insert_resource(SelfGuid(Some(ME)))
|
||||
.insert_resource(crate::ui_action::Spells {
|
||||
catalog: benilla_formats::SpellCatalog::from_displays(
|
||||
[
|
||||
display(FORTITUDE, "Power Word: Fortitude", 0),
|
||||
display(CORRUPTION, "Corruption", 0),
|
||||
display(PASSIVE, "Passive", 0x40),
|
||||
]
|
||||
.into_iter()
|
||||
.collect(),
|
||||
),
|
||||
..crate::ui_action::Spells::empty_for_tests()
|
||||
});
|
||||
for (guid, kind) in [(ME, 0x19), (MOB, 0x09)] {
|
||||
let e = app
|
||||
.world_mut()
|
||||
.spawn((
|
||||
Transform::default(),
|
||||
ObjectStore(benilla_protocol::ObjectFields::from_pairs(&[
|
||||
(2, kind),
|
||||
(22, health),
|
||||
])),
|
||||
))
|
||||
.id();
|
||||
app.world_mut()
|
||||
.resource_mut::<GuidIndex>()
|
||||
.0
|
||||
.insert(guid, e);
|
||||
}
|
||||
app
|
||||
}
|
||||
|
||||
/// One aura slot of `guid` moving from `old` to `new`: each line's family stem and word.
|
||||
fn slot(health: u32, guid: u64, slot: u16, old: u32, new: u32) -> Vec<(String, Option<LineWord>)> {
|
||||
let mut app = world(health);
|
||||
let entity = app.world().resource::<GuidIndex>().0[&guid];
|
||||
app.world_mut().write_message(FieldChanged {
|
||||
entity,
|
||||
guid,
|
||||
kind: if guid == ME {
|
||||
ObjectType::Player
|
||||
} else {
|
||||
ObjectType::Unit
|
||||
},
|
||||
index: FIELD_UNIT_AURA + slot,
|
||||
old,
|
||||
new,
|
||||
});
|
||||
app.world_mut().run_system_once(super::aura_lines).unwrap();
|
||||
app.world()
|
||||
.resource::<ChatLog>()
|
||||
.pending_combat()
|
||||
.into_iter()
|
||||
.map(|l| (l.family.key(l.variant), l.word.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// `0x62b480` raises `AURA_START`, `AURA_START_HARMFUL`, `AURA_END` or `AURA_END_HARMFUL` with the
|
||||
/// spell's name after its line on you (`0x62b74f`-`0x62b7ac`); harmful is slots 32 to 47
|
||||
/// (`0x61238e`).
|
||||
#[test]
|
||||
fn an_aura_on_you_raises_its_start_or_end_word() {
|
||||
let word = |m, s| Some(LineWord::with(m, s));
|
||||
assert_eq!(
|
||||
slot(100, ME, 0, 0, FORTITUDE),
|
||||
[(
|
||||
"AURAADDEDSELFHELPFUL".into(),
|
||||
word("AURA_START", "Power Word: Fortitude")
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
slot(100, ME, 0x20, 0, CORRUPTION),
|
||||
[(
|
||||
"AURAADDEDSELFHARMFUL".into(),
|
||||
word("AURA_START_HARMFUL", "Corruption")
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
slot(100, ME, 0, FORTITUDE, 0),
|
||||
[(
|
||||
"AURAREMOVEDSELF".into(),
|
||||
word("AURA_END", "Power Word: Fortitude")
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
slot(100, ME, 0x2f, CORRUPTION, 0),
|
||||
[(
|
||||
"AURAREMOVEDSELF".into(),
|
||||
word("AURA_END_HARMFUL", "Corruption")
|
||||
)]
|
||||
);
|
||||
assert_eq!(
|
||||
slot(100, MOB, 0, 0, FORTITUDE),
|
||||
[("AURAADDEDOTHERHELPFUL".into(), None)]
|
||||
);
|
||||
}
|
||||
|
||||
/// `0x62b480` writes nothing for a passive spell (`Attributes & 0x40`, `0x62b4fb`), and nothing for
|
||||
/// an aura leaving a unit with no health (`0x62b503`-`0x62b515`): no line and no word.
|
||||
#[test]
|
||||
fn a_passive_aura_or_one_leaving_the_dead_writes_nothing() {
|
||||
assert!(slot(100, ME, 0, 0, PASSIVE).is_empty());
|
||||
assert!(slot(100, ME, 0, PASSIVE, 0).is_empty());
|
||||
assert!(slot(0, ME, 0, FORTITUDE, 0).is_empty(), "dead");
|
||||
assert_eq!(
|
||||
slot(0, ME, 0, 0, FORTITUDE).len(),
|
||||
1,
|
||||
"an arrival on the dead still writes"
|
||||
);
|
||||
}
|
||||
@@ -216,6 +216,8 @@ mod tests {
|
||||
("ui_script/extract/mod.rs", "last_seam"),
|
||||
// The plate driver's anti-overlap scratch, cleared at the top of every run.
|
||||
("vplates.rs", "bucket"),
|
||||
// The floating text's, likewise; its system reads the VM for the outcome words.
|
||||
("combat_text/mod.rs", "bucket"),
|
||||
// The window's scale factor, which gates the same re-seat as `last_seam`.
|
||||
("ui_script/extract/mod.rs", "last_dpi"),
|
||||
// Pushed unconditionally every frame; there is nothing remembered to go stale.
|
||||
@@ -238,6 +240,9 @@ mod tests {
|
||||
// The glue booth's stage numbers, which must outlive the VM: a scene parked under the old
|
||||
// VM keeps its number until the booth drops it, so a new VM's scenes take fresh ones.
|
||||
("ui_script/glue_scene.rs", "top"),
|
||||
// The reactive spells' list, engine state the reference keeps past a `/reload` and empties
|
||||
// at the active player's arrival (`0x5dea86`), on whose creation the system clears it.
|
||||
("ui_action/state.rs", "reactive"),
|
||||
];
|
||||
|
||||
use crate::test_support::{fn_parameter_lists, rust_files};
|
||||
|
||||
@@ -388,42 +388,6 @@ fn load_exhaustion_rows(
|
||||
}
|
||||
}
|
||||
|
||||
/// Melee swing to the `UNIT_COMBAT` action (victim-state table `0x83de28`, `0x4946d0`) and
|
||||
/// descriptor, HitInfo keyed on the amount's sign: above zero CRITICAL `0x80`, GLANCING `0x4000`,
|
||||
/// CRUSHING `0x8000`; else ABSORB `0x20`, BLOCK `0x800`, RESIST `0x40`.
|
||||
fn melee_feedback(hit_info: u32, victim_state: u32, damage: u32) -> (&'static str, &'static str) {
|
||||
match victim_state {
|
||||
2 => ("DODGE", ""),
|
||||
3 => ("PARRY", ""),
|
||||
5 => ("BLOCK", ""),
|
||||
6 => ("EVADE", ""),
|
||||
7 => ("IMMUNE", ""),
|
||||
8 => ("DEFLECT", ""),
|
||||
// 0 UNAFFECTED / 1 NORMAL / 4 INTERRUPT: WOUND, descriptor by the amount-sign key.
|
||||
_ => {
|
||||
if damage > 0 {
|
||||
if hit_info & 0x80 != 0 {
|
||||
("WOUND", "CRITICAL")
|
||||
} else if hit_info & 0x4000 != 0 {
|
||||
("WOUND", "GLANCING")
|
||||
} else if hit_info & 0x8000 != 0 {
|
||||
("WOUND", "CRUSHING")
|
||||
} else {
|
||||
("WOUND", "")
|
||||
}
|
||||
} else if hit_info & 0x20 != 0 {
|
||||
("WOUND", "ABSORB")
|
||||
} else if hit_info & 0x800 != 0 {
|
||||
("WOUND", "BLOCK") // a full block `0x625e20` did not mark
|
||||
} else if hit_info & 0x40 != 0 {
|
||||
("WOUND", "RESIST")
|
||||
} else {
|
||||
("MISS", "")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A swing's `UNIT_COMBAT` on its victim, as `FloatSwingResult 0x6243e0` raises it (`0x4946d0`, at
|
||||
/// `0x6244bf` and `0x624518`), queued in the chat drain where its caller stands: for a displayed
|
||||
/// swing only (`0x625e40`, which returns at `0x624414` past both the number and the event), on a
|
||||
@@ -442,19 +406,13 @@ pub(crate) fn melee_unit_combat(
|
||||
let Some((guid, _)) = victim.filter(|(_, store)| crate::ui_chat::combat::is_unit(store)) else {
|
||||
return;
|
||||
};
|
||||
let (action, flags) = melee_feedback(s.hit_info, s.victim_state, s.damage);
|
||||
log.push_unit_combat(UnitCombatFeedback {
|
||||
guid,
|
||||
action,
|
||||
flags,
|
||||
amount: s.damage,
|
||||
school: 0, // the reference passes sub-damage 0's school (`0x4946fc`), not carried here
|
||||
});
|
||||
crate::combat_log::feedback::swing(log, guid, s.victim_state, s.hit_info, s.damage);
|
||||
}
|
||||
|
||||
/// `COMBAT_TEXT_UPDATE(messageType, data, extra)` (event `0x21e`, through the five helpers
|
||||
/// `0x626890`-`0x6269d0`): `data` and `extra` are `arg2` and `arg3`, nil when absent. Each combat-log
|
||||
/// formatter raises it right after its line, so the line's drain fires it.
|
||||
/// formatter raises it right after its line, so the line's drain fires it; the usable refresh
|
||||
/// raises `SPELL_ACTIVE` (`0x4b3226`).
|
||||
pub(crate) fn fire_combat_text(
|
||||
script: &mut UiScript,
|
||||
message_type: &str,
|
||||
|
||||
+1
-1
@@ -102,7 +102,7 @@ Each entry is the first sentence of a `Deviation:` comment, linking to where it
|
||||
|
||||
#### combat_text
|
||||
|
||||
- The reference stretches a raster of at most 32 px; each whole-pixel size is rasterized here, so the crit pop stays crisp. ([`src/combat_text/mod.rs:244`](../crates/benilla-app/src/combat_text/mod.rs#L244))
|
||||
- The reference stretches a raster of at most 32 px; each whole-pixel size is rasterized here, so the crit pop stays crisp. ([`src/combat_text/mod.rs:264`](../crates/benilla-app/src/combat_text/mod.rs#L264))
|
||||
|
||||
#### console
|
||||
|
||||
|
||||
Reference in New Issue
Block a user