Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.67 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. namespace Ateam
  6. {
  7. public class Echo : BaseBattleAISystem
  8. {
  9. //---------------------------------------------------
  10. // InitializeAI
  11. //---------------------------------------------------
  12.  
  13. int[,] stage;
  14. override public void InitializeAI()
  15. {
  16.  
  17. stage = GetStageData ();
  18.  
  19.  
  20. }
  21.  
  22. //---------------------------------------------------
  23. // UpdateAI
  24. //---------------------------------------------------
  25. bool xFlag = true;
  26. bool itemFlag=false;
  27. override public void UpdateAI()
  28. {
  29.  
  30. CharacterModel.Data enemy = _getEnemy ();
  31. List<CharacterModel.Data> playerList = GetTeamCharacterDataList (TEAM_TYPE.PLAYER);
  32.  
  33.  
  34. _MovePlayer (playerList [0], enemy, 1);
  35. _MoveSub (playerList [0], playerList [1],enemy, 1);
  36. _MoveSub (playerList [0], playerList [2],enemy, 1);
  37.  
  38.  
  39. }
  40.  
  41. int itemCount=0;
  42. int flameCount=0;
  43. public void _MovePlayer(CharacterModel.Data p,CharacterModel.Data enemy,int count){
  44.  
  45. Action(p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_LONG);
  46. Action(p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_MIDDLE);
  47.  
  48. int p_x = (int)p.BlockPos.x;
  49. int p_y = (int)p.BlockPos.y;
  50. int e_x = (int)enemy.BlockPos.x;
  51. int e_y = (int)enemy.BlockPos.y;
  52.  
  53. if (p_x<e_x+1 && p_x>e_x-1 && p_y<e_y+1 && p_y>e_y-1) {
  54. Action (p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_SHORT);
  55. }
  56.  
  57. if ((p.BlockPos - enemy.BlockPos).magnitude < 3 && itemCount == 0 && !itemFlag) {
  58. Debug.Log ("item go"+item.BlockPos.x+" "+item.BlockPos.y);
  59. itemFlag = true;
  60. }
  61.  
  62. if (itemFlag) {
  63. _itemGet (p);
  64. }
  65.  
  66. if(!itemFlag) {
  67.  
  68. if (p.Hp < 400) {
  69. Action (p.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
  70. }
  71.  
  72.  
  73. if (p_x < e_x && xFlag) {
  74. if (stage [p_y, p_x + 1] == 0) {
  75. if (Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
  76. xFlag = false;
  77. }
  78. } else {
  79. xFlag = false;
  80. }
  81. } else if (p_x > e_x && xFlag) {
  82. if (stage [p_y, p_x - 1] == 0) {
  83. if (Move (p.ActorId, Common.MOVE_TYPE.LEFT)) {
  84. xFlag = false;
  85. }
  86. } else {
  87. xFlag = false;
  88. }
  89. } else if (xFlag) {
  90. xFlag = false;
  91. }
  92.  
  93. if (p_y < e_y && !xFlag) {
  94. if (stage [p_y + 1, p_x] == 0) {
  95. if (Move (p.ActorId, Common.MOVE_TYPE.UP)) {
  96. xFlag = true;
  97. }
  98. } else {
  99. xFlag = true;
  100. }
  101. } else if (p_y > e_y && !xFlag) {
  102. if (stage [p_y - 1, p_x] == 0) {
  103. if (Move (p.ActorId, Common.MOVE_TYPE.DOWN)) {
  104. xFlag = true;
  105. }
  106. } else {
  107. xFlag = true;
  108. }
  109. } else if (!xFlag) {
  110. xFlag = true;
  111. }
  112. }
  113. }
  114.  
  115. public void _MoveSub(CharacterModel.Data p_main,CharacterModel.Data p_sub,CharacterModel.Data enemy,int count){
  116.  
  117. Action(p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_LONG);
  118. Action(p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_MIDDLE);
  119.  
  120. int p_x = (int)p_main.BlockPos.x;
  121. int p_y = (int)p_main.BlockPos.y;
  122. int e_x = (int)enemy.BlockPos.x;
  123. int e_y = (int)enemy.BlockPos.y;
  124.  
  125. if (p_x<e_x+1 && p_x>e_x-1 && p_y<e_y+1 && p_y>e_y-1) {
  126. Action (p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_SHORT);
  127. }
  128.  
  129. if (p_sub.Hp < 400) {
  130. Action (p_sub.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
  131. }
  132.  
  133. if (p_sub.BlockPos.x < p_main.BlockPos.x-3) {
  134. Move (p_sub.ActorId, Common.MOVE_TYPE.RIGHT);
  135. }
  136. if (p_sub.BlockPos.x > p_main.BlockPos.x-3) {
  137. Move (p_sub.ActorId, Common.MOVE_TYPE.LEFT);
  138. }
  139. if (p_sub.BlockPos.y < p_main.BlockPos.y) {
  140. Move (p_sub.ActorId, Common.MOVE_TYPE.UP);
  141. }
  142. if (p_sub.BlockPos.y > p_main.BlockPos.y) {
  143. Move (p_sub.ActorId, Common.MOVE_TYPE.DOWN);
  144. }
  145. }
  146.  
  147. public CharacterModel.Data _getEnemy(){
  148. List<CharacterModel.Data> enemyList = GetTeamCharacterDataList(TEAM_TYPE.ENEMY);
  149. if(enemyList[0].Hp>0)return enemyList[0];
  150. else if(enemyList[1].Hp>0)return enemyList[1];
  151. else return enemyList[2];
  152. }
  153.  
  154. ItemSpawnData item;
  155.  
  156. int right_count=0;
  157. int left_count=0;
  158. int up_count = 0;
  159. int down_count=0;
  160. public void _itemGet(CharacterModel.Data p){
  161. itemFlag = true;
  162.  
  163. if (p.Hp < 400) {
  164. Action (p.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
  165. }
  166.  
  167. int p_x = (int)p.BlockPos.x;
  168. int p_y = (int)p.BlockPos.y;
  169. int i_x = (int)item.BlockPos.x;
  170. int i_y = (int)item.BlockPos.y;
  171.  
  172. if (p_x < i_x && xFlag) {
  173. if (stage [p_y, p_x + 1] == 0) {
  174. if (Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
  175. xFlag = false;
  176. }
  177. } else {
  178. right_count++;
  179. left_count = 0;
  180. up_count = 0;
  181. down_count = 0;
  182. if(right_count>5){
  183. if (!Move (p.ActorId, Common.MOVE_TYPE.UP)) {
  184. Move (p.ActorId, Common.MOVE_TYPE.DOWN);
  185. }
  186. }
  187. Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
  188. xFlag = false;
  189. }
  190. } else if (p_x > i_x && xFlag) {
  191. if (stage [p_y, p_x - 1] == 0) {
  192. if (Move (p.ActorId, Common.MOVE_TYPE.LEFT)) {
  193. xFlag = false;
  194. }
  195. } else {
  196. right_count=0;
  197. left_count++;
  198. up_count = 0;
  199. down_count = 0;
  200. if(left_count>5){
  201. if (!Move (p.ActorId, Common.MOVE_TYPE.UP)) {
  202. Move (p.ActorId, Common.MOVE_TYPE.DOWN);
  203. }
  204. }
  205. Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
  206. xFlag = false;
  207. }
  208. } else if (xFlag) {
  209. xFlag = false;
  210. }
  211.  
  212. if (p_y < i_y && !xFlag) {
  213. if (stage [p_y+1, p_x ] == 0) {
  214. if (Move (p.ActorId, Common.MOVE_TYPE.UP)) {
  215. xFlag = true;
  216. }
  217. } else {
  218. right_count=0;
  219. left_count = 0;
  220. up_count++;
  221. down_count = 0;
  222. if(up_count>5){
  223. if (!Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
  224. Move (p.ActorId, Common.MOVE_TYPE.LEFT);
  225. }
  226. }
  227. Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
  228. xFlag = true;
  229. }
  230. }
  231.  
  232. else if (p_y > i_y && !xFlag) {
  233. if (stage [p_y-1, p_x ] == 0) {
  234. if (Move (p.ActorId, Common.MOVE_TYPE.DOWN)) {
  235. xFlag = true;
  236. }
  237. } else {
  238. right_count=0;
  239. left_count = 0;
  240. up_count = 0;
  241. down_count++;
  242. if(down_count>5){
  243. if (!Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
  244. Move (p.ActorId, Common.MOVE_TYPE.LEFT);
  245. }
  246. }
  247. Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
  248. xFlag = true;
  249. }
  250. }
  251.  
  252. else if (!xFlag) {
  253. xFlag = true;
  254. }
  255.  
  256. flameCount++;
  257.  
  258. if (p_x == i_x && p_y == i_y) {
  259. itemFlag = false;
  260. itemCount++;
  261. Debug.Log ("item get!!");
  262. }
  263.  
  264. }
  265.  
  266. //---------------------------------------------------
  267. // ItemSpawnCallback
  268. //---------------------------------------------------
  269. override public void ItemSpawnCallback(ItemSpawnData itemData)
  270. {
  271. if (!itemFlag) {
  272. item = itemData;
  273. }
  274. }
  275. }
  276. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement