Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////////////////////////////////////
- //
- // Mob Manager Functions
- //
- // This will handle all things related to the MobList map
- // and a thread for the mobs as well
- // NPCs are included in this section as well.
- //////////////////////////////////////////////////////////////////////
- #include "Stdafx.h"
- #include "GameServer.h"
- #include <map>
- CMobManager* g_pMobManager = NULL;
- CMobManager::CMobManager()
- {
- m_bRun = true;
- }
- CMobManager::~CMobManager()
- {
- Release();
- }
- void CMobManager::Init()
- {
- CreateMobThread();
- CreateNpcList();
- CreateMonsterList();
- }
- void CMobManager::Release()
- {
- }
- void CMobManager::Run()
- {
- CGameServer * app = (CGameServer*)NtlSfxGetApp();
- while (m_bRun)
- {
- Sleep(100);
- }
- }
- void CMobManager::CreateMobThread()
- {
- pThread = CNtlThreadFactory::CreateThread(this, "CMMThread");
- pThread->Start();
- }
- RwUInt32 CMobManager::CreateUniqueId(void)
- {
- if (m_uiMobId++)
- {
- if (m_uiMobId == 0xffffffff)
- m_uiMobId = 0;
- }
- return m_uiMobId;
- }
- void CMobManager::CreateNpcList()
- {
- CGameServer * app = (CGameServer*)NtlSfxGetApp();
- CSpawnTable* pNPCSpawnTbl = app->g_pTableContainer->GetNpcSpawnTable(1);
- for (CTable::TABLEIT itNPCSpawn = pNPCSpawnTbl->Begin(); itNPCSpawn != pNPCSpawnTbl->End(); ++itNPCSpawn)
- {
- sSPAWN_TBLDAT* pNPCSpwnTblData = (sSPAWN_TBLDAT*)itNPCSpawn->second;
- sNPC_TBLDAT* pNPCTblData = (sNPC_TBLDAT*)app->g_pTableContainer->GetNpcTable()->FindData(pNPCSpwnTblData->mob_Tblidx);
- if (pNPCTblData)
- {
- CMonster::MonsterData * cr = new CMonster::MonsterData;
- cr->Level = pNPCTblData->byLevel;
- cr->CurEP = pNPCTblData->wBasic_EP;
- cr->CurLP = pNPCTblData->wBasic_LP;
- cr->FightMode = false;
- cr->IsDead = false;
- cr->isSpawned = false;
- cr->MonsterID = pNPCTblData->tblidx;
- cr->MonsterSpawnID = pNPCSpwnTblData->tblidx;
- cr->Spawn_Loc = pNPCSpwnTblData->vSpawn_Loc;
- cr->Spawn_Dir = pNPCSpwnTblData->vSpawn_Dir;
- cr->MaxEP = pNPCTblData->wBasic_EP;
- cr->MaxLP = pNPCTblData->wBasic_LP;
- cr->curPos = cr->Spawn_Loc;
- cr->UniqueID = pNPCSpwnTblData->tblidx;
- m_map_Npc.insert(std::make_pair(cr->UniqueID, cr));
- }
- }
- }
- void CMobManager::CreateMonsterList()
- {
- CGameServer * app = (CGameServer*)NtlSfxGetApp();
- CWorldTable* pWorldTable = app->g_pTableContainer->GetWorldTable();
- CSpawnTable* pMOBSpawnTbl = app->g_pTableContainer->GetMobSpawnTable(1);
- for (CTable::TABLEIT itMOBSpawn = pMOBSpawnTbl->Begin(); itMOBSpawn != pMOBSpawnTbl->End(); ++itMOBSpawn)
- {
- sSPAWN_TBLDAT* pMOBSpwnTblData = (sSPAWN_TBLDAT*)itMOBSpawn->second;
- sMOB_TBLDAT* pMOBTblData = (sMOB_TBLDAT*)app->g_pTableContainer->GetMobTable()->FindData(pMOBSpwnTblData->mob_Tblidx);
- if (pMOBTblData)
- {
- CMonster::MonsterData * cr = new CMonster::MonsterData;
- cr->Level = pMOBTblData->byLevel;
- cr->CurEP = pMOBTblData->wBasic_EP;
- cr->CurLP = pMOBTblData->wBasic_LP;
- cr->FightMode = false;
- cr->IsDead = false;
- cr->isSpawned = false;
- cr->MonsterID = pMOBTblData->tblidx;
- cr->MonsterSpawnID = pMOBSpwnTblData->tblidx;
- cr->Spawn_Loc = pMOBSpwnTblData->vSpawn_Loc;
- cr->Spawn_Dir = pMOBSpwnTblData->vSpawn_Dir;
- cr->MaxEP = pMOBTblData->wBasic_EP;
- cr->MaxLP = pMOBTblData->wBasic_LP;
- cr->Spawn_Quantity = pMOBSpwnTblData->bySpawn_Quantity;
- cr->Move_DelayTime = pMOBSpwnTblData->byMove_DelayTime;
- cr->Run_Speed = pMOBTblData->fRun_Speed;
- cr->Run_Speed_origin = pMOBTblData->fRun_Speed_Origin;
- cr->Walk_Speed = pMOBTblData->fWalk_Speed;
- cr->Walk_Speed_origin = pMOBTblData->fWalk_Speed_Origin;
- cr->Spawn_Cool_Time = pMOBSpwnTblData->wSpawn_Cool_Time * 1000;
- cr->target = 0;
- cr->curPos = cr->Spawn_Loc;
- cr->Basic_aggro_point = pMOBTblData->byScan_Range;
- cr->Attack_range = pMOBTblData->fAttack_Range;
- cr->MaxchainAttackCount = pMOBTblData->byAttack_Animation_Quantity;
- cr->chainAttackCount = 0;
- cr->UniqueID = CreateUniqueId();
- m_map_Monster.insert(std::make_pair(cr->UniqueID, cr));
- }
- }
- }
- bool CMobManager::RunSpawnCheck(CNtlPacket * pPacket, sVECTOR3 curPos, CClientSession * pSession)
- {
- CGameServer * app = (CGameServer*)NtlSfxGetApp();
- #pragma region monstercheck
- CMonster::MonsterData* creaturelist;
- for (IterType it = m_map_Monster.begin(); it != m_map_Monster.end(); it++)
- {
- creaturelist = it->second;
- if (CreatureRangeCheck(curPos, creaturelist->Spawn_Loc) == true)
- {
- if (creaturelist->IsDead == false && creaturelist->isSpawned == false)
- {
- CNtlPacket packet(sizeof(sGU_OBJECT_CREATE));
- sGU_OBJECT_CREATE * res = (sGU_OBJECT_CREATE *)packet.GetPacketData();
- creaturelist->isSpawned = true;
- res->wOpCode = GU_OBJECT_CREATE;
- res->sObjectInfo.objType = OBJTYPE_MOB;
- res->handle = creaturelist->UniqueID;
- res->sObjectInfo.mobState.sCharStateBase.vCurLoc.x = creaturelist->Spawn_Loc.x;
- res->sObjectInfo.mobState.sCharStateBase.vCurLoc.y = creaturelist->Spawn_Loc.y;
- res->sObjectInfo.mobState.sCharStateBase.vCurLoc.z = creaturelist->Spawn_Loc.z;
- res->sObjectInfo.mobState.sCharStateBase.vCurDir.x = creaturelist->Spawn_Dir.x;
- res->sObjectInfo.mobState.sCharStateBase.vCurDir.y = creaturelist->Spawn_Dir.y;
- res->sObjectInfo.mobState.sCharStateBase.vCurDir.z = creaturelist->Spawn_Dir.z;
- res->sObjectInfo.mobState.sCharStateBase.byStateID = CHARSTATE_SPAWNING;
- res->sObjectInfo.mobState.sCharStateBase.bFightMode = creaturelist->FightMode;
- res->sObjectInfo.mobBrief.tblidx = creaturelist->MonsterID;
- res->sObjectInfo.mobBrief.wCurEP = creaturelist->CurEP;
- res->sObjectInfo.mobBrief.wMaxEP = creaturelist->MaxEP;
- res->sObjectInfo.mobBrief.wCurLP = creaturelist->CurLP;
- res->sObjectInfo.mobBrief.wMaxLP = creaturelist->MaxLP;
- res->sObjectInfo.mobBrief.fLastRunningSpeed = creaturelist->Run_Speed;
- res->sObjectInfo.mobBrief.fLastWalkingSpeed = creaturelist->Walk_Speed;
- creaturelist->spawnedForHandle[???] = pSession->GetavatarHandle();
- packet.SetPacketLen(sizeof(sGU_OBJECT_CREATE));
- g_pApp->Send(pSession->GetHandle(), &packet);
- }
- }
- else if ((creaturelist->isSpawned == true && CreatureRangeCheck(curPos, creaturelist->Spawn_Loc) == false) || creaturelist->IsDead == true)
- {
- CNtlPacket packet(sizeof(sGU_OBJECT_DESTROY));
- sGU_OBJECT_DESTROY * res = (sGU_OBJECT_DESTROY*)packet.GetPacketData();
- res->wOpCode = GU_OBJECT_DESTROY;
- res->handle = creaturelist->UniqueID;
- creaturelist->isSpawned = false;
- //creaturelist->isAggro = false;
- creaturelist->target = 0;
- //m_map_Monster.erase(creaturelist->UniqueID);
- packet.SetPacketLen(sizeof(sGU_OBJECT_DESTROY));
- g_pApp->Send(pSession->GetHandle(), &packet);
- }
- }
- #pragma endregion Monstercheckend
- #pragma region npccheck
- CSpawnTable* pNPCSpawnTbl = app->g_pTableContainer->GetNpcSpawnTable(1);
- for (IterType it = m_map_Npc.begin(); it != m_map_Npc.end(); it++)
- {
- creaturelist = it->second;
- sNPC_TBLDAT* pNPCTblData = (sNPC_TBLDAT*)app->g_pTableContainer->GetNpcTable()->FindData(creaturelist->MonsterID);
- if (pNPCTblData && app->mob->CreatureRangeCheck(curPos, creaturelist->Spawn_Loc) == true && creaturelist->isSpawned == false){
- CNtlPacket packet(sizeof(sGU_OBJECT_CREATE));
- sGU_OBJECT_CREATE * sPacket = (sGU_OBJECT_CREATE *)packet.GetPacketData();
- sPacket->wOpCode = GU_OBJECT_CREATE;
- sPacket->sObjectInfo.objType = OBJTYPE_NPC;
- sPacket->handle = CreateUniqueId();
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurLoc.x = creaturelist->Spawn_Loc.x;
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurLoc.y = creaturelist->Spawn_Loc.y;
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurLoc.z = creaturelist->Spawn_Loc.z;
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurDir.x = creaturelist->Spawn_Dir.x;
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurDir.y = creaturelist->Spawn_Dir.y;
- sPacket->sObjectInfo.npcState.sCharStateBase.vCurDir.z = creaturelist->Spawn_Dir.z;
- sPacket->sObjectInfo.npcState.sCharStateBase.byStateID = CHARSTATE_SPAWNING;
- sPacket->sObjectInfo.npcBrief.wCurEP = pNPCTblData->wBasic_EP;
- sPacket->sObjectInfo.npcBrief.wCurLP = pNPCTblData->wBasic_LP;
- sPacket->sObjectInfo.npcBrief.wMaxEP = pNPCTblData->wBasic_EP;
- sPacket->sObjectInfo.npcBrief.wMaxLP = pNPCTblData->wBasic_LP;
- sPacket->sObjectInfo.npcBrief.tblidx = creaturelist->MonsterID;
- creaturelist->isSpawned = true;
- //pSession->InsertIntoMyNpcList(pNPCSpwnTblData->mob_Tblidx, pNPCSpwnTblData->vSpawn_Loc);
- packet.SetPacketLen(sizeof(sGU_OBJECT_CREATE));
- g_pApp->Send(pSession->GetHandle(), &packet);
- }
- }
- return true;
- #pragma endregion Npccheckend
- }
- float CMobManager::Distance(const sVECTOR3 mycurPos, const CNtlVector othercurPos)
- {
- float first = (mycurPos.x - othercurPos.x) * (mycurPos.x - othercurPos.x);
- float second = (mycurPos.y - othercurPos.y) * (mycurPos.y - othercurPos.y);
- float third = (mycurPos.z - othercurPos.z) * (mycurPos.z - othercurPos.z);
- float distance = sqrt(first + second + third);
- return distance;
- }
- bool CMobManager::CreatureRangeCheck(sVECTOR3 mycurPos, CNtlVector othercurPos)
- {
- float distance = Distance(mycurPos, othercurPos);
- if (distance < DISTANCE_TO_SPAWN)
- {
- return true;
- }
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement