コード例 #1
0
ファイル: DropItemsList.cs プロジェクト: johndragon/CryoFall
        private static CreateItemResult ExecuteSpawnItem(
            DropItem dropItem,
            DelegateSpawnDropItem delegateSpawnDropItem,
            double probability)
        {
            probability *= DropListItemsCountMultiplier;

            if (!RandomHelper.RollWithProbability(probability))
            {
                return(new CreateItemResult()
                {
                    IsEverythingCreated = true
                });
            }

            var countToSpawn = dropItem.Count
                               + RandomHelper.Next(minValue: 0,
                                                   maxValueExclusive: dropItem.CountRandom + 1);

            if (countToSpawn <= 0)
            {
                // nothing to spawn this time
                return(new CreateItemResult()
                {
                    IsEverythingCreated = true
                });
            }

            if (probability > 1)
            {
                var multiplier = probability;
                countToSpawn = (int)Math.Round(countToSpawn * multiplier,
                                               MidpointRounding.AwayFromZero);
            }

            if (countToSpawn <= 0)
            {
                return(new CreateItemResult()
                {
                    IsEverythingCreated = true
                });
            }

            if (countToSpawn > ushort.MaxValue)
            {
                countToSpawn = ushort.MaxValue;
            }

            return(delegateSpawnDropItem(dropItem.ProtoItem, (ushort)countToSpawn));
        }
コード例 #2
0
        private static CreateItemResult ExecuteSpawnItem(
            DropItem dropItem,
            DelegateSpawnDropItem delegateSpawnDropItem,
            double probability)
        {
            var countToSpawn = dropItem.Count + RandomHelper.Next(0, dropItem.CountRandom + 1);

            if (countToSpawn <= 0)
            {
                return(new CreateItemResult()
                {
                    IsEverythingCreated = true
                });
            }

            // apply probability
            probability = MathHelper.Clamp(probability, 0, 1);
            if (probability < 1)
            {
                var countToSpawnFloat = countToSpawn * probability;
                if (countToSpawnFloat > 1)
                {
                    countToSpawn = (int)Math.Round(RandomHelper.NextDouble() * countToSpawnFloat,
                                                   MidpointRounding.AwayFromZero);
                }
                else
                {
                    // cannot spawn even 1 item... so let's roll and try spawn exactly 1 item
                    // TODO: not sure if we're using the probability correctly here
                    countToSpawn = RandomHelper.RollWithProbability(probability)
                                       ? 1
                                       : 0;
                }
            }

            if (countToSpawn <= 0)
            {
                return(new CreateItemResult()
                {
                    IsEverythingCreated = true
                });
            }

            if (countToSpawn > ushort.MaxValue)
            {
                countToSpawn = ushort.MaxValue;
            }

            return(delegateSpawnDropItem(dropItem.ProtoItem, (ushort)countToSpawn));
        }
コード例 #3
0
ファイル: DropItemsList.cs プロジェクト: johndragon/CryoFall
        /// <summary>
        /// Add item to the droplist.
        /// </summary>
        /// <param name="protoItem">Item prototype instance.</param>
        /// <param name="count">Minimal amount to spawn (if spawning/adding occurs).</param>
        /// <param name="countRandom">
        /// Additional amount to spawn (value selected randomly from 0 to the specified max value
        /// (inclusive) when spawning).
        /// </param>
        /// <param name="weight">
        /// Weight of this item in the droplist (higher weight in comparison to other entries - higher chance
        /// to spawn).
        /// </param>
        /// <param name="condition">(optional) Special condition.</param>
        public DropItemsList Add(
            IProtoItem protoItem,
            ushort count       = 1,
            ushort countRandom = 0,
            double weight      = 1,
            double probability = 1,
            DropItemConditionDelegate condition = null)
        {
            var dropItem = new DropItem(protoItem, count, countRandom);

            this.entries.Add(new ValueWithWeight <Entry>(
                                 new Entry(dropItem, condition, probability),
                                 weight));
            return(this);
        }
コード例 #4
0
ファイル: DropItemsList.cs プロジェクト: johndragon/CryoFall
 public Entry(DropItem dropEntryItem, DropItemConditionDelegate condition, double probability)
     : this(condition, probability)
 {
     this.EntryItem = dropEntryItem;
 }