/// <summary>
        /// Checks to see if a creature matches the critter type specified.
        /// </summary>
        /// <param name="type">The critter type.</param>
        /// <param name="creature">The creature to compare against.</param>
        /// <returns>true if the creature matches the type, or false otherwise.</returns>
        public static bool Matches(this CritterType type, CreatureBrain creature)
        {
            bool match;

            if (creature == null)
            {
                // Should not match any critter type
                match = false;
            }
            else
            {
                // Some creatures cannot be tamed (morbs)
                bool canBeTamed = creature.gameObject.GetDef <WildnessMonitor.Def>() != null;
                switch (type)
                {
                case CritterType.Tame:
                    match = !creature.HasTag(GameTags.Creatures.Wild) && canBeTamed;
                    break;

                case CritterType.Wild:
                    match = creature.HasTag(GameTags.Creatures.Wild) || !canBeTamed;
                    break;

                default:
                    throw new InvalidOperationException("Unsupported critter type " + type);
                }
            }
            return(match);
        }
 /// <summary>
 /// Adds a critter in the current world to the inventory.
 /// </summary>
 /// <param name="creature">The creature to add.</param>
 private void AddCritter(CreatureBrain creature)
 {
     if (counts.TryGetValue(creature.GetCritterType(), out CritterInventoryPerType
                            byType))
     {
         var  species = creature.PrefabID();
         var  alignment = creature.GetComponent <FactionAlignment>();
         bool targeted = false, targetable = false;
         // Create critter totals if not present
         if (!byType.TryGetValue(species, out CritterTotals totals))
         {
             byType.Add(species, totals = new CritterTotals());
             discovered = true;
         }
         totals.Total++;
         if (alignment != null)
         {
             targeted   = FACTION_TARGETED.Get(alignment);
             targetable = FACTION_TARGETABLE.Get(alignment);
         }
         // Reserve wrangled, marked for attack, and trussed/bagged creatures
         if ((creature.GetComponent <Capturable>()?.IsMarkedForCapture ?? false) ||
             (targeted && targetable) || creature.HasTag(GameTags.Creatures.Bagged))
         {
             totals.Reserved++;
         }
     }
 }
Esempio n. 3
0
        public static int DomesticatedCritters()
        {
            int count = 0;

            foreach (object brain in Components.Brains)
            {
                CreatureBrain cmp = brain as CreatureBrain;
                if ((UnityEngine.Object)cmp != (UnityEngine.Object)null)
                {
                    if (!cmp.HasTag(GameTags.Creatures.Wild))
                    {
                        count++;
                    }
                }
            }
            return(count);
        }
        /// <summary>
        /// Gets the type of a critter.
        /// </summary>
        /// <param name="creature">The critter to query.</param>
        /// <returns>The critter type.</returns>
        public static CritterType GetCritterType(this CreatureBrain creature)
        {
            var go     = creature.gameObject;
            var result = CritterType.Wild;

            if (creature != null)
            {
                if (go.GetDef <RobotBatteryMonitor.Def>() != null)
                {
                    result = CritterType.Artificial;
                }
                else if (go.GetDef <WildnessMonitor.Def>() != null && !creature.HasTag(GameTags.
                                                                                       Creatures.Wild))
                {
                    result = CritterType.Tame;
                }
            }
            return(result);
        }