string item_key(Weapon w) { if (w == null) return "No weapon key"; try { return w.Name; } catch { } return "No weapon key"; }
/** * Based on the player's votes, set the next weapon * */ private bool voteCalculateNextWeapon() { //create new var to store the weapon counts Dictionary<Weapon, Int32> voteCounts = new Dictionary<Weapon, int>(); //loop through all the given votes and count them up by weapon name foreach (KeyValuePair<String, Weapon> weaponVote in this.weaponVotes) { //check to see if the weapon is already in the vote list if (voteCounts.ContainsKey(weaponVote.Value)) { //if it is just increment the vote count by 1 voteCounts[weaponVote.Value] += 1; } else { //if it isnt, add it with a vote count of 1 voteCounts.Add(weaponVote.Value, 1); } } Weapon topWeapon = null; Int32 topCount = 0; //loop through all the given votes counts foreach (KeyValuePair<Weapon, Int32> voteCount in voteCounts) { //check to see if the weapon is already in the vote list if (voteCount.Value>topCount) { topCount = voteCount.Value; topWeapon = voteCount.Key; } } if (!this.nextWeapon.Equals(topWeapon)) { this.sayMessage("Next weapon changed by voting from the " + this.nextWeapon.description + " to the " + topWeapon.description); this.ConsoleWrite("Next weapon changed by voting from the " + this.nextWeapon.description + " to the " + topWeapon.description); this.nextWeapon = topWeapon; return true; } else { return false; } }
/** * Decides/sets the current and next weapon randomly * The current and next weapons must never be the same * Done when the plugin is first enabled * */ private void randomCalculateNextWeapon() { this.currentWeapon = this.getRandomWeapon(); do { this.nextWeapon = this.getRandomWeapon(); } while (this.nextWeapon.Equals(this.currentWeapon)); ConsoleWrite("Next weapon changed randomly to: " + this.nextWeapon.description); this.setProconRulz(); }
private void sendVote(String speaker, String message) { String possibleWeaponString = message.Split(' ')[1].ToUpper(); Weapon decision = new Weapon("blarg", "blarg", "blarg", "blarg"); if (this.weaponDictionary.TryGetValue(possibleWeaponString, out decision)) { bool changedVote = false; if (this.weaponVotes.ContainsKey(speaker)) { this.weaponVotes.Remove(speaker); changedVote = true; } this.weaponVotes.Add(speaker, decision); if (!changedVote) { this.playerSayMessage(speaker, "You voted the " + decision.description + " be used next round."); } else { this.playerSayMessage(speaker, "You changed your vote to the " + decision.description + "."); } if (!this.voteCalculateNextWeapon()) { this.playerSayMessage(speaker, "Not enough to change next weapon, next weapon still the " + this.nextWeapon.description + "."); } } else { this.playerSayMessage(speaker, possibleWeaponString + " is an invalid weapon Code. Server description on battlelog has weapon codes."); } }
public override void OnLevelLoaded(String mapFileName, String Gamemode, int roundsPlayed, int roundsTotal) { this.currentWeapon = this.nextWeapon; string newServerName = ""; if(this.serverNameTemplate.Contains("%W%")) { newServerName = this.serverNameTemplate.Replace("%W%", this.currentWeapon.description); } else { newServerName = this.serverNameTemplate; } this.ExecuteCommand("procon.protected.send", "vars.serverName", newServerName); ConsoleWrite("Server Name set to: '" + newServerName + "'"); this.setProconRulz(); this.votingStarted = false; this.nextWeapon = this.getRandomWeapon(); }