Rename and clean up MapleStorageInventory
This commit is contained in:
@@ -274,7 +274,7 @@ public class Storage {
|
||||
public void arrangeItems(Client c) {
|
||||
lock.lock();
|
||||
try {
|
||||
MapleStorageInventory msi = new MapleStorageInventory(c, items);
|
||||
StorageInventory msi = new StorageInventory(c, items);
|
||||
msi.mergeItems();
|
||||
items = msi.sortItems();
|
||||
|
||||
|
||||
@@ -28,161 +28,19 @@ import constants.inventory.ItemConstants;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author RonanLana
|
||||
*/
|
||||
|
||||
class PairedQuicksort {
|
||||
private int i = 0;
|
||||
private int j = 0;
|
||||
private final ArrayList<Integer> intersect;
|
||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||
|
||||
private void PartitionByItemId(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (x.getItemId() > A.get(i).getItemId()) i++;
|
||||
while (x.getItemId() < A.get(j).getItemId()) j--;
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByName(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(i).getItemId())) > 0) i++;
|
||||
while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(j).getItemId())) < 0) j--;
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByQuantity(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (x.getQuantity() > A.get(i).getQuantity()) i++;
|
||||
while (x.getQuantity() < A.get(j).getQuantity()) j--;
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByLevel(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Equip x, w, eqpI, eqpJ;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = (Equip)(A.get((i + j) / 2));
|
||||
|
||||
do {
|
||||
eqpI = (Equip)A.get(i);
|
||||
eqpJ = (Equip)A.get(j);
|
||||
|
||||
while (x.getLevel() > eqpI.getLevel()) i++;
|
||||
while (x.getLevel() < eqpJ.getLevel()) j--;
|
||||
|
||||
if (i <= j) {
|
||||
w = (Equip)A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
void MapleQuicksort(int Esq, int Dir, ArrayList<Item> A, int sort) {
|
||||
switch(sort) {
|
||||
case 3:
|
||||
PartitionByLevel(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PartitionByName(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PartitionByQuantity(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
default:
|
||||
PartitionByItemId(Esq, Dir, A);
|
||||
}
|
||||
|
||||
|
||||
if (Esq < j) MapleQuicksort(Esq, j, A, sort);
|
||||
if (i < Dir) MapleQuicksort(i, Dir, A, sort);
|
||||
}
|
||||
|
||||
public PairedQuicksort(ArrayList<Item> A, int primarySort, int secondarySort) {
|
||||
intersect = new ArrayList<>();
|
||||
|
||||
if(A.size() > 0) MapleQuicksort(0, A.size() - 1, A, primarySort);
|
||||
|
||||
intersect.add(0);
|
||||
for(int ind = 1; ind < A.size(); ind++) {
|
||||
if(A.get(ind - 1).getItemId() != A.get(ind).getItemId()) {
|
||||
intersect.add(ind);
|
||||
}
|
||||
}
|
||||
intersect.add(A.size());
|
||||
|
||||
for(int ind = 0; ind < intersect.size() - 1; ind++) {
|
||||
if(intersect.get(ind + 1) > intersect.get(ind)) MapleQuicksort(intersect.get(ind), intersect.get(ind + 1) - 1, A, secondarySort);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class MapleStorageInventory {
|
||||
private Client c;
|
||||
public class StorageInventory {
|
||||
private final Client c;
|
||||
private Map<Short, Item> inventory = new LinkedHashMap<>();
|
||||
private byte slotLimit;
|
||||
private final byte slotLimit;
|
||||
|
||||
public MapleStorageInventory(Client c, List<Item> toSort) {
|
||||
public StorageInventory(Client c, List<Item> toSort) {
|
||||
this.inventory = new LinkedHashMap<>();
|
||||
this.slotLimit = (byte)toSort.size();
|
||||
this.slotLimit = (byte) toSort.size();
|
||||
this.c = c;
|
||||
|
||||
for(Item item : toSort) {
|
||||
for (Item item : toSort) {
|
||||
this.addItem(item);
|
||||
}
|
||||
}
|
||||
@@ -244,7 +102,7 @@ public class MapleStorageInventory {
|
||||
if (src < 0 || dst < 0) {
|
||||
return;
|
||||
}
|
||||
if(dst > this.getSlotLimit()) {
|
||||
if (dst > this.getSlotLimit()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -299,16 +157,24 @@ public class MapleStorageInventory {
|
||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||
Item srcItem, dstItem;
|
||||
|
||||
for(short dst = 1; dst <= this.getSlotLimit(); dst++) {
|
||||
for (short dst = 1; dst <= this.getSlotLimit(); dst++) {
|
||||
dstItem = this.getItem(dst);
|
||||
if(dstItem == null) continue;
|
||||
if (dstItem == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for(short src = (short)(dst + 1); src <= this.getSlotLimit(); src++) {
|
||||
for (short src = (short) (dst + 1); src <= this.getSlotLimit(); src++) {
|
||||
srcItem = this.getItem(src);
|
||||
if(srcItem == null) continue;
|
||||
if (srcItem == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(dstItem.getItemId() != srcItem.getItemId()) continue;
|
||||
if(dstItem.getQuantity() == ii.getSlotMax(c, this.getItem(dst).getItemId())) break;
|
||||
if (dstItem.getItemId() != srcItem.getItemId()) {
|
||||
continue;
|
||||
}
|
||||
if (dstItem.getQuantity() == ii.getSlotMax(c, this.getItem(dst).getItemId())) {
|
||||
break;
|
||||
}
|
||||
|
||||
moveItem(src, dst);
|
||||
}
|
||||
@@ -344,7 +210,7 @@ public class MapleStorageInventory {
|
||||
for (short i = 1; i <= this.getSlotLimit(); i++) {
|
||||
Item item = this.getItem(i);
|
||||
if (item != null) {
|
||||
itemarray.add(item.copy());
|
||||
itemarray.add(item.copy());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,3 +226,167 @@ public class MapleStorageInventory {
|
||||
return itemarray;
|
||||
}
|
||||
}
|
||||
|
||||
class PairedQuicksort {
|
||||
private int i = 0;
|
||||
private int j = 0;
|
||||
private final ArrayList<Integer> intersect;
|
||||
ItemInformationProvider ii = ItemInformationProvider.getInstance();
|
||||
|
||||
private void PartitionByItemId(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (x.getItemId() > A.get(i).getItemId()) {
|
||||
i++;
|
||||
}
|
||||
while (x.getItemId() < A.get(j).getItemId()) {
|
||||
j--;
|
||||
}
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByName(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(i).getItemId())) > 0) {
|
||||
i++;
|
||||
}
|
||||
while (ii.getName(x.getItemId()).compareTo(ii.getName(A.get(j).getItemId())) < 0) {
|
||||
j--;
|
||||
}
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByQuantity(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Item x, w;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = A.get((i + j) / 2);
|
||||
do {
|
||||
while (x.getQuantity() > A.get(i).getQuantity()) {
|
||||
i++;
|
||||
}
|
||||
while (x.getQuantity() < A.get(j).getQuantity()) {
|
||||
j--;
|
||||
}
|
||||
|
||||
if (i <= j) {
|
||||
w = A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
private void PartitionByLevel(int Esq, int Dir, ArrayList<Item> A) {
|
||||
Equip x, w, eqpI, eqpJ;
|
||||
|
||||
i = Esq;
|
||||
j = Dir;
|
||||
|
||||
x = (Equip) (A.get((i + j) / 2));
|
||||
|
||||
do {
|
||||
eqpI = (Equip) A.get(i);
|
||||
eqpJ = (Equip) A.get(j);
|
||||
|
||||
while (x.getLevel() > eqpI.getLevel()) {
|
||||
i++;
|
||||
}
|
||||
while (x.getLevel() < eqpJ.getLevel()) {
|
||||
j--;
|
||||
}
|
||||
|
||||
if (i <= j) {
|
||||
w = (Equip) A.get(i);
|
||||
A.set(i, A.get(j));
|
||||
A.set(j, w);
|
||||
|
||||
i++;
|
||||
j--;
|
||||
}
|
||||
} while (i <= j);
|
||||
}
|
||||
|
||||
void MapleQuicksort(int Esq, int Dir, ArrayList<Item> A, int sort) {
|
||||
switch (sort) {
|
||||
case 3:
|
||||
PartitionByLevel(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
PartitionByName(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
PartitionByQuantity(Esq, Dir, A);
|
||||
break;
|
||||
|
||||
default:
|
||||
PartitionByItemId(Esq, Dir, A);
|
||||
}
|
||||
|
||||
|
||||
if (Esq < j) {
|
||||
MapleQuicksort(Esq, j, A, sort);
|
||||
}
|
||||
if (i < Dir) {
|
||||
MapleQuicksort(i, Dir, A, sort);
|
||||
}
|
||||
}
|
||||
|
||||
public PairedQuicksort(ArrayList<Item> A, int primarySort, int secondarySort) {
|
||||
intersect = new ArrayList<>();
|
||||
|
||||
if (A.size() > 0) {
|
||||
MapleQuicksort(0, A.size() - 1, A, primarySort);
|
||||
}
|
||||
|
||||
intersect.add(0);
|
||||
for (int ind = 1; ind < A.size(); ind++) {
|
||||
if (A.get(ind - 1).getItemId() != A.get(ind).getItemId()) {
|
||||
intersect.add(ind);
|
||||
}
|
||||
}
|
||||
intersect.add(A.size());
|
||||
|
||||
for (int ind = 0; ind < intersect.size() - 1; ind++) {
|
||||
if (intersect.get(ind + 1) > intersect.get(ind)) {
|
||||
MapleQuicksort(intersect.get(ind), intersect.get(ind + 1) - 1, A, secondarySort);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user