Commit 1c886c46 authored by Rikysamuel's avatar Rikysamuel
Browse files

merge

parents 3e23f483 53801f2e
......@@ -3,29 +3,12 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<<<<<<< HEAD
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/TradePanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/grandquest/GrandQuest.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/FindPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/LoginPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/MixItemPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/Request/Request.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/MapPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/MainFrame.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/InventoryPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/HelperClasses/Server.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/HelperClasses/ButtonColumn.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/OfferingPanel.java</file>
<file>file:/E:/OneDrive/Data%20Semester%206/Sistem%20Terdistribusi/GrandQuest/src/client/src/GUI/MixedItem.java</file>
=======
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/AcceptPanel.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/MainFrame.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/MixItemPanel.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/TradePanel.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/grandquest/GrandQuest.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/HelperClasses/Item.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/FindPanel.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/LoginPanel.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/InventoryPanel.java</file>
>>>>>>> 86d3b7e8f0f0920102862df169fb0ad151a60dc4
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/Request/Request.java</file>
<file>file:/D:/AFIK/Project/GrandQuest%20Sister/IF3230-Tugas-Besar-Sister-2015/src/client/src/GUI/MapPanel.java</file>
</group>
</open-files>
</project-private>
......@@ -6,8 +6,10 @@
package GUI;
import Request.Request;
import grandquest.GrandQuest;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
/**
*
......@@ -15,7 +17,7 @@ import javax.swing.ImageIcon;
*/
public class FindPanel extends javax.swing.JPanel {
GrandQuest gq;
int item;
int item = 0;
/**
* Creates new form FindPanel
......@@ -292,59 +294,79 @@ public class FindPanel extends javax.swing.JPanel {
private void HerbsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HerbsActionPerformed
ImageIcon image = new ImageIcon("img/herbs.png");
selectedItem.setIcon(image);
item = 0;
item = 1;
}//GEN-LAST:event_HerbsActionPerformed
private void ClayActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ClayActionPerformed
ImageIcon image = new ImageIcon("img/clay.png");
selectedItem.setIcon(image);
item = 0;
item = 2;
}//GEN-LAST:event_ClayActionPerformed
private void MineralActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MineralActionPerformed
ImageIcon image = new ImageIcon("img/mineral.png");
selectedItem.setIcon(image);
item = 0;
item = 3;
}//GEN-LAST:event_MineralActionPerformed
private void PotionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PotionActionPerformed
ImageIcon image = new ImageIcon("img/potion.png");
selectedItem.setIcon(image);
item = 0;
item = 4;
}//GEN-LAST:event_PotionActionPerformed
private void PilosopherStoneActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PilosopherStoneActionPerformed
ImageIcon image = new ImageIcon("img/stone.png");
selectedItem.setIcon(image);
item = 0;
item = 5;
}//GEN-LAST:event_PilosopherStoneActionPerformed
private void ManaCrystalActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ManaCrystalActionPerformed
ImageIcon image = new ImageIcon("img/mana.png");
selectedItem.setIcon(image);
item = 0;
item = 6;
}//GEN-LAST:event_ManaCrystalActionPerformed
private void LifeElixirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_LifeElixirActionPerformed
ImageIcon image = new ImageIcon("img/life.png");
selectedItem.setIcon(image);
item = 0;
item = 7;
}//GEN-LAST:event_LifeElixirActionPerformed
private void GemsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GemsActionPerformed
ImageIcon image = new ImageIcon("img/gems.png");
selectedItem.setIcon(image);
item = 0;
item = 8;
}//GEN-LAST:event_GemsActionPerformed
private void IncenseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IncenseActionPerformed
ImageIcon image = new ImageIcon("img/incense.png");
selectedItem.setIcon(image);
item = 0;
item = 9;
}//GEN-LAST:event_IncenseActionPerformed
private void findButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findButtonActionPerformed
if(Request.connectToServer(GrandQuest.host,GrandQuest.port)){
String sentence = Request.sendFind(GrandQuest.token, Integer.toString(item)).toString();
Request.responseHandler(Request.send(sentence));
}
if (Request.serverResponse!=null){
String res = Request.findInResponses("status");
switch(res){
case "ok" :
GrandQuest.offers = Request.findInResponses("offers");
System.out.println(GrandQuest.offers);
break;
default :
JOptionPane.showMessageDialog(null, "Error!", "Error", JOptionPane.ERROR_MESSAGE);
break;
}
GrandQuest.tableId = 1;
System.out.println("ID " + GrandQuest.tableId);
gq.retTrade();
}
}//GEN-LAST:event_findButtonActionPerformed
private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
......
......@@ -145,7 +145,7 @@ public class MapPanel extends javax.swing.JPanel {
String res = Request.findInResponses("status");
switch(res){
case "ok" :
item = Item.getItem(Integer.parseInt(Request.findInResponses("item")));
item = Item.getItemName(Integer.parseInt(Request.findInResponses("item")));
JOptionPane.showMessageDialog(null, "Congratulation, you've earned "+ item,"Information", JOptionPane.PLAIN_MESSAGE);
//PANEL MIXEDITEM
break;
......@@ -563,6 +563,7 @@ public class MapPanel extends javax.swing.JPanel {
}
GrandQuest.savedPane = this;
GrandQuest.tableId = 0;
gq.retTrade();
}
}//GEN-LAST:event_tradeButtonActionPerformed
......@@ -604,34 +605,8 @@ public class MapPanel extends javax.swing.JPanel {
}//GEN-LAST:event_inventoryButtonActionPerformed
private void findItemButonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_findItemButonActionPerformed
if(Request.connectToServer(GrandQuest.host,GrandQuest.port)){
String sentence = Request.inventory(GrandQuest.token).toString();
Request.responseHandler(Request.send(sentence));
}
if (Request.serverResponse!=null){
String res = Request.findInResponses("status");
switch(res){
case "ok" :
String inventory = Request.findInResponses("inventory");
System.out.println(inventory);
String [] result = inventory.replaceAll("\\[", "").replaceAll("\\]", "").split(",");
GrandQuest.inventory = new ArrayList<>();
for(String number : result)
{
GrandQuest.inventory.add(Integer.parseInt(number));
}
break;
default :
JOptionPane.showMessageDialog(null, "Error!", "Error", JOptionPane.ERROR_MESSAGE);
break;
}
GrandQuest.savedPane = this;
gq.retFind();
}
GrandQuest.savedPane = this;
gq.retFind();
}//GEN-LAST:event_findItemButonActionPerformed
private void logoutButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_logoutButtonActionPerformed
......
......@@ -7,6 +7,7 @@
package GUI;
import HelperClasses.ButtonColumn;
import HelperClasses.Item;
import Request.Request;
import grandquest.GrandQuest;
import java.awt.event.ActionEvent;
......@@ -33,7 +34,6 @@ public class TradePanel extends javax.swing.JPanel {
public TradePanel() {
gq = new GrandQuest();
offers = parseOffer(GrandQuest.offers);
initComponents();
initTable();
}
......@@ -45,11 +45,13 @@ public class TradePanel extends javax.swing.JPanel {
JTable createTable() {
Object[][] data;
if (offers!=null){
System.out.println("ID : " + GrandQuest.tableId);
data = new Object[offers.size()][6];
for (int i = 0; i < offers.size(); i++) {
data[i][0] = new ImageIcon(getClass().getResource("/img/honey.png"));
data[i][0] = new ImageIcon(getClass().getResource(Item.getItemIcon(Integer.valueOf(offers.get(i)[0]))));
data[i][1] = offers.get(i)[1];
data[i][2] = new ImageIcon(getClass().getResource("/img/herbs.png"));
data[i][2] = new ImageIcon(getClass().getResource(Item.getItemIcon(Integer.valueOf(offers.get(i)[2]))));
data[i][3] = offers.get(i)[3];
if (GrandQuest.tableId==0){
if (offers.get(i)[4].equals("false")){
......@@ -58,7 +60,8 @@ public class TradePanel extends javax.swing.JPanel {
data[i][4] = "Cancel";
}
} else{ // accept panel
System.out.println("Masuk find");
data[i][4] = "Buy";
}
data[i][5] = offers.get(i)[5];
}
......@@ -159,17 +162,21 @@ public class TradePanel extends javax.swing.JPanel {
data = data.replace("\"", "");
List<String []> offers = new ArrayList<>();
String[] dataParse = data.replace("[","").replace("]","").replace("\"", "").split(",");
String[] temp;
for (String dataParse1 : dataParse) {
temp = new String[6];
for (int j = 0; j < 6; j++) {
temp[j] = dataParse[j].replace("[", "");
String[] temp = new String[6];
int j = 0;
for (int i= 0; i<dataParse.length; i++) {
temp[j] = dataParse[i];
if (j==5) {
j = 0;
offers.add(temp);
temp = new String[6];
}
offers.add(temp);
else {
j++;
}
}
return offers;
} else{
return null;
......
......@@ -68,11 +68,19 @@ public class Item {
}
public static String getItem(int index) {
public static String getItemName(int index) {
String itemName;
createItem();
itemName = allItem.get(index).value;
return itemName;
}
public static String getItemIcon(int index) {
String itemName;
createItem();
itemName = allItem.get(index).key;
return itemName;
}
}
......@@ -258,23 +258,6 @@ public class Request {
return null;
}
/**
* generate JSON Object to find any item in offer menu
* @param item
* @return
*/
public static JSONObject findOffer(String item){
try {
JSONObject jo = new JSONObject();
jo.put("method", "findoffer");
jo.put("item", item);
return jo;
} catch (JSONException ex) {
Logger.getLogger(Request.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* generate JSON Object to accept other people's offer
......@@ -296,24 +279,6 @@ public class Request {
return null;
}
/**
* generate JSON Object to accept people's offer request
* @param token
* @param offertoken
* @return
*/
public static JSONObject accept(String token, String offertoken){
try {
JSONObject jo = new JSONObject();
jo.put("method", "accept");
jo.put("offer_token", offertoken);
return jo;
} catch (JSONException ex) {
Logger.getLogger(Request.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
/**
* generate JSON Object to fetch any item from the finished offer
......
......@@ -71,7 +71,6 @@ public class GrandQuest {
}
public void retTrade(){
tableId = 0;
mf.setContentPane(new TradePanel());
mf.revalidate();
}
......@@ -91,7 +90,8 @@ public class GrandQuest {
mf.setContentPane(new LoginPanel());
mf.revalidate();
}
/**
* @param args the command line arguments
*/
......
......@@ -63,7 +63,7 @@ javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=server.helper.Message
main.class=server.Server
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
......
......@@ -34,9 +34,7 @@ public class ServerHandler{
InputStream in = s.getInputStream();
DataOutputStream out = new DataOutputStream(s.getOutputStream());
out.write(request.getBytes());
byte[] byt = new byte[4096];
int count = in.read(byt);
request = new String(byt);
if(response != null) {
// request = request.substring(0,count);
......
......@@ -85,19 +85,19 @@ public class Database {
// System.out.println(saveOfferToTradeBox("553b64d23c892b2d5b772c74", 4, 5, 6, 2));
addItemToInventory("553b6adc3c892b2edffa877c", 3);
addItemToInventory("553b6adc3c892b2edffa877c", 2);
addItemToInventory("553b6adc3c892b2edffa877c", 3);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
addItemToInventory("553b6adc3c892b2edffa877c", 5);
// addItemToInventory("553b6adc3c892b2edffa877c", 3);
// addItemToInventory("553b6adc3c892b2edffa877c", 2);
// addItemToInventory("553b6adc3c892b2edffa877c", 3);
// addItemToInventory("553b6adc3c892b2edffa877c", 5);
// addItemToInventory("553b6adc3c892b2edffa877c", 5);
// addItemToInventory("553b6adc3c892b2edffa877c", 5);
//
// System.out.println(saveOfferToTradeBox("553b6adc3c892b2edffa877c", 4, 1, 5, 3));
// getTradebox("553b64d23c892b2d5b772c74");
// changeLocalTradeboxToFalse("553c36143c892b1bbf7723d6");
// System.out.println(isExist("sijc"));
System.out.println(getInventory("553cd35d3c892b2c6768f77d"));
}
/**
......@@ -470,27 +470,27 @@ public class Database {
try{
allOffer = new ArrayList<>();
if(cursor.hasNext())
while(cursor.hasNext())
{
while(cursor.hasNext())
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
{
String oneOfferString = cursor.next().toJson();
JSONObject jsonObj = new JSONObject(oneOfferString);
if(jsonObj.getInt("offered_item") == itemIdx)
{
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
oneoffer = new ArrayList<>();
oneoffer.add(jsonObj.getInt("offered_item"));
oneoffer.add(jsonObj.getInt("n1"));
oneoffer.add(jsonObj.getInt("demanded_item"));
oneoffer.add(jsonObj.getInt("n2"));
oneoffer.add(jsonObj.getBoolean("availability"));
oneoffer.add(getJsonObjId(jsonObj.toString()));
allOffer.add(oneoffer);
}
if(allOffer.isEmpty())
{
return null;
}
}
else
return null;
} catch (JSONException | NullPointerException ex) {
return null;
}
......
......@@ -13,8 +13,20 @@ package server.helper;
public class Map {
private String[][] map;
private String token;
private final String Honey = "R11";
private final String Herbs = "R12";
private final String Clay = "R13";
private final String Mineral = "R14";
private final String Potion = "R21";
private final String Incense = "R22";
private final String Gems = "R23";
private final String LifeElix = "R31";
private final String Mana = "R32";
private final String Stone = "R41";
public Map(String token){
map = Store.getMap();
this.token = token;
}
public String[][] getMap(){
......@@ -23,4 +35,72 @@ public class Map {
public String getToken(){
return token;
}
public void generateMap()
{
map[0][0] = Honey;
map[0][1] = Mineral;
map[0][2] = Herbs;
map[0][3] = Herbs;
map[0][4] = Mineral;
map[1][0] = Clay;
map[1][1] = Clay;
map[1][2] = Herbs;
map[1][3] = Mineral;
map[1][4] = Potion;
map[3][0] = Mineral;
map[3][1] = Herbs;
map[3][2] = Clay;
map[3][3] = Herbs;
map[3][4] = Incense;
map[4][0] = Mana;
map[4][1] = Gems;
map[4][2] = Potion;
map[4][3] = LifeElix;
map[4][4] = Mineral;
}
public int getItemIndex(int xPos, int yPos) {
int HONEY = 0;
int HERBS = 1;
int CLAY = 2;
int MINERAL = 3;
int POTION = 4;
int INCENSE = 5;
int GEMS = 6;
int LIFEELIXIR = 7;
int MANACRYSTAL = 8;
int PHILSTONE = 9;
if (map[xPos][yPos].equals(Honey)) {
return HONEY;
} else if (map[xPos][yPos].equals(Herbs)) {
return HERBS;
} else if (map[xPos][yPos].equals(Clay)) {
return CLAY;
} else if (map[xPos][yPos].equals(Mineral)) {
return MINERAL;
} else if (map[xPos][yPos].equals(Potion)) {
return POTION;
} else if (map[xPos][yPos].equals(Incense)) {
return INCENSE;
} else if (map[xPos][yPos].equals(Gems)) {
return GEMS;
} else if (map[xPos][yPos].equals(LifeElix)) {
return LIFEELIXIR;
} else if (map[xPos][yPos].equals(Mana)) {
return MANACRYSTAL;
} else if (map[xPos][yPos].equals(Stone)) {
return PHILSTONE;
} else {
return -1;
}
}
public void setEmpty(int x, int y)
{
map[x][y] = "-1";
}
}
......@@ -72,9 +72,13 @@ public class Message {
// getTradeBox("553b64d23c892b2d5b772c74");
// sendFind("553b64d23c892b2d5b772c74", 4);
System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 4, 5));
System.out.println("Get inventory: " + getInventory("553b6adc3c892b2edffa877c"));
System.out.println("Get tradebox: " + getTradeBox("553a1674179bf4356b7198d5"));
// System.out.println("Mix item: " + mixItem("553b6adc3c892b2edffa877c", 4, 5));
// System.out.println("Get inventory: " + getInventory("553b6adc3c892b2edffa877c"));
// System.out.println("Get tradebox: " + getTradeBox("553a1674179bf4356b7198d5"));
// System.out.println(receive("{\"item\": 0, \"method\": \"findoffer\"}"));
// System.out.println(move("553cd35d3c892b2c6768f77d", 4, 4));
// System.out.println(receive("{\"method\":\"field\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
System.out.println(receive("{\"method\":\"inventory\",\"token\":\"553cd35d3c892b2c6768f77d\"}"));
}
public static String callURL(String myURL) {
......@@ -373,11 +377,7 @@ public class Message {
int honey = 0, herbs = 0, clay = 0, mineral = 0, potion = 0, incense = 0, gems = 0, elixir = 0, crystal = 0, stone = 0;
/* Get masing masing item dari database */
String inv = "[" + honey + "," + herbs + "," + clay + "," + mineral + "," + potion +
"," + incense + "," + gems + "," + elixir + "," + crystal + "," + stone + "]";
if(log)
System.out.println("Inventory = " + inv);
ArrayList<Integer> inv = Database.getInventory(token);
JSONObject jsonObj = new JSONObject();
try {
......@@ -530,8 +530,7 @@ public class Message {
JSONObject jsonPosition = Database.getCurrentPosition(token);
int x;
int y;
String [][] map = Store.getMap();
int item;
String response;
try {
......@@ -539,7 +538,7 @@ public class Message {
x = jsonPosition.getInt("x");
y = jsonPosition.getInt("y");
item = Store.getItemIndex(x, y);
item = Store.getMap(token).getItemIndex(x, y);
if(Database.addItemToInventory(token, item))
{
jsonObj.put("status", "ok");
......@@ -630,8 +629,8 @@ public class Message {
jsonObj = new JSONObject();
jsonObj.put("method", "findoffer");
jsonObj.put("item", itemId);