protected override void Start() { if (!isServer) { base.Start(); return; } m_AnimAudioController = GetComponent <HerbistarAnimAudioController>(); m_AnimAudioController.OnDyingFinished += Die; Grower = new ScaledGrowth(transform, DataStore.GetFloat(Data.HerbistarInitialScale), DataStore.GetFloat(Data.HerbistarFinalScaleMin), DataStore.GetFloat(Data.HerbistarFinalScaleMax)); AgeData.DaysToGrown = DataStore.GetFloat(Data.HerbistarDaysToGrown); AgeData.LifeSpan = DataStore.GetFloat(Data.HerbistarLifeSpan); BaseSpeed = DataStore.GetFloat(Data.HerbistarBaseSpeed); WanderParameters.Radius = DataStore.GetFloat(Data.HerbistarWanderRadius); WanderParameters.Distance = DataStore.GetFloat(Data.HerbistarWanderDistance); WanderParameters.Jitter = DataStore.GetFloat(Data.HerbistarWanderJitter); base.Start(); Scale = Grower.Scale; BehaviourBrain.In(BehaviourState.Running) .If(() => Health <= 0) .GoTo(BehaviourState.Death) .ExecuteWhileIn(Wander, AnimSwitchUpdate); BehaviourBrain.In(BehaviourState.Death) .DoOnce(Die); BehaviourBrain.Initialize(BehaviourState.Running); }
protected override void Start() { if (Scale > 5f) { Scale = 1f; } else if (Scale < 1f) { Scale = 1f; } transform.localScale = new Vector3(Scale, Scale, Scale); if (FoodPosition == null) { Debug.LogError("FoodPosition is set to null in Gnomehatz", this); } if (!isServer && isClient) { base.Start(); return; } m_AnimAudioController = GetComponent <GnomehatzAnimAudioController>(); m_AnimAudioController.OnEatingFinished += OnEatingFinished; m_AnimAudioController.OnAttackFinished += OnAttackFinished; Grower = new ScaledGrowth(transform, DataStore.GetFloat(Data.GnomehatzInitialScale), DataStore.GetFloat(Data.GnomehatzFinalScaleMin), DataStore.GetFloat(Data.GnomehatzFinalScaleMax)); Grower.StartGrowing(); Scale = Grower.Scale; AgeData.DaysToGrown = DataStore.GetFloat(Data.GnomehatzDaysToGrown); AgeData.LifeSpan = DataStore.GetFloat(Data.GnomehatzLifeSpan); BaseSpeed = DataStore.GetFloat(Data.GnomehatzBaseSpeed); HuntingPeriodSpeed = DataStore.GetFloat(Data.GnomehatzHuntingPeriodSpeed); DaysBetweenReproductions = DataStore.GetFloat(Data.GnomehatzDaysBetweenReproductions); StarvingDamageAmount = DataStore.GetFloat(Data.GnomehatzStarvingDamageAmount); StructureCollisionDamageAmount = DataStore.GetFloat(Data.GnomehatzStructureCollisionDamageAmount); MaximumHerdSizeToAttack = DataStore.GetInt(Data.GnomehatzMaximumHerdSizeToAttack); HerdApproachDistance = DataStore.GetFloat(Data.GnomehatzHerdApproachDistance); SensingRadius = DataStore.GetFloat(Data.GnomehatzSensingRadius); base.Start(); BehaviourBrain.In(BehaviourState.Hunting) .If(() => Health <= 0 || AgeData.DaysOld > AgeData.LifeSpan) .GoTo(BehaviourState.Death) .If(() => ReproductionAllowed && Grower.State == GrowthState.Grown && Health >= 100f && FoodEatenWhileFullLife >= 2 && (AgeData.DaysOld - LastDayOfReproduction) > DaysBetweenReproductions) .GoTo(BehaviourState.Reproducing) .If(() => TimeSinceEating > DayClock.Singleton.DaysToSeconds(1f) && (HerbivoreSensor.Closest != null || ClosestSnatcher != null)) .GoTo(BehaviourState.Attacking) .ExecuteWhileIn(Hunt); BehaviourBrain.In(BehaviourState.Attacking) .If(() => (HerbivoreSensor.Closest == null && ClosestSnatcher == null) || TimeSinceEating < DayClock.Singleton.DaysToSeconds(1f)) .GoTo(BehaviourState.Hunting) .If(() => HerbivoreSensor.KClosest.Count > MaximumHerdSizeToAttack && HerbivoreSensor.Closest != null) .GoTo(BehaviourState.SkirtingHerd) .If(() => GrabbedTarget != null) .GoTo(BehaviourState.Eating) .ExecuteOnEntry(StartAttack) .ExecuteWhileIn(Attack) .ExecuteOnExit(EndAttack); BehaviourBrain.In(BehaviourState.Eating) .If(() => GrabbedTarget == null) .GoTo(BehaviourState.Hunting) .ExecuteOnEntry(StartEating) .ExecuteWhileIn(EatTarget) .ExecuteOnExit(EndEating); BehaviourBrain.In(BehaviourState.SkirtingHerd) .If(() => HerbivoreSensor.KClosest.Count < MaximumHerdSizeToAttack || HerbivoreSensor.Closest == null) .GoTo(BehaviourState.Hunting) .ExecuteWhileIn(SkirtHerd); BehaviourBrain.In(BehaviourState.Reproducing) .DoOnce(Reproduce) .If(() => true) .GoTo(BehaviourState.Hunting); BehaviourBrain.In(BehaviourState.Death) .DoOnce(Die); BehaviourBrain.Initialize(BehaviourState.Hunting); }
public override void OnStartServer() { m_AnimAudioController = GetComponent <TriHorseAnimAudioController>(); m_AnimAudioController.OnEatingFinished += OnEatingFinished; m_AnimAudioController.OnDyingFinished += Die; Grower = new ScaledGrowth(transform, DataStore.GetFloat(Data.TriHorseInitialScale), DataStore.GetFloat(Data.TriHorseFinalScaleMin), DataStore.GetFloat(Data.TriHorseFinalScaleMax)); Grower.StartGrowing(); Scale = Grower.Scale; AgeData.DaysToGrown = DataStore.GetFloat(Data.TriHorseDaysToGrown); AgeData.LifeSpan = DataStore.GetFloat(Data.TriHorseLifeSpan); BaseSpeed = DataStore.GetFloat(Data.TriHorseBaseSpeed); DaysBeforeReproducing = DataStore.GetFloat(Data.TriHorseDaysBeforeReproducing); DaysBetweenReproductions = DataStore.GetFloat(Data.TriHorseDaysBetweenReproductions); StarvingDamageAmount = DataStore.GetFloat(Data.TriHorseStarvingDamageAmount); StructureCollisionDamageAmount = DataStore.GetFloat(Data.TriHorseStructureCollisionDamageAmount); SensingRadius = DataStore.GetFloat(Data.TriHorseSensingRadius); WanderParameters.Radius = DataStore.GetFloat(Data.TriHorseWanderRadius); WanderParameters.Distance = DataStore.GetFloat(Data.TriHorseWanderDistance); WanderParameters.Jitter = DataStore.GetFloat(Data.TriHorseWanderJitter); FlockingOptions.WanderWeight = DataStore.GetFloat(Data.TriHorseWanderWeight); FlockingOptions.AlignmentWeight = DataStore.GetFloat(Data.TriHorseAlignWeight); FlockingOptions.MinDispersion = DataStore.GetFloat(Data.TriHorseMinFlockDispersion); FlockingOptions.MaxDispersion = DataStore.GetFloat(Data.TriHorseMaxFlockDispersion); FlockingOptions.MinDispersionSquared = FlockingOptions.MinDispersion * FlockingOptions.MinDispersion; FlockingOptions.MaxDispersionSquared = FlockingOptions.MaxDispersion * FlockingOptions.MaxDispersion; m_FlockmateSensor = new OctreeSensor <TriHorse>(transform, SensingRadius, 20, OctreeManager.Get(OctreeType.Herbivore)); m_FlockmateSensor.RefreshRate = m_FlockmateSensor.RefreshRate.Randomize(.05f); base.OnStartServer(); Scale = Grower.Scale; BehaviourBrain.In(BehaviourState.SeekingFood) .If(() => Health <= 0) .GoTo(BehaviourState.Death) .If(() => m_InDeathThrows) .GoTo(BehaviourState.Dying) .If(() => m_TimeSinceEating < DayClock.Singleton.DaysToSeconds(.4f)) .GoTo(BehaviourState.Flocking) .If(CanReproduce) .GoTo(BehaviourState.Reproducing) .If(() => m_EatingNodule) .GoTo(BehaviourState.Eating) .ExecuteWhileIn(SeekFood, StarvationCheck); BehaviourBrain.In(BehaviourState.Flocking) .If(() => Health <= 0) .GoTo(BehaviourState.Death) .If(() => m_InDeathThrows) .GoTo(BehaviourState.Dying) .If(() => m_TimeSinceEating > DayClock.Singleton.DaysToSeconds(.4f)) .GoTo(BehaviourState.SeekingFood) .If(CanReproduce) .GoTo(BehaviourState.Reproducing) .ExecuteWhileIn(Flocking); BehaviourBrain.In(BehaviourState.Eating) .If(() => m_InDeathThrows) .GoTo(BehaviourState.Dying) .If(() => !m_EatingNodule) .GoTo(BehaviourState.Flocking) .ExecuteOnEntry(StartEating) .ExecuteWhileIn(EatNodule) .ExecuteOnExit(EndEating); BehaviourBrain.In(BehaviourState.Reproducing) .DoOnce(Reproduce) .If(() => true) .GoTo(BehaviourState.SeekingFood); //Empty state. All action is handled through anim callbacks or outside function calls //Once we enter this state, we do not leave it. BehaviourBrain.In(BehaviourState.Dying); BehaviourBrain.In(BehaviourState.Death) .DoOnce(Die); BehaviourBrain.Initialize(BehaviourState.SeekingFood); //This forces the herbivore to start in the seeking food state m_TimeSinceEating = DayClock.Singleton.DaysToSeconds(.4f); }
protected override void BehaviourUpdate() { m_TimeSinceEating += Time.deltaTime; BehaviourBrain.Update(Time.deltaTime); }
protected override void BehaviourUpdate() { BehaviourBrain.Update(Time.deltaTime); }