Exemplo n.º 1
0
        /// <summary>
        /// Определяем, может ли команда выполниться.
        /// </summary>
        /// <returns> Возвращает true, если перемещение возможно. Иначе, false. </returns>
        public override CanExecuteCheckResult CanExecute()
        {
            var nodeViewModel = GetHoverNodeViewModel();

            if (nodeViewModel is null)
            {
                return(CanExecuteCheckResult.CreateFailed("No hover node."));
            }

            if (PlayerState.ActiveActor?.Actor is null)
            {
                return(CanExecuteCheckResult.CreateFailed("Active actor is not assigned."));
            }

            CreatePath(nodeViewModel);

            var pathIsNotEmpty = Path.Any();

            if (!pathIsNotEmpty)
            {
                return(CanExecuteCheckResult.CreateFailed("Found path is not correct or empty."));
            }

            return(CanExecuteCheckResult.CreateSuccessful());
        }
Exemplo n.º 2
0
        public override CanExecuteCheckResult CanExecute()
        {
            if (_inventoryState.SelectedProp is null)
            {
                // Means equipment will be unequiped from the slot (specified in command).
                return(CanExecuteCheckResult.CreateSuccessful());
            }

            if (SlotIndex is null)
            {
                throw new InvalidOperationException("Для команды не указан слот.");
            }

            if (_inventoryState.SelectedProp is null)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "Item to equip is not selected."
                });
            }

            if (_inventoryState.SelectedProp.Prop is not Equipment equipmentFromInventory)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "It is attempt to equip non-equipment."
                });
            }

            // Сломанную экипировку нельзя надевать
            if (equipmentFromInventory.Durable.Value <= 0)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "The selected equipment is broken."
                });
            }

            var equipmentCarrier = PlayerState.ActiveActor !.Actor.Person.GetModule <IEquipmentModule>();
            var slot             = equipmentCarrier.Slots[SlotIndex.Value];

            var canEquipInSlot = EquipmentCarrierHelper.CheckSlotCompability(equipmentFromInventory !, slot);

            if (!canEquipInSlot)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = $"Incompatible slot {slot?.Types} to assign equipment."
                });
            }

            var canEquipDual = EquipmentCarrierHelper.CheckDualCompability(equipmentCarrier,
                                                                           equipmentFromInventory,
                                                                           SlotIndex.Value);

            if (!canEquipDual)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "Equipment is not compatible to dual."
                });
            }

            var canEquipShield = EquipmentCarrierHelper.CheckShieldCompability(equipmentCarrier,
                                                                               equipmentFromInventory,
                                                                               SlotIndex.Value);

            if (!canEquipShield)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "It is attempt to equip second shield."
                });
            }

            var is1hTo2hSlot = Check2hOnlyInMainHandSlot(equipmentCarrier,
                                                         equipmentFromInventory,
                                                         SlotIndex.Value);

            if (is1hTo2hSlot != null && is1hTo2hSlot == false)
            {
                return(new CanExecuteCheckResult
                {
                    IsSuccess = false,
                    FailureReason = "It is attempt to equip two-handed in not main hand slot."
                });
            }

            return(new CanExecuteCheckResult {
                IsSuccess = true
            });
        }
Exemplo n.º 3
0
        public override CanExecuteCheckResult CanExecute()
        {
            var sector = _player.SectorNode.Sector;

            if (sector is null)
            {
                throw new InvalidOperationException();
            }

            var map = sector.Map;

            var activeActorViewModel = PlayerState.ActiveActor;

            if (activeActorViewModel is null)
            {
                return(CanExecuteCheckResult.CreateFailed("Active actor is not assigned."));
            }

            var currentNode = activeActorViewModel.Actor.Node;

            var target = GetTarget(PlayerState);

            if (target is null)
            {
                return(CanExecuteCheckResult.CreateFailed("Invalid target."));
            }

            var targetNode = target.Node;

            var act = PlayerState.TacticalAct;

            if (act is null)
            {
                return(CanExecuteCheckResult.CreateFailed("Act is not assigned."));
            }

            if (act.Constrains?.EnergyCost > 0 && activeActorViewModel.Actor.Person.GetModule <ISurvivalModule>().Stats
                .SingleOrDefault(x => x.Type == SurvivalStatType.Energy)?.Value < 0)
            {
                return(CanExecuteCheckResult.CreateFailed("The energy is critically low."));
            }

            if ((act.Stats.Targets & TacticalActTargets.Self) > 0 &&
                ReferenceEquals(activeActorViewModel.Actor, target))
            {
                // Лечить можно только самого себя.
                // Возможно, дальше будут компаньоны и другие НПЦ.
                // Тогда эту проверку нужно будет доработать.
                return(CanExecuteCheckResult.CreateSuccessful());
            }

            // Проверка, что цель достаточно близка по дистации и видна.
            if (act.Stats.Range == null)
            {
                return(CanExecuteCheckResult.CreateFailed("Act range is not valid."));
            }

            var isInDistance = act.CheckDistance(currentNode, targetNode, sector.Map);

            if (!isInDistance)
            {
                return(CanExecuteCheckResult.CreateFailed("Target is out of range."));
            }

            var targetIsOnLine = map.TargetIsOnLine(currentNode, targetNode);

            if (!targetIsOnLine)
            {
                return(CanExecuteCheckResult.CreateFailed("Target is not on line of sight."));
            }

            // Проверка наличия ресурсов для выполнения действия

            if (act.Constrains?.PropResourceType != null && act.Constrains?.PropResourceCount != null)
            {
                var hasPropResource = CheckPropResource(
                    activeActorViewModel.Actor.Person.GetModule <IInventoryModule>(),
                    act.Constrains.PropResourceType,
                    act.Constrains.PropResourceCount.Value);

                if (!hasPropResource)
                {
                    return(CanExecuteCheckResult.CreateFailed("Has not enought resources to perform act."));
                }
            }

            // Проверка КД

            if (act.CurrentCooldown > 0)
            {
                return(CanExecuteCheckResult.CreateFailed("Act cooldown is not over."));
            }

            return(CanExecuteCheckResult.CreateSuccessful());
        }