コード例 #1
0
ファイル: SelectedObject.cs プロジェクト: sadoseja/ClassicUO
        public static bool IsPointInMobile(Mobile mobile, int xx, int yy)
        {
            bool mirror = false;
            byte dir    = (byte)mobile.GetDirectionForAnimation();

            FileManager.Animations.GetAnimDirection(ref dir, ref mirror);


            sbyte animIndex = mobile.AnimIndex;

            for (int i = -2; i < Constants.USED_LAYER_COUNT; i++)
            {
                Layer layer = i == -2 ? Layer.Invalid : i == -1 ? Layer.Mount : LayerOrder.UsedLayers[dir, i];

                ushort graphic;

                if (layer == Layer.Invalid)
                {
                    graphic = mobile.GetGraphicForAnimation();
                }
                else if (mobile.HasEquipment)
                {
                    Item item = mobile.Equipment[(int)layer];

                    if (item == null)
                    {
                        continue;
                    }

                    if (layer == Layer.Mount)
                    {
                        graphic = item.GetGraphicForAnimation();
                    }
                    else if (item.ItemData.AnimID != 0)
                    {
                        if (Mobile.IsCovered(mobile, layer))
                        {
                            continue;
                        }

                        graphic = item.ItemData.AnimID;

                        if (FileManager.Animations.EquipConversions.TryGetValue(mobile.Graphic, out Dictionary <ushort, EquipConvData> map))
                        {
                            if (map.TryGetValue(item.ItemData.AnimID, out EquipConvData data))
                            {
                                graphic = data.Graphic;
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    continue;
                }


                byte animGroup = Mobile.GetGroupForAnimation(mobile, graphic, layer == Layer.Invalid);

                ushort  hue       = 0;
                ref var direction = ref FileManager.Animations.GetBodyAnimationGroup(ref graphic, ref animGroup, ref hue, true).Direction[dir];

                FileManager.Animations.AnimID    = graphic;
                FileManager.Animations.AnimGroup = animGroup;
                FileManager.Animations.Direction = dir;

                if ((direction.FrameCount == 0 || direction.Frames == null) && !FileManager.Animations.LoadDirectionGroup(ref direction))
                {
                    continue;
                }

                int fc = direction.FrameCount;

                if (fc != 0 && animIndex >= fc)
                {
                    animIndex = 0;
                }

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

                    if (frame == null || frame.IsDisposed)
                    {
                        continue;
                    }

                    int drawX;

                    int drawCenterY = frame.CenterY;
                    int yOff        = ((int)mobile.Offset.Z >> 2) - 22 - (int)(mobile.Offset.Y - mobile.Offset.Z - 3);
                    int drawY       = drawCenterY + yOff;

                    if (mirror)
                    {
                        drawX = -22 + (int)mobile.Offset.X;
                    }
                    else
                    {
                        drawX = -22 - (int)mobile.Offset.X;
                    }

                    int x = drawX + frame.CenterX;
                    int y = -drawY - (frame.Height + frame.CenterY) + drawCenterY;

                    if (mirror)
                    {
                        x = xx + x + 44 - TranslatedMousePositionByViewport.X;
                    }
                    else
                    {
                        x = TranslatedMousePositionByViewport.X - xx + x;
                    }

                    y = TranslatedMousePositionByViewport.Y - yy - y;

                    if (frame.Contains(x, y))
                    {
                        return(true);
                    }
                }
            }
コード例 #2
0
        private static sbyte DrawInternal
        (
            UltimaBatcher2D batcher,
            Mobile owner,
            Item entity,
            int x,
            int y,
            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 < 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;
                        }
                    }

                    ResetHueVector();
                    ShaderHueTranslator.GetHueVector(ref HueVector, 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 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;
                        }
                    }

                    if (frame.Contains(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);
        }
コード例 #3
0
        public static bool IsPointInCorpse(Item corpse, int xx, int yy)
        {
            if (corpse == null || World.CorpseManager.Exists(corpse.Serial, 0))
            {
                return(false);
            }

            byte dir    = (byte)((byte)corpse.Layer & 0x7F & 7);
            bool mirror = false;

            AnimationsLoader.Instance.GetAnimDirection(ref dir, ref mirror);
            AnimationsLoader.Instance.Direction = dir;
            byte animIndex = (byte)corpse.AnimIndex;

            for (int i = -1; i < Constants.USED_LAYER_COUNT; i++)
            {
                Layer layer = i == -1 ? Layer.Mount : LayerOrder.UsedLayers[dir, i];

                ushort graphic;
                ushort color = 0;

                if (layer == Layer.Invalid)
                {
                    graphic = corpse.GetGraphicForAnimation();
                    AnimationsLoader.Instance.AnimGroup = AnimationsLoader.Instance.GetDieGroupIndex(graphic, corpse.UsedLayer);
                }
                else if (corpse.HasEquipment && MathHelper.InRange(corpse.Amount, 0x0190, 0x0193) ||
                         MathHelper.InRange(corpse.Amount, 0x00B7, 0x00BA) ||
                         MathHelper.InRange(corpse.Amount, 0x025D, 0x0260) ||
                         MathHelper.InRange(corpse.Amount, 0x029A, 0x029B) ||
                         MathHelper.InRange(corpse.Amount, 0x02B6, 0x02B7) ||
                         corpse.Amount == 0x03DB || corpse.Amount == 0x03DF || corpse.Amount == 0x03E2 || corpse.Amount == 0x02E8 || corpse.Amount == 0x02E9)
                {
                    Item itemEquip = corpse.Equipment[(int)layer];

                    if (itemEquip == null)
                    {
                        continue;
                    }

                    graphic = itemEquip.ItemData.AnimID;

                    if (AnimationsLoader.Instance.EquipConversions.TryGetValue(corpse.Amount, out Dictionary <ushort, EquipConvData> map))
                    {
                        if (map.TryGetValue(graphic, out EquipConvData data))
                        {
                            graphic = data.Graphic;
                        }
                    }
                }
                else
                {
                    continue;
                }


                byte animGroup = AnimationsLoader.Instance.AnimGroup;

                AnimationGroup gr = layer == Layer.Invalid
                                        ? AnimationsLoader.Instance.GetCorpseAnimationGroup(ref graphic, ref animGroup, ref color)
                                        : AnimationsLoader.Instance.GetBodyAnimationGroup(ref graphic, ref animGroup, ref color);

                AnimationDirection direction = gr.Direction[AnimationsLoader.Instance.Direction];

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

                int fc = direction.FrameCount;

                if (fc > 0 && animIndex >= fc)
                {
                    animIndex = (byte)(fc - 1);
                }

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

                    if (frame == null || frame.IsDisposed)
                    {
                        continue;
                    }

                    int       drawCenterY = frame.CenterY;
                    const int drawX       = -22;
                    int       drawY       = drawCenterY - 22;
                    drawY -= 3;
                    int x = drawX + frame.CenterX;
                    int y = -drawY - (frame.Height + frame.CenterY) + drawCenterY;

                    if (mirror)
                    {
                        x = xx + x + 44 - TranslatedMousePositionByViewport.X;
                    }
                    else
                    {
                        x = TranslatedMousePositionByViewport.X - xx + x;
                    }

                    y = TranslatedMousePositionByViewport.Y - yy + y;

                    if (frame.Contains(x, y))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }