root/trunk/src/game/HostilRefManager.cpp @ 93

Revision 44, 4.2 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge Temp dev SVN with Assembla.
* Changes include:

  • Implementation of w12x's Outdoor PvP and Game Event Systems.
  • Temporary removal of IRC Chat Bot (until infinite loop when disabled is fixed).
  • All mangos -> trinity (to convert your mangos_string table, please run mangos_string_to_trinity_string.sql).
  • Improved Config cleanup.
  • And many more changes.

Original author: Seline
Date: 2008-10-14 11:57:03-05:00

Line 
1/*
2 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
3 *
4 * Thanks to the original authors: MaNGOS <http://www.mangosproject.org/>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21#include "HostilRefManager.h"
22#include "ThreatManager.h"
23#include "Unit.h"
24#include "Database/DBCStructure.h"
25#include "SpellMgr.h"
26
27HostilRefManager::~HostilRefManager()
28{
29    deleteReferences();
30}
31
32//=================================================
33// send threat to all my hateres for the pVictim
34// The pVictim is hated than by them as well
35// use for buffs and healing threat functionality
36
37void HostilRefManager::threatAssist(Unit *pVictim, float pThreat, SpellEntry const *pThreatSpell, bool pSingleTarget)
38{
39    HostilReference* ref;
40
41    uint32 size = pSingleTarget ? 1 : getSize();            // if pSingleTarget do not devide threat
42    ref = getFirst();
43    while(ref != NULL)
44    {
45        float threat = ThreatCalcHelper::calcThreat(pVictim, iOwner, pThreat, (pThreatSpell ? GetSpellSchoolMask(pThreatSpell) : SPELL_SCHOOL_MASK_NORMAL), pThreatSpell);
46        if(pVictim == getOwner())
47            ref->addThreat(float (threat) / size);          // It is faster to modify the threat durectly if possible
48        else
49            ref->getSource()->addThreat(pVictim, float (threat) / size);
50        ref = ref->next();
51    }
52}
53
54//=================================================
55
56void HostilRefManager::addThreatPercent(int32 pValue)
57{
58    HostilReference* ref;
59
60    ref = getFirst();
61    while(ref != NULL)
62    {
63        ref->addThreatPercent(pValue);
64        ref = ref->next();
65    }
66}
67
68//=================================================
69// The online / offline status is given to the method. The calculation has to be done before
70
71void HostilRefManager::setOnlineOfflineState(bool pIsOnline)
72{
73    HostilReference* ref;
74
75    ref = getFirst();
76    while(ref != NULL)
77    {
78        ref->setOnlineOfflineState(pIsOnline);
79        ref = ref->next();
80    }
81}
82
83//=================================================
84// The online / offline status is calculated and set
85
86void HostilRefManager::updateThreatTables()
87{
88    HostilReference* ref = getFirst();
89    while(ref)
90    {
91        ref->updateOnlineStatus();
92        ref = ref->next();
93    }
94}
95
96//=================================================
97// The references are not needed anymore
98// tell the source to remove them from the list and free the mem
99
100void HostilRefManager::deleteReferences()
101{
102    HostilReference* ref = getFirst();
103    while(ref)
104    {
105        HostilReference* nextRef = ref->next();
106        ref->removeReference();
107        delete ref;
108        ref = nextRef;
109    }
110}
111
112//=================================================
113// delete one reference, defined by Unit
114
115void HostilRefManager::deleteReference(Unit *pCreature)
116{
117    HostilReference* ref = getFirst();
118    while(ref)
119    {
120        HostilReference* nextRef = ref->next();
121        if(ref->getSource()->getOwner() == pCreature)
122        {
123            ref->removeReference();
124            delete ref;
125            break;
126        }
127        ref = nextRef;
128    }
129}
130
131//=================================================
132// set state for one reference, defined by Unit
133
134void HostilRefManager::setOnlineOfflineState(Unit *pCreature,bool pIsOnline)
135{
136    HostilReference* ref = getFirst();
137    while(ref)
138    {
139        HostilReference* nextRef = ref->next();
140        if(ref->getSource()->getOwner() == pCreature)
141        {
142            ref->setOnlineOfflineState(pIsOnline);
143            break;
144        }
145        ref = nextRef;
146    }
147}
148
149//=================================================
Note: See TracBrowser for help on using the browser.