Commit 6ff05155 authored by feihuaduo's avatar feihuaduo

修复部分卡转为卡组码错误的问题

parent a30eff35
...@@ -197,6 +197,7 @@ public interface Constants { ...@@ -197,6 +197,7 @@ public interface Constants {
String SCHEME_HTTPS = "https"; String SCHEME_HTTPS = "https";
String SCHEME_APP = "ygo"; String SCHEME_APP = "ygo";
String URI_HOST = "deck"; String URI_HOST = "deck";
String URI_DECK = "deck";
String QUERY_YDK = "ydk"; String QUERY_YDK = "ydk";
String QUERY_NAME = "name"; String QUERY_NAME = "name";
...@@ -226,4 +227,47 @@ public interface Constants { ...@@ -226,4 +227,47 @@ public interface Constants {
String DEF_ENCODING = "utf-8"; String DEF_ENCODING = "utf-8";
String[] NUM_40_LIST={
"0"
,"1"
,"2"
,"3"
,"4"
,"5"
,"6"
,"7"
,"8"
,"9"
,"a"
,"b"
,"c"
,"d"
,"e"
,"f"
,"g"
,"h"
,"i"
,"j"
,"k"
,"l"
,"m"
,"n"
,"o"
,"p"
,"q"
,"r"
,"s"
,"t"
,"u"
,"v"
,"w"
,"x"
,"y"
,"z"
,"A"
,"B"
,"C"
,"D"
};
} }
...@@ -239,7 +239,7 @@ public class GameUriManager { ...@@ -239,7 +239,7 @@ public class GameUriManager {
// if (!Constants.URI_HOST.equalsIgnoreCase(host)) { // if (!Constants.URI_HOST.equalsIgnoreCase(host)) {
// return; // return;
// } // }
if (Constants.URI_HOST.equals(host)) { if (Constants.URI_DECK.equals(host)) {
String name = uri.getQueryParameter(QUERY_NAME); String name = uri.getQueryParameter(QUERY_NAME);
if (!TextUtils.isEmpty(name)) { if (!TextUtils.isEmpty(name)) {
doOpenPath(name); doOpenPath(name);
......
package cn.garymb.ygomobile.bean; package cn.garymb.ygomobile.bean;
import static cn.garymb.ygomobile.Constants.ARG_DECK; import static cn.garymb.ygomobile.Constants.ARG_DECK;
import static cn.garymb.ygomobile.Constants.NUM_40_LIST;
import static cn.garymb.ygomobile.Constants.QUERY_EXTRA; import static cn.garymb.ygomobile.Constants.QUERY_EXTRA;
import static cn.garymb.ygomobile.Constants.QUERY_EXTRA_ALL; import static cn.garymb.ygomobile.Constants.QUERY_EXTRA_ALL;
import static cn.garymb.ygomobile.Constants.QUERY_MAIN; import static cn.garymb.ygomobile.Constants.QUERY_MAIN;
...@@ -16,9 +17,11 @@ import android.net.Uri; ...@@ -16,9 +17,11 @@ import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import java.io.File; import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import cn.garymb.ygomobile.Constants; import cn.garymb.ygomobile.Constants;
...@@ -40,65 +43,7 @@ public class Deck implements Parcelable { ...@@ -40,65 +43,7 @@ public class Deck implements Parcelable {
private static final int YGO_PROTOCOL_1 = 1; private static final int YGO_PROTOCOL_1 = 1;
private static final String CARD_DIVIDE_ID = "_"; private static final String CARD_DIVIDE_ID = "_";
private static final String CARD_DIVIDE_NUM = "*"; private static final String CARD_DIVIDE_NUM = "*";
private static final String CARD_NUM_2 = "-";
private static final String CARD_NUM_3 = "!";
private static List<CardIdNum> cardIdNumList;
static {
cardIdNumList = new ArrayList<>();
cardIdNumList.add(new CardIdNum("10", "a"));
cardIdNumList.add(new CardIdNum("11", "b"));
cardIdNumList.add(new CardIdNum("12", "c"));
cardIdNumList.add(new CardIdNum("13", "d"));
cardIdNumList.add(new CardIdNum("14", "e"));
cardIdNumList.add(new CardIdNum("15", "f"));
cardIdNumList.add(new CardIdNum("16", "g"));
cardIdNumList.add(new CardIdNum("17", "h"));
cardIdNumList.add(new CardIdNum("18", "i"));
cardIdNumList.add(new CardIdNum("19", "j"));
cardIdNumList.add(new CardIdNum("20", "k"));
cardIdNumList.add(new CardIdNum("21", "l"));
cardIdNumList.add(new CardIdNum("22", "m"));
cardIdNumList.add(new CardIdNum("23", "n"));
cardIdNumList.add(new CardIdNum("24", "o"));
cardIdNumList.add(new CardIdNum("25", "p"));
cardIdNumList.add(new CardIdNum("26", "q"));
cardIdNumList.add(new CardIdNum("27", "r"));
cardIdNumList.add(new CardIdNum("28", "s"));
cardIdNumList.add(new CardIdNum("29", "t"));
cardIdNumList.add(new CardIdNum("30", "u"));
cardIdNumList.add(new CardIdNum("31", "v"));
cardIdNumList.add(new CardIdNum("32", "w"));
cardIdNumList.add(new CardIdNum("33", "x"));
cardIdNumList.add(new CardIdNum("34", "y"));
cardIdNumList.add(new CardIdNum("35", "z"));
cardIdNumList.add(new CardIdNum("36", "A"));
cardIdNumList.add(new CardIdNum("37", "B"));
cardIdNumList.add(new CardIdNum("38", "C"));
cardIdNumList.add(new CardIdNum("39", "D"));
cardIdNumList.add(new CardIdNum("40", "E"));
cardIdNumList.add(new CardIdNum("41", "F"));
cardIdNumList.add(new CardIdNum("42", "G"));
cardIdNumList.add(new CardIdNum("43", "H"));
cardIdNumList.add(new CardIdNum("44", "I"));
cardIdNumList.add(new CardIdNum("45", "J"));
cardIdNumList.add(new CardIdNum("46", "K"));
cardIdNumList.add(new CardIdNum("47", "L"));
cardIdNumList.add(new CardIdNum("48", "M"));
cardIdNumList.add(new CardIdNum("49", "N"));
cardIdNumList.add(new CardIdNum("50", "O"));
cardIdNumList.add(new CardIdNum("51", "P"));
cardIdNumList.add(new CardIdNum("52", "Q"));
cardIdNumList.add(new CardIdNum("53", "R"));
cardIdNumList.add(new CardIdNum("54", "S"));
cardIdNumList.add(new CardIdNum("55", "T"));
cardIdNumList.add(new CardIdNum("56", "U"));
cardIdNumList.add(new CardIdNum("57", "V"));
cardIdNumList.add(new CardIdNum("58", "W"));
cardIdNumList.add(new CardIdNum("59", "X"));
cardIdNumList.add(new CardIdNum("60", "Y"));
cardIdNumList.add(new CardIdNum("61", "Z"));
}
private final ArrayList<Integer> mainlist; private final ArrayList<Integer> mainlist;
private final ArrayList<Integer> extraList; private final ArrayList<Integer> extraList;
...@@ -123,82 +68,114 @@ public class Deck implements Parcelable { ...@@ -123,82 +68,114 @@ public class Deck implements Parcelable {
} catch (Exception exception) { } catch (Exception exception) {
version = YGO_PROTOCOL_0; version = YGO_PROTOCOL_0;
} }
String main=null, extra=null, side=null; String main = null, extra = null, side = null;
List<String> mList = new ArrayList<>();
List<String> eList = new ArrayList<>();
List<String> sList = new ArrayList<>();
switch (version) { switch (version) {
case YGO_PROTOCOL_0: case YGO_PROTOCOL_0:
try { try {
main = uri.getQueryParameter(QUERY_MAIN_ALL); main = uri.getQueryParameter(QUERY_MAIN_ALL);
}catch (Exception e){} String[] mains = main.split(CARD_DIVIDE_ID);
mList.addAll(Arrays.asList(mains));
} catch (Exception ignored) {
}
try { try {
extra = uri.getQueryParameter(QUERY_EXTRA_ALL); extra = uri.getQueryParameter(QUERY_EXTRA_ALL);
}catch (Exception e){} String[] extras = extra.split(CARD_DIVIDE_ID);
eList.addAll(Arrays.asList(extras));
} catch (Exception ignored) {
}
try { try {
side = uri.getQueryParameter(QUERY_SIDE_ALL); side = uri.getQueryParameter(QUERY_SIDE_ALL);
}catch (Exception e){} String[] sides = side.split(CARD_DIVIDE_ID);
sList.addAll(Arrays.asList(sides));
} catch (Exception ignored) {
}
break; break;
case YGO_PROTOCOL_1: case YGO_PROTOCOL_1:
try { try {
main = uri.getQueryParameter(QUERY_MAIN); main = uri.getQueryParameter(QUERY_MAIN);
}catch (Exception e){} for (int i = 0; i < main.length() / 6; i++)
mList.add(main.substring(i * 6, i * 6 + 6));
} catch (Exception e) {
}
try { try {
extra = uri.getQueryParameter(QUERY_EXTRA); extra = uri.getQueryParameter(QUERY_EXTRA);
}catch (Exception e){} for (int i = 0; i < extra.length() / 6; i++)
eList.add(extra.substring(i * 6, i * 6 + 6));
} catch (Exception e) {
}
try { try {
side = uri.getQueryParameter(QUERY_SIDE); side = uri.getQueryParameter(QUERY_SIDE);
}catch (Exception e){} for (int i = 0; i < side.length() / 6; i++)
sList.add(side.substring(i * 6, i * 6 + 6));
} catch (Exception e) {
}
break; break;
default: default:
try { try {
main = uri.getQueryParameter(QUERY_MAIN_ALL); main = uri.getQueryParameter(QUERY_MAIN_ALL);
}catch (Exception e){} String[] mains = main.split(CARD_DIVIDE_ID);
mList.addAll(Arrays.asList(mains));
} catch (Exception ignored) {
}
try { try {
extra = uri.getQueryParameter(QUERY_EXTRA_ALL); extra = uri.getQueryParameter(QUERY_EXTRA_ALL);
}catch (Exception e){} String[] extras = extra.split(CARD_DIVIDE_ID);
eList.addAll(Arrays.asList(extras));
} catch (Exception ignored) {
}
try { try {
side = uri.getQueryParameter(QUERY_SIDE_ALL); side = uri.getQueryParameter(QUERY_SIDE_ALL);
}catch (Exception e){} String[] sides = side.split(CARD_DIVIDE_ID);
sList.addAll(Arrays.asList(sides));
} catch (Exception ignored) {
}
} }
if (!TextUtils.isEmpty(main)) { for (String m : mList) {
String[] mains = main.split(CARD_DIVIDE_ID); int[] idNum = toIdAndNum(m, version);
for (String m : mains) { if (idNum[0] > 0) {
int[] idNum = toIdAndNum(m, version); for (int i = 0; i < idNum[1]; i++) {
if (idNum[0] > 0) { mainlist.add(idNum[0]);
for (int i = 0; i < idNum[1]; i++) {
mainlist.add(idNum[0]);
}
} }
} }
} }
if (!TextUtils.isEmpty(extra)) {
String[] extras = extra.split(CARD_DIVIDE_ID);
for (String m : extras) { for (String m : eList) {
int[] idNum = toIdAndNum(m, version); int[] idNum = toIdAndNum(m, version);
if (idNum[0] > 0) { if (idNum[0] > 0) {
for (int i = 0; i < idNum[1]; i++) { for (int i = 0; i < idNum[1]; i++) {
extraList.add(idNum[0]); extraList.add(idNum[0]);
}
} }
} }
} }
if (!TextUtils.isEmpty(side)) {
String[] sides = side.split(CARD_DIVIDE_ID);
for (String m : sides) { for (String m : sList) {
int[] idNum = toIdAndNum(m, version); int[] idNum = toIdAndNum(m, version);
if (idNum[0] > 0) { if (idNum[0] > 0) {
for (int i = 0; i < idNum[1]; i++) { for (int i = 0; i < idNum[1]; i++) {
sideList.add(idNum[0]); sideList.add(idNum[0]);
}
} }
} }
} }
} }
public Deck(Uri uri) { public Deck(Uri uri) {
...@@ -228,13 +205,13 @@ public class Deck implements Parcelable { ...@@ -228,13 +205,13 @@ public class Deck implements Parcelable {
switch (protocol) { switch (protocol) {
case YGO_PROTOCOL_0: case YGO_PROTOCOL_0:
idNum=toIdAndNum0(m); idNum = toIdAndNum0(m);
break; break;
case YGO_PROTOCOL_1: case YGO_PROTOCOL_1:
idNum=toIdAndNum1(m); idNum = toIdAndNum1(m);
break; break;
default: default:
idNum=toIdAndNum0(m); idNum = toIdAndNum0(m);
break; break;
} }
return idNum; return idNum;
...@@ -243,16 +220,8 @@ public class Deck implements Parcelable { ...@@ -243,16 +220,8 @@ public class Deck implements Parcelable {
private int[] toIdAndNum1(String m) { private int[] toIdAndNum1(String m) {
//元素0为卡密,元素1为卡片数量 //元素0为卡密,元素1为卡片数量
int[] idNum = {0, 1}; int[] idNum = {0, 1};
if (m.contains(CARD_NUM_2)) { idNum[0] = toId(m.substring(0, m.length() - 1));
idNum[0] = toId(m.substring(0, m.length() - 1)); idNum[1] = Integer.parseInt(m.substring(m.length() - 1));
idNum[1] = 2;
} else if (m.contains(CARD_NUM_3)) {
idNum[0] = toId(m.substring(0, m.length() - 1));
idNum[1] = 3;
} else {
idNum[0] = toId(m);
}
return idNum; return idNum;
} }
...@@ -304,9 +273,9 @@ public class Deck implements Parcelable { ...@@ -304,9 +273,9 @@ public class Deck implements Parcelable {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
for (int i = 0; i < ids.size(); i++) { for (int i = 0; i < ids.size(); i++) {
Integer id = ids.get(i); Integer id = ids.get(i);
if (i > 0) { // if (i > 0) {
builder.append(CARD_DIVIDE_ID); // builder.append(CARD_DIVIDE_ID);
} // }
if (id > 0) { if (id > 0) {
//如果需要使用十六进制码: //如果需要使用十六进制码:
builder.append(compressedId(id)); builder.append(compressedId(id));
...@@ -330,91 +299,53 @@ public class Deck implements Parcelable { ...@@ -330,91 +299,53 @@ public class Deck implements Parcelable {
} }
i++; i++;
} }
//如果有同名卡 tNum = Math.min(3, tNum);
if (tNum > 1) { builder.append(tNum);
if (tNum == 2) { } else {
builder.append(CARD_NUM_2); builder.append(1);
} else {
builder.append(CARD_NUM_3);
}
}
} }
} }
} }
return builder.toString(); return builder.toString();
} }
//压缩卡密,目前直接转换为16进制 //压缩卡密,目前直接转换为40进制
private String compressedId(int id) { private String compressedId(int id) {
StringBuilder compressedId1 = new StringBuilder(); StringBuilder compressedId1 = new StringBuilder();
StringBuilder compressedId2 = new StringBuilder();
String ids = id + "";
// while (ids.startsWith("0")) {
// ids = ids.substring(1);
// }
int lenght = ids.length();
int n=lenght / 2;
if (lenght%2!=0)
n++;
for (int i = 0; i <n; i++) {
int start = i * 2;
int end = Math.min(start + 2, lenght);
compressedId1.append(getCardIdCompressedId(ids.substring(start, end)));
}
int currentPosition = 0; while (id > 40) {
while (currentPosition < lenght) { compressedId1.insert(0, NUM_40_LIST[id % 40]);
int start = currentPosition; id /= 40;
int end = Math.min(start + 2, lenght);
String message = ids.substring(start, end);
String result = getCardIdCompressedId(message);
if (message.equals(result)) {
compressedId2.append(ids.charAt(start));
currentPosition++;
} else {
compressedId2.append(result);
currentPosition = currentPosition + 2;
}
} }
compressedId1.insert(0, NUM_40_LIST[id]);
if (compressedId1.length() < 5)
return compressedId2.length() < compressedId1.length() ? compressedId2.toString() : compressedId1.toString(); for (int i = compressedId1.length(); i < 5; i++)
compressedId1.insert(0, "0");
return compressedId1.toString();
} }
private String getCardIdCompressedId(String idNum) {
for (CardIdNum cardIdNum : cardIdNumList) {
if (cardIdNum.getCardIdNum().equals(idNum)) {
return cardIdNum.getCardIdNumCompressed();
}
}
return idNum;
}
private String getCardIdUnCompressedId(String compressedNum) { private int getCardIdUnCompressedId(String compressedNum) {
for (CardIdNum cardIdNum : cardIdNumList) { for (int i = 0; i < NUM_40_LIST.length; i++) {
if (cardIdNum.getCardIdNumCompressed().equals(compressedNum)) { if (compressedNum.equals(NUM_40_LIST[i]))
return cardIdNum.getCardIdNum(); return i;
}
} }
return compressedNum; return 0;
} }
//解析卡密,目前直接16进制转换为10进制 //解析卡密,目前直接16进制转换为10进制
private int unId(String id) { private int unId(String id) {
StringBuilder compressedId = new StringBuilder(); int num = 0;
String[] sList = id.split(""); id = id.trim();
for (String s : sList) String[] sList = new String[id.length()];
compressedId.append(getCardIdUnCompressedId(s)); for (int i = 0; i < id.length(); i++) {
int cardId; sList[i] = id.charAt(i) + "";
try {
cardId = Integer.parseInt(compressedId.toString());
} catch (Exception e) {
cardId = 0;
} }
return cardId; for (int i = sList.length - 1; i >= 0; i--)
num += (getCardIdUnCompressedId(sList[i]) * Math.pow(40, sList.length - 1 - i));
// Log.e("DeckUU",(getCardIdUnCompressedId(sList[0]) * Math.pow(40, sList.length-1)+" "+sList.length+" num"+num));
return num;
} }
public String getName() { public String getName() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment