Core/Scripts: unified scripted gossip/quest api

Port From (https://github.com/TrinityCore/TrinityCore/commit/6604849716bc73d82a4cdbf8c66bb188086ceae4)
This commit is contained in:
hondacrx
2020-05-22 13:28:20 -04:00
parent 87b63b0975
commit c2aee387a8
30 changed files with 1642 additions and 1367 deletions
+34 -7
View File
@@ -18,14 +18,15 @@
using Framework.Dynamic;
using Game.Entities;
using Game.Spells;
using Framework.Constants;
namespace Game.AI
{
public class GameObjectAI
{
public GameObjectAI(GameObject g)
public GameObjectAI(GameObject gameObject)
{
go = g;
me = gameObject;
_scheduler = new TaskScheduler();
_events = new EventMap();
}
@@ -41,27 +42,53 @@ namespace Game.AI
public virtual void SetGUID(ulong guid, int id = 0) { }
public virtual ulong GetGUID(int id = 0) { return 0; }
/// <summary>
/// Called when a player opens a gossip dialog with the gameobject.
/// </summary>
public virtual bool GossipHello(Player player, bool reportUse) { return false; }
public virtual bool GossipSelect(Player player, uint sender, uint action) { return false; }
/// <summary>
/// Called when a player selects a gossip item in the gameobject's gossip menu.
/// </summary>
public virtual bool GossipSelect(Player player, uint menuId, uint gossipListId) { return false; }
/// <summary>
/// Called when a player selects a gossip with a code in the gameobject's gossip menu.
/// </summary>
public virtual bool GossipSelectCode(Player player, uint sender, uint action, string code) { return false; }
public virtual bool QuestAccept(Player player, Quest quest) { return false; }
public virtual bool QuestReward(Player player, Quest quest, uint opt) { return false; }
/// <summary>
/// Called when a player accepts a quest from the gameobject.
/// </summary>
public virtual void QuestAccept(Player player, Quest quest) { }
/// <summary>
/// Called when a player completes a quest and is rewarded, opt is the selected item's index or 0
/// </summary>
public virtual void QuestReward(Player player, Quest quest, uint opt) { }
/// <summary>
/// Called when the dialog status between a player and the gameobject is requested.
/// </summary>
public virtual uint GetDialogStatus(Player player) { return 100; }
public virtual void Destroyed(Player player, uint eventId) { }
public virtual void Damaged(Player player, uint eventId) { }
public virtual void SetData64(uint id, ulong value) { }
public virtual ulong GetData64(uint id) { return 0; }
public virtual uint GetData(uint id) { return 0; }
public virtual void SetData(uint id, uint value) { }
public virtual void OnGameEvent(bool start, ushort eventId) { }
public virtual void OnStateChanged(uint state, Unit unit) { }
public virtual void OnLootStateChanged(uint state, Unit unit) { }
public virtual void OnStateChanged(GameObjectState state) { }
public virtual void EventInform(uint eventId) { }
public virtual void SpellHit(Unit unit, SpellInfo spellInfo) { }
protected TaskScheduler _scheduler;
protected EventMap _events;
public GameObject go;
public GameObject me;
}
public class NullGameObjectAI : GameObjectAI
+29 -5
View File
@@ -378,15 +378,39 @@ namespace Game.AI
public virtual void HealDone(Unit to, uint addhealth) { }
public virtual void SpellInterrupted(uint spellId, uint unTimeMs) {}
public virtual void GossipHello(Player player) { }
public virtual void GossipSelect(Player player, uint menuId, uint gossipListId) { }
public virtual void GossipSelectCode(Player player, uint menuId, uint gossipListId, string code) { }
/// <summary>
/// Called when a player opens a gossip dialog with the creature.
/// </summary>
public virtual bool GossipHello(Player player) { return false; }
/// <summary>
/// Called when a player selects a gossip item in the creature's gossip menu.
/// </summary>
public virtual bool GossipSelect(Player player, uint menuId, uint gossipListId) { return false; }
/// <summary>
/// Called when a player selects a gossip with a code in the creature's gossip menu.
/// </summary>
public virtual bool GossipSelectCode(Player player, uint menuId, uint gossipListId, string code) { return false; }
/// <summary>
/// Called when a player accepts a quest from the creature.
/// </summary>
public virtual void QuestAccept(Player player, Quest quest) { }
public virtual void QuestSelect(Player player, Quest quest) { }
public virtual void QuestComplete(Player player, Quest quest) { }
/// <summary>
/// Called when a player completes a quest and is rewarded, opt is the selected item's index or 0
/// </summary>
public virtual void QuestReward(Player player, Quest quest, uint opt) { }
/// <summary>
/// Called when a game event starts or ends
/// </summary>
public virtual void OnGameEvent(bool start, ushort eventId) { }
// Called when the dialog status between a player and the creature is requested.
public virtual QuestGiverStatus GetDialogStatus(Player player) { return QuestGiverStatus.ScriptedNoStatus; }
public static AISpellInfoType[] AISpellInfo;
protected Unit me { get; private set; }
+26 -23
View File
@@ -789,17 +789,22 @@ namespace Game.AI
mEvadeDisabled = disable;
}
public override void GossipHello(Player player)
public override bool GossipHello(Player player)
{
GetScript().ProcessEventsFor(SmartEvents.GossipHello, player);
return false;
}
public override void GossipSelect(Player player, uint menuId, uint gossipListId)
public override bool GossipSelect(Player player, uint menuId, uint gossipListId)
{
GetScript().ProcessEventsFor(SmartEvents.GossipSelect, player, menuId, gossipListId);
return false;
}
public override void GossipSelectCode(Player player, uint menuId, uint gossipListId, string code) { }
public override bool GossipSelectCode(Player player, uint menuId, uint gossipListId, string code)
{
return false;
}
public override void QuestAccept(Player player, Quest quest)
{
@@ -811,6 +816,11 @@ namespace Game.AI
GetScript().ProcessEventsFor(SmartEvents.RewardQuest, player, quest.Id, opt);
}
public override void OnGameEvent(bool start, ushort eventId)
{
GetScript().ProcessEventsFor(start ? SmartEvents.GameEventStart : SmartEvents.GameEventEnd, null, eventId);
}
public void SetCombatMove(bool on)
{
if (mCanCombatMove == on)
@@ -899,11 +909,6 @@ namespace Game.AI
GetScript().SetScript9(e, entry);
}
public override void OnGameEvent(bool start, ushort eventId)
{
GetScript().ProcessEventsFor(start ? SmartEvents.GameEventStart : SmartEvents.GameEventEnd, null, eventId);
}
public override void OnSpellClick(Unit clicker, ref bool result)
{
if (!result)
@@ -1043,9 +1048,9 @@ namespace Game.AI
public override void InitializeAI()
{
GetScript().OnInitialize(go);
GetScript().OnInitialize(me);
// do not call respawn event if go is not spawned
if (go.IsSpawned())
if (me.IsSpawned())
GetScript().ProcessEventsFor(SmartEvents.Respawn);
}
@@ -1060,31 +1065,29 @@ namespace Game.AI
public override bool GossipHello(Player player, bool reportUse)
{
Log.outDebug(LogFilter.ScriptsAi, "SmartGameObjectAI.GossipHello");
GetScript().ProcessEventsFor(SmartEvents.GossipHello, player, reportUse ? 1 : 0u, 0, false, null, go);
GetScript().ProcessEventsFor(SmartEvents.GossipHello, player, reportUse ? 1 : 0u, 0, false, null, me);
return false;
}
public override bool GossipSelect(Player player, uint sender, uint action)
public override bool GossipSelect(Player player, uint menuId, uint gossipListId)
{
GetScript().ProcessEventsFor(SmartEvents.GossipSelect, player, sender, action, false, null, go);
GetScript().ProcessEventsFor(SmartEvents.GossipSelect, player, menuId, gossipListId, false, null, me);
return false;
}
public override bool GossipSelectCode(Player player, uint sender, uint action, string code)
public override bool GossipSelectCode(Player player, uint menuId, uint gossipListId, string code)
{
return false;
}
public override bool QuestAccept(Player player, Quest quest)
public override void QuestAccept(Player player, Quest quest)
{
GetScript().ProcessEventsFor(SmartEvents.AcceptedQuest, player, quest.Id, 0, false, null, go);
return false;
GetScript().ProcessEventsFor(SmartEvents.AcceptedQuest, player, quest.Id, 0, false, null, me);
}
public override bool QuestReward(Player player, Quest quest, uint opt)
public override void QuestReward(Player player, Quest quest, uint opt)
{
GetScript().ProcessEventsFor(SmartEvents.RewardQuest, player, quest.Id, opt, false, null, go);
return false;
GetScript().ProcessEventsFor(SmartEvents.RewardQuest, player, quest.Id, opt, false, null, me);
}
public override uint GetDialogStatus(Player player)
@@ -1094,7 +1097,7 @@ namespace Game.AI
public override void Destroyed(Player player, uint eventId)
{
GetScript().ProcessEventsFor(SmartEvents.Death, player, eventId, 0, false, null, go);
GetScript().ProcessEventsFor(SmartEvents.Death, player, eventId, 0, false, null, me);
}
public override void SetData(uint id, uint value)
@@ -1114,9 +1117,9 @@ namespace Game.AI
GetScript().ProcessEventsFor(start ? SmartEvents.GameEventStart : SmartEvents.GameEventEnd, null, eventId);
}
public override void OnStateChanged(uint state, Unit unit)
public override void OnLootStateChanged(uint state, Unit unit)
{
GetScript().ProcessEventsFor(SmartEvents.GoStateChanged, unit, state);
GetScript().ProcessEventsFor(SmartEvents.GoLootStateChanged, unit, state);
}
public override void EventInform(uint eventId)
@@ -757,7 +757,7 @@ namespace Game.AI
}
break;
case SmartEvents.Link:
case SmartEvents.GoStateChanged:
case SmartEvents.GoLootStateChanged:
case SmartEvents.GoEventInform:
case SmartEvents.TimedEventTriggered:
case SmartEvents.InstancePlayerEnter:
@@ -1638,7 +1638,7 @@ namespace Game.AI
{ SmartEvents.IsBehindTarget, SmartScriptTypeMaskId.Creature },
{ SmartEvents.GameEventStart, SmartScriptTypeMaskId.Creature + SmartScriptTypeMaskId.Gameobject },
{ SmartEvents.GameEventEnd, SmartScriptTypeMaskId.Creature + SmartScriptTypeMaskId.Gameobject },
{ SmartEvents.GoStateChanged, SmartScriptTypeMaskId.Gameobject },
{ SmartEvents.GoLootStateChanged, SmartScriptTypeMaskId.Gameobject },
{ SmartEvents.GoEventInform, SmartScriptTypeMaskId.Gameobject },
{ SmartEvents.ActionDone, SmartScriptTypeMaskId.Creature },
{ SmartEvents.OnSpellclick, SmartScriptTypeMaskId.Creature },
@@ -1813,7 +1813,7 @@ namespace Game.AI
public GameEvent gameEvent;
[FieldOffset(16)]
public GoStateChanged goStateChanged;
public GoLootStateChanged goLootStateChanged;
[FieldOffset(16)]
public EventInform eventInform;
@@ -2009,9 +2009,9 @@ namespace Game.AI
{
public uint gameEventId;
}
public struct GoStateChanged
public struct GoLootStateChanged
{
public uint state;
public uint lootState;
}
public struct EventInform
{
+6 -6
View File
@@ -2736,16 +2736,16 @@ namespace Game.AI
if (go == null)
return;
//store hostage as id1
AddEvent(SmartEvents.GoStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.StoreTargetList, 1, 0, 0, 0, 0, 0, SmartTargets.ClosestCreature, e.Action.installTtemplate.param1, 10, 0, 0);
AddEvent(SmartEvents.GoLootStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.StoreTargetList, 1, 0, 0, 0, 0, 0, SmartTargets.ClosestCreature, e.Action.installTtemplate.param1, 10, 0, 0);
//store invoker as id2
AddEvent(SmartEvents.GoStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.StoreTargetList, 2, 0, 0, 0, 0, 0, SmartTargets.None, 0, 0, 0, 0);
AddEvent(SmartEvents.GoLootStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.StoreTargetList, 2, 0, 0, 0, 0, 0, SmartTargets.None, 0, 0, 0, 0);
//signal hostage
AddEvent(SmartEvents.GoStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.SetData, 0, 0, 0, 0, 0, 0, SmartTargets.Stored, 1, 0, 0, 0);
AddEvent(SmartEvents.GoLootStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.SetData, 0, 0, 0, 0, 0, 0, SmartTargets.Stored, 1, 0, 0, 0);
//when hostage raeched end point, give credit to invoker
if (e.Action.installTtemplate.param2 != 0)
AddEvent(SmartEvents.DataSet, 0, 0, 0, 0, 0, 0, SmartActions.CallKilledmonster, e.Action.installTtemplate.param1, 0, 0, 0, 0, 0, SmartTargets.Stored, 2, 0, 0, 0);
else
AddEvent(SmartEvents.GoStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.CallKilledmonster, e.Action.installTtemplate.param1, 0, 0, 0, 0, 0, SmartTargets.Stored, 2, 0, 0, 0);
AddEvent(SmartEvents.GoLootStateChanged, 0, 2, 0, 0, 0, 0, SmartActions.CallKilledmonster, e.Action.installTtemplate.param1, 0, 0, 0, 0, 0, SmartTargets.Stored, 2, 0, 0, 0);
break;
}
default:
@@ -3632,9 +3632,9 @@ namespace Game.AI
ProcessAction(e, null, var0);
break;
}
case SmartEvents.GoStateChanged:
case SmartEvents.GoLootStateChanged:
{
if (e.Event.goStateChanged.state != var0)
if (e.Event.goLootStateChanged.lootState != var0)
return;
ProcessAction(e, unit, var0, var1);
break;