2022-03-05 12:44:06 +02:00
|
|
|
|
#ifndef __INC_METIN_II_GAME_CHARACTER_MANAGER_H__
|
|
|
|
|
#define __INC_METIN_II_GAME_CHARACTER_MANAGER_H__
|
|
|
|
|
|
|
|
|
|
#ifdef M2_USE_POOL
|
|
|
|
|
#include "pool.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-03-05 19:59:39 +02:00
|
|
|
|
#include <common/stl.h>
|
|
|
|
|
#include <common/length.h>
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
#include "vid.h"
|
|
|
|
|
|
|
|
|
|
class CDungeon;
|
|
|
|
|
class CHARACTER;
|
|
|
|
|
class CharacterVectorInteractor;
|
|
|
|
|
|
|
|
|
|
class CHARACTER_MANAGER : public singleton<CHARACTER_MANAGER>
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-03-06 00:01:03 +02:00
|
|
|
|
typedef std::unordered_map<std::string, LPCHARACTER> NAME_MAP;
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
CHARACTER_MANAGER();
|
|
|
|
|
virtual ~CHARACTER_MANAGER();
|
|
|
|
|
|
|
|
|
|
void Destroy();
|
|
|
|
|
|
|
|
|
|
void GracefulShutdown(); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>˴ٿ<CBB4><D9BF><EFBFBD> <20><> <20><><EFBFBD><EFBFBD>. PC<50><43> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ű<EFBFBD><C5B0> Destroy <20>Ѵ<EFBFBD>.
|
|
|
|
|
|
|
|
|
|
DWORD AllocVID();
|
|
|
|
|
|
|
|
|
|
LPCHARACTER CreateCharacter(const char * name, DWORD dwPID = 0);
|
|
|
|
|
#ifndef DEBUG_ALLOC
|
|
|
|
|
void DestroyCharacter(LPCHARACTER ch);
|
|
|
|
|
#else
|
|
|
|
|
void DestroyCharacter(LPCHARACTER ch, const char* file, size_t line);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void Update(int iPulse);
|
|
|
|
|
|
2022-03-12 11:39:41 +02:00
|
|
|
|
LPCHARACTER SpawnMob(DWORD dwVnum, int lMapIndex, int x, int y, int z, bool bSpawnMotion = false, int iRot = -1, bool bShow = true);
|
|
|
|
|
LPCHARACTER SpawnMobRange(DWORD dwVnum, int lMapIndex, int sx, int sy, int ex, int ey, bool bIsException=false, bool bSpawnMotion = false , bool bAggressive = false);
|
|
|
|
|
LPCHARACTER SpawnGroup(DWORD dwVnum, int lMapIndex, int sx, int sy, int ex, int ey, LPREGEN pkRegen = NULL, bool bAggressive_ = false, LPDUNGEON pDungeon = NULL);
|
|
|
|
|
bool SpawnGroupGroup(DWORD dwVnum, int lMapIndex, int sx, int sy, int ex, int ey, LPREGEN pkRegen = NULL, bool bAggressive_ = false, LPDUNGEON pDungeon = NULL);
|
|
|
|
|
bool SpawnMoveGroup(DWORD dwVnum, int lMapIndex, int sx, int sy, int ex, int ey, int tx, int ty, LPREGEN pkRegen = NULL, bool bAggressive_ = false);
|
|
|
|
|
LPCHARACTER SpawnMobRandomPosition(DWORD dwVnum, int lMapIndex);
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
void SelectStone(LPCHARACTER pkChrStone);
|
|
|
|
|
|
|
|
|
|
NAME_MAP & GetPCMap() { return m_map_pkPCChr; }
|
|
|
|
|
|
|
|
|
|
LPCHARACTER Find(DWORD dwVID);
|
|
|
|
|
LPCHARACTER Find(const VID & vid);
|
|
|
|
|
LPCHARACTER FindPC(const char * name);
|
|
|
|
|
LPCHARACTER FindByPID(DWORD dwPID);
|
|
|
|
|
|
|
|
|
|
bool AddToStateList(LPCHARACTER ch);
|
|
|
|
|
void RemoveFromStateList(LPCHARACTER ch);
|
|
|
|
|
|
|
|
|
|
// DelayedSave: <20><EFBFBD><EEB6B0> <20><>ƾ <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ؾ<EFBFBD> <20><> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>ϸ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ʹ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD> "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>Ѵ<EFBFBD>" <20><><EFBFBD><EFBFBD> ǥ<>ø<EFBFBD> <20>صΰ<D8B5> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
// (<28><>: 1 frame) <20>Ŀ<EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ų<EFBFBD><C5B2>.
|
|
|
|
|
void DelayedSave(LPCHARACTER ch);
|
|
|
|
|
bool FlushDelayedSave(LPCHARACTER ch); // Delayed <20><><EFBFBD><EFBFBD>Ʈ<EFBFBD><C6AE> <20>ִٸ<D6B4> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ѵ<EFBFBD>. <20><><EFBFBD><EFBFBD> ó<><C3B3><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20><>.
|
|
|
|
|
void ProcessDelayedSave();
|
|
|
|
|
|
|
|
|
|
template<class Func> Func for_each_pc(Func f);
|
|
|
|
|
|
|
|
|
|
void RegisterForMonsterLog(LPCHARACTER ch);
|
|
|
|
|
void UnregisterForMonsterLog(LPCHARACTER ch);
|
|
|
|
|
void PacketMonsterLog(LPCHARACTER ch, const void* buf, int size);
|
|
|
|
|
|
|
|
|
|
void KillLog(DWORD dwVnum);
|
|
|
|
|
|
|
|
|
|
void RegisterRaceNum(DWORD dwVnum);
|
|
|
|
|
void RegisterRaceNumMap(LPCHARACTER ch);
|
|
|
|
|
void UnregisterRaceNumMap(LPCHARACTER ch);
|
|
|
|
|
bool GetCharactersByRaceNum(DWORD dwRaceNum, CharacterVectorInteractor & i);
|
|
|
|
|
|
2022-03-12 11:39:41 +02:00
|
|
|
|
LPCHARACTER FindSpecifyPC(unsigned int uiJobFlag, int lMapIndex, LPCHARACTER except=NULL, int iMinLevel = 1, int iMaxLevel = PLAYER_MAX_LEVEL_CONST);
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
void SetMobItemRate(int value) { m_iMobItemRate = value; }
|
|
|
|
|
void SetMobDamageRate(int value) { m_iMobDamageRate = value; }
|
|
|
|
|
void SetMobGoldAmountRate(int value) { m_iMobGoldAmountRate = value; }
|
|
|
|
|
void SetMobGoldDropRate(int value) { m_iMobGoldDropRate = value; }
|
|
|
|
|
void SetMobExpRate(int value) { m_iMobExpRate = value; }
|
|
|
|
|
|
|
|
|
|
void SetMobItemRatePremium(int value) { m_iMobItemRatePremium = value; }
|
|
|
|
|
void SetMobGoldAmountRatePremium(int value) { m_iMobGoldAmountRatePremium = value; }
|
|
|
|
|
void SetMobGoldDropRatePremium(int value) { m_iMobGoldDropRatePremium = value; }
|
|
|
|
|
void SetMobExpRatePremium(int value) { m_iMobExpRatePremium = value; }
|
|
|
|
|
|
|
|
|
|
void SetUserDamageRatePremium(int value) { m_iUserDamageRatePremium = value; }
|
|
|
|
|
void SetUserDamageRate(int value ) { m_iUserDamageRate = value; }
|
|
|
|
|
int GetMobItemRate(LPCHARACTER ch);
|
|
|
|
|
int GetMobDamageRate(LPCHARACTER ch);
|
|
|
|
|
int GetMobGoldAmountRate(LPCHARACTER ch);
|
|
|
|
|
int GetMobGoldDropRate(LPCHARACTER ch);
|
|
|
|
|
int GetMobExpRate(LPCHARACTER ch);
|
|
|
|
|
|
|
|
|
|
int GetUserDamageRate(LPCHARACTER ch);
|
2022-03-12 11:39:41 +02:00
|
|
|
|
void SendScriptToMap(int lMapIndex, const std::string & s);
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
bool BeginPendingDestroy();
|
|
|
|
|
void FlushPendingDestroy();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_iMobItemRate;
|
|
|
|
|
int m_iMobDamageRate;
|
|
|
|
|
int m_iMobGoldAmountRate;
|
|
|
|
|
int m_iMobGoldDropRate;
|
|
|
|
|
int m_iMobExpRate;
|
|
|
|
|
|
|
|
|
|
int m_iMobItemRatePremium;
|
|
|
|
|
int m_iMobGoldAmountRatePremium;
|
|
|
|
|
int m_iMobGoldDropRatePremium;
|
|
|
|
|
int m_iMobExpRatePremium;
|
|
|
|
|
|
|
|
|
|
int m_iUserDamageRate;
|
|
|
|
|
int m_iUserDamageRatePremium;
|
|
|
|
|
int m_iVIDCount;
|
|
|
|
|
|
2022-03-06 00:01:03 +02:00
|
|
|
|
std::unordered_map<DWORD, LPCHARACTER> m_map_pkChrByVID;
|
|
|
|
|
std::unordered_map<DWORD, LPCHARACTER> m_map_pkChrByPID;
|
2022-03-05 12:44:06 +02:00
|
|
|
|
NAME_MAP m_map_pkPCChr;
|
|
|
|
|
|
|
|
|
|
char dummy1[1024]; // memory barrier
|
|
|
|
|
CHARACTER_SET m_set_pkChrState; // FSM<53><4D> <20><><EFBFBD>ư<EFBFBD><C6B0><EFBFBD> <20>ִ<EFBFBD> <20><><EFBFBD><EFBFBD>
|
|
|
|
|
CHARACTER_SET m_set_pkChrForDelayedSave;
|
|
|
|
|
CHARACTER_SET m_set_pkChrMonsterLog;
|
|
|
|
|
|
|
|
|
|
LPCHARACTER m_pkChrSelectedStone;
|
|
|
|
|
|
|
|
|
|
std::map<DWORD, DWORD> m_map_dwMobKillCount;
|
|
|
|
|
|
|
|
|
|
std::set<DWORD> m_set_dwRegisteredRaceNum;
|
|
|
|
|
std::map<DWORD, CHARACTER_SET> m_map_pkChrByRaceNum;
|
|
|
|
|
|
|
|
|
|
bool m_bUsePendingDestroy;
|
|
|
|
|
CHARACTER_SET m_set_pkChrPendingDestroy;
|
|
|
|
|
|
|
|
|
|
#ifdef M2_USE_POOL
|
|
|
|
|
ObjectPool<CHARACTER> pool_;
|
|
|
|
|
#endif
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template<class Func>
|
|
|
|
|
Func CHARACTER_MANAGER::for_each_pc(Func f)
|
|
|
|
|
{
|
2022-03-06 00:01:03 +02:00
|
|
|
|
std::unordered_map<DWORD, LPCHARACTER>::iterator it;
|
2022-03-05 12:44:06 +02:00
|
|
|
|
|
|
|
|
|
for (it = m_map_pkChrByPID.begin(); it != m_map_pkChrByPID.end(); ++it)
|
|
|
|
|
f(it->second);
|
|
|
|
|
|
|
|
|
|
return f;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CharacterVectorInteractor : public CHARACTER_VECTOR
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
CharacterVectorInteractor() : m_bMyBegin(false) { }
|
|
|
|
|
|
|
|
|
|
CharacterVectorInteractor(const CHARACTER_SET & r);
|
|
|
|
|
virtual ~CharacterVectorInteractor();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool m_bMyBegin;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#ifndef DEBUG_ALLOC
|
|
|
|
|
#define M2_DESTROY_CHARACTER(ptr) CHARACTER_MANAGER::instance().DestroyCharacter(ptr)
|
|
|
|
|
#else
|
|
|
|
|
#define M2_DESTROY_CHARACTER(ptr) CHARACTER_MANAGER::instance().DestroyCharacter(ptr, __FILE__, __LINE__)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#endif
|