Ejemplo n.º 1
0
        public virtual void SetHeldItemSlot(int selectedHotbarSlot, bool sendToPlayer = true)
        {
            InHandSlot = selectedHotbarSlot;

            if (sendToPlayer)
            {
                McpeMobEquipment order = McpeMobEquipment.CreateObject();
                order.runtimeEntityId = EntityManager.EntityIdSelf;
                order.item            = GetItemInHand();
                order.selectedSlot    = (byte)InHandSlot;
                order.slot            = (byte)(InHandSlot + HotbarSize);
                Player.SendPacket(order);
            }

            McpeMobEquipment broadcast = McpeMobEquipment.CreateObject();

            broadcast.runtimeEntityId = Player.EntityId;
            broadcast.item            = GetItemInHand();
            broadcast.selectedSlot    = (byte)InHandSlot;
            broadcast.slot            = (byte)(InHandSlot + HotbarSize);
            Player.Level?.RelayBroadcast(Player, broadcast);
        }
Ejemplo n.º 2
0
        public static void SendEnchantments(Player player, Item itemToEnchant)
        {
            if (itemToEnchant.ExtraData != null)
            {
                SendEmptyEnchantments(player);
                return;
            }

            var          rnd          = new Random();
            ItemType     itemType     = itemToEnchant.ItemType;
            ItemMaterial itemMaterial = itemToEnchant.ItemMaterial;

            int noBookshelves   = 15;
            int baseLevel       = (int)(rnd.Next(1, 9) + Math.Floor(noBookshelves / 2.0) + rnd.Next(0, noBookshelves + 1));
            int topSlotLevel    = (int)Math.Max(Math.Floor(baseLevel / 3.0), 1);
            int middleSlotLevel = (int)Math.Floor((baseLevel * 2) / 3.0) + 1;
            int bottomSlotLevel = (int)Math.Max(baseLevel, noBookshelves * 2);

            Log.Warn($"Enchanting values; baseLevel:{baseLevel}, top:{topSlotLevel}, middle:{middleSlotLevel}, bottom:{bottomSlotLevel}");

            // armor
            var armorTypes = new List <ItemType>
            {
                ItemType.Helmet,
                ItemType.Chestplate,
                ItemType.Leggings,
                ItemType.Boots
            };

            int enchantability = itemToEnchant switch
            {
                { } item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Leather => 15,
                {
                }

                item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Chain => 12,
                {
                }

                item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Iron => 9,
                {
                }

                item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Gold => 25,
                {
                }

                item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Diamond => 10,
                {
                }

                item when armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Netherite => 15,

                {
                }

                item     when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Wood => 15,
                { } item when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Stone => 5,
                { } item when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Iron => 14,
                { } item when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Gold => 22,
                { } item when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Diamond => 10,
                { } item when !armorTypes.Contains(item.ItemType) && item.ItemMaterial == ItemMaterial.Netherite => 15,

                _ => 1
            };
            int    randomEnchantability = 1 + rnd.Next(0, (int)Math.Floor(enchantability / 4.0) + 1) + rnd.Next(0, (int)Math.Floor(enchantability / 4.0) + 1);
            double randomBonus          = 1 + (rnd.NextDouble() + rnd.NextDouble() - 1) * 0.15;
            int    finalTopLevel        = (int)Math.Round((topSlotLevel + randomEnchantability) * randomBonus);
            int    finalMiddleLevel     = (int)Math.Round((middleSlotLevel + randomEnchantability) * randomBonus);
            int    finalBottomLevel     = (int)Math.Round((bottomSlotLevel + randomEnchantability) * randomBonus);

            Log.Warn($"Enchantability: {enchantability}");
            Log.Warn($"Random Bonus: {randomBonus}");
            Log.Warn($"Final: top:{finalTopLevel}, middle:{finalMiddleLevel}, bottom:{finalBottomLevel}");

            var topFinalEnchants    = new List <Enchant>();
            var middleFinalEnchants = new List <Enchant>();
            var bottomFinalEnchants = new List <Enchant>();

            Enchant topEnchant = SelectEnchant(GetPossibleEnchantsForItem(itemType, finalTopLevel), rnd);

            topFinalEnchants.Add(topEnchant);
            Enchant middleEnchant = SelectEnchant(GetPossibleEnchantsForItem(itemType, finalMiddleLevel), rnd);

            middleFinalEnchants.Add(middleEnchant);
            Enchant bottomEnchant = SelectEnchant(GetPossibleEnchantsForItem(itemType, finalBottomLevel), rnd);

            bottomFinalEnchants.Add(bottomEnchant);

            AddBonusEnchants(topFinalEnchants, rnd, finalTopLevel, itemType);
            AddBonusEnchants(middleFinalEnchants, rnd, finalMiddleLevel, itemType);
            AddBonusEnchants(bottomFinalEnchants, rnd, finalBottomLevel, itemType);

            if (topFinalEnchants.Count > 1)
            {
                Log.Warn($"Got {topFinalEnchants.Count} enchants on top");
            }
            if (middleFinalEnchants.Count > 1)
            {
                Log.Warn($"Got {middleFinalEnchants.Count} enchants in middle");
            }
            if (bottomFinalEnchants.Count > 1)
            {
                Log.Warn($"Got {bottomFinalEnchants.Count} enchants at bottom");
            }

            // do bonus

            var enchantOptions = McpePlayerEnchantOptions.CreateObject();

            enchantOptions.enchantOptions = new EnchantOptions
            {
                new EnchantOption
                {
                    Cost     = topEnchant.Cost,
                    Name     = GetRandomName(rnd),
                    OptionId = 1,
                    EquipActivatedEnchantments = topFinalEnchants,
                },
                new EnchantOption
                {
                    Cost     = middleEnchant.Cost,
                    Name     = GetRandomName(rnd),
                    OptionId = 2,
                    EquipActivatedEnchantments = middleFinalEnchants,
                },
                new EnchantOption
                {
                    Cost     = bottomEnchant.Cost,
                    Name     = GetRandomName(rnd),
                    OptionId = 3,
                    EquipActivatedEnchantments = bottomFinalEnchants,
                },
            };
            player.SendPacket(enchantOptions);
        }