diff --git a/src/game/AchievementMgr.cpp b/src/game/AchievementMgr.cpp new file mode 100644 index 000000000..170e1a8c4 --- /dev/null +++ b/src/game/AchievementMgr.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * 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); +} + diff --git a/src/game/AchievementMgr.h b/src/game/AchievementMgr.h new file mode 100644 index 000000000..7e7b6ccf2 --- /dev/null +++ b/src/game/AchievementMgr.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2005-2008 MaNGOS + * + * 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 diff --git a/src/game/Makefile.am b/src/game/Makefile.am index 307ffd305..7d583d0e6 100644 --- a/src/game/Makefile.am +++ b/src/game/Makefile.am @@ -30,6 +30,8 @@ noinst_LIBRARIES = libmangosgame.a libmangosgame_a_SOURCES = \ AccountMgr.cpp \ AccountMgr.h \ + AchievementMgr.h \ + AchievementMgr.cpp \ AddonHandler.cpp \ AddonHandler.h \ AggressorAI.cpp \ diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 2a83ed57a..f3a28a6a5 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -58,6 +58,7 @@ #include "Database/DatabaseImpl.h" #include "Spell.h" #include "SocialMgr.h" +#include "AchievementMgr.h" #include @@ -420,6 +421,7 @@ Player::Player (WorldSession *session): Unit() m_contestedPvPTimer = 0; m_declinedname = NULL; + m_achievementMgr = NULL; } Player::~Player () @@ -466,6 +468,7 @@ Player::~Player () itr->second.save->RemovePlayer(this); delete m_declinedname; + delete m_achievementMgr; } 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_achievementMgr = new AchievementMgr(this); + m_achievementMgr->LoadFromDB(); + if(!_LoadHomeBind(holder->GetResult(PLAYER_LOGIN_QUERY_LOADHOMEBIND))) return false; @@ -15190,6 +15196,7 @@ void Player::SaveToDB() // save pet (hunter pet level and experience and all type pets health/mana). if(Pet* pet = GetPet()) pet->SavePetToDB(PET_SAVE_AS_CURRENT); + m_achievementMgr->SaveToDB(); } // fast save function for item/money cheating preventing - save only inventory and money state diff --git a/src/game/Player.h b/src/game/Player.h index d026143d1..6b8db076a 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -45,6 +45,7 @@ class PlayerMenu; class Transport; class UpdateMask; class PlayerSocial; +class AchievementMgr; typedef std::deque PlayerMails; @@ -2054,6 +2055,7 @@ class MANGOS_DLL_SPEC Player : public Unit DeclinedName const* GetDeclinedNames() const { return m_declinedname; } + AchievementMgr *GetAchievementMgr() { return m_achievementMgr; } protected: /*********************************************************/ @@ -2284,6 +2286,7 @@ class MANGOS_DLL_SPEC Player : public Unit WorldLocation m_teleport_dest; DeclinedName *m_declinedname; + AchievementMgr *m_achievementMgr; private: // 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;