Mercurial > wow > askmrrobot
comparison AskMrRobot-Serializer/AskMrRobot-Serializer.lua @ 112:57c6cac5143c v52
7.3 update, preparation for reading crucible.
| author | yellowfive |
|---|---|
| date | Mon, 28 Aug 2017 19:33:14 -0700 |
| parents | 5021d5125484 |
| children | 4cd98aa90d78 |
comparison
equal
deleted
inserted
replaced
| 111:2f78f6c96183 | 112:57c6cac5143c |
|---|---|
| 1 -- AskMrRobot-Serializer will serialize and communicate character data between users. | 1 -- AskMrRobot-Serializer will serialize and communicate character data between users. |
| 2 -- This is used primarily to associate character information to logs uploaded to askmrrobot.com. | 2 -- This is used primarily to associate character information to logs uploaded to askmrrobot.com. |
| 3 | 3 |
| 4 local MAJOR, MINOR = "AskMrRobot-Serializer", 51 | 4 local MAJOR, MINOR = "AskMrRobot-Serializer", 52 |
| 5 local Amr, oldminor = LibStub:NewLibrary(MAJOR, MINOR) | 5 local Amr, oldminor = LibStub:NewLibrary(MAJOR, MINOR) |
| 6 | 6 |
| 7 if not Amr then return end -- already loaded by something else | 7 if not Amr then return end -- already loaded by something else |
| 8 | 8 |
| 9 -- event and comm used for player snapshotting on entering combat | 9 -- event and comm used for player snapshotting on entering combat |
| 881 --ret.Talents[pos] = getTalents(pos) | 881 --ret.Talents[pos] = getTalents(pos) |
| 882 end | 882 end |
| 883 end | 883 end |
| 884 end | 884 end |
| 885 | 885 |
| 886 -- TODO: hopefully we can read artifact here when there is an API to get info when the artifact UI is not open | |
| 887 -- get artifact info | |
| 888 local function readArtifact() | |
| 889 | |
| 890 end | |
| 891 | |
| 892 -- get currently equipped items, store with currently active spec | 886 -- get currently equipped items, store with currently active spec |
| 893 local function readEquippedItems(ret) | 887 local function readEquippedItems(ret) |
| 894 local equippedItems = {}; | 888 local equippedItems = {}; |
| 895 for slotNum = 1, #Amr.SlotIds do | 889 for slotNum = 1, #Amr.SlotIds do |
| 896 local slotId = Amr.SlotIds[slotNum] | 890 local slotId = Amr.SlotIds[slotNum] |
| 945 | 939 |
| 946 ret.Specs = {} | 940 ret.Specs = {} |
| 947 ret.Talents = {} | 941 ret.Talents = {} |
| 948 readSpecs(ret) | 942 readSpecs(ret) |
| 949 | 943 |
| 950 ret.Artifacts = {} | 944 ret.Artifacts = {} |
| 951 readArtifact() | |
| 952 | 945 |
| 953 ret.Equipped = {} | 946 ret.Equipped = {} |
| 954 readEquippedItems(ret) | 947 readEquippedItems(ret) |
| 955 | 948 |
| 956 return ret | 949 return ret |
| 1047 | 1040 |
| 1048 table.insert(fields, table.concat(itemParts, "")) | 1041 table.insert(fields, table.concat(itemParts, "")) |
| 1049 end | 1042 end |
| 1050 end | 1043 end |
| 1051 | 1044 |
| 1045 local function serializeCrucibleInfo(fields, info, pos, prevPowerId) | |
| 1046 | |
| 1047 if not info.Powers or not info.Active then | |
| 1048 return prevPowerId | |
| 1049 end | |
| 1050 | |
| 1051 local parts = {} | |
| 1052 | |
| 1053 if pos < 4 then | |
| 1054 table.insert(parts, pos) | |
| 1055 else | |
| 1056 local relic = Amr.ParseItemLink(info.ItemLink) | |
| 1057 table.insert(parts, Amr.GetItemUniqueId(relic) or "0") | |
| 1058 end | |
| 1059 | |
| 1060 for i,powerId in ipairs(info.Powers) do | |
| 1061 table.insert(parts, (powerId - prevPowerId) .. "") | |
| 1062 prevPowerId = powerId | |
| 1063 end | |
| 1064 | |
| 1065 for i,active in ipairs(info.Active) do | |
| 1066 table.insert(parts, active and "1" or "0") | |
| 1067 end | |
| 1068 | |
| 1069 table.insert(fields, table.concat(parts, ",")) | |
| 1070 | |
| 1071 return prevPowerId | |
| 1072 end | |
| 1073 | |
| 1052 -- Serialize just the identity portion of a player (region/realm/name) in the same format used by the full serialization | 1074 -- Serialize just the identity portion of a player (region/realm/name) in the same format used by the full serialization |
| 1053 function Amr:SerializePlayerIdentity(data) | 1075 function Amr:SerializePlayerIdentity(data) |
| 1054 local fields = {} | 1076 local fields = {} |
| 1055 table.insert(fields, MINOR) | 1077 table.insert(fields, MINOR) |
| 1056 table.insert(fields, data.Region) | 1078 table.insert(fields, data.Region) |
| 1121 table.insert(fields, data.Specs[spec]) | 1143 table.insert(fields, data.Specs[spec]) |
| 1122 table.insert(fields, data.Talents[spec] or "") | 1144 table.insert(fields, data.Talents[spec] or "") |
| 1123 | 1145 |
| 1124 local powerids = {} | 1146 local powerids = {} |
| 1125 local powerranks = {} | 1147 local powerranks = {} |
| 1126 local reliclinks = {} | 1148 local reliclinks = {} |
| 1149 local crucibleinfos = {} | |
| 1127 | 1150 |
| 1128 local artifactInfo = data.Artifacts and data.Artifacts[spec] | 1151 local artifactInfo = data.Artifacts and data.Artifacts[spec] |
| 1129 if artifactInfo and artifactInfo.Powers then | 1152 if artifactInfo and artifactInfo.Powers then |
| 1130 for k, v in spairs(artifactInfo.Powers) do | 1153 for k, v in spairs(artifactInfo.Powers) do |
| 1131 table.insert(powerids, k) | 1154 table.insert(powerids, k) |
| 1136 for i, link in ipairs(artifactInfo.Relics) do | 1159 for i, link in ipairs(artifactInfo.Relics) do |
| 1137 local relic = Amr.ParseItemLink(link) | 1160 local relic = Amr.ParseItemLink(link) |
| 1138 table.insert(reliclinks, Amr.GetItemUniqueId(relic) or "") | 1161 table.insert(reliclinks, Amr.GetItemUniqueId(relic) or "") |
| 1139 end | 1162 end |
| 1140 end | 1163 end |
| 1164 if artifactInfo and artifactInfo.Crucible then | |
| 1165 local prevPowerId = 0 | |
| 1166 for i = 1,3 do | |
| 1167 local relicInfo = #artifactInfo.Crucible.Equipped >= i and artifactInfo.Crucible.Equipped[i] | |
| 1168 if relicInfo then | |
| 1169 prevPowerId = serializeCrucibleInfo(crucibleinfos, relicInfo, i, prevPowerId) | |
| 1170 end | |
| 1171 end | |
| 1172 for k,relicInfo in pairs(artifactInfo.Crucible.Inventory) do | |
| 1173 if relicInfo then | |
| 1174 prevPowerId = serializeCrucibleInfo(crucibleinfos, relicInfo, 4, prevPowerId) | |
| 1175 end | |
| 1176 end | |
| 1177 end | |
| 1141 | 1178 |
| 1142 table.insert(fields, toCompressedNumberList(powerids)) | 1179 table.insert(fields, toCompressedNumberList(powerids)) |
| 1143 table.insert(fields, table.concat(powerranks, ",")) | 1180 table.insert(fields, table.concat(powerranks, ",")) |
| 1144 table.insert(fields, table.concat(reliclinks, ",")) | 1181 table.insert(fields, table.concat(reliclinks, ",")) |
| 1182 table.insert(fields, table.concat(crucibleinfos, "/")) | |
| 1145 | 1183 |
| 1146 --table.insert(fields, toCompressedNumberList(data.Glyphs[spec])) | 1184 --table.insert(fields, toCompressedNumberList(data.Glyphs[spec])) |
| 1147 end | 1185 end |
| 1148 end | 1186 end |
| 1149 | 1187 |
