Example #1
0
        public static bool SendToOutpost(Ship ship)
        {
            var opst = Core.GlobalData.Outposts.Where(n => !n.Done && n.Crew < n.RequiredCrew).FirstOrDefault();

            if (opst != null)
            {
                var can     = opst.RequiredCrew - opst.Crew;
                var sending = 0;
                if (can > SendingHelper.GetSailors(ship))
                {
                    sending = SendingHelper.GetSailors(ship);
                }
                else
                {
                    sending = can;
                }

                opst.Crew += sending;
                Networking.AddTask(new Task.OutpostSendShipTask(ship.InstId, opst.DefId, sending));
                return(true);
            }
            else
            {
                var locked = SendingHelper.GetUnlockableOutposts();
                if (locked.Count == 0)
                {
                    return(false);
                }

                var next = locked.OrderBy(n => n.Sailors).FirstOrDefault();
                if (next == null)
                {
                    return(false);
                }

                var sending = 0;
                sending = next.Crew > ship.Sailors() ? ship.Sailors() : next.Crew;
                Logger.Info(string.Format(Localization.DESTINATION_OUTPOST, ship.GetShipName()));
                Networking.AddTask(new Task.OutpostSendShipTask(ship.InstId, next.DefId, sending));
                Core.GlobalData.Outposts.Add(
                    new Outpost
                {
                    CargoOnTheWay = sending,
                    Crew          = sending,
                    DefId         = sending,
                    Done          = false,
                    PlayerLevel   = Core.GlobalData.Level,
                    RequiredCrew  = next.Crew
                });
                return(true);
            }

            // KAAAAAAAAAAAAZOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO?
        }
Example #2
0
        public static bool SendToUpgradable(Ship ship, string itemname)
        {
            var bestplace = SendingHelper.GetBestUpgPlace(itemname, ship.Sailors(), Core.Config.upgradablestrategy);

            if (bestplace == null || Core.GlobalData.Sailors < ship.Sailors())
            {
                return(false);
            }

            var place    = Definitions.UpgrDef.Items.Item.FirstOrDefault(n => n.DefId == bestplace.DefId);
            var shipfull = Definitions.ShipDef.Items.Item.Where(n => n.DefId == ship.DefId).FirstOrDefault();
            var lvls     = place?.Levels.Level.FirstOrDefault(n => n.Id == bestplace.Level);

            if (shipfull?.SlotUsage < place?.Slots)
            {
                return(false);
            }

            if (lvls != null)
            {
                var wecan  = lvls.MaterialKoef * ship.Capacity();
                var remain = bestplace.Amount - bestplace.Progress;
                if (remain < wecan)
                {
                    wecan = remain;
                }

                Core.GlobalData.Sailors -= lvls.Sailors;

                bestplace.CargoOnTheWay += wecan;
                var shp = Core.GlobalData.Ships.Where(n => n.InstId == ship.InstId).First();
                shp.Sent        = TimeUtils.GetEpochTime();
                shp.Loaded      = 0;
                shp.Type        = "upgradeable";
                shp.TargetId    = bestplace.DefId;
                shp.TargetLevel = bestplace.Level;
                Logger.Info(
                    Localization.SHIPS_SENDING + LocalizationCache.GetNameFromLoc(
                        Definitions.ShipDef.Items.Item.First(n => n.DefId == ship.DefId).NameLoc,
                        Definitions.ShipDef.Items.Item.First(n => n.DefId == ship.DefId).Name));
                Networking.AddTask(new Task.SendShipUpgradeableTask(ship, bestplace, wecan));
                return(true);
            }

            return(false);
        }
Example #3
0
        public static void SendShipsAutoDestination()
        {
            var bestships = new Queue <Ship>(Core.GlobalData.Ships.Where(n => n.Activated != 0 && n.Sent == 0)
                                             .OrderByDescending(SendingHelper.GetCapacity));
            int upgcont         = SendingHelper.GetPercentage(upgproc, bestships.Count);
            int outpostcont     = SendingHelper.GetPercentage(outpostproc, bestships.Count);
            int marketcount     = SendingHelper.GetPercentage(marketproc, bestships.Count);
            int contractorcount = SendingHelper.GetPercentage(contractorproc, bestships.Count);
            int wreckcount      = SendingHelper.GetPercentage(wreckproc, bestships.Count);

            //foreach (var ship in AutoTools.TakeAndRemove(bestships, upgcont))
            //{
            //    Destinations.SendToUpgradable(ship, Core.Config.autoshiptype);
            //}


            //foreach (var ship in AutoTools.TakeAndRemove(bestships, outpostcont))
            //{
            //    Destinations.SendToOutpost(ship);
            //}

            //foreach (var ship in AutoTools.TakeAndRemove(bestships, marketcount))
            //{
            //    Destinations.SendToMarketplace(ship);
            //}

            //foreach (var ship in AutoTools.TakeAndRemove(bestships, contractorcount))
            //{
            //    Destinations.SendToContractor(ship);
            //}

            //foreach (var ship in AutoTools.TakeAndRemove(bestships, wreckcount))
            //{
            //    Destinations.SendToWreck(ship);
            //    Logger.Info("wrk" + Definitions.ShipDef.Items.Item.Where(n => n.DefId == ship.DefId).First().Name);
            //}

            var failed = new Queue <Ship>(
                Core.GlobalData.Ships.Where(n => n.Activated != 0 && n.Sent == 0)
                .OrderByDescending(SendingHelper.GetCapacity));

            foreach (var ship in failed)
            {
                var perc = PercentageDest();
                if (contractorproc > perc[ShipDestType.Contractor])
                {
                    if (Destinations.SendToContractor(ship))
                    {
                        continue;
                    }
                }
                if (upgproc > perc[ShipDestType.Upgradable])
                {
                    if (Destinations.SendToUpgradable(ship, Core.Config.autoshiptype))
                    {
                        continue;
                    }
                }
                if (marketproc > perc[ShipDestType.Marketplace])
                {
                    if (Destinations.SendToMarketplace(ship))
                    {
                        continue;
                    }
                }
                if (outpostproc > perc[ShipDestType.Outpost])
                {
                    if (Destinations.SendToOutpost(ship))
                    {
                        continue;
                    }
                }

                if (Destinations.SendToContractor(ship))
                {
                    continue;
                }

                if (Destinations.SendToUpgradable(ship, Core.Config.autoshiptype))
                {
                    continue;
                }

                if (Destinations.SendToMarketplace(ship))
                {
                    continue;
                }

                if (Destinations.SendToOutpost(ship))
                {
                    continue;
                }
            }
        }