DeepCopy() public method

public DeepCopy ( ) : ItemInstance
return ItemInstance
Beispiel #1
0
        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);
        }
Beispiel #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);
        }
Beispiel #3
0
        /// <summary>
        /// c_scalc packet
        /// </summary>
        /// <param name="cScalcPacket"></param>
        public void GetBazaar(CScalcPacket cScalcPacket)
        {
            if (ServerManager.Instance.InShutdown || Session.Character == null || Session.Character.InExchangeOrTrade)
            {
                return;
            }
            SpinWait.SpinUntil(() => !ServerManager.Instance.InBazaarRefreshMode);
            BazaarItemDTO bz = DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == cScalcPacket.BazaarId);

            if (bz != null)
            {
                ItemInstance item = (ItemInstance)DAOFactory.IteminstanceDAO.FirstOrDefault(s => s.Id == bz.ItemInstanceId);
                if (item == null || bz.SellerId != Session.Character.CharacterId)
                {
                    return;
                }
                int  soldedamount = bz.Amount - item.Amount;
                long taxes        = bz.MedalUsed ? 0 : (long)(bz.Price * 0.10 * soldedamount);
                long price        = bz.Price * soldedamount - taxes;
                if (Session.Character.Inventory.CanAddItem(item.ItemVNum))
                {
                    if (Session.Character.Gold + price <= ServerManager.Instance.MaxGold)
                    {
                        Session.Character.Gold += price;
                        Session.SendPacket(Session.Character.GenerateGold());
                        Session.SendPacket(Session.Character.GenerateSay(string.Format(Language.Instance.GetMessageFromKey("REMOVE_FROM_BAZAAR"), price), 10));
                        if (item.Amount != 0)
                        {
                            ItemInstance newBz = item.DeepCopy();
                            newBz.Id   = Guid.NewGuid();
                            newBz.Type = newBz.Item.Type;
                            if (newBz is WearableInstance wear)
                            {
                                wear.EquipmentOptions.AddRange(DAOFactory.EquipmentOptionDAO.Where(s => s.WearableInstanceId == item.Id));
                                wear.EquipmentOptions.ForEach(s => s.WearableInstanceId = newBz.Id);
                            }
                            List <ItemInstance> newInv = Session.Character.Inventory.AddToInventory(newBz);
                        }
                        Session.SendPacket($"rc_scalc 1 {bz.Price} {bz.Amount - item.Amount} {bz.Amount} {taxes} {price + taxes}");

                        if (DAOFactory.BazaarItemDAO.FirstOrDefault(s => s.BazaarItemId == bz.BazaarItemId) != null)
                        {
                            DAOFactory.BazaarItemDAO.Delete(bz.BazaarItemId);
                        }

                        DAOFactory.IteminstanceDAO.Delete(item.Id);

                        ServerManager.Instance.BazaarRefresh(bz.BazaarItemId);
                    }
                    else
                    {
                        Session.SendPacket(UserInterfaceHelper.Instance.GenerateMsg(Language.Instance.GetMessageFromKey("MAX_GOLD"), 0));
                        Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                    }
                }
                else
                {
                    Session.SendPacket(UserInterfaceHelper.Instance.GenerateInfo(Language.Instance.GetMessageFromKey("NOT_ENOUGH_PLACE")));
                    Session.SendPacket($"rc_scalc 1 {bz.Price} 0 {bz.Amount} 0 0");
                }
            }
            else
            {
                Session.SendPacket("rc_scalc 1 0 0 0 0 0");
            }
        }
Beispiel #4
0
        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;
        }