Core/Instances: Implemented DungeonEncounter.dbc for creating completed encounters mask to use in packets

Core/Dungeon Finder: Implemented new way of giving random dungeon rewards, linked to DungeonEncounter.dbc
This commit is contained in:
Shauren
2011-02-03 22:20:40 +01:00
parent 7ea8bad07f
commit c2b0bcbd6c
33 changed files with 941 additions and 152 deletions

View File

@@ -24,14 +24,19 @@
#include "Creature.h"
#include "CreatureAI.h"
#include "Log.h"
#include "LFGMgr.h"
void InstanceScript::SaveToDB()
{
std::string data = GetSaveData();
if (data.empty())
return;
CharacterDatabase.escape_string(data);
CharacterDatabase.PExecute("UPDATE instance SET data = '%s' WHERE id = '%d'", data.c_str(), instance->GetInstanceId());
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPDATE_INSTANCE_DATA);
stmt->setUInt32(0, GetCompletedEncounterMask());
stmt->setString(1, data);
stmt->setUInt32(2, instance->GetInstanceId());
CharacterDatabase.Execute(stmt);
}
void InstanceScript::HandleGameObject(uint64 GUID, bool open, GameObject *go)
@@ -427,3 +432,29 @@ void InstanceScript::SendEncounterUnit(uint32 type, Unit* unit /*= NULL*/, uint8
instance->SendToPlayers(&data);
}
void InstanceScript::UpdateEncounterState(EncounterCreditType type, uint32 creditEntry, Unit* source)
{
DungeonEncounterList const* encounters = sObjectMgr->GetDungeonEncounterList(instance->GetId(), instance->GetDifficulty());
if (!encounters)
return;
for (DungeonEncounterList::const_iterator itr = encounters->begin(); itr != encounters->end(); ++itr)
{
if ((*itr)->creditType == type && (*itr)->creditEntry == creditEntry)
{
completedEncounters |= 1 << (*itr)->dbcEntry->encounterIndex;
sLog->outDebug("Instance %s (instanceId %u) completed encounter %s", instance->GetMapName(), instance->GetInstanceId(), (*itr)->dbcEntry->encounterName[0]);
if (uint32 dungeonId = (*itr)->lastEncounterDungeon)
{
Map::PlayerList const& players = instance->GetPlayers();
if (!players.isEmpty())
for (Map::PlayerList::const_iterator i = players.begin(); i != players.end(); ++i)
if (Player* player = i->getSource())
if (!source || player->IsAtGroupRewardDistance(source))
sLFGMgr->RewardDungeonDoneFor(dungeonId, player);
}
return;
}
}
}