TrinityCore
CombatLogPacketsCommon.cpp
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
19#include "Creature.h"
20#include "DB2Stores.h"
21#include "Map.h"
22#include "Player.h"
23#include "Spell.h"
24#include "SpellInfo.h"
25#include "Unit.h"
26
27namespace WorldPackets
28{
29namespace Spells
30{
32{
33 Health = unit->GetHealth();
36 Armor = unit->GetArmor();
37 PowerData.emplace_back(int32(unit->GetPowerType()), unit->GetPower(unit->GetPowerType()), int32(0));
38}
39
41{
42 if (Unit const* unitCaster = spell->GetCaster()->ToUnit())
43 {
44 Health = unitCaster->GetHealth();
45 AttackPower = unitCaster->GetTotalAttackPowerValue(unitCaster->GetClass() == CLASS_HUNTER ? RANGED_ATTACK : BASE_ATTACK);
46 SpellPower = unitCaster->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SPELL);
47 Armor = unitCaster->GetArmor();
48 Powers primaryPowerType = unitCaster->GetPowerType();
49 bool primaryPowerAdded = false;
50 for (SpellPowerCost const& cost : spell->GetPowerCost())
51 {
52 PowerData.emplace_back(int8(cost.Power), unitCaster->GetPower(Powers(cost.Power)), int32(cost.Amount));
53 if (cost.Power == primaryPowerType)
54 primaryPowerAdded = true;
55 }
56
57 if (!primaryPowerAdded)
58 PowerData.emplace(PowerData.begin(), int8(primaryPowerType), unitCaster->GetPower(primaryPowerType), 0);
59 }
60}
61
62template<class T, class U>
63bool ContentTuningParams::GenerateDataForUnits(T* /*attacker*/, U* /*target*/)
64{
65 return false;
66}
67
68template<>
69bool ContentTuningParams::GenerateDataForUnits<Creature, Player>(Creature* attacker, Player* target)
70{
71 CreatureTemplate const* creatureTemplate = attacker->GetCreatureTemplate();
72 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(attacker->GetMap()->GetDifficultyID());
73
75 PlayerLevelDelta = target->m_activePlayerData->ScalingPlayerLevelDelta;
78 if (ContentTuningEntry const* contentTuning = sContentTuningStore.LookupEntry(creatureDifficulty->ContentTuningID))
79 {
80 ScalingHealthItemLevelCurveID = contentTuning->HealthItemLevelCurveID;
81 TargetContentTuningID = contentTuning->ID;
82 }
83 TargetLevel = target->GetLevel();
84 Expansion = creatureDifficulty->HealthScalingExpansion;
85 TargetScalingLevelDelta = int8(attacker->m_unitData->ScalingLevelDelta);
86 return true;
87}
88
89template<>
90bool ContentTuningParams::GenerateDataForUnits<Player, Creature>(Player* attacker, Creature* target)
91{
92 CreatureTemplate const* creatureTemplate = target->GetCreatureTemplate();
93 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(target->GetMap()->GetDifficultyID());
94
96 PlayerLevelDelta = attacker->m_activePlayerData->ScalingPlayerLevelDelta;
99 if (ContentTuningEntry const* contentTuning = sContentTuningStore.LookupEntry(creatureDifficulty->ContentTuningID))
100 {
101 ScalingHealthItemLevelCurveID = contentTuning->HealthItemLevelCurveID;
102 TargetContentTuningID = contentTuning->ID;
103 }
104 TargetLevel = target->GetLevel();
105 Expansion = creatureDifficulty->HealthScalingExpansion;
106 TargetScalingLevelDelta = int8(target->m_unitData->ScalingLevelDelta);
107 return true;
108}
109
110template<>
111bool ContentTuningParams::GenerateDataForUnits<Creature, Creature>(Creature* attacker, Creature* target)
112{
113 Creature* accessor = target->HasScalableLevels() ? target : attacker;
114 CreatureTemplate const* creatureTemplate = accessor->GetCreatureTemplate();
115 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(accessor->GetMap()->GetDifficultyID());
116
119 PlayerItemLevel = 0;
120 TargetLevel = target->GetLevel();
121 Expansion = creatureDifficulty->HealthScalingExpansion;
122 TargetScalingLevelDelta = int8(accessor->m_unitData->ScalingLevelDelta);
123 TargetContentTuningID = creatureDifficulty->ContentTuningID;
124 return true;
125}
126
127template<>
128bool ContentTuningParams::GenerateDataForUnits<Unit, Unit>(Unit* attacker, Unit* target)
129{
130 if (Player* playerAttacker = Object::ToPlayer(attacker))
131 {
132 if (Player* playerTarget = Object::ToPlayer(target))
133 return GenerateDataForUnits(playerAttacker, playerTarget);
134 else if (Creature* creatureTarget = Object::ToCreature(target))
135 {
136 if (creatureTarget->HasScalableLevels())
137 return GenerateDataForUnits(playerAttacker, creatureTarget);
138 }
139 }
140 else if (Creature* creatureAttacker = Object::ToCreature(attacker))
141 {
142 if (Player* playerTarget = Object::ToPlayer(target))
143 {
144 if (creatureAttacker->HasScalableLevels())
145 return GenerateDataForUnits(creatureAttacker, playerTarget);
146 }
147 else if (Creature* creatureTarget = Object::ToCreature(target))
148 {
149 if (creatureAttacker->HasScalableLevels() || creatureTarget->HasScalableLevels())
150 return GenerateDataForUnits(creatureAttacker, creatureTarget);
151 }
152 }
153
154 return false;
155}
156
157ByteBuffer& operator<<(ByteBuffer& data, SpellCastLogData const& spellCastLogData)
158{
159 data << int64(spellCastLogData.Health);
160 data << int32(spellCastLogData.AttackPower);
161 data << int32(spellCastLogData.SpellPower);
162 data << int32(spellCastLogData.Armor);
163 data << int32(spellCastLogData.Unknown_1105_1);
164 data << int32(spellCastLogData.Unknown_1105_2);
165 data << BitsSize<9>(spellCastLogData.PowerData);
166 data.FlushBits();
167
168 for (SpellLogPowerData const& powerData : spellCastLogData.PowerData)
169 {
170 data << int8(powerData.PowerType);
171 data << int32(powerData.Amount);
172 data << int32(powerData.Cost);
173 }
174
175 return data;
176}
177
178ByteBuffer& operator<<(ByteBuffer& data, ContentTuningParams const& contentTuningParams)
179{
180 data << float(contentTuningParams.PlayerItemLevel);
181 data << float(contentTuningParams.TargetItemLevel);
182 data << int16(contentTuningParams.PlayerLevelDelta);
183 data << uint32(contentTuningParams.ScalingHealthItemLevelCurveID);
184 data << uint8(contentTuningParams.TargetLevel);
185 data << uint8(contentTuningParams.Expansion);
186 data << int8(contentTuningParams.TargetScalingLevelDelta);
187 data << uint32(contentTuningParams.Flags);
188 data << int32(contentTuningParams.PlayerContentTuningID);
189 data << int32(contentTuningParams.TargetContentTuningID);
190 data << int32(contentTuningParams.Unused927);
191 data.WriteBits(contentTuningParams.Type, 4);
192 data.FlushBits();
193 return data;
194}
195
197{
198 data >> visual.SpellXSpellVisualID;
199 data >> visual.ScriptVisualID;
200
201 return data;
202}
203
205{
206 data << int32(visual.SpellXSpellVisualID);
207 data << int32(visual.ScriptVisualID);
208
209 return data;
210}
211
213{
214 data << supportInfo.Supporter;
215 data << int32(supportInfo.SupportSpellID);
216 data << int32(supportInfo.AmountRaw);
217 data << float(supportInfo.AmountPortion);
218
219 return data;
220}
221}
222}
223
225{
226 return _fullLogPacket << LogData;
227}
DB2Storage< ContentTuningEntry > sContentTuningStore("ContentTuning.db2", &ContentTuningLoadInfo::Instance)
uint8_t uint8
Definition: Define.h:144
int64_t int64
Definition: Define.h:137
int16_t int16
Definition: Define.h:139
int8_t int8
Definition: Define.h:140
int32_t int32
Definition: Define.h:138
uint32_t uint32
Definition: Define.h:142
Spells
Definition: PlayerAI.cpp:32
@ CLASS_HUNTER
@ SPELL_SCHOOL_MASK_SPELL
@ BASE_ATTACK
@ RANGED_ATTACK
Powers
void FlushBits()
Definition: ByteBuffer.h:149
void WriteBits(uint64 value, int32 bits)
Definition: ByteBuffer.h:197
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:266
bool HasScalableLevels() const
Definition: Creature.cpp:3036
Difficulty GetDifficultyID() const
Definition: Map.h:357
static Unit * ToUnit(Object *o)
Definition: Object.h:261
Player * ToPlayer()
Definition: Object.h:251
Creature * ToCreature()
Definition: Object.h:257
UF::UpdateField< UF::ActivePlayerData, int32(WowCS::EntityFragment::CGObject), TYPEID_ACTIVE_PLAYER > m_activePlayerData
Definition: Player.h:2965
float GetAverageItemLevel() const
Definition: Player.cpp:29601
Definition: Spell.h:262
WorldObject * GetCaster() const
Definition: Spell.h:666
std::vector< SpellPowerCost > const & GetPowerCost() const
Definition: Spell.h:671
Definition: Unit.h:630
uint8 GetClass() const
Definition: Unit.h:759
Powers GetPowerType() const
Definition: Unit.h:806
uint64 GetHealth() const
Definition: Unit.h:783
uint32 GetArmor() const
Definition: Unit.h:769
UF::UpdateField< UF::UnitData, int32(WowCS::EntityFragment::CGObject), TYPEID_UNIT > m_unitData
Definition: Unit.h:1844
int32 GetPower(Powers power) const
Definition: Unit.cpp:9781
float GetTotalAttackPowerValue(WeaponAttackType attType, bool includeWeapon=true) const
Definition: Unit.cpp:9665
int32 SpellBaseDamageBonusDone(SpellSchoolMask schoolMask) const
Definition: Unit.cpp:6989
uint8 GetLevel() const
Definition: Unit.h:752
Map * GetMap() const
Definition: Object.h:749
ByteBuffer & operator>>(ByteBuffer &data, SpellCastVisual &visual)
ByteBuffer & operator<<(ByteBuffer &data, SpellCastLogData const &spellCastLogData)
int32 HealthScalingExpansion
Definition: CreatureData.h:451
CreatureDifficulty const * GetDifficulty(Difficulty difficulty) const
Definition: Creature.cpp:244
std::vector< SpellLogPowerData > PowerData