root/trunk/src/game/OutdoorPvPTF.cpp @ 157

Revision 102, 14.6 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 "OutdoorPvPTF.h"
20#include "OutdoorPvPMgr.h"
21#include "WorldPacket.h"
22#include "Player.h"
23#include "ObjectMgr.h"
24#include "Language.h"
25#include "World.h"
26
27OutdoorPvPTF::OutdoorPvPTF()
28{
29    m_TypeId = OUTDOOR_PVP_TF;
30}
31
32OutdoorPvPObjectiveTF::OutdoorPvPObjectiveTF(OutdoorPvP *pvp, OutdoorPvPTF_TowerType type)
33: OutdoorPvPObjective(pvp), m_TowerType(type), m_TowerState(TF_TOWERSTATE_N)
34{
35    AddCapturePoint(TFCapturePoints[type].entry,TFCapturePoints[type].map,TFCapturePoints[type].x,TFCapturePoints[type].y,TFCapturePoints[type].z,TFCapturePoints[type].o,TFCapturePoints[type].rot0,TFCapturePoints[type].rot1,TFCapturePoints[type].rot2,TFCapturePoints[type].rot3);
36}
37
38void OutdoorPvPObjectiveTF::FillInitialWorldStates(WorldPacket &data)
39{
40    data << uint32(TFTowerWorldStates[m_TowerType].n) << uint32(bool(m_TowerState & TF_TOWERSTATE_N));
41    data << uint32(TFTowerWorldStates[m_TowerType].h) << uint32(bool(m_TowerState & TF_TOWERSTATE_H));
42    data << uint32(TFTowerWorldStates[m_TowerType].a) << uint32(bool(m_TowerState & TF_TOWERSTATE_A));
43}
44
45void OutdoorPvPTF::FillInitialWorldStates(WorldPacket &data)
46{
47    data << TF_UI_TOWER_SLIDER_POS << uint32(50);
48    data << TF_UI_TOWER_SLIDER_N << uint32(100);
49    data << TF_UI_TOWER_SLIDER_DISPLAY << uint32(0);
50
51    data << TF_UI_TOWER_COUNT_H << m_HordeTowersControlled;
52    data << TF_UI_TOWER_COUNT_A << m_AllianceTowersControlled;
53    data << TF_UI_TOWERS_CONTROLLED_DISPLAY << uint32(!m_IsLocked);
54
55    data << TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT << first_digit;
56    data << TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT << second_digit;
57    data << TF_UI_LOCKED_TIME_HOURS << hours_left;
58
59    data << TF_UI_LOCKED_DISPLAY_NEUTRAL << uint32(m_IsLocked && !m_HordeTowersControlled && !m_AllianceTowersControlled);
60    data << TF_UI_LOCKED_DISPLAY_HORDE << uint32(m_IsLocked && (m_HordeTowersControlled > m_AllianceTowersControlled));
61    data << TF_UI_LOCKED_DISPLAY_ALLIANCE << uint32(m_IsLocked && (m_HordeTowersControlled < m_AllianceTowersControlled));
62
63    for(OutdoorPvPObjectiveSet::iterator itr = m_OutdoorPvPObjectives.begin(); itr != m_OutdoorPvPObjectives.end(); ++itr)
64    {
65        (*itr)->FillInitialWorldStates(data);
66    }
67}
68
69void OutdoorPvPTF::SendRemoveWorldStates(Player * plr)
70{
71    plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_POS,uint32(0));
72    plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_N,uint32(0));
73    plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_DISPLAY,uint32(0));
74
75    plr->SendUpdateWorldState(TF_UI_TOWER_COUNT_H,uint32(0));
76    plr->SendUpdateWorldState(TF_UI_TOWER_COUNT_A,uint32(0));
77    plr->SendUpdateWorldState(TF_UI_TOWERS_CONTROLLED_DISPLAY,uint32(0));
78
79    plr->SendUpdateWorldState(TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT,uint32(0));
80    plr->SendUpdateWorldState(TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT,uint32(0));
81    plr->SendUpdateWorldState(TF_UI_LOCKED_TIME_HOURS,uint32(0));
82
83    plr->SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_NEUTRAL,uint32(0));
84    plr->SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_HORDE,uint32(0));
85    plr->SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_ALLIANCE,uint32(0));
86
87    for(int i = 0; i < TF_TOWER_NUM; ++i)
88    {
89        plr->SendUpdateWorldState(uint32(TFTowerWorldStates[i].n),uint32(0));
90        plr->SendUpdateWorldState(uint32(TFTowerWorldStates[i].h),uint32(0));
91        plr->SendUpdateWorldState(uint32(TFTowerWorldStates[i].a),uint32(0));
92    }
93}
94
95void OutdoorPvPObjectiveTF::UpdateTowerState()
96{
97    m_PvP->SendUpdateWorldState(uint32(TFTowerWorldStates[m_TowerType].n),uint32(bool(m_TowerState & TF_TOWERSTATE_N)));
98    m_PvP->SendUpdateWorldState(uint32(TFTowerWorldStates[m_TowerType].h),uint32(bool(m_TowerState & TF_TOWERSTATE_H)));
99    m_PvP->SendUpdateWorldState(uint32(TFTowerWorldStates[m_TowerType].a),uint32(bool(m_TowerState & TF_TOWERSTATE_A)));
100}
101
102bool OutdoorPvPObjectiveTF::HandlePlayerEnter(Player *plr)
103{
104    if(OutdoorPvPObjective::HandlePlayerEnter(plr))
105    {
106        plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_DISPLAY, 1);
107        uint32 phase = (uint32)ceil(( m_ShiftPhase + m_ShiftMaxPhase) / ( 2 * m_ShiftMaxPhase ) * 100.0f);
108        plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_POS, phase);
109        plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_N, m_NeutralValue);
110        return true;
111    }
112    return false;
113}
114
115void OutdoorPvPObjectiveTF::HandlePlayerLeave(Player *plr)
116{
117    plr->SendUpdateWorldState(TF_UI_TOWER_SLIDER_DISPLAY, 0);
118    OutdoorPvPObjective::HandlePlayerLeave(plr);
119}
120
121bool OutdoorPvPObjectiveTF::HandleCapturePointEvent(Player *plr, uint32 eventId)
122{
123    if(eventId == TFTowerPlayerEnterEvents[m_TowerType])
124    {
125        this->HandlePlayerEnter(plr);
126        return true;
127    }
128    else if (eventId == TFTowerPlayerLeaveEvents[m_TowerType])
129    {
130        this->HandlePlayerLeave(plr);
131        return true;
132    }
133    return false;
134}
135
136void OutdoorPvPTF::BuffTeam(uint32 team)
137{
138    if(team == ALLIANCE)
139    {
140        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
141        {
142            if(Player * plr = objmgr.GetPlayer(*itr))
143                if(plr->IsInWorld()) plr->CastSpell(plr,TF_CAPTURE_BUFF,true);
144        }
145        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
146        {
147            if(Player * plr = objmgr.GetPlayer(*itr))
148                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(TF_CAPTURE_BUFF);
149        }
150    }
151    else if(team == HORDE)
152    {
153        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
154        {
155            if(Player * plr = objmgr.GetPlayer(*itr))
156                if(plr->IsInWorld()) plr->CastSpell(plr,TF_CAPTURE_BUFF,true);
157        }
158        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
159        {
160            if(Player * plr = objmgr.GetPlayer(*itr))
161                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(TF_CAPTURE_BUFF);
162        }
163    }
164    else
165    {
166        for(std::set<uint64>::iterator itr = m_PlayerGuids[0].begin(); itr != m_PlayerGuids[0].end(); ++itr)
167        {
168            if(Player * plr = objmgr.GetPlayer(*itr))
169                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(TF_CAPTURE_BUFF);
170        }
171        for(std::set<uint64>::iterator itr = m_PlayerGuids[1].begin(); itr != m_PlayerGuids[1].end(); ++itr)
172        {
173            if(Player * plr = objmgr.GetPlayer(*itr))
174                if(plr->IsInWorld()) plr->RemoveAurasDueToSpell(TF_CAPTURE_BUFF);
175        }
176    }
177}
178
179bool OutdoorPvPTF::Update(uint32 diff)
180{
181    bool changed = false;
182
183    if(changed = OutdoorPvP::Update(diff))
184    {
185        if(m_AllianceTowersControlled == TF_TOWER_NUM)
186        {
187            BuffTeam(ALLIANCE);
188            m_IsLocked = true;
189            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_NEUTRAL,uint32(0));
190            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_HORDE,uint32(0));
191            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_ALLIANCE,uint32(1));
192            SendUpdateWorldState(TF_UI_TOWERS_CONTROLLED_DISPLAY, uint32(0));
193        }
194        else if(m_HordeTowersControlled == TF_TOWER_NUM)
195        {
196            BuffTeam(HORDE);
197            m_IsLocked = true;
198            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_NEUTRAL,uint32(0));
199            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_HORDE,uint32(1));
200            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_ALLIANCE,uint32(0));
201            SendUpdateWorldState(TF_UI_TOWERS_CONTROLLED_DISPLAY, uint32(0));
202        }
203        else
204            BuffTeam(NULL);
205        SendUpdateWorldState(TF_UI_TOWER_COUNT_A, m_AllianceTowersControlled);
206        SendUpdateWorldState(TF_UI_TOWER_COUNT_H, m_HordeTowersControlled);
207    }
208    if(m_IsLocked)
209    {
210        // lock timer is down, release lock
211        if(m_LockTimer < diff)
212        {
213            m_LockTimer = TF_LOCK_TIME;
214            m_LockTimerUpdate = 0;
215            m_IsLocked = false;
216            SendUpdateWorldState(TF_UI_TOWERS_CONTROLLED_DISPLAY, uint32(1));
217            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_NEUTRAL,uint32(0));
218            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_HORDE,uint32(0));
219            SendUpdateWorldState(TF_UI_LOCKED_DISPLAY_ALLIANCE,uint32(0));
220        }
221        else
222        {
223            // worldstateui update timer is down, update ui with new time data
224            if(m_LockTimerUpdate < diff)
225            {
226                m_LockTimerUpdate = TF_LOCK_TIME_UPDATE;
227                uint32 minutes_left = m_LockTimer / 60000;
228                hours_left = minutes_left / 60;
229                minutes_left -= hours_left * 60;
230                second_digit = minutes_left % 10;
231                first_digit = minutes_left / 10;
232
233                SendUpdateWorldState(TF_UI_LOCKED_TIME_MINUTES_FIRST_DIGIT,first_digit);
234                SendUpdateWorldState(TF_UI_LOCKED_TIME_MINUTES_SECOND_DIGIT,second_digit);
235                SendUpdateWorldState(TF_UI_LOCKED_TIME_HOURS,hours_left);
236            } else m_LockTimerUpdate -= diff;
237            m_LockTimer -= diff;
238        }
239    }
240    return changed;
241}
242
243void OutdoorPvPTF::HandlePlayerEnterZone(Player * plr, uint32 zone)
244{
245    if(plr->GetTeam() == ALLIANCE)
246    {
247        if(m_AllianceTowersControlled >= TF_TOWER_NUM)
248            plr->CastSpell(plr,TF_CAPTURE_BUFF,true);
249    }
250    else
251    {
252        if(m_HordeTowersControlled >= TF_TOWER_NUM)
253            plr->CastSpell(plr,TF_CAPTURE_BUFF,true);
254    }
255    OutdoorPvP::HandlePlayerEnterZone(plr,zone);
256}
257
258void OutdoorPvPTF::HandlePlayerLeaveZone(Player * plr, uint32 zone)
259{
260    // remove buffs
261    plr->RemoveAurasDueToSpell(TF_CAPTURE_BUFF);
262    OutdoorPvP::HandlePlayerLeaveZone(plr, zone);
263}
264
265bool OutdoorPvPTF::SetupOutdoorPvP()
266{
267    m_AllianceTowersControlled = 0;
268    m_HordeTowersControlled = 0;
269
270    m_IsLocked = false;
271    m_LockTimer = TF_LOCK_TIME;
272    m_LockTimerUpdate = 0; 
273    hours_left = 6;
274    second_digit = 0;
275    first_digit = 0;
276
277    // add the zones affected by the pvp buff
278    for(int i = 0; i < OutdoorPvPTFBuffZonesNum; ++i)
279        sOutdoorPvPMgr.AddZone(OutdoorPvPTFBuffZones[i],this);
280
281    m_OutdoorPvPObjectives.insert(new OutdoorPvPObjectiveTF(this,TF_TOWER_NW));
282    m_OutdoorPvPObjectives.insert(new OutdoorPvPObjectiveTF(this,TF_TOWER_N));
283    m_OutdoorPvPObjectives.insert(new OutdoorPvPObjectiveTF(this,TF_TOWER_NE));
284    m_OutdoorPvPObjectives.insert(new OutdoorPvPObjectiveTF(this,TF_TOWER_SE));
285    m_OutdoorPvPObjectives.insert(new OutdoorPvPObjectiveTF(this,TF_TOWER_S));
286
287    return true;
288}
289
290bool OutdoorPvPObjectiveTF::Update(uint32 diff)
291{
292    // can update even in locked state if gathers the controlling faction
293    bool canupdate = ((((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled > 0) && this->m_AllianceActivePlayerCount > this->m_HordeActivePlayerCount) ||
294            ((((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled > 0) && this->m_AllianceActivePlayerCount < this->m_HordeActivePlayerCount);
295    // if gathers the other faction, then only update if the pvp is unlocked
296    canupdate = canupdate || !((OutdoorPvPTF*)m_PvP)->m_IsLocked;
297    if(canupdate && OutdoorPvPObjective::Update(diff))
298    {
299        if(m_OldState != m_State)
300        {
301            // if changing from controlling alliance to horde
302            if( m_OldState == OBJECTIVESTATE_ALLIANCE )
303            {
304                if(((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled)
305                    ((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled--;
306                sWorld.SendZoneText(OutdoorPvPTFBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_TF_LOOSE_A));
307            }
308            // if changing from controlling horde to alliance
309            else if ( m_OldState == OBJECTIVESTATE_HORDE )
310            {
311                if(((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled)
312                    ((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled--;
313                sWorld.SendZoneText(OutdoorPvPTFBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_TF_LOOSE_H));
314            }
315
316            uint32 artkit = 21;
317
318            switch(m_State)
319            {
320            case OBJECTIVESTATE_ALLIANCE:
321                m_TowerState = TF_TOWERSTATE_A;
322                artkit = 2;
323                if(((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled<TF_TOWER_NUM)
324                    ((OutdoorPvPTF*)m_PvP)->m_AllianceTowersControlled++;
325                sWorld.SendZoneText(OutdoorPvPTFBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_TF_CAPTURE_A));
326                break;
327            case OBJECTIVESTATE_HORDE:
328                m_TowerState = TF_TOWERSTATE_H;
329                artkit = 1;
330                if(((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled<TF_TOWER_NUM)
331                    ((OutdoorPvPTF*)m_PvP)->m_HordeTowersControlled++;
332                sWorld.SendZoneText(OutdoorPvPTFBuffZones[0],objmgr.GetTrinityStringForDBCLocale(LANG_OPVP_TF_CAPTURE_H));
333                break;
334            case OBJECTIVESTATE_NEUTRAL:
335            case OBJECTIVESTATE_NEUTRAL_ALLIANCE_CHALLENGE:
336            case OBJECTIVESTATE_NEUTRAL_HORDE_CHALLENGE:
337            case OBJECTIVESTATE_ALLIANCE_HORDE_CHALLENGE:
338            case OBJECTIVESTATE_HORDE_ALLIANCE_CHALLENGE:
339                m_TowerState = TF_TOWERSTATE_N;
340                break;
341            }
342
343            GameObject* flag = HashMapHolder<GameObject>::Find(m_CapturePoint);
344            if(flag)
345            {
346                flag->SetGoArtKit(artkit);
347                flag->SendUpdateObjectToAllExcept(NULL);
348            }
349
350            UpdateTowerState();
351        }
352
353        if(m_ShiftPhase != m_OldPhase)
354        {
355            // send this too, sometimes the slider disappears, dunno why :(
356            SendUpdateWorldState(TF_UI_TOWER_SLIDER_DISPLAY, 1);
357            // send these updates to only the ones in this objective
358            uint32 phase = (uint32)ceil(( m_ShiftPhase + m_ShiftMaxPhase) / ( 2 * m_ShiftMaxPhase ) * 100.0f);
359            SendUpdateWorldState(TF_UI_TOWER_SLIDER_POS, phase);
360            // send this too, sometimes it resets :S
361            SendUpdateWorldState(TF_UI_TOWER_SLIDER_N, m_NeutralValue);
362        }
363        return true;
364    }
365    return false;
366}
Note: See TracBrowser for help on using the browser.