123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- 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<MapItem> 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<CrystalBase> list = battleController.GetMap().GetCrystalBaseList();
- for(int i=0; i<list.Count; i++)
- {
- Station station = list[i].GetStation();
- if(station != null && station.team != owner.team)
- {
- owner.target = station;
- return;
- }
- }
- }
- int id = owner.GetThreadManager().GetMaxThreatId();
- BattleObject battleObj = battleController.GetMap().GetBattleObject(id);
- if(battleObj != null)
- {
- if(battleObj.IsDead())
- {
- owner.GetThreadManager().RemoveThreat(id);
- }
- else
- {
- owner.target = battleObj;
- }
- }
- }
- }
|