public void DeleteSelectedItems() { foreach (var presetItemViewModel in SelectedItems.ToList()) { PresetItems.Remove(presetItemViewModel); } }
private void Load(bool resetPresetLists = true) { if (resetPresetLists) { PresetEntities.Clear(); PresetItems.Clear(); } PresetEntities.AddRange(GetEntitiesFromFiles()); PresetItems.AddRange(ConvertEntitiesToItems(PresetEntities)); }
public void PreviousFrequency() { eventAggregator.Publish(new Events.HearingTest.StopPlaying()); IsPlaying = false; CurrentItem = PresetItems.Previous(); pitchGenerator.Frequency = CurrentItem.Frequency; CurrentFrequency = CurrentItem.Frequency.ToString(CultureInfo.InvariantCulture); MuteVolume(); eventAggregator.Publish(new Events.HearingTest.StartPlaying(CurrentItem)); IsPlaying = true; }
public void AddNewItem() { dialogBuilder.Reset(); var confirmationAction = new Action(() => { var errorString = dialogBuilder.UnderlyingViewModel.Error; if (!string.IsNullOrEmpty(errorString)) { MessageBox.Show(errorString, "Validation error", MessageBoxButton.OK); } else { var newItem = dialogBuilder.UnderlyingViewModel.ToPresetItem(); var existingItem = PresetItems.SingleOrDefault( x => x.Frequency == newItem.Frequency); if (existingItem != null) { PresetItems.Remove(existingItem); } PresetItems.Add(newItem); var items = PresetItems.OrderBy(x => x.Frequency).ToList(); PresetItems.Clear(); PresetItems.AddRange(items); } }); dialogBuilder.Title("Add item...") .LeftButtonContent("OK") .RightButtonContent("Cancel") .LeftButtonAction(confirmationAction) .Show(); }
private void ResetSettings() { MULTIbalancer rhs = new MULTIbalancer(); /* ===== SECTION 0 - Presets ===== */ Preset = rhs.Preset; // EnableUnstacking = rhs.EnableUnstacking; // don't reset EnableUnstacking /* ===== SECTION 1 - Settings ===== */ DebugLevel = rhs.DebugLevel; MaximumServerSize = rhs.MaximumServerSize; EnableBattlelogRequests = rhs.EnableBattlelogRequests; MaximumRequestRate = rhs.MaximumRequestRate; WaitTimeout = rhs.WaitTimeout; WhichBattlelogStats = rhs.WhichBattlelogStats; MaxTeamSwitchesByStrongPlayers = rhs.MaxTeamSwitchesByStrongPlayers; MaxTeamSwitchesByWeakPlayers = rhs.MaxTeamSwitchesByWeakPlayers; UnlimitedTeamSwitchingDuringFirstMinutesOfRound = rhs.UnlimitedTeamSwitchingDuringFirstMinutesOfRound; Enable2SlotReserve = rhs.Enable2SlotReserve; EnablerecruitCommand = rhs.EnablerecruitCommand; EnableWhitelistingOfReservedSlotsList = rhs.EnableWhitelistingOfReservedSlotsList; SecondsUntilAdaptiveSpeedBecomesFast = rhs.SecondsUntilAdaptiveSpeedBecomesFast; EnableInGameCommands = rhs.EnableInGameCommands; // Whitelist = rhs.Whitelist; // don't reset the whitelist // DisperseEvenlyList = rhs.DisperseEvenlyList; // don't reset the dispersal list /* ===== SECTION 2 - Exclusions ===== */ OnWhitelist = rhs.OnWhitelist; OnFriendsList = rhs.OnFriendsList; ApplyFriendsListToTeam = rhs.ApplyFriendsListToTeam; TopScorers = rhs.TopScorers; SameClanTagsInSquad = rhs.SameClanTagsInSquad; SameClanTagsInTeam = rhs.SameClanTagsInTeam; SameClanTagsForRankDispersal = rhs.SameClanTagsForRankDispersal; LenientRankDispersal = rhs.LenientRankDispersal; MinutesAfterJoining = rhs.MinutesAfterJoining; MinutesAfterBeingMoved = rhs.MinutesAfterBeingMoved; JoinedEarlyPhase = rhs.JoinedEarlyPhase; JoinedMidPhase = rhs.JoinedMidPhase; JoinedLatePhase = rhs.JoinedLatePhase; /* ===== SECTION 3 - Round Phase & Population Settings ===== */ EarlyPhaseTicketPercentageToUnstack = rhs.EarlyPhaseTicketPercentageToUnstack; MidPhaseTicketPercentageToUnstack = rhs.MidPhaseTicketPercentageToUnstack; LatePhaseTicketPercentageToUnstack = rhs.LatePhaseTicketPercentageToUnstack; EnableTicketLossRateLogging = rhs.EnableTicketLossRateLogging; SpellingOfSpeedNamesReminder = rhs.SpellingOfSpeedNamesReminder; EarlyPhaseBalanceSpeed = rhs.EarlyPhaseBalanceSpeed; MidPhaseBalanceSpeed = rhs.MidPhaseBalanceSpeed; LatePhaseBalanceSpeed = rhs.LatePhaseBalanceSpeed; /* ===== SECTION 4 - Scrambler ===== */ OnlyOnNewMaps = rhs.OnlyOnNewMaps; OnlyOnFinalTicketPercentage = rhs.OnlyOnFinalTicketPercentage; ScrambleBy = rhs.ScrambleBy; KeepClanTagsInSameTeam = rhs.KeepClanTagsInSameTeam; KeepFriendsInSameTeam = rhs.KeepFriendsInSameTeam; DivideBy = rhs.DivideBy; ClanTagToDivideBy = rhs.ClanTagToDivideBy; DelaySeconds = rhs.DelaySeconds; /* ===== SECTION 5 - Messages ===== */ QuietMode = rhs.QuietMode; YellDurationSeconds = rhs.YellDurationSeconds; BadBecauseMovedByBalancer = rhs.BadBecauseMovedByBalancer; BadBecauseWinningTeam = rhs.BadBecauseWinningTeam; BadBecauseBiggestTeam = rhs.BadBecauseBiggestTeam; BadBecauseRank = rhs.BadBecauseRank; BadBecauseDispersalList = rhs.BadBecauseDispersalList; ChatMovedForBalance = rhs.ChatMovedForBalance; YellMovedForBalance = rhs.YellMovedForBalance; ChatMovedToUnstack = rhs.ChatMovedToUnstack; YellMovedToUnstack = rhs.YellMovedToUnstack; ChatDetectedBadTeamSwitch = rhs.ChatDetectedBadTeamSwitch; YellDetectedBadTeamSwitch = rhs.YellDetectedBadTeamSwitch; ChatDetectedGoodTeamSwitch = rhs.ChatDetectedGoodTeamSwitch; YellDetectedGoodTeamSwitch = rhs.YellDetectedGoodTeamSwitch; ChatAfterUnswitching = rhs.ChatAfterUnswitching; YellAfterUnswitching = rhs.YellAfterUnswitching; /* ===== SECTION 6 - Unswitcher ===== */ ForbidSwitchingAfterAutobalance = rhs.ForbidSwitchingAfterAutobalance; ForbidSwitchingToWinningTeam = rhs.ForbidSwitchingToWinningTeam; ForbidSwitchingToBiggestTeam = rhs.ForbidSwitchingToBiggestTeam; ForbidSwitchingAfterDispersal = rhs.ForbidSwitchingAfterDispersal; EnableImmediateUnswitch = rhs.EnableImmediateUnswitch; /* ===== SECTION 7 - TBD ===== */ /* ===== SECTION 8 - Per-Mode Settings ===== */ List<String> simpleModes = GetSimplifiedModes(); fPerMode.Clear(); foreach (String sm in simpleModes) { PerModeSettings oneSet = null; if (!fPerMode.ContainsKey(sm)) { oneSet = new PerModeSettings(sm, fGameVersion == GameVersion.BF4); fPerMode[sm] = oneSet; } } /* ===== SECTION 9 - Debug Settings ===== */ ShowCommandInLog = rhs.ShowCommandInLog; LogChat = rhs.LogChat; EnableLoggingOnlyMode = rhs.EnableLoggingOnlyMode; }
public MULTIbalancer(PresetItems preset) : this() { switch (preset) { case PresetItems.Standard: // EarlyPhaseTicketPercentageToUnstack = new double[3] { 0,120,120}; // MidPhaseTicketPercentageToUnstack = new double[3] { 0,120,120}; // LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; // EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Adaptive, Speed.Adaptive}; // MidPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Adaptive, Speed.Adaptive}; // LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; // ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; // ForbidSwitchingToWinningTeam = UnswitchChoice.Always; // ForbidSwitchingToBiggestTeam = UnswitchChoice.Always; // ForbidSwitchingAfterDispersal = UnswitchChoice.Always; // EnableImmediateUnswitch = true; // // foreach (String mode in fPerMode.Keys) { // fPerMode[mode].PercentOfTopOfTeamIsStrong = 50; // } break; case PresetItems.Aggressive: OnWhitelist = true; OnFriendsList = false; ApplyFriendsListToTeam = false; TopScorers = false; SameClanTagsInSquad = false; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = false; LenientRankDispersal = false; MinutesAfterJoining = 0; MinutesAfterBeingMoved = 0; JoinedEarlyPhase = false; JoinedMidPhase = false; JoinedLatePhase = false; EarlyPhaseTicketPercentageToUnstack = new double[3] {110,110,110}; MidPhaseTicketPercentageToUnstack = new double[3] {110,110,110}; LatePhaseTicketPercentageToUnstack = new double[3] {110,110,110}; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Fast, Speed.Fast}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Fast, Speed.Fast}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Fast, Speed.Fast}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Always; ForbidSwitchingAfterDispersal = UnswitchChoice.Always; EnableImmediateUnswitch = true; // Does not count for automatic detection of preset foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 50; } break; case PresetItems.Passive: OnWhitelist = true; OnFriendsList = true; ApplyFriendsListToTeam = true; TopScorers = true; SameClanTagsInSquad = true; SameClanTagsInTeam = true; SameClanTagsForRankDispersal = true; LenientRankDispersal = true; MinutesAfterJoining = 15; MinutesAfterBeingMoved = 12*60; // 12 hours JoinedEarlyPhase = true; JoinedMidPhase = true; JoinedLatePhase = true; EarlyPhaseTicketPercentageToUnstack = new double[3] { 0, 0,200}; MidPhaseTicketPercentageToUnstack = new double[3] { 0,200,200}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Slow, Speed.Slow, Speed.Slow}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Slow, Speed.Slow, Speed.Slow}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Always; ForbidSwitchingAfterDispersal = UnswitchChoice.Never; EnableImmediateUnswitch = false; // Does not count for automatic detection of preset foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 50; } break; case PresetItems.Intensify: OnWhitelist = true; OnFriendsList = false; ApplyFriendsListToTeam = false; TopScorers = true; SameClanTagsInSquad = false; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = false; LenientRankDispersal = false; MinutesAfterJoining = 0; MinutesAfterBeingMoved = 0; JoinedEarlyPhase = false; JoinedMidPhase = false; JoinedLatePhase = true; EarlyPhaseTicketPercentageToUnstack = new double[3] {110,120,120}; MidPhaseTicketPercentageToUnstack = new double[3] {120,120,120}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; // TBD: Needs Speed.OverBalance (similar to Fast, but puts more players on losing team) EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Adaptive, Speed.Adaptive, Speed.Adaptive}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Adaptive, Speed.Adaptive, Speed.Adaptive}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Never; ForbidSwitchingAfterDispersal = UnswitchChoice.Always; EnableImmediateUnswitch = true; foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 25; } break; case PresetItems.Retain: OnWhitelist = true; OnFriendsList = true; ApplyFriendsListToTeam = true; TopScorers = true; SameClanTagsInSquad = true; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = true; LenientRankDispersal = true; MinutesAfterJoining = 15; MinutesAfterBeingMoved = 2*60; // 2 hours JoinedEarlyPhase = true; JoinedMidPhase = true; JoinedLatePhase = true; EarlyPhaseTicketPercentageToUnstack = new double[3] { 0, 0,150}; MidPhaseTicketPercentageToUnstack = new double[3] { 0,150,200}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Slow, Speed.Adaptive, Speed.Slow}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Slow, Speed.Adaptive, Speed.Slow}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Never; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Never; ForbidSwitchingAfterDispersal = UnswitchChoice.Never; EnableImmediateUnswitch = true; foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 5; } break; case PresetItems.BalanceOnly: OnWhitelist = true; OnFriendsList = false; ApplyFriendsListToTeam = false; TopScorers = true; SameClanTagsInSquad = true; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = true; LenientRankDispersal = false; MinutesAfterJoining = 5; MinutesAfterBeingMoved = 90; JoinedEarlyPhase = true; JoinedMidPhase = true; JoinedLatePhase = false; EarlyPhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; MidPhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Adaptive, Speed.Adaptive, Speed.Adaptive}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Adaptive, Speed.Adaptive, Speed.Adaptive}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; ForbidSwitchingToWinningTeam = UnswitchChoice.Never; ForbidSwitchingToBiggestTeam = UnswitchChoice.Never; ForbidSwitchingAfterDispersal = UnswitchChoice.Never; EnableImmediateUnswitch = true; foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 0; } break; case PresetItems.UnstackOnly: OnWhitelist = true; OnFriendsList = false; ApplyFriendsListToTeam = false; TopScorers = true; SameClanTagsInSquad = true; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = true; LenientRankDispersal = false; MinutesAfterJoining = 5; MinutesAfterBeingMoved = 90; JoinedEarlyPhase = true; JoinedMidPhase = true; JoinedLatePhase = false; EarlyPhaseTicketPercentageToUnstack = new double[3] { 0,120,120}; MidPhaseTicketPercentageToUnstack = new double[3] {120,120,120}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Unstack, Speed.Unstack, Speed.Unstack}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Unstack, Speed.Unstack, Speed.Unstack}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Unstack, Speed.Unstack, Speed.Unstack}; ForbidSwitchingAfterAutobalance = UnswitchChoice.Never; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Never; ForbidSwitchingAfterDispersal = UnswitchChoice.Always; EnableImmediateUnswitch = true; // Does not count for automatic detection of preset foreach (String mode in fPerMode.Keys) { fPerMode[mode].PercentOfTopOfTeamIsStrong = 50; } break; case PresetItems.None: break; default: break; } }
/* Constructor */ public MULTIbalancer() { /* Private members */ fIsEnabled = false; fFinalizerActive = false; fPluginState = PluginState.Disabled; fGameState = GameState.Unknown; fServerInfo = null; fRefreshCommand = false; fServerUptime = 0; fServerCrashed = false; fDebugScramblerBefore = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()}; fDebugScramblerAfter = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()}; fDebugScramblerStartRound = new List<PlayerModel>[2]{new List<PlayerModel>(), new List<PlayerModel>()}; fBalancedRound = 0; fUnstackedRound = 0; fUnswitchedRound = 0; fExcludedRound = 0; fExemptRound = 0; fFailedRound = 0; fTotalRound = 0; fBalanceIsActive = false; fRoundsEnabled = 0; fGrandTotalQuits = 0; fGrandRageQuits = 0; fTotalQuits = 0; fRageQuits = 0; fMoveThread = null; fFetchThread = null; fListPlayersThread = null; fScramblerThread = null; fTimerThread = null; fModeToSimple = new Dictionary<String,String>(); fEasyTypeDict = new Dictionary<int, Type>(); fEasyTypeDict.Add(0, typeof(int)); fEasyTypeDict.Add(1, typeof(Int16)); fEasyTypeDict.Add(2, typeof(Int32)); fEasyTypeDict.Add(3, typeof(Int64)); fEasyTypeDict.Add(4, typeof(float)); fEasyTypeDict.Add(5, typeof(long)); fEasyTypeDict.Add(6, typeof(String)); fEasyTypeDict.Add(7, typeof(string)); fEasyTypeDict.Add(8, typeof(double)); fBoolDict = new Dictionary<int, Type>(); fBoolDict.Add(0, typeof(Boolean)); fBoolDict.Add(1, typeof(bool)); fListStrDict = new Dictionary<int, Type>(); fListStrDict.Add(0, typeof(String[])); fPerMode = new Dictionary<String,PerModeSettings>(); fAllPlayers = new List<String>(); fKnownPlayers = new Dictionary<String, PlayerModel>(); fTeam1 = new List<PlayerModel>(); fTeam2 = new List<PlayerModel>(); fTeam3 = new List<PlayerModel>(); fTeam4 = new List<PlayerModel>(); fUnassigned = new List<String>(); fRoundStartTimestamp = DateTime.MinValue; fRoundOverTimestamp = DateTime.MinValue; fListPlayersTimestamp = DateTime.MinValue; fFullUnstackSwapTimestamp = DateTime.MinValue; fLastValidationTimestamp = DateTime.MinValue; fListPlayersQ = new Queue<DelayedRequest>(); fPendingTeamChange = new Dictionary<String,int>(); fMoving = new Dictionary<String, MoveInfo>(); fMoveQ = new Queue<MoveInfo>(); fReassigned = new List<String>(); fReservedSlots = new List<String>(); fTickets = new int[5]{0,0,0,0,0}; fFriendlyMaps = new Dictionary<String,String>(); fFriendlyModes = new Dictionary<String,String>(); fMaxTickets = -1; fRushMaxTickets = -1; fLastBalancedTimestamp = DateTime.MinValue; fEnabledTimestamp = DateTime.MinValue; fFinalStatus = null; fIsFullRound = false; fUnstackState = UnstackState.Off; fLastMsg = null; fRushStage = 0; fRushPrevAttackerTickets = 0; fRushAttackerStageLoss = 0; fRushAttackerStageSamples = 0; fMoveStash = new List<MoveInfo>(); fLastVersionCheckTimestamp = DateTime.MinValue; fTimeOutOfJoint = 0; fUnstackGroupCount = 0; fPriorityFetchQ = new PriorityQueue(this); fIsCacheEnabled = false; fScramblerLock = new DelayedRequest(); fWinner = 0; fUpdateThreadLock = new DelayedRequest(); fLastServerInfoTimestamp = DateTime.Now; fStageInProgress = false; fHost = String.Empty; fPort = String.Empty; fRushMap3Stages = new List<String>(new String[6]{"MP_007", "XP4_Quake", "XP5_002", "MP_012", "XP4_Rubble", "MP_Damage"}); fRushMap5Stages = new List<String>(new String[6]{"MP_013", "XP3_Valley", "MP_017", "XP5_001", "MP_Prison", "MP_Siege"}); fGroupAssignments = new int[5]{0,0,0,0,0}; fDispersalGroups = new List<String>[5]{null, new List<String>(), new List<String>(), new List<String>(), new List<String>()}; fNeedPlayerListUpdate = false; fFriends = new Dictionary<int, List<String>>(); fAllFriends = new List<String>(); fWhileScrambling = false; fExtrasLock = new DelayedRequest(); fExtraNames = new List<String>(); fGotLogin = false; fDebugScramblerSuspects = new Dictionary<String,String>(); fTimerRequestList = new List<DelayedRequest>(); fAverageTicketLoss = new Queue<double>[3]{null, new Queue<double>(), new Queue<double>()}; fTicketLossHistogram = new Histogram(); /* Settings */ /* ===== SECTION 0 - Presets ===== */ SettingsVersion = 1; Preset = PresetItems.Standard; EnableUnstacking = false; EnableSettingsWizard = false; WhichMode = "Conquest Large"; MetroIsInMapRotation = false; MaximumPlayersForMode = 64; LowestMaximumTicketsForMode = 300; HighestMaximumTicketsForMode = 400; PreferredStyleOfBalancing = PresetItems.Standard; ApplySettingsChanges = false; /* ===== SECTION 1 - Settings ===== */ DebugLevel = 2; MaximumServerSize = 64; EnableBattlelogRequests = true; MaximumRequestRate = 10; // in 20 seconds WaitTimeout = 30; // seconds WhichBattlelogStats = BattlelogStats.ClanTagOnly; MaxTeamSwitchesByStrongPlayers = 1; MaxTeamSwitchesByWeakPlayers = 2; UnlimitedTeamSwitchingDuringFirstMinutesOfRound = 5.0; Enable2SlotReserve = false; EnablerecruitCommand = false; EnableWhitelistingOfReservedSlotsList = true; Whitelist = new String[] {DEFAULT_LIST_ITEM}; fSettingWhitelist = new List<String>(Whitelist); DisperseEvenlyList = new String[] {DEFAULT_LIST_ITEM}; fSettingDisperseEvenlyList = new List<String>(DisperseEvenlyList); FriendsList = new String[] {DEFAULT_LIST_ITEM}; fSettingFriendsList = new List<String>(); SecondsUntilAdaptiveSpeedBecomesFast = 3*60; // 3 minutes default EnableInGameCommands = true; /* ===== SECTION 2 - Exclusions ===== */ OnWhitelist = true; OnFriendsList = false; ApplyFriendsListToTeam = false; TopScorers = true; SameClanTagsInSquad = true; SameClanTagsInTeam = false; SameClanTagsForRankDispersal = false; LenientRankDispersal = false; MinutesAfterJoining = 5; MinutesAfterBeingMoved = 90; // 1.5 hours JoinedEarlyPhase = true; JoinedMidPhase = true; JoinedLatePhase = false; /* ===== SECTION 3 - Round Phase & Population Settings ===== */ EarlyPhaseTicketPercentageToUnstack = new double[3] { 0,120,120}; MidPhaseTicketPercentageToUnstack = new double[3] { 0,120,120}; LatePhaseTicketPercentageToUnstack = new double[3] { 0, 0, 0}; EnableTicketLossRateLogging = false; SpellingOfSpeedNamesReminder = Speed.Click_Here_For_Speed_Names; EarlyPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Adaptive, Speed.Adaptive}; MidPhaseBalanceSpeed = new Speed[3] { Speed.Fast, Speed.Adaptive, Speed.Adaptive}; LatePhaseBalanceSpeed = new Speed[3] { Speed.Stop, Speed.Stop, Speed.Stop}; /* ===== SECTION 4 - Scrambler ===== */ OnlyOnNewMaps = true; // false means scramble every round OnlyOnFinalTicketPercentage = 120; // 0 means scramble regardless of final score ScrambleBy = DefineStrong.RoundScore; KeepSquadsTogether = true; KeepClanTagsInSameTeam = true; KeepFriendsInSameTeam = false; DivideBy = DivideByChoices.None; ClanTagToDivideBy = String.Empty; DelaySeconds = 50; /* ===== SECTION 5 - Messages ===== */ QuietMode = false; // false: chat is global, true: chat is private. Yells are always private YellDurationSeconds = 10; BadBecauseMovedByBalancer = "autobalance moved you to the %toTeam% team"; BadBecauseWinningTeam = "switching to the winning team is not allowed"; BadBecauseBiggestTeam = "switching to the biggest team is not allowed"; BadBecauseRank = "this server splits Colonel 100's between teams"; BadBecauseDispersalList = "you're on the list of players to split between teams"; ChatMovedForBalance = "*** MOVED %name% for balance ..."; YellMovedForBalance = "Moved %name% for balance ..."; ChatMovedToUnstack = "*** MOVED %name% to unstack teams ..."; YellMovedToUnstack = "Moved %name% to unstack teams ..."; ChatDetectedBadTeamSwitch = "%name%, you can't switch to team %fromTeam%: %reason%, sending you back ..."; YellDetectedBadTeamSwitch = "You can't switch to the %fromTeam% team: %reason%, sending you back!"; ChatDetectedGoodTeamSwitch = "%name%, thanks for helping out the %toTeam% team!"; YellDetectedGoodTeamSwitch = "Thanks for helping out the %toTeam% team!"; ChatAfterUnswitching = "%name%, please stay on the %toTeam% team for the rest of this round"; YellAfterUnswitching = "Please stay on the %toTeam% team for the rest of this round"; /* ===== SECTION 6 - Unswitcher ===== */ EnableImmediateUnswitch = true; ForbidSwitchingAfterAutobalance = UnswitchChoice.Always; ForbidSwitchingToWinningTeam = UnswitchChoice.Always; ForbidSwitchingToBiggestTeam = UnswitchChoice.Always; ForbidSwitchingAfterDispersal = UnswitchChoice.Always; /* ===== SECTION 7 - TBD ===== */ /* ===== SECTION 8 - Per-Mode Settings ===== */ /* ===== SECTION 9 - Debug Settings ===== */ ShowInLog = INVALID_NAME_TAG_GUID; ShowCommandInLog = String.Empty; LogChat = true; EnableLoggingOnlyMode = false; EnableExternalLogging = false; ExternalLogSuffix = "_mb.log"; }
public void SetPluginVariable(String strVariable, String strValue) { bool isPresetVar = false; bool isReminderVar = false; if (fIsEnabled) DebugWrite(strVariable + " <- " + strValue, 6); try { if (strVariable.Contains("Show In Log") && String.IsNullOrEmpty(strValue)) { DebugWrite("^8Detected pre-v1 settings, upgrading ...", 3); UpgradePreV1Settings(); strValue = INVALID_NAME_TAG_GUID; // mark as upgraded } else if (strVariable.Contains("Settings Version")) { DebugWrite("^1Settings Version = " + strValue, 3); } String tmp = strVariable; int pipeIndex = strVariable.IndexOf('|'); if (pipeIndex >= 0) { pipeIndex++; tmp = strVariable.Substring(pipeIndex, strVariable.Length - pipeIndex); } if (tmp.Contains("(Low, Med, High population)")) { tmp = tmp.Replace("(Low, Med, High population)", String.Empty); } BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; String propertyName = Regex.Replace(tmp, @"[^a-zA-Z_0-9]", String.Empty); if (strVariable.Contains("preset")) propertyName = "Preset"; FieldInfo field = this.GetType().GetField(propertyName, flags); Type fieldType = null; if (!strVariable.Contains("Settings for") && field != null) { fieldType = field.GetValue(this).GetType(); if (strVariable.Contains("preset")) { fieldType = typeof(PresetItems); try { Preset = (PresetItems)Enum.Parse(fieldType, strValue); isPresetVar = true; } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Spelling Of Speed Names Reminder")) { fieldType = typeof(Speed); try { field.SetValue(this, (Speed)Enum.Parse(fieldType, strValue)); isReminderVar = true; } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Balance Speed")) { fieldType = typeof(Speed[]); try { // Parse the list into an array of enum vals Speed[] items = MULTIbalancerUtils.ParseSpeedArray(this, strValue); // also validates field.SetValue(this, items); } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Ticket Percentage To Unstack")) { fieldType = typeof(double[]); try { // Parse the list into an array of numbers double[] nums = MULTIbalancerUtils.ParseNumArray(strValue); // also validates field.SetValue(this, nums); } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Scramble By")) { fieldType = typeof(DefineStrong); try { field.SetValue(this, (DefineStrong)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } else if (tmp == "Divide By") { fieldType = typeof(DivideByChoices); try { field.SetValue(this, (DivideByChoices)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Preferred Style Of Balancing")) { fieldType = typeof(PresetItems); try { field.SetValue(this, (PresetItems)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Forbid Switching")) { fieldType = typeof(UnswitchChoice); try { field.SetValue(this, (UnswitchChoice)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } else if (tmp.Contains("Which Battlelog Stats")) { fieldType = typeof(BattlelogStats); try { field.SetValue(this, (BattlelogStats)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } else if (fEasyTypeDict.ContainsValue(fieldType)) { field.SetValue(this, TypeDescriptor.GetConverter(fieldType).ConvertFromString(strValue)); } else if (fListStrDict.ContainsValue(fieldType)) { if (DebugLevel >= 8) ConsoleDebug("String array " + propertyName + " <- " + strValue); field.SetValue(this, CPluginVariable.DecodeStringArray(strValue)); if (propertyName == "Whitelist") { UpdateWhitelistModel(); /* MergeWithFile(Whitelist, fSettingWhitelist); if (EnableWhitelistingOfReservedSlotsList) MergeWhitelistWithReservedSlots(); UpdateAllFromWhitelist(); if (DebugLevel >= 8) { String l = "Whitelist: "; l = l + String.Join(", ", fSettingWhitelist.ToArray()); ConsoleDebug(l); } */ } else if (propertyName == "DisperseEvenlyList") { MergeWithFile(DisperseEvenlyList, fSettingDisperseEvenlyList); // clears fSettingDispersEvenlyList SetDispersalListGroups(); AssignGroups(); } else if (propertyName == "FriendsList") { MergeWithFile(FriendsList, fSettingFriendsList); // clears fSettingFriendsList SetFriends(); } } else if (fBoolDict.ContainsValue(fieldType)) { if (fIsEnabled) DebugWrite(propertyName + " strValue = " + strValue, 6); if (Regex.Match(strValue, "true", RegexOptions.IgnoreCase).Success) { field.SetValue(this, true); } else { field.SetValue(this, false); } } else { if (DebugLevel >= 8) ConsoleDebug("Unknown var " + propertyName + " with type " + fieldType); } } else { Match m = Regex.Match(tmp, @"([^:]+):\s([^:]+)$"); if (m.Success) { String mode = m.Groups[1].Value; String fieldPart = m.Groups[2].Value.Replace(" ",""); String perModeSetting = Regex.Replace(fieldPart, @"[^a-zA-Z_0-9]", String.Empty); perModeSetting = Regex.Replace(perModeSetting, @"(?:AsTickets|AsMinutes)", String.Empty); if (!fPerMode.ContainsKey(mode)) { fPerMode[mode] = new PerModeSettings(mode, fGameVersion == GameVersion.BF4); } PerModeSettings pms = fPerMode[mode]; field = pms.GetType().GetField(perModeSetting, flags); if (fIsEnabled) DebugWrite("Mode: " + mode + ", Field: " + perModeSetting + ", Value: " + strValue, 6); if (field != null) { fieldType = field.GetValue(pms).GetType(); if (fEasyTypeDict.ContainsValue(fieldType)) { field.SetValue(pms, TypeDescriptor.GetConverter(fieldType).ConvertFromString(strValue)); } else if (fListStrDict.ContainsValue(fieldType)) { field.SetValue(pms, new List<string>(CPluginVariable.DecodeStringArray(strValue))); } else if (fBoolDict.ContainsValue(fieldType)) { if (Regex.Match(strValue, "true", RegexOptions.IgnoreCase).Success) { field.SetValue(pms, true); } else { field.SetValue(pms, false); } } else if (strVariable.Contains("Determine Strong")) { fieldType = typeof(DefineStrong); try { field.SetValue(pms, (DefineStrong)Enum.Parse(fieldType, strValue)); } catch (Exception e) { ConsoleException(e); } } } else { if (fIsEnabled) DebugWrite("field is null", 6); } } } } catch (System.Exception e) { ConsoleException(e); } finally { if (!isReminderVar) { // Reset to show hint SpellingOfSpeedNamesReminder = Speed.Click_Here_For_Speed_Names; } if (isPresetVar) { // Update other settings based on new preset value MULTIbalancerUtils.UpdateSettingsForPreset(this, Preset); } else { // Update Preset value based on current settings UpdatePresetValue(); } if (strVariable.Contains("Apply Settings Changes") && ApplySettingsChanges) { ApplySettingsChanges = false; EnableSettingsWizard = false; ApplyWizardSettings(); } // Validate all values and correct if needed ValidateSettings(strVariable, strValue); // Handle show in log commands if (!String.IsNullOrEmpty(ShowCommandInLog)) { CommandToLog(ShowCommandInLog); ShowCommandInLog = String.Empty; } } }
private void UpdatePresetValue() { Preset = PresetItems.None; // backstop value try { // Check for Standard if (MULTIbalancerUtils.IsEqual(this, PresetItems.Standard)) { Preset = PresetItems.Standard; return; } // Check for Aggressive if (MULTIbalancerUtils.IsEqual(this, PresetItems.Aggressive)) { Preset = PresetItems.Aggressive; return; } // Check for Passive if (MULTIbalancerUtils.IsEqual(this, PresetItems.Passive)) { Preset = PresetItems.Passive; return; } // Check for Intensify if (MULTIbalancerUtils.IsEqual(this, PresetItems.Intensify)) { Preset = PresetItems.Intensify; return; } // Check for Retain if (MULTIbalancerUtils.IsEqual(this, PresetItems.Retain)) { Preset = PresetItems.Retain; return; } // Check for BalanceOnly if (MULTIbalancerUtils.IsEqual(this, PresetItems.BalanceOnly)) { Preset = PresetItems.BalanceOnly; return; } // Check for UnstackOnly if (MULTIbalancerUtils.IsEqual(this, PresetItems.UnstackOnly)) { Preset = PresetItems.UnstackOnly; return; } } catch (Exception e) { ConsoleException(e); } }
public TPresetItem FindPresetItemById(int id) { return(PresetItems.FirstOrDefault(e => e.Id == id)); }
private int GetNewPresetId() { return((PresetItems.Any() ? PresetItems.Max(p => p.Id) : 0) + 1); }