//MonoBehaviour calls private void Start() { _aiBrain = GetComponentInParent <AIBrain>(); }
public override void GeneralPostEffects(AIBrain ai) { ai.WorldState.SetKey(DS.isNearCurrentTarget, false); }
public override bool IsInterruptableBySystems(AIBrain ai) { return(false); }
virtual public void StopLooking(AIBrain ai) { }
public override void Activate(AIBrain ai) { ai.GetStateSystem <AIStateSystemWeapon>().HitMelee(ai); ai.GetStateSystem <AIStateSystemAnimator>().DisableLayer(ai, 1, false, false); }
virtual public void SetLookAtPosNStartLook(AIBrain ai, Vector3 position, ET.LookAtType lookAtType) { }
virtual public void SetLookAtPosNStartLook(AIBrain ai, ET.LookAtType lookAtType) { }
// These are for reference public virtual T RequestInfo <T>(AIBrain ai) where T : InformationP { return(null); }
public virtual List <T> RequestAllInfo <T>(AIBrain ai) where T : InformationP { return(null); }
public override bool IsApplicapable(AIBrain ai) { bool canApplyToBlackboard = ai.HaveCurrentTarget(); return(canApplyToBlackboard && ai.WorldState.CompareKey(DS.haveTarget, true)); }
public override void OnStart(AIBrain ai) { goalStates.Add(DS.killTarget, true); }
public override void Start() { base.Start(); EntityType type = EntityType.Companion; AddType(type); safeLocations = new List <Vector3>(); InvokeRepeating("MarkLocation", 1, 5); gunController = GetComponent <GunController>(); blackboard.treeData.Add("companion", this); blackboard.treeData.Add("eyes", eyes); blackboard.treeData.Add("gunController", gunController); NodeSequencer root = new NodeSequencer(new BTNode[] { new NodeSelector(new BTNode[] { new NodeAlwaysFail( new ActionCheckHitLocation() ), new NodeSequencer(new BTNode[] { new ActionReachedTarget(), new NodeInverter( new ActionCheckHideTimer() ), new ActionGetHidePosition(), new ActionRequestPathToTarget() }), new NodeSequencer(new BTNode[] { new ActionCheckOverwatch(), new ActionReachedTarget(), new ActionLookForEnemy(), new NodeCounter( new NodeSequencer(new BTNode[] { new ActionGetOverwatchPosition(), new ActionRequestPathToTarget() }), 4 ) }), new NodeSequencer(new BTNode[] { new ActionCheckForEnemiesInSight(), new NodeSelector(new BTNode[] { new ActionCheckAggressiveStance(), new ActionCheckDefensiveStance(), new NodeCounter( new NodeSequencer(new BTNode[] { new ActionReachedTarget(), new ActionGetHidePosition(), new ActionRequestPathToTarget() }), 1 ) }) }), new ActionToggleFlank(), new NodeInverter( new NodeSelector(new BTNode[] { new NodeInverter( new ActionCheckScavangeAction() ), new NodeInverter( new NodeSelector(new BTNode[] { new NodeCounter( new ActionCheckScavangeStatus(), 10 ), new NodeCounter( new NodeSequencer(new BTNode[] { new ActionReachedTarget(), new ActionGetScavangeLocation(), new ActionRequestPathToTarget() }), 5 ) }) ), new NodeSequencer(new BTNode[] { new ActionStopMovement(), new ActionGiveMedKitToPlayer(), new ActionRequestPathToTarget() }) }) ), new NodeSequencer(new BTNode[] { new NodeCounter( new NodeInverter( new ActionCheckFollowPosition() ), 0.5f ), new NodeSequencer(new BTNode[] { new ActionReachedTarget(), new ActionGetFollowPosition(), new ActionRequestPathToTarget() }) }) }), new NodeSelector(new BTNode[] { new NodeSequencer(new BTNode[] { new NodeCounter( new NodeInverter( new ActionCheckFollowPosition() ), 2 ), new ActionGetFollowPosition(), new ActionRequestPathToTarget() }), new NodeSelector(new BTNode[] { new NodeSequencer(new BTNode[] { new NodeInverter( new ActionCheckDefensiveStance() ), new ActionCheckForEnemiesInSight(), new NodeAlwaysFail( new ActionUseWeapon() ) }), new NodeSequencer(new BTNode[] { new ActionCheckPlayerTarget(), new ActionUseWeapon() }) }), new NodeSelector(new BTNode[] { new NodeSequencer(new BTNode[] { new ActionCheckFlankAction(), new NodeSequencer(new BTNode[] { new ActionGetAttackPosition(), new ActionRequestPathToTarget() }) }), new NodeSequencer(new BTNode[] { new NodeInverter( new ActionCheckFlankAction() ), new ActionReachedTarget(), new ActionToggleFlank() }) }) }) }); brain = new AIBrain(root, blackboard); brain.Start(); }
public override void Initialize(GameObject target, float duration, float interval, Constants.StatusEffectType statusType, SpecialAbility sourceAbility, int maxStack = 1, Effect onCompleteEffect = null) { base.Initialize(target, duration, interval, statusType, sourceAbility, maxStack); targetBrain = target.GetComponent <AIBrain>(); }
// Use this for initialization void Start() { myBrain = GetComponentInParent <AIBrain>(); }
public override bool IsCompleted(AIBrain ai) { return(base.IsCompleted(ai)); }
public float activatablePercentage = 80; // % public override void OnStart(AIBrain ai) { goalStates.Add(DS.bulletDodged, true); }
public override bool IsStillValid(AIBrain ai) { return(base.IsStillValid(ai)); }
private void Awake() { health = GetComponent <Health>(); stateSystems.Add(new AIShooterStateSystemAnimator(animatorProps, GetComponent <Animator>())); stateSystems.Add(new AIShooterStateSystemLookAt(lookIKProps)); stateSystems.Add(new AIShooterStateSystemMove(movementProps, patrolRoute)); stateSystems.Add(new AIShooterStateSystemWeapon(fireProps, weaponHandIKProps)); states.Add(new IdleState(stateSystems.ToArray())); states.Add(new AnimateState(stateSystems.ToArray())); states.Add(new MoveState(stateSystems.ToArray())); sensorSet.sensorList.RemoveAll(x => x == null); systemSet.systemList.RemoveAll(x => x == null); actionSet.actionList.RemoveAll(x => x == null); goalSet.goalList.RemoveAll(x => x == null); if (sensorSet == null || systemSet == null || goalSet == null || actionSet == null) { #if UNITY_EDITOR Debug.Log("You need to fill all sets"); #endif this.enabled = false; return; } List <AISensor> cloneSensors = new List <AISensor>(); foreach (AISensor sensor in sensorSet.sensorList) { cloneSensors.Add(UnityEngine.Object.Instantiate(sensor) as AISensor); } List <AIAction> cloneActions = new List <AIAction>(); foreach (AIAction action in actionSet.actionList) { cloneActions.Add(UnityEngine.Object.Instantiate(action) as AIAction); } List <AISystem> cloneSystems = new List <AISystem>(); foreach (AISystem system in systemSet.systemList) { cloneSystems.Add(UnityEngine.Object.Instantiate(system) as AISystem); } List <AIGoal> cloneGoals = new List <AIGoal>(); foreach (AIGoal goal in goalSet.goalList) { cloneGoals.Add(UnityEngine.Object.Instantiate(goal) as AIGoal); } AIMemoryShooter memory = new AIMemoryShooter(gameObject, 150, 2, 25, friendMask); GetComponent <SharedProps>().memory = memory; //初始化大脑 ai = new AIBrain( cloneSensors, cloneSystems, cloneActions, cloneGoals, states, stateSystems, brainProps, transform, memory, ref onAgentDead ); ai.OnAwake(); footSoundFx = new FootPlanting(footStepFx, GetComponent <Animator>()); }
virtual public void SetLookAtPosition(AIBrain ai, ET.LookAtType lookAtType) { }
// Use this for initialization public override void Start() { base.Start(); EntityType type = EntityType.Enemy | EntityType.HunterEnemy; AddType(type); enemyNearby = false; blackboard = new Blackboard(); gunController = GetComponent <GunController>(); blackboard.treeData.Add("entity", this); blackboard.treeData.Add("eyes", eyes); blackboard.treeData.Add("gunController", gunController); NodeSequencer root = new NodeSequencer(new BTNode[] { new NodeSelector(new BTNode[] { new NodeSelector(new BTNode[] { new ActionCheckForEnemiesInSight(), new NodeAlwaysFail( new NodeSequencer(new BTNode[] { new ActionCheckHitLocation(), new ActionRequestPathToTarget() }) ), new NodeSequencer(new BTNode[] { new ActionGetLastSightedSearchPosition(), new ActionRequestPathToTarget() }), new NodeSequencer(new BTNode[] { new ActionSearchingForEnemyBool(), new NodeInverter( new ActionReachedTarget() ) }), new ActionCheckForEnemiesNearby() }), new NodeSequencer(new BTNode[] { new ActionReachedTarget(), new ActionLookForEnemy(), new NodeCounter( new ActionMoveToPlayer(), 5 ), new NodeAlwaysFail( new ActionRequestPathToTarget() ) }) }), new NodeSelector(new BTNode[] { new ActionCheckForEnemiesInSight(), new NodeAlwaysFail( new ActionLookForEnemy() ) }), new NodeSelector(new BTNode[] { new NodeSequencer(new BTNode[] { new NodeSequencer(new BTNode[] { new NodeAlwaysSuccess( new NodeCounter( new ActionMoveToPlayer(), 1 ) ), new ActionUseWeapon(), new ActionReachedTarget() }) }), new NodeAlwaysSuccess( new NodeSequencer(new BTNode[] { new NodeInverter( new ActionCheckAttackPosition() ), new ActionMoveToPlayer(), new ActionRequestPathToTarget() }) ) }), new ActionRequestPathToTarget() }); brain = new AIBrain(root, blackboard); brain.Start(); }
virtual public void StartLooking(AIBrain ai) { }
public override void Activate(AIBrain ai) { base.Activate(ai); ai.GetStateSystem <AIStateSystemMove>().SetTurnToPosNStartTurn(ai, ET.TurnToType.ToCurrentTarget); }
private void Start() { aiBrain = GetComponentInParent <AIBrain>(); GameManager.instance.OnStartGame += SpawnBall; }
public override bool CanActivate(AIBrain ai) { return(true); }
public override void DeActivate(AIBrain ai) { ai.WorldState.SetKey(DS.isNearCurrentTarget, false); }
public override bool CanBeAddedToPlan(AIBrain ai) { return(base.CanBeAddedToPlan(ai) && Random.Range(0, 100) < addToPlanPercentage && ai.HaveCurrentWeapon()); }
public override bool IsCompleted(AIBrain ai) { return(ai.GetStateSystem <AIStateSystemWeapon>().IsMeleeHitEnded(ai)); }
public override void DeActivate(AIBrain ai) { ai.GetStateSystem <AIStateSystemMove>().StopTurning(ai); base.DeActivate(ai); ai.WorldState.SetKey(DS.atSafePosition, false); }
public override void OnUpdate(ref bool needToReplan, ref bool needToReevaluateGoals, AIBrain ai) { if (ai.HaveCurrentTarget()) { // target is dead if (ai.InfoCurrentTarget.IsDead || ai.InfoCurrentTarget.transform && ai.InfoCurrentTarget.transform.GetComponent <Health>() && ai.InfoCurrentTarget.transform.GetComponent <Health>().health <= 0 ) { var tempCTarget = ai.InfoCurrentTarget; ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; tempCTarget.IsDead = true; ai.Memory.BroadcastToListeners(new Messages.AIMessageTargetDead(tempCTarget.BaseTransform)); var susps = ai.Memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == tempCTarget.BaseTransform).ToList(); foreach (var x in susps) { ai.Memory.Remove(x); } } else if (!ai.InfoCurrentTarget.HaveFirePosition) { ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; } } // Removing current target conditions if (ai.InfoCurrentTarget != null) { if (ai.InfoCurrentTarget.health.Value <= 0 || !ai.InfoCurrentTarget.IsSure) { ai.InfoCurrentTarget = null; ai.WorldState.SetKey(DS.haveTarget, false); needToReplan = true; needToReevaluateGoals = true; } } List <InformationAlive> listFightables = new List <InformationAlive>(ai.Memory.Items.OfType <InformationAlive>()); foreach (var infoFightable in listFightables) { if (infoFightable.IsDead) { var susps = ai.Memory.Items.OfType <InformationSuspicion>().Where(x => x.BaseTransform != null && x.BaseTransform == infoFightable.BaseTransform).ToList(); foreach (var w in susps) { ai.Memory.Remove(w); } //ai.Memory.BroadcastToListeners(ai.Memory.GameObject, infoFightable); continue; } if (infoFightable.IsSure && infoFightable.HaveFirePosition && infoFightable.lastKnownPosition.Confidence > 0 && infoFightable.health.Value > 0) { if (ai.InfoCurrentTarget == null) // there is no target, set it { ai.InfoCurrentTarget = infoFightable; ai.WorldState.SetKey(DS.haveTarget, true); needToReplan = true; // replan when new target is found needToReevaluateGoals = true; targetChangedAt = Time.time; } else if ( // check to see if we can switch to a new target alwaysSelectMaxConfidenceTarget && infoFightable.SuspicionFirm > ai.InfoCurrentTarget.SuspicionFirm && Time.time - targetChangedAt > targetSwitchMinInterval && ai.InfoCurrentTarget.transform != infoFightable.transform && infoFightable.lastKnownPosition.Confidence > 0 && infoFightable.health.Value > 0 && infoFightable.HaveFirePosition ) { ai.InfoCurrentTarget = infoFightable; needToReplan = true; needToReevaluateGoals = true; targetChangedAt = Time.time; } } } }
private void OnEnable() { m_AIBrain = serializedObject.targetObject as AIBrain; }