public override void Update() { base.Update(); Schedule = new int[ModEntry.DaysPerMonth]; WorldDate date = new(Menu.Date); FlowBuilder builder = new(); builder.FormatText(I18n.Page_Train_About()); for (int day = 1; day <= ModEntry.DaysPerMonth; day++) { date.DayOfMonth = day; int time = Schedule[day - 1] = TrainHelper.GetTrainTime(date); if (time >= 0) { SDate sdate = new(day, date.Season); builder.Text("\n\n"); builder.Text($"{sdate.ToLocaleString(withYear: false)}\n", font: Game1.dialogueFont); builder.Text($" {TimeHelper.FormatTime(time)}"); } } if (date.SeasonIndex == 0 && date.Year == 1) { builder.FormatText($"\n\n{I18n.Page_Train_Notice()}", color: Color.Red); } SetRightFlow(builder, 2); }
/// <summary> /// a function to check if there is an available building to train a unit /// </summary> /// <param name="unitType">desired unit to be trained</param> /// <returns>true if an idle building is waiting, false otherwise</returns> public static bool TrainingBuildingAvailable(uint unitType) { HashSet <uint> hs = TrainHelper.GetTrainingBuildingTypes(unitType); if (VBot.Bot.StateManager.GetAvailableAgent(hs) != null) { return(true); } return(false); }
public void Expose_coaches() { var coachId = "A"; var train = TrainHelper.BuildTrainWith_1_coach_and_0_reserved_seat(coachId); Check.That(train.Coaches).HasSize(1); var coach = train.Coaches.Single().Value; Check.That(coach.Seats).HasSize(3); Check.That(coach.Seats.Select(x => x.CoachName).All(x => x == coachId)).IsTrue(); Check.That(coach.Seats).ContainsExactly(new Seat(coachId, 1, ""), new Seat(coachId, 2, ""), new Seat(coachId, 3, "")); }
public void MoveOnPath(double startT, double startMovement) { var result = TrainHelper.MoveOnPath(t => new Double2(t, 0), startT, startMovement); Assert.AreEqual((startMovement + startT).Clamp(0, 1), result.T, 0.0001); if (startMovement > 0) { Assert.AreEqual(Math.Max(0, startMovement - (1 - startT)), result.MovementLeft, 0.0001); } else { Assert.AreEqual(Math.Min(0, startMovement + startT), result.MovementLeft, 0.0001); } }
public async Task Reserve_seats_on_2_coaches_When_resereved_seats_exeed_coach_capacity() { var seatRequested = new SeatsRequested(2); var trainId = new TrainId("express_2000"); var bookingReferenceNumber = "10"; var bookingReferenceAdapter = Substitute.For <IBookingReference>(); bookingReferenceAdapter.GetBookingReference().Returns(Task.FromResult(bookingReferenceNumber)); var trainDataServiceAdapter = Substitute.For <ITrainDataService>(); trainDataServiceAdapter.GetTrain(trainId).Returns(Task.FromResult(new Train(trainId, TrainDataAdapter.AdaptTrainTopology("{\"seats\": {" + TrainHelper.BuildCoachJson("A", 10, numberOfReservedSeat: 6) + "," + TrainHelper.BuildCoachJson("B", 10, numberOfReservedSeat: 6) + "}}")))); var manager = new TicketOfficeService(trainDataServiceAdapter, bookingReferenceAdapter); IProvideReservation hexagon = new TicketOfficeService(trainDataServiceAdapter, bookingReferenceAdapter); var seatReservationAdapter = new SeatReservationAdapter(hexagon); var reservationRequestDto = new ReservationRequestDto { train_id = trainId.ToString(), number_of_seats = seatRequested.Value }; var jsonResult = await seatReservationAdapter.PostSeatsRequest(reservationRequestDto); Check.That(jsonResult).IsEqualTo($"{{\"train_id\": \"{trainId}\", \"booking_reference\": \"10\", \"seats\": [\"7A\", \"7B\"]}}"); }
// Methods /// <summary> /// checks if it is possible to build/research unit/upgrade, then gets an agent and orders it to complete the task. /// </summary> public override void OnFrame() { if (UnitType != 0) // make a unit { if (Controller.CanMakeUnit(UnitType) && FromAgent == null) { // set the from type and execute the task if (MorphHelper.MorpSteps.ContainsKey(UnitType)) { FromAgent = Controller.GetAvailableAgent(MorphHelper.GetPreMorphType(UnitType)); FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute() Clear(); // only dismissed as it is morph type and eggs are useless and don't need to be busy } else if (TrainHelper.TrainSteps.ContainsKey(UnitType)) { FromAgent = Controller.GetAvailableAgent(TrainHelper.GetTrainingBuildingTypes(UnitType)); FromAgent.Busy = true; FromAgent.Order(Units.GetAbilityId(UnitType)); // acts as execute() } else { FromAgent = Controller.GetAvailableAgent(Units.Workers); FromAgent.Busy = true; Controller.BuildStructure(FromAgent, UnitType); // acts as Execute() } } else if (FromAgent != null) { if (FromAgent.Unit.Orders.Count == 0) { // agent is idle. clear it Clear(); } } else { Clear(); } } else { if (Controller.CanMakeUpgrade(UpgradeType) && FromAgent == null) { FromAgent = Controller.GetAvailableAgent(UpgradeHelper.GetUpgradeBuildingTypes(UpgradeType)); FromAgent.Busy = true; FromAgent.Order(Upgrades.GetAbilityId(UpgradeType)); } else if (FromAgent != null) { if (FromAgent.Unit.Orders.Count == 0) { FromAgent.Busy = false; Clear(); } } else { Clear(); } } }