//Todo combine with action explore private void MoveToPos(Player player, UnitInfo unit, NVector pos, ActionHolder holder) { DataUnit dUnit = unit.dataUnit; NVector dPos = new NVector(holder.data["pos"]); //go to this field List <PPoint> points = S.Map().PathFinding(pos.level).Path(player, dUnit.movement, pos, dPos); foreach (PPoint pp in points) { NVector p = new NVector(pp.x, pp.y, pos.level); //free field? if (!S.Unit().Free(p)) { unit.SetLastInfo($"Can not explore the world, path {p} is blocked."); return; } //not enough cost? var terr = S.Map().Terrain(pos); if (S.Map().PathFinding(pos.level).CostNode(player, dUnit.movement, pos) > dUnit.ap) { return; } //explore terrain player.fog.Clear(pos); //move their unit.MoveTo(p, true); } holder.data.Remove("pos"); unit.SetRepeatAction(null); }
private void TryMoveUnit(UnitInfo info, NVector pos) { //is free? if (!S.Unit().Free(pos)) { OnMapUI.Get().unitUI.ShowPanelMessageError($"{info.name} can not move between the levels, the destination is blocked."); return; } //have enough ap? int cost = GameMgmt.Get().newMap[pos.level].PathFinding().Cost(info.Player(), info.dataUnit.movement, pos, pos); cost = Math.Max(cost, 10); // cost at least 10 ap if (cost > info.data.ap) { OnMapUI.Get().unitUI.ShowPanelMessageError($"{info.name} can not move between the levels. {info.name} need {cost} AP, but only have {info.data.ap} AP."); return; } info.data.ap -= cost; info.MoveTo(pos); }
private void MoveToPos(Player player, UnitInfo unit, ActionHolder holder) { DataUnit dUnit = unit.dataUnit; NVector dPos = new NVector(holder.data["pos"]); int level = unit.Pos().level; //go to this field List <PPoint> points = S.Map().PathFinding(level).Path(player, dUnit.movement, unit.Pos(), dPos); NVector last = null; Debug.Log("Go to Goal " + unit.Pos() + " " + dPos); //find last possible point foreach (PPoint pp in points) { NVector p = new NVector(pp.x, pp.y, level); //free field? string s = unit.Passable(p); Debug.Log(p + ": " + s); if (s != null) { break; } //save it last = p; } Debug.Log("Go to Goal " + last); //move their? if (last == null) { if (holder.data.ContainsKey("posTried")) { unit.SetLastInfo(S.T("actionRepeatErrorMove", holder.DataAction().Name())); unit.SetRepeatAction(null); } else { unit.SetLastInfo(S.T("actionRepeatErrorPath", holder.DataAction().Name())); if (unit.data.ap == unit.data.apMax) { holder.data["posTried"] = "yes"; } } return; } //move their unit.MoveTo(last, true); holder.data.Remove("posTried"); if (dPos.Equals(last)) { //perform it holder.data.Remove("pos"); PerformRepeat(player, unit, dPos, holder); } //has enough ap for a next exploration? //todo dynamic if (dUnit.ap >= 10) { //Explore(player, unit, pos, holder); } }