コード例 #1
0
        private static void DrawInternal
        (
            UltimaBatcher2D batcher,
            Mobile owner,
            Item entity,
            int x,
            int y,
            Vector3 hueVec,
            bool mirror,
            byte frameIndex,
            bool hasShadow,
            ushort id,
            byte animGroup,
            byte dir,
            bool isHuman,
            bool isParent,
            bool isMount,
            bool forceUOP,
            float depth,
            sbyte mountOffset,
            ushort overridedHue,
            bool charIsSitting
        )
        {
            if (id >= Constants.MAX_ANIMATIONS_DATA_INDEX_COUNT || owner == null)
            {
                return;
            }

            ushort hueFromFile = overridedHue;

            AnimationDirection direction = AnimationsLoader.Instance.GetBodyAnimationGroup
                                           (
                ref id,
                ref animGroup,
                ref hueFromFile,
                isParent,
                forceUOP
                                           )
                                           .Direction[dir];

            if (direction == null || direction.Address == -1 || direction.FileIndex == -1)
            {
                if (!(charIsSitting && entity == null && !hasShadow))
                {
                    return;
                }
            }

            if (direction == null || (direction.FrameCount == 0 || direction.SpriteInfos == null) && !AnimationsLoader.Instance.LoadAnimationFrames(id, animGroup, dir, ref direction))
            {
                if (!(charIsSitting && entity == null && !hasShadow))
                {
                    return;
                }
            }

            if (direction == null)
            {
                return;
            }

            int fc = direction.FrameCount;

            if (fc > 0 && frameIndex >= fc)
            {
                frameIndex = (byte)(fc - 1);
            }
            else if (frameIndex < 0)
            {
                frameIndex = 0;
            }

            if (frameIndex < direction.FrameCount)
            {
                ref var spriteInfo = ref direction.SpriteInfos[frameIndex % direction.FrameCount];

                if (spriteInfo.Texture == null)
                {
                    if (!(charIsSitting && entity == null && !hasShadow))
                    {
                        return;
                    }

                    goto SKIP;
                }

                if (mirror)
                {
                    x -= spriteInfo.UV.Width - spriteInfo.Center.X;
                }
                else
                {
                    x -= spriteInfo.Center.X;
                }

                y -= spriteInfo.UV.Height + spriteInfo.Center.Y;

SKIP:

                if (hasShadow)
                {
                    batcher.DrawShadow(spriteInfo.Texture, new Vector2(x, y), spriteInfo.UV, mirror, depth);
                }
                else
                {
                    ushort hue        = overridedHue;
                    bool   partialHue = false;

                    if (hue == 0)
                    {
                        hue        = entity?.Hue ?? owner.Hue;
                        partialHue = !isMount && entity != null && entity.ItemData.IsPartialHue;

                        if ((hue & 0x8000) != 0)
                        {
                            partialHue = true;
                            hue       &= 0x7FFF;
                        }

                        if (hue == 0)
                        {
                            hue = hueFromFile;

                            if (hue == 0 && _equipConvData.HasValue)
                            {
                                hue = _equipConvData.Value.Color;
                            }

                            partialHue = false;
                        }
                    }

                    hueVec = ShaderHueTranslator.GetHueVector(hue, partialHue, hueVec.Z);

                    if (spriteInfo.Texture != null)
                    {
                        Vector2   pos  = new Vector2(x, y);
                        Rectangle rect = spriteInfo.UV;

                        if (charIsSitting)
                        {
                            Vector3 mod = CalculateSitAnimation(y, entity, isHuman, ref spriteInfo);

                            batcher.DrawCharacterSitted
                            (
                                spriteInfo.Texture,
                                pos,
                                rect,
                                mod,
                                hueVec,
                                mirror,
                                depth + 1f
                            );
                        }
                        else
                        {
                            //bool isMounted = isHuman && owner.IsMounted;


                            //int diffX = spriteInfo.UV.Width /*- spriteInfo.Center.X*/;

                            //if (isMounted)
                            //{
                            //if (mountOffset != 0)
                            //{
                            //    mountOffset += 10;
                            //}
                            //else
                            //{
                            //mountOffset = (sbyte)Math.Abs(spriteInfo.Center.Y);
                            //}
                            //}

                            //var flags = AnimationsLoader.Instance.DataIndex[id].Flags;
                            //if (AnimationsLoader.Instance.DataIndex[id].Type == ANIMATION_GROUPS_TYPE.HUMAN)
                            //{

                            //}


                            int diffY = (spriteInfo.UV.Height + spriteInfo.Center.Y) - mountOffset;

                            //if (owner.Serial == World.Player.Serial && entity == null)
                            //{

                            //}

                            int value = /*!isMounted && diffX <= 44 ? spriteInfo.UV.Height * 2 :*/ Math.Max(1, diffY);
                            int count = Math.Max((spriteInfo.UV.Height / value) + 1, 2);

                            rect.Height = Math.Min(value, rect.Height);
                            int remains = spriteInfo.UV.Height - rect.Height;

                            int tiles = (byte)owner.Direction % 2 == 0 ? 2 : 2;
                            //tiles = 999;

                            for (int i = 0; i < count; ++i)
                            {
                                //hueVec.Y = 1;
                                //hueVec.X = 0x44 + (i * 20);

                                batcher.Draw
                                (
                                    spriteInfo.Texture,
                                    pos,
                                    rect,
                                    hueVec,
                                    0f,
                                    Vector2.Zero,
                                    1f,
                                    mirror ? SpriteEffects.FlipHorizontally : SpriteEffects.None,
                                    depth + 1f + (i * tiles)
                                    //depth + (i * tiles) + (owner.PriorityZ * 0.001f)
                                );

                                pos.Y      += rect.Height;
                                rect.Y     += rect.Height;
                                rect.Height = remains; // Math.Min(value, remains);
                                remains    -= rect.Height;
                            }
                        }

                        int xx = -spriteInfo.Center.X;
                        int yy = -(spriteInfo.UV.Height + spriteInfo.Center.Y + 3);

                        if (mirror)
                        {
                            xx = -(spriteInfo.UV.Width - spriteInfo.Center.X);
                        }

                        if (xx < owner.FrameInfo.X)
                        {
                            owner.FrameInfo.X = xx;
                        }

                        if (yy < owner.FrameInfo.Y)
                        {
                            owner.FrameInfo.Y = yy;
                        }

                        if (owner.FrameInfo.Width < xx + spriteInfo.UV.Width)
                        {
                            owner.FrameInfo.Width = xx + spriteInfo.UV.Width;
                        }

                        if (owner.FrameInfo.Height < yy + spriteInfo.UV.Height)
                        {
                            owner.FrameInfo.Height = yy + spriteInfo.UV.Height;
                        }
                    }

                    if (entity != null && entity.ItemData.IsLight)
                    {
                        Client.Game.GetScene <GameScene>().AddLight(owner, entity, mirror ? x + spriteInfo.UV.Width : x, y);
                    }
                }
            }