示例#1
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);
        }
        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);
        }