TrinityCore
Loading...
Searching...
No Matches
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 "PacketOperators.h"
23#include "Player.h"
24#include "Spell.h"
25#include "SpellInfo.h"
26#include "Unit.h"
27
29{
31{
32 Health = unit->GetHealth();
35 Armor = unit->GetArmor();
36 if (Player const* player = unit->ToPlayer())
37 {
38 Versatility = player->GetRatingBonusValue(CR_VERSATILITY_DAMAGE_DONE) * 100.0f;
39 Avoidance = player->GetRatingBonusValue(CR_AVOIDANCE) * 100.0f;
40 }
41 PowerData.emplace_back(int32(unit->GetPowerType()), unit->GetPower(unit->GetPowerType()), int32(0));
42}
43
45{
46 if (Unit const* unitCaster = spell->GetCaster()->ToUnit())
47 {
48 Health = unitCaster->GetHealth();
49 AttackPower = unitCaster->GetTotalAttackPowerValue(unitCaster->GetClass() == CLASS_HUNTER ? RANGED_ATTACK : BASE_ATTACK);
50 SpellPower = unitCaster->SpellBaseDamageBonusDone(SPELL_SCHOOL_MASK_SPELL);
51 Armor = unitCaster->GetArmor();
52 if (Player const* player = unitCaster->ToPlayer())
53 {
54 Versatility = player->GetRatingBonusValue(CR_VERSATILITY_DAMAGE_DONE) * 100.0f;
55 Avoidance = player->GetRatingBonusValue(CR_AVOIDANCE) * 100.0f;
56 }
57 Powers primaryPowerType = unitCaster->GetPowerType();
58 bool primaryPowerAdded = false;
59 for (SpellPowerCost const& cost : spell->GetPowerCost())
60 {
61 PowerData.emplace_back(int8(cost.Power), unitCaster->GetPower(Powers(cost.Power)), int32(cost.Amount));
62 if (cost.Power == primaryPowerType)
63 primaryPowerAdded = true;
64 }
65
66 if (!primaryPowerAdded)
67 PowerData.emplace(PowerData.begin(), int8(primaryPowerType), unitCaster->GetPower(primaryPowerType), 0);
68 }
69}
70
71template<class T, class U>
72bool ContentTuningParams::GenerateDataForUnits(T* /*attacker*/, U* /*target*/)
73{
74 return false;
75}
76
77template<>
78bool ContentTuningParams::GenerateDataForUnits<Creature, Player>(Creature* attacker, Player* target)
79{
80 CreatureTemplate const* creatureTemplate = attacker->GetCreatureTemplate();
81 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(attacker->GetMap()->GetDifficultyID());
82
84 PlayerLevelDelta = target->m_activePlayerData->ScalingPlayerLevelDelta;
87 if (ContentTuningEntry const* contentTuning = sContentTuningStore.LookupEntry(creatureDifficulty->ContentTuningID))
88 {
89 ScalingHealthItemLevelCurveID = contentTuning->HealthItemLevelCurveID;
90 ScalingHealthPrimaryStatCurveID = contentTuning->HealthPrimaryStatCurveID;
91 TargetContentTuningID = contentTuning->ID;
92 }
93 TargetLevel = target->GetLevel();
94 Expansion = creatureDifficulty->HealthScalingExpansion;
95 TargetScalingLevelDelta = int8(attacker->m_unitData->ScalingLevelDelta);
96 return true;
97}
98
99template<>
100bool ContentTuningParams::GenerateDataForUnits<Player, Creature>(Player* attacker, Creature* target)
101{
102 CreatureTemplate const* creatureTemplate = target->GetCreatureTemplate();
103 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(target->GetMap()->GetDifficultyID());
104
106 PlayerLevelDelta = attacker->m_activePlayerData->ScalingPlayerLevelDelta;
108 TargetItemLevel = 0;
109 if (ContentTuningEntry const* contentTuning = sContentTuningStore.LookupEntry(creatureDifficulty->ContentTuningID))
110 {
111 ScalingHealthItemLevelCurveID = contentTuning->HealthItemLevelCurveID;
112 ScalingHealthPrimaryStatCurveID = contentTuning->HealthPrimaryStatCurveID;
113 TargetContentTuningID = contentTuning->ID;
114 }
115 TargetLevel = target->GetLevel();
116 Expansion = creatureDifficulty->HealthScalingExpansion;
117 TargetScalingLevelDelta = int8(target->m_unitData->ScalingLevelDelta);
118 return true;
119}
120
121template<>
122bool ContentTuningParams::GenerateDataForUnits<Creature, Creature>(Creature* attacker, Creature* target)
123{
124 Creature* accessor = target->HasScalableLevels() ? target : attacker;
125 CreatureTemplate const* creatureTemplate = accessor->GetCreatureTemplate();
126 CreatureDifficulty const* creatureDifficulty = creatureTemplate->GetDifficulty(accessor->GetMap()->GetDifficultyID());
127
130 PlayerItemLevel = 0;
131 TargetLevel = target->GetLevel();
132 Expansion = creatureDifficulty->HealthScalingExpansion;
133 TargetScalingLevelDelta = int8(accessor->m_unitData->ScalingLevelDelta);
134 TargetContentTuningID = creatureDifficulty->ContentTuningID;
135 return true;
136}
137
138template<>
139bool ContentTuningParams::GenerateDataForUnits<Unit, Unit>(Unit* attacker, Unit* target)
140{
141 if (Player* playerAttacker = Object::ToPlayer(attacker))
142 {
143 if (Player* playerTarget = Object::ToPlayer(target))
144 return GenerateDataForUnits(playerAttacker, playerTarget);
145 else if (Creature* creatureTarget = Object::ToCreature(target))
146 {
147 if (creatureTarget->HasScalableLevels())
148 return GenerateDataForUnits(playerAttacker, creatureTarget);
149 }
150 }
151 else if (Creature* creatureAttacker = Object::ToCreature(attacker))
152 {
153 if (Player* playerTarget = Object::ToPlayer(target))
154 {
155 if (creatureAttacker->HasScalableLevels())
156 return GenerateDataForUnits(creatureAttacker, playerTarget);
157 }
158 else if (Creature* creatureTarget = Object::ToCreature(target))
159 {
160 if (creatureAttacker->HasScalableLevels() || creatureTarget->HasScalableLevels())
161 return GenerateDataForUnits(creatureAttacker, creatureTarget);
162 }
163 }
164
165 return false;
166}
167
168ByteBuffer& operator<<(ByteBuffer& data, SpellCastLogData const& spellCastLogData)
169{
170 data << int64(spellCastLogData.Health);
171 data << int32(spellCastLogData.AttackPower);
172 data << int32(spellCastLogData.SpellPower);
173 data << int32(spellCastLogData.Armor);
174 data << int32(spellCastLogData.Versatility);
175 data << int32(spellCastLogData.Avoidance);
176 data << Bits<1>(spellCastLogData.HideFromCombatLog);
177 data << BitsSize<9>(spellCastLogData.PowerData);
178 data.FlushBits();
179
180 for (SpellLogPowerData const& powerData : spellCastLogData.PowerData)
181 {
182 data << int8(powerData.PowerType);
183 data << int32(powerData.Amount);
184 data << int32(powerData.Cost);
185 }
186
187 return data;
188}
189
190ByteBuffer& operator<<(ByteBuffer& data, ContentTuningParams const& contentTuningParams)
191{
192 data << float(contentTuningParams.PlayerItemLevel);
193 data << float(contentTuningParams.TargetItemLevel);
194 data << int16(contentTuningParams.PlayerLevelDelta);
195 data << int32(contentTuningParams.ScalingHealthItemLevelCurveID);
196 data << int32(contentTuningParams.Unused1117);
197 data << int32(contentTuningParams.ScalingHealthPrimaryStatCurveID);
198 data << uint8(contentTuningParams.TargetLevel);
199 data << uint8(contentTuningParams.Expansion);
200 data << int8(contentTuningParams.TargetScalingLevelDelta);
201 data << uint32(contentTuningParams.Flags);
202 data << int32(contentTuningParams.PlayerContentTuningID);
203 data << int32(contentTuningParams.TargetContentTuningID);
204 data << int32(contentTuningParams.TargetHealingContentTuningID);
205 data << float(contentTuningParams.PlayerPrimaryStatToExpectedRatio);
206 data << Bits<4>(contentTuningParams.Type);
207 data.FlushBits();
208
209 return data;
210}
211
213{
214 data >> visual.SpellXSpellVisualID;
215 data >> visual.ScriptVisualID;
216
217 return data;
218}
219
221{
222 data << int32(visual.SpellXSpellVisualID);
223 data << int32(visual.ScriptVisualID);
224
225 return data;
226}
227
229{
230 data << supportInfo.Supporter;
231 data << int32(supportInfo.SupportSpellID);
232 data << int32(supportInfo.AmountRaw);
233 data << float(supportInfo.AmountPortion);
234
235 return data;
236}
237}
238
240{
245}
DB2Storage< ContentTuningEntry > sContentTuningStore("ContentTuning.db2", &ContentTuningLoadInfo::Instance)
uint8_t uint8
Definition Define.h:156
int64_t int64
Definition Define.h:149
int16_t int16
Definition Define.h:151
int8_t int8
Definition Define.h:152
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
@ CLASS_HUNTER
@ SPELL_SCHOOL_MASK_SPELL
@ BASE_ATTACK
@ RANGED_ATTACK
Powers
@ CR_AVOIDANCE
Definition Unit.h:337
@ CR_VERSATILITY_DAMAGE_DONE
Definition Unit.h:345
void FlushBits()
Definition ByteBuffer.h:141
CreatureTemplate const * GetCreatureTemplate() const
Definition Creature.h:266
bool HasScalableLevels() const
Difficulty GetDifficultyID() const
Definition Map.h:360
Player * ToPlayer()
Definition Object.h:126
Creature * ToCreature()
Definition Object.h:121
Unit * ToUnit()
Definition Object.h:116
UF::UpdateField< UF::ActivePlayerData, int32(WowCS::EntityFragment::CGObject), TYPEID_ACTIVE_PLAYER > m_activePlayerData
Definition Player.h:3062
float GetAverageItemLevel() const
Definition Player.cpp:30033
Definition Spell.h:277
WorldObject * GetCaster() const
Definition Spell.h:699
std::vector< SpellPowerCost > const & GetPowerCost() const
Definition Spell.h:704
Definition Unit.h:635
uint8 GetClass() const
Definition Unit.h:764
Powers GetPowerType() const
Definition Unit.h:811
uint64 GetHealth() const
Definition Unit.h:788
uint32 GetArmor() const
Definition Unit.h:774
UF::UpdateField< UF::UnitData, int32(WowCS::EntityFragment::CGObject), TYPEID_UNIT > m_unitData
Definition Unit.h:1881
int32 GetPower(Powers power) const
Definition Unit.cpp:10028
float GetTotalAttackPowerValue(WeaponAttackType attType, bool includeWeapon=true) const
Definition Unit.cpp:9912
int32 SpellBaseDamageBonusDone(SpellSchoolMask schoolMask) const
Definition Unit.cpp:7084
uint8 GetLevel() const
Definition Unit.h:757
Map * GetMap() const
Definition Object.h:411
ByteBuffer & operator>>(ByteBuffer &data, SpellCastVisual &visual)
ByteBuffer & operator<<(ByteBuffer &data, SpellCastLogData const &spellCastLogData)
CreatureDifficulty const * GetDifficulty(Difficulty difficulty) const
Definition Creature.cpp:252
std::vector< SpellLogPowerData > PowerData