Merge branch 'master_0.05' into master_dev
# Conflicts: # serverlogic/src/main/java/com/ljsd/jieling/handler/GetPlayerInfoHandler.java # serverlogic/src/main/java/com/ljsd/jieling/logic/activity/GmDialActivity.java # serverlogic/src/main/java/com/ljsd/jieling/logic/dao/PlayerManager.java # serverlogic/src/main/java/com/ljsd/jieling/logic/player/PlayerLogic.java # serverlogic/src/main/java/com/ljsd/jieling/logic/store/BuyGoodsNewLogic.javamaster_dev
commit
b5db821978
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"version":"6",
|
||||
"tables":"SpecialConfig"
|
||||
"version":"",
|
||||
"tables":""
|
||||
}
|
||||
|
|
@ -1,7 +1,5 @@
|
|||
{
|
||||
"version":"9",
|
||||
"version":"5",
|
||||
"classes":[
|
||||
{"name":"CBean2Proto.class","fullName":"com.ljsd.jieling.util.CBean2Proto"},
|
||||
{"name":"EquipLogic.class","fullName":"com.ljsd.jieling.logic.equip.EquipLogic"}
|
||||
]
|
||||
}
|
||||
|
|
@ -55,7 +55,8 @@ public class ChatLogic {
|
|||
*/
|
||||
public void getAllChatMessageInfo(ISession iSession, int chatType,long messageId) throws Exception {
|
||||
int uid = iSession.getUid();
|
||||
FriendManager friendManager = UserManager.getUser(uid).getFriendManager();
|
||||
User user = UserManager.getUser(uid);
|
||||
FriendManager friendManager = user.getFriendManager();
|
||||
List<Integer> friends = friendManager.getFriends();
|
||||
List<ChatProto.ChatInfo> chatInfoList = new ArrayList<>();
|
||||
switch (chatType){
|
||||
|
|
@ -66,14 +67,14 @@ public class ChatLogic {
|
|||
chatInfoList = MessageCache.worldMsg.getObjs(messageId);
|
||||
break;
|
||||
case 2://公会
|
||||
int guildId = UserManager.getUser(uid).getPlayerInfoManager().getGuildId();
|
||||
int guildId = user.getPlayerInfoManager().getGuildId();
|
||||
if(guildId!=0&&MessageCache.guildMsg.containsKey(guildId)){
|
||||
chatInfoList = MessageCache.guildMsg.get(guildId).getObjs(messageId);
|
||||
}
|
||||
break;
|
||||
case 3: //好友
|
||||
Map<Object, Object> hmget = RedisUtil.getInstence().hmget(GameApplication.serverId + RedisKey.CUser_Chat + uid);
|
||||
if (hmget != null && hmget.size() != 0){
|
||||
if (hmget != null && !hmget.isEmpty()){
|
||||
for (Map.Entry<Object, Object> entry :hmget.entrySet()){
|
||||
String[] split = entry.getKey().toString().split("#");
|
||||
String message = String.valueOf(entry.getValue());
|
||||
|
|
@ -82,16 +83,12 @@ public class ChatLogic {
|
|||
continue;
|
||||
}
|
||||
long time = Long.parseLong(split[1]);
|
||||
User user = UserManager.getUser(userid);
|
||||
chatInfoList.add(CBean2Proto.getChatInfoBuilder(user, message,time,0));
|
||||
chatInfoList.add(CBean2Proto.getChatInfoBuilder(userid, message,time,0));
|
||||
}
|
||||
}
|
||||
if (hmget!= null && !hmget.isEmpty()){
|
||||
//取出数据好友聊天数据后删除
|
||||
RedisUtil.getInstence().del(GameApplication.serverId + RedisKey.CUser_Chat + uid);
|
||||
}
|
||||
break;
|
||||
|
||||
case 4: //跨服
|
||||
int group = GlobleSystemLogic.getInstence().getCrossGroup();
|
||||
if(group==-1){
|
||||
|
|
@ -99,13 +96,12 @@ public class ChatLogic {
|
|||
return;
|
||||
}
|
||||
chatInfoList = MessageCache.getCrossMsg(messageId,String.valueOf(group));
|
||||
|
||||
break;
|
||||
default:{
|
||||
LOGGER.info("getAllChatMessageInfo wrong chatType=>{} uid=>{}", chatType, uid);
|
||||
}
|
||||
default:
|
||||
LOGGER.info("getAllChatMessageInfo wrong chatType=>{} uid=>{}", chatType, uid);
|
||||
break;
|
||||
}
|
||||
ChatProto.GetChatMessageInfoResponse getChatMessageInfoResponse = ChatProto.GetChatMessageInfoResponse
|
||||
ChatProto.GetChatMessageInfoResponse getChatMessageInfoResponse = ChatProto.GetChatMessageInfoResponse
|
||||
.newBuilder().addAllChatInfo(chatInfoList)
|
||||
.build();
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.GET_CHAT_MESSAGE_REPONSE_VALUE, getChatMessageInfoResponse, true);
|
||||
|
|
@ -153,7 +149,7 @@ public class ChatLogic {
|
|||
result[i]=c;
|
||||
}
|
||||
tmp = new String(result);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,tmp,nowTime,-1);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(),tmp,nowTime,-1);
|
||||
ChatProto.SendChatInfoResponse response = ChatProto.SendChatInfoResponse.newBuilder().setChatInfo(chatInfo).build();
|
||||
MessageUtil.sendMessage(iSession,1,msgId,response,true);
|
||||
return;
|
||||
|
|
@ -190,7 +186,7 @@ public class ChatLogic {
|
|||
mes[i]='*';
|
||||
}
|
||||
tmp = new String(mes);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,tmp,nowTime,-1);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(),tmp,nowTime,-1);
|
||||
ChatProto.SendChatInfoResponse response = ChatProto.SendChatInfoResponse.newBuilder().setChatInfo(chatInfo).build();
|
||||
MessageUtil.sendMessage(iSession,1,msgId,response,true);
|
||||
ReportUtil.onReportEvent(user, ReportEventEnum.SEND_MESSAGE.getType(),String.valueOf(chatType),message,new Date());
|
||||
|
|
@ -200,7 +196,7 @@ public class ChatLogic {
|
|||
switch (chatType){
|
||||
case 1: //世界
|
||||
long messageId = RedisUtil.getInstence().increment(GameApplication.serverId + RedisKey.CHAT_WORD_MSG_ID + GameApplication.serverId);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId);
|
||||
ChatProto.ChatInfo chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(),message,nowTime,messageId);
|
||||
|
||||
MessageCache.addWordMsg(chatInfo,messageId);
|
||||
break;
|
||||
|
|
@ -210,7 +206,7 @@ public class ChatLogic {
|
|||
if(guildId==0){
|
||||
throw new ErrorCodeException(ErrorCode.CHAT_NO_FAMILY);
|
||||
}
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user,message,nowTime,messageId);
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(),message,nowTime,messageId);
|
||||
MessageCache.addGuildMsg(chatInfo,messageId,guildId);
|
||||
break;
|
||||
case 3: //好友
|
||||
|
|
@ -222,7 +218,7 @@ public class ChatLogic {
|
|||
//现在好友推送
|
||||
if (OnlineUserManager.checkUidOnline(friendId)) {
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(friendId);
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user, message, nowTime, 0);
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(), message, nowTime, 0);
|
||||
sendChatInfoIndication = ChatProto.SendChatInfoIndication.newBuilder()
|
||||
.setChatInfo(chatInfo)
|
||||
.setType(1)
|
||||
|
|
@ -242,7 +238,7 @@ public class ChatLogic {
|
|||
}
|
||||
|
||||
messageId = RedisUtil.getInstence().increment( RedisKey.CHAT_CROSS_MSG_ID + group);
|
||||
chatInfo = CBean2Proto.getCrossChatInfoBuilder(user,message,nowTime,messageId);
|
||||
chatInfo = CBean2Proto.getChatInfoBuilder(user.getId(),message,nowTime,messageId);
|
||||
MessageCache.addCrossMsg(chatInfo,messageId,String.valueOf(group));
|
||||
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,10 @@ package com.ljsd.jieling.chat.messge;
|
|||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
import java.util.concurrent.locks.ReadWriteLock;
|
||||
import java.util.concurrent.locks.ReentrantLock;
|
||||
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||
|
||||
public class LoopQueue<T> {
|
||||
class Item{
|
||||
|
|
@ -19,93 +23,103 @@ public class LoopQueue<T> {
|
|||
|
||||
}
|
||||
}
|
||||
private int writeIndex;
|
||||
private Item[] queueList;
|
||||
private int maxlen = 0;
|
||||
private int getMaxLen =0;
|
||||
private long diffTime ;
|
||||
private int initLength =20;
|
||||
private final ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
|
||||
private final Lock writeLock = new ReentrantLock();
|
||||
private int writeIndex; // 这是共享资源的索引
|
||||
private final Item[] queueList; // 共享资源
|
||||
private int maxlen; // 假设的最大长度
|
||||
private long diffTime;// 时间差阈值,假设
|
||||
private int initLength = 20; // 假设的初始长度
|
||||
|
||||
public LoopQueue(int maxlen, int getMaxLen, long diffTime) {
|
||||
public LoopQueue(int maxlen, long diffTime) {
|
||||
this.maxlen = maxlen;
|
||||
queueList = (Item[])Array.newInstance(Item.class, maxlen);
|
||||
queueList = (Item[])Array.newInstance(Item.class, maxlen);
|
||||
for(int i=0; i<maxlen; i++){
|
||||
queueList[i] = new Item();
|
||||
}
|
||||
writeIndex = 0;
|
||||
this.getMaxLen = getMaxLen;
|
||||
this.diffTime = diffTime;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//添加一个新的元素到循环队列中
|
||||
public synchronized void push(T obj,long messageId) {
|
||||
this.queueList[writeIndex%maxlen].setObj(obj,messageId);
|
||||
writeIndex = writeIndex+1;
|
||||
public void push(T obj, long messageId) {
|
||||
// writeLock.lock();
|
||||
try {
|
||||
int index = writeIndex % maxlen;
|
||||
// 假设 setObj 是一个正确设置对象和消息 ID 的方法
|
||||
queueList[index].setObj(obj,messageId); // 或者使用 setObj 方法,如果它存在
|
||||
writeIndex++;
|
||||
} finally {
|
||||
// writeLock.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
//diffTime 允许的取到的最小时间差的数据,为-1时,则不校验时间差
|
||||
//getMaxLen 允许取到的最大数量
|
||||
public synchronized List<T> getObjs(long messageId) {
|
||||
public List<T> getObjs(long messageId) {
|
||||
List<T> objs = new ArrayList<>();
|
||||
int nextIndex = writeIndex%maxlen-1;
|
||||
int endIndex = writeIndex%maxlen;
|
||||
if(nextIndex==-1){
|
||||
nextIndex = maxlen - 1;
|
||||
}
|
||||
|
||||
boolean needCompareTime = (messageId == 0);
|
||||
long curTime = System.currentTimeMillis();
|
||||
while(queueList[nextIndex].obj != null && nextIndex != endIndex){
|
||||
// readWriteLock.readLock().lock();
|
||||
try {
|
||||
int nextIndex = (writeIndex - 1 + maxlen) % maxlen;
|
||||
int endIndex = writeIndex % maxlen;
|
||||
|
||||
if(!needCompareTime){
|
||||
//比较消息id
|
||||
if(messageId>=queueList[nextIndex].messgeId){
|
||||
long curTime = System.currentTimeMillis();
|
||||
|
||||
while (queueList[nextIndex].obj != null && nextIndex != endIndex) {
|
||||
if (!needCompareTime && messageId >= queueList[nextIndex].messgeId) {
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
if (needCompareTime) {
|
||||
if (objs.size() >= initLength ||
|
||||
(diffTime != -1 && (curTime - queueList[nextIndex].timestamp) >= diffTime)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (needCompareTime && objs.size() >= initLength ){
|
||||
break;
|
||||
}
|
||||
objs.add(0, queueList[nextIndex].obj);
|
||||
|
||||
if(needCompareTime){
|
||||
if(diffTime!=-1&& (curTime - queueList[nextIndex].timestamp) >= diffTime){
|
||||
if (objs.size() > maxlen) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
objs.add(0, queueList[nextIndex].obj);
|
||||
if(objs.size()>maxlen){
|
||||
break;
|
||||
}
|
||||
|
||||
nextIndex--;
|
||||
if(nextIndex == -1){
|
||||
nextIndex = maxlen - 1;
|
||||
nextIndex = (nextIndex - 1 + maxlen) % maxlen;
|
||||
}
|
||||
} finally {
|
||||
// readWriteLock.readLock().unlock();
|
||||
}
|
||||
if(!needCompareTime && objs.size()>getMaxLen){
|
||||
return objs.subList(0,getMaxLen);
|
||||
|
||||
// 后处理不需要在锁中进行
|
||||
if (!needCompareTime && objs.size() > maxlen) {
|
||||
return objs.subList(0, maxlen);
|
||||
}
|
||||
|
||||
return objs;
|
||||
}
|
||||
|
||||
public synchronized String toString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for(int i=0; i<maxlen; i++){
|
||||
builder.append(i);
|
||||
if(i == writeIndex%maxlen){
|
||||
builder.append("(writeIndex)");
|
||||
@Override
|
||||
public String toString() {
|
||||
// readWriteLock.readLock().lock();
|
||||
try {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < maxlen; i++) {
|
||||
builder.append(i);
|
||||
if (i == writeIndex % maxlen) {
|
||||
builder.append("(writeIndex)");
|
||||
}
|
||||
builder.append("->");
|
||||
if (queueList[i] == null) {
|
||||
builder.append("-1");
|
||||
} else {
|
||||
builder.append(queueList[i].toString()); // 确保obj有有效的toString方法
|
||||
}
|
||||
builder.append(",");
|
||||
}
|
||||
builder.append("->");
|
||||
if(queueList[i].obj == null){
|
||||
builder.append("-1");
|
||||
} else {
|
||||
builder.append(queueList[i].obj);
|
||||
}
|
||||
builder.append(",");
|
||||
return builder.toString();
|
||||
} finally {
|
||||
// readWriteLock.readLock().unlock();
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,23 +3,18 @@ package com.ljsd.jieling.chat.messge;
|
|||
import com.google.gson.Gson;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import org.luaj.vm2.ast.Str;
|
||||
import rpc.protocols.ChatProto;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class MessageCache {
|
||||
private static final int capuatiy =30;
|
||||
private static final int msgInterval = 24*3600*1000;
|
||||
private static final int perCaught= 30;
|
||||
|
||||
public static LoopQueue worldMsg = new LoopQueue(capuatiy,perCaught,-1);
|
||||
public static LoopQueue sysMsg = new LoopQueue(capuatiy,perCaught,msgInterval);
|
||||
public static LoopQueue worldMsg = new LoopQueue(capuatiy, -1);
|
||||
public static LoopQueue sysMsg = new LoopQueue(capuatiy, msgInterval);
|
||||
public static Map<Integer,LoopQueue> guildMsg = new ConcurrentHashMap();
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
|
|
@ -32,7 +27,7 @@ public class MessageCache {
|
|||
}
|
||||
public static void addGuildMsg(ChatProto.ChatInfo chatInfo,long messageId,int guildId){
|
||||
if(!guildMsg.containsKey(guildId)){
|
||||
guildMsg.put(guildId,new LoopQueue(capuatiy,perCaught,-1));
|
||||
guildMsg.put(guildId,new LoopQueue(capuatiy, -1));
|
||||
}
|
||||
guildMsg.get(guildId).push(chatInfo,messageId);
|
||||
}
|
||||
|
|
@ -44,53 +39,41 @@ public class MessageCache {
|
|||
RedisUtil.getInstence().hset(key,String.valueOf(index),gson.toJson(chatInfo));
|
||||
}
|
||||
|
||||
public static List<ChatProto.ChatInfo> getCrossMsg(long messageId,String group){
|
||||
String key = RedisKey.CHAT_CROSS_INFO_CACHE+group;
|
||||
Map<Integer,ChatProto.ChatInfo> map = new HashMap<>();
|
||||
Map<Object, Object> collect = RedisUtil.getInstence().hmget(key);
|
||||
collect.entrySet().forEach(o -> map.put(Integer.parseInt(o.getKey().toString()),
|
||||
gson.fromJson(o.getValue().toString(),ChatProto.ChatInfo.class)));
|
||||
public static List<ChatProto.ChatInfo> getCrossMsg(long messageId, String group) {
|
||||
String key = RedisKey.CHAT_CROSS_INFO_CACHE + group;
|
||||
Map<Object, Object> rawMap = RedisUtil.getInstence().hmget(key);
|
||||
|
||||
if (rawMap == null || rawMap.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<ChatProto.ChatInfo> objs = new ArrayList<>();
|
||||
Object obj = RedisUtil.getInstence().get(RedisKey.CHAT_CROSS_MSG_ID + group);
|
||||
if(obj==null){
|
||||
|
||||
if (obj == null) {
|
||||
return objs;
|
||||
}
|
||||
int writeIndex = Integer.parseInt(String.valueOf(obj));
|
||||
int nextIndex = writeIndex % capuatiy; // Assuming capacity is a static value or defined elsewhere
|
||||
|
||||
Integer nextIndex = writeIndex%capuatiy;
|
||||
|
||||
if(nextIndex==-1){
|
||||
nextIndex = capuatiy - 1;
|
||||
}
|
||||
if(collect.size()<=0){
|
||||
return objs;
|
||||
}
|
||||
boolean needCompareTime = (messageId == 0);
|
||||
|
||||
while(map.containsKey(nextIndex)){
|
||||
while (rawMap.containsKey(nextIndex)) {
|
||||
String rawValue = String.valueOf(rawMap.get(nextIndex));
|
||||
ChatProto.ChatInfo chatInfo = gson.fromJson(rawValue, ChatProto.ChatInfo.class);
|
||||
|
||||
ChatProto.ChatInfo o = map.get(nextIndex);
|
||||
if(!needCompareTime){
|
||||
//比较消息id
|
||||
if(messageId>=o.getMessageId()){
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
objs.add(0, o);
|
||||
if(objs.size()>perCaught){
|
||||
if (!needCompareTime && messageId >= chatInfo.getMessageId()) {
|
||||
break;
|
||||
}
|
||||
nextIndex--;
|
||||
if(nextIndex == -1){
|
||||
nextIndex = capuatiy - 1;
|
||||
}
|
||||
}
|
||||
if(!needCompareTime && objs.size()>perCaught){
|
||||
return objs.subList(0,perCaught);
|
||||
}
|
||||
|
||||
return objs;
|
||||
objs.add(0, chatInfo);
|
||||
|
||||
if (objs.size() > perCaught) {
|
||||
break;
|
||||
}
|
||||
|
||||
nextIndex = (nextIndex - 1 + capuatiy) % capuatiy;
|
||||
}
|
||||
return objs.size() > perCaught ? objs.subList(0, perCaught) : objs;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,9 +38,6 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
|
||||
//注释
|
||||
public <T> void save(int uid,T obj) throws Exception {
|
||||
// MongoRoot root = (MongoRoot)obj;
|
||||
// mongoTemplate.save(obj,root.getCollection());
|
||||
// root.setBsave(true);
|
||||
int serverIdByUid = AreaManager.getInstance().getServerIdByUid(uid);
|
||||
MongoTemplate otherMonogTemplate = getMongoTemplate(serverIdByUid);
|
||||
if (otherMonogTemplate == null) {
|
||||
|
|
@ -75,14 +72,8 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
if (mongoTemplate != null) {
|
||||
return mongoTemplate.findAll(clazz);
|
||||
}
|
||||
|
||||
// for (MongoTemplate mongoTemplate : MongoUtil.mongoTemplateMap.values()) {
|
||||
// List<T> all = mongoTemplate.findAll(clazz);
|
||||
// list.addAll(all);
|
||||
// }
|
||||
}
|
||||
return list;
|
||||
//return mongoTemplate.findAll(clazz,collectionName);
|
||||
}
|
||||
|
||||
public <T> List<T> findAllByCondition(Query query, Class<T> entityClass) {
|
||||
|
|
@ -149,7 +140,6 @@ public class LjsdMongoTemplate implements MongoUpdateImp {
|
|||
return otherMonogTemplate.findById(id,clazz,collectionName);
|
||||
}
|
||||
|
||||
|
||||
public <T> T findById(int id, Class<T> clazz) throws Exception {
|
||||
int serverIdByUid ;
|
||||
if(clazz.equals(GlobalSystemControl.class)||clazz.equals(ServerConfig.class)){
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ import com.ljsd.jieling.logic.dao.root.User;
|
|||
import com.ljsd.jieling.util.ConfigurableApplicationContextManager;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.SysUtil;
|
||||
import com.mongodb.DBObject;
|
||||
import com.mongodb.MongoClient;
|
||||
import org.bson.Document;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.data.annotation.Transient;
|
||||
|
|
@ -86,22 +88,37 @@ public class MongoUtil {
|
|||
}
|
||||
|
||||
//todo 慢查 需要修改
|
||||
public List<User> getRandomUsers(int size, int uid, int level) throws Exception {
|
||||
public List<User> getRandomUsers(int size, int uid, int level) {
|
||||
// 验证size参数的有效性
|
||||
if (size <= 0) {
|
||||
return null;
|
||||
return Collections.emptyList();
|
||||
}
|
||||
int randomLevel = MathUtils.random(5, 20);
|
||||
Criteria criatira = new Criteria();
|
||||
int minLevel = level - randomLevel;
|
||||
minLevel = Math.max(minLevel, 5);
|
||||
int maxLevel = level + randomLevel;
|
||||
long befor3Day = System.currentTimeMillis() - BEFOR_3_DAY;
|
||||
|
||||
criatira.andOperator(Criteria.where("id").nin(uid),//不包含自己
|
||||
Criteria.where("playerManager.level").gte(minLevel), Criteria.where("playerManager.level").lte(maxLevel),
|
||||
Criteria.where("playerManager.loginTime").gte(befor3Day));
|
||||
Query query = new Query(criatira).limit(size * 2 + 1);
|
||||
// 随机等级差异的计算
|
||||
int randomLevel = MathUtils.random(5, 20);
|
||||
int minLevel = Math.max(level - randomLevel, 5);
|
||||
int maxLevel = level + randomLevel;
|
||||
|
||||
// 计算三天前的时间点
|
||||
long threeDaysAgo = System.currentTimeMillis() - BEFOR_3_DAY;
|
||||
|
||||
// 构建查询条件
|
||||
Criteria criteria = Criteria.where("id").nin(uid)
|
||||
.and("playerManager.level").gte(minLevel).lte(maxLevel)
|
||||
.and("playerManager.loginTime").gte(threeDaysAgo);
|
||||
|
||||
// 创建查询对象,并设置限制条件
|
||||
int length = size * 2 + 1;
|
||||
Query query = Query.query(criteria).limit(length);
|
||||
|
||||
// 限定返回的字段,只返回需要的字段可以提高效率
|
||||
query.fields().include("playerManager");
|
||||
|
||||
// MongoTemplate mongoTemplate = mongoTemplateMap.get(GameApplication.serverId);
|
||||
// DBObject explainResult = mongoTemplate.getCollection("user").find(query.getQueryObject()).explain();
|
||||
// LOGGER.info("随机玩家mongo检查:{}",explainResult.toString());
|
||||
|
||||
// 执行查询
|
||||
return this.myMongoTemplate.findAllByCondition(query, User.class);
|
||||
}
|
||||
|
||||
|
|
@ -262,7 +279,7 @@ public class MongoUtil {
|
|||
mongoTemplate = new MongoTemplate(mongoDbFactory, mappingMongoConverter);
|
||||
mongoTemplateMap.put(serverId,mongoTemplate);
|
||||
}
|
||||
return mongoTemplate;
|
||||
return mongoTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -60,6 +60,11 @@ public class EquipManager extends MongoBase {
|
|||
updateString("equipMap." + equip.getId(), equip);
|
||||
}
|
||||
|
||||
public void updateEquip(PropertyItem equip){
|
||||
equipMap.put(equip.getId(),equip);
|
||||
updateString("equipMap", equipMap);
|
||||
}
|
||||
|
||||
public void removeEquip(String equipId){
|
||||
if (!equipMap.containsKey(equipId)){
|
||||
return;
|
||||
|
|
@ -130,9 +135,11 @@ public class EquipManager extends MongoBase {
|
|||
|
||||
public void loadFaxiang(String key,String heroId) {
|
||||
PropertyItem faxiang = getEquip(key);
|
||||
if (faxiang != null){
|
||||
faxiang.setHeroId(heroId);
|
||||
if (faxiang == null){
|
||||
return;
|
||||
}
|
||||
faxiang.setHeroId(heroId);
|
||||
updateEquip(faxiang);
|
||||
}
|
||||
|
||||
public void unloadFaxiang(String key) {
|
||||
|
|
|
|||
|
|
@ -24,7 +24,6 @@ public class Item extends MongoBase {
|
|||
}
|
||||
|
||||
|
||||
|
||||
public int getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import com.ljsd.jieling.handler.map.MapManager;
|
|||
import com.ljsd.jieling.jbean.ActivityManager;
|
||||
import com.ljsd.jieling.jbean.gm.GmActivityManager;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import org.springframework.data.mongodb.core.index.CompoundIndex;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
|
||||
@Document
|
||||
@CompoundIndex(def = "{'playerManager.level' : 1, 'playerManager.loginTime': 1}", name = "level_loginTime_idx")
|
||||
public class User {
|
||||
|
||||
public static final String _COLLECTION_NAME = "user";
|
||||
|
|
|
|||
|
|
@ -16,6 +16,9 @@ public class ItemLog {
|
|||
private String id;
|
||||
@Field(value = "uid")
|
||||
private int uid;
|
||||
/**
|
||||
* 0 增加,1 减少
|
||||
*/
|
||||
@Field(value = "type")
|
||||
private int type;
|
||||
@Field(value = "level")
|
||||
|
|
@ -46,6 +49,17 @@ public class ItemLog {
|
|||
this.itemTotalNum = itemTotalNum;
|
||||
}
|
||||
|
||||
public ItemLog(User user, int type, int reason, int itemId, long itemNum, long itemTotalNum) {
|
||||
this.uid = user.getId();
|
||||
this.type = type;
|
||||
this.level = user.getPlayerInfoManager().getLevel();
|
||||
this.time = String.valueOf(TimeUtils.now());
|
||||
this.reason = reason;
|
||||
this.itemId = itemId;
|
||||
this.itemNum = itemNum;
|
||||
this.itemTotalNum = itemTotalNum;
|
||||
}
|
||||
|
||||
public ItemLog(User user, int type, int reason, Item item, long itemNum) {
|
||||
this.uid = user.getId();
|
||||
this.type = type;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import com.ljsd.jieling.core.GlobalsDef;
|
|||
import com.ljsd.jieling.core.VipPrivilegeType;
|
||||
import com.ljsd.jieling.dataReport.reportBeans_37.ChatContentType;
|
||||
import com.ljsd.jieling.db.mongo.AreaManager;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.db.redis.RedisKey;
|
||||
import com.ljsd.jieling.db.redis.RedisUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
|
|
@ -57,6 +58,7 @@ import util.MathUtils;
|
|||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public class PlayerLogic {
|
||||
|
|
|
|||
|
|
@ -788,42 +788,24 @@ public class CBean2Proto {
|
|||
.build();
|
||||
}
|
||||
|
||||
|
||||
public static ChatProto.ChatInfo getChatInfoBuilder(User user,String message,long time,long messageId) {
|
||||
public static ChatProto.ChatInfo getChatInfoBuilder(int uid,String message,long time,long messageId) {
|
||||
ChatProto.ChatInfo.Builder chatInfo = ChatProto.ChatInfo.newBuilder();
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
chatInfo.setSenderId(user.getId());
|
||||
chatInfo.setSenderName(playerInfoManager.getNickName());
|
||||
chatInfo.setSenderlevel(playerInfoManager.getLevel());
|
||||
chatInfo.setSendervip(playerInfoManager.getVipLevel());
|
||||
chatInfo.setTimes(time);
|
||||
chatInfo.setMsg(message);
|
||||
chatInfo.setHead(playerInfoManager.getHead());
|
||||
chatInfo.setFrame(playerInfoManager.getHeadFrame());
|
||||
chatInfo.setSoulVal(playerInfoManager.getMaxForce());
|
||||
chatInfo.setMessageId(messageId);
|
||||
chatInfo.setUserTitle(playerInfoManager.getUserTitle());
|
||||
chatInfo.setPracticeLevel(user.getHeroManager().getPracticeLevel());
|
||||
return chatInfo.build();
|
||||
}
|
||||
|
||||
public static ChatProto.ChatInfo getCrossChatInfoBuilder(User user,String message,long time,long messageId){
|
||||
ChatProto.ChatInfo.Builder chatInfo = ChatProto.ChatInfo.newBuilder();
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
chatInfo.setSenderId(user.getId());
|
||||
chatInfo.setSenderName(playerInfoManager.getNickName());
|
||||
chatInfo.setSenderlevel(playerInfoManager.getLevel());
|
||||
chatInfo.setSendervip(playerInfoManager.getVipLevel());
|
||||
chatInfo.setTimes(time);
|
||||
chatInfo.setMsg(message);
|
||||
chatInfo.setHead(playerInfoManager.getHead());
|
||||
chatInfo.setFrame(playerInfoManager.getHeadFrame());
|
||||
chatInfo.setSoulVal(playerInfoManager.getMaxForce());
|
||||
chatInfo.setMessageId(messageId);
|
||||
chatInfo.setUserTitle(playerInfoManager.getUserTitle());
|
||||
chatInfo.setPracticeLevel(user.getHeroManager().getPracticeLevel());
|
||||
String serverName = CrossServiceLogic.simplifyServerName(GameApplication.serverId);
|
||||
chatInfo.setServerName(serverName);
|
||||
CSPlayer csPlayer = CrossServiceLogic.getPlayerByRedis(uid);
|
||||
if (csPlayer != null){
|
||||
chatInfo.setSenderId(csPlayer.getUserId());
|
||||
chatInfo.setSenderName(csPlayer.getName());
|
||||
chatInfo.setSenderlevel(csPlayer.getLevel());
|
||||
chatInfo.setTimes(time);
|
||||
chatInfo.setMsg(message);
|
||||
chatInfo.setHead(csPlayer.getHead());
|
||||
chatInfo.setFrame(csPlayer.getHeadFrame());
|
||||
chatInfo.setSoulVal(csPlayer.getMaxFore());
|
||||
chatInfo.setMessageId(messageId);
|
||||
chatInfo.setUserTitle(csPlayer.getUserTitle());
|
||||
chatInfo.setPracticeLevel(csPlayer.getPracticeLevel());
|
||||
String serverName = CrossServiceLogic.getServerName(csPlayer.getServerId());
|
||||
chatInfo.setServerName(serverName);
|
||||
}
|
||||
return chatInfo.build();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ public class ItemUtil {
|
|||
addCard(user, itemObj.getCardMap(), dropBuilder,reason);
|
||||
addEquip(user, itemObj.getEquipMap(), dropBuilder,reason);
|
||||
addSpecialMonster(user,itemObj,dropBuilder,reason);
|
||||
addMagicSoldier(user,itemObj.getMagicSoldierMap(),dropBuilder);
|
||||
addMagicSoldier(user,itemObj.getMagicSoldierMap(),dropBuilder,reason);
|
||||
addGemNew(user,itemObj.getGemNewMap(),dropBuilder);
|
||||
}
|
||||
|
||||
|
|
@ -1189,18 +1189,20 @@ public class ItemUtil {
|
|||
|
||||
StringBuilder reward = new StringBuilder();
|
||||
List<CommonProto.Equip> jewelList = new CopyOnWriteArrayList<>();
|
||||
Map<String, PropertyItem> propertyItemMap = user.getEquipManager().getEquipMap();
|
||||
// jewelMap 为了做宝物礼包推送<宝物品质, 数量>
|
||||
ArrayList<Integer> jewelPush = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry : equipMap.entrySet()) {
|
||||
Integer key = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
long count1 = propertyItemMap.values().stream().filter(v -> v.getEquipId() == key).count();
|
||||
int itemType = SItem.getsItemMap().get(key).getItemType();
|
||||
if(!ifPropertyItem(itemType)){
|
||||
continue;
|
||||
}
|
||||
for (int i = 0; i < count; i++) {
|
||||
// 到达装备上限,发送邮件,不走背包
|
||||
if (user.getEquipManager().getEquipMap().size() >= gameSetting.getEquipNumlimit()) {
|
||||
if (propertyItemMap.size() >= gameSetting.getEquipNumlimit()) {
|
||||
reward.append(key).append("#1").append("|");
|
||||
if (reward.length() > 0){
|
||||
reward = new StringBuilder(reward.substring(0, reward.length() - 1));
|
||||
|
|
@ -1211,6 +1213,8 @@ public class ItemUtil {
|
|||
ReportUtil.onReportEvent(user,ReportEventEnum.GET_TREASURE.getType(), key,reason);
|
||||
}
|
||||
}
|
||||
// 后台日志
|
||||
ItemLogic.getInstance().addItemLog(new ItemLog(user, 0, reason, key, count, count+count1));
|
||||
}
|
||||
|
||||
if (reward.length() > 0) {
|
||||
|
|
@ -1298,42 +1302,42 @@ public class ItemUtil {
|
|||
int hasHeroNum = user.getHeroManager().getHeroMap().size();
|
||||
String title = SErrorCodeEerverConfig.getI18NMessage("card_bag_limit_title");
|
||||
String content = SErrorCodeEerverConfig.getI18NMessage("card_bag_limit_txt");
|
||||
int nowInt = TimeUtils.nowInt();
|
||||
if (hasHeroNum >= gameSetting.getHeroNumlimit()){
|
||||
String reward = getLimitReward(cardMap);
|
||||
int nowTime =(int) (TimeUtils.now()/1000);
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,reward,nowTime,Global.MAIL_EFFECTIVE_TIME);
|
||||
MailLogic.getInstance().sendMail(user.getId(),title,content,reward,nowInt,Global.MAIL_EFFECTIVE_TIME);
|
||||
MessageUtil.nofityBagIsFull(user);
|
||||
return;
|
||||
}
|
||||
List<CommonProto.Hero> heroList = new CopyOnWriteArrayList<>();
|
||||
StringBuilder reward = new StringBuilder();
|
||||
for (Map.Entry<Integer, Integer> entry : cardMap.entrySet()) {
|
||||
Integer itemId = entry.getKey();
|
||||
int count = entry.getValue();
|
||||
for (int i = 0; i < count; i++) {
|
||||
if (user.getHeroManager().getHeroMap().size() >= gameSetting.getHeroNumlimit()) {
|
||||
if (reward.length() == 0){
|
||||
reward = new StringBuilder(entry.getKey() + "#1");
|
||||
reward = new StringBuilder(itemId + "#1");
|
||||
}else{
|
||||
reward.append("|").append(entry.getKey()).append("#1");
|
||||
reward.append("|").append(itemId).append("#1");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
addCard(user, entry.getKey(),heroList,reason);
|
||||
SItem sItem = SItem.getsItemMap().get(entry.getKey());
|
||||
addCard(user, itemId,heroList,reason);
|
||||
SItem sItem = SItem.getsItemMap().get(itemId);
|
||||
extraDropAop(user,dropBuilder,sItem);
|
||||
}
|
||||
// 回退所得神将不更新任务或活动
|
||||
if (reason == BIReason.HERO_RETURN) {
|
||||
continue;
|
||||
}
|
||||
fiveStarEvent(user,entry.getKey());
|
||||
fiveStarEvent(user, itemId);
|
||||
if(reason != BIReason.HERO_RANDOM){
|
||||
fiveStarPushByCombine(user,entry.getKey(),count);
|
||||
fiveStarPushByCombine(user, itemId,count);
|
||||
}
|
||||
}
|
||||
if (reward.length() > 0) {
|
||||
int nowTime = (int) (TimeUtils.now() / 1000);
|
||||
MailLogic.getInstance().sendMail(user.getId(), title, content, reward.toString(), nowTime, Global.MAIL_EFFECTIVE_TIME);
|
||||
MailLogic.getInstance().sendMail(user.getId(), title, content, reward.toString(), nowInt, Global.MAIL_EFFECTIVE_TIME);
|
||||
MessageUtil.nofityBagIsFull(user);
|
||||
}
|
||||
dropBuilder.addAllHero(heroList);
|
||||
|
|
@ -1866,16 +1870,20 @@ public class ItemUtil {
|
|||
if(itemObj.getSpecialMonsterMap().isEmpty()){
|
||||
return;
|
||||
}
|
||||
Map<String, Pokemon> pokemonMap = user.getPokemonManager().getPokemonMap();
|
||||
for(Map.Entry<Integer,Integer> entry:itemObj.getSpecialMonsterMap().entrySet()){
|
||||
for(int i = 0 ; i <entry.getValue();i++){
|
||||
Pokemon pokemon = new Pokemon(user.getId(),entry.getKey());
|
||||
Integer itemId = entry.getKey();
|
||||
Integer number = entry.getValue();
|
||||
long count = pokemonMap.values().stream().filter(v -> v.getTmpId() == itemId).count();
|
||||
for(int i = 0; i < number; i++){
|
||||
Pokemon pokemon = new Pokemon(user.getId(), itemId);
|
||||
user.getPokemonManager().addPokemon(pokemon);
|
||||
if(!user.getPokemonManager().getPokemonGot().contains(pokemon.getTmpId())){
|
||||
user.getPokemonManager().addPokemonGot(pokemon.getTmpId());
|
||||
}
|
||||
dropBuilder.addPokemon(CBean2Proto.getPokemon(pokemon));
|
||||
SSpiritAnimal animal = STableManager.getConfig(SSpiritAnimal.class).get(entry.getKey());
|
||||
ReportUtil.onReportEvent(user,ReportEventEnum.GET_BEAST.getType(),entry.getKey(),animal.getQuality(),reason);
|
||||
SSpiritAnimal animal = STableManager.getConfig(SSpiritAnimal.class).get(itemId);
|
||||
ReportUtil.onReportEvent(user,ReportEventEnum.GET_BEAST.getType(), itemId,animal.getQuality(),reason);
|
||||
if (animal.getQuality() >= SSpecialConfig.getIntegerValue(SSpecialConfig.ANIMAL_BROADCAST_QUALITY)&&reason!=BIReason.COMPOS_HERO_REWARD) { //策划资质改成星级
|
||||
String nameColor = user.getPlayerInfoManager().getNameColor();
|
||||
String message = SErrorCodeEerverConfig.getI18NMessageNeedConvert("animal_get_broadcast_content",
|
||||
|
|
@ -1886,6 +1894,8 @@ public class ItemUtil {
|
|||
}
|
||||
}
|
||||
}
|
||||
// 后台日志
|
||||
ItemLogic.getInstance().addItemLog(new ItemLog(user, 0, reason, itemId, count, count+number));
|
||||
}
|
||||
// 触发任务,东海寻仙
|
||||
user.getUserMissionManager().onGameEvent(user,GameEvent.ONE_MISSION_TYPE_CONSUME,MissionType.HAVE_ID_STAR_LV_POKEMON_NUM);
|
||||
|
|
@ -1894,17 +1904,23 @@ public class ItemUtil {
|
|||
/**
|
||||
* 掉落神兵
|
||||
*/
|
||||
private static void addMagicSoldier(User user,Map<Integer,Integer> map,CommonProto.Drop.Builder dropBuilder) {
|
||||
private static void addMagicSoldier(User user,Map<Integer,Integer> map,CommonProto.Drop.Builder dropBuilder, int reason) {
|
||||
if(map == null || map.isEmpty()){
|
||||
return;
|
||||
}
|
||||
MagicSoldierManager manager = user.getMagicSoldierManager();
|
||||
Map<String, MagicSoldier> soldierMap = manager.getMagicSoldierMap();
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
for (int i = 0; i < entry.getValue(); i++) {
|
||||
MagicSoldier soldier = new MagicSoldier(user.getId(), entry.getKey());
|
||||
Integer itemId = entry.getKey();
|
||||
Integer number = entry.getValue();
|
||||
long count = soldierMap.values().stream().filter(v -> v.getTmpId() == itemId).count();
|
||||
for (int i = 0; i < number; i++) {
|
||||
MagicSoldier soldier = new MagicSoldier(user.getId(), itemId);
|
||||
manager.setMagicSoldier(soldier);
|
||||
dropBuilder.addMagicSoldier(CBean2Proto.toBeanMagicSoldier(soldier));
|
||||
}
|
||||
// 后台日志
|
||||
ItemLogic.getInstance().addItemLog(new ItemLog(user, 0, reason, itemId, count, count+number));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue