Exemple #1
0
    public void PerFrameUpdate()
    {
        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy != null)
        {
            //check if is in range
            float   dist           = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position);
            Vector3 targetVelocity = ParentCharacter.MyAI.BlackBoard.TargetEnemy.GetCharacterVelocity();

            if (targetVelocity.magnitude >= 0.25f)
            {
                if (dist > _weaponReach * 0.75f)
                {
                    //go to target enemy

                    ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position + targetVelocity * 0.1f;
                    ParentCharacter.Destination   = ParentCharacter.MyAI.BlackBoard.NavTarget;
                    ParentCharacter.CurrentStance = HumanStances.Run;
                    ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                }
                else
                {
                    if (_attackTimer >= _attackWaitTimeout)
                    {
                        ParentCharacter.SendCommand(CharacterCommands.RunningAttack);
                        _attackTimer       = -1;
                        _attackWaitTimeout = UnityEngine.Random.Range(0.5f, 1.5f);
                    }
                }
            }
            else
            {
                if (dist <= _weaponReach)
                {
                    ParentCharacter.SendCommand(CharacterCommands.Idle);
                    if (_attackTimer >= _attackWaitTimeout)
                    {
                        float attackType = UnityEngine.Random.value;
                        if (attackType < 0.5f)
                        {
                            ParentCharacter.SendCommand(CharacterCommands.LeftAttack);
                        }
                        else
                        {
                            ParentCharacter.SendCommand(CharacterCommands.RightAttack);
                        }

                        _attackTimer       = -1;
                        _attackWaitTimeout = UnityEngine.Random.Range(0.5f, 1.5f);
                    }
                }
                else
                {
                    ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position;
                    ParentCharacter.Destination   = ParentCharacter.MyAI.BlackBoard.NavTarget;
                    ParentCharacter.CurrentStance = HumanStances.Run;
                    ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                }
            }
        }
    }
Exemple #2
0
	public void UpdateAction()
	{
		if(!CheckAvailability() || _executionStopped)
		{
			return;
		}

		ParentCharacter.MyAI.Bark("Fire in the hole!");

		if(ParentCharacter.MyAI.BlackBoard.InvisibleEnemy != null)
		{
			ParentCharacter.AimPoint = ParentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition;
			ParentCharacter.SendCommand(CharacterCommands.ThrowGrenade);
		}



		StopAction();
		ParentCharacter.MyEventHandler.TriggerOnActionCompletion();

		/*
		if(CheckActionCompletion())
		{
			StopAction();

		}
		*/
	}
Exemple #3
0
    public override bool ExecuteAction()
    {
        CsDebug.Inst.CharLog(ParentCharacter, "Start executing Ranged Attack action " + ParentCharacter.name);

        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy == null)
        {
            CsDebug.Inst.CharLog(ParentCharacter, "There is NO target enemy");
            return(false);
        }

        _executionStopped   = false;
        _readyForCompletion = false;
        _exitDelayTimer     = 0;

        ParentCharacter.SendCommand(CharacterCommands.Aim);
        ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
        _maneuverState = ManeuverState.MoveTowards;



        ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
        ParentCharacter.MyEventHandler.OnActionUpdateTimer += UpdateAction;

        UpdateAction();

        return(true);
    }
 public override void StopAction()
 {
     Debug.Log("Stopping executing Hide in Cover");
     ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
     ParentCharacter.SendCommand(CharacterCommands.StopCrouch);
     ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAhead, Vector3.zero);
 }
    public void PerFrameUpdate()
    {
        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy != null)
        {
            //check if is in range
            _dist = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position);

            if (_dist > 1.5f && _biteState != BiteState.Bite)
            {
                //go to target enemy
                ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position - ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.forward * 0.5f;
                ParentCharacter.Destination   = ParentCharacter.MyAI.BlackBoard.NavTarget;
                ParentCharacter.CurrentStance = HumanStances.Run;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
            }
            else if (_dist > 1.5f && _biteState == BiteState.Bite)
            {
                ParentCharacter.GetComponent <MutantCharacter>().OnCancelStrangle();
                StopAction();
                ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
            }
            else
            {
                if (_biteState != BiteState.Bite)
                {
                    //Debug.Log("Ready to bite");
                    ParentCharacter.SendCommand(CharacterCommands.Bite);
                    _biteState = BiteState.Bite;
                }
            }
        }
    }
    public void UpdateAction()
    {
        if (!CheckAvailability())
        {
            return;
        }

        if (ParentCharacter.MyReference.CurrentWeapon == null)
        {
            ParentCharacter.SendCommand(ParentCharacter.MyAI.WeaponSystem.GetBestWeaponChoice());
        }

        if (_isCoverFound)
        {
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
            ParentCharacter.SendCommand(CharacterCommands.StopCrouch);
            ParentCharacter.GetComponent <HumanCharacter>().CurrentStance = HumanStances.Sprint;


            ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.MyAI.BlackBoard.SelectedCoverLoc;
            //GameObject.Find("Marker1").transform.position = ParentCharacter.MyAI.BlackBoard.SelectedCoverLoc;
            //GameObject.Find("Sphere").transform.position = ParentCharacter.MyAI.BlackBoard.SelectedCover.transform.position;
            ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
            ParentCharacter.SendCommand(CharacterCommands.GoToPosition);

            ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, ParentCharacter.MyAI.BlackBoard.AvgPersonalThreatDir);
        }


        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
 public override void StopAction()
 {
     Debug.Log("Stop executing Take attack cover " + ParentCharacter.name);
     ParentCharacter.SendCommand(CharacterCommands.Idle);
     ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
     ParentCharacter.MyAI.BlackBoard.IsNavTargetSet      = false;
 }
Exemple #8
0
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }



        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy != null)
        {
            float dist = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position);

            if (dist >= 5)
            {
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                ParentCharacter.CurrentStance = HumanStances.Run;
            }
        }


        if (_attackTimer >= 0 && _attackTimer < _attackWaitTimeout)
        {
            _attackTimer += 1;
        }

        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public void UpdateAction()
    {
        //continue to check if body is locked, i.e. wait till it's not locked
        if (!CheckAvailability())
        {
            return;
        }

        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy != null &&
            Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position) > 8 &&
            ParentCharacter.MyAI.BlackBoard.TargetEnemyThreat >= 0.33f &&
            !ParentCharacter.MyJobs.Contains(NPCJobs.Guard) &&
            Vector3.Distance(ParentCharacter.MyAI.BlackBoard.DefensePoint, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position) < ParentCharacter.MyAI.BlackBoard.DefenseRadius * 2f)
        {
            ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position;
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
            ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
        }
        else
        {
            ParentCharacter.SendCommand(CharacterCommands.Idle);
            ParentCharacter.SendCommand(CharacterCommands.Aim);
        }



        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }

        if (ParentCharacter.MyAI.BlackBoard.TargetCorpse != null)
        {
            Vector3 distance = ParentCharacter.MyAI.BlackBoard.TargetCorpse.LastKnownPos - ParentCharacter.transform.position;
            if (distance.magnitude > 2)
            {
                ParentCharacter.CurrentStance = HumanStances.Run;
                ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAhead, Vector3.zero);
                Vector3 dest = ParentCharacter.MyAI.BlackBoard.TargetCorpse.LastKnownPos - distance.normalized * 0.5f;
                ParentCharacter.Destination = dest;
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
            }
            else
            {
                if (ParentCharacter.MyAI.IsCharacterFriendly((Character)ParentCharacter.MyAI.BlackBoard.TargetCorpse.Target))
                {
                    //if corpse and I are friendly, then I'll check corpse and then raise alert
                    if (ParentCharacter.GetCharacterVelocity().magnitude <= 0.1f)
                    {
                        ParentCharacter.MyAnimator.SetBool("IsChecking", true);
                    }

                    _checkTimer++;

                    if (_checkTimer > 3)
                    {
                        //notify everyone on the team to draw weapon and do random patrol
                        ParentCharacter.MyAI.Bark("Somebody killed him! Search perimeter!");
                        ParentCharacter.MyAI.BlackBoard.GuardLevel = 3;
                        ParentCharacter.SendDelayCallBack(2, ParentCharacter.MyAI.Squad.SetSquadAlertLevel, 3);
                        ParentCharacter.MyAI.Squad.BroadcastMemoryFact(ParentCharacter.MyAI.BlackBoard.TargetCorpse);
                        StopAction();

                        ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
                        return;
                    }
                }
                else
                {
                    //not in same faction, will consider it as a container to loot
                }
            }
        }



        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public override void StopAction()
    {
        CsDebug.Inst.CharLog(ParentCharacter, "Stop executing attack from Cover" + ParentCharacter.name);

        ParentCharacter.SendCommand(CharacterCommands.StopCrouch);
        ParentCharacter.MyAI.WeaponSystem.StopFiringRangedWeapon();
        ParentCharacter.MyEventHandler.OnOneSecondTimer -= UpdateAction;
    }
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }



        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy != null)
        {
            Weapon enemyWeapon = ParentCharacter.MyAI.BlackBoard.TargetEnemy.MyAI.WeaponSystem.GetCurrentWeapon();
            if (enemyWeapon == null)
            {
                //assume is ranged
                _isEnemyRanged = true;
            }
            else if (enemyWeapon.IsRanged)
            {
                _isEnemyRanged = true;
            }
            else
            {
                _isEnemyRanged = false;
            }

            float dist = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.TargetEnemy.transform.position);

            if (dist < 5 && dist > _weaponReach && !_isEnemyRanged)
            {
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                ParentCharacter.CurrentStance = HumanStances.Walk;
            }
            else if (dist >= 5)
            {
                ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
                ParentCharacter.CurrentStance = HumanStances.Run;
            }
        }
        else
        {
            //going to assume that enemy is ranged
            _isEnemyRanged = true;
        }

        if (_attackTimer >= 0 && _attackTimer < _attackWaitTimeout)
        {
            _attackTimer += 1;
        }

        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
Exemple #13
0
    public void UpdateAction()
    {
        if (!CheckAvailability())
        {
            return;
        }

        //if is patrolling, select a random location and go there. after
        //reaching destination, set patrolling to false, and wait for random seconds
        //then patrol again.


        if (_idleTimer >= _idleDuration)
        {
            _isPatrolling = true;
        }
        else
        {
            _idleTimer    = _idleTimer + 1;
            _isPatrolling = false;
        }

        if (_isPatrolling)
        {
            HandlePatrolUpdate();
            ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAhead, Vector3.zero);
        }
        else
        {
            HandleIdleUpdate();
            ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, Vector3.zero);
        }

        //check if need to pull out weapon
        ParentCharacter.SendCommand(CharacterCommands.SetAlert);


        //check if need to aim
        if (ParentCharacter.MyAI.BlackBoard.GuardLevel > 2 && ((MutantCharacter)ParentCharacter).IsRangedCapable)
        {
            ParentCharacter.SendCommand(CharacterCommands.Aim);
        }
        else
        {
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
        }



        //check if patrol is complete
        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
Exemple #14
0
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }

        //check if need to pull out weapon
        if (ParentCharacter.MyAI.BlackBoard.GuardLevel > 1 && ParentCharacter.MyReference.CurrentWeapon == null)
        {
            ParentCharacter.SendCommand(ParentCharacter.MyAI.WeaponSystem.GetBestWeaponChoice());
        }
        else if (ParentCharacter.MyAI.BlackBoard.GuardLevel <= 1 && ParentCharacter.MyReference.CurrentWeapon != null)
        {
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
            ParentCharacter.SendCommand(CharacterCommands.Unarm);
        }

        //check if need to aim down sight
        if (ParentCharacter.MyAI.BlackBoard.GuardLevel > 2)
        {
            ParentCharacter.SendCommand(CharacterCommands.Aim);
        }

        //if is exploring, check if near next node, if so find next node if not at destination
        if (ParentCharacter.MyJobs.Contains(NPCJobs.Explore) && ParentCharacter.IsCommander)
        {
            NavNode nextNode = ParentCharacter.MyAI.Squad.NextNavNode;
            //Debug.Log("GOTO next node is " + nextNode.name + " dist " + Vector3.Distance(ParentCharacter.transform.position, nextNode.transform.position));
            if (nextNode != null)
            {
                if (AI.IsPositionInArea(ParentCharacter.transform.position, nextNode.transform.position, ParentCharacter.MyAI.BlackBoard.PatrolRange))
                {
                    NavNode next = AI.FindNextNavNode(nextNode, ParentCharacter.MyAI.Squad.DestNavNode);
                    if (next != null)
                    {
                        ParentCharacter.MyAI.Squad.NextNavNode    = next;
                        ParentCharacter.MyAI.BlackBoard.PatrolLoc = ParentCharacter.MyAI.Squad.NextNavNode.transform.position;
                    }
                }
            }
        }

        ParentCharacter.CurrentStance = HumanStances.Walk;
        ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAheadAround, Vector3.zero);
        ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.PatrolLoc;
        ParentCharacter.SendCommand(CharacterCommands.GoToPosition);



        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
Exemple #15
0
    public override void StopAction()
    {
        CsDebug.Inst.CharLog(ParentCharacter, "Search enemy is completed!");
        ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;

        ParentCharacter.MyAI.TargetingSystem.Mode       = AITargetingModes.LookAhead;
        ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
        //ParentCharacter.SendCommand(CharacterCommands.StopAim);
        ParentCharacter.SendCommand(CharacterCommands.Idle);
    }
Exemple #16
0
    public override bool ExecuteAction()
    {
        if (ParentCharacter.MyAI.BlackBoard.InvisibleEnemy == null)
        {
            return(false);
        }

        CsDebug.Inst.CharLog(ParentCharacter, "Start executing Search Enemy");

        ParentCharacter.MyAI.BlackBoard.NavTarget      = ParentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition;
        ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = true;

        WorkingMemoryFact fact   = ParentCharacter.MyAI.WorkingMemory.FindExistingFact(FactType.KnownEnemy, ParentCharacter.MyAI.BlackBoard.InvisibleEnemy);
        float             threat = fact.ThreatLevel;

        //if threat is low, just run towards last known location
        //if threat is high, keep aiming and go carefully towards a distance away from the last known location
        CsDebug.Inst.CharLog(ParentCharacter, "Action search enemy threat is " + threat);
        if (threat >= 0.66f)
        {
            Vector3 dist = ParentCharacter.MyAI.BlackBoard.InvisibleEnemy.transform.position - ParentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition;

            _isSearchDestSet = SelectSearchDestination(ParentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition + dist.normalized * -4, new Vector3(3, 3, 3), out _searchDest);



            ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
        }
        else
        {
            _searchDest      = ParentCharacter.MyAI.BlackBoard.NavTarget;
            _isSearchDestSet = true;
            ParentCharacter.SendCommand(CharacterCommands.StopAim);
            ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Run;
        }

        ParentCharacter.MyAI.BlackBoard.GuardLevel = 2;

        if (ParentCharacter.ActionState != HumanActionStates.SwitchWeapon && ParentCharacter.MyReference.CurrentWeapon == null)
        {
            ParentCharacter.SendCommand(CharacterCommands.SetAlert);
        }


        _searchDuration = UnityEngine.Random.Range(20, 40);
        _searchTimer    = 0;
        _nextTalkTime   = UnityEngine.Random.Range(3, 7);

        UpdateAction();

        ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
        ParentCharacter.MyEventHandler.OnActionUpdateTimer += UpdateAction;

        return(true);
    }
 public override void StopAction()
 {
     CsDebug.Inst.CharLog(ParentCharacter, "Stop executing Guard");
     _executionStopped = true;
     if (ParentCharacter.CurrentStance == HumanStances.Sprint)
     {
         ParentCharacter.CurrentStance = HumanStances.Run;
     }
     ParentCharacter.SendCommand(CharacterCommands.Idle);
     ParentCharacter.MyEventHandler.OnOneSecondTimer -= UpdateAction;
 }
 public override void StopAction()
 {
     //CsDebug.Inst.Log("Action patrol area is completed!", CsDLevel.Info, CsDComponent.AI);
     CsDebug.Inst.CharLog(ParentCharacter, "Action patrol area is completed!");
     ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
     ParentCharacter.MyAI.BlackBoard.IsNavTargetSet      = false;
     if (ParentCharacter.MyReference.CurrentWeapon != null)
     {
         ParentCharacter.SendCommand(CharacterCommands.StopAim);
     }
     ParentCharacter.SendCommand(CharacterCommands.Idle);
 }
Exemple #19
0
 private void HandleIdleUpdate()
 {
     if (_actionTimer >= _actionTimeout)
     {
         ParentCharacter.SendCommand(CharacterCommands.IdleAction);
         _actionTimer   = 0;
         _actionTimeout = UnityEngine.Random.Range(15f, 30f);
     }
     else
     {
         _actionTimer = _actionTimer + 1;
     }
 }
Exemple #20
0
    public void PerFrameUpdate()
    {
        float dist = Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.FollowTarget.transform.position);

        if (dist > _distThreshold)
        {
            Transform followTarget = ParentCharacter.MyAI.BlackBoard.FollowTarget.transform;
            ParentCharacter.Destination = followTarget.position + _followTargetPadding;
            ParentCharacter.MyAI.BlackBoard.NavTarget = ParentCharacter.Destination.Value;
        }
        else if (dist < _distThreshold / 2 && ParentCharacter.GetCharacterVelocity().magnitude > 0)
        {
            ParentCharacter.SendCommand(CharacterCommands.Idle);
        }
    }
    public override void StopAction()
    {
        //Debug.Log("Stopping idle activity " + ParentCharacter.name);
        ParentCharacter.SendCommand(CharacterCommands.Idle);
        ParentCharacter.MyEventHandler.OnOneSecondTimer -= UpdateAction;

        //reset animations
        ResetAnimation();

        //reset idle dest
        if (_currentIdleDest != null)
        {
            _currentIdleDest.IsOccupied = false;
        }
    }
 public override bool AbortAction(float priority)
 {
     if (priority >= 1)
     {
         //mark this action as impossible and stop action
         ParentCharacter.MyAI.WorkingMemory.AddFact(FactType.FailedAction, this.Name, Vector3.zero, 1, 0.4f);
         ParentCharacter.SendCommand(CharacterCommands.Idle);
         StopAction();
         return(true);
     }
     else
     {
         return(false);
     }
 }
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }

        //check if is at guarding position
        if (Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.PatrolLoc) > 1)
        {
            CsDebug.Inst.CharLog(ParentCharacter, "Guard current stance is " + ParentCharacter.CurrentStance + " " + ParentCharacter.name);
            //run to guarding position
            if (ParentCharacter.CurrentStance == HumanStances.Walk)
            {
                ParentCharacter.CurrentStance = HumanStances.Run;
            }

            ParentCharacter.SendCommand(CharacterCommands.StopAim);
            ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.PatrolLoc;
            ParentCharacter.SendCommand(CharacterCommands.GoToPosition);

            if (Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.PatrolLoc) < 3)
            {
                ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, ParentCharacter.MyAI.BlackBoard.GuardDirection);
            }
            else
            {
                ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAhead, Vector3.zero);
            }
        }
        else
        {
            //look around
            //Debug.Log(ParentCharacter.Name + " is guarding in place");
            ParentCharacter.MyAI.BlackBoard.GuardLevel = 2;
            ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, ParentCharacter.MyAI.BlackBoard.GuardDirection);
            if (ParentCharacter.MyAI.BlackBoard.TargetEnemy == null)
            {
                ParentCharacter.SendCommand(CharacterCommands.StopAim);
            }
        }

        if (CheckActionCompletion() && ParentCharacter.MyAI.BlackBoard.GuardLevel > 0)
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public void UpdateAction()
    {
        if (!CheckAvailability())
        {
            return;
        }

        ParentCharacter.SendCommand(CharacterCommands.Aim);


        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public override bool ExecuteAction()
    {
        Debug.LogError("Start executing Flank Target " + ParentCharacter.name);
        _executionStopped = false;



        //must either have target or invisible target
        if (ParentCharacter.MyAI.BlackBoard.TargetEnemy == null && ParentCharacter.MyAI.BlackBoard.InvisibleEnemy == null)
        {
            return(false);
        }



        //find a location behind invisible enemy
        Character target = ParentCharacter.MyAI.BlackBoard.InvisibleEnemy;

        if (target == null)
        {
            target = ParentCharacter.MyAI.BlackBoard.TargetEnemy;
        }


        if (Vector3.Distance(target.transform.position, ParentCharacter.MyAI.BlackBoard.LastKnownEnemyPosition) > 5)
        {
            return(false);
        }

        Vector3 lineOfSight = ParentCharacter.transform.position - target.transform.position;
        Vector3 direction   = Vector3.Cross(lineOfSight, Vector3.up).normalized + -1 * lineOfSight.normalized;

        if (!AI.RandomPoint(target.transform.position + direction.normalized * 15, new Vector3(5, 2, 5), out flankDest))
        {
            StopAction();
        }

        ParentCharacter.SendCommand(CharacterCommands.StopAim);
        ParentCharacter.MyAI.Bark("Anu cheeki breeki\n iv damke!");
        UpdateAction();

        ParentCharacter.MyEventHandler.OnOneSecondTimer -= UpdateAction;
        ParentCharacter.MyEventHandler.OnOneSecondTimer += UpdateAction;


        return(true);
    }
    public void UpdateAction()
    {
        if (!CheckAvailability() || _executionStopped)
        {
            return;
        }

        ParentCharacter.CurrentStance = HumanStances.Run;
        ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAheadAround, Vector3.zero);
        ParentCharacter.Destination = flankDest;
        ParentCharacter.SendCommand(CharacterCommands.GoToPosition);

        if (CheckActionCompletion())
        {
            StopAction();
            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
    public override bool ExecuteAction()
    {
        Debug.Log("Start executing Hide in Cover ");
        Vector3 faceDir = ParentCharacter.GetCharacterVelocity().normalized * -1;

        ParentCharacter.MyAI.TargetingSystem.SetTargetingMode(AITargetingModes.LookAround, faceDir);


        ParentCharacter.SendCommand(CharacterCommands.Crouch);


        ParentCharacter.MyEventHandler.OnActionUpdateTimer -= UpdateAction;
        ParentCharacter.MyEventHandler.OnActionUpdateTimer += UpdateAction;

        UpdateAction();



        return(true);
    }
    public void UpdateAction()
    {
        //continue to check if body is locked, i.e. wait till it's not locked
        if (!CheckAvailability())
        {
            return;
        }

        if (ParentCharacter.ActionState != HumanActionStates.SwitchWeapon && ParentCharacter.MyReference.CurrentWeapon == null)
        {
            ParentCharacter.SendCommand(ParentCharacter.MyAI.WeaponSystem.GetBestWeaponChoice());
        }

        if (CheckActionCompletion())
        {
            StopAction();

            ParentCharacter.MyEventHandler.TriggerOnActionCompletion();
        }
    }
Exemple #29
0
 private void HandlePatrolUpdate()
 {
     if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
     {
         CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is set. is patrolling " + _isPatrolling);
         //check if is near patrol destination; if so set isNavTargetSet to false
         if (Vector3.Distance(ParentCharacter.transform.position, ParentCharacter.MyAI.BlackBoard.NavTarget) <= 2)
         {
             ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
             _isPatrolling = false;
             _idleDuration = UnityEngine.Random.Range(5f, 20f);
             _idleTimer    = 0;
         }
         else if (!_isPatrolling)
         {
             ParentCharacter.Destination = ParentCharacter.MyAI.BlackBoard.NavTarget;
             ((HumanCharacter)ParentCharacter).CurrentStance = HumanStances.Walk;
             ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
             if (ParentCharacter.GetCharacterVelocity().magnitude <= 0)
             {
                 ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = false;
             }
             _isPatrolling = true;
         }
     }
     else
     {
         CsDebug.Inst.CharLog(ParentCharacter, "Patrol area update action nav target is not set");
         Vector3 result;
         ParentCharacter.MyAI.BlackBoard.IsNavTargetSet = SelectPatrolDestination(out result);
         if (ParentCharacter.MyAI.BlackBoard.IsNavTargetSet)
         {
             ParentCharacter.MyAI.BlackBoard.NavTarget = result;
             ParentCharacter.Destination   = ParentCharacter.MyAI.BlackBoard.NavTarget;
             ParentCharacter.CurrentStance = HumanStances.Walk;
             ParentCharacter.SendCommand(CharacterCommands.GoToPosition);
             _isPatrolling = true;
         }
     }
 }
    private void ResetAnimation()
    {
        if (ParentCharacter.MyAnimator.GetBool("IsChairSitting"))
        {
            ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.ChairStand;
            ParentCharacter.SendCommand(CharacterCommands.PlayAnimationAction);
        }
        else if (ParentCharacter.MyAnimator.GetBool("IsGroundSitting"))
        {
            ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.GroundStand;
            ParentCharacter.SendCommand(CharacterCommands.PlayAnimationAction);
        }
        else if (ParentCharacter.MyAnimator.GetBool("IsSleeping") || ParentCharacter.MyAnimator.GetBool("IsJackingOff"))
        {
            ParentCharacter.MyAI.BlackBoard.AnimationAction = AnimationActions.SleepStand;
            ParentCharacter.SendCommand(CharacterCommands.PlayAnimationAction);
        }
        else if (ParentCharacter.MyAnimator.GetBool("IsCommanderStand"))
        {
            ParentCharacter.MyAnimator.SetBool("IsCommanderStand", false);
            ParentCharacter.SendCommand(CharacterCommands.AnimationActionDone);
        }
        else
        {
            ParentCharacter.SendCommand(CharacterCommands.AnimationActionDone);
        }


        ParentCharacter.MyAnimator.SetTrigger("Cancel");
        if (_guitar != null)
        {
            ParentCharacter.CharacterAudio.Stop();
            GameObject.Destroy(_guitar);
        }
        SmallAction = SmallActionType.None;
    }