// Closing Event Callbacks private void OnMarkForClose(IMyEntity obj) { var ammo = new MyObjectBuilder_AmmoMagazine() { SubtypeName = "SpotlightTurretAmmoMagazine" }; IMyInventory inv = obj.GameLogic.GetAs <TurretSpotlight>().m_inventory; List <MyInventoryItem> items = new List <MyInventoryItem>(); inv.GetItems(items); MyFixedPoint amount = 0; foreach (var item in items) { amount += item.Amount; } obj.GameLogic.GetAs <TurretSpotlight>().m_inventory.RemoveItemsOfType(amount, ammo); }
public void InitTerminalValues(TurretSetting settings = null) { try { if (!m_init) { CreateTerminalControls(); // load stored terminal data LoadTerminalValues(m_turret, settings); m_turret.ShowInInventory = false; if (PlayerInput.Instance.isServer) { m_inventory = m_turret.GetInventory() as IMyInventory; NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.EACH_100TH_FRAME; PlayerInput.Instance.SaveTerminalValues(m_turret.EntityId); } m_turret.EnabledChanged += OnEnabledChanged; m_turret.IsWorkingChanged += OnIsWorkingChanged; m_turret.PropertiesChanged += OnPropertiesChanged; if (PlayerInput.Instance.isServer) { m_turret.OnMarkForClose += OnMarkForClose; } m_init = true; CheckAndAddLight(); //NeedsUpdate |= MyEntityUpdateEnum.EACH_FRAME; } } catch (Exception e) { // Do nothing Logger.Instance.LogMessage("Init Terminal Values Error: " + e.Message); Logger.Instance.LogMessage(e.StackTrace); NeedsUpdate |= VRage.ModAPI.MyEntityUpdateEnum.BEFORE_NEXT_FRAME; } }
public void AllJuiceInInv(List <JuiceItem> readin, IMyInventory inv) { if (inv == null) { return; } var inv_rel = (MyInventory)inv; var items = (inv_rel).GetItems(); // If this cast is not safe then then universe has imploded foreach (var item in items) { var stype_id = item.Content.SubtypeId.ToString(); if (item.Content.TypeId.ToString() == CANISTER_TYPE_ID && items_.ContainsKey(stype_id)) { var juice_def = items_[stype_id]; readin.Add(new JuiceItem { Canister = item, JuiceDef = juice_def }); } } }
public static int CalculatePlayerThreat(IMyCharacter character, Vector3D requesterPosition) { if (character.IsDead) { return(0); } float threat = 0; float distance = (float)Vector3D.Distance(requesterPosition, character.GetPosition()); threat += distance < 175 ? distance < 125 ? distance < 75 ? 5000 : 2500 : 1500 : 500; if (character.EquippedTool is IMyAngleGrinder) { threat *= 5; } IMyInventory myInventory = character.GetInventory(); List <MyInventoryItem> items = new List <MyInventoryItem>(); myInventory.GetItems(items); foreach (MyInventoryItem item in items) { if (item.Type == MyItemType.MakeTool("AngleGrinder4Item")) { threat += 1000; continue; } if (item.Type == MyItemType.MakeTool("AngleGrinder3Item")) { threat += 750; continue; } if (item.Type == MyItemType.MakeTool("AngleGrinder2Item")) { threat += 500; continue; } if (item.Type == MyItemType.MakeTool("AngleGrinderItem")) { threat += 250; continue; } if (item.Type == MyItemType.MakeTool("UltimateAutomaticRifleItem")) { threat += 100; continue; } if (item.Type == MyItemType.MakeTool("RapidFireAutomaticRifleItem")) { threat += 80; continue; } if (item.Type == MyItemType.MakeTool("PreciseAutomaticRifleItem")) { threat += 60; continue; } if (item.Type == MyItemType.MakeTool("AutomaticRifleItem")) { threat += 40; continue; } if (item.Type == MyItemType.MakeAmmo("NATO_5p56x45mm")) { threat += 20; continue; } } return((int)threat); }