//------------------------------------------------------------------------ IParticleEmitter *CItem::GetEffectEmitter(uint32 id) const { TEffectInfoMap::const_iterator it = m_effects.find(id); if (it == m_effects.end()) return 0; const SEffectInfo &info = it->second; SEntitySlotInfo slotInfo; if (GetEntity()->GetSlotInfo(info.slot, slotInfo) && slotInfo.pParticleEmitter) return slotInfo.pParticleEmitter; if (GetEntity()->GetSlotInfo(info.characterSlot, slotInfo) && slotInfo.pCharacter) { ICharacterInstance *pCharacter = slotInfo.pCharacter; IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(info.helper.c_str()); if (pAttachment) { CEffectAttachment *pEffectAttachment = static_cast<CEffectAttachment *>(pAttachment->GetIAttachmentObject()); if (!pEffectAttachment) { // commenting out for silencer functionality //GameWarning("CItem::GetEffectEmitter: no effect attachment on %s (helper %s)", GetEntity()->GetName(), info.helper.c_str()); return 0; } return pEffectAttachment->GetEmitter(); } } return 0; }
void CKVoltEffect::ResetScreenEffect() { if(m_screenEffect && m_ownerActor->IsClient()) { IAttachment* screenAttachment = GetScreenAttachment(); if(screenAttachment) { CEffectAttachment* pEffectAttachment = new CEffectAttachment(m_screenEffect->GetName(), Vec3(0,0,0), Vec3(0,1,0), 1.f); if (pEffectAttachment->GetEmitter()) { screenAttachment->AddBinding(pEffectAttachment); pEffectAttachment->ProcessAttachment(screenAttachment); } else { delete pEffectAttachment; } } else { GameWarning("Failed to find #camera attachment"); } //FadeCrosshair(); DisableScopeReticule(); } }
//------------------------------------------------------------------------ uint32 CItem::AttachEffect(int slot, uint32 id, bool attach, const char *effectName, const char *helper, const Vec3 &offset, const Vec3 &dir, float scale, bool prime) { if (m_stats.mounted) slot=eIGS_FirstPerson; if (attach) { if (!g_pGameCVars->i_particleeffects) return 0; IParticleEffect *pParticleEffect = gEnv->pParticleManager->FindEffect(effectName); if (!pParticleEffect) return 0; // generate id ++m_effectGenId; while (!m_effectGenId || (m_effects.find(m_effectGenId) != m_effects.end())) ++m_effectGenId; SEntitySlotInfo slotInfo; SEffectInfo effectInfo; bool validSlot = GetEntity()->GetSlotInfo(slot, slotInfo) && (slotInfo.pCharacter || slotInfo.pStatObj); if (!validSlot || slotInfo.pStatObj || (!helper || !helper[0])) { // get helper position Vec3 position(0,0,0); if (validSlot && helper && helper[0]) { IStatObj *pStatsObj = slotInfo.pStatObj; position = pStatsObj->GetHelperPos(helper); position = GetEntity()->GetSlotLocalTM(slot, false).TransformPoint(position); } position+=offset; // find a free slot SEntitySlotInfo dummy; int i=0; while (GetEntity()->GetSlotInfo(eIGS_Last+i, dummy)) i++; // move particle slot to the helper position+offset effectInfo.helper = helper; effectInfo.slot = GetEntity()->LoadParticleEmitter(eIGS_Last+i, pParticleEffect, 0, prime, true); Matrix34 tm = IParticleEffect::ParticleLoc(position, dir, scale); GetEntity()->SetSlotLocalTM(effectInfo.slot, tm); } else if (slotInfo.pCharacter) // bone attachment { effectInfo.helper = helper; effectInfo.characterSlot = slot; ICharacterInstance *pCharacter = slotInfo.pCharacter; IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(helper); if (!pAttachment) { GameWarning("Item '%s' trying to attach effect '%s' to attachment '%s' which does not exist!", GetEntity()->GetName(), effectName, helper); return 0; } CEffectAttachment *pEffectAttachment = new CEffectAttachment(effectName, Vec3(0,0,0), Vec3(0,1,0), scale); Matrix34 tm = Matrix34(Matrix33::CreateRotationVDir(dir)); tm.SetTranslation(offset); pAttachment->AddBinding(pEffectAttachment); pAttachment->SetAttRelativeDefault(QuatT(tm)); pEffectAttachment->UpdateAttachment(pAttachment); if (pEffectAttachment->GetEmitter()) { if (prime) pEffectAttachment->GetEmitter()->Prime(); } } m_effects.insert(TEffectInfoMap::value_type(m_effectGenId, effectInfo)); return m_effectGenId; } else if (id) { TEffectInfoMap::iterator it = m_effects.find(id); if (it == m_effects.end()) return 0; SEffectInfo &info = it->second; if (info.slot>-1) { GetEntity()->FreeSlot(info.slot); } else { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(info.characterSlot); if (pCharacter) { IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(info.helper.c_str()); if(pAttachment) pAttachment->ClearBinding(); } } m_effects.erase(it); } return 0; }
TAttachedEffectId CEffectsController::AttachParticleEffect(IParticleEffect* pParticleEffect, const int targetSlot, const char *helperName, const SEffectAttachParams &attachParams) { CRY_ASSERT(m_pOwnerEntity); if (pParticleEffect) { SEntitySlotInfo slotInfo; SEffectInfo effectInfo; const bool validSlot = m_pOwnerEntity->GetSlotInfo(targetSlot, slotInfo); if (!validSlot || slotInfo.pStatObj) { //Get helper position on static object (if any) Vec3 localHelperPosition = attachParams.offset; if (validSlot) { const Matrix34& localSlotMtx = m_pOwnerEntity->GetSlotLocalTM(targetSlot, false); localHelperPosition = slotInfo.pStatObj->GetHelperPos(helperName) + attachParams.offset; localHelperPosition = localSlotMtx.TransformPoint(localHelperPosition); } int attachSlot = FindSafeSlot(attachParams.firstSafeSlot); //Offset particle to desired location effectInfo.entityEffectSlot = m_pOwnerEntity->LoadParticleEmitter(attachSlot, pParticleEffect, 0, attachParams.prime, false); Matrix34 localEffectMtx(IParticleEffect::ParticleLoc(localHelperPosition, attachParams.direction, attachParams.scale)); m_pOwnerEntity->SetSlotLocalTM(effectInfo.entityEffectSlot, localEffectMtx); ++m_effectGeneratorId; effectInfo.id = m_effectGeneratorId; m_attachedEffects.push_back(effectInfo); return m_effectGeneratorId; } else if (slotInfo.pCharacter) { IAttachmentManager *pAttachmentManager = slotInfo.pCharacter->GetIAttachmentManager(); IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(helperName); if (pAttachment) { CEffectAttachment *pEffectAttachment = new CEffectAttachment(pParticleEffect, attachParams.offset, attachParams.direction, attachParams.scale); if (attachParams.prime) { if (IParticleEmitter* pEmitter = pEffectAttachment->GetEmitter()) { pEmitter->Prime(); } } pAttachment->AddBinding(pEffectAttachment); pEffectAttachment->ProcessAttachment(pAttachment); } else { GameWarning("[EntityEffects] Can not attach '%s' to entity '%s', attachment point helper '%s' does not exist", pParticleEffect->GetName(), m_pOwnerEntity->GetName(), helperName); return 0; } ++m_effectGeneratorId; effectInfo.id = m_effectGeneratorId; effectInfo.characterEffectSlot = targetSlot; effectInfo.helperName = helperName; m_attachedEffects.push_back(effectInfo); return m_effectGeneratorId; } } return 0; }