Commit d7b7a81d authored by qq247321453's avatar qq247321453

异图同名卡

parent 3ebc0037
......@@ -62,7 +62,7 @@ public class CardSort implements Comparator<Card> {
return 1;
}
//同名卡
if(c1.isAlias(c2)){
if(c1.getCode() == c2.getCode()){
return comp(c1.Code, c2.Code);
}
int sortKey1 = getSortKey1(c1);
......
......@@ -26,16 +26,16 @@ import java.util.zip.ZipInputStream;
import cn.garymb.ygomobile.App;
import cn.garymb.ygomobile.AppsSettings;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.utils.IOUtils;
import ocgcore.data.Card;
import ocgcore.enums.CardAttribute;
import ocgcore.enums.CardOt;
public class CardManager {
private static int cdbNum = 0;
private final SparseArray<Card> cardDataHashMap = new SparseArray<>();
private String dbDir, exDbPath;
private static final String TAG = IrrlichtBridge.TAG;
/**
* @see DataManager#getCardManager()
......@@ -138,39 +138,60 @@ public class CardManager {
public void loadCards() {
cardDataHashMap.clear();
int count = readAllCards(AppsSettings.get().getDataBaseFile(), cardDataHashMap);
Log.i("Irrlicht", "load defualt cdb:" + count);
if (TextUtils.isEmpty(exDbPath))
return;
if (AppsSettings.get().isReadExpansions()) {
File dir = new File(exDbPath);
if (dir.exists()) {
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File file = new File(dir, name);
return file.isFile() && ((name.endsWith(".cdb") || (name.endsWith(".zip") || name.endsWith(".ypk"))));
}
});
//读取全部卡片
if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".cdb")) {
count = readAllCards(file, cardDataHashMap);
} else if (file.getName().endsWith(".zip") || file.getName().endsWith(".ypk")) {
Log.e("CardManager", "读取压缩包");
try {
for (File file1 : readZipCdb(file.getAbsolutePath())) {
count = readAllCards(file1, cardDataHashMap);
Log.i(TAG, "load defualt cdb:" + count);
if (!TextUtils.isEmpty(exDbPath)) {
if (AppsSettings.get().isReadExpansions()) {
File dir = new File(exDbPath);
if (dir.exists()) {
File[] files = dir.listFiles(new FilenameFilter() {
@Override
public boolean accept(File dir, String name) {
File file = new File(dir, name);
return file.isFile() && ((name.endsWith(".cdb") || (name.endsWith(".zip") || name.endsWith(".ypk"))));
}
});
//读取全部卡片
if (files != null) {
for (File file : files) {
if (file.getName().endsWith(".cdb")) {
count = readAllCards(file, cardDataHashMap);
} else if (file.getName().endsWith(".zip") || file.getName().endsWith(".ypk")) {
Log.e("CardManager", "读取压缩包");
try {
for (File file1 : readZipCdb(file.getAbsolutePath())) {
count = readAllCards(file1, cardDataHashMap);
}
} catch (IOException e) {
Log.e("CardManager", "读取压缩包错误" + e);
}
} catch (IOException e) {
Log.e("CardManager", "读取压缩包错误" + e);
}
Log.i(TAG, "load " + count + " cdb:" + file);
}
Log.i("Irrlicht", "load " + count + " cdb:" + file);
}
}
}
}
buildAliasCards();
}
private void buildAliasCards() {
int N = getCount();
for (int i = 0; i < N; i++) {
Card c = cardDataHashMap.valueAt(i);
if(c.Alias == 0){
continue;
}
//规则同名,或者多图同名
Card alias = getCard(c.Alias);
if (alias != null) {
if (c.isSame(alias)) {
//多图同名,它们属性必定是一致
c.setRealCode(alias.Code);
} else if(Math.abs(c.Alias - c.Code) <= 10){
Log.w(TAG, c.Name + ":" + c.Code + " is same card "+c.Alias);
}
}
}
}
@WorkerThread
......@@ -215,7 +236,7 @@ public class CardManager {
}
} catch (Throwable e) {
e.printStackTrace();
Log.e("Irrlicht", "read cards " + file, e);
Log.e(TAG, "read cards " + file, e);
} finally {
IOUtils.close(reader);
IOUtils.close(db);
......
......@@ -3,6 +3,7 @@ package ocgcore.data;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import androidx.annotation.NonNull;
......@@ -24,6 +25,8 @@ public class Card extends CardData implements Parcelable {
public String Name;
public String Desc;
public int RealCode;
public Card() {
}
......@@ -32,6 +35,7 @@ public class Card extends CardData implements Parcelable {
if (card != null) {
this.Name = card.Name;
this.Desc = card.Desc;
this.RealCode = card.RealCode;
}
}
......@@ -62,6 +66,7 @@ public class Card extends CardData implements Parcelable {
super(in);
this.Name = in.readString();
this.Desc = in.readString();
this.RealCode = in.readInt();
}
public static boolean isType(long Type, CardType type) {
......@@ -81,6 +86,18 @@ public class Card extends CardData implements Parcelable {
return this;
}
@Override
public int getCode() {
if(RealCode > 0){
return RealCode;
}
return Code;//super.getCode();
}
public void setRealCode(int realCode) {
RealCode = realCode;
}
public int getStar() {
return (Level & 0xff);
}
......@@ -135,10 +152,6 @@ public class Card extends CardData implements Parcelable {
return false;
}
public boolean isAlias(Card c){
return c.Code == this.Code || c.Alias == this.Code || c.Code == this.Alias;
}
public boolean containsName(String key){
return Name != null && Name.contains(key);
}
......@@ -147,6 +160,16 @@ public class Card extends CardData implements Parcelable {
return Desc != null && Desc.contains(key);
}
/**
* 同样一张卡,不同卡图,它们属性应该是一样的
*/
public boolean isSame(Card c){
if(c.Code == this.Code || c.Alias == this.Code || c.Code == this.Alias) {
return TextUtils.equals(c.Name, this.Name) && c.Type == this.Type && c.Ot == this.Ot;
}
return false;
}
@NonNull
@Override
public String toString() {
......@@ -177,5 +200,6 @@ public class Card extends CardData implements Parcelable {
super.writeToParcel(dest, flags);
dest.writeString(this.Name);
dest.writeString(this.Desc);
dest.writeInt(this.RealCode);
}
}
......@@ -102,6 +102,7 @@ public class CardData implements Parcelable {
* 同卡,不同卡图
*/
public int getCode(){
//TODO 暂时的兼容做法
if (Alias > 0 && Math.abs(Alias - Code) <= 10) {
return Alias;
} else {
......
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