void CInstructor::CallOutput(const tstring& sOutput) { if (!GetCurrentLesson()) return; for (size_t i = 0; i < GetCurrentLesson()->m_aOutputs.size(); i++) { CLessonOutput* pOutput = &GetCurrentLesson()->m_aOutputs[i]; if (pOutput->m_sOutput == sOutput) { for (size_t i = 0; i < GameServer()->GetMaxEntities(); i++) { CBaseEntity* pEntity = CBaseEntity::GetEntity(i); if (!pEntity) continue; if (pEntity->IsDeleted()) continue; if (pOutput->m_sTarget.length() == 0) continue; if (pOutput->m_sTarget.length() == 0) continue; if (pOutput->m_sTarget[0] == '*') { if (tstring(pEntity->GetClassName()) != pOutput->m_sTarget.c_str()+1) continue; } else { if (pEntity->GetName() != pOutput->m_sTarget) continue; } pEntity->CallInput(pOutput->m_sInput, convertstring<char, tchar>(pOutput->m_sArgs)); } } } }
void FireInput(class CCommand* pCommand, tvector<tstring>& asTokens, const tstring& sCommand) { if (!CVar::GetCVarBool("cheats")) return; if (asTokens.size() < 3) { TMsg("Format: ent_input entityname input [optional args]\n"); return; } tvector<CBaseEntity*> apEntities; CBaseEntity::FindEntitiesByName(asTokens[1], apEntities); if (!apEntities.size()) { if (CVar::GetCVarBool("debug_entity_outputs")) TMsg("Console -> none\n"); else TError("No entities found that match name \"" + asTokens[1] + "\".\n"); return; } tstring sArgs; for (size_t i = 3; i < asTokens.size(); i++) sArgs += asTokens[i] + " "; for (size_t i = 0; i < apEntities.size(); i++) { CBaseEntity* pTargetEntity = apEntities[i]; if (CVar::GetCVarBool("debug_entity_outputs")) TMsg("Console -> " + tstring(pTargetEntity->GetClassName()) + "(\"" + pTargetEntity->GetName() + "\")." + asTokens[2] + "(\"" + sArgs + "\")\n"); pTargetEntity->CallInput(asTokens[2], sArgs); } }
/*************************************************************** Spawns treasure chest/armory crate, what ever on winning bcnm ****************************************************************/ bool spawnTreasureForBcnm(CInstance* instance){ DSP_DEBUG_BREAK_IF(instance==NULL); //get ids from DB const int8* fmtQuery = "SELECT npcId \ FROM bcnm_treasure_chests \ WHERE bcnmId = %u AND instanceNumber = %u"; int32 ret = Sql_Query(SqlHandle, fmtQuery, instance->getID(), instance->getInstanceNumber()); if (ret == SQL_ERROR || Sql_NumRows(SqlHandle) == 0) { ShowError("spawnTreasureForBcnm : SQL error - Cannot find any npc IDs for BCNMID %i Instance %i \n", instance->getID(), instance->getInstanceNumber()); } else { while(Sql_NextRow(SqlHandle) == SQL_SUCCESS) { uint32 npcid = Sql_GetUIntData(SqlHandle,0); CBaseEntity* PNpc = (CBaseEntity*)zoneutils::GetEntity(npcid, TYPE_NPC); if (PNpc != NULL) { PNpc->status = STATUS_NORMAL; PNpc->animation = 0; PNpc->loc.zone->PushPacket(PNpc, CHAR_INRANGE, new CEntityUpdatePacket(PNpc, ENTITY_SPAWN, UPDATE_ALL)); instance->addNpc(PNpc); ShowDebug(CL_CYAN"Spawned %s id %i inst %i \n",PNpc->status,PNpc->id,instance->getInstanceNumber()); }else { ShowDebug(CL_CYAN"spawnTreasureForBcnm: <%s> is already spawned\n" CL_RESET, PNpc->GetName()); } } return true; } return false; }
void CGameServer::LoadLevel(const CHandle<CLevel>& pLevel) { // Create and name the entities first and add them to this array. This way we avoid a problem where // one entity needs to connect to another entity which has not yet been created. tmap<size_t, CBaseEntity*> apEntities; // Do a quick precache now to load default models and such. Another precache will come later. const auto& aEntities = pLevel->GetEntityData(); for (size_t i = 0; i < aEntities.size(); i++) AddToPrecacheList("C" + aEntities[i].GetClass()); PrecacheList(); m_bAllowPrecaches = true; for (size_t i = 0; i < aEntities.size(); i++) { const CLevelEntity* pLevelEntity = &aEntities[i]; tstring sClass = "C" + pLevelEntity->GetClass(); auto it = CBaseEntity::GetEntityRegistration().find(sClass); TAssert(it != CBaseEntity::GetEntityRegistration().end()); if (it == CBaseEntity::GetEntityRegistration().end()) { TError("Unregistered entity '" + sClass + "'\n"); continue; } AddToPrecacheList("C" + aEntities[i].GetClass()); CBaseEntity* pEntity = Create<CBaseEntity>(sClass.c_str()); apEntities[i] = pEntity; pEntity->SetName(pLevelEntity->GetName()); // Process outputs here so that they exist when handle callbacks run. for (size_t k = 0; k < pLevelEntity->GetOutputs().size(); k++) { auto pOutput = &pLevelEntity->GetOutputs()[k]; tstring sValue = pOutput->m_sOutput; CSaveData* pSaveData = CBaseEntity::FindOutput(pEntity->GetClassName(), sValue); TAssert(pSaveData); if (!pSaveData) { TError("Unknown output '" + sValue + "'\n"); continue; } tstring sTarget = pOutput->m_sTargetName; tstring sInput = pOutput->m_sInput; tstring sArgs = pOutput->m_sArgs; bool bKill = pOutput->m_bKill; if (!sTarget.length()) { TUnimplemented(); TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing a target.\n"); continue; } if (!sInput.length()) { TUnimplemented(); TError("Output '" + sValue + "' of entity '" + pEntity->GetName() + "' (" + pEntity->GetClassName() + ") is missing an input.\n"); continue; } pEntity->AddOutputTarget(sValue, sTarget, sInput, sArgs, bKill); } } for (auto it = apEntities.begin(); it != apEntities.end(); it++) { auto pLevelEntity = &aEntities[it->first]; CBaseEntity* pEntity = it->second; // Force physics related stuff first so it's available if there's a physics model. auto itScale = pLevelEntity->GetParameters().find("Scale"); if (itScale != pLevelEntity->GetParameters().end()) UnserializeParameter("Scale", itScale->second, pEntity); auto itOrigin = pLevelEntity->GetParameters().find("Origin"); if (itOrigin != pLevelEntity->GetParameters().end()) UnserializeParameter("Origin", itOrigin->second, pEntity); for (auto it = pLevelEntity->GetParameters().begin(); it != pLevelEntity->GetParameters().end(); it++) { tstring sHandle = it->first; tstring sValue = it->second; if (sHandle == "MoveParent") continue; if (sHandle == "Scale") continue; if (sHandle == "Origin") continue; UnserializeParameter(sHandle, sValue, pEntity); } } for (auto it = apEntities.begin(); it != apEntities.end(); it++) { auto pLevelEntity = &aEntities[it->first]; CBaseEntity* pEntity = it->second; // Force MoveParent last so that global -> local conversion is performed. auto itMoveParent = pLevelEntity->GetParameters().find("MoveParent"); if (itMoveParent != pLevelEntity->GetParameters().end()) UnserializeParameter("MoveParent", itMoveParent->second, pEntity); } for (size_t i = 0; i < apEntities.size(); i++) apEntities[i]->PostLoad(); if (CWorkbench::IsActive()) CWorkbench::LoadLevel(pLevel); }