Skip to content

Commit

Permalink
[10115] Add function to update model_info at changes to scale or model.
Browse files Browse the repository at this point in the history
* At every change to model or scale, the related data (bounding_radius/combat_reach) is now updated accordingly (note that player combat_reach are not changed like creature).
* UpdateModelData is called from within SetDisplayId while changes to scale has explicit call to UpdateModelData after new scale is set (mostly for aura scale)
* The updated values are calculated by (scale*bounding_radius)/(scale*combat_reach)
* Database values for bounding_radius/combat_reach are expected to be relative to scale like 1.0

Signed-off-by: NoFantasy <nofantasy@nf.no>
  • Loading branch information
NoFantasy committed Jun 28, 2010
1 parent d8adc74 commit 3a9ce83
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 25 deletions.
4 changes: 1 addition & 3 deletions src/game/Creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )

SetDisplayId(display_id);
SetNativeDisplayId(display_id);

SetByteValue(UNIT_FIELD_BYTES_0, 2, minfo->gender);

// Load creature equipment
Expand All @@ -264,9 +265,6 @@ bool Creature::InitEntry(uint32 Entry, uint32 team, const CreatureData *data )

SetName(normalInfo->Name); // at normal entry always

SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, minfo->bounding_radius);
SetFloatValue(UNIT_FIELD_COMBATREACH, minfo->combat_reach);

SetFloatValue(UNIT_MOD_CAST_SPEED, 1.0f);

SetSpeedRate(MOVE_WALK, cinfo->speed_walk);
Expand Down
4 changes: 0 additions & 4 deletions src/game/GameEventMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -739,8 +739,6 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
{
pCreature->SetDisplayId(itr->second.modelid);
pCreature->SetNativeDisplayId(itr->second.modelid);
pCreature->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS,minfo->bounding_radius);
pCreature->SetFloatValue(UNIT_FIELD_COMBATREACH,minfo->combat_reach );
}
}
}
Expand All @@ -754,8 +752,6 @@ void GameEventMgr::ChangeEquipOrModel(int16 event_id, bool activate)
{
pCreature->SetDisplayId(itr->second.modelid_prev);
pCreature->SetNativeDisplayId(itr->second.modelid_prev);
pCreature->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS,minfo->bounding_radius);
pCreature->SetFloatValue(UNIT_FIELD_COMBATREACH,minfo->combat_reach );
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/game/Pet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,7 @@ bool Pet::InitStatsForLevel(uint32 petlevel, Unit* owner)
scale = cFamily->minScale + float(getLevel() - cFamily->minScaleLevel) / cFamily->maxScaleLevel * (cFamily->maxScale - cFamily->minScale);

SetObjectScale(scale);
UpdateModelData();
}
m_bonusdamage = 0;

Expand Down
20 changes: 3 additions & 17 deletions src/game/Player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4439,8 +4439,6 @@ void Player::BuildPlayerRepop()

StopMirrorTimers(); //disable timers(bars)

SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, (float)1.0); //see radius of death player?

// set and clear other
SetByteValue(UNIT_FIELD_BYTES_1, 3, UNIT_BYTE1_FLAG_ALWAYS_STAND);
}
Expand Down Expand Up @@ -18441,6 +18439,9 @@ void Player::InitDisplayIds()
return;
}

// reset scale before reapply auras
SetObjectScale(DEFAULT_OBJECT_SCALE);

uint8 gender = getGender();
switch(gender)
{
Expand All @@ -18456,21 +18457,6 @@ void Player::InitDisplayIds()
sLog.outError("Invalid gender %u for player",gender);
return;
}

// reset scale before reapply auras
SetObjectScale(DEFAULT_OBJECT_SCALE);

if (CreatureModelInfo const* modelInfo = sObjectMgr.GetCreatureModelInfo(GetDisplayId()))
{
// bounding_radius and combat_reach is normally modified by scale, but player is always 1.0 scale by default so no need to modify values here.
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, modelInfo->bounding_radius);
SetFloatValue(UNIT_FIELD_COMBATREACH, modelInfo->combat_reach);
}
else
{
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE);
SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f);
}
}

// Return true is the bought item has a max count to force refresh of window by caller
Expand Down
1 change: 1 addition & 0 deletions src/game/SpellAuras.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3597,6 +3597,7 @@ void Aura::HandleAuraTrackStealthed(bool apply, bool /*Real*/)
void Aura::HandleAuraModScale(bool apply, bool /*Real*/)
{
GetTarget()->ApplyPercentModFloatValue(OBJECT_FIELD_SCALE_X, float(m_modifier.m_amount), apply);
GetTarget()->UpdateModelData();
}

void Aura::HandleModPossess(bool apply, bool Real)
Expand Down
17 changes: 17 additions & 0 deletions src/game/Unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12980,6 +12980,8 @@ void Unit::SetDisplayId(uint32 modelId)
{
SetUInt32Value(UNIT_FIELD_DISPLAYID, modelId);

UpdateModelData();

if(GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet())
{
Pet *pet = ((Pet*)this);
Expand All @@ -12991,6 +12993,21 @@ void Unit::SetDisplayId(uint32 modelId)
}
}

void Unit::UpdateModelData()
{
if (CreatureModelInfo const* modelInfo = sObjectMgr.GetCreatureModelInfo(GetDisplayId()))
{
// we expect values in database to be relative to scale = 1.0
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, GetObjectScale() * modelInfo->bounding_radius);

// never actually update combat_reach for player, it's always the same. Below player case is for initialization
if (GetTypeId() == TYPEID_PLAYER)
SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f);
else
SetFloatValue(UNIT_FIELD_COMBATREACH, GetObjectScale() * modelInfo->combat_reach);
}
}

void Unit::ClearComboPointHolders()
{
while(!m_ComboPointHolders.empty())
Expand Down
3 changes: 3 additions & 0 deletions src/game/Unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -1706,6 +1706,9 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void setTransForm(uint32 spellid) { m_transform = spellid;}
uint32 getTransForm() const { return m_transform;}

// at any changes to scale and/or displayId
void UpdateModelData();

DynamicObject* GetDynObject(uint32 spellId, SpellEffectIndex effIndex);
DynamicObject* GetDynObject(uint32 spellId);
void AddDynObject(DynamicObject* dynObj);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_nr.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10114"
#define REVISION_NR "10115"
#endif // __REVISION_NR_H__

0 comments on commit 3a9ce83

Please sign in to comment.