bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/) { Monster* monster = Monster::createMonster(mType); if (!monster) { return false; } if (startup) { //No need to send out events to the surrounding since there is no one out there to listen! if (!g_game.internalPlaceCreature(monster, pos, true)) { delete monster; return false; } } else { if (!g_game.placeCreature(monster, pos, false, true)) { delete monster; return false; } } monster->setDirection(dir); monster->setSpawn(this); monster->setMasterPos(pos, radius); monster->useThing2(); spawnedMap.insert(spawned_pair(spawnId, monster)); spawnMap[spawnId].lastSpawn = OTSYS_TIME(); return true; }
void Spawn::idle(int t) { SpawnedMap::iterator it; for(it = spawnedmap.begin(); it != spawnedmap.end();) { if (it->second->isRemoved == true /*it->second->health <= 0*/) { if(it->first != 0) { spawnmap[it->first].lastspawn = OTSYS_TIME(); } it->second->releaseThing(); //delete it->second; spawnedmap.erase(it++); } else if(!isInSpawnRange(it->second->pos) && it->first != 0) { spawnedmap.insert(spawned_pair(0, it->second)); spawnedmap.erase(it++); } else ++it; } for(SpawnMap::iterator sit = spawnmap.begin(); sit != spawnmap.end(); ++sit) { if(spawnedmap.count(sit->first) == 0) { if((OTSYS_TIME() - sit->second.lastspawn) >= sit->second.spawntime) { SpectatorVec list; SpectatorVec::iterator it; game->getSpectators(Range(sit->second.pos, true), list); bool playerFound = false; for(it = list.begin(); it != list.end(); ++it) { Player *player = dynamic_cast<Player*>(*it); if(player && player->access < g_config.ACCESS_PROTECT) { playerFound = true; break; } } if(playerFound) { sit->second.lastspawn = OTSYS_TIME(); continue; } respawn(sit->first, sit->second.pos, sit->second.name, sit->second.dir); } } } }
void Spawn::cleanup() { for (SpawnedMap::iterator it = spawnedMap.begin(); it != spawnedMap.end();) { uint32_t spawnId = it->first; Monster* monster = it->second; if (monster->isRemoved()) { if (spawnId != 0) { spawnMap[spawnId].lastSpawn = OTSYS_TIME(); } monster->releaseThing2(); spawnedMap.erase(it++); } else if (!isInSpawnZone(monster->getPosition()) && spawnId != 0) { spawnedMap.insert(spawned_pair(0, monster)); spawnedMap.erase(it++); } else { ++it; } } }
void Spawn::cleanup() { auto it = spawnedMap.begin(); while (it != spawnedMap.end()) { uint32_t spawnId = it->first; Monster* monster = it->second; if (monster->isRemoved()) { if (spawnId != 0) { spawnMap[spawnId].lastSpawn = OTSYS_TIME(); } monster->decrementReferenceCounter(); it = spawnedMap.erase(it); } else if (!isInSpawnZone(monster->getPosition()) && spawnId != 0) { spawnedMap.insert(spawned_pair(0, monster)); it = spawnedMap.erase(it); } else { ++it; } } }
Monster* Spawn::respawn(unsigned long spawnid, Position &pos, std::string &name, Direction dir) { //Monster *monster = new Monster(name, game); Monster* monster = Monster::createMonster(name, game); if(monster){ //if(monster->isLoaded()) { monster->setDirection(dir); monster->masterPos = centerPos; if(game->placeCreature(pos, monster)) { monster->useThing(); spawnedmap.insert(spawned_pair(spawnid, monster)); spawnmap[spawnid].lastspawn = OTSYS_TIME(); return monster; } //} //not loaded, or could not place it on the map delete monster; monster = NULL; } return NULL; }
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/) { std::unique_ptr<Monster> monster_ptr(new Monster(mType)); if (startup) { //No need to send out events to the surrounding since there is no one out there to listen! if (!g_game.internalPlaceCreature(monster_ptr.get(), pos, true)) { return false; } } else { if (!g_game.placeCreature(monster_ptr.get(), pos, false, true)) { return false; } } Monster* monster = monster_ptr.release(); monster->setDirection(dir); monster->setSpawn(this); monster->setMasterPos(pos); monster->incrementReferenceCounter(); spawnedMap.insert(spawned_pair(spawnId, monster)); spawnMap[spawnId].lastSpawn = OTSYS_TIME(); return true; }
bool Spawn::spawnMonster(uint32_t spawnId, MonsterType* mType, const Position& pos, Direction dir, bool startup /*= false*/) { std::unique_ptr<Monster> monster_ptr(new Monster(mType)); //add por jose eduardo Monster* monsterPk = monster_ptr.get(); int genderRang = monsterPk->getGenderRange(); if (genderRang == 0){ // random int gendeR = uniform_random(1, 2); if (gendeR == 1){ monsterPk->setSkull(SKULL_FEMALE); } else{ monsterPk->setSkull(SKULL_MALE); } } else if (genderRang == 1){ // male monsterPk->setSkull(SKULL_MALE); } else if (genderRang == 2){ // female monsterPk->setSkull(SKULL_FEMALE); } else if (genderRang == 3){ // undefined monsterPk->setSkull(SKULL_UNDEFINED); } int levelPoke = uniform_random(monsterPk->getMaxLevel(), monsterPk->getMinLevel()); monsterPk->name = monsterPk->name + " [" + std::to_string(levelPoke) + "]"; int Health = (levelPoke / 2)*monsterPk->getMaxHealth(); monsterPk->changeHealth(Health, false); int shinyR = uniform_random(1, 100); if (shinyR == 75){ monsterPk->switchShiny(true); }else{ monsterPk->switchShiny(false); } //add Jose Eduardo if (startup) { //No need to send out events to the surrounding since there is no one out there to listen! if (!g_game.internalPlaceCreature(monster_ptr.get(), pos, true)) { return false; } } else { if (!g_game.placeCreature(monster_ptr.get(), pos, false, true)) { return false; } } Monster* monster = monster_ptr.release(); monster->setDirection(dir); monster->setSpawn(this); monster->setMasterPos(pos, radius); monster->useThing2(); spawnedMap.insert(spawned_pair(spawnId, monster)); spawnMap[spawnId].lastSpawn = OTSYS_TIME(); return true; }