Battlegrounds/Buffs: Rework using areatriggers
Port From (https://github.com/TrinityCore/TrinityCore/commit/f5461a1161a5a9dfabe7a142ad84f8c900776c92)
This commit is contained in:
@@ -1546,52 +1546,6 @@ namespace Game.BattleGrounds
|
||||
SetRemainingTime(0);
|
||||
}
|
||||
|
||||
// IMPORTANT NOTICE:
|
||||
// buffs aren't spawned/despawned when players captures anything
|
||||
// buffs are in their positions when Battleground starts
|
||||
public void HandleTriggerBuff(ObjectGuid goGuid)
|
||||
{
|
||||
if (!FindBgMap())
|
||||
{
|
||||
Log.outError(LogFilter.Battleground, $"Battleground::HandleTriggerBuff called with null bg map, {goGuid}");
|
||||
return;
|
||||
}
|
||||
|
||||
GameObject obj = GetBgMap().GetGameObject(goGuid);
|
||||
if (!obj || obj.GetGoType() != GameObjectTypes.Trap || !obj.IsSpawned())
|
||||
return;
|
||||
|
||||
// Change buff type, when buff is used:
|
||||
int index = BgObjects.Length - 1;
|
||||
while (index >= 0 && BgObjects[index] != goGuid)
|
||||
index--;
|
||||
if (index < 0)
|
||||
{
|
||||
Log.outError(LogFilter.Battleground, $"Battleground.HandleTriggerBuff: cannot find buff gameobject ({goGuid}, entry: {obj.GetEntry()}, type: {obj.GetGoType()}) in internal data for BG (map: {GetMapId()}, instance id: {m_InstanceID})!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Randomly select new buff
|
||||
int buff = RandomHelper.IRand(0, 2);
|
||||
uint entry = obj.GetEntry();
|
||||
if (m_BuffChange && entry != Buff_Entries[buff])
|
||||
{
|
||||
// Despawn current buff
|
||||
SpawnBGObject(index, BattlegroundConst.RespawnOneDay);
|
||||
// Set index for new one
|
||||
for (byte currBuffTypeIndex = 0; currBuffTypeIndex < 3; ++currBuffTypeIndex)
|
||||
{
|
||||
if (entry == Buff_Entries[currBuffTypeIndex])
|
||||
{
|
||||
index -= currBuffTypeIndex;
|
||||
index += buff;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SpawnBGObject(index, BattlegroundConst.BuffRespawnTime);
|
||||
}
|
||||
|
||||
public virtual void HandleKillPlayer(Player victim, Player killer)
|
||||
{
|
||||
// Keep in mind that for arena this will have to be changed a bit
|
||||
@@ -1974,7 +1928,6 @@ namespace Game.BattleGrounds
|
||||
// this must be filled inructors!
|
||||
public uint[] StartMessageIds = new uint[4];
|
||||
|
||||
public bool m_BuffChange;
|
||||
bool m_IsRandom;
|
||||
|
||||
public BGHonorMode m_HonorMode;
|
||||
|
||||
@@ -601,17 +601,9 @@ namespace Game.Entities
|
||||
|
||||
// Type 0 despawns after being triggered, type 1 does not.
|
||||
// @todo This is activation radius. Casting radius must be selected from spell
|
||||
float radius;
|
||||
if (goInfo.Trap.radius == 0f)
|
||||
{
|
||||
// Battlegroundgameobjects have data2 == 0 && data5 == 3
|
||||
if (goInfo.Trap.cooldown != 3)
|
||||
break;
|
||||
|
||||
radius = 3.0f;
|
||||
}
|
||||
else
|
||||
radius = goInfo.Trap.radius / 2.0f;
|
||||
float radius = goInfo.Trap.radius / 2.0f; // this division seems to date back to when the field was called diameter, don't think it is still relevant.
|
||||
if (radius == 0f)
|
||||
break;
|
||||
|
||||
Unit target;
|
||||
// @todo this hack with search required until GO casting not implemented
|
||||
@@ -753,18 +745,6 @@ namespace Game.Entities
|
||||
SetLootState(LootState.JustDeactivated);
|
||||
else if (goInfo.Trap.charges == 0)
|
||||
SetLootState(LootState.Ready);
|
||||
|
||||
// Battleground gameobjects have data2 == 0 && data5 == 3
|
||||
if (goInfo.Trap.radius == 0 && goInfo.Trap.cooldown == 3)
|
||||
{
|
||||
Player player = target.ToPlayer();
|
||||
if (player)
|
||||
{
|
||||
Battleground bg = player.GetBattleground();
|
||||
if (bg)
|
||||
bg.HandleTriggerBuff(GetGUID());
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1683,7 +1683,7 @@ namespace Game.Entities
|
||||
return searcher.GetTarget();
|
||||
}
|
||||
|
||||
GameObject FindNearestGameObjectWithOptions(float range, FindGameObjectOptions options)
|
||||
public GameObject FindNearestGameObjectWithOptions(float range, FindGameObjectOptions options)
|
||||
{
|
||||
NearestCheckCustomizer checkCustomizer = new(this, range);
|
||||
GameObjectWithOptionsInObjectRangeCheck<NearestCheckCustomizer> checker = new(this, checkCustomizer, options);
|
||||
@@ -4062,13 +4062,13 @@ namespace Game.Entities
|
||||
public ObjectGuid? PrivateObjectOwnerGuid;
|
||||
}
|
||||
|
||||
class FindGameObjectOptions
|
||||
public class FindGameObjectOptions
|
||||
{
|
||||
public uint? GameObjectId;
|
||||
public string StringId;
|
||||
|
||||
public bool? IsSummon;
|
||||
public bool? IsSpawned;
|
||||
public bool? IsSpawned = true; // most searches should be for spawned objects only, to search for "any" just clear this field at call site
|
||||
|
||||
public bool IgnorePhases;
|
||||
public bool IgnoreNotOwnedPrivateObjects = true;
|
||||
|
||||
@@ -109,7 +109,7 @@ namespace Scripts.World.Areatriggers
|
||||
}
|
||||
|
||||
struct Misc
|
||||
{
|
||||
{
|
||||
//Brewfest
|
||||
public const uint AreatriggerTalkCooldown = 5; // In Seconds
|
||||
|
||||
@@ -396,4 +396,41 @@ namespace Scripts.World.Areatriggers
|
||||
player.KilledMonsterCredit(CreatureIds.KillCreditTeleportStormwind);
|
||||
}
|
||||
}
|
||||
|
||||
[Script]
|
||||
class areatrigger_battleground_buffs : AreaTriggerAI
|
||||
{
|
||||
public areatrigger_battleground_buffs(AreaTrigger areatrigger) : base(areatrigger) { }
|
||||
|
||||
public override void OnUnitEnter(Unit unit)
|
||||
{
|
||||
if (!unit.IsPlayer())
|
||||
return;
|
||||
|
||||
var player = unit.ToPlayer();
|
||||
GameObject buffObject = player.FindNearestGameObjectWithOptions(4.0f, new FindGameObjectOptions() { StringId = "bg_buff_object" });
|
||||
if (buffObject != null)
|
||||
{
|
||||
buffObject.ActivateObject(GameObjectActions.Disturb, 0, player);
|
||||
buffObject.DespawnOrUnsummon();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Script]
|
||||
class AreaTrigger_at_battleground_buffs : AreaTriggerScript
|
||||
{
|
||||
public AreaTrigger_at_battleground_buffs() : base("at_battleground_buffs") { }
|
||||
|
||||
public override bool OnTrigger(Player player, AreaTriggerRecord areaTrigger)
|
||||
{
|
||||
GameObject buffObject = player.FindNearestGameObjectWithOptions(4.0f, new FindGameObjectOptions() { StringId = "bg_buff_object" });
|
||||
if (buffObject != null)
|
||||
{
|
||||
buffObject.ActivateObject(GameObjectActions.Disturb, 0, player);
|
||||
buffObject.DespawnOrUnsummon();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user