Exemplo n.º 1
0
        public Marketplace()
        {
            this.InitializeComponent();

            if (Core.GlobalData != null && Core.GlobalData.Inventory != null)
            {
                foreach (var item in AutoTools.GetUsableMarketplacePoints())
                {
                    if (Core.Config.marketitems.Contains(item.Id))
                    {
                        this.locallist.Add(new IgnoreMarketplaceData.IgnoreItem {
                            Id = item.Id, Selected = true
                        });
                    }
                    else
                    {
                        this.locallist.Add(new IgnoreMarketplaceData.IgnoreItem {
                            Id = item.Id, Selected = false
                        });
                    }
                }
            }

            ((ListBox)this.checkedListBox1).DataSource    = this.locallist;
            ((ListBox)this.checkedListBox1).DisplayMember = "Name";
            ((ListBox)this.checkedListBox1).ValueMember   = "Selected";
            for (var i = 0; i < this.checkedListBox1.Items.Count; i++)
            {
                var obj = (IgnoreMarketplaceData.IgnoreItem) this.checkedListBox1.Items[i];
                this.checkedListBox1.SetItemChecked(i, obj.Selected);
            }

            this.checkedListBox1.ItemCheck += this.CheckedListBox1_ItemCheck;
        }
Exemplo n.º 2
0
        public static bool SendToMarketplace(Ship ship)
        {
            // Outpost send!

            // 1. Find with done == 0
            var marketplacepoints = AutoTools.GetEnabledMarketPlacePoints();

            var neededitems = AutoTools.NeededItemsForUpgradePercentage().OrderBy(pair => pair.Value).Select(n => n.Key)
                              .ToList();

            var maktplc = new MarketplaceDefenitions.Material();

            if (ship.Sailors() < Definitions.MarketDef.Items.Item[1].Sailors)
            {
                return(false);
            }

            var placeswithneeded = new List <MarketplaceDefenitions.Material>();

            foreach (var need in neededitems)
            {
                foreach (var plc in Definitions.MarketDef.Items.Item[1].Materials.Material)
                {
                    if (plc.OutputId == need)
                    {
                        placeswithneeded.Add(plc);
                    }
                }
            }

            var found = false;

            foreach (var inpMaterial in placeswithneeded)
            {
                if (found)
                {
                    break;
                }

                foreach (var point in marketplacepoints)
                {
                    if (inpMaterial.InputId == point.Id)
                    {
                        maktplc = inpMaterial;
                        found   = true;
                        break;
                    }
                }
            }

            if (maktplc.OutputType == null)
            {
                var can = Definitions.MarketDef.Items.Item[1].Materials.Material.Where(
                    n => n.InputId == marketplacepoints.OrderByDescending(b => b.Amount).FirstOrDefault()?.Id).ToList();
                if (can.Count > 0)
                {
                    maktplc = can[new Random().Next(can.Count)];
                }
            }

            if (maktplc?.OutputType == null)
            {
                return(false);
            }

            var wehaveininv = Core.GlobalData.GetAmountItem(maktplc.InputId);
            var canproceed  = 0;

            canproceed = wehaveininv < ship.Capacity() ? wehaveininv : ship.Capacity();

            Core.GlobalData.Inventory.Where(n => n.Id == maktplc.InputId).FirstOrDefault().Amount -= canproceed;
            Logger.Info(string.Format(Localization.DESTINATION_MARKETPLACE, ship.GetShipName()));
            Networking.AddTask(new Task.SendShipMarketplaceTask(ship.InstId, maktplc.Id, 1, canproceed));
            var locship = Core.GlobalData.Ships.Where(n => n.InstId == ship.InstId).First();

            locship.Type        = "marketplace";
            locship.TargetId    = 1;
            locship.TargetLevel = 0;
            locship.MaterialId  = 0;
            locship.Sent        = TimeUtils.GetEpochTime();
            locship.MaterialId  = maktplc.Id;
            locship.Loaded      = 0;
            return(true);
        }