Exemplo n.º 1
0
        public override void Run()
        {
            base.Run();
            GameObject currentVehicle = VTOLAPI.instance.GetPlayersVehicleGameObject();

            ModuleEngine[] engines = currentVehicle.GetComponentsInChildren <ModuleEngine>();

            System.Random rand  = new System.Random();
            int           index = rand.Next(engines.ToList().Count());

            Debug.Log($"Total Engines: {engines.ToList().Count()}");

            if (!engines[index].failed)
            {
                Debug.Log($"Failing Engine {index}");
                engines[index].FailEngine();
                if (rand.Next(1, 100) < 80)
                {
                    Debug.Log($"Unfailing Engine {index}");
                    StartCoroutine(unfailEngine(index, engines));
                }
                else
                {
                    Debug.Log($"Engine {index} is permanently failed");
                }
            }
        }
Exemplo n.º 2
0
        private void GenerateEnemy(int size)
        {
            var random = new System.Random();

            if (Enemy == null)
            {
                Enemy = GameObject.FindWithTag("Enemy");
            }
            AddElement(Enemy, random.Next(size) / 2, 1, random.Next(size) / 2, 1, 0);
        }
Exemplo n.º 3
0
    /// <summary>
    /// 字体随机颜色
    /// </summary>
    public System.Drawing.Color GetRandomColor()
    {
        System.Random RandomNum_First = new System.Random((int)DateTime.Now.Ticks);
        System.Threading.Thread.Sleep(RandomNum_First.Next(50));
        System.Random RandomNum_Sencond = new System.Random((int)DateTime.Now.Ticks);
        int           int_Red           = RandomNum_First.Next(180);
        int           int_Green         = RandomNum_Sencond.Next(180);
        int           int_Blue          = (int_Red + int_Green > 300) ? 0 : 400 - int_Red - int_Green;

        int_Blue = (int_Blue > 255) ? 255 : int_Blue;
        return(System.Drawing.Color.FromArgb(int_Red, int_Green, int_Blue));
    }
Exemplo n.º 4
0
    GameObject SpawnCloud(bool canSpawnInScreen)
    {
        int     idx2Spawn      = random.Next(cloudPrefabsToSpawn.Count);
        Vector3 position2Spawn = new Vector3
                                 (
            canSpawnInScreen ? random.Next(-600, 600) : random.Next(800, 1000),
            random.Next(-500, 500),
            random.Next(-3, 0)
                                 );

        return(Instantiate(cloudPrefabsToSpawn[idx2Spawn], position2Spawn, Quaternion.identity));
    }
Exemplo n.º 5
0
        public static Vector3 GetRandomPoint(this Bounds bounds, string seed = "random")
        {
            if (seed == "random")
            {
                seed = Time.realtimeSinceStartup.ToString();
            }

            Random pseudoRandom = new System.Random(seed.GetHashCode());

            float x = pseudoRandom.Next((int)(bounds.min.x * 100), (int)(bounds.max.x * 100)) / 100f;
            float y = pseudoRandom.Next((int)(bounds.min.y * 100), (int)(bounds.max.y * 100)) / 100f;
            float z = pseudoRandom.Next((int)(bounds.min.z * 100), (int)(bounds.max.z * 100)) / 100f;

            return(new Vector3(x, y, z));
        }
Exemplo n.º 6
0
    private PlayerSkills.BaseSkill GetVincentEnergySkill()
    {
        PlayerSkills.BaseSkill skill = player.GetComponent <PlayerSkills>().fireball;
        var random  = new System.Random();
        var skillID = random.Next(0, 5);

        switch (skillID)
        {
        case 0:
            skill = player.GetComponent <PlayerSkills>().fireball;
            break;

        case 1:
            skill = player.GetComponent <PlayerSkills>().lightning;
            break;

        case 2:
            skill = player.GetComponent <PlayerSkills>().rushdown;
            break;

        case 3:
            skill = player.GetComponent <PlayerSkills>().offering;
            break;

        case 4:
            skill = player.GetComponent <PlayerSkills>().healingWave;
            break;
        }

        return(skill);
    }
Exemplo n.º 7
0
    private PlayerSkills.BaseSkill GetMarcEnergySkill()
    {
        PlayerSkills.BaseSkill skill = player.GetComponent <PlayerSkills>().fireball;
        var random  = new System.Random();
        var skillID = random.Next(0, 5);

        switch (skillID)
        {
        case 0:
            skill = player.GetComponent <PlayerSkills>().warcry;
            break;

        case 1:
            skill = player.GetComponent <PlayerSkills>().berserk;
            break;

        case 2:
            skill = player.GetComponent <PlayerSkills>().feelNoPain;
            break;

        case 3:
            skill = player.GetComponent <PlayerSkills>().rushdown;
            break;

        case 4:
            skill = player.GetComponent <PlayerSkills>().offering;
            break;
        }

        return(skill);
    }
        private IEnumerator FlashLightsRandom()
        {
            var colorList = new List <Color> {
                Color.black, Color.green, Color.red, Color.yellow
            };

            System.Random rand      = new System.Random();
            int           index     = rand.Next(colorList.Count);
            Color         randColor = colorList[index];

            double randWait = rand.NextDouble();

            if (gear != null && gear.statusLight != null)
            {
                gear.statusLight.toggleColor = randColor;
                gear.statusLight.Toggle();
            }
            else
            {
                Debug.Log("It seems gear or statuslight is null");
            }
            yield return(new WaitForSeconds((float)randWait));

            if (running)
            {
                this.StartCoroutine(FlashLightsRandom());
            }
        }
Exemplo n.º 9
0
        public void RemoveTest()
        {
            int num  = 50000;
            var list = new SortSet <int, int>();
            var lst  = new List <int>();
            var rand = new System.Random();

            for (var i = 0; i < num; i++)
            {
                var val = rand.Next();
                lst.Add(val);
                list.Add(val, val);
            }

            foreach (int n in lst)
            {
                list.Remove(n);
            }

            foreach (var val in list)
            {
                Assert.Fail();
                if (val < 0)
                {
                }
            }

            if (list.Count != 0)
            {
                Assert.Fail();
            }
        }
Exemplo n.º 10
0
        public void AddElementTest()
        {
            //var list2 = new SortSet<object, int>();
            int num  = 50000;
            var list = new SortSet <int, int>();
            var rand = new System.Random();

            for (var i = 0; i < num; i++)
            {
                var val = rand.Next();
                list.Add(val, val);
                //list.Add(i,i);
            }

            var max = 0;

            foreach (var val in list)
            {
                if (max <= val)
                {
                    max = val;
                }
                else
                {
                    Assert.Fail();
                }
            }
        }
Exemplo n.º 11
0
    public void Shoot(float projectileSize = 5, float soundVolume = 0.1f)
    {
        if (Time.time > timeToFire)
        {
            if (Firerate > 0)
            {
                timeToFire = Time.time + 1 / Firerate;
            }

            int randomAmmo = rand.Next(0, Ammunition.Length);

            GameObject ammu = Instantiate(Ammunition[randomAmmo], firePoint.position, firePoint.rotation);
            ammu.transform.localScale = new Vector3(projectileSize, projectileSize, 1);
            ammu.transform.Rotate(new Vector3(0, 0, -90));

            ammu.GetComponent <AudioSource>().volume = soundVolume;

            ProjectileLogic ammuLogic = ammu.GetComponent <ProjectileLogic>();
            ammuLogic.AvoidCollisionByGameObject(gameObject);

            float currentSpread = UnityEngine.Random.Range(-Spread, Spread);

            Vector3 travelDirection       = (firePoint.position - transform.position);
            Vector3 travelDirectionSpread =
                new Vector3(travelDirection.x + currentSpread, travelDirection.y + currentSpread);

            ammuLogic.Initiate(travelDirectionSpread, Damage, Speed);
        }
    }
Exemplo n.º 12
0
        public override void PostProcessProjectile(Projectile projectile)
        {
            PlayerController owner = this.gun.CurrentOwner as PlayerController;
            //hammerpoint
            bool hammer = owner.PlayerHasActiveSynergy("Hop-up: Hammer Point Rounds");

            if (hammer)
            {
                projectile.baseData.damage = 15f;
            }
            else
            {
                projectile.baseData.damage = 3f;
            }

            bool shatter = owner.PlayerHasActiveSynergy("Hop-up: Shattering Tier Lists");

            if (shatter)
            {
                int rng = rand.Next(1, 20);
                if (rng == 1)
                {
                    Projectile shatterer  = ((Gun)ETGMod.Databases.Items[157]).DefaultModule.projectiles[0];
                    GameObject gameObject = SpawnManager.SpawnProjectile(shatterer.gameObject, owner.specRigidbody.UnitCenter, Quaternion.Euler(0f, 0f, (owner.CurrentGun == null) ? 0f : owner.CurrentGun.CurrentAngle));
                    Projectile component  = gameObject.GetComponent <Projectile>();
                    component.Owner            = owner;
                    component.baseData.damage  = 50f;
                    component.ignoreDamageCaps = true;
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        /// Generate a valid credit card number based on provider using Luhn's (Mod10) formula.
        /// </summary>
        /// <returns>The random valid credit card number.</returns>
        public string GetRandomValidCreditCardNumber(CreditCard provider)
        {
            bool   isValid = false;
            string fakeCreditCardNumber = "";

            while (!isValid)
            {
                System.Random r = new System.Random();
                fakeCreditCardNumber = provider.Prefix.ToString();

                //Build out randomized number that is 16 digits long.
                while (fakeCreditCardNumber.Length < 16)
                {
                    fakeCreditCardNumber += r.Next(0, 10);
                }

                List <char> ccChar         = fakeCreditCardNumber.ToCharArray().ToList();
                List <char> reversedNumber = ccChar;
                reversedNumber.Reverse();
                char check_digit = reversedNumber.First();
                reversedNumber.RemoveAt(0);

                var sum = 0;
                for (var x = 0; x < reversedNumber.Count; x++)
                {
                    var current_sum = 0;
                    //Double every other value.
                    if (x % 2 == 0)
                    {
                        var doubled_sum = reversedNumber[x].ToString().ToInt() * 2;
                        if (doubled_sum >= 10)
                        {
                            current_sum = doubled_sum.ToString()[0].ToString().ToInt() + doubled_sum.ToString()[1].ToString().ToInt();
                        }
                        else
                        {
                            current_sum = doubled_sum;
                        }
                    }
                    else
                    {
                        current_sum = reversedNumber[x].ToString().ToInt();
                    }

                    sum += current_sum;
                }

                string new_sum = (sum * 9).ToString();
                if (new_sum[new_sum.Length - 1].ToString().ToInt() == check_digit.ToString().ToInt())
                {
                    isValid = true;
                    break;
                }

                fakeCreditCardNumber = "";
            }

            return(fakeCreditCardNumber);
        }
Exemplo n.º 14
0
 public int Get(System.Random random)
 {
     if (Min == Max)
     {
         return(Min);
     }
     return(random.Next(Min, Max));
 }
Exemplo n.º 15
0
        /// <summary>
        /// 创建随机的字符区域编码
        /// </summary>
        /// <param name="length">要随机的长度</param>
        /// <returns></returns>
        private object[] CreateRegionCode(int length)
        {
            //定义一个字符串数组储存汉字编码的组成元素
            string[] rBase = new String[16] {
                "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "a", "b", "c", "d", "e", "f"
            };
            var rnd = new System.Random();

            //定义一个object数组用来
            object[] bytes = new object[length];

            /*每循环一次产生一个含两个元素的十六进制字节数组,并将其放入byte数组中
             * 每个汉字有四个区位码组成
             * 区位码第1位和区位码第2位作为字节数组第一个元素
             * 区位码第3位和区位码第4位作为字节数组第二个元素
             */
            for (int i = 0; i < length; i++)
            {
                //区位码第1位
                int    r1     = rnd.Next(11, 14);
                string str_r1 = rBase[r1].Trim();
                //区位码第2位
                rnd = new Random(r1 * Guid.NewGuid().GetHashCode() + i);//更换随机数发生器的种子避免产生重复值
                var    r2     = rnd.Next(0, r1 == 13 ? 7 : 16);
                string str_r2 = rBase[r2].Trim();
                //区位码第3位
                rnd = new Random(r2 * Guid.NewGuid().GetHashCode() + i);
                int    r3     = rnd.Next(10, 16);
                string str_r3 = rBase[r3].Trim();
                //区位码第4位
                rnd = new Random(r3 * Guid.NewGuid().GetHashCode() + i);
                int r4;
                switch (r3)
                {
                case 10:
                    r4 = rnd.Next(1, 16);
                    break;

                case 15:
                    r4 = rnd.Next(0, 15);
                    break;

                default:
                    r4 = rnd.Next(0, 16);
                    break;
                }

                string str_r4 = rBase[r4].Trim();
                //定义两个字节变量存储产生的随机汉字区位码
                byte byte1 = Convert.ToByte(str_r1 + str_r2, 16);
                byte byte2 = Convert.ToByte(str_r3 + str_r4, 16);
                //将两个字节变量存储在字节数组中
                byte[] str_r = { byte1, byte2 };
                //将产生的一个汉字的字节数组放入object数组中
                bytes.SetValue(str_r, i);
            }
            return(bytes);
        }
Exemplo n.º 16
0
 private static void Scramble(String[] data, System.Random r)
 {
     for (int i = 0; i < data.Length; ++i)
     {
         int    ix = r.Next(data.Length);
         String s  = data[i];
         data[i]  = data[ix];
         data[ix] = s;
     }
 }
Exemplo n.º 17
0
        public AssociatedResponce(int SwarmReward_Index, int MoveReward_Index)
        {
            Random rnd = new System.Random();
            int    x1  = rnd.Next(5);
            int    x2  = rnd.Next(5);
            int    x3  = rnd.Next(5);

            SwarmChoice = new int[3] {
                x1, x3, x2
            };
            MovementChoice = new int[3] {
                x2, x1, x3
            };

            SwarmChoice[SwarmReward_Index]   += 1;
            MovementChoice[MoveReward_Index] += 1;

            setresponse();
        }
 public int NextRandomMovementType(int start, int end)
 {
     if (randomRandoms.Next(2) == 0)
     {
         return(nextMovementType.Next(start, end));
     }
     else
     {
         return(nextMovementType2.Next(start, end));
     }
 }
Exemplo n.º 19
0
    int[] getRanArray(int pCurrentN, System.Random pRand)
    {
        int[] randArr = new int[pCurrentN];
        int   n       = randArr.Length;

        for (int i = 0; i < n; i++)
        {
            randArr[i] = pRand.Next(1, 101);
        }
        return(randArr);
    }
    void DrawMaze()
    {
        for (int i = 0; i < mazeWidth; i++)
        {
            for (int j = 0; j < mazeHeight; j++)
            {
                Vector3 position = new Vector3(i, j);

                if (maze.Grid[i, j] == true)
                {
                    CreateMazeSprite(position, floor, transform, 0, mazeRg.Next(0, 3) * 90);
                }
                else
                {
                    CreateMazeSprite(position, roof, transform, 0, 0);

                    DrawWalls(i, j);
                }
            }
        }
    }
Exemplo n.º 21
0
        private IEnumerator ExplodeCreature(Creature creature, Vector3 dir)
        {
            var random = new System.Random();

            while (Time.time - creature.spawnTime <= 2)
            {
                yield return(new WaitForFixedUpdate());
            }

            string[] parts =
            {
                "LeftHand",  "LeftForeArm",  "LeftArm",
                "RightHand", "RightForeArm", "RightArm",
                "LeftFoot",  "LeftLeg",
                "RightFoot", "RightLeg",
                "Head"
            };

            int index = 0;

            while (index < parts.Length)
            {
                foreach (var part in creature.ragdoll.parts)
                {
                    try
                    {
                        part.rb.AddForce((dir + Vector3.up),
                                         ForceMode.Impulse);

                        if (part.name == parts[index])
                        {
                            if (random.Next(1, 101) <= 50)
                            {
                                part.Slice();
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        Debug.Log(exception.Message);
                    }
                }

                index++;
            }

            if (creature.state != Creature.State.Dead)
            {
                creature.Kill();
            }

            yield return(null);
        }
Exemplo n.º 22
0
    void OnTriggerEnter(Collider other)
    {
        System.Random r    = new System.Random();
        int           rInt = r.Next(0, 100);

        Debug.Log("A");
        if (probability > rInt)
        {
            Debug.Log("Dead");
            EventController.current.ChangeMode("finish", "You get burn");
        }
    }
Exemplo n.º 23
0
    private void Start()
    {
        energySkillOneImage.sprite = player.GetComponent <PlayerController>().energySkill1.icon;
        energySkillTwoImage.sprite = player.GetComponent <PlayerController>().energySkill2.icon;
        staminaSkillImage.sprite   = player.GetComponent <PlayerController>().staminaSkill.icon;
        _newSkill = GetNewSkill();
        var random  = new System.Random();
        var random1 = random.Next(0, 10);

        _newSkill.skillLevel = random1 > 6 ? 1 : 0;
        newSkillImage.sprite = _newSkill.icon;
    }
Exemplo n.º 24
0
 private void Partition(int left, int right, int top, int bottom, bool splitVertical, int splitRemaining, System.Random pseudoRandom)
 {
     if (splitRemaining <= 0 || left >= right || top >= bottom)
     {
         return;
     }
     splitRemaining -= 1;
     if (splitVertical)
     {
         int target = pseudoRandom.Next(left, right + 1);
         _mapManager.CreatePassage(new Coordinate(target, top), new Coordinate(target, bottom), drawPassage? 0: 1);
         Partition(left, target - 1, top, bottom, false, splitRemaining, pseudoRandom);
         Partition(target + 1, right, top, bottom, false, splitRemaining, pseudoRandom);
     }
     else
     {
         int target = pseudoRandom.Next(top, bottom + 1);
         _mapManager.CreatePassage(new Coordinate(left, target), new Coordinate(right, target), drawPassage? 0: 1);
         Partition(left, right, top, target - 1, true, splitRemaining, pseudoRandom);
         Partition(left, right, target + 1, bottom, true, splitRemaining, pseudoRandom);
     }
 }
Exemplo n.º 25
0
        // Select `count` elements randomly from list
        private IEnumerable <T> RandomSelect <T>(int count, IList <T> list, System.Random random = null)
        {
            var retVal     = new List <T>(count);
            var randomImpl = random ?? new System.Random();

            for (var i = 0; i < count; i++)
            {
                var idx = random.Next(list.Count());
                retVal.Add(list[idx]);
                list.RemoveAt(idx);
            }

            return(retVal);
        }
Exemplo n.º 26
0
        public static int linear_fit_classification_rosenblatt(ref double[] model, double[,] inputs, double[] outputs, int iterationNumber, double step)
        {
            double[,] X = new double[inputs.GetLength(0), inputs.GetLength(1) + 1];
            for (int j = 0; j < inputs.GetLength(0); j++)
            {
                X[j, 0] = 1;
                for (int k = 0; k < inputs.GetLength(1); k++)
                {
                    X[j, k + 1] = inputs[j, k];
                }
            }

            System.Random random = new System.Random();

            int len1 = X.GetLength(1);

            double[,] rndInput = new double[len1, 1];
            double[] flatRndInput = new double[len1 - 1];
            double[,] rndOutput = new double[1, 1];

            for (int i = 0; i < iterationNumber; i++)
            {
                int num = random.Next(0, outputs.Length);

                for (int j = 0; j < len1; j++)
                {
                    rndInput[j, 0] = X[num, j];
                    if (j > 0)
                    {
                        flatRndInput[j - 1] = X[num, j];
                    }
                }

                rndOutput[0, 0] = outputs[num];

                double linearClassifyRes = linear_classify(ref model, flatRndInput);

                double[,] sub = new double[1, 1];
                sub[0, 0]     = linearClassifyRes;

                double[,] subRes      = SubstractMatrix(rndOutput, sub);
                double[,] multiplyRes = MultiplyMatrix(rndInput, subRes);
                double[,] rectModel   = ToRectangular(model, 1);

                rectModel = AdditionMatrix(rectModel, MultiplyMatrixScalar(step, multiplyRes));
                ToLinear(ref model, rectModel);
            }

            return(0);
        }
Exemplo n.º 27
0
        // FIX THIS
        public void shuffle()
        {
            System.Random RandomGen     = new System.Random(DateTime.Now.Millisecond);
            ArrayList     ScrambledList = new ArrayList();
            Int32         Index;

            while (this.deck.Count > 0)
            {
                Index = RandomGen.Next(this.deck.Count);
                ScrambledList.Add(this.deck[Index]);
                this.deck.RemoveAt(Index);
            }
            this.deck = ScrambledList;
        }
Exemplo n.º 28
0
    //列表乱序函数
    public static void RandomizeList(IList pList)
    {
        System.Random rng = new System.Random();
        int           n   = pList.Count;

        while (n > 1)
        {
            n--;
            int k     = rng.Next(n + 1);
            var value = pList[k];
            pList[k] = pList[n];
            pList[n] = value;
        }
    }
Exemplo n.º 29
0
        private GameObject FindPotentialListeningDeviceObject()
        {
            List <GameObject> potentialListeningDevices = GameObject.FindObjectsOfType <BuggableFurniture>().Select(x => x.gameObject).OfType <GameObject>().ToList();

            if (potentialListeningDevices.Count == 0)
            {
                return(null);
            }

            System.Random random      = new System.Random();
            int           randomIndex = random.Next(0, potentialListeningDevices.Count);

            return(potentialListeningDevices.ElementAt(randomIndex));
        }
Exemplo n.º 30
0
    public void ReplaceSkill()
    {
        if (_newSkill.description == "Fireball" || _newSkill.description == "Summon Arrows" ||
            _newSkill.description == "Lightning" || _newSkill.description == "Poisonous Fumes" ||
            _newSkill.description == "Warcry" || _newSkill.description == "Metallicize" ||
            _newSkill.description == "Berserk" || _newSkill.description == "Feel No Pain" ||
            _newSkill.description == "Rushdown" || _newSkill.description == "Offering" ||
            _newSkill.description == "Healing Wave") // switch energy skill
        {
            var random   = new System.Random();
            var skillIdx = random.Next(0, 2);
            var random2  = random.Next(0, 10);
            switch (skillIdx)
            {
            case 0:
                player.GetComponent <PlayerController>().energySkill1 = _newSkill;
                if (random2 > 6)
                {
                    player.GetComponent <PlayerController>().energySkill1.skillLevel = 1;
                }
                break;

            case 1:
                player.GetComponent <PlayerController>().energySkill2 = _newSkill;
                if (random2 > 6)
                {
                    player.GetComponent <PlayerController>().energySkill2.skillLevel = 1;
                }
                break;
            }
        }
        else
        {
            player.GetComponent <PlayerController>().staminaSkill = _newSkill;
        }
        LoadNextScene();
    }
Exemplo n.º 31
0
    public Stage GenerateStage(int eventCount, int timeStep, bool shields, bool asteroids, bool bosses, bool colorsShifts, bool rotators)
    {
        var stage = new List<GameEvent> ();
        var currentColor = Colors.player;
        System.Random randGen = new System.Random ();
        //Set seeds!
        var firstShift = (int)eventCount / 3;
        var secondShift = (int)(eventCount * 2.0 / 3.0);
        for (int i = 0; i < eventCount; i++) {
          if (i == eventCount - 1 && bosses) {
        stage.Add (((GameEvent)new Boss (new Vector3 (0, 0, 0), 1, timeStep)));
        continue;
          }
          if (colorsShifts && (i == firstShift || i == secondShift)) {
        currentColor = ColorUtils.GetRandomBackgroundColor (currentColor, randGen);
        stage.Add ((GameEvent)new BackgroundShift (currentColor, timeStep));
        continue;
          }

          var spawns = new List<Spawn> ();

          foreach (var slot in RandomSample(Constants.slots, randGen, randGen.Next(2,5))) {
        var chance = randGen.NextDouble ();
        var position = new Vector3 (slot, 5, 1);
        var color = ColorUtils.GetRandomColorForBackground (currentColor, randGen);
        var cannons = new bool[8];
        for(int j=0; j<8; j++) {
          if((randGen.Next() % 3) == 0)
            cannons[j] = true;
          else
            cannons[j] = false;
        }

        if (cannons.All(f=>!f)) {
          var luckyCannon = randGen.Next () % 8;
              cannons [luckyCannon] = true;
        }
        spawns.Add (BuildSingleSpawn (position, cannons, shields,  asteroids, rotators, color, chance));
          }
          stage.Add ((GameEvent)new SpawnSet (spawns, timeStep));
        }
        return new Stage (stage);
    }