Scripts: enhance SCRIPT_COMMAND_TALK command to make Players talk (add 0x1 bit to datalong2 and command will expect Player instead of Creature for talking).

--HG--
branch : trunk
This commit is contained in:
azazel
2010-09-16 13:28:16 +06:00
parent 236356628a
commit a034ac9937
3 changed files with 67 additions and 32 deletions

View File

@@ -2267,7 +2267,7 @@ void Creature::AllLootRemovedFromCorpse()
else
decayRate = 0.0f;
uint32 diff = (m_corpseRemoveTime - now) * decayRate;
uint32 diff = uint32((m_corpseRemoveTime - now) * decayRate);
m_corpseRemoveTime -= diff;
m_respawnTime -= diff;

View File

@@ -3030,40 +3030,75 @@ void Map::ScriptsProcess()
switch (step.script->command)
{
case SCRIPT_COMMAND_TALK:
// Source or target must be Creature.
if (Creature *cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
if (step.script->datalong > CHAT_TYPE_WHISPER)
{
if (step.script->datalong > CHAT_TYPE_WHISPER)
sLog.outError("%s invalid chat type (%u) specified, skipping.", step.script->GetDebugInfo().c_str(), step.script->datalong);
break;
}
if (step.script->datalong2 & 0x1)
{
if (Player *pSource = _GetScriptPlayerSourceOrTarget(source, target, step.script))
{
sLog.outError("%s invalid chat type (%u) specified, skipping.", step.script->GetDebugInfo().c_str(), step.script->datalong);
break;
}
uint64 targetGUID = target ? target->GetGUID() : 0;
int loc_idx = pSource->GetSession()->GetSessionDbLocaleIndex();
const std::string text(sObjectMgr.GetTrinityString(step.script->dataint, loc_idx));
uint64 targetGUID = target ? target->GetGUID() : 0;
switch (step.script->datalong)
{
case CHAT_TYPE_SAY:
cSource->Say(step.script->dataint, LANG_UNIVERSAL, targetGUID);
break;
case CHAT_TYPE_YELL:
cSource->Yell(step.script->dataint, LANG_UNIVERSAL, targetGUID);
break;
case CHAT_TYPE_TEXT_EMOTE:
cSource->TextEmote(step.script->dataint, targetGUID);
break;
case CHAT_TYPE_BOSS_EMOTE:
cSource->MonsterTextEmote(step.script->dataint, targetGUID, true);
break;
case CHAT_TYPE_WHISPER:
if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
{
sLog.outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
switch (step.script->datalong)
{
case CHAT_TYPE_SAY:
pSource->Say(text, LANG_UNIVERSAL);
break;
}
cSource->Whisper(step.script->dataint, targetGUID);
break;
default:
break; // must be already checked at load
case CHAT_TYPE_YELL:
pSource->Yell(text, LANG_UNIVERSAL);
break;
case CHAT_TYPE_TEXT_EMOTE:
case CHAT_TYPE_BOSS_EMOTE:
pSource->TextEmote(text);
break;
case CHAT_TYPE_WHISPER:
if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
{
sLog.outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
break;
}
pSource->Whisper(text, LANG_UNIVERSAL, targetGUID);
break;
default:
break; // must be already checked at load
}
}
}
else
{
// Source or target must be Creature.
if (Creature *cSource = _GetScriptCreatureSourceOrTarget(source, target, step.script))
{
uint64 targetGUID = target ? target->GetGUID() : 0;
switch (step.script->datalong)
{
case CHAT_TYPE_SAY:
cSource->Say(step.script->dataint, LANG_UNIVERSAL, targetGUID);
break;
case CHAT_TYPE_YELL:
cSource->Yell(step.script->dataint, LANG_UNIVERSAL, targetGUID);
break;
case CHAT_TYPE_TEXT_EMOTE:
cSource->TextEmote(step.script->dataint, targetGUID);
break;
case CHAT_TYPE_BOSS_EMOTE:
cSource->MonsterTextEmote(step.script->dataint, targetGUID, true);
break;
case CHAT_TYPE_WHISPER:
if (!targetGUID || !IS_PLAYER_GUID(targetGUID))
{
sLog.outError("%s attempt to whisper to non-player unit, skipping.", step.script->GetDebugInfo().c_str());
break;
}
cSource->Whisper(step.script->dataint, targetGUID);
break;
default:
break; // must be already checked at load
}
}
}
break;

View File

@@ -455,7 +455,7 @@ enum WorldStates
// DB scripting commands
enum ScriptCommands
{
SCRIPT_COMMAND_TALK = 0, // source/target = Creature, target = any, datalong = talk type (0=say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text), dataint = string_id
SCRIPT_COMMAND_TALK = 0, // source/target = Creature, target = any, datalong = talk type (0=say, 1=whisper, 2=yell, 3=emote text, 4=boss emote text), datalong2 & 1 = player talk (instead of creature), dataint = string_id
SCRIPT_COMMAND_EMOTE = 1, // source/target = Creature, datalong = emote id, datalong2 = 0: set emote state; > 0: play emote state
SCRIPT_COMMAND_FIELD_SET = 2, // source/target = Creature, datalong = field id, datalog2 = value
SCRIPT_COMMAND_MOVE_TO = 3, // source/target = Creature, datalong2 = time to reach, x/y/z = destination