protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { if (spring.IsRunning) { context = spring.StartContext; voteStarter = context.Players.FirstOrDefault(x => x.Name == e.UserName && !x.IsSpectator); if (voteStarter != null) { question = string.Format("Resign team {0}?", voteStarter.AllyID + 1); int cnt = 0; foreach (var p in context.Players.Where(x => x.AllyID == voteStarter.AllyID && !x.IsSpectator)) { if (p.IsIngame || tas.MyBattle.Users.Any(x => x.Name == p.Name)) { if (!tas.ExistingUsers[p.Name].IsAway) { cnt++; } } } winCount = cnt / 2 + 1; return(true); } } AutoHost.Respond(tas, spring, e, "You cannot resign now"); question = null; winCount = 0; return(false); }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { question = "Exit this game?"; int cnt = 0; context = spring.StartContext; foreach (var p in context.Players.Where(x => !x.IsSpectator)) { if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name)) { //Note: "ExistingUsers" is empty if users disconnected from lobby but still ingame. bool afk = tas.ExistingUsers.ContainsKey(p.Name) && tas.ExistingUsers[p.Name].IsAway; if (!afk) { cnt++; } } } winCount = cnt / 2 + 1; return(true); } else { AutoHost.Respond(tas, spring, e, "game not running"); return(false); } }
public virtual bool Vote(TasSayEventArgs e, bool vote) { if (AllowVote(e)) { userVotes[e.UserName] = vote; var yes = userVotes.Count(x => x.Value == true); var no = userVotes.Count(x => x.Value == false); ah.SayBattle(string.Format("Poll: {0} [!y={1}/{3}, !n={2}/{3}]", Question, yes, no, CountNoIntoWinCount ? WinCount + no : WinCount)); if ((!CountNoIntoWinCount && yes >= WinCount) || (CountNoIntoWinCount && yes >= WinCount + no)) { ah.SayBattle(string.Format("Poll: {0} [END:SUCCESS]", Question)); ended = true; SuccessAction(); return(true); } else if (no >= WinCount) { End(); return(true); } } else { ah.Respond(e, "You are not allowed to vote"); return(false); } return(false); }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (words.Length == 0) { question = "Rehost this game?"; return(true); } else { string[] mods; int[] indexes; if (AutoHost.FilterMods(words, ah, out mods, out indexes) == 0) { AutoHost.Respond(tas, spring, e, "cannot find such mod"); return(false); } else { modname = mods[0]; question = "Rehost this game to " + modname + "?"; return(true); } } }
public void FindLinks(string[] words, FileType type, TasClient tas, TasSayEventArgs e) { if (words.Length == 0) { Battle b = tas.MyBattle; if (b == null) { return; } ah.Respond(e, string.Format("Getting Zero-K mirrors for currently hosted {0}", type)); if (type == FileType.Map) { plasmaService.DownloadFileAsync(b.MapName, e); } else { plasmaService.DownloadFileAsync(b.ModName, e); } } else { int[] resultIndexes; string[] resultVals; int cnt; if (type == FileType.Map) { cnt = ah.FilterMaps(words, out resultVals, out resultIndexes); } else { cnt = ah.FilterMods(words, out resultVals, out resultIndexes); } if (cnt == 0) { ah.Respond(e, string.Format("No such {0} found", type)); } else { ah.Respond(e, string.Format("Getting Zero-K mirrors for {0}, please wait", resultVals[0])); plasmaService.DownloadFileAsync(resultVals[0], e); } } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { question = "Exit this game?"; return(true); } else { AutoHost.Respond(tas, spring, e, "game not running"); return(false); } }
override protected bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { question = "Force game?"; return(true); } else { AutoHost.Respond(tas, spring, e, "battle not started yet"); return(false); } }
private void GetLinksAsync(string name, TasSayEventArgs e) { Task.Factory.StartNew(() => { DownloadFileResult ret; try { ret = plasmaService.DownloadFile(name); } catch (Exception ex) { Trace.TraceError(ex.ToString()); return; } if (ret.links != null && ret.links.Count > 0) { foreach (string s in ret.links) { ah.Respond(e, s.Replace(" ", "%20")); } } else { ah.Respond(e, "No links found"); } }); }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; CountNoIntoWinCount = false; if (!spring.IsRunning) { var invalid = tas.MyBattle.Users.Values.Where(x => !x.IsSpectator && (x.SyncStatus != SyncStatuses.Synced || x.LobbyUser.IsAway)).ToList(); if (invalid.Count > 0) { foreach (var inv in invalid) { ah.ComRing(e, new[] { inv.Name }); // ring invalids ot notify them } } // people wihtout map and spring map changed in last 2 minutes, dont allow start yet if (tas.MyBattle.Users.Values.Any(x => !x.IsSpectator && x.SyncStatus != SyncStatuses.Synced) && DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds < MainConfig.MapChangeDownloadWait) { var waitTime = (int)(MainConfig.MapChangeDownloadWait - DateTime.Now.Subtract(ah.lastMapChange).TotalSeconds); AutoHost.Respond(tas, spring, e, string.Format("Map was changed and some players don't have it yet, please wait {0} more seconds", waitTime)); return(false); } question = "Start game? "; if (invalid.Count > 0) { var invalids = string.Join(",", invalid); ah.SayBattle(invalids + " will be forced spectators if they don't download their maps and stop being afk when vote ends"); question += string.Format("WARNING, SPECTATES: {0}", invalids); } if (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) >= 2) { winCount = (tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) + 1) / 2 + 1; } else { winCount = 1; } return(true); } else { AutoHost.Respond(tas, spring, e, "battle already started"); return(false); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (!spring.IsRunning) { question = "Force start game?"; winCount = tas.MyBattle.Users.Values.Count(x => !x.IsSpectator) / 2 + 1; return(true); } else { AutoHost.Respond(tas, spring, e, "battle already started"); return(false); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { AutoHost.Respond(tas, spring, e, "Cannot attack a different planet while the game is running"); return(false); } else { if (words.Length > 0) { // FIXME get list of valid planets //string[] vals; //int[] indexes; //ah.FilterMaps(words, out vals, out indexes); if (true) //(vals.Length > 0) { try { planetID = System.Convert.ToInt32(words[0]); question = string.Format("Attack planet {0} {2}/Planetwars/Planet/{1} ?", planetID, planetID, GlobalConst.BaseSiteUrl); // FIXME get planet name return(true); } catch (System.FormatException ex) { AutoHost.Respond(tas, spring, e, "Invalid planet ID"); return(false); } } else { AutoHost.Respond(tas, spring, e, "Invalid planet for attack"); return(false); } } else { AutoHost.Respond(tas, spring, e, "Please specify a planet"); // FIXME list possible planets return(false); } } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (words.Length == 0) { if (ah.BossName == "") { ah.Respond(e, "there is currently no boss to remove"); return(false); } else { player = ""; question = "Remove current boss " + ah.BossName + "?"; return(true); } } string[] players; int[] indexes; if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0) { player = players[0]; if (player == tas.UserName) { ah.Respond(e, "you flatter me, but no"); return(false); } else { question = "Elect " + player + " for the boss?"; return(true); } } else { AutoHost.Respond(tas, spring, e, "Cannot find such player"); return(false); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { if (spring.IsRunning) { context = spring.StartContext; voteStarter = context.Players.FirstOrDefault(x => x.Name == e.UserName && !x.IsSpectator); if (voteStarter != null) { question = string.Format("Resign team {0}?", voteStarter.AllyID + 1); int cnt = 0, total = 0; foreach (var p in context.Players.Where(x => x.AllyID == voteStarter.AllyID && !x.IsSpectator)) { total++; if (p.IsIngame || tas.MyBattle.Users.ContainsKey(p.Name)) { //Note: "ExistingUsers" is empty if users disconnected from lobby but still ingame. bool afk = tas.ExistingUsers.ContainsKey(p.Name) && tas.ExistingUsers[p.Name].IsAway; if (!afk) { cnt++; } } } winCount = (cnt * 3 / 5) + 1; if (total > 1 && winCount == 1) { winCount = 2; // prevents most pathological cases (like a falsely AFK partner in 2v2) } return(true); } } AutoHost.Respond(tas, spring, e, "You cannot resign now"); question = null; winCount = 0; return(false); }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { question = null; winCount = 0; if (words.Length == 0) { ah.Respond(e, "You must specify player name"); return(false); } string[] players; int[] indexes; if (AutoHost.FilterUsers(new[] { words[0] }, tas, spring, out players, out indexes) > 0) { player = players[0]; if (player == tas.UserName) { ah.Respond(e, "won't kick myself, not in suicidal mood today"); return(false); } else { string reason = (words.Length > 1 && words[1] != "for") ? " for" : ""; for (var i = 1; i < words.Length; i++) { reason += " " + words[i]; } question = "Kick " + player + reason + "?"; return(true); } } else { AutoHost.Respond(tas, spring, e, "Cannot find such player"); return(false); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { AutoHost.Respond(tas, spring, e, "Cannot set options while the game is running"); return(false); } else { var wordFormat = Utils.Glue(words); scriptTagsFormat = ah.GetOptionsString(e, words); if (scriptTagsFormat == "") { return(false); } else { question = "Set option " + wordFormat + "?"; return(true); } } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (words.Length == 0) { AutoHost.Respond(tas, spring, e, "You must specify player name"); return(false); } string[] players; int[] indexes; if (AutoHost.FilterUsers(words, tas, spring, out players, out indexes) > 0) { player = players[0]; question = "Spectate " + player + "?"; return(true); } else { AutoHost.Respond(tas, spring, e, "Cannot find such player"); return(false); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { AutoHost.Respond(tas, spring, e, "Cannot change map while the game is running"); return(false); } else { string[] vals; int[] indexes; if (words.Length > 0) { ah.FilterMaps(words, out vals, out indexes); if (vals.Length > 0) { map = vals[0]; var resource = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map); question = string.Format("Change map to {0} {2}/Maps/Detail/{1} ?", map, resource[0].ResourceID, GlobalConst.BaseSiteUrl); return(true); } else { AutoHost.Respond(tas, spring, e, "Cannot find such map"); return(false); } } else { try { if (tas.MyBattle != null && !spring.IsRunning) { var serv = GlobalConst.GetSpringieService(); Task.Factory.StartNew(() => { RecommendedMapResult foundMap; try { foundMap = serv.GetRecommendedMap(tas.MyBattle.GetContext(), true); } catch (Exception ex) { Trace.TraceError(ex.ToString()); return; } if (foundMap != null && foundMap.MapName != null && tas.MyBattle != null) { if (tas.MyBattle.MapName != foundMap.MapName) { map = foundMap.MapName; } } }); // I have no idea why it can't just work like the above way var resourceList = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map); var resource = resourceList.Find(x => x.InternalName == map); question = string.Format("Change map to {0} {2}/Maps/Detail/{1} ?", map, resource.ResourceID, GlobalConst.BaseSiteUrl); return(true); } } catch (System.Exception ex) { AutoHost.Respond(tas, spring, e, ex.ToString()); //System.Diagnostics.Trace.TraceError(ex.ToString()); } return(false); } } }
public void ComListPlanets(TasSayEventArgs e, string[] words) { string[] vals; int[] indexes; try { if (FilterPlanets(words, out vals, out indexes) > 0) { autoHost.Respond(e, string.Format("{0} can attack:", server.GetOffensiveFaction(account).Name)); for (int i = 0; i < vals.Length; ++i) { autoHost.Respond(e, string.Format("{0}: {1}", indexes[i], vals[i])); } } else { autoHost.Respond(e, "no such planet found"); } } catch (Exception ex) { autoHost.Respond(e, string.Format("Error getting planets: {0}", ex)); } }
protected override bool PerformInit(TasSayEventArgs e, string[] words, out string question, out int winCount) { winCount = 0; question = null; if (spring.IsRunning) { AutoHost.Respond(tas, spring, e, "Cannot change map while the game is running"); return(false); } else { string[] vals; int[] indexes; if (words.Length > 0) { ah.FilterMaps(words, out vals, out indexes); if (vals.Length > 0) { map = vals[0]; var resource = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map); question = string.Format("Change map to {0} http://zero-k.info/Maps/Detail/{1} ?", map, resource[0].ResourceID); return(true); } else { AutoHost.Respond(tas, spring, e, "Cannot find such map"); return(false); } } else { try { if (tas.MyBattle != null && !spring.IsRunning) { var serv = new PlasmaShared.SpringieInterfaceReference.SpringieService(); serv.Timeout = 15000; serv.GetRecommendedMapCompleted += (sender, args) => { if (!args.Cancelled && args.Error == null) { var foundMap = args.Result; if (foundMap != null && foundMap.MapName != null && tas.MyBattle != null) { if (tas.MyBattle.MapName != foundMap.MapName) { map = foundMap.MapName; } } } }; serv.GetRecommendedMapAsync(tas.MyBattle.GetContext(), true); // I have no idea why it can't just work like the above way ResourceData[] resourceArray = ah.cache.FindResourceData(new string[] { map }, ResourceType.Map); System.Collections.Generic.List <ResourceData> resourceList = new System.Collections.Generic.List <ResourceData>(resourceArray); var resource = resourceList.Find(x => x.InternalName == map); question = string.Format("Change map to {0} http://zero-k.info/Maps/Detail/{1} ?", map, resource.ResourceID); return(true); } } catch (System.Exception ex) { AutoHost.Respond(tas, spring, e, ex.ToString()); //System.Diagnostics.Trace.TraceError(ex.ToString()); } return(false); } } }
protected void Respond(TasSayEventArgs eventArgs, string text, params object[] args) { AutoHost.Respond(handler.TasClient, handler.Spring, eventArgs, string.Format(text, args)); }