//------------------------------------------------------------------ void CLam::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory, const char *setup) { if(gEnv->bServer && m_lamparams.giveExtraAccessory) { CActor *pActor=GetActor(pickerId); if (pActor && pActor->IsPlayer()) { IInventory *pInventory=GetActorInventory(pActor); if (pInventory) { if (!m_lamparams.isLamRifle && !pInventory->HasAccessory(CItem::sLAMFlashLight) && gEnv->bMultiplayer) m_pItemSystem->GiveItem(pActor, m_lamparams.extraAccessoryName.c_str(), false, false, false); else if(m_lamparams.isLamRifle && !pInventory->HasAccessory(CItem::sLAMRifleFlashLight) && gEnv->bMultiplayer) m_pItemSystem->GiveItem(pActor, m_lamparams.extraAccessoryName.c_str(), false, false, false); } } } //FIX-ME!! //Scout beam needs to go into the inventory like a normal item, not accessory static IEntityClass* pBeamClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass("ScoutSearchBeam"); if(GetEntity()->GetClass()==pBeamClass) CItem::PickUp(pickerId,sound,select,keepHistory,setup); else CAccessory::PickUp(pickerId,sound,select,keepHistory,setup); }
bool CJaw::CanPickUp(EntityId userId) const { CActor *pActor = GetActor(userId); IInventory *pInventory=GetActorInventory(pActor); if (m_sharedparams->params.pickable && m_stats.pickable && !m_stats.flying && (!m_owner.GetId() || m_owner.GetId()==userId) && !m_stats.selected && !GetEntity()->IsHidden()) { if (pInventory && pInventory->FindItem(GetEntityId())!=-1) return false; } else return false; if(GetAmmoCount(m_fm->GetAmmoType())<=0) { return false; } uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName()); int maxNumRockets = GetWeaponSharedParams()->ammoParams.capacityAmmo[0].count; if(pInventory && (pInventory->GetCountOfUniqueId(uniqueId)>=maxNumRockets)) { if(pActor->IsClient()) { SHUDEventWrapper::DisplayInfo(eInfo_Warning, 0.5f, "@mp_CannotCarryMoreLAW"); } return false; } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CItem, SvRequestAttachAccessory) { if (IInventory *pInventory=GetActorInventory(GetOwnerActor())) { char accessoryName[129] = {0}; bool result = g_pGame->GetIGameFramework()->GetNetworkSafeClassName(accessoryName, 128, params.accessoryClassId); #if !defined(_RELEASE) if(!result) { char errorMsg[256]; sprintf(errorMsg, "CItem::SvRequestAttachAccessory failed to find network safe class name for id %d", params.accessoryClassId); CRY_ASSERT_MESSAGE(result, errorMsg); } #endif if (accessoryName[0] != '\0' && pInventory->GetCountOfClass(accessoryName)>0) { DoSwitchAccessory(accessoryName); GetGameObject()->InvokeRMI(ClAttachAccessory(), params, eRMI_ToAllClients|eRMI_NoLocalCalls); return true; } } return true; // set this to false later }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CItem, SvRequestDetachAccessory) { if (IInventory *pInventory=GetActorInventory(GetOwnerActor())) { char accessoryName[129] = {0}; bool result = g_pGame->GetIGameFramework()->GetNetworkSafeClassName(accessoryName, 128, params.accessoryClassId); #if !defined(_RELEASE) if(!result) { char errorMsg[256]; sprintf(errorMsg, "CItem::SvRequestDetachAccessory failed to find network safe class name for id %d", params.accessoryClassId); CRY_ASSERT_MESSAGE(result, errorMsg); } #endif if (accessoryName[0] != '\0') { AttachAccessory(accessoryName, false, true, true); GetGameObject()->InvokeRMI(ClDetachAccessory(), params, eRMI_ToRemoteClients); return true; } } return true; }
//========================================= bool CRocketLauncher::CanPickUp(EntityId userId) const { CActor *pActor = GetActor(userId); IInventory *pInventory=GetActorInventory(pActor); if (m_sharedparams->params.pickable && m_stats.pickable && !m_stats.flying && !m_frozen &&(!m_ownerId || m_ownerId==userId) && !m_stats.selected && !GetEntity()->IsHidden()) { if (pInventory && pInventory->FindItem(GetEntityId())!=-1) return false; } else return false; uint8 uniqueId = m_pItemSystem->GetItemUniqueId(GetEntity()->GetClass()->GetName()); //Can not pick up a LAW while I have one already if(pInventory && (pInventory->GetCountOfUniqueId(uniqueId)>0)) { if(pActor->IsClient()) g_pGame->GetGameRules()->OnTextMessage(eTextMessageCenter, "@mp_CannotCarryMoreLAW"); return false; } return true; }
//------------------------------------------------------------------------ IMPLEMENT_RMI(CItem, SvRequestAttachAccessory) { if (IInventory *pInventory = GetActorInventory(GetOwnerActor())) { if (pInventory->GetCountOfClass(params.accessory.c_str()) > 0) { DoSwitchAccessory(params.accessory.c_str()); GetGameObject()->InvokeRMI(ClAttachAccessory(), params, eRMI_ToAllClients | eRMI_NoLocalCalls); return true; } } return true; // set this to false later }
//------------------------------------------------------------------------ CItem *CItem::GetAccessoryPlaceHolder(const ItemString &name) { IInventory *pInventory = GetActorInventory(GetOwnerActor()); if(!pInventory) return 0; IEntityClass *pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(name); int slotId = pInventory->FindNext(pClass, 0, -1, false); if(slotId >= 0) return static_cast<CItem *>(m_pItemSystem->GetItem(pInventory->GetItem(slotId))); return 0; }
//------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------- void CPlayerFeature::DualSOCOM(CActor *pActor) { if(pActor && !pActor->IsPlayer()) { IInventory *pInventory=GetActorInventory(pActor); if (pInventory) { if (IsServer()) { m_pItemSystem->GiveItem(pActor, "SOCOM", false, false,false); //m_pItemSystem->SetActorItem(pActor,"SOCOM",true); } } } }
//------------------------------------------------------------------------ void CC4::PickUp(EntityId pickerId, bool sound, bool select/* =true */, bool keepHistory/* =true */, const char *setup /*= NULL*/) { CActor *pActor=GetActor(pickerId); if (pActor) { IInventory *pInventory=GetActorInventory(pActor); if (pInventory) { if (!pInventory->GetItemByClass(CItem::sDetonatorClass)) { if (IsServer()) m_pItemSystem->GiveItem(pActor, "Detonator", false, false, false); } } } CWeapon::PickUp(pickerId, sound, select, keepHistory, setup); }
//------------------------------------------------------------------------ void CAmmoPickup::PickUp(EntityId pickerId, bool sound, bool select, bool keepHistory) { if(!CheckAmmoRestrictions(pickerId)) return; SetOwnerId(pickerId); CActor *pActor=GetActor(pickerId); if (!pActor) return; IInventory *pInventory = GetActorInventory(pActor); if (!pInventory) return; if (IsServer()) { // bonus ammo is always put in the actor's inv if (!m_bonusammo.empty()) { for (TAmmoMap::iterator it=m_bonusammo.begin(); it!=m_bonusammo.end(); ++it) { int count=it->second; SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count); if(pActor->IsPlayer()) { ShouldSwitchGrenade(it->first); OnIncendiaryAmmoPickedUp(it->first,count); } } m_bonusammo.clear(); } for (TAmmoMap::iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it) { int count=it->second; SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count); if(pActor->IsPlayer()) { ShouldSwitchGrenade(it->first); OnIncendiaryAmmoPickedUp(it->first,count); } } if (!m_ammoName.empty() && m_ammoCount) { IEntityClass* pClass = gEnv->pEntitySystem->GetClassRegistry()->FindClass(m_ammoName.c_str()); SetInventoryAmmoCount(pClass, GetInventoryAmmoCount(pClass)+m_ammoCount); if(pActor->IsPlayer()) { ShouldSwitchGrenade(pClass); OnIncendiaryAmmoPickedUp(pClass,m_ammoCount); } } TriggerRespawn(); } //Play sound if(!m_pickup_sound.empty()) { IEntity *pPicker = m_pEntitySystem->GetEntity(pickerId); if(pPicker) { IEntitySoundProxy* pSoundProxy = (IEntitySoundProxy*)pPicker->GetProxy(ENTITY_PROXY_SOUND); if(pSoundProxy) { //Execute sound at picker position pSoundProxy->PlaySound(m_pickup_sound, pPicker->GetWorldPos(),FORWARD_DIRECTION, FLAG_SOUND_DEFAULT_3D, eSoundSemantic_Weapon); } } } RemoveEntity(); }
//------------------------------------------------------------------------ void CWeapon::OnPickedUp(EntityId actorId, bool destroyed) { BROADCAST_WEAPON_EVENT(OnPickedUp, (this, actorId, destroyed)); CItem::OnPickedUp(actorId, destroyed); GetEntity()->SetFlags(GetEntity()->GetFlags() | ENTITY_FLAG_NO_PROXIMITY); GetEntity()->SetFlags(GetEntity()->GetFlags() & ~ENTITY_FLAG_ON_RADAR); if(GetISystem()->IsSerializingFile() == 1) return; if(!IsServer()) return; CActor *pActor=GetActor(actorId); if(!pActor) return; // bonus ammo is always put in the actor's inv if(!m_bonusammo.empty()) { for(TAmmoMap::iterator it=m_bonusammo.begin(); it!=m_bonusammo.end(); ++it) { int count=it->second; SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count); } m_bonusammo.clear(); } if(!m_ammoCapacity.empty()) { IInventory *pInventory = GetActorInventory(GetOwnerActor()); if(pInventory) { for(TAmmoMap::iterator it=m_ammoCapacity.begin(); it!=m_ammoCapacity.end(); ++it) pInventory->SetAmmoCapacity(it->first, it->second); } m_ammoCapacity.clear(); } // current ammo is only added to actor's inv, if we already have this weapon if(destroyed && m_sharedparams->params.unique) { for(TAmmoMap::iterator it=m_ammo.begin(); it!=m_ammo.end(); ++it) { //Only add ammo to inventory, if not accessory ammo (accessories give ammo already) if(m_accessoryAmmo.find(it->first)==m_accessoryAmmo.end()) { int count=it->second; SetInventoryAmmoCount(it->first, GetInventoryAmmoCount(it->first)+count); } } } if(!gEnv->bMultiplayer && !m_initialSetup.empty() && pActor->IsClient()) { for(TAccessoryMap::iterator it=m_accessories.begin(); it!=m_accessories.end(); ++it) FixAccessories(GetAccessoryParams(it->first), true); } m_expended_ammo = 0; }
//------------------------------------------------------------------------ void CWeapon::OnPickedUp(EntityId actorId, bool destroyed) { BROADCAST_WEAPON_EVENT(OnPickedUp, (this, actorId, destroyed)); BaseClass::OnPickedUp(actorId, destroyed); GetEntity()->SetFlags(GetEntity()->GetFlags() | ENTITY_FLAG_NO_PROXIMITY); // bonus ammo is always put in the actor's inv if (!m_bonusammo.empty()) { for (TAmmoVector::iterator it = m_bonusammo.begin(); it != m_bonusammo.end(); ++it) { const SWeaponAmmo& currentBonusAmmo = *it; SetInventoryAmmoCount(currentBonusAmmo.pAmmoClass, GetInventoryAmmoCount(currentBonusAmmo.pAmmoClass)+currentBonusAmmo.count); } m_bonusammo.clear(); } if(GetISystem()->IsSerializingFile() == 1) return; CActor *pActor = GetActor(actorId); if (!pActor) return; // current ammo is only added to actor's inv, if we already have this weapon if (destroyed && m_sharedparams->params.unique) { for (TAmmoVector::iterator it = m_ammo.begin(); it!=m_ammo.end(); ++it) { //Only add ammo to inventory, if not accessory ammo (accessories give ammo already) const SWeaponAmmo& currentAmmo = *it; const SWeaponAmmo* pAccessoryAmmo = SWeaponAmmoUtils::FindAmmo(m_weaponsharedparams->ammoParams.accessoryAmmo, currentAmmo.pAmmoClass); if(pAccessoryAmmo != NULL) { SetInventoryAmmoCount(currentAmmo.pAmmoClass, GetInventoryAmmoCount(currentAmmo.pAmmoClass)+currentAmmo.count); } } } TestClipAmmoCountIsValid(); if (!gEnv->bServer && pActor->IsPlayer()) { IEntityClass* pCurrentAmmoClass = m_fm ? m_fm->GetAmmoType() : NULL; if (pCurrentAmmoClass) { //server has serialised the inventory count already if(IInventory* pInventory = GetActorInventory(GetOwnerActor())) { if(m_lastRecvInventoryAmmo > pInventory->GetAmmoCapacity(pCurrentAmmoClass)) { pInventory->SetAmmoCapacity(pCurrentAmmoClass, m_lastRecvInventoryAmmo); } SetInventoryAmmoCountInternal(pInventory, pCurrentAmmoClass, m_lastRecvInventoryAmmo); } } } if(gEnv->bMultiplayer) { HighlightWeapon(false); } m_expended_ammo = 0; }