Core/CreatureAI: Implement an OnSpellClick hook instead of the ugly way that uses DoAction with EVENT_SPELLCLICK.

Core/SmartAI: Implement SMART_EVENT_ON_SPELLCLICK. Parameter is the clicker.

If someone could update the wiki accordingly for SAI I would appreciate that. Thanks to @Shauren for some help!
This commit is contained in:
Discover-
2012-06-19 00:07:20 +02:00
parent 29f1ab2438
commit e190a202ca
11 changed files with 26 additions and 27 deletions
+2 -2
View File
@@ -128,8 +128,6 @@ class CreatureAI : public UnitAI
void OnCharmed(bool apply);
//virtual void SpellClick(Player* player) {}
// Called at reaching home after evade
virtual void JustReachedHome() {}
@@ -171,6 +169,8 @@ class CreatureAI : public UnitAI
virtual void PassengerBoarded(Unit* /*passenger*/, int8 /*seatId*/, bool /*apply*/) {}
virtual void OnSpellClick(Unit* /*clicker*/) { }
virtual bool CanSeeAlways(WorldObject const* /*obj*/) { return false; }
protected:
virtual void MoveInLineOfSight(Unit* /*who*/);
@@ -826,6 +826,11 @@ void SmartAI::sOnGameEvent(bool start, uint16 eventId)
GetScript()->ProcessEventsFor(start ? SMART_EVENT_GAME_EVENT_START : SMART_EVENT_GAME_EVENT_END, NULL, eventId);
}
void SmartAI::OnSpellClick(Unit* clicker)
{
GetScript()->ProcessEventsFor(SMART_EVENT_ON_SPELLCLICK, clicker);
}
int SmartGameObjectAI::Permissible(const GameObject* g)
{
if (g->GetAIName() == "SmartGameObjectAI")
@@ -198,6 +198,8 @@ class SmartAI : public CreatureAI
void RemoveAuras();
void OnSpellClick(Unit* clicker);
private:
uint32 mFollowCreditType;
uint32 mFollowArrivedTimer;
@@ -2534,6 +2534,7 @@ void SmartScript::ProcessEvent(SmartScriptHolder& e, Unit* unit, uint32 var0, ui
case SMART_EVENT_JUST_CREATED:
case SMART_EVENT_GOSSIP_HELLO:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
ProcessAction(e, unit, var0, var1, bvar, spell, gob);
break;
case SMART_EVENT_IS_BEHIND_TARGET:
@@ -538,7 +538,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
}
case SMART_EVENT_ACTION_DONE:
{
if (e.event.doAction.eventId < EVENT_SPELLCLICK || e.event.doAction.eventId > EVENT_CHARGE)
if (e.event.doAction.eventId > EVENT_CHARGE)
{
sLog->outErrorDb("SmartAIMgr: Entry %d SourceType %u Event %u Action %u uses invalid event id %u, skipped.", e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType(), e.event.doAction.eventId);
return false;
@@ -577,6 +577,7 @@ bool SmartAIMgr::IsEventValid(SmartScriptHolder& e)
case SMART_EVENT_GOSSIP_HELLO:
case SMART_EVENT_JUST_CREATED:
case SMART_EVENT_FOLLOW_COMPLETED:
case SMART_EVENT_ON_SPELLCLICK:
break;
default:
sLog->outErrorDb("SmartAIMgr: Not handled event_type(%u), Entry %d SourceType %u Event %u Action %u, skipped.", e.GetEventType(), e.entryOrGuid, e.GetScriptType(), e.event_id, e.GetActionType());
@@ -154,8 +154,9 @@ enum SMART_EVENT
SMART_EVENT_GO_STATE_CHANGED = 70, // go state
SMART_EVENT_GO_EVENT_INFORM = 71, // eventId
SMART_EVENT_ACTION_DONE = 72, // eventId (SharedDefines.EventId)
SMART_EVENT_ON_SPELLCLICK = 73, // clicker (unit)
SMART_EVENT_END = 73,
SMART_EVENT_END = 74,
};
struct SmartEvent
@@ -1178,6 +1179,7 @@ const uint32 SmartAIEventMask[SMART_EVENT_END][2] =
{SMART_EVENT_GO_STATE_CHANGED, SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_GO_EVENT_INFORM, SMART_SCRIPT_TYPE_MASK_GAMEOBJECT },
{SMART_EVENT_ACTION_DONE, SMART_SCRIPT_TYPE_MASK_CREATURE },
{SMART_EVENT_ON_SPELLCLICK, SMART_SCRIPT_TYPE_MASK_CREATURE },
};
enum SmartEventFlags
+1 -1
View File
@@ -16935,7 +16935,7 @@ bool Unit::HandleSpellClick(Unit* clicker, int8 seatId)
Creature* creature = ToCreature();
if (creature && creature->IsAIEnabled)
creature->AI()->DoAction(EVENT_SPELLCLICK);
creature->AI()->OnSpellClick(clicker);
return true;
}
@@ -3151,8 +3151,6 @@ enum SummonType
enum EventId
{
EVENT_SPELLCLICK = 1001,
EVENT_FALL_GROUND = 1002,
EVENT_CHARGE = 1003,
};
@@ -81,11 +81,6 @@ void PointMovementGenerator<T>::MovementInform(T & /*unit*/)
template <> void PointMovementGenerator<Creature>::MovementInform(Creature &unit)
{
//if (id == EVENT_FALL_GROUND)
//{
// unit.setDeathState(JUST_DIED);
// unit.SetFlying(true);
//}
if (unit.AI())
unit.AI()->MovementInform(POINT_MOTION_TYPE, id);
}
@@ -1013,11 +1013,8 @@ class npc_dream_portal : public CreatureScript
{
}
void DoAction(int32 const action)
void OnSpellClick(Unit* /*clicker*/)
{
if (action != EVENT_SPELLCLICK)
return;
_used = true;
me->DespawnOrUnsummon();
}
@@ -720,20 +720,18 @@ class boss_flame_leviathan_overload_device : public CreatureScript
{
}
void DoAction(const int32 param)
void OnSpellClick(Unit* /*clicker*/)
{
if (param == EVENT_SPELLCLICK)
if (me->GetVehicle())
{
if (me->GetVehicle())
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
if (Unit* player = me->GetVehicle()->GetPassenger(SEAT_PLAYER))
{
me->RemoveFlag(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_SPELLCLICK);
me->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE);
if (Unit* player = me->GetVehicle()->GetPassenger(SEAT_PLAYER))
{
me->GetVehicleBase()->CastSpell(player, SPELL_SMOKE_TRAIL, true);
player->GetMotionMaster()->MoveKnockbackFrom(me->GetVehicleBase()->GetPositionX(), me->GetVehicleBase()->GetPositionY(), 30, 30);
player->ExitVehicle();
}
me->GetVehicleBase()->CastSpell(player, SPELL_SMOKE_TRAIL, true);
player->GetMotionMaster()->MoveKnockbackFrom(me->GetVehicleBase()->GetPositionX(), me->GetVehicleBase()->GetPositionY(), 30, 30);
player->ExitVehicle();
}
}
}