Пример #1
0
        public static void CollectFish()
        {
            var totalfish = 0;

            foreach (var boat in Core.GlobalData.Boats)
            {
                var started = TimeUtils.FromUnixTime(boat.ProdStart);
                var b       = Definitions.BoatDef.Items.Item.FirstOrDefault(n => n.DefId == 1)?.Levels.Level
                              .FirstOrDefault(n => n.Id == Core.GlobalData.BoatLevel);
                if (b == null)
                {
                    continue;
                }

                var turns = Math.Round((TimeUtils.FixedUTCTime - started).TotalSeconds / b.TurnTime);
                if (turns > b.TurnCount / 2)
                {
                    totalfish += (int)(b.OutputAmount * turns);
                    Networking.AddTask(new Task.TakeFish(boat));
                }
            }

            if (totalfish > 0)
            {
                Logger.Info(string.Format(Localization.FISH_COLLECTING, totalfish));
            }
        }
Пример #2
0
        private void btn_removeitem_Click(object sender, EventArgs e)
        {
            var much = (int)this.num_removenum.Value;

            if (much <= 0)
            {
                return;
            }

            if (this.dataGridView4.CurrentRow != null)
            {
                if (dataGridView4.CurrentRow != null)
                {
                    var picked = (GUIBinds.InventoryGrid.InventoryBinding.Item)dataGridView4.CurrentRow.DataBoundItem;
                    var wehave = picked.Amount;
                    if (wehave != 0 && wehave >= much)
                    {
                        var item = MaterialDB.GetItem(picked.ID);
                        Logger.Info(string.Format(PrivateLocal.INVENTORY_REMOVED, much, item.Name));
                        Networking.AddTask(new Task.RemoveMaterialTask(item.DefId, much));
                        Core.GlobalData.Inventory.First(n => n.Id == item.DefId).Amount -= much;
                    }
                }
            }
        }
Пример #3
0
        public static void UnloadOutpost(Ship ship, int uniqueid)
        {
            var loc = Core.GlobalData.Outposts.Where(n => n.DefId == ship.TargetId).First();

            ship.LogUnload();
            var outp = Core.GlobalData.Outposts.Where(n => n.DefId == ship.TargetId).FirstOrDefault();

            if (outp.CargoOnTheWay <= ship.Sailors())
            {
                outp.CargoOnTheWay -= ship.Sailors();
            }

            Networking.AddTask(
                new Task.DockShipTaskOutPost(
                    ship,
                    false,
                    SendingHelper.GetCapacity(ship),
                    ship.Cargo,
                    SendingHelper.GetSailors(ship),
                    ship.Crew,
                    ship.TargetLevel,
                    loc.CargoOnTheWay + loc.Crew,
                    loc.RequiredCrew,
                    uniqueid));
            SendingHelper.NullShip(ship);
        }
Пример #4
0
        public static void CollectMuseum()
        {
            // 12 = museum
            var museum = Core.GlobalData.Buildings.FirstOrDefault(n => n.DefId == 12);

            if (museum == null)
            {
                return;
            }

            var slot = Core.GlobalData.Slots.FirstOrDefault(n => n.Type == "museum_ship");

            if (slot == null)
            {
                return;
            }

            if (slot.SlotUsed == 0)
            {
                return;
            }

            var started = TimeUtils.FromUnixTime(slot.LastUsed);
            var b       = Definitions.MuseumLvlDef.Items.Item.First(n => n.DefId == slot.Level);

            var turns = Math.Round((TimeUtils.FixedUTCTime - started).TotalSeconds / b.TurnTime);

            if (turns >= b.TurnCount)
            {
                museum.ProdStart = TimeUtils.GetEpochTime();
                Logger.Info(Localization.MUSEUM_COLLECT);
                Networking.AddTask(new Task.ConfirmMuseumTask(b.TurnCount));
            }
        }
Пример #5
0
        public static void CollectMaterials()
        {
            foreach (var data in Core.GlobalData.Buildings)
            {
                if (data.UpgStart == 0 && data.ProdStart != 0)
                {
                    var def = Definitions.BuildingDef.Items.Item.First(n => n.DefId == data.DefId);
                    if (def.Type != "factory")
                    {
                        continue;
                    }

                    var defs    = def.Levels.Level.First(n => n.Id == data.Level);
                    var started = TimeUtils.FromUnixTime(data.ProdStart);

                    // var prodtime = defs.ProdOutputs.ProdOutput[data.ProdId - 1]; //todo add this!
                    if ((TimeUtils.FixedUTCTime - started).TotalSeconds > defs.ProdOutputs.ProdOutput[0].Time)
                    {
                        Logger.Info(
                            string.Format(
                                Localization.BUILDINGS_COLLECTING,
                                defs.ProdOutputs.ProdOutput[0].Amount,
                                MaterialDB.GetLocalizedName(defs.ProdOutputs.ProdOutput[0].MaterialId)));

                        Networking.AddTask(new Task.FinishBuildingProducingTask(data.InstId));

                        data.ProdStart = 0;
                    }
                }
            }
        }
Пример #6
0
        public static bool SendToWreck(Ship ship)
        {
            var wreck = Core.GlobalData.Wrecks.Where(n => n.Status == 0).FirstOrDefault();

            if (wreck != null)
            {
                if (wreck.Sailors < ship.Sailors())
                {
                    var shp = Core.GlobalData.Ships.Where(n => n.InstId == ship.InstId).First();
                    shp.Sent        = TimeUtils.GetEpochTime();
                    shp.Loaded      = 0;
                    shp.Type        = "wreck";
                    shp.TargetId    = wreck.InstId;
                    shp.TargetLevel = 0;
                    wreck.Status    = 1;
                    Logger.Info(string.Format(Localization.DESTINATION_WRECK, ship.GetShipName()));
                    Networking.AddTask(new Task.SendShipwreckTask(ship.InstId, wreck.InstId));
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Пример #7
0
        public static void UpgradeContractor()
        {
            for (var index = 0; index < Core.GlobalData.Contracts.Count; index++)
            {
                var upg = Core.GlobalData.Contracts[index];
                if (upg.Done == 1)
                {
                    continue;
                }
                var def       = Definitions.ConDef.Items.Item.FirstOrDefault(n => n.DefId == upg.DefId);
                var currquest = def?.Quests.Quest.FirstOrDefault(n => n.Id == upg.QuestId);
                if (currquest == null)
                {
                    continue;
                }

                if (currquest.Amount != 0 && upg.Progress >= currquest.Amount && upg.QuestId <= def.QuestCount)
                {
                    // upgrade ofc
                    Logger.Info(
                        string.Format(Localization.CONTRACTOR_UPGRADED
                                      , LocalizationCache.GetNameFromLoc(def.NameLoc, def.Name)));

                    // todo: add new local
                    Networking.AddTask(new Task.ConfirmContractTask(upg.DefId, upg.QuestId, currquest.Rewards));

                    upg.QuestId++;
                    upg.Progress = 0;
                }
            }
        }
Пример #8
0
 public static void FinishUpgrade()
 {
     foreach (var data in Core.GlobalData.Buildings)
     {
         if (data.UpgStart != 0 && data.ProdStart == 0)
         {
             var defined = Definitions.BuildingDef.Items.Item.FirstOrDefault(n => n.DefId == data.DefId);
             var upgrade = defined.Levels.Level.FirstOrDefault(n => n.Id == data.Level + 1);
             if (upgrade != null)
             {
                 if ((TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(data.UpgStart)).TotalSeconds
                     > upgrade.UpgradeTime)
                 {
                     Logger.Info(
                         string.Format(
                             Localization.BUILDINGS_FINISHED_UPG,
                             LocalizationCache.GetNameFromLoc(defined.NameLoc, defined.Name)));
                     Networking.AddTask(new Task.FinishBuildingUpgradeTask(data.InstId));
                     data.UpgStart = 0;
                     data.Level++;
                 }
             }
         }
     }
 }
Пример #9
0
        public static void UnloadUpgradable(Ship ship, int uniqueid)
        {
            var defenition = Definitions.UpgrDef.Items.Item.FirstOrDefault(n => n.DefId == ship.TargetId);
            var lvl        = defenition?.Levels.Level.FirstOrDefault(n => n.Id == ship.TargetLevel);

            if (lvl != null)
            {
                ship.LogUnload();
                var upg = Core.GlobalData.Upgradeables.FirstOrDefault(n => n.DefId == ship.TargetId);
                if (upg != null)
                {
                    upg.Progress += lvl.MaterialKoef * SendingHelper.GetCapacity(ship);
                }

                Networking.AddTask(
                    new Task.UnloadShipTask(
                        ship.InstId,
                        Core.GlobalData.Level,
                        Enums.EObject.upgradeable,
                        SendingHelper.GetCapacity(ship),
                        lvl.MaterialKoef * SendingHelper.GetCapacity(ship),
                        SendingHelper.GetSailors(ship),
                        lvl.Sailors,
                        ship.TargetLevel,
                        null, uniqueid));
                SendingHelper.NullShip(ship);
            }
        }
Пример #10
0
        public static void UnloadContractor(Ship ship, int uniqueid)
        {
            var currentcontractor = Definitions.ConDef.Items.Item
                                    .FirstOrDefault(n => n.DefId == ship.TargetId);

            var quest = currentcontractor?.Quests.Quest.FirstOrDefault(n => n.Id == ship.TargetLevel);

            if (quest == null)
            {
                return;
            }

            if (currentcontractor.Type == "static")
            {
                var usedshit  = quest.MaterialKoef * SendingHelper.GetCapacity(ship);
                var lcontract = Core.GlobalData.Contracts.FirstOrDefault(n => n.DefId == ship.TargetId);
                // TODO: increasing of progress or amount!
                ship.LogUnload();
                Networking.AddTask(
                    new Task.DockShipTaskContractor(
                        ship,
                        false,
                        SendingHelper.GetCapacity(ship),
                        usedshit,
                        SendingHelper.GetSailors(ship),
                        currentcontractor.Sailors,
                        ship.TargetLevel,
                        currentcontractor.DefId,
                        lcontract.Progress,
                        (int)quest.InputAmount(),
                        quest.ObjectiveTypeId,
                        uniqueid));
            }
            else
            {
                var usedshit  = quest.MaterialKoef * SendingHelper.GetCapacity(ship);
                var lcontract = Core.GlobalData.Contracts.FirstOrDefault(n => n.DefId == ship.TargetId);
                var inp       = quest.InputAmount();
                // TODO: increasing of progress or amount!
                ship.LogUnload();
                Networking.AddTask(
                    new Task.DockShipTaskContractor(
                        ship,
                        false,
                        SendingHelper.GetCapacity(ship),
                        usedshit,
                        SendingHelper.GetSailors(ship),
                        currentcontractor.Sailors,
                        ship.TargetLevel,
                        currentcontractor.DefId,
                        lcontract.Progress,
                        (int)quest.InputAmount(),
                        quest.ObjectiveTypeId,
                        uniqueid));
            }

            SendingHelper.NullShip(ship);
        }
Пример #11
0
        public static void LoadSocContractor(Ship ship)
        {
            Logger.Info(
                Localization.SHIPS_LOADING + 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.UnloadShipSocialContractTask(ship.InstId));
            ship.Loaded = 1;
        }
Пример #12
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?
        }
Пример #13
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);
        }
Пример #14
0
        private static void Main(string[] args)
        {
            Console.WriteLine("BarrelTest");
            var token = File.ReadAllText("token.txt");

            Core.ServerToken = token;

            Events.SyncFailedEvent.SyncFailed.OnSyncFailedEvent += Kicked_OnWrongSession;

            for (var i = 7; i < 200; i++)
            {
                kicked = false;
                var attempts = 0;
                Console.WriteLine("Testing inverval = " + i);
                Networking.Login();
                while (true)
                {
                    Thread.Sleep(i * 1000);
                    if (!kicked)
                    {
                        var barrelid = TimeUtils.GetCurrentEvent().Barrel.Integer.Value;
                        var bar      = Barrels.BarrelController.GetNextBarrel(
                            Definitions.BarrelDef.Items.Item.Where(n => n.DefId == 21).First());
                        if (bar.Definition.Id != 0)
                        {
                            Console.WriteLine(
                                $"Barrel! Collecting {bar.Amount} {MaterialDB.GetItem(bar.Definition.Id).Name}");
                        }

                        Networking.AddTask(
                            new Task.ConfirmBarrelTask(
                                (int)barrelid,
                                bar.get_type(),
                                bar.Amount,
                                bar.Definition.Id,
                                Core.GlobalData.Level));
                        attempts++;
                    }
                    else
                    {
                        File.WriteAllText(i.ToString(), attempts.ToString());
                        break;
                    }
                }
            }
        }
Пример #15
0
        public static void LoadUpgradeable(Ship ship)
        {
            var lvl = Definitions.UpgrDef.Items.Item.FirstOrDefault(n => n.DefId == ship.TargetId)?.Levels
                      .Level.First(n => n.Id == ship.TargetLevel);

            if (lvl != null)
            {
                Logger.Info(
                    Localization.SHIPS_LOADING + LocalizationCache.GetNameFromLoc(
                        Definitions.ShipDef.Items.Item.First(n => n.DefId == ship.DefId).NameLoc,
                        Definitions.ShipDef.Items.Item.First(n => n.DefId == ship.DefId).Name));
                Core.GlobalData.Upgradeables.First(n => n.DefId == ship.TargetId).CargoOnTheWay -=
                    lvl.MaterialKoef * SendingHelper.GetCapacity(ship);
                Core.GlobalData.Upgradeables.First(n => n.DefId == ship.TargetId).Progress +=
                    lvl.MaterialKoef * SendingHelper.GetCapacity(ship);

                Networking.AddTask(new Task.LoadShipUpgradeableTask(ship.InstId));
                ship.Loaded = 1;
            }
        }
Пример #16
0
        public static void UnloadWreck(Ship ship, int uniqueid)
        {
            var wrk = Core.GlobalData.Wrecks.Where(n => n.InstId == ship.TargetId).FirstOrDefault();

            if (wrk != null)
            {
                ship.LogUnload();
                Networking.AddTask(
                    new Task.UnloadShipTask(
                        ship.InstId,
                        Core.GlobalData.Level,
                        Enums.EObject.wreck,
                        SendingHelper.GetCapacity(ship),
                        0,
                        SendingHelper.GetSailors(ship),
                        wrk.Sailors,
                        ship.TargetLevel,
                        null,
                        uniqueid));
                SendingHelper.NullShip(ship);
            }
        }
Пример #17
0
        public static void CollectBarrel()
        {
            var nearestev        = TimeUtils.GetCurrentEvent().Barrel.Integer.Value;
            var barrelcontroller = Definitions.BarrelDef.Items.Item.Where(n => n.DefId == nearestev).First();
            var nextbarrel       = BarrelController.GetNextBarrel(barrelcontroller);

            if (nextbarrel.Definition.Id != 0)
            {
                Logger.Info(
                    string.Format(
                        Localization.BARREL_COLLECTING_ITEM,
                        nextbarrel.Amount,
                        MaterialDB.GetLocalizedName(nextbarrel.Definition.Id)));
                if (Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == nextbarrel.Definition.Id) != null)
                {
                    Core.GlobalData.Inventory.First(n => n.Id == nextbarrel.Definition.Id).Amount += nextbarrel.Amount;
                }
                else
                {
                    Core.GlobalData.Inventory.Add(
                        new Item {
                        Amount = nextbarrel.Amount, Id = nextbarrel.Definition.Id
                    });
                }
            }
            else
            {
                Logger.Info(string.Format(Localization.BARREL_COLLECTING_SAILORS, nextbarrel.Amount));
            }

            Networking.AddTask(
                new Task.ConfirmBarrelTask(
                    barrelcontroller.DefId,
                    nextbarrel.get_type(),
                    nextbarrel.Amount,
                    nextbarrel.Definition.Id,
                    Core.GlobalData.Level));
        }
Пример #18
0
        public static void UnloadSocialcontract(Ship ship, int uniqueid)
        {
            var co = Core.GlobalData.SocialContracts.Where(n => n.InstId == ship.TargetId)
                     .FirstOrDefault();

            if (co == null)
            {
                return;
            }

            ship.LogUnload();
            Networking.AddTask(
                new Task.DockShipSocialContractor(
                    ship,
                    false,
                    ship.Capacity(),
                    co.MaterialKoef / co.Amount,
                    ship.Sailors(),
                    co.Sailors,
                    ship.TargetLevel,
                    uniqueid));
            SendingHelper.NullShip(ship);
        }
Пример #19
0
        public static void UpgradeUpgradable()
        {
            for (var index = 0; index < Core.GlobalData.Upgradeables.Count; index++)
            {
                var upg        = Core.GlobalData.Upgradeables[index];
                var def        = Definitions.UpgrDef.Items.Item.FirstOrDefault(n => n.DefId == upg.DefId);
                var currentlvl = def?.Levels.Level.FirstOrDefault(n => n.Id == upg.Level);
                if (def == null || currentlvl == null)
                {
                    continue;
                }

                if (upg.Level >= def.MaxLevel)
                {
                    continue;
                }

                var nextlvl = def.Levels.Level.FirstOrDefault(n => n.Id == upg.Level + 1);
                if (nextlvl == null)
                {
                    continue;
                }

                if (upg.Progress >= currentlvl.Amount)
                {
                    // upgrade ofc
                    Core.GlobalData.Upgradeables[index].Level++;
                    Core.GlobalData.Upgradeables[index].Progress     = 0;
                    Core.GlobalData.Upgradeables[index].Amount       = nextlvl.Amount;
                    Core.GlobalData.Upgradeables[index].MaterialKoef = nextlvl.MaterialKoef;
                    Logger.Info(
                        Localization.UPGRADABLE_UPGRADED + LocalizationCache.GetNameFromLoc(def.NameLoc, def.Name));
                    Networking.AddTask(new Task.ConfirmUpgradeableTask(upg.DefId, Core.GlobalData.Level));
                }
            }
        }
Пример #20
0
        public static void UnloadMarketplace(Ship ship, int uniqueid)
        {
            var market = Definitions.MarketDef.Items.Item.FirstOrDefault(n => n.DefId == ship.TargetId);
            var lvl    = Definitions.MarketDef.Items.Item.FirstOrDefault(n => n.DefId == ship.TargetId);
            var mat    = lvl?.Materials.Material.FirstOrDefault(n => n.Id == ship.MaterialId);

            if (mat != null)
            {
                ship.LogUnload();
                Networking.AddTask(
                    new Task.UnloadShipTask(
                        ship.InstId,
                        Core.GlobalData.Level,
                        Enums.EObject.marketplace,
                        SendingHelper.GetCapacity(ship),
                        mat.InputKoef * SendingHelper.GetCapacity(ship),
                        SendingHelper.GetSailors(ship),
                        market.Sailors,
                        ship.TargetLevel,
                        null,
                        uniqueid));
                SendingHelper.NullShip(ship);
            }
        }
Пример #21
0
        public static void AutoUpgrade(bool onlyfactory)
        {
            foreach (var data in Core.GlobalData.Buildings)
            {
                if (data.UpgStart == 0 && data.ProdStart == 0)
                {
                    var defined    = Definitions.BuildingDef.Items.Item.FirstOrDefault(n => n.DefId == data.DefId);
                    var neededmats = defined?.Levels.Level.FirstOrDefault(n => n.Id == data.Level + 1);

                    if (defined != null && defined.Type != "factory" && onlyfactory)
                    {
                        continue;
                    }

                    if (neededmats != null)
                    {
                        var ok = true;

                        foreach (var neededmat in neededmats.Materials.Material)
                        {
                            if (Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == neededmat.Id) != null)
                            {
                                var m = Core.GlobalData.Inventory.First(n => n.Id == neededmat.Id);
                                if (neededmat.Amount > m.Amount)
                                {
                                    ok = false;
                                }
                            }
                            else
                            {
                                ok = false;
                                break;
                            }
                        }

                        if (ok)
                        {
                            if (neededmats.ReqId != 0)
                            {
                                var def = Core.GlobalData.Buildings.FirstOrDefault(n => n.DefId == neededmats.ReqId);
                                if (def != null)
                                {
                                    ok = def.Level >= neededmats.ReqLevel;
                                }
                                else
                                {
                                    ok = false;
                                }
                            }

                            if (neededmats.PlayerLevel > Core.GlobalData.Level)
                            {
                                ok = false;
                            }
                        }

                        if (ok)
                        {
                            foreach (var neededmat in neededmats.Materials.Material)
                            {
                                var m = Core.GlobalData.Inventory.First(n => n.Id == neededmat.Id);
                                m.Amount -= neededmat.Amount;
                            }

                            Logger.Info(
                                string.Format(
                                    Localization.BUILDINGS_STARTED_UPG,
                                    LocalizationCache.GetNameFromLoc(defined.NameLoc, defined.Name)));
                            Networking.AddTask(
                                new Task.StartBuildingUpgradeTask(
                                    data.InstId,
                                    data.ProdId,
                                    data.Level,
                                    data.UpgType.ToString(),
                                    data.DefId,
                                    data.GridX,
                                    data.GridY));
                            data.UpgStart = TimeUtils.GetEpochTime();
                        }
                    }
                }
            }
        }
Пример #22
0
        public static bool SendToContractor(Ship ship)
        {
            if (ship == null)
            {
                return(false);
            }
            var statiopst = new List <Contractor>();
            var genopst   = new List <Contractor>();

            foreach (var contractor in Core.GlobalData.Contracts)
            {
                if (contractor == null)
                {
                    continue;
                }
                if (contractor.Done != 0)
                {
                    continue;
                }

                var def   = Definitions.ConDef.Items.Item.FirstOrDefault(c => contractor.DefId == c.DefId);
                var quest = def?.Quests.Quest.FirstOrDefault(q => contractor.QuestId == q.Id);
                if (quest == null)
                {
                    continue;
                }
                if (Core.GlobalData.GetAmountItem(quest.ObjectiveDefId) >= quest.InputAmount())
                {
                    if (def.EventId != 0 && def.EventId != TimeUtils.GetCurrentEvent().DefId)
                    {
                        if (!Core.Config.exploitmode)
                        {
                            continue;
                        }
                    }
                    if (def.Type == "static")
                    {
                        statiopst.Add(contractor);
                    }
                    else
                    {
                        genopst.Add(contractor);
                    }
                }
            }

            foreach (var opst in statiopst.OrderBy(n => n.QuestId))
            {
                var def   = Definitions.ConDef.Items.Item.FirstOrDefault(c => opst.DefId == c.DefId);
                var quest = def?.Quests.Quest.FirstOrDefault(q => opst.QuestId == q.Id);
                if (quest == null || def == null)
                {
                    continue;
                }
                var exists = quest.Amount - opst.Progress;
                if (exists <= 0)
                {
                    continue;
                }

                var wecan = 0;
                if (exists * quest.MaterialKoef > ship.Capacity())
                {
                    wecan = ship.Capacity();
                }
                else
                {
                    wecan = exists;
                }

                Core.GlobalData.Contracts.First(n => n.DefId == opst.DefId).CargoOnTheWay +=
                    wecan * quest.MaterialKoef;
                Core.GlobalData.Contracts.First(n => n.DefId == opst.DefId).Progress +=
                    wecan * quest.MaterialKoef;
                Logger.Info(string.Format(Localization.DESTINATION_CONTRACTOR, ship.GetShipName()));
                Networking.AddTask(
                    new Task.SendShipContractorTask(
                        ship.InstId,
                        opst.DefId,
                        quest.ObjectiveDefId,
                        quest.Id,
                        wecan * quest.MaterialKoef));
                var lship = Core.GlobalData.Ships.FirstOrDefault(n => n.DefId == ship.DefId);
                lship.Sent        = TimeUtils.GetEpochTime();
                lship.Loaded      = 0;
                lship.Type        = "contractor";
                lship.TargetId    = opst.DefId;
                lship.MaterialId  = quest.ObjectiveDefId;
                lship.TargetLevel = quest.Id;
                return(true);
            }

            foreach (var opst in genopst.OrderBy(n => n.QuestId))
            {
                var def   = Definitions.ConDef.Items.Item.FirstOrDefault(c => opst.DefId == c.DefId);
                var quest = def?.Quests.Quest.FirstOrDefault(q => opst.QuestId == q.Id);
                if (quest == null)
                {
                    continue;
                }
                var already = opst.Progress;
                var exists  = (int)quest.InputAmount() - opst.Progress;
                if (exists <= 0)
                {
                    continue;
                }
                var wecan = 0;
                if (exists * quest.MaterialKoef > ship.Capacity())
                {
                    wecan = ship.Capacity();
                }
                else
                {
                    wecan = exists;
                }

                Core.GlobalData.Contracts.First(n => n.DefId == opst.DefId).CargoOnTheWay +=
                    wecan * quest.MaterialKoef;
                Core.GlobalData.Contracts.First(n => n.DefId == opst.DefId).Progress +=
                    wecan * quest.MaterialKoef;
                var lship = Core.GlobalData.Ships.FirstOrDefault(n => n.DefId == ship.DefId);
                lship.Sent        = TimeUtils.GetEpochTime();
                lship.Loaded      = 0;
                lship.Type        = "contractor";
                lship.TargetId    = opst.DefId;
                lship.MaterialId  = quest.ObjectiveDefId;
                lship.TargetLevel = quest.Id;
                Logger.Info(string.Format(Localization.DESTINATION_CONTRACTOR, ship.GetShipName()));
                Networking.AddTask(
                    new Task.SendShipContractorTask(
                        ship.InstId,
                        opst.DefId,
                        quest.ObjectiveDefId,
                        quest.Id,
                        wecan * quest.MaterialKoef));
                return(true);
            }
            return(false);
        }
Пример #23
0
        public static void ProduceFactories()
        {
            foreach (var data in Core.GlobalData.Buildings)
            {
                if (data.UpgStart == 0 && data.ProdStart == 0)
                {
                    var def = Definitions.BuildingDef.Items.Item.First(n => n.DefId == data.DefId);
                    if (def.Type != "factory")
                    {
                        continue;
                    }

                    var needed = def.Levels.Level.FirstOrDefault(n => n.Id == data.Level);
                    if (needed == null)
                    {
                        continue;
                    }

                    if (data.DefId == 11)
                    {
                        // This is a machinery
                        if (Core.Config.autothresholdworkshop)
                        {
                            // Mechanical part
                            if (Core.GlobalData.GetAmountItem(33) < Core.Config.thresholdmechanical)
                            {
                                var prodid = 1;
                                var enough = true;
                                var mat    = needed.ProdOutputs.ProdOutput.Where(n => n.Id == 1).FirstOrDefault();
                                if (mat == null)
                                {
                                    continue;
                                }

                                foreach (var prod in mat.Inputs.Input)
                                {
                                    if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount)
                                    {
                                        enough = false;
                                    }
                                }

                                if (enough)
                                {
                                    foreach (var inp in mat.Inputs.Input)
                                    {
                                        Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount;
                                    }

                                    Logger.Info(
                                        string.Format(
                                            Localization.FACTORIES_STARTED_PROD,
                                            MaterialDB.GetLocalizedName(mat.MaterialId)));
                                    Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid));
                                    data.ProdStart = TimeUtils.GetEpochTime();

                                    continue;
                                }

                                // This will work
                            }

                            // Fuel
                            if (Core.GlobalData.GetAmountItem(180) < Core.Config.thresholdfuel)
                            {
                                var prodid = 2;
                                var enough = true;
                                var mat    = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault();
                                if (mat == null)
                                {
                                    continue;
                                }

                                foreach (var prod in mat.Inputs.Input)
                                {
                                    if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount)
                                    {
                                        enough = false;
                                    }
                                }

                                if (enough)
                                {
                                    foreach (var inp in mat.Inputs.Input)
                                    {
                                        Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount;
                                    }

                                    Logger.Info(
                                        string.Format(
                                            Localization.FACTORIES_STARTED_PROD,
                                            MaterialDB.GetLocalizedName(mat.MaterialId)));
                                    Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid));
                                    data.ProdStart = TimeUtils.GetEpochTime();
                                    continue;
                                }
                            }

                            // todo CHECK FOR LEVEL!!!
                            // Concrete
                            if (data.Level >= 5)
                            {
                                if (Core.GlobalData.GetAmountItem(182) < Core.Config.thresholdconcrete)
                                {
                                    var prodid = 3;

                                    var enough = true;
                                    var mat    = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault();
                                    if (mat == null)
                                    {
                                        continue;
                                    }

                                    foreach (var prod in mat.Inputs.Input)
                                    {
                                        if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount)
                                        {
                                            enough = false;
                                        }
                                    }

                                    if (enough)
                                    {
                                        foreach (var inp in mat.Inputs.Input)
                                        {
                                            Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount;
                                        }

                                        Logger.Info(
                                            string.Format(
                                                Localization.FACTORIES_STARTED_PROD,
                                                MaterialDB.GetLocalizedName(mat.MaterialId)));
                                        Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid));
                                        data.ProdStart = TimeUtils.GetEpochTime();
                                    }
                                }
                            }
                        }
                        else
                        {
                            var prodid        = 0;
                            var matid         = 0;
                            var thresholdconc = 0;
                            switch (Core.Config.workshoptype)
                            {
                            case WorkshopType.Concrete:
                            {
                                matid         = 182;
                                prodid        = 3;
                                thresholdconc = Core.Config.thresholdconcrete;
                            }

                            break;

                            case WorkshopType.Fuel:
                            {
                                matid         = 180;
                                prodid        = 2;
                                thresholdconc = Core.Config.thresholdfuel;
                            }

                            break;

                            case WorkshopType.MechanicalPart:
                            {
                                matid         = 33;
                                prodid        = 1;
                                thresholdconc = Core.Config.thresholdmechanical;
                                break;
                            }
                            }

                            if (prodid == 3 && data.Level < 5)
                            {
                                continue;
                            }

                            if (Core.GlobalData.GetAmountItem(matid) < thresholdconc || thresholdconc == 0)
                            {
                                var enough = true;
                                var mat    = needed.ProdOutputs.ProdOutput.Where(n => n.Id == prodid).FirstOrDefault();
                                if (mat == null)
                                {
                                    continue;
                                }

                                foreach (var prod in mat.Inputs.Input)
                                {
                                    if (Core.GlobalData.GetAmountItem(prod.Id) < prod.Amount)
                                    {
                                        enough = false;
                                    }
                                }

                                if (enough)
                                {
                                    foreach (var inp in mat.Inputs.Input)
                                    {
                                        Core.GlobalData.Inventory.First(n => n.Id == inp.Id).Amount -= inp.Amount;
                                    }

                                    Logger.Info(
                                        string.Format(
                                            Localization.FACTORIES_STARTED_PROD,
                                            MaterialDB.GetLocalizedName(mat.MaterialId)));
                                    Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, prodid));
                                    data.ProdStart = TimeUtils.GetEpochTime();
                                }
                            }
                        }

                        // Don't need another shit
                        continue;
                    }

                    // lets start?
                    // DO WE HAVE ENOUGH RESOURCES
                    var ok     = true;
                    var inputs = needed.ProdOutputs.ProdOutput;
                    var Dict   = new Dictionary <long, long>();
                    foreach (var input in inputs)
                    {
                        foreach (var inp in input.Inputs.Input)
                        {
                            var ourmat = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == inp.Id);
                            if (ourmat == null)
                            {
                                ok = false;
                            }
                            else
                            {
                                if (ourmat.Amount >= inp.Amount)
                                {
                                    if (Dict.ContainsKey(inp.Id))
                                    {
                                        Dict[inp.Id] += inp.Amount;
                                    }
                                    else
                                    {
                                        Dict.Add(inp.Id, inp.Amount);
                                    }
                                }
                                else
                                {
                                    ok = false;
                                }
                            }
                        }

                        if (MaterialDB.GetItem(input.MaterialId).Name == "wood")
                        {
                            var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId);
                            if (amount != null && Core.Config.woodlimit != 0)
                            {
                                if (amount.Amount > Core.Config.woodlimit)
                                {
                                    ok = false;
                                }
                            }
                        }

                        if (MaterialDB.GetItem(input.MaterialId).Name == "iron")
                        {
                            var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId);
                            if (amount != null && Core.Config.ironlimit != 0)
                            {
                                if (amount.Amount > Core.Config.ironlimit)
                                {
                                    ok = false;
                                }
                            }
                        }

                        if (MaterialDB.GetItem(input.MaterialId).Name == "stone")
                        {
                            var amount = Core.GlobalData.Inventory.FirstOrDefault(n => n.Id == input.MaterialId);
                            if (amount != null && Core.Config.stonelimit != 0)
                            {
                                if (amount.Amount > Core.Config.stonelimit)
                                {
                                    ok = false;
                                }
                            }
                        }
                    }

                    if (ok)
                    {
                        foreach (var inp in Dict)
                        {
                            Core.GlobalData.Inventory.First(n => n.Id == inp.Key).Amount -= (int)inp.Value;
                        }

                        Logger.Info(
                            string.Format(
                                Localization.FACTORIES_STARTED_PROD,
                                MaterialDB.GetLocalizedName(needed.ProdOutputs.ProdOutput[0].MaterialId)));
                        Networking.AddTask(new Task.StartBuildingProducingTask(data.InstId, data.ProdId));
                        data.ProdStart = TimeUtils.GetEpochTime();
                    }
                }
            }
        }
Пример #24
0
        public static void UnloadAllShips()
        {
            var unloadedships = new List <int>();

            foreach (var shi in Core.GlobalData.Ships)
            {
                var ship = Core.GlobalData.Ships.Where(n => n.InstId == shi.InstId).First();
                if (ship.TargetId != 0 && ship.Activated != 0 && ship.IsVoyageCompleted())
                {
                    switch (ship.Type)
                    {
                    case "upgradeable":
                    {
                        if (ship.Loaded == 1)
                        {
                            unloadedships.Add(ship.DefId);
                            var ship1    = ship;
                            int uniqueid = unloadedships.Count(n => n == ship1.DefId);
                            UnloadUpgradable(ship, uniqueid);
                        }

                        break;
                    }

                    case "marketplace":
                    {
                        unloadedships.Add(ship.DefId);
                        int uniqueid = unloadedships.Count(n => n == ship.DefId);
                        UnloadMarketplace(ship, uniqueid);
                        break;
                    }

                    case "wreck":
                    {
                        unloadedships.Add(ship.DefId);
                        int uniqueid = unloadedships.Count(n => n == ship.DefId);
                        UnloadWreck(ship, uniqueid);
                        break;
                    }

                    case "contractor":
                    {
                        if (ship.Loaded == 1)
                        {
                            unloadedships.Add(ship.DefId);
                            int uniqueid = unloadedships.Count(n => n == ship.DefId);
                            UnloadContractor(ship, uniqueid);
                        }
                        break;
                    }

                    case "outpost":
                    {
                        unloadedships.Add(ship.DefId);
                        int uniqueid = unloadedships.Count(n => n == ship.DefId);
                        UnloadOutpost(ship, uniqueid);
                        break;
                    }

                    case "social_contract":
                    {
                        Networking.AddTask(new Task.UnloadShipSocialContractTask(ship.InstId));
                        if (ship.Loaded == 1)
                        {
                            unloadedships.Add(ship.DefId);
                            int uniqueid = unloadedships.Count(n => n == ship.DefId);
                            UnloadSocialcontract(ship, uniqueid);
                        }
                        break;
                    }
                    }
                }
            }
            unloadedships.Clear();
        }
Пример #25
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);
        }