public void SaveToHangar() { if (!AlliancePlugin.config.HangarEnabled) { Context.Respond("Alliance hangar is not enabled."); return; } if (MySession.Static.IsSaveInProgress) { Context.Respond("World is saving! Try again soon."); 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)); } if (MyGravityProviderSystem.IsPositionInNaturalGravity(Context.Player.GetPosition())) { Context.Respond("You cannot use this command in natural gravity!"); 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 hangar here! Too close to a denied location."); return; } } Boolean console = false; if (Context.Player == null) { console = true; } 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.HangarSave)) { Context.Respond("Current rank does not have access to hangar save."); return; } if (alliance.hasUnlockedHangar) { HangarData hangar = alliance.LoadHangar(); if (hangar == null) { Context.Respond("Error loading the hangar."); return; } string name = ""; int pcu = 0; if (hangar.getAvailableSlot() > 0) { ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> gridWithSubGrids = GridFinder.FindLookAtGridGroup(Context.Player.Character); List <MyCubeGrid> grids = new List <MyCubeGrid>(); foreach (var item in gridWithSubGrids) { foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in item.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Projector != null) { continue; } if (FacUtils.IsOwnerOrFactionOwned(grid, Context.Player.IdentityId, true)) { pcu += grid.BlocksPCU; foreach (MyProjectorBase proj in grid.GetFatBlocks().OfType <MyProjectorBase>()) { proj.Clipboard.Clear(); } grids.Add(grid); if (name == "") { name = grid.DisplayName; name = name.Replace("/", ""); name = name.Replace("-", ""); name = name.Replace("\\", ""); } } else { Context.Respond("The grid you are looking at includes a grid that isnt owned by you or a faction member."); return; } } } if (grids.Count == 0) { Context.Respond("Could not find grid."); return; } if (name == "") { name = "Temporary Name"; } if (pcu >= AlliancePlugin.config.MaxHangarSlotPCU) { Context.Respond("PCU is greater than the configured maximum"); return; } bool result = hangar.SaveGridToHangar(name + "_" + string.Format("{0:yyyy-MM-dd_HH-mm-ss-fff}", DateTime.Now), Context.Player.SteamUserId, alliance, Context.Player.Character.PositionComp.GetPosition(), fac, grids, Context.Player.IdentityId); if (!result) { Context.Respond("Could not save. Are enemies within 15km?"); } else { Context.Respond("Grid saved."); foreach (MyCubeGrid grid in grids) { if (grid != null) { grid.Close(); } } } } else { Context.Respond("Hangar is full, to upgrade use !ah upgrade true."); } } else { Context.Respond("Alliance has not unlocked the hangar to unlock use !ah unlock."); } }
public void UnlockHangar() { if (!AlliancePlugin.config.HangarEnabled) { Context.Respond("Alliance hangar is not enabled."); return; } Boolean console = false; if (Context.Player == null) { console = true; } 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.hasUnlockedHangar) { ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> gridWithSubGrids = GridFinder.FindLookAtGridGroup(Context.Player.Character); List <MyCubeGrid> grids = new List <MyCubeGrid>(); foreach (var item in gridWithSubGrids) { foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in item.Nodes) { MyCubeGrid grid = groupNodes.NodeData; if (grid.Projector != null) { continue; } if (FacUtils.GetPlayersFaction(FacUtils.GetOwner(grid)) != null) { if (FacUtils.InSameFaction(FacUtils.GetOwner(grid), Context.Player.IdentityId)) { if (!grids.Contains(grid)) { grids.Add(grid); } } } else { if (FacUtils.GetOwner(grid).Equals(Context.Player.Identity.IdentityId)) { if (!grids.Contains(grid)) { grids.Add(grid); } } } } } //Do stuff with taking components from grid storage //GridCosts localGridCosts = GetComponentsAndCost(projectedGrid); //gridCosts.setComponents(localGridCosts.getComponents()); UpgradeCost cost = new UpgradeCost(); List <VRage.Game.ModAPI.IMyInventory> invents = new List <VRage.Game.ModAPI.IMyInventory>(); foreach (MyCubeGrid grid in grids) { invents.AddList(ShipyardCommands.GetInventories(grid)); } cost = ShipyardCommands.LoadUnlockCost(AlliancePlugin.path + "//HangarUnlockCost.txt"); if (cost != null) { if (cost.MetaPointCost > 0) { if (alliance.CurrentMetaPoints < cost.MetaPointCost) { Context.Respond("Cannot afford the meta point cost of " + cost.MetaPointCost); return; } } if (cost.MoneyRequired > 0) { if (EconUtils.getBalance(Context.Player.IdentityId) >= cost.MoneyRequired) { if (ShipyardCommands.ConsumeComponents(invents, cost.itemsRequired, Context.Player.SteamUserId)) { alliance.CurrentMetaPoints -= cost.MetaPointCost; EconUtils.takeMoney(Context.Player.IdentityId, cost.MoneyRequired); alliance.hasUnlockedHangar = true; HangarData hangar = alliance.LoadHangar(); AlliancePlugin.SaveAllianceData(alliance); ShipyardCommands.SendMessage("[Alliance Hangar]", "Unlocking the hangar. You were charged: " + String.Format("{0:n0}", cost.MoneyRequired) + " and components taken", Color.Green, (long)Context.Player.SteamUserId); } } else { ShipyardCommands.SendMessage("[Alliance Hangar]", "You cant afford the upgrade price of: " + String.Format("{0:n0}", cost.MoneyRequired), Color.Red, (long)Context.Player.SteamUserId); } } else { if (ShipyardCommands.ConsumeComponents(invents, cost.itemsRequired, Context.Player.SteamUserId)) { alliance.CurrentMetaPoints -= cost.MetaPointCost; alliance.hasUnlockedHangar = true; HangarData hangar = alliance.LoadHangar(); AlliancePlugin.SaveAllianceData(alliance); } } } else { Context.Respond("Error loading upgrade details."); return; } } }