public void SeachTarget() { if (m_Owner.m_Status.HaveState(StatusType.RunAway)) { m_run.PathAI(m_Owner.GetMapGrid(), m_Owner.RunPos, m_Owner.m_Attr); return; } bool IsTault = false; int tSceneID = m_Owner.m_Status.GetResalseSceneID(StatusType.Taunt); Life t = CM.GetLifeM(tSceneID, LifeMType.SOLDIER); if (t != null && t is Role && t.InBoat && m_Owner.CheckTarget(t)) { IsTault = true; } else { tSceneID = -1; } if (m_Owner.m_Status.HaveState(StatusType.FakeTaunt)) { LifeMCamp camp = m_Owner.m_Core.m_Camp == LifeMCamp.ATTACK ? LifeMCamp.DEFENSE : LifeMCamp.ATTACK; List <Life> l = new List <Life>(); ///需要排除隐形 。。。。。。。。。。。。。。。。。。 CM.SearchLifeMListInBoat(ref l, LifeMType.SOLDIER, camp); foreach (Role r in l) { if (r.m_Status.HaveState(StatusType.Mark)) { t = r; IsTault = true; } } } // if (m_Owner.m_isDead) { return; } if (m_Owner.m_Core.m_Camp == LifeMCamp.ATTACK && (m_Owner.m_Attr.AttrType != 3000 || !m_Owner.m_bReachGold)) { if (IsTault) { m_Owner.m_TargetisAttack = false; m_Owner.ChangeTarget(ChangeTargetReason.Taunt, t); #if UNITY_EDITOR_LOG FileLog.write(m_Owner.SceneID, "SeachTarget + m_Owner.Target = t;"); #endif SeachPath(t); } if (m_Owner.Target != null && (m_Owner.Target != null && !m_Owner.Target.isDead && m_Owner.m_TargetisAttack)) { SeachPath(m_Owner.Target); } else if (m_Owner.m_Attr.IsHide) { if (m_Owner.m_target == null || (m_Owner.m_target != null && m_Owner.m_target.isDead)) { int TargetSceneID = m_RadarAI.GetSearchTarget(tSceneID, m_Owner.GetMapGrid(), m_Owner.m_Attr.AttackLike); m_Owner.m_TargetisAttack = false; #if UNITY_EDITOR_LOG FileLog.write(m_Owner.SceneID, "SeachTarget + CM.GetAllLifeM(TargetSceneID,LifeMType.ALL)"); #endif m_Owner.ChangeTarget(ChangeTargetReason.RadarSearchTarget, CM.GetAllLifeM(TargetSceneID, LifeMType.ALL)); //m_Owner.Target = CM.GetAllLifeM(TargetSceneID,LifeMType.ALL); } if (m_Owner.Target != null && !m_Owner.Target.isDead) { MapGrid End = m_Owner.Target.GetTargetMapGrid(); if (m_Owner.Target is Role) { MapGrid g = End; if (m_Owner.Target.WalkDir == WalkDir.WALKRIGHT) { g = g.Left; while (g != null) { if (g.Type == GridType.GRID_NORMAL) { if (g.IsAttackStations()) { End = g; break; } else { g = g.Left; } } else { break; } } } else if (m_Owner.Target.WalkDir == WalkDir.WALKLEFT) { g = g.Right; while (g != null) { if (g.Type == GridType.GRID_NORMAL) { if (g.IsAttackStations()) { End = g; break; } else { g = g.Right; } } else { break; } } } } if (End != null) { m_run.PathAI(m_Owner.GetMapGrid(), End, m_Owner.m_Attr); } } else { m_run.CheackIdlePath(); } } else if (m_Owner.Target != null && (m_Owner.Target != null && m_Owner.Target is Role && !m_Owner.Target.isDead && m_Owner.TargetAttacked)) { Role roletarget = m_Owner.Target as Role; //Debug.Log(m_Owner.SceneID + "," +m_Owner.GetMapPos() + "," + roletarget.GetMapPos() + "," + roletarget.transform.localPosition + "," + m_Owner.transform.localPosition + "," +m_Owner.PropAttackSkillInfo.m_distance * MapGrid.m_width / MapGrid.m_Pixel); if (NdUtil.IsLifeSampMapLayer(roletarget, m_Owner.GetMapPos()) && Mathf.Abs(roletarget.m_thisT.localPosition.x - m_Owner.m_thisT.localPosition.x) - 0.25f < m_Owner.PropAttackSkillInfo.m_distance * MapGrid.m_width / MapGrid.m_Pixel) { SeachPath(m_Owner.Target); } else { m_Owner.m_TargetisAttack = false; SeachPath(CM.GoldBuild, true); } } else { m_Owner.m_TargetisAttack = false; SeachPath(CM.GoldBuild, true); } } else { if (m_Owner.m_target == null || (m_Owner.m_target != null && m_Owner.m_target.isDead) || (IsTault && m_Owner.m_target != t)) { #if UNITY_EDITOR_LOG string str = "SeachTarget new old:" + m_Owner.m_target + "," + m_Owner.m_TargetAttacked + m_Owner.GetMapPos(); if (m_Owner.m_target != null) { str += "," + m_Owner.m_target.isDead; } #endif int TargetSceneID = m_RadarAI.GetSearchTarget(tSceneID, m_Owner.GetMapGrid(), m_Owner.m_Attr.AttackLike); m_Owner.m_TargetisAttack = false; m_Owner.ChangeTarget(ChangeTargetReason.RadarSearchTarget, CM.GetAllLifeM(TargetSceneID, LifeMType.ALL)); #if UNITY_EDITOR_LOG FileLog.write(m_Owner.SceneID, str + " new " + m_Owner.m_target); #endif } #if UNITY_EDITOR_LOG FileLog.write(m_Owner.SceneID, "SeachTarget old " + m_Owner.m_target); #endif SeachPath(); } }
public virtual bool CheckDoAttackTarget(Life target, int Sort, int distant, bool isusedir = true) { if (target == null || target.isDead) { return(false); } //确认目标在行走路线上。 Life life = CM.GetAllLifeM(m_SceneID, LifeMType.SOLDIER | LifeMType.SUMMONPET) as Role; if (life == null) { return(false); } float radius = distant;//PropSkillInfo.m_distance/MapGrid.m_Pixel; //攻击距离为0的时候是全屏攻击范围 if (radius <= 0) { return(true); } if (!life.m_Attr.IsHide && isusedir && (life as Role).run.CheckInRoad(target.GetMapPos()) == false) { return(false); } //单人 //if (Sort == 1) { Life l = CM.GetAllLifeM(m_SceneID, LifeMType.SOLDIER | LifeMType.SUMMONPET); if (l is Role) { Role parent = l as Role; WalkDir pdir = parent.WalkDir; List <MapGrid> allg = target.GetAllMapGrid(); if (!NdUtil.IsLifeSampMapLayer(target, parent.GetMapPos())) { bool link = false; foreach (MapGrid g in allg) { if (MapGrid.CheckLink(parent.GetMapGrid(), g)) { link = true; } } if (!link) { return(false); } } List <IggWall> lw = new List <IggWall>(); MapGrid.GetWallList(ref lw, parent.GetMapPos(), target.GetMapPos()); foreach (IggWall w in lw) { if (!w.Open) { return(false); } } //radius += parent.m_Attr.Radius; float x1 = parent.m_thisT.localPosition.x; /*MapGrid g = MapGrid.GetMG(target.GetMapPos()); * if (g == null) * { * //Debug.LogError(target + "," + target.GetMapPos() + "," + target.InBoat); * return false; * }*/ //float x2 = 0;//g.pos.x; List <float> lx2 = new List <float>(); foreach (MapGrid g in allg) { lx2.Add(g.pos.x); } if (target is Role) { //radius += (int)(target as Role).m_Attr.Radius; lx2[0] = target.m_thisT.localPosition.x; /*if (target.WalkDir == WalkDir.WALKLEFT) * x2 -= target.RankDeep * Role.s_deepoffset; * else * x2 += target.RankDeep * Role.s_deepoffset;*/ if (target.RankDeep > 0) { lx2[0] = target.GetMapGrid().pos.x; } if (distant == 3 && target.WalkDir != l.WalkDir) { if ((target as Role).RoleWalk != null) { lx2[0] = (target as Role).RoleWalk.run.GetAttackStationMapGrid().pos.x; } } } if (parent.m_Attr.IsHide && target is Role) { if (target.WalkDir == WalkDir.WALKLEFT) { MapGrid lg = target.GetMapGrid().Right; while (lg != null) { if (lg.Type == GridType.GRID_NORMAL) { if (lg.IsAttackStations()) { List <int> samelist = new List <int>(); List <int> unsamelist = new List <int>(); lg.GetCampRoleList(parent.m_Core.m_Camp, ref samelist, ref unsamelist); if (unsamelist.Count <= 0) { pdir = target.WalkDir; lx2[0] += 1f; } break; } else { lg = lg.Right; } } else { break; } } } else if (target.WalkDir == WalkDir.WALKRIGHT) { MapGrid rg = target.GetMapGrid().Left; while (rg != null) { if (rg.Type == GridType.GRID_NORMAL) { if (rg.IsAttackStations()) { List <int> samelist = new List <int>(); List <int> unsamelist = new List <int>(); rg.GetCampRoleList(parent.m_Core.m_Camp, ref samelist, ref unsamelist); if (unsamelist.Count <= 0) { pdir = target.WalkDir; lx2[0] -= 1f; } break; } else { rg = rg.Left; } } else { break; } } } } if (l.RankDeep > 0) { x1 = l.GetMapGrid().pos.x; } radius += target.RankDeep * Role.s_deepoffset + l.RankDeep * Role.s_deepoffset; if (target is IggWall) { radius += 1; } radius += 0.5f; if (isusedir) { if (pdir == WalkDir.WALKLEFT) { foreach (float x2 in lx2) { if (x1 >= x2 && (x1 - x2) <= (radius * MapGrid.m_width)) { return(true); } } } else if (pdir == WalkDir.WALKRIGHT) { foreach (float x2 in lx2) { if (x1 <= x2 && (x2 - x1) <= (radius * MapGrid.m_width)) { return(true); } } } else { foreach (float x2 in lx2) { if (Mathf.Abs(x1 - x2) < radius * MapGrid.m_width) { return(true); } } } } else { foreach (float x2 in lx2) { if (Mathf.Abs(x1 - x2) < radius * MapGrid.m_width) { return(true); } } } } } return(false); }