/// <summary>Returns an unused Short ID value for the given creature type to use.</summary> private int GetUnusedShortID(CreatureCategory creatureCategory) { int newShortID = 1; switch (creatureCategory) { case CreatureCategory.Horse: List <int> usedHorseIDs = new List <int>(); foreach (Horse horse in GetHorses()) { usedHorseIDs.Add(horse.Manners); } while (usedHorseIDs.Contains(newShortID)) { newShortID++; } break; case CreatureCategory.Pet: List <int> usedPetIDs = new List <int>(); foreach (Pet pet in GetPets()) { usedPetIDs.Add(pet.Manners); } while (usedPetIDs.Contains(newShortID)) { newShortID++; } break; case CreatureCategory.Animal: while (AnimalShortToLongIDs.ContainsKey(newShortID)) { newShortID++; } break; default: break; } return(newShortID); }
/// <summary>Removes a creature from the Animal Skinner system.</summary> private void RemoveCreature(CreatureCategory category, long id) { switch (category) { case CreatureCategory.Horse: // Horse isn't in the system if (!HorseSkinMap.ContainsKey(id)) { return; } HorseSkinMap.Remove(id); break; case CreatureCategory.Pet: // Pet isn't in the system if (!PetSkinMap.ContainsKey(id)) { return; } PetSkinMap.Remove(id); break; case CreatureCategory.Animal: // Animal isn't in the system if (!AnimalSkinMap.ContainsKey(id)) { return; } // Remove from ShortID lists int shortID = AnimalLongToShortIDs[id]; AnimalLongToShortIDs.Remove(id); AnimalShortToLongIDs.Remove(shortID); AnimalSkinMap.Remove(id); break; default: break; } }
/************************ ** Protected / Internal *************************/ /// <summary>Returns the creature of the given category and ID</summary> internal static Character GetCreature(CreatureCategory creatureCategory, long id) { switch (creatureCategory) { case CreatureCategory.Horse: foreach (Horse horse in GetHorses()) { if (id == horse.Manners) { return(horse); } } break; case CreatureCategory.Pet: foreach (Pet pet in GetPets()) { if (id == pet.Manners) { return(pet); } } break; case CreatureCategory.Animal: foreach (FarmAnimal animal in GetAnimals()) { if (id == animal.myID.Value) { return(animal); } } break; default: return(null); } return(null); }
public override void Load(ValuesDictionary valuesDictionary, IdToEntityMap idToEntityMap) { m_subsystemGameInfo = base.Project.FindSubsystem <SubsystemGameInfo>(throwOnError: true); m_subsystemPlayers = base.Project.FindSubsystem <SubsystemPlayers>(throwOnError: true); m_subsystemSky = base.Project.FindSubsystem <SubsystemSky>(throwOnError: true); m_subsystemBodies = base.Project.FindSubsystem <SubsystemBodies>(throwOnError: true); m_subsystemTime = base.Project.FindSubsystem <SubsystemTime>(throwOnError: true); m_subsystemNoise = base.Project.FindSubsystem <SubsystemNoise>(throwOnError: true); m_componentCreature = base.Entity.FindComponent <ComponentCreature>(throwOnError: true); m_componentPathfinding = base.Entity.FindComponent <ComponentPathfinding>(throwOnError: true); m_componentMiner = base.Entity.FindComponent <ComponentMiner>(throwOnError: true); m_componentFeedBehavior = base.Entity.FindComponent <ComponentRandomFeedBehavior>(); m_componentCreatureModel = base.Entity.FindComponent <ComponentCreatureModel>(throwOnError: true); m_dayChaseRange = valuesDictionary.GetValue <float>("DayChaseRange"); m_nightChaseRange = valuesDictionary.GetValue <float>("NightChaseRange"); m_dayChaseTime = valuesDictionary.GetValue <float>("DayChaseTime"); m_nightChaseTime = valuesDictionary.GetValue <float>("NightChaseTime"); m_autoChaseMask = valuesDictionary.GetValue <CreatureCategory>("AutoChaseMask"); m_chaseNonPlayerProbability = valuesDictionary.GetValue <float>("ChaseNonPlayerProbability"); m_chaseWhenAttackedProbability = valuesDictionary.GetValue <float>("ChaseWhenAttackedProbability"); m_chaseOnTouchProbability = valuesDictionary.GetValue <float>("ChaseOnTouchProbability"); m_componentCreature.ComponentHealth.Attacked += delegate(ComponentCreature attacker) { if (m_random.Float(0f, 1f) < m_chaseWhenAttackedProbability) { if (m_chaseWhenAttackedProbability >= 1f) { Attack(attacker, 30f, 60f, isPersistent: true); } else { Attack(attacker, 7f, 7f, isPersistent: false); } } }; m_componentCreature.ComponentBody.CollidedWithBody += delegate(ComponentBody body) { if (m_target == null && m_autoChaseSuppressionTime <= 0f && m_random.Float(0f, 1f) < m_chaseOnTouchProbability) { ComponentCreature componentCreature2 = body.Entity.FindComponent <ComponentCreature>(); if (componentCreature2 != null) { bool flag2 = m_subsystemPlayers.IsPlayer(body.Entity); bool flag3 = (componentCreature2.Category & m_autoChaseMask) != 0; if ((flag2 && m_subsystemGameInfo.WorldSettings.GameMode > GameMode.Harmless) || (!flag2 && flag3)) { Attack(componentCreature2, 7f, 7f, isPersistent: false); } } } if (m_target != null && body == m_target.ComponentBody && body.StandingOnBody == m_componentCreature.ComponentBody) { m_componentCreature.ComponentLocomotion.JumpOrder = 1f; } }; m_stateMachine.AddState("LookingForTarget", delegate { m_importanceLevel = 0f; m_target = null; }, delegate { if (IsActive) { m_stateMachine.TransitionTo("Chasing"); } else if (m_autoChaseSuppressionTime <= 0f && (m_target == null || ScoreTarget(m_target) <= 0f) && m_componentCreature.ComponentHealth.Health > 0.4f) { m_range = ((m_subsystemSky.SkyLightIntensity < 0.2f) ? m_nightChaseRange : m_dayChaseRange); ComponentCreature componentCreature = FindTarget(); if (componentCreature != null) { m_targetInRangeTime += m_dt; } else { m_targetInRangeTime = 0f; } if (m_targetInRangeTime > 3f) { bool flag = m_subsystemSky.SkyLightIntensity >= 0.1f; float maxRange = flag ? (m_dayChaseRange + 6f) : (m_nightChaseRange + 6f); float maxChaseTime = flag ? (m_dayChaseTime * m_random.Float(0.75f, 1f)) : (m_nightChaseTime * m_random.Float(0.75f, 1f)); Attack(componentCreature, maxRange, maxChaseTime, (!flag) ? true : false); } } }, null); m_stateMachine.AddState("RandomMoving", delegate { m_componentPathfinding.SetDestination(m_componentCreature.ComponentBody.Position + new Vector3(6f * m_random.Float(-1f, 1f), 0f, 6f * m_random.Float(-1f, 1f)), 1f, 1f, 0, useRandomMovements: false, ignoreHeightDifference: true, raycastDestination: false, null); }, delegate { if (m_componentPathfinding.IsStuck || !m_componentPathfinding.Destination.HasValue) { m_stateMachine.TransitionTo("Chasing"); } if (!IsActive) { m_stateMachine.TransitionTo("LookingForTarget"); } }, delegate { m_componentPathfinding.Stop(); }); m_stateMachine.AddState("Chasing", delegate { m_subsystemNoise.MakeNoise(m_componentCreature.ComponentBody, 0.25f, 6f); m_componentCreature.ComponentCreatureSounds.PlayIdleSound(skipIfRecentlyPlayed: false); m_nextUpdateTime = 0.0; }, delegate { if (!IsActive) { m_stateMachine.TransitionTo("LookingForTarget"); } else if (m_chaseTime <= 0f) { m_autoChaseSuppressionTime = m_random.Float(10f, 60f); m_importanceLevel = 0f; } else if (m_target == null) { m_importanceLevel = 0f; } else if (m_target.ComponentHealth.Health <= 0f) { if (m_componentFeedBehavior != null) { m_subsystemTime.QueueGameTimeDelayedExecution(m_subsystemTime.GameTime + (double)m_random.Float(1f, 3f), delegate { if (m_target != null) { m_componentFeedBehavior.Feed(m_target.ComponentBody.Position); } }); } m_importanceLevel = 0f; } else if (!m_isPersistent && m_componentPathfinding.IsStuck) { m_importanceLevel = 0f; } else if (m_isPersistent && m_componentPathfinding.IsStuck) { m_stateMachine.TransitionTo("RandomMoving"); } else { if (ScoreTarget(m_target) <= 0f) { m_targetUnsuitableTime += m_dt; } else { m_targetUnsuitableTime = 0f; } if (m_targetUnsuitableTime > 3f) { m_importanceLevel = 0f; } else { int maxPathfindingPositions = 0; if (m_isPersistent) { maxPathfindingPositions = (m_subsystemTime.FixedTimeStep.HasValue ? 1500 : 500); } BoundingBox boundingBox = m_componentCreature.ComponentBody.BoundingBox; BoundingBox boundingBox2 = m_target.ComponentBody.BoundingBox; Vector3 v = 0.5f * (boundingBox.Min + boundingBox.Max); Vector3 vector = 0.5f * (boundingBox2.Min + boundingBox2.Max); float num = Vector3.Distance(v, vector); float num2 = (num < 4f) ? 0.2f : 0f; m_componentPathfinding.SetDestination(vector + num2 * num * m_target.ComponentBody.Velocity, 1f, 1.5f, maxPathfindingPositions, useRandomMovements: true, ignoreHeightDifference: false, raycastDestination: true, m_target.ComponentBody); if (m_random.Float(0f, 1f) < 0.33f * m_dt) { m_componentCreature.ComponentCreatureSounds.PlayAttackSound(); } } } }, null); m_stateMachine.TransitionTo("LookingForTarget"); }