//------------------------------------------------------------------------ void CInventory::Destroy() { // //CryLog("%s::CInventory::Destroy()",GetEntity()->GetName()); // if(!GetISystem()->IsSerializingFile()) { IEntitySystem *pEntitySystem = gEnv->pEntitySystem; IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); TInventoryVector deleteList = m_stats.slots; for (TInventoryIt it = deleteList.begin(); it != deleteList.end(); ++it) { EntityId entityId = *it; IItem *pItem = pItemSystem->GetItem(entityId); if (pItem) { RemoveItemFromCategorySlot(pItem->GetEntityId()); pItem->RemoveOwnerAttachedAccessories(); pItem->AttachToHand(false); pItem->AttachToBack(false); pItem->SetOwnerId(0); } pEntitySystem->RemoveEntity(entityId); } } Clear(); }
// RMI receiver in the server to remove all items from the inventory. changes are automatically propagated to the clients IMPLEMENT_RMI(CInventory, SvReq_RemoveAllItems) { IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem(); IItem* pItem = pItemSystem->GetItem( GetCurrentItem() ); if (pItem) { pItem->Select(false); pItemSystem->SetActorItem( GetActor(), (EntityId)0, false ); } Destroy(); if (gEnv->bMultiplayer) { TRMIInventory_Dummy Info; GetGameObject()->InvokeRMI( Cl_RemoveAllAmmo(), Info, eRMI_ToAllClients); } else { ResetAmmo(); } return true; }
void CAICorpse::AboutToBeRemoved() { IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); ICharacterInstance* pCharacter = GetEntity()->GetCharacter(0); IAttachmentManager* pAttachmentManager = (pCharacter != NULL) ? pCharacter->GetIAttachmentManager() : NULL; for (uint32 i = 0; i < (uint32)m_attachedItemsInfo.size(); ++i) { AttachedItem& attachedItem = m_attachedItemsInfo[i]; IItem* pItem = pItemSystem->GetItem( attachedItem.id ); if((pItem != NULL) && ShouldDropOnCorpseRemoval( pItem->GetEntity()->GetClass() )) { IAttachment* pAttachment = (pAttachmentManager != NULL) ? pAttachmentManager->GetInterfaceByName( attachedItem.attachmentName.c_str() ) : NULL; if(pAttachment != NULL) { pAttachment->ClearBinding(); } pItem->Drop( 1.0f, false, true ); pItem->GetEntity()->SetFlags( pItem->GetEntity()->GetFlags() & ~ENTITY_FLAG_NO_SAVE ); attachedItem.id = 0; } } }
//------------------------------------------------------------------------ int CInventory::GetCountOfCategory(const char *categoryName) const { IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); int count = 0; TInventoryCIt end = m_stats.slots.end(); for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it) { IItem *pItem = pItemSystem->GetItem(*it); if (pItem) { const char *cat = pItemSystem->GetItemCategory(pItem->GetEntity()->GetClass()->GetName()); if (!strcmp(cat, categoryName)) count++; } } TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end(); for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit) { const char *cat = pItemSystem->GetItemCategory((*cit)->GetName()); if (!strcmp(cat,categoryName)) count++; } return count; }
IAttachmentManager* CLaserBeam::GetLaserCharacterAttachmentManager() { IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); CItem* pOwnerItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId)); if (pOwnerItem) { IEntity* pAttachedEntity = pOwnerItem->GetEntity(); if(pOwnerItem->IsAccessory()) { EntityId parentId = pOwnerItem->GetParentId(); if(parentId) { if(IEntity* pParentEnt = gEnv->pEntitySystem->GetEntity(parentId)) { pAttachedEntity = pParentEnt; } } } if (ICharacterInstance *pCharacter = pAttachedEntity->GetCharacter(eIGS_FirstPerson)) { return pCharacter->GetIAttachmentManager(); } } return NULL; }
//------------------------------------------------------------------------ int CInventory::GetCountOfUniqueId(uint8 uniqueId) const { //Skip uniqueId 0 if(!uniqueId) return 0; IItemSystem *pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); int count = 0; TInventoryCIt end = m_stats.slots.end(); for (TInventoryCIt it = m_stats.slots.begin(); it != end; ++it) { IItem *pItem = pItemSystem->GetItem(*it); if (pItem) { uint8 id = pItemSystem->GetItemUniqueId(pItem->GetEntity()->GetClass()->GetName()); if (id==uniqueId) count++; } } TInventoryVectorEx::const_iterator endEx = m_stats.accessorySlots.end(); for (TInventoryVectorEx::const_iterator cit = m_stats.accessorySlots.begin(); cit!=endEx; ++cit) { uint8 id = pItemSystem->GetItemUniqueId((*cit)->GetName()); if (id==uniqueId) count++; } return count; }
void Serialize(SActivationInfo* pActInfo, TSerialize ser) { ser.Value("active", m_active); ser.Value("ammo", m_ammo); ser.Value("weaponId", m_weapId); if (ser.IsReading()) { if (m_active && m_weapId != 0) { IItemSystem* pItemSys = CCryAction::GetCryAction()->GetIItemSystem(); IItem* pItem = pItemSys->GetItem(m_weapId); if (!pItem || !pItem->GetIWeapon()) { GameWarning("[flow] CFlowNode_WeaponListener: Serialize no item/weapon."); return; } IWeapon* pWeapon = pItem->GetIWeapon(); // set weapon listener pWeapon->AddEventListener(this, "CFlowNode_WeaponListener"); // CryLog("[flow] CFlowNode_WeaponListener::Serialize() successfully created on '%s'", pItem->GetEntity()->GetName()); } else { Reset(); } } }
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 CReplayItemList::OnActionControllerDeleted() { IItemSystem* pItemSys = g_pGame->GetIGameFramework()->GetIItemSystem(); TItemVec::const_iterator end = m_items.end(); for(TItemVec::const_iterator it = m_items.begin(); it!=end; ++it) { if(IItem* pItem = pItemSys->GetItem(*it)) { pItem->UpdateCurrentActionController(); } } m_items.clear(); }
//------------------------------------------------------------------------ void CInventory::Clear(bool forceClear) { if(m_ignoreNextClear && !forceClear) { m_ignoreNextClear = false; return; } if(!gEnv->bServer) { IItemSystem* pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); TInventoryIt end = m_stats.slots.end(); for(TInventoryIt it = m_stats.slots.begin(); it != end; ++it) { if(IItem* pItem = pItemSystem->GetItem(*it)) { pItem->RemoveOwnerAttachedAccessories(); pItem->AttachToHand(false); pItem->AttachToBack(false); pItem->SetOwnerId(0); pItem->GetEntity()->Hide(true); } } } m_stats.slots.clear(); m_stats.accessorySlots.clear(); ResetAmmoAndUsers(); for (int i = 0; i < IInventory::eInventorySlot_Last; ++i) { m_stats.slotsInfo[i].Reset(); } m_stats.currentItemId = 0; m_stats.holsteredItemId = 0; m_stats.lastItemId = 0; TListenerVec::iterator iter = m_listeners.begin(); m_iteratingListeners = true; while (iter != m_listeners.end()) { (*iter)->OnClearInventory(); ++iter; } m_iteratingListeners = false; }
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); } }
//------------------------------------------------------------------------------ void CWeapon::ToggleFlashLight() { static IEntityClass* pFlashLightClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("Flashlight"); IGameFramework* pGameFramework = g_pGame->GetIGameFramework(); IItemSystem* pItemSystem = pGameFramework->GetIItemSystem(); for (size_t i = 0; i < m_accessories.size(); ++i) { if (m_accessories[i].pClass == pFlashLightClass) { IItem* pItem = pItemSystem->GetItem(m_accessories[i].accessoryId); CFlashLight* pFlashLight = static_cast<CFlashLight*>(pItem); pFlashLight->ToggleFlashLight(); break; } } }
// RMI receiver in the server to remove an item from the inventory. change is automatically propagated to the clients IMPLEMENT_RMI(CInventory, SvReq_RemoveItem) { TRMIInventory_Item Info(params); IItemSystem* pItemSystem = CCryAction::GetCryAction()->GetIItemSystem(); IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass( Info.m_ItemClass.c_str()); if (pClass) { IItem* pItem = pItemSystem->GetItem( GetItemByClass( pClass ) ); if (pItem && pItem->GetEntityId()==GetCurrentItem()) { pItem->Select(false); pItemSystem->SetActorItem( GetActor(), (EntityId)0, false ); } if (pItem) gEnv->pEntitySystem->RemoveEntity( pItem->GetEntityId() ); } return true; }
void CAICorpse::SetupFromSource( IEntity& sourceEntity, ICharacterInstance& characterInstance, const uint32 priority) { // 1.- Move resources from source entity, into AICorpse GetEntity()->SetFlags(GetEntity()->GetFlags() | (ENTITY_FLAG_CASTSHADOW)); sourceEntity.MoveSlot(GetEntity(), 0); // Moving everything from one slot into another will also clear the render proxies in the source. // Thus, we need to invalidate the model so that it will be properly reloaded when a non-pooled // entity is restored from a save-game. CActor* sourceActor = static_cast<CActor*>(gEnv->pGame->GetIGameFramework()->GetIActorSystem()->GetActor(sourceEntity.GetId())); if (sourceActor != NULL) { sourceActor->InvalidateCurrentModelName(); } // 2.- After 'MoveSlot()', characterInstance is now stored inside CAICorpse // It needs to be now updated from the entity system characterInstance.SetFlags( characterInstance.GetFlags() | CS_FLAG_UPDATE ); #if AI_CORPSES_ENABLE_SERIALIZE m_modelName = characterInstance.GetFilePath(); #endif // 3.- Search for any attached weapon and clone them IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); IAttachmentManager* pAttachmentManager = characterInstance.GetIAttachmentManager(); const uint32 attachmentCount = (uint32)pAttachmentManager->GetAttachmentCount(); for(uint32 i = 0; i < attachmentCount ; ++i) { IAttachment* pAttachment = pAttachmentManager->GetInterfaceByIndex(i); assert(pAttachment != NULL); IAttachmentObject* pAttachmentObject = pAttachment->GetIAttachmentObject(); if((pAttachmentObject == NULL) || (pAttachmentObject->GetAttachmentType() != IAttachmentObject::eAttachment_Entity)) continue; const EntityId attachedEntityId = static_cast<CEntityAttachment*>(pAttachmentObject)->GetEntityId(); IItem* pItem = pItemSystem->GetItem(attachedEntityId); if(pItem != NULL) { if(AllowCloneAttachedItem( pItem->GetEntity()->GetClass() )) { if(m_attachedItemsInfo.size() < m_attachedItemsInfo.max_size()) { AttachedItem attachedItemInfo; attachedItemInfo.pClass = pItem->GetEntity()->GetClass(); attachedItemInfo.attachmentName = pAttachment->GetName(); attachedItemInfo.id = CloneAttachedItem( attachedItemInfo, pAttachment ); m_attachedItemsInfo.push_back(attachedItemInfo); } } } } //Only accept requested priority if it has attached weapons m_priority = (m_attachedItemsInfo.size() > 0) ? priority : 0; //Force physics to sleep immediately (if not already) IPhysicalEntity* pCorpsePhysics = GetEntity()->GetPhysics(); if(pCorpsePhysics != NULL) { pe_action_awake awakeAction; awakeAction.bAwake = 0; pCorpsePhysics->Action( &awakeAction ); } }
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; } } }
void CLaserBeam::UpdateLaser(const CLaserBeam::SLaserUpdateDesc& laserUpdateDesc) { if(m_pLaserParams && m_laserOn) { IEntity* pLaserEntity = CreateLaserEntity(); if (pLaserEntity) { m_lastLaserUpdatePosition = laserUpdateDesc.m_laserPos; m_lastLaserUpdateDirection = laserUpdateDesc.m_laserDir; m_laserUpdateTimer += laserUpdateDesc.m_frameTime; UpdateLaserGeometry(*pLaserEntity); if(m_laserUpdateTimer < LASER_UPDATE_TIME) return; m_laserUpdateTimer = Random(0.0f, LASER_UPDATE_TIME * 0.4f); if ((laserUpdateDesc.m_ownerCloaked && !laserUpdateDesc.m_weaponZoomed) || laserUpdateDesc.m_bOwnerHidden) { pLaserEntity->Hide(true); return; } pLaserEntity->Hide(false); const float range = m_pLaserParams->laser_range[GetIndexFromGeometrySlot()]; // Use the same flags as the AI system uses for visbility. const int objects = ent_terrain|ent_static|ent_rigid|ent_sleeping_rigid|ent_independent; //ent_living; const int flags = (geom_colltype_ray << rwi_colltype_bit) | rwi_colltype_any | (10 & rwi_pierceability_mask) | (geom_colltype14 << rwi_colltype_bit); //If we did not get a result, just cancel it, we will queue a new one again RayCastRequest::Priority requestPriority = RayCastRequest::MediumPriority; if (m_queuedRayId != 0) { g_pGame->GetRayCaster().Cancel(m_queuedRayId); m_queuedRayId = 0; requestPriority = RayCastRequest::HighPriority; } IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); IPhysicalEntity* pSkipEntity = NULL; uint8 numSkips = 0; CItem* pItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId)); if(pItem) { if(pItem->IsAccessory()) { CItem* pParentItem = static_cast<CItem*>(pItemSystem->GetItem(pItem->GetParentId())); if(pParentItem) { pItem = pParentItem; } } IEntity* pOwnerEnt = 0; CWeapon* pWeapon = static_cast<CWeapon*>(pItem->GetIWeapon()); if (pWeapon && pWeapon->GetHostId() != 0) { pOwnerEnt = gEnv->pEntitySystem->GetEntity(pWeapon->GetHostId()); } else { pOwnerEnt = pItem->GetOwner(); } if(pOwnerEnt) { IPhysicalEntity* pOwnerPhysics = pOwnerEnt->GetPhysics(); if(pOwnerPhysics) { pSkipEntity = pOwnerPhysics; numSkips++; } } } m_queuedRayId = g_pGame->GetRayCaster().Queue( requestPriority, RayCastRequest(laserUpdateDesc.m_laserPos, laserUpdateDesc.m_laserDir*range, objects, flags, &pSkipEntity, numSkips), functor(*this, &CLaserBeam::OnRayCastDataReceived)); } } else if (!m_pLaserParams) { GameWarning("LASER PARAMS: Item of type CLaser is missing it's laser params!"); } }
void CLaserBeam::FixAttachment(IEntity* pLaserEntity) { m_usingEntityAttachment = false; IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); CItem* pOwnerItem = static_cast<CItem*>(pItemSystem->GetItem(m_ownerEntityId)); if (pOwnerItem) { IEntity* pOwnerEntity = pOwnerItem->GetEntity(); IEntity* pAttachedEntity = pOwnerEntity; const char* attach_helper = "laser_term"; Vec3 offset = pOwnerItem->GetSlotHelperPos(m_geometrySlot, attach_helper, false); if(m_geometrySlot == eIGS_FirstPerson) { if(pOwnerItem->IsAccessory()) { EntityId parentId = pOwnerItem->GetParentId(); if(parentId) { if(CItem* pParentItem = static_cast<CItem*>(pItemSystem->GetItem(parentId))) { const SAccessoryParams* pParams = pParentItem->GetAccessoryParams(pAttachedEntity->GetClass()); attach_helper = pParams->attach_helper.c_str(); pAttachedEntity = pParentItem->GetEntity(); } } } if(pAttachedEntity) { ICharacterInstance *pCharacter = pAttachedEntity->GetCharacter(eIGS_FirstPerson); if (pCharacter) { IAttachmentManager *pAttachmentManager = pCharacter->GetIAttachmentManager(); IAttachment *pLaserAttachment = pAttachmentManager->GetInterfaceByName(LASER_ATTACH_NAME); if(!pLaserAttachment) { IAttachment *pAttachment = pAttachmentManager->GetInterfaceByName(attach_helper); if(pAttachment) { const char* pBone = pCharacter->GetICharacterModel()->GetICharacterModelSkeleton()->GetJointNameByID(pAttachment->GetJointID()); pLaserAttachment = pAttachmentManager->CreateAttachment(LASER_ATTACH_NAME, CA_BONE, pBone); if(pLaserAttachment) { QuatT relative = pAttachment->GetAttRelativeDefault(); if(pOwnerItem->GetEntity() != pAttachedEntity) { Matrix34 mtx(relative); relative.t = relative * offset; } pLaserAttachment->SetAttRelativeDefault(relative); } } } if(pLaserAttachment) { CEntityAttachment* pEntAttach = new CEntityAttachment; pEntAttach->SetEntityId(m_laserEntityId); pLaserAttachment->AddBinding(pEntAttach); pLaserAttachment->HideAttachment(0); m_usingEntityAttachment = true; } } } } if(!m_usingEntityAttachment && pOwnerEntity) { pOwnerEntity->AttachChild(pLaserEntity); pLaserEntity->SetLocalTM(Matrix34::CreateTranslationMat(offset)); } } }
//------------------------------------------------------------------------ bool CGameRules::OnPromoteToServer(SHostMigrationInfo& hostMigrationInfo, uint32& state) { if (!g_pGame->GetIGameFramework()->ShouldMigrateNub(hostMigrationInfo.m_session)) { return true; } CryLogAlways("[Host Migration]: CGameRules::OnPromoteToServer() started"); // Server time will change after we migrate (change from old server time to new server time) m_gameStartedTime.SetValue(m_gameStartedTime.GetValue() - m_cachedServerTime.GetValue()); m_gameStartTime.SetValue(m_gameStartTime.GetValue() - m_cachedServerTime.GetValue()); // If this migration has reset (we're not the original anticipated host, remove any entities from the first attempt if (!m_hostMigrationCachedEntities.empty()) { HostMigrationRemoveDuplicateDynamicEntities(); } // Now we know we're the server, remove the actors for anyone we know isn't going to migrate CGameLobby *pGameLobby = g_pGame->GetGameLobby(); CRY_ASSERT(pGameLobby); if (pGameLobby) { TPlayers playersToRemove; IActorSystem *pActorSystem = g_pGame->GetIGameFramework()->GetIActorSystem(); playersToRemove.reserve(pActorSystem->GetActorCount()); IActorIteratorPtr actorIt = pActorSystem->CreateActorIterator(); IActor *pActor; while (pActor = actorIt->Next()) { if (pActor->IsPlayer()) { CRY_ASSERT(pActor->GetChannelId()); SCryMatchMakingConnectionUID conId = pGameLobby->GetConnectionUIDFromChannelID((int) pActor->GetChannelId()); if (pGameLobby->GetSessionNames().Find(conId) == SSessionNames::k_unableToFind) { CryLog(" player '%s' has not got a corresponding CGameLobby entry, removing actor", pActor->GetEntity()->GetName()); playersToRemove.push_back(pActor->GetEntityId()); } } } const int numPlayersToRemove = playersToRemove.size(); for (int i = 0; i < numPlayersToRemove; ++ i) { FakeDisconnectPlayer(playersToRemove[i]); } } for (uint32 i = 0; i < MAX_PLAYERS; ++ i) { m_migratedPlayerChannels[i] = 0; } IItemSystem *pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); IEntityItPtr it = gEnv->pEntitySystem->GetEntityIterator(); it->MoveFirst(); for (uint32 i = 0; i < m_hostMigrationItemMaxCount; ++ i) { m_pHostMigrationItemInfo[i].Reset(); } uint32 itemIndex = 0; IEntity *pEntity = NULL; while (pEntity = it->Next()) { IItem *pItem = pItemSystem->GetItem(pEntity->GetId()); if (pItem) { if (pItem->GetOwnerId()) { IEntity *pOwner = gEnv->pEntitySystem->GetEntity(pItem->GetOwnerId()); if (pOwner) { EntityId currentItemId = 0; IActor *pOwnerActor = g_pGame->GetIGameFramework()->GetIActorSystem()->GetActor(pOwner->GetId()); if (pOwnerActor) { IItem *pCurrentItem = pOwnerActor->GetCurrentItem(); currentItemId = pCurrentItem ? pCurrentItem->GetEntityId() : 0; } CryLog("[CG] Item '%s' is owned by '%s'", pEntity->GetName(), pOwner->GetName()); //m_pHostMigrationItemInfo[itemIndex].Set(pEntity->GetId(), pOwner->GetId(), pItem->IsUsed(), (pItem->GetEntityId() == currentItemId)); itemIndex ++; if (itemIndex >= m_hostMigrationItemMaxCount) { CRY_ASSERT(itemIndex < m_hostMigrationItemMaxCount); break; } } } } // Tell entities that we're host migrating // - Currently only used by ForbiddenArea but may well be needed for other entities later // - Currently only called on the new server, add to OnDemoteToClient if we need to use this on a client IScriptTable *pScript = pEntity->GetScriptTable(); if (pScript != NULL && pScript->GetValueType("OnHostMigration") == svtFunction) { m_pScriptSystem->BeginCall(pScript, "OnHostMigration"); m_pScriptSystem->PushFuncParam(pScript); m_pScriptSystem->PushFuncParam(true); m_pScriptSystem->EndCall(); } } // This needs initialising on the new server otherwise the respawn timer will be counting down // from uninitialised data. Likewise for the pre-round timer. ResetReviveCycleTime(); const int numRespawnParams = m_respawndata.size(); for (int i = 0; i < numRespawnParams; ++ i) { SEntityRespawnData *pData = &m_respawndata[i]; pEntity = gEnv->pEntitySystem->GetEntity(pData->m_currentEntityId); if (pEntity == NULL) { CryLog(" detected respawn entity (id=%u) is not present, scheduling for respawn", pData->m_currentEntityId); ScheduleEntityRespawn(pData->m_currentEntityId, false, g_pGameCVars->g_defaultItemRespawnTimer); } } CryLog("[Host Migration]: CGameRules::OnPromoteToServer() finished"); CCCPOINT(HostMigration_OnPromoteToServer); return true; }
virtual void ProcessEvent( EFlowEvent event,SActivationInfo *pActInfo ) { IVehicleSystem * pVehicleSystem = NULL; IVehicle * pVehicle = NULL; switch(event) { case eFE_Initialize: { pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, false); break; } case eFE_Activate: { if (!pActInfo->pEntity) return; pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem(); pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId()); if (!pVehicleSystem || !pVehicle) return; string givenString = GetPortString(pActInfo, IN_PARTS); currentParam = givenString.substr(0,givenString.find_first_of(":")); currentSetting = givenString.substr(givenString.find_first_of(":")+1,(givenString.length()-givenString.find_first_of(":"))); column1 = 10.f; column2 = 100.f; if (IsPortActive(pActInfo,IN_SHOW)) pActInfo->pGraph->SetRegularlyUpdated(pActInfo->myID, true); break; } case eFE_Update: { IRenderer * pRenderer = gEnv->pRenderer; pVehicleSystem = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem(); pVehicle = pVehicleSystem->GetVehicle(pActInfo->pEntity->GetId()); if(!pVehicleSystem || !pActInfo->pEntity || !pVehicle) return; pRenderer->Draw2dLabel(column1,10,GetPortFloat(pActInfo,IN_SIZE)+2.f,Col_Cyan,false,pActInfo->pEntity->GetName()); if(currentParam=="Seats") { loops = 0; for(uint32 i=0;i<pVehicle->GetSeatCount();i++) { IVehicleSeat * currentSeat; if(currentSetting=="All") { currentSeat = pVehicle->GetSeatById(i+1); } else { currentSeat = pVehicle->GetSeatById(pVehicle->GetSeatId(currentSetting)); i = pVehicle->GetSeatCount()-1; } loops += 1; // column 1 string pMessage = ("%s:", currentSeat->GetSeatName()); if (column2<pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessage.size()*8*GetPortFloat(pActInfo, IN_SIZE); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage); // column 2 if(currentSeat->GetPassenger(true)) { pMessage = ("- %s", gEnv->pEntitySystem->GetEntity(currentSeat->GetPassenger(true))->GetName()); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessage); } } } else if(currentParam=="Wheels") { pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"!"); } else if(currentParam=="Weapons") { loops = 0; for(int i=0;i<pVehicle->GetWeaponCount();i++) { IItemSystem * pItemSystem = gEnv->pGame->GetIGameFramework()->GetIItemSystem(); IWeapon * currentWeapon; EntityId currentEntityId; IItem * pItem; if(currentSetting=="All") { currentEntityId = pVehicle->GetWeaponId(i+1); } else { currentEntityId = gEnv->pEntitySystem->FindEntityByName(currentSetting)->GetId(); i = pVehicle->GetWeaponCount()-1; } if(!pItemSystem->GetItem(currentEntityId)) return; pItem = pItemSystem->GetItem(currentEntityId); currentWeapon = pItem->GetIWeapon(); loops += 1; // column 1 string pMessageName = string().Format("%s", gEnv->pEntitySystem->GetEntity(currentEntityId)->GetName()); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("seat: %s firemode: %i", pVehicle->GetWeaponParentSeat(currentEntityId)->GetSeatName(), currentWeapon->GetCurrentFireMode()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),Col_Cyan,false,pMessageValue); } } else if(currentParam=="Components") { loops = 0; for(int i=0;i<pVehicle->GetComponentCount();i++) { IVehicleComponent * currentComponent; if(currentSetting=="All") { currentComponent = pVehicle->GetComponent(i); } else { currentComponent = pVehicle->GetComponent(currentSetting); i = pVehicle->GetComponentCount()-1; } loops += 1; ColorF labelColor; labelColor = ColorF(currentComponent->GetDamageRatio(),(1.f-currentComponent->GetDamageRatio()),0.f); // column 1 string pMessageName = string().Format("%s", currentComponent->GetComponentName()).c_str(); pRenderer->Draw2dLabel(column1,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageName); if (column2<pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE)) column2=pMessageName.size()*8*GetPortFloat(pActInfo, IN_SIZE); // column 2 string pMessageValue = string().Format("%5.2f (%3.2f)", currentComponent->GetDamageRatio()*currentComponent->GetMaxDamage(), currentComponent->GetDamageRatio()).c_str(); pRenderer->Draw2dLabel(column2,(15*(float(loops+1))*GetPortFloat(pActInfo,IN_SIZE)),GetPortFloat(pActInfo,IN_SIZE),labelColor,false,pMessageValue); } } else { pRenderer->Draw2dLabel(column1,50.f,GetPortFloat(pActInfo,IN_SIZE)+1.f,Col_Red,false,"no component selected!"); } break; } } };
//------------------------------------------------------------------------ int CScriptBind_Item::OnUsed(IFunctionHandler *pH, ScriptHandle userId) { CItem *pItem = GetItem(pH); if (!pItem) return pH->EndFunction(); CActor *pActor = GetActor((EntityId)userId.n); if (!pActor) return pH->EndFunction(); if (pItem->CanUse((EntityId)userId.n)) { if(IEntity* pParent = pItem->GetEntity()->GetParent()) { IVehicle* pVehicle = gEnv->pGame->GetIGameFramework()->GetIVehicleSystem()->GetVehicle(pParent->GetId()); if(pVehicle) { CPlayer* pPlayer = static_cast<CPlayer*>(pActor); IInteractor* pInteractor = pPlayer->GetInteractor(); return pH->EndFunction( pVehicle->OnUsed((EntityId)userId.n, pInteractor->GetOverSlotIdx()) ); } } pActor->UseItem(pItem->GetEntityId()); return pH->EndFunction(true); } else if (pItem->CanPickUp((EntityId)userId.n)) { //Should be always the client... if (pActor->IsClient()) { CPlayer* pClientPlayer = static_cast<CPlayer*>(pActor); const SInteractionInfo& interactionInfo = pClientPlayer->GetCurrentInteractionInfo(); bool expectedItem = (interactionInfo.interactiveEntityId == pItem->GetEntityId()); bool expectedInteraction = (interactionInfo.interactionType == eInteraction_PickupItem) || (interactionInfo.interactionType == eInteraction_ExchangeItem); if (!expectedItem || !expectedInteraction) { return pH->EndFunction(); } if (interactionInfo.interactionType == eInteraction_ExchangeItem) { IItemSystem* pItemSystem = g_pGame->GetIGameFramework()->GetIItemSystem(); CItem* pCurrentItem = static_cast<CItem*>(pActor->GetCurrentItem()); CItem* pExchangeItem = static_cast<CItem*>(pItemSystem->GetItem(interactionInfo.swapEntityId)); if (pExchangeItem && pCurrentItem) pExchangeItem->ScheduleExchangeToNextItem(pActor, pItem, pCurrentItem); } else { pActor->PickUpItem(pItem->GetEntityId(), true, true); } } else { pActor->PickUpItem(pItem->GetEntityId(), true, true); } return pH->EndFunction(true); } return pH->EndFunction(); }