コード例 #1
0
ファイル: WorldServer.cpp プロジェクト: DerBasti/DreamROSE
void WorldServer::runMap(Map* curMap) {
	if (!curMap)
		return;
#else
void runMap(Map* curMap) {
	if (!curMap)
		return;
	ChronoTimer t;
	dword_t timePerFrame = (1000 / 60);
	do {
		long long timeDiff = timePerFrame - (t.getDuration());
		t.update();
		if (timeDiff > 0) {
			Sleep(timeDiff);
		}
		if (!curMap->hasActivePlayers()) {
			continue;
		}
#endif
	Player* curPlayer = nullptr;
	NPC* curNPC = nullptr;
	Map::Sector* newSector = nullptr;

	LinkedList<Entity*> entityToRemove;
	for(unsigned int i=0;i<curMap->getSectorCount();i++) {
		Map::Sector* curSector = curMap->getSector(i);
		LinkedList<Entity*>::Node* entityNode = curSector->getFirstEntity();
		bool updateNextNode = false;
		while(entityNode) {
			if(updateNextNode) {
				entityNode = entityNode->getNextNode();
				if(!entityNode)
					break;
			} 
			updateNextNode = true;
			Entity* curEntity = entityNode->getValue();
			if (!curEntity || !curEntity->isIngame() || curEntity->getEntityType() == Entity::TYPE_DROP) {
				continue;
			}
			byte_t result = curEntity->movementRoutine();
			if (result & Entity::Movement::INITIAL_ATTACK) {
				curEntity->getAttackAnimation();
			}
			if (result & Entity::Movement::TARGET_REACHED) {
				bool isProcFrameReached = curEntity->playAnimation();
			}
			if ((newSector = curEntity->checkForNewSector()) != nullptr) {
				entityNode = curEntity->setSector(newSector);
				curEntity->checkVisuality();
				if (entityNode) {//in case we have a valid succeeding node
					updateNextNode = false;
				}
			}
			switch (curEntity->getEntityType()) {
				case Entity::TYPE_PLAYER:
					curPlayer = dynamic_cast<Player*>(curEntity);
					curPlayer->checkRegeneration();
				break;
				case Entity::TYPE_NPC:
				case Entity::TYPE_MONSTER:
					curNPC = dynamic_cast<NPC*>(curEntity);
					if (result == Entity::Movement::IDLE) {
						//In case the NPC/Monster is idling
						//run AI with state "IDLE"
						if(curEntity->getTarget() == NULL) {
							AIService::run(curNPC, AIP::ON_IDLE);
						} else {
							AIService::run(curNPC, AIP::ON_ATTACK);
						}
					} else {
						//In case it's walking and has no target
						//i.e. walking around/away
						if (curEntity->getTarget() == NULL) {
							curNPC->setTimeAICheck();
						} else {
							AIService::run(curNPC, AIP::ON_ATTACK);
						}
					}
				break;
			}
		}
	}
	curMap->checkSpawns();
#ifdef __ROSE_MULTI_THREADED__
	} while (true);
#endif
	
}

bool WorldServer::loadSTBs() {

	std::cout << "Reading all STBs...\r";
#ifdef __ROSE_USE_VFS__	
	VFSData fileBuf;
	this->aiFile = new AISTB(this->vfs, "3DDATA\\STB\\FILE_AI.STB");
	this->npcFile = new NPCSTB(this->vfs, "3DDATA\\STB\\LIST_NPC.STB");
	this->skillFile = new SkillSTB(this->vfs, "3DDATA\\STB\\LIST_SKILL.STB");
	this->dropFile = new STBFile(this->vfs, "3DDATA\\STB\\ITEM_DROP.STB");
	this->zoneFile = new ZoneSTB(this->vfs, "3DDATA\\STB\\LIST_ZONE.STB");
	this->questFile = new STBFile(this->vfs, "3DDATA\\STB\\LIST_QUEST.STB", false);
	this->statusFile = new StatusSTB(this->vfs, "3DDATA\\STB\\LIST_STATUS.STB");
	this->motionFile = new STBFile(this->vfs, "3DDATA\\STB\\TYPE_MOTION.STB", false);

	this->equipmentFile[0x00] = nullptr;
	this->equipmentFile[ItemType::HEADGEAR] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_CAP.STB");
	this->equipmentFile[ItemType::ARMOR] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_BODY.STB");
	this->equipmentFile[ItemType::GLOVES] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_ARMS.STB");
	this->equipmentFile[ItemType::BACK] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_BACK.STB");
	this->equipmentFile[ItemType::FACE] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_FACEITEM.STB");
	this->equipmentFile[ItemType::SHOES] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_FOOT.STB");
	this->equipmentFile[ItemType::JEWELS] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_JEMITEM.STB");
	this->equipmentFile[ItemType::JEWELRY] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_JEWEL.STB");
	this->equipmentFile[ItemType::OTHER] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_NATURAL.STB");
	this->equipmentFile[ItemType::PAT] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_PAT.STB");
	this->equipmentFile[ItemType::SHIELD] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_SUBWPN.STB");
	this->equipmentFile[ItemType::CONSUMABLES] = new ConsumeSTB(this->vfs, "3DDATA\\STB\\LIST_USEITEM.STB");
	this->equipmentFile[ItemType::QUEST] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_QUESTITEM.STB");
	this->equipmentFile[ItemType::WEAPON] = new STBFile(this->vfs, "3DDATA\\STB\\LIST_WEAPON.STB");

#else
	this->aiFile = new AISTB((workingPath + std::string("\\3DDATA\\STB\\FILE_AI.STB")).c_str());
	this->npcFile = new NPCSTB((workingPath + std::string("\\3DDATA\\STB\\LIST_NPC.STB")).c_str());
	this->skillFile = new SkillSTB((workingPath + std::string("\\3DDATA\\STB\\LIST_SKILL.STB")).c_str());
	this->dropFile = new STBFile((workingPath + std::string("\\3DDATA\\STB\\ITEM_DROP.STB")).c_str());
	this->zoneFile = new ZoneSTB((workingPath + std::string("\\3DDATA\\STB\\LIST_ZONE.STB")).c_str());
	this->equipmentFile[ItemType::HEADGEAR] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_CAP.STB")).c_str());
	this->equipmentFile[ItemType::ARMOR] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_BODY.STB")).c_str());
	this->equipmentFile[ItemType::GLOVES] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_ARMS.STB")).c_str());
	this->equipmentFile[ItemType::BACK] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_BACK.STB")).c_str());
	this->equipmentFile[ItemType::FACE] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_FACEITEM.STB")).c_str());
	this->equipmentFile[ItemType::SHOES] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_FOOT.STB")).c_str());
	this->equipmentFile[ItemType::JEWELS] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_JEMITEM.STB")).c_str());
	this->equipmentFile[ItemType::JEWELRY] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_JEWEL.STB")).c_str());
	this->equipmentFile[ItemType::OTHER] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_NATURAL.STB")).c_str());
	this->equipmentFile[ItemType::PAT] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_PAT.STB")).c_str());
	this->equipmentFile[ItemType::SHIELD] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_SUBWPN.STB")).c_str());
	this->equipmentFile[ItemType::CONSUMABLES] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_USEITEM.STB")).c_str());
	this->equipmentFile[ItemType::QUEST] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_QUESTITEM.STB")).c_str());
	this->equipmentFile[ItemType::WEAPON] = new STBFile((workingPath + std::string("\\3DDATA\\STB\\LIST_WEAPON.STB")).c_str());
#endif
	std::cout << "Finished reading all STBs!\n";
	return true;
}