Exemplo n.º 1
0
        private void PlaceOneType(List <MissionSpot> spotInfos, MissionSpotType type, int targetAmount, Dictionary <MissionSpotType, int> distanceInfos, Dictionary <MissionSpotType, List <Position> > staticObjects, AccuracyInfo accuracyInfo)
        {
            var distanceToMyType = distanceInfos[type];
            var zoneWidth        = _zone.Size.Width;
            var borderWidthMax   = zoneWidth;

            //to make it fast
            //border increase 200
            //start border 200

            var borderIncrease = accuracyInfo.borderIncrease;
            var currentBorder  = accuracyInfo.initialBorder;
            var foundTotal     = 0;

            var freePoints = new List <Point>(_zone.Configuration.Size.Width * _zone.Configuration.Size.Height);

            InitPoints(spotInfos, distanceInfos, staticObjects, freePoints);

            while (true)
            {
                if (currentBorder > borderWidthMax)
                {
                    Logger.Info("Max border reached " + type);
                    return;
                }

                Logger.Info("border:" + currentBorder);

                var maxAttempts = freePoints.Count;
                var attempts    = 0;
                while (true)
                {
                    if (freePoints.Count == 0)
                    {
                        Logger.Info("no more free points");
                        return;
                    }

                    attempts++;
                    if (attempts > maxAttempts)
                    {
                        currentBorder += borderIncrease;
                        Logger.Info("MAX attempts reached!");
                        break;
                    }

                    if (attempts % 50000 == 0)
                    {
                        Logger.Info(type + " working " + attempts);
                    }

                    var pickedIndex    = FastRandom.NextInt(freePoints.Count - 1);
                    var pickedPosition = freePoints[pickedIndex].ToPosition();



                    //super turbo mode, skips border check when it generates random points
                    //if (type != MissionSpotType.randompoint)
                    //{ is keep distance }


                    //good if the distance is kept
                    if (!IsKeepDistance(pickedPosition, spotInfos, distanceInfos, staticObjects, 0, currentBorder))
                    {
                        continue;
                    }


                    if (!CheckConditionsAroundPosition(pickedPosition, accuracyInfo.blockRadius, accuracyInfo.islandRadius))
                    {
                        freePoints.Remove(pickedPosition);
                        continue;
                    }

                    //--- yay! position found!

                    var si = new MissionSpot(type, pickedPosition, _zone.Id);

                    spotInfos.Add(si);
                    SaveInfoAsync(si);

                    foundTotal++;
                    if (foundTotal >= targetAmount)
                    {
                        Logger.Info(foundTotal + " " + type + " was found successfully. Target amount reached!");
                        return;
                    }

                    CleanUpOneSpot(pickedPosition, distanceToMyType, ref freePoints);
                    //MakeSnap(type,freeKeys);
                    Logger.Info(type + "\t\t" + foundTotal + "\tattempts:" + attempts);
                    break;
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles the player accuracy data.
        /// </summary>
        /// <param name="m">The match.</param>
        public void HandlePlayerAccuracyData(Match m)
        {
            if (string.IsNullOrEmpty(_sst.ServerInfo.PlayerFollowedForAccuracy))
            {
                Log.Write(
                    "Accuracy data detected but is of no use player last followed is not set. Ignoring.",
                    _logClassType, _logPrefix);

                return;
            }
            if (!Helpers.KeyExists(_sst.ServerInfo.PlayerFollowedForAccuracy, _sst.ServerInfo.CurrentPlayers))
            {
                Log.Write(
                    "Player currently being followed is no longer on the server/doesn't exist in internal list. Ignoring.",
                    _logClassType, _logPrefix);

                return;
            }
            var extracted  = m.Groups["accdata"].Value;
            var accstrings = extracted.Split(' ');

            if (accstrings.Length < 15)
            {
                Log.Write("Got accuracy data length of invalid size. Ignoring.", _logClassType, _logPrefix);
                return;
            }
            var accs = new int[accstrings.Length];

            for (var k = 0; k < accstrings.Length; k++)
            {
                int n;
                int.TryParse(accstrings[k], out n);
                accs[k] = n;
            }
            var playerAccInfo = new AccuracyInfo
            {
                MachineGun   = accs[2], ShotGun = accs[3], GrenadeLauncher = accs[4], RocketLauncher = accs[5],
                LightningGun = accs[6], RailGun = accs[7], PlasmaGun = accs[8], Bfg = accs[9], GrapplingHook = accs[10],
                NailGun      = accs[11], ProximityMineLauncher = accs[12], ChainGun = accs[13], HeavyMachineGun = accs[14]
            };

            // Set
            _sst.ServerInfo.CurrentPlayers[_sst.ServerInfo.PlayerFollowedForAccuracy].Acc = playerAccInfo;
            Log.Write(string.Format(
                          "Set accuracy data for currently followed player: {0}. Data: (MG) {1} | (SG) {2}" +
                          " | (GL) {3} | (RL) {4} | (LG) {5} | (RG) {6} | (PG) {7} | (BFG) {8} | (GH) {9} |" +
                          " (NG) {10} | (PRX) {11} | (CG) {12} | (HMG) {13}", _sst.ServerInfo.PlayerFollowedForAccuracy,
                          playerAccInfo.MachineGun, playerAccInfo.ShotGun, playerAccInfo.GrenadeLauncher,
                          playerAccInfo.RocketLauncher, playerAccInfo.LightningGun, playerAccInfo.RailGun,
                          playerAccInfo.PlasmaGun, playerAccInfo.Bfg, playerAccInfo.GrapplingHook, playerAccInfo.NailGun,
                          playerAccInfo.ProximityMineLauncher, playerAccInfo.ChainGun, playerAccInfo.HeavyMachineGun),
                      _logClassType, _logPrefix);

            // Announce (new cmd because command queue is synchronous)
            if (_sst.Mod.Accuracy.Active)
            {
                var a = new AccCmd(_sst);
                // ReSharper disable once UnusedVariable (synchronous)
                var s = a.ShowAccuracy();
            }
            // Reset
            _sst.ServerInfo.PlayerFollowedForAccuracy = string.Empty;
        }