[11990] More db-script command changes

* Allow SCRIPT_COMMAND_KILL_CREDIT to give the kill of an involved npc.
  This is marked by datalong (creature-entry) == 0
* Remove immediate execution of commands. This will prevent infinite loops when db-scripts trigger db-scripts which are executed immediately
* Add check for SCRIPT_COMMAND_PLAY_SOUND
* Add check to catch an invalid command

Signed-off-by: Schmoozerd <schmoozerd@scriptdev2.com>
This commit is contained in:
Schmoozerd 2012-05-09 22:35:00 +02:00
parent 419ba5fc28
commit 414d432d24
6 changed files with 109 additions and 91 deletions

View file

@ -215,7 +215,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
switch (tmp.command)
{
case SCRIPT_COMMAND_TALK:
case SCRIPT_COMMAND_TALK: // 0
{
if (tmp.talk.chatType > CHAT_TYPE_ZONE_YELL)
{
@ -247,7 +247,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
// if (!GetMangosStringLocale(tmp.dataint)) will be checked after db_script_string loading
break;
}
case SCRIPT_COMMAND_EMOTE:
case SCRIPT_COMMAND_EMOTE: // 1
{
if (!sEmotesStore.LookupEntry(tmp.emote.emoteId))
{
@ -256,7 +256,12 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_TELEPORT_TO:
case SCRIPT_COMMAND_FIELD_SET: // 2
case SCRIPT_COMMAND_MOVE_TO: // 3
case SCRIPT_COMMAND_FLAG_SET: // 4
case SCRIPT_COMMAND_FLAG_REMOVE: // 5
break;
case SCRIPT_COMMAND_TELEPORT_TO: // 6
{
if (!sMapStore.LookupEntry(tmp.teleportTo.mapId))
{
@ -271,7 +276,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_QUEST_EXPLORED:
case SCRIPT_COMMAND_QUEST_EXPLORED: // 7
{
Quest const* quest = sObjectMgr.GetQuestTemplate(tmp.questExplored.questId);
if (!quest)
@ -313,16 +318,16 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_KILL_CREDIT:
case SCRIPT_COMMAND_KILL_CREDIT: // 8
{
if (!ObjectMgr::GetCreatureTemplate(tmp.killCredit.creatureEntry))
if (tmp.killCredit.creatureEntry && !ObjectMgr::GetCreatureTemplate(tmp.killCredit.creatureEntry))
{
sLog.outErrorDb("Table `%s` has invalid creature (Entry: %u) in SCRIPT_COMMAND_KILL_CREDIT for script id %u", tablename, tmp.killCredit.creatureEntry, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT:
case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT: // 9
{
uint32 goEntry = 0;
@ -364,7 +369,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE:
case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE: // 10
{
if (!MaNGOS::IsValidMapCoord(tmp.x, tmp.y, tmp.z, tmp.o))
{
@ -379,8 +384,8 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_OPEN_DOOR:
case SCRIPT_COMMAND_CLOSE_DOOR:
case SCRIPT_COMMAND_OPEN_DOOR: // 11
case SCRIPT_COMMAND_CLOSE_DOOR: // 12
{
uint32 goEntry = 0;
@ -419,7 +424,9 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_REMOVE_AURA:
case SCRIPT_COMMAND_ACTIVATE_OBJECT: // 13
break;
case SCRIPT_COMMAND_REMOVE_AURA: // 14
{
if (!sSpellStore.LookupEntry(tmp.removeAura.spellId))
{
@ -429,7 +436,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_CAST_SPELL:
case SCRIPT_COMMAND_CAST_SPELL: // 15
{
if (!sSpellStore.LookupEntry(tmp.castSpell.spellId))
{
@ -439,7 +446,17 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_CREATE_ITEM:
case SCRIPT_COMMAND_PLAY_SOUND: // 16
{
if (!sSoundEntriesStore.LookupEntry(tmp.playSound.soundId))
{
sLog.outErrorDb("Table `%s` using nonexistent sound (id: %u) in SCRIPT_COMMAND_PLAY_SOUND for script id %u",
tablename, tmp.playSound.soundId, tmp.id);
continue;
}
break;
}
case SCRIPT_COMMAND_CREATE_ITEM: // 17
{
if (!ObjectMgr::GetItemPrototype(tmp.createItem.itemEntry))
{
@ -455,12 +472,12 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_DESPAWN_SELF:
case SCRIPT_COMMAND_DESPAWN_SELF: // 18
{
// for later, we might consider despawn by database guid, and define in datalong2 as option to despawn self.
break;
}
case SCRIPT_COMMAND_PLAY_MOVIE:
case SCRIPT_COMMAND_PLAY_MOVIE: // 19
{
if (!sMovieStore.LookupEntry(tmp.playMovie.movieId))
{
@ -470,7 +487,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_MOVEMENT:
case SCRIPT_COMMAND_MOVEMENT: // 20
{
if (tmp.movement.movementType >= MAX_DB_MOTION_TYPE)
{
@ -481,11 +498,9 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_SET_ACTIVEOBJECT:
{
case SCRIPT_COMMAND_SET_ACTIVEOBJECT: // 21
break;
}
case SCRIPT_COMMAND_SET_FACTION:
case SCRIPT_COMMAND_SET_FACTION: // 22
{
if (tmp.faction.factionId && !sFactionTemplateStore.LookupEntry(tmp.faction.factionId))
{
@ -495,7 +510,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL:
case SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL: // 23
{
if (tmp.data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
{
@ -516,7 +531,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL:
case SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL: // 24
{
if (tmp.data_flags & SCRIPT_FLAG_COMMAND_ADDITIONAL)
{
@ -537,15 +552,10 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
break;
}
case SCRIPT_COMMAND_SET_RUN:
{
case SCRIPT_COMMAND_SET_RUN: // 25
case SCRIPT_COMMAND_ATTACK_START: // 26
break;
}
case SCRIPT_COMMAND_ATTACK_START:
{
break;
}
case SCRIPT_COMMAND_GO_LOCK_STATE:
case SCRIPT_COMMAND_GO_LOCK_STATE: // 27
{
if (// lock(0x01) and unlock(0x02) together
((tmp.goLockState.lockState & 0x01) && (tmp.goLockState.lockState & 0x02)) ||
@ -561,7 +571,7 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_STAND_STATE:
case SCRIPT_COMMAND_STAND_STATE: // 28
{
if (tmp.standState.stand_state >= MAX_UNIT_STAND_STATE)
{
@ -570,11 +580,9 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS:
{
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS: // 29
break;
}
case SCRIPT_COMMAND_SEND_TAXI_PATH:
case SCRIPT_COMMAND_SEND_TAXI_PATH: // 30
{
if (!sTaxiPathStore.LookupEntry(tmp.sendTaxiPath.taxiPathId))
{
@ -606,6 +614,11 @@ void ScriptMgr::LoadScripts(ScriptMapMapName& scripts, const char* tablename)
}
break;
}
default:
{
sLog.outErrorDb("Table `%s` unknown command %u, skipping.", tablename, tmp.command);
continue;
}
}
if (scripts.second.find(tmp.id) == scripts.second.end())
@ -1013,7 +1026,7 @@ void ScriptAction::HandleScriptStep()
switch (m_script->command)
{
case SCRIPT_COMMAND_TALK:
case SCRIPT_COMMAND_TALK: // 0
{
if (!pSource)
{
@ -1072,11 +1085,11 @@ void ScriptAction::HandleScriptStep()
pSource->MonsterYellToZone(textId, m_script->talk.language, unitTarget);
break;
default:
break; // must be already checked at load
break; // must be already checked at load
}
break;
}
case SCRIPT_COMMAND_EMOTE:
case SCRIPT_COMMAND_EMOTE: // 1
{
if (LogIfNotUnit(pSource))
break;
@ -1084,7 +1097,7 @@ void ScriptAction::HandleScriptStep()
((Unit*)pSource)->HandleEmote(m_script->emote.emoteId);
break;
}
case SCRIPT_COMMAND_FIELD_SET:
case SCRIPT_COMMAND_FIELD_SET: // 2
// TODO
if (!source)
{
@ -1100,7 +1113,7 @@ void ScriptAction::HandleScriptStep()
source->SetUInt32Value(m_script->setField.fieldId, m_script->setField.fieldValue);
break;
case SCRIPT_COMMAND_MOVE_TO:
case SCRIPT_COMMAND_MOVE_TO: // 3
{
if (LogIfNotUnit(pSource))
break;
@ -1131,7 +1144,7 @@ void ScriptAction::HandleScriptStep()
}
break;
}
case SCRIPT_COMMAND_FLAG_SET:
case SCRIPT_COMMAND_FLAG_SET: // 4
// TODO
if (!source)
{
@ -1147,7 +1160,7 @@ void ScriptAction::HandleScriptStep()
source->SetFlag(m_script->setFlag.fieldId, m_script->setFlag.fieldValue);
break;
case SCRIPT_COMMAND_FLAG_REMOVE:
case SCRIPT_COMMAND_FLAG_REMOVE: // 5
// TODO
if (!source)
{
@ -1163,7 +1176,7 @@ void ScriptAction::HandleScriptStep()
source->RemoveFlag(m_script->removeFlag.fieldId, m_script->removeFlag.fieldValue);
break;
case SCRIPT_COMMAND_TELEPORT_TO:
case SCRIPT_COMMAND_TELEPORT_TO: // 6
{
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);
if (!pPlayer)
@ -1172,7 +1185,7 @@ void ScriptAction::HandleScriptStep()
pPlayer->TeleportTo(m_script->teleportTo.mapId, m_script->x, m_script->y, m_script->z, m_script->o);
break;
}
case SCRIPT_COMMAND_QUEST_EXPLORED:
case SCRIPT_COMMAND_QUEST_EXPLORED: // 7
{
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);
if (!pPlayer)
@ -1206,20 +1219,35 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_KILL_CREDIT:
case SCRIPT_COMMAND_KILL_CREDIT: // 8
{
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);
if (!pPlayer)
break;
uint32 creatureEntry = m_script->killCredit.creatureEntry;
WorldObject* pRewardSource = pSource && pSource->GetTypeId() == TYPEID_UNIT ? pSource : (pTarget && pTarget->GetTypeId() == TYPEID_UNIT ? pTarget : NULL);
// dynamic effect, take entry of reward Source
if (!creatureEntry)
{
if (pRewardSource)
creatureEntry = pRewardSource->GetEntry();
else
{
sLog.outError(" DB-SCRIPTS: Process table `%s` id %u, command %u called for dynamic killcredit without creature partner, skipping.", m_table, m_script->id, m_script->command);
break;
}
}
if (m_script->killCredit.isGroupCredit)
pPlayer->RewardPlayerAndGroupAtEvent(m_script->killCredit.creatureEntry, pSource);
pPlayer->RewardPlayerAndGroupAtEvent(creatureEntry, pRewardSource);
else
pPlayer->KilledMonsterCredit(m_script->killCredit.creatureEntry);
pPlayer->KilledMonsterCredit(creatureEntry, pRewardSource ? pRewardSource->GetObjectGuid() : ObjectGuid());
break;
}
case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT:
case SCRIPT_COMMAND_RESPAWN_GAMEOBJECT: // 9
{
GameObject* pGo = NULL;
uint32 time_to_despawn = m_script->respawnGo.despawnDelay < 5 ? 5 : m_script->respawnGo.despawnDelay;
@ -1257,14 +1285,14 @@ void ScriptAction::HandleScriptStep()
}
if (pGo->isSpawned())
break; //gameobject already spawned
break; //gameobject already spawned
pGo->SetLootState(GO_READY);
pGo->SetRespawnTime(time_to_despawn); //despawn object in ? seconds
pGo->SetRespawnTime(time_to_despawn); //despawn object in ? seconds
pGo->Refresh();
break;
}
case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE:
case SCRIPT_COMMAND_TEMP_SUMMON_CREATURE: // 10
{
if (!pSource)
{
@ -1286,8 +1314,8 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_OPEN_DOOR:
case SCRIPT_COMMAND_CLOSE_DOOR:
case SCRIPT_COMMAND_OPEN_DOOR: // 11
case SCRIPT_COMMAND_CLOSE_DOOR: // 12
{
GameObject* pDoor;
uint32 time_to_reset = m_script->changeDoor.resetDelay < 15 ? 15 : m_script->changeDoor.resetDelay;
@ -1323,7 +1351,7 @@ void ScriptAction::HandleScriptStep()
if (m_script->command == SCRIPT_COMMAND_OPEN_DOOR && pDoor->GetGoState() != GO_STATE_READY ||
m_script->command == SCRIPT_COMMAND_CLOSE_DOOR && pDoor->GetGoState() == GO_STATE_READY)
break; // to be opened door already open, or to be closed door already closed
break; // to be opened door already open, or to be closed door already closed
pDoor->UseDoorOrButton(time_to_reset);
@ -1332,7 +1360,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_ACTIVATE_OBJECT:
case SCRIPT_COMMAND_ACTIVATE_OBJECT: // 13
{
if (LogIfNotUnit(pSource))
break;
@ -1342,7 +1370,7 @@ void ScriptAction::HandleScriptStep()
((GameObject*)pTarget)->Use((Unit*)pSource);
break;
}
case SCRIPT_COMMAND_REMOVE_AURA:
case SCRIPT_COMMAND_REMOVE_AURA: // 14
{
if (LogIfNotUnit(pSource))
break;
@ -1350,7 +1378,7 @@ void ScriptAction::HandleScriptStep()
((Unit*)pSource)->RemoveAurasDueToSpell(m_script->removeAura.spellId);
break;
}
case SCRIPT_COMMAND_CAST_SPELL:
case SCRIPT_COMMAND_CAST_SPELL: // 15
{
if (LogIfNotUnit(pSource))
break;
@ -1362,7 +1390,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_PLAY_SOUND: // TODO
case SCRIPT_COMMAND_PLAY_SOUND: // 16 // TODO
{
if (!pSource)
{
@ -1398,7 +1426,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_CREATE_ITEM:
case SCRIPT_COMMAND_CREATE_ITEM: // 17
{
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);
if (!pPlayer)
@ -1409,7 +1437,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_DESPAWN_SELF:
case SCRIPT_COMMAND_DESPAWN_SELF: // 18
{
// TODO - Remove this check after a while
if (pTarget && pTarget->GetTypeId() != TYPEID_UNIT && pSource && pSource->GetTypeId() == TYPEID_UNIT)
@ -1425,7 +1453,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_PLAY_MOVIE:
case SCRIPT_COMMAND_PLAY_MOVIE: // 19
{
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);
if (!pPlayer)
@ -1435,7 +1463,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_MOVEMENT:
case SCRIPT_COMMAND_MOVEMENT: // 20
{
if (LogIfNotCreature(pSource))
break;
@ -1458,7 +1486,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_SET_ACTIVEOBJECT:
case SCRIPT_COMMAND_SET_ACTIVEOBJECT: // 21
{
if (LogIfNotCreature(pSource))
break;
@ -1466,7 +1494,7 @@ void ScriptAction::HandleScriptStep()
((Creature*)pSource)->SetActiveObjectState(m_script->activeObject.activate);
break;
}
case SCRIPT_COMMAND_SET_FACTION:
case SCRIPT_COMMAND_SET_FACTION: // 22
{
if (LogIfNotCreature(pSource))
break;
@ -1478,7 +1506,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL:
case SCRIPT_COMMAND_MORPH_TO_ENTRY_OR_MODEL: // 23
{
if (LogIfNotCreature(pSource))
break;
@ -1497,7 +1525,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL:
case SCRIPT_COMMAND_MOUNT_TO_ENTRY_OR_MODEL: // 24
{
if (LogIfNotCreature(pSource))
break;
@ -1516,7 +1544,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_SET_RUN:
case SCRIPT_COMMAND_SET_RUN: // 25
{
if (LogIfNotCreature(pSource))
break;
@ -1525,7 +1553,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_ATTACK_START:
case SCRIPT_COMMAND_ATTACK_START: // 26
{
if (LogIfNotCreature(pSource))
break;
@ -1545,7 +1573,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_GO_LOCK_STATE:
case SCRIPT_COMMAND_GO_LOCK_STATE: // 27
{
if (LogIfNotGameObject(pSource))
break;
@ -1570,7 +1598,7 @@ void ScriptAction::HandleScriptStep()
else if (m_script->goLockState.lockState & 0x08)
pGo->RemoveFlag(GAMEOBJECT_FLAGS, GO_FLAG_NO_INTERACT);
}
case SCRIPT_COMMAND_STAND_STATE:
case SCRIPT_COMMAND_STAND_STATE: // 28
{
if (LogIfNotCreature(pSource))
break;
@ -1579,7 +1607,7 @@ void ScriptAction::HandleScriptStep()
((Unit*)pSource)->SetStandState(m_script->standState.stand_state);
break;
}
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS:
case SCRIPT_COMMAND_MODIFY_NPC_FLAGS: // 29
{
if (LogIfNotCreature(pSource))
break;
@ -1601,7 +1629,7 @@ void ScriptAction::HandleScriptStep()
break;
}
case SCRIPT_COMMAND_SEND_TAXI_PATH:
case SCRIPT_COMMAND_SEND_TAXI_PATH: // 30
{
// only Player
Player* pPlayer = GetPlayerTargetOrSourceAndLog(pSource, pTarget);