void Stampede::Activate() { AnimationSystem::GetInstance()->ResetAnimation(action); trail = GameplayState::GetInstance()->CreateEmitter("radicorn_mane"); duration = 3.0f; firstHit = false; SGD::AudioManager::GetInstance()->PlayAudio(GameplayState::GetInstance()->stampede_sfx, true); damage = owner->GetStat(StatType::accuracy) + 35; SGD::Point spawnPoint; if (fromTheLeft) { spawnPoint.y = owner->GetPosition().y - 900; m_vtVelocity.y = 1200; } else { spawnPoint.y = owner->GetPosition().y + 900; m_vtVelocity.y = -1200; trail->SetRotation(PI); } NPC* temp = FindControllingNPC(owner); spawnPoint.x = temp->GetTarget()->GetPosition().x; this->SetPosition(spawnPoint); }
bool World::createDynamicNPC(const std::string &name, TYPE_OF_RACE_ID type, const position &pos, /*CCharacter::face_to dir,*/ Character::sex_type sex, const std::string &scriptname) { try { try { NPC *newNPC = new NPC(DYNNPC_BASE, name, type, pos, (Character::face_to)4/*dir*/, false, sex, {}); // add npc to npc list Npc.insert(newNPC); try { // try to load the script std::shared_ptr<LuaNPCScript> script(new LuaNPCScript(scriptname, newNPC)); newNPC->setScript(script); } catch (ScriptException &e) { Logger::error(LogFacility::Script) << "World::createDynamicNPC: Error while loading dynamic NPC script: " << scriptname << ": " << e.what() << Log::end; } } catch (FieldNotFound &) { Logger::error(LogFacility::Script) << "World::createDynamicNPC: No space available for dynamic NPC: " << name << " near " << pos << Log::end; } return true; } catch (...) { Logger::error(LogFacility::Script) << "World::createDynamicNPC: Unknown error while loading dynamic NPC: " << name << Log::end; return false; } }
void EntityList::AETaunt(Client* taunter, float range) { LinkedListIterator<NPC*> iterator(npc_list); if(range == 0) { range = 100; //arbitrary default... } range = range * range; iterator.Reset(); while(iterator.MoreElements()) { NPC * them = iterator.GetData(); float zdiff = taunter->GetZ() - them->GetZ(); if (zdiff < 0) zdiff *= -1; if (zdiff < 10 && taunter->IsAttackAllowed(them) && taunter->DistNoRootNoZ(*them) <= range) { if (taunter->CheckLosFN(them)) { taunter->Taunt(them, true); } } iterator.Advance(); } }
//////////////////////////////////////////////////////////////////////////////// // 액션을 실행한다. //////////////////////////////////////////////////////////////////////////////// void ActionSay::execute (Creature * pCreature1 , Creature * pCreature2) throw(Error) { __BEGIN_TRY Assert(pCreature1 != NULL); Assert(pCreature2 != NULL); Assert(pCreature1->isNPC()); Assert(pCreature2->isPC()); NPC* pNPC = dynamic_cast<NPC*>(pCreature1); Player* pPlayer = pCreature2->getPlayer(); Assert(pPlayer != NULL); GCNPCResponse okpkt; pPlayer->sendPacket(&okpkt); GCNPCSay gcNPCSay; gcNPCSay.setObjectID(pNPC->getObjectID()); gcNPCSay.setScriptID(m_ScriptID); gcNPCSay.setSubjectID(0); pPlayer->sendPacket(&gcNPCSay); __END_CATCH }
int script::addnpc(lua_State *L) { int n = lua_gettop(L); if (n < 6) { return 0; } unsigned short map = (unsigned short)lua_tonumber(L, 1); unsigned short x = (unsigned short)lua_tonumber(L, 2); unsigned short y = (unsigned short)lua_tonumber(L, 3); const char *name = lua_tolstring(L, 4, 0); unsigned short apr = (unsigned short)lua_tonumber(L, 5); unsigned short dir = (unsigned short)lua_tonumber(L, 6); Map *m = DataService::getService()->getMap(map); if (!m) return 0; NPC *npc = new NPC(x, y, m, name, apr, dir); m->addEntity(npc); lua_pushnumber(L, (double)npc->getOid()); return 1; }
int16 QuestManager::unique_spawn(int npc_type, int grid, int unused, float x, float y, float z, float heading) { Mob *other = entity_list.GetMobByNpcTypeID(npc_type); if(other != NULL) { return(other->GetID()); } NPCType* tmp = 0; if ((tmp = Database::Instance()->GetNPCType(npc_type))) { NPC* npc = new NPC(tmp, 0, x, y, z, heading); npc->AddLootTable(); entity_list.AddNPC(npc,true); // Quag: Sleep in main thread? ICK! // Sleep(200); // Quag: check is irrelevent, it's impossible for npc to be 0 here // (we're in main thread, nothing else can possibly modify it) // if(npc != 0) { if(grid > 0) { // HarakiriFIXME npc->AssignWaypoints(grid); } npc->SendPosUpdate(); // } return(npc->GetID()); } return(0); }
//////////////////////////////////////////////////////////////////////////////// // 액션을 실행한다. //////////////////////////////////////////////////////////////////////////////// void ActionRandomSay::execute (Creature * pCreature1 , Creature * pCreature2) throw(Error) { __BEGIN_TRY __BEGIN_DEBUG Assert(pCreature1 != NULL); Assert(pCreature2 == NULL); Assert(pCreature1->isNPC()); // RandomSay는 아래에서 보다시피, 임의의 범위(Start와 End) 안의 // 스크립트 중 랜덤을 돌려 하나를 클라이언트에게 보내는 식이다. // 그러므로 Start와 End 사이에 존재하지 않는 스크립트가 있으면 곤란하다. // 스크립트 테이블을 만들 때, RandomSay에 사용하는 것은 // 데이터가 반드시 연속적으로 존재하게 만들어야 한다. NPC* pNPC = dynamic_cast<NPC*>(pCreature1); ScriptID_t scriptID = m_StartScriptID + random() % (m_EndScriptID - m_StartScriptID + 1); const Script* pScript = g_pPublicScriptManager->getScript(scriptID); GCNPCSay gcNPCSay; gcNPCSay.setObjectID(pNPC->getObjectID()); gcNPCSay.setScriptID(pScript->getScriptID()); gcNPCSay.setSubjectID(0); Zone * pZone = pNPC->getZone(); Assert(pZone != NULL); pZone->broadcastPacket(pNPC->getX() , pNPC->getY() , &gcNPCSay); __END_DEBUG __END_CATCH }
bool Spawn2::Process() { //Yeahlight: This is where an NPC spawn/respawn happens if (timer->Check()) { timer->Disable(); SpawnGroup* sg = zone->spawn_group_list->GetSpawnGroup(spawngroup_id_); if (sg == 0) return false; SPAWN_TIME_OF_DAY tmp_time_of_day; int32 npcid = sg->GetNPCType(&tmp_time_of_day); if (npcid) { NPCType* tmp = Database::Instance()->GetNPCType(npcid); //Yeahlight: Preventing boats from autospawning for Tazadar if (tmp && tmp->race != 72 && tmp->race != 73) { tmp->time_of_day = tmp_time_of_day; // Kibanu NPC* npc = new NPC(tmp, this, x, y, z, heading, false, roamRange, myRoamBox, myPathGrid, myPathGridStart); npc->AddLootTable(); npc->GetMeleeWeapons(); npc->CalcBonuses(true, true); entity_list.AddNPC(npc); } } else { Reset(); } } return true; }
void Trap::CreateHiddenTrigger() { if(hiddenTrigger) return; const NPCType *base_type = database.GetNPCType(500); NPCType *make_npc = new NPCType; memcpy(make_npc, base_type, sizeof(NPCType)); make_npc->max_hp = 100000; make_npc->cur_hp = 100000; strcpy(make_npc->name, "a_trap"); make_npc->runspeed = 0.0f; make_npc->bodytype = BT_Special; make_npc->race = 127; make_npc->gender = 0; make_npc->loottable_id = 0; make_npc->npc_spells_id = 0; make_npc->d_meele_texture1 = 0; make_npc->d_meele_texture2 = 0; make_npc->trackable = 0; make_npc->level = level; strcpy(make_npc->special_abilities, "19,1^20,1^24,1^25,1"); NPC* npca = new NPC(make_npc, 0, x, y, z, 0, FlyMode3); npca->GiveNPCTypeData(make_npc); entity_list.AddNPC(npca); hiddenTrigger = npca; ownHiddenTrigger = true; }
gemNPCActor* Tribe::GetMostHated(NPC* npc, float range, bool includeOutsideRegion, bool includeInvisible, bool includeInvincible, float* hate) { float mostHatedAmount = 0.0; gemNPCActor* mostHated = NULL; csVector3 pos; iSector* sector; psGameObject::GetPosition(npc->GetActor(), pos, sector); for(size_t i=0; i < members.GetSize(); i++) { NPC* member = members[i]; float hateValue = 0; gemNPCActor* hated = member->GetMostHated(pos, sector, range, NULL, includeOutsideRegion, includeInvisible, includeInvincible, &hateValue); if(!mostHated || hateValue > mostHatedAmount) { mostHatedAmount = hateValue; mostHated = hated; } } if(hate) { *hate = mostHatedAmount; } return mostHated; }
void Tournament::add_spawnable_npc(GSpawnNPC *snpc) { NPC *npc = resources.get_npc(snpc->npc_name); SpawnableNPC *nnpc = new SpawnableNPC; nnpc->npc = npc; nnpc->state.id = snpc->id; nnpc->state.owner = snpc->owner; nnpc->state.flags = 0; nnpc->state.direction = snpc->direction; nnpc->state.x = snpc->x; nnpc->state.y = snpc->y; nnpc->state.accel_x = snpc->accel_x; nnpc->state.accel_y = snpc->accel_y; nnpc->icon = NPCAnimationStanding; nnpc->iconindex = 0; nnpc->init_owner = snpc->owner; nnpc->ignore_owner_counter = npc->get_ignore_owner_counter(); nnpc->move_counter = static_cast<double>(npc->get_move_init_randomized()); spawnable_npcs.push_back(nnpc); if (!server) { try { if (snpc->sound_name[0]) { subsystem.play_sound(resources.get_sound(snpc->sound_name), 0); } } catch (const Exception& e) { subsystem << e.what(); } } }
QList<NPC*> GameLoader::loadNpcs(const QDomElement& element) { QList<NPC*> npcs; QString source = element.attribute("source"); if (!source.isNull()) { QDomDocument document = load(path()+"/"+source); npcs = loadNpcs(document.documentElement()); _paths.pop(); return npcs; } QDomNodeList children = element.childNodes(); for (int i=0; i<children.size(); ++i) { QDomElement child = children.at(i).toElement(); if (child.tagName()=="npc") { NPC* npc = new NPC(); npc->setName(child.attribute("name")); initializeObject(child, npc); npcs << npc; } } return npcs; }
void NPCManager::handleNewMap() { Map_NPC mn; ItemStack item_roll; // remove existing NPCs for (unsigned i=0; i<npcs.size(); i++) delete(npcs[i]); npcs.clear(); // read the queued NPCs in the map file while (!map->npcs.empty()) { mn = map->npcs.front(); map->npcs.pop(); NPC *npc = new NPC(map, items); npc->load(mn.id, stats->level); npc->pos.x = mn.pos.x; npc->pos.y = mn.pos.y; // if this NPC needs randomized items while (npc->random_stock > 0 && npc->stock_count < NPC_VENDOR_MAX_STOCK) { item_roll.item = loot->randomItem(npc->level); item_roll.quantity = rand() % items->items[item_roll.item].rand_vendor + 1; npc->stock.add(item_roll); npc->random_stock--; } npc->stock.sort(); npcs.push_back(npc); } }
///===================================================== /// ///===================================================== void AISystem::DefendStrategy() const{ static IntVec2 defenceLocation(48, 9); for (Actors::const_iterator actorIter = Actor::s_actorsOnMap.cbegin(); actorIter != Actor::s_actorsOnMap.cend(); ++actorIter){ Actor* actor = actorIter->second; if (actor->m_isDead) continue; if (actor->IsPlayer()){ break; } else{ NPC* npc = (NPC*)actor; if (npc->m_plannedBehavior->m_name == "Wander" && CalcDistanceSquared(npc->m_position, defenceLocation) > (10 * 10)){ //if we're far away from the defence location and wandering, move toward the defence location DefendLocationBehavior* defendLocationBehavior = (DefendLocationBehavior*)npc->FindBehaviorByName("DefendLocation"); RECOVERABLE_ASSERT(defendLocationBehavior != nullptr); if (defendLocationBehavior != nullptr){ defendLocationBehavior->m_defenceLocation = defenceLocation; npc->m_plannedBehavior = defendLocationBehavior; } } } } }
void castSkybaserForGhost(Mission* mission, Airplane* airplane, CatToy* ghost) { assert( ghost ); // detect cattoy level float cattoyLevel = 0.25f * ( ghost->getVirtues()->getEnduranceSkill() + ghost->getVirtues()->getPerceptionSkill() + ghost->getVirtues()->getRiggingSkill() + ghost->getVirtues()->getTrackingSkill() ); // detect player is a LICENSED_CHAR bool playerIsLicensed = mission->getScene()->getCareer()->getLicensedFlag(); // build list of same level npc std::vector<unsigned int> npcs; database::NPCInfo::select( cattoyLevel, 0.126f, !playerIsLicensed, npcs ); // select NPC unsigned int index = getCore()->getRandToolkit()->getUniformInt() % npcs.size(); unsigned int npcId = npcs[index]; // create NPC NPC* npc = new NPC( mission, npcId, airplane, NULL, ghost ); // devote ghost npc->devoteCattoy(); // setup cameraman behaviour npc->setProgram( new NPCCameraman( npc ) ); // setup brief signature npc->getJumper()->setSignatureType( stBrief ); }
NPC* WorldServer::getNPCGlobal(const word_t npcId) { for (unsigned int i = 0;i<this->globalNPCs.size(); i++) { NPC* npc = this->globalNPCs[i]; if (npc->getTypeId() == npcId) return npc; } return nullptr; }
void Tribe::TriggerEvent(Perception* pcpt, float maxRange, csVector3* basePos, iSector* baseSector) { for(size_t i=0; i < members.GetSize(); i++) { NPC* npc = members[i]; npc->TriggerEvent(pcpt, maxRange, basePos, baseSector); } }
NPC* castGhostNPC(Mission* mission, Enclosure* enclosure, CatToy* ghost, unsigned int npcId) { // create NPC NPC* npc = new NPC( mission, npcId, NULL, enclosure, ghost ); // setup cameraman behaviour npc->setProgram( new NPCCameraman( npc ) ); // setup brief signature npc->getJumper()->setSignatureType( stBrief ); return npc; }
int Tribe::AliveCount() const { int count = 0; for(size_t i=0; i < members.GetSize(); i++) { NPC* npc = members[i]; if(npc->IsAlive()) count++; } return count; }
void Level::DrawForeground(int xOffset, int yOffset, float playerY) { for(int i = (_middleLayer + 1); i < _layers.size(); i++) { _layers.at(i)->Draw(xOffset, yOffset); } for(int i = 0; i < _npcs.size(); i++) { NPC* npc = _npcs.at(i); if(npc->GetY() > playerY) npc->Render(); } }
void Tribe::SendPerception(const char* pcpt, csArray<NPC*> npcs) { Perception perception(pcpt); for(size_t i=0; i<npcs.GetSize(); i++) { NPC* npc = npcs[i]; RDebug(this, 5, "--> Percept npc %s(%s): %s",npc->GetName(),ShowID(npc->GetEID()),perception.ToString(npc).GetDataSafe()); npc->TriggerEvent(&perception); } }
bool WorldServer::loadIFOs(Map* curMap, STBFile& warpFile) { std::string folderPath = std::string(curMap->getMapPath()); if (folderPath.length() == 0) return true; #ifdef __ROSE_USE_VFS__ //dword_t fileAmount = this->vfs->getFileCountFromFolder(folderPath.c_str()); std::vector<std::string> files = this->vfs->getFileNamesFromFolder(folderPath.c_str() , ".ifo"); #else folderPath = workingPath + std::string("\\") + folderPath.substr(0, folderPath.find_last_of("\\") + 1); //Get all IFOs from the current map directory QuickInfo::getFilesFromDirectoryA(folderPath, std::string(".ifo"), files); if (files.size() == 0) { //In case there are none (for whatever reason), don't do anything return true; } #endif this->teleGates.reserve(warpFile.getRowCount()); for (unsigned int i = 0; i < this->teleGates.capacity(); i++) this->teleGates.addValue(Telegate()); /** ASSIGN SECTORS **/ curMap->setSectorWidthAndHeight(this->zoneFile->getZoneSize(curMap->getId())); //As precaution, as some Maps seem to have 0 as ZoneSize if (curMap->getSectorWidthAndHeight() == 0) { curMap->setSectorWidthAndHeight(IFO::CUSTOMIZED_SECTOR_SIZE); } curMap->createSectors(files); //Iterate through all *.ifo files GlobalLogger::debug("Loading IFOs from path %s...\n", folderPath.c_str()); for (unsigned int j = 0; j < files.size(); j++) { VFSData fileData; this->vfs->readFile(files.at(j).c_str(), fileData); IFO ifo(&fileData); //Add all spawns of the current *.ifo to the map for (unsigned int k = 0; k < ifo.getSpawnAmount(); k++) { curMap->addSpawn(new IFOSpawn(ifo.getSpawn(k))); } //Add all (IFO-)NPCs to the map for (unsigned int k = 0; k < ifo.getNPCAmount(); k++) { IFONPC& npcINFO = ifo.getNPC(k); NPCData& npcData = this->npcData.at(npcINFO.getObjectId()); NPC *newNpc = new NPC(&npcData, &this->aiData.getValue(npcData.getAIId()), curMap->getId(), npcINFO.getPosition()); newNpc->setDirection(npcINFO.getDirection()); newNpc->setSector(curMap->getSector(newNpc->getPositionCurrent())); this->globalNPCs.push_back(newNpc); } //Create telegates from the previously read IFO-info this->loadTelegates(curMap->getId(), warpFile, ifo); } return true; }
void NPCManager::removeNpcFromMap(uint8_t npcID) { map<uint8_t, NPC*>::const_iterator iter = m_npcMap.begin(); for(; iter != m_npcMap.end(); ++iter) { NPC* pNPC = iter->second; if(pNPC->getID() == npcID) { pNPC->removeFromMap(); } } }
NPC* Map::getNPC(const word_t type) const { LinkedList<Entity*>::Node* nNode = this->getFirstEntity(); for(;nNode;nNode = nNode->getNextNode()) { Entity* entity = nNode->getValue(); if(!entity || entity->getEntityType() != Entity::TYPE_NPC) continue; NPC* curNpc = dynamic_cast<NPC*>(entity); if(curNpc->getTypeId() == type) return curNpc; } return nullptr; }
// show NPC on the specified map void NPCManager::showNpcOnMap(uint16_t mapID, CCNode* pParent) { map<uint8_t, NPC*>::iterator iter = m_npcMap.begin(); for(; iter != m_npcMap.end(); ++iter) { NPC* pNPC = iter->second; if(pNPC->getMapID() == mapID) { pNPC->showOnMap(pParent); } } }
void NessBox2DApp::draw() { // clear out the window with black gl::clear( Color( 0.2, 0.2, 0.2 ) ); if( ness.getY() < jeff.getY() ) { ness.draw(); jeff.draw(); } else { jeff.draw(); ness.draw(); } }
//////////////////////////////////////////////////////////////////////////////// // 액션을 실행한다. //////////////////////////////////////////////////////////////////////////////// void ActionPrepareTeach::execute (Creature * pCreature1 , Creature * pCreature2) throw(Error) { __BEGIN_TRY Assert(pCreature1 != NULL); Assert(pCreature1->isNPC()); NPC* pNPC = dynamic_cast<NPC*>(pCreature1); pNPC->setMaxSkillLevel(m_MaxLevel); __END_CATCH }
void MapLoader::loadNpcs(MapData& data, Screen* screen, Map* map) const { MapMainCharacter* mainCharacter = dynamic_cast<MapScreen*>(screen)->getMainCharacter(); if (mainCharacter == nullptr) { g_logger->logError("MapLoader", "Could not find main character of map screen"); return; } // calculate npcs for (auto& it : data.npcs) { NPC* mapNPC = new NPC(map); mapNPC->load(mainCharacter, it); screen->addObject(mapNPC); } }
// get NPC by boss ID NPC* NPCManager::getNpcByBossID(uint16_t bossID) { map<uint8_t, NPC*>::const_iterator iter = m_npcMap.begin(); for(; iter != m_npcMap.end(); ++iter) { NPC* pNPC = iter->second; if(pNPC->getMonsterID() == bossID) { return pNPC; } } return NULL; }
bool Tribe::CheckMembers(const csString &type, int number) { // Handle special case where name is 'number' if(type == "number") { // Check if total number is correct (we don't care if their idle or not if(number < 0 || (size_t)number <= members.GetSize()) { return true; } return false; } for(size_t i=0; i<members.GetSize(); i++) { NPC* member = members[i]; if(!member->GetCurrentBehavior()) { // Discard Members with no Behavior // This shouldn't happen but... ermm just in case continue; } if((member->GetTribeMemberType() != type) && (type != "any")) { // Just skip any members of wrong type. continue; } if(strcasecmp(member->GetCurrentBehavior()->GetName(), npcIdleBehavior.GetDataSafe()) == 0) { number--; } if(number <= 0) { return true; } } // We don't have enough members return false; }