Core/GameObject: Implement ControlZone gameobject type

Port From (https://github.com/TrinityCore/TrinityCore/commit/f96f041c3edadfb5f1f09705fe699c2d7a9ed423)
This commit is contained in:
hondacrx
2024-01-31 20:53:44 -05:00
parent 7545d9395d
commit e2caec12dc
11 changed files with 998 additions and 1270 deletions
+62 -295
View File
@@ -2,18 +2,13 @@
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
using Framework.Constants;
using Framework.Database;
using Game.Chat;
using Game.DataStorage;
using Game.Entities;
using Game.Groups;
using Game.Maps;
using Game.Misc;
using Game.Networking;
using Game.Networking.Packets;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
namespace Game.PvP
@@ -36,9 +31,6 @@ namespace Game.PvP
public virtual void HandlePlayerLeaveZone(Player player, uint zone)
{
// inform the objectives of the leaving
foreach (var pair in m_capturePoints)
pair.Value.HandlePlayerLeave(player);
// 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)
if (!player.GetSession().PlayerLogout())
SendRemoveWorldStates(player);
@@ -48,15 +40,10 @@ namespace Game.PvP
public virtual void HandlePlayerResurrects(Player player, uint zone) { }
public virtual bool Update(uint diff)
public virtual void Update(uint diff)
{
bool objective_changed = false;
foreach (var pair in m_capturePoints)
{
if (pair.Value.Update(diff))
objective_changed = true;
}
return objective_changed;
foreach (var (_, capturePoint) in m_capturePoints)
capturePoint.Update(diff);
}
public int GetWorldState(int worldStateId)
@@ -87,27 +74,18 @@ namespace Game.PvP
// creature kills must be notified, even if not inside objective / not outdoor pvp active
// player kills only count if active and inside objective
if ((groupGuy.IsOutdoorPvPActive() && IsInsideObjective(groupGuy)) || killed.IsTypeId(TypeId.Unit))
if (groupGuy.IsOutdoorPvPActive() || killed.IsTypeId(TypeId.Unit))
HandleKillImpl(groupGuy, killed);
}
}
else
{
// creature kills must be notified, even if not inside objective / not outdoor pvp active
if ((killer.IsOutdoorPvPActive() && IsInsideObjective(killer)) || killed.IsTypeId(TypeId.Unit))
if (killer.IsOutdoorPvPActive() || killed.IsTypeId(TypeId.Unit))
HandleKillImpl(killer, killed);
}
}
bool IsInsideObjective(Player player)
{
foreach (var pair in m_capturePoints)
if (pair.Value.IsInsideObjective(player))
return true;
return false;
}
public virtual bool HandleCustomSpell(Player player, uint spellId, GameObject go)
{
foreach (var pair in m_capturePoints)
@@ -140,7 +118,7 @@ namespace Game.PvP
return false;
}
void BroadcastPacket(ServerPacket packet)
public void BroadcastPacket(ServerPacket packet)
{
// This is faster than sWorld.SendZoneMessage
for (int team = 0; team < 2; ++team)
@@ -185,26 +163,6 @@ namespace Game.PvP
TeamCastSpell((uint)(teamIndex == TeamId.Alliance ? TeamId.Horde : TeamId.Alliance), spellId2 != 0 ? -(int)spellId2 : -(int)spellId);
}
public override void OnGameObjectCreate(GameObject go)
{
if (go.GetGoType() != GameObjectTypes.ControlZone)
return;
OPvPCapturePoint cp = GetCapturePoint(go.GetSpawnId());
if (cp != null)
cp.m_capturePoint = go;
}
public override void OnGameObjectRemove(GameObject go)
{
if (go.GetGoType() != GameObjectTypes.ControlZone)
return;
OPvPCapturePoint cp = GetCapturePoint(go.GetSpawnId());
if (cp != null)
cp.m_capturePoint = null;
}
public void SendDefenseMessage(uint zoneId, uint id)
{
DefenseMessageBuilder builder = new(zoneId, id);
@@ -212,6 +170,40 @@ namespace Game.PvP
BroadcastWorker(localizer, zoneId);
}
public override void ProcessEvent(WorldObject target, uint eventId, WorldObject invoker)
{
if (invoker != null)
{
GameObject gameobject = invoker.ToGameObject();
if (gameobject != null)
{
if (gameobject.GetGoType() == GameObjectTypes.ControlZone)
{
if (!ControlZoneHandlers.TryGetValue(gameobject.GetEntry(), out OutdoorPvPControlZoneHandler handler))
return;
var controlzone = gameobject.GetGoInfo().ControlZone;
if (eventId == controlzone.CaptureEventAlliance)
handler.HandleCaptureEventAlliance(gameobject);
else if (eventId == controlzone.CaptureEventHorde)
handler.HandleCaptureEventHorde(gameobject);
else if (eventId == controlzone.ContestedEventAlliance)
handler.HandleContestedEventAlliance(gameobject);
else if (eventId == controlzone.ContestedEventHorde)
handler.HandleContestedEventHorde(gameobject);
else if (eventId == controlzone.NeutralEventAlliance)
handler.HandleNeutralEventAlliance(gameobject);
else if (eventId == controlzone.NeutralEventHorde)
handler.HandleNeutralEventHorde(gameobject);
else if (eventId == controlzone.ProgressEventAlliance)
handler.HandleProgressEventAlliance(gameobject);
else if (eventId == controlzone.ProgressEventHorde)
handler.HandleProgressEventHorde(gameobject);
}
}
}
}
void BroadcastWorker(IDoWork<Player> _worker, uint zoneId)
{
for (uint i = 0; i < SharedConst.PvpTeamsCount; ++i)
@@ -238,23 +230,11 @@ namespace Game.PvP
public virtual void SendRemoveWorldStates(Player player) { }
public void AddCapturePoint(OPvPCapturePoint cp)
{
if (m_capturePoints.ContainsKey(cp.m_capturePointSpawnId))
Log.outError(LogFilter.Outdoorpvp, "OutdoorPvP.AddCapturePoint: CapturePoint {0} already exists!", cp.m_capturePointSpawnId);
m_capturePoints[cp.m_capturePointSpawnId] = cp;
}
OPvPCapturePoint GetCapturePoint(ulong lowguid)
{
return m_capturePoints.LookupByKey(lowguid);
}
public Map GetMap() { return m_map; }
// the map of the objectives belonging to this outdoorpvp
public Dictionary<ulong, OPvPCapturePoint> m_capturePoints = new();
protected Dictionary<uint /*control zone entry*/, OutdoorPvPControlZoneHandler> ControlZoneHandlers = new();
List<ObjectGuid>[] m_players = new List<ObjectGuid>[2];
public OutdoorPvPTypes m_TypeId;
@@ -263,229 +243,24 @@ namespace Game.PvP
public class OPvPCapturePoint
{
uint m_team;
// objective states
public ObjectiveStates OldState { get; set; }
public ObjectiveStates State { get; set; }
// pointer to the OutdoorPvP this objective belongs to
public OutdoorPvP PvP { get; set; }
public OPvPCapturePoint(OutdoorPvP pvp)
{
m_team = TeamId.Neutral;
OldState = ObjectiveStates.Neutral;
State = ObjectiveStates.Neutral;
PvP = pvp;
m_activePlayers[0] = new HashSet<ObjectGuid>();
m_activePlayers[1] = new HashSet<ObjectGuid>();
}
public virtual bool HandlePlayerEnter(Player player)
{
if (m_capturePoint != null)
{
player.SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldState1, 1);
player.SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldstate2, (uint)Math.Ceiling((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
player.SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldstate3, m_neutralValuePct);
}
return m_activePlayers[player.GetTeamId()].Add(player.GetGUID());
}
public virtual void HandlePlayerLeave(Player player)
{
if (m_capturePoint != null)
player.SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldState1, 0);
m_activePlayers[player.GetTeamId()].Remove(player.GetGUID());
}
public virtual void SendChangePhase()
{
if (m_capturePoint == null)
return;
// send this too, sometimes the slider disappears, dunno why :(
SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldState1, 1);
// send these updates to only the ones in this objective
SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldstate2, (uint)Math.Ceiling((m_value + m_maxValue) / (2 * m_maxValue) * 100.0f));
// send this too, sometimes it resets :S
SendUpdateWorldState(m_capturePoint.GetGoInfo().ControlZone.worldstate3, m_neutralValuePct);
}
public bool SetCapturePointData(uint entry)
{
Log.outDebug(LogFilter.Outdoorpvp, "Creating capture point {0}", entry);
// check info existence
GameObjectTemplate goinfo = Global.ObjectMgr.GetGameObjectTemplate(entry);
if (goinfo == null || goinfo.type != GameObjectTypes.ControlZone)
{
Log.outError(LogFilter.Outdoorpvp, "OutdoorPvP: GO {0} is not capture point!", entry);
return false;
}
// get the needed values from goinfo
m_maxValue = goinfo.ControlZone.maxTime;
m_maxSpeed = m_maxValue / (goinfo.ControlZone.minTime != 0 ? goinfo.ControlZone.minTime : 60);
m_neutralValuePct = goinfo.ControlZone.neutralPercent;
m_minValue = MathFunctions.CalculatePct(m_maxValue, m_neutralValuePct);
return true;
}
public virtual bool Update(uint diff)
{
if (m_capturePoint == null)
return false;
float radius = m_capturePoint.GetGoInfo().ControlZone.radius;
for (int team = 0; team < 2; ++team)
{
foreach (var playerGuid in m_activePlayers[team].ToList())
{
Player player = Global.ObjAccessor.FindPlayer(playerGuid);
if (player != null)
if (!m_capturePoint.IsWithinDistInMap(player, radius) || !player.IsOutdoorPvPActive())
HandlePlayerLeave(player);
}
}
List<Unit> players = new();
var checker = new AnyPlayerInObjectRangeCheck(m_capturePoint, radius);
var searcher = new PlayerListSearcher(m_capturePoint, players, checker);
Cell.VisitWorldObjects(m_capturePoint, searcher, radius);
foreach (Player player in players)
{
if (player.IsOutdoorPvPActive())
{
if (m_activePlayers[player.GetTeamId()].Add(player.GetGUID()))
HandlePlayerEnter(player);
}
}
// get the difference of numbers
float fact_diff = (float)(m_activePlayers[0].Count - m_activePlayers[1].Count) * diff / 1000;
if (fact_diff == 0.0f)
return false;
Team Challenger;
float maxDiff = m_maxSpeed * diff;
if (fact_diff < 0)
{
// horde is in majority, but it's already horde-controlled . no change
if (State == ObjectiveStates.Horde && m_value <= -m_maxValue)
return false;
if (fact_diff < -maxDiff)
fact_diff = -maxDiff;
Challenger = Team.Horde;
}
else
{
// ally is in majority, but it's already ally-controlled . no change
if (State == ObjectiveStates.Alliance && m_value >= m_maxValue)
return false;
if (fact_diff > maxDiff)
fact_diff = maxDiff;
Challenger = Team.Alliance;
}
float oldValue = m_value;
uint oldTeam = m_team;
OldState = State;
m_value += fact_diff;
if (m_value < -m_minValue) // red
{
if (m_value < -m_maxValue)
m_value = -m_maxValue;
State = ObjectiveStates.Horde;
m_team = TeamId.Horde;
}
else if (m_value > m_minValue) // blue
{
if (m_value > m_maxValue)
m_value = m_maxValue;
State = ObjectiveStates.Alliance;
m_team = TeamId.Alliance;
}
else if (oldValue * m_value <= 0) // grey, go through mid point
{
// if challenger is ally, then n.a challenge
if (Challenger == Team.Alliance)
State = ObjectiveStates.NeutralAllianceChallenge;
// if challenger is horde, then n.h challenge
else if (Challenger == Team.Horde)
State = ObjectiveStates.NeutralHordeChallenge;
m_team = TeamId.Neutral;
}
else // grey, did not go through mid point
{
// old phase and current are on the same side, so one team challenges the other
if (Challenger == Team.Alliance && (OldState == ObjectiveStates.Horde || OldState == ObjectiveStates.NeutralHordeChallenge))
State = ObjectiveStates.HordeAllianceChallenge;
else if (Challenger == Team.Horde && (OldState == ObjectiveStates.Alliance || OldState == ObjectiveStates.NeutralAllianceChallenge))
State = ObjectiveStates.AllianceHordeChallenge;
m_team = TeamId.Neutral;
}
if (m_value != oldValue)
SendChangePhase();
if (OldState != State)
{
if (oldTeam != m_team)
ChangeTeam(oldTeam);
ChangeState();
return true;
}
return false;
}
public void SendUpdateWorldState(uint field, uint value)
{
for (int team = 0; team < 2; ++team)
{
// send to all players present in the area
foreach (var guid in m_activePlayers[team])
{
Player player = Global.ObjAccessor.FindPlayer(guid);
if (player != null)
player.SendUpdateWorldState(field, value);
}
}
}
public void SendObjectiveComplete(uint id, ObjectGuid guid)
{
uint team;
switch (State)
{
case ObjectiveStates.Alliance:
team = 0;
break;
case ObjectiveStates.Horde:
team = 1;
break;
default:
return;
}
// send to all players present in the area
foreach (var playerGuid in m_activePlayers[team])
{
Player player = Global.ObjAccessor.FindPlayer(playerGuid);
if (player != null)
player.KilledMonsterCredit(id, guid);
}
}
public bool IsInsideObjective(Player player)
{
var plSet = m_activePlayers[player.GetTeamId()];
return plSet.Contains(player.GetGUID());
}
public virtual void Update(uint diff) { }
public virtual bool HandleCustomSpell(Player player, uint spellId, GameObject go)
{
@@ -507,26 +282,18 @@ namespace Game.PvP
public virtual void ChangeState() { }
public virtual void ChangeTeam(uint oldTeam) { }
}
public ulong m_capturePointSpawnId;
public GameObject m_capturePoint;
// active players in the area of the objective, 0 - alliance, 1 - horde
public HashSet<ObjectGuid>[] m_activePlayers = new HashSet<ObjectGuid>[2];
// total shift needed to capture the objective
public float m_maxValue;
float m_minValue;
// maximum speed of capture
float m_maxSpeed;
// the status of the objective
public float m_value;
uint m_team;
// objective states
public ObjectiveStates OldState { get; set; }
public ObjectiveStates State { get; set; }
// neutral value on capture bar
public uint m_neutralValuePct;
// pointer to the OutdoorPvP this objective belongs to
public OutdoorPvP PvP { get; set; }
public class OutdoorPvPControlZoneHandler : ControlZoneHandler
{
OutdoorPvP _pvp;
public OutdoorPvPControlZoneHandler(OutdoorPvP pvp)
{
_pvp = pvp;
}
public T GetOutdoorPvP<T>() where T : OutdoorPvP { return _pvp as T; }
}
class DefenseMessageBuilder : MessageBuilder
@@ -6,16 +6,55 @@ using Game.Entities;
using Game.Maps;
using Game.Networking.Packets;
using Game.Scripting;
using System.Collections.Generic;
namespace Game.PvP
namespace Game.PvP.HellfirePeninsula
{
class HellfirePeninsulaPvP : OutdoorPvP
{
// how many towers are controlled
uint m_AllianceTowersControlled;
uint m_HordeTowersControlled;
List<ObjectGuid> _controlZoneGUIDs = new();
public HellfirePeninsulaPvP(Map map) : base(map)
{
m_TypeId = OutdoorPvPTypes.HellfirePeninsula;
m_AllianceTowersControlled = 0;
m_HordeTowersControlled = 0;
ControlZoneHandlers[(uint)GameObjectIds.TowerS] = new HellfirePeninsulaControlZoneHandler(this);
GetControlZoneTowerSouthHandler().SetFlagArtKitAlliance(65);
GetControlZoneTowerSouthHandler().SetFlagArtKitHorde(64);
GetControlZoneTowerSouthHandler().SetFlagArtKitNeutral(66);
GetControlZoneTowerSouthHandler().SetTextCaptureAlliance(DefenseMessages.BrokenHillTakenAlliance);
GetControlZoneTowerSouthHandler().SetTextCaptureHorde(DefenseMessages.BrokenHillTakenHorde);
GetControlZoneTowerSouthHandler().SetWorldstateAlliance(WorldStateIds.UiTowerSA);
GetControlZoneTowerSouthHandler().SetWorldstateHorde(WorldStateIds.UiTowerSH);
GetControlZoneTowerSouthHandler().SetWorldstateNeutral(WorldStateIds.UiTowerSN);
GetControlZoneTowerSouthHandler().SetKillCredit((uint)KillCreditIds.TowerS);
ControlZoneHandlers[(uint)GameObjectIds.TowerN] = new HellfirePeninsulaControlZoneHandler(this);
GetControlZoneTowerNorthHandler().SetFlagArtKitAlliance(62);
GetControlZoneTowerNorthHandler().SetFlagArtKitHorde(61);
GetControlZoneTowerNorthHandler().SetFlagArtKitNeutral(63);
GetControlZoneTowerNorthHandler().SetTextCaptureAlliance(DefenseMessages.OverlookTakenAlliance);
GetControlZoneTowerNorthHandler().SetTextCaptureHorde(DefenseMessages.OverlookTakenHorde);
GetControlZoneTowerNorthHandler().SetWorldstateAlliance(WorldStateIds.UiTowerNA);
GetControlZoneTowerNorthHandler().SetWorldstateHorde(WorldStateIds.UiTowerNH);
GetControlZoneTowerNorthHandler().SetWorldstateNeutral(WorldStateIds.UiTowerNN);
GetControlZoneTowerNorthHandler().SetKillCredit((uint)KillCreditIds.TowerN);
ControlZoneHandlers[(uint)GameObjectIds.TowerW] = new HellfirePeninsulaControlZoneHandler(this);
GetControlZoneTowerWestHandler().SetFlagArtKitAlliance(67);
GetControlZoneTowerWestHandler().SetFlagArtKitHorde(68);
GetControlZoneTowerWestHandler().SetFlagArtKitNeutral(69);
GetControlZoneTowerWestHandler().SetTextCaptureAlliance(DefenseMessages.StadiumTakenAlliance);
GetControlZoneTowerWestHandler().SetTextCaptureHorde(DefenseMessages.StadiumTakenHorde);
GetControlZoneTowerWestHandler().SetWorldstateAlliance(WorldStateIds.UiTowerWA);
GetControlZoneTowerWestHandler().SetWorldstateHorde(WorldStateIds.UiTowerWH);
GetControlZoneTowerWestHandler().SetWorldstateNeutral(WorldStateIds.UiTowerWN);
GetControlZoneTowerWestHandler().SetKillCredit((uint)KillCreditIds.TowerW);
}
public override bool SetupOutdoorPvP()
@@ -24,8 +63,8 @@ namespace Game.PvP
m_HordeTowersControlled = 0;
// add the zones affected by the pvp buff
for (int i = 0; i < HPConst.BuffZones.Length; ++i)
RegisterZone(HPConst.BuffZones[i]);
for (int i = 0; i < Misc.BuffZones.Length; ++i)
RegisterZone(Misc.BuffZones[i]);
return true;
}
@@ -34,23 +73,14 @@ namespace Game.PvP
{
switch (go.GetEntry())
{
case 182175:
AddCapturePoint(new HellfirePeninsulaCapturePoint(this, OutdoorPvPHPTowerType.BrokenHill, go, m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.BrokenHill]));
break;
case 182174:
AddCapturePoint(new HellfirePeninsulaCapturePoint(this, OutdoorPvPHPTowerType.Overlook, go, m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.Overlook]));
break;
case 182173:
AddCapturePoint(new HellfirePeninsulaCapturePoint(this, OutdoorPvPHPTowerType.Stadium, go, m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.Stadium]));
break;
case 183514:
m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.BrokenHill] = go.GetSpawnId();
GetControlZoneTowerSouthHandler().SetFlagGuid(go.GetGUID());
break;
case 182525:
m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.Overlook] = go.GetSpawnId();
GetControlZoneTowerNorthHandler().SetFlagGuid(go.GetGUID());
break;
case 183515:
m_towerFlagSpawnIds[(int)OutdoorPvPHPTowerType.Stadium] = go.GetSpawnId();
GetControlZoneTowerWestHandler().SetFlagGuid(go.GetGUID());
break;
default:
break;
@@ -65,12 +95,12 @@ namespace Game.PvP
if (player.GetTeam() == Team.Alliance)
{
if (m_AllianceTowersControlled >= 3)
player.CastSpell(player, OutdoorPvPHPSpells.AllianceBuff, true);
player.CastSpell(player, SpellIds.AllianceBuff, true);
}
else
{
if (m_HordeTowersControlled >= 3)
player.CastSpell(player, OutdoorPvPHPSpells.HordeBuff, true);
player.CastSpell(player, SpellIds.HordeBuff, true);
}
base.HandlePlayerEnterZone(player, zone);
}
@@ -79,31 +109,29 @@ namespace Game.PvP
{
// remove buffs
if (player.GetTeam() == Team.Alliance)
player.RemoveAurasDueToSpell(OutdoorPvPHPSpells.AllianceBuff);
player.RemoveAurasDueToSpell(SpellIds.AllianceBuff);
else
player.RemoveAurasDueToSpell(OutdoorPvPHPSpells.HordeBuff);
player.RemoveAurasDueToSpell(SpellIds.HordeBuff);
base.HandlePlayerLeaveZone(player, zone);
}
public override bool Update(uint diff)
public override void Update(uint diff)
{
bool changed = base.Update(diff);
if (changed)
base.Update(diff);
if (m_AllianceTowersControlled == 3)
TeamApplyBuff(TeamId.Alliance, SpellIds.AllianceBuff, SpellIds.HordeBuff);
else if (m_HordeTowersControlled == 3)
TeamApplyBuff(TeamId.Horde, SpellIds.HordeBuff, SpellIds.AllianceBuff);
else
{
if (m_AllianceTowersControlled == 3)
TeamApplyBuff(TeamId.Alliance, OutdoorPvPHPSpells.AllianceBuff, OutdoorPvPHPSpells.HordeBuff);
else if (m_HordeTowersControlled == 3)
TeamApplyBuff(TeamId.Horde, OutdoorPvPHPSpells.HordeBuff, OutdoorPvPHPSpells.AllianceBuff);
else
{
TeamCastSpell(TeamId.Alliance, -(int)OutdoorPvPHPSpells.AllianceBuff);
TeamCastSpell(TeamId.Horde, -(int)OutdoorPvPHPSpells.HordeBuff);
}
SetWorldState(OutdoorPvPHPWorldStates.Count_A, (int)m_AllianceTowersControlled);
SetWorldState(OutdoorPvPHPWorldStates.Count_H, (int)m_HordeTowersControlled);
TeamCastSpell(TeamId.Alliance, -(int)SpellIds.AllianceBuff);
TeamCastSpell(TeamId.Horde, -(int)SpellIds.HordeBuff);
}
return changed;
SetWorldState(WorldStateIds.CountA, (int)m_AllianceTowersControlled);
SetWorldState(WorldStateIds.CountH, (int)m_HordeTowersControlled);
}
public override void SendRemoveWorldStates(Player player)
@@ -112,30 +140,53 @@ namespace Game.PvP
initWorldStates.MapID = player.GetMapId();
initWorldStates.AreaID = player.GetZoneId();
initWorldStates.SubareaID = player.GetAreaId();
initWorldStates.AddState(OutdoorPvPHPWorldStates.Display_A, 0);
initWorldStates.AddState(OutdoorPvPHPWorldStates.Display_H, 0);
initWorldStates.AddState(OutdoorPvPHPWorldStates.Count_H, 0);
initWorldStates.AddState(OutdoorPvPHPWorldStates.Count_A, 0);
initWorldStates.AddState(WorldStateIds.DisplayA, 0);
initWorldStates.AddState(WorldStateIds.DisplayH, 0);
initWorldStates.AddState(WorldStateIds.CountH, 0);
initWorldStates.AddState(WorldStateIds.CountA, 0);
for (int i = 0; i < (int)OutdoorPvPHPTowerType.Num; ++i)
foreach (var pair in ControlZoneHandlers)
{
initWorldStates.AddState(HPConst.Map_N[i], 0);
initWorldStates.AddState(HPConst.Map_A[i], 0);
initWorldStates.AddState(HPConst.Map_H[i], 0);
HellfirePeninsulaControlZoneHandler handler = pair.Value as HellfirePeninsulaControlZoneHandler;
initWorldStates.AddState(handler.GetWorldStateNeutral(), 0);
initWorldStates.AddState(handler.GetWorldStateHorde(), 0);
initWorldStates.AddState(handler.GetWorldStateAlliance(), 0);
}
player.SendPacket(initWorldStates);
}
public override void HandleKillImpl(Player killer, Unit killed)
public override void HandleKillImpl(Player player, Unit killed)
{
if (!killed.IsTypeId(TypeId.Player))
if (!killed.IsPlayer())
return;
if (killer.GetTeam() == Team.Alliance && killed.ToPlayer().GetTeam() != Team.Alliance)
killer.CastSpell(killer, OutdoorPvPHPSpells.AlliancePlayerKillReward, true);
else if (killer.GetTeam() == Team.Horde && killed.ToPlayer().GetTeam() != Team.Horde)
killer.CastSpell(killer, OutdoorPvPHPSpells.HordePlayerKillReward, true);
// need to check if player is inside an capture zone
bool isInsideCaptureZone = false;
foreach (ObjectGuid guid in _controlZoneGUIDs)
{
GameObject gameObject = GetMap().GetGameObject(guid);
if (gameObject != null)
{
var insidePlayerGuids = gameObject.GetInsidePlayers();
if (!insidePlayerGuids.Empty())
{
if (insidePlayerGuids.Contains(player.GetGUID()))
{
isInsideCaptureZone = true;
break;
}
}
}
}
if (isInsideCaptureZone)
{
if (player.GetTeam() == Team.Alliance && killed.ToPlayer().GetTeam() != Team.Alliance)
player.CastSpell(player, SpellIds.AlliancePlayerKillReward, true);
else if (player.GetTeam() == Team.Horde && killed.ToPlayer().GetTeam() != Team.Horde)
player.CastSpell(player, SpellIds.HordePlayerKillReward, true);
}
}
public uint GetAllianceTowersControlled()
@@ -158,131 +209,121 @@ namespace Game.PvP
m_HordeTowersControlled = count;
}
// how many towers are controlled
uint m_AllianceTowersControlled;
uint m_HordeTowersControlled;
ulong[] m_towerFlagSpawnIds = new ulong[(int)OutdoorPvPHPTowerType.Num];
HellfirePeninsulaControlZoneHandler GetControlZoneTowerNorthHandler() { return ControlZoneHandlers[(uint)GameObjectIds.TowerN] as HellfirePeninsulaControlZoneHandler; }
HellfirePeninsulaControlZoneHandler GetControlZoneTowerSouthHandler() { return ControlZoneHandlers[(uint)GameObjectIds.TowerS] as HellfirePeninsulaControlZoneHandler; }
HellfirePeninsulaControlZoneHandler GetControlZoneTowerWestHandler() { return ControlZoneHandlers[(uint)GameObjectIds.TowerW] as HellfirePeninsulaControlZoneHandler; }
}
class HellfirePeninsulaCapturePoint : OPvPCapturePoint
class HellfirePeninsulaControlZoneHandler : OutdoorPvPControlZoneHandler
{
public HellfirePeninsulaCapturePoint(OutdoorPvP pvp, OutdoorPvPHPTowerType type, GameObject go, ulong flagSpawnId) : base(pvp)
{
m_TowerType = (uint)type;
m_flagSpawnId = flagSpawnId;
ObjectGuid _flagGuid;
uint _textCaptureAlliance;
uint _textCaptureHorde;
uint _flagArtKitNeutral;
uint _flagArtKitHorde;
uint _flagArtKitAlliance;
int _worldstateNeutral;
int _worldstateHorde;
int _worldstateAlliance;
uint _killCredit;
m_capturePointSpawnId = go.GetSpawnId();
m_capturePoint = go;
SetCapturePointData(go.GetEntry());
public HellfirePeninsulaControlZoneHandler(HellfirePeninsulaPvP pvp) : base(pvp) { }
public override void HandleProgressEventHorde(GameObject controlZone)
{
base.HandleProgressEventHorde(controlZone);
controlZone.SetGoArtKit(1);
controlZone.SendCustomAnim(0);
GameObject flag = controlZone.GetMap().GetGameObject(_flagGuid);
if (flag != null)
flag.SetGoArtKit(_flagArtKitHorde);
controlZone.GetMap().SetWorldStateValue(_worldstateHorde, 1, false);
controlZone.GetMap().SetWorldStateValue(_worldstateAlliance, 0, false);
controlZone.GetMap().SetWorldStateValue(_worldstateNeutral, 0, false);
GetOutdoorPvPHP().SendDefenseMessage(Misc.BuffZones[0], _textCaptureHorde);
var guidSet = controlZone.GetInsidePlayers();
foreach (ObjectGuid guid in guidSet)
{
Player player = Global.ObjAccessor.GetPlayer(controlZone, guid);
if (player != null && player.GetTeam() == Team.Horde)
player.KilledMonsterCredit(_killCredit);
}
}
public override void ChangeState()
public override void HandleProgressEventAlliance(GameObject controlZone)
{
uint field = 0;
switch (OldState)
base.HandleProgressEventAlliance(controlZone);
controlZone.SetGoArtKit(2);
controlZone.SendCustomAnim(1);
GameObject flag = controlZone.GetMap().GetGameObject(_flagGuid);
if (flag != null)
flag.SetGoArtKit(_flagArtKitAlliance);
controlZone.GetMap().SetWorldStateValue(_worldstateHorde, 0, false);
controlZone.GetMap().SetWorldStateValue(_worldstateAlliance, 1, false);
controlZone.GetMap().SetWorldStateValue(_worldstateNeutral, 0, false);
GetOutdoorPvPHP().SendDefenseMessage(Misc.BuffZones[0], _textCaptureAlliance);
var guidSet = controlZone.GetInsidePlayers();
foreach (ObjectGuid guid in guidSet)
{
case ObjectiveStates.Neutral:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.Alliance:
field = HPConst.Map_A[m_TowerType];
uint alliance_towers = ((HellfirePeninsulaPvP)PvP).GetAllianceTowersControlled();
if (alliance_towers != 0)
((HellfirePeninsulaPvP)PvP).SetAllianceTowersControlled(--alliance_towers);
break;
case ObjectiveStates.Horde:
field = HPConst.Map_H[m_TowerType];
uint horde_towers = ((HellfirePeninsulaPvP)PvP).GetHordeTowersControlled();
if (horde_towers != 0)
((HellfirePeninsulaPvP)PvP).SetHordeTowersControlled(--horde_towers);
break;
case ObjectiveStates.NeutralAllianceChallenge:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.NeutralHordeChallenge:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.AllianceHordeChallenge:
field = HPConst.Map_A[m_TowerType];
break;
case ObjectiveStates.HordeAllianceChallenge:
field = HPConst.Map_H[m_TowerType];
break;
Player player = Global.ObjAccessor.GetPlayer(controlZone, guid);
if (player != null && player.GetTeam() == Team.Alliance)
player.KilledMonsterCredit(_killCredit);
}
// send world state update
if (field != 0)
{
PvP.SetWorldState((int)field, 0);
field = 0;
}
uint artkit = 21;
uint artkit2 = HPConst.TowerArtKit_N[m_TowerType];
switch (State)
{
case ObjectiveStates.Neutral:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.Alliance:
{
field = HPConst.Map_A[m_TowerType];
artkit = 2;
artkit2 = HPConst.TowerArtKit_A[m_TowerType];
uint alliance_towers = ((HellfirePeninsulaPvP)PvP).GetAllianceTowersControlled();
if (alliance_towers < 3)
((HellfirePeninsulaPvP)PvP).SetAllianceTowersControlled(++alliance_towers);
PvP.SendDefenseMessage(HPConst.BuffZones[0], HPConst.LangCapture_A[m_TowerType]);
break;
}
case ObjectiveStates.Horde:
{
field = HPConst.Map_H[m_TowerType];
artkit = 1;
artkit2 = HPConst.TowerArtKit_H[m_TowerType];
uint horde_towers = ((HellfirePeninsulaPvP)PvP).GetHordeTowersControlled();
if (horde_towers < 3)
((HellfirePeninsulaPvP)PvP).SetHordeTowersControlled(++horde_towers);
PvP.SendDefenseMessage(HPConst.BuffZones[0], HPConst.LangCapture_H[m_TowerType]);
break;
}
case ObjectiveStates.NeutralAllianceChallenge:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.NeutralHordeChallenge:
field = HPConst.Map_N[m_TowerType];
break;
case ObjectiveStates.AllianceHordeChallenge:
field = HPConst.Map_A[m_TowerType];
artkit = 2;
artkit2 = HPConst.TowerArtKit_A[m_TowerType];
break;
case ObjectiveStates.HordeAllianceChallenge:
field = HPConst.Map_H[m_TowerType];
artkit = 1;
artkit2 = HPConst.TowerArtKit_H[m_TowerType];
break;
}
Map map = Global.MapMgr.FindMap(530, 0);
var bounds = map.GetGameObjectBySpawnIdStore().LookupByKey(m_capturePointSpawnId);
foreach (var go in bounds)
go.SetGoArtKit(artkit);
bounds = map.GetGameObjectBySpawnIdStore().LookupByKey(m_flagSpawnId);
foreach (var go in bounds)
go.SetGoArtKit(artkit2);
// send world state update
if (field != 0)
PvP.SetWorldState((int)field, 1);
// complete quest objective
if (State == ObjectiveStates.Alliance || State == ObjectiveStates.Horde)
SendObjectiveComplete(HPConst.CreditMarker[m_TowerType], ObjectGuid.Empty);
}
uint m_TowerType;
ulong m_flagSpawnId;
public override void HandleNeutralEventHorde(GameObject controlZone)
{
base.HandleNeutralEventHorde(controlZone);
GetOutdoorPvPHP().SetHordeTowersControlled(GetOutdoorPvPHP().GetHordeTowersControlled() - 1);
}
public override void HandleNeutralEventAlliance(GameObject controlZone)
{
base.HandleNeutralEventAlliance(controlZone);
GetOutdoorPvPHP().SetAllianceTowersControlled(GetOutdoorPvPHP().GetAllianceTowersControlled() - 1);
}
public override void HandleNeutralEvent(GameObject controlZone)
{
base.HandleNeutralEvent(controlZone);
controlZone.SetGoArtKit(21);
controlZone.SendCustomAnim(2);
GameObject flag = controlZone.GetMap().GetGameObject(_flagGuid);
if (flag != null)
flag.SetGoArtKit(_flagArtKitNeutral);
controlZone.GetMap().SetWorldStateValue(_worldstateHorde, 0, false);
controlZone.GetMap().SetWorldStateValue(_worldstateAlliance, 0, false);
controlZone.GetMap().SetWorldStateValue(_worldstateNeutral, 1, false);
}
public HellfirePeninsulaPvP GetOutdoorPvPHP()
{
return GetOutdoorPvP<HellfirePeninsulaPvP>();
}
public void SetFlagGuid(ObjectGuid guid) { _flagGuid = guid; }
public void SetTextCaptureHorde(uint text) { _textCaptureHorde = text; }
public void SetTextCaptureAlliance(uint text) { _textCaptureAlliance = text; }
public void SetFlagArtKitNeutral(uint artKit) { _flagArtKitNeutral = artKit; }
public void SetFlagArtKitHorde(uint artKit) { _flagArtKitHorde = artKit; }
public void SetFlagArtKitAlliance(uint artKit) { _flagArtKitAlliance = artKit; }
public void SetWorldstateNeutral(int id) { _worldstateNeutral = id; }
public void SetWorldstateHorde(int id) { _worldstateHorde = id; }
public void SetWorldstateAlliance(int id) { _worldstateAlliance = id; }
public void SetKillCredit(uint credit) { _killCredit = credit; }
public int GetWorldStateNeutral() { return _worldstateNeutral; }
public int GetWorldStateHorde() { return _worldstateHorde; }
public int GetWorldStateAlliance() { return _worldstateAlliance; }
}
[Script]
@@ -296,32 +337,10 @@ namespace Game.PvP
}
}
struct HPConst
struct Misc
{
public static uint[] LangCapture_A = { DefenseMessages.BrokenHillTakenAlliance, DefenseMessages.OverlookTakenAlliance, DefenseMessages.StadiumTakenAlliance };
public static uint[] LangCapture_H = { DefenseMessages.BrokenHillTakenHorde, DefenseMessages.OverlookTakenHorde, DefenseMessages.StadiumTakenHorde };
public static uint[] Map_N = { 2485, 2482, 0x9a8 };
public static uint[] Map_A = { 2483, 2480, 2471 };
public static uint[] Map_H = { 2484, 2481, 2470 };
public static uint[] TowerArtKit_A = { 65, 62, 67 };
public static uint[] TowerArtKit_H = { 64, 61, 68 };
public static uint[] TowerArtKit_N = { 66, 63, 69 };
// HP, citadel, ramparts, blood furnace, shattered halls, mag's lair
public static uint[] BuffZones = { 3483, 3563, 3562, 3713, 3714, 3836 };
public static uint[] CreditMarker = { 19032, 19028, 19029 };
public static uint[] CapturePointEventEnter = { 11404, 11396, 11388 };
public static uint[] CapturePointEventLeave = { 11403, 11395, 11387 };
}
struct DefenseMessages
@@ -334,7 +353,7 @@ namespace Game.PvP
public const uint BrokenHillTakenHorde = 14846; // '|cffffff00Broken Hill has been taken by the Horde!|r'
}
struct OutdoorPvPHPSpells
struct SpellIds
{
public const uint AlliancePlayerKillReward = 32155;
public const uint HordePlayerKillReward = 32158;
@@ -342,7 +361,7 @@ namespace Game.PvP
public const uint HordeBuff = 32049;
}
enum OutdoorPvPHPTowerType
enum TowerType
{
BrokenHill = 0,
Overlook = 1,
@@ -350,12 +369,56 @@ namespace Game.PvP
Num = 3
}
struct OutdoorPvPHPWorldStates
struct WorldStateIds
{
public const int Display_A = 0x9ba;
public const int Display_H = 0x9b9;
public const int DisplayA = 0x9ba;
public const int DisplayH = 0x9b9;
public const int Count_H = 0x9ae;
public const int Count_A = 0x9ac;
public const int CountH = 0x9ae;
public const int CountA = 0x9ac;
public const int UiTowerSA = 2483;
public const int UiTowerSH = 2484;
public const int UiTowerSN = 2485;
public const int UiTowerNA = 2480;
public const int UiTowerNH = 2481;
public const int UiTowerNN = 2482;
public const int UiTowerWA = 2471;
public const int UiTowerWH = 2470;
public const int UiTowerWN = 2472;
}
enum EventIds
{
HP_EVENT_TOWER_W_PROGRESS_HORDE = 11383,
HP_EVENT_TOWER_W_PROGRESS_ALLIANCE = 11387,
HP_EVENT_TOWER_W_NEUTRAL_HORDE = 11386,
HP_EVENT_TOWER_W_NEUTRAL_ALLIANCE = 11385,
HP_EVENT_TOWER_N_PROGRESS_HORDE = 11396,
HP_EVENT_TOWER_N_PROGRESS_ALLIANCE = 11395,
HP_EVENT_TOWER_N_NEUTRAL_HORDE = 11394,
HP_EVENT_TOWER_N_NEUTRAL_ALLIANCE = 11393,
HP_EVENT_TOWER_S_PROGRESS_HORDE = 11404,
HP_EVENT_TOWER_S_PROGRESS_ALLIANCE = 11403,
HP_EVENT_TOWER_S_NEUTRAL_HORDE = 11402,
HP_EVENT_TOWER_S_NEUTRAL_ALLIANCE = 11401
}
enum GameObjectIds
{
TowerW = 182173,
TowerN = 182174,
TowerS = 182175
}
enum KillCreditIds
{
TowerS = 19032,
TowerN = 19028,
TowerW = 19029
}
}