示例#1
0
        static void Main()
        {
            LoadSettings();

            bool check_status = false;

            while (!check_status)
            {
                try
                {
                    Tools.CW("Введите размер массива: ");

                    List <int> buffer = MyRandom.GetList(
                        int.Parse(Console.ReadLine())
                        );

                    buffer.Sort();

                    Tools.ShowBuffer(buffer);


                    Tools.CW("\nВведите чо нада: ");
                    int p = Convert.ToInt32(Console.ReadLine());

                    int tmp1 = buffer.Find(x => x == p);
                    if (tmp1 == 0)
                    {
                        Tools.CWL("Элемента нема");
                    }
                    else
                    {
                        Tools.CWL($"Найдено: {tmp1}");
                        Tools.CWL($"Индекс: {buffer.FindIndex(x => x == tmp1)}");
                    }

                    check_status = true;
                }
                catch (Exception er) { Tools.ERROR(er.Message); }

                Tools.READ_LINE();
            }
        }
示例#2
0
        public List <int> RandBuffList(int buffGroupId, int num)
        {
            List <int> ret         = new List <int>();
            var        tbBuffGroup = Table.GetBuffGroup(buffGroupId);

            if (tbBuffGroup == null)
            {
                return(ret);
            }
            if (tbBuffGroup.BuffID.Count != tbBuffGroup.QuanZhong.Count || tbBuffGroup.BuffID.Count < num)
            {
                Logger.Error("RandBuffList  {0} addbuffgroup size not eaqual!", buffGroupId);
                return(ret);
            }
            var buffList = new List <int>();
            var propList = new List <int>();
            var maxProp  = 0;

            for (int i = 0; i < tbBuffGroup.BuffID.Count; i++)
            {
                maxProp += tbBuffGroup.QuanZhong[i];
                buffList.Add(tbBuffGroup.BuffID[i]);
                propList.Add(tbBuffGroup.QuanZhong[i]);
            }
            for (int _i = 0; _i < num; _i++)
            {
                var rand = MyRandom.Random(0, maxProp - 1);
                var prop = 0;
                for (int i = 0; i < buffList.Count && i < propList.Count; i++)
                {
                    prop += propList[i];
                    if (prop >= rand)
                    {
                        ret.Add(buffList[i]);
                        buffList.RemoveAt(i);
                        propList.RemoveAt(i);
                        break;
                    }
                }
            }
            return(ret);
        }
示例#3
0
        public MyCompositeOrePlanetDeposit(MyCsgShapeBase baseShape, int seed, float minDepth, float maxDepth, MyOreProbability[] oreProbabilties) :
            base(baseShape, null)
        {
            m_minDepth = minDepth;
            double outherSphereVolume = (4.0 * MathHelper.Pi * Math.Pow(minDepth, 3.0f)) / 3.0;
            double innerSphereVolume  = (4.0 * MathHelper.Pi * Math.Pow(maxDepth, 3.0f)) / 3.0;

            double depositVolume = (4.0 * MathHelper.Pi * Math.Pow(DEPOSIT_MAX_SIZE, 3.0f)) / 3.0;
            double volume        = outherSphereVolume - innerSphereVolume;

            m_numDeposits = (int)Math.Floor((volume * 0.4f) / depositVolume);

            int numSectors = (int)(minDepth / DEPOSIT_MAX_SIZE);

            MyRandom random = MyRandom.Instance;

            FillMaterialCollections();
            Vector3D offset = -new Vector3D(DEPOSIT_MAX_SIZE / 2.0);

            using (var stateToken = random.PushSeed(seed))
            {
                for (int i = 0; i < m_numDeposits; ++i)
                {
                    Vector3D direction          = MyProceduralWorldGenerator.GetRandomDirection(random);
                    float    distanceFromCenter = random.NextFloat(maxDepth, minDepth);
                    Vector3D position           = direction * distanceFromCenter;

                    Vector3I cellPos = Vector3I.Ceiling((Shape.Center() + position) / DEPOSIT_MAX_SIZE);

                    MyCompositeShapeOreDeposit deposit;
                    if (m_deposits.TryGetValue(cellPos, out deposit) == false)
                    {
                        var oreDefinition      = GetOre(random.NextFloat(0, 1), oreProbabilties);
                        var materialDefinition = m_materialsByOreType[oreDefinition.OreName][random.Next() % m_materialsByOreType[oreDefinition.OreName].Count];
                        deposit             = new MyCompositeShapeOreDeposit(new MyCsgSimpleSphere(cellPos * DEPOSIT_MAX_SIZE + offset, random.NextFloat(64, DEPOSIT_MAX_SIZE / 2.0f)), materialDefinition);
                        m_deposits[cellPos] = deposit;
                    }
                }
            }

            m_materialsByOreType.Clear();
        }
示例#4
0
        public override void OnNpcDie(ObjNPC npc, ulong characterId = 0)
        {
            base.OnNpcDie(npc, characterId);

            if (state >= eDungeonState.WillClose)
            {
                return;
            }

            var caster = FindCharacter(characterId);

            if (caster == null)
            {
                return;
            }
            caster = caster.GetRewardOwner();
            var casterPlayer = caster as ObjPlayer;

            if (casterPlayer == null)
            {
                return;
            }
            int score;

            if (npc.TypeId == 58999)
            {
//箱子
                score = 2;
                casterPlayer.AddBuff(BoxBuffId[MyRandom.Random(BoxBuffId.Length)], 1, casterPlayer);
            }
            else
            {
                score = 3;
            }

            if (state == eDungeonState.Start)
            {
                //加积分
                var unit = PlayerScore[casterPlayer.ObjId];
                unit.Damage += score;
            }
        }
示例#5
0
        public Vector3 RandomPoint()
        {
            Vector3 vector2;

            if (_random == null)
            {
                _random = new MyRandom();
            }
            Vector3 vector = new Vector3();

            do
            {
                vector.X = (2f * ((float)_random.NextDouble())) - 1f;
                vector.Y = (2f * ((float)_random.NextDouble())) - 1f;
                vector.Z = (2f * ((float)_random.NextDouble())) - 1f;
                vector2  = Vector3.Cross(vector, this.Normal);
            }while (vector2 == Vector3.Zero);
            vector2.Normalize();
            return((Vector3)(vector2 * ((float)Math.Sqrt(_random.NextDouble()))));
        }
    public void Design(Transform styleHolder)
    {
        var house = GameHolder.PrefabsManager.prefabs.GetObject("House");

        int houseCount = MyRandom.Range(buildingsRange);

        for (int i = 0; i < houseCount; i++)
        {
            var     localScale = MyRandom.Range(buildingsScaleRange);
            Vector3 localPoint = new Vector3(
                MyRandom.Range(localPosition), .1f,
                MyRandom.Range(localPosition));

            var newHouse = GameObject.Instantiate(house);
            newHouse.transform.parent        = styleHolder;
            newHouse.transform.localPosition = localPoint;
            newHouse.transform.localScale    = new Vector3(localScale[0], localScale[1], localScale[2]);
        }
        Debug.Log("City now!", styleHolder.parent);
    }
示例#7
0
        public OctreeNoise(long seed, double cubeSideMax, double cubeSideMin, IMyModule densityNoise)
        {
            // cubeSideMin * (2^depth) == cubeSideMax
            m_depth = (int)Math.Ceiling(Math.Log(cubeSideMax / cubeSideMin) / Math.Log(2)) + 1;
            var seedLow  = (int)(seed >> 0);
            var seedHigh = (int)(seed >> 32);

            m_densityNoise = densityNoise ?? new MyCompositeNoise(m_depth, (float)(1 / cubeSideMax), seedLow);
            var rng = new MyRandom(seedHigh);

            m_placementNoise = new IMyModule[3];
            m_warpNoise      = new IMyModule[3];
            for (var i = 0; i < 3; i++)
            {
                m_placementNoise[i] = new MySimplex(rng.Next(), (float)(10 / cubeSideMin));
                m_warpNoise[i]      = new MySimplex(rng.Next(), (float)(1 / (cubeSideMax * 4)));
            }
            m_probabilityModule = new MySimplex(rng.Next(), 1);
            m_cubeSideMax       = cubeSideMax;
        }
示例#8
0
        public Vector3D RandomPoint()
        {
            Vector3D vectord2;

            if (_random == null)
            {
                _random = new MyRandom();
            }
            Vector3D vectord = new Vector3D();

            do
            {
                vectord.X = (2.0 * _random.NextDouble()) - 1.0;
                vectord.Y = (2.0 * _random.NextDouble()) - 1.0;
                vectord.Z = (2.0 * _random.NextDouble()) - 1.0;
                vectord2  = Vector3D.Cross(vectord, this.Normal);
            }while (vectord2 == Vector3D.Zero);
            vectord2.Normalize();
            return((Vector3D)(vectord2 * Math.Sqrt(_random.NextDouble())));
        }
示例#9
0
        public static async Task <UserProfile> GetUserRandomAsync()
        {
            if (Const.Offline)
            {
                return(ViewModels.MainViewModel.OtherProfiles[MyRandom.GetRandom(ViewModels.MainViewModel.OtherProfiles.Count)]);
            }

            var snapshots = await Instance.GetCollection("UserProfile").GetDocumentsAsync();

            var snapshot = snapshots.Documents[MyRandom.GetRandom((int)snapshots.Count)];

            if (!snapshot.Exists)
            {
                return(await GetUserRandomAsync());
            }
            var userProfile = LoadSaveData <UserProfile>(snapshot.Data);

            userProfile.Id = snapshot.Id;
            return(userProfile);
        }
示例#10
0
        public void Shuffle()
        {
            //if (rand == null)
            //    rand = new MyRandom();

            for (int i = 0; i < decklist.Count; i++)
            {
                if (i % 10 == 0)
                {
                    rand = new MyRandom();
                }
                int j = rand.Next(i, decklist.Count);
                if (i != j)
                {
                    object o = decklist[i];
                    decklist[i] = decklist[j];
                    decklist[j] = o;
                }
            }
        }
示例#11
0
        private IMeal FillChildKnapsack(IEnumerable <DietaryReferenceIntake> maxWeight, IEnumerable <FoodIntake> firstFoodIntakes, IEnumerable <FoodIntake> secondFoodIntakes, IEnumerable <Food> foods)
        {
            var child = MealFactory.GetMeal(maxWeight, firstFoodIntakes);

            foreach (var item in secondFoodIntakes)
            {
                var random = MyRandom.Next(0, 1);
                if (random < 0.8)
                {
                    child.AddFoodIntake(item);
                }
            }

            if (child.FoodIntakesCount == 0)
            {
                child.Fill(foods);
            }

            return(child);
        }
示例#12
0
        public override void Ctrl()
        {
            base.Ctrl();
            StageDataPackage stageData = this.StageData;
            MyRandom         ran       = this.Ran;
            PointF           position  = this.Position;
            int minValue = (int)position.X - 70;

            position = this.Position;
            int       maxValue  = (int)position.X + 70;
            PointF    Position  = new PointF((float)ran.Next(minValue, maxValue), this.Position.Y + 20f);
            double    num       = (double)(this.StageData.Ran.Next(10, 20) / 10);
            double    Direction = -1.0 * Math.PI / 2.0 - (double)this.StageData.Ran.Next(1, 5) / 10.0;
            StoryStar storyStar = new StoryStar(stageData, "Star", Position, (float)num, Direction);

            storyStar.Active   = true;
            storyStar.Scale    = (float)this.StageData.Ran.Next(15, 40) / 80f;
            storyStar.LifeTime = 40;
            this.Story.StoryEffectList.Add((BaseObject)storyStar);
        }
    void spawnTrash()
    {
        // Height and width of camera - used to determine where to spawn
        float canvasHeight = objectRectTransform.rect.height;
        float canvasWidth  = objectRectTransform.rect.width;

        float camHeight = Camera.main.orthographicSize;
        float camWidth  = camHeight * Camera.main.aspect;

        // Spawn random trash
        for (int i = 0; i < 5; ++i)
        {
            float xPos   = Random.Range(xrange.x, xrange.y);
            float yPos   = Random.Range(yrange.x, yrange.y);
            int   ranInt = Random.Range(0, trash.Length);

            //gets a random location relative to camera boundaries
            float newLocY = Random.Range(Camera.main.transform.position.y - trash[ranInt].GetComponent <SpriteRenderer>().bounds.size.y, Camera.main.transform.position.y - camHeight);
            float newLocX = Random.Range(Camera.main.transform.position.x - camWidth, Camera.main.transform.position.x + camWidth);

            trash[ranInt].GetComponent <SpriteRenderer>().enabled = false;
            Vector3 randomLoc = MyRandom.Location2D(gameObject.GetComponent <Canvas>().transform.position, 5, 2);

            GameObject randObj = (GameObject)GameObject.Instantiate(trash[ranInt], randomLoc, new Quaternion());
            randObj.transform.parent = this.gameObject.transform;
            numTrash++;
            trashList.Add(randObj.GetComponent <trash_click>());
        }

        // Spawn random animals
        for (int i = 0; i < numTrash / 4; ++i)
        {
            //gets a random location relative to camera boundaries
            Vector3 randomLoc = MyRandom.Location2D(gameObject.GetComponent <Canvas>().transform.position, 5, 2);
            //changes depth of new location to ensure spawned food will be visible and above track
            randomLoc.z = 0;
            int        ranInt  = Random.Range(0, animal.Length);
            GameObject randObj = (GameObject)GameObject.Instantiate(animal[ranInt], randomLoc, new Quaternion());
            randObj.transform.parent = this.gameObject.transform;
        }
    }
示例#14
0
        private void OnFuBenNetRetCallBack(IEvent ievent)
        {
            var e = ievent as DungeonNetRetCallBack;

            switch (e.Type)
            {
            case 10:
            {
                int idx = MyRandom.Random(AwardList.Count - 1);
                OnClickAward(idx);
            }
            break;

            case 11:
            {
                ScrollContainer.SetActive(false);
                MainInfo.SetActive(true);
                TeamInfo.SetActive(false);
                VipInfo.SetActive(false);
            }
            break;

            case 12:
            {
                ScrollContainer.SetActive(false);
                MainInfo.SetActive(false);
                TeamInfo.SetActive(true);
                VipInfo.SetActive(false);
            }
            break;

            case 13:
            {
                ScrollContainer.SetActive(false);
                MainInfo.SetActive(false);
                TeamInfo.SetActive(false);
                VipInfo.SetActive(true);
            }
            break;
            }
        }
示例#15
0
        /// <summary>
        /// Fase de improvisacion para los organismos
        /// </summary>
        /// <param name="posXi"></param>
        public Solution Improvisation(int posXi)
        {
            const double par  = 0.5;
            var          hmcr = 0.95;

            var neko = new Solution(this);

            for (var k = 0; k < MyProblem.NumVertices; k++)
            {
                if (MyRandom.NextDouble() <= hmcr)
                {
                    var posAleatoria = MyRandom.Next(Population.Count);
                    while (posAleatoria == posXi)
                    {
                        posAleatoria = MyRandom.Next(Population.Count);
                    }

                    neko.Vertices[k] = Population[posAleatoria].Vertices[k];
                    if (MyRandom.NextDouble() <= par)
                    {
                        if (MyRandom.NextDouble() > 0.5)
                        {
                            neko.Vertices[k] = 0;
                        }
                        else
                        {
                            neko.Vertices[k] = 1;
                        }
                    }
                }
                else
                {
                    neko.Vertices[k] = MyRandom.Next(2);
                }
            }
            neko.RecalculatePosInstalaciones();
            //neko.RepararSolutionAwareness();
            neko.RepairSolutionRandomly();
            neko.Evaluate();
            return(neko);
        }
示例#16
0
        private static Vector3 CreateRandomPointOnBox(MyRandom self, float boxSize)
        {
            Vector3 result = Vector3.Zero;

            switch (self.Next() & 6)
            {// each side of a box
            case 0: return(new Vector3(0f, self.NextFloat(), self.NextFloat()));

            case 1: return(new Vector3(1f, self.NextFloat(), self.NextFloat()));

            case 2: return(new Vector3(self.NextFloat(), 0f, self.NextFloat()));

            case 3: return(new Vector3(self.NextFloat(), 1f, self.NextFloat()));

            case 4: return(new Vector3(self.NextFloat(), self.NextFloat(), 0f));

            case 5: return(new Vector3(self.NextFloat(), self.NextFloat(), 1f));
            }
            result *= boxSize;
            return(result);
        }
示例#17
0
        public void shuffleArrayTest()
        {
            int[] result  = new int[5];
            int[] result1 = new int[5];
            for (int i = 0; i < 10000; i++)
            {
                int[] rands = MyRandom.shuffleArray(5);
                result[rands[0]]++;
                result1[rands[4]]++;
            }

            Assert.IsTrue(2000 - 100 < result[0]);
            Assert.IsTrue(2000 + 100 > result[0]);
            Assert.IsTrue(2000 - 100 < result[4]);
            Assert.IsTrue(2000 + 100 > result[4]);

            Assert.IsTrue(2000 - 100 < result1[0]);
            Assert.IsTrue(2000 + 100 > result1[0]);
            Assert.IsTrue(2000 - 100 < result1[4]);
            Assert.IsTrue(2000 + 100 > result1[4]);
        }
示例#18
0
            public override void OnEnter(E_Monster self, MFSMStateType prevType)
            {
                switch (self.m_MonsterType)
                {
                case MonsterType.NORMAL:
                    m_timer = MyRandom.NextFloat(c_normalRespawnTimeMin, c_normalRespawnTimeMax);
                    break;

                case MonsterType.ELITE:
                    m_timer = c_eliteRespawnTime;
                    break;

                case MonsterType.BOSS:
                    m_timer = c_bossRespawnTime;
                    break;

                case MonsterType.FINAL_BOSS:
                    m_timer = c_finalBossRespawnTime;
                    break;
                }
            }
示例#19
0
    void TierTwoVolumes()
    {
        int pick = MyRandom.NoRepeatRange(0, 2, lastPick);

        lastPick = pick;

        switch (pick)
        {
        case 0:     //left, right not playing
            leftBase = 0.0f; rightBase = 0.0f; upBase = 0.5f;
            break;

        case 1:     //up, left not playing
            leftBase = 0.0f; rightBase = 0.5f; upBase = 0.0f;
            break;

        case 2:     //up, right not splaying
            leftBase = 0.5f; rightBase = 0.0f; upBase = 0.0f;
            break;
        }
    }
        public void DieRollReturnsANumberBetween1And6()
        {
            MyRandom random = new MyRandom();
            Die      die    = new Die(random, 6);

            int value = die.Roll();

            Assert.IsTrue(1 <= value && value <= 6);

            // TestTools Code
            UnitTest test = Factory.CreateTest();
            TestVariable <MyRandom> _random = test.CreateVariable <MyRandom>();
            TestVariable <Die>      _die    = test.CreateVariable <Die>();
            TestVariable <int>      _value  = test.CreateVariable <int>();

            test.Arrange(_random, Expr(() => new MyRandom()));
            test.Arrange(_die, Expr(_random, (r) => new Die(r, 6)));
            test.Arrange(_value, Expr(_die, d => d.Roll()));
            test.Assert.IsTrue(Expr(_value, v => 1 <= v && v <= 6));
            test.Execute();
        }
示例#21
0
        public Point Evaluate()
        {
            int maxX    = Sum();
            int sampleX = MyRandom.Range(0, maxX);
            int indexX  = Array.BinarySearch(colsum, sampleX);

            if (indexX < 0)
            {
                indexX = ~indexX;             // if not found exactly, this is index of first number bigger than sampleX
            }
            int maxY    = RowSum(indexX);
            int sampleY = MyRandom.Range(0, maxY);
            int indexY  = Array.BinarySearch(rowsum[indexX], sampleY);

            if (indexY < 0)
            {
                indexY = ~indexY;
            }

            return(new Point(indexX, indexY)); // this is pixel, now normalize (row, col)
        }
示例#22
0
        public ObjDropItem CreateDropItem(Scene _this,
                                          int type,
                                          List <ulong> ownerList,
                                          ulong teamId,
                                          int itemId,
                                          int count,
                                          Vector2 pos)
        {
            if (count <= 0)
            {
                return(null);
            }
            var item = new ObjDropItem(type, ownerList, teamId, itemId, count);

            item.InitBase(_this.GenerateNextId(), itemId);

            PlayerLog.WriteLog((int)LogType.DropItem, "CreateDropItem  Id ={0} SceneId={1} pos={2},{3}", item.ObjId,
                               _this.TypeId, pos.X, pos.Y);
            var randomRadian = MyRandom.Random() * 2 * Math.PI;

            const float MaxDistance = 10f;
            const float MinDistance = 6f;

            var distance  = MyRandom.Random((int)MinDistance, (int)MaxDistance) / 10.0f;
            var targetPos = pos +
                            new Vector2(distance * (float)Math.Cos(randomRadian), distance * (float)Math.Sin(randomRadian));

            if (SceneObstacle.ObstacleValue.Obstacle == _this.GetObstacleValue(targetPos.X, targetPos.Y))
            {
                item.SetPosition(pos);
            }
            else
            {
                item.SetPosition(targetPos);
            }
            item.OrginPos = pos;
            _this.EnterScene(item);

            return(item);
        }
        /// <summary>
        /// Initialize all parameters to 0 -> meaning that previous sequences were all 0
        /// </summary>
        /// <param name="nGPU"></param>
        public override void Init(int nGPU)
        {
            if (Owner.Delay_d != null)
            {
                MyRandom rand = new MyRandom();
                Owner.Delay_d.SafeCopyToHost();
                Owner.Bias_b.SafeCopyToHost();
                Owner.Weight_u.SafeCopyToHost();
                Owner.Weight_v.SafeCopyToHost();
                Owner.LearningRate_η.SafeCopyToHost();

                // Generated interval
                for (int s = 0; s < Owner.Neurons; s++)
                {
                    // Randomize bias
                    Owner.Bias_b.Host[s] = (float)rand.NextDouble(0, 0.1f);
                }

                for (int s = 0; s < Owner.Synapses; s++)
                {
                    // Init conduction delays
                    Owner.Delay_d.Host[s] = Owner.Fifo_x[s].Count;
                    // Randomize weights
                    Owner.Weight_u.Host[s] = (float)rand.NextDouble(0, 0.1f);
                    Owner.Weight_v.Host[s] = (float)rand.NextDouble(0, 0.1f);
                }

                for (int i = 0; i < 4; i++)
                {
                    // Init learning rate
                    Owner.LearningRate_η.Host[i] = 1;
                }

                Owner.Delay_d.SafeCopyToDevice();
                Owner.Bias_b.SafeCopyToDevice();
                Owner.Weight_u.SafeCopyToDevice();
                Owner.Weight_v.SafeCopyToDevice();
                Owner.LearningRate_η.SafeCopyToDevice();
            }
        }
示例#24
0
        // 触发黑市npc
        public void TrigerBusinessman(DungeonScene _this)
        {
            var sceneNpcId = _this.mFubenRecord.BusinessManSceneId;
            var pr         = _this.mFubenRecord.BusinessManPR;

            if (sceneNpcId >= 0 && pr >= 0 && MyRandom.Random(10000) < pr)
            {
                _this.CreateSceneNpc(sceneNpcId);

                // 初始化商店物品数量
                var sceneNpc = Table.GetSceneNpc(sceneNpcId);
                if (sceneNpc == null)
                {
                    return;
                }

                var npc = Table.GetNpcBase(sceneNpc.DataID);
                if (npc == null)
                {
                    return;
                }

                _this.MapShopItems.Clear();
                foreach (var serviceId in npc.Service)
                {
                    if (serviceId >= 0)
                    {
                        var serviceR = Table.GetService(serviceId);
                        if (serviceR == null || serviceR.Param[0] < 0)
                        {
                            continue;
                        }

                        var shopType = serviceR.Param[0];
                        _this.MapShopItems[shopType] = new Dictionary <int, int>();
                        SceneServer.Instance.ServerControl.InitFubenStoreCounts(shopType, _this.MapShopItems[shopType]);
                    }
                }
            }
        }
示例#25
0
        private void checkKnife()
        {
            //主に包丁処理

            //-----------------
            // 包丁をランダムに使う
            //-----------------
            var knifeList = GameFactory.getGame().shareData.players.getUseItemPlayers(ITEM.KNIFE);

            if (knifeList.Count > 0)
            {
                // shuffle用の配列
                int[] rand = MyRandom.shuffleArray(knifeList.Count);

                //使用アイテムの保存
                Dictionary <int, ITEM> tmp = new Dictionary <int, ITEM>();
                foreach (var p in knifeList)
                {
                    tmp.Add(p.id, p.getUseItem());
                }

                // 包丁を使う
                for (int i = 0; i < knifeList.Count; i++)
                {
                    var p = knifeList[rand[i]];

                    // 先がナイフの場合はあとまわし
                    var opp = GameFactory.getGame().shareData.players.getPlayer(p.net_opp);
                    if (tmp.ContainsKey(opp.id))
                    {
                        if (tmp[opp.id] == ITEM.KNIFE)
                        {
                            continue;
                        }
                    }
                    // 実行
                    sub.kill(p);
                }
            }
        }
示例#26
0
 public override void OnTick(E_Monster self, float dT)
 {
     if (m_moveTimer > 0f)
     {
         m_moveTimer -= dT;
     }
     else
     {
         var     dir = m_targetPos - self.m_position;
         Vector2 dirNorm;
         if (dir.LengthSquared() <= float.Epsilon)
         {
             dirNorm = Vector2.UnitX;
         }
         else
         {
             dirNorm = Vector2.Normalize(dir);
         }
         var deltaP = dirNorm * self.m_Speed * dT * 0.01f;
         if (deltaP.LengthSquared() >= dir.LengthSquared())
         {
             deltaP = dir;
         }
         self.m_position = self.m_position + deltaP;
         if ((self.m_position - m_targetPos).LengthSquared() <= 0.01f)
         {
             m_moveTimer = MyRandom.NextFloat(5f, 10f);
             m_targetPos = self.m_respawnPosition + new Vector2(MyRandom.NextFloat(0f, 3f), MyRandom.NextFloat(0f, 3f));
         }
     }
     if (m_recoverTimer > 0f)
     {
         m_recoverTimer -= dT;
     }
     else
     {
         m_recoverTimer = c_recoverTime;
         GL_UnitBattleAttribute.s_instance.NotifyMonsterAutoRecover(self);
     }
 }
示例#27
0
        private Task RunnerTwo(CancellationTokenSource tokenSource, int raceLength = 500, int step = 10)
        {
            return(Task.Run(() => Application.Current.Dispatcher.Invoke(async() => {
                int delay = MyRandom.Next(10, 101);
                while (Canvas.GetLeft(this.RacerTwo) < raceLength)
                {
                    if (tokenSource.Token.IsCancellationRequested)
                    {
                        break;
                    }
                    Canvas.SetLeft(this.RacerTwo,
                                   (double)Clamp((int)Canvas.GetLeft(this.RacerTwo) + step,
                                                 (int)Canvas.GetLeft(this.RacerTwo),
                                                 raceLength));

                    // Update UI
                    Application.Current.Dispatcher.Invoke(delegate { }, System.Windows.Threading.DispatcherPriority.Render);
                    await Task.Delay(delay);
                }
                tokenSource.Cancel();
            })));
        }
示例#28
0
        public override void OnTickIdle(ObjNPC npc, float delta)
        {
            var retinue = npc as ObjRetinue;

            if (retinue == null)
            {
                return;
            }
            if (retinue.Owner == null)
            {
                retinue.Scene.LeaveScene(retinue);
            }
            var myPos    = retinue.GetPosition();
            var ownerPos = retinue.Owner.GetPosition();
            var distance = (myPos - ownerPos).LengthSquared();

            //if (distance > 400)
            //{
            //    var diff = GetRandomPostion();
            //    diff += ownerPos;
            //    npc.SetCheckPostion(diff);
            //    //retinue.MoveTo(ownerPos, 2);
            //    npc.EnterState(BehaviorState.GoHome);
            //    return;
            //}
            if (distance > 9)
            {
                retinue.MoveTo(ownerPos, 2);
                lastNoMoveIdeTime = DateTime.Now.AddSeconds(MyRandom.Random(3, 7));
                //var p = myPos + Vector2.Normalize(ownerPos - myPos) * 2;
                //retinue.MoveTo(p);
            }
            else if (lastNoMoveIdeTime < DateTime.Now)
            {
                var diff = Utility.GetRandomPostion();
                retinue.MoveTo(new Vector2(ownerPos.X + diff.X, ownerPos.Y + diff.Y), 0.2f);
                lastNoMoveIdeTime = DateTime.Now.AddSeconds(MyRandom.Random(3, 7));
            }
        }
示例#29
0
        public void Mutate(int index, bool all = false)
        {
            int rand = MyRandom.Rnd(2);

            if (all || rand == 0)
            {
                Angle[index] = Math.Max(-18, Math.Min(18, MyRandom.Rnd(-40, 40)));
            }

            if (all || rand == 1)
            {
                if (MyRandom.Rnd(100) < ShieldProbability)
                {
                    Thrust[index] = -1;
                }
                else
                {
                    Thrust[index] = Math.Max(0, Math.Min(MaxThrust, MyRandom.Rnd((int)-0.5 * MaxThrust, 2 * MaxThrust)));
                }
            }
            _score = -1;
        }
示例#30
0
    void SpawnARandomFish(Rect area, Field field, MyRandom r)
    {
        var go = Instantiate(
            prefab_fishes[r.Next(0, prefab_fishes.Length)],
            new Vector2(
                r.NextFloat(area.xMin, area.xMax),
                r.NextFloat(area.yMin, area.yMax)
                ),
            Quaternion.identity
            );

        float slc = r.NextFloat(0.5f, 1.5f);

        go.transform.localScale = new Vector3(slc, slc, 1);
        go.transform.parent     = transform;

        var body = go.GetComponent <Rigidbody2D>();

        body.AddForce(new Vector2(r.NextFloat(-0.01f, 0.01f), r.NextFloat(-0.01f, 0.01f)), ForceMode2D.Impulse);

        field.fishes.Add(go);
    }
        private GameplayScreen()
        {
            TransitionOnTime = TimeSpan.FromSeconds(1.5);
            TransitionOffTime = TimeSpan.FromSeconds(0.5);

            random = new MyRandom(Environment.TickCount);
            zunePad = new ZunePad();
            highScores = new Highscores(this);
            drawText = new DrawText(this);
            drawPrims = new DrawPrims(this);
            boidManager = new BoidManager(this);
            particles = new ParticleSystem(this);
            world = new World(this);
            player = new Player(this);
        }