Example #1
0
        /// <summary>
        /// <para> NonNegative range: (0, 0) (inclusive) -> (<see cref="float.MaxValue"/>, <see cref="float.MaxValue"/>) (exclusive) </para>
        /// <para> All range: (<see cref="float.MinValue"/>, <see cref="float.MinValue"/>) (inclusive) -> (<see cref="float.MaxValue"/>, <see cref="float.MaxValue"/>) (exclusive) </para>
        /// </summary>
        public Vector2 Next(RandomRange rangeType = RandomRange.NonNegative)
        {
            var x = _parent.Float.NextUnl(rangeType);
            var y = _parent.Float.NextUnl(rangeType);

            return(new Vector2(x, y));
        }
Example #2
0
        /// <summary>
        /// <para> NonNegative range: 0 (inclusive) -> <see cref="double.MaxValue"/> (exclusive) </para>
        /// <para> All range: <see cref="double.MinValue"/> (inclusive) -> <see cref="double.MaxValue"/> (exclusive) </para>
        /// </summary>
        public double NextUnl(RandomRange rangeType = RandomRange.NonNegative)
        {
            double mantissa = (Next01(rangeType) * 2.0d) - 1.0d;
            double exponent = Math.Pow(2.0d, _parent.Int.FromRange(-126, 128));

            return(mantissa * exponent);
        }
Example #3
0
 public void StartStagger()
 {
     OnAttackInterrupt();
     animator.SetState(PigmanAnimatorState.Stagger);
     phase           = PigmanAttackPhase.Stagger;
     staggerTimeLeft = RandomRange.FromVector(data.staggerTime);
 }
Example #4
0
        /// <summary>
        /// <para> NonNegative range: 0 (inclusive) -> <paramref name="max"/> (exclusive) </para>
        /// <para> All range: -1 (exclusive) -> <paramref name="max"/> (exclusive) </para>
        /// </summary>
        public double Next01Max(double max, RandomRange rangeType = RandomRange.NonNegative)
        {
            switch (rangeType)
            {
            case RandomRange.NonNegative:
                if (max <= 0d || max > 1d)
                {
                    throw new ArgumentOutOfRangeException("max", max,
                                                          "The 'max' parameter for this method must be in range of 0 (exclusive) and +1 (inclusive) when the 'rangeType' parameter is 'NonNegative'.");
                }

                return(FromRange(0d, max));

            case RandomRange.All:
                if (max <= -1d || max > 1d)
                {
                    throw new ArgumentOutOfRangeException("max", max,
                                                          "The 'max' parameter for this method must be in range of -1 (exclusive) and +1 (inclusive) when the 'rangeType' parameter is 'All'.");
                }

                var dist  = max + 1;              //the distance between max and -1.
                var syMax = dist / 2;             //the new max value that makes symetrical '-syMax 0 +syMax' range.
                var syRnd = FromRange(0d, syMax) *
                            _parent.RandomSign(); //a random in range '-syMax -> +syMax' (both exclusive).
                var diff = syMax - max;           //difference between original max and syMax.
                return
                    (syRnd - diff);               //remove the difference from syRnd so we get the random number in original range.

            default:
                throw new ArgumentOutOfRangeException("rangeType", rangeType, null);
            }
        }
Example #5
0
    public static void HitCheck(WeaponInfoObject usedWeapon, int aim)
    {
        hitChance = aim;

        //hitChance= (coverIntervenience + weaponBaseAccuracy + WeaponProficiency + heightAdvantage + Bonuses - Penalties - (distance * weapontypeRange))
        hitRoll = RandomRange.RollDice(1, 100);
        if (hitRoll <= hitChance)
        {
            //Run damage script
            DamageDealt(usedWeapon.baseDamage, usedWeapon.numberOfDiceDamage, usedWeapon.numberOfSidesDamage, true);
        }
        else
        {
            //Run damage script
            DamageDealt(0, 0, 0, false);
        }

        //int tempCase = usedWeapon.weaponRange;
        //switch (tempCase)
        //{
        //    case 0:
        //        Debug.Log("case 1");
        //        break;
        //    case 2:
        //        Debug.Log("case 2");
        //        break;
        //    default:
        //        Debug.Log("default");
        //        break;
        //}
    }
Example #6
0
    public void StateStart()
    {
        animationEvents.OnRoarEnd    += OnRoarEnd;
        animationEvents.OnStandUpEnd += OnStandUpEnd;

        physics.flip.Direction = moveDirection;
        if (animator.IsState(PigmanAnimatorState.Sit))
        {
            animator.SetState(PigmanAnimatorState.StandUp);
            phase = Phase.Stand;
        }
        else
        {
            float waitToRunTime = RandomRange.FromVector(data.abandonChaseTime);
            if (waitToRunTime > 0)
            {
                waitTimeLeft = waitToRunTime;
                animator.SetState(PigmanAnimatorState.Idle);
                phase = Phase.Wait;
            }
            else
            {
                animator.SetState(PigmanAnimatorState.Run);
                phase = Phase.Run;
            }
        }
    }
Example #7
0
 public void StartParry()
 {
     OnAttackInterrupt();
     animator.SetState(PigmanAnimatorState.Parry);
     phase         = PigmanAttackPhase.Parry;
     parryTimeLeft = RandomRange.FromVector(data.parryTime);
     AudioSingleton.PlaySound(AudioSingleton.Instance.clips.parry);
 }
        public override void LoadFrom(IniFile ini)
        {
            base.LoadFrom(ini);

            this.FancyName = ini.GetEntryValue(this.ToString(), "fancyname").ToString();
            string mass = ini.GetEntryValue(this.ToString(), "mass").ToString();

            this.Mass = new RandomRange();
            this.ParseNumberOrTuple(mass, ref Mass.Min, ref Mass.Max);
        }
Example #9
0
    public static void DamageDealt(int baseDamage, int numberOfDiceDamage, int numberOfSideDamage, bool contact)
    {
        int n = 0;

        //Get Weapon damage parameters
        n = RandomRange.RollDice(numberOfDiceDamage, numberOfSideDamage);

        //Give Damage dealt
        hit    = contact;
        damage = n + baseDamage;
    }
Example #10
0
    IEnumerator SpawnObjects()
    {
        while (isGameActive)
        {
            yield return(new WaitForSeconds(Random.Range(spawnRateMin, spawnRateMax)));

            int index = (int)RandomRange.Range(
                new FloatRange(0f, 1f, weightEnemy),
                new FloatRange(1f, 2f, weightPowerup),
                new FloatRange(2f, 3f, weightPoint)
                );
            Instantiate(assets[index], RandomStartPos(), assets[index].transform.rotation);
            Debug.Log("Spawn enemy");
        }
    }
Example #11
0
    void fillItem(GameObject[] itemRange, RandomRange itemCountRange)
    {
        int        numberOfItems = itemCountRange.getRand();
        GameObject instance;

        for (int i = 0; i < numberOfItems; i++)
        {
            int        itemPositionIndex = new RandomRange(0, layout.Count - 1).getRand();
            Vector3    itemPosition      = layout[itemPositionIndex];
            GameObject itemType          = itemRange[new RandomRange(0, itemRange.Length - 1).getRand()];
            instance = Instantiate(itemType, itemPosition, Quaternion.identity) as GameObject;
            instance.transform.SetParent(boardHolder);
            layout.RemoveAt(itemPositionIndex);
        }
    }
        /// <summary>
        /// <para> NonNegative range: 0 (inclusive) -> <see cref="int.MaxValue"/> (exclusive) </para>
        /// <para> All range: <see cref="int.MinValue"/> (inclusive) -> <see cref="int.MaxValue"/> (exclusive) </para>
        /// </summary>
        public int Next(RandomRange rangeType = RandomRange.NonNegative)
        {
            switch (rangeType)
            {
            case RandomRange.NonNegative:
                // The System.Random.Next() is NonNegative.
                return(_parent.Random.Next());

            case RandomRange.All:
                return(_parent.Random.Next(int.MinValue, int.MaxValue));

            default:
                throw new ArgumentOutOfRangeException("rangeType", rangeType, null);
            }
        }
Example #13
0
        /// <summary>
        /// <para> NonNegative range: 0 (inclusive) -> +1 (exclusive) </para>
        /// <para> All range: -1 (exclusive) -> +1 (exclusive) </para>
        /// </summary>
        public double Next01(RandomRange rangeType = RandomRange.NonNegative)
        {
            switch (rangeType)
            {
            case RandomRange.NonNegative:
                // The System.Random.NextDouble() is NonNegative.
                return(_parent.Random.NextDouble());

            case RandomRange.All:
                // We need to randomize the sign, because the System.Random.NextDouble() is NonNegative.
                return(_parent.Random.NextDouble() * 2 - 1);

            default:
                throw new ArgumentOutOfRangeException("rangeType", rangeType, null);
            }
        }
Example #14
0
        static void BackProcess(object delay)
        {
            IntPtr consoleWindow = Win32.Imports.FindWindowByCaption(IntPtr.Zero, _APP_NAME);

            RandomRange keyIndexRange = new RandomRange(0, _KEYS.Length);
            RandomRange delayRange    = delay.GetType() == typeof(RandomRange) ? (RandomRange)delay : new RandomRange(0, 0);

            const uint msg_KeyDown = 0x0100, msg_KeyUp = 0x0101;

            while (_STATUS == ProcessStatus.Found)
            {
                _PROCESS_HWND = Win32.Imports.FindWindowByCaption(IntPtr.Zero, _PROCESS_NAME);

                // TODO: user can add in new keys, or delete. and can set associated timers with each key.
                if (_PROCESS_HWND != IntPtr.Zero)
                {
                    Thread.Sleep(delayRange.Next());
                    {
                        // TODO: MAIN PROCESSING GOES HERE
                        int keyIndex = keyIndexRange.Next();
                        Console.WriteLine(keyIndex);

                        uint vKey = _KEYS[keyIndex];
                        uint sKey = Win32.Imports.MapVirtualKeyA(vKey, 0);

                        Win32.Imports.SendNotifyMessageA(_PROCESS_HWND, msg_KeyDown, vKey, 0x00000000 | (sKey << 16)
                                                         | 0x00000000 | 0x00000000 | 0x00000000);
                        Win32.Imports.SendNotifyMessageA(_PROCESS_HWND, msg_KeyUp, vKey, 0x00000000 | (sKey << 16)
                                                         | 0x00000000 | 0x00000000 | 0x00000000);
                    }
                }
                else
                {
                    _MUT.WaitOne();
                    _STATUS = ProcessStatus.Terminated;
                    _MUT.ReleaseMutex();
                }
            }

            Console.WriteLine("Now terminating.");
        }
        /// <summary>
        /// <para> NonNegative range: 0 (inclusive) -> <paramref name="max"/> (exclusive) </para>
        /// <para> All range: <see cref="int.MinValue"/> (inclusive) -> <paramref name="max"/> (exclusive) </para>
        /// </summary>
        public int NextMax(int max, RandomRange rangeType = RandomRange.NonNegative)
        {
            switch (rangeType)
            {
            case RandomRange.NonNegative:
                if (max < 0)
                {
                    throw new ArgumentOutOfRangeException("max", max,
                                                          "The 'max' parameter cannot be negative when the 'rangeType' parameter is 'NonNegative'.");
                }

                // The System.Random.Next() is NonNegative.
                return(_parent.Random.Next(max));

            case RandomRange.All:
                return(_parent.Random.Next(int.MinValue, max));

            default:
                throw new ArgumentOutOfRangeException("rangeType", rangeType, null);
            }
        }
Example #16
0
    void fillFloor()
    {
        RandomRange floorRange      = new RandomRange(0, floorTiles.Length - 1);
        RandomRange outerWallsRange = new RandomRange(0, outerWallTiles.Length - 1);
        GameObject  instance;

        for (int i = 0; i < columns; i++)
        {
            for (int j = 0; j < rows; j++)
            {
                if ((i == 0 || i == columns - 1) || (j == 0 || j == rows - 1))
                {
                    instance = Instantiate(outerWallTiles[outerWallsRange.getRand()], new Vector3(i, j, 0), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }
                else
                {
                    instance = Instantiate(floorTiles[floorRange.getRand()], new Vector3(i, j, 0), Quaternion.identity) as GameObject;
                    instance.transform.SetParent(boardHolder);
                }
            }
        }
    }
Example #17
0
        public void TestIRandomExtensionMethods()
        {
            IRandom rand = new TinyMT();

            rand.Init(1); // 2545341989 will be the first number
            Assert.IsTrue(rand.Generate(0, 5) == 4); // 2545341989 % 5 = 4

            rand.Init(1);
            Assert.IsTrue(rand.Generate(1, 6) == 5); // 2545341989 % 5 + 1 = 5

            rand.Init(1);
            Assert.IsTrue(rand.PickElement(new uint[] { 0, 1, 2, 3, 4 }) == 4); // 2545341989 % 5 = 4, so 4th element

            rand.Init(1);
            Assert.IsTrue(rand.DieRoll(10) == 10); // last digit of 2545341989 plus one

            RandomRange range = new RandomRange(0, 10, 3);
            rand.Init(1);
            // first random number: 2545341989 % 10 = 9
            // second random number: 981918433 % 10 = 3
            // third random number: 3715302833 % 10 = 3
            // total: 15, over three passes: result = 5
            Assert.IsTrue(rand.Generate(range) == 5);
        }
Example #18
0
        private static AudioProperties ReadAudioProperties(this BinaryReader reader)
        {
            AudioProperties audioProperties = default;

            audioProperties.OverrideEffects = reader.ReadBoolean();
            audioProperties.EffectCount     = reader.ReadByte();
            if (audioProperties.EffectCount > 0)
            {
                audioProperties.BypassedEffects = (BypassedEffects)reader.ReadByte();
            }
            audioProperties.Effects = new Effect[audioProperties.EffectCount];
            for (var i = 0; i < audioProperties.EffectCount; i++)
            {
                Effect effect = default;
                effect.Index               = reader.ReadByte();
                effect.Id                  = reader.ReadUInt32();
                effect.UseShareSets        = reader.ReadBoolean();
                effect.Rendered            = reader.ReadBoolean();
                audioProperties.Effects[i] = effect;
            }
            audioProperties.Unknown_1      = reader.ReadByte();
            audioProperties.OutputBusId    = reader.ReadUInt32();
            audioProperties.ParentId       = reader.ReadUInt32();
            audioProperties.MidiOverride   = (Override)reader.ReadByte();
            audioProperties.ParameterCount = reader.ReadByte();
            audioProperties.ParameterTypes = new AudioParameterType[audioProperties.ParameterCount];
            for (var i = 0; i < audioProperties.ParameterCount; i++)
            {
                audioProperties.ParameterTypes[i] = (AudioParameterType)reader.ReadByte();
            }
            audioProperties.ParameterValues = new ValueType[audioProperties.ParameterCount];
            for (var i = 0; i < audioProperties.ParameterCount; i++)
            {
                var parameterType = audioProperties.ParameterTypes[i].ToString();
                if (parameterType.EndsWith("_UInt"))
                {
                    audioProperties.ParameterValues[i] = reader.ReadUInt32();
                }
                else if (parameterType.EndsWith("_Int"))
                {
                    audioProperties.ParameterValues[i] = reader.ReadInt32();
                }
                else
                {
                    audioProperties.ParameterValues[i] = reader.ReadSingle();
                }
            }
            audioProperties.Unknown_2   = reader.ReadByte();
            audioProperties.Positioning = (PositioningBehavior)reader.ReadByte();
            if (audioProperties.Positioning.HasFlag(PositioningBehavior.ThreeDimensional))
            {
                audioProperties.IsGameDefined = reader.ReadBoolean();
                audioProperties.AttenuationId = reader.ReadUInt32();
                if (!audioProperties.IsGameDefined)
                {
                    audioProperties.UserDefinedPlaySettings = (PositionEditorSettings)reader.ReadByte();
                    audioProperties.TransitionTime          = reader.ReadUInt32();
                    audioProperties.ControlPointKeyCount    = reader.ReadUInt32();
                    audioProperties.ControlPointKeys        = new ControlPointKey[audioProperties.ControlPointKeyCount];
                    for (var i = 0; i < audioProperties.ControlPointKeyCount; i++)
                    {
                        ControlPointKey controlPointKey = default;
                        controlPointKey.X                   = reader.ReadSingle();
                        controlPointKey.Z                   = reader.ReadSingle();
                        controlPointKey.Y                   = reader.ReadSingle();
                        controlPointKey.Timestamp           = reader.ReadUInt32();
                        audioProperties.ControlPointKeys[i] = controlPointKey;
                    }
                    audioProperties.RandomRangeCount    = reader.ReadUInt32();
                    audioProperties.RandomRangeUnknowns = new RandomRangeUnknown[audioProperties.RandomRangeCount];
                    for (var i = 0; i < audioProperties.RandomRangeCount; i++)
                    {
                        RandomRangeUnknown randomRangeUnknown = default;
                        randomRangeUnknown.Unknown_0           = reader.ReadUInt32();
                        randomRangeUnknown.Unknown_4           = reader.ReadUInt32();
                        audioProperties.RandomRangeUnknowns[i] = randomRangeUnknown;
                    }
                    audioProperties.RandomRanges = new RandomRange[audioProperties.RandomRangeCount];
                    for (var i = 0; i < audioProperties.RandomRangeCount; i++)
                    {
                        RandomRange randomRange = default;
                        randomRange.LeftRight           = reader.ReadSingle();
                        randomRange.FrontBack           = reader.ReadSingle();
                        randomRange.UpDown              = reader.ReadSingle();
                        audioProperties.RandomRanges[i] = randomRange;
                    }
                }
            }
            audioProperties.AuxSendsBehavior = (AuxSendsBehavior)reader.ReadByte();
            if (audioProperties.AuxSendsBehavior.HasFlag(AuxSendsBehavior.OverrideAuxSends))
            {
                audioProperties.AuxiliarySendBusIds    = new uint[4];
                audioProperties.AuxiliarySendBusIds[0] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[1] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[2] = reader.ReadUInt32();
                audioProperties.AuxiliarySendBusIds[3] = reader.ReadUInt32();
            }
            audioProperties.LimitBehavior = (SoundLimitBehavior)reader.ReadByte();
            audioProperties.VirtualVoiceReturnBehavior = (VirtualVoiceReturnBehavior)reader.ReadByte();
            audioProperties.Unknown_3            = reader.ReadByte();
            audioProperties.Unknown_4            = reader.ReadByte();
            audioProperties.VirtualVoiceBehavior = (VirtualVoiceBehavior)reader.ReadByte();
            audioProperties.HdrBehavior          = (HdrBehavior)reader.ReadByte();
            audioProperties.StateGroupCount      = reader.ReadUInt32();
            audioProperties.StateGroups          = new StateGroup[audioProperties.StateGroupCount];
            for (var i = 0; i < audioProperties.StateGroupCount; i++)
            {
                StateGroup stateGroup = new StateGroup();
                stateGroup.Id             = reader.ReadUInt32();
                stateGroup.ChangeOccursAt = (InteractiveMusicKeyPoint)reader.ReadByte();
                stateGroup.StateWithCustomSettingsCount = reader.ReadUInt16();
                stateGroup.StateWithCustomSettings      = new StateWithCustomSettings[stateGroup.StateWithCustomSettingsCount];
                for (var j = 0; j < stateGroup.StateWithCustomSettingsCount; j++)
                {
                    StateWithCustomSettings stateWithCustomSettings = default;
                    stateWithCustomSettings.StateId       = reader.ReadUInt32();
                    stateWithCustomSettings.SettingsId    = reader.ReadUInt32();
                    stateGroup.StateWithCustomSettings[j] = stateWithCustomSettings;
                }
                audioProperties.StateGroups[i] = stateGroup;
            }
            audioProperties.RtpcCount = reader.ReadUInt16();
            audioProperties.Rtpcs     = new Rtpc[audioProperties.RtpcCount];
            for (var i = 0; i < audioProperties.RtpcCount; i++)
            {
                Rtpc rtpc = new Rtpc();
                rtpc.X                 = reader.ReadUInt32();
                rtpc.IsMidi            = reader.ReadBoolean();
                rtpc.IsGeneralSettings = reader.ReadBoolean();
                rtpc.Parameter         = (RtpcParameterType)reader.ReadByte();
                rtpc.UnknownId         = reader.ReadUInt32();
                rtpc.CurveScalingType  = (CurveScalingType)reader.ReadByte();
                rtpc.PointCount        = reader.ReadUInt16();
                rtpc.Points            = new RtpcPoint[rtpc.PointCount];
                for (var j = 0; j < rtpc.PointCount; j++)
                {
                    RtpcPoint rtpcPoint = default;
                    rtpcPoint.X = reader.ReadSingle();
                    rtpcPoint.Y = reader.ReadSingle();
                    rtpcPoint.FollowingCurveShape = (CurveShape)reader.ReadByte();
                    rtpcPoint.Unknown             = reader.ReadBytes(3);
                    rtpc.Points[j] = rtpcPoint;
                }
                audioProperties.Rtpcs[i] = rtpc;
            }
            return(audioProperties);
        }
Example #19
0
 private void PrepareForAttack()
 {
     timeToAttackLeft = RandomRange.FromVector(data.prepareTimeToAttack);
     animator.SetState(PigmanAnimatorState.Idle);
     phase = PigmanAttackPhase.Prepare;
 }
Example #20
0
 public void OnRoarEnd()
 {
     timeLeftToRoar = RandomRange.FromVector(data.roarsInterval);
     animator.SetState(PigmanAnimatorState.Idle);
 }
 private void BeginWaitForGoingBack()
 {
     waitTimeLeft = RandomRange.FromVector(data.abandonChaseTime);
     animator.SetState(PigmanAnimatorState.Idle);
 }
Example #22
0
 /// <summary>
 /// <para> NonNegative range: 0 (inclusive) -> <see cref="float.MaxValue"/> (exclusive) </para>
 /// <para> All range: <see cref="float.MinValue"/> (inclusive) -> <see cref="float.MaxValue"/> (exclusive) </para>
 /// </summary>
 public float NextUnl(RandomRange rangeType = RandomRange.NonNegative)
 {
     return((float)_parent.Double.NextUnl(rangeType));
 }