bot_testattachanddropcycle.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. class BotEventEntityAttached : BotEventBase { };
  2. class BotEventEntityDetached : BotEventBase { };
  3. class BotTestAttachAndDropCycle extends BotStateBase
  4. {
  5. EntityAI m_Entity;
  6. ref BotTestAttachAndDropCycle_Detaching m_Detaching;
  7. ref BotTestAttachAndDropCycle_Attaching m_Attaching;
  8. void BotTestAttachAndDropCycle (Bot bot = NULL, BotStateBase parent = NULL)
  9. {
  10. // setup nested state machine
  11. m_FSM = new BotFSM(this); // @NOTE: set owner of the submachine fsm
  12. m_Detaching = new BotTestAttachAndDropCycle_Detaching(m_Bot, this);
  13. m_Attaching = new BotTestAttachAndDropCycle_Attaching(m_Bot, this);
  14. // events
  15. BotEventBase __EntAtt__ = new BotEventEntityAttached;
  16. BotEventBase __EntDet__ = new BotEventEntityDetached;
  17. // transitions
  18. m_FSM.AddTransition(new BotTransition( m_Detaching, __EntDet__, m_Attaching));
  19. m_FSM.AddTransition(new BotTransition( m_Attaching, __EntAtt__, m_Detaching));
  20. m_FSM.SetInitialState(m_Detaching);
  21. }
  22. override void OnEntry (BotEventBase e)
  23. {
  24. m_Entity = m_Owner.GetInventory().CreateAttachment("TaloonBag_Orange");
  25. m_Detaching.m_Entity = m_Entity;
  26. m_Attaching.m_Entity = m_Entity;
  27. super.OnEntry(e);
  28. }
  29. override void OnExit (BotEventBase e)
  30. {
  31. m_Entity = null;
  32. super.OnExit(e);
  33. }
  34. override void OnUpdate (float dt)
  35. {
  36. super.OnUpdate(dt);
  37. }
  38. };
  39. class BotTestAttachAndDropCycle_Detaching extends BotStateBase
  40. {
  41. EntityAI m_Entity;
  42. override void OnEntry (BotEventBase e)
  43. {
  44. super.OnEntry(e);
  45. }
  46. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  47. override void OnExit (BotEventBase e)
  48. {
  49. super.OnExit(e);
  50. }
  51. override void OnUpdate (float dt)
  52. {
  53. if (m_Entity)
  54. {
  55. botDebugPrint("[bot] + " + m_Owner + " drop item=" + m_Entity + " bot=" + m_Owner);
  56. m_Owner.PredictiveDropEntity(m_Entity);
  57. InventoryLocation loc = new InventoryLocation;
  58. if (m_Entity.GetInventory().GetCurrentInventoryLocation(loc))
  59. {
  60. if (loc.GetType() == InventoryLocationType.GROUND)
  61. {
  62. m_Bot.ProcessEvent(new BotEventEntityDetached(m_Owner, m_Entity));
  63. }
  64. }
  65. }
  66. }
  67. };
  68. class BotTestAttachAndDropCycle_Attaching extends BotStateBase
  69. {
  70. EntityAI m_Entity;
  71. override void OnEntry (BotEventBase e)
  72. {
  73. super.OnEntry(e);
  74. }
  75. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  76. override void OnExit (BotEventBase e)
  77. {
  78. super.OnExit(e);
  79. }
  80. override void OnUpdate (float dt)
  81. {
  82. if (m_Entity)
  83. {
  84. botDebugPrint("[bot] + " + m_Owner + " att item=" + m_Entity + " bot=" + m_Owner);
  85. if (m_Owner.GetInventory().CanAddAttachment(m_Entity))
  86. {
  87. m_Owner.PredictiveTakeEntityAsAttachment(m_Entity);
  88. InventoryLocation loc = new InventoryLocation;
  89. if (m_Entity.GetInventory().GetCurrentInventoryLocation(loc))
  90. {
  91. if (loc.GetType() == InventoryLocationType.ATTACHMENT)
  92. {
  93. m_Bot.ProcessEvent(new BotEventEntityAttached(m_Owner, m_Entity));
  94. }
  95. }
  96. }
  97. }
  98. }
  99. };