/// <summary>
        /// 魔法界面
        /// </summary>
        /// <param name="context"></param>
        /// <param name="magicChain">魔法链</param>
        /// <param name="selectedCallBack">选择回调</param>
        public ScreenMagic(SimulatorContext context, ResMagicChain magicChain, Action <BaseMagic> selectedCallBack) : base(context)
        {
            if (magicChain == null || selectedCallBack == null)
            {
                throw new Exception("ScreenMagic construtor params can't be null.");
            }
            _magicChain             = magicChain;
            _onItemSelectedCallBack = selectedCallBack;

            _cursor  = Context.GraphicsFactory.NewImageBuilder(12, 11);
            _marker  = Context.GraphicsFactory.NewImageBuilder(5, 8);
            _marker2 = Context.GraphicsFactory.NewImageBuilder(5, 8);

            CreateImage();
        }
        public void Deserialize(BinaryReader binaryReader)
        {
            Type         = binaryReader.ReadInt32();
            Index        = binaryReader.ReadInt32();
            _imgHead     = Context.LibData.GetImage(1, Index);
            LevelupChain = Context.LibData.GetLevelupChain(Index);

            SetWalkingSprite(new WalkingSprite(Context, Type, binaryReader.ReadInt32()));
            FightingSprite = new FightingSprite(Context, false, Index);
            Direction      = (Direction)binaryReader.ReadInt32();
            SetStep(binaryReader.ReadInt32());
            SetPosInMap(binaryReader.ReadInt32(), binaryReader.ReadInt32());

            var hasMagicChain = binaryReader.ReadBoolean();

            if (hasMagicChain)
            {
                MagicChain = new ResMagicChain(Context);
                MagicChain.Deserialize(binaryReader);
            }

            Name       = binaryReader.ReadString();
            Level      = binaryReader.ReadInt32();
            MaxHP      = binaryReader.ReadInt32();
            HP         = binaryReader.ReadInt32();
            MaxMP      = binaryReader.ReadInt32();
            MP         = binaryReader.ReadInt32();
            Attack     = binaryReader.ReadInt32();
            Defend     = binaryReader.ReadInt32();
            Speed      = binaryReader.ReadInt32();
            Lingli     = binaryReader.ReadInt32();
            Luck       = binaryReader.ReadInt32();
            CurrentExp = binaryReader.ReadInt32();

            for (int i = 0; i < 8; i++)
            {
                var type  = binaryReader.ReadInt32();
                var index = binaryReader.ReadInt32();
                if (type != 0 && index != 0)
                {
                    Equipments[i] = Context.LibData.GetGoods(type, index) as GoodsEquipment;
                }
            }
        }
        public override void SetData(byte[] buf, int offset)
        {
            Type  = buf[offset] & 0xff;
            Index = buf[offset + 1] & 0xff;
            ResMagicChain magicChain = Context.LibData.GetMagicChain(buf[offset + 0x2f] & 0xff);

            if (magicChain != null)
            {
                magicChain.LearnFromChain(buf[offset + 2] & 0xff);
                MagicChain = magicChain;
            }

            AddBuff((CombatBuff)(buf[offset + 3] & 0xff));
            AttackBuff     = (CombatBuff)(buf[offset + 4] & 0xff);
            BuffLastRound  = buf[offset + 0x17] & 0xff;
            Name           = buf.GetString(offset + 6);
            Level          = buf[offset + 0x12] & 0xff;
            MaxHP          = buf.Get2BytesUInt(offset + 0x18);
            HP             = buf.Get2BytesUInt(offset + 0x1a);
            MaxMP          = buf.Get2BytesUInt(offset + 0x1c);
            MP             = buf.Get2BytesUInt(offset + 0x1e);
            Attack         = buf.Get2BytesUInt(offset + 0x20);
            Defend         = buf.Get2BytesUInt(offset + 0x22);
            Speed          = buf[offset + 0x13] & 0xff;
            Lingli         = buf[offset + 0x14] & 0xff;
            Luck           = buf[offset + 0x16] & 0xff;
            MonsterIQ      = buf[offset + 0x15] & 0xff;
            Money          = buf.Get2BytesUInt(offset + 0x24);
            EXP            = buf.Get2BytesUInt(offset + 0x26);
            _carryGoods[0] = (int)buf[offset + 0x28] & 0xff;
            _carryGoods[1] = (int)buf[offset + 0x29] & 0xff;
            _carryGoods[2] = (int)buf[offset + 0x2a] & 0xff;
            _dropGoods[0]  = (int)buf[offset + 0x2b] & 0xff;
            _dropGoods[1]  = (int)buf[offset + 0x2c] & 0xff;
            _dropGoods[2]  = (int)buf[offset + 0x2d] & 0xff;
            FightingSprite = new FightingSprite(Context, true, (int)buf[offset + 0x2e] & 0xff);
        }
        /// <summary>
        /// 获取资源
        /// </summary>
        /// <param name="resType">资源文件类型号1-12</param>
        /// <param name="type">资源类型</param>
        /// <param name="index">资源索引号</param>
        /// <returns>资源对象,不存在则返回</returns>
        public ResBase GetRes(int resType, int type, int index)
        {
            ResBase rtn    = null;
            int     offset = GetDataOffset(resType, type, index);

            //TODO 超过索引的资源直接不处理???
            if (offset != -1 && offset < _data.Length)
            {
                switch (resType)
                {
                case RES_GUT:
                    rtn = new ResGut(Context);
                    break;

                case RES_MAP:
                    rtn = new ResMap(Context);
                    break;

                case RES_ARS:
                    switch (type)
                    {
                    case 1:         // 玩家角色
                        rtn = new PlayerCharacter(Context);
                        break;

                    case 2:         // NPC角色
                        rtn = new NPC(Context);
                        break;

                    case 3:         // 敌人角色
                        rtn = new Monster(Context);
                        break;

                    case 4:         // 场景对象
                        rtn = new SceneObj(Context);
                        break;

                    default:
                        rtn = null;
                        break;
                    }
                    break;

                case RES_MRS:
                    rtn = InternalGetMagic(type, index);
                    break;

                case RES_SRS:
                    rtn = new ResSrs(Context);
                    break;

                case RES_GRS:
                    rtn = InternalGetGoods(type, index);
                    break;

                case RES_TIL:
                case RES_ACP:
                case RES_GDP:
                case RES_GGJ:
                case RES_PIC:
                    rtn = new ResImage(Context);
                    break;

                case RES_MLR:
                    if (type == 1)
                    {
                        rtn = new ResMagicChain(Context);
                    }
                    else if (type == 2)
                    {
                        rtn = new ResLevelupChain(Context);
                    }
                    break;
                }
                rtn.SetData(_data, offset);
            }
            else
            { // 资源不存在
              //Log.e("Context.LibData.GetRes", "resType:" + resType + " type:" + type + " index:" + index + " not found.");
            }

            return(rtn);
        }
        public override void SetData(byte[] buf, int offset)
        {
            Type     = buf[offset] & 0xFF;
            Index    = buf[offset + 1] & 0xFF;
            _imgHead = Context.LibData.GetImage(1, Index);
            SetWalkingSprite(new WalkingSprite(Context, Type, buf[offset + 0x16] & 0xFF));
            FightingSprite = new FightingSprite(Context, false, Index);
            Direction direction = Direction.North;

            switch (buf[offset + 2] & 0xFF)
            {
            case 1:
                direction = Direction.North;
                break;

            case 2:
                direction = Direction.East;
                break;

            case 3:
                direction = Direction.South;
                break;

            case 4:
                direction = Direction.West;
                break;
            }
            Direction = direction;
            SetStep(buf[offset + 3] & 0xff);
            SetPosInMap(buf[offset + 5] & 0xFF, buf[offset + 6] & 0xFF);
            MagicChain = Context.LibData.GetMagicChain(buf[offset + 0x17] & 0xff);
            if (MagicChain != null)
            {
                MagicChain.LearnFromChain(buf[offset + 9] & 0xff);
            }
            else
            {
                MagicChain = new ResMagicChain(Context);
            }
            Name   = buf.GetString(offset + 0x0a);
            Level  = buf[offset + 0x20] & 0xff;
            MaxHP  = buf.Get2BytesUInt(offset + 0x26);
            HP     = buf.Get2BytesUInt(offset + 0x28);
            MaxMP  = buf.Get2BytesUInt(offset + 0x2a);
            MP     = buf.Get2BytesUInt(offset + 0x2c);
            Attack = buf.Get2BytesUInt(offset + 0x2e);
            Defend = buf.Get2BytesUInt(offset + 0x30);
            Speed  = buf[offset + 0x36] & 0xff;
            Lingli = buf[offset + 0x37] & 0xff;
            Luck   = buf[offset + 0x38] & 0xff;

            CurrentExp = buf.Get2BytesUInt(offset + 0x32);

            LevelupChain = Context.LibData.GetLevelupChain(Index);

            int tmp;

            tmp = buf[offset + 0x1e] & 0xff;
            if (tmp != 0)
            {
                Equipments[0] = Context.LibData.GetGoods(6, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x1f] & 0xff;
            if (tmp != 0)
            {
                Equipments[1] = Context.LibData.GetGoods(6, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x1b] & 0xff;
            if (tmp != 0)
            {
                Equipments[2] = Context.LibData.GetGoods(5, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x1d] & 0xff;
            if (tmp != 0)
            {
                Equipments[3] = Context.LibData.GetGoods(3, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x1c] & 0xff;
            if (tmp != 0)
            {
                Equipments[4] = Context.LibData.GetGoods(7, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x19] & 0xff;
            if (tmp != 0)
            {
                Equipments[5] = Context.LibData.GetGoods(2, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x1a] & 0xff;
            if (tmp != 0)
            {
                Equipments[6] = Context.LibData.GetGoods(4, tmp) as GoodsEquipment;
            }

            tmp = buf[offset + 0x18] & 0xff;
            if (tmp != 0)
            {
                Equipments[7] = Context.LibData.GetGoods(1, tmp) as GoodsEquipment;
            }
        }