コード例 #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);
        }