コード例 #1
0
        public override void AI()
        {
            if (Main.netMode < 2 && FirstFrame)
            {
                FirstFrame = false;
                if (PlayerMod.PlayerHasGuardian(Main.player[Main.myPlayer], GuardianID, GuardianModID))
                {
                    GuardianData gd = PlayerMod.GetPlayerGuardian(Main.player[Main.myPlayer], GuardianID, GuardianModID);
                    AgeScale = TerraGuardian.GetAgeSizeValue(gd.GetRealAgeDecimal());
                }
                else
                {
                    float AgeValue = TerraGuardian.GetAgeDecimalValue(Base.Age, Base.Birthday, GuardianGlobalInfos.LifeTime, Base.GetGroup.AgingSpeed);
                    AgeScale = TerraGuardian.GetAgeSizeValue(AgeValue);
                }
            }
            npc.scale = AgeScale * Base.GetScale;
            if (MessageTime > 0)
            {
                MessageTime--;
            }
            float Acceleration = Base.Acceleration, MaxSpeed = Base.MaxSpeed, Deceleration = Base.SlowDown,
                  JumpSpeed = Base.JumpSpeed;

            for (int i = 0; i < 255; i++)
            {
                if (Main.player[i].talkNPC == npc.whoAmI)
                {
                    Idle = false;
                    StareAt(Main.player[i]);
                    break;
                }
            }
            if (Idle)
            {
                if (npc.direction == 0)
                {
                    npc.TargetClosest(true);
                    //npc.direction = (Main.rand.NextDouble() < 0.5 ? -1 : 1);
                }
                if (IdleBehaviorTime <= 0)
                {
                    IdleBehaviorType = (byte)Main.rand.Next(2);
                    IdleBehaviorTime = 200 + Main.rand.Next(200);
                    npc.direction   *= -1;
                }
                if (IdleBehaviorType == 1)
                {
                    Walk = true;
                    if (npc.direction > 0)
                    {
                        MoveRight = true;
                    }
                    else
                    {
                        MoveLeft = true;
                    }
                }
                IdleBehaviorTime--;
                if (MoveLeft || MoveRight)
                {
                    bool HasTileInFront = false;
                    for (int x = 0; x < 3; x++)
                    {
                        for (int y = 0; y < 4; y++)
                        {
                            int  Tx = (int)npc.Center.X / 16 + (2 + x) * npc.direction, Ty = (int)npc.Bottom.Y / 16 + y;
                            Tile tile = MainMod.GetTile(Tx, Ty);
                            if (tile.active() && (Main.tileSolid[tile.type] || Main.tileSolidTop[tile.type]))
                            {
                                HasTileInFront = true;
                                break;
                            }
                        }
                    }
                    if (!HasTileInFront)
                    {
                        if (MoveRight)
                        {
                            MoveRight = false;
                            MoveLeft  = true;
                        }
                        else
                        {
                            MoveRight = true;
                            MoveLeft  = false;
                        }
                    }
                }
            }
            if (Walk)
            {
                Acceleration = TerraGuardian.WalkAcceleration;
                MaxSpeed     = TerraGuardian.WalkMaxSpeed;
                Deceleration = TerraGuardian.WalkSlowDown;
            }
            else if (Dash)
            {
                MaxSpeed     *= 2;
                Acceleration *= 2;
            }
            int MaxJumpHeight = Base.MaxJumpHeight;

            if (MoveLeft)
            {
                npc.direction   = -1;
                npc.velocity.X -= Acceleration;
                if (npc.velocity.X < -MaxSpeed)
                {
                    npc.velocity.X = -MaxSpeed;
                }
                if (npc.collideX && npc.velocity.Y == 0)
                {
                    Jump = true;
                }
            }
            if (MoveRight)
            {
                npc.direction   = 1;
                npc.velocity.X += Acceleration;
                if (npc.velocity.X > MaxSpeed)
                {
                    npc.velocity.X = MaxSpeed;
                }
                if (npc.collideX && npc.velocity.Y == 0)
                {
                    Jump = true;
                }
            }
            if (!MoveRight && !MoveLeft)
            {
                if (npc.velocity.X > 0)
                {
                    npc.velocity.X -= Deceleration;
                    if (npc.velocity.X < 0)
                    {
                        npc.velocity.X = 0;
                    }
                }
                if (npc.velocity.X < 0)
                {
                    npc.velocity.X += Deceleration;
                    if (npc.velocity.X > 0)
                    {
                        npc.velocity.X = 0;
                    }
                }
            }
            if (Jump)
            {
                if (JumpTime == 0)
                {
                    if (npc.velocity.Y == 0)
                    {
                        JumpTime       = MaxJumpHeight;
                        npc.velocity.Y = -JumpSpeed;
                    }
                }
                else
                {
                    if (npc.collideY)
                    {
                        JumpTime = 0;
                    }
                    else
                    {
                        JumpTime--;
                        npc.velocity.Y = -JumpSpeed;
                    }
                }
            }
            else
            {
                if (JumpTime != 0)
                {
                    JumpTime = 0;
                }
            }
            IsWalking = Walk;
            MoveLeft  = MoveRight = DropFromPlatform = Jump = Action = Dash = Walk = Idle = false;
            Collision.StepUp(ref npc.position, ref npc.velocity, npc.width, npc.height, ref npc.stepSpeed, ref npc.gfxOffY);
            Vector4 SlopedCollision = Collision.SlopeCollision(npc.position, npc.velocity, npc.width, npc.height, 1f, false);

            npc.position = SlopedCollision.XY();
            npc.velocity = SlopedCollision.ZW();
        }
コード例 #2
0
 public float GetRealAgeDecimal()
 {
     return(TerraGuardian.GetAgeDecimalValue((SavedAge > 0 ? SavedAge : Base.Age), Base.Birthday, GetLifeTime, Base.GetGroup.AgingSpeed));
     //return (float)((SavedAge > 0 ? SavedAge : Base.Age) * Base.GetGroup.AgingSpeed + (GetLifeTime.TotalDays * (double)Base.GetGroup.AgingSpeed) / DaysToYears);
 }