Ejemplo n.º 1
0
        private void checkTransitions()
        {
            PossibleTransitions.Clear();
            _alwaysVisibleTransitions.Clear();

            // ID локации
            var locationId = CurrentLocation.id;
            // Получаем все переходы с локации
            var transitions = Quest.Transitions.Where(v => v.from == locationId).ToList();

            transitions.ForEach(v => CheckTransition(v));

            //ReduceTransition(CurrentLocation);

            //transitions = transitions.Where(t => CheckTransition(t)).ToList();
        }
Ejemplo n.º 2
0
        private void ReduceTransition(Location currentLocation)
        {
            var rnd = new Random();

            var allTransactions          = new Dictionary <string, IList <Transition> >();
            var alwaysVisibleTransitions = new List <Transition>();

            // Группируем транзакции по имени перехода
            foreach (var possibleTransition in PossibleTransitions)
            {
                IList <Transition> transactionList;
                var titleText = string.IsNullOrEmpty(possibleTransition.title.Text)
                    ?""
                    :possibleTransition.title.Text;
                if (!allTransactions.TryGetValue(titleText, out transactionList))
                {
                    transactionList = new List <Transition>();
                    allTransactions.Add(titleText, transactionList);
                }
                transactionList.Add(possibleTransition);
            }

            // Добавляем всегда видимыет транзакции
            foreach (var alwaysVisibleTransition in _alwaysVisibleTransitions)
            {
                var titleText = string.IsNullOrEmpty(alwaysVisibleTransition.title.Text)
                    ? ""
                    : alwaysVisibleTransition.title.Text;
                if (!allTransactions.ContainsKey(alwaysVisibleTransition.title.Text))
                {
                    alwaysVisibleTransitions.Add(alwaysVisibleTransition);
                }
            }

            //var allTransactions = _possibleTransitions.Concat(_alwaysVisibleTransitions).ToList();

            PossibleTransitions.Clear();
            _alwaysVisibleTransitions.Clear();

            alwaysVisibleTransitions.ForEach(v => _alwaysVisibleTransitions.Add(v));

            foreach (var allTransaction in allTransactions)
            {
                if (allTransaction.Value.Count == 1)
                {
                    var transition = allTransaction.Value.Single();
                    var priority   = transition.priority;
                    if (priority < 1f)
                    {
                        if (rnd.Next(1000) < (int)(priority * 1000))
                        {
                            PossibleTransitions.Add(transition);
                        }
                    }
                    else
                    {
                        PossibleTransitions.Add(transition);
                    }
                    continue;
                }
                var        allRange          = allTransaction.Value.Sum(v => v.priority);
                var        randValue         = rnd.Next((int)(allRange * 1000));
                var        countPriority     = 0;
                Transition selectTransaction = null;
                foreach (var transition in allTransaction.Value)
                {
                    selectTransaction = transition;
                    countPriority     = (int)(transition.priority * 1000);
                    if (countPriority >= randValue)
                    {
                        break;
                    }
                }
                PossibleTransitions.Add(selectTransaction);
            }
        }