示例#1
0
 private static void LaserMessages()
 {
     // Initialize messages
     Messages.LaserProgress = ModNetworking.CreateMessageType(DataType.Block, DataType.Boolean, DataType.Boolean, DataType.Single, DataType.Boolean, DataType.Vector3);
     // Script after message has been received
     ModNetworking.Callbacks[Messages.LaserProgress] += message2 =>
     {
         // Save and convert data that just received from message
         Block         block       = (Block)message2.GetData(0);
         bool          ActivationY = (bool)message2.GetData(1);
         bool          ActivationK = (bool)message2.GetData(2);
         float         length      = (float)message2.GetData(3);
         bool          hit         = (bool)message2.GetData(4);
         Vector3       velo        = (Vector3)message2.GetData(5);
         NewLaserBlock clk         = block.SimBlock.GameObject.GetComponent <NewLaserBlock>();
         // Use the initialization
         clk.SetMPState(ActivationY, ActivationK, length, hit, velo);
     };
     Messages.LaserSimuStart = ModNetworking.CreateMessageType(DataType.Block);
     ModNetworking.Callbacks[Messages.LaserSimuStart] += message4 =>
     {
         Block block = (Block)message4.GetData(0);
         // The script on cloak block in client
         NewLaserBlock clk = block.SimBlock.GameObject.GetComponent <NewLaserBlock>();
         // Use the initialization
         clk.OnSimulateStart();
     };
 }
示例#2
0
        // This is called when the mod is first loaded.
        public override void OnLoad()
        {
            // Initialize messages
            Messages.CloakProgress = ModNetworking.CreateMessageType(DataType.Block, DataType.Single, DataType.Boolean, DataType.Single, DataType.Vector3, DataType.Boolean);
            // Script after message has been received
            ModNetworking.Callbacks[Messages.CloakProgress] += message2 =>
            {
                // Save and convert data that just received from message
                Block   block      = (Block)message2.GetData(0);
                float   sizee      = (float)message2.GetData(1);
                bool    Activation = (bool)message2.GetData(2);
                float   timer      = (float)message2.GetData(3);
                Vector3 position   = (Vector3)message2.GetData(4);
                bool    flashish   = (bool)message2.GetData(5);
                // I used static method so I can get the desired detector script
                // Note that block.SimBlock is the simulating instance of desired block. if not using SimBlock then the building instance will be given.
                StealthCloakFieldScript clk = StealthCloakFieldScriptMP.getSCFS(block.SimBlock);
                if (clk.GetType() == typeof(StealthCloakFieldScriptMP))
                {
                    // Some method for syncing
                    ((StealthCloakFieldScriptMP)clk).CloakSizeModifier(sizee, Activation, timer, position, flashish);
                }
            };

            Messages.CloakSimuStart = ModNetworking.CreateMessageType(DataType.Block);
            ModNetworking.Callbacks[Messages.CloakSimuStart] += message4 =>
            {
                Block block = (Block)message4.GetData(0);
                // The script on cloak block in client
                PROCloakScript clk = block.SimBlock.GameObject.GetComponent <PROCloakScript>();
                // Use the initialization
                clk.Initialization();
            };
        }
示例#3
0
        private static void TrackingComputerMessages()
        {
            Messages.TrackingComputerLock = ModNetworking.CreateMessageType(DataType.Block, DataType.Vector3, DataType.Vector3);
            ModNetworking.Callbacks[Messages.TrackingComputerLock] += message6 =>
            {
                Block block = (Block)message6.GetData(0);
                // The script on cloak block in client
                BasicTrackingComputerBehavior clk = block.SimBlock.GameObject.GetComponent <BasicTrackingComputerBehavior>();
                // Use the initialization
                clk.AcquireTarget(new Ray((Vector3)message6.GetData(1), (Vector3)message6.GetData(2)));
            };

            Messages.TrackingComputerSync = ModNetworking.CreateMessageType(DataType.Block, DataType.Vector3, DataType.Boolean);
            ModNetworking.Callbacks[Messages.TrackingComputerSync] += message7 =>
            {
                Block block = (Block)message7.GetData(0);
                // The script on cloak block in client
                BasicTrackingComputerBehavior clk = block.SimBlock.GameObject.GetComponent <BasicTrackingComputerBehavior>();
                // Use the initialization
                clk.setSign((bool)message7.GetData(2), (Vector3)message7.GetData(1));
            };

            Messages.ModTrackingComputerShot = ModNetworking.CreateMessageType(DataType.Block);
            ModNetworking.Callbacks[Messages.ModTrackingComputerShot] += message11 =>
            {
                Block block = (Block)message11.GetData(0);
                // The script on cloak block in client
                ModifiedTurret clk = block.SimBlock.GameObject.GetComponent <ModifiedTurret>();
                clk.shot();
            };

            Messages.MissileGuidanceModeSwitch = ModNetworking.CreateMessageType(DataType.Block, DataType.Integer);
            ModNetworking.Callbacks[Messages.MissileGuidanceModeSwitch] += message =>
            {
                Block block = (Block)message.GetData(0);
                // The script on cloak block in client
                TrackingComputer clk = block.SimBlock.GameObject.GetComponent <TrackingComputer>();
                // Use the initialization
                clk.MissileGuidanceModeInt = (int)message.GetData(1);
                clk.MissileVisReplacement((int)message.GetData(1));
            };

            Messages.OverLoaded = ModNetworking.CreateMessageType(DataType.Block);
            ModNetworking.Callbacks[Messages.OverLoaded] += message8 =>
            {
                Block block = (Block)message8.GetData(0);
                // The script on cloak block in client
                BasicTrackingComputerBehavior clk = block.SimBlock.GameObject.GetComponent <BasicTrackingComputerBehavior>();
            };
        }
示例#4
0
        // This is called when the mod is first loaded.
        public override void OnLoad()
        {
            LaserMessages();
            TrackingComputerMessages();

            Messages.PilotPanelSync = ModNetworking.CreateMessageType(DataType.Block, DataType.Vector3, DataType.Vector3, DataType.Vector3);
            ModNetworking.Callbacks[Messages.PilotPanelSync] += message31 =>
            {
                Block block = (Block)message31.GetData(0);
                // The script on cloak block in client
                PilotPanelScript clk = block.SimBlock.GameObject.GetComponent <PilotPanelScript>();
                // Use the initialization
                clk.SetParams((Vector3)message31.GetData(1), (Vector3)message31.GetData(2), (Vector3)message31.GetData(3));
            };
        }
示例#5
0
        public void Awake()
        {
            // Loading
            var engine = new Jint.Engine();

            //var logic = new Interpreter();
            Registers   = new Dictionary <Type, Action <BlockBehaviour, KeyInputController> >();
            Unregisters = new Dictionary <Type, Action <BlockBehaviour> >();

            ModConsole.RegisterCommand("script", args => {
                var text = string.Join(" ", args);
                //var func = logic.PrepareScript(text);
                //logic.AddExtFunc(func, "print", (ctx, x) => { ModConsole.Log(x[0]?.ToString()); return null; }, true);
                //logic.SetScript(func);
                //var res = logic.ContinueScript(1000);
                Func <JsValue, JsValue[], JsValue> printCb = (thiz, x) => {
                    ModConsole.Log(x[0]?.ToObject().ToString());
                    return(x[0]);
                };

                JsValue curV = null;
                Func <JsValue, JsValue[], JsValue> irqv = (thiz, x) => {
                    curV = x[0];
                    return(null);
                };
                var script = new JavaScriptParser(text, Jint.Engine.DefaultParserOptions).ParseScript();
                engine.SetValue("print", printCb);
                engine.SetValue("irqv", irqv);
                engine.SetScript(script);
                engine.Executor.OnLog = (x) => ModConsole.Log(x?.ToString());
                bool cli = false;
                engine.Executor.OnNextStatement = () =>
                {
                    if (cli)
                    {
                        return;
                    }
                    cli = true;
                    try
                    {
                        if (curV != null)
                        {
                            engine.Invoke(curV);
                        }
                    }
                    finally
                    {
                        cli = false;
                    }
                };
                var res = engine.ContinueScript(1000);
                ModConsole.Log(res?.ToString());
            }, "exec script");

            ModConsole.RegisterCommand("cpuapi", args =>
            {
                foreach (var line in SingleInstance <Blocks.Api.CpuApi> .Instance.GetHelp())
                {
                    ModConsole.Log(line);
                }
            }, "print cpu api list");

            ModConsole.RegisterCommand("sensordbg", args =>
            {
                DrawSensorDebug = args.Length < 1 ? false : args[0] == "true";
            }, "print sensor debug points");

            CpuBlock.Create(this);
            // These creator functions find corresponding block in game prefabs
            // and replace it with inheritor
            ExtLogicGate.Create(this);
            ExtAltimeterBlock.Create(this);
            ExtSpeedometerBlock.Create(this);
            ExtAnglometerBlock.Create(this);
            ExtSensorBlock.Create(this);
            ModConsole.Log($"Logic mod Awake");

            Events.OnMachineSimulationToggle += Events_OnMachineSimulationToggle;
            LineMaterial           = new Material(Shader.Find("Hidden/Internal-Colored"));
            LineMaterial.hideFlags = HideFlags.HideAndDontSave;
            LineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
            LineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
            LineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
            LineMaterial.SetInt("_ZWrite", 0);

            Camera.onPostRender += DrawConnectingLines;
            Events.OnBlockInit  += InitBlock;

            CpuInfoMessage = ModNetworking.CreateMessageType(new DataType[]
            {
                DataType.Block,
                DataType.ByteArray
            });

            CpuLogMessage = ModNetworking.CreateMessageType(new DataType[]
            {
                DataType.Block,
                DataType.String
            });

            ModNetworking.Callbacks[CpuInfoMessage] += (Action <Message>)((msg) =>
            {
                Player localPlayer = Player.GetLocalPlayer();
                if (msg == null || localPlayer == null || !localPlayer.IsHost)
                {
                    return;
                }

                var block = msg.GetData(0) as Modding.Blocks.Block;
                if (!(block?.BlockScript is CpuBlock cpu))
                {
                    return;
                }

                if (block.Machine == localPlayer.Machine)
                {
                    return; // don't read updates for MY machine!
                }
                cpu.AfterEdit_ServerRecv((byte[])msg.GetData(1));
            });

            ModNetworking.Callbacks[CpuLogMessage] += (Action <Message>)((msg) =>
            {
                if (msg == null)
                {
                    return;
                }

                var block = msg.GetData(0) as Modding.Blocks.Block;
                if (!(block?.BlockScript is CpuBlock cpu))
                {
                    return;
                }

                cpu.LogMessage((string)msg.GetData(1));
            });
        }
        public MessageController()
        {
            //Initiating messages
            Messages.rocketFiredMsg = ModNetworking.CreateMessageType(DataType.Block);
            Messages.rocketTargetBlockBehaviourMsg = ModNetworking.CreateMessageType(DataType.Block, DataType.Block);
            Messages.rocketTargetEntityMsg         = ModNetworking.CreateMessageType(DataType.Entity, DataType.Block);
            Messages.rocketTargetNullMsg           = ModNetworking.CreateMessageType(DataType.Block);
            Messages.rocketRayToHostMsg            = ModNetworking.CreateMessageType(DataType.Vector3, DataType.Vector3, DataType.Block);
            Messages.rocketHighExploPosition       = ModNetworking.CreateMessageType(DataType.Vector3, DataType.Single);
            Messages.rocketLockOnMeMsg             = ModNetworking.CreateMessageType(DataType.Block, DataType.Integer);
            Messages.rocketLostTargetMsg           = ModNetworking.CreateMessageType(DataType.Block);

            //Initiating callbacks
            ModNetworking.Callbacks[Messages.rocketHighExploPosition] += (Message msg) =>
            {
                if (StatMaster.isClient)
                {
                    Vector3 position            = (Vector3)msg.GetData(0);
                    float   bombExplosiveCharge = (float)msg.GetData(1);
                    int     levelBombCategory   = 4;
                    int     levelBombID         = 5001;
                    float   radius      = 7f;
                    float   power       = 3600f;
                    float   torquePower = 100000f;
                    float   upPower     = 0.25f;
                    try
                    {
                        GameObject bomb = UnityEngine.Object.Instantiate(PrefabMaster.LevelPrefabs[levelBombCategory].GetValue(levelBombID).gameObject);
                        bomb.transform.position = position;
                        ExplodeOnCollide bombControl = bomb.GetComponent <ExplodeOnCollide>();
                        bomb.transform.localScale = Vector3.one * bombExplosiveCharge;
                        bombControl.radius        = radius * bombExplosiveCharge;
                        bombControl.power         = power * bombExplosiveCharge;
                        bombControl.torquePower   = torquePower * bombExplosiveCharge;
                        bombControl.upPower       = upPower;
                        bombControl.Explodey();
                    }
                    catch { }
                }
            };

            ModNetworking.Callbacks[Messages.rocketFiredMsg] += (Message msg) =>
            {
                Block       rocketBlock = (Block)msg.GetData(0);
                TimedRocket rocket      = rocketBlock.GameObject.GetComponent <TimedRocket>();
                RocketsController.Instance.UpdateRocketFiredStatus(rocket);
            };

            ModNetworking.Callbacks[Messages.rocketTargetBlockBehaviourMsg] += (Message msg) =>
            {
#if DEBUG
                Debug.Log("Receive block target");
#endif
                Block        rocketBlock = (Block)msg.GetData(1);
                RocketScript rocket      = rocketBlock.GameObject.GetComponent <RocketScript>();
                rocket.target         = ((Block)msg.GetData(0)).GameObject.transform;
                rocket.targetCollider = rocket.target.gameObject.GetComponentInChildren <Collider>(true);
            };

            ModNetworking.Callbacks[Messages.rocketTargetEntityMsg] += (Message msg) =>
            {
#if DEBUG
                Debug.Log("Receive entity target");
#endif
                Block        rocketBlock = (Block)msg.GetData(1);
                RocketScript rocket      = rocketBlock.GameObject.GetComponent <RocketScript>();
                rocket.target         = ((Entity)msg.GetData(0)).GameObject.transform;
                rocket.targetCollider = rocket.target.gameObject.GetComponentInChildren <Collider>(true);
            };

            ModNetworking.Callbacks[Messages.rocketTargetNullMsg] += (Message msg) =>
            {
#if DEBUG
                Debug.Log("Receive entity target");
#endif
                Block        rocketBlock = (Block)msg.GetData(0);
                RocketScript rocket      = rocketBlock.GameObject.GetComponent <RocketScript>();
                rocket.target         = null;
                rocket.targetCollider = null;
            };

            ModNetworking.Callbacks[Messages.rocketRayToHostMsg] += (Message msg) =>
            {
                Block        rocketBlock = (Block)msg.GetData(2);
                RocketScript rocket      = rocketBlock.GameObject.GetComponent <RocketScript>();
                rocket.rayFromClient         = new Ray((Vector3)msg.GetData(0), (Vector3)msg.GetData(1));
                rocket.activeGuide           = false;
                rocket.receivedRayFromClient = true;
            };

            ModNetworking.Callbacks[Messages.rocketLockOnMeMsg] += (Message msg) =>
            {
                Block rocket          = (Block)msg.GetData(0);
                int   targetMachineID = (int)msg.GetData(1);
                RocketsController.Instance.UpdateRocketTarget(rocket.InternalObject, targetMachineID);
            };
            ModNetworking.Callbacks[Messages.rocketLostTargetMsg] += (Message msg) =>
            {
                Block rocket = (Block)msg.GetData(0);
                RocketsController.Instance.RemoveRocketTarget(rocket.InternalObject);
            };
        }
示例#7
0
 public static void CreateMessageTypes()
 {
     tankTypeMessage = ModNetworking.CreateMessageType(DataType.ByteArray, DataType.Boolean);
     ModNetworking.Callbacks[tankTypeMessage] += LJTMachine.OnTankTypeMessageReceive;
 }
示例#8
0
 protected static void SetupNetworking()
 {
     targetingMessageType = ModNetworking.CreateMessageType(DataType.Block, DataType.Vector3);
     ModNetworking.Callbacks[targetingMessageType] += ProcessRemoteTargeting;
 }
示例#9
0
 public static void SetupNetworking()
 {
     portalShotMessageType = ModNetworking.CreateMessageType(DataType.Block, DataType.Integer, DataType.Integer, DataType.Vector3, DataType.Vector3, DataType.Vector3);
     ModNetworking.Callbacks[portalShotMessageType] += ProcessRemotePortalPlacement;
 }
示例#10
0
 public static void SetupNetworking()
 {
     polymorphMessageType = ModNetworking.CreateMessageType(DataType.Block, DataType.Entity, DataType.Boolean);
     ModNetworking.Callbacks[polymorphMessageType] += ProcessRemotePolymorphing;
 }