|
| 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 | + |
| 18 | +#include "SummonInfo.h" |
| 19 | + |
| 20 | +#include "Creature.h" |
| 21 | +#include "DBCStores.h" |
| 22 | +#include "Log.h" |
| 23 | +#include "ObjectAccessor.h" |
| 24 | +#include "SummonInfoArgs.h" |
| 25 | + |
| 26 | +SummonInfo::SummonInfo(Creature* summonedCreature, SummonInfoArgs const& args) : |
| 27 | + _summonedCreature(ASSERT_NOTNULL(summonedCreature)), _summonerGUID(args.SummonerGUID), _remainingDuration(args.Duration), |
| 28 | + _maxHealth(args.MaxHealth), _summonSpellId(args.SummonSpellId),_despawnOnSummonerLogout(false), |
| 29 | + _despawnOnSummonerDeath(false), _despawnWhenExpired(false) |
| 30 | +{ |
| 31 | + if (args.SummonPropertiesId.has_value()) |
| 32 | + InitializeSummonProperties(*args.SummonPropertiesId); |
| 33 | +} |
| 34 | + |
| 35 | +void SummonInfo::InitializeSummonProperties(uint32 summonPropertiesId) |
| 36 | +{ |
| 37 | + SummonPropertiesEntry const* summonProperties = sSummonPropertiesStore.LookupEntry(summonPropertiesId); |
| 38 | + if (!summonProperties) |
| 39 | + { |
| 40 | + TC_LOG_ERROR("entities.unit", "Creature %s has been summoned with a non-existing SummonProperties.dbc entry (RecId: %u).", _summonedCreature->GetGUID().ToString().c_str(), summonPropertiesId); |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + if (summonProperties->Faction) |
| 45 | + _factionId = summonProperties->Faction; |
| 46 | + |
| 47 | + _despawnOnSummonerLogout = summonProperties->GetFlags().HasFlag(SummonPropertiesFlags::DespawnOnSummonerLogout); |
| 48 | + _despawnOnSummonerDeath = summonProperties->GetFlags().HasFlag(SummonPropertiesFlags::DespawnOnSummonerDeath); |
| 49 | + _despawnWhenExpired = summonProperties->GetFlags().HasFlag(SummonPropertiesFlags::DespawnWhenExpired); |
| 50 | + |
| 51 | + //if (_despawnOnSummonerDeath && summonProperties->GetFlags().HasFlag(SummonPropertiesFlags::DontDespawnOnSummonerDeath)) |
| 52 | + // _despawnOnSummonerDeath = false; |
| 53 | +} |
| 54 | + |
| 55 | +Creature* SummonInfo::GetSummonedCreature() const |
| 56 | +{ |
| 57 | + return _summonedCreature; |
| 58 | +} |
| 59 | + |
| 60 | +Unit* SummonInfo::GetUnitSummoner() const |
| 61 | +{ |
| 62 | + if (!_summonerGUID.has_value()) |
| 63 | + return nullptr; |
| 64 | + |
| 65 | + return ObjectAccessor::GetUnit(*_summonedCreature, *_summonerGUID); |
| 66 | +} |
| 67 | + |
| 68 | +GameObject* SummonInfo::GetGameObjectSummoner() const |
| 69 | +{ |
| 70 | + if (!_summonerGUID.has_value()) |
| 71 | + return nullptr; |
| 72 | + |
| 73 | + return ObjectAccessor::GetGameObject(*_summonedCreature, *_summonerGUID); |
| 74 | +} |
| 75 | + |
| 76 | +Optional<Milliseconds> SummonInfo::GetRemainingDuration() const |
| 77 | +{ |
| 78 | + return _remainingDuration; |
| 79 | +} |
| 80 | + |
| 81 | +Optional<uint64> SummonInfo::GetMaxHealth() const |
| 82 | +{ |
| 83 | + return _maxHealth; |
| 84 | +} |
| 85 | + |
| 86 | +Optional<uint32> SummonInfo::GetSummonSpellId() const |
| 87 | +{ |
| 88 | + return _summonSpellId; |
| 89 | +} |
| 90 | + |
| 91 | +Optional<uint32> SummonInfo::GetFactionId() const |
| 92 | +{ |
| 93 | + return _factionId; |
| 94 | +} |
| 95 | + |
| 96 | +bool SummonInfo::DespawnsOnSummonerLogout() const |
| 97 | +{ |
| 98 | + return _despawnOnSummonerLogout; |
| 99 | +} |
| 100 | + |
| 101 | +void SummonInfo::SetDespawnOnSummonerLogout(bool set) |
| 102 | +{ |
| 103 | + _despawnOnSummonerLogout = set; |
| 104 | +} |
| 105 | + |
| 106 | +bool SummonInfo::DespawnsOnSummonerDeath() const |
| 107 | +{ |
| 108 | + return _despawnOnSummonerDeath; |
| 109 | +} |
| 110 | + |
| 111 | +void SummonInfo::SetDespawnOnSummonerDeath(bool set) |
| 112 | +{ |
| 113 | + _despawnOnSummonerDeath = set; |
| 114 | +} |
| 115 | + |
| 116 | +bool SummonInfo::DespawnsWhenExpired() const |
| 117 | +{ |
| 118 | + return _despawnWhenExpired; |
| 119 | +} |
| 120 | + |
| 121 | +void SummonInfo::SetDespawnWhenExpired(bool set) |
| 122 | +{ |
| 123 | + _despawnWhenExpired = set; |
| 124 | +} |
0 commit comments