Esempio n. 1
0
    public void RunAction(IGameAction action)
    {
        if (_currentAction != null)
        {
            return;
        }

        //Пропуск хода
        if (action == null)
        {
            EndAction(null);
            return;
        }

        if (action.Check())
        {
            OnActionStart?.Invoke(action);
            _currentAction = action;
            action.status  = actionStatuses.start;
            StartCoroutine(action.Execute());
        }
        else
        {
            Debug.LogFormat("Действие {0} не прошло проверку", action.GetType());
        }
    }
Esempio n. 2
0
        /// <summary>
        /// Serializes the given IGameAction (all ContructorFields).
        /// </summary>
        /// <param name="rootElement">The parent element.</param>
        /// <param name="gameAction">The serializing IGameAction.</param>
        private void SerializeGameAction(XElement rootElement, IGameAction gameAction)
        {
            var element = new XElement("gameAction", new XAttribute("name", gameAction.GetType().ToString().Split('.').Last()));

            rootElement.Add(element);
            foreach (var item in GetSortedArgsToSerialization(gameAction))
            {
                SerializeArgument(element, item.Value);
            }
        }
        /// <summary>
        /// 转换Action
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="inputAction"></param>
        /// <param name="outputAction"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        protected bool ParseAction <T>(IGameAction inputAction, out T outputAction, out string error)
            where T : class, IGameAction
        {
            if (inputAction is T)
            {
                outputAction = inputAction as T;
                error        = null;
                return(true);
            }

            outputAction = null;
            error        = GetActionTypeErrorString(inputAction.GetType().Name, typeof(T).Name);
            return(false);
        }
Esempio n. 4
0
        public Optional.Option <Engine, IEnumerable <string> > Perform(
            [NotNull] IGameAction action)
        {
            var rules = this.Rules.GetValueOrDefault(action.GetType());

            if (rules == null)
            {
                return(Option.None <Engine, IEnumerable <string> >(new string[] { $"Engine does not not {action.GetType().FullName} actions" }));
            }

            if (!rules.All(rule => rule.Verify(this, action)))
            {
                return(Option.None <Engine, IEnumerable <string> >(new string[] {}));
            }

            var newEngine = Engine.NextTurn(action.Perform(this));

            return(Option.Some <Engine, IEnumerable <string> >(newEngine));
        }
 /// <summary>
 /// Serializes the given IGameAction (all ContructorFields).
 /// </summary>
 /// <param name="rootElement">The parent element.</param>
 /// <param name="gameAction">The serializing IGameAction.</param>
 private void SerializeGameAction(XElement rootElement, IGameAction gameAction)
 {
     var element = new XElement("gameAction", new XAttribute("name", gameAction.GetType().ToString().Split('.').Last()));
     rootElement.Add(element);
     foreach (var item in GetSortedArgsToSerialization(gameAction)) {
         SerializeArgument(element, item.Value);
     }
 }