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); }
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}"); }
public static void OnTempMechanicInfoStateChanged(TempMechanicState oldState, TempMechanicState newState, TempMechanicInfo info) => TempMechanicInfoStateChanged?.Invoke(oldState, newState, info);
public static void OnTempMechanicAdded(TempMechanicInfo mechanic) => TempMechanicAdded?.Invoke(mechanic);