コード例 #1
0
ファイル: Map.cs プロジェクト: Uportorst/OpenNos
        public MapItem PutItem(InventoryType type, short slot, byte amount, ref ItemInstance inv, ClientSession session)
        {
            Logger.Debug($"type: {type} slot: {slot} amount: {amount}", session.SessionId);
            Guid           random2       = Guid.NewGuid();
            MapItem        droppedItem   = null;
            List <GridPos> Possibilities = new List <GridPos>();

            for (short x = -2; x < 3; x++)
            {
                for (short y = -2; y < 3; y++)
                {
                    Possibilities.Add(new GridPos()
                    {
                        x = x, y = y
                    });
                }
            }

            short mapX     = 0;
            short mapY     = 0;
            bool  niceSpot = false;

            foreach (GridPos possibilitie in Possibilities.OrderBy(s => _random.Next()))
            {
                mapX = (short)(session.Character.MapX + possibilitie.x);
                mapY = (short)(session.Character.MapY + possibilitie.y);
                if (!IsBlockedZone(mapX, mapY))
                {
                    niceSpot = true;
                    break;
                }
            }

            if (niceSpot)
            {
                if (amount > 0 && amount <= inv.Amount)
                {
                    ItemInstance newItemInstance = inv.DeepCopy();
                    newItemInstance.Id     = random2;
                    newItemInstance.Amount = amount;
                    droppedItem            = new CharacterMapItem(mapX, mapY, newItemInstance);

                    DroppedList[droppedItem.TransportId] = droppedItem;
                    inv.Amount -= amount;
                }
            }
            return(droppedItem);
        }
コード例 #2
0
        public MapItem PutItem(InventoryType type, short slot, short amount, ref ItemInstance inv, ClientSession session)
        {
            Logger.LogUserEventDebug("PUTITEM", session.GenerateIdentity(), $"type: {type} slot: {slot} amount: {amount}");
            Guid           random2       = Guid.NewGuid();
            MapItem        droppedItem   = null;
            List <GridPos> possibilities = new List <GridPos>();

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

            short mapX     = 0;
            short mapY     = 0;
            bool  niceSpot = false;

            foreach (GridPos possibility in possibilities.OrderBy(s => _random.Next()))
            {
                mapX = (short)(session.Character.PositionX + possibility.X);
                mapY = (short)(session.Character.PositionY + possibility.Y);
                if (!Map.IsBlockedZone(mapX, mapY))
                {
                    niceSpot = true;
                    break;
                }
            }

            if (niceSpot && amount > 0 && amount <= inv.Amount)
            {
                ItemInstance newItemInstance = inv.DeepCopy();
                newItemInstance.Id     = random2;
                newItemInstance.Amount = amount;
                droppedItem            = new CharacterMapItem(mapX, mapY, newItemInstance);


                DroppedList[droppedItem.TransportId] = droppedItem;
                inv.Amount -= amount;
            }
            return(droppedItem);
        }
コード例 #3
0
        public MapItem PutItem(byte type, short slot, byte amount, ref ItemInstance inv)
        {
            Logger.Debug($"type: {type} slot: {slot} amount: {amount}", Owner.Session.SessionId);
            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;

            foreach (MapCell possibilitie in Possibilities.OrderBy(s => _random.Next()))
            {
                MapX = (short)(Owner.MapX + possibilitie.X);
                MapY = (short)(Owner.MapY + possibilitie.Y);
                if (!Owner.Session.CurrentMap.IsBlockedZone(MapX, MapY))
                {
                    break;
                }
            }

            if (amount > 0 && amount <= inv.Amount)
            {
                ItemInstance newItemInstance = inv.DeepCopy();
                newItemInstance.Id     = random2;
                newItemInstance.Amount = amount;
                droppedItem            = new CharacterMapItem(MapX, MapY, newItemInstance);

                Owner.Session.CurrentMap.DroppedList.TryAdd(droppedItem.TransportId, droppedItem);
                inv.Amount -= amount;
            }
            return(droppedItem);
        }
コード例 #4
0
ファイル: Map.cs プロジェクト: OpenNos/OpenNos
        public MapItem PutItem(InventoryType type, short slot, byte amount, ref ItemInstance inv, ClientSession session)
        {
            Logger.Debug($"type: {type} slot: {slot} amount: {amount}", session.SessionId);
            Guid random2 = Guid.NewGuid();
            MapItem droppedItem = null;
            List<GridPos> Possibilities = new List<GridPos>();

            for (short x = -2; x < 3; x++)
            {
                for (short y = -2; y < 3; y++)
                {
                    Possibilities.Add(new GridPos() { x = x, y = y });
                }
            }

            short mapX = 0;
            short mapY = 0;
            bool niceSpot = false;
            foreach (GridPos possibilitie in Possibilities.OrderBy(s => _random.Next()))
            {
                mapX = (short)(session.Character.MapX + possibilitie.x);
                mapY = (short)(session.Character.MapY + possibilitie.y);
                if (!IsBlockedZone(mapX, mapY))
                {
                    niceSpot = true;
                    break;
                }
            }

            if (niceSpot)
            {
                if (amount > 0 && amount <= inv.Amount)
                {
                    ItemInstance newItemInstance = inv.DeepCopy();
                    newItemInstance.Id = random2;
                    newItemInstance.Amount = amount;
                    droppedItem = new CharacterMapItem(mapX, mapY, newItemInstance);

                    DroppedList[droppedItem.TransportId] = droppedItem;
                    inv.Amount -= amount;
                }
            }
            return droppedItem;
        }