コード例 #1
0
 private void UpdateActionSlot(ItemActionType itemlessActionType, ActionSlot actionSlot,
                               ActionAssignment?assignedActionType)
 {
     if (_actionManager.TryGet(itemlessActionType, out var action))
     {
         actionSlot.Assign(action);
     }
     else
     {
         Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType);
         actionSlot.Clear();
     }
     actionSlot.Cooldown = null;
 }
コード例 #2
0
        private void UpdateActionSlot(ActionType actionType, ActionSlot actionSlot, ActionAssignment?assignedActionType)
        {
            if (_actionManager.TryGet(actionType, out var action))
            {
                actionSlot.Assign(action, true);
            }
            else
            {
                Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType);
                actionSlot.Clear();
                return;
            }

            if (!_actionsComponent.TryGetActionState(actionType, out var actionState) || !actionState.Enabled)
            {
                // action is currently disabled

                // just revoked an action we were trying to target with, stop targeting
                if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action)
                {
                    StopTargeting();
                }

                actionSlot.DisableAction();
                actionSlot.Cooldown = null;
            }
            else
            {
                // action is currently granted
                actionSlot.EnableAction();
                actionSlot.Cooldown = actionState.Cooldown;

                // if we are targeting for this action and it's now on cooldown, stop targeting if we're supposed to
                if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
                    actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown)
                {
                    StopTargeting();
                }
            }

            // check if we need to toggle it
            if (action.BehaviorType == BehaviorType.Toggle)
            {
                actionSlot.ToggledOn = actionState.ToggledOn;
            }
        }
コード例 #3
0
        private void UpdateActionSlot(EntityUid item, ItemActionType itemActionType, ActionSlot actionSlot,
                                      ActionAssignment?assignedActionType)
        {
            if (!_entityManager.TryGetEntity(item, out var itemEntity))
            {
                return;
            }
            if (_actionManager.TryGet(itemActionType, out var action))
            {
                actionSlot.Assign(action, itemEntity, true);
            }
            else
            {
                Logger.ErrorS("action", "unrecognized actionType {0}", assignedActionType);
                actionSlot.Clear();
                return;
            }

            if (!_actionsComponent.TryGetItemActionState(itemActionType, item, out var actionState))
            {
                // action is no longer tied to an item, this should never happen as we
                // check this at the start of this method. But just to be safe
                // we will restore our assignment here to the correct state
                Logger.ErrorS("action", "coding error, expected actionType {0} to have" +
                              " a state but it didn't", assignedActionType);
                _actionsComponent.Assignments.AssignSlot(SelectedHotbar, actionSlot.SlotIndex,
                                                         ActionAssignment.For(itemActionType));
                actionSlot.Assign(action);
                return;
            }

            if (!actionState.Enabled)
            {
                // just disabled an action we were trying to target with, stop targeting
                if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action)
                {
                    StopTargeting();
                }

                actionSlot.DisableAction();
            }
            else
            {
                // action is currently granted
                actionSlot.EnableAction();

                // if we are targeting with an action now on cooldown, stop targeting if we should
                if (SelectingTargetFor?.Action != null && SelectingTargetFor.Action == action &&
                    SelectingTargetFor.Item == itemEntity &&
                    actionState.IsOnCooldown(_gameTiming) && action.DeselectOnCooldown)
                {
                    StopTargeting();
                }
            }
            actionSlot.Cooldown = actionState.Cooldown;

            // check if we need to toggle it
            if (action.BehaviorType == BehaviorType.Toggle)
            {
                actionSlot.ToggledOn = actionState.ToggledOn;
            }
        }