Ejemplo n.º 1
0
 private static bool CheckRetainerUpdate(RetainerUpdateItem info)
 {
     return(info != null &&
            info.RetainerId != 0 &&
            info.ContainerId == GlobalConfig.MARKET_RETAINER_CONTAINER &&
            info.ContainerSlot >= 0 &&
            info.ContainerSlot <= 20 &&
            (info.IsRemove ||
             info.ItemInfo != null &&
             info.ItemInfo.Amount > 0 &&
             info.ItemInfo.Amount < GlobalConfig.MARKET_COUNT_THRESHOLD &&
             info.OldPrice > 0 &&
             info.OldPrice <= GlobalConfig.MARKET_PRICE_THRESHOLD / info.ItemInfo.Amount &&
             info.NewPrice > 0 &&
             info.NewPrice <= GlobalConfig.MARKET_PRICE_THRESHOLD / info.ItemInfo.Amount));
 }
Ejemplo n.º 2
0
        public void HandleInventoryModify(NetworkMessageHeader header, IResult message)
        {
            if (message == null)
            {
                return;
            }

            var msg = (NetworkInventoryModify)message;

            if (msg.FromContainer == InventoryContainerId.HIRE_LISTING)
            {
                if (_irBuffer.TryGetValue((int)msg.FromContainer, out var items))
                {
                    items.InventoryItems.RemoveAll(x => x.Slot == msg.FromSlot);
                }

                var dat = new RetainerUpdateItem();
                dat.ContainerId   = InventoryContainerId.HIRE_LISTING;
                dat.ContainerSlot = msg.FromSlot;
                dat.IsRemove      = true;

                OnDataReady?.Invoke(new PackedResult(PackedResultType.RetainerUpdate,
                                                     new RetainerUpdateResult {
                    UpdateItems = new List <RetainerUpdateItem> {
                        dat
                    }
                }));                                                                                   // delete
            }
            else if (msg.ToContainer == InventoryContainerId.HIRE_LISTING)
            {
                var result = OnRequestScan?.Invoke(InventoryContainerId.HIRE_LISTING);
                if (result == null)
                {
                    return;
                }
                if (!_irBuffer.TryGetValue((int)msg.ToContainer, out var items))
                {
                    _irBuffer[(int)msg.ToContainer] = new InventoryContainer(
                        InventoryContainerTypeConverter.ToOffset((int)InventoryContainerId.HIRE_LISTING),
                        InventoryContainerId.HIRE_LISTING);
                }

                items.InventoryItems.AddRange(result.InventoryContainers.First().InventoryItems.Where(x => x.Slot == msg.ToSlot));
                // always a ClientTrigger follows add operation, so we do not need to forge request here.
            }
        }
Ejemplo n.º 3
0
        public void HandleClientTrigger(NetworkMessageHeader header, IResult message)
        {
            if (message == null)
            {
                return;
            }

            var msg = (NetworkClientTrigger)message;

            var dat = new RetainerUpdateItem();

            dat.ContainerId   = InventoryContainerId.HIRE_LISTING;
            dat.NewPrice      = msg.Param12;
            dat.ContainerSlot = msg.Param11;
            dat.IsRemove      = false;
            try
            {
                dat.RetainerId = _retainerId;
                dat.ItemInfo   = _irBuffer[(int)dat.ContainerId].InventoryItems.First(x => x.Slot == dat.ContainerSlot);
                dat.OldPrice   =
                    _ipBuffer.TryGetValue((int)dat.ContainerId * PrimeForInventorySlot + dat.ContainerSlot,
                                          out var old)
                        ? old
                        : dat.ItemInfo.UnitPrice;
                dat.ItemInfo.UnitPrice = dat.NewPrice;
            }
            catch
            {
                dat.RetainerId = -1;
                dat.ItemInfo   = null;
                dat.OldPrice   = -1;
            }

            OnDataReady?.Invoke(new PackedResult(PackedResultType.RetainerUpdate,
                                                 new RetainerUpdateResult {
                UpdateItems = new List <RetainerUpdateItem> {
                    dat
                }
            }));                                                                               // add or change
        }