void WorldSession::HandleTextEmoteOpcode( WorldPacket & recv_data ) { CHECK_PACKET_SIZE(recv_data, 16); if(!_player->IsInWorld() || !_player->isAlive()) return; uint64 guid; uint32 text_emote, unk, namelen =1; const char* name =" "; recv_data >> text_emote; recv_data >> unk; recv_data >> guid; Unit * pUnit = _player->GetMapMgr()->GetUnit(guid); if(pUnit) { if(pUnit->IsPlayer()) { name = static_cast< Player* >( pUnit )->GetName(); namelen = (uint32)strlen(name) + 1; } else if(pUnit->GetTypeId() == TYPEID_UNIT) { Creature * p = static_cast<Creature*>(pUnit); if(p->GetCreatureName()) { name = p->GetCreatureName()->Name; namelen = (uint32)strlen(name) + 1; } else { name = 0; namelen = 0; } } } emoteentry *em = dbcEmoteEntry.LookupEntry(text_emote); if(em) { WorldPacket data(SMSG_EMOTE, 28 + namelen); sHookInterface.OnEmote(_player, (EmoteType)em->textid); if(pUnit) CALL_SCRIPT_EVENT(pUnit,OnEmote)(_player,(EmoteType)em->textid); switch(em->textid) { case EMOTE_STATE_SLEEP: case EMOTE_STATE_SIT: case EMOTE_STATE_KNEEL: case EMOTE_STATE_DANCE: { _player->SetUInt32Value(UNIT_NPC_EMOTESTATE, em->textid); }break; } data << (uint32)em->textid; data << (uint64)GetPlayer()->GetGUID(); GetPlayer()->SendMessageToSet(&data, true); //If player receives his own emote, his animation stops. data.Initialize(SMSG_TEXT_EMOTE); data << (uint64)GetPlayer()->GetGUID(); data << (uint32)text_emote; data << unk; data << (uint32)namelen; if( namelen > 1 ) data.append(name, namelen); else data << (uint8)0x00; GetPlayer()->SendMessageToSet(&data, true); } }
void WorldSession::HandleTextEmoteOpcode(WorldPacket & recv_data) { CHECK_INWORLD_RETURN CHECK_PACKET_SIZE(recv_data, 16); if(!_player->isAlive()) return; uint64 guid; uint32 text_emote, unk, namelen = 1; const char* name = " "; recv_data >> text_emote; recv_data >> unk; recv_data >> guid; if(m_muted && m_muted >= (uint32)UNIXTIME) { SystemMessage("Your voice is currently muted by a moderator."); return; } if(!GetPermissionCount() && sWorld.flood_lines) { /* flood detection, wheeee! */ if(UNIXTIME >= floodTime) { floodLines = 0; floodTime = UNIXTIME + sWorld.flood_seconds; } if((++floodLines) > sWorld.flood_lines) { return; } } Unit* pUnit = _player->GetMapMgr()->GetUnit(guid); if(pUnit) { if(pUnit->IsPlayer()) { name = TO< Player* >(pUnit)->GetName(); namelen = (uint32)strlen(name) + 1; } else if(pUnit->IsPet()) { name = TO< Pet* >(pUnit)->GetName().c_str(); namelen = (uint32)strlen(name) + 1; } else { Creature* p = TO< Creature* >(pUnit); name = p->GetCreatureInfo()->Name; namelen = (uint32)strlen(name) + 1; } } emoteentry* em = dbcEmoteEntry.LookupEntryForced(text_emote); if(em) { WorldPacket data(SMSG_EMOTE, 28 + namelen); sHookInterface.OnEmote(_player, (EmoteType)em->textid, pUnit); if(pUnit) CALL_SCRIPT_EVENT(pUnit, OnEmote)(_player, (EmoteType)em->textid); switch(em->textid) { case EMOTE_STATE_SLEEP: case EMOTE_STATE_SIT: case EMOTE_STATE_KNEEL: case EMOTE_STATE_DANCE: { _player->SetEmoteState(em->textid); } break; } data << (uint32)em->textid; data << (uint64)GetPlayer()->GetGUID(); GetPlayer()->SendMessageToSet(&data, true); //If player receives his own emote, his animation stops. data.Initialize(SMSG_TEXT_EMOTE); data << (uint64)GetPlayer()->GetGUID(); data << (uint32)text_emote; data << unk; data << (uint32)namelen; if(namelen > 1) data.append(name, namelen); else data << (uint8)0x00; GetPlayer()->SendMessageToSet(&data, true); #ifdef ENABLE_ACHIEVEMENTS _player->GetAchievementMgr().UpdateAchievementCriteria(ACHIEVEMENT_CRITERIA_TYPE_DO_EMOTE, text_emote, 0, 0); #endif sQuestMgr.OnPlayerEmote(_player, text_emote, guid); } }
void GameEventMgr::ScriptedBackToOrig(uint32 event_id) { GameEventScriptMap::iterator event_backup = m_GameEventScriptBackup.find(event_id); if( event_backup == m_GameEventScriptBackup.end() ) return; set<EventScript*>::iterator itr = event_backup->second.begin(); for( itr; itr != event_backup->second.end(); itr++ ) { uint32 mapid = (*itr)->mapid; uint32 sql_id = (*itr)->sql_id; uint8 type = (*itr)->type; uint32 data1 = (*itr)->data_1; uint32 data2 = (*itr)->data_2; uint32 data3 = (*itr)->data_3; MapMgr * mapmgr = sInstanceMgr.GetMapMgr( mapid ); if( mapmgr == NULL ) return; Creature *c; GameObject *go; if(type < GAMEOBJECT_CHANGE_STATE) { c = mapmgr->GetSqlIdCreature( sql_id ); if( c == NULL ) return; } else { go = mapmgr->GetSqlIdGameObject( sql_id ); if( go == NULL ) return; } switch( type ) { case CREATURE_CHANGE_SCRIPTED_CHANGE: { CALL_SCRIPT_EVENT(c, GameEventFinish)(event_id); } break; case CREATURE_CHANGE_EMOTE: { c->Emote(EmoteType(data1)); c->SetEmoteState(data2); c->SetStandState(static_cast<uint8>(data3)); } break; case CREATURE_CHANGE_DISPLAYID: { c->SetDisplayId(data1); c->SetNativeDisplayId(data2); c->SetMount(data3); c->EventModelChange(); } break; case CREATURE_CHANGE_WEAPON: { c->SetEquippedItem(MELEE, data1); c->SetEquippedItem(OFFHAND, data2); c->SetEquippedItem(RANGED, data3); } break; case CREATURE_CHANGE_REACT: { c->SetFaction(data1); c->SetUInt32Value(UNIT_NPC_FLAGS, data2); c->SetUInt32Value(UNIT_FIELD_FLAGS, data3); } break; case CREATURE_CAST_SPELL_ON_EVENT_STOP: { SpellEntry * sp = dbcSpell.LookupEntryForced( data1 ); if( sp == NULL ) return; SpellCastTime * casttime = dbcSpellCastTime.LookupEntry(sp->CastingTimeIndex); Spell * spell = sSpellFactoryMgr.NewSpell(c, sp, false, NULL); SpellCastTargets t(0); // force self casting if( data2 ) { t.m_unitTarget = c->GetGUID(); } else { spell->GenerateTargets(&t); spell->m_targets = t; } if (objmgr.IsSpellDisabled(spell->GetProto()->Id) || spell->CanCast(false) != SPELL_CANCAST_OK || !spell->HasPower() || c->m_silenced || c->IsStunned() || c->IsFeared() ) { delete spell; return; } if( casttime->CastTime > 0 ) c->GetAIInterface()->StopMovement(casttime->CastTime); spell->prepare(&t); } break; case CREATURE_CHANGE_UPDATE_FIELD: { c->SetUInt32Value(data1, data2); } break; case GAMEOBJECT_CHANGE_STATE: { go->SetState((uint8)data1); } break; } } m_GameEventScriptBackup.erase(event_id); }
void WorldSession::HandleAutostoreLootItemOpcode( WorldPacket & recv_data ) { if(!_player->IsInWorld()) return; // uint8 slot = 0; uint32 itemid = 0; uint32 amt = 1; uint8 lootSlot = 0; uint8 error = 0; SlotResult slotresult; Item *add; Loot *pLoot = NULL; if(_player->isCasting()) _player->InterruptSpell(); GameObject * pGO = NULL; Creature * pCreature = NULL; if(UINT32_LOPART(GUID_HIPART(GetPlayer()->GetLootGUID())) == HIGHGUID_UNIT) { pCreature = _player->GetMapMgr()->GetCreature((uint32)GetPlayer()->GetLootGUID()); if (!pCreature)return; pLoot=&pCreature->loot; } else if(UINT32_LOPART(GUID_HIPART(_player->GetLootGUID())) == HIGHGUID_GAMEOBJECT) { pGO = _player->GetMapMgr()->GetGameObject((uint32)GetPlayer()->GetLootGUID()); if(!pGO)return; pLoot=&pGO->loot; }else if( (UINT32_LOPART(GUID_HIPART(_player->GetLootGUID())) == HIGHGUID_ITEM) ) { Item *pItem = _player->GetItemInterface()->GetItemByGUID(_player->GetLootGUID()); if(!pItem) return; pLoot = pItem->loot; } if(!pLoot) return; recv_data >> lootSlot; if (lootSlot >= pLoot->items.size()) { sLog.outDebug("AutoLootItem: Player %s might be using a hack! (slot %d, size %d)", GetPlayer()->GetName(), lootSlot, pLoot->items.size()); return; } amt = pLoot->items.at(lootSlot).iItemsCount; if (!amt)//Test for party loot { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL,INV_ERR_ALREADY_LOOTED); return; } itemid = pLoot->items.at(lootSlot).item.itemid; ItemPrototype* it = ItemPrototypeStorage.LookupEntry(itemid); if((error = _player->GetItemInterface()->CanReceiveItem(it, 1))) { _player->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, error); return; } if(pGO) CALL_GO_SCRIPT_EVENT(pGO, OnLootTaken)(_player, it); else if(pCreature) CALL_SCRIPT_EVENT(pCreature, OnLootTaken)(_player, it); add = GetPlayer()->GetItemInterface()->FindItemLessMax(itemid, amt, false); sHookInterface.OnLoot(_player, pCreature, 0, itemid); if (!add) { slotresult = GetPlayer()->GetItemInterface()->FindFreeInventorySlot(it); if(!slotresult.Result) { GetPlayer()->GetItemInterface()->BuildInventoryChangeError(NULL, NULL, INV_ERR_INVENTORY_FULL); return; } sLog.outDebug("AutoLootItem MISC"); Item *item = objmgr.CreateItem( itemid, GetPlayer()); item->SetUInt32Value(ITEM_FIELD_STACK_COUNT,amt); uint32 rndprop=pLoot->items.at(lootSlot).iRandomProperty; if(rndprop) item->SetUInt32Value(ITEM_FIELD_RANDOM_PROPERTIES_ID,rndprop); item->ApplyRandomProperties(); GetPlayer()->GetItemInterface()->SafeAddItem(item,slotresult.ContainerSlot, slotresult.Slot); if (it->Class == 12) // Quest item sQuestMgr.OnPlayerItemPickup(GetPlayer(),item); } else { add->SetCount(add->GetUInt32Value(ITEM_FIELD_STACK_COUNT) + amt); add->m_isDirty = true; if (it->Class == 12) // Quest item sQuestMgr.OnPlayerItemPickup(GetPlayer(),add); } pLoot->items.at(lootSlot).iItemsCount=0; // this gets sent to all looters WorldPacket data(1); data.SetOpcode(SMSG_LOOT_REMOVED); data << lootSlot; Player * plr; for(LooterSet::iterator itr = pLoot->looters.begin(); itr != pLoot->looters.end(); ++itr) { if((plr = _player->GetMapMgr()->GetPlayer(*itr))) plr->GetSession()->SendPacket(&data); } WorldPacket idata; if(it->Class == ITEM_CLASS_QUEST) { uint32 pcount = _player->GetItemInterface()->GetItemCount(it->ItemId, true); BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(lootSlot).iRandomProperty,0xFF,0,0xFFFFFFFF,pcount); } else BuildItemPushResult(&idata, _player->GetGUID(), ITEM_PUSH_TYPE_LOOT, amt, itemid, pLoot->items.at(lootSlot).iRandomProperty); if(_player->InGroup()) _player->GetGroup()->SendPacketToAll(&idata); else SendPacket(&idata); }
void GameEventMgr::DoScript(uint32 event_id, uint32 sql_id, uint8 type, uint32 data1, uint32 data2, uint32 data3, char * say, uint32 mapid) { MapMgr * mapmgr = sInstanceMgr.GetMapMgr( mapid ); if( mapmgr == NULL ) return; Creature *c; GameObject *go; if(type < GAMEOBJECT_CHANGE_STATE) { c = mapmgr->GetSqlIdCreature( sql_id ); if( c == NULL ) return; } else { go = mapmgr->GetSqlIdGameObject( sql_id ); if( go == NULL ) return; } // create backup for original values EventScript * es = new EventScript(); es->sql_id = sql_id; es->mapid = mapid; es->type = type; es->data_1 = 0; // null them out first! es->data_2 = 0; es->data_3 = 0; if( c && strlen(say) ) { c->SendChatMessage(CHAT_MSG_MONSTER_SAY, LANG_UNIVERSAL, say); } switch( type ) { case CREATURE_CHANGE_SCRIPTED_CHANGE: { CALL_SCRIPT_EVENT(c, GameEventStart)(event_id); } break; case CREATURE_CHANGE_EMOTE: { // do not backup one-shoot emote c->Emote(EmoteType(data1)); // backup emote state first es->data_2 = c->GetEmoteState(); c->SetEmoteState(data2); // backup stand state es->data_3 = static_cast<uint32>(c->GetStandState()); c->SetStandState(static_cast<uint8>(data3)); } break; case CREATURE_CHANGE_DISPLAYID: { es->data_1 = c->GetDisplayId(); c->SetDisplayId(data1); es->data_2 = c->GetNativeDisplayId(); c->SetNativeDisplayId(data2); es->data_3 = c->GetMount(); c->SetMount(data3); c->EventModelChange(); } break; case CREATURE_CHANGE_WEAPON: { es->data_1 = c->GetEquippedItem(MELEE); es->data_2 = c->GetEquippedItem(OFFHAND); es->data_3 = c->GetEquippedItem(RANGED); c->SetEquippedItem(MELEE, data1); c->SetEquippedItem(OFFHAND, data2); c->SetEquippedItem(RANGED, data3); } break; case CREATURE_CHANGE_REACT: { es->data_1 = c->GetFaction(); c->SetFaction(data1); es->data_2 = c->GetUInt32Value(UNIT_NPC_FLAGS); c->SetUInt32Value(UNIT_NPC_FLAGS, data2); es->data_3 = c->GetUInt32Value(UNIT_FIELD_FLAGS); c->SetUInt32Value(UNIT_FIELD_FLAGS, data3); } break; case CREATURE_CAST_SPELL_ON_EVENT_START: { SpellEntry * sp = dbcSpell.LookupEntryForced( data1 ); if( sp == NULL ) return; SpellCastTime * casttime = dbcSpellCastTime.LookupEntry(sp->CastingTimeIndex); Spell * spell = sSpellFactoryMgr.NewSpell(c, sp, false, NULL); SpellCastTargets t(0); // force self casting if( data2 ) { t.m_unitTarget = c->GetGUID(); } else { spell->GenerateTargets(&t); spell->m_targets = t; } if (objmgr.IsSpellDisabled(spell->GetProto()->Id) || spell->CanCast(false) != SPELL_CANCAST_OK || !spell->HasPower() || c->m_silenced || c->IsStunned() || c->IsFeared() ) { delete spell; return; } if( casttime->CastTime > 0 ) c->GetAIInterface()->StopMovement(casttime->CastTime); spell->prepare(&t); } break; case CREATURE_CAST_SPELL_ON_EVENT_STOP: { // this time just backup it, we will procez it on event end es->data_1 = data1; es->data_2 = data2; } break; case CREATURE_CHANGE_UPDATE_FIELD: { es->data_1 = data1; es->data_2 = c->GetUInt32Value(data1); c->SetUInt32Value(data1, data2); } break; case CREATURE_CHANGE_DESPAWN: { GameEventMap::iterator itr = CheckAndReturnEvent( event_id ); if( itr == m_GameEventMap.end() ) return; uint32 current_time = mktime(&g_localTime); // this is calculated in seconds and added 1 extra second as timer for spawn and despawn uint32 respawntime = itr->second->end_time - current_time + 1; // values here are in miliseconds c->Despawn(0, respawntime*1000); delete es; return; } break; case GAMEOBJECT_CHANGE_STATE: { es->data_1 = (uint32)go->GetState(); go->SetState((uint8)data1); } break; } // insert event into storage GameEventScriptMap::iterator itr = m_GameEventScriptBackup.find(event_id); if( itr == m_GameEventScriptBackup.end() ) { set< EventScript* > s; s.insert( es ); m_GameEventScriptBackup.insert(make_pair(event_id, s)); } else { itr->second.insert( es ); } }