예제 #1
0
        public Boolean SaveGridToHangar(String gridName, ulong steamid, Alliance alliance, Vector3D position, MyFaction faction, List <MyCubeGrid> gridsToSave, long IdentityId)
        {
            if (!CheckGrids(position, IdentityId))
            {
                AlliancePlugin.Log.Info("Failed grid check");
                return(false);
            }

            if (!CheckCharacters(position, IdentityId))
            {
                AlliancePlugin.Log.Info("Failed character check");
                return(false);
            }
            HangarLog     log  = GetHangarLog(alliance);
            HangarLogItem item = new HangarLogItem();

            item.action   = "Saved";
            item.steamid  = steamid;
            item.GridName = gridName;
            item.time     = DateTime.Now;
            log.log.Add(item);
            utils.WriteToJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json", log);
            HangarItem hangItem = new HangarItem();

            hangItem.name     = gridName;
            hangItem.steamid  = steamid;
            hangItem.position = position;
            ItemsInHangar.Add(getAvailableSlot(), hangItem);
            GridManager.SaveGridNoDelete(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + gridName + ".xml"), gridName, true, false, gridsToSave);
            if (AlliancePlugin.GridBackupInstalled)
            {
                List <MyObjectBuilder_CubeGrid> obBuilders = new List <MyObjectBuilder_CubeGrid>();
                foreach (MyCubeGrid grid in gridsToSave)
                {
                    obBuilders.Add(grid.GetObjectBuilder() as MyObjectBuilder_CubeGrid);
                }
                AlliancePlugin.BackupGridMethod(obBuilders, IdentityId);
            }
            utils.WriteToJsonFile <HangarData>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//hangar.json", this);
            return(true);
        }
예제 #2
0
        public Boolean LoadGridFromHangar(int slotNum, ulong steamid, Alliance alliance, MyIdentity identity, MyFaction faction)
        {
            HangarItem hangItem = ItemsInHangar[slotNum];

            if (!CheckGrids(hangItem.position, identity.IdentityId))
            {
                return(false);
            }

            if (!CheckCharacters(hangItem.position, identity.IdentityId))
            {
                return(false);
            }

            if (!GridManager.LoadGrid(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"), ItemsInHangar[slotNum].position, true, steamid, ItemsInHangar[slotNum].name))
            {
                if (!GridManager.LoadGrid(System.IO.Path.Combine(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml"), ItemsInHangar[slotNum].position, false, steamid, ItemsInHangar[slotNum].name))
                {
                    return(false);
                }
            }

            HangarLog     log  = GetHangarLog(alliance);
            HangarLogItem item = new HangarLogItem();

            item.action   = "Loaded";
            item.steamid  = steamid;
            item.GridName = ItemsInHangar[slotNum].name;
            item.time     = DateTime.Now;
            log.log.Add(item);
            utils.WriteToJsonFile <HangarLog>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//log.json", log);


            if (AlliancePlugin.GridBackupInstalled)
            {
                List <MyObjectBuilder_CubeGrid> obBuilders = new List <MyObjectBuilder_CubeGrid>();
                obBuilders = GridManager.GetObjectBuilders(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml");
                if (obBuilders != null)
                {
                    AlliancePlugin.BackupGridMethod(obBuilders, identity.IdentityId);
                }
                else
                {
                    AlliancePlugin.Log.Error("Error saving a backup when loading this grid");
                }
            }

            File.Delete(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//" + ItemsInHangar[slotNum].name + ".xml");
            ItemsInHangar.Remove(slotNum);
            List <HangarItem> temp = new List <HangarItem>();

            foreach (HangarItem hangitem in ItemsInHangar.Values)
            {
                temp.Add(hangitem);
            }
            ItemsInHangar.Clear();
            int i = 1;

            foreach (HangarItem hangitem in temp)
            {
                ItemsInHangar.Add(i, hangitem);
                i++;
            }
            utils.WriteToJsonFile <HangarData>(AlliancePlugin.path + "//HangarData//" + alliance.AllianceId + "//hangar.json", this);

            return(true);
        }
예제 #3
0
        public void LoadFromHangar(string slotNumber)
        {
            if (!AlliancePlugin.config.HangarEnabled)
            {
                Context.Respond("Alliance hangar is not enabled.");
                return;
            }
            if (cooldowns.TryGetValue(Context.Player.IdentityId, out DateTime value))
            {
                if (DateTime.Now <= value)
                {
                    Context.Respond(GetCooldownMessage(value));
                    return;
                }
                else
                {
                    cooldowns[Context.Player.IdentityId] = DateTime.Now.AddSeconds(60);
                }
            }
            else
            {
                cooldowns.Add(Context.Player.IdentityId, DateTime.Now.AddSeconds(60));
            }
            MyFaction fac = MySession.Static.Factions.GetPlayerFaction(Context.Player.IdentityId);

            if (fac == null)
            {
                Context.Respond("You must be in a faction to use alliance features.");
                return;
            }
            Alliance alliance = AlliancePlugin.GetAlliance(fac);

            if (alliance == null)
            {
                Context.Respond("You are not a member of an alliance.");
                return;
            }
            if (AlliancePlugin.HasFailedUpkeep(alliance))
            {
                Context.Respond("Alliance failed to pay upkeep. Upgrades disabled.");
                return;
            }
            if (!alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.HangarLoad) && !alliance.HasAccess(Context.Player.SteamUserId, AccessLevel.HangarLoadOther))
            {
                Context.Respond("Current rank does not have access to hangar load.");
                return;
            }
            if (alliance.hasUnlockedHangar)
            {
                HangarData hangar = alliance.LoadHangar();
                if (hangar == null)
                {
                    Context.Respond("Error loading the hangar.");
                    return;
                }
                int slot;
                try
                {
                    slot = int.Parse(slotNumber);
                }
                catch (Exception)
                {
                    Context.Respond("Cannot parse that number.");
                    return;
                }
                if (!hangar.ItemsInHangar.ContainsKey(slot))
                {
                    Context.Respond("No grid available to load for that number!");
                    return;
                }
                HangarItem item = hangar.ItemsInHangar[slot];

                //this took up way too much of one line

                if (hangar.LoadGridFromHangar(slot, Context.Player.SteamUserId, alliance, Context.Player.Identity as MyIdentity, fac))
                {
                    Context.Respond("Grid should be loaded!");
                }
                else
                {
                    Context.Respond("Could not load, are there enemies within 15km?");
                    MyGps gps = new MyGps
                    {
                        Coords         = item.position,
                        Name           = item.name + " Failed load location",
                        DisplayName    = item.name + " Failed load location",
                        Description    = "Failed load location",
                        GPSColor       = Color.LightBlue,
                        IsContainerGPS = true,
                        ShowOnHud      = true,
                        DiscardAt      = new TimeSpan(50000)
                    };
                    gps.UpdateHash();
                    MyGpsCollection gpscol = (MyGpsCollection)MyAPIGateway.Session?.GPS;


                    gpscol.SendAddGps(Context.Player.IdentityId, ref gps);
                }
            }
            else
            {
                Context.Respond("Alliance has not unlocked the hangar to unlock use !ah unlock.");
            }
        }