public MyTSSEnergyHydrogen(Sandbox.ModAPI.IMyTextSurface surface, VRage.Game.ModAPI.IMyCubeBlock block, Vector2 size) : base((Sandbox.ModAPI.Ingame.IMyTextSurface)surface, (VRage.Game.ModAPI.Ingame.IMyCubeBlock)block, size) { this.m_innerSize = new Vector2(MyTSSEnergyHydrogen.ASPECT_RATIO, 1f); MyTextSurfaceScriptBase.FitRect(size, ref this.m_innerSize); this.m_decorationSize = new Vector2(0.012f * this.m_innerSize.X, MyTSSEnergyHydrogen.DECORATION_RATIO * this.m_innerSize.Y); this.m_sb.Clear(); this.m_sb.Append("Power Usage: 00.000"); Vector2 vector2 = MyGuiManager.MeasureStringRaw(this.m_fontId, this.m_sb, 1f); float val2 = MyTSSEnergyHydrogen.TEXT_RATIO * this.m_innerSize.Y / vector2.Y; this.m_fontScale = Math.Min(this.m_innerSize.X * 0.72f / vector2.X, val2); this.m_firstLine = this.m_halfSize.Y - this.m_decorationSize.Y * 0.55f; this.m_secondLine = this.m_halfSize.Y + this.m_decorationSize.Y * 0.55f; if (this.m_block == null) { return; } this.m_grid = this.m_block.CubeGrid as MyCubeGrid; if (this.m_grid == null) { return; } this.m_resourceDistributor = this.m_grid.GridSystems.ResourceDistributor; this.m_grid.GridSystems.ConveyorSystem.BlockAdded += new Action <MyCubeBlock>(this.ConveyorSystemOnBlockAdded); this.m_grid.GridSystems.ConveyorSystem.BlockRemoved += new Action <MyCubeBlock>(this.ConveyorSystemOnBlockRemoved); this.Recalculate(); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { string[] split = command.Split(','); if (split.Length != 3) { if (split.Length > 3) { message = "Too many arguments: " + split.Length; } else { message = "Too few arguments: " + split.Length; } return(null); } string split2 = split[2].Trim(); uint packedValue; if (uint.TryParse(split2, out packedValue)) { m_value = new Color(packedValue); } else { message = "Not a colour value: " + split2; m_hasValue = false; return(null); } m_hasValue = true; message = null; return(mover => SetPropertyOfBlock(mover, split[0], split[1], m_value)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (string.IsNullOrWhiteSpace(command)) { message = "No target"; return(null); } string[] split = command.Split(','); if (split.Length == 1) { m_fetch = false; } else if (split.Length == 2) { if (split[1].TrimStart().StartsWith("f", StringComparison.InvariantCultureIgnoreCase)) { m_fetch = true; } else { message = "Invalid argument: " + split[1]; return(null); } } else { message = "Too many arguments: " + split.Length; return(null); } m_target = new StringBuilder(split[0]); message = null; return(mover => new WeldGrid(mover, split[0], m_fetch)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (string.IsNullOrWhiteSpace(command)) { message = null; return(ActionMethod); } message = "extraneous: " + command; return(null); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!PrettySI.TryParse(command, out m_distance)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => mover.NavSet.Settings_Commands.DestinationRadius = m_distance > 0f ? m_distance : AllNavigationSettings.DefaultRadius); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (Enum.TryParse(command, true, out m_target)) { message = null; return(mover => new VoxelLander(mover, m_target == Target.planet)); } message = "Neither asteroid nor planet: " + command; return(null); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!GetVector(command, out destination)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => new GOLIS(mover, destination)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!GetVector(command, out m_offsetValue)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => mover.NavSet.Settings_Task_NavMove.DestinationOffset = m_offsetValue); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!PrettySI.TryParse(command, out m_radius)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => new Grinder(mover, m_radius)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!PrettySI.TryParse(command, out m_speed)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => mover.NavSet.Settings_Commands.SpeedTarget = m_speed > 0f ? m_speed : AllNavigationSettings.DefaultSpeed); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!GetVector(command, out destination)) { message = "Failed to parse: " + command; return(null); } message = null; return(mover => new GOLIS(mover, ((PositionBlock)destination).ToWorld(mover.NavSet.Settings_Current.NavigationBlock.Block))); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (string.IsNullOrWhiteSpace(command)) { message = "No grid name"; return(null); } m_gridName = new StringBuilder(command); message = null; return(mover => new FlyToGrid(mover, command)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (PrettySI.TryParse(command.RemoveWhitespace(), out duration)) { message = null; return(mover => mover.NavSet.Settings_Task_NavWay.WaitUntil = Globals.ElapsedTime.Add(duration)); } else { message = "Not a time span: " + command; return(null); } }
private void OnIsWorkingChanged(VRage.Game.ModAPI.IMyCubeBlock obj) { if (MyAPIGateway.Session == null) { return; } if (MyAPIGateway.Utilities.IsDedicated && MyAPIGateway.Multiplayer.IsServer) { return; } var color = IsWorking ? GREEN : RED; m_block.SetEmissiveParts(EMISSIVE_MATERIAL_NAME, color, 1f); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { string blockName; Base6Directions.Direction?forward, upward; if (!SplitNameDirections(command, out blockName, out forward, out upward, out message)) { return(null); } message = null; m_searchBlockName = new StringBuilder(blockName); m_forward = forward; m_upward = upward; return(ActionMethod); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { byte[] oreType; if (command.Equals("arvest", StringComparison.InvariantCultureIgnoreCase)) { oreType = null; } else { if (string.IsNullOrWhiteSpace(command)) { message = "no ores specified"; return(null); } string[] splitComma = command.Split(','); List <byte> oreTypeList = new List <byte>(); m_activeOres.Clear(); foreach (string name in splitComma) { string trimmed = name.Trim(); Ore ore; if (!TryGetOre(trimmed, out ore)) { message = "Not ore: " + name; return(null); } byte[] oreIds; if (!OreDetector.TryGetMaterial(trimmed, out oreIds)) { message = "Failed to get material index: " + name; return(null); } m_activeOres.Add(ore); oreTypeList.AddArray(oreIds); } oreType = oreTypeList.ToArray(); } message = null; return(mover => new Miner(mover, oreType)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (string.IsNullOrWhiteSpace(command)) { message = "No target specified"; return(null); } if (Enum.TryParse(command, true, out m_target) && (m_target == Target.asteroid || m_target == Target.planet)) { m_gridName.Clear(); } else { m_target = Target.grid; m_gridName = new StringBuilder(command); } message = null; return(mover => new Orbiter(mover, command)); }
protected override AutopilotActionList.AutopilotAction Parse(VRage.Game.ModAPI.IMyCubeBlock autopilot, string command, out string message) { if (!ServerSettings.GetSetting <bool>(ServerSettings.SettingName.bAllowWeaponControl)) { message = "Weapon control is disabled in settings"; return(null); } string[] split = command.RemoveWhitespace().Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); m_range = 0f; long entityId = 0L; m_activeResponses.Clear(); foreach (string s in split) { if (s.Equals("off", StringComparison.InvariantCultureIgnoreCase)) { m_activeResponses.Add(EnemyFinder.Response.None); message = null; return(mover => mover.NavSet.Settings_Commands.EnemyFinder = null); } float range; if (PrettySI.TryParse(s, out range)) { m_range = range; continue; } if (s.StartsWith("id", StringComparison.InvariantCultureIgnoreCase)) { if (s.Length < 3) { message = "Could not get id from " + s; return(null); } string idStr = s.Substring(2, s.Length - 2); IMyEntity entity; if (!long.TryParse(idStr, out entityId) || !MyAPIGateway.Entities.TryGetEntityById(entityId, out entity)) { message = "Not an id: " + idStr; return(null); } else { m_enemyId = entityId; } continue; } string resStr = s.Replace('-', '_'); EnemyFinder.Response r; if (!Enum.TryParse <EnemyFinder.Response>(resStr, true, out r)) { message = "Not a response: " + resStr; return(null); } else { m_activeResponses.Add(r); } } if (m_activeResponses.Count == 0) { message = "No responses"; return(null); } message = null; return(mover => { if (mover.NavSet.Settings_Commands.EnemyFinder == null) { mover.NavSet.Settings_Commands.EnemyFinder = new EnemyFinder(mover, mover.NavSet, entityId); } mover.NavSet.Settings_Commands.EnemyFinder.AddResponses(m_range, m_activeResponses); }); }
public void UpgradeAction(IMyTerminalBlock block) { Dictionary <int, List <MyInventoryItem> > InventoryTransfer = new Dictionary <int, List <MyInventoryItem> >(); MyEntity entity = MyVisualScriptLogicProvider.GetEntityById(block.EntityId); var blockSelf = entity as VRage.Game.ModAPI.IMyCubeBlock; var selfPos = blockSelf.Position; var selfGrid = blockSelf.CubeGrid; var selfOb = blockSelf.GetObjectBuilderCubeBlock(true); var ob = new MyObjectBuilder_CubeBlock() { SubtypeName = Upgrades[block.BlockDefinition.SubtypeId], BuildPercent = selfOb.BuildPercent, IntegrityPercent = selfOb.IntegrityPercent, Min = selfOb.Min, BlockOrientation = selfOb.BlockOrientation, SkinSubtypeId = selfOb.SkinSubtypeId, ColorMaskHSV = selfOb.ColorMaskHSV, BuiltBy = selfOb.BuiltBy, ShareMode = selfOb.ShareMode, Owner = selfOb.Owner }; MyCubeBlockDefinition def = MyDefinitionManager.Static.GetDefinition <CBT>(Upgrades[block.BlockDefinition.SubtypeId]); if (block.InventoryCount > 0) { for (int i = 0; i < block.InventoryCount; i++) { List <MyInventoryItem> items = new List <MyInventoryItem>(); block.GetInventory(i).GetItems(items); InventoryTransfer.Add(i, items); while (block.GetInventory(i).ItemCount > 0) { block.GetInventory(i).RemoveItemsAt(0); } } } MyAPIGateway.Utilities.InvokeOnGameThread(() => { selfGrid.RazeBlock(selfPos); var newBlock = selfGrid.AddBlock(ob, false); VRage.Game.ModAPI.IMyCubeBlock fatNewBlock = newBlock.FatBlock; var terminal = fatNewBlock as IMyTerminalBlock; terminal.CustomName = block.CustomName; terminal.CustomData = block.CustomData; terminal.ShowInInventory = block.ShowInInventory; terminal.ShowInTerminal = block.ShowInTerminal; terminal.ShowInToolbarConfig = block.ShowInToolbarConfig; terminal.ShowOnHUD = block.ShowOnHUD; if (InventoryTransfer.Count > 0) { List <MyInventoryItem> items = new List <MyInventoryItem>(); for (int i = 0; i < terminal.InventoryCount; i++) { foreach (MyInventoryItem item in InventoryTransfer[i]) { terminal.GetInventory(i).AddItems(item.Amount, GetBuilder(item.Type.TypeId, item.Type.SubtypeId)); } } } TransferCustomSettings((BT)block, (BT)fatNewBlock); }); }
private void OnIsWorkingChanged(VRage.Game.ModAPI.IMyCubeBlock obj) { OnStateChanged(); }