parent
c041d3dcdf
commit
9e636e277b
|
@ -38,6 +38,30 @@ public class StringUtil {
|
|||
return values;
|
||||
}
|
||||
|
||||
public static long[] parseFiledLong(String value) {
|
||||
if ("null".equals(value) || StringUtil.isEmpty(value)) {
|
||||
return new long[0];
|
||||
}
|
||||
String[] param = value.split("#");
|
||||
long[] values = new long[param.length];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = Long.parseLong(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static long[][] parseFiledLong2(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new long[0][0];
|
||||
}
|
||||
String[] param = value.split("\\|");
|
||||
long[][] values = new long[param.length][];
|
||||
for (int i = 0; i < param.length; i++) {
|
||||
values[i] = parseFiledLong(param[i]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
public static int[][][] parseFiledInt3(String value) {
|
||||
if ("null".equals(value) || value == null) {
|
||||
return new int[0][0][0];
|
||||
|
|
|
@ -66,6 +66,11 @@ public class GmActivity extends MongoBase {
|
|||
return value;
|
||||
}
|
||||
|
||||
public void addValue(int v) {
|
||||
this.value += v;
|
||||
updateString("value",value);
|
||||
}
|
||||
|
||||
public void setValue(int value) {
|
||||
this.value = value;
|
||||
updateString("value",value);
|
||||
|
|
|
@ -37,6 +37,11 @@ public class GmMission extends MongoBase {
|
|||
updateString("value",value);
|
||||
}
|
||||
|
||||
public void addValue(int v) {
|
||||
this.value += v;
|
||||
updateString("value",value);
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ public class GlobalDataManaager implements IManager {
|
|||
// 御剑行
|
||||
RidingSwardLogic.getInstance().zeroClearRidingSwardByUser(user);
|
||||
// 自动返利
|
||||
GmActivityLogic.getInstance().zeroUpdateGmActivity(user);
|
||||
GmActivityLogic.zeroUpdateGmActivity(user);
|
||||
//周卡邮件发放未领取奖励
|
||||
// WeekCardLogic.getInstance().sendWeekCardRewardMail(session);
|
||||
WeekCardLogic.getInstance().weekCardInfoIndication(user,0,0);
|
||||
|
|
|
@ -46,14 +46,6 @@ public class GmActivityLogic implements IEventHandler {
|
|||
Poster.getPoster().listenEvent(this, AutoRechargeBackEvent.class);
|
||||
}
|
||||
|
||||
public static GmActivityLogic getInstance() {
|
||||
return GmActivityLogic.Instance.instance;
|
||||
}
|
||||
|
||||
public static class Instance {
|
||||
public final static GmActivityLogic instance = new GmActivityLogic();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
if (!(event instanceof AutoRechargeBackEvent)){
|
||||
|
@ -132,7 +124,7 @@ public class GmActivityLogic implements IEventHandler {
|
|||
* 获取gm活动
|
||||
* @return
|
||||
*/
|
||||
private Map<String, ARBActivity> getArbActivity(){
|
||||
private static Map<String, ARBActivity> getArbActivity(){
|
||||
HashMap<String, ARBActivity> map = new HashMap<>();
|
||||
// 单属于本服的活动
|
||||
Map<String, ARBActivity> arbActivityMap = RedisUtil.getInstence().getMapValues2(RedisKey.GM_ACTIVITY_INFO, String.valueOf(GameApplication.serverId), String.class, ARBActivity.class);
|
||||
|
@ -257,46 +249,60 @@ public class GmActivityLogic implements IEventHandler {
|
|||
*/
|
||||
private void getRewardToMonsterCurrencyBack(User user, GmActivity gmActivity, double price) throws Exception {
|
||||
List<ARBMission> gmMissionList = findAllGmMission(gmActivity.getId());
|
||||
if (gmMissionList == null || gmMissionList.isEmpty()) {
|
||||
LOGGER.error("妖晶返利活动,详细档位信息未配置,userid:{}, 活动id:{}", user.getId(), gmActivity.getId());
|
||||
return;
|
||||
}
|
||||
// 档位排序
|
||||
List<ARBMission> arbMissions = gmMissionList.stream().sorted(Comparator.comparing(ARBMission::getSort)).collect(Collectors.toList());
|
||||
int num = gmActivity.getValue() + (int) price;
|
||||
gmActivity.setValue(num);
|
||||
for (ARBMission arbMission : arbMissions) {
|
||||
if (num <= 0){
|
||||
break;
|
||||
}
|
||||
// 未到领取条件
|
||||
if (gmActivity.getValue() < arbMission.getBeforeNum()){
|
||||
continue;
|
||||
gmActivity.addValue((int) price);
|
||||
int totalNum = gmActivity.getValue();
|
||||
|
||||
int limit = arbMissions.get(0).getBeforeNum();
|
||||
if (totalNum < limit || totalNum <= 0) {
|
||||
LOGGER.error("妖晶返利活动,充值金额不足最低领取调解,userid:{},活动id:{},当前累充金额:{},最低条件:{}", user.getId(), gmActivity.getId(), totalNum, limit);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < arbMissions.size(); i++) {
|
||||
ARBMission arbMission = arbMissions.get(i);
|
||||
// 能被领取的数目
|
||||
int availableNum = arbMission.getAfterNum() - arbMission.getBeforeNum();
|
||||
if (i == 0){
|
||||
availableNum += arbMission.getBeforeNum();
|
||||
}
|
||||
// 已领取
|
||||
GmMission gmMission = gmActivity.getMissionMap().getOrDefault(arbMission.getId(), new GmMission());
|
||||
if (gmMission.getState() == 1){
|
||||
num -= arbMission.getAfterNum();
|
||||
GmMission mission = gmActivity.getMissionMap().getOrDefault(arbMission.getId(), new GmMission());
|
||||
if (mission.getState() == 1) {
|
||||
totalNum -= availableNum;
|
||||
continue;
|
||||
}
|
||||
// 当前档位还可以返利得金额
|
||||
int count = arbMission.getAfterNum() - gmMission.getValue();
|
||||
// 总返利和当前档位返利获取最小
|
||||
double min = Math.min(num, count);
|
||||
int rewardNum = (int) (arbMission.getBackRatio()/100d*1000*min);
|
||||
// 返利妖晶
|
||||
int[][] reward = {{16,rewardNum}};
|
||||
|
||||
// 发邮件
|
||||
String mailReward = ItemUtil.getMailReward(reward);
|
||||
if (!StringUtil.isEmpty(mailReward)){
|
||||
MailLogic.getInstance().sendMail(user.getId(),arbMission.getActivity().getName(),arbMission.getTitle(),mailReward,TimeUtils.nowInt(),Global.MAIL_EFFECTIVE_TIME);
|
||||
// 返利数量
|
||||
int minNum = Math.min(totalNum, availableNum);
|
||||
minNum -= mission.getValue();
|
||||
long rewardNum = (long) (minNum * 10000L * (arbMission.getBackRatio() / 100d));
|
||||
|
||||
// 邮件奖励
|
||||
ArrayList<long[][]> reward = new ArrayList<>();
|
||||
reward.add(new long[][]{{16, rewardNum}});
|
||||
String mailReward = ItemUtil.getMailRewardLong(reward);
|
||||
if (!StringUtil.isEmpty(mailReward)) {
|
||||
MailLogic.getInstance().sendMail(user.getId(), arbMission.getActivity().getName(), arbMission.getTitle(), mailReward, TimeUtils.nowInt(), Global.MAIL_EFFECTIVE_TIME);
|
||||
}
|
||||
// 档位信息更新
|
||||
gmMission.setId(arbMission.getId());
|
||||
if (num - min > 0){
|
||||
gmMission.setValue(arbMission.getAfterNum());
|
||||
gmMission.setState(1);
|
||||
num -= arbMission.getAfterNum();
|
||||
}else {
|
||||
gmMission.setValue(gmMission.getValue() + (int) min);
|
||||
|
||||
// 档位更新
|
||||
mission.setId(arbMission.getId());
|
||||
mission.addValue(minNum);
|
||||
if (mission.getValue() == availableNum){
|
||||
totalNum -= availableNum;
|
||||
mission.setState(1);
|
||||
}
|
||||
gmActivity.putMissionMap(mission.getId(),mission);
|
||||
// 本档位未满,不需要继续循环了
|
||||
if (mission.getState() != 1){
|
||||
break;
|
||||
}
|
||||
gmActivity.putMissionMap(arbMission.getId(),gmMission);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -304,7 +310,7 @@ public class GmActivityLogic implements IEventHandler {
|
|||
* 零点更新活动信息
|
||||
* @param user
|
||||
*/
|
||||
public void zeroUpdateGmActivity(User user){
|
||||
public static void zeroUpdateGmActivity(User user){
|
||||
Map<String, ARBActivity> arbActivityMap = getArbActivity();
|
||||
GmActivityManager manager = user.getGmActivityManager();
|
||||
for (GmActivity gmActivity : manager.getActivityMap().values()) {
|
||||
|
|
|
@ -84,11 +84,12 @@ public class MailLogic {
|
|||
removeIds.add(cMail.getId());
|
||||
continue;
|
||||
}
|
||||
if(cMail.getMailItem()!=null && "2100#15".equals(cMail.getMailItem())){
|
||||
String mailItem = cMail.getMailItem();
|
||||
if("2100#15".equals(mailItem)){
|
||||
removeIds.add(cMail.getId());
|
||||
continue;
|
||||
}
|
||||
if(cMail.getMailItem()!=null &&cMail.getMailItem().contains("null")){
|
||||
if(mailItem != null && mailItem.contains("null")){
|
||||
removeIds.add(cMail.getId());
|
||||
continue;
|
||||
}
|
||||
|
@ -203,7 +204,8 @@ public class MailLogic {
|
|||
if (mail == null){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
if (mail.getMailItem()==null||mail.getMailItem().isEmpty()){
|
||||
String mailItem = mail.getMailItem();
|
||||
if (mailItem ==null || mailItem.isEmpty()){
|
||||
mail.setState(Global.MAIL_STATE_READ);
|
||||
mail.setNoUseDeleteTime(TimeUtils.now()+TimeUtils.DAY*Global.MAIL_NOUSE_DELETE_TIME);
|
||||
}else{
|
||||
|
@ -254,14 +256,13 @@ public class MailLogic {
|
|||
throw new ErrorCodeException(ErrorCode.MAIL_NO_REWARD);
|
||||
}
|
||||
// 转换二维数组
|
||||
int[][] itemArr = StringUtil.parseFiledInt2(mailItem.toString());
|
||||
long[][] itemArr = StringUtil.parseFiledLong2(mailItem.toString());
|
||||
// 检测卡牌和装备背包
|
||||
int limit = ItemUtil.checkCardAndEquipLimit(user,itemArr);
|
||||
int state = 0;
|
||||
if (limit == 0){
|
||||
// 领取道具
|
||||
state = ItemUtil.dropByMail(user, itemArr, dropBuilder, BIReason.TAKE_MAIL_REWARD);
|
||||
|
||||
if (state == 1){
|
||||
// 改变邮件状态
|
||||
mail.setState(Global.MAIL_DRAW_ST_GOT);
|
||||
|
@ -320,10 +321,11 @@ public class MailLogic {
|
|||
if (cMail.getState() == Global.MAIL_STATE_NEW) {
|
||||
continue;
|
||||
}
|
||||
if (cMail.getMailItem().isEmpty() && cMail.getState() != Global.MAIL_STATE_READ) {
|
||||
String mailItem = cMail.getMailItem();
|
||||
if (mailItem.isEmpty() && cMail.getState() != Global.MAIL_STATE_READ) {
|
||||
continue;
|
||||
}
|
||||
if (!cMail.getMailItem().isEmpty() && cMail.getState() != Global.MAIL_DRAW_ST_GOT) {
|
||||
if (!mailItem.isEmpty() && cMail.getState() != Global.MAIL_DRAW_ST_GOT) {
|
||||
continue;
|
||||
}
|
||||
delMailIds.add(cMail.getId());
|
||||
|
|
|
@ -491,8 +491,9 @@ public class CBean2Proto {
|
|||
if(!withOutContent){
|
||||
mailProto.setContent(mail.getContent());
|
||||
}
|
||||
if(mail.getMailItem()!=null){
|
||||
mailProto.setMailItem(mail.getMailItem());
|
||||
String mailItem = mail.getMailItem();
|
||||
if(mailItem !=null){
|
||||
mailProto.setMailItem(mailItem);
|
||||
}
|
||||
return mailProto.build();
|
||||
}
|
||||
|
|
|
@ -176,6 +176,16 @@ public class ItemUtil {
|
|||
return ints;
|
||||
}
|
||||
|
||||
public static int dropByMail(User user, long[][] itemArr,CommonProto.Drop.Builder dropBuilder,int reason) throws Exception {
|
||||
ItemMap itemObj = new ItemMap();
|
||||
|
||||
selectLongItemArr(itemArr,itemObj);
|
||||
// useRandomItem(user,randomMap,reason);
|
||||
int ints = addItemByMail(user, itemObj.getItemMap(), dropBuilder, reason);
|
||||
maptoAddWithOutItem(user,itemObj,dropBuilder,reason);
|
||||
return ints;
|
||||
}
|
||||
|
||||
//指定道具掉落(如:邮件,初始化物品)
|
||||
public static CommonProto.Drop.Builder drop(User user, List<int[][]> itemArrs,int reason) throws Exception {
|
||||
CommonProto.Drop.Builder dropBuilder = CommonProto.Drop.newBuilder();
|
||||
|
@ -325,6 +335,13 @@ public class ItemUtil {
|
|||
return getReward(itemObj);
|
||||
}
|
||||
|
||||
public static String getMailRewardLong (List<long[][]> itemArrs) throws Exception {
|
||||
ItemMap itemObj = new ItemMap();
|
||||
for(long[][] itemArr : itemArrs){
|
||||
selectLongItemArr(itemArr,itemObj);
|
||||
}
|
||||
return getReward(itemObj);
|
||||
}
|
||||
|
||||
|
||||
public static void combineReward(User user,boolean isLoop,int[] dropGroupIds,float dropRatio,ItemMap itemObj,int reason)throws ErrorCodeException{
|
||||
|
@ -1769,6 +1786,42 @@ public class ItemUtil {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测卡牌和道具上限
|
||||
* 2021-1-25:装备属于道具一种,所以不再另作处理,做默认
|
||||
* @param user
|
||||
* @param itemArr
|
||||
* @return
|
||||
*/
|
||||
public static int checkCardAndEquipLimit( User user ,long[][] itemArr) {
|
||||
int result = 0;
|
||||
|
||||
SGameSetting gameSetting = STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting();
|
||||
Map<Integer, Long> itemTypeMap = getItemTypeMap(itemArr);
|
||||
for (Map.Entry<Integer, Long> entry : itemTypeMap.entrySet()) {
|
||||
if (entry.getKey() == GlobalItemType.CARD){
|
||||
int hasHeroNum = user.getHeroManager().getHeroMap().size();
|
||||
// 英雄数量超最大上限
|
||||
if (hasHeroNum+entry.getValue() > gameSetting.getHeroNumlimit()){
|
||||
result++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 道具校验
|
||||
for(long[] ints:itemArr){
|
||||
int id = (int) ints[0];
|
||||
Item item = user.getItemManager().getItem(id);
|
||||
SItem sItem = SItem.getsItemMap().get(id);
|
||||
//数量超过了
|
||||
if (item!=null&&item.getItemNum()+ints[1] > sItem.getItemNumlimit()){
|
||||
result++;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品种类map
|
||||
* @param itemArr
|
||||
|
@ -1789,6 +1842,26 @@ public class ItemUtil {
|
|||
return itemTypeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取物品种类map
|
||||
* @param itemArr
|
||||
* @return
|
||||
*/
|
||||
public static Map<Integer,Long> getItemTypeMap(long[][] itemArr){
|
||||
Map<Integer,Long> itemTypeMap = new HashMap<>();
|
||||
for (long[] ints : itemArr) {
|
||||
int itemId = (int) ints[0];
|
||||
SItem sItem = SItem.getsItemMap().get(itemId);
|
||||
int itemType = getItemType(sItem);
|
||||
if(itemTypeMap.containsKey(itemType)){
|
||||
itemTypeMap.put(itemType,itemTypeMap.get(itemType)+ints[1]);
|
||||
}else{
|
||||
itemTypeMap.put(itemType,ints[1]);
|
||||
}
|
||||
}
|
||||
return itemTypeMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 特权加成收益计算
|
||||
* @param user
|
||||
|
|
Loading…
Reference in New Issue