示例#1
0
        public BosError Buy(GeneratorInfo generator)
        {
            int unitBrokened = Services.TransportService.GetUnitBrokenedCount(generator.GeneratorId);

            if (unitBrokened <= 0)
            {
                return(BosError.NoBrokenedUnits);
            }
            double price    = GetTempMechanicPrice(generator, unitBrokened);
            var    currency = Bos.Data.Currency.CreateCompanyCash(price);

            if (!Services.PlayerService.IsEnough(currency))
            {
                return(BosError.NotEnoughCompanyCash);
            }

            var mechanicData = Services.ResourceService.MechanicDataRepository.GetMechanicData(planetId:
                                                                                               Services.PlanetService.CurrentPlanet.Id);

            Services.PlayerService.RemoveCurrency(currency);

            // int unitCount = Mathf.Min(unitBrokened, mechanicData.ServiceUnitsRestoredPer10Seconds);
            TempMechanicInfo newMechanic = new TempMechanicInfo(generator.GeneratorId, unitBrokened, mechanicData.TempMechanicSpeed);

            AddTempMechanic(newMechanic);
            return(BosError.Ok);
        }
示例#2
0
 private void AddTempMechanic(TempMechanicInfo mechanic)
 {
     if (TempMechanics.ContainsKey(mechanic.GeneratorId))
     {
         TempMechanics[mechanic.GeneratorId].Add(mechanic.Id, mechanic);
     }
     else
     {
         Dictionary <string, TempMechanicInfo> generatorMechanics =
             new Dictionary <string, TempMechanicInfo> {
             [mechanic.Id] = mechanic
         };
         TempMechanics.Add(mechanic.GeneratorId, generatorMechanics);
     }
     mechanic.StartMechanic();
     GameEvents.OnTempMechanicAdded(mechanic);
     UDBG.Log($"mechanic started with interval => {mechanic.Interval}");
 }
示例#3
0
 public static void OnTempMechanicInfoStateChanged(TempMechanicState oldState, TempMechanicState newState, TempMechanicInfo info)
 => TempMechanicInfoStateChanged?.Invoke(oldState, newState, info);
示例#4
0
 public static void OnTempMechanicAdded(TempMechanicInfo mechanic)
 => TempMechanicAdded?.Invoke(mechanic);