void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate || event == eFE_Initialize) { if (IsPortActive(pActInfo, INP_ACTIVE)) { bool active = GetPortBool(pActInfo, 0); if (active) m_pGF->GetIItemSystem()->RegisterListener(this); else m_pGF->GetIItemSystem()->UnregisterListener(this); } if (IsPortActive(pActInfo, INP_CHECK)) { IActor* pActor = GetInputActor( pActInfo ); if (pActor) { IInventory* pInventory = pActor->GetInventory(); if (pInventory) { IEntity* pEntityItem = gEnv->pEntitySystem->GetEntity( pInventory->GetCurrentItem() ); TriggerOutputs( pActInfo, pEntityItem ); } } } } }
//------------------------------------------------------------------------ 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 ) { 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 ) { 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)) { 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 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 CFlowNode_AISequenceAction_WeaponDrawFromInventory::HandleSequenceEvent(AIActionSequence::SequenceEvent sequenceEvent) { switch(sequenceEvent) { case AIActionSequence::StartAction: { CRY_ASSERT_MESSAGE(m_actInfo.pEntity, "entity has magically gone"); if (!m_actInfo.pEntity) { // the entity has gone for some reason, at least make sure the action gets finished properly and the FG continues CancelSequenceAndActivateOutputPort(OutputPort_Done); return; } assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIActorSystem()); IActor* pActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(m_actInfo.pEntity->GetId()); if (!pActor) { CRY_ASSERT_MESSAGE(0, "Provided entity must be an IActor"); CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Provided entity %s must be an IActor", m_actInfo.pEntity->GetName()); CancelSequenceAndActivateOutputPort(OutputPort_Done); return; } assert(gEnv && gEnv->pGame && gEnv->pGame->GetIGameFramework() && gEnv->pGame->GetIGameFramework()->GetIItemSystem()); IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); IInventory* pInventory = pActor->GetInventory(); if (!pInventory) { CRY_ASSERT_MESSAGE(0, "Actor has no inventory"); CryWarning(VALIDATOR_MODULE_AI, VALIDATOR_WARNING, "Actor %s has no inventory", m_actInfo.pEntity->GetName()); CancelSequenceAndActivateOutputPort(OutputPort_Done); return; } pInventory->SetHolsteredItem(EntityId(0)); // otherwise trying to holster the new weapon later on will not work (i. e. will do nothing) // draw the weapon const string& weaponName = GetPortString(&m_actInfo, InputPort_WeaponName); pItemSystem->SetActorItem(pActor, weaponName.c_str(), false); FinishSequenceActionAndActivateOutputPort(OutputPort_Done); } break; } }
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) { pInventory->ResetAmmo(); const bool removeFromWeapons = GetPortBool(pActInfo, 1); if(removeFromWeapons) { IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem(); const size_t numItems = pInventory->GetCount(); for(size_t i=0; i<numItems; ++i) { const EntityId item = pInventory->GetItem(i); if(IItem* pItem = pItemSystem->GetItem(item)) { if(IWeapon* pWeapon = pItem->GetIWeapon()) { const size_t numFiremodes = pWeapon->GetNumOfFireModes(); for(size_t f=0; f<numFiremodes; ++f) { if(IFireMode* pFireMode = pWeapon->GetFireMode(f)) { if(IEntityClass* pAmmoType = pFireMode->GetAmmoType()) { pWeapon->SetAmmoCount(pAmmoType, 0); } } } } } } } ActivateOutput(pActInfo, 0, true); } else ActivateOutput(pActInfo, 0, false); } }
//-------------------------------------------- bool CAmmoPickup::CheckAmmoRestrictions(EntityId pickerId) { if(g_pGameCVars->i_unlimitedammo != 0) return true; if(gEnv->pSystem->IsEditor()) return true; IActor* pPicker = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId); if(pPicker) { IInventory *pInventory = pPicker->GetInventory(); if(pInventory) { for (TAmmoMap::const_iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it) { int invAmmo = pInventory->GetAmmoCount(it->first); int invLimit = pInventory->GetAmmoCapacity(it->first); if(invAmmo>=invLimit && (!gEnv->pSystem->IsEditor())) return false; } const char *ammoName=0; if (GetEntityProperty("AmmoName", ammoName) && ammoName && ammoName[0]) { int count=0; GetEntityProperty("Count", count); if (count) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoName); if(pClass) { int invAmmo = pInventory->GetAmmoCount(pClass); int invLimit = pInventory->GetAmmoCapacity(pClass); if(invAmmo>=invLimit) return false; } } } } } return true; }
void ProcessEvent(EFlowEvent event, SActivationInfo* pActInfo) { if (event == eFE_Activate && (IsPortActive(pActInfo, IN_GET) || IsPortActive(pActInfo, IN_SET))) { IActor* pActor = GetInputActor(pActInfo); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (pInventory) { const string& ammoType = GetPortString(pActInfo, IN_AMMOTYPE); IEntityClass* pAmmoClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(ammoType.c_str()); if (pAmmoClass) { if (IsPortActive(pActInfo, IN_SET)) { const bool bAdd = GetPortBool(pActInfo, IN_ADD); const int ammoAmount = GetPortInt(pActInfo, IN_AMMOCOUNT); pInventory->SetAmmoCount(pAmmoClass, bAdd ? (ammoAmount + pInventory->GetAmmoCount(pAmmoClass)) : (ammoAmount)); } int magazineAmmo = 0; int inventoryAmmo = pInventory->GetAmmoCount(pAmmoClass); if (IItem* pItem = pActor->GetCurrentItem()) { IWeapon* pCurrentWeapon = GetWeapon(pItem->GetEntityId()); if (pCurrentWeapon) { magazineAmmo = pCurrentWeapon->GetAmmoCount(pAmmoClass); } } ActivateOutput(pActInfo, OUT_MAGAZINE, magazineAmmo); ActivateOutput(pActInfo, OUT_INVENTORY, inventoryAmmo); ActivateOutput(pActInfo, OUT_TOTAL, (magazineAmmo + inventoryAmmo)); } } } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo,0)) { IGameFramework* pGF = 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; pInventory->RMIReqToServer_RemoveAllItems(); // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations ActivateOutput(pActInfo, 0, true); } }
void ProcessEvent( EFlowEvent event, SActivationInfo *pActInfo ) { if (event == eFE_Activate && IsPortActive(pActInfo, EIP_Trigger)) { IActor* pActor = GetInputActor( pActInfo ); if (!pActor) return; IInventory *pInventory = pActor->GetInventory(); if (!pInventory) return; const bool& addPack = GetPortBool(pActInfo, EIP_AddToggle); const string& packName = GetPortString(pActInfo, EIP_EquipmentPack); const bool& selectPrimary = GetPortBool(pActInfo, EIP_SelectPrimary); if (pActor->IsPlayer()) pInventory->RMIReqToServer_AddEquipmentPack( packName.c_str(), addPack, selectPrimary ); else { if (gEnv->bServer) CCryAction::GetCryAction()->GetIItemSystem()->GetIEquipmentManager()->GiveEquipmentPack( pActor, packName.c_str(), addPack, selectPrimary ); } // TODO: instant output activation, with delayed effective change in the inventory, it potentially could cause problems in rare situations ActivateOutput(pActInfo, EOP_Done, true); } else if (event == eFE_PrecacheResources) { const string& packName = GetPortString(pActInfo, 1); if (!packName.empty()) { IGameRules* pGameRules = CCryAction::GetCryAction()->GetIGameRulesSystem()->GetCurrentGameRules(); CRY_ASSERT_MESSAGE(pGameRules != NULL, "No game rules active, can not precache resources"); if (pGameRules) { pGameRules->PrecacheLevelResource(packName.c_str(), eGameResourceType_Loadout); } } } }
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 CJaw::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char* setup) { for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it) { SWeaponAmmo& currentBonusAmmo = *it; currentBonusAmmo.count = 0; } IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); IActor* pPicketActor = gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pickerId); IInventory* pInventory = pPicketActor->GetInventory(); bool giveExtraTube = GiveExtraTubeToInventory(pPicketActor, pItemSystem); if (pPicketActor->IsClient()) SetAmmoCount(m_fm->GetAmmoType(), 1); BaseClass::PickUp(pickerId,sound,select,keepHistory, setup); if (giveExtraTube) { int numJaws = m_weaponsharedparams->ammoParams.extraItems; while(numJaws-- > 0) { pItemSystem->GiveItem(pPicketActor, GetEntity()->GetClass()->GetName(), false, false, false); } m_extraTubesAdded = true; } if(m_auxSlotUsed) { DrawSlot(eIGS_ThirdPersonAux,false); m_auxSlotUsed = false; } if(GetOwnerActor() && !GetOwnerActor()->IsPlayer()) m_stats.first_selection = false; }
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); } }
void CHUDCrosshair::UpdateCrosshair() { IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); if(!pClientActor) return; int iNewFriendly = 0; if(pClientActor->GetLinkedVehicle()) { // JanM/MichaelR: // Get status from the VehicleWeapon, which raycasts considering the necessary SkipEntities (in contrast to WorldQuery) // Julien: this is now done in MP as well iNewFriendly = g_pHUD->GetVehicleInterface()->GetFriendlyFire(); } else { if(!gEnv->bMultiplayer) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { iNewFriendly = pWeapon->IsWeaponLowered() && pWeapon->IsPendingFireRequest(); if(iNewFriendly && pWeapon->GetEntity()->GetClass() == CItem::sTACGunFleetClass) iNewFriendly = 0; } else{ //Two handed pickups need the red X as well CPlayer *pPlayer= static_cast<CPlayer*>(pClientActor); if(CWeapon *pOffHand = static_cast<CWeapon*>(pPlayer->GetItemByClass(CItem::sOffHandClass))) iNewFriendly = pOffHand->IsWeaponLowered(); } } else { EntityId uiCenterId = pClientActor->GetGameObject()->GetWorldQuery()->GetLookAtEntityId(); if(uiCenterId) { iNewFriendly = IsFriendlyEntity(gEnv->pEntitySystem->GetEntity(uiCenterId)); } } } // SNH: if player is carrying a claymore or mine, ask the weapon whether it is possible to place it currently // (takes into account player speed / stance / aim direction). // So 'friendly' is a bit of a misnomer here, but we want the "don't/can't fire" crosshair... if(iNewFriendly != 1 && g_pHUD) { CWeapon *pWeapon = g_pHUD->GetCurrentWeapon(); if(pWeapon) { static IEntityClass* pClaymoreClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Claymore"); static IEntityClass* pAVMineClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("AVMine"); IEntityClass* pClass = pWeapon->GetEntity()->GetClass(); if(pClass == pClaymoreClass || pClass == pAVMineClass) { if(IFireMode* pfm = pWeapon->GetFireMode(pWeapon->GetCurrentFireMode())) { if(!pfm->IsFiring()) iNewFriendly = pWeapon->CanFire() ? 0 : 1; } } } } if(iNewFriendly != m_iFriendlyTarget) { m_iFriendlyTarget = iNewFriendly; //m_animCrossHair.Invoke("setFriendly", m_iFriendlyTarget); if(iNewFriendly) m_animFriendCross.SetVisible(true); else m_animFriendCross.SetVisible(false); } if(m_animInterActiveIcons.GetVisible()) { m_bHideUseIconTemp = false; CItem *pItem = static_cast<CItem*>(pClientActor->GetCurrentItem()); if(pItem) { IWeapon *pWeapon = pItem->GetIWeapon(); if(pWeapon) { CItem::SStats stats = pItem->GetStats(); if(stats.mounted && stats.used) m_bHideUseIconTemp = true; } } if(!m_bHideUseIconTemp) { EntityId offHandId = pClientActor->GetInventory()->GetItemByClass(CItem::sOffHandClass); IItem *pOffHandItem = g_pGame->GetIGameFramework()->GetIItemSystem()->GetItem(offHandId); if(pOffHandItem) { COffHand *pOffHand = static_cast<COffHand*>(pOffHandItem); uint32 offHandState = pOffHand->GetOffHandState(); if(offHandState == eOHS_HOLDING_OBJECT || offHandState == eOHS_THROWING_OBJECT || offHandState == eOHS_HOLDING_NPC || offHandState == eOHS_THROWING_NPC) m_bHideUseIconTemp = true; } } } }
//------------------------------------------------------------------------ bool CGameRules::OnInitiate(SHostMigrationInfo& hostMigrationInfo, uint32& state) { if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session)) { return true; } CryLog("[Host Migration]: CGameRules::OnInitiate() Saving character for host migration started"); m_hostMigrationClientHasRejoined = false; IEntityScriptProxy* pScriptProxy = static_cast<IEntityScriptProxy*>(GetEntity()->GetProxy(ENTITY_PROXY_SCRIPT)); if (pScriptProxy) { if (string(pScriptProxy->GetState()) == "InGame") { m_hostMigrationTimeSinceGameStarted = (m_cachedServerTime - m_gameStartedTime); } } HostMigrationStopAddingPlayers(); if (gEnv->IsClient()) { if (!m_pHostMigrationParams) { m_pHostMigrationParams = new SHostMigrationClientRequestParams(); m_pHostMigrationClientParams = new SHostMigrationClientControlledParams(); } IActor *pPlayer = g_pGame->GetIGameFramework()->GetClientActor(); if (pPlayer) { m_pHostMigrationClientParams->m_viewQuat = pPlayer->GetViewRotation(); m_pHostMigrationClientParams->m_position = pPlayer->GetEntity()->GetPos(); pe_status_living livStat; IPhysicalEntity *pPhysicalEntity = pPlayer->GetEntity()->GetPhysics(); if (pPhysicalEntity != NULL && (pPhysicalEntity->GetType() == PE_LIVING) && (pPhysicalEntity->GetStatus(&livStat) > 0)) { m_pHostMigrationClientParams->m_velocity = livStat.velUnconstrained; m_pHostMigrationClientParams->m_hasValidVelocity = true; CryLog(" velocity={%f,%f,%f}", m_pHostMigrationClientParams->m_velocity.x, m_pHostMigrationClientParams->m_velocity.y, m_pHostMigrationClientParams->m_velocity.z); } IInventory *pInventory = pPlayer->GetInventory(); m_pHostMigrationClientParams->m_numExpectedItems = 0; int numAmmoTypes = 0; m_pHostMigrationClientParams->m_pAmmoParams = new SHostMigrationClientControlledParams::SAmmoParams[numAmmoTypes]; m_pHostMigrationClientParams->m_numAmmoParams = numAmmoTypes; /*CryLog(" player has %i different ammo types", numAmmoTypes); for (int i = 0; i < numAmmoTypes; ++ i) { IEntityClass *pAmmoType = pInventory->GetAmmoType(i); int ammoCount = pInventory->GetAmmoCount(pAmmoType); m_pHostMigrationClientParams->m_pAmmoParams[i].m_pAmmoClass = pAmmoType; m_pHostMigrationClientParams->m_pAmmoParams[i].m_count = ammoCount; CryLog(" %s : %i", pAmmoType->GetName(), ammoCount); }* EntityId holseredItemId = pInventory->GetHolsteredItem(); if (holseredItemId) { IEntity *pHolsteredEntity = gEnv->pEntitySystem->GetEntity(holseredItemId); if (pHolsteredEntity) { m_pHostMigrationClientParams->m_pHolsteredItemClass = pHolsteredEntity->GetClass(); } }*/ IMovementController *pMovementController = pPlayer->GetMovementController(); if(pMovementController) { SMovementState movementState; pMovementController->GetMovementState(movementState); m_pHostMigrationClientParams->m_aimDirection = movementState.aimDirection; } /*CItem *pItem = static_cast<CItem*>(pPlayer->GetCurrentItem()); if (pItem) { m_pHostMigrationClientParams->m_pSelectedItemClass = pItem->GetEntity()->GetClass(); CryLog(" currently using item '%s", pItem->GetEntity()->GetName()); }*/ } else { CRY_ASSERT_MESSAGE(false, "Failed to find client actor when initiating a host migration"); gEnv->pNetwork->TerminateHostMigration(hostMigrationInfo.m_session); return false; } } g_pGame->SetHostMigrationState(CGame::eHMS_WaitingForPlayers); CCCPOINT(HostMigration_OnInitiate); return true; }
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 CHUDCrosshair::Update(float fDeltaTime) { if(m_bBroken) return; IActor *pClientActor = g_pGame->GetIGameFramework()->GetClientActor(); IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); if(!pClientActor || !pItemSystem) return; IInventory *pInventory = pClientActor->GetInventory(); if(!pInventory) return; IItem *pItem = pItemSystem->GetItem(pInventory->GetCurrentItem()); IWeapon *pWeapon = NULL; IWeapon *pSlaveWeapon = NULL; const float fAlternateIronSight = 0.03f; if(pItem) { pWeapon = pItem->GetIWeapon(); if(pItem->IsDualWieldMaster()) { if(IItem *pSlave=pItem->GetDualWieldSlave()) pSlaveWeapon = pSlave->GetIWeapon(); } } else if(IVehicle *pVehicle=pClientActor->GetLinkedVehicle()) { pItem = pItemSystem->GetItem(pVehicle->GetCurrentWeaponId(pClientActor->GetEntityId())); if(pItem) pWeapon = pItem->GetIWeapon(); } if(pWeapon) { float fMinSpread = 0.0f; float fMaxSpread = 0.0f; m_spread = 0.0f; if(IFireMode *pFireMode=pWeapon->GetFireMode(pWeapon->GetCurrentFireMode())) { fMinSpread = pFireMode->GetMinSpread(); fMaxSpread = pFireMode->GetMaxSpread(); m_spread = pFireMode->GetSpread(); } if(pSlaveWeapon) { if(IFireMode *pSlaveFireMode=pSlaveWeapon->GetFireMode(pSlaveWeapon->GetCurrentFireMode())) { fMinSpread += pSlaveFireMode->GetMinSpread(); fMaxSpread += pSlaveFireMode->GetMaxSpread(); m_spread += pSlaveFireMode->GetSpread(); } } CPlayer *pPlayer = static_cast<CPlayer*>(pClientActor); if(pPlayer && pPlayer->GetNanoSuit() && pPlayer->GetNanoSuit()->GetMode() == NANOMODE_STRENGTH) m_spread *=0.5; if(g_pGameCVars->hud_iAlternateCrosshairSpread) { if(m_spread < fMinSpread) m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch) / g_pGameCVars->hud_fAlternateCrosshairSpreadCrouch; else m_spread = min(m_spread,g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral) / g_pGameCVars->hud_fAlternateCrosshairSpreadNeutral; } else { m_spread = min((m_spread-fMinSpread),15.0f) / 15.0f; IZoomMode *pZoomMode = pWeapon->GetZoomMode(pWeapon->GetCurrentZoomMode()); if(pZoomMode && !pZoomMode->IsToggle() && (pZoomMode->IsZoomed() || pZoomMode->IsZooming())) { m_spread -= fAlternateIronSight; } else { m_spread = min(m_spread,1.0f); m_spread = max(m_spread,0.0f); } } } if(m_animCrossHair.GetVisible() && !g_pHUD->InSpectatorMode()) { //also disables the damage indicator if(/*g_pGameCVars->hud_crosshair>0 && m_iCrosshair > 0 &&*/ (g_pGameCVars->g_difficultyLevel<4 || gEnv->bMultiplayer)) { m_animCrossHair.GetFlashPlayer()->Advance(fDeltaTime); m_animCrossHair.GetFlashPlayer()->Render(); } if(m_animInterActiveIcons.GetVisible()) //if the crosshair is invisible, the use icon should be too { if(!m_bHideUseIconTemp) //hides the icon, when something is already grabbed/being used { m_animInterActiveIcons.GetFlashPlayer()->Advance(fDeltaTime); m_animInterActiveIcons.GetFlashPlayer()->Render(); } } } if(m_animFriendCross.GetVisible()) { m_animFriendCross.GetFlashPlayer()->Advance(fDeltaTime); m_animFriendCross.GetFlashPlayer()->Render(); } if(!g_pGameCVars->hud_iAlternateCrosshairSpread) { m_spread = max(m_spread,-fAlternateIronSight); m_spread = min(m_spread,1.0f); } if (m_smoothSpread != m_spread) { Interpolate(m_smoothSpread, m_spread, 20.0f, fDeltaTime); m_animCrossHair.Invoke("setRecoil", m_smoothSpread); } UpdateCrosshair(); }
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; } } }