分页请求物品
parent
b838bf774e
commit
afe89d4879
|
@ -0,0 +1,7 @@
|
|||
package com.ljsd.jieling.globals;
|
||||
|
||||
public interface Global {
|
||||
int SEND_CARD_COUNT = 50; // 每页发送卡牌个数
|
||||
int SEND_ITEM_COUNT = 3; // 每页发送道具个数
|
||||
int SEND_EQUIP_COUNT = 50; // 每页发送装备个数
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
package com.ljsd.jieling.handler;
|
||||
|
||||
import com.ljsd.jieling.globals.Global;
|
||||
import com.ljsd.jieling.logic.dao.User;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
|
@ -12,7 +13,6 @@ import com.ljsd.jieling.util.MessageUtil;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
|
@ -33,14 +33,23 @@ public class GetAllItemHandler extends BaseHandler {
|
|||
int msgIndex = netData.getIndex();
|
||||
PlayerInfoProto.GetItemInfoRequest getItemInfoRequest
|
||||
= PlayerInfoProto.GetItemInfoRequest.parseFrom(netData.parseClientProtoNetData());
|
||||
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={}",
|
||||
userId, token,msgId,msgIndex);
|
||||
int index = getItemInfoRequest.getIndex();
|
||||
boolean isSendFinish = true;
|
||||
int itemStartIndex = getItemInfoRequest.getIndex();
|
||||
LOGGER.info("processMessage->uid={},token={},msgId={},msgIndex={},itemStartIndex={}",
|
||||
userId, token,msgId,msgIndex,itemStartIndex);
|
||||
boolean isSendFinish = false;
|
||||
User user = UserManager.getUserForLogin(userId);
|
||||
List<CommonProto.Item> allItemList = ItemUtil.getAllItem(user,index);
|
||||
if (allItemList.size() > 200){
|
||||
isSendFinish = false;
|
||||
List<CommonProto.Item> allItemList = ItemUtil.getAllItem(user);
|
||||
int endItemIndes = itemStartIndex + Global.SEND_ITEM_COUNT;
|
||||
if (itemStartIndex < allItemList.size()) {
|
||||
if (endItemIndes >= allItemList.size()) {
|
||||
endItemIndes = allItemList.size();
|
||||
}
|
||||
if (allItemList.size() == endItemIndes){
|
||||
isSendFinish = true;
|
||||
}
|
||||
allItemList = allItemList.subList(itemStartIndex, endItemIndes);
|
||||
}else{
|
||||
isSendFinish = true;
|
||||
}
|
||||
PlayerInfoProto.GetItemInfoResponse getItemInfoResponse = PlayerInfoProto.GetItemInfoResponse.newBuilder()
|
||||
.addAllItemlist(allItemList)
|
||||
|
|
|
@ -80,7 +80,6 @@ public class STableManager {
|
|||
try {
|
||||
String tableName = clazz.getAnnotation(Table.class).name();
|
||||
String path = SysUtil.getPath("conf", "server", tableName + ".txt");
|
||||
System.out.println("=============="+path);
|
||||
File file = new File(path);
|
||||
String line;
|
||||
List<String> key = new ArrayList<>();
|
||||
|
|
|
@ -1,36 +1,81 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import java.util.Date;
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
|
||||
public class Mail {
|
||||
|
||||
private String id;
|
||||
public class Mail extends MongoBase {
|
||||
|
||||
private int id ;
|
||||
private int roleUid; //所属玩家的UID
|
||||
|
||||
private boolean isRead;//是,否已读,未读,附件未领取
|
||||
private int state;//0:未读 1:已读取 2: 未领取 3 已领取
|
||||
|
||||
private String head; //标题
|
||||
|
||||
private Date sendDate;//发送的日期
|
||||
|
||||
private long sendTime; //发送时间
|
||||
|
||||
private String mailItemList;//获取所有的附件
|
||||
|
||||
private int effectiveTime;//有效日期
|
||||
|
||||
private int isDraw;//附件状态 是 否领取1和0
|
||||
|
||||
private String content;//邮件内容
|
||||
|
||||
private long readtime;//读邮件时间
|
||||
private String mailItem;//获取所有的附件
|
||||
|
||||
private int sendTime; //发送时间
|
||||
|
||||
private int effectiveTime;//有效时间()
|
||||
|
||||
private String sendName;//发送者名字
|
||||
|
||||
private int senderUid;
|
||||
|
||||
private long recvTime;
|
||||
|
||||
private int mailType; //邮件类型 1:系统邮件 2:idip 业务邮件
|
||||
|
||||
public Mail(int uid,String head,String content,String mailItem,int sendTime,int effectiveTime,String sendName,int mailType){
|
||||
this.roleUid = uid;
|
||||
this.head = head;
|
||||
this.content = content;
|
||||
this.mailItem = mailItem;
|
||||
this.sendTime = sendTime;
|
||||
this.effectiveTime = effectiveTime ;
|
||||
this.sendName = sendName ;
|
||||
this.mailType = mailType;
|
||||
}
|
||||
public void setState(int state) throws Exception {
|
||||
updateString("state", state);
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getRoleUid() {
|
||||
return roleUid;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public String getHead() {
|
||||
return head;
|
||||
}
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getMailItem() {
|
||||
return mailItem;
|
||||
}
|
||||
|
||||
public int getSendTime() {
|
||||
return sendTime;
|
||||
}
|
||||
|
||||
public int getEffectiveTime() {
|
||||
return effectiveTime;
|
||||
}
|
||||
|
||||
public String getSendName() {
|
||||
return sendName;
|
||||
}
|
||||
|
||||
public int getMailType() {
|
||||
return mailType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
package com.ljsd.jieling.logic.dao;
|
||||
|
||||
import com.ljsd.common.mogodb.MongoBase;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class MailManager extends MongoBase {
|
||||
private Map<Integer, Mail> mailMap = new ConcurrentHashMap<>();
|
||||
|
||||
public Map<Integer, Mail> getMailMap() {
|
||||
return mailMap;
|
||||
}
|
||||
|
||||
public void setMailMap(Map<Integer, Mail> mailMap) {
|
||||
this.mailMap = mailMap;
|
||||
}
|
||||
public void addMail(Mail mail) throws Exception {
|
||||
// mail.init(getRoot(), getMongoKey() + ".mailMap." + mail.getId());
|
||||
// updateString("mailMap." + mail.getId(), mail);
|
||||
// mailMap.put(item.getItemId(), item);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,8 @@ public class User extends MongoRoot {
|
|||
|
||||
private TeamPosManager teamPosManager;
|
||||
|
||||
private MailManager mailManager;
|
||||
|
||||
|
||||
|
||||
public User(int uid, PlayerManager playerManager, ItemManager itemManager,
|
||||
|
@ -28,6 +30,7 @@ public class User extends MongoRoot {
|
|||
this.heroManager = heroManager;
|
||||
this.mapManager = mapManager;
|
||||
this.teamPosManager = new TeamPosManager();
|
||||
this.mailManager = new MailManager();
|
||||
|
||||
//綁定关系
|
||||
playerManager.init(this, "playerManager", false);
|
||||
|
@ -35,6 +38,7 @@ public class User extends MongoRoot {
|
|||
heroManager.init(this, "heroManager", false);
|
||||
mapManager.init(this, "mapManager", false);
|
||||
teamPosManager.init(this,"teamPosManager",false);
|
||||
mailManager.init(this,"mailManager",false);
|
||||
}
|
||||
|
||||
public User(){
|
||||
|
@ -102,4 +106,12 @@ public class User extends MongoRoot {
|
|||
public void setTeamPosManager(TeamPosManager teamPosManager) {
|
||||
this.teamPosManager = teamPosManager;
|
||||
}
|
||||
|
||||
public MailManager getMailManager() {
|
||||
return mailManager;
|
||||
}
|
||||
|
||||
public void setMailManager(MailManager mailManager) {
|
||||
this.mailManager = mailManager;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,19 +15,20 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
|||
public class ItemUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(ItemUtil.class);
|
||||
//掉落
|
||||
public static CommonProto.Drop.Builder drop(User user, int dropGroupId, CommonProto.Drop.Builder drop) throws Exception {
|
||||
public static CommonProto.Drop.Builder drop(User user, int dropGroupId) throws Exception {
|
||||
CommonProto.Drop.Builder dropBuilder = CommonProto.Drop.newBuilder();
|
||||
SRewardGroup sRewardGroup = SRewardGroup.getsRewardItemMap().get(dropGroupId);
|
||||
if (sRewardGroup == null){
|
||||
return drop;
|
||||
return dropBuilder;
|
||||
}
|
||||
Map<Integer, Integer> itemMap = new HashMap<>();
|
||||
Map<Integer, Integer> cardMap = new HashMap<>();
|
||||
|
||||
selectDrop(sRewardGroup,itemMap,cardMap);
|
||||
|
||||
addItem(user,itemMap,drop);
|
||||
addCard(user,cardMap,drop);
|
||||
return drop;
|
||||
addItem(user,itemMap,dropBuilder);
|
||||
addCard(user,cardMap,dropBuilder);
|
||||
return dropBuilder;
|
||||
}
|
||||
|
||||
private static void selectDrop(SRewardGroup sRewardGroup,Map<Integer, Integer> itemMap, Map<Integer, Integer> cardMap) {
|
||||
|
@ -130,9 +131,9 @@ public class ItemUtil {
|
|||
ItemManager itemManager = user.getItemManager();
|
||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||
SItem sItem = SItem.getsItemMap().get (entry.getKey());
|
||||
// if (sItem == null){
|
||||
// continue;
|
||||
// }
|
||||
if (sItem == null){
|
||||
continue;
|
||||
}
|
||||
Item item = itemManager.getItem(entry.getKey());
|
||||
if (item == null){
|
||||
item = itemManager.newItem(entry.getKey(), entry.getValue());
|
||||
|
@ -141,11 +142,11 @@ public class ItemUtil {
|
|||
item.setItemNum(item.getItemNum() + entry.getValue());
|
||||
}
|
||||
}
|
||||
if (dropBuilder != null) {
|
||||
itemProtoList.add(CBean2Proto.getItem(item));
|
||||
}
|
||||
itemProtoList.add(CBean2Proto.getItem(item));
|
||||
}
|
||||
if (dropBuilder != null) {
|
||||
dropBuilder.addAllItemlist(itemProtoList);
|
||||
}
|
||||
dropBuilder.addAllItemlist(itemProtoList);
|
||||
//todo 为了测试 日后要删掉
|
||||
UserManager.ljsdMongoTemplate.lastUpdate();
|
||||
}
|
||||
|
@ -170,7 +171,7 @@ public class ItemUtil {
|
|||
}
|
||||
|
||||
|
||||
public static List<CommonProto.Item > getAllItem(User user,int index){
|
||||
public static List<CommonProto.Item > getAllItem(User user){
|
||||
List<CommonProto.Item > itemList = new ArrayList<>();
|
||||
ItemManager itemManager = user.getItemManager();
|
||||
Map<Integer, Item> itemMap = itemManager.getItemMap();
|
||||
|
@ -179,33 +180,9 @@ public class ItemUtil {
|
|||
itemList.add(CBean2Proto.getItem(entry.getValue()));
|
||||
}
|
||||
}
|
||||
listByPage(itemList,index);
|
||||
return itemList;
|
||||
}
|
||||
|
||||
private static void listByPage(List<CommonProto.Item> itemList,int pagesize) {
|
||||
int totalcount=itemList.size();
|
||||
int pagecount=0;
|
||||
int m=totalcount%pagesize;
|
||||
if (m>0){
|
||||
pagecount=totalcount/pagesize+1;
|
||||
}else{
|
||||
pagecount=totalcount/pagesize;
|
||||
}
|
||||
for(int i=1;i<=pagecount;i++){
|
||||
if (m==0){
|
||||
itemList = itemList.subList((i-1)*pagesize,pagesize*(i));
|
||||
}else{
|
||||
if (i==pagecount){
|
||||
itemList= itemList.subList((i-1)*pagesize,totalcount);
|
||||
}else{
|
||||
itemList= itemList.subList((i-1)*pagesize,pagesize*(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void addCard(User user,Map<Integer,Integer> cardMap,CommonProto.Drop.Builder dropBuilder) throws Exception {
|
||||
List<CommonProto.Hero> heroList = new CopyOnWriteArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry : cardMap.entrySet()) {
|
||||
|
|
|
@ -45,7 +45,7 @@ netty.tcpPort = 16080
|
|||
netty.chatTcpPort = 20001
|
||||
netty.logintcpPort = 18091
|
||||
netty.udpPort = 18092
|
||||
netty.udpTargetIp=127.0.0.1
|
||||
netty.udpTargetIp=60.1.1.212
|
||||
netty.udpTargetPort=10001
|
||||
netty.reconnectDelay=3000
|
||||
netty.bossThreadCount=1
|
||||
|
|
|
@ -18,7 +18,7 @@ public class NettyClient {
|
|||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(NettyClient.class);
|
||||
|
||||
private static int uid = 10000018;
|
||||
private static int uid = 10000022;
|
||||
private static int msgIndex = 1;
|
||||
private static int token=543242;
|
||||
|
||||
|
@ -44,7 +44,7 @@ public class NettyClient {
|
|||
handler.sendRequest_jieling(makeFinalMessage(gameMessage, MessageTypeProto.MessageType.LOGIN_REQUEST_VALUE));
|
||||
// handler.sendRequest_jieling(makeFinalMessage(getHero(), MessageTypeProto.MessageType.GET_HEROINFO_REQUEST_VALUE));
|
||||
// handler.sendRequest_jieling(makeFinalMessage(getRandomHero(), MessageTypeProto.MessageType.HERO_RAND_REQQUEST_VALUE));
|
||||
for (int i = 800; i< 900;i++){
|
||||
for (int i = 1000; i< 1500;i++){
|
||||
handler.sendRequest_jieling(makeFinalMessage(gmRequest(i), MessageTypeProto.MessageType.GM_REQUEST_VALUE));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue