giftbox_base.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. class GiftBox_Base extends Container_Base
  2. {
  3. protected vector m_HalfExtents; // The Y value contains a heightoffset and not the halfextent !!!
  4. protected ref OpenableBehaviour m_Openable;
  5. void GiftBox_Base()
  6. {
  7. m_HalfExtents = vector.Zero;
  8. m_Openable = new OpenableBehaviour(false);
  9. RegisterNetSyncVariableBool("m_Openable.m_IsOpened");
  10. }
  11. override bool CanReceiveItemIntoCargo(EntityAI item)
  12. {
  13. if (!super.CanReceiveItemIntoCargo(item))
  14. return false;
  15. if (GameInventory.GetInventoryCheckContext() == InventoryCheckContext.DEFAULT)
  16. {
  17. if (!GetGame().IsDedicatedServer())
  18. return IsOpen();
  19. }
  20. return true;
  21. }
  22. override void Open()
  23. {
  24. m_Openable.Open();
  25. SetSynchDirty();
  26. }
  27. override void Close()
  28. {
  29. m_Openable.Close();
  30. SetSynchDirty();
  31. }
  32. override bool IsOpen()
  33. {
  34. return m_Openable.IsOpened();
  35. }
  36. override void SetActions()
  37. {
  38. super.SetActions();
  39. AddAction(ActionUnpackGift);
  40. }
  41. override void OnDebugSpawn()
  42. {
  43. EntityAI entity;
  44. if (Class.CastTo(entity, this))
  45. {
  46. entity.GetInventory().CreateInInventory("Chemlight_Green");
  47. }
  48. }
  49. override void EEHealthLevelChanged(int oldLevel, int newLevel, string zone)
  50. {
  51. super.EEHealthLevelChanged(oldLevel,newLevel,zone);
  52. if (newLevel == GameConstants.STATE_RUINED && GetGame().IsServer())
  53. {
  54. MiscGameplayFunctions.DropAllItemsInInventoryInBounds(this, m_HalfExtents);
  55. DeleteSafe();
  56. }
  57. }
  58. }
  59. class GiftBox_Small extends GiftBox_Base {}
  60. class GiftBox_Medium extends GiftBox_Base {}
  61. class GiftBox_Large extends GiftBox_Base {}