Пример #1
0
        private SpriteFrameDeathSequence?GetSpecificDeathAnimation(DeathStateActorAnimationArgs args)
        {
            //exit immediately if there's no potential
            if (ExtraDeathAnimations == null || ExtraDeathAnimations.Length == 0)
            {
                return(null);
            }

            IEnumerable <SpriteFrameDeathSequence> shortList = ExtraDeathAnimations;

            //yes it's LINQ, no I don't care

            //extreme death is prioritized; it makes no sense to play a headshot death if they've been pasted
            shortList = shortList.Where(s => s.ExtremeDeath == args.ExtremeDeath);

            //then look for specific damage type
            if (shortList.Any(s => s.DamageType == args.DamageType))
            {
                shortList = shortList.Where(s => s.DamageType == args.DamageType);
            }
            else
            {
                shortList = shortList.Where(s => s.DamageType == 0);
            }

            //then look for specific hit location
            if (shortList.Any(s => s.HitLocation == args.HitLocation))
            {
                shortList = shortList.Where(s => s.HitLocation == args.HitLocation);
            }
            else
            {
                shortList = shortList.Where(s => s.HitLocation == 0);
            }

            //pick the _last_ item
            if (shortList.Any())
            {
                return(shortList.Last());
            }

            return(null);
        }
Пример #2
0
        public void EnterState(ActorAiState newState)
        {
            if (LockAiState)
            {
                return;
            }

            if (newState != CurrentAiState)
            {
                LastAiState = CurrentAiState;
            }

            ExitState(CurrentAiState); //good place or no?

            TimeInState = 0;

            switch (newState)
            {
            case ActorAiState.Idle:
                Target = null;
                AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Idle);
                MovementComponent.AbortMove();
                break;

            case ActorAiState.Dead:
            {
                if (CurrentAiState == ActorAiState.Dead)         //fix for glitchy looking behaviour
                {
                    break;
                }

                MovementComponent.AbortMove();
                MovementComponent.HandleDeath();
                var deathStateArgs = new DeathStateActorAnimationArgs()
                {
                    DamageEffector = LastHit?.DamageEffector ?? 0, DamageType = LastHit?.DamageType ?? 0, ExtremeDeath = WasExtremeDeath, HitLocation = LastHit?.HitLocation ?? 0, HitMaterial = LastHit?.HitMaterial ?? 0
                };
                if (DieImmediately)
                {
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Dead, deathStateArgs);
                }
                else
                {
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Dying, deathStateArgs);
                }

                AudioComponent.Ref()?.StopLivingSounds();
                if (WasExtremeDeath)
                {
                    AudioComponent.Ref()?.PlayExtremeDeathSound();
                }
                else
                {
                    AudioComponent.Ref()?.PlayDeathSound();
                }

                if (InteractionComponent != null)
                {
                    InteractionComponent.InteractionDisabledByHit = false;
                }

                if (DestroyOnDeath)
                {
                    this.gameObject.SetActive(false);         //actually destroying the object breaks saving
                }
                if (OnDeathSpecial != null)
                {
                    OnDeathSpecial.Execute(new ActionInvokerData {
                            Activator = this
                        });
                }

                if (DisableHitboxesOnDeath)
                {
                    var hitboxComponents = GetComponentsInChildren <IHitboxComponent>(true);
                    foreach (var hitboxComponent in hitboxComponents)
                    {
                        if (hitboxComponent is MonoBehaviour mb)         //IHitboxComponent does not actually imply MonoBehaviour
                        {
                            mb.gameObject.SetActive(false);
                        }
                    }
                }

                if (DisableCollidersOnDeath)
                {
                    var colliders = GetComponentsInChildren <Collider>(true);
                    foreach (var collider in colliders)
                    {
                        collider.enabled = false;
                    }
                }

                if (
                    ((LastHit != null && LastHit.Value.Originator != null && LastHit.Value.Originator is PlayerController) ||
                     (Target != null && Target.GetComponent <PlayerController>())
                    ) &&
                    GrantXpOnDeath > 0
                    )
                {
                    GameState.Instance.PlayerRpgState.GrantXPScaled(GrantXpOnDeath);
                }
            }
            break;

            case ActorAiState.Wandering:
                Target = null;
                AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Walking);
                //set initial destination
                Vector2 newpos = VectorUtils.GetRandomVector2(InitialPosition.GetFlatVector(), WanderRadius);
                MovementComponent.SetDestination(newpos.GetSpaceVector());
                AudioComponent.Ref()?.StartWalkSound();
                break;

            case ActorAiState.Chasing:
                if (RunOnChase)
                {
                    MovementComponent.IsRunning = true;
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Running);
                    AudioComponent.Ref()?.StartRunSound();
                }
                else
                {
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Walking);
                    AudioComponent.Ref()?.StartWalkSound();
                }

                {
                    //set target

                    if (Target == null)
                    {
                        GetSwizzledTarget();     //fix for loading saves
                    }
                    SetChaseDestination();
                }
                break;

            case ActorAiState.ScriptedMoveTo:
                if (RunOnChase)
                {
                    MovementComponent.IsRunning = true;
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Running);
                    AudioComponent.Ref()?.StartRunSound();
                }
                else
                {
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Walking);
                    AudioComponent.Ref()?.StartWalkSound();
                }
                MovementComponent.SetDestination(MovementComponent.MovementTarget);
                break;

            case ActorAiState.Attacking:
                if (AttackComponent == null)
                {
                    Debug.LogError($"{name} tried to attack, but has no attack component!");
                    EnterState(ActorAiState.Idle);
                    return;
                }

                if (Target == null)
                {
                    GetSwizzledTarget();     //fix for loading saves
                }
                //set animation, fire projectile, set timer
                AttackComponent.BeginAttack();
                break;

            case ActorAiState.Covering:
                break;

            case ActorAiState.Hurting:
                AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Hurting);
                AudioComponent.Ref()?.PlayPainSound();
                break;

            case ActorAiState.Fleeing:
                if (RunOnFlee)
                {
                    MovementComponent.IsRunning = true;
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Running);
                    AudioComponent.Ref()?.StartRunSound();
                }
                else
                {
                    AnimationComponent.Ref()?.SetAnimation(ActorAnimState.Walking);
                    AudioComponent.Ref()?.StartWalkSound();
                }

                {
                    //set target
                    var d = transform.position + ((Target.position - transform.position).normalized * -(1 + Mathf.Abs(MovementComponent.TargetThreshold)));
                    MovementComponent.SetDestination(d);
                }
                break;

            case ActorAiState.ScriptedAction:
                //nop
                break;

            default:
                break;
            }

            CurrentAiState = newState;
        }