public void OnClientMessage(ClientMessage msg) { string action = msg.GetString("action"); switch (action) { case "gimme": economyManager.AddResource( EconomyManager.Resource.RewardAmount, msg.GetInt("amount"), (ItemClass)ScriptableObject.CreateInstance("ItemClass")); break; case "payLoan": { var r = economyManager.PayLoanNow(msg.GetInt("id")); if (r == null) { Log($"PayLoanNow returns null"); } else { Log($"PayLoanNow returns: {r}"); } break; } //case "setBudget": { // //TODO, also set tax rate // //economyManager.SetBudget(); // break; // } default: throw new ArgumentException($"Invalid method {action}"); } }
/// <summary> /// Handle "Citizen" 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": SendCitizen(msg.GetInt("id")); break; default: throw new ArgumentException($"Invalid method {action}"); } }
/// <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); }); } }
/// <summary> /// Handle "District" message from client. /// </summary> /// <param name="msg">Message.</param> /// <remarks>Expects a dict with one of the keys: /// <c>get</c>: district ID => get info about specified district /// <c>list</c>: (anything) => get list of valid IDs /// </remarks> public void OnDistrictMessage(ClientMessage msg) { string action = msg.GetString("action"); switch (action) { case "get": SendJson(GetDistrict(msg.GetInt("id")), "District"); break; case "list": SendDistrictList(); break; default: throw new ArgumentException($"Invalid method {action}"); } }
/// <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}"); } }