Beispiel #1
0
        void GiveInventoryStack(Player player, string itemname, int qty)
        {
            var inventory        = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);
            var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(itemname, true, true);
            var invGameItemStack = new InvGameItemStack(blueprintForName, qty, null);

            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
        }
Beispiel #2
0
        private void GetItemsFromSavedInventory(Player target, Collection <string[]> savedContents)
        {
            var inventory = target.GetInventory();

            foreach (var savedItem in savedContents)
            {
                var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(savedItem[0], true, true);
                var invGameItemStack = new InvGameItemStack(blueprintForName, Int32.Parse(savedItem[1]), null);
                ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
            }
        }
Beispiel #3
0
        void GiveKit(Player player, KitData kit)
        {
            if (kit.Items.Count == 0)
            {
                return;
            }

            var inventory = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);

            if (inventory.Contents.FreeSlotCount < kit.Stacks)
            {
                SendMessage(player, KitNoRoom, kit.Name, kit.Stacks);
                return;
            }

            if (!CanRedeemKit(player, kit))
            {
                return;
            }

            foreach (var iteminfo in kit.Items)
            {
                var blueprintForName    = InvDefinitions.Instance.Blueprints.GetBlueprintForName(iteminfo.Name, true, true);
                var containerManagement = blueprintForName.TryGet <ContainerManagement>();
                var stackLimit          = containerManagement?.StackLimit ?? 0;
                var amount      = iteminfo.Amount;
                var amountGiven = 0;
                while (amountGiven < amount)
                {
                    var amountToGive     = Mathf.Min(stackLimit, amount - amountGiven);
                    var invGameItemStack = new InvGameItemStack(blueprintForName, amountToGive, null);
                    if (!ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack))
                    {
                        var stackAmount = amountToGive - invGameItemStack.StackAmount;
                        if (stackAmount != 0)
                        {
                            amountGiven += stackAmount;
                        }
                    }
                    else
                    {
                        amountGiven += amountToGive;
                    }

                    if (inventory.Contents.FreeSlotCount == 0)
                    {
                        break;
                    }
                }
            }

            SendMessage(player, KitRedeemed, kit.Name);
        }
        private void GivePoa(Player player, Options selection)
        {
            if (selection != Options.Yes)
            {
                return;
            }

            var inventory        = player.GetInventory().Contents;
            var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName("Potion of appearance", true, true);
            var invGameItemStack = new InvGameItemStack(blueprintForName, 1, null);

            inventory.AddItem(invGameItemStack);
        }
Beispiel #5
0
        void giveItems(Player player, int multiplier, string resource)
        {
            var playerName       = player.Name;
            var inventory        = player.GetInventory();
            var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(resource, true, true);
            int amountToGive     = multiplier * amount;
            var invGameItemStack = new InvGameItemStack(blueprintForName, amountToGive, null);

            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);

            if (amountToGive > 0)
            {
                SendReply(player, "Thanks for voting " + multiplier + " times, you have received " + amountToGive + " stone", player.DisplayName);
            }
        }
        // THIS CONTROLS WHEN A PLAYER IS KILLED
        private void OnEntityDeath(EntityDeathEvent deathEvent)
        {
            if (deathEvent.Entity.IsPlayer)
            {
                var killer = deathEvent.KillingDamage.DamageSource.Owner;
                var player = deathEvent.Entity.Owner;

                // Check for bounties
                var reward = GetBountyOnPlayer(player);
                if (reward.Count < 1)
                {
                    return;
                }

                // Make sure the player is not in the same guild
                if (player.GetGuild().Name == killer.GetGuild().Name)
                {
                    PrintToChat("[FF0000]Assassin's Guild[FFFFFF] : [00FF00]" + player.DisplayName + "[FFFFFF] was slain by a member of the same guild, so no bounty was collected!");
                    return;
                }

                // Get the inventory
                var inventory = killer.GetInventory();

                // Give the rewards to the player
                foreach (var bounty in reward)
                {
                    var resource = bounty[0];
                    var amount   = Int32.Parse(bounty[1]);
                    PrintToChat("Reward = " + resource + " " + amount.ToString());
                    // Create a blueprint
                    var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(resource, true, true);
                    // Create item stack
                    var invGameItemStack = new InvGameItemStack(blueprintForName, amount, null);
                    // Add the reward to the inventory
                    ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
                }

                // Notify everyone
                PrintToChat("[FF0000]Assassin's Guild[FFFFFF] : [00FF00]" + killer.DisplayName + "[FFFFFF] has ended [FF00FF]" + player.DisplayName + "[FFFFFF]'s life and has secured the bounty on their head!");
            }
        }
Beispiel #7
0
        private object GiveItem(IPlayer target, string itemNameOrId, int amount = 1, string container = "main")
        {
            if (config.ItemBlacklist.Contains(itemNameOrId.ToLower()))
            {
                return(null);
            }

            string itemName = itemNameOrId;

#if HURTWORLDITEMV2
            PlayerSession      session   = target.Object as PlayerSession;
            PlayerInventory    inventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>();
            ItemGeneratorAsset generator = FindItem(itemNameOrId);

            ItemObject itemObj;
            if (generator.IsStackable())
            {
                itemObj = GlobalItemManager.Instance.CreateItem(generator, amount);
                if (!inventory.GiveItemServer(itemObj))
                {
                    GlobalItemManager.SpawnWorldItem(itemObj, inventory);
                }
            }
            else
            {
                int amountGiven = 0;
                while (amountGiven < amount)
                {
                    itemObj = GlobalItemManager.Instance.CreateItem(generator);
                    if (!inventory.GiveItemServer(itemObj))
                    {
                        GlobalItemManager.SpawnWorldItem(itemObj, inventory);
                    }
                    amountGiven++;
                }
            }
#elif HURTWORLD
            PlayerSession   session   = target.Object as PlayerSession;
            PlayerInventory inventory = session.WorldPlayerEntity.GetComponent <PlayerInventory>();
            GlobalItemManager.Instance.GiveItem(session.Player, FindItem(itemNameOrId), amount);
#elif REIGNOFKINGS
            Player player = target.Object as Player;
            if (player == null)
            {
                return(false);
            }

            Container itemContainer = null;
            switch (container.ToLower())
            {
            case "belt":
                itemContainer = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Hotbar);
                break;

            case "main":
                itemContainer = player.CurrentCharacter.Entity.GetContainerOfType(CollectionTypes.Inventory);
                break;
            }

            InvItemBlueprint blueprint = InvDefinitions.Instance.Blueprints.GetBlueprintForName(itemName, true, true);
            if (blueprint == null)
            {
                return(false);
            }

            ContainerManagement containerManagement = blueprint.TryGet <ContainerManagement>();
            int stackableAmount = containerManagement != null ? containerManagement.StackLimit : 0;
            int amountGiven     = 0;
            while (amountGiven < amount)
            {
                int amountToGive           = Mathf.Min(stackableAmount, amount - amountGiven);
                InvGameItemStack itemStack = new InvGameItemStack(blueprint, amountToGive, null);
                if (!ItemCollection.AutoMergeAdd(itemContainer.Contents, itemStack))
                {
                    int stackAmount = amountToGive - itemStack.StackAmount;
                    if (stackAmount != 0)
                    {
                        amountGiven += stackAmount;
                    }
                    else
                    {
                        break;
                    }
                }
                else
                {
                    amountGiven += amountToGive;
                }
                if (itemContainer.Contents.FreeSlotCount == 0)
                {
                    break;
                }
            }
#elif RUST
            Item item = ItemManager.Create(FindItem(itemNameOrId));
            if (item == null)
            {
                return(false);
            }

            item.amount = amount;

            BasePlayer basePlayer = target.Object as BasePlayer;
            if (basePlayer == null)
            {
                return(false);
            }

            ItemContainer itemContainer = null;
            switch (container.ToLower())
            {
            case "belt":
                itemContainer = basePlayer.inventory.containerBelt;
                break;

            case "main":
                itemContainer = basePlayer.inventory.containerMain;
                break;
            }

            if (!basePlayer.inventory.GiveItem(item, itemContainer))
            {
                item.Remove();
                return(false);
            }

            itemName = item.info.displayName.english;

            if (config.ShowPopupNotices)
            {
                target.Command("note.inv", item.info.itemid, amount);
                target.Command("gametip.showgametip", Lang("ItemReceived", target.Id, itemName, amount));
                timer.Once(2f, () => target.Command("gametip.hidegametip"));
            }
#endif
            if (config.ShowChatNotices)
            {
                Message(target, "ItemReceived", itemName, amount);
            }

            if (config.LogToConsole)
            {
                Log($"{target.Name} {amount} x {itemName}");
            }

            return(true);
        }
Beispiel #8
0
        private void GiveDailyRewards(Player player, string cmd, string[] playerString)
        {
            if (!player.HasPermission("admin") && !PlayerIsOnTheList(player.Name))
            {
                PrintToChat(player, "Only admins or designated vote-reward givers can give daily awards."); return;
            }
            if (playerString.Length <= 0)
            {
                PrintToChat(player, "You need to specifiy a player to give the rewards to."); return;
            }

            // Convert the player name string array to a string
            var targetPlayerName = playerString[0];

            if (playerString.Length > 1)
            {
                for (var i = 1; i < playerString.Length; i++)
                {
                    targetPlayerName = string.Format(targetPlayerName + " {0}", playerString[i]);
                }
            }

            // Find the chosen target player
            Player targetPlayer = Server.GetPlayerByName(targetPlayerName);

            if (targetPlayer == null)
            {
                PrintToChat(player, "That player doesn't appear to be online right now.");
                return;
            }

            if (targetPlayerName.ToLower() == player.Name.ToLower())
            {
                // Trying to give resources to self!
                if (!player.HasPermission("admin"))
                {
                    PrintToChat(player, "Only admins can give daily resources to themselves!");
                    return;
                }
            }

            var inventory = targetPlayer.GetInventory();

            if (inventory.Contents.FreeSlotCount < 5)
            {
                PrintToChat(player, "That player doesn't have enough space to receive the rewards! Give 'em hell!");
                return;
            }

            // GIVE WOOD
            var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName("Wood", true, true);
            // STACK OF 1000
            var invGameItemStack = new InvGameItemStack(blueprintForName, 1000, null);

            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
            // STACK OF 500
            invGameItemStack = new InvGameItemStack(blueprintForName, 500, null);
            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);

            // GIVE STONE
            blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName("Stone", true, true);
            // STACK OF 1000
            invGameItemStack = new InvGameItemStack(blueprintForName, 1000, null);
            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
            // STACK OF 500
            invGameItemStack = new InvGameItemStack(blueprintForName, 500, null);
            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);

            // GIVE IRON
            blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName("Iron", true, true);
            // STACK OF 1000
            invGameItemStack = new InvGameItemStack(blueprintForName, 1000, null);
            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);

            // GIVE DIAMOND
            blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName("Diamond", true, true);
            // STACK OF 2
            invGameItemStack = new InvGameItemStack(blueprintForName, 2, null);
            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);


            PrintToChat("[FF0000]Vote Rewards [FFFFFF]: The daily rewards have been given to [00FF00]" + targetPlayerName + "[FFFFFF] for voting.");
        }
Beispiel #9
0
        void giveItems(Player player, int voteCount)
        {
            Debug(1, "Votecount passed to giveitems is " + voteCount);
            var playerName = player.Name;
            var playerId   = player.Id;
            var inventory  = player.GetInventory();


            var tmplastVote = Users.Where(d => d.steamid == playerId).FirstOrDefault();

            //Debug(1, "The lastvotecount before checks is " + tmplastVote.lastvote);

            if (tmplastVote == null)
            {
                Debug(1, "LastVote is null for user, recreate.");
                Users.Add(new LastVote((ulong)playerId, 0));
                SaveVotes();
            }
            else
            {
                if (tmplastVote.lastvote > voteCount)
                {
                    tmplastVote.lastvote = 0;
                }
                ;                                                                    //this means to interval has reset
            }
            //Debug(1, "The lastvotecount after checks is " + tmplastVote.lastvote);

            tmplastVote = Users.Where(d => d.steamid == playerId).FirstOrDefault();

            //Debug(1, "The lastvotecount after select is " + tmplastVote.lastvote);

            int LastVote = tmplastVote.lastvote;

            if (voteCount == 0 || voteCount == LastVote)
            {
                PrintToChat(player, "You have no new rewards, please vote for our server to receive rewards.");
                if ((string)Config["tgsApi"] != null || (string)Config["tgsApi"] != "")
                {
                    PrintToChat(player, (string)Config["tgsAddress"]);
                }
                if ((string)Config["serverId"] != null || (string)Config["serverId"] != "")
                {
                    PrintToChat(player, "http://reign-of-kings.net/server/" + Config["serverId"] + "/");
                }
                return;
            }

            var RewardsLimited = from p in Rewards.ToList() where (p.votesRequired > LastVote && p.votesRequired <= voteCount) || p.votesRequired == -1 select p;

            Debug(1, "RewardsLimited contains " + RewardsLimited.Count() + " rewards and isnull? " + (RewardsLimited == null));

            foreach (var voteReward in RewardsLimited)
            {
                var votesNeeded    = voteReward.votesRequired;
                int resourceAmount = voteReward.itemAmount;

                if (voteReward.itemName.ToLower() == "gold" && LastVote < voteCount)
                {
                    if (plugins.Exists("GrandExchange"))
                    {
                        GrandExchange.Call("GiveGold", new object[] { player, voteReward.itemAmount });
                        PrintToChat(player, "[00FF00]" + voteReward.itemAmount + "[FFFF00] gold[FFFFFF] reward received.");
                    }
                    else
                    {
                        Puts("VoteChecker Error: Grand Exchange doesn't appeear to be installed or loaded. You can't use the gold reward");
                    }
                }
                else
                {
                    var resource     = InvDefinitions.Instance.Blueprints.GetBlueprintForName(voteReward.itemName, true, true);
                    int amountToGive = resourceAmount;
                    Debug(1, "Should we give? amnt:" + amountToGive + " vtneed:" + votesNeeded + " vtcnt:" + voteCount + " lstvote: " + LastVote);

                    if (amountToGive > 0 && voteReward.itemName.ToLower() != "gold" && LastVote < voteCount)
                    {
                        int remainderToGive = amountToGive;

                        while (remainderToGive > 0)
                        {
                            var maxStackSize = 1000;
                            var stackToGive  = maxStackSize;

                            if (remainderToGive <= maxStackSize)
                            {
                                stackToGive = remainderToGive;
                            }

                            var invGameItemStack = new InvGameItemStack(resource, stackToGive, null);
                            ItemCollection.AutoMergeAdd(inventory.Contents, invGameItemStack);
                            remainderToGive -= maxStackSize;
                        }
                        PrintToChat(player, "Thanks for voting " + voteCount + " times, you have received " + amountToGive + " " + voteReward.itemName);
                    }
                }
            }

            if (tmplastVote != null)
            {
                tmplastVote.lastvote = voteCount; Debug(1, "Storing users last vote, ");
            }                                                                                                     //else { Users.Add(new LastVote(playerId, voteCount)); }
            //possible fix v
            foreach (var e in Users.Where(a => a.steamid == (ulong)player.Id))
            {
                e.lastvote = voteCount;
            }
            //possible fix ^

            timesVoted = 0;
        }
Beispiel #10
0
        void cmdPGive(Player player, string cmd, string[] args)
        {
            if (!permission.UserHasPermission(player.Id.ToString(), "cangive"))
            {
                SendReply(player, "You do not have permission to use this command!");
                return;
            }
            switch (args[0])
            {
            default:
                if (args.Length == 2)
                {
                    var blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(args[0].ToString(), true, true);
                    var inventory        = player.GetInventory().Contents;
                    if (blueprintForName == null)
                    {
                        SendReply(player, "Could not find blueprint for {0}.", args[0].ToString());
                        return;
                    }
                    if (inventory.FreeSlotCount == 0)
                    {
                        SendReply(player, "You dont have enough space in your inventory!");
                        return;
                    }
                    int amount           = Convert.ToInt32(args[1]);
                    var invGameItemStack = new InvGameItemStack(blueprintForName, amount, null);
                    ItemCollection.AutoMergeAdd(inventory, invGameItemStack);
                    SendReply(player, "You have received {0} {1}.", blueprintForName.Name, amount.ToString());
                }
                else
                {
                    SendReply(player, "/pgive <ItemName> <ItemStack>");
                    return;
                }
                break;

            case "to":
                if (args.Length == 4)
                {
                    Player target           = Server.GetPlayerByName(args[1]);
                    var    blueprintForName = InvDefinitions.Instance.Blueprints.GetBlueprintForName(args[2].ToString(), true, true);
                    var    inventory        = target.GetInventory().Contents;
                    if (blueprintForName == null)
                    {
                        SendReply(player, "Could not find blueprint for {0}.", args[2].ToString());
                        return;
                    }
                    if (inventory.FreeSlotCount == 0)
                    {
                        SendReply(player, "You dont have enough space in your inventory!");
                        return;
                    }
                    if (target == null)
                    {
                        SendReply(player, "Player not found!");
                        return;
                    }
                    int amount           = Convert.ToInt32(args[3]);
                    var invGameItemStack = new InvGameItemStack(blueprintForName, amount, null);
                    ItemCollection.AutoMergeAdd(inventory, invGameItemStack);
                    SendReply(target, "You have received {1} {0}.", blueprintForName.Name, amount.ToString());
                    SendReply(player, "You gave {0} {2} {1}.", target.DisplayName, blueprintForName.Name, amount.ToString());
                }
                else
                {
                    SendReply(player, "/pgive to <TargetPlayer> <ItemName> <ItemStack> ");
                    return;
                }
                break;

            case "help":
                SendReply(player, "/pgive to <PlayerName> <ItemName> <ItemStack> => Gives the item and the amount to the target.");
                SendReply(player, "/pgive <ItemName> <ItemStack> => Gives the item and the amount to the player who used the command.");
                break;
            }
        }