Пример #1
0
        // Finds all entities a player owns on a certain radius & returns them
        private List <BaseEntity>[] FindWhat(BasePlayer player, float radius, WantedEntityType entityMask)
        {
            Dictionary <int, int> checkedInstanceIDs = new Dictionary <int, int>();

            List <BaseEntity>[] foundItems = new List <BaseEntity> [3];
            foundItems[0] = new List <BaseEntity>();
            foundItems[1] = new List <BaseEntity>();
            foundItems[2] = new List <BaseEntity>();

            foreach (var collider in Physics.OverlapSphere(player.transform.position, radius))
            {
                BaseEntity entity = collider.gameObject.ToBaseEntity();
                if (entity && !checkedInstanceIDs.ContainsKey(entity.GetInstanceID()))
                {
                    checkedInstanceIDs.Add(entity.GetInstanceID(), 1);
                    if (entity.OwnerID == player.userID)
                    {
                        if (pluginConfig.Commands.AllowAutoturretSharing && IsBitSet(entityMask, WantedEntityType.AT) && entity is AutoTurret)
                        {
                            foundItems[0].Add(entity);
                        }
                        if (pluginConfig.Commands.AllowCodelockSharing && IsBitSet(entityMask, WantedEntityType.CL) && entity.HasSlot(BaseEntity.Slot.Lock) && entity.GetSlot(BaseEntity.Slot.Lock) && entity.GetSlot(BaseEntity.Slot.Lock).GetComponent <CodeLock>())
                        {
                            foundItems[1].Add(entity);
                        }
                        if (pluginConfig.Commands.AllowCupboardSharing && IsBitSet(entityMask, WantedEntityType.CB) && entity is BuildingPrivlidge)
                        {
                            foundItems[2].Add(entity);
                        }
                    }
                }
            }
            return(foundItems);
        }
Пример #2
0
 private bool IsBitSet(WantedEntityType value, WantedEntityType pos)
 {
     return((value & pos) != 0);
 }
Пример #3
0
        private string buildAnswer(BasePlayer player, int createdWLEntries, int foundAT, int foundCL, int foundCB, string command, WantedEntityType type)
        {
            var sb = new StringBuilder();

            if (pluginConfig.Commands.AllowAutoturretSharing && IsBitSet(type, WantedEntityType.AT))
            {
                sb.AppendLine(string.Format(lang.GetMessage(FoundXY, this, player.UserIDString), foundAT, "AutoTurrets"));
            }
            if (pluginConfig.Commands.AllowCodelockSharing && IsBitSet(type, WantedEntityType.CL))
            {
                sb.AppendLine(string.Format(lang.GetMessage(FoundXY, this, player.UserIDString), foundCL, "CodeLocks"));
            }
            if (pluginConfig.Commands.AllowCupboardSharing && IsBitSet(type, WantedEntityType.CB))
            {
                sb.AppendLine(string.Format(lang.GetMessage(FoundXY, this, player.UserIDString), foundCB, "Cupboards"));
            }
            if (string.Equals(command, pluginConfig.Commands.ShareCommand))
            {
                sb.AppendLine(string.Format(lang.GetMessage(CreatedWL, this, player.UserIDString), createdWLEntries));
            }
            else if (string.Equals(command, pluginConfig.Commands.UnshareCommand))
            {
                sb.AppendLine(string.Format(lang.GetMessage(DeletedWL, this, player.UserIDString), createdWLEntries));
            }

            return(sb.ToString());
        }
Пример #4
0
        private void cmdShareShort(BasePlayer player, string command, string[] args)
        {
            // Check Permission
            if (pluginConfig.General.UsePermission && !permission.UserHasPermission(player.UserIDString, "share.allowed"))
            {
                SendReply(player, lang.GetMessage(NoPermission, this, player.UserIDString));
                return;
            }

            // Check Syntax
            if (args == null || args.Length != 2 || (Array.IndexOf(WhatOptions, args[1].ToLower()) == -1))
            {
                SendReply(player, string.Format(lang.GetMessage(WrongSyntax, this, player.UserIDString), "/" + command + " " + string.Join(" ", args)));
                return;
            }

            // Decide with who to share
            List <BasePlayer> playerList;

            switch (args[0].ToLower())
            {
            case "clan":
                playerList = FindClanMember(player);
                if (playerList == null || playerList.Count == 0)
                {
                    SendReply(player, lang.GetMessage(NoClan, this, player.UserIDString));
                    return;
                }
                break;

            case "friends":
                playerList = FindFriends(player);
                if (playerList == null || playerList.Count == 0)
                {
                    SendReply(player, lang.GetMessage(NoFriends, this, player.UserIDString));
                    return;
                }
                break;

            default:
                BasePlayer foundPlayer = FindPlayer(args[0]);
                if (foundPlayer)
                {
                    playerList = new List <BasePlayer>();
                    playerList.Add(foundPlayer);
                    break;
                }
                else
                {
                    SendReply(player, string.Format(lang.GetMessage(Player404, this, player.UserIDString), args[0]));
                    return;
                }
            }

            // Check on what to auth
            WantedEntityType wantedType = (WantedEntityType)Enum.Parse(typeof(WantedEntityType), args[1].ToUpper());

            List <BaseEntity>[] items;
            items = FindWhat(player, pluginConfig.Commands.Radius, wantedType);


            // Check whether to add or to remove
            int counter = 0;

            if (string.Equals(command, pluginConfig.Commands.ShareCommand))
            {
                foreach (BasePlayer foundPlayer in playerList)
                {
                    if (foundPlayer == null)
                    {
                        continue;
                    }

                    foreach (AutoTurret at in items[0])
                    {
                        if (AddToWhiteList(at, foundPlayer))
                        {
                            counter++;
                        }
                    }
                    foreach (BaseEntity cl in items[1])
                    {
                        if (AddToWhiteList(cl.GetSlot(BaseEntity.Slot.Lock).GetComponent <CodeLock>(), foundPlayer))
                        {
                            counter++;
                        }
                    }
                    foreach (BuildingPrivlidge cb in items[2])
                    {
                        if (AddToWhiteList(cb, foundPlayer))
                        {
                            counter++;
                        }
                    }
                }
            }
            else if (string.Equals(command, pluginConfig.Commands.UnshareCommand))
            {
                foreach (BasePlayer foundPlayer in playerList)
                {
                    if (foundPlayer == null || (pluginConfig.General.PreventPlayersFromUnsharingThemself && foundPlayer.userID == player.userID))
                    {
                        continue;
                    }

                    foreach (AutoTurret at in items[0])
                    {
                        if (RemoveFromWhiteList(at, foundPlayer))
                        {
                            counter++;
                        }
                    }
                    foreach (BaseEntity cl in items[1])
                    {
                        if (RemoveFromWhiteList(cl.GetSlot(BaseEntity.Slot.Lock).GetComponent <CodeLock>(), foundPlayer))
                        {
                            counter++;
                        }
                    }
                    foreach (BuildingPrivlidge cb in items[2])
                    {
                        if (RemoveFromWhiteList(cb, foundPlayer))
                        {
                            counter++;
                        }
                    }
                }
            }

            // Respond to player what has been done
            SendReply(player, buildAnswer(player, counter, items[0].Count, items[1].Count, items[2].Count, command, wantedType));
        }