Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sharedstash -- m4ke #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
145 changes: 135 additions & 10 deletions gomule/src/gomule/d2s/D2Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public class D2Character extends D2ItemListAdapter
public static final int CUBESIZEX = 3;
public static final int CUBESIZEY = 4;

// m4ke
public static final int NUM_SHAREDPAGES = 3;
private ArrayList<SharedStashPage> sharedStash;
private SharedStashPage currSharedPage;
private int currSharedPageNum;
private int currStashPage;
private String sharedStashFileName;
private ArrayList<D2Item> currStashItems;
// /m4ke

private D2BitReader iReader;
private ArrayList iCharItems;
private D2Item iCharCursorItem;
Expand Down Expand Up @@ -133,10 +143,95 @@ public D2Character(String pFileName) throws Exception{
iMercItems = new ArrayList();
iReader = new D2BitReader(iFileName);
readChar();

// m4ke
sharedStash = new ArrayList<>();
currStashItems = new ArrayList<>();
currStashPage = 0;
if(iHC) sharedStashFileName = "SharedStashHardCoreV2.d2i";
else sharedStashFileName = "SharedStashSoftCoreV2.d2i";
sharedStashFileName = pFileName.substring(0, pFileName.lastIndexOf(File.separator)+1) + sharedStashFileName;
readSharedStash();
// /m4ke

// clear status
setModified(false);
}

// m4ke
public void setStashPage(int num) {
if(currStashPage==0) {
for(int i=0; i<iCharItems.size(); i++) {
D2Item d2i = (D2Item)iCharItems.get(i);
if(d2i.get_panel()==5)
unmarkCharGrid(d2i);
}

} else {
for(int i=0; i<currSharedPage.getItems().size(); i++) {
unmarkCharGrid(currSharedPage.getItemAt(i));
}
}

if(num==0) {
for(int i=0; i<iCharItems.size(); i++) {
D2Item d2i = (D2Item)iCharItems.get(i);
if(d2i.get_panel()==5)
markCharGrid(d2i);
}
} else {
currSharedPage = sharedStash.get(num-1);
currSharedPageNum = num-1;
for(int i=0; i<currSharedPage.getItems().size(); i++) {
markCharGrid(currSharedPage.getItemAt(i));
}
}
currStashPage = num;
}
public int getStashPageNum() {
return currStashPage;
}
public ArrayList getCurrSharedPageItems() {
return currSharedPage.getItems();
}
public SharedStashPage getCurrSharedPage() {
return currSharedPage;
}
private void readSharedStash() throws Exception {
D2BitReader br = new D2BitReader(sharedStashFileName);
int lLastItemEnd = 0x40;
int lNextJM = br.findNextFlag("JM", lLastItemEnd);
long numItems2 = 0;
int lItemStart2 = 0;
int i = 0;

while (lNextJM > 0) {
// System.err.println("lNextJM: find JM " + lNextJM);
// get numItems and read items
br.set_byte_pos(lNextJM + 2);
numItems2 = br.read(16);
// System.err.println("numItems2: " + numItems2);

lLastItemEnd = lNextJM + 4; // JM + numItems(2bytes)
SharedStashPage ssp = new SharedStashPage();
for ( int j = 0 ; j < numItems2 ; j++ )
{
// System.err.println("lLastItemEnd: " + lLastItemEnd);
lItemStart2 = lLastItemEnd;

D2Item lItem = new D2Item(sharedStashFileName, br, lItemStart2, 1);
lLastItemEnd = lItemStart2 + lItem.getItemLength();
ssp.addItem(lItem);
}
sharedStash.add(ssp);
lNextJM = br.findNextFlag("JM", lLastItemEnd);
i++;
}
currSharedPage = sharedStash.get(0);
currSharedPageNum = 0;
}
// /m4ke

private void readChar() throws Exception{
iReader.set_byte_pos(4);
long lVersion = iReader.read(32);
Expand Down Expand Up @@ -1048,7 +1143,11 @@ public boolean unmarkMercGrid(D2Item i) {
}

public void addCharItem(D2Item pItem){
iCharItems.add(pItem);
int panel = pItem.get_panel();
if(pItem.get_panel()!=5 || currStashPage==0)
iCharItems.add(pItem);
else
currSharedPage.addItem(pItem);
pItem.setCharLvl((int)iCharLevel);
setModified(true);
}
Expand All @@ -1066,7 +1165,10 @@ public void addMercItem(D2Item pItem){
}

public void removeCharItem(int i){
iCharItems.remove(i);
if(i >= iCharItems.size())
currSharedPage.removeItemAt(i - iCharItems.size());
else
iCharItems.remove(i);
setModified(true);
}

Expand Down Expand Up @@ -1291,16 +1393,28 @@ public int getCharItemIndex(int panel, int x, int y){ // iRow, iCol are input
}
}
}else{
for (int i = 0; i < iCharItems.size(); i++){
D2Item temp_item = (D2Item) iCharItems.get(i);
if (temp_item.get_panel() == panel) {
int col = temp_item.get_col();
int row = temp_item.get_row();
if ((x >= col) && (x <= col + temp_item.get_width() - 1) && (y >= row) && (y <= row + temp_item.get_height() - 1)) {
return i;
// m4ke
if(currStashPage>0 && panel == 5) {
for (int i = 0; i < currSharedPage.getItems().size(); i++){
//D2Item temp_item = (D2Item) iCharItems.get(i);
D2Item temp_item = (D2Item) currSharedPage.getItemAt(i);
if (temp_item.get_panel() == panel) {
int row = temp_item.get_col();
int col = temp_item.get_row();
if (x >= row && x <= row + temp_item.get_width() - 1 && y >= col && y <= col + temp_item.get_height() - 1)return iCharItems.size() + i;
}
}
} else {
for (int i = 0; i < iCharItems.size(); i++){
D2Item temp_item = (D2Item) iCharItems.get(i);
if (temp_item.get_panel() == panel) {
int row = temp_item.get_col();
int col = temp_item.get_row();
if (x >= row && x <= row + temp_item.get_width() - 1 && y >= col && y <= col + temp_item.get_height() - 1)return i;
}
}
}
// /m4ke
}
return -1;
}
Expand Down Expand Up @@ -1680,7 +1794,18 @@ public int getCharBlock() {

public void addItem(D2Item item){equipItem(item);};
public D2Item getCursorItem(){return iCharCursorItem;}
public D2Item getCharItem(int i){return (D2Item) iCharItems.get(i);}
// m4ke
//public D2Item getCharItem(int i){return (D2Item) iCharItems.get(i);}
public D2Item getCharItem(int i) {
D2Item d2i = null;
if(i>=iCharItems.size()) {
d2i = currSharedPage.getItemAt(i - iCharItems.size());
} else {
d2i = (D2Item) iCharItems.get(i);
}
return d2i;
}
// /m4ke
public D2Item getMercItem(int i){return (D2Item) iMercItems.get(i);}
public D2Item getCorpseItem(int i){return (D2Item) iCorpseItems.get(i);}
public D2Item getGolemItem() {return golemItem;}
Expand Down
51 changes: 51 additions & 0 deletions gomule/src/gomule/d2s/SharedStashPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package gomule.item;

import java.util.ArrayList;

public class SharedStashPage {

private final long MAX_STASHGOLD = 2500000;

private ArrayList<D2Item> items;
private long gold;

public SharedStashPage() {
items = new ArrayList<>();
gold = 0;
}

public void addItem(D2Item d2i) {
items.add(d2i);
}

public D2Item getItemAt(int i) {
return items.get(i);
}

public ArrayList getItems() {
return items;
}

public D2Item removeItemAt(int i) {
return items.remove(i);
}

public long getGold(long x) {
long tmp = x;

if(x>gold) tmp = gold;
gold -= tmp;

return tmp;
}


public long putGold(long x) {
long tmp = x;

if(gold+x>MAX_STASHGOLD) tmp = (gold+x) - MAX_STASHGOLD;
gold += tmp;

return tmp;
}
}
54 changes: 52 additions & 2 deletions gomule/src/gomule/gui/D2ViewChar.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

import gomule.d2s.*;
import gomule.item.*;

import java.awt.*;
import java.awt.event.*;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;

import javax.swing.*;
import javax.swing.event.*;

import randall.util.*;

/**
Expand Down Expand Up @@ -1310,6 +1313,17 @@ public void mouseReleased(MouseEvent pEvent)
{
int lX = pEvent.getX();
int lY = pEvent.getY();
// m4ke
if(lX>=309 && lX <=340 && lY>=392 && lY <=423)
setStash(0);
else if(lX>=346 && lX <=377 && lY>=392 && lY <=423)
setStash(1);
else if(lX>=383 && lX <=414 && lY>=392 && lY <=423)
setStash(2);
else if(lX>=420 && lX <=451 && lY>=392 && lY <=423)
setStash(3);
// /m4ke

if (((lX >= 16 + 308 && lX <= 45 + 308) || (lX >= 247 + 308 && lX <= 276 + 308)) && (lY >= 24 && lY <= 44))
{
setWeaponSlot(1);
Expand Down Expand Up @@ -1577,6 +1591,13 @@ public void setWeaponSlot(int pWeaponSlot)
// repaint();
}

// m4ke
public void setStash(int n) {
iCharacter.setStashPage(n);
build();
}
// /m4ke

public void build()
{
Image lEmptyBackground;
Expand All @@ -1601,9 +1622,38 @@ public void build()

if ( iCharacter != null )
{
for (int i = 0; i < iCharacter.getCharItemNr(); i++)
// m4ke
Font font = new Font("Lucida", Font.BOLD, 20);
lGraphics.setFont(font);
lGraphics.setColor(Color.BLACK);
lGraphics.drawString("P", 318, 415);
lGraphics.drawString("S1", 350, 415);
lGraphics.drawString("S2", 386, 415);
lGraphics.drawString("S3", 423, 415);
lGraphics.setColor(Color.WHITE);
lGraphics.drawString("Stash: "+iCharacter.getStashPageNum(), 460, 415);

ArrayList<D2Item> tempList = new ArrayList<>();
for(int i=0; i<iCharacter.getCharItemNr(); i++) {
D2Item d2i = iCharacter.getCharItem(i);
if(iCharacter.getStashPageNum()==0 || d2i.get_panel()!=5) {
tempList.add(d2i);
}
}
if(iCharacter.getStashPageNum()!=0) {
for(int i=0; i<iCharacter.getCurrSharedPageItems().size(); i++) {
tempList.add(iCharacter.getCurrSharedPage().getItemAt(i));
}
}

//for (int i = 0; i < iCharacter.getCharItemNr(); i++)
// /m4ke
for (int i = 0; i < tempList.size(); i++)
// /m4ke
{
D2Item temp_item = iCharacter.getCharItem(i);
// m4ke
//D2Item temp_item = iCharacter.getCharItem(i);
D2Item temp_item = tempList.get(i);
Image lImage = D2ImageCache.getDC6Image(temp_item);
int location = temp_item.get_location();
// on one of the grids
Expand Down