Ejemplo n.º 1
0
        public void HangarList()
        {
            if (!AlliancePlugin.config.HangarEnabled)
            {
                Context.Respond("Hangar not enabled.");
                return;
            }
            if (Context.Player != null)
            {
                //Do stuff with taking components from grid storage
                //GridCosts localGridCosts = GetComponentsAndCost(projectedGrid);
                //gridCosts.setComponents(localGridCosts.getComponents());
                IMyFaction faction = FacUtils.GetPlayersFaction(Context.Player.IdentityId);
                if (faction == null)
                {
                    Context.Respond("Must be in a faction to use alliance features.");
                    return;
                }
                Alliance alliance = AlliancePlugin.GetAlliance(faction as MyFaction);
                if (alliance == null)
                {
                    Context.Respond("You are not a member of an alliance with an unlocked hangar.");
                    return;
                }
                if (AlliancePlugin.HasFailedUpkeep(alliance))
                {
                    Context.Respond("Alliance failed to pay upkeep. Upgrades disabled.");
                    return;
                }
                if (alliance.hasUnlockedHangar)
                {
                    HangarData hangar = alliance.LoadHangar();
                    if (hangar == null)
                    {
                        Context.Respond("Error loading the hangar.");

                        return;
                    }
                    Context.Respond("Hangar Slots available : " + hangar.SlotsAmount, Color.LightBlue, "Alliance Hangar");
                    for (int i = 1; i <= hangar.SlotsAmount; i++)
                    {
                        if (hangar.ItemsInHangar.ContainsKey(i))
                        {
                            hangar.ItemsInHangar.TryGetValue(i, out HangarItem slot);

                            Context.Respond(slot.name.Split('_')[0] + " : " + AlliancePlugin.GetPlayerName(slot.steamid), Color.LightBlue, "[ " + i + " ]");
                        }
                        else
                        {
                            Context.Respond("", Color.Green, "[ Available ]");
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public void BankLog(string timeformat = "MM-dd-yyyy")
 {
     if (Context.Player != null)
     {
         //Do stuff with taking components from grid storage
         //GridCosts localGridCosts = GetComponentsAndCost(projectedGrid);
         //gridCosts.setComponents(localGridCosts.getComponents());
         IMyFaction faction = FacUtils.GetPlayersFaction(Context.Player.IdentityId);
         if (faction == null)
         {
             Context.Respond("You must be in a faction to use alliance features.");
             return;
         }
         Alliance alliance = AlliancePlugin.GetAlliance(faction as MyFaction);
         if (alliance == null)
         {
             Context.Respond("You are not a member of an alliance with an unlocked shipyard.");
             return;
         }
         if (AlliancePlugin.HasFailedUpkeep(alliance))
         {
             Context.Respond("Alliance failed to pay upkeep. Upgrades disabled.");
             return;
         }
         if (alliance.hasUnlockedHangar)
         {
             HangarData    data = alliance.LoadHangar();
             HangarLog     log  = data.GetHangarLog(alliance);
             StringBuilder sb   = new StringBuilder();
             log.log.Reverse();
             foreach (HangarLogItem item in log.log)
             {
                 sb.AppendLine(item.time.ToString(timeformat) + " : " + AlliancePlugin.GetPlayerName(item.steamid) + " " + item.action + " " + item.GridName.Split('_')[0]);
                 continue;
             }
             DialogMessage m = new DialogMessage("Alliance Hangar Records", alliance.name, sb.ToString());
             ModCommunication.SendMessageTo(m, Context.Player.SteamUserId);
         }
         else
         {
             Context.Respond("Alliance has not unlocked hangar.");
         }
     }
 }
Ejemplo n.º 3
0
        public string OutputMembers()
        {
            StringBuilder sb = new StringBuilder();

            foreach (long id in AllianceMembers)
            {
                IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id);
                if (fac != null)
                {
                    sb.AppendLine(fac.Tag);
                    foreach (KeyValuePair <long, MyFactionMember> member in fac.Members)
                    {
                        sb.AppendLine(AlliancePlugin.GetPlayerName(MySession.Static.Players.TryGetSteamId(member.Value.PlayerId)));
                    }
                    sb.AppendLine("");
                }
            }
            return(sb.ToString());
        }
Ejemplo n.º 4
0
        public void ViewItemInfo(int number)
        {
            if (!list.items.ContainsKey(number))
            {
                Context.Respond("There is no item in the market for that slot number.");
                return;
            }
            StringBuilder sb   = new StringBuilder();
            MarketItem    item = list.items[number];

            sb.AppendLine("Seller Name: " + AlliancePlugin.GetPlayerName(item.SellerSteamId));
            sb.AppendLine("Current ID: " + number);
            sb.AppendLine("Name: " + item.Name);
            sb.AppendLine("Price: " + String.Format("{0:n0}", item.Price) + " SC.");
            sb.AppendLine("PCU" + item.PCU);
            sb.AppendLine("Grid Weight:" + String.Format("{0:n0}", item.GridMass));
            sb.AppendLine("Description: " + item.Description);
            sb.AppendLine("");
            sb.AppendLine("Blocks on grid");
            foreach (KeyValuePair <string, Dictionary <string, int> > keys in item.CountsOfBlocks)
            {
                sb.AppendLine(keys.Key.Replace("MyObjectBuilder_", ""));
                foreach (KeyValuePair <string, int> blocks in keys.Value)
                {
                    sb.AppendLine(blocks.Key.Replace("MyObjectBuilder_", "") + " " + blocks.Value);
                }
            }
            sb.AppendLine("");
            sb.AppendLine("Cargo Items");
            foreach (KeyValuePair <string, MyFixedPoint> keys in item.Cargo)
            {
                sb.AppendLine(keys.Key.ToString().Replace("MyObjectBuilder_", "") + " " + keys.Value);
            }
            DialogMessage m = new DialogMessage("The Market", "", sb.ToString());

            ModCommunication.SendMessageTo(m, Context.Player.SteamUserId);
        }
Ejemplo n.º 5
0
        public void BuyGrid(int number)
        {
            if (!list.items.ContainsKey(number))
            {
                Context.Respond("There is no item in the market for that slot number.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            MarketItem item = list.items[number];

            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json"))
            {
                Context.Respond("That grid is no longer available for sale.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            if (!File.Exists(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"))
            {
                Context.Respond("This grid should be available, but its file for the grid doesnt exist.");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }
            if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition()))
            {
                Context.Respond("You cannot use this command in natural gravity!");
                confirmations.Remove(Context.Player.IdentityId);
                return;
            }

            foreach (DeniedLocation denied in AlliancePlugin.HangarDeniedLocations)
            {
                if (Vector3.Distance(Context.Player.GetPosition(), new Vector3(denied.x, denied.y, denied.z)) <= denied.radius)
                {
                    Context.Respond("Cannot buy here, too close to a denied location.");
                    confirmations.Remove(Context.Player.IdentityId);
                    return;
                }
            }
            if (EconUtils.getBalance(Context.Player.IdentityId) >= item.Price)
            {
                if (confirmations.ContainsKey(Context.Player.IdentityId))
                {
                    if (confirmations[Context.Player.IdentityId] >= DateTime.Now)
                    {
                        if (GridManager.LoadGrid(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml", Context.Player.GetPosition(), false, Context.Player.SteamUserId, item.Name))
                        {
                            EconUtils.takeMoney(Context.Player.IdentityId, item.Price);
                            long sellerId = MySession.Static.Players.TryGetIdentityId(item.SellerSteamId);
                            EconUtils.addMoney(sellerId, item.Price);
                            if (AlliancePlugin.GridBackupInstalled)
                            {
                                AlliancePlugin.BackupGridMethod(GridManager.GetObjectBuilders(AlliancePlugin.path + "//ShipMarket//Grids//" + item.ItemId + ".xml"), Context.Player.IdentityId);
                            }
                            item.Buyer  = Context.Player.SteamUserId;
                            item.soldAt = DateTime.Now;
                            item.Status = ItemStatus.Sold;
                            Context.Respond("The grid should appear near you.");
                            confirmations.Remove(Context.Player.IdentityId);
                            if (!Directory.Exists(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId))
                            {
                                Directory.CreateDirectory(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId);
                            }
                            list.items.Remove(number);

                            File.Delete(AlliancePlugin.path + "//ShipMarket//ForSale//" + item.ItemId + ".json");
                            utils.WriteToJsonFile <MarketItem>(AlliancePlugin.path + "//ShipMarket//Sold//" + item.SellerSteamId + "//" + item.ItemId, item);
                        }
                        else
                        {
                            Context.Respond("Failed to load the grid! transaction cancelled.");
                            return;
                        }
                    }
                    else
                    {
                        Context.Respond("Time ran out, start again");
                        confirmations[Context.Player.IdentityId] = DateTime.Now.AddSeconds(20);
                    }
                }
                else
                {
                    Context.Respond("Run command again within 20 seconds to confirm. Target grid name is " + item.Name + " Sold by " + AlliancePlugin.GetPlayerName(item.SellerSteamId));
                    confirmations.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(20));
                    Context.Respond("It costs " + String.Format("{0:n0}", item.Price) + " SC.");
                }
            }
            else
            {
                Context.Respond("You cannot afford that. It costs " + String.Format("{0:n0}", item.Price) + " SC.");
            }
        }
Ejemplo n.º 6
0
        public void ViewMarket()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("To view information on a listing use !market info number");
            sb.AppendLine("To search the market use !market search input.");
            sb.AppendLine("To purchase a grid from the market use !market buy number");
            sb.AppendLine("");
            foreach (KeyValuePair <int, MarketItem> items in list.items)
            {
                sb.AppendLine("[" + items.Key + "] " + items.Value.Name + ", Seller " + AlliancePlugin.GetPlayerName(items.Value.SellerSteamId));
            }
            DialogMessage m = new DialogMessage("The Market", "", sb.ToString());

            ModCommunication.SendMessageTo(m, Context.Player.SteamUserId);
        }
Ejemplo n.º 7
0
        public string OutputAlliance()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(description);
            sb.AppendLine("");
            bankBalance = DatabaseForBank.GetBalance(AllianceId);
            sb.AppendLine("Bank Balance : " + String.Format("{0:n0}", bankBalance) + " SC.");
            if (failedUpkeep > 0)
            {
                sb.AppendLine("Failed Upkeep : " + this.failedUpkeep + " Deleted at " + AlliancePlugin.config.UpkeepFailBeforeDelete);
            }


            sb.AppendLine("Expected Upkeep Value :" + String.Format("{0:n0}", this.GetUpkeep()) + " SC.");
            sb.AppendLine("");
            sb.AppendLine("Meta Points : " + String.Format("{0:n0}", CurrentMetaPoints));
            sb.AppendLine("");
            sb.AppendLine(LeaderTitle);

            sb.AppendLine(AlliancePlugin.GetPlayerName(SupremeLeader));

            StringBuilder perms = new StringBuilder();

            foreach (KeyValuePair <String, RankPermissions> customs in CustomRankPermissions)
            {
                perms.Clear();
                foreach (AccessLevel level in customs.Value.permissions)
                {
                    perms.Append(level.ToString() + ", ");
                }
                sb.AppendLine("");
                sb.AppendLine(customs.Key + " Permissions : " + perms.ToString());
                sb.AppendLine(customs.Key + " tax rate : " + CustomRankPermissions[customs.Key].taxRate * 100 + "%");
            }

            sb.AppendLine("");
            perms.Clear();
            foreach (AccessLevel level in UnrankedPerms.permissions)
            {
                perms.Append(level.ToString() + ", ");
            }
            sb.AppendLine("Unranked Permissions : " + perms.ToString());
            sb.AppendLine("Unranked tax rate : " + UnrankedPerms.taxRate * 100 + "%");
            sb.AppendLine("");
            otherTitlesDic.Clear();
            foreach (KeyValuePair <ulong, String> titles in PlayersCustomRank)
            {
                if (otherTitlesDic.ContainsKey(titles.Value))
                {
                    otherTitlesDic[titles.Value].AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key));
                }
                else
                {
                    StringBuilder sbb = new StringBuilder();
                    sbb.AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key));
                    otherTitlesDic.Add(titles.Value, sbb);
                }
            }
            foreach (KeyValuePair <String, StringBuilder> key in otherTitlesDic)
            {
                sb.AppendLine(key.Value.ToString());
            }
            otherTitlesDic.Clear();
            foreach (KeyValuePair <ulong, String> titles in otherTitles)
            {
                if (otherTitlesDic.ContainsKey(titles.Value))
                {
                    otherTitlesDic[titles.Value].AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key));
                }
                else
                {
                    StringBuilder sbb = new StringBuilder();
                    sbb.AppendLine(titles.Value + " " + AlliancePlugin.GetPlayerName(titles.Key));
                    otherTitlesDic.Add(titles.Value, sbb);
                }
            }
            foreach (KeyValuePair <String, StringBuilder> key in otherTitlesDic)
            {
                sb.AppendLine(key.Value.ToString());
            }
            sb.AppendLine("");
            sb.AppendLine("Hostile Factions and Hostile Alliances");
            foreach (long id in EnemyFactions)
            {
                IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id);
                if (fac != null)
                {
                    sb.AppendLine(fac.Tag);
                }
                foreach (String s in enemies)
                {
                    sb.AppendLine(s);
                }
            }
            sb.AppendLine("");
            sb.AppendLine("Member Factions");
            int memberCount = 0;

            foreach (long id in AllianceMembers)
            {
                IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id);
                if (fac != null)
                {
                    sb.AppendLine(fac.Tag + " - " + fac.Members.Count + " members");
                    memberCount += fac.Members.Count;
                }
            }
            sb.AppendLine("Total Members " + memberCount);
            sb.AppendLine("");
            sb.AppendLine("Pending invites");
            foreach (long id in Invites)
            {
                IMyFaction fac = MySession.Static.Factions.TryGetFactionById(id);
                if (fac != null)
                {
                    sb.AppendLine(fac.Name + " - " + fac.Tag);
                }
            }

            return(sb.ToString());
        }