feat(model): ModelScene actors draw the ranged weapon and dual wield

A ranged or auto-repeat spell's start now sets the caster's sheathe
state 2 at once, as HandleSpellStart (0x006E78F3) does through
SetSheatheState (0x00611CF0, (2, 1, 1)): the ranged lane hangs in its
hand and the other held item at its sheath point. A unit that is not
the active player keeps state 2 through its later animations
(0x005FDF80 asks for 2 again), so the actor keeps it until SetSheathed,
SetModelByUnit or a new model. Every re-hang (SetSheathed, the sheathe
categories, a try-on) honours it per lane, so a sheathed bow now comes
to hand for the shot and BowPull finds it there.

An actor that shows a creature display or a model file now holds two
one-hand weapons. DressUpModel's TryOnItem asks the active player's
dual-wield skill (0x005EAB70) only when it shows that player and
refuses a second one-hander on any other model; the world draws a
creature's two weapons regardless. An actor that shows a unit keeps the
dressing room's rule.
This commit is contained in:
Brues
2026-11-09 11:51:31 -06:00
parent 4294a2bbfa
commit 1148be8cdc
4 changed files with 54 additions and 17 deletions
+5
View File
@@ -6376,6 +6376,11 @@ enum Offsets {
// right hand (attachment 1) for the main-hand lane and the left (2) for
// the off hand (AttachItemModel 0x0047A0C0).
FUN_M2MODEL_HAS_ANIMATION = 0x00711960,
// A ranged or auto-repeat spell's start sets the caster's sheathe state
// to 2 at once (HandleSpellStart 0x006E78F3: SetSheatheState 0x00611CF0
// with (2, 1, 1)): the ranged weapon in hand, the melee weapons on their
// sheath points. A unit that is not the active player keeps state 2
// through its later animations (0x005FDF80 asks for 2 again).
// IsDeathAnimation `int __stdcall(int anim)`, ret 4 (a jump table). A
// dead unit plays only death animations: CGUnit_C::PlayAnimation
// (0x005FE2F0) returns for health below 1 unless the animation is one.
+11 -1
View File
@@ -99,8 +99,14 @@ class Actor : public Animation::Object {
// Shows a copy of the unit's model, dressed and armed per autoDress,
// sheathed and hideWeapons; false (and no model) when it has none.
bool SetUnitModel(uint64_t guid);
// Hangs the held items per sheathed and hideWeapons.
// Hangs the held items per sheathed and hideWeapons, or drawn for a
// ranged shot.
void ApplyWeapons();
// A ranged spell's start: the ranged weapon in hand, the other held item
// sheathed, until SetSheathed or a new model.
void DrawRanged();
// Whether lane `i` hangs at its sheath point.
bool LaneSheathed(int i) const;
// Puts the item on the model (Outfit::TryOn), once the model has loaded
// and the item's record is cached; returns the ItemTryOnReason.
int TryOnItem(const Model::TryOn::Request &request);
@@ -132,6 +138,7 @@ class Actor : public Animation::Object {
bool autoDress = true;
bool sheathed = false;
bool hideWeapons = false;
bool rangedDrawn = false; // the unit's sheathe state 2
// Per lane: the SetSheathedCategory category (Outfit::SheatheCategory),
// and the sheathe type the lane's item has of its own. The lane itself
// holds the type it hangs with.
@@ -198,6 +205,9 @@ class Actor : public Animation::Object {
// The spell visuals an actor casts (model/SceneSpell.cpp).
namespace Casts {
// The held item the caster shoots with (an INVTYPE_RANGED, THROWN or
// RANGEDRIGHT lane), or -1.
int RangedLane(const Actor &caster);
// Starts the cast; false when the spell, its visual or the caster's model is
// missing. `castTimeMs` < 0 takes the spell's cast time.
bool Play(Actor &caster, uint32_t spellID, Actor *target, int castTimeMs);
+24 -2
View File
@@ -240,6 +240,7 @@ void ReleaseModel(Actor &actor) {
actor.unitGuid = 0;
actor.lanes[0] = actor.lanes[1] = Outfit::HeldLane{};
actor.weapons = Outfit::Weapons{};
actor.rangedDrawn = false;
actor.ammoDisplay = 0;
for (Outfit::Appearance &slot : actor.worn)
slot = Outfit::Appearance{};
@@ -332,9 +333,23 @@ void Actor::ApplyWeapons() {
if (model == nullptr)
return;
Outfit::HangWeapons(model, lanes, weapons, sheathed, hideWeapons);
for (int i = 0; i < 2; ++i)
if (LaneSheathed(i) != sheathed)
Outfit::SetSheatheType(model, lanes, i, weapons, lanes[i].sheatheType, LaneSheathed(i), hideWeapons);
Model::DisplayInfo::LightChildren(SceneFrame(), model);
}
// Sheathe state 2, as SetSheatheState (0x00611CF0) applies it at once; a
// second ranged spell finds it set and changes nothing.
void Actor::DrawRanged() {
if (rangedDrawn || model == nullptr)
return;
rangedDrawn = true;
ApplyWeapons();
}
bool Actor::LaneSheathed(int i) const { return rangedDrawn ? i != Casts::RangedLane(*this) : sheathed; }
void Actor::TookLane(void *onModel, int i) {
ownSheathe[i] = lanes[i].sheatheType;
ApplySheatheCategory(onModel, i);
@@ -347,7 +362,7 @@ void Actor::ApplySheatheCategory(void *onModel, int i) {
useUnitSheatheCategory ? Outfit::kSheatheDefault : sheatheCategory[i];
const uint8_t type = Outfit::SheatheTypeFor(ownSheathe[i], category);
if (type != lanes[i].sheatheType)
Outfit::SetSheatheType(onModel, lanes, i, weapons, type, sheathed, hideWeapons);
Outfit::SetSheatheType(onModel, lanes, i, weapons, type, LaneSheathed(i), hideWeapons);
}
namespace {
@@ -395,7 +410,10 @@ void PutOn(Actor &actor, const TryOn::Request &request, const uint8_t *record) {
ShowIfNotEquippable(record);
Outfit::HeldTryOn held;
held.bodySlot = request.bodySlot;
held.dualWield = Outfit::CanDualWield(actor.unitGuid);
// The dressing room's test (TryOnItem asks the active player's skill only
// when it shows that player) is for a unit's model. A creature display
// or a model file holds two one-handers, as the world draws an NPC's.
held.dualWield = actor.unitGuid == 0 || Outfit::CanDualWield(actor.unitGuid);
held.sheathed = actor.sheathed;
held.hide = actor.hideWeapons;
held.enchant = request.enchant;
@@ -411,6 +429,8 @@ void PutOn(Actor &actor, const TryOn::Request &request, const uint8_t *record) {
if (actor.weapons.visual[lane] != 0)
slot.enchant = request.enchant;
actor.TookLane(actor.model, lane);
if (actor.rangedDrawn)
actor.ApplyWeapons();
}
Outfit::TrimWorn(actor.dresser, actor.lanes, actor.worn);
Model::DisplayInfo::LightChildren(actor.SceneFrame(), actor.model);
@@ -749,6 +769,7 @@ int __fastcall Script_SetModelByUnit(void *L) {
return 0;
}
actor->sheathed = Game::Lua::ToBoolean(L, 3) != 0;
actor->rangedDrawn = false;
actor->autoDress = Game::Lua::Type(L, 4) <= Game::Lua::TYPE_NIL || Game::Lua::ToBoolean(L, 4) != 0;
actor->hideWeapons = Game::Lua::ToBoolean(L, 5) != 0;
const uint64_t guid = Unit::Identity::GuidForToken(Game::Lua::ToString(L, 2));
@@ -896,6 +917,7 @@ int __fastcall Script_SetSheathed(void *L) {
return 0;
actor->sheathed = Game::Lua::ToBoolean(L, 2) != 0;
actor->hideWeapons = Game::Lua::ToBoolean(L, 3) != 0;
actor->rangedDrawn = false;
actor->ApplyWeapons();
return 0;
}
+14 -14
View File
@@ -73,6 +73,17 @@
namespace Model::Scene::Casts {
int RangedLane(const Actor &actor) {
for (int i = 0; i < 2; ++i) {
const uint32_t type = actor.lanes[i].inventoryType;
if (actor.lanes[i].itemClass != 0 &&
(type == Offsets::INVTYPE_RANGED || type == Offsets::INVTYPE_THROWN ||
type == Offsets::INVTYPE_RANGEDRIGHT))
return i;
}
return -1;
}
namespace {
// The release events, '$CSL', '$CSR', '$CST'.
@@ -137,19 +148,6 @@ bool HasTintProcedure(const uint8_t *kit) {
return false;
}
// The held item the caster shoots with (an INVTYPE_RANGED, THROWN or
// RANGEDRIGHT lane), or -1.
int RangedLane(const Actor &actor) {
for (int i = 0; i < 2; ++i) {
const uint32_t type = actor.lanes[i].inventoryType;
if (actor.lanes[i].itemClass != 0 &&
(type == Offsets::INVTYPE_RANGED || type == Offsets::INVTYPE_THROWN ||
type == Offsets::INVTYPE_RANGEDRIGHT))
return i;
}
return -1;
}
bool IsRanged(const uint8_t *spell) {
return (Game::Read<uint32_t>(spell, Offsets::OFF_SPELL_RECORD_ATTRIBUTES) & Offsets::SPELL_ATTR_RANGED) != 0;
}
@@ -741,8 +739,10 @@ bool Play(Actor &caster, uint32_t spellID, Actor *target, int castTimeMs) {
// HandleSpellStart (0x006E78A1): a ranged or auto-repeat spell sets the
// ammo in hand.
if (IsRanged(spell) || (Game::Read<uint32_t>(spell, Offsets::OFF_SPELL_RECORD_ATTRIBUTES_EX2) &
Offsets::SPELL_ATTR_EX2_AUTOREPEAT_FLAG) != 0)
Offsets::SPELL_ATTR_EX2_AUTOREPEAT_FLAG) != 0) {
HoldAmmo(caster, cast.ammoDisplay);
caster.DrawRanged();
}
cast.target = target != nullptr ? target : &caster;
caster.spellCasts.push_back(std::move(cast));
SpellCast &added = caster.spellCasts.back();