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