Exemplo n.º 1
0
        public void DropItemByMonster(long?Owner, DropDTO drop, short mapX, short mapY)
        {
            try
            {
                MapItem        droppedItem   = null;
                short          localMapX     = (short)(_random.Next(mapX - 1, mapX + 1));
                short          localMapY     = (short)(_random.Next(mapY - 1, mapY + 1));
                List <MapCell> Possibilities = new List <MapCell>();

                for (short x = -1; x < 2; x++)
                {
                    for (short y = -1; y < 2; y++)
                    {
                        Possibilities.Add(new MapCell()
                        {
                            X = x, Y = y
                        });
                    }
                }

                foreach (MapCell possibilitie in Possibilities.OrderBy(s => _random.Next()))
                {
                    localMapX = (short)(mapX + possibilitie.X);
                    localMapY = (short)(mapY + possibilitie.Y);
                    if (!IsBlockedZone(localMapX, localMapY))
                    {
                        break;
                    }
                }

                ItemInstance newInstance = InventoryList.CreateItemInstance(drop.ItemVNum);
                newInstance.Amount = drop.Amount;

                droppedItem = new MapItem(localMapX, localMapY)
                {
                    ItemInstance = newInstance,
                    Owner        = Owner
                };

                // rarify
                if (droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.Armor || droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.MainWeapon || droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.SecondaryWeapon)
                {
                    droppedItem.Rarify(null);
                }

                DroppedList.TryAdd(droppedItem.ItemInstance.TransportId, droppedItem);

                // TODO: UseTransportId
                Broadcast($"drop {droppedItem.ItemInstance.ItemVNum} {droppedItem.ItemInstance.TransportId} {droppedItem.PositionX} {droppedItem.PositionY} {droppedItem.ItemInstance.Amount} 0 0 -1");
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }
Exemplo n.º 2
0
        public void DropItemByMonster(long?Owner, DropDTO drop, short mapX, short mapY)
        {
            try
            {
                Random  rnd         = new Random((int)DateTime.Now.Ticks & 0x0000FFFF);
                MapItem droppedItem = null;
                short   localMapX   = (short)(rnd.Next(mapX - 1, mapX + 1));
                short   localMapY   = (short)(rnd.Next(mapY - 1, mapY + 1));
                while (IsBlockedZone(localMapX, localMapY))
                {
                    localMapX = (short)(rnd.Next(mapX - 1, mapX + 1));
                    localMapY = (short)(rnd.Next(mapY - 1, mapY + 1));
                }

                ItemInstance newInstance = InventoryList.CreateItemInstance(drop.ItemVNum);
                newInstance.Amount = drop.Amount;

                droppedItem = new MapItem(localMapX, localMapY)
                {
                    ItemInstance = newInstance,
                    Owner        = Owner
                };

                //rarify
                if (droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.Armor || droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.MainWeapon || droppedItem.ItemInstance.Item.EquipmentSlot == (byte)EquipmentType.SecondaryWeapon)
                {
                    droppedItem.Rarify(null);
                }

                DroppedList.TryAdd(droppedItem.ItemInstance.TransportId, droppedItem);

                Broadcast($"drop {droppedItem.ItemInstance.ItemVNum} {droppedItem.ItemInstance.TransportId} {droppedItem.PositionX} {droppedItem.PositionY} {droppedItem.ItemInstance.Amount} 0 0 -1");//TODO UseTransportId
            }
            catch (Exception e)
            {
                Logger.Error(e);
            }
        }