Example #1
0
        public static UctAction CanMoveTo(GameInstance game, CachedMob mob, AxialCoord coord)
        {
            bool isEmpty = game.Map[coord] == HexType.Empty && game.State.AtCoord(coord, true) == null;

            int  distance    = game.Pathfinder.Distance(mob.MobInstance.Coord, coord);
            int  remainingAp = mob.MobInstance.Ap - distance;
            bool enoughAp    = remainingAp >= 0;

            if (isEmpty && enoughAp)
            {
                return(UctAction.MoveAction(mob.MobId, coord));
            }
            else
            {
                return(UctAction.NullAction());
            }
        }
        private void HandleLeftClick()
        {
            var abilitySelected = SelectedAbilityIndex.HasValue;

            var mouseHex   = Camera2D.Instance.MouseHex;
            var currentMob = _game.CurrentMob;

            if (_game.Pathfinder.IsValidCoord(mouseHex))
            {
                var targetId = _game.State.AtCoord(mouseHex, true);
                if (targetId != null)
                {
                    if (targetId == currentMob)
                    {
                        ShowMessage("You can't target yourself.");
                    }
                    else
                    {
                        var mobInfo        = _game.MobManager.MobInfos[currentMob.Value];
                        var targetInstance = _game.State.MobInstances[targetId.Value];
                        var targetInfo     = _game.MobManager.MobInfos[targetId.Value];

                        if (targetInstance.Hp == 0)
                        {
                            ShowMessage("This mob is already dead.");
                        }
                        else
                        {
                            if (mobInfo.Team == targetInfo.Team)
                            {
                                ShowMessage("You can't target your team.");
                            }
                            else if (SelectedAbilityIndex.HasValue)
                            {
                                if (abilitySelected)
                                {
                                    AttackMob(targetId.Value);
                                }
                                else
                                {
                                    ShowMessage("You can't move here.");
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (abilitySelected)
                    {
                        ShowMessage("You can't cast spells on the ground.");
                    }
                    else
                    {
                        var mobInstance = _game.State.MobInstances[currentMob.Value];

                        if (_game.Map[mouseHex] == HexType.Empty)
                        {
                            var distance = _game.Pathfinder.Distance(mobInstance.Coord, mouseHex);

                            if (distance == int.MaxValue)
                            {
                                ShowMessage("Target is unreachable");
                            }
                            else if (distance > mobInstance.Ap)
                            {
                                ShowMessage("You don't have enough AP.");
                            }
                            else
                            {
                                InputManager.Instance.UserInputEnabled = false;
                                _eventHub.SlowPlayAction(_game, UctAction.MoveAction(currentMob.Value, mouseHex))
                                .ContinueWith(t => { InputManager.Instance.UserInputEnabled = true; })
                                .LogContinuation();
                            }
                        }
                        else
                        {
                            ShowMessage("You can't walk into a wall.");
                        }
                    }
                }
            }
        }