public void Serialize(BinaryWriter binaryWriter) { binaryWriter.Write(Type); binaryWriter.Write(Index); binaryWriter.Write(GetWalkingSpriteId()); binaryWriter.Write((int)Direction); binaryWriter.Write(GetStep()); binaryWriter.Write(PosInMap.X); binaryWriter.Write(PosInMap.Y); if (MagicChain != null) { binaryWriter.Write(true); MagicChain.Serialize(binaryWriter); } else { binaryWriter.Write(false); } binaryWriter.Write(Name); binaryWriter.Write(Level); binaryWriter.Write(MaxHP); binaryWriter.Write(HP); binaryWriter.Write(MaxMP); binaryWriter.Write(MP); binaryWriter.Write(Attack); binaryWriter.Write(Defend); binaryWriter.Write(Speed); binaryWriter.Write(Lingli); binaryWriter.Write(Luck); binaryWriter.Write(CurrentExp); for (int i = 0; i < 8; i++) { if (Equipments[i] == null) { binaryWriter.Write(0); binaryWriter.Write(0); } else { binaryWriter.Write(Equipments[i].Type); binaryWriter.Write(Equipments[i].Index); } } }
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; } }