📄 field.h
字号:
// Zone.h: interface for the Field class.
//
//////////////////////////////////////////////////////////////////////
#ifndef __Field_H__
#define __Field_H__
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <vector>
#include <set>
#include <hash_map>
#include <MemoryPoolFactory.h>
#include <ResultCode.h>
#include <ProgramCommon/WzDataType.h>
#include "Sector.h"
#include "FieldInfo.h"
#include "ObjectGroupManager.h"
#include "SectorGroup.h"
#include "AITypes.h"
using namespace util;
using namespace std;
class Object;
class Character;
class NPC;
class Map;
class FieldInfo;
struct WzVector;
class AIManager;
class NPC;
struct APP_MSG;
class ObjectList;
struct MSG_BASE_FORWARD;
struct AI_MSG;
class RegenManager;
class TriggerManager;
class MAPOBJECT_INFO;
class MapObject;
class ObjectGroupManager;
class EffectManager;
class BaseEffect;
class TargetFinder;
typedef std::vector<Object*> OBJECT_VECTOR;
typedef OBJECT_VECTOR::iterator OBJECT_VECTOR_ITER;
typedef set<int> SET_SECTOR;
typedef set<int>::iterator SET_SECTOR_ITR;
typedef vector<Sector *> VEC_SECTOR;
typedef VEC_SECTOR::iterator VEC_SECTOR_ITR;
class Field
{
private:
enum
{
MAX_PACKET_LEVEL_INDEX = 2,
MAX_RESERVED_SECTOR_OF_SECTOR_NUM = 100,
};
public:
Field();
virtual ~Field();
VOID Release( CMemoryPoolFactory<SectorGroup> * pSectorGroupPool, CMemoryPoolFactory<Sector> * pSectorPool );
VOID Init( Map *pMap, FieldInfo * pFieldInfo, const TCHAR * pszGroupName,
CMemoryPoolFactory<SectorGroup> * pSectorGroupPool,
CMemoryPoolFactory<Sector> * pSectorPool );
VOID Update( DWORD dwDeltaTick );
// 坷宏璃飘 林函狼 冀磐甸俊霸 菩哦 傈价
RC::ePACKET_SEND_RESULT SendPacketAround( DWORD dwSectorIndex, MSG_BASE_FORWARD * pMsg, WORD wSize, DWORD dwMyObjKey = 0 );
RC::ePACKET_SEND_RESULT SendPacketToAll( MSG_BASE_FORWARD * pMsg, WORD wSize, DWORD dwMyObjKey = 0 );
RC::ePACKET_SEND_RESULT SendExPacketAround( DWORD dwSectorIndex, DWORD dwNumberOfMessages, BYTE **pMsg, WORD *pwSize, DWORD dwMyObjKey = 0 );
RC::ePACKET_SEND_RESULT SendExPacketToAll( DWORD dwNumberOfMessages, BYTE **pMsg, WORD *pwSize, DWORD dwMyObjKey = 0 );
BOOL EnterField( Object* pObject, WzVector * pwzVec ); // Field 弥檬 柳涝
BOOL EnterField_Dir( Object* pObject, WzVector * pwzVec, WORD wAngle ); // Field 弥檬 柳涝-规氢 爱绊
VOID LeaveField( Object* pObject ); // Field 肯傈洒 栋巢
VOID ChangeSector( Object * pObject ); // Sector狼 函版
SectorGroupList* GetSectorGroupList() { return m_pSectorGroupList; }
BOOL WarpObject( Object* pObject, WzVector* pVec); // Object狼 鞘靛郴 况橇
VOID TeleportObject( Object * pObject, WzVector * pVec );
DWORD GetSectorIndex(WzVector* pwzVec);
BOOL IsMovableCoordinates(WzVector* pwzVec);
inline Map* GetMap() { return m_pMap; }
inline FieldInfo* GetFieldInfo() { return m_pFieldInfo; }
inline ObjectList* GetNPCList() const { return m_pNPCList; }
BOOL CreateNPC( eOBJECT_TYPE eObjectType, DWORD dwCode, DWORD dwNumberOfNPC, WzVector* pvPos, DWORD dwAreaID=0, DWORD dwGroupID=0 );
BOOL CreateNPC_Dir( eOBJECT_TYPE eObjectType, DWORD dwCode, DWORD dwNumberOfNPC, WzVector* pvPos, DWORD dwAreaID=0, DWORD dwGroupID=0, WORD wAngle=0 );
VOID DestroyAllNPC();
VOID DestroyNearNPC( Object* pObject );
BOOL FindPath( Character* pChar, WzVector* pwvDest );
BOOL FindPathThrust( Character *pChar, WzVector *pwvMoveDistance, BOOL bForcedMove=FALSE );
Character* SearchTarget( NPC* pNPC, eTARGET_SEARCH_TYPE eSearchType, eSKILL_TARGET_TYPE eTargetType );
Character* FindCharacter( DWORD dwObjectKey ); // 唱吝浚 漂沥 sector 林函阑 茫酒具且淀..
NPC* FindNPC( DWORD dwObjectKey );
BOOL AddNPC( NPC* pNPC );
BOOL RemoveNPC( NPC* pNPC );
VOID AddDeadNPCList( Object *pObject );
VOID RemoveAllNPC();
VOID AddMapObjectAll();
VOID RemoveMapObjectAll();
BOOL RemoveMapObject( const DWORD dwMapObjectID );
MapObject * FindMapObject( const DWORD dwObjectKey );
VOID GetAreaRandomVector( WzID id, WzVector & wzVec );
WzVector GetRandomStartingVector();
BOOL CheckMapVersion( DWORD dwCheckSum );
VOID SendAIMessageAroundExceptMe( Object *pObject, AI_MSG *pMsg, WORD wSize, DWORD dwDelay = 0 );
TriggerManager * GetTriggerManager() { return m_pTriggerManager; }
//VOID SetFieldIndex( INT iFieldIndex ) { m_iFieldIndex = iFieldIndex; }
//INT GetFieldIndex(){ return m_iFieldIndex; }
inline CODETYPE GetFieldCode() { return m_pFieldInfo->GetFieldCode(); }
// 皋牢鸥百阑 吝缴栏肺 老沥康开俊 加窍绰 某腐磐甸阑 茫绰促.( byTargetType -> 0 : 葛滴, 1 : 利焙, 2 : 酒焙 )
BYTE FindTargetsByAttacker( eSKILL_TARGET_TYPE eTargetType, Character* pAttacker, Character** pTargetArray, WzVector &vMainTargetPos,
float fRange, unsigned int uiRangeForm, float fArea=0,
BYTE byCountLimit=MAX_TARGET_NUM, DWORD dwExceptTargetKey=0 );
// 老沥 康开俊 加窍绰 某腐磐甸阑 茫绰促.
BYTE FindTargetsByPosition( Character** pTargetArray, DWORD dwSectorIndex, WzVector &vMainPos,
float fRange, BYTE byCountLimit=MAX_TARGET_NUM );
VOID InitRegenManager( WORD MonsterType ); //! 烙矫肺 窃荐肺 畴免
// 弊缝 概聪历
ObjectGroup* AllocGroup( DWORD dwAreaID, DWORD dwGroupID );
BOOL RemoveGroup( ObjectGroup *pGroup );
ObjectGroup* FindGroup( DWORD dwAreaID, DWORD dwGroupID );
ObjectGroup* FindGroup( DWORD64 dwGroupKey );
// @@@@@@ 捞芭 弥利拳且 规过阑 茫酒扼!
// Add, RemoveObject且锭 Field俊辑 墨款飘 函荐甫 啊瘤绊 乐霸 茄促.
DWORD GetPlayerNum();
// EffectManager
BaseEffect* AllocEffect( eFIELDEFFECT_TYPE eEffectType );
inline INT GetRIndex() { return m_RoomIndex; }
template<class ObjectOperator>
VOID ForEachNPC( ObjectOperator & Opr );
template <class PlayerFinder>
Character* SearchPlayer( PlayerFinder& finder );
template <class NPCFinder>
Character* SearchNPC( NPCFinder& finder );
template< class ObjectOperator >
BOOL SearchNeighborFieldItemAt( DWORD dwSectorIndex, ObjectOperator & Opr );
template< class ObjectOperator >
VOID ForeachPlayer( ObjectOperator & Opr );
template< class ObjectOperator >
VOID ForeachNeighborPlayerAt( DWORD dwSectorIndex, ObjectOperator & Opr );
template< class ObjectOperator >
VOID ForeachNeighborFieldItemAt( DWORD dwSectorIndex, ObjectOperator & Opr );
template< class ObjectOperator >
VOID ForeachNeighborNPCAt( DWORD dwSectorIndex, ObjectOperator & Opr );
// 浚柳率;;
VOID SetActiveRoom();
inline CWorldBase * GetWorldBase() { return m_pFieldInfo->GetWorldBase(); }
// GM cmd? -_-;
VOID KillAllNPC( Player* pPlayer, BOOL bIsDrop );
BOOL KillNPC(Player* pPlayer, NPC* pNPC, BOOL bIsDrop );
WzVector GetRandomPosInAround( const WzVector * pOrgPos, INT iDist );
private:
VOID IncreasePlayerReferenceCount( DWORD dwSectorIndex, Object *pObject );
VOID DecreasePlayerReferenceCount( DWORD dwSectorIndex, Object *pObject );
Character* SearchTarget( TargetFinder *pFinder );
Sector* GetSector( DWORD dwSectorIndex );
private:
Map *m_pMap; //< 开曼炼 两摹救鸥.积阿秦焊祭
FieldInfo * m_pFieldInfo;
//INT m_iFieldIndex; //< 0~MAX_FIELD_IN_MAP_NUM
BYTE m_nMaxPacketLevel;
DWORD m_dwSectorXNum;
DWORD m_dwSectorYNum;
DWORD m_dwTotalSectorNum;
DWORD m_dwSectorSize;
SET_SECTOR m_setCurrSector;
SET_SECTOR m_setPrevSector;
SET_SECTOR m_setEnterSector;
SET_SECTOR m_setLeaveSector;
VEC_SECTOR m_vecTotalSector;
ObjectList *m_pNPCList;
ObjectList *m_pDeadNPCList;
ObjectList * m_pMapObjectList;
RegenManager *m_pRegenManager;
TriggerManager * m_pTriggerManager;
ObjectGroupManager *m_pObjectGroupManager;
EffectManager *m_pEffectManager;
INT m_RoomIndex; //< 浚柳俊辑 荤侩窍绰 Index
SectorGroupList* m_pSectorGroupList;
};
template<class ObjectOperator>
VOID Field::ForEachNPC( ObjectOperator & Opr )
{
NPC* pNPC;
for( M_OBJECT_LIST_ITR it = m_pNPCList->begin(); it != m_pNPCList->end(); ++it )
{
pNPC = (NPC*)(it->second);
Opr( pNPC );
}
}
template <class PlayerFinder>
Character* Field::SearchPlayer( PlayerFinder& finder )
{
// 利(敲饭捞绢) 府胶飘吝俊辑 矫具郴俊 甸绢坷绰 利捞 乐绰瘤 八荤
BOOL bFind = FALSE;
Sector *pSector; SectorGroup *pSectorGroup;
for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
{
pSectorGroup = *it;
if( bFind ) break;
if( !pSectorGroup->GetReferenceCount() ) continue;
for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
{
pSector = *itr;
if( pSector->SearchPlayer( finder ) )
{
bFind = TRUE;
break;
}
}
}
return finder.GetTarget();
}
template <class NPCFinder>
Character* Field::SearchNPC( NPCFinder& finder )
{
BOOL bFind = FALSE;
Sector *pSector; SectorGroup *pSectorGroup;
for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
{
pSectorGroup = *it;
if( bFind ) break;
if( !pSectorGroup->GetReferenceCount() ) continue;
for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
{
pSector = *itr;
if( pSector->SearchNPC( finder ) )
{
bFind = TRUE;
break;
}
}
}
return finder.GetTarget();
}
template< class ObjectOperator >
BOOL Field::SearchNeighborFieldItemAt( DWORD dwSectorIndex, ObjectOperator & Opr )
{
Sector *pSector = GetSector( dwSectorIndex );
// 磊扁冀磐 林函狼 贸府甫 茄促.
if( pSector )
{
if( pSector->SearchFieldItem( Opr ) ) return TRUE;
}
// 林函冀磐 贸府甫 茄促.
SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
ASSERT( pInfo );
POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
SectorInfo * pNextInfo = NULL;
while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
{
pSector = GetSector( pNextInfo->GetSectorIndex() );
if( !pSector ) continue;
if( pSector->SearchFieldItem( Opr ) )
{
return TRUE;
}
}
return FALSE;
}
template<class ObjectOperator>
VOID Field::ForeachPlayer( ObjectOperator & Opr )
{
Sector *pSector; SectorGroup *pSectorGroup;
for( SECTORGROUP_ITERATOR it = m_pSectorGroupList->Begin(); it != m_pSectorGroupList->End(); ++it )
{
pSectorGroup = *it;
if( !pSectorGroup->GetReferenceCount() ) continue;
for( SECTOR_ITERATOR itr = pSectorGroup->Begin(); itr != pSectorGroup->End(); ++itr )
{
pSector = *itr;
pSector->ForeachPlayer( Opr );
}
}
}
template< class ObjectOperator >
VOID Field::ForeachNeighborPlayerAt( DWORD dwSectorIndex, ObjectOperator & Opr )
{
Sector *pSector = GetSector( dwSectorIndex );
// 磊扁冀磐 林函狼 贸府甫 茄促.
if( pSector )
{
pSector->ForeachPlayer( Opr );
}
// 林函冀磐 贸府甫 茄促.
SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
ASSERT( pInfo );
POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
SectorInfo * pNextInfo = NULL;
while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
{
pSector = GetSector( pNextInfo->GetSectorIndex() );
if( !pSector ) continue;
pSector->ForeachPlayer( Opr );
}
}
template< class ObjectOperator >
VOID Field::ForeachNeighborFieldItemAt( DWORD dwSectorIndex, ObjectOperator & Opr )
{
Sector *pSector = GetSector( dwSectorIndex );
// 磊扁冀磐 林函狼 贸府甫 茄促.
if( pSector )
{
pSector->ForeachItem( Opr );
}
// 林函冀磐 贸府甫 茄促.
SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
ASSERT( pInfo );
POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
SectorInfo * pNextInfo = NULL;
while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
{
pSector = GetSector( pNextInfo->GetSectorIndex() );
if( !pSector ) continue;
pSector->ForeachItem( Opr );
}
}
template< class ObjectOperator >
VOID Field::ForeachNeighborNPCAt( DWORD dwSectorIndex, ObjectOperator & Opr )
{
Sector *pSector = GetSector( dwSectorIndex );
// 磊扁冀磐 林函狼 贸府甫 茄促.
if( pSector )
{
pSector->ForeachNPC( Opr );
}
// 林函冀磐 贸府甫 茄促.
SectorInfo * pInfo = m_pFieldInfo->GetSectorInfo( dwSectorIndex );
ASSERT( pInfo );
POS pos = pInfo->GetNeighborSectorInfoList().GetFirstPos();
SectorInfo * pNextInfo = NULL;
while( (pNextInfo = pInfo->GetNeighborSectorInfoList().GetNextPos( pos )) != NULL )
{
pSector = GetSector( pNextInfo->GetSectorIndex() );
if( !pSector ) continue;
pSector->ForeachNPC( Opr );
}
}
template< class ObjectType>
class ObjectFinder
{
ObjectType * m_pObject;
DWORD m_dwObjectKey;
public:
ObjectFinder( DWORD dwObjectKey ):m_dwObjectKey(dwObjectKey),m_pObject(NULL){}
~ObjectFinder(){}
ObjectType * GetTargetObject() { return m_pObject; }
BOOL operator()( ObjectType * pObject )
{
if( pObject->GetObjectKey() == m_dwObjectKey )
{
m_pObject = pObject;
return TRUE;
}
return FALSE;
}
};
#endif // __Field_H__
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -