Exemplo n.º 1
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++;
                 }
             }
         }
     }
 }
Exemplo n.º 2
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;
                }
            }
        }
Exemplo n.º 3
0
 public static void LogUnload(this Ship ship)
 {
     Logger.Info(
         Localization.SHIPS_UNLOADING + LocalizationCache.GetNameFromLoc(
             Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.NameLoc,
             Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.Name));
 }
Exemplo n.º 4
0
            public static BindingList <Ship> GetShips()
            {
                var ret = new BindingList <Ship>();

                if (Core.GlobalData == null)
                {
                    return(ret);
                }

                if (Core.GlobalData.Buildings == null)
                {
                    return(ret);
                }

                foreach (var ship in Core.GlobalData.Ships.Where(n => n.Activated != 0))
                {
                    var name = LocalizationCache.GetNameFromLoc(
                        Definitions.ShipDef.Items.Item.Where(n => n.DefId == ship.DefId)?.FirstOrDefault()?.NameLoc,
                        Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.Name);
                    var Ship = new Ship();
                    Ship.ID   = ship.InstId;
                    Ship.Name = name;

                    var willatportat = string.Empty;
                    if (ship.Sent != 0)
                    {
                        try
                        {
                            Ship.Route = LocalizationCache.GetNameFromLoc(ship.GetTravelName(), string.Empty);
                            if (ship.Type == "social_contract")
                            {
                                Ship.Route = PrivateLocal.SHIPS_SOCIAL_CONTRACT;
                            }

                            var willatportattime = ship.Sent + ship.GetTravelTime();

                            // lol xD
                            if ((TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(willatportattime)).TotalSeconds > 0)
                            {
                                willatportat = "--:--:--";
                            }
                            else
                            {
                                willatportat =
                                    (TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(willatportattime)).ToString(
                                        @"hh\:mm\:ss");
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }

                    Ship.InPortAt = willatportat;
                    ret.Add(Ship);
                }

                return(ret);
            }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
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));
                }
            }
        }
Exemplo n.º 9
0
 public static string GetLocalizedName(int id)
 {
     return(LocalizationCache.GetNameFromLoc(
                Definitions.MatDef.Items.Item.FirstOrDefault(n => n.DefId == id)?.NameLoc.ToLower(),
                Definitions.MatDef.Items.Item.FirstOrDefault(n => n.DefId == id)?.Name));
 }
Exemplo n.º 10
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();
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
 public static string GetShipName(this Ship ship)
 {
     return(LocalizationCache.GetNameFromLoc(
                Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.NameLoc,
                Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.Name));
 }
Exemplo n.º 12
0
            public static BindingList <Building> GetBuildings()
            {
                var ret = new BindingList <Building>();

                if (Core.GlobalData == null)
                {
                    return(ret);
                }

                if (Core.GlobalData.Buildings == null)
                {
                    return(ret);
                }

                foreach (var building in Core.GlobalData.Buildings)
                {
                    var Building = new Building();
                    Building.ID   = building.InstId;
                    Building.Name = LocalizationCache.GetNameFromLoc(
                        Definitions.BuildingDef.Items.Item.Where(n => n.DefId == building.DefId).FirstOrDefault()
                        ?.NameLoc,
                        Definitions.BuildingDef.Items.Item.Where(n => n.DefId == building.DefId).FirstOrDefault()
                        ?.Name);
                    Building.Level = building.Level;
                    var producing = string.Empty;
                    if (building.ProdStart != 0)
                    {
                        var willbeproducedat = building.ProdStart + Definitions.BuildingDef.Items.Item
                                               .Where(n => n.DefId == building.DefId).FirstOrDefault()?.Levels.Level
                                               .Where(n => n.Id == building.Level).FirstOrDefault()?.ProdOutputs
                                               .ProdOutput[0].Time;
                        if (willbeproducedat.HasValue)
                        {
                            producing = (TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(willbeproducedat.Value))
                                        .ToString(@"hh\:mm\:ss");
                        }

                        // lol xD
                    }

                    var upgrade = string.Empty;
                    if (building.UpgStart != 0)
                    {
                        var willbeproducedat = building.UpgStart + Definitions.BuildingDef.Items.Item
                                               .Where(n => n.DefId == building.DefId).FirstOrDefault()?.Levels.Level
                                               .Where(n => n.Id == building.Level + 1).FirstOrDefault()
                                               ?.UpgradeTime;
                        if (willbeproducedat.HasValue)
                        {
                            upgrade = (TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime((long)willbeproducedat))
                                      .ToString(@"hh\:mm\:ss");
                        }
                    }

                    if (building.DefId == 12)
                    {
                        if (building.UpgStart == 0)
                        {
                            var slot = Core.GlobalData.Slots.FirstOrDefault(n => n.Type == "museum_ship");
                            if (slot == null)
                            {
                                continue;
                            }

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

                            var started = TimeUtils.FromUnixTime(slot.LastUsed);

                            var b = Definitions.MuseumLvlDef.Items.Item.First(n => n.DefId == building.Level);

                            producing = (TimeUtils.FixedUTCTime - started.AddSeconds(b.TurnCount * b.TurnTime))
                                        .ToString(@"hh\:mm\:ss");
                        }
                    }

                    Building.UpgradeIgnore = false;

                    Building.Producing = producing;
                    Building.Upgrade   = upgrade;
                    ret.Add(Building);
                }

                return(ret);
            }
Exemplo n.º 13
0
                    private string GetShips()
                    {
                        var builder = new StringBuilder();

                        if (Core.GlobalData != null)
                        {
                            if (Core.GlobalData.Ships != null)
                            {
                                foreach (var ship in Core.GlobalData.Ships.Where(n => n.Activated != 0))
                                {
                                    var name = LocalizationCache.GetNameFromLoc(
                                        Definitions.ShipDef.Items.Item.Where(n => n.DefId == ship.DefId)?.FirstOrDefault()?.NameLoc,
                                        Definitions.ShipDef.Items.Item.FirstOrDefault(n => n.DefId == ship.DefId)?.Name);

                                    builder.Append(name + "|");


                                    if (ship.Sent != 0)
                                    {
                                        try
                                        {
                                            if (ship.Type == "social_contract")
                                            {
                                                builder.Append(PrivateLocal.SHIPS_SOCIAL_CONTRACT);
                                            }
                                            else
                                            {
                                                builder.Append(LocalizationCache.GetNameFromLoc(ship.GetTravelName(), string.Empty));
                                            }



                                            var willatportattime = ship.Sent + ship.GetTravelTime();

                                            // lol xD
                                            if ((TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(willatportattime)).TotalSeconds > 0)
                                            {
                                                builder.Append("|--:--:--");
                                            }
                                            else
                                            {
                                                builder.Append("|" +
                                                               (TimeUtils.FixedUTCTime - TimeUtils.FromUnixTime(willatportattime)).ToString(
                                                                   @"hh\:mm\:ss"));
                                            }
                                        }
                                        catch (Exception)
                                        {
                                        }
                                    }


                                    builder.AppendLine();
                                }
                            }
                            else
                            {
                                builder.Append(PrivateLocal.TELEGRAM_EXCEPTION_NULL);
                            }
                        }
                        else
                        {
                            builder.Append(PrivateLocal.TELEGRAM_EXCEPTION_NULL);
                        }

                        return(builder.ToString());
                    }