Ejemplo n.º 1
0
        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);
            }
        }