Exemple #1
0
        private void ShowUnitAttack(MapElementInfo own, MapElementInfo enemy)
        {
            int x = own.Pos().x - enemy.Pos().x;
            int y = own.Pos().y - enemy.Pos().y;

            Debug.LogWarning(own.name + " " + own.IsBuilding());
            //show attacker animation
            if (!own.IsBuilding())
            {
                UnitInfo unit = (UnitInfo)own;

                var sq = DOTween.Sequence();
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1));
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1));
                unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.AttackEast:x < 0?UnitAnimatorType.AttackWest:y < 0?UnitAnimatorType.AttackSouth:UnitAnimatorType.AttackNorth);
            }

            //show defender animation
            if (!enemy.IsBuilding())
            {
                UnitInfo unit = (UnitInfo)enemy;

                var sq = DOTween.Sequence();
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f - x / 4f, unit.Pos().y - y / 4f), 1));
                sq.Append(unit.transform.DOMove(new Vector3(unit.Pos().x + 0.5f, unit.Pos().y), 1));
                unit.UnitAnimator().PlayFightAnimation(x > 0?UnitAnimatorType.DefendEast:x < 0?UnitAnimatorType.DefendWest:y < 0?UnitAnimatorType.DefendSouth:UnitAnimatorType.DefendNorth);
            }
        }
Exemple #2
0
        protected virtual bool AddGoal(UnitInfo unit, ActionHolder holder, NVector pos)
        {
            //found it and movable?
            int cost = GameMgmt.Get().newMap.PathFinding(unit.Pos().level).Cost(unit.Player(), unit.dataUnit.movement, unit.Pos(), pos);

            if (cost > 0)
            {
                Debug.Log("Set Goal " + cost + " " + unit.Pos() + " " + pos);
                holder.data["pos"] = pos.ToString();
                return(true);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        /// Press the action
        /// </summary>
        /// <param name="key"></param>
        private void PressAction(InputKey key)
        {
            //which has this action?
            if (_aUnit != null)
            {
                BaseDataBuildingUnit data = _aUnit.baseData;
                //unit contains action?
                if (data.action.Contains(key.id))
                {
                    //TODO check more settings
                    //can perform action?
                    ActionHolder action = data.action.Get(key.id);
                    OnMapUI.Get().unitUI.ShowPanelMessageError(data.action.Perform(action, ActionEvent.Direct, _aUnit.Player(), _aUnit, _aUnit.Pos()));

                    return;
                }
            }

            if (_aBuilding != null)
            {
                BaseDataBuildingUnit data = _aBuilding.baseData;
                //unit contains action?
                if (data.action.Contains(key.id))
                {
                    //TODO check more settings
                    //can perform action?
                    ActionHolder action = data.action.Get(key.id);
                    OnMapUI.Get().unitUI.ShowPanelMessageError(data.action.Perform(action, ActionEvent.Direct, _aBuilding.Player(), _aBuilding, _aBuilding.Pos()));

                    return;
                }
            }

            //found nothing?
            OnMapUI.Get().unitUI.ShowPanelMessageError($"Action {L.b.actions[key.id].Name()} can not called, their is no unit or building, who can perform it.");
        }
Exemple #4
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);
            }
        }