//------------------------------------------------------------------------ void CItem::SetCharacterAttachment(int slot, const char *name, IEntity *pEntity, int objSlot, bool owner) { SEntitySlotInfo info; if (!pEntity->GetSlotInfo(objSlot, info)) return; if (info.pCharacter) SetCharacterAttachment(slot, name, info.pCharacter, owner); else if (info.pStatObj) SetCharacterAttachment(slot, name, info.pStatObj, owner); }
//------------------------------------------------------------------------ void CItem::ReAttachAccessory(const ItemString &name) { CItem *pAccessory = GetAccessory(name); SAccessoryParams *params = GetAccessoryParams(name); if(pAccessory && params) { SetCharacterAttachment(eIGS_FirstPerson, params->attach_helper.c_str(), pAccessory->GetEntity(), eIGS_FirstPerson, 0); Vec3 position = GetSlotHelperPos(eIGS_ThirdPerson, params->attach_helper.c_str(), false); GetEntity()->AttachChild(pAccessory->GetEntity()); Matrix34 tm(Matrix34::CreateIdentity()); tm.SetTranslation(position); pAccessory->GetEntity()->SetLocalTM(tm); pAccessory->SetParentId(GetEntityId()); pAccessory->Physicalize(false, false); PlayLayer(params->attach_layer, eIPAF_Default|eIPAF_NoBlend); } }
//------------------------------------------------------------------------ void CItem::AttachAccessoryPlaceHolder(const ItemString &name, bool attach) { const SAccessoryParams *params = GetAccessoryParams(name); if(!params) return; CItem *pPlaceHolder = GetAccessoryPlaceHolder(name); if(!pPlaceHolder) return; if(attach) { SetCharacterAttachment(eIGS_FirstPerson, params->attach_helper, pPlaceHolder->GetEntity(), eIGS_FirstPerson, 0); PlayLayer(params->attach_layer, eIPAF_FirstPerson, false); } else { ResetCharacterAttachment(eIGS_FirstPerson, params->attach_helper); StopLayer(params->attach_layer, eIPAF_FirstPerson, false); } }
//------------------------------------------------------------------------ bool CItem::SetGeometry(int slot, const ItemString &name, const Vec3 &poffset, const Ang3 &aoffset, float scale, bool forceReload) { bool changedfp=false; switch(slot) { case eIGS_Arms: { if(!name || forceReload) { GetEntity()->FreeSlot(slot); #ifndef ITEM_USE_SHAREDSTRING m_geometry[slot].resize(0); #else m_geometry[slot].reset(); #endif } ResetCharacterAttachment(eIGS_FirstPerson, ITEM_ARMS_ATTACHMENT_NAME); ICharacterInstance *pCharacter=0; if(name && name[0]) { if(name != m_geometry[slot]) GetEntity()->LoadCharacter(slot, name); DrawSlot(eIGS_Arms, false); pCharacter = GetEntity()->GetCharacter(eIGS_Arms); } else if(m_pForcedArms) { pCharacter = m_pForcedArms; } else { int armsId=m_stats.hand==eIH_Right?0:1; pCharacter = GetOwnerActor()?GetOwnerActor()->GetFPArms(armsId):0; } if(pCharacter) { pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE)); SetCharacterAttachment(eIGS_FirstPerson, ITEM_ARMS_ATTACHMENT_NAME, pCharacter, 0); } } break; case eIGS_FirstPerson: case eIGS_ThirdPerson: default: { if(!name || forceReload) { GetEntity()->FreeSlot(slot); #ifndef ITEM_USE_SHAREDSTRING m_geometry[slot].resize(0); #else m_geometry[slot].reset(); #endif } DestroyAttachmentHelpers(slot); if(name && name[0]) { if(m_geometry[slot] != name) { const char *ext = PathUtil::GetExt(name.c_str()); if((stricmp(ext, "chr") == 0) || (stricmp(ext, "cdf") == 0) || (stricmp(ext, "cga") == 0)) GetEntity()->LoadCharacter(slot, name, 0); else GetEntity()->LoadGeometry(slot, name, 0, 0); changedfp=slot==eIGS_FirstPerson; } CreateAttachmentHelpers(slot); SetDefaultIdleAnimation(slot, g_pItemStrings->idle); } if(slot == eIGS_FirstPerson) { ICharacterInstance *pCharacter = GetEntity()->GetCharacter(eIGS_FirstPerson); if(pCharacter) { pCharacter->SetFlags(pCharacter->GetFlags()&(~CS_FLAG_UPDATE)); } } else if(slot == eIGS_Destroyed) DrawSlot(eIGS_Destroyed, false); } break; } Matrix34 slotTM; slotTM = Matrix34::CreateRotationXYZ(aoffset); slotTM.Scale(Vec3(scale, scale, scale)); slotTM.SetTranslation(poffset); GetEntity()->SetSlotLocalTM(slot, slotTM); if(changedfp && m_stats.mounted) { PlayAction(m_idleAnimation[eIGS_FirstPerson], 0, true); ForceSkinning(true); if(!m_mountparams.pivot.empty()) { Matrix34 tm=GetEntity()->GetSlotLocalTM(eIGS_FirstPerson, false); Vec3 pivot = GetSlotHelperPos(eIGS_FirstPerson, m_mountparams.pivot.c_str(), false); tm.AddTranslation(pivot); GetEntity()->SetSlotLocalTM(eIGS_FirstPerson, tm); } GetEntity()->InvalidateTM(); } m_geometry[slot] = name ? name : ""; ReAttachAccessories(); return true; }
void CItem::AttachAccessory(const ItemString &name, bool attach, bool noanim, bool force, bool initialSetup) { if(!force && IsBusy()) return; bool anim = !noanim && m_stats.fp; SAccessoryParams *params = GetAccessoryParams(name); if(!params) return; if(attach) { if(!IsAccessoryHelperFree(params->attach_helper)) return; if(CItem *pAccessory = AddAccessory(name)) { pAccessory->Physicalize(false, false); pAccessory->SetViewMode(m_stats.viewmode); if(!initialSetup) pAccessory->m_bonusAccessoryAmmo.clear(); SetCharacterAttachment(eIGS_FirstPerson, params->attach_helper, pAccessory->GetEntity(), eIGS_FirstPerson, 0); SetBusy(true); AttachAction action(pAccessory, params); if(anim) { PlayAction(params->attach_action, 0, false, eIPAF_Default|eIPAF_NoBlend); m_scheduler.TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<AttachAction>::Create(action), false); } else action.execute(this); } } else { if(CItem *pAccessory = GetAccessory(name)) { DetachAction action(pAccessory, params); if(anim) { StopLayer(params->attach_layer, eIPAF_Default|eIPAF_NoBlend); PlayAction(params->detach_action, 0, false, eIPAF_Default|eIPAF_NoBlend); m_scheduler.TimerAction(GetCurrentAnimationTime(eIGS_FirstPerson), CSchedulerAction<DetachAction>::Create(action), false); SetBusy(true); } else { SetBusy(true); action.execute(this); } } } //Skip all this for the offhand if(GetEntity()->GetClass()!=CItem::sOffHandClass) FixAccessories(params, attach); //Attach silencer to 2nd SOCOM ///////////////////////////////////////////////////////////// bool isDualWield = IsDualWieldMaster(); CItem *dualWield = 0; if(isDualWield) { IItem *slave = GetDualWieldSlave(); if(slave && slave->GetIWeapon()) dualWield = static_cast<CItem *>(slave); else isDualWield = false; } if(isDualWield) dualWield->AttachAccessory(name,attach,noanim); ////////////////////////////////////////////////////////////// //Luciano - send game event g_pGame->GetIGameFramework()->GetIGameplayRecorder()->Event(GetOwner(), GameplayEvent(eGE_AttachedAccessory, name, (float)attach, (void *)GetEntityId())); }