Exemplo n.º 1
0
        public override void InvokeServer(Dictionary <string, string> contents)
        {
            if (!int.TryParse(contents["Id"], out int idx))
            {
                SandboxMain.Log($"Invalid  ID \"{contents["Id"]}\" Replicated", true);
                return;
            }

            if (!int.TryParse(contents["Amount"], out int amt))
            {
                SandboxMain.Log($"Invalid amount \"{contents["Amount"]}\" Replicated, overriding to 1", true);
                amt = 1;
            }

            if (!DataUtils.ReadVector3FromDictionary("Location", ref contents, out Vector3 hit))
            {
                SandboxMain.Log(
                    $"Invalid location \"[{contents["Location.x"]}, {contents["Location.y"]}, {contents["Location.z"]}] Replicated",
                    true);
                return;
            }

            for (int i = 0; i < amt; i++)
            {
                Vector3 randomDirection = new Vector3(Random.value, Random.value, Random.value);
                PickupDropletController.CreatePickupDroplet(MakeIndex(idx),
                                                            hit + Vector3.up * 1.5f,
                                                            Vector3.up * 20f + randomDirection * 5f);
            }
        }
Exemplo n.º 2
0
        public static bool RayTrace(out RaycastHit hit)
        {
            Camera camera = Camera.main;

            if (camera == null)
            {
                SandboxMain.Log("Unable to find camera reference.", true);
                hit = new RaycastHit();
                return(false);
            }

            Transform transform = camera.transform;
            Ray       ray       = new Ray {
                origin    = transform.position,
                direction = transform.forward
            };

            if (Physics.Raycast(ray, out hit))
            {
                return(true);
            }

            SandboxMain.Log("Unable to find trace location.", true);
            return(false);
        }
Exemplo n.º 3
0
        public override void InvokeServer(Dictionary <string, string> contents)
        {
            string username = contents["Target"];
            string idStr    = contents["Id"];
            string amtStr   = contents["Amount"];

            if (!int.TryParse(amtStr, out int amt))
            {
                amt = 1;
            }

            NetworkUser user = UnityUtils.GetNetworkUserWithName(username);

            if (user == null)
            {
                SandboxMain.Log($"Unable to find user with name {username}");
                return;
            }

            if (Enum.TryParse(idStr, true, out ItemIndex item))
            {
                user.GetCurrentBody().inventory.GiveItem(item, amt);
            }
            else if (Enum.TryParse(idStr, true, out EquipmentIndex _))
            {
                user.GetCurrentBody().inventory.GiveEquipmentString(idStr);
            }
        }
Exemplo n.º 4
0
        protected override PreparedResult Prepare(Dictionary <string, object> conVars,
                                                  ref Dictionary <string, string> packetContents)
        {
            foreach (Command cmd in SandboxMain.CmdHandler.GetCommands())
            {
                SandboxMain.ToHud(" -- " + cmd.Key());
            }

            return(PreparedResult.Stop);
        }
Exemplo n.º 5
0
        // ReSharper disable once MemberCanBePrivate.Global
        public static PlayerCharacterMasterController GetPlayerController(
            Predicate <PlayerCharacterMasterController> filter)
        {
            foreach (PlayerCharacterMasterController ctrlr in PlayerCharacterMasterController.instances)
            {
                SandboxMain.Debug($"Player controller: {ctrlr.GetDisplayName()}, isLocal: {ctrlr.isLocalPlayer}");
                if (filter(ctrlr))
                {
                    return(ctrlr);
                }
            }

            return(null);
        }
Exemplo n.º 6
0
        // ReSharper disable once MemberCanBeMadeStatic.Global
        public void Replicate(CommandPacket pkt)
        {
            NetworkClient client = NetworkManager.singleton.client;

            if (client == null)
            {
                SandboxMain.Log("NetworkManager.singleton.client is null", true);
                return;
            }

            if (!client.Send(CommandPacketType, pkt))
            {
                SandboxMain.Log($"Failed to replicate command {pkt.CmdKey}", true);
            }
        }
Exemplo n.º 7
0
        protected override PreparedResult Prepare(Dictionary <string, object> conVars,
                                                  ref Dictionary <string, string> packetContents)
        {
            if (!UnityUtils.RayTrace(out RaycastHit hit))
            {
                return(PreparedResult.Stop);
            }

            string id = conVars["Id"].ToString();

            string[] nearbyNames = DataUtils.SelectEnum(id, out T idx, 3, false, GetDefault());

            if (AreEqual(idx, GetDefault()))
            {
                SandboxMain.ToHud("Unable to find  ID: " + id);

                // ReSharper disable once InvertIf
                if (nearbyNames.Length > 0)
                {
                    SandboxMain.ToHud("Did you mean:");
                    foreach (string t in nearbyNames)
                    {
                        SandboxMain.ToHud("    " + t);
                    }
                }

                return(PreparedResult.Stop);
            }

            string amtStr = conVars["Amount"].ToString();

            if (!int.TryParse(amtStr, out int amt))
            {
                amt = 1;
            }

            packetContents.Add("Id", ToInteger(idx).ToString());
            packetContents.Add("Amount", amt.ToString());
            DataUtils.WriteVector3ToDictionary("Location", hit.point, ref packetContents);

            return(PreparedResult.Replicate);
        }
Exemplo n.º 8
0
        public override void InvokeServer(Dictionary <string, string> contents)
        {
            string spawnCard = contents["SpawnCard"];

            if (!DataUtils.ReadVector3FromDictionary("Location", ref contents, out Vector3 hit))
            {
                SandboxMain.Log(
                    $"Invalid location \"[{contents["Location.x"]}, {contents["Location.y"]}, {contents["Location.z"]}] Replicated",
                    true);
                return;
            }

            SpawnCard card = Resources.Load <SpawnCard>("SpawnCards/" + spawnCard);

            if (card == null)
            {
                SandboxMain.Log($"Unable to load a spawnCard called \"{spawnCard}\"", true);
                return;
            }

            card.DoSpawn(hit, Quaternion.identity);
        }
Exemplo n.º 9
0
        public void Invoke(IEnumerable <string> arguments)
        {
            Dictionary <string, object> conVars = new Dictionary <string, object>();

            ParseArguments(arguments, ref conVars);
            CommandPacket pkt = new CommandPacket();

            if (Prepare(conVars, ref pkt.Contents) == PreparedResult.Stop)
            {
                return;
            }

            if (NetworkServer.active)
            {
                SandboxMain.Log($"Invoking command \"{Key()}\" on server");
                InvokeServer(pkt.Contents);
            }
            else
            {
                SandboxMain.NetHandler.Replicate(pkt);
            }
        }
Exemplo n.º 10
0
 public void StartServer()
 {
     SandboxMain.Log("NetworkCommandListener starting");
     NetworkServer.RegisterHandler(CommandPacketType, HandlePacket);
     SandboxMain.Log("NetworkCommandListener started");
 }
Exemplo n.º 11
0
 // ReSharper disable once MemberCanBeMadeStatic.Global
 public void StopServer()
 {
     SandboxMain.Log("NetworkCommandListener stopping");
     NetworkServer.UnregisterHandler(CommandPacketType);
     SandboxMain.Log("NetworkCommandListener stopped");
 }