Ejemplo n.º 1
0
        public void TestHitFormulaDeath1()
        {
            var random = Substitute.For<IRandom>();

            var formula = new HitTest(random);
            random.NextLong(Arg.Any<long>(), Arg.Any<long>()).Returns(0xffffffe);

            var fishs = new List<RequsetFishData>
            {
                new RequsetFishData
                {
                    FishId = 1,
                    FishOdds = 1
                }
            };
            var weapon = new RequestWeaponData
            {
                TotalHits = 1,
                WeaponBet = 1,
                WeaponOdds = 1,
                BulletId = 1
            };

            var request = new HitRequest(fishs.ToArray(), weapon, true);

            var hitResponses = formula.TotalRequest(request);
            foreach(var respones in hitResponses)
            {
                Assert.AreEqual(1, respones.WepId);
                Assert.AreEqual(1, respones.FishId);
                Assert.AreEqual(FISH_DETERMINATION.DEATH, respones.DieResult);
            }
        }
Ejemplo n.º 2
0
        public void TestHitFormulaDeath2()
        {
            var random = Substitute.For<IRandom>();

            var formula = new HitTest(random);
            random.NextLong(Arg.Any<long>(), Arg.Any<long>()).Returns(0x0fffffff / 26); // 9d89d8

            var fishs = new List<RequsetFishData>
            {
                new RequsetFishData
                {
                    FishId = 1,
                    FishOdds = 25
                }
            };
            var weapon = new RequestWeaponData
            {
                TotalHits = 1,
                WeaponBet = 1,
                WeaponOdds = 1,
                BulletId = 1,
                WeaponType =WEAPON_TYPE.INVALID
            };

            var hitRequest = new HitRequest(fishs.ToArray(), weapon, true);

            var hitResponses = formula.TotalRequest(hitRequest); // a3d70a

            foreach(var response in hitResponses)
            {
                Assert.AreEqual(1, response.WepId);
                Assert.AreEqual(1, response.FishId);
                Assert.AreEqual(FISH_DETERMINATION.DEATH, response.DieResult);
            }
        }
Ejemplo n.º 3
0
        public override HitResponse[] TotalRequest(HitRequest request)
        {
            var hitResponses = new List <HitResponse>();

            foreach (var fishData in request.FishDatas)
            {
                const int   MAX_WEPBET    = 10000;
                const int   MAX_WEPODDS   = 10000;
                const short MAX_TOTALHITS = 1000;
                const short MAX_FISHODDS  = 1000;
                const long  gateOffset    = 0x0fffffff;

                if (request.WeaponData.WeaponBet > MAX_WEPBET)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (request.WeaponData.WeaponOdds > MAX_WEPODDS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (request.WeaponData.TotalHits == 0 || request.WeaponData.TotalHits > MAX_TOTALHITS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    continue;
                }

                if (fishData.FishOdds == 0 || fishData.FishOdds > MAX_FISHODDS)
                {
                    hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                }
                else
                {
                    long gate = 1000;
                    gate *= gateOffset;
                    gate *= request.WeaponData.WeaponBet;
                    gate /= request.WeaponData.TotalHits;
                    gate /= fishData.FishOdds;
                    gate /= 1000;

                    if (gate > 0x0fffffff)
                    {
                        gate = 0x10000000;
                    }

                    var rValue = _Random.NextLong(0, long.MaxValue);

                    var value = rValue % 0x10000000;

                    if (value < gate)
                    {
                        hitResponses.Add(_Die(fishData, request.WeaponData));
                    }
                    else
                    {
                        hitResponses.Add(HitTest._Miss(fishData, request.WeaponData));
                    }
                }
            }

            return(hitResponses.ToArray());
        }
Ejemplo n.º 4
0
        public void TestHitFormulaSurvival2()
        {
            var random = Substitute.For<IRandom>();

            var formula = new HitTest(random);
            random.NextLong(Arg.Any<long>(), Arg.Any<long>()).Returns(0x0fffffff / 25);

            var fishs = new List<RequsetFishData>
            {
                new RequsetFishData
                {
                    FishId = 1,
                    FishOdds = 25
                }
            };
            var weapon = new RequestWeaponData
            {
                TotalHits = 1,
                WeaponBet = 1,
                WeaponOdds = 1,
                BulletId = 1
            };

            var request = new HitRequest(fishs.ToArray(), weapon, true);

            var hitResponses = formula.TotalRequest(request);
            foreach(var response in hitResponses)
            {
                Assert.AreEqual(1, response.WepId);
                Assert.AreEqual(WEAPON_TYPE.INVALID, response.FeedbackWeapons[0]);
                Assert.AreEqual(1, response.FishId);
                Assert.AreEqual(FISH_DETERMINATION.SURVIVAL, response.DieResult);
            }
        }