CBattleEvent* CBattleDust::FindEvent(EntityId id) { IGameObject *pBattleEventGameObject = g_pGame->GetIGameFramework()->GetGameObject(id); if(pBattleEventGameObject) { return static_cast<CBattleEvent*>(pBattleEventGameObject->QueryExtension("BattleEvent")); } return NULL; }
virtual void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: break; case eFE_Activate: IGameFramework* const pGameFramework = gEnv->pGame->GetIGameFramework(); IGameObject* const pGameObject = pGameFramework->GetGameObject(pActInfo->pEntity->GetId()); if(IsPortActive(pActInfo, EIP_Enslave) || IsPortActive(pActInfo, EIP_UnEnslave) ) { IAnimatedCharacter* const pAnimChar = pGameObject ? (IAnimatedCharacter*) pGameObject->QueryExtension("AnimatedCharacter") : NULL; if(pAnimChar && pAnimChar->GetActionController()) { const EntityId slaveChar = GetPortEntityId(pActInfo, EIP_Slave); IGameObject* pSlaveGameObject = pGameFramework->GetGameObject(slaveChar); IAnimatedCharacter* pSlaveAnimChar = pSlaveGameObject ? (IAnimatedCharacter*) pSlaveGameObject->QueryExtension("AnimatedCharacter") : NULL; if(pSlaveAnimChar && pSlaveAnimChar->GetActionController()) { IAnimationDatabaseManager &dbManager = gEnv->pGame->GetIGameFramework()->GetMannequinInterface().GetAnimationDatabaseManager(); uint32 db_crc32 = CCrc32::ComputeLowercase(GetPortString(pActInfo, EIP_DB)); const IAnimationDatabase* db = dbManager .FindDatabase(db_crc32); const string& scopeContextName = GetPortString(pActInfo, EIP_ScopeContext); const string& requestedScopeContext = scopeContextName.empty() ? "SlaveChar" : scopeContextName; const TagID scopeContext = pAnimChar->GetActionController()->GetContext().controllerDef.m_scopeContexts.Find(scopeContextName.c_str()); pAnimChar->GetActionController()->SetSlaveController(*pSlaveAnimChar->GetActionController(), scopeContext, IsPortActive(pActInfo, EIP_Enslave) ? true : false, db); ActivateOutput(pActInfo, EOP_Success, 1 ); } else { CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or Animated character found for the slave"); ActivateOutput(pActInfo, EOP_Fail, 1 ); } } else { CryWarning( VALIDATOR_MODULE_GAME, VALIDATOR_ERROR, "No GameObject or AnimatedCharacter found"); ActivateOutput(pActInfo, EOP_Fail, 1 ); } } break; } }
void CBattleDust::RecordEvent(EBattleDustEventType event, Vec3 worldPos, const IEntityClass* pClass) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); if(!g_pGameCVars->g_battleDust_enable) return; if(!gEnv->bServer) return; // this typically means the xml file failed to load. Turn off the dust. if(m_maxParticleCount == 0) return; SBattleEventParameter param; if(!GetEventParams(event, pClass, param)) return; if(param.m_power == 0 || worldPos.IsEquivalent(Vec3(0,0,0))) return; if(m_pBattleEventClass == NULL) m_pBattleEventClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( "BattleEvent" ); // first check if we need a new event bool newEvent = true; for(std::list<EntityId>::iterator it = m_eventIdList.begin(); it != m_eventIdList.end(); ++it) { EntityId areaId = (*it); CBattleEvent *pBattleArea = FindEvent(areaId); if(pBattleArea && CheckIntersection(pBattleArea, worldPos, param.m_power)) { // don't need a new event as this one is within an existing one. Just merge them. MergeAreas(pBattleArea, worldPos, param.m_power); pBattleArea->m_lifeRemaining += param.m_lifetime; pBattleArea->m_lifetime = pBattleArea->m_lifeRemaining; pBattleArea->m_lifetime = CLAMP(pBattleArea->m_lifetime, 0.0f, m_maxLifetime); pBattleArea->m_lifeRemaining = CLAMP(pBattleArea->m_lifeRemaining, 0.0f, m_maxLifetime); newEvent = false; break; } } if(newEvent) { IEntitySystem * pEntitySystem = gEnv->pEntitySystem; SEntitySpawnParams esp; esp.id = 0; esp.nFlags = 0; esp.pClass = m_pBattleEventClass; if (!esp.pClass) return; esp.pUserData = NULL; esp.sName = "BattleDust"; esp.vPosition = worldPos; // when CBattleEvent is created it will add itself to the list IEntity * pEntity = pEntitySystem->SpawnEntity( esp ); if(pEntity) { // find the just-added entity in the list, and set it's properties IGameObject* pGO = g_pGame->GetIGameFramework()->GetGameObject(pEntity->GetId()); if(pGO) { CBattleEvent* pNewEvent = static_cast<CBattleEvent*>(pGO->QueryExtension("BattleEvent")); if(pNewEvent) { pNewEvent->m_radius = param.m_power; pNewEvent->m_peakRadius = param.m_power; pNewEvent->m_lifetime = param.m_lifetime; pNewEvent->m_lifeRemaining = param.m_lifetime; pNewEvent->m_worldPos = worldPos; pNewEvent->m_lifetime = CLAMP(pNewEvent->m_lifetime, 0.0f, m_maxLifetime); pNewEvent->m_lifeRemaining = CLAMP(pNewEvent->m_lifeRemaining, 0.0f, m_maxLifetime); pGO->ChangedNetworkState(CBattleEvent::PROPERTIES_ASPECT); } } } } }