bot_testspawnandopencan.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. class BotEventEntityInHands : BotEventBase { };
  2. class BotSpawnEntityInHands extends BotStateBase
  3. {
  4. string m_Type;
  5. void BotSpawnEntityInHands (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  6. {
  7. if (new_type == string.Empty)
  8. m_Type = "TunaCan";
  9. else
  10. m_Type = new_type;
  11. }
  12. override void OnEntry (BotEventBase e)
  13. {
  14. super.OnEntry(e);
  15. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  16. {
  17. m_Owner.GetHumanInventory().CreateInHands(m_Type);
  18. }
  19. }
  20. override void OnExit (BotEventBase e) { super.OnExit(e); }
  21. override void OnUpdate (float dt)
  22. {
  23. super.OnUpdate(dt);
  24. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  25. if (inHands)
  26. {
  27. botDebugPrint("[bot] + " + m_Owner + " hand item=" + inHands + " bot=" + m_Owner);
  28. m_Bot.ProcessEvent(new BotEventEntityInHands(m_Owner, inHands));
  29. }
  30. }
  31. };
  32. class BotEventEntityInHandsOpened : BotEventBase { };
  33. class BotOpenEntityInHands extends BotStateBase
  34. {
  35. EntityAI m_Entity;
  36. override void OnEntry (BotEventBase e)
  37. {
  38. super.OnEntry(e);
  39. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  40. {
  41. BotEventEntityInHands ev_ih = BotEventEntityInHands.Cast(e);
  42. if (ev_ih)
  43. {
  44. m_Entity = ev_ih.m_Entity;
  45. Edible_Base b = Edible_Base.Cast(m_Entity);
  46. if (b)
  47. {
  48. botDebugPrint("[bot] + " + m_Owner + " will open edible item=" + b + " bot=" + m_Owner);
  49. b.Open();
  50. }
  51. }
  52. }
  53. }
  54. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  55. override void OnExit (BotEventBase e)
  56. {
  57. super.OnExit(e);
  58. }
  59. override void OnUpdate (float dt)
  60. {
  61. super.OnUpdate(dt);
  62. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  63. botDebugSpam("[bot] + " + m_Owner + " wait for opened item inHands=" + inHands + " bot=" + m_Owner);
  64. if (inHands)
  65. {
  66. string t_str = inHands.GetType();
  67. //string t_str = t.ToString();
  68. if (t_str.IndexOf("_Opened") != -1)
  69. {
  70. botDebugPrint("[bot] + " + m_Owner + " opened item=" + inHands + " bot=" + m_Owner);
  71. m_Bot.ProcessEvent(new BotEventEntityInHandsOpened(m_Owner, inHands));
  72. }
  73. }
  74. }
  75. };
  76. class Bot_TestSpawnOpen extends BotStateBase
  77. {
  78. string m_Type;
  79. ref BotSpawnEntityInHands m_Spawning;
  80. ref BotOpenEntityInHands m_Opening;
  81. void Bot_TestSpawnOpen (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  82. {
  83. m_Type = new_type;
  84. // setup nested state machine
  85. m_FSM = new BotFSM(this); // @NOTE: set owner of the submachine fsm
  86. m_Spawning = new BotSpawnEntityInHands(m_Bot, this);
  87. m_Opening = new BotOpenEntityInHands(m_Bot, this);
  88. // events
  89. BotEventBase __EntInH__ = new BotEventEntityInHands;
  90. // transitions
  91. m_FSM.AddTransition(new BotTransition( m_Spawning, __EntInH__, m_Opening));
  92. //m_FSM.AddTransition(new BotTransition( m_Opening, __EntAtt__, m_Eating));
  93. //m_FSM.AddTransition(new BotTransition( m_Eating, __EntAtt__, m_Eating));
  94. m_FSM.SetInitialState(m_Spawning);
  95. }
  96. override void OnEntry (BotEventBase e) { super.OnEntry(e); }
  97. override void OnExit (BotEventBase e) { super.OnExit(e); }
  98. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  99. };
  100. class BotEventHandsEmpty : BotEventBase { };
  101. class BotWaitForEmptyHands extends BotStateBase
  102. {
  103. override void OnEntry (BotEventBase e) { super.OnEntry(e); }
  104. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  105. override void OnExit (BotEventBase e) { super.OnExit(e); }
  106. override void OnUpdate (float dt)
  107. {
  108. super.OnUpdate(dt);
  109. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  110. botDebugSpam("[bot] + " + m_Owner + " waiting for empty hands, inHands=" + inHands + " bot=" + m_Owner);
  111. if (!inHands)
  112. {
  113. botDebugPrint("[bot] + " + m_Owner + " hand slot empty. bot=" + m_Owner);
  114. m_Bot.ProcessEvent(new BotEventHandsEmpty(m_Owner, inHands));
  115. }
  116. }
  117. };
  118. class BotWaitForChangeInHands extends BotStateBase
  119. {
  120. /*override void OnExit (BotEventBase e)
  121. {
  122. super.OnExit(e);
  123. m_Bot.ProcessEvent(new BotEventEndOK(m_Owner));
  124. }*/
  125. };
  126. class BotDropEntityInHands extends BotWaitForChangeInHands
  127. {
  128. EntityAI m_Entity;
  129. override void OnEntry (BotEventBase e)
  130. {
  131. super.OnEntry(e);
  132. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  133. if (inHands)
  134. {
  135. botDebugPrint("[bot] + " + m_Owner + " dropping item=" + inHands + " bot=" + m_Owner);
  136. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  137. m_Owner.PredictiveDropEntity(inHands);
  138. //m_Owner.LocalDropEntity(inHands);
  139. }
  140. }
  141. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  142. override void OnExit (BotEventBase e) { super.OnExit(e); }
  143. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  144. };
  145. class BotEatEntityInHands extends BotWaitForChangeInHands
  146. {
  147. EntityAI m_Entity;
  148. override void OnEntry (BotEventBase e)
  149. {
  150. super.OnEntry(e);
  151. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  152. if (inHands)
  153. {
  154. botDebugPrint("[bot] + " + m_Owner + " eating item=" + inHands + " bot=" + m_Owner);
  155. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_CLIENT)
  156. {
  157. #ifdef BOT
  158. ActionManagerBase mgr = m_Owner.GetActionManager();
  159. ActionManagerClient cli_mgr = ActionManagerClient.Cast(mgr);
  160. if (cli_mgr)
  161. {
  162. ActionTarget target;
  163. target = new ActionTarget(inHands, null, -1, vector.Zero, -1);
  164. cli_mgr.PerformAction(AT_EAT, target, inHands);
  165. }
  166. #endif
  167. }
  168. }
  169. }
  170. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  171. override void OnExit (BotEventBase e) { super.OnExit(e); }
  172. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  173. };
  174. class BotDestroyEntityInHands extends BotWaitForChangeInHands
  175. {
  176. EntityAI m_Entity;
  177. override void OnEntry (BotEventBase e)
  178. {
  179. super.OnEntry(e);
  180. EntityAI inHands = m_Owner.GetHumanInventory().GetEntityInHands();
  181. if (inHands)
  182. {
  183. botDebugPrint("[bot] + " + m_Owner + " deleting item=" + inHands + " bot=" + m_Owner);
  184. if (m_Owner.GetInstanceType() == DayZPlayerInstanceType.INSTANCETYPE_SERVER)
  185. inHands.Delete();
  186. }
  187. }
  188. override void OnAbort (BotEventBase e) { super.OnAbort(e); }
  189. override void OnExit (BotEventBase e) { super.OnExit(e); }
  190. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  191. };
  192. class Bot_TestSpawnOpenDrop extends Bot_TestSpawnOpen
  193. {
  194. ref BotDropEntityInHands m_Dropping;
  195. void Bot_TestSpawnOpenDrop (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  196. {
  197. m_Dropping = new BotDropEntityInHands(m_Bot, this);
  198. // events
  199. BotEventBase __EntOpn__ = new BotEventEntityInHandsOpened;
  200. BotEventBase __HndChg__ = new BotEventOnItemInHandsChanged;
  201. // transitions
  202. m_FSM.AddTransition(new BotTransition( m_Opening, __EntOpn__, m_Dropping));
  203. m_FSM.AddTransition(new BotTransition( m_Dropping, __HndChg__, NULL));
  204. }
  205. override void OnEntry (BotEventBase e) { super.OnEntry(e); }
  206. override void OnExit (BotEventBase e) { super.OnExit(e); }
  207. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  208. };
  209. class Bot_TestSpawnOpenDestroy extends Bot_TestSpawnOpen
  210. {
  211. ref BotDestroyEntityInHands m_Destroying;
  212. void Bot_TestSpawnOpenDestroy (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  213. {
  214. m_Destroying = new BotDestroyEntityInHands(m_Bot, this);
  215. // events
  216. BotEventBase __EntOpn__ = new BotEventEntityInHandsOpened;
  217. BotEventBase __HndChg__ = new BotEventOnItemInHandsChanged;
  218. // transitions
  219. m_FSM.AddTransition(new BotTransition( m_Opening, __EntOpn__, m_Destroying));
  220. m_FSM.AddTransition(new BotTransition( m_Destroying, __HndChg__, NULL));
  221. }
  222. override void OnEntry (BotEventBase e) { super.OnEntry(e); }
  223. override void OnExit (BotEventBase e) { super.OnExit(e); }
  224. override void OnUpdate (float dt) { super.OnUpdate(dt); }
  225. };
  226. class Bot_TestSpawnOpenEat extends Bot_TestSpawnOpen
  227. {
  228. ref BotEatEntityInHands m_Eating;
  229. void Bot_TestSpawnOpenEat (Bot bot = NULL, BotStateBase parent = NULL, string new_type = "")
  230. {
  231. m_Eating = new BotEatEntityInHands(m_Bot, this);
  232. // events
  233. BotEventBase __EntOpn__ = new BotEventEntityInHandsOpened;
  234. BotEventBase __HndChg__ = new BotEventOnItemInHandsChanged;
  235. // transitions
  236. m_FSM.AddTransition(new BotTransition( m_Opening, __EntOpn__, m_Eating));
  237. m_FSM.AddTransition(new BotTransition( m_Eating, __HndChg__, NULL));
  238. }
  239. override void OnEntry (BotEventBase e)
  240. {
  241. super.OnEntry(e);
  242. }
  243. override void OnExit (BotEventBase e)
  244. {
  245. super.OnExit(e);
  246. }
  247. override void OnUpdate (float dt)
  248. {
  249. super.OnUpdate(dt);
  250. }
  251. };