|
@@ -31,6 +31,7 @@ import com.iohao.mmo.common.provide.proto.ShowItemMessage;
|
|
|
import lombok.experimental.UtilityClass;
|
|
|
|
|
|
import java.util.List;
|
|
|
+import java.util.function.Supplier;
|
|
|
|
|
|
/**
|
|
|
* 用于界面显示的物品消息,类似单次跑马灯
|
|
@@ -40,7 +41,13 @@ import java.util.List;
|
|
|
*/
|
|
|
@UtilityClass
|
|
|
public class CommonExchange {
|
|
|
- public void broadcastShowItem(List<ShowItemMessage> itemMessages, long userId) {
|
|
|
+ public void broadcastShowItem(Supplier<List<ShowItemMessage>> supplier, long userId) {
|
|
|
+ List<ShowItemMessage> itemMessages = supplier.get();
|
|
|
+
|
|
|
+ if (CollKit.isEmpty(itemMessages)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
CmdInfo cmdInfo = CommonCmd.of(CommonCmd.broadcastShowItem);
|
|
|
ByteValueList byteValueList = WrapperKit.ofListByteValue(itemMessages);
|
|
|
|
|
@@ -48,7 +55,24 @@ public class CommonExchange {
|
|
|
broadcastContext.broadcast(cmdInfo, byteValueList, userId);
|
|
|
}
|
|
|
|
|
|
- public void broadcastShowItem(List<ShowItemMessage> itemMessages, FlowContext flowContext) {
|
|
|
+ /**
|
|
|
+ * 物品获得通知
|
|
|
+ * <pre>
|
|
|
+ * 用于界面显示的物品消息
|
|
|
+ * 使用 supplier 有个好处,就是当游戏不需要这个物品获得通知这个推送业务时,
|
|
|
+ * 只需要在这个方法做控制就好的,
|
|
|
+ * 并且还能减少转换,也就是不调用 supplier.get() 方法。
|
|
|
+ *
|
|
|
+ * 在调用端也不需要做任何改动,保留原样即可,
|
|
|
+ * 由于不转换,因此也就没损耗。
|
|
|
+ * </pre>
|
|
|
+ *
|
|
|
+ * @param supplier supplier
|
|
|
+ * @param flowContext flowContext
|
|
|
+ */
|
|
|
+ public void broadcastShowItem(Supplier<List<ShowItemMessage>> supplier, FlowContext flowContext) {
|
|
|
+ List<ShowItemMessage> itemMessages = supplier.get();
|
|
|
+
|
|
|
if (CollKit.isEmpty(itemMessages)) {
|
|
|
return;
|
|
|
}
|