Exemplo n.º 1
0
        /// <summary>
        /// <para>Scripts that use UpdateManager and run on a server shall be added here.</para>
        /// </summary>
        private void RegisterScripts_Server()
        {
            #region Autopilot

            RadarEquipment.Definition apRadar = new RadarEquipment.Definition()
            {
                Radar = true,
                LineOfSight = false,
                MaxTargets_Tracking = 3,
                MaxPowerLevel = 1000
            };

            Action<IMyCubeBlock> construct = block => {
                if (ShipAutopilot.IsAutopilotBlock(block))
                {
                    var sca = new ShipAutopilot(block);
                    RegisterForUpdates(ShipAutopilot.UpdateFrequency, sca.Update, block);
                    RegisterForUpdates(100, sca.m_block.NetworkNode.Update100, block);
                    RadarEquipment r = new RadarEquipment(block, apRadar, block);
                    RegisterForUpdates(100, r.Update100, block);
                }
            };

            RegisterForBlock(typeof(MyObjectBuilder_Cockpit), construct);
            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
                RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), construct);

            #endregion

            #region Weapons

            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowHacker))
                RegisterForBlock(typeof(MyObjectBuilder_LandingGear), block => {
                    if (Hacker.IsHacker(block))
                    {
                        Hacker h = new Hacker(block);
                        RegisterForUpdates(10, h.Update10, block);
                    }
                });
            else
                myLogger.debugLog("Hacker is disabled in settings");

            #endregion

            #region Solar

            {
                SunProperties sun = new SunProperties();
                RegisterForUpdates(10, sun.Update10);
            }
            RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => {
                Solar s = new Solar(block);
                RegisterForUpdates(100, s.Update100, block);
            });
            RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => {
                Solar s = new Solar(block);
                RegisterForUpdates(100, s.Update100, block);
            });

            #endregion

            RegisterForBlock(typeof(MyObjectBuilder_OreDetector), block => {
                var od = new OreDetector(block);
                RegisterForUpdates(1000, od.Update, block);
            });

            if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bImmortalMiner))
                new DamageHandler();
        }
Exemplo n.º 2
0
		/// <summary>
		/// <para>Scripts that use UpdateManager and run on a server shall be added here.</para>
		/// </summary>
		private void RegisterScripts_Server()
		{
			#region Autopilot

			if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
				RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), (IMyCubeBlock block) => {
					if (ShipController_Autopilot.IsAutopilotBlock(block))
					{
						var sca = new ShipController_Autopilot(block);
						RegisterForUpdates(ShipController_Autopilot.UpdateFrequency, sca.Update, block);
					}
				});
			RegisterForBlock(typeof(MyObjectBuilder_Cockpit), (IMyCubeBlock block) => {
				if (ShipController_Autopilot.IsAutopilotBlock(block))
				{
					var sca = new ShipController_Autopilot(block);
					RegisterForUpdates(ShipController_Autopilot.UpdateFrequency, sca.Update, block);
				}
			});

			#endregion

			#region Antenna Communication

			RegisterForBlock(typeof(MyObjectBuilder_Beacon), (IMyCubeBlock block) => {
				Beacon newBeacon = new Beacon(block);
				RegisterForUpdates(100, newBeacon.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_TextPanel), (IMyCubeBlock block) => {
				TextPanel newTextPanel = new TextPanel(block);
				RegisterForUpdates(100, newTextPanel.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_LaserAntenna), (IMyCubeBlock block) => {
				LaserAntenna newLA = new LaserAntenna(block);
				RegisterForUpdates(100, newLA.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_MyProgrammableBlock), (IMyCubeBlock block) => {
				ProgrammableBlock newPB = new ProgrammableBlock(block);
				RegisterForUpdates(100, newPB.UpdateAfterSimulation100, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_RadioAntenna), (IMyCubeBlock block) => {
				RadioAntenna newRA = new RadioAntenna(block);
				RegisterForUpdates(100, newRA.UpdateAfterSimulation100, block);
			});
			RegisterForPlayer((player) => {
				Player p = new Player(player);
				RegisterForUpdates(100, p.Update100, player, Player.OnLeave);
			});
			if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bUseRemoteControl))
				RegisterForBlock(typeof(MyObjectBuilder_RemoteControl), (IMyCubeBlock block) => {
					if (ShipController_Autopilot.IsAutopilotBlock(block))
						new ShipController(block);
					// Does not receive Updates
				});
			RegisterForBlock(typeof(MyObjectBuilder_Cockpit), (IMyCubeBlock block) => {
				if (ShipController_Autopilot.IsAutopilotBlock(block))
					new ShipController(block);
				// Does not receive Updates
			});

			#endregion

			#region Weapons

			if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowWeaponControl))
			{
				#region Turrets

				Action<IMyCubeBlock> constructor;
				if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowGuidedMissile))
					constructor = block => {
						Turret t = new Turret(block);
						RegisterForUpdates(1, t.Update_Targeting, block);
						if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
						{
							GuidedMissileLauncher gml = new GuidedMissileLauncher(t);
							RegisterForUpdates(1, gml.Update1, block);
						}
					};
				else
					constructor = block => {
						Turret t = new Turret(block);
						RegisterForUpdates(1, t.Update_Targeting, block);
					};

				RegisterForBlock(typeof(MyObjectBuilder_LargeGatlingTurret), constructor);
				RegisterForBlock(typeof(MyObjectBuilder_LargeMissileTurret), constructor);
				RegisterForBlock(typeof(MyObjectBuilder_InteriorTurret), constructor);

				#endregion

				#region Fixed


				if (ServerSettings.GetSetting<bool>(ServerSettings.SettingName.bAllowGuidedMissile))
				{
					constructor = block => {
						FixedWeapon w = new FixedWeapon(block);
						RegisterForUpdates(1, w.Update_Targeting, block);
						if (GuidedMissileLauncher.IsGuidedMissileLauncher(block))
						{
							GuidedMissileLauncher gml = new GuidedMissileLauncher(w);
							RegisterForUpdates(1, gml.Update1, block);
						}
					};

					RegisterForUpdates(1, GuidedMissile.Update1);
					RegisterForUpdates(10, GuidedMissile.Update10);
					RegisterForUpdates(100, GuidedMissile.Update100);
				}
				else
					constructor = block => {
						FixedWeapon w = new FixedWeapon(block);
						RegisterForUpdates(1, w.Update_Targeting, block);
					};

				RegisterForBlock(typeof(MyObjectBuilder_SmallGatlingGun), constructor);
				RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncher), constructor);
				RegisterForBlock(typeof(MyObjectBuilder_SmallMissileLauncherReload), constructor);

				#endregion

				#region Disruption

				RegisterForUpdates(10, EMP.Update);
				RegisterForUpdates(10, AirVentDepressurize.Update);
				RegisterForUpdates(10, DoorLock.Update);
				RegisterForUpdates(10, GravityReverse.Update);
				RegisterForUpdates(10, DisableTurret.Update);
				RegisterForUpdates(10, TraitorTurret.Update);

				RegisterForBlock(typeof(MyObjectBuilder_LandingGear), block => {
					if (Hacker.IsHacker(block))
					{
						Hacker h = new Hacker(block);
						RegisterForUpdates(10, h.Update10, block);
					}
				});

				#endregion
			}
			else
				myLogger.debugLog("Weapon Control is disabled", "RegisterScripts_Server()", Logger.severity.INFO);

			#endregion

			#region Solar

			{
				SunProperties sun = new SunProperties();
				RegisterForUpdates(10, sun.Update10);
			}
			RegisterForBlock(typeof(MyObjectBuilder_OxygenFarm), (block) => {
				Solar s = new Solar(block);
				RegisterForUpdates(1, s.Update1, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_SolarPanel), (block) => {
				Solar s = new Solar(block);
				RegisterForUpdates(1, s.Update1, block);
			});

			#endregion

			#region Attached

			RegisterForBlock(typeof(MyObjectBuilder_MotorStator), (block) => {
				StatorRotor.Stator stator = new StatorRotor.Stator(block);
				RegisterForUpdates(1, stator.Update10, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_MotorAdvancedStator), (block) => {
				StatorRotor.Stator stator = new StatorRotor.Stator(block);
				RegisterForUpdates(1, stator.Update10, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_MotorRotor), (block) => {
				new StatorRotor.Rotor(block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_MotorAdvancedRotor), (block) => {
				new StatorRotor.Rotor(block);
			});

			RegisterForBlock(typeof(MyObjectBuilder_ExtendedPistonBase), (block) => {
				Piston.PistonBase pistonBase = new Piston.PistonBase(block);
				RegisterForUpdates(100, pistonBase.Update, block);
			});
			RegisterForBlock(typeof(MyObjectBuilder_PistonTop), (block) => {
				new Piston.PistonTop(block);
			});

			RegisterForBlock(typeof(MyObjectBuilder_ShipConnector), (block) => {
				Connector conn = new Connector(block);
				RegisterForUpdates(10, conn.Update, block);
			});

			RegisterForBlock(typeof(MyObjectBuilder_LandingGear), (block) => {
				new LandingGear(block);
			});

			#endregion

			RegisterForBlock(typeof(MyObjectBuilder_OreDetector), block => {
				var od = new OreDetector(block);
				RegisterForUpdates(1000, od.Update, block);
			});

			RegisterForPlayerLeaves(UserSettings.OnPlayerLeave);
		}