Exemplo n.º 1
0
        public ViewModelWindowTradingStationAdmin(
            IStaticWorldObject worldObjectTradingStation,
            ObjectTradingStationPrivateState privateState,
            ObjectTradingStationPublicState publicState)
        {
            this.worldObjectTradingStation = worldObjectTradingStation;

            this.IsInsideFactionClaim = LandClaimSystem.SharedIsWorldObjectOwnedByFaction(worldObjectTradingStation);
            if (!this.IsInsideFactionClaim)
            {
                this.ViewModelOwnersEditor = new ViewModelWorldObjectOwnersEditor(
                    privateState.Owners,
                    callbackServerSetOwnersList:
                    ownersList => WorldObjectOwnersSystem.ClientSetOwners(worldObjectTradingStation, ownersList),
                    title: CoreStrings.ObjectOwnersList_Title);
            }

            this.ViewModelStockContainerExchange = new ViewModelItemsContainerExchange(
                privateState.StockItemsContainer);

            this.Lots = publicState.Lots.Select(l => new ViewModelTradingStationLot(l, this.LotEditorSaveHandler))
                        .ToList();

            this.isStationSellingMode = publicState.Mode == TradingStationMode.StationSelling;
        }
Exemplo n.º 2
0
        public ViewModelWindowTradingStationUser(ObjectTradingStationPublicState publicState)
        {
            this.publicState = publicState;

            this.lots = publicState.Lots.Select(l => new ViewModelTradingStationLot(l))
                        .ToList();

            publicState.ClientSubscribe(_ => _.Mode,
                                        _ => this.NotifyPropertyChanged(nameof(this.IsStationSellingMode)),
                                        this);
        }
        public ViewModelWindowTradingStationAdmin(
            IStaticWorldObject worldObjectTradingStation,
            ObjectTradingStationPrivateState privateState,
            ObjectTradingStationPublicState publicState)
        {
            this.worldObjectTradingStation = worldObjectTradingStation;
            this.ViewModelOwnersEditor     = new ViewModelWorldObjectOwnersEditor(
                privateState.Owners,
                callbackServerSetOwnersList:
                ownersList => WorldObjectOwnersSystem.ClientSetOwners(worldObjectTradingStation, ownersList),
                title: CoreStrings.ObjectOwnersList_Title);

            this.ViewModelStockContainerExchange = new ViewModelItemsContainerExchange(
                privateState.StockItemsContainer,
                callbackTakeAllItemsSuccess: () => { });

            this.Lots = publicState.Lots.Select(l => new ViewModelTradingStationLot(l, this.LotEditorSaveHandler))
                        .ToList();

            this.isStationSellingMode = publicState.Mode == TradingStationMode.StationSelling;
        }
Exemplo n.º 4
0
        private static void ServerRefreshTradingStationLots(
            ObjectTradingStationPrivateState privateState,
            ObjectTradingStationPublicState publicState)
        {
            var stockContainer = privateState.StockItemsContainer;

            privateState.LastStockItemsContainerHash = stockContainer.StateHash;

            int availableCoinPenny = stockContainer.CountItemsOfType(ProtoItemCoinPenny.Value),
                availableCoinShiny = stockContainer.CountItemsOfType(ProtoItemCoinShiny.Value);

            var isStationSelling = publicState.Mode == TradingStationMode.StationSelling;

            foreach (var lot in publicState.Lots)
            {
                if (lot.State == TradingStationLotState.Disabled)
                {
                    lot.CountAvailable = 0;
                    lot.ItemOnSale     = null;
                    continue;
                }

                if (lot.ProtoItem == null ||
                    !(lot.PriceCoinPenny > 0 || lot.PriceCoinShiny > 0) ||
                    lot.LotQuantity < 1 ||
                    lot.LotQuantity > TradingStationLot.MaxLotQuantity)
                {
                    lot.CountAvailable = 0;
                    lot.ItemOnSale     = null;
                    lot.State          = TradingStationLotState.Disabled;
                    continue;
                }

                uint countAvailable;
                if (isStationSelling)
                {
                    // calculate how much items the station can sell
                    countAvailable = (uint)stockContainer.CountItemsOfType(lot.ProtoItem);
                    if (countAvailable > 0)
                    {
                        lot.ItemOnSale = stockContainer.Items.FirstOrDefault(i => i.ProtoItem == lot.ProtoItem);

                        // it can accomodate at least one item
                        // check that there is enough space to accomodate money
                        if (lot.PriceCoinPenny > 0 &&
                            !ServerItems.CanCreateItem(stockContainer,
                                                       ProtoItemCoinPenny.Value,
                                                       count: lot.PriceCoinPenny) ||
                            lot.PriceCoinShiny > 0 &&
                            !ServerItems.CanCreateItem(stockContainer,
                                                       ProtoItemCoinShiny.Value,
                                                       count: lot.PriceCoinShiny))
                        {
                            lot.CountAvailable = 0;
                            lot.State          = TradingStationLotState.NoSpace;
                            continue;
                        }
                    }
                    else
                    {
                        lot.ItemOnSale = null;
                    }
                }
                else // if station is buying
                {
                    lot.ItemOnSale = null;

                    // calculate how much station can buy considering the available amount of coins and the price of the lot
                    var canAffordWithPenny = lot.PriceCoinPenny > 0
                                                 ? availableCoinPenny / lot.PriceCoinPenny
                                                 : int.MaxValue;
                    var canAffordWithShiny = lot.PriceCoinShiny > 0
                                                 ? availableCoinShiny / lot.PriceCoinShiny
                                                 : int.MaxValue;

                    countAvailable = (uint)(Math.Min(canAffordWithPenny, canAffordWithShiny)
                                            * lot.LotQuantity);
                    if (countAvailable > 0)
                    {
                        // it can afford at least one item
                        // check that there is enough space to accomodate item
                        if (!ServerItems.CanCreateItem(stockContainer,
                                                       lot.ProtoItem,
                                                       count: lot.LotQuantity))
                        {
                            lot.CountAvailable = 0;
                            lot.State          = TradingStationLotState.NoSpace;
                            continue;
                        }
                    }
                }

                lot.CountAvailable = countAvailable;
                lot.State          = countAvailable >= lot.LotQuantity
                                ? TradingStationLotState.Available
                                : isStationSelling
                                    ? TradingStationLotState.OutOfStock
                                    : TradingStationLotState.NoMoney;
            }
        }