using UnityEngine; using System.Collections; using System.Collections.Generic; public class CraftAI : AI { public bool followTarget; protected float lastCheckOccupyTime; protected float checkOccupyInterval = 3f; // Use this for initialization override protected void Start () { base.Start(); owner.MoveStepComplete += CheckGetItem; } protected virtual void OnDestroy() { owner.MoveStepComplete -= CheckGetItem; } protected Craft owner { get{ return _owner as Craft; } } protected virtual bool CheckOccupy() { if(GameTime.time - lastCheckOccupyTime > checkOccupyInterval) { lastCheckOccupyTime = GameTime.time; return true; } return false; } protected void CheckGetItem() { if(!CanSendMessage()) { return; } if(!owner.IsHero()) return; List itemList = battleController.GetMap().GetMapItemByGrid(owner.col, owner.row); if(itemList != null && itemList.Count > 0) { MapItem mapItem = itemList[0]; if(mapItem is FlagItem) DealFlag(mapItem as FlagItem); else battleController.GetMessageManager().GetItem(player, owner.id, mapItem.id); } } private void DealFlag(FlagItem flagItem) { if(flagItem.team == owner.team) { if(flagItem.IsInBase()) { FlagItem oppFlagItem = battleController.GetMap().GetFlag(TeamUtil.GetOpponentTeam(flagItem.team)); if(oppFlagItem.linkedCraftId == owner.id) battleController.GetMessageManager().CaptureFlag(player, owner); } else { battleController.GetMessageManager().ReturnFlag(player, owner, flagItem); } } else battleController.GetMessageManager().GetFlag(player, owner, flagItem); } protected void FindMaxThreatTarget() { if(map.HasFlag()) { FlagItem myFlag = map.GetFlag(owner.team); if(myFlag.linkedCraftId != -1) { owner.target = map.GetBattleObject(myFlag.linkedCraftId); return; } } else if(map.id == MapData.MapID.Challenge) { List list = battleController.GetMap().GetCrystalBaseList(); for(int i=0; i