Core/Objects: Implemented vignettes
Port From (https://github.com/TrinityCore/TrinityCore/commit/fccf6fb72b60b08dfbe6d5fb17fba55239944fca)
This commit is contained in:
@@ -1724,6 +1724,13 @@ namespace Game.Entities
|
||||
if (CreateVehicleKit(vehId, entry, true))
|
||||
UpdateDisplayPower();
|
||||
|
||||
if (!IsPet())
|
||||
{
|
||||
uint vignetteId = GetCreatureTemplate().VignetteID;
|
||||
if (vignetteId != 0)
|
||||
SetVignette(vignetteId);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2052,6 +2059,10 @@ namespace Game.Entities
|
||||
RemoveUnitFlag(UnitFlags.InCombat);
|
||||
|
||||
SetMeleeDamageSchool((SpellSchools)cInfo.DmgSchool);
|
||||
|
||||
uint vignetteId = cInfo.VignetteID;
|
||||
if (vignetteId != 0)
|
||||
SetVignette(vignetteId);
|
||||
}
|
||||
|
||||
InitializeMovementAI();
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Game.Entities
|
||||
public List<uint> GossipMenuIds = new();
|
||||
public Dictionary<Difficulty, CreatureDifficulty> difficultyStorage = new();
|
||||
public uint RequiredExpansion;
|
||||
public uint VignetteID; // @todo Read Vignette.db2
|
||||
public uint VignetteID;
|
||||
public uint Faction;
|
||||
public ulong Npcflag;
|
||||
public float SpeedWalk;
|
||||
|
||||
@@ -72,6 +72,8 @@ namespace Game.Entities
|
||||
|
||||
public override void CleanupsBeforeDelete(bool finalCleanup)
|
||||
{
|
||||
SetVignette(0);
|
||||
|
||||
base.CleanupsBeforeDelete(finalCleanup);
|
||||
|
||||
RemoveFromOwner();
|
||||
@@ -371,6 +373,10 @@ namespace Game.Entities
|
||||
_animKitId = (ushort)gameObjectAddon.AIAnimKitID;
|
||||
}
|
||||
|
||||
uint vignetteId = GetGoInfo().GetSpawnVignette();
|
||||
if (vignetteId != 0)
|
||||
SetVignette(vignetteId);
|
||||
|
||||
LastUsedScriptID = GetGoInfo().ScriptId;
|
||||
|
||||
m_stringIds[0] = goInfo.StringId;
|
||||
@@ -2591,6 +2597,25 @@ namespace Game.Entities
|
||||
break;
|
||||
}
|
||||
|
||||
if (m_vignette != null)
|
||||
{
|
||||
Player player = user.ToPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
Quest reward = Global.ObjectMgr.GetQuestTemplate((uint)m_vignette.Data.RewardQuestID);
|
||||
if (reward != null && !player.GetQuestRewardStatus((uint)m_vignette.Data.RewardQuestID))
|
||||
player.RewardQuest(reward, LootItemType.Item, 0, this, false);
|
||||
|
||||
if (m_vignette.Data.VisibleTrackingQuestID != 0)
|
||||
player.SetRewardedQuest(m_vignette.Data.VisibleTrackingQuestID);
|
||||
}
|
||||
|
||||
// only unregister it from visibility (need to keep vignette for other gameobject users in case its usable by multiple players
|
||||
// to flag their quest completion
|
||||
if (GetGoInfo().ClearObjectVignetteonOpening())
|
||||
Vignettes.Remove(m_vignette, this);
|
||||
}
|
||||
|
||||
if (spellId == 0)
|
||||
return;
|
||||
|
||||
@@ -3348,6 +3373,10 @@ namespace Game.Entities
|
||||
if (m_goTypeImpl != null)
|
||||
m_goTypeImpl.OnRelocated();
|
||||
|
||||
// TODO: on heartbeat
|
||||
if (m_vignette != null)
|
||||
Vignettes.Update(m_vignette, this);
|
||||
|
||||
UpdateObjectVisibility(false);
|
||||
}
|
||||
|
||||
@@ -3423,6 +3452,24 @@ namespace Game.Entities
|
||||
SendMessageToSet(activateAnimKit, true);
|
||||
}
|
||||
|
||||
public override VignetteData GetVignette() { return m_vignette; }
|
||||
|
||||
public void SetVignette(uint vignetteId)
|
||||
{
|
||||
if (m_vignette != null)
|
||||
{
|
||||
if (m_vignette.Data.ID == vignetteId)
|
||||
return;
|
||||
|
||||
Vignettes.Remove(m_vignette, this);
|
||||
m_vignette = null;
|
||||
}
|
||||
|
||||
VignetteRecord vignette = CliDB.VignetteStorage.LookupByKey(vignetteId);
|
||||
if (vignette != null)
|
||||
m_vignette = Vignettes.Create(vignette, this);
|
||||
}
|
||||
|
||||
public void SetSpellVisualId(uint spellVisualId, ObjectGuid activatorGuid = default)
|
||||
{
|
||||
SetUpdateFieldValue(m_values.ModifyValue(m_gameObjectData).ModifyValue(m_gameObjectData.SpellVisualID), spellVisualId);
|
||||
@@ -3900,6 +3947,8 @@ namespace Game.Entities
|
||||
ushort _animKitId;
|
||||
uint _worldEffectID;
|
||||
|
||||
VignetteData m_vignette;
|
||||
|
||||
Dictionary<ObjectGuid, PerPlayerState> m_perPlayerState;
|
||||
|
||||
GameObjectState m_prevGoState; // What state to set whenever resetting
|
||||
|
||||
@@ -744,7 +744,25 @@ namespace Game.Entities
|
||||
GameObjectTypes.AuraGenerator => AuraGenerator.serverOnly,
|
||||
_ => 0,
|
||||
};
|
||||
|
||||
|
||||
public uint GetSpawnVignette() => type switch
|
||||
{
|
||||
|
||||
GameObjectTypes.Chest => Chest.SpawnVignette,
|
||||
GameObjectTypes.Goober => Goober.SpawnVignette,
|
||||
GameObjectTypes.NewFlag => NewFlag.SpawnVignette,
|
||||
GameObjectTypes.NewFlagDrop => NewFlagDrop.SpawnVignette,
|
||||
GameObjectTypes.CapturePoint => CapturePoint.SpawnVignette,
|
||||
GameObjectTypes.GatheringNode => GatheringNode.SpawnVignette,
|
||||
_ => 0
|
||||
};
|
||||
|
||||
public bool ClearObjectVignetteonOpening() => type switch
|
||||
{
|
||||
GameObjectTypes.GatheringNode => GatheringNode.ClearObjectVignetteonOpening != 0,
|
||||
_ => false
|
||||
};
|
||||
|
||||
public uint GetSpellFocusType()
|
||||
{
|
||||
switch (type)
|
||||
@@ -776,7 +794,7 @@ namespace Game.Entities
|
||||
GameObjectTypes.SpellFocus or GameObjectTypes.Multi or GameObjectTypes.SiegeableMulti => false,
|
||||
_ => true
|
||||
};
|
||||
|
||||
|
||||
public void InitializeQueryData()
|
||||
{
|
||||
QueryData = new QueryGameObjectResponse();
|
||||
|
||||
@@ -1553,6 +1553,8 @@ namespace Game.Entities
|
||||
return null;
|
||||
}
|
||||
|
||||
public virtual VignetteData GetVignette() { return null; }
|
||||
|
||||
public TempSummon SummonCreature(uint entry, float x, float y, float z, float o = 0, TempSummonType despawnType = TempSummonType.ManualDespawn, TimeSpan despawnTime = default, ObjectGuid privateObjectOwner = default)
|
||||
{
|
||||
if (x == 0.0f && y == 0.0f && z == 0.0f)
|
||||
|
||||
@@ -230,6 +230,22 @@ namespace Game.Entities
|
||||
|
||||
UpdateCriteria(CriteriaType.EnterTopLevelArea, newZone);
|
||||
UpdateCriteria(CriteriaType.LeaveTopLevelArea, oldZone);
|
||||
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
|
||||
foreach (var vignette in GetMap().GetInfiniteAOIVignettes())
|
||||
{
|
||||
if (!vignette.Data.GetFlags().HasFlag(VignetteFlags.ZoneInfiniteAOI))
|
||||
continue;
|
||||
|
||||
if (vignette.ZoneID == newZone && Vignettes.CanSee(this, vignette))
|
||||
vignette.FillPacket(vignetteUpdate.Added);
|
||||
else if (vignette.ZoneID == oldZone)
|
||||
vignetteUpdate.Removed.Add(vignette.Guid);
|
||||
}
|
||||
|
||||
if (!vignetteUpdate.Added.IDs.Empty() || !vignetteUpdate.Removed.Empty())
|
||||
SendPacket(vignetteUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5644,6 +5644,17 @@ namespace Game.Entities
|
||||
{
|
||||
UpdateVisibilityForPlayer();
|
||||
|
||||
// Send map wide vignettes before UpdateZone, that will send zone wide vignettes
|
||||
// But first send on new map will wipe all vignettes on client
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignetteUpdate.ForceUpdate = true;
|
||||
|
||||
foreach (VignetteData vignette in GetMap().GetInfiniteAOIVignettes())
|
||||
if (!vignette.Data.GetFlags().HasFlag(VignetteFlags.ZoneInfiniteAOI) && Vignettes.CanSee(this, vignette))
|
||||
vignette.FillPacket(vignetteUpdate.Added);
|
||||
|
||||
SendPacket(vignetteUpdate);
|
||||
|
||||
// update zone
|
||||
uint newzone, newarea;
|
||||
GetZoneAndAreaId(out newzone, out newarea);
|
||||
@@ -6034,13 +6045,23 @@ namespace Game.Entities
|
||||
}
|
||||
|
||||
#region Sends / Updates
|
||||
void BeforeVisibilityDestroy(WorldObject obj, Player p)
|
||||
void BeforeVisibilityDestroy(WorldObject t, Player p)
|
||||
{
|
||||
if (!obj.IsTypeId(TypeId.Unit))
|
||||
return;
|
||||
var creature = t.ToCreature();
|
||||
if (creature != null)
|
||||
if (p.GetPetGUID() == creature.GetGUID() && creature.IsPet())
|
||||
creature.ToPet().Remove(PetSaveMode.NotInSlot, true);
|
||||
|
||||
if (p.GetPetGUID() == obj.GetGUID() && obj.ToCreature().IsPet())
|
||||
((Pet)obj).Remove(PetSaveMode.NotInSlot, true);
|
||||
VignetteData vignette = t.GetVignette();
|
||||
if (vignette != null)
|
||||
{
|
||||
if (!vignette.Data.IsInfiniteAOI())
|
||||
{
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignetteUpdate.Removed.Add(vignette.Guid);
|
||||
p.SendPacket(vignetteUpdate);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateVisibilityOf(ICollection<WorldObject> targets)
|
||||
@@ -6103,8 +6124,7 @@ namespace Game.Entities
|
||||
{
|
||||
if (!CanSeeOrDetect(target, false, true))
|
||||
{
|
||||
if (target.IsTypeId(TypeId.Unit))
|
||||
BeforeVisibilityDestroy(target.ToCreature(), this);
|
||||
BeforeVisibilityDestroy(target, this);
|
||||
|
||||
if (!target.IsDestroyedObject())
|
||||
target.SendOutOfRangeForPlayer(this);
|
||||
@@ -6158,6 +6178,16 @@ namespace Game.Entities
|
||||
|
||||
public void SendInitialVisiblePackets(WorldObject target)
|
||||
{
|
||||
var sendVignette = (VignetteData vignette, Player where) =>
|
||||
{
|
||||
if (!vignette.Data.IsInfiniteAOI() && Vignettes.CanSee(where, vignette))
|
||||
{
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignette.FillPacket(vignetteUpdate.Added);
|
||||
where.SendPacket(vignetteUpdate);
|
||||
}
|
||||
};
|
||||
|
||||
Unit targetUnit = target.ToUnit();
|
||||
if (targetUnit != null)
|
||||
{
|
||||
@@ -6167,6 +6197,20 @@ namespace Game.Entities
|
||||
if (targetUnit.HasUnitState(UnitState.MeleeAttacking) && targetUnit.GetVictim() != null)
|
||||
targetUnit.SendMeleeAttackStart(targetUnit.GetVictim());
|
||||
}
|
||||
|
||||
VignetteData vignette = targetUnit.GetVignette();
|
||||
if (vignette != null)
|
||||
sendVignette(vignette, this);
|
||||
}
|
||||
else
|
||||
{
|
||||
GameObject targetGo = target.ToGameObject();
|
||||
if (targetGo != null)
|
||||
{
|
||||
VignetteData vignette = targetGo.GetVignette();
|
||||
if (vignette != null)
|
||||
sendVignette(vignette, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -928,6 +928,20 @@ namespace Game.Entities
|
||||
}
|
||||
}
|
||||
|
||||
VignetteData vignette = victim.GetVignette();
|
||||
if (vignette != null)
|
||||
{
|
||||
foreach (Player tapper in tappers)
|
||||
{
|
||||
Quest reward = Global.ObjectMgr.GetQuestTemplate((uint)vignette.Data.RewardQuestID);
|
||||
if (reward != null)
|
||||
tapper.RewardQuest(reward, LootItemType.Item, 0, victim, false);
|
||||
|
||||
if (vignette.Data.VisibleTrackingQuestID != 0)
|
||||
tapper.SetRewardedQuest(vignette.Data.VisibleTrackingQuestID);
|
||||
}
|
||||
}
|
||||
|
||||
new KillRewarder(tappers.ToArray(), victim, false).Reward();
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,7 @@ namespace Game.Entities
|
||||
public UnitTypeMask UnitTypeMask { get; set; }
|
||||
UnitState m_state;
|
||||
protected LiquidTypeRecord _lastLiquid;
|
||||
VignetteData m_vignette;
|
||||
protected DeathState m_deathState;
|
||||
public Vehicle m_vehicle { get; set; }
|
||||
public Vehicle VehicleKit { get; set; }
|
||||
|
||||
@@ -684,6 +684,10 @@ namespace Game.Entities
|
||||
if (isInWater)
|
||||
RemoveAurasWithInterruptFlags(SpellAuraInterruptFlags2.Swimming);
|
||||
|
||||
// TODO: on heartbeat
|
||||
if (m_vignette != null)
|
||||
Vignettes.Update(m_vignette, this);
|
||||
|
||||
return (relocated || turn);
|
||||
}
|
||||
|
||||
|
||||
@@ -538,6 +538,8 @@ namespace Game.Entities
|
||||
// This needs to be before RemoveFromWorld to make GetCaster() return a valid for aura removal
|
||||
InterruptNonMeleeSpells(true);
|
||||
|
||||
SetVignette(0);
|
||||
|
||||
if (IsInWorld)
|
||||
RemoveFromWorld();
|
||||
else
|
||||
@@ -939,6 +941,24 @@ namespace Game.Entities
|
||||
return collisionHeight1 == 0.0f ? MapConst.DefaultCollesionHeight : collisionHeight1;
|
||||
}
|
||||
|
||||
public override VignetteData GetVignette() { return m_vignette; }
|
||||
|
||||
public void SetVignette(uint vignetteId)
|
||||
{
|
||||
if (m_vignette != null)
|
||||
{
|
||||
if (m_vignette.Data.ID == vignetteId)
|
||||
return;
|
||||
|
||||
Vignettes.Remove(m_vignette, this);
|
||||
m_vignette = null;
|
||||
}
|
||||
|
||||
var vignette = CliDB.VignetteStorage.LookupByKey(vignetteId);
|
||||
if (vignette != null)
|
||||
m_vignette = Vignettes.Create(vignette, this);
|
||||
}
|
||||
|
||||
public override string GetDebugInfo()
|
||||
{
|
||||
string str = $"{base.GetDebugInfo()}\nIsAIEnabled: {IsAIEnabled()} DeathState: {GetDeathState()} UnitMovementFlags: {GetUnitMovementFlags()} UnitMovementFlags2: {GetUnitMovementFlags2()} Class: {GetClass()}\n" +
|
||||
@@ -1574,6 +1594,9 @@ namespace Game.Entities
|
||||
SetEmoteState(Emote.OneshotNone);
|
||||
SetStandState(UnitStandStateType.Stand);
|
||||
|
||||
if (m_vignette != null && !m_vignette.Data.GetFlags().HasFlag(VignetteFlags.PersistsThroughDeath))
|
||||
SetVignette(0);
|
||||
|
||||
// players in instance don't have ZoneScript, but they have InstanceScript
|
||||
ZoneScript zoneScript = GetZoneScript() != null ? GetZoneScript() : GetInstanceScript();
|
||||
if (zoneScript != null)
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
// Copyright (c) CypherCore <http://github.com/CypherCore> All rights reserved.
|
||||
// Licensed under the GNU GENERAL PUBLIC LICENSE. See LICENSE file in the project root for full license information.
|
||||
|
||||
using Framework.Constants;
|
||||
using Game.DataStorage;
|
||||
using Game.Maps;
|
||||
using Game.Networking.Packets;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Game.Entities
|
||||
{
|
||||
static class Vignettes
|
||||
{
|
||||
public static void UpdatePosition(VignetteData vignette, WorldObject owner)
|
||||
{
|
||||
vignette.Position = owner.GetPosition();
|
||||
WmoLocation wmoLocation = owner.GetCurrentWmo();
|
||||
if (wmoLocation != null)
|
||||
{
|
||||
vignette.WMOGroupID = (uint)wmoLocation.GroupId;
|
||||
vignette.WMODoodadPlacementID = wmoLocation.UniqueId;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SendVignetteUpdate(VignetteData vignette, WorldObject owner)
|
||||
{
|
||||
if (!owner.IsInWorld)
|
||||
return;
|
||||
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignette.FillPacket(vignetteUpdate.Updated);
|
||||
vignetteUpdate.Write();
|
||||
|
||||
var sender = (Player receiver) =>
|
||||
{
|
||||
if (CanSee(receiver, vignette))
|
||||
receiver.SendPacket(vignetteUpdate);
|
||||
};
|
||||
|
||||
MessageDistDeliverer notifier = new(owner, sender, owner.GetVisibilityRange());
|
||||
Cell.VisitWorldObjects(owner, notifier, owner.GetVisibilityRange());
|
||||
}
|
||||
|
||||
public static void SendVignetteAdded(VignetteData vignette, WorldObject owner)
|
||||
{
|
||||
if (!owner.IsInWorld)
|
||||
return;
|
||||
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignette.FillPacket(vignetteUpdate.Added);
|
||||
vignetteUpdate.Write();
|
||||
|
||||
var sender = (Player receiver) =>
|
||||
{
|
||||
if (CanSee(receiver, vignette))
|
||||
receiver.SendPacket(vignetteUpdate);
|
||||
};
|
||||
|
||||
MessageDistDeliverer notifier = new(owner, sender, owner.GetVisibilityRange());
|
||||
Cell.VisitWorldObjects(owner, notifier, owner.GetVisibilityRange());
|
||||
}
|
||||
|
||||
public static VignetteData Create(VignetteRecord vignetteData, WorldObject owner)
|
||||
{
|
||||
VignetteData vignette = new();
|
||||
vignette.Guid = ObjectGuid.Create(HighGuid.Vignette, owner.GetMapId(), vignetteData.ID, owner.GetMap().GenerateLowGuid(HighGuid.Vignette));
|
||||
vignette.Object = owner.GetGUID();
|
||||
vignette.Position = owner.GetPosition();
|
||||
vignette.Data = vignetteData;
|
||||
vignette.ZoneID = owner.GetZoneId(); // not updateable
|
||||
UpdatePosition(vignette, owner);
|
||||
|
||||
if (vignetteData.IsInfiniteAOI())
|
||||
owner.GetMap().AddInfiniteAOIVignette(vignette);
|
||||
else
|
||||
SendVignetteAdded(vignette, owner);
|
||||
|
||||
return vignette;
|
||||
}
|
||||
|
||||
public static void Update(VignetteData vignette, WorldObject owner)
|
||||
{
|
||||
UpdatePosition(vignette, owner);
|
||||
|
||||
if (vignette.Data.IsInfiniteAOI())
|
||||
vignette.NeedUpdate = true;
|
||||
else
|
||||
SendVignetteUpdate(vignette, owner);
|
||||
}
|
||||
|
||||
public static void Remove(VignetteData vignette, WorldObject owner)
|
||||
{
|
||||
if (vignette.Data.IsInfiniteAOI())
|
||||
owner.GetMap().RemoveInfiniteAOIVignette(vignette);
|
||||
else
|
||||
{
|
||||
VignetteUpdate vignetteUpdate = new();
|
||||
vignetteUpdate.Removed.Add(vignette.Guid);
|
||||
owner.SendMessageToSet(vignetteUpdate, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool CanSee(Player player, VignetteData vignette)
|
||||
{
|
||||
if (vignette.Data.GetFlags().HasFlag(VignetteFlags.ZoneInfiniteAOI))
|
||||
if (vignette.ZoneID != player.GetZoneId())
|
||||
return false;
|
||||
|
||||
if (vignette.Data.VisibleTrackingQuestID != 0)
|
||||
if (player.IsQuestRewarded(vignette.Data.VisibleTrackingQuestID))
|
||||
return false;
|
||||
|
||||
var playerCondition = CliDB.PlayerConditionStorage.LookupByKey(vignette.Data.PlayerConditionID);
|
||||
if (playerCondition != null && !ConditionManager.IsPlayerMeetingCondition(player, playerCondition))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public class VignetteData
|
||||
{
|
||||
public ObjectGuid Guid;
|
||||
public ObjectGuid Object;
|
||||
public Position Position;
|
||||
public VignetteRecord Data;
|
||||
public uint ZoneID;
|
||||
public uint WMOGroupID;
|
||||
public uint WMODoodadPlacementID;
|
||||
public bool NeedUpdate;
|
||||
|
||||
public void FillPacket(VignetteDataSet dataSet)
|
||||
{
|
||||
dataSet.IDs.Add(Guid);
|
||||
|
||||
VignetteDataPkt data = new();
|
||||
data.ObjGUID = Object;
|
||||
data.Position = Position;
|
||||
data.VignetteID = (int)Data.ID;
|
||||
data.ZoneID = ZoneID;
|
||||
data.WMOGroupID = WMOGroupID;
|
||||
data.WMODoodadPlacementID = WMODoodadPlacementID;
|
||||
|
||||
dataSet.Data.Add(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user