Exemple #1
0
        public GameObject.MapEntities.Actors.NPC GenerateOneNPC()
        {
            GameObject.MapEntities.Actors.NPC npc = new GameObject.MapEntities.Actors.NPC("Hello. I am an NPC.");
            npc.Commands = new List <GameObject.Interactions.NPCCommand>();

            npc.Commands.Add(new GameObject.Interactions.NPCCommands.OpenShop()
            {
                Label = "Shop"
            });
            Vector3 pos = new Vector3(RNG.NextInt(63), 0, RNG.NextInt(63));

            npc.Position    = pos;
            npc.Heading     = RNG.NextInt(350);
            npc.DisplayName = "npc";
            return(npc);
        }
Exemple #2
0
        public int BeginTeleport(int entityId, Vector3 target)
        {
            int id;

            do
            {
                id = _randomProvider.NextInt();
            } while (_teleportIds.ContainsKey(id));

            _teleportIds[id] = new TeleportInfo(entityId, target);
            return(id);
        }
        public Monster GenerateOneMonster()
        {
            Monster monster = new Monster();

            monster.Model       = GameModel.ModelGeometryCompiler.LoadModel("default");
            monster.DisplayName = "monster. kill me please.";
            Vector3 pos = new Vector3(RNG.NextInt(63), 0, RNG.NextInt(63));

            monster.Position             = pos;
            monster.LeashRadius          = 30;
            monster.PrimaryLootRollCount = 2;
            monster.PrimaryLootTable     = new List <Tuple <int, Item> >();
            ItemConsumable potA = new ItemConsumable
            {
                Colour = new Color(200, 50, 0),
                Name   = "HP potion"
            };
            ItemConsumable potB = new ItemConsumable
            {
                Colour = new Color(0, 100, 200),
                Name   = "MP potion"
            };
            Material  matA  = Material.MaterialTemplates.GetRandomMaterial();
            ItemEquip weapA = new ItemEquip();

            BonusPool p = BonusPool.Load("heavy_0_10");

            weapA.Bonuses.Add(p.PickBonus());
            weapA.Bonuses.Add(p.PickBonus());
            weapA.SubType           = RNG.NextInt(0, 1) * 4;
            weapA.PrimaryMaterial   = Material.MaterialTemplates.GetRandomMaterial();
            weapA.SecondaryMaterial = Material.MaterialTemplates.GetRandomMaterial();
            monster.PrimaryLootTable.Add(new Tuple <int, Item>(5, potA));
            monster.PrimaryLootTable.Add(new Tuple <int, Item>(5, potB));
            monster.PrimaryLootTable.Add(new Tuple <int, Item>(1, matA));
            monster.PrimaryLootTable.Add(new Tuple <int, Item>(3, null));
            monster.PrimaryLootTable.Add(new Tuple <int, Item>(10, weapA));

            return(monster);
        }
Exemple #4
0
        public WithinAgentTransition <T>[] GetOutgoingWithinHostTransitions(bool shuffle, IRandomProvider random)
        {
            if (_permutationCacheSize != WithinHostTransitionsFromState.Count)
            {
                GeneratePermutationCache();
            }

            if (!shuffle || WithinHostTransitionsFromState.Count <= 1)
            {
                return(_cachedPermutations[0]); // the first permutation is always in order
            }
            else
            {
                var permutationIdx = random.NextInt(0, _permutationCacheSize - 1);

                return(_cachedPermutations[permutationIdx]);
            }
        }
Exemple #5
0
        public static async Task <BigInteger> GenerateAsync(BigInteger maxExclusive, IRandomProvider randomProvider)
        {
            if (randomProvider == null)
            {
                throw new ArgumentNullException(nameof(randomProvider));
            }
            if (maxExclusive == BigIntegerHelpers.Zero)
            {
                throw new ArgumentOutOfRangeException(nameof(maxExclusive), "Max exclusive must be above 0.");
            }

            if (maxExclusive == BigIntegerHelpers.One)
            {
                return(BigInteger.Zero);
            }

            if (maxExclusive < new BigInteger(int.MaxValue))
            {
                return(new BigInteger(randomProvider.NextInt((int)maxExclusive)));
            }

            var        bytes  = maxExclusive.ToByteArray();
            BigInteger result = 0;

            await Task.Run(() =>
            {
                do
                {
                    randomProvider.NextBytes(bytes);
                    if (bytes.All(v => v == 0))
                    {
                        throw new InvalidOperationException("Zero buffer returned by random provider.");
                    }

                    bytes[bytes.Length - 1] &= 0x7F;
                    result = new BigInteger(bytes);
                } while (result >= maxExclusive || result.Equals(BigIntegerHelpers.One) ||
                         result.Equals(BigIntegerHelpers.Zero));
            });

            return(result);
        }
Exemple #6
0
        public static List <int> ReservoirSampling(IEnumerable <double> weightStream, int k, IRandomProvider random)
        {
            var wSum = 0d;
            var r    = new List <int>(k);

            if (k == 0)
            {
                return(r);
            }

            using var enumerator = weightStream.GetEnumerator();
            for (var x = 0; x < k; x++)
            {
                enumerator.MoveNext();
                var currentWeight = enumerator.Current;
                r.Add(x);
                wSum += currentWeight;
            }

            var i = k;

            while (enumerator.MoveNext())
            {
                wSum += enumerator.Current;
                var p = enumerator.Current / wSum;
                var j = random.NextDouble();
                if (j <= p)
                {
                    var index = random.NextInt(0, k);
                    r[index] = i;
                }

                i++;
            }

            return(r);
        }