bot_testitemmovebackandforth.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. class BotTestItemMoveBackAndForth extends BotStateBase
  2. {
  3. EntityAI m_Entity;
  4. ref BotTestItemMoveBackAndForth_MoveFromSlotToSlot m_Move;
  5. void BotTestItemMoveBackAndForth (Bot bot = NULL, BotStateBase parent = NULL)
  6. {
  7. // setup nested state machine
  8. m_FSM = new BotFSM(this); // @NOTE: set owner of the submachine fsm
  9. m_Move = new BotTestItemMoveBackAndForth_MoveFromSlotToSlot(m_Bot, this);
  10. // events
  11. BotEventBase __EntAtt__ = new BotEventEntityAttached;
  12. // transitions
  13. m_FSM.AddTransition(new BotTransition( m_Move, __EntAtt__, m_Move));
  14. m_FSM.SetInitialState(m_Move);
  15. }
  16. override void OnEntry (BotEventBase e)
  17. {
  18. //m_Entity = m_Owner.GetInventory().CreateAttachment("TaloonBag_Orange");
  19. //m_Entity = m_Owner.GetInventory().FindAttachment();
  20. EntityAI hgear = m_Owner.GetInventory().FindAttachment( InventorySlots.GetSlotIdFromString("Headgear") );
  21. EntityAI mask = m_Owner.GetInventory().FindAttachment( InventorySlots.GetSlotIdFromString("Mask") );
  22. if (hgear)
  23. m_Entity = hgear;
  24. if (mask)
  25. m_Entity = mask;
  26. InventoryLocation loc = new InventoryLocation;
  27. if (m_Entity.GetInventory().GetCurrentInventoryLocation(loc))
  28. {
  29. m_Move.m_WaitingForSlot = loc.GetSlot();
  30. }
  31. else
  32. Error("EE");
  33. m_Move.m_Entity = m_Entity;
  34. super.OnEntry(e);
  35. }
  36. override void OnExit (BotEventBase e)
  37. {
  38. m_Entity = null;
  39. super.OnExit(e);
  40. }
  41. override void OnUpdate (float dt)
  42. {
  43. super.OnUpdate(dt);
  44. }
  45. };
  46. class BotTestItemMoveBackAndForth_MoveFromSlotToSlot extends BotStateBase
  47. {
  48. EntityAI m_Entity;
  49. int m_WaitingForSlot = InventorySlots.INVALID;
  50. int m_hgSlot = InventorySlots.GetSlotIdFromString("Headgear");
  51. int m_mskSlot = InventorySlots.GetSlotIdFromString("Mask");
  52. override void OnEntry (BotEventBase e)
  53. {
  54. super.OnEntry(e);
  55. }
  56. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  57. override void OnExit (BotEventBase e)
  58. {
  59. super.OnExit(e);
  60. }
  61. int GetNextSlot (int curr)
  62. {
  63. if (curr == m_hgSlot)
  64. return m_mskSlot;
  65. if (curr == m_mskSlot)
  66. return m_hgSlot;
  67. Error("EE2");
  68. return InventorySlots.INVALID;
  69. }
  70. override void OnUpdate (float dt)
  71. {
  72. if (m_Entity)
  73. {
  74. botDebugPrint("[bot] + " + m_Owner + " move item=" + m_Entity);
  75. InventoryLocation loc = new InventoryLocation;
  76. if (m_Entity.GetInventory().GetCurrentInventoryLocation(loc))
  77. {
  78. if (loc.GetType() == InventoryLocationType.ATTACHMENT)
  79. {
  80. if (loc.GetSlot() == m_WaitingForSlot)
  81. {
  82. int nextSlot = GetNextSlot(m_WaitingForSlot);
  83. botDebugPrint("[bot] + " + m_Owner + " will switch slot=" + nextSlot + " for item=" + m_Entity);
  84. m_WaitingForSlot = nextSlot;
  85. m_Owner.PredictiveTakeEntityAsAttachmentEx(m_Entity, nextSlot);
  86. //m_Bot.ProcessEvent(new BotEventEntityDet(m_Owner, m_Entity));
  87. }
  88. }
  89. }
  90. }
  91. }
  92. };