lvxinran 2020-08-16 14:21:45 +08:00
commit 1bbf5bc010
11 changed files with 354 additions and 54 deletions

View File

@ -24,12 +24,22 @@ public abstract class MongoBase implements Serializable {
}
public void updateString(String fieldName, Object value) {
if("".equals(mongoKey)){
MongoUpdateCacheThreadLocal.addUpdateRequest(this, fieldName, value);
}else{
MongoUpdateCacheThreadLocal.addUpdateRequest(this, mongoKey + "." + fieldName, value);
if(null == value){
if("".equals(mongoKey)){
MongoUpdateCacheThreadLocal.removeRequest(this, fieldName);
}else{
MongoUpdateCacheThreadLocal.removeRequest(this, mongoKey + "." + fieldName);
}
}else {
if("".equals(mongoKey)){
MongoUpdateCacheThreadLocal.addUpdateRequest(this, fieldName, value);
}else{
MongoUpdateCacheThreadLocal.addUpdateRequest(this, mongoKey + "." + fieldName, value);
}
}
}
public void removeSubString(String key) {

View File

@ -145,6 +145,8 @@ public interface BIReason {
int EQUIP_UNLOAD_REWARD = 79;//卸下装备
int ESPECIAL_BACK = 80;//法宝归元获得
int HERO_CHANGE= 81;//抽卡
int ADVENTURE_UPLEVEL_CONSUME = 1000;//秘境升级
int SECRETBOX_CONSUME = 1001;//秘盒抽卡

View File

@ -0,0 +1,36 @@
package com.ljsd.jieling.handler.hero;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
/**
* Description:
* Author: zsx
* CreateDate: 2020/8/10 10:51
*/
public class CancelHeroChangeRequestHandler extends BaseHandler<HeroInfoProto.CancelHeroChangeRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return null;
}
@Override
public GeneratedMessage processWithProto(int uid, HeroInfoProto.CancelHeroChangeRequest proto) throws Exception {
User user = UserManager.getUser(uid);
Hero hero = user.getHeroManager().getHero(proto.getHeroId());
if (hero == null){
throw new ErrorCodeException( ErrorCode.ITEM_DECOMPOSE_NO_HERO);
}
hero.setChangeId(0);
return HeroInfoProto.CancelHeroChangeResponse.newBuilder().build();
}
}

View File

@ -0,0 +1,73 @@
package com.ljsd.jieling.handler.hero;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.expedition.ExpeditionLogic;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.CBean2Proto;
import com.ljsd.jieling.util.ItemUtil;
import config.SCHero;
import config.SSpecialConfig;
/**
* Description: des
* Author: zsx
* CreateDate: 2020/8/10 10:51
*/
public class DoHeroChangeRequestHandler extends BaseHandler<HeroInfoProto.DoHeroChangeRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return null;
}
@Override
public GeneratedMessage processWithProto(int uid, HeroInfoProto.DoHeroChangeRequest proto) throws Exception {
User user = UserManager.getUser(uid);
Hero hero = user.getHeroManager().getHero(proto.getHeroId());
if (hero == null){
throw new ErrorCodeException( ErrorCode.ITEM_DECOMPOSE_NO_HERO);
}
if(hero.getChangeId()==0){
throw new ErrorCodeException("未置换");
}
//check lock
if(hero.getIsLock() == 1){
throw new ErrorCodeException( ErrorCode.ITEM_DECOMPOSE_HERO_LOCK);
}
//check cfg
SCHero hero1 = SCHero.getsCHero().get(hero.getTemplateId());
if(null == hero1){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
// int[][] ints = new int[1][2];
// ints[0][0]=hero.getChangeId();
// ints[0][1]= 1;
//check in team
int[] teamId = SSpecialConfig.getOnceArrayValue(SSpecialConfig.HERO_RESOLVE_LICENCE);
boolean battleArray = HeroLogic.getInstance().isBattleArray(user, proto.getHeroId(),teamId);
if (!battleArray){
throw new ErrorCodeException(ErrorCode.ITEM_DECOMPOSE_HERO_TEAM);
}
user.getHeroManager().removeHero(uid,hero.getId());
CommonProto.Drop.Builder drop = CommonProto.Drop.newBuilder();
//random tempid
Hero newHero = new Hero(uid,hero.getChangeId(),hero.getStar(),hero);
user.getHeroManager().addHero(newHero);
drop.addHero(CBean2Proto.getHero(newHero));
return HeroInfoProto.DoHeroChangeResponse.newBuilder().setDrop(drop).build();
}
}

View File

@ -0,0 +1,120 @@
package com.ljsd.jieling.handler.hero;
import com.google.protobuf.GeneratedMessage;
import com.ljsd.jieling.exception.ErrorCode;
import com.ljsd.jieling.exception.ErrorCodeException;
import com.ljsd.jieling.globals.BIReason;
import com.ljsd.jieling.handler.BaseHandler;
import com.ljsd.jieling.logic.dao.Hero;
import com.ljsd.jieling.logic.dao.TeamPosHeroInfo;
import com.ljsd.jieling.logic.dao.UserManager;
import com.ljsd.jieling.logic.dao.root.User;
import com.ljsd.jieling.logic.hero.HeroLogic;
import com.ljsd.jieling.logic.player.PlayerLogic;
import com.ljsd.jieling.protocols.CommonProto;
import com.ljsd.jieling.protocols.HeroInfoProto;
import com.ljsd.jieling.protocols.MessageTypeProto;
import com.ljsd.jieling.util.ItemUtil;
import config.SCHero;
import config.SLotteryRewardConfig;
import config.SLotterySetting;
import config.SSpecialConfig;
import manager.STableManager;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;
/**
* Description: des
* Author: zsx
* CreateDate: 2020/8/10 10:51
*/
public class SaveHeroChangeRequestHandler extends BaseHandler<HeroInfoProto.SaveHeroChangeRequest> {
@Override
public MessageTypeProto.MessageType getMessageCode() {
return null;
}
@Override
public GeneratedMessage processWithProto(int uid, HeroInfoProto.SaveHeroChangeRequest proto) throws Exception {
User user = UserManager.getUser(uid);
Hero hero = user.getHeroManager().getHero(proto.getHeroId());
if (hero == null){
throw new ErrorCodeException( ErrorCode.ITEM_DECOMPOSE_NO_HERO);
}
//check lock
if(hero.getIsLock() == 1){
throw new ErrorCodeException( ErrorCode.ITEM_DECOMPOSE_HERO_LOCK);
}
//check cfg
SCHero hero1 = SCHero.getsCHero().get(hero.getTemplateId());
if(null == hero1){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
//check in team
int[] teamId = SSpecialConfig.getOnceArrayValue(SSpecialConfig.HERO_RESOLVE_LICENCE);
AtomicBoolean inTeams = HeroLogic.getInstance().isInTeams(user, proto.getHeroId(), teamId);
if(!inTeams.get()){
throw new ErrorCodeException(ErrorCode.ITEM_DECOMPOSE_HERO_TEAM);
}
int propertyName = hero1.getPropertyName();
int heroStar = hero.getStar();
Map<Integer, Integer> integerIntegerMap = SLotterySetting.getChangeIds().get(heroStar);
if(null == integerIntegerMap|| integerIntegerMap.size() ==0){
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
int type =integerIntegerMap.get(propertyName);
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
int perCount = sLotterySetting.getPerCount();
//check item
boolean enoughCost = false;
for (int[] cost:sLotterySetting.getCostItem()){
int [][] costItems = new int[][]{cost};
enoughCost = ItemUtil.itemCost(user, costItems,BIReason.RANDOM_HERO_CONSUME,type);
if(enoughCost){
break;
}
}
if(!enoughCost){
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
}
//random Hero
int result =hero.getTemplateId();
int j=0;
while (j<1000&&result==hero.getTemplateId()){
j++;
//所有获得物品
int[][] resultRandom = new int[perCount][];
//进行抽取
for(int i = 0 ;i<perCount;i++){
int rewardId = HeroLogic.randomOne(user, type);
SLotteryRewardConfig sLotteryRewardConfig = STableManager.getConfig(SLotteryRewardConfig.class).get(rewardId);
resultRandom[i] =sLotteryRewardConfig.getReward();
}
result = resultRandom[0][0];
}
if(result==0){
System.out.println("j = " + j+"result = " + result+"hero = " + hero.getTemplateId());
LOGGER.error("随机失败"+j);
throw new ErrorCodeException(ErrorCode.CFG_NULL);
}
System.out.println("j = " + j+"result = " + result+"hero = " + hero.getTemplateId());
hero.getTemplateId();
hero.setChangeId(result);
return HeroInfoProto.SaveHeroChangeResponse.newBuilder().setHeroTempId(result).build();
}
}

View File

@ -47,7 +47,7 @@ public class Hero extends MongoBase {
private int isLock;
private int createType ;
private int changeId ;
private Set<String> jewelInfo = new HashSet<>();
public Hero(){
@ -189,7 +189,13 @@ public class Hero extends MongoBase {
public Map<Integer, Integer> getSoulEquipByPositionMap() {
return soulEquipByPositionMap==null?new HashMap<>():soulEquipByPositionMap;
if(soulEquipByPositionMap == null){
Map<Integer,Integer> map = new HashMap<>();
updateString("soulEquipByPositionMap" ,map);
return map;
}else {
return soulEquipByPositionMap;
}
}
public void updateSoulEquipPositionMap(int position,int equipId) {
@ -283,5 +289,11 @@ public class Hero extends MongoBase {
}
public void setChangeId(int changeId) {
this.changeId = changeId;
}
public int getChangeId() {
return changeId;
}
}

View File

@ -253,6 +253,8 @@ public class HeroLogic{
for(int i = 0;i<tenTimesMustGetItem.length;i++) {
resultRandom[i+index+1] = tenTimesMustGetItem[i];
}
Poster.getPoster().dispatchEvent(new RandomCardEvent(user.getId(),sLotterySetting.getActivityId(),heroManager.getRandomPoolByType().get(sLotterySetting.getMergePool()),sLotterySetting.getPerCount()));
// //1群英招募
HeroInfoProto.HeroRandResponse.Builder builder = HeroInfoProto.HeroRandResponse.newBuilder();
@ -267,6 +269,8 @@ public class HeroLogic{
System.out.println(System.currentTimeMillis()-time);
}
/**
*
* @param user
@ -274,7 +278,7 @@ public class HeroLogic{
* @return
* @throws Exception
*/
private int randomOne(User user,int type) throws Exception {
public static int randomOne(User user,int type) throws Exception {
SLotterySetting sLotterySetting = STableManager.getConfig(SLotterySetting.class).get(type);
int mergePool = sLotterySetting.getMergePool();
List<SLotterySpecialConfig> specialConfigs = SLotterySpecialConfig.getLotterySpecialConfigListByType(mergePool);
@ -401,7 +405,7 @@ public class HeroLogic{
return poolId;
}
private int getPooId(SLotterySetting sLotterySetting) throws Exception {
private static int getPooId(SLotterySetting sLotterySetting) throws Exception {
int[][] diamondBoxContain = sLotterySetting.getDiamondBoxContain();
int totalWeight = 0;
for(int i=0;i<diamondBoxContain.length;i++){
@ -436,7 +440,7 @@ public class HeroLogic{
public SLotteryRewardConfig randomHeroByPoolId(int poolId,int randomCount,int userLevel){
public static SLotteryRewardConfig randomHeroByPoolId(int poolId,int randomCount,int userLevel){
List<SLotteryRewardConfig> sLotteryRewardConfigs = new ArrayList<>();
List<SLotteryRewardConfig> sLotteryRewardConfigListByPoolId = SLotteryRewardConfig.getSLotteryRewardConfigListByPoolId(poolId);
int totalCountByPoolId =0;
@ -2189,19 +2193,16 @@ public class HeroLogic{
//妖灵师是否在阵容中
public boolean isBattleArray (User user,String heroId){
public boolean isBattleArray (User user,String heroId,int[] teamId){
Map<Integer, List<TeamPosHeroInfo>> teamPosForHero = user.getTeamPosManager().getTeamPosForHero();
//判断是否不可下阵中有该英雄
AtomicBoolean result = new AtomicBoolean(true);
int[] teamId = SSpecialConfig.getOnceArrayValue(SSpecialConfig.HERO_RESOLVE_LICENCE);
List<Integer> list = new ArrayList<>();
Arrays.stream(teamId).forEach(i->list.add(i));
list.stream().filter(tId->teamPosForHero.containsKey(tId)).forEach(tId->teamPosForHero.get(tId).forEach(hero->{
if(hero.getHeroId().equals(heroId)){
result.set(false);
}
}));
AtomicBoolean result = isInTeams(user, heroId, teamId);
//直接删除英雄
if(result.get()){
teamPosForHero.entrySet().stream().filter(entry->
@ -2227,6 +2228,22 @@ public class HeroLogic{
return result.get();
}
public AtomicBoolean isInTeams(User user,String heroId,int[] teamId){
Map<Integer, List<TeamPosHeroInfo>> teamPosForHero = user.getTeamPosManager().getTeamPosForHero();
//判断是否不可下阵中有该英雄
AtomicBoolean result = new AtomicBoolean(true);
List<Integer> list = new ArrayList<>();
Arrays.stream(teamId).forEach(i->list.add(i));
list.stream().filter(tId->teamPosForHero.containsKey(tId)).forEach(tId->teamPosForHero.get(tId).forEach(hero->{
if(hero.getHeroId().equals(heroId)){
result.set(false);
}
}));
return result;
}
public int calPokenmonForce(Pokemon pokemon){
Map<Integer,Integer> pokemonAttributeMap = new HashMap<>();
combinePokemonAttribute(pokemonAttributeMap, pokemon,false);
@ -2609,7 +2626,7 @@ public class HeroLogic{
}
Map<Integer,Integer> returnItems = new HashMap<>();
equipIdsList.forEach(e->{
soulEquipByPositionMap.remove(e.getPosition());
hero.removeSoulEquip(e.getPosition());
returnItems.put(e.getEquipId(),1);
});
ItemUtil.dropMap(user,returnItems,BIReason.UNLOAD_SOUL_REWARD);

View File

@ -464,7 +464,8 @@ public class ItemLogic {
if(hero.getIsLock() == 1){
return ErrorCode.ITEM_DECOMPOSE_HERO_LOCK;
}
boolean battleArray = HeroLogic.getInstance().isBattleArray(user, heroId);
int[] teamId = SSpecialConfig.getOnceArrayValue(SSpecialConfig.HERO_RESOLVE_LICENCE);
boolean battleArray = HeroLogic.getInstance().isBattleArray(user, heroId,teamId);
if (!battleArray){
return ErrorCode.ITEM_DECOMPOSE_HERO_TEAM;
}

View File

@ -105,6 +105,7 @@ public class CBean2Proto {
.setLockState(hero.getIsLock())
.addAllJewels(hero.getJewelInfo())
.setCreatetype(hero.getCreateType())
.setChangeId(hero.getChangeId())
.build();
}

View File

@ -1,38 +1,56 @@
package config;
import manager.STableManager;
import manager.Table;
import java.util.HashMap;
import java.util.Map;
@Table(name ="LotterySetting")
public class SLotterySetting implements BaseConfig {
private int id;
private int diamondBoxInterval;
private int[][] cost;
private int[][] diamondBoxContain;
private int[][] tenTimesMustGetItem;
private int[][] costItem;
private int perCount;
private int lotteryType;
private int mergePool;
private int propertyType;
private int activityId;
private int diamondBoxInterval;
private int[][] costItem;
private int freeTimes;
private int maxTimes;
private int[][] diamondBoxContain;
@Override
private int[][] tenTimesMustGetItem;
private int perCount;
private int mergePool;
private int activityId;
public static Map<Integer,Map<Integer,Integer>> changeIds = new HashMap<>();
@Override
public void init() throws Exception {
Map<Integer, Map<Integer, Integer>> integerMapMap = new HashMap<>();
Map<Integer, SLotterySetting> config = STableManager.getConfig(SLotterySetting.class);
for (Map.Entry<Integer,SLotterySetting> entry:config.entrySet()) {
if(entry.getValue().getLotteryType()==7){
Map<Integer, Integer> orDefault = integerMapMap.getOrDefault(4, new HashMap<>());
orDefault.put(entry.getValue().getPropertyType(),entry.getKey());
integerMapMap.put(4,orDefault);
}else if (entry.getValue().getLotteryType()==8){
Map<Integer, Integer> orDefault = integerMapMap.getOrDefault(5, new HashMap<>());
orDefault.put(entry.getValue().getPropertyType(),entry.getKey());
integerMapMap.put(5,orDefault);
}
}
changeIds = integerMapMap;
}
@ -41,49 +59,56 @@ public class SLotterySetting implements BaseConfig {
return id;
}
public int getLotteryType() {
return lotteryType;
}
public int getPropertyType() {
return propertyType;
}
public int getDiamondBoxInterval() {
return diamondBoxInterval;
}
public int[][] getCost() {
return cost;
public int[][] getCostItem() {
return costItem;
}
public int getFreeTimes() {
return freeTimes;
}
public int getMaxTimes() {
return maxTimes;
}
public int[][] getDiamondBoxContain() {
return diamondBoxContain;
}
public int[][] getTenTimesMustGetItem() {
public int[][] getTenTimesMustGetItem() {
return tenTimesMustGetItem;
}
public int getPerCount() {
public int getPerCount() {
return perCount;
}
public int[][] getCostItem() {
return costItem;
}
public int getLotteryType() {
return lotteryType;
}
public int getMergePool() {
public int getMergePool() {
return mergePool;
}
public int getActivityId() {
public int getActivityId() {
return activityId;
}
public int getFreeTimes() {
return freeTimes;
public static Map<Integer, Map<Integer, Integer>> getChangeIds() {
return changeIds;
}
public int getMaxTimes() {
return maxTimes;
public static void setChangeIds(Map<Integer, Map<Integer, Integer>> changeIds) {
SLotterySetting.changeIds = changeIds;
}
}

View File

@ -67,6 +67,9 @@ public class SSpecialConfig implements BaseConfig {
public static final String DISCOUNT_LEVEL= "discount_level";//限时折扣推送等级#推送间隔等级
public static final String GUILD_WAR_ISOPEN = "Guild_war_isopen";//老公会战是否开启
public static final String LUCKYTURNDAILYLIMIT = "LuckyTurnDailyLimit";//幸运探宝每日上限
public static final String REPLACE_ITEM_ID = "replace_item_id";//置换玉道具ID
public static final String REPLACE_COST = "replace_cost";//置换玉消耗
@Override
public void init() throws Exception {