mirror of
https://git.krews.org/morningstar/Arcturus-Community.git
synced 2024-11-23 07:20:50 +01:00
Automatically convert credit redeemables on trade confirm
This commit is contained in:
parent
d06b9bae11
commit
948669cbff
@ -8,6 +8,7 @@ import com.eu.habbo.messages.outgoing.inventory.AddHabboItemComposer;
|
|||||||
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
import com.eu.habbo.messages.outgoing.inventory.InventoryRefreshComposer;
|
||||||
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
import com.eu.habbo.messages.outgoing.rooms.users.RoomUserStatusComposer;
|
||||||
import com.eu.habbo.messages.outgoing.trading.*;
|
import com.eu.habbo.messages.outgoing.trading.*;
|
||||||
|
import com.eu.habbo.threading.runnables.QueryDeleteHabboItem;
|
||||||
import gnu.trove.set.hash.THashSet;
|
import gnu.trove.set.hash.THashSet;
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
@ -214,6 +215,33 @@ public class RoomTrade {
|
|||||||
userOne.clearItems();
|
userOne.clearItems();
|
||||||
userTwo.clearItems();
|
userTwo.clearItems();
|
||||||
|
|
||||||
|
int creditsForUserTwo = 0;
|
||||||
|
THashSet<HabboItem> creditFurniUserOne = new THashSet<>();
|
||||||
|
for (HabboItem item : itemsUserOne) {
|
||||||
|
int worth = RoomTrade.getCreditsByItem(item);
|
||||||
|
if (worth > 0) {
|
||||||
|
creditsForUserTwo += worth;
|
||||||
|
creditFurniUserOne.add(item);
|
||||||
|
new QueryDeleteHabboItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemsUserOne.removeAll(creditFurniUserOne);
|
||||||
|
|
||||||
|
int creditsForUserOne = 0;
|
||||||
|
THashSet<HabboItem> creditFurniUserTwo = new THashSet<>();
|
||||||
|
for (HabboItem item : itemsUserTwo) {
|
||||||
|
int worth = RoomTrade.getCreditsByItem(item);
|
||||||
|
if (worth > 0) {
|
||||||
|
creditsForUserOne += worth;
|
||||||
|
creditFurniUserTwo.add(item);
|
||||||
|
new QueryDeleteHabboItem(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
itemsUserTwo.removeAll(creditFurniUserTwo);
|
||||||
|
|
||||||
|
userOne.getHabbo().giveCredits(creditsForUserOne);
|
||||||
|
userTwo.getHabbo().giveCredits(creditsForUserTwo);
|
||||||
|
|
||||||
userOne.getHabbo().getInventory().getItemsComponent().addItems(itemsUserTwo);
|
userOne.getHabbo().getInventory().getItemsComponent().addItems(itemsUserTwo);
|
||||||
userTwo.getHabbo().getInventory().getItemsComponent().addItems(itemsUserOne);
|
userTwo.getHabbo().getInventory().getItemsComponent().addItems(itemsUserOne);
|
||||||
|
|
||||||
@ -287,4 +315,14 @@ public class RoomTrade {
|
|||||||
public List<RoomTradeUser> getRoomTradeUsers() {
|
public List<RoomTradeUser> getRoomTradeUsers() {
|
||||||
return this.users;
|
return this.users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getCreditsByItem(HabboItem item) {
|
||||||
|
if (!item.getBaseItem().getName().startsWith("CF_") && !item.getBaseItem().getName().startsWith("CFC_")) return 0;
|
||||||
|
|
||||||
|
try {
|
||||||
|
return Integer.valueOf(item.getBaseItem().getName().split("_")[1]);
|
||||||
|
} catch (Exception e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,18 +39,8 @@ public class TradeUpdateComposer extends MessageComposer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.response.appendInt(roomTradeUser.getItems().size());
|
this.response.appendInt(roomTradeUser.getItems().size());
|
||||||
this.response.appendInt(roomTradeUser.getItems().stream().mapToInt(this::getCreditsByItem).sum());
|
this.response.appendInt(roomTradeUser.getItems().stream().mapToInt(RoomTrade::getCreditsByItem).sum());
|
||||||
}
|
}
|
||||||
return this.response;
|
return this.response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getCreditsByItem(HabboItem item) {
|
|
||||||
if (!item.getBaseItem().getName().startsWith("CF_") && !item.getBaseItem().getName().startsWith("CFC_")) return 0;
|
|
||||||
|
|
||||||
try {
|
|
||||||
return Integer.valueOf(item.getBaseItem().getName().split("_")[1]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user