Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- namespace Ateam
- {
- public class Echo : BaseBattleAISystem
- {
- //---------------------------------------------------
- // InitializeAI
- //---------------------------------------------------
- int[,] stage;
- override public void InitializeAI()
- {
- stage = GetStageData ();
- }
- //---------------------------------------------------
- // UpdateAI
- //---------------------------------------------------
- bool xFlag = true;
- bool itemFlag=false;
- override public void UpdateAI()
- {
- CharacterModel.Data enemy = _getEnemy ();
- List<CharacterModel.Data> playerList = GetTeamCharacterDataList (TEAM_TYPE.PLAYER);
- _MovePlayer (playerList [0], enemy, 1);
- _MoveSub (playerList [0], playerList [1],enemy, 1);
- _MoveSub (playerList [0], playerList [2],enemy, 1);
- }
- int itemCount=0;
- int flameCount=0;
- public void _MovePlayer(CharacterModel.Data p,CharacterModel.Data enemy,int count){
- Action(p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_LONG);
- Action(p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_MIDDLE);
- int p_x = (int)p.BlockPos.x;
- int p_y = (int)p.BlockPos.y;
- int e_x = (int)enemy.BlockPos.x;
- int e_y = (int)enemy.BlockPos.y;
- if (p_x<e_x+1 && p_x>e_x-1 && p_y<e_y+1 && p_y>e_y-1) {
- Action (p.ActorId, Define.Battle.ACTION_TYPE.ATTACK_SHORT);
- }
- if ((p.BlockPos - enemy.BlockPos).magnitude < 3 && itemCount == 0 && !itemFlag) {
- Debug.Log ("item go"+item.BlockPos.x+" "+item.BlockPos.y);
- itemFlag = true;
- }
- if (itemFlag) {
- _itemGet (p);
- }
- if(!itemFlag) {
- if (p.Hp < 400) {
- Action (p.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
- }
- if (p_x < e_x && xFlag) {
- if (stage [p_y, p_x + 1] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
- xFlag = false;
- }
- } else {
- xFlag = false;
- }
- } else if (p_x > e_x && xFlag) {
- if (stage [p_y, p_x - 1] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.LEFT)) {
- xFlag = false;
- }
- } else {
- xFlag = false;
- }
- } else if (xFlag) {
- xFlag = false;
- }
- if (p_y < e_y && !xFlag) {
- if (stage [p_y + 1, p_x] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.UP)) {
- xFlag = true;
- }
- } else {
- xFlag = true;
- }
- } else if (p_y > e_y && !xFlag) {
- if (stage [p_y - 1, p_x] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.DOWN)) {
- xFlag = true;
- }
- } else {
- xFlag = true;
- }
- } else if (!xFlag) {
- xFlag = true;
- }
- }
- }
- public void _MoveSub(CharacterModel.Data p_main,CharacterModel.Data p_sub,CharacterModel.Data enemy,int count){
- Action(p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_LONG);
- Action(p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_MIDDLE);
- int p_x = (int)p_main.BlockPos.x;
- int p_y = (int)p_main.BlockPos.y;
- int e_x = (int)enemy.BlockPos.x;
- int e_y = (int)enemy.BlockPos.y;
- if (p_x<e_x+1 && p_x>e_x-1 && p_y<e_y+1 && p_y>e_y-1) {
- Action (p_sub.ActorId, Define.Battle.ACTION_TYPE.ATTACK_SHORT);
- }
- if (p_sub.Hp < 400) {
- Action (p_sub.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
- }
- if (p_sub.BlockPos.x < p_main.BlockPos.x-3) {
- Move (p_sub.ActorId, Common.MOVE_TYPE.RIGHT);
- }
- if (p_sub.BlockPos.x > p_main.BlockPos.x-3) {
- Move (p_sub.ActorId, Common.MOVE_TYPE.LEFT);
- }
- if (p_sub.BlockPos.y < p_main.BlockPos.y) {
- Move (p_sub.ActorId, Common.MOVE_TYPE.UP);
- }
- if (p_sub.BlockPos.y > p_main.BlockPos.y) {
- Move (p_sub.ActorId, Common.MOVE_TYPE.DOWN);
- }
- }
- public CharacterModel.Data _getEnemy(){
- List<CharacterModel.Data> enemyList = GetTeamCharacterDataList(TEAM_TYPE.ENEMY);
- if(enemyList[0].Hp>0)return enemyList[0];
- else if(enemyList[1].Hp>0)return enemyList[1];
- else return enemyList[2];
- }
- ItemSpawnData item;
- int right_count=0;
- int left_count=0;
- int up_count = 0;
- int down_count=0;
- public void _itemGet(CharacterModel.Data p){
- itemFlag = true;
- if (p.Hp < 400) {
- Action (p.ActorId, Define.Battle.ACTION_TYPE.INVINCIBLE);
- }
- int p_x = (int)p.BlockPos.x;
- int p_y = (int)p.BlockPos.y;
- int i_x = (int)item.BlockPos.x;
- int i_y = (int)item.BlockPos.y;
- if (p_x < i_x && xFlag) {
- if (stage [p_y, p_x + 1] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
- xFlag = false;
- }
- } else {
- right_count++;
- left_count = 0;
- up_count = 0;
- down_count = 0;
- if(right_count>5){
- if (!Move (p.ActorId, Common.MOVE_TYPE.UP)) {
- Move (p.ActorId, Common.MOVE_TYPE.DOWN);
- }
- }
- Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
- xFlag = false;
- }
- } else if (p_x > i_x && xFlag) {
- if (stage [p_y, p_x - 1] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.LEFT)) {
- xFlag = false;
- }
- } else {
- right_count=0;
- left_count++;
- up_count = 0;
- down_count = 0;
- if(left_count>5){
- if (!Move (p.ActorId, Common.MOVE_TYPE.UP)) {
- Move (p.ActorId, Common.MOVE_TYPE.DOWN);
- }
- }
- Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
- xFlag = false;
- }
- } else if (xFlag) {
- xFlag = false;
- }
- if (p_y < i_y && !xFlag) {
- if (stage [p_y+1, p_x ] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.UP)) {
- xFlag = true;
- }
- } else {
- right_count=0;
- left_count = 0;
- up_count++;
- down_count = 0;
- if(up_count>5){
- if (!Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
- Move (p.ActorId, Common.MOVE_TYPE.LEFT);
- }
- }
- Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
- xFlag = true;
- }
- }
- else if (p_y > i_y && !xFlag) {
- if (stage [p_y-1, p_x ] == 0) {
- if (Move (p.ActorId, Common.MOVE_TYPE.DOWN)) {
- xFlag = true;
- }
- } else {
- right_count=0;
- left_count = 0;
- up_count = 0;
- down_count++;
- if(down_count>5){
- if (!Move (p.ActorId, Common.MOVE_TYPE.RIGHT)) {
- Move (p.ActorId, Common.MOVE_TYPE.LEFT);
- }
- }
- Debug.Log (right_count+"-"+left_count+"-"+up_count+"-"+down_count);
- xFlag = true;
- }
- }
- else if (!xFlag) {
- xFlag = true;
- }
- flameCount++;
- if (p_x == i_x && p_y == i_y) {
- itemFlag = false;
- itemCount++;
- Debug.Log ("item get!!");
- }
- }
- //---------------------------------------------------
- // ItemSpawnCallback
- //---------------------------------------------------
- override public void ItemSpawnCallback(ItemSpawnData itemData)
- {
- if (!itemFlag) {
- item = itemData;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement