[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; uint32 spellId = 0;
bool triggered = false; 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) // test only for exist cooldown data (cooldown timer used for door/buttons reset that not have use cooldown)
if (uint32 cooldown = GetGOInfo()->GetCooldown()) if (uint32 cooldown = GetGOInfo()->GetCooldown())
{ {
@ -946,7 +943,9 @@ void GameObject::Use(Unit* user)
m_cooldownTime = sWorld.GetGameTime() + cooldown; m_cooldownTime = sWorld.GetGameTime() + cooldown;
} }
switch(GetGoType()) bool scriptReturnValue = user->GetTypeId() == TYPEID_PLAYER && sScriptMgr.OnGameObjectUse((Player*)user, this);
switch (GetGoType())
{ {
case GAMEOBJECT_TYPE_DOOR: // 0 case GAMEOBJECT_TYPE_DOOR: // 0
{ {
@ -954,6 +953,7 @@ void GameObject::Use(Unit* user)
UseDoorOrButton(); UseDoorOrButton();
// activate script // activate script
if (!scriptReturnValue)
GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this); GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this);
return; return;
} }
@ -962,10 +962,12 @@ void GameObject::Use(Unit* user)
//buttons never really despawn, only reset to default state/flags //buttons never really despawn, only reset to default state/flags
UseDoorOrButton(); UseDoorOrButton();
TriggerLinkedGameObject(user);
// activate script // activate script
if (!scriptReturnValue)
GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this); GetMap()->ScriptsStart(sGameObjectScripts, GetGUIDLow(), spellCaster, this);
TriggerLinkedGameObject(user);
return; return;
} }
case GAMEOBJECT_TYPE_QUESTGIVER: // 2 case GAMEOBJECT_TYPE_QUESTGIVER: // 2
@ -988,6 +990,8 @@ void GameObject::Use(Unit* user)
if (user->GetTypeId() != TYPEID_PLAYER) if (user->GetTypeId() != TYPEID_PLAYER)
return; return;
TriggerLinkedGameObject(user);
// TODO: possible must be moved to loot release (in different from linked triggering) // TODO: possible must be moved to loot release (in different from linked triggering)
if (GetGOInfo()->chest.eventId) if (GetGOInfo()->chest.eventId)
{ {
@ -997,11 +1001,13 @@ void GameObject::Use(Unit* user)
GetMap()->ScriptsStart(sEventScripts, GetGOInfo()->chest.eventId, user, this); GetMap()->ScriptsStart(sEventScripts, GetGOInfo()->chest.eventId, user, this);
} }
TriggerLinkedGameObject(user);
return; return;
} }
case GAMEOBJECT_TYPE_GENERIC: // 5 case GAMEOBJECT_TYPE_GENERIC: // 5
{ {
if (scriptReturnValue)
return;
// No known way to exclude some - only different approach is to select despawnable GOs by Entry // No known way to exclude some - only different approach is to select despawnable GOs by Entry
SetLootState(GO_JUST_DEACTIVATED); SetLootState(GO_JUST_DEACTIVATED);
return; return;
@ -1011,8 +1017,11 @@ void GameObject::Use(Unit* user)
// Currently we do not expect trap code below to be Use() // Currently we do not expect trap code below to be Use()
// directly (except from spell effect). Code here will be called by TriggerLinkedGameObject. // 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 // 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()); user->CastSpell(user, spellId, true, NULL, NULL, GetObjectGuid());
// TODO: all traps can be activated, also those without spell. // TODO: all traps can be activated, also those without spell.
@ -1024,7 +1033,7 @@ void GameObject::Use(Unit* user)
return; return;
} }
case GAMEOBJECT_TYPE_CHAIR: //7 Sitting: Wooden bench, chairs case GAMEOBJECT_TYPE_CHAIR: // 7 Sitting: Wooden bench, chairs
{ {
GameObjectInfo const* info = GetGOInfo(); GameObjectInfo const* info = GetGOInfo();
if (!info) if (!info)
@ -1047,7 +1056,7 @@ void GameObject::Use(Unit* user)
// the object orientation + 1/2 pi // the object orientation + 1/2 pi
// every slot will be on that straight line // every slot will be on that straight line
float orthogonalOrientation = GetOrientation()+M_PI_F*0.5f; float orthogonalOrientation = GetOrientation() + M_PI_F * 0.5f;
// find nearest slot // find nearest slot
for(uint32 i=0; i<info->chair.slots; ++i) for(uint32 i=0; i<info->chair.slots; ++i)
{ {
@ -1074,14 +1083,14 @@ void GameObject::Use(Unit* user)
y_lowest = y_i; y_lowest = y_i;
} }
} }
player->TeleportTo(GetMapId(), x_lowest, y_lowest, GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET); player->TeleportTo(GetMapId(), x_lowest, y_lowest, GetPositionZ(), GetOrientation(), TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET);
} }
else else
{ {
// fallback, will always work // fallback, will always work
player->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(),TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET); player->TeleportTo(GetMapId(), GetPositionX(), GetPositionY(), GetPositionZ(), GetOrientation(), TELE_TO_NOT_LEAVE_TRANSPORT | TELE_TO_NOT_LEAVE_COMBAT | TELE_TO_NOT_UNSUMMON_PET);
} }
player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR+info->chair.height); player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR + info->chair.height);
return; return;
} }
case GAMEOBJECT_TYPE_SPELL_FOCUS: // 8 case GAMEOBJECT_TYPE_SPELL_FOCUS: // 8
@ -1089,12 +1098,25 @@ void GameObject::Use(Unit* user)
TriggerLinkedGameObject(user); TriggerLinkedGameObject(user);
// some may be activated in addition? Conditions for this? (ex: entry 181616) // some may be activated in addition? Conditions for this? (ex: entry 181616)
break; return;
} }
case GAMEOBJECT_TYPE_GOOBER: //10 case GAMEOBJECT_TYPE_GOOBER: // 10
{ {
GameObjectInfo const* info = GetGOInfo(); 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) if (user->GetTypeId() == TYPEID_PLAYER)
{ {
Player* player = (Player*)user; Player* player = (Player*)user;
@ -1134,18 +1156,8 @@ void GameObject::Use(Unit* user)
} }
TriggerLinkedGameObject(user); if (scriptReturnValue)
return;
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();
// cast this spell later if provided // cast this spell later if provided
spellId = info->goober.spellId; spellId = info->goober.spellId;
@ -1162,7 +1174,7 @@ void GameObject::Use(Unit* user)
break; break;
} }
case GAMEOBJECT_TYPE_CAMERA: //13 case GAMEOBJECT_TYPE_CAMERA: // 13
{ {
GameObjectInfo const* info = GetGOInfo(); GameObjectInfo const* info = GetGOInfo();
if (!info) if (!info)
@ -1184,7 +1196,7 @@ void GameObject::Use(Unit* user)
return; return;
} }
case GAMEOBJECT_TYPE_FISHINGNODE: //17 fishing bobber case GAMEOBJECT_TYPE_FISHINGNODE: // 17 fishing bobber
{ {
if (user->GetTypeId() != TYPEID_PLAYER) if (user->GetTypeId() != TYPEID_PLAYER)
return; return;
@ -1194,7 +1206,7 @@ void GameObject::Use(Unit* user)
if (player->GetObjectGuid() != GetOwnerGuid()) if (player->GetObjectGuid() != GetOwnerGuid())
return; return;
switch(getLootState()) switch (getLootState())
{ {
case GO_READY: // ready for loot case GO_READY: // ready for loot
{ {
@ -1203,7 +1215,7 @@ void GameObject::Use(Unit* user)
// 3) chance is linear dependence from (base_zone_skill-skill) // 3) chance is linear dependence from (base_zone_skill-skill)
uint32 zone, subzone; uint32 zone, subzone;
GetZoneAndAreaId(zone,subzone); GetZoneAndAreaId(zone, subzone);
int32 zone_skill = sObjectMgr.GetFishingBaseSkillLevel(subzone); int32 zone_skill = sObjectMgr.GetFishingBaseSkillLevel(subzone);
if (!zone_skill) if (!zone_skill)
@ -1211,13 +1223,13 @@ void GameObject::Use(Unit* user)
//provide error, no fishable zone or area should be 0 //provide error, no fishable zone or area should be 0
if (!zone_skill) if (!zone_skill)
sLog.outErrorDb("Fishable areaId %u are not properly defined in `skill_fishing_base_level`.",subzone); sLog.outErrorDb("Fishable areaId %u are not properly defined in `skill_fishing_base_level`.", subzone);
int32 skill = player->GetSkillValue(SKILL_FISHING); int32 skill = player->GetSkillValue(SKILL_FISHING);
int32 chance = skill - zone_skill + 5; int32 chance = skill - zone_skill + 5;
int32 roll = irand(1,100); int32 roll = irand(1, 100);
DEBUG_LOG("Fishing check (skill: %i zone min skill: %i chance %i roll: %i",skill,zone_skill,chance,roll); DEBUG_LOG("Fishing check (skill: %i zone min skill: %i chance %i roll: %i", skill, zone_skill, chance, roll);
// normal chance // normal chance
bool success = skill >= zone_skill && chance >= roll; bool success = skill >= zone_skill && chance >= roll;
@ -1246,7 +1258,7 @@ void GameObject::Use(Unit* user)
if (success || sWorld.getConfig(CONFIG_BOOL_SKILL_FAIL_LOOT_FISHING)) if (success || sWorld.getConfig(CONFIG_BOOL_SKILL_FAIL_LOOT_FISHING))
{ {
// prevent removing GO at spell cancel // prevent removing GO at spell cancel
player->RemoveGameObject(this,false); player->RemoveGameObject(this, false);
SetOwnerGuid(player->GetObjectGuid()); SetOwnerGuid(player->GetObjectGuid());
if (fishingHole) // will set at success only if (fishingHole) // will set at success only
@ -1282,7 +1294,7 @@ void GameObject::Use(Unit* user)
player->FinishSpell(CURRENT_CHANNELED_SPELL); player->FinishSpell(CURRENT_CHANNELED_SPELL);
return; return;
} }
case GAMEOBJECT_TYPE_SUMMONING_RITUAL: //18 case GAMEOBJECT_TYPE_SUMMONING_RITUAL: // 18
{ {
if (user->GetTypeId() != TYPEID_PLAYER) if (user->GetTypeId() != TYPEID_PLAYER)
return; return;
@ -1367,7 +1379,7 @@ void GameObject::Use(Unit* user)
// go to end function to spell casting // go to end function to spell casting
break; break;
} }
case GAMEOBJECT_TYPE_SPELLCASTER: //22 case GAMEOBJECT_TYPE_SPELLCASTER: // 22
{ {
SetUInt32Value(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED); SetUInt32Value(GAMEOBJECT_FLAGS, GO_FLAG_LOCKED);
@ -1390,7 +1402,7 @@ void GameObject::Use(Unit* user)
AddUse(); AddUse();
break; break;
} }
case GAMEOBJECT_TYPE_MEETINGSTONE: //23 case GAMEOBJECT_TYPE_MEETINGSTONE: // 23
{ {
GameObjectInfo const* info = GetGOInfo(); GameObjectInfo const* info = GetGOInfo();
@ -1431,7 +1443,7 @@ void GameObject::Use(Unit* user)
if (player->CanUseBattleGroundObject()) if (player->CanUseBattleGroundObject())
{ {
// in battleground check // in battleground check
BattleGround *bg = player->GetBattleGround(); BattleGround* bg = player->GetBattleGround();
if (!bg) if (!bg)
return; return;
// BG flag click // BG flag click
@ -1575,7 +1587,7 @@ void GameObject::Use(Unit* user)
// Some has spell, need to process those further. // Some has spell, need to process those further.
return; return;
} }
case GAMEOBJECT_TYPE_BARBER_CHAIR: //32 case GAMEOBJECT_TYPE_BARBER_CHAIR: // 32
{ {
GameObjectInfo const* info = GetGOInfo(); GameObjectInfo const* info = GetGOInfo();
if (!info) if (!info)
@ -1592,12 +1604,12 @@ void GameObject::Use(Unit* user)
WorldPacket data(SMSG_ENABLE_BARBER_SHOP, 0); WorldPacket data(SMSG_ENABLE_BARBER_SHOP, 0);
player->GetSession()->SendPacket(&data); player->GetSession()->SendPacket(&data);
player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR+info->barberChair.chairheight); player->SetStandState(UNIT_STAND_STATE_SIT_LOW_CHAIR + info->barberChair.chairheight);
return; return;
} }
default: default:
sLog.outError("GameObject::Use unhandled GameObject type %u (entry %u).", GetGoType(), GetEntry()); sLog.outError("GameObject::Use unhandled GameObject type %u (entry %u).", GetGoType(), GetEntry());
break; return;
} }
if (!spellId) if (!spellId)
@ -1606,7 +1618,7 @@ void GameObject::Use(Unit* user)
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId); SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId);
if (!spellInfo) if (!spellInfo)
{ {
sLog.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId,GetEntry(),GetGoType()); sLog.outError("WORLD: unknown spell id %u at use action for gameobject (Entry: %u GoType: %u )", spellId, GetEntry(), GetGoType());
return; return;
} }

View file

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