Example #1
0
        private IProp[] GenerateContent(DropTableScheme[] dropTables)
        {
            //TODO Модификаторы нужно будет получать из игрока, актёра, который открыл сундук и актёров, которые на это могу повлиять.
            var modificators  = new DropTableModificatorScheme[0];
            var rolledRecords = new List <DropTableRecordSubScheme>();

            foreach (var table in dropTables)
            {
                var records = table.Records;
                var recMods = GetModRecords(records, modificators);

                var totalWeight = recMods.Sum(x => x.ModifiedWeight);

                // Записи с нулевым весом всегда добавляются.
                rolledRecords.AddRange(records.Where(x => x.Weight == 0));

                for (var rollIndex = 0; rollIndex < table.Rolls; rollIndex++)
                {
                    var rolledWeight = _randomSource.RollWeight(totalWeight);
                    var recMod       = DropRoller.GetRecord(recMods, rolledWeight);

                    if (recMod.Record.SchemeSid == null)
                    {
                        continue;
                    }

                    rolledRecords.Add(recMod.Record);
                }
            }

            var props = rolledRecords.Select(GenerateProp).ToArray();

            return(props);
        }
Example #2
0
        public void GetRecord_RollIn1stBorder_Has1stRecord()
        {
            // ARRANGE
            var records = new[] {
                new DropTableRecordSubScheme("trophy1", 16),
                new DropTableRecordSubScheme("trophy2", 64)
            };

            var roll = 16;

            var recMods = records.Select(x => new DropTableModRecord
            {
                Record         = x,
                ModifiedWeight = x.Weight
            }).ToArray();



            // ACT
            var recordMod = DropRoller.GetRecord(recMods, roll);



            // ASSERT
            recordMod.Record.SchemeSid.Should().Be("trophy1");
        }
Example #3
0
        private IProp[] ResolveInner(IDropTableScheme[] dropTables)
        {
            var modificators  = GetModifiers();
            var rolledRecords = new List <IDropTableRecordSubScheme>();

            var openDropTables = new List <IDropTableScheme>(dropTables);

            while (openDropTables.Any())
            {
                var table   = openDropTables[0];
                var records = table.Records;
                var recMods = GetModRecords(records, modificators);

                var totalWeight = recMods.Sum(x => x.ModifiedWeight);

                for (var rollIndex = 0; rollIndex < table.Rolls; rollIndex++)
                {
                    var rolledWeight = _randomSource.RollWeight(totalWeight);
                    var recMod       = DropRoller.GetRecord(recMods, rolledWeight);

                    if (recMod.Record.SchemeSid == null)
                    {
                        continue;
                    }

                    rolledRecords.Add(recMod.Record);

                    if (recMod.Record.Extra != null)
                    {
                        //TODO Доделать учёт Rolls для экстра.
                        // Сейчас все экстра гарантированно выпадают по разу.
                        openDropTables.AddRange(recMod.Record.Extra);
                    }
                }

                openDropTables.RemoveAt(0);
            }

            var props = rolledRecords.Select(GenerateProp).ToArray();

            return(props);
        }
Example #4
0
        private IProp[] ResolveInner(IDropTableScheme[] dropTables)
        {
            var modificators  = GetModifiers();
            var rolledRecords = new List <IDropTableRecordSubScheme>();

            var openDropTables = new List <IDropTableScheme>(dropTables);

            while (openDropTables.Any())
            {
                try
                {
                    var table = openDropTables[0];

                    var records = table.Records;
                    if (!records.Any())
                    {
                        // Do not try to roll if drop table has no records.

                        // Dont forget to remove empty drop table from open to avoid endless loop.
                        openDropTables.RemoveAt(0);
                        continue;
                    }

                    var recMods = GetModRecords(records, modificators);

                    var totalWeight = recMods.Sum(x => x.ModifiedWeight);

                    Debug.Assert(table.Rolls > 0,
                                 "There is no reason to have zero rolls in table. This is most likely a mistake.");
                    var rolls = table.Rolls;
                    if (rolls == 0)
                    {
                        rolls = 1;
                    }

                    for (var rollIndex = 0; rollIndex < rolls; rollIndex++)
                    {
                        var rolledWeight = _randomSource.RollWeight(totalWeight);
                        var recMod       = DropRoller.GetRecord(recMods, rolledWeight);

                        if (recMod.Record.SchemeSid == null)
                        {
                            continue;
                        }

                        rolledRecords.Add(recMod.Record);

                        if (recMod.Record.Extra != null)
                        {
                            //TODO Доделать учёт Rolls для экстра.
                            // Сейчас все экстра гарантированно выпадают по разу.
                            openDropTables.AddRange(recMod.Record.Extra);
                        }
                    }

                    openDropTables.RemoveAt(0);
                }
                catch
                {
                    openDropTables.RemoveAt(0);
                    //TODO FIX
                }
            }

            var props = rolledRecords.Select(GenerateProp).ToArray();

            return(props);
        }