[11848] Change use of ScriptLibrary OnGOUse return value in GO::Use

Now mainly used to allow or prevent DB scripts use
Also some related code cleaned and reordered

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
Schmoozerd 2011-11-19 00:49:32 +01:00
parent c814e10481
commit 3ae1f25b9b
2 changed files with 58 additions and 46 deletions

View file

@ -934,9 +934,6 @@ void GameObject::Use(Unit* user)
uint32 spellId = 0;
bool triggered = false;
if (user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this))
return;
// test only for exist cooldown data (cooldown timer used for door/buttons reset that not have use cooldown)
if (uint32 cooldown = GetGOInfo()->GetCooldown())
{
@ -946,6 +943,8 @@ void GameObject::Use(Unit* user)
m_cooldownTime = sWorld.GetGameTime() + cooldown;
}
bool scriptReturnValue = user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this);
switch (GetGoType())
{
case GAMEOBJECT_TYPE_DOOR: // 0
@ -954,6 +953,7 @@ void GameObject::Use(Unit* user)
UseDoorOrButton();
// activate script
if (!scriptReturnValue)
GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this);
return;
}
@ -962,10 +962,12 @@ void GameObject::Use(Unit* user)
//buttons never really despawn, only reset to default state/flags
UseDoorOrButton();
TriggerLinkedGameObject(user);
// activate script
if (!scriptReturnValue)
GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this);
TriggerLinkedGameObject(user);
return;
}
case GAMEOBJECT_TYPE_QUESTGIVER: // 2
@ -988,6 +990,8 @@ void GameObject::Use(Unit* user)
if (user->GetTypeId() != TYPEID_PLAYER)
return;
TriggerLinkedGameObject(user);
// TODO: possible must be moved to loot release (in different from linked triggering)
if (GetGOInfo()->chest.eventId)
{
@ -997,11 +1001,13 @@ void GameObject::Use(Unit* user)
GetMap()->ScriptsStart(sEventScripts, GetGOInfo()->chest.eventId, user, this);
}
TriggerLinkedGameObject(user);
return;
}
case GAMEOBJECT_TYPE_GENERIC: // 5
{
if (scriptReturnValue)
return;
// No known way to exclude some - only different approach is to select despawnable GOs by Entry
SetLootState(GO_JUST_DEACTIVATED);
return;
@ -1011,8 +1017,11 @@ void GameObject::Use(Unit* user)
// Currently we do not expect trap code below to be Use()
// directly (except from spell effect). Code here will be called by TriggerLinkedGameObject.
if (scriptReturnValue)
return;
// FIXME: when GO casting will be implemented trap must cast spell to target
if (uint32 spellId = GetGOInfo()->trap.spellId)
if (spellId = GetGOInfo()->trap.spellId)
user->CastSpell(user, spellId, true, NULL, NULL, GetObjectGuid());
// TODO: all traps can be activated, also those without spell.
@ -1089,12 +1098,25 @@ void GameObject::Use(Unit* user)
TriggerLinkedGameObject(user);
// some may be activated in addition? Conditions for this? (ex: entry 181616)
break;
return;
}
case GAMEOBJECT_TYPE_GOOBER: // 10
{
GameObjectInfo const* info = GetGOInfo();
TriggerLinkedGameObject(user);
SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
SetLootState(GO_ACTIVATED);
// this appear to be ok, however others exist in addition to this that should have custom (ex: 190510, 188692, 187389)
if (info->goober.customAnim)
SendGameObjectCustomAnim(GetObjectGuid());
else
SetGoState(GO_STATE_ACTIVE);
m_cooldownTime = time(NULL) + info->GetAutoCloseTime();
if (user->GetTypeId() == TYPEID_PLAYER)
{
Player* player = (Player*)user;
@ -1134,18 +1156,8 @@ void GameObject::Use(Unit* user)
}
TriggerLinkedGameObject(user);
SetFlag(GAMEOBJECT_FLAGS, GO_FLAG_IN_USE);
SetLootState(GO_ACTIVATED);
// this appear to be ok, however others exist in addition to this that should have custom (ex: 190510, 188692, 187389)
if (info->goober.customAnim)
SendGameObjectCustomAnim(GetObjectGuid());
else
SetGoState(GO_STATE_ACTIVE);
m_cooldownTime = time(NULL) + info->GetAutoCloseTime();
if (scriptReturnValue)
return;
// cast this spell later if provided
spellId = info->goober.spellId;
@ -1597,7 +1609,7 @@ void GameObject::Use(Unit* user)
}
default:
sLog.outError("GameObject::Use unhandled GameObject type %u (entry %u).", GetGoType(), GetEntry());
break;
return;
}
if (!spellId)

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "11847"
#define REVISION_NR "11848"
#endif // __REVISION_NR_H__