예제 #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);