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 "Map.h"
21#include "Player.h"
22#include "Spell.h"
23#include "SpellInfo.h"
24#include "Unit.h"
25
26namespace WorldPackets
27{
28namespace Spells
29{
31{
32 Health = unit->GetHealth();
35 Armor = unit->GetArmor();
36 PowerData.emplace_back(int32(unit->GetPowerType()), unit->GetPower(unit->GetPowerType()), int32(0));
37}
38
40{
41 if (Unit const* unitCaster = spell->GetCaster()->ToUnit())
42 {
43 Health = unitCaster->GetHealth();
44 AttackPower = unitCaster->GetTotalAttackPowerValue(unitCaster->GetClass() == CLASS_HUNTER ? RANGED_ATTACK : BASE_ATTACK);
45 SpellPower = unitCaster->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SPELL);
46 Armor = unitCaster->GetArmor();
47 Powers primaryPowerType = unitCaster->GetPowerType();
48 bool primaryPowerAdded = false;
49 for (SpellPowerCost const& cost : spell->GetPowerCost())
50 {
51 PowerData.emplace_back(int32(cost.Power), unitCaster->GetPower(Powers(cost.Power)), int32(cost.Amount));
52 if (cost.Power == primaryPowerType)
53 primaryPowerAdded = true;
54 }
55
56 if (!primaryPowerAdded)
57 PowerData.insert(PowerData.begin(), SpellLogPowerData(int32(primaryPowerType), unitCaster->GetPower(primaryPowerType), 0));
58 }
59}
60
61template<class T, class U>
62bool ContentTuningParams::GenerateDataForUnits(T* /*attacker*/, U* /*target*/)
63{
64 return false;
65}
66
67template<>
68bool ContentTuningParams::GenerateDataForUnits<Creature, Player>(Creature* attacker, Player* target)
69{
70 CreatureTemplate const* creatureTemplate = attacker->GetCreatureTemplate();
71 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(attacker->GetMap()->GetDifficultyID());
72
74 PlayerLevelDelta = target->m_activePlayerData->ScalingPlayerLevelDelta;
77 ScalingHealthItemLevelCurveID = target->m_unitData->ScalingHealthItemLevelCurveID;
78 TargetLevel = target->GetLevel();
79 Expansion = creatureDifficulty->HealthScalingExpansion;
80 TargetScalingLevelDelta = int8(attacker->m_unitData->ScalingLevelDelta);
81 TargetContentTuningID = creatureDifficulty->ContentTuningID;
82 return true;
83}
84
85template<>
86bool ContentTuningParams::GenerateDataForUnits<Player, Creature>(Player* attacker, Creature* target)
87{
88 CreatureTemplate const* creatureTemplate = target->GetCreatureTemplate();
89 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(target->GetMap()->GetDifficultyID());
90
92 PlayerLevelDelta = attacker->m_activePlayerData->ScalingPlayerLevelDelta;
95 ScalingHealthItemLevelCurveID = target->m_unitData->ScalingHealthItemLevelCurveID;
96 TargetLevel = target->GetLevel();
97 Expansion = creatureDifficulty->HealthScalingExpansion;
98 TargetScalingLevelDelta = int8(target->m_unitData->ScalingLevelDelta);
99 TargetContentTuningID = creatureDifficulty->ContentTuningID;
100 return true;
101}
102
103template<>
104bool ContentTuningParams::GenerateDataForUnits<Creature, Creature>(Creature* attacker, Creature* target)
105{
106 Creature* accessor = target->HasScalableLevels() ? target : attacker;
107 CreatureTemplate const* creatureTemplate = accessor->GetCreatureTemplate();
108 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(accessor->GetMap()->GetDifficultyID());
109
112 PlayerItemLevel = 0;
113 TargetLevel = target->GetLevel();
114 Expansion = creatureDifficulty->HealthScalingExpansion;
115 TargetScalingLevelDelta = int8(accessor->m_unitData->ScalingLevelDelta);
116 TargetContentTuningID = creatureDifficulty->ContentTuningID;
117 return true;
118}
119
120template<>
121bool ContentTuningParams::GenerateDataForUnits<Unit, Unit>(Unit* attacker, Unit* target)
122{
123 if (Player* playerAttacker = Object::ToPlayer(attacker))
124 {
125 if (Player* playerTarget = Object::ToPlayer(target))
126 return GenerateDataForUnits(playerAttacker, playerTarget);
127 else if (Creature* creatureTarget = Object::ToCreature(target))
128 {
129 if (creatureTarget->HasScalableLevels())
130 return GenerateDataForUnits(playerAttacker, creatureTarget);
131 }
132 }
133 else if (Creature* creatureAttacker = Object::ToCreature(attacker))
134 {
135 if (Player* playerTarget = Object::ToPlayer(target))
136 {
137 if (creatureAttacker->HasScalableLevels())
138 return GenerateDataForUnits(creatureAttacker, playerTarget);
139 }
140 else if (Creature* creatureTarget = Object::ToCreature(target))
141 {
142 if (creatureAttacker->HasScalableLevels() || creatureTarget->HasScalableLevels())
143 return GenerateDataForUnits(creatureAttacker, creatureTarget);
144 }
145 }
146
147 return false;
148}
149
150ByteBuffer& operator<<(ByteBuffer& data, SpellCastLogData const& spellCastLogData)
151{
152 data << int64(spellCastLogData.Health);
153 data << int32(spellCastLogData.AttackPower);
154 data << int32(spellCastLogData.SpellPower);
155 data << int32(spellCastLogData.Armor);
156 data.WriteBits(spellCastLogData.PowerData.size(), 9);
157 data.FlushBits();
158
159 for (WorldPackets::Spells::SpellLogPowerData const& powerData : spellCastLogData.PowerData)
160 {
161 data << int32(powerData.PowerType);
162 data << int32(powerData.Amount);
163 data << int32(powerData.Cost);
164 }
165
166 return data;
167}
168
169ByteBuffer& operator<<(ByteBuffer& data, ContentTuningParams const& contentTuningParams)
170{
171 data << float(contentTuningParams.PlayerItemLevel);
172 data << float(contentTuningParams.TargetItemLevel);
173 data << int16(contentTuningParams.PlayerLevelDelta);
174 data << uint32(contentTuningParams.ScalingHealthItemLevelCurveID);
175 data << uint8(contentTuningParams.TargetLevel);
176 data << uint8(contentTuningParams.Expansion);
177 data << int8(contentTuningParams.TargetScalingLevelDelta);
178 data << uint32(contentTuningParams.Flags);
179 data << int32(contentTuningParams.PlayerContentTuningID);
180 data << int32(contentTuningParams.TargetContentTuningID);
181 data << int32(contentTuningParams.Unused927);
182 data.WriteBits(contentTuningParams.Type, 4);
183 data.FlushBits();
184 return data;
185}
186
188{
189 data >> visual.SpellXSpellVisualID;
190 data >> visual.ScriptVisualID;
191
192 return data;
193}
194
196{
197 data << int32(visual.SpellXSpellVisualID);
198 data << int32(visual.ScriptVisualID);
199
200 return data;
201}
202
204{
205 data << supportInfo.CasterGUID;
206 data << int32(supportInfo.SpellID);
207 data << int32(supportInfo.Amount);
208 data << float(supportInfo.Percentage);
209
210 return data;
211}
212}
213}
214
216{
217 return _fullLogPacket << LogData;
218}
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 WriteBits(std::size_t value, int32 bits)
Definition: ByteBuffer.h:203
void FlushBits()
Definition: ByteBuffer.h:155
CreatureTemplate const * GetCreatureTemplate() const
Definition: Creature.h:250
bool HasScalableLevels() const
Definition: Creature.cpp:3026
Difficulty GetDifficultyID() const
Definition: Map.h:324
static Unit * ToUnit(Object *o)
Definition: Object.h:225
Player * ToPlayer()
Definition: Object.h:215
Creature * ToCreature()
Definition: Object.h:221
float GetAverageItemLevel() const
Definition: Player.cpp:29020
UF::UpdateField< UF::ActivePlayerData, 0, TYPEID_ACTIVE_PLAYER > m_activePlayerData
Definition: Player.h:2864
Definition: Spell.h:255
WorldObject * GetCaster() const
Definition: Spell.h:647
std::vector< SpellPowerCost > const & GetPowerCost() const
Definition: Spell.h:652
Definition: Unit.h:627
UF::UpdateField< UF::UnitData, 0, TYPEID_UNIT > m_unitData
Definition: Unit.h:1814
uint8 GetClass() const
Definition: Unit.h:752
Powers GetPowerType() const
Definition: Unit.h:799
uint64 GetHealth() const
Definition: Unit.h:776
uint32 GetArmor() const
Definition: Unit.h:762
int32 GetPower(Powers power) const
Definition: Unit.cpp:9401
float GetTotalAttackPowerValue(WeaponAttackType attType, bool includeWeapon=true) const
Definition: Unit.cpp:9285
int32 SpellBaseDamageBonusDone(SpellSchoolMask schoolMask) const
Definition: Unit.cpp:6894
uint8 GetLevel() const
Definition: Unit.h:746
Map * GetMap() const
Definition: Object.h:624
ByteBuffer & operator>>(ByteBuffer &data, SpellCastVisual &visual)
ByteBuffer & operator<<(ByteBuffer &data, SpellCastLogData const &spellCastLogData)
int32 HealthScalingExpansion
Definition: CreatureData.h:442
CreatureDifficulty const * GetDifficulty(Difficulty difficulty) const
Definition: Creature.cpp:238
std::vector< SpellLogPowerData > PowerData