fix family & task

back_recharge
wangyuan 2019-08-03 16:49:47 +08:00
parent 703a7686b9
commit eef97e054a
4 changed files with 154 additions and 34 deletions

View File

@ -23,7 +23,12 @@ public abstract class MongoBase {
}
public void updateString(String fieldName, Object value) {
MongoUpdateCacheThreadLocal.addUpdateRequest(this, mongoKey + "." + fieldName, value);
if("".equals(mongoKey)){
MongoUpdateCacheThreadLocal.addUpdateRequest(this, fieldName, value);
}else{
MongoUpdateCacheThreadLocal.addUpdateRequest(this, mongoKey + "." + fieldName, value);
}
}
public void removeString(String key) {

View File

@ -0,0 +1,65 @@
package com.ljsd.jieling.config;
import com.ljsd.jieling.logic.STableManager;
import com.ljsd.jieling.logic.Table;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Table(name ="BeginnerTask")
public class SBeginnerTask implements BaseConfig {
private int id;
private int taskType;
private int[][] taskValue;
private int[][] reward;
private int[] jump;
public static Map<Integer, SBeginnerTask> sBeginnerTaskCongigMap;
public static Map<Integer, List<SBeginnerTask>> sBeginnerByTypeMap;
@Override
public void init() throws Exception {
Map<Integer, SBeginnerTask> config = STableManager.getConfig(SBeginnerTask.class);
Map<Integer, List<SBeginnerTask>> configTmp = new HashMap<>();
for(SBeginnerTask sBeginnerTask : config.values()){
int taskType = sBeginnerTask.getTaskType();
if(!configTmp.containsKey(taskType)){
configTmp.put(taskType,new ArrayList<>());
}
configTmp.get(taskType).add(sBeginnerTask);
}
sBeginnerByTypeMap = configTmp;
sBeginnerTaskCongigMap = config;
}
public int getId() {
return id;
}
public int getTaskType() {
return taskType;
}
public int[][] getTaskValue() {
return taskValue;
}
public int[][] getReward() {
return reward;
}
public int[] getJump() {
return jump;
}
}

View File

@ -112,6 +112,10 @@ public class RedisKey {
public static final String FAMILY_ID = "FAMILY_ID";
public static final String OPERATE_FAMILY = "OPERATE_FAMILY";
public static final String OPERATE_FAMILY_APPLY = "OPERATE_FAMILY_APPLY";
public static final String OPERATE_FAMILY_APPLY_JOIN = "OPERATE_FAMILY_APPLY_JOIN";
public static String getKey(String type, String key, boolean withoutServerId) {
if (withoutServerId) {
return GameApplication.areaId + Delimiter_colon + type + Delimiter_colon + String.valueOf(key);

View File

@ -3,7 +3,12 @@ package com.ljsd.jieling.logic.family;
import com.ljsd.jieling.config.SErrorCodeEerverConfig;
import com.ljsd.jieling.config.SGuildSetting;
import com.ljsd.jieling.core.GlobalsDef;
import com.ljsd.jieling.db.redis.RedisKey;
import com.ljsd.jieling.db.redis.RedisUtil;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.ktbeans.KTGameType;
import com.ljsd.jieling.ktbeans.KtEventUtils;
import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
import com.ljsd.jieling.logic.OnlineUserManager;
import com.ljsd.jieling.logic.dao.GuilidManager;
import com.ljsd.jieling.logic.dao.UserManager;
@ -16,11 +21,13 @@ import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.Family;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.*;
public class GuildLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(GuildLogic.class);
public static int getMemberType(int targetUid, Map<Integer, Set<Integer>> members ){
@ -191,8 +198,20 @@ public class GuildLogic {
MessageUtil.sendErrorResponse(session,0,msgId,"公会不存在");
return;
}
guildInfo.addMembers(GlobalsDef.MEMBER,uid);
user.getPlayerInfoManager().setGuildId(guildId);
//todo 判读人数是否已达上限
boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY, Integer.toString(guildId), Integer.toString(uid), 500);
if(!isSuccess){
MessageUtil.sendErrorResponse(session,0, msgId,"请稍后重试");
return;
}
try {
applyToJoin(guildInfo,uid,false);
}catch (Exception e){
LOGGER.error("the exception={}",e);
}finally {
RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY,Integer.toString(guildId), Integer.toString(uid));
}
addGuildLog(guildInfo.getId(),GuildDef.Log.JOIN,user.getPlayerInfoManager().getNickName());
Family.FamilyJoinIndicaion build = Family.FamilyJoinIndicaion.newBuilder().setFamilyBaseInfo(CBean2Proto.getFamilyBaseInfo(guildInfo)).setFamilyUserInfo(CBean2Proto.getFamilyUserInfo(user, GlobalsDef.MEMBER)).build();
Family.FamilyJoinResponse response = Family.FamilyJoinResponse.newBuilder().setFamilyJoinIndicaion(build).build();
@ -304,39 +323,66 @@ public class GuildLogic {
return;
}
GuildInfo guildInfo = GuilidManager.guildInfoMap.get(guildId);
switch (type){
case 1: //全部同意
GuilidManager.removeApplyGuildInfos(guildId);
Map<Integer, Set<Integer>> members = guildInfo.getMembers();
int count = 0;
for(Set<Integer> memberOfType : members.values()){
count+=memberOfType.size();
}
Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(guildId, 0);
for(Integer addUid : applyGuildInfos.keySet()){
if(30-count<=0){
break;
boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY, Integer.toString(guildId), Integer.toString(uid), 500);
if(!isSuccess){
MessageUtil.sendErrorResponse(session,0, msgId,"请稍后重试");
return;
}
try {
switch (type){
case 1: //全部同意
GuilidManager.removeApplyGuildInfos(guildId);
Map<Integer, Set<Integer>> members = guildInfo.getMembers();
int count = 0;
for(Set<Integer> memberOfType : members.values()){
count+=memberOfType.size();
}
guildInfo.addMembers(GlobalsDef.MEMBER,addUid);
sendFamilyJoinIndication(addUid,guildInfo);
count++;
}
break;
case 2: //全部拒绝
GuilidManager.removeApplyGuildInfos(guildId);
break;
case 3: //同意一个
guildInfo.addMembers(GlobalsDef.MEMBER,applyId);
User targetUser = UserManager.getUser(applyId);
targetUser.getPlayerInfoManager().setGuildId(guildInfo.getId());
GuilidManager.removeOneApplyGuildInfos(guildId,applyId);
sendFamilyJoinIndication(applyId,guildInfo);
break;
case 4: //拒绝一个
GuilidManager.removeOneApplyGuildInfos(guildId,applyId);
break;
Map<Integer, GuildApply> applyGuildInfos = GuilidManager.getApplyGuildInfos(guildId, 0);
for(Integer addUid : applyGuildInfos.keySet()){
if(30-count<=0){
break;
}
applyToJoin(guildInfo,addUid,true);
count++;
}
break;
case 2: //全部拒绝
GuilidManager.removeApplyGuildInfos(guildId);
break;
case 3: //同意一个
applyToJoin(guildInfo,applyId,true);
break;
case 4: //拒绝一个
GuilidManager.removeOneApplyGuildInfos(guildId,applyId);
break;
}
}catch (Exception e){
LOGGER.error("the exception={}",e);
}finally {
RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY,Integer.toString(guildId), Integer.toString(uid));
}
MessageUtil.sendMessage(session,1,msgId,null,true);
}
private static void applyToJoin(GuildInfo guildInfo,int applyId,boolean isApply) throws Exception {
boolean isSuccess = RedisUtil.getInstence().tryGetDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN, Integer.toString(applyId), Integer.toString(applyId), 500);
if(!isSuccess){
return;
}
try {
guildInfo.addMembers(GlobalsDef.MEMBER,applyId);
User targetUser = UserManager.getUser(applyId);
targetUser.getPlayerInfoManager().setGuildId(guildInfo.getId());
}catch (Exception e){
LOGGER.error("the exception={}",e);
}finally {
RedisUtil.getInstence().releaseDistributedLock(RedisKey.OPERATE_FAMILY_APPLY_JOIN,Integer.toString(applyId), Integer.toString(applyId));
}
if(isApply){
GuilidManager.removeOneApplyGuildInfos(guildInfo.getId(),applyId);
sendFamilyJoinIndication(applyId,guildInfo);
}
}