奇门遁甲初版未测试
parent
4de7b94119
commit
2ee83fef78
|
|
@ -338,4 +338,6 @@ public interface BIReason {
|
|||
|
||||
int CHOICE_DRAW_CARD = 1102;//心愿抽奖
|
||||
|
||||
int QIMENDUNJIA_DRAW = 1103;//奇门遁甲
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package com.ljsd.jieling.handler.activity;
|
||||
|
||||
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.activity.ActivityLogic;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import rpc.protocols.ActivityProto;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/6/8 15:40
|
||||
* @Description: 奇门遁甲/玲珑宝阁抽奖
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class QiMenDunJiaDrawHandler extends BaseHandler<ActivityProto.qiMenDunJiaDrawRequest> {
|
||||
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public GeneratedMessage processWithProto(int uid, ActivityProto.qiMenDunJiaDrawRequest proto) throws Exception {
|
||||
// 用户信息
|
||||
User user = UserManager.getUser(uid);
|
||||
if (user == null) {
|
||||
throw new ErrorCodeException(ErrorCode.UNKNOWN);
|
||||
}
|
||||
return ActivityLogic.getInstance().qiMenDunJiaDraw(user,proto.getActivityId());
|
||||
}
|
||||
}
|
||||
|
|
@ -18,6 +18,7 @@ public final class ActivityManager extends MongoBase {
|
|||
private com.ljsd.jieling.jbean.LuckWheelMission luckWheel; // 幸运探宝奖池
|
||||
private com.ljsd.jieling.jbean.LuckWheelMission luckWheelAdvance; // 高级幸运探宝奖池
|
||||
private com.ljsd.jieling.jbean.SubRewardPoolInfo subRewardPoolInfo; // 挖矿奖池
|
||||
private Map<Integer,List<Integer>> doubleRewardPoolInfo = new HashMap<>(); // 奇门遁甲奖池
|
||||
|
||||
public ActivityManager() {
|
||||
}
|
||||
|
|
@ -30,6 +31,7 @@ public final class ActivityManager extends MongoBase {
|
|||
this.luckWheel = new LuckWheelMission(_o_.luckWheel);
|
||||
this.luckWheelAdvance = new LuckWheelMission(_o_.luckWheelAdvance);
|
||||
this.subRewardPoolInfo = new SubRewardPoolInfo(_o_.subRewardPoolInfo);
|
||||
this.doubleRewardPoolInfo = new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<Integer, com.ljsd.jieling.jbean.ActivityMission> getActivityMissionMap() {
|
||||
|
|
@ -77,6 +79,14 @@ public final class ActivityManager extends MongoBase {
|
|||
this.subRewardPoolInfo = subrewardpoolinfo;
|
||||
}
|
||||
|
||||
public void setDoubleRewardPoolInfo(Map<Integer, List<Integer>> doubleRewardPoolInfo) {
|
||||
updateString("doubleRewardPoolInfo",doubleRewardPoolInfo);
|
||||
this.doubleRewardPoolInfo = doubleRewardPoolInfo;
|
||||
}
|
||||
|
||||
public Map<Integer, List<Integer>> getDoubleRewardPoolInfo() {
|
||||
return doubleRewardPoolInfo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,47 @@
|
|||
package com.ljsd.jieling.jbean;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author hj
|
||||
* @Date 2021/6/8 13:41
|
||||
* @Description:
|
||||
* @Version 1.0
|
||||
*/
|
||||
public class DoubleRewardPoolInfo{
|
||||
|
||||
/**
|
||||
* 外圈,存储的是已抽中的奖励
|
||||
*/
|
||||
private List<Integer> bigRewardPool = new ArrayList<>();
|
||||
/**
|
||||
* 内圈,存储的是已抽中的奖励
|
||||
*/
|
||||
private List<Integer> smallRewardPool = new ArrayList<>();
|
||||
|
||||
public DoubleRewardPoolInfo() {
|
||||
}
|
||||
|
||||
|
||||
public DoubleRewardPoolInfo(DoubleRewardPoolInfo _o_ ) {
|
||||
this.bigRewardPool = new ArrayList<>(_o_.bigRewardPool);
|
||||
this.smallRewardPool = new ArrayList<>(_o_.smallRewardPool);
|
||||
}
|
||||
|
||||
public List<Integer> getBigRewardPool() {
|
||||
return bigRewardPool;
|
||||
}
|
||||
|
||||
public void setBigRewardPool(List<Integer> bigRewardPool) {
|
||||
this.bigRewardPool = bigRewardPool;
|
||||
}
|
||||
|
||||
public List<Integer> getSmallRewardPool() {
|
||||
return smallRewardPool;
|
||||
}
|
||||
|
||||
public void setSmallRewardPool(List<Integer> smallRewardPool) {
|
||||
this.smallRewardPool = smallRewardPool;
|
||||
}
|
||||
}
|
||||
|
|
@ -23,6 +23,7 @@ import com.ljsd.jieling.logic.mission.GameEvent;
|
|||
import com.ljsd.jieling.logic.mission.event.MissionEventDistributor;
|
||||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.util.InnerMessageUtil;
|
||||
import com.ljsd.jieling.util.ItemUtil;
|
||||
|
|
@ -1669,4 +1670,84 @@ public class ActivityLogic implements IEventHandler{
|
|||
// 返回奖励信息
|
||||
return ItemUtil.dropPer(user, reward, BIReason.CHOICE_DRAW_CARD);
|
||||
}
|
||||
|
||||
/**
|
||||
* 奇门遁甲抽奖
|
||||
* @param user
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public ActivityProto.qiMenDunJiaDrawResponse qiMenDunJiaDraw(User user,int activityId) throws Exception {
|
||||
ActivityProto.qiMenDunJiaDrawResponse.Builder response = ActivityProto.qiMenDunJiaDrawResponse.newBuilder();
|
||||
ArrayList<Integer> hits = new ArrayList<>();
|
||||
int[][] rewards = new int[2][];
|
||||
// 根据返回判断是否需要抽外圈
|
||||
boolean result = qiMenRandom(user, 2, rewards, hits);
|
||||
if (result){
|
||||
// 外圈抽奖
|
||||
qiMenRandom(user, 1, rewards, hits);
|
||||
// 事件分发
|
||||
|
||||
}
|
||||
// 处理奖励
|
||||
CommonProto.Drop.Builder drop = ItemUtil.dropPer(user, rewards, BIReason.QIMENDUNJIA_DRAW);
|
||||
|
||||
response.setDrop(drop).addAllIdList(hits);
|
||||
return response.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 奇门遁甲随机奖励
|
||||
* @param user 玩家
|
||||
* @param type 内圈,外圈
|
||||
* @param rewards 奖励的二维数组
|
||||
* @param hits 抽中的索引id
|
||||
* @return true:需要进行外圈抽奖 false:不需要外圈抽奖
|
||||
*/
|
||||
private boolean qiMenRandom(User user, int type, int[][] rewards, List<Integer> hits){
|
||||
boolean result = false;
|
||||
|
||||
// 根据类型获取卡池
|
||||
List<SLingLongPool> smallPool = new ArrayList<>(SLingLongPool.map.get(type));
|
||||
// 玩家身上记录已抽中的索引id
|
||||
Map<Integer, List<Integer>> doubleRewardPoolInfo = user.getActivityManager().getDoubleRewardPoolInfo();
|
||||
List<Integer> rewardPool = doubleRewardPoolInfo.getOrDefault(type,new ArrayList<>());
|
||||
// 已抽中的去除
|
||||
smallPool.removeIf(v->rewardPool.contains(v.getId()));
|
||||
// 总权重和随机值
|
||||
int totalWeight = smallPool.stream().mapToInt(SLingLongPool::getGetRate).sum();
|
||||
int randomInt = MathUtils.randomInt(totalWeight);
|
||||
|
||||
for (SLingLongPool pool : smallPool) {
|
||||
// 中将
|
||||
if (randomInt <= pool.getGetRate()){
|
||||
// 物品id
|
||||
rewards[type][0] = pool.getItemId()[0];
|
||||
// 物品数量
|
||||
rewards[type][1] = pool.getItemId()[1];
|
||||
// 中门
|
||||
if (pool.getItemId()[0] == 105){
|
||||
result = true;
|
||||
// 更新数据用,已经抽中的需要记录
|
||||
rewardPool.add(pool.getItemId()[0]);
|
||||
}else {
|
||||
rewardPool.clear();
|
||||
}
|
||||
// 返回给前端的抽中的id
|
||||
hits.add(pool.getItemId()[0]);
|
||||
}
|
||||
randomInt -= pool.getGetRate();
|
||||
}
|
||||
|
||||
// 外圈抽奖用,抽中全部
|
||||
if (rewardPool.size() >= SLingLongPool.map.get(type).size()){
|
||||
rewardPool.clear();
|
||||
}
|
||||
|
||||
// 更新数据库
|
||||
doubleRewardPoolInfo.put(type,rewardPool);
|
||||
user.getActivityManager().setDoubleRewardPoolInfo(doubleRewardPoolInfo);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,5 +94,5 @@ public interface ActivityType {
|
|||
int DEMON_TREASURE = 36;//降妖夺宝
|
||||
int NEW_GENERAL_ATTACK = 200;//新将来袭
|
||||
|
||||
|
||||
int QI_MEN_DUN_JIA = 67;//奇门遁甲
|
||||
}
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ public enum ActivityTypeEnum {
|
|||
EQUIP_UPLEVEL(ActivityType.EQUIP_UPLEVEL,EquipUpLevelActivity::new),
|
||||
TA_SUI_LING_XIAO(ActivityType.TA_SUI_LING_XIAO,TaSuiLingXiaoActivity::new),
|
||||
CHOICE_DRAW_CRAD(ActivityType.CHOICE_DRAW_CRAD,ChoiceDrawCardActivity::new),
|
||||
QIMENDUNJIA_DRAW(ActivityType.QI_MEN_DUN_JIA,QiMenDunJiaActivity::new),
|
||||
|
||||
;
|
||||
private int type;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
package com.ljsd.jieling.logic.activity;
|
||||
|
||||
import com.ljsd.jieling.jbean.ActivityMission;
|
||||
import com.ljsd.jieling.jbean.DoubleRewardPoolInfo;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import config.SActivityRewardConfig;
|
||||
import config.SLingLongPool;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author hj
|
||||
* 奇门遁甲活动
|
||||
*/
|
||||
@SuppressWarnings("ALL")
|
||||
public class QiMenDunJiaActivity extends AbstractActivity {
|
||||
|
||||
QiMenDunJiaActivity(int id) {
|
||||
super(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initActivity(User user) throws Exception {
|
||||
ActivityMission mission = new ActivityMission();
|
||||
// 读表获取阶段奖励信息
|
||||
List<SActivityRewardConfig> configs = SActivityRewardConfig.getsActivityRewardConfigByActivityId(id);
|
||||
List<Integer> list = configs.stream().mapToInt(SActivityRewardConfig::getId).boxed().collect(Collectors.toList());
|
||||
// 初始化阶段奖励
|
||||
ActivityLogic.getInstance().initOtherMission(mission, list);
|
||||
user.getActivityManager().getActivityMissionMap().put(id, mission);
|
||||
// 卡池初始化
|
||||
user.getActivityManager().setDoubleRewardPoolInfo(new HashMap<>());
|
||||
LOGGER.info("奇门遁甲/玲珑宝阁 初始化..."+id);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
package config;
|
||||
|
||||
import manager.STableManager;
|
||||
import manager.Table;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Table(name ="LingLongPool")
|
||||
public class SLingLongPool implements BaseConfig {
|
||||
|
||||
private int id;
|
||||
|
||||
private int activityId;
|
||||
|
||||
private int[] itemId;
|
||||
|
||||
private int getRate;
|
||||
|
||||
private int position;
|
||||
|
||||
/**
|
||||
* key: 内圈外圈id value: 对象list
|
||||
*/
|
||||
public static Map<Integer, List<SLingLongPool>> map = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
Map<Integer, SLingLongPool> config = STableManager.getConfig(SLingLongPool.class);
|
||||
config.values().forEach(v->{
|
||||
List<SLingLongPool> longPools = map.getOrDefault(v.getPosition(), new ArrayList<>());
|
||||
longPools.add(v);
|
||||
map.put(v.getPosition(),longPools);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getActivityId() {
|
||||
return activityId;
|
||||
}
|
||||
|
||||
public int[] getItemId() {
|
||||
return itemId;
|
||||
}
|
||||
|
||||
public int getGetRate() {
|
||||
return getRate;
|
||||
}
|
||||
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue