public bool DefMapsEqual <T>(DefMap <TrainableDef, T> mapA, DefMap <TrainableDef, T> mapB) where T : new()
        {
            if (mapA.Count != mapB.Count)
            {
                return(false);
            }

            foreach (var pair in mapA)
            {
                var validPairs = mapB.Where(pairB => pairB.Key == pair.Key);
                if (validPairs != null && validPairs.Count() > 0)
                {
                    var pairB = validPairs.First();
                    if (!pair.Value.Equals(pairB.Value))
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }

            return(true);
        }
Exemple #2
0
 public void TrainingTrackerTickRare()
 {
     if (pawn.Suspended)
     {
         countDecayFrom += 250;
     }
     else if (!pawn.Spawned)
     {
         countDecayFrom += 250;
     }
     else if (steps[TrainableDefOf.Tameness] == 0)
     {
         countDecayFrom = Find.TickManager.TicksGame;
     }
     else
     {
         if (Find.TickManager.TicksGame < countDecayFrom + TrainableUtility.DegradationPeriodTicks(pawn.def))
         {
             return;
         }
         TrainableDef trainableDef = (from kvp in steps
                                      where kvp.Value > 0
                                      select kvp.Key).Except(steps.Where((KeyValuePair <TrainableDef, int> kvp) => kvp.Value > 0 && kvp.Key.prerequisites != null).SelectMany((KeyValuePair <TrainableDef, int> kvp) => kvp.Key.prerequisites)).RandomElement();
         if (trainableDef == TrainableDefOf.Tameness && !TrainableUtility.TamenessCanDecay(pawn.def))
         {
             countDecayFrom = Find.TickManager.TicksGame;
             return;
         }
         countDecayFrom = Find.TickManager.TicksGame;
         steps[trainableDef]--;
         if (steps[trainableDef] > 0 || !learned[trainableDef])
         {
             return;
         }
         learned[trainableDef] = false;
         if (pawn.Faction == Faction.OfPlayer)
         {
             if (trainableDef == TrainableDefOf.Tameness)
             {
                 pawn.SetFaction(null);
                 Messages.Message("MessageAnimalReturnedWild".Translate(pawn.LabelShort, pawn), pawn, MessageTypeDefOf.NegativeEvent);
             }
             else
             {
                 Messages.Message("MessageAnimalLostSkill".Translate(pawn.LabelShort, trainableDef.LabelCap, pawn.Named("ANIMAL")), pawn, MessageTypeDefOf.NegativeEvent);
             }
         }
     }
 }