Exemple #1
0
        //update for an indirect attack
        public bool OnIndirectAttackUpdate()
        {
            if (sourceStepTimer > 0)
            {
                sourceStepTimer -= Time.deltaTime;
            }
            else
            {
                source.InvokeAttackPerformedEvent();
                //not an area attack:
                CustomEvents.OnAttackPerformed(source, source.Target, source.GetTargetPosition());

                sources[sourceStep].Launch(gameMgr.EffectPool, source);
                if (launchType == LaunchTypes.inOrder)                                //if the attack is supposed to go through attack objects in order and launch them
                {
                    sourceStep++;                                                     //increment the source step
                }
                if (sourceStep >= sources.Length || launchType == LaunchTypes.random) //if we reached the last attack object or the launch type is set to random
                {
                    sourceStep = 0;                                                   //end of attack
                    source.OnAttackComplete();
                }
                else //move to next attack object
                {
                    sourceStepTimer = sources[sourceStep].GetDelay();
                }

                return(true); //return whenever an attack object is launched
            }

            return(false);
        }
Exemple #2
0
        //update the attack entity when there's a target
        protected virtual void OnTargetUpdate()
        {
            //the override of this method in both the UnitAttack and BuildingAttack components are responsible for checking the conditions for which an attack can be continued or not
            //reaching this stage means that all conditions have been met and it's safe to continue with the attack

            if (wasInTargetRange == false) //if the attacker never was in the target's range but just entered it:
            {
                attackerInRangeEvent.Invoke();
                CustomEvents.OnAttackerInRange(this, Target, GetTargetPosition()); //launch custom event

                wasInTargetRange          = true;                                  //mark as in target's range.
                initialEngagementDistance = Vector3.Distance(transform.position, GetTargetPosition());
            }

            weapon.UpdateActiveRotation(GetTargetPosition());

            if (reloadTimer > 0 || IsInLineOfSight() == false) //still in reload time or not facing target? do not proceed
            {
                return;
            }

            if (delayTimer > 0) //delay timer
            {
                delayTimer -= Time.deltaTime;
                return;
            }

            //If the attack delay is over, the attack is triggered and LOS conditions are met
            if (triggered)
            {
                if (direct == true) //Is this a direct attack (no use of attack objects)?
                {
                    attackPerformedEvent.Invoke();
                    //not an area attack:
                    CustomEvents.OnAttackPerformed(this, Target, GetTargetPosition());

                    damage.TriggerAttack(Target, GetTargetPosition());
                    AudioManager.Play(FactionEntity.AudioSourceComp, attackAudio, false);
                    OnAttackComplete();
                }
                else if (attackObjectLauncher.OnIndirectAttackUpdate()) //indirect attack ? -> must launch attack objects
                {
                    AudioManager.Play(FactionEntity.AudioSourceComp, attackAudio, false);
                }
            }
        }