Example #1
0
        /// <summary>
        /// Returns a <see cref="String"/> that represents the common threshold value, if any, for
        /// all conditions based on the specified game parameter.</summary>
        /// <param name="victory">
        /// <c>true</c> to consider <see cref="FactionClass.VictoryConditions"/>; <c>false</c> to
        /// consider <see cref="FactionClass.DefeatConditions"/>.</param>
        /// <param name="parameter">
        /// A <see cref="ConditionParameter"/> value indicating which element of each <see
        /// cref="Condition"/> collection to consider.</param>
        /// <returns><para>
        /// An em dash (—) if no faction defines a <see cref="Condition"/> with the specified
        /// <paramref name="parameter"/>.
        /// </para><para>-or-</para><para>
        /// The <see cref="Condition.Threshold"/> value of each <see cref="Condition"/> with the
        /// specified <paramref name="parameter"/> if it is equal for all factions.
        /// </para><para>-or-</para><para>
        /// An asterisk "*" if neither of the above is true.</para></returns>

        private string GetCommonThreshold(bool victory, ConditionParameter parameter)
        {
            var factions = this._worldState.Factions;

            if (factions.Count == 0)
            {
                return("—");
            }

            // get presence and data of first faction's condition
            var conditions = GetFactionConditions(factions[0], victory);

            Condition firstCondition;
            bool      firstPresent = conditions.TryGetValue(parameter, out firstCondition);

            // get other factions' conditions where present
            for (int i = 1; i < factions.Count; i++)
            {
                Condition condition;
                conditions = GetFactionConditions(factions[i], victory);
                bool present = conditions.TryGetValue(parameter, out condition);

                // check for different presence or condition
                if (present != firstPresent || (present && condition != firstCondition))
                {
                    return("*");
                }
            }

            // use common threshold or else common absence indicator
            return(firstPresent ?
                   firstCondition.Threshold.ToString(ApplicationInfo.Culture) : "—");
        }
Example #2
0
    public bool Condition(ConditionParameter conditionParameter)
    {
        bool result = true;
        List <ConditionGroupParameter> groupList = conditionParameter.GetGroupList();

        for (int i = 0; i < groupList.Count; ++i)
        {
            ConditionGroupParameter groupParameter = groupList[i];
            result = true;

            for (int j = 0; j < groupParameter.parameterList.Count; ++j)
            {
                BehaviorParameter parameter = groupParameter.parameterList[j];
                bool value = Condition(parameter);
                if (!value)
                {
                    result = false;
                    break;
                }
            }

            if (result)
            {
                break;
            }
        }

        return(result);
    }
Example #3
0
        public bool Condition(ConditionParameter conditionParameter)
        {
            bool result = true;

            for (int i = 0; i < conditionParameter.groupList.Count; ++i)
            {
                TransitionGroupParameter groupParameter = conditionParameter.groupList[i];
                result = true;

                for (int j = 0; j < groupParameter.parameterList.Count; ++j)
                {
                    SkillHsmConfigHSMParameter parameter = groupParameter.parameterList[j];
                    bool value = Condition(parameter);
                    if (!value)
                    {
                        result = false;
                        break;
                    }
                }

                if (result)
                {
                    break;
                }
            }

            return(result);
        }
Example #4
0
        public virtual void AddTransition(SkillHsmConfigTransition transition)
        {
            _transitionList.Add(transition);

            ConditionParameter conditionParametr = new ConditionParameter();

            conditionParametr.SetGroup(transition);
            _conditionParameterDic[transition.TransitionId] = conditionParametr;
        }
Example #5
0
        public bool Apply(ConditionParameter param, object paramValue, object inputValue)
        {
            Require.NotNull(param, "param");
            Require.NotNull(paramValue, "paramValue");
            Require.That(paramValue is IComparable, "paramValue", "Require comparable parameter value.");
            Require.NotNull(inputValue, "inputValue");
            Require.That(inputValue is IComparable, "inputValue", "Require comparable input value.");

            return ((IComparable)paramValue).CompareTo((IComparable)inputValue) > 0;
        }
Example #6
0
        /// <summary>
        /// 执行节点抽象方法
        /// </summary>
        /// <returns>返回执行结果</returns>
        public virtual int Execute(ref bool result)
        {
            result = false;
#if UNITY_EDITOR
            NodeNotify.NotifyExecute(NodeId, Time.realtimeSinceStartup);
#endif
            int toStateId = -1;
            for (int i = 0; i < _transitionList.Count; ++i)
            {
                SkillHsmConfigTransition transition         = _transitionList[i];
                ConditionParameter       conditionParameter = null;
                if (_conditionParameterDic.TryGetValue(transition.TransitionId, out conditionParameter))
                {
                    result = _iconditionCheck.Condition(conditionParameter);
                }
                if (result)
                {
                    toStateId = transition.ToStateId;
                    break;
                }
            }

            return(toStateId);
        }
Example #7
0
        /// <summary>
        /// Handles the <see cref="Selector.SelectionChanged"/> event for the "Compare" <see
        /// cref="ListView"/> on the <see cref="TablesTab"/> page.</summary>
        /// <param name="sender">
        /// The <see cref="Object"/> where the event handler is attached.</param>
        /// <param name="args">
        /// A <see cref="SelectionChangedEventArgs"/> object containing event data.</param>
        /// <remarks>
        /// <b>OnCompareTableSelected</b> updates the "Defeat" and "Victory" text boxes and the
        /// "Faction" list view to reflect the selected ranking criterion.</remarks>

        private void OnCompareTableSelected(object sender, SelectionChangedEventArgs args)
        {
            args.Handled = true;

            // retrieve selected item, if any
            CompareListItem item = CompareTableList.SelectedItem as CompareListItem;

            // clear faction list
            FactionList.Items.Clear();

            // clear thresholds if selection cleared
            if (item == null)
            {
                DefeatInfo.Clear();
                VictoryInfo.Clear();
                return;
            }

            // retrieve selected criterion
            string id       = item.Item3 as String;
            var    resource = item.Item3 as ResourceClass;

            if (resource != null)
            {
                id = resource.Id;
            }

            // show faction ranking
            CreateFactionRows(resource, id);

            string defeatText  = "—"; // em dash
            string victoryText = "—"; // em dash

            if (resource != null)
            {
                // show global thresholds for resource conditions
                if (resource.Defeat != Int32.MinValue)
                {
                    defeatText = resource.Format(resource.Defeat, false);
                }

                if (resource.Victory != Int32.MaxValue)
                {
                    victoryText = resource.Format(resource.Victory, false);
                }
            }
            else
            {
                ConditionParameter parameter = ConditionParameter.Turns;
                switch (id)
                {
                case "sites": parameter = ConditionParameter.Sites; break;

                case "units": parameter = ConditionParameter.Units; break;

                case "unit-strength": parameter = ConditionParameter.UnitStrength; break;
                }

                // show common thresholds for specific conditions
                if (parameter != ConditionParameter.Turns)
                {
                    defeatText  = GetCommonThreshold(false, parameter);
                    victoryText = GetCommonThreshold(true, parameter);
                }
            }

            // show or clear thresholds
            DefeatInfo.Text  = defeatText;
            VictoryInfo.Text = victoryText;
        }
 public bool Apply(ConditionParameter param, object paramValue, object inputValue)
 {
     return !ComparisonOperators.GreaterThan.Apply(param, paramValue, inputValue);
 }
Example #9
0
            /// <summary>
            /// Initializes a new instance of the <see cref="ConditionListItem"/> class with the
            /// specified <see cref="ConditionParameter"/>.</summary>
            /// <param name="parameter">
            /// The initial value for the <see cref="Parameter"/> and <see cref="ParameterText"/>
            /// properties.</param>
            /// <exception cref="InvalidEnumArgumentException">
            /// <paramref name="parameter"/> is not a valid <see cref="ConditionParameter"/> value.
            /// </exception>

            public ConditionListItem(ConditionParameter parameter)
            {
                Parameter     = parameter;
                ParameterText = Condition.GetParameterString(parameter);
            }