public static void syncDatabase(MessageIn msg) { // It is safe to perform the following updates in a transaction //dal::PerformTransaction transaction(storage.database()); while(msg.getUnreadLength()>0) { int msgType=msg.readInt8(); switch((Sync)msgType) { case Sync.SYNC_CHARACTER_POINTS: { Logger.Write(LogLevel.Debug, "received SYNC_CHARACTER_POINTS"); int charId=msg.readInt32(); int charPoints=msg.readInt32(); int corrPoints=msg.readInt32(); Program.storage.updateCharacterPoints(charId, charPoints, corrPoints); break; } case Sync.SYNC_CHARACTER_ATTRIBUTE: { Logger.Write(LogLevel.Debug, "received SYNC_CHARACTER_ATTRIBUTE"); int charId=msg.readInt32(); int attrId=msg.readInt32(); double @base=msg.readDouble(); double mod=msg.readDouble(); Program.storage.updateAttribute(charId, (uint)attrId, @base, mod); break; } case Sync.SYNC_CHARACTER_SKILL: { Logger.Write(LogLevel.Debug, "received SYNC_CHARACTER_SKILL"); int charId=msg.readInt32(); int skillId=msg.readInt8(); int skillValue=msg.readInt32(); Program.storage.updateExperience(charId, skillId, skillValue); break; } case Sync.SYNC_ONLINE_STATUS: { Logger.Write(LogLevel.Debug, "received SYNC_ONLINE_STATUS"); int charId=msg.readInt32(); bool online=(msg.readInt8()==1); Program.storage.setOnlineStatus(charId, online); break; } } } //transaction.commit(); }
// /** Sets the value of a base attribute of the character. */ // void setAttribute(unsigned int id, double value) // { mAttributes[id].base = value; } // // void setModAttribute(unsigned int id, double value) // { mAttributes[id].modified = value; } public void deserializeCharacterData(MessageIn msg) { // general character properties setAccountLevel(msg.readInt8()); setGender((BeingGender)msg.readInt8()); setHairStyle(msg.readInt8()); setHairColor(msg.readInt8()); setLevel(msg.readInt16()); setCharacterPoints(msg.readInt16()); setCorrectionPoints(msg.readInt16()); // character attributes uint attrSize=(uint)msg.readInt16(); for(uint i = 0;i < attrSize;++i) { uint id=(uint)msg.readInt16(); double @base=msg.readDouble(), mod=msg.readDouble(); setAttribute(id, @base); setModAttribute(id, mod); } // character skills int skillSize=msg.readInt16(); for(int i = 0;i < skillSize;++i) { int skill=msg.readInt16(); int level=msg.readInt32(); setExperience(skill, level); } // status effects currently affecting the character int statusSize=msg.readInt16(); for(int i = 0;i < statusSize;i++) { int status=msg.readInt16(); int time=msg.readInt16(); applyStatusEffect(status, time); } // location setMapId(msg.readInt16()); Point temporaryPoint=new Point(); temporaryPoint.x=msg.readInt16(); temporaryPoint.y=msg.readInt16(); setPosition(temporaryPoint); // kill count int killSize=msg.readInt16(); for(int i = 0;i < killSize;i++) { int monsterId=msg.readInt16(); int kills=msg.readInt32(); setKillCount(monsterId, kills); } // character specials int specialSize=msg.readInt16(); clearSpecials(); for(int i = 0;i < specialSize;i++) { giveSpecial(msg.readInt32()); } Possessions poss=getPossessions(); Dictionary< uint, EquipmentItem > equipData=new Dictionary<uint, EquipmentItem>(); int equipSlotsSize=msg.readInt16(); uint eqSlot; EquipmentItem equipItem=new EquipmentItem(); for(int j = 0;j < equipSlotsSize;++j) { eqSlot=(uint)msg.readInt16(); equipItem.itemId=(uint)msg.readInt16(); equipItem.itemInstance=(uint)msg.readInt16(); equipData.Add(eqSlot, equipItem); } poss.setEquipment(equipData); // Loads inventory - must be last because size isn't transmitted Dictionary<uint, InventoryItem > inventoryData=new Dictionary<uint, InventoryItem>(); while(msg.getUnreadLength()>0) { InventoryItem i=new InventoryItem(); int slotId=msg.readInt16(); i.itemId=(uint)msg.readInt16(); i.amount=(uint)msg.readInt16(); inventoryData.Add((uint)slotId, i); } poss.setInventory(inventoryData); }