public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsWorking) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; //if (!inventory.ContainItems(amount, new MyObjectBuilder_PhysicalGunObject { SubtypeName = "AutomaticRifleItem" })) //{ // inventory.AddItems(amount, new MyObjectBuilder_PhysicalGunObject { SubtypeName = "AutomaticRifleItem" }); // terminalBlock.RefreshCustomInfo(); //} //if (!inventory.ContainItems(amount, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_5p56x45mm" })) //{ // inventory.AddItems(10, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_5p56x45mm" }); // terminalBlock.RefreshCustomInfo(); //} //if (!inventory.ContainItems(10000, new MyObjectBuilder_Ore { SubtypeName = "Iron" })) //{ // inventory.AddItems(amount, new MyObjectBuilder_Ore { SubtypeName = "Iron" }); // terminalBlock.RefreshCustomInfo(); //} float cur = (float)inventory.CurrentVolume; float max = (float)inventory.MaxVolume; if (cur / max < 0.9 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply" }); BlackShop.AddSupply(inventory); terminalBlock.RefreshCustomInfo(); } if (cur / max < 0.9 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply2" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "Supply2" }); BlackShop.AddSupply(inventory, true); terminalBlock.RefreshCustomInfo(); } } }
/// <summary> /// Finds the best available tool. /// Returns true if the id was changed. /// </summary> private bool MakeBest(ref MyDefinitionId id, int index) { if (MyAPIGateway.Session.CreativeMode) { if (index == EquipIndex) { return(false); } id = Ids[EquipIndex]; return(true); } IMyInventory inv = p.Character.GetInventory(); MyFixedPoint one = 1; for (int i = Ids.Length - 1; i > index; i--) { if (inv.ContainItems(one, Ids[i])) { id = Ids[i]; return(true); } } return(false); }
/// <summary> /// Finds the next higher level tool. /// Returns true if the id was changed. /// </summary> private bool Upgrade(ref MyDefinitionId id, int index) { if (MyAPIGateway.Session.CreativeMode) { if (index == Ids.Length - 1) { return(false); } EquipIndex = index + 1; id = Ids[EquipIndex]; return(true); } IMyInventory inv = p.Character.GetInventory(); MyFixedPoint one = 1; for (int i = index + 1; i < Ids.Length; i++) { if (inv.ContainItems(one, Ids[i])) { id = Ids[i]; return(true); } } return(false); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsWorking) { Frame = frameShift++; if (Frame % 30 != 0) { return; } List <IMyPlayer> players = new List <IMyPlayer>(); MyAPIGateway.Players.GetPlayers(players, x => x.Character != null && !x.IsBot); int count = players.Count; IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(0) as IMyInventory; if (!inventory.ContainItems(Core.Settings.ResourceMax, new MyObjectBuilder_Ingot { SubtypeName = "Coin" })) { inventory.AddItems(Core.Settings.ResourcePerMinute + count * Core.Settings.ResourceIncreasePerPlayerMinute, new MyObjectBuilder_Ingot { SubtypeName = "Coin" }); terminalBlock.RefreshCustomInfo(); } //IMyInventory inventory1 = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; //if (!inventory1.ContainItems(10, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_25x184mm" })) //{ // inventory1.AddItems(1, new MyObjectBuilder_AmmoMagazine { SubtypeName = "NATO_25x184mm" }); // terminalBlock.RefreshCustomInfo(); //} //List<IMyPlayer> players = new List<IMyPlayer>(); //MyAPIGateway.Players.GetPlayers(players, x => x.Controller != null && x.Controller.ControlledEntity != null); //foreach (IMyPlayer player in players) //{ // if (player.Controller.ControlledEntity is IMyCharacter) // { // MyEntity entity = player.Controller.ControlledEntity.Entity as MyEntity; // if (entity.HasInventory) // { // inventory = entity.GetInventoryBase() as MyInventory; // if (!inventory.ContainItems(10000, new MyObjectBuilder_Ingot { SubtypeName = "Coin" })) // { // inventory.AddItems(5, new MyObjectBuilder_Ingot { SubtypeName = "Coin" }); // terminalBlock.RefreshCustomInfo(); // } // } // } //} } }
public static VRage.MyFixedPoint RemoveMaxItems(this IMyInventory srcInventory, VRage.MyFixedPoint maxRemoveFP, MyObjectBuilder_PhysicalObject objectBuilder) { var contentId = objectBuilder.GetObjectId(); VRage.MyFixedPoint removedAmount = 0; if (!srcInventory.ContainItems(maxRemoveFP, objectBuilder)) { maxRemoveFP = srcInventory.GetItemAmount(contentId); } if (maxRemoveFP > 0) { srcInventory.RemoveItemsOfType(maxRemoveFP, contentId, MyItemFlags.None, false); removedAmount = maxRemoveFP; } return(maxRemoveFP); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsFunctional) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; if (!inventory.ContainItems(10000, new MyObjectBuilder_Ore { SubtypeName = "Iron" })) { inventory.AddItems(5, new MyObjectBuilder_Ore { SubtypeName = "Iron" }); terminalBlock.RefreshCustomInfo(); } } }
/// <summary> /// Finds the best available id. /// Returns true if an id was found. /// </summary> /// <param name="itemRemoved">The item to ignore when checking inventory.</param> private bool GetBestId(out MyDefinitionId id, MyDefinitionId?itemRemoved = null) { if (MyAPIGateway.Session.CreativeMode) { id = Ids[EquipIndex]; return(true); } IMyInventory inv = p.Character.GetInventory(); MyFixedPoint one = 1; for (int i = Ids.Length - 1; i >= 0; i--) { MyDefinitionId temp = Ids[i]; if ((!itemRemoved.HasValue || itemRemoved.Value != temp) && inv.ContainItems(one, temp)) { id = temp; return(true); } } id = new MyDefinitionId(); return(false); }
public override void UpdateBeforeSimulation100() { base.UpdateBeforeSimulation100(); if (m_generator.IsFunctional) { IMyInventory inventory = ((Sandbox.ModAPI.IMyTerminalBlock)Entity).GetInventory(1) as IMyInventory; VRage.MyFixedPoint amount = 1; float cur = (float)inventory.CurrentVolume; float max = (float)inventory.MaxVolume; if (cur / max < 0.8 && inventory.ContainItems(1, new MyObjectBuilder_Ingot { SubtypeName = "RandomItem" })) { inventory.RemoveItemsOfType(1, new MyObjectBuilder_Ingot { SubtypeName = "RandomItem" }); RandomShop.AddRandomItem(inventory); terminalBlock.RefreshCustomInfo(); } } }
// // == SessionComponent Hooks // public override void UpdateBeforeSimulation() { try { if (MyAPIGateway.Session == null || MyAPIGateway.Utilities == null || MyAPIGateway.Multiplayer == null) // exit if api is not ready { return; } if (!Inited) // init and set handlers { Init(); } if (Settings == null) // request or load setting { GetSettings(); // if server, settings will be set a this call, so it safe } if (!IsServer) // if client exit at this point. Cleaning works only on server side. { return; } if (Codes == null) { GetCodes(); } Frame = frameShift++; if (Frame % 3600 != 0) { return; } List <IMyPlayer> players = new List <IMyPlayer>(); //MyAPIGateway.Players.GetPlayers(players, x => x.Controller != null && x.Controller.ControlledEntity != null); MyAPIGateway.Players.GetPlayers(players, x => x.Character != null && !x.IsBot); foreach (IMyPlayer player in players) { if (player.Character is IMyCharacter) { MyEntity entity = player.Character.Entity as MyEntity; if (entity.HasInventory) { IMyInventory inventory = entity.GetInventoryBase() as MyInventory; if (!inventory.ContainItems(Settings.SalaryMax, new MyObjectBuilder_Ingot { SubtypeName = "Coin" })) { inventory.AddItems(Settings.SalaryPerMinute, new MyObjectBuilder_Ingot { SubtypeName = "Coin" }); //terminalBlock.RefreshCustomInfo(); } } } } } catch (Exception ex) { Logger.Log.Error("EXCEPTION at BeaconSecurity.UpdateBeforeSimulation(): {0} {1}", ex.Message, ex.StackTrace); } }