Beispiel #1
0
        protected override void OnUpdate()
        {
            if (isDemon)
            {
                OnUpdateHitbox();
                HandleBlinking();

                MoveInstantly(new Vector2(speedX, speedY), MoveType.RelativeTime, true);
            }
            else
            {
                base.OnUpdate();
            }

            if (frozenTimeLeft > 0)
            {
                return;
            }

            switch (state)
            {
            case StateWarpingIn: {
                if (stateTime <= 0f)
                {
                    bool    found     = false;
                    Vector3 pos       = Transform.Pos;
                    Vector3 targetPos = new Vector3(float.MaxValue, float.MaxValue, 0f);

                    List <Player> players = api.Players;
                    for (int i = 0; i < players.Count; i++)
                    {
                        Vector3 newPos = players[i].Transform.Pos;
                        if ((pos - newPos).Length < (pos - targetPos).Length)
                        {
                            targetPos = newPos;
                            found     = true;
                        }
                    }

                    if (found)
                    {
                        IsFacingLeft = (targetPos.X < pos.X);
                    }

                    renderer.Active = true;

                    state = StateTransition;
                    SetTransition(AnimState.TransitionWarpIn, false, delegate {
                            state     = StateIdling;
                            stateTime = 80f;

                            isInvulnerable = false;
                        });
                }

                break;
            }

            case StateIdling: {
                if (stateTime <= 0f)
                {
                    FollowNearestPlayer(StateRunning1, MathF.Rnd.NextFloat(60, 120));
                }

                break;
            }

            case StateRunning1: {
                if (stateTime <= 0f)
                {
                    if (health < maxHealth / 2)
                    {
                        isDemon = true;
                        speedX  = 0f;
                        speedY  = 0f;

                        isInvulnerable = true;
                        canBeFrozen    = false;

                        state = StateTransition;
                        // DEMON_FLY
                        SetAnimation((AnimState)669);
                        // DEMON_TRANSFORM_START
                        SetTransition((AnimState)670, false, delegate {
                                collisionFlags &= ~CollisionFlags.ApplyGravitation;
                                isInvulnerable  = false;

                                state = StateDemonFlying;

                                lastPos   = Transform.Pos;
                                targetPos = lastPos + new Vector3(0f, -200f, 0f);
                            });
                    }
                    else
                    {
                        if (MathF.Rnd.NextFloat() < 0.5f)
                        {
                            FollowNearestPlayer(
                                StateRunning1,
                                MathF.Rnd.NextFloat(60, 120));
                        }
                        else
                        {
                            FollowNearestPlayer(
                                StateRunning2,
                                MathF.Rnd.NextFloat(10, 30));
                        }
                    }
                }
                else
                {
                    if (!CanMoveToPosition(speedX, 0))
                    {
                        IsFacingLeft ^= true;
                        speedX        = (IsFacingLeft ? -4f : 4f);
                    }
                }
                break;
            }

            case StateRunning2: {
                if (stateTime <= 0f)
                {
                    speedX = 0f;

                    state = StateTransition;
                    SetTransition(AnimState.TransitionRunToIdle, false, delegate {
                            SetTransition((AnimState)15, false, delegate {
                                shots = MathF.Rnd.Next(1, 8);
                                Shoot();
                            });
                        });
                }
                break;
            }

            case StateDemonFlying: {
                if (attackTime <= 0f)
                {
                    state = StateDemonSpewingFireball;
                }
                else
                {
                    attackTime -= Time.TimeMult;
                    FollowNearestPlayerDemon();
                }
                break;
            }

            case StateDemonSpewingFireball: {
                state = StateTransition;
                SetTransition((AnimState)673, false, delegate {
                        PlaySound("SpitFireball");

                        Fireball fireball = new Fireball();
                        fireball.OnAttach(new ActorInstantiationDetails {
                            Api    = api,
                            Pos    = Transform.Pos + new Vector3(IsFacingLeft ? -26f : 26f, -14f, 0f),
                            Params = new[] { (ushort)(IsFacingLeft ? 1 : 0) }
                        });
                        api.AddActor(fireball);

                        SetTransition((AnimState)674, false, delegate {
                            state = StateDemonFlying;

                            attackTime = MathF.Rnd.NextFloat(100f, 240f);
                        });
                    });
                break;
            }

            case StateFalling: {
                if (canJump)
                {
                    state = StateTransition;
                    // DISORIENTED_START
                    SetTransition((AnimState)666, false, delegate {
                            // DISORIENTED
                            SetTransition((AnimState)667, false, delegate {
                                // DISORIENTED
                                SetTransition((AnimState)667, false, delegate {
                                    // DISORIENTED_WARP_OUT
                                    SetTransition((AnimState)6670, false, delegate {
                                        base.OnPerish(null);
                                    });
                                });
                            });
                        });
                }
                break;
            }
            }

            stateTime -= Time.TimeMult;
        }