Beispiel #1
0
//------------------------------------------------------------------------
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);

}
// 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 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;
	}
}
// 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;
}