public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } if (!Player.Instance.PlayerPickAndDrop.IsHandleFood) { status = GoalStatus.Failed; return; } switch (eatInPlayerHandState) { case EatInPlayerHandState.Catch: if (child.IsComplete) { Player.Instance.PlayerPickAndDrop.DropOffFood(); AddSubgoal(new GoalEatFood(owner, owner.Steering.Aim)); eatInPlayerHandState = EatInPlayerHandState.Eat; owner.Creature.currentEmotion = EmotionState.Friendly; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } bool enemyClose = false; bool obstacleClose = false; IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); foreach (DataCreature data in creatures) { Agent agent = data.creature?.agentCreature; if (!agent || !agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 5f) { continue; } bool isHostil = CreatureIsHostil(owner, agent.Creature); if (isHostil && Vector3.Distance(owner.transform.position, agent.transform.position) < owner.PerceptionConfig.viewRadius / 4) { enemyClose = true; break; } } DataObstacle obstacle = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f); obstacleClose = obstacle != null; switch (evadeState) { case EvadeState.Flee: if (!enemyClose && obstacleClose) { child.Abort(); AddSubgoal(new GoalHide(owner)); evadeState = EvadeState.Hide; } break; case EvadeState.Hide: if (enemyClose) { child.Abort(); AddSubgoal(new GoalFlee(owner)); evadeState = EvadeState.Flee; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } DesirabilitiesConfig desirabilitiesConfig = GameManager.Instance.DesirabilitiesConfig; float vigilanceConsideration = desirabilitiesConfig.DefensePlayerConsiderationMinVigilance; float vigilance = desirabilitiesConfig.DefensePlayerDesirabilityByAggressivity.Evaluate(owner.Creature.Traits.Vigilance.Value) * (1 / vigilanceConsideration); float distToObserve = Mathf.Lerp(minDistToObserve, maxDistToObserve, 1 - vigilance); bool playerClose = owner.Memory.Player.lastSeeTime > Time.time - 1f && Vector3.Distance(owner.transform.position, Player.Instance.transform.position) < distToObserve; switch (evadeState) { case ObserveState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalLookAtPlayer(owner)); evadeState = ObserveState.LookAt; } else if (playerClose) { child.Abort(); AddSubgoal(new GoalLookAtPlayer(owner)); evadeState = ObserveState.LookAt; } break; case ObserveState.LookAt: if (!playerClose) { child.Abort(); AddSubgoal(new GoalPursuitPlayer(owner)); evadeState = ObserveState.Pursuit; } break; } if (Time.time - timeStart >= desirabilitiesConfig.ObservePlayerMaxTimeSpend) { status = GoalStatus.Completed; } base.ProcessSubgoals(); }
public override void Process() { if (status == GoalStatus.Inactive) { Activate(); } if (status == GoalStatus.Failed) { return; } Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } if (squad.IsDisband) { status = GoalStatus.Failed; } else { //squad.DebugLine(); } switch (shareState) { case ShareState.Pursuit: if (child.IsComplete) { if (iAmLeader) { AddSubgoal(new GoalTalk(owner, partner, memoryType, iAmLeader)); shareState = ShareState.Talk; } else { AddSubgoal(new GoalLookAt(owner, partner)); shareState = ShareState.Talk; } } break; } base.ProcessSubgoals(); }
public override void Process() { if (status == GoalStatus.Inactive) { Activate(); } if (status == GoalStatus.Failed) { return; } Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } if (squad.IsDisband) { status = GoalStatus.Failed; } else { //squad.DebugLine(); } switch (reproduceState) { case ReproduceState.Pursuit: if (child.IsComplete) { if (iAmleader) { AddSubgoal(new GoalBreed(owner, partner.Creature)); reproduceState = ReproduceState.Breed; } else { AddSubgoal(new GoalIdle(owner)); reproduceState = ReproduceState.Breed; } } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } if (Vector3.Distance(owner.transform.position, owner.Steering.Destination) < 1f) { status = GoalStatus.Completed; } base.ProcessSubgoals(); }
private bool ActivateGoals(bool p_activate) { List <QuestStep> steps = GetCurrentSteps(); if (steps != null && steps.Count > 0) { List <NPC> currentNPCs = new List <NPC>(); foreach (QuestStep step in steps) { if (p_activate) { step.SetGoal(Goal.Activate(m_player, this, step.m_goal)); NPC handInNPC = step.GetGoal().m_handInNPC; if (handInNPC && handInNPC != null) { if (!currentNPCs.Contains(handInNPC)) { currentNPCs.Add(handInNPC); } if (!m_npcHistory.Contains(handInNPC)) { m_npcHistory.Add(handInNPC); } } } else { step.GetGoal().Deactivate(m_player); } } m_currentNPCs.Clear(); m_currentNPCs.AddRange(currentNPCs); return(true); } return(false); }
public static Goal Activate(Entity p_entity, Quest p_quest, string p_goal) { if (m_defaultGoals.Count == 0) { LoadGoals(); } string[] split = p_goal.Split(' '); Goal found = m_defaultGoals.Find(r => r.m_type == split[0]); if (found != null) { Goal newGoal = (Goal)Activator.CreateInstance(found.GetType()); // unsure if this will even work newGoal.m_associatedQuest = p_quest; newGoal.Activate(p_entity, p_goal.Replace(split[0] + " ", "").Split(' ')); return(newGoal); } return(null); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } switch (tiredState) { case TiredState.ReachNest: if (child.HasFailed || child.IsComplete) { AddSubgoal(new GoalSleep(owner)); tiredState = TiredState.Sleep; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } bool playerClose = owner.Memory.Player.lastSeeTime > Time.time - 5f && Vector3.Distance(owner.transform.position, Player.Instance.transform.position) < owner.PerceptionConfig.viewRadius / 4; DataObstacle obstacle = owner.Memory.Obstacles.Read().FirstOrDefault(data => MaxColliderSize(data.collider) >= 2f); bool obstacleClose = obstacle != null; switch (evadeState) { case EvadeState.Flee: if (!playerClose && obstacleClose) { child.Abort(); AddSubgoal(new GoalHidePlayer(owner)); evadeState = EvadeState.Hide; } break; case EvadeState.Hide: if (playerClose) { child.Abort(); AddSubgoal(new GoalFleePlayer(owner)); evadeState = EvadeState.Flee; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } switch (searchFoodState) { case SearchFoodState.Find: if (child.HasFailed) { //TODO AddSubgoal(new GoalCommunicate(owner, MemoryType.FoodSources)); searchFoodState = SearchFoodState.Communicate; //AddSubgoal(new GoalWander(owner)); //searchFoodState = SearchFoodState.Wander; } break; case SearchFoodState.Communicate: if (child.IsComplete || child.HasFailed) { AddSubgoal(new GoalFindSourceFood(owner, filter)); searchFoodState = SearchFoodState.Find; } break; case SearchFoodState.Wander: break; } base.ProcessSubgoals(); }
protected void ProcessSubgoals() { int nbSubgoals = subgoals.Count; bool lastGoalFailed = false; while (nbSubgoals != 0 && (subgoals.Peek().IsComplete || subgoals.Peek().HasFailed)) { Goal endGoal = subgoals.Dequeue(); lastGoalFailed = endGoal.HasFailed; endGoal.Terminate(); --nbSubgoals; } if (nbSubgoals != 0) { Goal activeGoal = GetActiveGoal(); if (activeGoal.IsInactive) { activeGoal.Activate(); } activeGoal.Process(); if (activeGoal.IsComplete && nbSubgoals > 1) { status = GoalStatus.Active; } } else { status = lastGoalFailed ? GoalStatus.Failed : GoalStatus.Completed; } }
public override void Process() { Goal child = GetActiveGoal(); if (child != null && child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent aggresor = null; float distanceToAggresor = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } bool isHostil = GoalEvade.CreatureIsHostil(owner, agent.Creature); if (!isHostil) { continue; } //bool attackSpecies = agent.Steering.Target && agent.Steering.Target.Creature.SpecieID == owner.Creature.SpecieID; //if(!attackSpecies) continue; float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (agent != owner && agent.Creature.SpecieID != owner.Creature.SpecieID && distanceToAgent < distanceToAggresor) { aggresor = agent; distanceToAggresor = distanceToAgent; } } switch (defenseState) { case DefenseState.LookAt: if (aggresor == null) { if (child != null) { child.Abort(); } } else if (owner.Steering.Behavior != eSteeringBehavior.LookAt) { AddSubgoal(new GoalLookAt(owner, aggresor)); } /*else if(aggresor.Steering.Target != owner){ * if(child != null) child.Abort(); * AddSubgoal(new GoalPursuit(owner, aggresor)); * defenseState = DefenseState.Pursuit; * }*/ else if (distanceToAggresor < 2) { if (child != null) { child.Abort(); } AddSubgoal(new GoalAttack(owner, aggresor.Creature)); defenseState = DefenseState.Attack; } else { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (aggresor.Steering.Target == agent) { friendAggresed = true; break; } } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuit(owner, aggresor)); if (Random.value > 0.5f) { owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureDefense); } defenseState = DefenseState.Pursuit; } } break; case DefenseState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalAttack(owner, owner.Steering.Target.Creature)); defenseState = DefenseState.Attack; } else if (child.HasFailed) { defenseState = DefenseState.LookAt; } else if (aggresor != null) { if ((owner.Steering.Behavior == eSteeringBehavior.Pursuit || owner.Steering.Behavior == eSteeringBehavior.Seek) && aggresor != owner.Steering.Target && Vector3.Distance(owner.transform.position, aggresor.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Destination)) { child.Abort(); AddSubgoal(new GoalPursuit(owner, aggresor)); } } break; case DefenseState.Attack: if (aggresor == null) { break; } if (child.IsComplete || child.HasFailed) { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (aggresor.Steering.Target == agent) { friendAggresed = true; break; } } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuit(owner, aggresor)); defenseState = DefenseState.Pursuit; } else { AddSubgoal(new GoalLookAt(owner, aggresor)); defenseState = DefenseState.LookAt; } /*if(aggresor.Steering.Target != owner){ * AddSubgoal(new GoalPursuit(owner, aggresor)); * defenseState = DefenseState.Pursuit; * }else{ * AddSubgoal(new GoalLookAt(owner, aggresor)); * defenseState = DefenseState.LookAt; * }*/ } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child != null && child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent aggresor = null; float distanceToAggresor = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent || !agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (agent.Thinking.ActiveGoal?.GetType() == typeof(GoalTired)) { continue; } Goal goal = agent.Thinking.ActiveGoal; if (!(goal is GoalDefensePlayer)) { continue; } Goal subGoal = (goal as GoalComposite).GetActiveGoal(); if (subGoal == null || (!(subGoal is GoalPursuitPlayer) && !(subGoal is GoalAttackPlayer))) { continue; } float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (agent != owner && agent.Creature.SpecieID != owner.Creature.SpecieID && distanceToAgent < distanceToAggresor) { aggresor = agent; distanceToAggresor = distanceToAgent; } } if (!aggresor) { status = GoalStatus.Completed; return; } switch (protectState) { case ProtectState.Start: AddSubgoal(new GoalPursuit(owner, aggresor)); protectState = ProtectState.Pursuit; break; case ProtectState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalAttack(owner, owner.Steering.Target.Creature)); protectState = ProtectState.Attack; } else if ((owner.Steering.Behavior == eSteeringBehavior.Pursuit || owner.Steering.Behavior == eSteeringBehavior.Seek) && aggresor != owner.Steering.Target && Vector3.Distance(owner.transform.position, aggresor.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Destination)) { child.Abort(); AddSubgoal(new GoalPursuit(owner, aggresor)); } break; case ProtectState.Attack: if (child.IsComplete || child.HasFailed) { AddSubgoal(new GoalPursuit(owner, aggresor)); protectState = ProtectState.Pursuit; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent edible = null; float distanceToEdible = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (data.RegistrationDate < Time.time - 2f || !agent.gameObject.activeSelf) { continue; } float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (!ShouldAttack(agent.Creature)) { continue; } if (agent != owner && GetCreatureFilter()(agent.Creature) && distanceToAgent < distanceToEdible) { edible = agent; distanceToEdible = distanceToAgent; } } switch (huntState) { case HuntState.Search: if (child.HasFailed) { AddSubgoal(new GoalSeekNest(owner, new List <int>(owner.Memory.Species.GetByKey(owner.Creature.SpecieID).PreyIDs))); huntState = HuntState.SeekNest; } if (!edible) { break; } child.Abort(); AddSubgoal(new GoalPursuit(owner, edible)); //Ajout de son //owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureFindFood); huntState = HuntState.Pursuit; break; case HuntState.SeekNest: if (child.HasFailed) { AddSubgoal(new GoalWander(owner)); huntState = HuntState.Wander; } if (!edible) { break; } child.Abort(); AddSubgoal(new GoalPursuit(owner, edible)); //Ajout de son //owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureFindFood); huntState = HuntState.Pursuit; break; case HuntState.Wander: if (!edible) { break; } child.Abort(); AddSubgoal(new GoalPursuit(owner, edible)); //Ajout de son //owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureFindFood); huntState = HuntState.Pursuit; break; case HuntState.Pursuit: if (child.IsComplete) { if (Attacking.IsVictimWillDie(owner.Steering.Target.Creature, owner.Creature)) { AddSubgoal(new GoalEatCreature(owner, owner.Steering.Target.Creature)); huntState = HuntState.Eat; } else { AddSubgoal(new GoalAttack(owner, owner.Steering.Target.Creature)); huntState = HuntState.Attack; } } else if (child.HasFailed) { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); huntState = HuntState.Search; } else if (edible != null) { if (owner.Steering.Behavior == eSteeringBehavior.Pursuit && edible == owner.Steering.Target && !ShouldAttack(edible.Creature)) { child.Abort(); AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); huntState = HuntState.Search; } else if (owner.Steering.Behavior == eSteeringBehavior.Seek || (owner.Steering.Behavior == eSteeringBehavior.Pursuit && edible != owner.Steering.Target)) { if ((owner.Steering.Behavior == eSteeringBehavior.Seek && Vector3.Distance(owner.transform.position, edible.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Destination)) || (owner.Steering.Behavior == eSteeringBehavior.Pursuit && (!owner.Steering.Target || Vector3.Distance(owner.transform.position, edible.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Target.transform.position)))) { child.Abort(); AddSubgoal(new GoalPursuit(owner, edible)); } } else if (owner.Creature.DNADistortion.HaveParticularity(typeof(Vacuum))) { if (Vector3.Distance(owner.transform.position, edible.transform.position) < 11) { Vacuum vacuum = owner.Creature.DNADistortion.GetParticularity(typeof(Vacuum)) as Vacuum; if (vacuum.IsRecharged()) { child.Abort(); AddSubgoal(new GoalLookAt(owner, edible)); huntState = HuntState.Vacuum; vacuumTime = Time.time; vacuum.Active(); } } } /*if((owner.Steering.Behavior == eSteeringBehavior.Pursuit && edible != owner.Steering.Target) || owner.Steering.Behavior == eSteeringBehavior.Seek && Vector3.Distance(owner.transform.position, edible.transform.position) + 5f < Vector3.Distance(owner.transform.position, owner.Steering.Destination)){ || child.Abort(); || AddSubgoal(new GoalPursuit(owner, edible)); || }*/ } else { child.Abort(); AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); huntState = HuntState.Search; } break; case HuntState.Attack: if (child.IsComplete || child.HasFailed) { AddSubgoal(new GoalPursuit(owner, owner.Steering.Target)); huntState = HuntState.Pursuit; } break; case HuntState.Vacuum: if (!edible) { status = GoalStatus.Failed; break; } float distance = Vector3.Distance(owner.transform.position, edible.transform.position); if (distance < 3) { child.Abort(); AddSubgoal(new GoalEatCreature(owner, owner.Steering.Target.Creature)); huntState = HuntState.Eat; (owner.Creature.DNADistortion.GetParticularity(typeof(Vacuum)) as Vacuum).Desactive(); } else if (distance > 12 || Time.time - vacuumTime > 15) { (owner.Creature.DNADistortion.GetParticularity(typeof(Vacuum)) as Vacuum).Desactive(); status = GoalStatus.Failed; } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent friend = null; float distanceToFriend = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (agent == owner) { continue; } if (data.RegistrationDate < Time.time - 0.5f || !agent.gameObject.activeSelf) { continue; } if (!agent.IsThinking || agent.IsThrow) { continue; } float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (distanceToAgent >= distanceToFriend) { continue; } /*bool recentTalk = false; * IReadOnlyCollection<DataCommunication> communications = owner.Memory.Communications.Read(); * foreach(DataCommunication com in communications){ * if(com.creature == agent.Creature && com.subject == memoryType){ * recentTalk = true; * break; * } * }*/ if (GetCreatureFilter()(agent.Creature)) { friend = agent; distanceToFriend = distanceToAgent; } } switch (communicateState) { case CommunicateState.Search: if (child.HasFailed) { AddSubgoal(new GoalSeekNest(owner)); communicateState = CommunicateState.SeekNest; } if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.SeekNest: if (child.HasFailed) { AddSubgoal(new GoalWander(owner)); communicateState = CommunicateState.Wander; } if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.Wander: if (!friend) { break; } child.Abort(); asked.Add(friend.Creature); if (friend.Thinking.RequestGoal(GoalCommunication_Evaluator.Instance)) { Squad squad = new Squad(owner, friend); AddSubgoal(new GoalShare(owner, friend, memoryType, squad)); friend.Thinking.ActiveGoal = new GoalShare(friend, owner, memoryType, squad); communicateState = CommunicateState.Share; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case CommunicateState.Share: if (child.HasFailed) { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); communicateState = CommunicateState.Search; } break; } base.ProcessSubgoals(); }
public void ActivateSubGoal(Goal _g) { if (this.HasGoal(_g)) { _g.Activate(); } }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataCreature> creatures = owner.Memory.Creatures.Read(); Agent partenaire = null; float distanceToFriend = Mathf.Infinity; foreach (DataCreature data in creatures) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (asked.Contains(data.creature)) { continue; } if (data.RegistrationDate < Time.time - 0.5f || !agent.gameObject.activeSelf) { continue; } if (!agent.IsThinking || agent.IsThrow) { continue; } float distanceToAgent = Vector3.Distance(owner.transform.position, agent.transform.position); if (agent != owner && agent.Creature.SpecieID == owner.Creature.SpecieID && distanceToAgent < distanceToFriend) { partenaire = agent; distanceToFriend = distanceToAgent; } } switch (reproductionState) { case ReproductionState.Search: if (child.HasFailed) { AddSubgoal(new GoalSeekNest(owner)); reproductionState = ReproductionState.SeekNest; } if (!partenaire) { break; } child.Abort(); asked.Add(partenaire.Creature); if (partenaire.Thinking.RequestGoal(GoalReproduction_Evaluator.Instance)) { Squad squad = new Squad(owner, partenaire); AddSubgoal(new GoalReproduce(owner, partenaire, squad)); partenaire.Thinking.ActiveGoal = new GoalReproduce(partenaire, owner, squad); reproductionState = ReproductionState.Reproduce; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case ReproductionState.SeekNest: if (child.HasFailed) { AddSubgoal(new GoalWander(owner)); reproductionState = ReproductionState.Wander; } if (!partenaire) { break; } child.Abort(); asked.Add(partenaire.Creature); if (partenaire.Thinking.RequestGoal(GoalReproduction_Evaluator.Instance)) { Squad squad = new Squad(owner, partenaire); AddSubgoal(new GoalReproduce(owner, partenaire, squad)); partenaire.Thinking.ActiveGoal = new GoalReproduce(partenaire, owner, squad); reproductionState = ReproductionState.Reproduce; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case ReproductionState.Wander: if (!partenaire) { break; } child.Abort(); asked.Add(partenaire.Creature); if (partenaire.Thinking.RequestGoal(GoalReproduction_Evaluator.Instance)) { Squad squad = new Squad(owner, partenaire); AddSubgoal(new GoalReproduce(owner, partenaire, squad)); partenaire.Thinking.ActiveGoal = new GoalReproduce(partenaire, owner, squad); reproductionState = ReproductionState.Reproduce; } else { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); } break; case ReproductionState.Reproduce: if (child.HasFailed) { AddSubgoal(new GoalSearchCreature(owner, GetCreatureFilter())); reproductionState = ReproductionState.Search; } break; } base.ProcessSubgoals(); }
public override void Process() { DesirabilitiesConfig desirabilitiesConfig = GameManager.Instance.DesirabilitiesConfig; float vigilanceConsideration = desirabilitiesConfig.DefensePlayerConsiderationMinVigilance; float vigilance = (desirabilitiesConfig.DefensePlayerDesirabilityByAggressivity.Evaluate(owner.Creature.Traits.Vigilance.Value) - vigilanceConsideration) * (1 / (1 - vigilanceConsideration)); vigilance *= (Player.Instance.PlayerController.Velocity.magnitude * desirabilitiesConfig.DefensePlayerPlayerSpeedThreatWeight); float distToAttack = Mathf.Lerp(minDistToAttack, maxDistToAttack, vigilance); float distToPursuit = Mathf.Lerp(minDistToPursuit, maxDistToPursuit, vigilance); Vector3 playerPos = Player.Instance.transform.position; float distanceToPlayer = Vector3.Distance(owner.transform.position, playerPos); Goal child = GetActiveGoal(); if (child != null && child.IsInactive) { child.Activate(); } switch (defenseState) { case DefenseState.LookAt: if (owner.Steering.Behavior != eSteeringBehavior.LookAtPlayer) { AddSubgoal(new GoalLookAtPlayer(owner)); } else if (distanceToPlayer < 2) { if (child != null) { child.Abort(); } AddSubgoal(new GoalAttackPlayer(owner)); defenseState = DefenseState.Attack; timeStart = Time.time; } else if (Time.time - timeStart >= desirabilitiesConfig.DefensePlayerMaxTimeSpend) { status = GoalStatus.Completed; } else { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; Agent friend = null; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (Vector3.Distance(agent.transform.position, playerPos) < distToAttack) { friendAggresed = true; friend = agent; break; } } if (!friendAggresed) { friendAggresed = Vector3.Distance(owner.transform.position, playerPos) < distToAttack; friend = owner; } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuitPlayer(owner)); defenseState = DefenseState.Pursuit; if (Random.value > 0.5f) { owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureDefense); } timeStart = Time.time; } } break; case DefenseState.Pursuit: if (child.IsComplete) { AddSubgoal(new GoalAttackPlayer(owner)); defenseState = DefenseState.Attack; } else if (child.HasFailed) { defenseState = DefenseState.LookAt; } else if (Vector3.Distance(owner.transform.position, playerPos) > distToPursuit) { child.Abort(); defenseState = DefenseState.LookAt; } break; case DefenseState.Attack: if (child.IsComplete || child.HasFailed) { IReadOnlyCollection <DataCreature> friends = owner.Memory.Creatures.Read(); bool friendAggresed = false; Agent friend = null; foreach (DataCreature data in friends) { if (!data.creature) { continue; } Agent agent = data.creature.agentCreature; if (!agent.gameObject.activeSelf || data.RegistrationDate < Time.time - 1f) { continue; } if (Vector3.Distance(agent.transform.position, playerPos) < distToAttack) { friendAggresed = true; friend = agent; break; } } if (!friendAggresed) { friendAggresed = Vector3.Distance(owner.transform.position, playerPos) < distToAttack; friend = owner; } if (friendAggresed) { if (child != null) { child.Abort(); } AddSubgoal(new GoalPursuitPlayer(owner)); defenseState = DefenseState.Pursuit; } else { AddSubgoal(new GoalLookAtPlayer(owner)); defenseState = DefenseState.LookAt; } } break; } base.ProcessSubgoals(); }
public override void Process() { Goal child = GetActiveGoal(); if (child.IsInactive) { child.Activate(); } IReadOnlyCollection <DataFood> foods = owner.Memory.Foods.Read(); Food edible = null; float distanceToEdible = Mathf.Infinity; foreach (DataFood data in foods) { if (!data.food) { continue; } Food food = data.food; if (!food || !food.gameObject.activeSelf || !food.Eatable) { continue; } if (Player.Instance.PlayerPickAndDrop.IsHandleFood && Player.Instance.PlayerPickAndDrop.TransportableFruit == food) { continue; } if (data.RegistrationDate < Time.time - 0.5f) { continue; } if (!GetFoodTypeFilter()(food.tag == "Fruit" ? FoodType.Fruit : FoodType.Vegetable)) { continue; } float distanceToFood = Vector3.Distance(owner.transform.position, food.transform.position); if (distanceToFood < distanceToEdible) { edible = food; distanceToEdible = distanceToFood; } } switch (harvestState) { case HarvestState.Search: if (!edible) { break; } child.Abort(); AddSubgoal(new GoalCatch(owner, edible.transform)); //Ajout de son //owner.Creature.AudioBox.PlayOneShot(SoundOneShot.CreatureFindFood); harvestState = HarvestState.Catch; break; case HarvestState.Catch: if (child.IsComplete) { AddSubgoal(new GoalEatFood(owner, owner.Steering.Aim)); harvestState = HarvestState.Eat; } else if (child.HasFailed) { AddSubgoal(new GoalSearchFood(owner, GetFoodTypeFilter())); harvestState = HarvestState.Search; } else if (edible != null) { if ((owner.Steering.Behavior == eSteeringBehavior.Catch && edible != owner.Steering.Aim.gameObject) || owner.Steering.Behavior == eSteeringBehavior.Seek && Vector3.Distance(owner.transform.position, edible.transform.position) < Vector3.Distance(owner.transform.position, owner.Steering.Destination)) { AddSubgoal(new GoalCatch(owner, edible.transform)); child.Abort(); } } break; } base.ProcessSubgoals(); }