Exemplo n.º 1
0
        public MapItem PutItem(short amount, IItemInstance inv, ClientSession session)
        {
            Guid           random2       = Guid.NewGuid();
            MapItem        droppedItem   = null;
            List <MapCell> possibilities = new List <MapCell>();

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

            short mapX                 = 0;
            short mapY                 = 0;
            var   niceSpot             = false;
            var   orderedPossibilities = possibilities.OrderBy(_ => RandomFactory.Instance.RandomNumber()).ToList();

            for (var i = 0; i < orderedPossibilities.Count && !niceSpot; i++)
            {
                mapX = (short)(session.Character.PositionX + orderedPossibilities[i].X);
                mapY = (short)(session.Character.PositionY + orderedPossibilities[i].Y);
                if (Map.IsBlockedZone(session.Character.PositionX, session.Character.PositionY, mapX, mapY))
                {
                    continue;
                }

                niceSpot = true;
            }

            if (!niceSpot)
            {
                return(null);
            }

            if (amount <= 0 || amount > inv.Amount)
            {
                return(null);
            }

            var newItemInstance = (IItemInstance)inv.Clone();

            newItemInstance.Id     = random2;
            newItemInstance.Amount = amount;
            droppedItem            = new MapItem
            {
                MapInstance = this, ItemInstance = newItemInstance, PositionX = mapX, PositionY = mapY
            };
            DroppedList[droppedItem.VisualId] = droppedItem;
            inv.Amount -= amount;
            if (inv.Amount == 0)
            {
                session.Character.Inventory.DeleteById(inv.Id);
            }

            return(droppedItem);
        }
Exemplo n.º 2
0
        public MapItem?PutItem(short amount, IItemInstance inv, ClientSession session)
        {
            var     random2 = Guid.NewGuid();
            MapItem?droppedItem;
            var     possibilities = new List <(short X, short Y)>();

            for (short x = -1; x < 2; x++)
            {
                for (short y = -1; y < 2; y++)
                {
                    possibilities.Add((x, y));
                }
            }

            short mapX                 = 0;
            short mapY                 = 0;
            var   niceSpot             = false;
            var   orderedPossibilities = possibilities.OrderBy(_ => RandomHelper.Instance.RandomNumber()).ToList();

            for (var i = 0; (i < orderedPossibilities.Count) && !niceSpot; i++)
            {
                mapX = (short)(session.Character.PositionX + orderedPossibilities[i].X);
                mapY = (short)(session.Character.PositionY + orderedPossibilities[i].Y);
                if (Map.IsBlockedZone(session.Character.PositionX, session.Character.PositionY, mapX, mapY))
                {
                    continue;
                }

                niceSpot = true;
            }

            if (!niceSpot)
            {
                return(null);
            }

            if ((amount <= 0) || (amount > inv.Amount))
            {
                return(null);
            }

            var newItemInstance = (IItemInstance)inv.Clone();

            newItemInstance.Id             = random2;
            newItemInstance.Amount         = amount;
            droppedItem                    = _mapItemGenerationService.Create(this, newItemInstance, mapX, mapY);
            MapItems[droppedItem.VisualId] = droppedItem;
            inv.Amount -= amount;
            if (inv.Amount == 0)
            {
                session.Character.InventoryService !.DeleteById(inv.Id);
            }

            return(droppedItem);
        }