BVB Source Codes

CRYENGINE Show ScriptBind_ItemSystem.cpp Source code

Return Download CRYENGINE: download ScriptBind_ItemSystem.cpp Source code - Download CRYENGINE Source code - Type:.cpp
  1. // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
  2.  
  3. /*************************************************************************
  4.    -------------------------------------------------------------------------
  5.    $Id$
  6.    $DateTime$
  7.  
  8.    -------------------------------------------------------------------------
  9.    History:
  10.    - 30:9:2004   14:22 : Created by M谩rcio Martins
  11.  
  12. *************************************************************************/
  13. #include "StdAfx.h"
  14. #include "ItemSystem.h"
  15. #include "IActorSystem.h"
  16. #include "ScriptBind_ItemSystem.h"
  17. #include <CryPhysics/IPhysics.h>
  18.  
  19. //------------------------------------------------------------------------
  20. CScriptBind_ItemSystem::CScriptBind_ItemSystem(ISystem* pSystem, CItemSystem* pItemSystem, IGameFramework* pGameFramework)
  21.         : m_pItemSystem(pItemSystem),
  22.         m_pGameFramework(pGameFramework)
  23. {
  24.         Init(pSystem->GetIScriptSystem(), pSystem);
  25.         SetGlobalName("ItemSystem");
  26.  
  27.         RegisterGlobals();
  28.         RegisterMethods();
  29.  
  30.         m_pEquipmentManager = static_cast<CEquipmentManager*>(pItemSystem->GetIEquipmentManager());
  31. }
  32.  
  33. //------------------------------------------------------------------------
  34. CScriptBind_ItemSystem::~CScriptBind_ItemSystem()
  35. {
  36. }
  37.  
  38. //------------------------------------------------------------------------
  39. int CScriptBind_ItemSystem::Reset(IFunctionHandler* pH)
  40. {
  41.         return pH->EndFunction();
  42. }
  43.  
  44. //------------------------------------------------------------------------
  45. int CScriptBind_ItemSystem::GiveItem(IFunctionHandler* pH, const char* itemName)
  46. {
  47.         EntityId actorId = 0;
  48.         if (pH->GetParamType(2) == svtPointer)
  49.         {
  50.                 ScriptHandle sh;
  51.                 pH->GetParam(2, sh);
  52.                 actorId = (EntityId)sh.n;
  53.         }
  54.         else if (pH->GetParamType(2) == svtString)
  55.         {
  56.                 const char* name = 0;
  57.                 pH->GetParam(2, name);
  58.                 if (name)
  59.                 {
  60.                         IEntity* pEntity = gEnv->pEntitySystem->FindEntityByName(name);
  61.                         actorId = pEntity->GetId();
  62.                 }
  63.         }
  64.  
  65.         bool sound = true;
  66.         if (pH->GetParamCount() > 2 && (pH->GetParamType(3) == svtNumber || pH->GetParamType(3) == svtBool))
  67.                 pH->GetParam(3, sound);
  68.  
  69.         bool selectItem = true;
  70.         if (pH->GetParamCount() > 3 && (pH->GetParamType(4) == svtBool))
  71.         {
  72.                 pH->GetParam(4, selectItem);
  73.         }
  74.  
  75.         IActor* pActor = 0;
  76.         if (actorId)
  77.                 pActor = m_pGameFramework->GetIActorSystem()->GetActor(actorId);
  78.         else
  79.                 pActor = m_pGameFramework->GetClientActor();
  80.  
  81.         if (pActor)
  82.         {
  83.                 ScriptHandle result(m_pItemSystem->GiveItem(pActor, itemName, sound, selectItem));
  84.                 if (result.n)
  85.                         return pH->EndFunction(result);
  86.         }
  87.  
  88.         return pH->EndFunction();
  89. }
  90.  
  91. //------------------------------------------------------------------------
  92. int CScriptBind_ItemSystem::SetActorItem(IFunctionHandler* pH, ScriptHandle actorId, ScriptHandle itemId, bool keepHistory)
  93. {
  94.         IActor* pActor = m_pGameFramework->GetIActorSystem()->GetActor((EntityId)actorId.n);
  95.         if (pActor)
  96.                 m_pItemSystem->SetActorItem(pActor, (EntityId)itemId.n, keepHistory);
  97.  
  98.         return pH->EndFunction();
  99. }
  100.  
  101. //------------------------------------------------------------------------
  102. int CScriptBind_ItemSystem::SetActorItemByName(IFunctionHandler* pH, ScriptHandle actorId, const char* name, bool keepHistory)
  103. {
  104.         IActor* pActor = m_pGameFramework->GetIActorSystem()->GetActor((EntityId)actorId.n);
  105.         if (pActor)
  106.                 m_pItemSystem->SetActorItem(pActor, name, keepHistory);
  107.  
  108.         return pH->EndFunction();
  109. }
  110.  
  111. //------------------------------------------------------------------------
  112. int CScriptBind_ItemSystem::GiveItemPack(IFunctionHandler* pH, ScriptHandle actorId, const char* packName)
  113. {
  114.         bool bKeepOld = false;
  115.         bool bSelectPrimary = false;
  116.         if (pH->GetParamCount() > 2 && (pH->GetParamType(3) == svtNumber || pH->GetParamType(3) == svtBool))
  117.                 pH->GetParam(3, bKeepOld);
  118.         if (pH->GetParamCount() > 3 && (pH->GetParamType(4) == svtNumber || pH->GetParamType(4) == svtBool))
  119.                 pH->GetParam(4, bSelectPrimary);
  120.  
  121.         bool bOK = false;
  122.         IActor* pActor = m_pGameFramework->GetIActorSystem()->GetActor((EntityId)actorId.n);
  123.         if (pActor)
  124.                 bOK = m_pItemSystem->GetIEquipmentManager()->GiveEquipmentPack(pActor, packName, bKeepOld, bSelectPrimary);
  125.  
  126.         return pH->EndFunction(bOK);
  127. }
  128.  
  129. //------------------------------------------------------------------------
  130. int CScriptBind_ItemSystem::GetPackPrimaryItem(IFunctionHandler* pH, const char* packName)
  131. {
  132.         CEquipmentManager::SEquipmentPack* pPack = m_pEquipmentManager->GetPack(packName);
  133.  
  134.         if (pPack != 0)
  135.                 return pH->EndFunction(pPack->m_primaryItem.c_str());
  136.  
  137.         GameWarning("[EquipmentMgr] ItemSystem.GetPackPrimaryItem: Pack '%s' cannot be found.", packName);
  138.         return pH->EndFunction(false);
  139. }
  140.  
  141. //------------------------------------------------------------------------
  142. int CScriptBind_ItemSystem::GetPackNumItems(IFunctionHandler* pH, const char* packName)
  143. {
  144.         CEquipmentManager::SEquipmentPack* pPack = m_pEquipmentManager->GetPack(packName);
  145.  
  146.         if (pPack != 0)
  147.                 return pH->EndFunction(pPack->NumItems());
  148.  
  149.         GameWarning("[EquipmentMgr] ItemSystem.GetPackItemByIndex: Pack '%s' cannot be found.", packName);
  150.         return pH->EndFunction(0);
  151. }
  152.  
  153. //------------------------------------------------------------------------
  154. int CScriptBind_ItemSystem::GetPackItemByIndex(IFunctionHandler* pH, const char* packName, int index)
  155. {
  156.         CEquipmentManager::SEquipmentPack* pPack = m_pEquipmentManager->GetPack(packName);
  157.  
  158.         if (pPack != 0)
  159.         {
  160.                 const CEquipmentManager::SEquipmentPack::SEquipmentItem* pItem = pPack->GetItemByIndex(index);
  161.                 if (pItem)
  162.                         return pH->EndFunction(pItem->m_name.c_str());
  163.                 else
  164.                 {
  165.                         GameWarning("[EquipmentMgr] ItemSystem.GetPackItemByIndex: Index %d not valid. Pack '%s' has %d items.", index, packName, pPack->NumItems());
  166.                         return pH->EndFunction(false);
  167.                 }
  168.         }
  169.  
  170.         GameWarning("[EquipmentMgr] ItemSystem.GetPackItemByIndex: Pack '%s' cannot be found.", packName);
  171.         return pH->EndFunction(false);
  172. }
  173.  
  174. //------------------------------------------------------------------------
  175. void CScriptBind_ItemSystem::RegisterGlobals()
  176. {
  177. }
  178.  
  179. //------------------------------------------------------------------------
  180. int CScriptBind_ItemSystem::SerializePlayerLTLInfo(IFunctionHandler* pH, bool reading)
  181. {
  182.         m_pItemSystem->SerializePlayerLTLInfo(reading);
  183.         return pH->EndFunction(0);
  184. }
  185.  
  186. //------------------------------------------------------------------------
  187. void CScriptBind_ItemSystem::RegisterMethods()
  188. {
  189. #undef SCRIPT_REG_CLASSNAME
  190. #define SCRIPT_REG_CLASSNAME &CScriptBind_ItemSystem::
  191.  
  192.         SCRIPT_REG_TEMPLFUNC(Reset, "");
  193.         SCRIPT_REG_TEMPLFUNC(GiveItem, "itemName, [actorName]");
  194.         SCRIPT_REG_TEMPLFUNC(SetActorItem, "actorId, itemId, keepHistory");
  195.         SCRIPT_REG_TEMPLFUNC(SetActorItemByName, "actorId, name, keepHistory");
  196.         SCRIPT_REG_TEMPLFUNC(GiveItemPack, "actorId, packName, [keepOld]");
  197.         SCRIPT_REG_TEMPLFUNC(GetPackPrimaryItem, "packName");
  198.         SCRIPT_REG_TEMPLFUNC(GetPackNumItems, "packName");
  199.         SCRIPT_REG_TEMPLFUNC(GetPackItemByIndex, "packName, index");
  200.         SCRIPT_REG_TEMPLFUNC(SerializePlayerLTLInfo, "reading");
  201. }
  202.  
  203. //------------------------------------------------------------------------
  204.  
downloadScriptBind_ItemSystem.cpp Source code - Download CRYENGINE Source code
Related Source Codes/Software:
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top