Ejemplo n.º 1
0
        /// <summary>
        /// Handles "set" and "move" messages from client.
        /// </summary>
        /// <param name="msg">Message.</param>
        /// <param name="relative">If set to <c>true</c> relative.</param>
        protected void HandleMove(ClientMessage msg, bool relative)
        {
            var cam = ToolsModifierControl.cameraController;

            cam.ClearTarget();
            Vector3 targetPos, currentPos;
            Vector2 targetAngle, currentAngle;

            if (msg.HasKey("targetPosition"))
            {
                targetPos = msg.GetVector3("targetPosition");
            }
            else
            {
                targetPos = cam.m_targetPosition;
            }

            if (msg.HasKey("position"))
            {
                currentPos = msg.GetVector3("position");
            }
            else
            {
                currentPos = cam.m_currentPosition;
            }

            if (msg.HasKey("targetAngle"))
            {
                targetAngle = msg.GetVector2("targetAngle");
            }
            else
            {
                targetAngle = cam.m_targetAngle;
            }

            if (msg.HasKey("angle"))
            {
                currentAngle = msg.GetVector2("angle");
            }
            else
            {
                currentAngle = cam.m_currentAngle;
            }

            if (!relative)
            {
                cam.m_targetPosition.Set(0, 0, 0);
                cam.m_currentPosition.Set(0, 0, 0);
                cam.m_targetAngle.Set(0, 0);
                cam.m_currentAngle.Set(0, 0);
            }
            cam.m_targetPosition  += targetPos;
            cam.m_currentPosition += currentPos;
            cam.m_targetAngle     += targetAngle;
            cam.m_currentAngle    += currentAngle;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles "lookAt" message from client.
        /// </summary>
        /// <param name="msg">Message.</param>
        protected void HandleLookAt(ClientMessage msg)
        {
            Vector3    pos;
            InstanceID id  = default(InstanceID);
            var        cam = ToolsModifierControl.cameraController;

            cam.ClearTarget();
            if (msg.HasKey("building"))
            {
                id.Building = (ushort)msg.GetInt("building");
                pos         = BuildingManager.instance.m_buildings.m_buffer[id.Building].m_position;
            }
            else if (msg.HasKey("vehicle"))
            {
                id.Vehicle = (ushort)msg.GetInt("vehicle");
                pos        = VehicleManager.instance.m_vehicles.m_buffer[id.Vehicle].GetLastFramePosition();
            }
            else if (msg.HasKey("parkedVehicle"))
            {
                id.ParkedVehicle = (ushort)msg.GetInt("parkedVehicle");
                pos = VehicleManager.instance.m_parkedVehicles.m_buffer[id.ParkedVehicle].m_position;
            }
            else if (msg.HasKey("segment"))
            {
                id.NetSegment = (ushort)msg.GetInt("segment");
                pos           = NetManager.instance.m_segments.m_buffer[id.NetSegment].m_bounds.center;
            }
            else if (msg.HasKey("node"))
            {
                id.NetNode = (ushort)msg.GetInt("node");
                pos        = NetManager.instance.m_nodes.m_buffer[id.NetNode].m_position;
            }
            else if (msg.HasKey("citizenInstance"))
            {
                id.CitizenInstance = (ushort)msg.GetInt("citizenInstance");
                pos = CitizenManager.instance.m_instances.m_buffer[id.CitizenInstance].GetLastFramePosition();
            }
            else if (msg.HasKey("position"))
            {
                cam.m_targetPosition = msg.GetVector3("position");
                return;
            }
            else
            {
                throw new ArgumentException("No target specified");
            }
            bool zoom      = !msg.HasKey("zoom") || msg.GetBool("zoom");
            bool openPanel = !msg.HasKey("openInfoPanel") || msg.GetBool("openInfoPanel");

            cam.SetTarget(id, pos, zoom);
            if (openPanel)
            {
                SimulationManager.instance.m_ThreadingWrapper.QueueMainThread(() => {
                    DefaultTool.OpenWorldInfoPanel(id, pos);
                });
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Handle "Building" message from client.
        /// </summary>
        /// <param name="msg">Message.</param>
        /// <remarks>Expects a dict with one of the keys:
        /// <c>get</c>: building ID => get info about specified building
        /// <c>list</c>: (anything) => get list of valid IDs
        /// </remarks>
        public void OnClientMessage(ClientMessage msg)
        {
            string action = msg.GetString("action");

            switch (action)
            {
            case "get": {
                SendBuilding(msg.GetInt("id"));
                break;
            }

            case "getByProblem": {
                //This could be just a ulong parameter but nope,
                //apparently you can't use ulong in json for reasons
                string flags = msg.GetString("problem");
                if (flags == null || (!ProblemFlags.ContainsKey(flags) &&
                                      !ProblemFlagNames.ContainsKey(flags)))
                {
                    throw new ArgumentException("Invalid problem name");
                }
                if (ProblemFlags.ContainsKey(flags))
                {
                    SendProblems(ProblemFlags[flags]);
                }
                else
                {
                    SendFlags(ProblemFlagNames[flags]);
                }
                break;
            }

            case "list":
                SendList();
                break;

            case "destroy":
                DestroyBuilding(msg.GetInt("id"));
                break;

            case "canRebuild": {
                int  id = msg.GetInt("id");
                bool ok = CanRebuild(msg.GetInt("id"), out string status);
                SendJson(new Dictionary <string, string> {
                        { "canRebuild", ok.ToString() },
                        { "id", id.ToString() },
                        { "status", status },
                    }, "canRebuild");
                break;
            }

            case "rebuild": {
                int  id    = msg.GetInt("id");
                bool force = msg.HasKey("force") && msg.GetBool("force");
                bool ok    = RebuildBuilding(msg.GetInt("id"),
                                             out string status, force);
                SendJson(new Dictionary <string, string> {
                        { "rebuild", ok.ToString() },
                        { "id", id.ToString() },
                        { "status", status },
                    }, "rebuild");
                break;
            }

            default:
                throw new ArgumentException($"Invalid method {action}");
            }
        }