Пример #1
0
        public TaskCenter(QuoteCenter aQc, TradeCenter aTc, DataCenter aDc)
        {
            tc = aTc;
            qc = aQc;
            dc = aDc;

            //demoTask(); // remove in production
            initOrder();
        }
        public override bool ShouldSkip(Pawn pawn)
        {
            var pendingTradeCenters = Find.ListerBuildings.AllBuildingsColonistOfClass<TradeCenter>()
                .Where(tradeCenter => tradeCenter.pendingItemsCounter.Any());

            if (pendingTradeCenters.Any())
            {
                closestTradeCenter = GenClosest.ClosestThing_Global_Reachable(pawn.Position,
                    pendingTradeCenters.Cast<Thing>(), PathEndMode.Touch, TraverseParms.For(pawn)) as TradeCenter;

                if (closestTradeCenter != null)
                {
                    closestSellable = GenClosest.ClosestThing_Global_Reachable(pawn.Position,
                        closestTradeCenter.pendingItemsCounter, PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999,
                        sellable =>
                            pawn.CanReserve(sellable) && !sellable.IsBurning());

                    if (closestSellable != null)
                        return false;
                }
            }
            return true;
        }
Пример #3
0
        private IEnumerable <AllInOne> CreateCommonData(dynamic _exchange)
        {
            var allKoins = new List <string>();
            var cd       = _exchange.coindelta as IEnumerable <Coinddelta>;

            FindAndAllKoin(cd.Select(x => x.MarketName.Split('-').FirstOrDefault()), allKoins);
            var koinex = _exchange.koinex as IEnumerable <Koinex>;

            FindAndAllKoin(koinex.Select(x => x.currency_short_form), allKoins);
            var wazirx = _exchange.wazirx as IEnumerable <Wazirx>;

            FindAndAllKoin(wazirx.Select(x => x.baseMarket), allKoins);
            var bitbns = _exchange.bitbns as IEnumerable <Bitbns>;

            FindAndAllKoin(bitbns.Select(x => x.currency_short_form), allKoins);

            // prepare data
            var allkoindata = new List <AllInOne>();

            foreach (var koin in allKoins)
            {
                var kd = new AllInOne();
                kd.name     = koin;
                kd.fullname = koin;
                if (cd.Count(x => x.MarketName.Split('-').FirstOrDefault().ToUpper() == koin) > 0)
                {
                    var cdData       = cd.FirstOrDefault(x => x.MarketName.Split('-').FirstOrDefault().ToUpper() == koin);
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "CD",
                        lastprice = cdData.Last,
                        url       = $"https://coindelta.com/market/advance/{cdData.MarketName}",
                    };
                    kd.exchages.Add(exchangeinfo);
                }
                else
                {
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "CD",
                        lastprice = 0,
                        url       = "https://coindelta.com",
                    };
                    kd.exchages.Add(exchangeinfo);
                }

                if (koinex.Count(x => x.currency_short_form.ToUpper() == koin) > 0)
                {
                    var kodata       = koinex.FirstOrDefault(x => x.currency_short_form.ToUpper() == koin);
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "KNX",
                        lastprice = Convert.ToDouble(kodata.last_traded_price),
                        url       = $"https://koinex.in/exchange/inr/{kodata.currency_full_form}",
                    };
                    kd.exchages.Add(exchangeinfo);
                }
                else
                {
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "KNX",
                        lastprice = 0,
                        url       = "https://koinex.in",
                    };
                    kd.exchages.Add(exchangeinfo);
                }

                if (bitbns.Count(x => x.currency_short_form.ToUpper() == koin) > 0)
                {
                    var bitbnsdata   = bitbns.FirstOrDefault(x => x.currency_short_form.ToUpper() == koin);
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "BITBNS",
                        lastprice = Convert.ToDouble(bitbnsdata.last_traded_price),
                        url       = $"https://bitbns.com/trade/#/{koin.ToLower()}",
                    };
                    kd.exchages.Add(exchangeinfo);
                }
                else
                {
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "BITBNS",
                        lastprice = 0,
                        url       = "https://bitbns.com/trade",
                    };
                    kd.exchages.Add(exchangeinfo);
                }

                if (wazirx.Count(x => x.baseMarket.ToUpper() == koin) > 0)
                {
                    var wazirxdata   = wazirx.FirstOrDefault(x => x.baseMarket.ToUpper() == koin);
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "WZRX",
                        lastprice = Convert.ToDouble(wazirxdata.last),
                        url       = $"https://wazirx.com/exchange/{koin}-INR",
                    };
                    kd.exchages.Add(exchangeinfo);
                }
                else
                {
                    var exchangeinfo = new TradeCenter
                    {
                        name      = "WZRX",
                        lastprice = 0,
                        url       = "https://wazirx.com/exchange",
                    };
                    kd.exchages.Add(exchangeinfo);
                }

                allkoindata.Add(kd);
            }

            return(allkoindata);
        }
Пример #4
0
        public override void ResolveTrade()
        {
            tradeCenter = TradeUtil.FindOccupiedTradeCenter(TradeSession.playerNegotiator);

            // goods offered by colony
            switch (ActionToDo)
            {
                case TradeAction.PlayerSells:
                    // offerLeftover - current amount of tradeable type to offer
                    var exportLeftover = Math.Abs(countToDrop);
                    while (exportLeftover > 0)
                    {
                        if (thingsColony.Count == 0)
                        {
                            Log.Error("Nothing left to give to trader for " + this);
                            return;
                        }
                        // thingsColony used as a stack of the same type things. We always deal with the first thing in this stack
                        var currentThing = FirstThingColony;
                        var offerCount = Mathf.Min(exportLeftover, currentThing.stackCount);
                        exportLeftover -= offerCount;
                        currentThing.SetForbidden(true);
                        // if thing is a stackable resource
                        if (currentThing.def.stackLimit > 1)
                        {
                            Log.Message(String.Format("added {0} {1}", ThingDef, offerCount));
                            // make counter for deal resolve (control group)
                            if (tradeCenter.pendingResourcesCounters.ContainsKey(ThingDef))
                                tradeCenter.pendingResourcesCounters[ThingDef] += offerCount;
                            else
                                tradeCenter.pendingResourcesCounters.Add(currentThing.def, offerCount);
                        }
                        // clears placed blueprints for minified things
                        if (!(currentThing is Pawn)) currentThing.PreTraded(ActionToDo, tradeCenter.negotiator, tradeCenter.trader);
                        tradeCenter.pendingItemsCounter.Add(currentThing);
                        thingsColony.Remove(currentThing);
                    }
                    break;
                case TradeAction.PlayerBuys:
                    // offerLeftover - current amount of tradeable type to offer
                    var importLeftover = Math.Abs(countToDrop);
                    while (importLeftover > 0)
                    {
                        if (thingsTrader.Count == 0)
                        {
                            Log.Error("Nothing left to take from trader for " + this);
                            return;
                        }
                        var currentThing = FirstThingTrader;
                        var transferCount = Mathf.Min(importLeftover, currentThing.stackCount);
                        // make new thing\stack by splitting required amount of another stack (can take it whole)
                        var transferedThing = currentThing.SplitOff(transferCount);
                        importLeftover -= transferCount;
                        // check for full thing transfer
                        if (transferedThing == currentThing)
                        {
                            // remove thing from current tradeable list
                            thingsTrader.Remove(currentThing);
                        }
                        // trasfer sellable to the trader exchange container
                        tradeCenter.traderStock.TransferToContainer(transferedThing, tradeCenter.traderExchangeContainer, transferedThing.stackCount);
                        // update trader goods total cost
                        tradeCenter.traderGoodsCost += PriceFor(ActionToDo)* transferedThing.stackCount;
                        CheckTeachOpportunity(transferedThing);
                    }
                    break;
            }
        }