Example #1
0
        public void EnableWeapons()
        {
            try
            {
                directionalWeapons = directionalWeapons.Where(x => x != null && x.IsFunctional).ToList();
                //var launchers = directionalWeapons.Where(x => x.Name.Contains("launcher")).ToList();

                foreach (var weapon in directionalWeapons)
                {
                    if (poweron == null || gunon == null)
                    {
                        poweron = weapon.GetActionWithName("OnOff_On"); //.Apply(weapon);
                        gunon   = weapon.GetActionWithName("Shoot_On"); //.Apply(weapon);
                    }
                    else
                    {
                        poweron.Apply(weapon);
                        gunon.Apply(weapon);
                    }
                }
                //if (poweron != null && gunon != null)
                //    MyAPIGateway.Parallel.Start(() => FireLaunchers(launchers, poweron, gunon));
            }
            catch (Exception e)
            {
                Logger.LogException(e);
            }
        }
Example #2
0
		private static void RunActionOnBlock(Pathfinder pathfinder, string blockName, string actionString, List<Ingame.TerminalActionParameter> termParams)
		{
			blockName = blockName.Trim();
			actionString = actionString.Trim(); // leave spaces in actionString

			foreach (IMyCubeBlock fatblock in AttachedGrid.AttachedCubeBlocks(pathfinder.Mover.Block.CubeGrid, AttachedGrid.AttachmentKind.Permanent, true))
			{
				if (!(fatblock is IMyTerminalBlock))
					continue;

				if (!pathfinder.Mover.Block.Controller.canControlBlock(fatblock))
					continue;

				if (!fatblock.DisplayNameText.Contains(blockName, StringComparison.InvariantCultureIgnoreCase))
					continue;

				IMyTerminalBlock terminalBlock = fatblock as IMyTerminalBlock;
				Sandbox.ModAPI.Interfaces.ITerminalAction actionToRun = terminalBlock.GetActionWithName(actionString); // get actionToRun on every iteration so invalid blocks can be ignored
				if (actionToRun != null)
				{
					if (termParams != null)
						actionToRun.Apply(fatblock, termParams);
					else
						actionToRun.Apply(fatblock);
				}
			}
		}
Example #3
0
        private void FireLaunchers(List <IMyTerminalBlock> launchers, ITerminalAction onoff, ITerminalAction fire)
        {
            DateTime start = DateTime.Now;

            foreach (var launcher in launchers)
            {
                while ((DateTime.Now - start).TotalMilliseconds < 100)
                {
                }
                start = DateTime.Now;

                {
                    onoff.Apply(launcher);
                    fire.Apply(launcher);
                }
            }
        }
Example #4
0
 public void DisableWeapons()
 {
     try {
         directionalWeapons = directionalWeapons.Where(x => x != null && x.IsFunctional).ToList();
         foreach (var weapon in directionalWeapons)
         {
             if (poweroff == null || gunoff == null)
             {
                 poweroff = weapon.GetActionWithName("Shoot_Off"); //.Apply(weapon);
                 gunoff   = weapon.GetActionWithName("OnOff_Off"); //.Apply(weapon);
             }
             else
             {
                 poweroff.Apply(weapon);
                 gunoff.Apply(weapon);
             }
         }
     }
     catch (Exception e)
     {
         Logger.LogException(e);
     }
 }