Added AchievementMgr

This commit is contained in:
arrai 2008-10-27 13:43:44 +01:00
parent 002a2fc5fc
commit 5d2f3291c0
5 changed files with 124 additions and 0 deletions

View file

@ -0,0 +1,72 @@
/*
* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "AchievementMgr.h"
#include "Common.h"
#include "Player.h"
#include "WorldPacket.h"
AchievementMgr::AchievementMgr(Player *player)
{
m_player = player;
}
void AchievementMgr::SaveToDB()
{
// TODO store achievements
}
void AchievementMgr::LoadFromDB()
{
// TODO load achievements
}
void AchievementMgr::SendAchievementEarned(uint32 achievementId)
{
WorldPacket data(SMSG_MESSAGECHAT, 200);
data << uint8(CHAT_MSG_ACHIEVEMENT);
data << uint32(LANG_UNIVERSAL);
data << uint64(GetPlayer()->GetGUID());
data << uint32(0);
data << uint64(GetPlayer()->GetGUID());
const char *msg = "|Hplayer:$N|h[$N]|h has earned the achievement $a!";
data << uint32(strlen(msg));
data << msg;
data << uint8(0);
data << uint32(achievementId);
GetPlayer()->SendMessageToSet(&data, true);
data.Initialize(SMSG_ACHIEVEMENT_EARNED, 8+4+8);
data.append(GetPlayer()->GetPackGUID());
data << uint32(achievementId);
data << uint64(0x0000000); // magic number? same as in SMSG_CRITERIA_UPDATE. static for every player?
GetPlayer()->SendMessageToSet(&data, true);
}
void AchievementMgr::SendCriteriaUpdate(uint32 criteriaId, uint32 counter)
{
WorldPacket data(SMSG_CRITERIA_UPDATE, 8+4+8);
data << uint32(criteriaId);
data << uint8(counter);
data << uint8(counter);// 2 times?
data.append(GetPlayer()->GetPackGUID());
data << uint64(0x0000000); // unknown, same as in SMSG_EARNED_ACHIEVEMENT, static for every player?
data << uint32(0); // unknown, 0
GetPlayer()->SendMessageToSet(&data, true);
}

40
src/game/AchievementMgr.h Normal file
View file

@ -0,0 +1,40 @@
/*
* Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __MANGOS_ACHIEVEMENTMGR_H
#define __MANGOS_ACHIEVEMENTMGR_H
#include "Player.h"
class AchievementMgr
{
public:
AchievementMgr(Player* pl);
void LoadFromDB();
void SaveToDB();
void SendAchievementEarned(uint32 achievementId);
void SendCriteriaUpdate(uint32 criteriaId, uint32 counter);
Player* GetPlayer() { return m_player;}
private:
Player* m_player;
};
#endif

View file

@ -30,6 +30,8 @@ noinst_LIBRARIES = libmangosgame.a
libmangosgame_a_SOURCES = \ libmangosgame_a_SOURCES = \
AccountMgr.cpp \ AccountMgr.cpp \
AccountMgr.h \ AccountMgr.h \
AchievementMgr.h \
AchievementMgr.cpp \
AddonHandler.cpp \ AddonHandler.cpp \
AddonHandler.h \ AddonHandler.h \
AggressorAI.cpp \ AggressorAI.cpp \

View file

@ -58,6 +58,7 @@
#include "Database/DatabaseImpl.h" #include "Database/DatabaseImpl.h"
#include "Spell.h" #include "Spell.h"
#include "SocialMgr.h" #include "SocialMgr.h"
#include "AchievementMgr.h"
#include <cmath> #include <cmath>
@ -420,6 +421,7 @@ Player::Player (WorldSession *session): Unit()
m_contestedPvPTimer = 0; m_contestedPvPTimer = 0;
m_declinedname = NULL; m_declinedname = NULL;
m_achievementMgr = NULL;
} }
Player::~Player () Player::~Player ()
@ -466,6 +468,7 @@ Player::~Player ()
itr->second.save->RemovePlayer(this); itr->second.save->RemovePlayer(this);
delete m_declinedname; delete m_declinedname;
delete m_achievementMgr;
} }
void Player::CleanupsBeforeDelete() void Player::CleanupsBeforeDelete()
@ -13971,6 +13974,9 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
m_social = sSocialMgr.LoadFromDB(holder->GetResult(PLAYER_LOGIN_QUERY_LOADSOCIALLIST), GetGUIDLow()); m_social = sSocialMgr.LoadFromDB(holder->GetResult(PLAYER_LOGIN_QUERY_LOADSOCIALLIST), GetGUIDLow());
m_achievementMgr = new AchievementMgr(this);
m_achievementMgr->LoadFromDB();
if(!_LoadHomeBind(holder->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND))) if(!_LoadHomeBind(holder->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND)))
return false; return false;
@ -15190,6 +15196,7 @@ void Player::SaveToDB()
// save pet (hunter pet level and experience and all type pets health/mana). // save pet (hunter pet level and experience and all type pets health/mana).
if(Pet* pet = GetPet()) if(Pet* pet = GetPet())
pet->SavePetToDB(PET_SAVE_AS_CURRENT); pet->SavePetToDB(PET_SAVE_AS_CURRENT);
m_achievementMgr->SaveToDB();
} }
// fast save function for item/money cheating preventing - save only inventory and money state // fast save function for item/money cheating preventing - save only inventory and money state

View file

@ -45,6 +45,7 @@ class PlayerMenu;
class Transport; class Transport;
class UpdateMask; class UpdateMask;
class PlayerSocial; class PlayerSocial;
class AchievementMgr;
typedef std::deque<Mail*> PlayerMails; typedef std::deque<Mail*> PlayerMails;
@ -2054,6 +2055,7 @@ class MANGOS_DLL_SPEC Player : public Unit
DeclinedName const* GetDeclinedNames() const { return m_declinedname; } DeclinedName const* GetDeclinedNames() const { return m_declinedname; }
AchievementMgr *GetAchievementMgr() { return m_achievementMgr; }
protected: protected:
/*********************************************************/ /*********************************************************/
@ -2284,6 +2286,7 @@ class MANGOS_DLL_SPEC Player : public Unit
WorldLocation m_teleport_dest; WorldLocation m_teleport_dest;
DeclinedName *m_declinedname; DeclinedName *m_declinedname;
AchievementMgr *m_achievementMgr;
private: private:
// internal common parts for CanStore/StoreItem functions // internal common parts for CanStore/StoreItem functions
uint8 _CanStoreItem_InSpecificSlot( uint8 bag, uint8 slot, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool swap, Item *pSrcItem ) const; uint8 _CanStoreItem_InSpecificSlot( uint8 bag, uint8 slot, ItemPosCountVec& dest, ItemPrototype const *pProto, uint32& count, bool swap, Item *pSrcItem ) const;