aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormegamage <none@none>2008-12-04 23:00:35 -0600
committermegamage <none@none>2008-12-04 23:00:35 -0600
commitd36672cd7e4ae3d328f30c020c5421668ad4cb5e (patch)
tree572ff4758483da0d2d723ab33e028d48670de76e /src
parent450c0a45b87fb043f39298cf94c7f7254ade2fc5 (diff)
*Update spell range calculation. Original patch by QAston.
--HG-- branch : trunk
Diffstat (limited to 'src')
-rw-r--r--src/game/Level3.cpp2
-rw-r--r--src/game/Object.h3
-rw-r--r--src/game/ObjectMgr.cpp4
-rw-r--r--src/game/Player.cpp2
-rw-r--r--src/game/SharedDefines.h7
-rw-r--r--src/game/Spell.cpp28
-rw-r--r--src/game/Spell.h7
-rw-r--r--src/game/SpellMgr.cpp10
-rw-r--r--src/game/SpellMgr.h3
-rw-r--r--src/game/Unit.cpp5
-rw-r--r--src/game/Unit.h1
-rw-r--r--src/shared/Database/DBCStructure.h2
12 files changed, 42 insertions, 32 deletions
diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp
index 42aa9393399..51b9a092ba3 100644
--- a/src/game/Level3.cpp
+++ b/src/game/Level3.cpp
@@ -4406,7 +4406,7 @@ static bool HandleResetStatsOrLevelHelper(Player* player)
player->m_form = FORM_NONE;
player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
- player->SetFloatValue(UNIT_FIELD_COMBATREACH, DEFAULT_WORLD_OBJECT_SIZE );
+ player->SetFloatValue(UNIT_FIELD_COMBATREACH, DEFAULT_COMBAT_REACH );
player->setFactionForRace(player->getRace());
diff --git a/src/game/Object.h b/src/game/Object.h
index 43ecca2afb0..b5546c04caa 100644
--- a/src/game/Object.h
+++ b/src/game/Object.h
@@ -34,11 +34,12 @@
#define CONTACT_DISTANCE 0.5f
#define INTERACTION_DISTANCE 5.0f
-#define ATTACK_DISTANCE 5.0f
#define MAX_VISIBILITY_DISTANCE (5*SIZE_OF_GRID_CELL/2.0f) // max distance for visible object show, limited by active zone for player based at cell size (active zone = 5x5 cells)
#define DEFAULT_VISIBILITY_DISTANCE (SIZE_OF_GRID_CELL) // default visible distance
#define DEFAULT_WORLD_OBJECT_SIZE 0.388999998569489f // player size, also currently used (correctly?) for any non Unit world objects
+#define DEFAULT_COMBAT_REACH 1.5f
+#define ATTACK_DISTANCE (5.0f - DEFAULT_COMBAT_REACH * 2) // melee range: center to center for players
enum TypeMask
{
diff --git a/src/game/ObjectMgr.cpp b/src/game/ObjectMgr.cpp
index 54f92b5fccf..11682704d03 100644
--- a/src/game/ObjectMgr.cpp
+++ b/src/game/ObjectMgr.cpp
@@ -1050,10 +1050,10 @@ void ObjectMgr::LoadCreatureModelInfo()
if(!mInfo)
continue;
- if(mInfo->combat_reach < 0.5f)
+ if(mInfo->combat_reach < 0.1f)
{
//sLog.outErrorDb("Creature model (Entry: %u) has invalid combat reach (%f), setting it to 0.5", mInfo->modelid, mInfo->combat_reach);
- const_cast<CreatureModelInfo*>(mInfo)->combat_reach = 0.5f;
+ const_cast<CreatureModelInfo*>(mInfo)->combat_reach = DEFAULT_COMBAT_REACH;
}
}
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index 184e4ae697c..d16dac54f54 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -546,7 +546,7 @@ bool Player::Create( uint32 guidlow, std::string name, uint8 race, uint8 class_,
}
SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
- SetFloatValue(UNIT_FIELD_COMBATREACH, DEFAULT_WORLD_OBJECT_SIZE );
+ SetFloatValue(UNIT_FIELD_COMBATREACH, DEFAULT_COMBAT_REACH );
switch(gender)
{
diff --git a/src/game/SharedDefines.h b/src/game/SharedDefines.h
index e625a9e48db..0d40b4c50dc 100644
--- a/src/game/SharedDefines.h
+++ b/src/game/SharedDefines.h
@@ -200,13 +200,6 @@ enum SpellCategory
SPELL_CATEGORY_DRINK = 59,
};
-enum SpellRangeFlag
-{
- SPELL_RANGE_DEFAULT = 0,
- SPELL_RANGE_MEELE = 1, //unused
- SPELL_RANGE_RANGED = 2, //hunters' shoots, auto shoot, shoot, deadly throw, throw
-};
-
// ***********************************
// Spell Attributes definitions
// ***********************************
diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp
index 35e5dbd815f..56247e1bcbe 100644
--- a/src/game/Spell.cpp
+++ b/src/game/Spell.cpp
@@ -4670,19 +4670,35 @@ bool Spell::CanAutoCast(Unit* target)
uint8 Spell::CheckRange(bool strict)
{
- float range_mod;
+ //float range_mod;
// self cast doesn't need range checking -- also for Starshards fix
if (m_spellInfo->rangeIndex == 1) return 0;
- if (strict) //add radius of caster
+ // i do not know why we need this
+ /*if (strict) //add radius of caster
range_mod = 1.25;
else //add radius of caster and ~5 yds "give"
- range_mod = 6.25;
+ range_mod = 6.25;*/
SpellRangeEntry const* srange = sSpellRangeStore.LookupEntry(m_spellInfo->rangeIndex);
- float max_range = GetSpellMaxRange(srange) + range_mod;
- float min_range = GetSpellMinRange(srange);
+ float max_range, min_range;
+ float range_type = GetSpellRangeType(srange);
+ if(range_type == SPELL_RANGE_DEFAULT)
+ {
+ max_range = GetSpellMaxRange(srange);// + range_mod;
+ min_range = GetSpellMinRange(srange);
+ }
+ else if(range_type == SPELL_RANGE_MELEE)
+ {
+ max_range = ATTACK_DISTANCE;
+ min_range = GetSpellMinRange(srange);
+ }
+ else
+ {
+ max_range = GetSpellMaxRange(srange);// + range_mod;
+ min_range = ATTACK_DISTANCE;
+ }
if(Player* modOwner = m_caster->GetSpellModOwner())
modOwner->ApplySpellMod(m_spellInfo->Id, SPELLMOD_RANGE, max_range, this);
@@ -4694,8 +4710,10 @@ uint8 Spell::CheckRange(bool strict)
// distance from target center in checks
if(!m_caster->IsWithinCombatDist(target, max_range))
return SPELL_FAILED_OUT_OF_RANGE; //0x5A;
+
if(min_range && m_caster->IsWithinCombatDist(target, min_range)) // skip this check if min_range = 0
return SPELL_FAILED_TOO_CLOSE;
+
if( m_caster->GetTypeId() == TYPEID_PLAYER &&
(m_spellInfo->FacingCasterFlags & SPELL_FACING_FLAG_INFRONT) && !m_caster->HasInArc( M_PI, target ) )
return SPELL_FAILED_UNIT_NOT_INFRONT;
diff --git a/src/game/Spell.h b/src/game/Spell.h
index 365acb93ce9..9ba620b66b8 100644
--- a/src/game/Spell.h
+++ b/src/game/Spell.h
@@ -69,6 +69,13 @@ enum SpellCastFlags
CAST_FLAG_UNKNOWN3 = 0x00000100
};
+enum SpellRangeFlag
+{
+ SPELL_RANGE_DEFAULT = 0,
+ SPELL_RANGE_MELEE = 1, //melee
+ SPELL_RANGE_RANGED = 2, //hunter range and ranged weapon
+};
+
enum SpellNotifyPushType
{
PUSH_IN_FRONT,
diff --git a/src/game/SpellMgr.cpp b/src/game/SpellMgr.cpp
index 2886affc8b6..8d17d94ec8e 100644
--- a/src/game/SpellMgr.cpp
+++ b/src/game/SpellMgr.cpp
@@ -90,16 +90,6 @@ uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell)
return (castTime > 0) ? uint32(castTime) : 0;
}
-float GetSpellMinRange(SpellRangeEntry const *range)
-{
- if (!range)
- return 0;
- if (!range->minRange)
- if (range->flags==SPELL_RANGE_RANGED)
- //return 5.0;
- return 2.0;//this is a hack, needs fix
- return range->minRange;
-}
bool IsPassiveSpell(uint32 spellId)
{
diff --git a/src/game/SpellMgr.h b/src/game/SpellMgr.h
index 303f1378c32..f89edb49635 100644
--- a/src/game/SpellMgr.h
+++ b/src/game/SpellMgr.h
@@ -272,8 +272,9 @@ SpellSpecific GetSpellSpecific(uint32 spellId);
// Different spell properties
inline float GetSpellRadius(SpellRadiusEntry const *radius) { return (radius ? radius->Radius : 0); }
uint32 GetSpellCastTime(SpellEntry const* spellInfo, Spell const* spell = NULL);
-float GetSpellMinRange(SpellRangeEntry const *range);
+inline float GetSpellMinRange(SpellRangeEntry const *range) { return (range ? range->minRange : 0); }
inline float GetSpellMaxRange(SpellRangeEntry const *range) { return (range ? range->maxRange : 0); }
+inline uint32 GetSpellRangeType(SpellRangeEntry const *range) { return (range ? range->type : 0); }
inline uint32 GetSpellRecoveryTime(SpellEntry const *spellInfo) { return spellInfo->RecoveryTime > spellInfo->CategoryRecoveryTime ? spellInfo->RecoveryTime : spellInfo->CategoryRecoveryTime; }
int32 GetSpellDuration(SpellEntry const *spellInfo);
int32 GetSpellMaxDuration(SpellEntry const *spellInfo);
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 257b3dffd8d..2f0e5a1fe43 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -443,14 +443,13 @@ bool Unit::IsWithinCombatDist(Unit *obj, float dist2compare) const
void Unit::GetRandomContactPoint( const Unit* obj, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const
{
- //assert(GetCombatReach() > 0.1);
float combat_reach = GetCombatReach();
- if(combat_reach < 0.1)
+ if(combat_reach < 0.1) // sometimes bugged for players
{
sLog.outError("Unit %u (Type: %u) has invalid combat_reach %f",GetGUIDLow(),GetTypeId(),combat_reach);
if(GetTypeId() == TYPEID_UNIT)
sLog.outError("Creature entry %u has invalid combat_reach", ((Creature*)this)->GetEntry());
- combat_reach = 0.5;
+ combat_reach = DEFAULT_COMBAT_REACH;
}
uint32 attacker_number = getAttackers().size();
if(attacker_number > 0) --attacker_number;
diff --git a/src/game/Unit.h b/src/game/Unit.h
index 3b2656b539a..24722645eaf 100644
--- a/src/game/Unit.h
+++ b/src/game/Unit.h
@@ -774,6 +774,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
bool canReachWithAttack(Unit *pVictim) const;
float GetCombatReach() const { return m_floatValues[UNIT_FIELD_COMBATREACH]; }
bool IsWithinCombatDist(Unit *obj, float dist2compare) const;
+ bool IsWithinMeleeRange(Unit *obj) const { return IsWithinCombatDist(obj, ATTACK_DISTANCE); }
void GetRandomContactPoint( const Unit* target, float &x, float &y, float &z, float distance2dMin, float distance2dMax ) const;
uint32 m_extraAttacks;
bool m_canDualWield;
diff --git a/src/shared/Database/DBCStructure.h b/src/shared/Database/DBCStructure.h
index a84b119664d..94c6589e5e3 100644
--- a/src/shared/Database/DBCStructure.h
+++ b/src/shared/Database/DBCStructure.h
@@ -686,7 +686,7 @@ struct SpellRangeEntry
uint32 ID;
float minRange;
float maxRange;
- uint32 flags;
+ uint32 type;
};
struct SpellShapeshiftEntry