Ejemplo n.º 1
0
        public void Process(RenderTime elapsedTime)
        {
            if (Dead)
            {
                return;
            }

            if (CurrentAction == ActionType.Idle)
            {
                if (MovementSpeed < 0)
                {
                    elapsedTime /= 2;
                }
                else if (MovementSpeed > 0)
                {
                    elapsedTime *= 2;
                }
            }
            ActionTime += elapsedTime;

            RenderTime totalActionTime = GetActionTime(CharData, CharDir, CurrentAction);
            RenderTime totalPassTime   = GetPassTime(CharData, CharDir, CurrentAction);

            if (ActionTime >= totalPassTime)
            {
                ActionDone = true;
            }

            if (ActionTime >= totalActionTime)
            {
                if (ActionLoop)
                {
                    ActionTime = ActionTime % totalActionTime;
                }
                else
                {
                    switch (CurrentAction)
                    {
                    case ActionType.None:
                    {
                        ActionTime    = RenderTime.Zero;
                        CurrentAction = ActionType.Idle;
                    }
                    break;

                    case ActionType.Idle:
                    {
                        if (totalActionTime > RenderTime.Zero)
                        {
                            ActionTime = ActionTime % totalActionTime;
                        }
                        else
                        {
                            ActionTime = RenderTime.Zero;
                        }
                    }
                    break;

                    default:
                    {
                        ActionTime    = RenderTime.Zero;
                        CurrentAction = ActionType.None;
                    }
                    break;
                    }
                }
            }

            CharFrameType = FrameType.Idle;
            CharFrame     = 0;
            TileOffset    = new Loc2D();
            drawOffset    = new Loc2D();
            opacity       = 255;
            MapHeight     = 0;
            if (CurrentAction == ActionType.Idle)
            {
                CharFrameType = FrameType.Idle;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                if (totalFrames > 0)
                {
                    CharFrame = (ActionTime.Ticks / IDLE_FRAME_LENGTH.Ticks) % totalFrames;
                }

                TileOffset = new Loc2D();
                MapHeight  = 0;
            }
            else if (CurrentAction == ActionType.Walk)
            {
                CharFrameType = FrameType.Walk;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);

                if (totalFrames > 0)
                {
                    CharFrame = ((ActionTime + PrevActionTime).Ticks / WALK_FRAME_LENGTH.Ticks) % totalFrames;
                }

                if (!MoveInPlace)
                {
                    if (ActionTime.Ticks <= totalPassTime.Ticks)
                    {
                        Operations.MoveInDirection8(ref TileOffset, CharDir, ActionTime.Ticks * Graphics.TextureManager.TILE_SIZE / totalPassTime.Ticks);
                    }
                }
            }
            else if (CurrentAction == ActionType.Attack)
            {
                CharFrameType = FrameType.Attack;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                if (totalFrames > 0)
                {
                    CharFrame = (ActionTime.Ticks * totalFrames / totalActionTime.Ticks);
                }

                if (!MoveInPlace)
                {
                    int pullback_distance = Graphics.TextureManager.TILE_SIZE / 8;
                    int farthest_distance = Graphics.TextureManager.TILE_SIZE * 3 / 4;
                    int hold_point        = totalActionTime.Ticks / 8;
                    int rush_point        = totalActionTime.Ticks * 2 / 8;
                    int hit_point         = totalActionTime.Ticks * 4 / 8;
                    int return_point      = totalActionTime.Ticks * 6 / 8;
                    if (ActionTime.Ticks <= hold_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -ActionTime.Ticks * pullback_distance / rush_point);
                    }
                    else if (ActionTime.Ticks <= rush_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -pullback_distance);
                    }
                    else if (ActionTime.Ticks <= hit_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, (ActionTime.Ticks - rush_point) * (farthest_distance + pullback_distance) / (hit_point - rush_point) - pullback_distance);
                    }
                    else if (ActionTime.Ticks <= return_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, farthest_distance);
                    }
                    else
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, ((totalActionTime.Ticks - hit_point) - (ActionTime.Ticks - hit_point)) * farthest_distance / (totalActionTime.Ticks - hit_point));
                    }
                }
            }
            else if (CurrentAction == ActionType.AttackArm)
            {
                CharFrameType = FrameType.AttackArm;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                if (totalFrames > 0)
                {
                    CharFrame = (ActionTime.Ticks * totalFrames / totalActionTime.Ticks);
                }

                if (!MoveInPlace)
                {
                    int pullback_distance = Graphics.TextureManager.TILE_SIZE / 8;
                    int farthest_distance = Graphics.TextureManager.TILE_SIZE * 3 / 4;
                    int hold_point        = totalActionTime.Ticks / 8;
                    int rush_point        = totalActionTime.Ticks * 2 / 8;
                    int hit_point         = totalActionTime.Ticks * 4 / 8;
                    int return_point      = totalActionTime.Ticks * 6 / 8;
                    if (ActionTime.Ticks <= hold_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -ActionTime.Ticks * pullback_distance / rush_point);
                    }
                    else if (ActionTime.Ticks <= rush_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -pullback_distance);
                    }
                    else if (ActionTime.Ticks <= hit_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, (ActionTime.Ticks - rush_point) * (farthest_distance + pullback_distance) / (hit_point - rush_point) - pullback_distance);
                    }
                    else if (ActionTime.Ticks <= return_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, farthest_distance);
                    }
                    else
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, ((totalActionTime.Ticks - hit_point) - (ActionTime.Ticks - hit_point)) * farthest_distance / (totalActionTime.Ticks - hit_point));
                    }
                }
            }
            else if (CurrentAction == ActionType.AltAttack)
            {
                CharFrameType = FrameType.AltAttack;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                CharFrame = (ActionTime.Ticks * totalFrames / totalActionTime.Ticks);

                if (!MoveInPlace)
                {
                    int pullback_distance = Graphics.TextureManager.TILE_SIZE / 8;
                    int farthest_distance = Graphics.TextureManager.TILE_SIZE * 3 / 4;
                    int hold_point        = totalActionTime.Ticks / 8;
                    int rush_point        = totalActionTime.Ticks * 2 / 8;
                    int hit_point         = totalActionTime.Ticks * 4 / 8;
                    int return_point      = totalActionTime.Ticks * 6 / 8;
                    if (ActionTime.Ticks <= hold_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -ActionTime.Ticks * pullback_distance / rush_point);
                    }
                    else if (ActionTime.Ticks <= rush_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -pullback_distance);
                    }
                    else if (ActionTime.Ticks <= hit_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, (ActionTime.Ticks - rush_point) * (farthest_distance + pullback_distance) / (hit_point - rush_point) - pullback_distance);
                    }
                    else if (ActionTime.Ticks <= return_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, farthest_distance);
                    }
                    else
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, ((totalActionTime.Ticks - hit_point) - (ActionTime.Ticks - hit_point)) * farthest_distance / (totalActionTime.Ticks - hit_point));
                    }
                }
            }
            else if (CurrentAction == ActionType.SpAttack)
            {
                CharFrameType = FrameType.SpAttack;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                CharFrame = (ActionTime.Ticks * totalFrames / totalActionTime.Ticks);
            }
            else if (CurrentAction == ActionType.SpAttackShoot)
            {
                CharFrameType = FrameType.SpAttackShoot;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                CharFrame = (ActionTime.Ticks * totalFrames / totalActionTime.Ticks);

                if (!MoveInPlace)
                {
                    int pullback_distance = Graphics.TextureManager.TILE_SIZE / 8;
                    int farthest_distance = Graphics.TextureManager.TILE_SIZE / 8;
                    int hold_point        = totalActionTime.Ticks / 8;
                    int rush_point        = totalActionTime.Ticks * 3 / 8;
                    int hit_point         = totalActionTime.Ticks * 4 / 8;
                    int return_point      = totalActionTime.Ticks * 7 / 8;
                    if (ActionTime.Ticks <= hold_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -ActionTime.Ticks * pullback_distance / rush_point);
                    }
                    else if (ActionTime.Ticks <= rush_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, -pullback_distance);
                    }
                    else if (ActionTime.Ticks <= hit_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, (ActionTime.Ticks - rush_point) * (farthest_distance + pullback_distance) / (hit_point - rush_point) - pullback_distance);
                    }
                    else if (ActionTime.Ticks <= return_point)
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, farthest_distance);
                    }
                    else
                    {
                        Operations.MoveInDirection8(ref drawOffset, CharDir, ((totalActionTime.Ticks - hit_point) - (ActionTime.Ticks - hit_point)) * farthest_distance / (totalActionTime.Ticks - hit_point));
                    }
                }
            }
            else if (CurrentAction == ActionType.SpAttackCharge)
            {
                CharFrameType = FrameType.SpAttackCharge;
                int totalFrames = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, CharDir);
                if (totalFrames > 0)
                {
                    CharFrame = totalFrames - 1;
                }

                if (!MoveInPlace)
                {
                    if (ActionTime.Ticks / 40 % 2 == 0)
                    {
                        Operations.MoveInDirection8(ref drawOffset, Operations.AddDir(CharDir, Direction8.Left), 1);
                    }
                }
            }
            else if (CurrentAction == ActionType.Sleeping)
            {
                CharFrameType = FrameType.Sleep;
                int frameCount = TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(CharFrameType, Direction8.Down);
                CharFrame = (ActionTime.Ticks * frameCount / totalActionTime.Ticks);
            }
            else if (CurrentAction == ActionType.Hurt)
            {
                CharFrameType = FrameType.Hurt;
                CharFrame     = 0;
                if (!MoveInPlace)
                {
                    if ((ActionTime.Ticks * 3 / totalActionTime.Ticks) % 2 == 0)
                    {
                        Operations.MoveInDirection8(ref drawOffset, Operations.ReverseDir(CharDir), 1);
                    }
                }
            }
            else if (CurrentAction == ActionType.Defeated)
            {
                CharFrameType = FrameType.Hurt;
                CharFrame     = 0;
                if ((ActionTime.Ticks * 6 / totalActionTime.Ticks) % 2 == 0)
                {
                    Operations.MoveInDirection8(ref drawOffset, Operations.ReverseDir(CharDir), 1);
                }
                if ((ActionTime.Ticks * 2 / totalActionTime.Ticks) > 0)
                {
                    opacity = 128;
                }
            }
            //else if (CurrentAction == ActionType.Jump)
            //{
            //    CharFrame = (ActionTime * TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(FrameType.AltAttack, CharDir) / FrameLength);
            //    if (ActionData1 > 1 || ActionData1 == 0)
            //    {
            //        Operations.MoveInDirection8(ref tileOffset, CharDir, ActionTime * ActionData1 * Graphics.TextureManager.TILE_SIZE / FrameLength);
            //    }
            //    else
            //    {
            //        int moveDist = ActionTime * 2 * Graphics.TextureManager.TILE_SIZE / FrameLength;
            //        if (moveDist > Graphics.TextureManager.TILE_SIZE) moveDist = Graphics.TextureManager.TILE_SIZE;
            //        Operations.MoveInDirection8(ref tileOffset, CharDir, moveDist);
            //    }
            //}
            //else if (CurrentAction == ActionType.JumpHit)
            //{
            //    int phaseTotal = (FrameLength / 2);
            //    int phaseTime = ActionTime % phaseTotal;
            //    if (ActionTime < FrameLength / 2)
            //    {
            //        CharFrame = (phaseTime * TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(FrameType.AltAttack, CharDir) / phaseTotal);
            //        if (ActionData1 > 1 || ActionData1 == 0)
            //        {
            //            Operations.MoveInDirection8(ref drawOffset, CharDir, phaseTime * ActionData1 * Graphics.TextureManager.TILE_SIZE / phaseTotal);
            //        }
            //        else
            //        {
            //            int moveDist = phaseTime * 2 * Graphics.TextureManager.TILE_SIZE / phaseTotal;
            //            if (moveDist > Graphics.TextureManager.TILE_SIZE) moveDist = Graphics.TextureManager.TILE_SIZE;
            //            Operations.MoveInDirection8(ref drawOffset, CharDir, moveDist);
            //        }
            //        MapHeight = phaseTime * Graphics.TextureManager.TILE_SIZE / phaseTotal;
            //    }
            //    else
            //    {
            //        CharFrame = (phaseTime * TextureManager.GetSpriteSheet(CharData.Species, CharData.Form, CharData.Shiny, CharData.Gender).FrameData.GetFrameCount(FrameType.AltAttack, CharDir) / phaseTotal);
            //        Operations.MoveInDirection8(ref drawOffset, CharDir, ActionData1 * Graphics.TextureManager.TILE_SIZE - phaseTime * ActionData1 * Graphics.TextureManager.TILE_SIZE / phaseTotal);
            //        MapHeight = (phaseTotal - phaseTime) * Graphics.TextureManager.TILE_SIZE / phaseTotal;
            //    }
            //}
            else if (CurrentAction == ActionType.Deflect)
            {
                CharFrameType = FrameType.Hurt;
                CharFrame     = 0;
                TileOffset    = new Loc2D();
                Operations.MoveInDirection8(ref TileOffset, CharDir, ActionTime.Ticks * Graphics.TextureManager.TILE_SIZE / totalActionTime.Ticks);
                MapHeight = DrawHelper.GetArc(TextureManager.TILE_SIZE / 2, totalActionTime.Ticks, ActionTime.Ticks);
            }
            else if (CurrentAction == ActionType.Knockback)
            {
                CharFrameType = FrameType.Hurt;
                CharFrame     = 0;
                TileOffset    = new Loc2D();
                Operations.MoveInDirection8(ref TileOffset, Operations.ReverseDir(CharDir), ActionTime.Ticks * Graphics.TextureManager.TILE_SIZE / totalActionTime.Ticks);
                MapHeight = 0;
            }
            else
            {
                CharFrameType = FrameType.Idle;
                CharFrame     = 0;
                TileOffset    = new Loc2D();
                MapHeight     = 0;
            }
        }