From b0fc64efe826efdf3c33fc418580d28494482fd4 Mon Sep 17 00:00:00 2001 From: yangweihome <2248568041@qq.com> Date: Fri, 3 Dec 2021 16:46:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E8=AE=B0=E7=89=8C=E5=99=A8?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ratel/landlords/client/SimpleClient.java | 2 +- ...entEventListener_CODE_GAME_POKER_PLAY.java | 2 + ...lientEventListener_CODE_GAME_STARTING.java | 2 + .../ratel/landlords/utils/LastCardsUtils.java | 67 +++++++++++++++++++ ...verEventListener_CODE_GAME_POKER_PLAY.java | 12 +++- ...istener_CODE_GAME_POKER_PLAY_REDIRECT.java | 11 +++ ...erverEventListener_CODE_GAME_STARTING.java | 14 +++- serverlist.json | 3 +- 8 files changed, 108 insertions(+), 5 deletions(-) create mode 100644 landlords-common/src/main/java/org/nico/ratel/landlords/utils/LastCardsUtils.java diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java index 0b8cb0d..da43ad4 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/SimpleClient.java @@ -28,7 +28,7 @@ public class SimpleClient { public static String protocol = "pb"; private final static String[] serverAddressSource = new String[]{ - "https://raw.githubusercontent.com/ainilili/ratel/master/serverlist.json", +// "https://raw.githubusercontent.com/ainilili/ratel/master/serverlist.json", "https://gitee.com/ainilili/ratel/raw/master/serverlist.json" }; diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_POKER_PLAY.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_POKER_PLAY.java index 1a05e77..6787829 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_POKER_PLAY.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_POKER_PLAY.java @@ -27,6 +27,8 @@ public class ClientEventListener_CODE_GAME_POKER_PLAY extends ClientEventListene List pokers = Noson.convert(map.get("pokers"), new NoType>() { }); SimplePrinter.printPokers(pokers); + SimplePrinter.printNotice("Last cards are"); + SimplePrinter.printNotice(map.get("lastPokers").toString()); SimplePrinter.printNotice("Please enter the combination you came up with (enter [exit|e] to exit current room, enter [pass|p] to jump current round, enter [view|v] to show all valid combinations.)"); String line = SimpleWriter.write("combination"); diff --git a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_STARTING.java b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_STARTING.java index e080380..14dc2f5 100644 --- a/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_STARTING.java +++ b/landlords-client/src/main/java/org/nico/ratel/landlords/client/event/ClientEventListener_CODE_GAME_STARTING.java @@ -25,6 +25,8 @@ public class ClientEventListener_CODE_GAME_STARTING extends ClientEventListener SimplePrinter.printNotice(""); SimplePrinter.printNotice("Your cards are"); SimplePrinter.printPokers(pokers); + SimplePrinter.printNotice("Last cards are"); + SimplePrinter.printNotice(map.get("lastPokers").toString()); get(ClientEventCode.CODE_GAME_LANDLORD_ELECT).call(channel, data); } diff --git a/landlords-common/src/main/java/org/nico/ratel/landlords/utils/LastCardsUtils.java b/landlords-common/src/main/java/org/nico/ratel/landlords/utils/LastCardsUtils.java new file mode 100644 index 0000000..5f87629 --- /dev/null +++ b/landlords-common/src/main/java/org/nico/ratel/landlords/utils/LastCardsUtils.java @@ -0,0 +1,67 @@ +package org.nico.ratel.landlords.utils; + +import org.nico.ratel.landlords.entity.Poker; + +import java.util.*; + +public class LastCardsUtils { + + public static String getLastCards(List> pokers){ + StringBuffer lastCards = new StringBuffer(); + Map lastCardMap = initLastCards(); + for(int i = 0; i < pokers.size(); i++){ + List pokerList = pokers.get(i); + for(int a = 0; a < pokerList.size(); a++){ + Poker poker = pokerList.get(a); + lastCardMap.put(poker.getLevel().getName(),(lastCardMap.get(poker.getLevel().getName())+1)); + } + } + List defSort = new ArrayList<>(); + initDefSort(defSort); + for(int i = 0; i < defSort.size(); i++){ + String key = defSort.get(i); + lastCards.append(key + "["+lastCardMap.get(key)+"] "); + } + + return lastCards.toString(); + } + + private static void initDefSort(List defSort){ + defSort.add("3"); + defSort.add("4"); + defSort.add("5"); + defSort.add("6"); + defSort.add("7"); + defSort.add("8"); + defSort.add("9"); + defSort.add("10"); + defSort.add("J"); + defSort.add("Q"); + defSort.add("K"); + defSort.add("A"); + defSort.add("2"); + defSort.add("S"); + defSort.add("X"); + + } + + private static Map initLastCards(){ + Map lastCards = new HashMap<>(); + lastCards.put("A",0); + lastCards.put("2",0); + lastCards.put("3",0); + lastCards.put("4",0); + lastCards.put("5",0); + lastCards.put("6",0); + lastCards.put("7",0); + lastCards.put("8",0); + lastCards.put("9",0); + lastCards.put("10",0); + lastCards.put("J",0); + lastCards.put("Q",0); + lastCards.put("K",0); + lastCards.put("S",0); + lastCards.put("X",0); + return lastCards; + } +} diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY.java index 7e20410..1ee6c2e 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY.java @@ -16,6 +16,7 @@ import org.nico.ratel.landlords.helper.PokerHelper; import org.nico.ratel.landlords.print.SimplePrinter; import org.nico.ratel.landlords.server.ServerContains; import org.nico.ratel.landlords.server.robot.RobotEventListener; +import org.nico.ratel.landlords.utils.LastCardsUtils; public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventListener { @@ -77,6 +78,14 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventList room.setLastPokerShell(currentPokerSell); room.setCurrentSellClient(next.getId()); + List> lastPokerList = new ArrayList<>(); + for(int i = 0; i < room.getClientSideList().size(); i++){ + if(room.getClientSideList().get(i).getId() != clientSide.getId()){ + lastPokerList.add(room.getClientSideList().get(i).getPokers()); + } + } + String lastPokers = LastCardsUtils.getLastCards(lastPokerList); + lastPokerList = new ArrayList<>(); clientSide.getPokers().removeAll(currentPokers); MapHelper mapHelper = MapHelper.newInstance() .put("clientId", clientSide.getId()) @@ -84,7 +93,8 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY implements ServerEventList .put("clientType", clientSide.getType()) .put("pokers", currentPokers) .put("lastSellClientId", clientSide.getId()) - .put("lastSellPokers", currentPokers); + .put("lastSellPokers", currentPokers) + .put("lastPokers",lastPokers); if (!clientSide.getPokers().isEmpty()) { mapHelper.put("sellClientNickname", next.getNickname()); diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java index d156ff4..87c8996 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT.java @@ -9,10 +9,12 @@ import org.nico.noson.Noson; import org.nico.noson.util.string.StringUtils; import org.nico.ratel.landlords.channel.ChannelUtils; import org.nico.ratel.landlords.entity.ClientSide; +import org.nico.ratel.landlords.entity.Poker; import org.nico.ratel.landlords.entity.Room; import org.nico.ratel.landlords.enums.ClientEventCode; import org.nico.ratel.landlords.helper.MapHelper; import org.nico.ratel.landlords.server.ServerContains; +import org.nico.ratel.landlords.utils.LastCardsUtils; public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements ServerEventListener{ @@ -37,6 +39,14 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements Server } } + List> lastPokerList = new ArrayList<>(); + for(int i = 0; i < room.getClientSideList().size(); i++){ + if(room.getClientSideList().get(i).getId() != clientSide.getId()){ + lastPokerList.add(room.getClientSideList().get(i).getPokers()); + } + } + String lastPokers = LastCardsUtils.getLastCards(lastPokerList); + lastPokerList = new ArrayList<>(); String result = MapHelper.newInstance() .put("pokers", clientSide.getPokers()) .put("lastSellPokers", datas.get("lastSellPokers")) @@ -44,6 +54,7 @@ public class ServerEventListener_CODE_GAME_POKER_PLAY_REDIRECT implements Server .put("clientInfos", clientInfos) .put("sellClientId", room.getCurrentSellClient()) .put("sellClientNickname", ServerContains.CLIENT_SIDE_MAP.get(room.getCurrentSellClient()).getNickname()) + .put("lastPokers",lastPokers) .json(); ChannelUtils.pushToClient(clientSide.getChannel(), ClientEventCode.CODE_GAME_POKER_PLAY_REDIRECT, result); diff --git a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java index 1c46386..1372300 100644 --- a/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java +++ b/landlords-server/src/main/java/org/nico/ratel/landlords/server/event/ServerEventListener_CODE_GAME_STARTING.java @@ -1,5 +1,6 @@ package org.nico.ratel.landlords.server.event; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; @@ -12,6 +13,8 @@ import org.nico.ratel.landlords.helper.MapHelper; import org.nico.ratel.landlords.helper.PokerHelper; import org.nico.ratel.landlords.server.ServerContains; import org.nico.ratel.landlords.server.robot.RobotEventListener; +import org.nico.ratel.landlords.utils.JsonUtils; +import org.nico.ratel.landlords.utils.LastCardsUtils; public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListener { @@ -42,11 +45,17 @@ public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListen // Record the first speaker room.setFirstSellClient(startGrabClient.getId()); - + List> otherPokers = new ArrayList<>(); for (ClientSide client : roomClientList) { client.setType(ClientType.PEASANT); client.setStatus(ClientStatus.PLAYING); - + for(ClientSide otherClient : roomClientList){ + if(otherClient.getId() != client.getId()){ + otherPokers.add(otherClient.getPokers()); + } + } + String lastCards = LastCardsUtils.getLastCards(otherPokers); + otherPokers = new ArrayList<>(); String result = MapHelper.newInstance() .put("roomId", room.getId()) .put("roomOwner", room.getRoomOwner()) @@ -54,6 +63,7 @@ public class ServerEventListener_CODE_GAME_STARTING implements ServerEventListen .put("nextClientNickname", startGrabClient.getNickname()) .put("nextClientId", startGrabClient.getId()) .put("pokers", client.getPokers()) + .put("lastPokers",lastCards) .json(); if (client.getRole() == ClientRole.PLAYER) { diff --git a/serverlist.json b/serverlist.json index 7289b4e..2260057 100644 --- a/serverlist.json +++ b/serverlist.json @@ -3,5 +3,6 @@ "47.103.16.48:1024:jsClient[v1.2.7]", "s2.imlazy.ink:25020:FxCraft[v1.2.6]", "47.240.60.124:6565:ChenCodeX[v1.2.6]", - "cmi.zerodream.net:1919:ZeroDream[v1.2.2]" + "cmi.zerodream.net:1919:ZeroDream[v1.2.2]", + "106.14.125.226:1024:jipaiqi[v1.3.0]" ]