public override Pos FindWhereToMove() { //先寻路 route = scene.BFS(location, focus.location, BFSSearchNormal); //显示寻路路径 scene.ResetRouteAera(route); scene.Show(); scene.ResetRouteAera(new List <Pos>()); //这是完全搜不到 if (route.Count == 1) { route = scene.BFS(location, focus.location, BFSSearchRoute); route.RemoveAt(route.Count - 1); //如果这次搜索还是找不到 if (route.Count == 0) { return(location); } else { foreach (var v in route) { //攻击检测到的第一个敌对单位 if (scene.SelectBlock(v).target != null && scene.SelectBlock(v).target.faction != faction) { focus = scene.SelectBlock(v).target; scene.canvas.RefreshUI(); FindWhereToMove(); } } } } //路上所有的火都可以增加自己的移动力 foreach (var v in route) { if (scene.SelectBlock(v).name == "fire") { act++; } } //这是已经可以攻击了,不用判定了 if (route.Count < aimRange + 2) { canAttack = true; return(location); } //如果距离上来看能走到,那么试图进入精确定位模式 if (route.Count <= act + 2) { //如果能找到可以落脚的点 靠谱的移动路径 Pos p = FindPosToMove(); if (p != new Pos(0, 0)) { //如果太远的话只能冲刺到脸上但不能立即攻击 if (route.Count > act / 3 + 2) { canAttack = false; return(p); } canAttack = true; return(p); } } //如果精确定位失败,那么执行接近定位策略 if (act > route.Count - 1) { act = route.Count - 1; } for (int i = act; i > 0; i--) { //检测最远的一个点有没有被遮挡 Block b = scene.SelectBlock(route[i]); //如果最远的点是空的,那么返回移动路线 if (b.target == null) { Pos a = route[i]; Pos bb = a; return(route[i]); } } //真哪都去不了,gg 不动了 act = 0; route = new List <Pos>(); return(location); }
public override void Action() { canAttack = false; act = actMax; if (focus.isDead) { int n = 0; if ((n = scene.GetPlayers().Count) > 0) { int r = scene.random.Next(0, n); focus = scene.GetPlayers()[r]; } else { focus = null; } } //没有仇恨目标 不行动 if (focus == null) { return; } //查找应在走到哪 Pos to = FindWhereToMove(); route = scene.BFS(location, to, BFSSearchNormal); if (route.Count > 2) { Thread.Sleep(100); } scene.Show(); MoveTo(route.Last()); scene.Show(); if (canAttack) { scene.MoveCursorTo(location); scene.environmentController.ShowMessageBox("自爆球炸了!!!"); foreach (var v in SetNearbyPos(0)) { //检测所有爆炸点,如果不为0产生自爆攻击 Target t; Skill s; if ((t = scene.SelectBlock(location + v).target) != null) { //对友军造成一半伤害 if (t.faction == Faction.Enemy) { s = Skill.CreateBoom(); s.caster = this; s.damage = s.damage / 2; t.BeHit(s); } //对岩石造成六倍伤害 if (t.faction == Faction.Friendly) { s = Skill.CreateBoom(); s.caster = this; s.damage = s.damage * 6; t.BeHit(s); } //对英雄造成一倍伤害 if (t.faction == Faction.Player) { s = Skill.CreateBoom(); s.caster = this; t.BeHit(s); } } } Dead(); isDead = true; } }
//准备执行攻击操作 主要是玩家的攻击控制器 public override bool Attack(Pos to, Skill s) { if (s.type == SkillType.Rest) { int t = act; changeAct(-act); changeHP(s.heal * t); changeMP(s.addMana * t); string message = name + "休息:消耗行动" + t.ToString() + ";"; if (s.heal != 0) { message += "回复" + (s.heal * t).ToString() + "HP;"; } if (s.addMana != 0) { message += "回复" + (s.addMana * t).ToString() + "MP;"; } scene.AddDebugMessage("#B" + message); } List <Pos> list = new List <Pos>(); list.AddRange(scene.cursorLayer.cursor.cursorAera); list.Add(new Pos(0, 0)); bool flag = false; if (s.costAct > act) { scene.AddDebugMessage("#B行动力不足"); return(false); } if (s.costMana > mp) { scene.AddDebugMessage("#B法力值不足"); return(false); } if (s.type == SkillType.Damage || s.type == SkillType.Holy) { foreach (var v in list) { //如果不是空 就执行攻击 //之后加入一点更复杂的条件 if (scene.SelectBlock(v + to).target != null) { if (scene.SelectBlock(v + to).target.faction != faction) { scene.SelectBlock(v + to).target.BeHit(s); scene.ResetMoveAera(new List <Pos>()); scene.ResetRouteAera(new List <Pos>()); scene.MoveCursor(new Pos(0, 0)); scene.ReloadCursor(Scene.CursorType.Point); flag = true; } } } } if (s.type == SkillType.Heal) { foreach (var v in list) { //如果不是空 就执行攻击 //之后加入一点更复杂的条件 if (scene.SelectBlock(v + to).target != null) { if (scene.SelectBlock(v + to).target.faction == faction) { scene.SelectBlock(v + to).target.BeHit(s); scene.ResetMoveAera(new List <Pos>()); scene.ResetRouteAera(new List <Pos>()); scene.MoveCursor(new Pos(0, 0)); scene.ReloadCursor(Scene.CursorType.Point); flag = true; } } } } else if (s.type == SkillType.Create) { foreach (var v in list) { //如果是空则执行创造 if (scene.SelectBlock(v + to).target == null && scene.SelectBlock(v + to).CanMove == true) { scene.SelectBlock(v + to).target = new Stone(scene, v + to, s.summonHP); scene.environmentController.lists.Add(scene.SelectBlock(v + to).target); scene.ResetMoveAera(new List <Pos>()); scene.ResetRouteAera(new List <Pos>()); scene.MoveCursor(new Pos(0, 0)); scene.ReloadCursor(Scene.CursorType.Point); flag = true; } } } if (flag) { changeAct(-s.costAct); changeMP(-s.costMana); } return(flag); }