Commit 05d24db3 authored by kenan's avatar kenan

卡片排序

parent 699bccdb
...@@ -255,10 +255,6 @@ public class DeckInfo { ...@@ -255,10 +255,6 @@ public class DeckInfo {
} }
} }
private boolean comp(Card c1, Card c2) {
return CardSort.ASC.compare(c1, c2) < 0;
}
public void sortAll() { public void sortAll() {
sortMain(); sortMain();
sortExtra(); sortExtra();
...@@ -281,9 +277,9 @@ public class DeckInfo { ...@@ -281,9 +277,9 @@ public class DeckInfo {
int len = cards.size(); int len = cards.size();
for (int i = 0; i < len - 1; i++) { for (int i = 0; i < len - 1; i++) {
for (int j = 0; j < len - 1 - i; j++) { for (int j = 0; j < len - 1 - i; j++) {
Card d1 = cards.get(j); Card c1 = cards.get(j);
Card d2 = cards.get(j + 1); Card c2 = cards.get(j + 1);
if (comp(d1, d2)) { if (CardSort.FULL_ASC.compare(c1, c2) > 0) {
Collections.swap(cards, j, j + 1); Collections.swap(cards, j, j + 1);
} }
} }
......
...@@ -162,7 +162,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement ...@@ -162,7 +162,7 @@ public class DeckAdapater extends RecyclerView.Adapter<DeckViewHolder> implement
if (d1.getType() == d2.getType()) { if (d1.getType() == d2.getType()) {
Card c1 = d1.getCardInfo(); Card c1 = d1.getCardInfo();
Card c2 = d2.getCardInfo(); Card c2 = d2.getCardInfo();
return CardSort.ASC.compare(c1, c2) < 0; return CardSort.FULL_ASC.compare(c1, c2) > 0;
} }
return (d1.getType().ordinal() - d2.getType().ordinal()) > 0; return (d1.getType().ordinal() - d2.getType().ordinal()) > 0;
} }
......
...@@ -7,15 +7,52 @@ import ocgcore.enums.CardType; ...@@ -7,15 +7,52 @@ import ocgcore.enums.CardType;
public class CardSort implements Comparator<Card> { public class CardSort implements Comparator<Card> {
public static final CardSort ASC = new CardSort(); public static final CardSort ASC = new CardSort(false);
public static final CardSort FULL_ASC = new CardSort(true);
public CardSort() { private final boolean full;
private CardSort(boolean full) {
this.full = full;
} }
private int comp(long l1, long l2) { private int comp(long l1, long l2) {
return Long.compare(l1, l2); return Long.compare(l1, l2);
} }
private static final int SORT_OTHER = 999;
private static final int SORT_MONSTER = 1;
private static final int SORT_LINK = 2;
private static final int SORT_SPELL = 3;
private static final int SORT_TRAP = 4;
private static final int SORT_FUSION = 10;
private static final int SORT_SYNCHRO = 11;
private static final int SORT_XYZ = 12;
private int getSortKey1(Card c1){
if (c1.isType(CardType.Link)) {
return SORT_LINK;
} else if (c1.isType(CardType.Monster)) {
return SORT_MONSTER;
} else if (c1.isType(CardType.Spell)) {
return SORT_SPELL;
} else if (c1.isType(CardType.Trap)) {
return SORT_TRAP;
} else{
return SORT_OTHER;
}
}
private int getSortKey2(Card c1){
if (c1.isType(CardType.Fusion)) {
return SORT_FUSION;
} else if (c1.isType(CardType.Synchro)) {
return SORT_SYNCHRO;
} else if (c1.isType(CardType.Xyz)) {
return SORT_XYZ;
} else{
return SORT_OTHER;
}
}
@Override @Override
public int compare(Card c1, Card c2) { public int compare(Card c1, Card c2) {
if (c1 == null) { if (c1 == null) {
...@@ -24,121 +61,72 @@ public class CardSort implements Comparator<Card> { ...@@ -24,121 +61,72 @@ public class CardSort implements Comparator<Card> {
if (c2 == null) { if (c2 == null) {
return 1; return 1;
} }
// boolean log = c1.Code == 74003290||c2.Code == 74003290; //同名卡
if (c1.isType(CardType.Spell)) { if(c1.isAlias(c2)){
if (c2.isType(CardType.Monster)) { return comp(c1.Code, c2.Code);
//怪兽在前面 }
return -1; int sortKey1 = getSortKey1(c1);
} else if (c2.isType(CardType.Trap)) { int sortKey2 = getSortKey1(c2);
//陷阱在前面 if(sortKey1 != sortKey2){
return 1; return Integer.compare(sortKey1, sortKey2);
}
if(sortKey1 == SORT_SPELL || sortKey2 == SORT_TRAP){
long type1, type2;
if(sortKey1 == SORT_SPELL){
type1 = c1.Type ^ CardType.Spell.value();
type2 = c2.Type ^ CardType.Spell.value();
} else {
type1 = c1.Type ^ CardType.Trap.value();
type2 = c2.Type ^ CardType.Trap.value();
} }
long type1 = c1.Type ^ CardType.Spell.value();
long type2 = c2.Type ^ CardType.Spell.value();
int rs = comp(type1, type2); int rs = comp(type1, type2);
if (rs == 0) { if (rs == 0) {
return comp(c1.Code, c2.Code); return comp(c1.Code, c2.Code);
} else { } else {
return rs; return rs;
} }
} else if (c1.isType(CardType.Trap)) { } else if(sortKey1 == SORT_OTHER){
//怪兽魔法在前面 return comp(c1.Code, c2.Code);
if (c2.isType(CardType.Monster) || c2.isType(CardType.Spell)) { } else if(sortKey1 == SORT_LINK){
return -1; //高星的在前面
return Integer.compare(c2.getStar(), c1.getStar());
} else {
//monster
if(full) {
sortKey1 = getSortKey2(c1);
sortKey2 = getSortKey2(c2);
if (sortKey1 != sortKey2) {
//需要反转
return Integer.compare(sortKey1, sortKey2);
}
} }
long type1 = c1.Type ^ CardType.Trap.value(); //高星的在前面
long type2 = c2.Type ^ CardType.Trap.value(); int rs = comp(c2.getStar(), c1.getStar());
int rs = comp(type1, type2); if (rs != 0) {
if (rs == 0) {
return comp(c1.Code, c2.Code);
} else {
return rs; return rs;
} }
} else if (c1.isType(CardType.Monster)) { //高攻击的在前面
//魔法陷阱在后面 rs = comp(c2.Attack, c1.Attack);
if (c2.isType(CardType.Spell) || c2.isType(CardType.Trap)) { if (rs != 0) {
//怪兽在前面 return rs;
return 1; }
//高防御的在前面
rs = comp(c2.Defense, c1.Defense);
if (rs != 0) {
return rs;
} }
if (isSameType(c1, c2, CardType.Fusion)
|| isSameType(c1, c2, CardType.Synchro)
|| isSameType(c1, c2, CardType.Xyz)
|| isSameType(c1, c2, CardType.Link)
|| (!isSpecialType(c1) && !isSpecialType(c2))) {
int rs = comp(c1.getStar(), c2.getStar());
if (rs != 0) {
return rs;
}
rs = comp(c1.Attack, c2.Attack);
if (rs != 0) {
return rs;
}
rs = comp(c1.Defense, c2.Defense);
if (rs != 0) {
return rs;
}
rs = comp(c1.Attribute, c2.Attribute); rs = comp(c1.Attribute, c2.Attribute);
if (rs != 0) { if (rs != 0) {
return rs; return rs;
}
rs = comp(c1.Race, c2.Race);
if (rs != 0) {
return rs;
}
rs = comp(c1.Ot, c2.Ot);
if (rs != 0) {
return rs;
}
} }
else { rs = comp(c1.Race, c2.Race);
//超量,同调,融合 if (rs != 0) {
//Fusion,Synchro,Xyz,Link return rs;
//1 ,2 ,3 ,4 }
if (c1.isType(CardType.Xyz)) { rs = comp(c1.Ot, c2.Ot);
if (c2.isType(CardType.Synchro)) { if (rs != 0) {
return -1; return rs;
} else if (c2.isType(CardType.Fusion)) {
return -2;
} else if (c2.isType(CardType.Link)) {
return 1;
} else {
return 2;
}
}
else if (c1.isType(CardType.Synchro)) {
if (c2.isType(CardType.Fusion)) {
return -1;
} else if (c2.isType(CardType.Xyz)) {
return 1;
} else if (c2.isType(CardType.Link)) {
return 2;
} else {
return 3;
}
}
else if (c1.isType(CardType.Fusion)) {
if (c2.isType(CardType.Synchro)) {
return 1;
} else if (c2.isType(CardType.Xyz)) {
return 2;
} else if (c2.isType(CardType.Link)) {
return 3;
} else {
return 4;
}
}
else if (c1.isType(CardType.Link)) {
if (c2.isType(CardType.Xyz)) {
return -3;
} else if (c2.isType(CardType.Synchro)) {
return -2;
} else if (c2.isType(CardType.Fusion)) {
return -1;
} else {
return 1;
}
}
} }
} }
return comp(c1.Code, c2.Code); return comp(c1.Code, c2.Code);
......
...@@ -129,6 +129,10 @@ public class Card extends CardData implements Parcelable { ...@@ -129,6 +129,10 @@ public class Card extends CardData implements Parcelable {
return false; return false;
} }
public boolean isAlias(Card c){
return c.Code == this.Code || c.Alias == this.Code || c.Code == this.Alias;
}
@Override @Override
public String toString() { public String toString() {
return "Card{" + return "Card{" +
......
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