[7518] Implement new script command SCRIPT_COMMAND_PLAY_SOUND (look in World.h for args)

* Also rewrite use SMSG_PLAY_OBJECT_SOUND/SMSG_PLAY_SOUND
  Now WorldObject have 2 function for sound level dependent from distance (PlayDistanceSound)
  and for not depednet (PlayDirectSound)
* Old Player::PlaySound function removed and uses need to be updated to WorldObject functions
  Note: function called for _source_ of sound in different from old function.
* chat command .debug ps removed and .debug playsound can used for bother packects test:
  if no selection used SMSG_PLAY_SOUND, if selection exist including self then SMSG_PLAY_OBJECT_SOUND.
This commit is contained in:
VladimirMangos 2009-03-22 20:02:45 +03:00
parent b14bf188c5
commit ab2bdc3e69
13 changed files with 100 additions and 50 deletions

Binary file not shown.

View file

@ -118,7 +118,6 @@ ChatCommand * ChatHandler::getCommandTable()
{ "sendopcode", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendOpcodeCommand, "", NULL }, { "sendopcode", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendOpcodeCommand, "", NULL },
{ "spawnvehicle", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSpawnVehicle, "", NULL }, { "spawnvehicle", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSpawnVehicle, "", NULL },
{ "uws", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugUpdateWorldStateCommand, "", NULL }, { "uws", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugUpdateWorldStateCommand, "", NULL },
{ "ps", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugPlaySound2Command, "", NULL },
{ "scn", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendChannelNotifyCommand, "", NULL }, { "scn", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendChannelNotifyCommand, "", NULL },
{ "scm", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendChatMsgCommand, "", NULL }, { "scm", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendChatMsgCommand, "", NULL },
{ "sps", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendSetPhaseShiftCommand, "", NULL }, { "sps", SEC_ADMINISTRATOR, false, &ChatHandler::HandleDebugSendSetPhaseShiftCommand, "", NULL },

View file

@ -417,7 +417,6 @@ class ChatHandler
bool HandleDebugSellErrorCommand(const char* args); bool HandleDebugSellErrorCommand(const char* args);
bool HandleDebugBuyErrorCommand(const char* args); bool HandleDebugBuyErrorCommand(const char* args);
bool HandleDebugUpdateWorldStateCommand(const char* args); bool HandleDebugUpdateWorldStateCommand(const char* args);
bool HandleDebugPlaySound2Command(const char* args);
bool HandleDebugSendChannelNotifyCommand(const char* args); bool HandleDebugSendChannelNotifyCommand(const char* args);
bool HandleDebugSendChatMsgCommand(const char* args); bool HandleDebugSendChatMsgCommand(const char* args);
bool HandleRenameCommand(const char * args); bool HandleRenameCommand(const char * args);

View file

@ -1971,35 +1971,6 @@ bool ChatHandler::HandleWhispersCommand(const char* args)
return false; return false;
} }
//Play sound
bool ChatHandler::HandleDebugPlaySoundCommand(const char* args)
{
// USAGE: .debug playsound #soundid
// #soundid - ID decimal number from SoundEntries.dbc (1st column)
// this file have about 5000 sounds.
// In this realization only caller can hear this sound.
if( *args )
{
uint32 dwSoundId = atoi((char*)args);
if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
{
PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
SetSentErrorMessage(true);
return false;
}
WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
m_session->SendPacket(&data);
PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
return true;
}
return false;
}
//Save all players in the world //Save all players in the world
bool ChatHandler::HandleSaveAllCommand(const char* /*args*/) bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
{ {

View file

@ -1688,3 +1688,24 @@ void WorldObject::SetPhaseMask(uint32 newPhaseMask, bool update)
if(update && IsInWorld()) if(update && IsInWorld())
ObjectAccessor::UpdateObjectVisibility(this); ObjectAccessor::UpdateObjectVisibility(this);
} }
void WorldObject::PlayDistanceSound( uint32 sound_id, Player* target /*= NULL*/ )
{
WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
data << uint32(sound_id);
data << GetGUID();
if (target)
target->SendDirectMessage( &data );
else
SendMessageToSet( &data, true );
}
void WorldObject::PlayDirectSound( uint32 sound_id, Player* target /*= NULL*/ )
{
WorldPacket data(SMSG_PLAY_SOUND, 4);
data << uint32(sound_id);
if (target)
target->SendDirectMessage( &data );
else
SendMessageToSet( &data, true );
}

View file

@ -458,6 +458,9 @@ class MANGOS_DLL_SPEC WorldObject : public Object
void MonsterWhisper(int32 textId, uint64 receiver, bool IsBossWhisper = false); void MonsterWhisper(int32 textId, uint64 receiver, bool IsBossWhisper = false);
void BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, uint64 TargetGuid) const; void BuildMonsterChat(WorldPacket *data, uint8 msgtype, char const* text, uint32 language, char const* name, uint64 TargetGuid) const;
void PlayDistanceSound(uint32 sound_id, Player* target = NULL);
void PlayDirectSound(uint32 sound_id, Player* target = NULL);
void SendObjectDeSpawnAnim(uint64 guid); void SendObjectDeSpawnAnim(uint64 guid);
virtual void SaveRespawnTime() {} virtual void SaveRespawnTime() {}

View file

@ -16363,16 +16363,6 @@ void Player::SendAutoRepeatCancel()
GetSession()->SendPacket( &data ); GetSession()->SendPacket( &data );
} }
void Player::PlaySound(uint32 Sound, bool OnlySelf)
{
WorldPacket data(SMSG_PLAY_SOUND, 4);
data << Sound;
if (OnlySelf)
GetSession()->SendPacket( &data );
else
SendMessageToSet( &data, true );
}
void Player::SendExplorationExperience(uint32 Area, uint32 Experience) void Player::SendExplorationExperience(uint32 Area, uint32 Experience)
{ {
WorldPacket data( SMSG_EXPLORATION_EXPERIENCE, 8 ); WorldPacket data( SMSG_EXPLORATION_EXPERIENCE, 8 );

View file

@ -1603,8 +1603,6 @@ class MANGOS_DLL_SPEC Player : public Unit
void SendDelayResponse(const uint32); void SendDelayResponse(const uint32);
void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP); void SendLogXPGain(uint32 GivenXP,Unit* victim,uint32 RestXP);
//Low Level Packets
void PlaySound(uint32 Sound, bool OnlySelf);
//notifiers //notifiers
void SendAttackSwingCantAttack(); void SendAttackSwingCantAttack();
void SendAttackSwingCancelAttack(); void SendAttackSwingCancelAttack();

View file

@ -2046,8 +2046,7 @@ void Aura::HandleAuraDummy(bool apply, bool Real)
m_target->CastSpell(m_target, 51581, true, NULL, this); m_target->CastSpell(m_target, 51581, true, NULL, this);
return; return;
case 43873: // Headless Horseman Laugh case 43873: // Headless Horseman Laugh
if(caster->GetTypeId() == TYPEID_PLAYER) m_target->PlayDistanceSound(11965);
((Player*)caster)->PlaySound(11965, false);
return; return;
case 46354: // Blood Elf Illusion case 46354: // Blood Elf Illusion
if(caster) if(caster)

View file

@ -2237,6 +2237,47 @@ void World::ScriptsProcess()
break; break;
} }
case SCRIPT_COMMAND_PLAY_SOUND:
{
if(!source)
{
sLog.outError("SCRIPT_COMMAND_PLAY_SOUND call for NULL creature.");
break;
}
WorldObject* pSource = dynamic_cast<WorldObject*>(source);
if(!pSource)
{
sLog.outError("SCRIPT_COMMAND_PLAY_SOUND call for non-world object (TypeId: %u), skipping.",source->GetTypeId());
break;
}
// bitmask: 0/1=anyone/target, 0/2=with distance dependent
Player* pTarget = NULL;
if(step.script->datalong2 & 1)
{
if(!target)
{
sLog.outError("SCRIPT_COMMAND_PLAY_SOUND in targeted mode call for NULL target.");
break;
}
if(target->GetTypeId()!=TYPEID_PLAYER)
{
sLog.outError("SCRIPT_COMMAND_PLAY_SOUND in targeted mode call for non-player (TypeId: %u), skipping.",target->GetTypeId());
break;
}
pTarget = (Player*)target;
}
// bitmask: 0/1=anyone/target, 0/2=with distance dependent
if(step.script->datalong2 & 2)
pSource->PlayDistanceSound(step.script->datalong,pTarget);
else
pSource->PlayDirectSound(step.script->datalong,pTarget);
break;
}
default: default:
sLog.outError("Unknown script command %u called.",step.script->command); sLog.outError("Unknown script command %u called.",step.script->command);
break; break;

View file

@ -322,6 +322,7 @@ enum RealmZone
#define SCRIPT_COMMAND_ACTIVATE_OBJECT 13 // source = unit, target=GO #define SCRIPT_COMMAND_ACTIVATE_OBJECT 13 // source = unit, target=GO
#define SCRIPT_COMMAND_REMOVE_AURA 14 // source (datalong2!=0) or target (datalong==0) unit, datalong = spell_id #define SCRIPT_COMMAND_REMOVE_AURA 14 // source (datalong2!=0) or target (datalong==0) unit, datalong = spell_id
#define SCRIPT_COMMAND_CAST_SPELL 15 // source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s #define SCRIPT_COMMAND_CAST_SPELL 15 // source/target cast spell at target/source (script->datalong2: 0: s->t 1: s->s 2: t->t 3: t->s
#define SCRIPT_COMMAND_PLAY_SOUND 16 // source = any object, target=any/player, datalong (sound_id), datalong2 (bitmask: 0/1=anyone/target, 0/2=with distance dependent, so 1|2 = 3 is target with distance dependent)
/// Storage class for commands issued for delayed execution /// Storage class for commands issued for delayed execution
struct CliCommandHolder struct CliCommandHolder

View file

@ -213,13 +213,41 @@ bool ChatHandler::HandleDebugUpdateWorldStateCommand(const char* args)
return true; return true;
} }
bool ChatHandler::HandleDebugPlaySound2Command(const char* args) //Play sound
bool ChatHandler::HandleDebugPlaySoundCommand(const char* args)
{ {
if(!args) // USAGE: .debug playsound #soundid
// #soundid - ID decimal number from SoundEntries.dbc (1st column)
if( !*args )
{
SendSysMessage(LANG_BAD_VALUE);
SetSentErrorMessage(true);
return false; return false;
}
uint32 soundid = atoi(args); uint32 dwSoundId = atoi((char*)args);
m_session->GetPlayer()->PlaySound(soundid, false);
if(!sSoundEntriesStore.LookupEntry(dwSoundId))
{
PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
SetSentErrorMessage(true);
return false;
}
Unit* unit = getSelectedUnit();
if(!unit)
{
SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
SetSentErrorMessage(true);
return false;
}
if(m_session->GetPlayer()->GetSelection())
unit->PlayDistanceSound(dwSoundId,m_session->GetPlayer());
else
unit->PlayDirectSound(dwSoundId,m_session->GetPlayer());
PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
return true; return true;
} }

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 "7517" #define REVISION_NR "7518"
#endif // __REVISION_NR_H__ #endif // __REVISION_NR_H__