示例#1
0
 public static void SellItem(DigPlayer player, string itemName, int amount = 1)
 {
     InventoryItem item = ItemManager.GetItemFromName(itemName);
     if (item != null)
     {
         IShopItem shopItem = ItemManager.GetShopItemByName(itemName);
         if (shopItem != null)
         {
             int itemSellPrice = shopItem.SellPrice;
             if (player.Inventory.Contains(item) && player.Inventory.GetItemCount(item) >= amount)
             {
                 if (player.Inventory.RemoveItem(item, amount))
                 {
                     player.digMoney += itemSellPrice * amount;
                     string prefix = (amount > 1 ? "Items" : "Item");
                     player.Player.Reply(prefix + " sold! You received " + (itemSellPrice * amount) + " money.");
                 }
                 else
                     player.Player.Reply("Internal error, try doing that again.");
             }
             else
                 player.Player.Reply("You do not have enough of that item.");
         }
         else
             player.Player.Reply("You can't sell that item.");
     }
     else
     {
         if (itemName != "")
             player.Player.Reply("That item does not exist.");
     }
 }
示例#2
0
 public static void BuyItem(DigPlayer player, string itemName, int amount = 1)
 {
     InventoryItem item = ItemManager.GetItemFromName(itemName);
     IShopItem shopItem = ItemManager.GetShopItemByName(itemName);
     if (item != null && shopItem != null)
     {
         int totalItemPrice = shopItem.BuyPrice * amount;
         if (player.digMoney >= totalItemPrice)
         {
             player.digMoney -= totalItemPrice;
             player.Inventory.AddItem(new InventoryItem(item), amount);
             player.Player.Reply("You bought " + amount + " " + itemName + "!");
         }
         else
         {
             if (amount == 1)
                 player.Player.Reply("You need " + totalItemPrice + " money to buy that item.");
             else
                 player.Player.Reply("You need " + totalItemPrice + " money, " + shopItem.BuyPrice + " each, to buy those items.");
         }
     }
     else
     {
         if (itemName != "")
             player.Player.Reply("That item does not exist.");
         player.Player.Reply("You can buy these items:");
         List<InventoryItem> shopItems = ItemManager.GetBuyableItems();
         string temp = "";
         foreach (InventoryItem oitem in shopItems)
         {
             temp += oitem.Name + (shopItems.Last().Name.Equals(oitem.Name) ? "" : ", ");
         }
         player.Player.Send(temp);
     }
 }
示例#3
0
        static public void BuyItem(DigPlayer player, string itemName, int amount = 1)
        {
            InventoryItem item     = ItemManager.GetItemFromName(itemName);
            IShopItem     shopItem = ItemManager.GetShopItemByName(itemName);

            if (item != null && shopItem != null)
            {
                int totalItemPrice = shopItem.BuyPrice * amount;
                if (player.digMoney >= totalItemPrice)
                {
                    player.digMoney -= totalItemPrice;
                    player.Inventory.AddItem(new InventoryItem(item), amount);
                    player.Player.Reply("You bought " + amount + " " + itemName + "!");
                }
                else
                {
                    if (amount == 1)
                    {
                        player.Player.Reply("You need " + totalItemPrice + " money to buy that item.");
                    }
                    else
                    {
                        player.Player.Reply("You need " + totalItemPrice + " money, " + shopItem.BuyPrice + " each, to buy those items.");
                    }
                }
            }
            else
            {
                if (itemName != "")
                {
                    player.Player.Reply("That item does not exist.");
                }
                player.Player.Reply("You can buy these items:");
                List <InventoryItem> shopItems = ItemManager.GetBuyableItems();
                string temp = "";
                foreach (InventoryItem oitem in shopItems)
                {
                    temp += oitem.Name + (shopItems.Last().Name.Equals(oitem.Name) ? "" : ", ");
                }
                player.Player.Send(temp);
            }
        }
示例#4
0
        static public void SellItem(DigPlayer player, string itemName, int amount = 1)
        {
            InventoryItem item = ItemManager.GetItemFromName(itemName);

            if (item != null)
            {
                IShopItem shopItem = ItemManager.GetShopItemByName(itemName);
                if (shopItem != null)
                {
                    int itemSellPrice = shopItem.SellPrice;
                    if (player.Inventory.Contains(item) && player.Inventory.GetItemCount(item) >= amount)
                    {
                        if (player.Inventory.RemoveItem(item, amount))
                        {
                            player.digMoney += itemSellPrice * amount;
                            string prefix = (amount > 1 ? "Items" : "Item");
                            player.Player.Reply(prefix + " sold! You received " + (itemSellPrice * amount) + " money.");
                        }
                        else
                        {
                            player.Player.Reply("Internal error, try doing that again.");
                        }
                    }
                    else
                    {
                        player.Player.Reply("You do not have enough of that item.");
                    }
                }
                else
                {
                    player.Player.Reply("You can't sell that item.");
                }
            }
            else
            {
                if (itemName != "")
                {
                    player.Player.Reply("That item does not exist.");
                }
            }
        }
示例#5
0
        private void DigBlock(int x, int y, IPlayer player, float digStrength, bool mining, bool explosion = false)
        {
            if (digHardness == null)
            {
                resetDigHardness();
            }

            if (!(x > 0 && y > 0 && x < bot.Room.Width && y < bot.Room.Height))
            {
                return;
            }

            if (digHardness[x, y] <= 0)
            {
                return;
            }

            IBlock block   = bot.Room.getBlock(0, x, y);
            int    blockId = -1;
            float  blockXp = 0;

            DigPlayer digPlayer = null;

            if (player != null)
            {
                if (!player.HasMetadata("digplayer"))
                {
                    player.SetMetadata("digplayer", new DigPlayer(player));
                }

                digPlayer = (DigPlayer)player.GetMetadata("digplayer");
            }

            if (mining)
            {
                InventoryItem temp = ItemManager.GetItemFromOreId(block.Id);
                if (temp != null)
                {
                    Ore ore = ItemManager.GetOreByName(temp.Name);
                    blockId = 414;



                    if (digPlayer.digLevel >= Convert.ToInt32(ore.LevelRequired))
                    {
                        if (digHardness[x, y] <= digStrength)
                        {
                            digHardness[x, y] = 0F;

                            InventoryItem newsak = new InventoryItem(temp);

                            digPlayer.Inventory.AddItem(newsak, 1);
                            int oldLevel = digPlayer.digLevel;
                            digPlayer.digXp += Convert.ToInt32(ore.XPGain);
                            int newLevel = digPlayer.digLevel;
                            if (newLevel > oldLevel)
                            {
                                player.Reply("You have leveled up to level " + newLevel + "!");
                            }
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }

            if (explosion)
            {
                blockId = 414;
            }

            switch (block.Id)
            {
            case BlockIds.Blocks.Sand.BROWN:
                blockId = 414;
                blockXp = 0.08f;
                break;

            case BlockIds.Blocks.Sand.GRAY:
                blockId = 414;
                blockXp = 0.1f;
                break;

            case 1022:     // gray bricks
                blockId = 414;
                blockXp = 0.2f;
                break;

            case BlockIds.Blocks.JungleRuins.BLUE:
                blockId = BlockIds.Action.Liquids.WATER;
                blockXp = 0.1f;
                break;

            case 21:
                blockId = 369;     //BlockIds.Action.Liquids.MUD;
                blockXp = 0.1f;
                break;

            default:
                if (blockId == -1)
                {
                    return;
                }
                else
                {
                    break;
                }
            }

            digHardness[x, y] -= digStrength;

            if (digHardness[x, y] <= 0)
            {
                digHardness[x, y] = 0f;

                bot.Room.setBlock(x, y, new NormalBlock(blockId));
                lock (dugBlocksToPlaceQueueLock)
                    dugBlocksToPlaceQueue.Enqueue(new BlockWithPos(x, y, block));

                if (blockXp > 0 && digPlayer != null)
                {
                    digPlayer.digXp += blockXp;
                }
            }
        }
        public override void onMessage(PlayerIOClient.Message m)
        {
            switch (m.Type)
            {
            case "add":
            {
                IPlayer player = bot.Room.getPlayer(m.GetInt(0));
                if (player != null)
                {
                    player.SetMetadata("digplayer", new DigPlayer(player));
                }
            }
            break;

            case "init":
            case "reset":
                digHardness = new float[bot.Room.Width, bot.Room.Height];
                resetDigHardness();
                break;

            case "m":
            {
                int   userId     = m.GetInt(0);
                float playerPosX = m.GetFloat(1);
                float playerPosY = m.GetFloat(2);
                float speedX     = m.GetFloat(3);
                float speedY     = m.GetFloat(4);
                float modifierX  = m.GetFloat(5);
                float modifierY  = m.GetFloat(6);
                float horizontal = m.GetFloat(7);
                float vertical   = m.GetFloat(8);
                int   Coins      = m.GetInt(9);

                int blockX = (int)(playerPosX / 16 + 0.5);
                int blockY = (int)(playerPosY / 16 + 0.5);

                IPlayer player = bot.Room.getPlayer(userId);
                if (player == null || player.IsGod || player.IsMod)
                {
                    return;
                }

                if (!player.HasMetadata("digplayer"))
                {
                    player.SetMetadata("digplayer", new DigPlayer(player));
                }
                DigPlayer digPlayer = (DigPlayer)player.GetMetadata("digplayer");

                int digRange    = digPlayer.digRange;
                int digStrength = digPlayer.digStrength;

                int blockId = (bot.Room.getBlock(0, blockX + (int)horizontal, blockY + (int)vertical).Id);
                if (isDigable(blockId))                                //(blockId >= Skylight.BlockIds.Blocks.Sand.BROWN - 5 && blockId <= Skylight.BlockIds.Blocks.Sand.BROWN)
                {
                    if (digRange > 1)
                    {
                        for (int x = (horizontal == 1) ? -1 : -digRange + 1; x < ((horizontal == -1) ? 2 : digRange); x++)
                        {
                            for (int y = (vertical == 1) ? -1 : -digRange + 1; y < ((vertical == -1) ? 2 : digRange); y++)
                            {
                                float distance = (float)Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
                                if (distance <= 1.41421357 * (digRange - 1) || distance < 1.4142)
                                {
                                    DigBlock(blockX + x + (int)Math.Ceiling(horizontal), blockY + y + (int)Math.Ceiling(vertical), player, (digRange - distance) * digStrength, false);
                                }
                            }
                        }
                        AddUnsavedPlayer(player);
                        return;
                    }
                }
                {
                    if (horizontal == 0 || vertical == 0)
                    {
                        DigBlock(blockX + (int)horizontal, blockY + (int)vertical, player, digStrength, true);
                    }

                    blockId = bot.Room.getBlock(0, blockX, blockY).Id;
                    DigBlock(blockX, blockY, player, digStrength, true);
                    AddUnsavedPlayer(player);
                }
            }
            break;

            case "b":
            {
                int layer   = m.GetInt(0);
                int blockId = m.GetInt(3);
                int x       = m.GetInt(1);
                int y       = m.GetInt(2);

                if (layer == 0)
                {
                    resetBlockHardness(x, y, blockId);
                }
            }
            break;
            }
        }
        public override void onTick()
        {
            if (!bot.Room.HasCode)
            {
                return;
            }

            DigPlayer digPlayer = null;

            lock (playersToSave)
            {
                if (playersToSaveQueue.Count > 0)
                {
                    IPlayer player = playersToSaveQueue.Dequeue();
                    playersToSave.Remove(player);

                    digPlayer = (DigPlayer)player.GetMetadata("digplayer");
                }
            }
            if (digPlayer != null)
            {
                digPlayer.Save();
            }

            lock (dugBlocksToPlaceQueueLock)
            {
                while (dugBlocksToPlaceQueue.Count > bot.Room.Width * bot.Room.Height / 5)
                {
                    BlockWithPos block = dugBlocksToPlaceQueue.Dequeue();
                    if (digHardness[block.X, block.Y] == 0f)
                    {
                        bot.Room.setBlock(block.X, block.Y, block.Block);
                    }
                }
            }

            Pair <BlockPos, ItemDynamite> toRemove = null;

            List <Pair <BlockPos, ItemDynamite> > .Enumerator e = dynamites.GetEnumerator();
            while (e.MoveNext())
            {
                if ((DateTime.Now - e.Current.second.DatePlaced).Seconds >= 5)
                {
                    Random r        = new Random();
                    int    x        = e.Current.first.X;
                    int    y        = e.Current.first.Y;
                    float  strength = e.Current.second.Strength;
                    List <Pair <BlockWithPos, double> > blocksToRemove = new List <Pair <BlockWithPos, double> >();
                    for (int xx = (int)(x - strength); xx < x + strength; xx++)
                    {
                        for (int yy = (int)(y - strength); yy < y + strength; yy++)
                        {
                            double distanceFromCenter = Math.Sqrt(Math.Pow(x - xx, 2) + Math.Pow(y - yy, 2));
                            if (distanceFromCenter <= strength)
                            {
                                bool shouldRemove = (r.Next((int)((distanceFromCenter / strength) * 100)) <= 50 ? true : false);
                                if (shouldRemove)
                                {
                                    blocksToRemove.Add(new Pair <BlockWithPos, double>(new BlockWithPos(xx, yy, new NormalBlock(414, 0)), distanceFromCenter));

                                    if (e.Current.second.Placer != null)
                                    {
                                        int           blockIdReplaced = bot.Room.getBlock(0, xx, yy).Id;
                                        InventoryItem oreItem         = ItemManager.GetItemFromOreId(blockIdReplaced);
                                        if (oreItem != null && r.Next(4) == 0)
                                        {
                                            e.Current.second.Placer.Inventory.AddItem(oreItem, 1);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    blocksToRemove.Sort((s1, s2) => s1.second.CompareTo(s2.second));
                    bot.Room.setBlock(e.Current.first.X, e.Current.first.Y, new NormalBlock(414, 0));
                    foreach (var block in blocksToRemove)
                    {
                        DigBlock(block.first.X, block.first.Y, null, (int)Math.Floor(1 / block.second * 50) * ((float)r.Next(100) / 100 + 1), false, true);
                    }
                    blocksToRemove.Clear();


                    toRemove = e.Current;
                    break;
                }
            }
            if (toRemove != null)
            {
                dynamites.Remove(toRemove);
            }
        }
        public override void onCommand(string cmd, string[] args, ICmdSource cmdSource)
        {
            if (cmdSource is IPlayer && (IPlayer)cmdSource != null)
            {
                IPlayer   player    = (IPlayer)cmdSource;
                DigPlayer digPlayer = DigPlayer.FromPlayer(player);

                AddUnsavedPlayer(player);

                switch (cmd)
                {
                case "dynamite":
                {
                    ItemDynamite dynamite = new ItemDynamite();
                    dynamite.Placer = digPlayer;
                    if (digPlayer.Inventory.RemoveItem(dynamite, 1) || player.IsGod)
                    {
                        bot.ChatSayer.Say(player.Name + " has placed a big barrel of dynamite! Hide!!");
                        bot.Room.setBlock(player.BlockX, player.BlockY, new NormalBlock(163, 0));
                        dynamites.Add(
                            new Pair <BlockPos, ItemDynamite>(new BlockPos(0, player.BlockX, player.BlockY), dynamite)
                            );
                    }
                    else
                    {
                        player.Reply("You have no dynamite! Buy it at the shop.");
                    }
                }
                break;

                case "dig":
                case "help":
                case "commands":
                case "digcommands":
                    player.Reply("Here are the commands: !xp, !level, !inventory, !xpleft, !buy, !sell, !money, !levelforores, !save");
                    break;

                case "levelforores":
                {
                    string total = "";
                    foreach (Ore ore in ItemManager.GetOres())
                    {
                        total += ore.Name + ": " + ore.LevelRequired + (ItemManager.GetOres().Last().Name.Equals(ore.Name) ? "" : ", ");
                    }
                    player.Reply(total);
                }
                break;

                case "generate":
                    if (player.IsOp)
                    {
                        int seed = -1;

                        if (args.Length >= 1)
                        {
                            Int32.TryParse(args[0], out seed);
                        }
                        if (seed == -1)
                        {
                            seed = random.Next();
                        }

                        bot.ChatSayer.Say("Generating new map with seed " + seed + ".");
                        digHardness = new float[bot.Room.Width, bot.Room.Height];
                        Generate(bot.Room.Width, bot.Room.Height, seed);
                    }
                    break;

                case "worm":
                    if (player.IsOp)
                    {
                        zombies.SpawnZombie(player.BlockX, player.BlockY);
                        player.Reply("Worm spawned.");
                    }
                    break;

                case "givexp":
                    if (player.IsOp && args.Length >= 2)
                    {
                        IPlayer receiver = bot.Room.getPlayer(args[0]);
                        if (receiver != null)
                        {
                            int xp = Int32.Parse(args[1]);
                            if (!receiver.HasMetadata("digplayer"))
                            {
                                receiver.SetMetadata("digplayer", new DigPlayer(receiver));
                            }
                            DigPlayer receiverDigPlayer = (DigPlayer)receiver.GetMetadata("digplayer");
                            receiverDigPlayer.digXp += xp;
                            AddUnsavedPlayer(receiver);
                        }
                        else
                        {
                            player.Reply("That player doesn't exist.");
                        }
                    }
                    else
                    {
                        player.Reply("Usage: !givexp <player> <xp>");
                    }
                    break;

                case "setxp":
                    if (player.IsOp && args.Length >= 2)
                    {
                        IPlayer receiver = bot.Room.getPlayer(args[0]);
                        if (receiver != null)
                        {
                            int xp = Int32.Parse(args[1]);
                            if (!receiver.HasMetadata("digplayer"))
                            {
                                receiver.SetMetadata("digplayer", new DigPlayer(receiver));
                            }
                            DigPlayer receiverDigPlayer = (DigPlayer)receiver.GetMetadata("digplayer");
                            receiverDigPlayer.digXp = xp;
                            AddUnsavedPlayer(receiver);
                        }
                        else
                        {
                            player.Reply("That player doesn't exist.");
                        }
                    }
                    else
                    {
                        player.Reply("Usage: !setxp <player> <xp>");
                    }
                    break;

                case "givemoney":
                    if (player.IsOp && args.Length >= 2)
                    {
                        IPlayer receiver = bot.Room.getPlayer(args[0]);
                        if (receiver != null)
                        {
                            int money = Int32.Parse(args[1]);
                            if (!receiver.HasMetadata("digplayer"))
                            {
                                receiver.SetMetadata("digplayer", new DigPlayer(receiver));
                            }
                            DigPlayer receiverDigPlayer = (DigPlayer)receiver.GetMetadata("digplayer");
                            receiverDigPlayer.digMoney += money;
                            AddUnsavedPlayer(receiver);
                        }
                        else
                        {
                            player.Reply("That player doesn't exist.");
                        }
                    }
                    else
                    {
                        player.Reply("Usage: !givemoney <player> <money>");
                    }
                    break;

                case "setmoney":
                    if (player.IsOp && args.Length >= 2)
                    {
                        IPlayer receiver = bot.Room.getPlayer(args[0]);
                        if (receiver != null)
                        {
                            int money = Int32.Parse(args[1]);
                            if (!receiver.HasMetadata("digplayer"))
                            {
                                receiver.SetMetadata("digplayer", new DigPlayer(receiver));
                            }
                            DigPlayer receiverDigPlayer = (DigPlayer)receiver.GetMetadata("digplayer");
                            receiverDigPlayer.digMoney = money;
                            AddUnsavedPlayer(receiver);
                        }
                        else
                        {
                            player.Reply("That player doesn't exist.");
                        }
                    }
                    else
                    {
                        player.Reply("Usage: !setmoney <player> <money>");
                    }
                    break;

                case "xp":
                    player.Reply("XP: " + digPlayer.digXp);
                    break;

                case "xpleft":
                    player.Reply("You need " + (digPlayer.xpRequired_ - digPlayer.digXp).ToString() + " XP for level " + (digPlayer.digLevel + 1).ToString());
                    break;

                case "level":
                    player.Reply("Level: " + digPlayer.digLevel);
                    break;

                case "inventory":
                    player.Reply(digPlayer.Inventory.ToString());
                    break;

                case "save":
                    player.Reply("Saved!");
                    digPlayer.Save();
                    break;

                case "setshop":
                    if (player.IsOp)
                    {
                        Shop.SetLocation(player.BlockX, player.BlockY);
                        player.Reply("Shop set at X:" + player.BlockX + " Y:" + player.BlockY);
                    }
                    break;

                case "money":
                    player.Reply("Money: " + digPlayer.digMoney);
                    break;

                case "buy":
                    if (Shop.IsPlayerClose(player))
                    {
                        if (args.Length >= 1)
                        {
                            string itemName = args[0].ToLower();
                            int    amount   = 1;

                            if (args.Length >= 2)
                            {
                                if (!int.TryParse(args[1], out amount))
                                {
                                    amount = 1;
                                }
                            }

                            if (amount < 1)
                            {
                                player.Reply("You can't buy a negative amount of items.");
                                break;
                            }

                            Shop.BuyItem(digPlayer, itemName, amount);
                        }
                        else
                        {
                            player.Reply("Usage: !buy <item> [amount=1]");
                            Shop.BuyItem(digPlayer, "", 0);
                        }
                    }
                    else
                    {
                        player.Reply("You aren't near the shop.");
                    }
                    break;

                case "sell":
                    if (Shop.IsPlayerClose(player))
                    {
                        if (args.Length >= 1)
                        {
                            string itemName = args[0].ToLower();
                            int    amount   = 1;

                            if (args.Length >= 2)
                            {
                                if (!int.TryParse(args[1], out amount))
                                {
                                    amount = 1;
                                }
                            }

                            if (amount < 1)
                            {
                                player.Reply("You can't buy a negative amount of items.");
                                break;
                            }

                            Shop.SellItem(digPlayer, itemName, amount);
                        }
                        else
                        {
                            player.Reply("Usage: !sell <item> [amount=1]");
                            Shop.SellItem(digPlayer, "", 0);
                        }
                    }
                    else
                    {
                        player.Reply("You aren't near the shop.");
                    }
                    break;
                }
            }
        }