示例#1
0
        public Rect GetSpriteSheetSize()
        {
            var size = new Rect();

            size.SetWidth(this._mNumPatternZ * this._mNumPatternX * this._mLayers * this.GetWidth() *
                          SpriteManager.SpriteSize);
            size.SetHeight(this._mAnimationPhases * this._mNumPatternY * this.GetHeight() * SpriteManager.SpriteSize);
            return(size);
        }
示例#2
0
        public void Unserialize(ushort clientId, ThingCategory category, BinaryReader fin)
        {
            _mNull     = false;
            _mId       = clientId;
            _mCategory = category;

            int  count = 0;
            int  attr  = -1;
            bool done  = false;

            for (int i = 0; i < (int)ThingAttr.ThingLastAttr; ++i)
            {
                count++;
                attr = fin.ReadByte();
                if (attr == (int)ThingAttr.ThingLastAttr)
                {
                    done = true;
                    break;
                }

//                if (attr == 254)
//                {
//                    continue;
//                }


                if (GameConfig.ClientVersion >= 1000)
                {
                    //             In 10.10+ all attributes from 16 and up were
                    //             * incremented by 1 to make space for 16 as
                    //             * "No Movement Animation" flag.
                    //
                    if (attr == 16)
                    {
                        attr = (int)ThingAttr.ThingAttrNoMoveAnimation;
                    }
                    else if (attr > 16)
                    {
                        attr -= 1;
                    }
                }
                else if (GameConfig.ClientVersion >= 860)
                {
                    //             Default attribute values follow
                    //             * the format of 8.6-9.86.
                    //             * Therefore no changes here.
                    //
                }
                else if (GameConfig.ClientVersion >= 780)
                {
                    //             In 7.80-8.54 all attributes from 8 and higher were
                    //             * incremented by 1 to make space for 8 as
                    //             * "Item Charges" flag.
                    //
                    if (attr == 8)
                    {
                        MAttribs[ThingAttr.ThingAttrChargeable] = true;
                        continue;
                    }
                    else if (attr > 8)
                    {
                        attr -= 1;
                    }
                }
                else if (GameConfig.ClientVersion >= 755)
                {
                    // In 7.55-7.72 attributes 23 is "Floor Change".
                    if (attr == 23)
                    {
                        attr = (int)ThingAttr.ThingAttrFloorChange;
                    }
                }
                else if (GameConfig.ClientVersion >= 740)
                {
                    //             In 7.4-7.5 attribute "Ground Border" did not exist
                    //             * attributes 1-15 have to be adjusted.
                    //             * Several other changes in the format.
                    //
                    if (attr > 0 && attr <= 15)
                    {
                        attr += 1;
                    }
                    else if (attr == 16)
                    {
                        attr = (int)ThingAttr.ThingAttrLight;
                    }
                    else if (attr == 17)
                    {
                        attr = (int)ThingAttr.ThingAttrFloorChange;
                    }
                    else if (attr == 18)
                    {
                        attr = (int)ThingAttr.ThingAttrFullGround;
                    }
                    else if (attr == 19)
                    {
                        attr = (int)ThingAttr.ThingAttrElevation;
                    }
                    else if (attr == 20)
                    {
                        attr = (int)ThingAttr.ThingAttrDisplacement;
                    }
                    else if (attr == 22)
                    {
                        attr = (int)ThingAttr.ThingAttrMinimapColor;
                    }
                    else if (attr == 23)
                    {
                        attr = (int)ThingAttr.ThingAttrRotateable;
                    }
                    else if (attr == 24)
                    {
                        attr = (int)ThingAttr.ThingAttrLyingCorpse;
                    }
                    else if (attr == 25)
                    {
                        attr = (int)ThingAttr.ThingAttrHangable;
                    }
                    else if (attr == 26)
                    {
                        attr = (int)ThingAttr.ThingAttrHookSouth;
                    }
                    else if (attr == 27)
                    {
                        attr = (int)ThingAttr.ThingAttrHookEast;
                    }
                    else if (attr == 28)
                    {
                        attr = (int)ThingAttr.ThingAttrAnimateAlways;
                    }

                    // "Multi Use" and "Force Use" are swapped
                    if (attr == (int)ThingAttr.ThingAttrMultiUse)
                    {
                        attr = (int)ThingAttr.ThingAttrForceUse;
                    }
                    else if (attr == (int)ThingAttr.ThingAttrForceUse)
                    {
                        attr = (int)ThingAttr.ThingAttrMultiUse;
                    }
                }

                switch (attr)
                {
                case (int)ThingAttr.ThingAttrDisplacement:
                {
                    if (GameConfig.ClientVersion >= 755)
                    {
                        _mDisplacement.X = fin.ReadUInt16();
                        _mDisplacement.Y = fin.ReadUInt16();
                    }
                    else
                    {
                        _mDisplacement.X = 8;
                        _mDisplacement.Y = 8;
                    }
                    MAttribs[(ThingAttr)attr] = true;
                    break;
                }

                case (int)ThingAttr.ThingAttrLight:
                {
                    Light light = new Light();
                    light.Intensity           = (byte)fin.ReadUInt16();
                    light.Color               = (byte)fin.ReadUInt16();
                    MAttribs[(ThingAttr)attr] = light;
                    break;
                }

                case (int)ThingAttr.ThingAttrMarket:
                {
                    MarketData market = new MarketData();
                    market.Category = fin.ReadUInt16();
                    market.TradeAs  = fin.ReadUInt16();
                    market.ShowAs   = fin.ReadUInt16();
                    var nameLength = fin.ReadUInt16();
                    var chars      = fin.ReadChars(nameLength);
                    market.Name               = new string(chars);
                    market.RestrictVocation   = fin.ReadUInt16();
                    market.RequiredLevel      = fin.ReadUInt16();
                    MAttribs[(ThingAttr)attr] = market;
                    break;
                }

                case (int)ThingAttr.ThingAttrElevation:
                {
                    _mElevation = fin.ReadUInt16();
                    MAttribs[(ThingAttr)attr] = _mElevation;
                    break;
                }

                case (int)ThingAttr.ThingAttrUsable:
                case (int)ThingAttr.ThingAttrGround:
                case (int)ThingAttr.ThingAttrWritable:
                case (int)ThingAttr.ThingAttrWritableOnce:
                case (int)ThingAttr.ThingAttrMinimapColor:
                case (int)ThingAttr.ThingAttrCloth:
                case (int)ThingAttr.ThingAttrLensHelp:
                    MAttribs[(ThingAttr)attr] = fin.ReadUInt16();
                    ;
                    break;

                default:
                    MAttribs[(ThingAttr)attr] = true;
                    break;
                }
                ;
//                switch (attr)
//                {
//                    case (int) ThingTypeFlags6.HAS_OFFSET:
//                    {
//                        if (GameConfig.ClientVersion >= 755)
//                        {
//                            m_displacement.x = fin.ReadUInt16();
//                            m_displacement.y = fin.ReadUInt16();
//                        }
//                        else
//                        {
//                            m_displacement.x = 8;
//                            m_displacement.y = 8;
//                        }
//                        m_attribs[(ThingAttr) attr] = true;
//                        break;
//                    }
//                    case (int) ThingTypeFlags6.HAS_LIGHT:
//                    {
//                        Light light = new Light();
//                        light.intensity = (byte) fin.ReadUInt16();
//                        light.color = (byte) fin.ReadUInt16();
//                        m_attribs[(ThingAttr) attr] = light;
//                        break;
//                    }
//                    case (int) ThingTypeFlags6.MARKET_ITEM:
//                    {
//                        MarketData market = new MarketData();
//                        market.category = fin.ReadUInt16();
//                        market.tradeAs = fin.ReadUInt16();
//                        market.showAs = fin.ReadUInt16();
//                        var nameLength = fin.ReadUInt16();
//                        market.name = new string(fin.ReadChars(nameLength));
//                        market.restrictVocation = fin.ReadUInt16();
//                        market.requiredLevel = fin.ReadUInt16();
//                        m_attribs[(ThingAttr) attr] = market;
//                        break;
//                    }
//                    case (int) ThingTypeFlags6.HAS_ELEVATION:
//                    {
//                        m_elevation = fin.ReadUInt16();
//                        m_attribs[(ThingAttr) attr] = m_elevation;
//                        break;
//                    }
//                    case (int) ThingTypeFlags6.USABLE:
//                    case (int) ThingTypeFlags6.GROUND:
//                    case (int) ThingTypeFlags6.WRITABLE:
//                    case (int) ThingTypeFlags6.WRITABLE_ONCE:
//                    case (int) ThingTypeFlags6.MINI_MAP:
//                    case (int) ThingTypeFlags6.CLOTH:
//                    case (int) ThingTypeFlags6.LENS_HELP:
//                        m_attribs[(ThingAttr) attr] = fin.ReadUInt16();
//                        ;
//                        break;
//                    default:
//                        m_attribs[(ThingAttr)attr] = true;
//                        break;
//                };
            }

            if (!done)
            {
                return;
            }

            bool hasFrameGroups = (category == ThingCategory.ThingCategoryCreature && GameConfig.GameIdleAnimations);

            groupCount = hasFrameGroups ? fin.ReadByte() : (byte)1;

            _mAnimationPhases = 0;

            if (groupCount == 0)
            {
                _mAnimator.Add(new Animator());
            }

            for (int i = 0; i < groupCount; ++i)
            {
                uint frameGroupType = (uint)FrameGroupType.FrameGroupDefault;
                if (hasFrameGroups)
                {
                    frameGroupType = fin.ReadByte();
                }

                uint width  = fin.ReadByte();
                uint height = fin.ReadByte();
                _mSize = new Rect(0, 0, (int)width, (int)height);
                if (width > 1 || height > 1)
                {
                    _mRealSize  = fin.ReadByte();
                    _mExactSize = Math.Min(_mRealSize, Math.Max((int)width * (int)32, (int)height * (int)32));
                }
                else
                {
                    _mExactSize = 32;
                }

                _mLayers      = fin.ReadByte();
                _mNumPatternX = fin.ReadByte();
                _mNumPatternY = fin.ReadByte();
                if (GameConfig.ClientVersion >= 755)
                {
                    _mNumPatternZ = fin.ReadByte();
                }
                else
                {
                    _mNumPatternZ = 1;
                }

                var groupAnimationsPhases = fin.ReadByte();
                _mAnimationPhases += groupAnimationsPhases;

                if (groupAnimationsPhases > 1 && GameConfig.GameEnhancedAnimations)
                {
                    _mAnimator.Add(new Animator());
                    _mAnimator[i].Unserialize(groupAnimationsPhases, fin);
                }
                else
                {
                    _mAnimator.Add(new Animator());
                    _mAnimator[i]._mAnimationPhases = groupAnimationsPhases;
                }

                int totalSprites = (int)_mSize.Width() * (int)_mSize.Height() * _mLayers * _mNumPatternX *
                                   _mNumPatternY *
                                   _mNumPatternZ * groupAnimationsPhases;

                if (totalSprites > 4096)
                {
                    return;
                }

                for (int x = 0; x < totalSprites; x++)
                {
                    _mSpritesIndex.Add(GameConfig.GameSpritesU32 ? (int)fin.ReadUInt32() : fin.ReadUInt16());
                }
            }

//            m_textures.resize(m_animationPhases);
//            m_texturesFramesRects.resize(m_animationPhases);
            for (int i = 0; i < _mAnimationPhases; i++)
            {
                _mTexturesFramesRects.Add(new List <Rect>());
            }
//            m_texturesFramesOriginRects.resize(m_animationPhases);
            for (int i = 0; i < _mAnimationPhases; i++)
            {
                _mTexturesFramesOriginRects.Add(new List <Rect>());
            }
//            m_texturesFramesOffsets.resize(m_animationPhases);
            for (int i = 0; i < _mAnimationPhases; i++)
            {
                _mTexturesFramesOffsets.Add(new List <Position>());
            }
        }