예제 #1
0
        public void ComPlanet(TasSayEventArgs e, string[] words)
        {
            if (words.Length == 0)
            {
                autoHost.Respond(e, "You must specify planet name");
                return;
            }
            string[] vals;
            int[]    indexes;
            if (FilterPlanets(words, out vals, out indexes) > 0)
            {
                var    info       = server.GetPlayerInfo(account, e.UserName);
                var    fact       = server.GetOffensiveFaction(account);
                bool   canset     = false;
                string bestPlayer = "";
                if (info != null)
                {
                    if (info.IsCommanderInChief)
                    {
                        canset = true;
                    }
                    else
                    {
                        canset = true;
                        int bestRank = info.RankOrder;
                        foreach (var u in tas.GetBattle().Users)
                        {
                            if (!u.IsSpectator && u.name != e.UserName && tas.GetBattle().Mod.Sides[u.Side].ToLower() == info.FactionName.ToLower())
                            {
                                var pi = server.GetPlayerInfo(account, u.name);
                                if (pi != null && pi.RankOrder < bestRank)
                                {
                                    // someone sle with better rank exists
                                    bestPlayer = pi.Name;
                                    bestRank   = pi.RankOrder;
                                    canset     = false;
                                }
                            }
                        }
                    }
                }

                if (canset)
                {
                    if (info.FactionName == fact.Name)
                    {
                        string pname = vals[0].Split('|')[0];
                        autoHost.SayBattle(string.Format("changing planet to {0} by {1}", pname, e.UserName));
                        var planet = server.GetAttackOptions(account).Where(m => m.Name == pname).Single();
                        tas.ChangeMap(Program.main.Spring.UnitSyncWrapper.MapList[planet.MapName]);
                    }
                    else
                    {
                        autoHost.Respond(e, string.Format("It's currently {0} turn", fact.Name));
                    }
                }
                else
                {
                    autoHost.Respond(e, string.Format("You are not first in command here, {0} must do it!", bestPlayer));
                }
            }
            else
            {
                autoHost.Respond(e, "Cannot find such planet.");
            }
        }