// update button with countdown using Countdown function and information to find summonerGroup and button and cooldown private void countDownButton(int championNumber, int spellNumber, System.Windows.Controls.Button button, int modifier = 0, int champLevel = 0) { SummonerGroup summonerGroup = summonerGroups[championNumber - 1]; // find SummonerGroup based on champNumber float timerLength = 0; string spellName = ""; // get the champ level if it's from 1-18, and set the timer length based on that if (champLevel > 0 && champLevel <= 18) { timerLength = (int)(430.588 - (10.588 * champLevel)) - modifier; } else { // get the timer length and spell name based on the spell number switch (spellNumber) { case 1: timerLength = summonerGroup.spell1Cd - modifier; spellName = summonerGroup.spell1Name; break; case 2: timerLength = summonerGroup.spell2Cd - modifier; spellName = summonerGroup.spell2Name; break; } } if (button.Content.Equals("Activate")) // only run if the countdown isn't already in progress { //set color of button button.Background = redColor; //start to countdown on the button countdown(timerLength, TimeSpan.FromSeconds(1), time => { if (time > 0) { button.Content = time.ToString(); //update content of button to be the time left in the timer //update the cooldown strings list by sending a cooldown string object created with // champ name, spell name, and time left in the cooldown updateCooldownStrings(new CooldownString(summonerGroup.champName, spellName, time.ToString())); } else { // when the timer runs out, make the button change to say 'activate' and be green button.Content = "Activate"; button.Background = greenColor; } }); } }
// take the input in the form of [champion name] and [spell name] and convert // that to a champion and spell number using summonerGroups private void parseLastLine(string[] line) //EXAMPLE INPUT: [annie] [flash] { // if the command is "n", send all the summoner cooldowns in game chat if (line[0].Equals("n")) { foreach (CooldownString cds in cooldownStrings) { //send each cooldown in chat individually, since you can only send one line at a time in the game sendString(cds.toString()); } } // make input into all lowercase for the sake of comparison string inputName = line[0].ToLower(); string inputSpell = line[1].ToLower(); // find the summoner group associated with this champion name (LINQ IMPLEMENTATION) SummonerGroup summonerGroup = summonerGroups.First(sg => sg.champName.Equals(inputName)); // find the champion number by finding the index of the found summonerGroup int champNumber = summonerGroups.FindIndex(sg => sg == summonerGroup) + 1; // find if the spell number is 1 or 2 based on which one it matches in the summonerGroup int spellNumber = 0; if (inputSpell == summonerGroup.spell1Name) { spellNumber = 1; } else if (inputSpell == summonerGroup.spell2Name) { spellNumber = 2; } // find if the player inputted a cooldown modifier as their // 3rd input (number to be subtracted from the original cooldown) int cdModifier = 0; if (line.Length >= 3) { Int32.TryParse(line[2], out cdModifier); } // find if the player inputted a champion level // in the case of teleport (which has a special cooldown based on level) int champLevel = 0; if (inputSpell.Equals("teleport")) { // if you want to put teleport level and modifier, the formula is champion, spell, champLevel, modifier if (line.Length >= 4) { Int32.TryParse(line[2], out champLevel); Int32.TryParse(line[3], out cdModifier); } // if you only want to put teleport level OR modifier, you indicate by making the 3rd input negative, // which then it will be the modifier. ex: "annie flash 10" = cdModifier 10, "annie flash -10" = champLevel 10 else if (line.Length == 3) { int thirdInput; Int32.TryParse(line[2], out thirdInput); if (thirdInput > 0) { cdModifier = thirdInput; } else { champLevel = Math.Abs(thirdInput); } } } if (cdModifier < 0) { cdModifier = 0; //if modifier was inputted as negative, just make it 0 } // trigger the respective button based on the champNumber and spellNumber updateSpellButton(champNumber, spellNumber, cdModifier, champLevel); }