Exemplo n.º 1
0
        private static sbyte DrawInternal
        (
            UltimaBatcher2D batcher,
            Mobile owner,
            Item entity,
            int x,
            int y,
            ref Vector3 hueVec,
            bool mirror,
            sbyte frameIndex,
            bool hasShadow,
            ushort id,
            byte animGroup,
            byte dir,
            bool isHuman,
            bool isParent = true,
            bool isMount  = false,
            bool forceUOP = false,
            float alpha   = 0
        )
        {
            if (id >= Constants.MAX_ANIMATIONS_DATA_INDEX_COUNT || owner == null)
            {
                return(0);
            }

            ushort hueFromFile = _viewHue;


            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 (!(_transform && entity == null && !hasShadow))
                {
                    return(0);
                }
            }

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

            if (direction == null)
            {
                return(0);
            }

            direction.LastAccessTime = Time.Ticks;

            int fc = direction.FrameCount;

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

            if (frameIndex < direction.FrameCount)
            {
                AnimationFrameTexture frame = direction.Frames[frameIndex];

                if (frame == null || frame.IsDisposed)
                {
                    if (!(_transform && entity == null && !hasShadow))
                    {
                        return(0);
                    }

                    goto SKIP;
                }

                frame.Ticks = Time.Ticks;

                if (mirror)
                {
                    x -= frame.Width - frame.CenterX;
                }
                else
                {
                    x -= frame.CenterX;
                }

                y -= frame.Height + frame.CenterY;

SKIP:

                if (hasShadow)
                {
                    batcher.DrawSpriteShadow(frame, x, y, mirror);
                }
                else
                {
                    ushort hue        = _viewHue;
                    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 = Vector3.Zero;
                    ShaderHueTranslator.GetHueVector(ref hueVec, hue, partialHue, alpha);

                    // this is an hack to make entities partially hued. OG client seems to ignore this.

                    /*if (entity != null && entity.ItemData.AnimID == 0 && entity.ItemData.IsLight)
                     * {
                     *  HueVector.X = entity.Hue == 0 ? owner.Hue : entity.Hue;
                     *  HueVector.Y = ShaderHueTranslator.SHADER_LIGHTS;
                     *  HueVector.Z = alpha;
                     * }
                     */

                    if (_transform)
                    {
                        const float UPPER_BODY_RATIO = 0.35f;
                        const float MID_BODY_RATIO   = 0.60f;
                        const float LOWER_BODY_RATIO = 0.94f;

                        if (entity == null && isHuman)
                        {
                            int frameHeight = frame?.Height ?? 61;
                            _characterFrameStartY = y - (frame != null ? 0 : frameHeight - SIT_OFFSET_Y);
                            _characterFrameHeight = frameHeight;
                            _startCharacterWaistY = (int)(frameHeight * UPPER_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterKneesY = (int)(frameHeight * MID_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterFeetY  = (int)(frameHeight * LOWER_BODY_RATIO) + _characterFrameStartY;

                            if (frame == null)
                            {
                                return(0);
                            }
                        }

                        float h3mod = UPPER_BODY_RATIO;
                        float h6mod = MID_BODY_RATIO;
                        float h9mod = LOWER_BODY_RATIO;


                        if (entity != null)
                        {
                            float itemsEndY = y + frame.Height;

                            if (y >= _startCharacterWaistY)
                            {
                                h3mod = 0;
                            }
                            else if (itemsEndY <= _startCharacterWaistY)
                            {
                                h3mod = 1.0f;
                            }
                            else
                            {
                                float upperBodyDiff = _startCharacterWaistY - y;
                                h3mod = upperBodyDiff / frame.Height;

                                if (h3mod < 0)
                                {
                                    h3mod = 0;
                                }
                            }


                            if (_startCharacterWaistY >= itemsEndY || y >= _startCharacterKneesY)
                            {
                                h6mod = 0;
                            }
                            else if (_startCharacterWaistY <= y && itemsEndY <= _startCharacterKneesY)
                            {
                                h6mod = 1.0f;
                            }
                            else
                            {
                                float midBodyDiff;

                                if (y >= _startCharacterWaistY)
                                {
                                    midBodyDiff = _startCharacterKneesY - y;
                                }
                                else if (itemsEndY <= _startCharacterKneesY)
                                {
                                    midBodyDiff = itemsEndY - _startCharacterWaistY;
                                }
                                else
                                {
                                    midBodyDiff = _startCharacterKneesY - _startCharacterWaistY;
                                }

                                h6mod = h3mod + midBodyDiff / frame.Height;

                                if (h6mod < 0)
                                {
                                    h6mod = 0;
                                }
                            }


                            if (itemsEndY <= _startCharacterKneesY)
                            {
                                h9mod = 0;
                            }
                            else if (y >= _startCharacterKneesY)
                            {
                                h9mod = 1.0f;
                            }
                            else
                            {
                                float lowerBodyDiff = itemsEndY - _startCharacterKneesY;
                                h9mod = h6mod + lowerBodyDiff / frame.Height;

                                if (h9mod < 0)
                                {
                                    h9mod = 0;
                                }
                            }
                        }

                        batcher.DrawCharacterSitted
                        (
                            frame,
                            x,
                            y,
                            mirror,
                            h3mod,
                            h6mod,
                            h9mod,
                            ref hueVec
                        );
                    }
                    else if (frame != null)
                    {
                        batcher.DrawSprite
                        (
                            frame,
                            x,
                            y,
                            mirror,
                            ref hueVec
                        );

                        int yy = -(frame.Height + frame.CenterY + 3);
                        int xx = -frame.CenterX;

                        if (mirror)
                        {
                            xx = -(frame.Width - frame.CenterX);
                        }

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

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

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

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


                    if (AnimationsLoader.Instance.PixelCheck(id, animGroup, dir, direction.IsUOP, frameIndex, mirror ? x + frame.Width - SelectedObject.TranslatedMousePositionByViewport.X : SelectedObject.TranslatedMousePositionByViewport.X - x, SelectedObject.TranslatedMousePositionByViewport.Y - y))
                    {
                        SelectedObject.Object = owner;
                    }

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

                return(AnimationsLoader.Instance.DataIndex[id].MountedHeightOffset);
            }

            return(0);
        }
Exemplo n.º 2
0
        private static sbyte DrawInternal(UltimaBatcher2D batcher,
                                          Mobile owner,
                                          Item entity,
                                          int x,
                                          int y,
                                          bool mirror,
                                          ref sbyte frameIndex,
                                          bool hasShadow,
                                          ushort id,
                                          bool isHuman,
                                          bool isParent = true,
                                          bool isMount  = false)
        {
            if (id >= Constants.MAX_ANIMATIONS_DATA_INDEX_COUNT || owner == null)
            {
                return(0);
            }

            ushort hueFromFile = _viewHue;
            byte   animGroup   = AnimationsLoader.Instance.AnimGroup;

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

            AnimationsLoader.Instance.AnimID = id;

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

            if (direction == null || ((direction.FrameCount == 0 || direction.Frames == null) && !AnimationsLoader.Instance.LoadDirectionGroup(ref direction)))
            {
                if (!(_transform && entity == null && !hasShadow))
                {
                    return(0);
                }
            }

            if (direction == null)
            {
                return(0);
            }

            direction.LastAccessTime = Time.Ticks;

            int fc = direction.FrameCount;

            if ((fc > 0 && frameIndex >= fc) || frameIndex < 0)
            {
                frameIndex = 0;
            }

            if (frameIndex < direction.FrameCount)
            {
                var frame = direction.Frames[frameIndex];

                if (frame == null || frame.IsDisposed)
                {
                    if (!(_transform && entity == null && !hasShadow))
                    {
                        return(0);
                    }

                    goto SKIP;
                }

                frame.Ticks = Time.Ticks;

                if (mirror)
                {
                    x -= frame.Width - frame.CenterX;
                }
                else
                {
                    x -= frame.CenterX;
                }

                y -= frame.Height + frame.CenterY;

SKIP:

                if (hasShadow)
                {
                    batcher.DrawSpriteShadow(frame, x, y, mirror);
                }
                else
                {
                    ushort hue        = _viewHue;
                    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;
                        }
                    }
                    ResetHueVector();
                    ShaderHuesTraslator.GetHueVector(ref HueVector, hue, partialHue, 0);

                    if (_transform)
                    {
                        const float UPPER_BODY_RATIO = 0.35f;
                        const float MID_BODY_RATIO   = 0.60f;
                        const float LOWER_BODY_RATIO = 0.94f;

                        if (entity == null && isHuman)
                        {
                            int frameHeight = frame?.Height ?? 61;
                            _characterFrameStartY = y - (frame != null ? 0 : (frameHeight - 4));
                            _characterFrameHeight = frameHeight;
                            _startCharacterWaistY = (int)(frameHeight * UPPER_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterKneesY = (int)(frameHeight * MID_BODY_RATIO) + _characterFrameStartY;
                            _startCharacterFeetY  = (int)(frameHeight * LOWER_BODY_RATIO) + _characterFrameStartY;

                            if (frame == null)
                            {
                                return(0);
                            }
                        }

                        float h3mod = UPPER_BODY_RATIO;
                        float h6mod = MID_BODY_RATIO;
                        float h9mod = LOWER_BODY_RATIO;


                        if (entity != null)
                        {
                            float itemsEndY = y + frame.Height;

                            if (y >= _startCharacterWaistY)
                            {
                                h3mod = 0;
                            }
                            else if (itemsEndY <= _startCharacterWaistY)
                            {
                                h3mod = 1.0f;
                            }
                            else
                            {
                                float upperBodyDiff = _startCharacterWaistY - y;
                                h3mod = upperBodyDiff / frame.Height;

                                if (h3mod < 0)
                                {
                                    h3mod = 0;
                                }
                            }


                            if (_startCharacterWaistY >= itemsEndY || y >= _startCharacterKneesY)
                            {
                                h6mod = 0;
                            }
                            else if (_startCharacterWaistY <= y && itemsEndY <= _startCharacterKneesY)
                            {
                                h6mod = 1.0f;
                            }
                            else
                            {
                                float midBodyDiff;

                                if (y >= _startCharacterWaistY)
                                {
                                    midBodyDiff = _startCharacterKneesY - y;
                                }
                                else if (itemsEndY <= _startCharacterKneesY)
                                {
                                    midBodyDiff = itemsEndY - _startCharacterWaistY;
                                }
                                else
                                {
                                    midBodyDiff = _startCharacterKneesY - _startCharacterWaistY;
                                }

                                h6mod = h3mod + midBodyDiff / frame.Height;

                                if (h6mod < 0)
                                {
                                    h6mod = 0;
                                }
                            }


                            if (itemsEndY <= _startCharacterKneesY)
                            {
                                h9mod = 0;
                            }
                            else if (y >= _startCharacterKneesY)
                            {
                                h9mod = 1.0f;
                            }
                            else
                            {
                                float lowerBodyDiff = itemsEndY - _startCharacterKneesY;
                                h9mod = h6mod + lowerBodyDiff / frame.Height;

                                if (h9mod < 0)
                                {
                                    h9mod = 0;
                                }
                            }
                        }

                        batcher.DrawCharacterSitted(frame, x, y, mirror, h3mod, h6mod, h9mod, ref HueVector);
                    }
                    else if (frame != null)
                    {
                        batcher.DrawSprite(frame, x, y, mirror, ref HueVector);

                        int yy = -(frame.Height + frame.CenterY + 3);
                        int xx = -frame.CenterX;

                        if (mirror)
                        {
                            xx = -(frame.Width - frame.CenterX);
                        }

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

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

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

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

                    owner.Texture = frame;
                    owner.Select(mirror ? x + frame.Width - SelectedObject.TranslatedMousePositionByViewport.X : SelectedObject.TranslatedMousePositionByViewport.X - x, SelectedObject.TranslatedMousePositionByViewport.Y - y);

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

                return(AnimationsLoader.Instance.DataIndex[id].MountedHeightOffset);
            }

            return(0);
        }
Exemplo n.º 3
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);
                    }
                }
            }