Exemple #1
0
 public static void MoveOldAnimalStatusData()
 {
     if (Context.IsMainPlayer)
     {
         if (FarmerData?.AnimalData == null || FarmerData.AnimalData.Count == 0)
         {
             return;
         }
         AnimalHusbandryModEntry.monitor.Log($"Migrating animal status data from old format to the new one.", LogLevel.Info);
         FarmerData?.AnimalData?.RemoveAll(s =>
         {
             try
             {
                 FarmAnimal farmAnimal = Utility.getAnimal(s.Id);
                 if (farmAnimal != null)
                 {
                     if (s.DayParticipatedContest != null)
                     {
                         farmAnimal.SetDayParticipatedContest(s.DayParticipatedContest);
                     }
                     if (s.HasWon != null)
                     {
                         farmAnimal.SetHasWon(s.HasWon.Value);
                     }
                     if (s.LastDayFeedTreat != null)
                     {
                         farmAnimal.SetLastDayFeedTreat(s.LastDayFeedTreat);
                     }
                     s.FeedTreatsQuantity.ToList().ForEach(t => farmAnimal.SetFeedTreatsQuantity(t.Key, t.Value));
                 }
                 else
                 {
                     AnimalHusbandryModEntry.monitor.Log($"The animal id '{s.Id}' was not found in the game and its animal status data is being discarded.", LogLevel.Warn);
                 }
                 return(true);
             }
             catch (Exception e)
             {
                 AnimalHusbandryModEntry.monitor.Log($"Unexpected error while trying to migrate animal status data of animal id '{s.Id}'. The animal status data will be kept on the old format but will not be used.", LogLevel.Warn);
                 AnimalHusbandryModEntry.monitor.Log($"Message from pregnancy error above: {e.Message}");
                 return(false);
             }
         });
     }
 }