root/trunk/src/game/OutdoorPvPSI.cpp @ 240

Revision 102, 9.1 kB (checked in by yumileroy, 17 years ago)

[svn] Fixed copyright notices to comply with GPL.

Original author: w12x
Date: 2008-10-23 03:29:52-05: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 "OutdoorPvPSI.h"
20#include "WorldPacket.h"
21#include "Player.h"
22#include "GameObject.h"
23#include "MapManager.h"
24#include "ObjectMgr.h"
25#include "OutdoorPvPMgr.h"
26#include "Language.h"
27#include "World.h"
28
29OutdoorPvPSI::OutdoorPvPSI()
30{
31    m_TypeId = OUTDOOR_PVP_SI;
32    m_Gathered_A = 0;
33    m_Gathered_H = 0;
34    m_LastController = 0;
35}
36
37void OutdoorPvPSI::FillInitialWorldStates(WorldPacket &data)
38{
39    data << SI_GATHERED_A << m_Gathered_A;
40    data << SI_GATHERED_H << m_Gathered_H;
41    data << SI_SILITHYST_MAX << SI_MAX_RESOURCES;
42}
43
44void OutdoorPvPSI::SendRemoveWorldStates(Player *plr)
45{
46    plr->SendUpdateWorldState(SI_GATHERED_A,0);
47    plr->SendUpdateWorldState(SI_GATHERED_H,0);
48    plr->SendUpdateWorldState(SI_SILITHYST_MAX,0);
49}
50
51void OutdoorPvPSI::UpdateWorldState()
52{
53    SendUpdateWorldState(SI_GATHERED_A,m_Gathered_A);
54    SendUpdateWorldState(SI_GATHERED_H,m_Gathered_H);
55    SendUpdateWorldState(SI_SILITHYST_MAX,SI_MAX_RESOURCES);
56}
57
58bool OutdoorPvPSI::SetupOutdoorPvP()
59{
60    for(int i = 0; i < OutdoorPvPSIBuffZonesNum; ++i)
61        sOutdoorPvPMgr.AddZone(OutdoorPvPSIBuffZones[i],this);
62    return true;
63}
64
65bool OutdoorPvPSI::Update(uint32 diff)
66{
67    return false;
68}
69
70void OutdoorPvPSI::HandlePlayerEnterZone(Player * plr, uint32 zone)
71{
72    if(plr->GetTeam() == m_LastController)
73        plr->CastSpell(plr,SI_CENARION_FAVOR,true);
74    OutdoorPvP::HandlePlayerEnterZone(plr,zone);
75}
76
77void OutdoorPvPSI::HandlePlayerLeaveZone(Player * plr, uint32 zone)
78{
79    // remove buffs
80    plr->RemoveAurasDueToSpell(SI_CENARION_FAVOR);
81    OutdoorPvP::HandlePlayerLeaveZone(plr, zone);
82}
83
84void OutdoorPvPSI::BuffTeam(uint32 team)
85{
86    if(team == ALLIANCE)
87    {
88        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
89        {
90            if(Player * plr = objmgr.GetPlayer(*itr))
91                if(plr->IsInWorld()) plr->CastSpell(plr,SI_CENARION_FAVOR,true);
92        }
93        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
94        {
95            if(Player * plr = objmgr.GetPlayer(*itr))
96                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(SI_CENARION_FAVOR);
97        }
98    }
99    else if(team == HORDE)
100    {
101        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
102        {
103            if(Player * plr = objmgr.GetPlayer(*itr))
104                if(plr->IsInWorld()) plr->CastSpell(plr,SI_CENARION_FAVOR,true);
105        }
106        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
107        {
108            if(Player * plr = objmgr.GetPlayer(*itr))
109                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(SI_CENARION_FAVOR);
110        }
111    }
112    else
113    {
114        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
115        {
116            if(Player * plr = objmgr.GetPlayer(*itr))
117                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(SI_CENARION_FAVOR);
118        }
119        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
120        {
121            if(Player * plr = objmgr.GetPlayer(*itr))
122                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(SI_CENARION_FAVOR);
123        }
124    }
125}
126
127bool OutdoorPvPSI::HandleAreaTrigger(Player *plr, uint32 trigger)
128{
129    switch(trigger)
130    {
131    case SI_AREATRIGGER_A:
132        if(plr->GetTeam() == ALLIANCE && plr->HasAura(SI_SILITHYST_FLAG,0))
133        {
134            // remove aura
135            plr->RemoveAurasDueToSpell(SI_SILITHYST_FLAG);
136            ++ m_Gathered_A;
137            if(m_Gathered_A >= SI_MAX_RESOURCES)
138            {
139                BuffTeam(ALLIANCE);
140                sWorld.SendZoneText(OutdoorPvPSIBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_A));
141                m_LastController = ALLIANCE;
142                m_Gathered_A = 0;
143                m_Gathered_H = 0;
144            }
145            UpdateWorldState();
146            // reward player
147            plr->CastSpell(plr,SI_TRACES_OF_SILITHYST,true);
148            // add 19 honor
149            plr->RewardHonor(NULL,1,19);
150            // add 20 cenarion circle repu
151            plr->ModifyFactionReputation(609,20);
152            // complete quest
153            plr->KilledMonster(SI_TURNIN_QUEST_CM_A,0);
154        }
155        return true;
156    case SI_AREATRIGGER_H:
157        if(plr->GetTeam() == HORDE && plr->HasAura(SI_SILITHYST_FLAG,0))
158        {
159            // remove aura
160            plr->RemoveAurasDueToSpell(SI_SILITHYST_FLAG);
161            ++ m_Gathered_H;
162            if(m_Gathered_H >= SI_MAX_RESOURCES)
163            {
164                BuffTeam(HORDE);
165                sWorld.SendZoneText(OutdoorPvPSIBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_SI_CAPTURE_H));
166                m_LastController = HORDE;
167                m_Gathered_A = 0;
168                m_Gathered_H = 0;
169            }
170            UpdateWorldState();
171            // reward player
172            plr->CastSpell(plr,SI_TRACES_OF_SILITHYST,true);
173            // add 19 honor
174            plr->RewardHonor(NULL,1,19);
175            // add 20 cenarion circle repu
176            plr->ModifyFactionReputation(609,20);
177            // complete quest
178            plr->KilledMonster(SI_TURNIN_QUEST_CM_H,0);
179        }
180        return true;
181    }
182    return false;
183}
184
185bool OutdoorPvPSI::HandleDropFlag(Player *plr, uint32 spellId)
186{
187    if(spellId == SI_SILITHYST_FLAG)
188    {
189        // if it was dropped away from the player's turn-in point, then create a silithyst mound, if it was dropped near the areatrigger, then it was dispelled by the outdoorpvp, so do nothing
190        switch(plr->GetTeam())
191        {
192        case ALLIANCE:
193            {
194                AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(SI_AREATRIGGER_A);
195                if(atEntry)
196                {
197                    // 5.0f is safe-distance
198                    if(plr->GetDistance(atEntry->x,atEntry->y,atEntry->z) > 5.0f + atEntry->radius)
199                    {
200                        // he dropped it further, summon mound
201                        GameObject * go = new GameObject;
202                        Map * map = MapManager::Instance().GetMap(plr->GetMapId(), plr);
203                        if(!map)
204                            return true;
205                        if(!go->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),SI_SILITHYST_MOUND, map,plr->GetPositionX(),plr->GetPositionY(),plr->GetPositionZ(),plr->GetOrientation(),0,0,0,0,100,1))
206                        {
207                            delete go;               
208                        }
209                        else
210                        {
211                            go->SetRespawnTime(0);
212                            map->Add(go);
213                        }
214                    }
215                }
216            }
217            break;
218        case HORDE:
219            {
220                AreaTriggerEntry const* atEntry = sAreaTriggerStore.LookupEntry(SI_AREATRIGGER_H);
221                if(atEntry)
222                {
223                    // 5.0f is safe-distance
224                    if(plr->GetDistance(atEntry->x,atEntry->y,atEntry->z) > 5.0f + atEntry->radius)
225                    {
226                        // he dropped it further, summon mound
227                        GameObject * go = new GameObject;
228                        Map * map = MapManager::Instance().GetMap(plr->GetMapId(), plr);
229                        if(!map)
230                            return true;
231                        if(!go->Create(objmgr.GenerateLowGuid(HIGHGUID_GAMEOBJECT),SI_SILITHYST_MOUND, map ,plr->GetPositionX(),plr->GetPositionY(),plr->GetPositionZ(),plr->GetOrientation(),0,0,0,0,100,1))
232                        {
233                            delete go;               
234                        }
235                        else
236                        {
237                            go->SetRespawnTime(0);
238                            map->Add(go);
239                        }
240                    }
241                }
242            }
243            break;
244        }
245        return true;
246    }
247    return false;
248}
249
250bool OutdoorPvPSI::HandleCustomSpell(Player *plr, uint32 spellId, GameObject *go)
251{
252    if(!go || spellId != SI_SILITHYST_FLAG_GO_SPELL)
253        return false;
254    plr->CastSpell(plr,SI_SILITHYST_FLAG,true);
255    if(go->GetGOInfo()->id == SI_SILITHYST_MOUND)
256    {
257        // despawn go
258        go->SetRespawnTime(0);
259        go->Delete();
260    }
261    return true;
262}
Note: See TracBrowser for help on using the browser.