private static int[] ModifySequenceToTotal(CryptoRandom rnd, int[] sequences, int minValue, int maxValue, int total) { var sum = sequences.Sum(); var runs = Math.Abs(total - sum); if (runs > 0) { sequences = sequences.OrderBy(s => rnd.Next()).ToArray(); var doIncrease = sum < total; var currentIndex = 0; for (var i = 0; i < runs;) { var currentValue = sequences[currentIndex]; if (doIncrease && currentValue + 1 <= maxValue || !doIncrease && currentValue - 1 >= minValue) { sequences[currentIndex] = currentValue + (doIncrease ? 1 : -1); i++; } currentIndex++; if (currentIndex >= sequences.Length) { currentIndex = 0; } } } return(sequences); }
public static Vector3 Randomize(this CryptoRandom rnd, Vector3 position, int amount) { if (position.IsValid()) { if (amount > 0) { amount = rnd.Next((int)Math.Floor(amount * 0.9f), (int)Math.Ceiling(amount * 1.1f)); position.X += rnd.Next(0, amount * 2 + 1) - amount; position.Y += rnd.Next(0, amount * 2 + 1) - amount; } position.X = Truncate((int)position.X + (float)rnd.NextDouble(), 3); position.Y = Truncate((int)position.Y + (float)rnd.NextDouble(), 3); position.Z = NavMesh.GetHeightForPosition(position.X, position.Y); } return(position); }
public static int[] CreateSequence(this CryptoRandom rnd, int count, int minValue, int maxValue, int total) { var sequences = new int[count]; for (var i = 0; i < count; i++) { sequences[i] = rnd.Next(minValue, maxValue + 1); } return(ModifySequenceToTotal(rnd, sequences, minValue, maxValue, total)); }
private static int[] ModifySequenceToTotal(CryptoRandom rnd, int[] sequences, int minValue, int maxValue, int total) { var sum = sequences.Sum(); var runs = Math.Abs(total - sum); if (runs > 0) { sequences = sequences.OrderBy(s => rnd.Next()).ToArray(); var doIncrease = sum < total; var currentIndex = 0; for (var i = 0; i < runs;) { var currentValue = sequences[currentIndex]; if (doIncrease && currentValue + 1 <= maxValue || !doIncrease && currentValue - 1 >= minValue) { sequences[currentIndex] = currentValue + (doIncrease ? 1 : -1); i++; } currentIndex++; if (currentIndex >= sequences.Length) { currentIndex = 0; } } } return sequences; }
private void OnSpellbookCastSpell(Spellbook sender, SpellbookCastSpellEventArgs args) { try { if (!sender.Owner.IsMe || !_menu.Item(_menu.Name + ".enabled").GetValue <bool>()) { return; } var flash = _menu.Item(_menu.Name + ".spells.flash").GetValue <Slider>().Value; if (flash > 0 && Utils.GameTimeTickCount - _lastFlashCast <= flash * 1000) { return; } var isSpell = _spells.Any(s => s.Equals(args.Slot) && IsSpellEnabled(s)); var isItem = _items.Any(s => s.Equals(args.Slot)); if (!isSpell && !isItem) { return; } if (!_randomizedSpells.ContainsKey(args.Slot)) { _randomizedSpells[args.Slot] = false; } if (_randomizedSpells[args.Slot]) { _randomizedSpells[args.Slot] = false; return; } var spell = ObjectManager.Player.Spellbook.GetSpell(args.Slot); if (spell == null) { return; } var position = args.Target != null ? args.Target.Position : (args.StartPosition.IsValid() ? args.StartPosition : (args.EndPosition.IsValid() ? args.EndPosition : ObjectManager.Player.Position)); #region Screen if (_menu.Item(_menu.Name + ".spells.screen").GetValue <bool>() && position.IsValid() && !position.IsOnScreen()) { args.Process = false; _blockedOrders++; return; } #endregion Screen #region Checks if (_menu.Item(_menu.Name + ".spells.checks").GetValue <bool>()) { if (Utils.GameTimeTickCount - _lastSpellCast >= _random.Next((int)(1000f * 0.975f), (int)(1000f * 1.025f))) { _isCasting = false; } if (MenuGUI.IsShopOpen || MenuGUI.IsChatOpen || ((_isCasting || ObjectManager.Player.Spellbook.IsCastingSpell) && isSpell) || !spell.IsReady()) { args.Process = false; _blockedSpells++; return; } } #endregion Checks #region Delay var defaultDelay = _menu.Item(_menu.Name + ".spells.delay").GetValue <Slider>().Value; var delay = Math.Max( _random.Next((int)(defaultDelay * 0.85f), (int)(defaultDelay * 1.15f)), _random.Next((int)(Game.Ping * 0.45f), (int)(Game.Ping * 0.55f))); var type = spell.SData.TargettingType.ToString(); if (_targetTypes.Any(t => type.Contains(t))) { var percent = _menu.Item(_menu.Name + ".spells.range-delay").GetValue <Slider>().Value; if (percent > 0) { delay = Math.Max(delay, GetRangeDelay(position, _lastCastPosition, percent)); } } if (Utils.GameTimeTickCount - (isSpell ? _lastSpellCast : _lastItemCast) <= delay) { args.Process = false; _blockedSpells++; return; } #endregion Delay _lastCastPosition = position.IsValid() && _targetTypes.Any(t => type.Contains(t)) ? position : Vector3.Zero; #region Randomize var randomPosition = _menu.Item(_menu.Name + ".spells.position").GetValue <Slider>().Value; if (randomPosition > 0 && args.Target == null && (type.Contains("Cone") || type.Contains("Location")) && !_randomizedSpells[args.Slot]) { var startPos = Vector3.Zero; var endPos = Vector3.Zero; if (args.StartPosition.IsValid()) { startPos = _random.Randomize(args.StartPosition, randomPosition); } if (args.EndPosition.IsValid()) { endPos = _random.Randomize(args.EndPosition, randomPosition); } if (startPos.IsValid() || endPos.IsValid()) { args.Process = false; _randomizedSpells[args.Slot] = true; if (startPos.IsValid() && endPos.IsValid()) { ObjectManager.Player.Spellbook.CastSpell(args.Slot, startPos, endPos); } else if (startPos.IsValid()) { ObjectManager.Player.Spellbook.CastSpell(args.Slot, startPos); } else if (endPos.IsValid()) { ObjectManager.Player.Spellbook.CastSpell(args.Slot, endPos); } } } #endregion Randomize _isCasting = true; if (isSpell) { _lastSpellCast = Utils.GameTimeTickCount; } else { _lastItemCast = Utils.GameTimeTickCount; } } catch (Exception ex) { args.Process = true; Console.WriteLine(ex); } }