root/trunk/src/game/OutdoorPvP.cpp @ 229

Revision 229, 24.1 kB (checked in by yumileroy, 17 years ago)

[svn] *** Source: MaNGOS ***
* Fixed build extractor at Windows Vista. Author: Vladimir
* Fixed comment text and code indentifiers spelling. Author: Vladimir & Paradox.
* Access cached member lists in guild handlers instead of querying the DB. Author: Hunuza
* Small fixes in send/received packet and simple code cleanup also. Author: Vladimir
* Not output error at loading empty character_ticket table. Author: Vladimir
* Not reset display model at shapeshift aura remove if it not set at apply. Author: Arthorius
* Applied props to few files.

Original author: visagalis
Date: 2008-11-14 16:28:45-06:00

Line 
1/*
2 * Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#include "OutdoorPvP.h"
20#include "OutdoorPvPMgr.h"
21#include "ObjectAccessor.h"
22#include "ObjectMgr.h"
23#include "Map.h"
24#include "MapManager.h"
25#include "OutdoorPvPObjectiveAI.h"
26#include "Group.h"
27#include "WorldPacket.h"
28
29OutdoorPvPObjective::OutdoorPvPObjective(OutdoorPvP * pvp) 
30: m_PvP(pvp), m_AllianceActivePlayerCount(0), m_HordeActivePlayerCount(0),
31m_ShiftTimer(0), m_ShiftPhase(0), m_ShiftMaxPhase(0), m_OldPhase(0),
32m_State(0), m_OldState(0), m_CapturePoint(0), m_NeutralValue(0), m_ShiftMaxCaptureSpeed(0), m_CapturePointCreature(0)
33{
34}
35
36bool OutdoorPvPObjective::HandlePlayerEnter(Player * plr)
37{
38    // only called if really entered, so no use in the return value anymore
39    // player distance and activity state was checked already in the AI
40    std::set<uint64>::iterator pitr = m_ActivePlayerGuids.find(plr->GetGUID());
41    // if not already counted as active, add player
42    if(pitr == m_ActivePlayerGuids.end())
43    {
44        if(plr->GetTeam() == ALLIANCE)
45            ++m_AllianceActivePlayerCount;
46        else
47            ++m_HordeActivePlayerCount;
48        m_ActivePlayerGuids.insert(plr->GetGUID());
49        sLog.outDebug("player %u entered an outdoorpvpobjective", plr->GetGUIDLow());
50        return true;
51    }
52    return true;
53}
54
55void OutdoorPvPObjective::HandlePlayerLeave(Player * plr)
56{
57    // only decrease the count if the player is in the active list
58    if(m_ActivePlayerGuids.find(plr->GetGUID())!=m_ActivePlayerGuids.end())
59    {
60        if(plr->GetTeam() == ALLIANCE)
61            --m_AllianceActivePlayerCount;
62        else
63            --m_HordeActivePlayerCount;
64        m_ActivePlayerGuids.erase(plr->GetGUID());
65    }
66}
67
68void OutdoorPvPObjective::HandlePlayerActivityChanged(Player * plr)
69{
70    if(m_CapturePointCreature)
71        if(Creature * c = HashMapHolder<Creature>::Find(m_CapturePointCreature))
72            if(c->AI())
73                c->AI()->MoveInLineOfSight(plr);
74}
75
76bool OutdoorPvPObjective::AddObject(uint32 type, uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3)
77{
78    GameObjectInfo const* goinfo = objmgr.GetGameObjectInfo(entry);
79    if (!goinfo)
80        return false;
81
82    uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
83
84    GameObjectData& data = objmgr.NewGOData(guid);
85
86    data.id             = entry;
87    data.mapid          = map;
88    data.posX           = x;
89    data.posY           = y;
90    data.posZ           = z;
91    data.orientation    = o;
92    data.rotation0      = rotation0;
93    data.rotation1      = rotation1;
94    data.rotation2      = rotation2;
95    data.rotation3      = rotation3;
96    data.spawntimesecs  = 0;
97    data.animprogress   = 100;
98    data.spawnMask      = 1;
99    data.go_state       = 1;
100
101    objmgr.AddGameobjectToGrid(guid, &data);
102
103    // 2 way registering
104    m_Objects[type] = MAKE_NEW_GUID(guid, entry, HIGHGUID_GAMEOBJECT);
105    m_ObjectTypes[m_Objects[type]]=type;
106
107    Map * pMap = MapManager::Instance().FindMap(map);
108    if(!pMap)
109        return true;
110    GameObject * go = new GameObject;
111    if(!go->Create(guid,entry, pMap,x,y,z,o,rotation0,rotation1,rotation2,rotation3,100,1))
112    {
113        sLog.outError("Gameobject template %u not found in database.", entry);
114        delete go;
115        return true;
116    }
117
118    go->SetRespawnTime(0);
119    objmgr.SaveGORespawnTime(go->GetDBTableGUIDLow(),0,0);
120    pMap->Add(go);
121
122    return true;
123}
124
125bool OutdoorPvPObjective::AddCreature(uint32 type, uint32 entry, uint32 teamval, uint32 map, float x, float y, float z, float o, uint32 spawntimedelay)
126{
127    CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(entry);
128    if(!cinfo)
129    {
130        return false;
131    }
132
133    uint32 displayId = objmgr.ChooseDisplayId(teamval, cinfo, NULL);
134    CreatureModelInfo const *minfo = objmgr.GetCreatureModelRandomGender(displayId);
135    if (!minfo)
136    {
137        return false;
138    }
139    else
140        displayId = minfo->modelid;                        // it can be different (for another gender)
141
142    uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT);
143
144    CreatureData& data = objmgr.NewOrExistCreatureData(guid);
145
146    data.id = entry;
147    data.mapid = map;
148    data.displayid = displayId;
149    data.equipmentId = cinfo->equipmentId;
150    data.posX = x;
151    data.posY = y;
152    data.posZ = z;
153    data.orientation = o;
154    data.spawntimesecs = spawntimedelay;
155    data.spawndist = 0;
156    data.currentwaypoint = 0;
157    data.curhealth = cinfo->maxhealth;
158    data.curmana = cinfo->maxmana;
159    data.is_dead = false;
160    data.movementType = cinfo->MovementType;
161    data.spawnMask = 1;
162
163    objmgr.AddCreatureToGrid(guid, &data);
164
165    m_Creatures[type] = MAKE_NEW_GUID(guid, entry, HIGHGUID_UNIT);
166    m_CreatureTypes[m_Creatures[type]] = type;
167
168    Map * pMap = MapManager::Instance().FindMap(map);
169    if(!pMap)
170        return true;
171    Creature* pCreature = new Creature;
172    if (!pCreature->Create(guid, pMap, entry, teamval))
173    {
174        sLog.outError("Can't create creature entry: %u",entry);
175        delete pCreature;
176        return true;
177    }
178
179    pCreature->AIM_Initialize();
180
181    pCreature->Relocate(x, y, z, o);
182
183    if(!pCreature->IsPositionValid())
184    {
185        sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY());
186        return false;
187    }
188
189    if(spawntimedelay)
190        pCreature->SetRespawnDelay(spawntimedelay);
191
192    pMap->Add(pCreature);
193
194    return true;
195}
196
197bool OutdoorPvPObjective::AddCapturePoint(uint32 entry, uint32 map, float x, float y, float z, float o, float rotation0, float rotation1, float rotation2, float rotation3)
198{
199    sLog.outDebug("creating capture point %u and capture point creature",entry);
200
201    // check info existence
202    GameObjectInfo const* goinfo = objmgr.GetGameObjectInfo(entry);
203    if (!goinfo)
204        return false;
205
206    CreatureInfo const *cinfo = objmgr.GetCreatureTemplate(OPVP_TRIGGER_CREATURE_ENTRY);
207    if(!cinfo)
208        return false;
209
210    // create capture point creature
211    uint32 displayId = objmgr.ChooseDisplayId(0, cinfo, NULL);
212
213    uint32 creature_guid = objmgr.GenerateLowGuid(HIGHGUID_UNIT);
214
215    CreatureData& cdata = objmgr.NewOrExistCreatureData(creature_guid);
216
217    cdata.id = OPVP_TRIGGER_CREATURE_ENTRY;
218    cdata.mapid = map;
219    cdata.displayid = displayId;
220    cdata.equipmentId = cinfo->equipmentId;
221    cdata.posX = x;
222    cdata.posY = y;
223    cdata.posZ = z;
224    cdata.orientation = o;
225    cdata.spawntimesecs = 1;
226    cdata.spawndist = 0;
227    cdata.currentwaypoint = 0;
228    cdata.curhealth = cinfo->maxhealth;
229    cdata.curmana = cinfo->maxmana;
230    cdata.is_dead = false;
231    cdata.movementType = cinfo->MovementType;
232    cdata.spawnMask = 1;
233
234    objmgr.AddCreatureToGrid(creature_guid, &cdata);
235    m_CapturePointCreature = MAKE_NEW_GUID(creature_guid, OPVP_TRIGGER_CREATURE_ENTRY, HIGHGUID_UNIT);
236
237    // create capture point go
238    uint32 guid = objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT);
239
240    GameObjectData& data = objmgr.NewGOData(guid);
241
242    data.id             = entry;
243    data.mapid          = map;
244    data.posX           = x;
245    data.posY           = y;
246    data.posZ           = z;
247    data.orientation    = o;
248    data.rotation0      = rotation0;
249    data.rotation1      = rotation1;
250    data.rotation2      = rotation2;
251    data.rotation3      = rotation3;
252    data.spawntimesecs  = 1;
253    data.animprogress   = 100;
254    data.spawnMask      = 1;
255    data.go_state       = 1;
256
257    objmgr.AddGameobjectToGrid(guid, &data);
258
259    m_CapturePoint = MAKE_NEW_GUID(guid, entry, HIGHGUID_GAMEOBJECT);
260
261    // get the needed values from goinfo
262    m_ShiftMaxPhase = goinfo->raw.data[17];
263    m_ShiftMaxCaptureSpeed = m_ShiftMaxPhase / float(goinfo->raw.data[16]);
264    m_NeutralValue = goinfo->raw.data[12];
265
266    // add to map if map is already loaded
267    Map * pMap = MapManager::Instance().FindMap(map);
268    if(!pMap)
269        return true;
270    // add GO...
271    GameObject * go = new GameObject;
272    if(!go->Create(guid,entry, pMap,x,y,z,o,rotation0,rotation1,rotation2,rotation3,100,1))
273    {
274        sLog.outError("Gameobject template %u not found in database.", entry);
275        delete go;
276    }
277    else
278    {
279        go->SetRespawnTime(0);
280        objmgr.SaveGORespawnTime(go->GetDBTableGUIDLow(), 0, 0);
281        pMap->Add(go);
282    }
283    // add creature...
284    Creature* pCreature = new Creature;
285    if (!pCreature->Create(creature_guid, pMap, OPVP_TRIGGER_CREATURE_ENTRY, 0))
286    {
287        sLog.outError("Can't create creature entry: %u",entry);
288        delete pCreature;
289    }
290    else
291    {
292        pCreature->AIM_Initialize();
293
294        pCreature->Relocate(x, y, z, o);
295
296        if(!pCreature->IsPositionValid())
297        {
298            sLog.outError("ERROR: Creature (guidlow %d, entry %d) not added to opvp. Suggested coordinates isn't valid (X: %f Y: %f)",pCreature->GetGUIDLow(),pCreature->GetEntry(),pCreature->GetPositionX(),pCreature->GetPositionY());
299            return false;
300        }
301
302        pMap->Add(pCreature);
303    }
304    return true;
305}
306
307bool OutdoorPvPObjective::DelCreature(uint32 type)
308{
309    if(!m_Creatures[type])
310    {
311        sLog.outDebug("opvp creature type %u was already deleted",type);
312        return false;
313    }
314
315    Creature *cr = HashMapHolder<Creature>::Find(m_Creatures[type]);
316    if(!cr)
317    {
318        // can happen when closing the core
319        m_Creatures[type] = 0;
320        return false;
321    }
322    sLog.outDebug("deleting opvp creature type %u",type);
323    uint32 guid = cr->GetDBTableGUIDLow();
324    // Don't save respawn time
325    cr->SetRespawnTime(0);
326    cr->RemoveCorpse();
327    cr->CleanupsBeforeDelete();
328    // explicit removal from map
329    // beats me why this is needed, but with the recent removal "cleanup" some creatures stay in the map if "properly" deleted
330    // so this is a big fat workaround, if AddObjectToRemoveList and DoDelayedMovesAndRemoves worked correctly, this wouldn't be needed
331    if(Map * map = MapManager::Instance().FindMap(cr->GetMapId()))
332        map->Remove(cr,false);
333    // delete respawn time for this creature
334    WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u'", guid);
335    cr->AddObjectToRemoveList();
336    objmgr.DeleteCreatureData(guid);
337    m_CreatureTypes[m_Creatures[type]] = 0;
338    m_Creatures[type] = 0;
339    return true;
340}
341
342bool OutdoorPvPObjective::DelObject(uint32 type)
343{
344    if(!m_Objects[type])
345        return false;
346
347    GameObject *obj = HashMapHolder<GameObject>::Find(m_Objects[type]);
348    if(!obj)
349    {
350        m_Objects[type] = 0;
351        return false;
352    }
353    uint32 guid = obj->GetDBTableGUIDLow();
354    obj->SetRespawnTime(0);                                 // not save respawn time
355    obj->Delete();
356    objmgr.DeleteGOData(guid);
357    m_ObjectTypes[m_Objects[type]] = 0;
358    m_Objects[type] = 0;
359    return true;
360}
361
362bool OutdoorPvPObjective::DelCapturePoint()
363{
364    if(m_CapturePoint)
365    {
366        GameObject *obj = HashMapHolder<GameObject>::Find(m_CapturePoint);
367        if(obj)
368        {
369            uint32 guid = obj->GetDBTableGUIDLow();
370            obj->SetRespawnTime(0);                                 // not save respawn time
371            obj->Delete();
372            objmgr.DeleteGOData(guid);
373        }
374        m_CapturePoint = 0;
375    }
376    if(m_CapturePointCreature)
377    {
378        Creature *cr = HashMapHolder<Creature>::Find(m_CapturePointCreature);
379        if(cr)
380        {
381            uint32 guid = cr->GetDBTableGUIDLow();
382            // Don't save respawn time
383            cr->SetRespawnTime(0);
384            cr->RemoveCorpse();
385            cr->CleanupsBeforeDelete();
386            // explicit removal from map
387            // beats me why this is needed, but with the recent removal "cleanup" some creatures stay in the map if "properly" deleted
388            // so this is a big fat workaround, if AddObjectToRemoveList and DoDelayedMovesAndRemoves worked correctly, this wouldn't be needed
389            if(Map * map = MapManager::Instance().FindMap(cr->GetMapId()))
390                map->Remove(cr,false);
391            // delete respawn time for this creature
392            WorldDatabase.PExecute("DELETE FROM creature_respawn WHERE guid = '%u'", guid);
393            cr->AddObjectToRemoveList();
394            objmgr.DeleteCreatureData(guid);
395        }
396        m_CapturePointCreature = 0;
397    }
398    return true;
399}
400
401void OutdoorPvPObjective::DeleteSpawns()
402{
403    for(std::map<uint32,uint64>::iterator i = m_Objects.begin(); i != m_Objects.end(); ++i)
404        DelObject(i->first);
405    for(std::map<uint32,uint64>::iterator i = m_Creatures.begin(); i != m_Creatures.end(); ++i)
406        DelCreature(i->first);
407    DelCapturePoint();
408}
409
410void OutdoorPvP::DeleteSpawns()
411{
412    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
413        (*itr)->DeleteSpawns();
414}
415
416OutdoorPvP::OutdoorPvP()
417{
418}
419
420OutdoorPvP::~OutdoorPvP()
421{
422    DeleteSpawns();
423}
424
425void OutdoorPvP::HandlePlayerEnterZone(Player * plr, uint32 zone)
426{
427    if(plr->GetTeam()==ALLIANCE)
428        m_PlayerGuids[0].insert(plr->GetGUID());
429    else
430        m_PlayerGuids[1].insert(plr->GetGUID());
431}
432
433void OutdoorPvP::HandlePlayerLeaveZone(Player * plr, uint32 zone)
434{
435    // inform the objectives of the leaving
436    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
437        (*itr)->HandlePlayerLeave(plr);
438    // remove the world state information from the player (we can't keep everyone up to date, so leave out those who are not in the concerning zones)
439    if(zone != plr->GetZoneId())
440        SendRemoveWorldStates(plr);
441    if(plr->GetTeam()==ALLIANCE)
442        m_PlayerGuids[0].erase(plr->GetGUID());
443    else
444        m_PlayerGuids[1].erase(plr->GetGUID());
445    sLog.outDebug("player left an outdoorpvp zone");
446}
447
448bool OutdoorPvP::Update(uint32 diff)
449{
450    bool objective_changed = false;
451    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
452        objective_changed |= (*itr)->Update(diff);
453    return objective_changed;
454}
455
456bool OutdoorPvPObjective::Update(uint32 diff)
457{
458    uint32 Challenger = 0;
459    if(m_ShiftTimer<diff)
460    {
461        m_ShiftTimer = OUTDOORPVP_OBJECTIVE_UPDATE_INTERVAL;
462
463        // get the difference of numbers
464        float fact_diff = (m_AllianceActivePlayerCount - m_HordeActivePlayerCount);
465
466        if(fact_diff<0)
467        {
468            if(fact_diff < - m_ShiftMaxCaptureSpeed)
469                fact_diff = - m_ShiftMaxCaptureSpeed;
470            Challenger = HORDE;
471            // horde is in majority, but it's already horde-controlled -> no change
472            if(m_State == OBJECTIVESTATE_HORDE && m_ShiftPhase == - m_ShiftMaxPhase)
473                return false;
474        }
475        else if(fact_diff>0)
476        {
477            if(fact_diff > m_ShiftMaxCaptureSpeed)
478                fact_diff = m_ShiftMaxCaptureSpeed;
479            Challenger = ALLIANCE;
480            // ally is in majority, but it's already ally-controlled -> no change
481            if(m_State == OBJECTIVESTATE_ALLIANCE && m_ShiftPhase == m_ShiftMaxPhase)
482                return false;
483        }
484        else /*if(fact_diff==0)*/ // no change
485            return false;
486
487        m_OldPhase = m_ShiftPhase;
488
489        m_OldState = m_State;
490
491        m_ShiftPhase += fact_diff;
492
493        // check limits, these are over the grey part
494        if(m_ShiftPhase <= - m_ShiftMaxPhase * (float)(m_NeutralValue) / 100.0f)
495        {
496            if(m_ShiftPhase <= - m_ShiftMaxPhase)
497                m_ShiftPhase = - m_ShiftMaxPhase;
498            m_State = OBJECTIVESTATE_HORDE;
499            return true;
500        }
501        else if(m_ShiftPhase >= m_ShiftMaxPhase * (float)(m_NeutralValue) / 100.0f)
502        {
503            if(m_ShiftPhase >= m_ShiftMaxPhase)
504                m_ShiftPhase = m_ShiftMaxPhase;
505            m_State = OBJECTIVESTATE_ALLIANCE;
506            return true;
507        }
508
509        if(m_OldPhase*m_ShiftPhase <=0)
510        {
511            // gone through neutral
512            // if challenger is ally, then n->a challenge
513            if(Challenger == ALLIANCE)
514                m_State = OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE;
515            // if challenger is horde, then n->h challenge
516            else if(Challenger == HORDE)
517                m_State = OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE;
518        }
519        else
520        {
521            // old phase and current are on the same side, so one team challenges the other
522            if(Challenger == ALLIANCE && (m_OldState == OBJECTIVESTATE_HORDE || m_OldState == OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE))
523                m_State = OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE;
524            else if(Challenger == HORDE && (m_OldState == OBJECTIVESTATE_ALLIANCE || m_OldState == OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE))
525                m_State = OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE;
526        }
527
528        return true;
529    } else m_ShiftTimer-=diff;
530
531    return false;
532}
533
534bool OutdoorPvPObjective::HandleCaptureCreaturePlayerMoveInLos(Player * p, Creature * c)
535{
536    // check if guid matches
537    if(c->GetGUID() != m_CapturePointCreature)
538        return false;
539
540    // check if capture point go is spawned
541    GameObject * cp = HashMapHolder<GameObject>::Find(m_CapturePoint);
542    if(!cp)
543        return false;
544
545    // check range and activity
546    if(cp->IsWithinDistInMap(p,cp->GetGOInfo()->raw.data[0]) && p->IsOutdoorPvPActive())
547    {
548        // data[8] will be used for player enter
549        return HandleCapturePointEvent(p, cp->GetGOInfo()->raw.data[8]); //i_objective->HandlePlayerEnter((Player*)u);
550    }
551    else
552    {
553        // data[9] will be used for player leave
554        return HandleCapturePointEvent(p, cp->GetGOInfo()->raw.data[9]); //i_objective->HandlePlayerLeave((Player*)u);
555    }
556}
557
558void OutdoorPvP::SendUpdateWorldState(uint32 field, uint32 value)
559{
560    // send to both factions
561    for(int i = 0; i < 2; ++i)
562    {
563        // send to all players present in the area
564        for(std::set<uint64>::iterator itr = m_PlayerGuids[i].begin(); itr != m_PlayerGuids[i].end(); ++itr)
565        {
566            Player * plr = objmgr.GetPlayer(*itr);
567            if(plr)
568            {
569                plr->SendUpdateWorldState(field,value);
570            }
571        }
572    }
573}
574
575void OutdoorPvPObjective::SendUpdateWorldState(uint32 field, uint32 value)
576{
577    // send to all players present in the area
578    for(std::set<uint64>::iterator itr = m_ActivePlayerGuids.begin(); itr != m_ActivePlayerGuids.end(); ++itr)
579    {
580        Player * plr = objmgr.GetPlayer(*itr);
581        if(plr)
582        {
583            plr->SendUpdateWorldState(field,value);
584        }
585    }
586}
587
588void OutdoorPvPObjective::SendObjectiveComplete(uint32 id,uint64 guid)
589{
590    uint32 controlling_faction;
591    switch(m_State)
592    {
593    case OBJECTIVESTATE_ALLIANCE:
594        controlling_faction = ALLIANCE;
595        break;
596    case OBJECTIVESTATE_HORDE:
597        controlling_faction = HORDE;
598        break;
599    default:
600        return;
601        break;
602    }
603
604    // send to all players present in the area
605    for(std::set<uint64>::iterator itr = m_ActivePlayerGuids.begin(); itr != m_ActivePlayerGuids.end(); ++itr)
606    {
607        Player * plr = objmgr.GetPlayer(*itr);
608        if(plr && plr->GetTeam() == controlling_faction)
609        {
610            plr->KilledMonster(id,guid);
611        }
612    }
613}
614
615void OutdoorPvP::HandlePlayerActivityChanged(Player * plr)
616{
617    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
618        (*itr)->HandlePlayerActivityChanged(plr);
619}
620
621void OutdoorPvP::HandleKill(Player *killer, Unit * killed)
622{
623    if(Group * pGroup = killer->GetGroup())
624    {
625        for(GroupReference *itr = pGroup->GetFirstMember(); itr != NULL; itr = itr->next())
626        {
627            Player *pGroupGuy = itr->getSource();
628
629            if(!pGroupGuy)
630                continue;
631
632            // skip if too far away
633            if(!pGroupGuy->IsAtGroupRewardDistance(killed))
634                continue;
635
636            // creature kills must be notified, even if not inside objective / not outdoor pvp active
637            // player kills only count if active and inside objective
638            if(( pGroupGuy->IsOutdoorPvPActive() && IsInsideObjective(pGroupGuy) ) || killed->GetTypeId() == TYPEID_UNIT)
639            {
640                HandleKillImpl(pGroupGuy, killed);
641            }
642        }
643    }
644    else
645    {
646        // creature kills must be notified, even if not inside objective / not outdoor pvp active
647        if(killer && (( killer->IsOutdoorPvPActive() && IsInsideObjective(killer) ) || killed->GetTypeId() == TYPEID_UNIT))
648        {
649            HandleKillImpl(killer, killed);
650        }
651    }
652}
653
654bool OutdoorPvP::IsInsideObjective(Player *plr)
655{
656    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
657    {
658        if((*itr)->IsInsideObjective(plr))
659            return true;
660    }
661    return false;
662}
663
664bool OutdoorPvPObjective::IsInsideObjective(Player *plr)
665{
666    std::set<uint64>::iterator itr = m_ActivePlayerGuids.find(plr->GetGUID());
667    return itr != m_ActivePlayerGuids.end();
668}
669
670bool OutdoorPvP::HandleCustomSpell(Player *plr, uint32 spellId, GameObject * go)
671{
672    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
673    {
674        if((*itr)->HandleCustomSpell(plr,spellId,go))
675            return true;
676    }
677    return false;
678}
679
680bool OutdoorPvPObjective::HandleCustomSpell(Player *plr, uint32 spellId, GameObject * go)
681{
682    if(!plr->IsOutdoorPvPActive())
683        return false;
684    return false;
685}
686
687bool OutdoorPvP::HandleOpenGo(Player *plr, uint64 guid)
688{
689    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
690    {
691        if((*itr)->HandleOpenGo(plr,guid) >= 0)
692            return true;
693    }
694    return false;
695}
696
697bool OutdoorPvP::HandleCaptureCreaturePlayerMoveInLos(Player * p, Creature * c)
698{
699    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
700    {
701        if((*itr)->HandleCaptureCreaturePlayerMoveInLos(p, c))
702            return true;
703    }
704    return false;
705}
706
707bool OutdoorPvP::HandleGossipOption(Player * plr, uint64 guid, uint32 id)
708{
709    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
710    {
711        if((*itr)->HandleGossipOption(plr, guid, id))
712            return true;
713    }
714    return false;
715}
716
717bool OutdoorPvP::CanTalkTo(Player * plr, Creature * c, GossipOption &gso)
718{
719    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
720    {
721        if((*itr)->CanTalkTo(plr, c, gso))
722            return true;
723    }
724    return false;
725}
726
727bool OutdoorPvP::HandleDropFlag(Player * plr, uint32 id)
728{
729    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
730    {
731        if((*itr)->HandleDropFlag(plr, id))
732            return true;
733    }
734    return false;
735}
736
737bool OutdoorPvPObjective::HandleGossipOption(Player * plr, uint64 guid, uint32 id)
738{
739    return false;
740}
741
742bool OutdoorPvPObjective::CanTalkTo(Player * plr, Creature * c, GossipOption &gso)
743{
744    return false;
745}
746
747bool OutdoorPvPObjective::HandleDropFlag(Player * plr, uint32 id)
748{
749    return false;
750}
751
752int32 OutdoorPvPObjective::HandleOpenGo(Player *plr, uint64 guid)
753{
754    std::map<uint64,uint32>::iterator itr = m_ObjectTypes.find(guid);
755    if(itr != m_ObjectTypes.end())
756    {
757        return itr->second;   
758    }
759    return -1;
760}
761
762bool OutdoorPvP::HandleAreaTrigger(Player *plr, uint32 trigger)
763{
764    return false;
765}
Note: See TracBrowser for help on using the browser.