//------------------------------------------------------------------------ void CWeaponSystem::RefGun(IConsoleCmdArgs *args) { IGameFramework *pGF = gEnv->pGame->GetIGameFramework(); IItemSystem *pItemSystem = pGF->GetIItemSystem(); IActor *pActor = pGF->GetClientActor(); if(!pActor || !pActor->IsPlayer()) return; IInventory *pInventory = pActor->GetInventory(); if(!pInventory) return; // give & select the refgun EntityId itemId = pInventory->GetItemByClass(CItem::sRefWeaponClass); if(0 == itemId) { // if actor doesn't have it, only give it in editor if(!gEnv->IsEditor()) return; itemId = pItemSystem->GiveItem(pActor, CItem::sRefWeaponClass->GetName(), false, true, true); } pItemSystem->SetActorItem(pActor, itemId, true); }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { IGameFramework* pGF = gEnv->pGame->GetIGameFramework(); if (event == eFE_Activate && IsPortActive(pActInfo,0)) { IActor* pActor = GetInputActor( pActInfo ); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const string& item = GetPortString(pActInfo, 1); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(item); if (0 == pInventory->GetItemByClass(pClass)) { ActivateOutput(pActInfo, 0, false); } else { pGF->GetIItemSystem()->SetActorItem(pActor, item, true); ActivateOutput(pActInfo, 0, true); } } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo,0)) { IGameFramework * pGameFramework = gEnv->pGame->GetIGameFramework(); IActor* pActor = GetInputActor( pActInfo ); if (!pActor || pActor!=gEnv->pGame->GetIGameFramework()->GetClientActor()) // to avoid some extra RMIs and object creation. Tho, this causes the node to not work properly if it is used with non players entities. (which was never intended anyway) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const string& itemClass = GetPortString( pActInfo, 1 ); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( itemClass.c_str() ); EntityId id = pInventory->GetItemByClass( pClass ); if (id!=0) { pInventory->RMIReqToServer_RemoveItem( itemClass.c_str() ); // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations ActivateOutput(pActInfo,0,true); } else ActivateOutput(pActInfo,0,true); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo,0)) { IActor* pActor = GetInputActor( pActInfo ); if (!pActor || pActor!=gEnv->pGame->GetIGameFramework()->GetClientActor()) // to avoid some extra RMIs and object creation. Tho, this causes the node to not work properly if it is used with non players entities. (which was never intended anyway) return; IEntitySystem* pEntSys = gEnv->pEntitySystem; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const string& itemClass = GetPortString(pActInfo, 1); const char* pItemClass = itemClass.c_str(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(pItemClass); EntityId id = pInventory->GetItemByClass(pClass); if (id == 0 || GetPortBool(pActInfo, 3) == false) { if(gEnv->bServer) { gEnv->pGame->GetIGameFramework()->GetIItemSystem()->GiveItem( pActor, pItemClass , false, true, true ); } else { // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations pInventory->RMIReqToServer_AddItem( pItemClass ); } ActivateOutput( pActInfo, 0, true ); } else { // item already in inventory ActivateOutput(pActInfo, 0, false); } } else if (event == eFE_PrecacheResources) { const string& itemClass = GetPortString(pActInfo, 1); if (!itemClass.empty()) { IGameRules* pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules(); CRY_ASSERT_MESSAGE(pGameRules != NULL, "No game rules active, can not precache resources"); if (pGameRules) { pGameRules->PrecacheLevelResource(itemClass.c_str(), eGameResourceType_Item); } } } }
void CFlashUIInventoryNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if(event == eFE_Activate && IsPortActive(pActInfo, 0)) { IActor* pActor = GetInputActor( pActInfo ); if(pActor) { IInventory* pInventory = pActor->GetInventory(); if(pInventory) { string weapons = ""; bool first = true; int inv_cap = gEnv->pConsole->GetCVar("i_inventory_capacity")->GetIVal(); for (int i = 0; i < inv_cap; i++) { const char* weaponName = pInventory->GetItemString(i); if(strcmp(weaponName, "") != 0) { bool selectable = false; //Get the weapon and check if it is a selectable item IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry(); EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weaponName)); IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item); if(pEntity) { CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER); CItem* pItem = (CItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName()); if(pItem) { selectable = pItem->CanSelect(); } } if(selectable) { if(!first) weapons.append(","); first = false; weapons.append(weaponName); } } } ActivateOutput(pActInfo, eO_OnCall, true); ActivateOutput(pActInfo, eO_Args, weapons); } } } }
void CFlashUIGetCompatibleAccessoriesNode ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if(event == eFE_Activate && IsPortActive(pActInfo, 0)) { string accessories = ""; IActor* pActor = GetInputActor( pActInfo ); if(pActor) { IInventory* pInventory = pActor->GetInventory(); if(pInventory) { //Get the item ID via the Input string const string weapon_name = GetPortString(pActInfo, eI_Weapon); IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry(); EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name)); //Fetch the actual weapon via the ID IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item); if(pEntity) { CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER); const char* ext = pGameObject->GetEntity()->GetClass()->GetName(); CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName()); //If the weapon exists, ask for all compatible accessories if(pWeapon) { //All compatible accessories for this weapon const DynArray<string> pCompatibleAccessoriesVec = pWeapon->GetCompatibleAccessories(); bool first = true; DynArray<string>::const_iterator it; for (it = pCompatibleAccessoriesVec.begin(); it != pCompatibleAccessoriesVec.end(); it++) { if (!first) accessories.append(","); accessories.append((*it)); first = false; } } } } } //return, if 'accessories' is empty, it has no compatible attachments, or the weapon/inventory was invalid ActivateOutput(pActInfo, eO_OnCall, true); ActivateOutput(pActInfo, eO_Args, accessories); } }
void CJaw::DropUnused(CActor* pOwner) { IInventory* pInventory = pOwner->GetInventory(); EntityId nextJawEntity = 0; for (;;) { nextJawEntity = pInventory->GetItemByClass(GetEntity()->GetClass()); if (!nextJawEntity) break; CJaw* pNextJawItem = static_cast<CJaw*>(m_pItemSystem->GetItem(nextJawEntity)); if (pNextJawItem) pNextJawItem->Drop(1.0f, false, false); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case (eFE_Activate): { if (!IsPortActive(pActInfo, 0)) return; IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); // get actor IActor* pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1)); IItem* pItem = pItemSys->GetItem(pInventory->GetItemByClass(pClass)); if (!pItem || !pItem->GetIWeapon()) { pItem = pActor->GetCurrentItem(); if (!pItem || pItem->GetEntity()->GetClass() != pClass || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponAmmo: No item/weapon %s!", GetPortString(pActInfo,1).c_str()); return; } } IWeapon *pWeapon = pItem->GetIWeapon(); const string& ammoType = GetPortString(pActInfo,2); IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str()); CRY_ASSERT(pAmmoClass); IFireMode* pCurrentFireMode = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode()); if (pCurrentFireMode) { int clipSize = pCurrentFireMode->GetClipSize(); int ammo = pWeapon->GetAmmoCount(pAmmoClass) + GetPortInt(pActInfo,3); ammo = CLAMP(ammo, 0, clipSize); pWeapon->SetAmmoCount(pAmmoClass, ammo); } ActivateOutput(pActInfo, 0, pWeapon->GetAmmoCount(pAmmoClass)); } break; } }
void CJaw::Drop(float impulseScale, bool selectNext, bool byDeath) { // No special handling needed when exiting editor game mode if (gEnv->IsEditor() && !gEnv->IsEditorGameMode()) return BaseClass::Drop(impulseScale, selectNext, byDeath); CActor* pOwner = GetOwnerActor(); //Don't let the player drop it if it has not been opened if(m_stats.first_selection && pOwner && pOwner->IsPlayer() && !pOwner->IsDead() && !byDeath) return; if(pOwner && !pOwner->IsPlayer()) { //In this case goes to the clip, no the inventory if(m_minDropAmmoAvailable && !m_weaponsharedparams->ammoParams.minDroppedAmmo.empty()) { TAmmoVector::const_iterator end = m_weaponsharedparams->ammoParams.minDroppedAmmo.end(); for(TAmmoVector::const_iterator it = m_weaponsharedparams->ammoParams.minDroppedAmmo.begin(); it != end; ++it) { SWeaponAmmoUtils::SetAmmo(m_ammo, it->pAmmoClass, it->count); } m_minDropAmmoAvailable = false; } } BaseClass::Drop(impulseScale,selectNext,byDeath); if (pOwner && !selectNext && !pOwner->IsHeadUnderWater()) { IInventory* pInventory = pOwner->GetInventory(); EntityId pNextJawItem = pInventory->GetItemByClass(GetEntity()->GetClass()); m_pItemSystem->SetActorItem(pOwner, pNextJawItem, true); } if (pOwner && pOwner->IsPlayer()) { if (m_fired) DropUsed(); else DropUnused(pOwner); } }
void CJaw::AddAmmoCapacity() { CActor* pOwner = GetOwnerActor(); if (!pOwner || !(gEnv->bServer || pOwner->IsClient())) return; IInventory* pOwnerInventory = pOwner->GetInventory(); if (!pOwnerInventory) return; if (pOwnerInventory->GetItemByClass(GetEntity()->GetClass()) != 0) return; const CWeaponSharedParams* pWeaponParams = GetWeaponSharedParams(); for (size_t i = 0; i < pWeaponParams->ammoParams.capacityAmmo.size(); ++i) { IEntityClass* pAmmoType = pWeaponParams->ammoParams.capacityAmmo[i].pAmmoClass; int capacity = pWeaponParams->ammoParams.capacityAmmo[i].count; pOwnerInventory->SetAmmoCapacity(pAmmoType, capacity); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo,0)) { IActor* pActor = GetInputActor( pActInfo ); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(GetPortString(pActInfo,1)); EntityId id = pInventory->GetItemByClass(pClass); ActivateOutput(pActInfo, 0, id !=0 ? true : false); ActivateOutput(pActInfo, id != 0 ? 2 : 1, true); ActivateOutput(pActInfo, 3, id); } }
void CFlashUIGetEquippedAccessoriesNode::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if(event == eFE_Activate && IsPortActive(pActInfo, 0)) { string accessories = ""; IActor* pActor = GetInputActor( pActInfo ); if(pActor) { IInventory* pInventory = pActor->GetInventory(); if(pInventory) { //Get the item ID via the Input string const string weapon_name = GetPortString(pActInfo, eI_Weapon); IEntityClassRegistry *pRegistery = gEnv->pEntitySystem->GetClassRegistry(); EntityId item = pInventory->GetItemByClass(pRegistery->FindClass(weapon_name)); //Fetch the actual object via the ID CGameObject * pGameObject = (CGameObject*)gEnv->pEntitySystem->GetEntity(item)->GetProxy(ENTITY_PROXY_USER); const char* ext = pGameObject->GetEntity()->GetClass()->GetName(); IItem* pWeapon = (IItem*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName()); //If the weapon exists, return all equipped attachments in a comma seperated string if(pWeapon) { //All equipped accessories for this weapon weapons accessories = static_cast<CItem*>(pWeapon)->GetAttachedAccessoriesString(); } } } //return, if 'accesories' is empty, it has no attachments, or something was invalid ActivateOutput(pActInfo, eO_OnCall, true); ActivateOutput(pActInfo, eO_Args, accessories); } }
// (jh) this function is called on any input dispatching it to a relevant method and eventually to Lua onAction method void CPlayerInput::OnAction( const ActionId& actionId, int activationMode, float value ) { FUNCTION_PROFILER(GetISystem(), PROFILE_GAME); if (g_pGame->GetHostMigrationState() != CGame::eHMS_NotMigrating) { Reset(); return; } m_pPlayer->GetGameObject()->ChangedNetworkState( INPUT_ASPECT ); m_lastActions=m_actions; //this tell if OnAction have to be forwarded to scripts, now its true by default, only high framerate actions are ignored bool filterOut = true; m_checkZoom = false; const CGameActions& actions = g_pGame->Actions(); IVehicle* pVehicle = m_pPlayer->GetLinkedVehicle(); bool canMove = CanMove(); // disable movement while standing up if (!canMove) m_deltaMovement.zero(); // try to dispatch action to OnActionHandlers bool handled; { FRAME_PROFILER("New Action Processing", GetISystem(), PROFILE_GAME); handled = s_actionHandler.Dispatch(this, m_pPlayer->GetEntityId(), actionId, activationMode, value, filterOut); } { FRAME_PROFILER("Regular Action Processing", GetISystem(), PROFILE_GAME); if (!handled) { filterOut = true; if (!m_pPlayer->m_stats.spectatorMode) { if (actions.ulammo==actionId && m_pPlayer->m_pGameFramework->CanCheat() && gEnv->pSystem->IsDevMode()) { g_pGameCVars->i_unlimitedammo = 1; } else if (actions.debug_ag_step == actionId) { gEnv->pConsole->ExecuteString("ag_step"); } else if(actions.voice_chat_talk == actionId) { if(gEnv->bMultiplayer) { if(activationMode == eAAM_OnPress) g_pGame->GetIGameFramework()->EnableVoiceRecording(true); else if(activationMode == eAAM_OnRelease) g_pGame->GetIGameFramework()->EnableVoiceRecording(false); } } } } if (!m_pPlayer->m_stats.spectatorMode) { IInventory* pInventory = m_pPlayer->GetInventory(); if (!pInventory) return; bool scope = false; EntityId itemId = pInventory->GetCurrentItem(); CWeapon *pWeapon = 0; if (itemId) { pWeapon = m_pPlayer->GetWeapon(itemId); if (pWeapon) { scope = (pWeapon->IsZoomed() && pWeapon->GetMaxZoomSteps()>1); } } if (pVehicle) { if (m_pPlayer->m_pVehicleClient && !m_pPlayer->IsFrozen()) m_pPlayer->m_pVehicleClient->OnAction(pVehicle, m_pPlayer->GetEntityId(), actionId, activationMode, value); //FIXME:not really good m_actions = 0; m_deltaMovement.Set(0,0,0); } else if (m_pPlayer->GetHealth() > 0 && !m_pPlayer->m_stats.isFrozen.Value() && !m_pPlayer->m_stats.inFreefall.Value() && !m_pPlayer->m_stats.isOnLadder && !m_pPlayer->m_stats.isStandingUp && m_pPlayer->GetGameObject()->GetAspectProfile(eEA_Physics)!=eAP_Sleep) { m_pPlayer->CActor::OnAction(actionId, activationMode, value); if ((!scope || actionId == actions.use)) { COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if (pOffHand) { pOffHand->OnAction(m_pPlayer->GetEntityId(), actionId, activationMode, value); } if ((!pWeapon || !pWeapon->IsMounted())) { if ((actions.drop==actionId) && itemId) { float impulseScale=1.0f; if (activationMode==eAAM_OnPress) m_buttonPressure=2.5f; if (activationMode==eAAM_OnRelease) { m_buttonPressure=CLAMP(m_buttonPressure, 0.0f, 2.5f); impulseScale=1.0f+(1.0f-m_buttonPressure/2.5f)*15.0f; if (m_pPlayer->DropItem(itemId, impulseScale, true) && pOffHand && pOffHand->IsSelected()) { if (EntityId fistsId = pInventory->GetItemByClass(CItem::sFistsClass)) { m_pPlayer->SelectItem(fistsId, false); } pOffHand->PreExecuteAction(eOHA_REINIT_WEAPON, eAAM_OnPress); CItem* pItem = static_cast<CItem*>(m_pPlayer->GetCurrentItem()); if (pItem) { pItem->SetActionSuffix("akimbo_"); pItem->PlayAction(g_pItemStrings->idle); } } } } else if (actions.nextitem==actionId) m_pPlayer->SelectNextItem(1, true, 0); else if (actions.previtem==actionId) m_pPlayer->SelectNextItem(-1, true, 0); else if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.debug==actionId) { if (g_pGame) { if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sDebugGunClass)) g_pGame->GetWeaponSystem()->DebugGun(0); if (!m_pPlayer->GetInventory()->GetItemByClass(CItem::sRefWeaponClass)) g_pGame->GetWeaponSystem()->RefGun(0); } m_pPlayer->SelectNextItem(1, true, actionId.c_str()); } } } else { if (actions.handgrenade==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.explosive==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.utility==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.small==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.medium==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.heavy==actionId) m_pPlayer->SelectNextItem(1, true, actionId.c_str()); else if (actions.drop==actionId && activationMode == eAAM_OnRelease && itemId) m_pPlayer->DropItem(itemId, 1.0f, true); } } if (m_checkZoom) { if (pWeapon) { IZoomMode *zm = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode()); CScreenEffects* pScreenEffects = m_pPlayer->GetScreenEffects(); if (zm && !zm->IsZoomingInOrOut() && !zm->IsZoomed() && pScreenEffects != 0) { if (!m_moveButtonState && m_pPlayer->IsClient()) { IBlendedEffect *fovEffect = CBlendedEffect<CFOVEffect>::Create(CFOVEffect(m_pPlayer->GetEntityId(),1.0f)); IBlendType *blend = CBlendType<CLinearBlend>::Create(CLinearBlend(1.0f)); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomIn, false); pScreenEffects->ResetBlendGroup(CScreenEffects::eSFX_GID_ZoomOut, false); pScreenEffects->StartBlend(fovEffect, blend, 1.0f/.25f, CScreenEffects::eSFX_GID_ZoomIn); } else { pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomIn); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_ZoomOut); pScreenEffects->EnableBlends(true, CScreenEffects::eSFX_GID_HitReaction); } } } } } } bool hudFilterOut = true; // FIXME: temporary method to dispatch Actions to HUD (it's not yet possible to register) hudFilterOut = true; //Filter must take into account offHand too COffHand* pOffHand = static_cast<COffHand*>(m_pPlayer->GetWeaponByClass(CItem::sOffHandClass)); if(pOffHand && pOffHand->IsSelected()) filterOut = false; //send the onAction to scripts, after filter the range of actions. for now just use and hold if (filterOut && hudFilterOut) { FRAME_PROFILER("Script Processing", GetISystem(), PROFILE_GAME); HSCRIPTFUNCTION scriptOnAction(NULL); IScriptTable *scriptTbl = m_pPlayer->GetEntity()->GetScriptTable(); if (scriptTbl) { scriptTbl->GetValue("OnAction", scriptOnAction); if (scriptOnAction) { char *activation = 0; switch(activationMode) { case eAAM_OnHold: activation = "hold"; break; case eAAM_OnPress: activation = "press"; break; case eAAM_OnRelease: activation = "release"; break; default: activation = ""; break; } Script::Call(gEnv->pScriptSystem,scriptOnAction,scriptTbl,actionId.c_str(),activation, value); } } gEnv->pScriptSystem->ReleaseFunc(scriptOnAction); } }
void CFlashUICheckAccessoryState ::ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if(event == eFE_Activate && IsPortActive(pActInfo, 0)) { IActor* pActor = GetInputActor( pActInfo ); bool is_equipped = false; bool is_inInventory = false; if(pActor) { IInventory* pInventory = pActor->GetInventory(); if(pInventory) { IEntityClassRegistry *pRegistry = gEnv->pEntitySystem->GetClassRegistry(); //Find the accessory's class in the registry const string accessory_name = GetPortString(pActInfo, eI_Accessory); IEntityClass* pClass = pRegistry->FindClass(accessory_name); //Check if its in inventory if(pInventory->HasAccessory(pClass) != 0) { is_inInventory = true; } //if it is, check if its equipped as well if(is_inInventory) { //Get the weapon ID via the Input string const char* weapon_name = GetPortString(pActInfo, eI_Weapon).c_str(); EntityId item = pInventory->GetItemByClass(pRegistry->FindClass(weapon_name)); //Fetch the actual weapon via the ID IEntity* pEntity = gEnv->pEntitySystem->GetEntity(item); if(pEntity) { CGameObject * pGameObject = (CGameObject*)pEntity->GetProxy(ENTITY_PROXY_USER); const char* ext = pGameObject->GetEntity()->GetClass()->GetName(); CWeapon* pWeapon = (CWeapon*)pGameObject->QueryExtension(pGameObject->GetEntity()->GetClass()->GetName()); bool selectable = pWeapon->CanSelect(); if(pWeapon) { if(pWeapon->GetAccessory(pClass->GetName()) != 0) { is_equipped = true; } } } } } } if(!is_inInventory) ActivateOutput(pActInfo, eO_DontHave, true); else if(is_equipped) ActivateOutput(pActInfo, eO_Equipped, true); else ActivateOutput(pActInfo, eO_InInventory, true); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { switch (event) { case eFE_Initialize: { m_actInfo = *pActInfo; Reset(); } break; case eFE_Activate: { IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); // create listener if (IsPortActive(pActInfo, IN_DISABLE)) { Reset(); } if (IsPortActive(pActInfo, IN_ENABLE)) { Reset(); IItem* pItem = 0; EntityId weaponId = GetPortEntityId(pActInfo, IN_WEAPONID); if (weaponId != 0) { pItem = pItemSys->GetItem(weaponId); } else { IActor* pActor = CCryAction::GetCryAction()->GetClientActor(); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const string& weaponClass = GetPortString(pActInfo, IN_WEAPONCLASS); if (!weaponClass.empty()) { // get actor weapon by class IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(weaponClass); pItem = pItemSys->GetItem( pInventory->GetItemByClass(pClass) ); } else { // get current actor weapon pItem = pItemSys->GetItem(pInventory->GetCurrentItem()); } } if (!pItem || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponListener: no item/weapon."); return; } m_weapId = pItem->GetEntity()->GetId(); IWeapon* pWeapon = pItem->GetIWeapon(); // set initial ammo m_ammo = GetPortInt(pActInfo, IN_AMMO); if (m_ammo == 0) m_ammo = -1; // 0 input means infinite // set weapon listener pWeapon->AddEventListener(this, "CFlowNode_WeaponListener"); m_active = true; //CryLog("WeaponListener successfully created on %s", pItem->GetEntity()->GetName()); } break; } } }