专属商城
parent
c5cd4fb8bd
commit
fb2d6919b5
|
@ -147,7 +147,7 @@ public class GetPlayerInfoHandler extends BaseHandler{
|
|||
}
|
||||
|
||||
FourChallengeLogic.getInstance().firstGetTimes(user);// 四灵试炼初始化
|
||||
StoreLogic.reloadStoreInfo(user,7);//重载功能商店
|
||||
StoreLogic.getInstance().reloadStoreInfo(user,7);//重载功能商店
|
||||
ExplorerMapLogic.getInstance().calOfflineReward(user);//挂机探索
|
||||
//森罗幻境自动挂机返回掉落展示清除
|
||||
Map<Integer,Integer> dropShow = mapManager.getTowerGetRewardInfoShowMap();
|
||||
|
|
|
@ -31,12 +31,12 @@ public class ForceRandSoulEquipHandler extends BaseHandler<HeroInfoProto.SoulFor
|
|||
public void processWithProto(ISession iSession, HeroInfoProto.SoulForceRandRequest proto) throws Exception {
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
boolean update = StoreLogic.checkBuyGoodsAndUpdate(user, 7, 10019, 1);
|
||||
boolean update = StoreLogic.getInstance().checkBuyGoodsAndUpdate(user, 7, 10019, 1);
|
||||
if (!update){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
|
||||
int pos= SSpecialConfig.getIntegerValue(SSpecialConfig.MANDATORY_ASTROLOGICAL);
|
||||
int pos = SSpecialConfig.getIntegerValue(SSpecialConfig.MANDATORY_ASTROLOGICAL);
|
||||
SEquipTalismanaLottery lotteryIn = STableManager.getConfig(SEquipTalismanaLottery.class).get(pos);
|
||||
if (null == lotteryIn) {
|
||||
throw new Exception("SEquipTalismanaLottery 配置不存在" + pos);
|
||||
|
|
|
@ -665,10 +665,10 @@ public class MapLogic {
|
|||
mapManager.findSuddenlyBoss(bossId, now);
|
||||
}
|
||||
} else if (mapPointConfig.getStyle() == EventType.businessman) {
|
||||
if (!StoreLogic.checkContainsStore(user, StoreType.CLOUD_STORE, false)) {
|
||||
if (!StoreLogic.getInstance().checkContainsStore(user, StoreType.CLOUD_STORE, false)) {
|
||||
int initialEventId = mapPointConfig.getInitialEventId();
|
||||
SEventPointConfig sEventPointConfig = STableManager.getConfig(SEventPointConfig.class).get(initialEventId);
|
||||
StoreLogic.initOneStore(user, sEventPointConfig.getOption()[0]);
|
||||
StoreLogic.getInstance().initOneStore(user, sEventPointConfig.getOption()[0]);
|
||||
}
|
||||
} else if (mapPointConfig.getStyle() == EventType.towerBuff) {
|
||||
if (cell.getEventId() == 0) {
|
||||
|
@ -1486,14 +1486,14 @@ public class MapLogic {
|
|||
MapInfoProto.MapSweepResponse.Builder mapSweepResponse = MapInfoProto.MapSweepResponse.newBuilder();
|
||||
|
||||
//随机云游商店
|
||||
if (!StoreLogic.checkContainsStore(user, StoreType.CLOUD_STORE, true)) {
|
||||
if (!StoreLogic.getInstance().checkContainsStore(user, StoreType.CLOUD_STORE, true)) {
|
||||
int hasStore = 0;
|
||||
for (int i = 0; i < count; i++) {
|
||||
int[][] sweepingStoreProbability = sChallengeConfig.getSweepingStoreProbability();
|
||||
if (sweepingStoreProbability.length > 0) {
|
||||
hasStore = MathUtils.randomFromWeight(sChallengeConfig.getSweepingStoreProbability());
|
||||
if (hasStore == 1) {
|
||||
StoreLogic.initOneStore(user, sChallengeConfig.getSweepingStoreId());
|
||||
StoreLogic.getInstance().initOneStore(user, sChallengeConfig.getSweepingStoreId());
|
||||
mapSweepResponse.setCloudStore(hasStore);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ public class FourtyThreeBehavior extends BaseBehavior{
|
|||
public boolean process(int optionId, User user, int[][] behaviorTypeValues, MapInfoProto.EventUpdateResponse.Builder eventUpdateResponse) throws Exception {
|
||||
MapManager mapManager = user.getMapManager();
|
||||
int storeIndex = MathUtils.randomFromWeight(STrialConfig.sTrialConfigMap.get(mapManager.getTrialInfo().getFloor()).getRandomStore());
|
||||
StoreLogic.initOrUpdateOneStore(user,8,storeIndex);
|
||||
StoreLogic.getInstance().initOrUpdateOneStore(user,8,storeIndex);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
|
|
@ -262,7 +262,7 @@ public abstract class AbstractMap implements IMap {
|
|||
Map<Integer, SCMap> scMap =SCMap.sCMap.get(mapManager.getCurMapId());
|
||||
Map<Integer, Cell> newMap = new HashMap<>();
|
||||
Random random = new Random();
|
||||
boolean alreadHadYunShop = StoreLogic.checkContainsStore(user, StoreType.CLOUD_STORE,true);
|
||||
boolean alreadHadYunShop = StoreLogic.getInstance().checkContainsStore(user, StoreType.CLOUD_STORE,true);
|
||||
mapManager.checkSuddenlyBoss();
|
||||
int suddenlyBoss = mapManager.getSuddenlyBoss();
|
||||
boolean canFindsuddenlyBoss = System.currentTimeMillis()> (mapManager.getSuddenlyBossStartTime() + STableManager.getFigureConfig(CommonStaticConfig.class).getGameSetting().getIncidentalBossCd())*1000;
|
||||
|
|
|
@ -39,7 +39,6 @@ import util.MathUtils;
|
|||
import util.TimeUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
|
@ -298,7 +297,7 @@ public class TowerMap extends AbstractMap {
|
|||
case 3:
|
||||
//商店
|
||||
int storeIndex = MathUtils.randomFromWeight(sTrialConfig.getRandomStore());
|
||||
StoreLogic.initOrUpdateOneStore(user,8,storeIndex);
|
||||
StoreLogic.getInstance().initOrUpdateOneStore(user,8,storeIndex);
|
||||
while (cellMap3.size() < sTrialConfig.getGameCount()[2]) {
|
||||
int randomIndex = random.nextInt(scMap1.getGroups().length);
|
||||
int x = scMap1.getGroups()[randomIndex][0];
|
||||
|
|
|
@ -1,19 +1,12 @@
|
|||
package com.ljsd.jieling.handler.store;
|
||||
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.NewWelfareEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.NewWelfareTypeEnum;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.dao.UserManager;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.netty.cocdex.PacketNetData;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import rpc.protocols.CommonProto;
|
||||
import org.springframework.stereotype.Component;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
import com.ljsd.jieling.util.MessageUtil;
|
||||
import org.springframework.stereotype.Component;
|
||||
import util.TimeUtils;
|
||||
|
||||
@Component
|
||||
public class BuyStoreItemHandler extends BaseHandler {
|
||||
|
@ -26,15 +19,6 @@ public class BuyStoreItemHandler extends BaseHandler {
|
|||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
PlayerInfoProto.BuyStoreItemRequest buyStoreItemRequest = PlayerInfoProto.BuyStoreItemRequest.parseFrom(netData.parseClientProtoNetData());
|
||||
CommonProto.Drop drop = StoreLogic.buyStoreItem(iSession.getUid(), buyStoreItemRequest.getStoreId(), buyStoreItemRequest.getItemId(), buyStoreItemRequest.getItemNum());
|
||||
if (buyStoreItemRequest.getItemId()==1106){
|
||||
Poster.getPoster().dispatchEvent(new NewWelfareEvent(UserManager.getUser(iSession.getUid()), NewWelfareTypeEnum.BUY_1106.getType(),0));
|
||||
}
|
||||
if (buyStoreItemRequest.getItemId()==1107){
|
||||
Poster.getPoster().dispatchEvent(new NewWelfareEvent(UserManager.getUser(iSession.getUid()), NewWelfareTypeEnum.BUY_1107.getType(),0));
|
||||
}
|
||||
PlayerInfoProto.BuyStoreItemResponse builder = PlayerInfoProto.BuyStoreItemResponse.newBuilder().setDrop(drop).build();
|
||||
int msgId = MessageTypeProto.MessageType.BUY_STORE_ITEM_RESPONSE_VALUE;
|
||||
MessageUtil.sendMessage(iSession, 1,msgId, builder, true);
|
||||
StoreLogic.getInstance().buyStoreItem(iSession, buyStoreItemRequest);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,6 @@ public class GetAllStoreHandler extends BaseHandler {
|
|||
|
||||
@Override
|
||||
public void process(ISession iSession, PacketNetData netData) throws Exception {
|
||||
StoreLogic.getAllStoreInfo(iSession);
|
||||
StoreLogic.getInstance().getAllStoreInfo(iSession);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package com.ljsd.jieling.handler.store;
|
||||
|
||||
import com.ljsd.jieling.handler.BaseHandler;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import org.springframework.stereotype.Component;
|
||||
import rpc.protocols.MessageTypeProto;
|
||||
import rpc.protocols.PlayerInfoProto;
|
||||
|
||||
@Component
|
||||
public class OneClickPurchaseHandler extends BaseHandler<PlayerInfoProto.StoreOneClickPurchaseRequest> {
|
||||
|
||||
@Override
|
||||
public MessageTypeProto.MessageType getMessageCode() {
|
||||
return MessageTypeProto.MessageType.StoreOneClickPurchaseRequest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void processWithProto(ISession iSession, PlayerInfoProto.StoreOneClickPurchaseRequest proto) throws Exception {
|
||||
StoreLogic.getInstance().oneClickPurchase(iSession, proto.getId());
|
||||
}
|
||||
}
|
|
@ -23,10 +23,10 @@ public class StoreRefreItemHandler extends BaseHandler {
|
|||
int type = buyStoreItemRequest.getType();
|
||||
int storeId = buyStoreItemRequest.getStoreId();
|
||||
if (type ==0){
|
||||
StoreLogic.handRefreStore(iSession,storeId);
|
||||
StoreLogic.getInstance().handRefreStore(iSession,storeId);
|
||||
}
|
||||
if (type ==1){
|
||||
StoreLogic.automaticRefreStore(iSession,storeId);
|
||||
StoreLogic.getInstance().automaticRefreStore(iSession,storeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,7 +65,7 @@ public class Cmd_changename extends GmRoleAbstract {
|
|||
long userCreateTime = user.getPlayerInfoManager().getCreateTime();
|
||||
long startTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(),sGlobalActivity.getEndTimeLong(),sGlobalActivity.getTime(),userCreateTime, 1);
|
||||
long endTime = ToolsUtil.getTimeLong(sGlobalActivity.getStartTimeLong(),sGlobalActivity.getEndTimeLong(),sGlobalActivity.getTime(),userCreateTime, 2);
|
||||
StoreLogic.initOnsStoereWithTime(user,10,startTime,endTime);
|
||||
StoreLogic.getInstance().initOnsStoereWithTime(user,10,startTime,endTime);
|
||||
LOGGER.info("hotfix user={} store end",user.getId());
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ public class Cmd_changename extends GmRoleAbstract {
|
|||
if("endStore".equals(args[2])){
|
||||
if(!user.getStoreManager().getStoreInfoMap().containsKey(13)){
|
||||
TimeControllerOfFunction openTimeOfFuntionCacheByType = GlobalDataManaager.getInstance().getOpenTimeOfFuntionCacheByType(FunctionIdEnum.Endless);
|
||||
StoreLogic.initOnsStoereWithTime(user, 13,openTimeOfFuntionCacheByType.getStartTime(),openTimeOfFuntionCacheByType.getEndTime());
|
||||
StoreLogic.getInstance().initOnsStoereWithTime(user, 13,openTimeOfFuntionCacheByType.getStartTime(),openTimeOfFuntionCacheByType.getEndTime());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -289,7 +289,7 @@ public class GlobalDataManaager implements IManager {
|
|||
MissionEventDistributor.init();
|
||||
DataManagerDistributor.init();
|
||||
initServerIsLanEnviornment();
|
||||
StoreLogic.checkGlobalStore(true);
|
||||
StoreLogic.getInstance().checkGlobalStore(true);
|
||||
new RPCServerTask().start();
|
||||
new RPCGmServerTask().start();
|
||||
new RPCWorldServerTask().start();
|
||||
|
@ -304,6 +304,7 @@ public class GlobalDataManaager implements IManager {
|
|||
new SummonTreasureHandler();
|
||||
new ArchitectureUnLockHandler();
|
||||
new SaveHeroForceEventHandler();
|
||||
new FunctionRefreshEventHandler();
|
||||
new GmActivityLogic();
|
||||
new AddItemHandler();
|
||||
RankLogic.heroHotRankInit();//英雄热度排行榜同步更新英雄配置表
|
||||
|
|
|
@ -282,18 +282,17 @@ public class ActivityLogic implements IEventHandler{
|
|||
if(storeId == 0){
|
||||
return;
|
||||
}
|
||||
StoreLogic.initOnsStoereWithTime(user,storeId,startTime,endTime);
|
||||
StoreLogic.getInstance().initOnsStoereWithTime(user,storeId,startTime,endTime);
|
||||
}
|
||||
|
||||
public boolean initAllActivityMission(Map<Integer,ActivityMission> map, int activityId) {
|
||||
public void initAllActivityMission(Map<Integer,ActivityMission> map, int activityId) {
|
||||
if (map.containsKey(activityId)) {
|
||||
return false;
|
||||
return;
|
||||
}
|
||||
ActivityMission activityMission = new ActivityMission();
|
||||
//自动初始化
|
||||
map.put(activityId, activityMission);
|
||||
initMissionInfo(activityMission,activityId);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -59,6 +59,9 @@ class NewRechargeSumDayActivity extends AbstractActivity {
|
|||
*/
|
||||
private void zeroUpdate(User user) throws Exception {
|
||||
ActivityMission mission = user.getActivityManager().getActivityMissionMap().get(id);
|
||||
if (mission == null){
|
||||
return;
|
||||
}
|
||||
mission.setV(0);
|
||||
boolean finishAndTake = checkActivityMissionFinishAndTake(user.getId(), id, mission);
|
||||
if (finishAndTake){
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package com.ljsd.jieling.logic.activity.eventhandler;
|
||||
|
||||
import com.ljsd.jieling.logic.activity.IEventHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.FunctionRefreshEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.IEvent;
|
||||
import com.ljsd.jieling.logic.activity.event.Poster;
|
||||
import com.ljsd.jieling.logic.store.StoreLogic;
|
||||
|
||||
public class FunctionRefreshEventHandler implements IEventHandler {
|
||||
|
||||
public FunctionRefreshEventHandler() {
|
||||
Poster.getPoster().listenEvent(this, FunctionRefreshEvent.class);
|
||||
}
|
||||
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
if(!(event instanceof FunctionRefreshEvent)){
|
||||
return;
|
||||
}
|
||||
StoreLogic.getInstance().checkAllowOfFunction((FunctionRefreshEvent)event);
|
||||
}
|
||||
}
|
|
@ -19,29 +19,23 @@ public class StoreManager extends MongoBase {
|
|||
return storeInfoMap;
|
||||
}
|
||||
|
||||
public void addStoreInfo(StoreInfo storeInfo) throws Exception {
|
||||
public void addStoreInfo(StoreInfo storeInfo) {
|
||||
storeInfo.init(this.getRootId(), getMongoKey() + ".storeInfoMap." + storeInfo.getId());
|
||||
storeInfoMap.put(storeInfo.getId(), storeInfo);
|
||||
updateString("storeInfoMap." + storeInfo.getId(), storeInfo);
|
||||
}
|
||||
|
||||
public void removeStoreInfo(Integer key) {
|
||||
StoreInfo storeInfo= storeInfoMap.get(key);
|
||||
if (storeInfo!=null){
|
||||
storeInfoMap.remove(key);
|
||||
removeString(getMongoKey() + ".storeInfoMap." + key);
|
||||
}
|
||||
storeInfoMap.remove(key);
|
||||
removeString(getMongoKey() + ".storeInfoMap." + key);
|
||||
}
|
||||
|
||||
public void removeStoreItemInfo(Integer key,Integer itemKey) {
|
||||
StoreInfo storeInfo= storeInfoMap.get(key);
|
||||
if (storeInfo==null){
|
||||
if (storeInfo == null){
|
||||
return;
|
||||
}
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
if(itemNumMap==null){
|
||||
return;
|
||||
}
|
||||
itemNumMap.put(itemKey,0);
|
||||
storeInfo.getItemNumMap().remove(itemKey);
|
||||
updateString(getMongoKey() + ".storeInfoMap." + key, storeInfo);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,6 @@ import com.ljsd.jieling.logic.GlobleSystemLogic;
|
|||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
import com.ljsd.jieling.logic.fight.specialparm.SpecialForTeamBuildEnum;
|
||||
import com.ljsd.jieling.logic.hero.HeroAttributeEnum;
|
||||
import com.ljsd.jieling.logic.hero.HeroLogic;
|
||||
import com.ljsd.jieling.logic.mail.MailLogic;
|
||||
|
@ -197,7 +196,7 @@ public class ExpeditionLogic {
|
|||
}
|
||||
//更新商店
|
||||
try {
|
||||
StoreLogic.initOneStore(user, 56);
|
||||
StoreLogic.getInstance().initOneStore(user, 56);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ public class GuildChallengeLogic {
|
|||
}
|
||||
user.getPlayerInfoManager().removeVipPriviliageId(3013);
|
||||
user.getStoreManager().removeStoreItemInfo(7,10031);
|
||||
StoreLogic.sendStoreUpdateIndication(uid,user.getStoreManager().getStoreInfoMap().get(7));
|
||||
StoreLogic.getInstance().sendStoreUpdateIndication(uid,user.getStoreManager().getStoreInfoMap().get(7));
|
||||
guildMyInfo.addRefreshedBoss(guildMyInfo.getLastMonsterId());
|
||||
isRefresh = 1;
|
||||
}
|
||||
|
@ -306,7 +306,7 @@ public class GuildChallengeLogic {
|
|||
}
|
||||
user1.getPlayerInfoManager().removeVipPriviliageId(3013);
|
||||
user1.getStoreManager().removeStoreItemInfo(7,10031);
|
||||
StoreLogic.sendStoreUpdateIndication(user1.getId(),user1.getStoreManager().getStoreInfoMap().get(7));
|
||||
StoreLogic.getInstance().sendStoreUpdateIndication(user1.getId(),user1.getStoreManager().getStoreInfoMap().get(7));
|
||||
guildMyInfo.setLastMonsterId(bossId+1);
|
||||
guildMyInfo.setGuildChallengeDamage(0);
|
||||
guildMyInfo.addRefreshedBoss(bossId);
|
||||
|
|
|
@ -1566,7 +1566,7 @@ public class GuildLogic {
|
|||
int level = guildMyInfo.getGuildSkill().get(type);
|
||||
|
||||
int size = SGuildTechnology.technologyMap.get(type).size();
|
||||
boolean update = StoreLogic.checkBuyGoodsAndUpdate(user, 7, 10028, 1);
|
||||
boolean update = StoreLogic.getInstance().checkBuyGoodsAndUpdate(user, 7, 10028, 1);
|
||||
if(!update){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
|
|
|
@ -224,10 +224,10 @@ public class CombatLogic {
|
|||
boolean update = true;
|
||||
if(position == 0){
|
||||
if(!PlayerLogic.getInstance().checkAndUpdate(user,VipPrivilegeType.FAST_MAP_LIMIT,1)) {
|
||||
update = StoreLogic.checkBuyGoodsAndUpdate(user,7,10008,1);
|
||||
update = StoreLogic.getInstance().checkBuyGoodsAndUpdate(user,7,10008,1);
|
||||
}
|
||||
}else{
|
||||
update = StoreLogic.checkBuyGoodsAndUpdate(user,7,10015,1);
|
||||
update = StoreLogic.getInstance().checkBuyGoodsAndUpdate(user,7,10015,1);
|
||||
}
|
||||
if (!update){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
|
|
|
@ -494,7 +494,7 @@ public class HardStageLogic {
|
|||
|
||||
boolean update = PlayerLogic.getInstance().checkAndUpdate(user, VipPrivilegeType.BUY_YUHENGLONGHUNDAN_LIMIT, 1);
|
||||
if (!update){
|
||||
boolean update1 = StoreLogic.checkBuyGoodsAndUpdate(user, 7, 10006, 1);
|
||||
boolean update1 = StoreLogic.getInstance().checkBuyGoodsAndUpdate(user, 7, 10006, 1);
|
||||
if(!update1){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.ljsd.jieling.logic.store;
|
||||
|
||||
import com.ljsd.jieling.core.FunctionIdEnum;
|
||||
import com.ljsd.jieling.core.VipPrivilegeType;
|
||||
import com.ljsd.jieling.db.mongo.MongoUtil;
|
||||
import com.ljsd.jieling.exception.ErrorCode;
|
||||
import com.ljsd.jieling.exception.ErrorCodeException;
|
||||
|
@ -11,7 +12,6 @@ import com.ljsd.jieling.ktbeans.parmsBean.ParamEventBean;
|
|||
import com.ljsd.jieling.logic.GlobalDataManaager;
|
||||
import com.ljsd.jieling.logic.OnlineUserManager;
|
||||
import com.ljsd.jieling.logic.activity.ActivityType;
|
||||
import com.ljsd.jieling.logic.activity.IEventHandler;
|
||||
import com.ljsd.jieling.logic.activity.event.*;
|
||||
import com.ljsd.jieling.logic.dao.*;
|
||||
import com.ljsd.jieling.logic.dao.root.User;
|
||||
|
@ -19,6 +19,7 @@ import com.ljsd.jieling.logic.mission.GameEvent;
|
|||
import com.ljsd.jieling.logic.player.PlayerLogic;
|
||||
import com.ljsd.jieling.network.server.ProtocolsManager;
|
||||
import com.ljsd.jieling.network.session.ISession;
|
||||
import com.ljsd.jieling.tools.Utils;
|
||||
import com.ljsd.jieling.util.*;
|
||||
import config.SPlayerLevelConfig;
|
||||
import config.SStoreConfig;
|
||||
|
@ -35,108 +36,97 @@ import java.util.*;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public class StoreLogic implements IEventHandler {
|
||||
public class StoreLogic {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(StoreLogic.class);
|
||||
|
||||
private static Set<Integer> openStoreInfo = new HashSet<>();
|
||||
|
||||
private static Set<Integer> storeGiftType = new HashSet<>(3);
|
||||
private StoreLogic(){
|
||||
Poster.getPoster().listenEvent(this, FunctionRefreshEvent.class);
|
||||
}
|
||||
public static class Instance {
|
||||
public final static StoreLogic instance = new StoreLogic();
|
||||
}
|
||||
|
||||
public static StoreLogic getInstance() {
|
||||
return StoreLogic.Instance.instance;
|
||||
}
|
||||
|
||||
static {
|
||||
storeGiftType.add(30);
|
||||
storeGiftType.add(31);
|
||||
storeGiftType.add(32);
|
||||
StoreLogic.getInstance();
|
||||
}
|
||||
|
||||
public static void checkGlobalStore(boolean isStartServer) {
|
||||
public void checkGlobalStore(boolean isStartServer) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
long now = calendar.getTimeInMillis();
|
||||
try {
|
||||
|
||||
for (SStoreTypeConfig sStoreTypeConfig : SStoreTypeConfig.getsStoreTypeConfigMap().values()) {
|
||||
if (sStoreTypeConfig.getStoreOpenRule() == 3) {
|
||||
long startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_TIME, 0, 1);
|
||||
long endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_TIME, 0, 2);
|
||||
if (startTime != 0 && endTime != 0 && now > startTime && now < endTime && !openStoreInfo.contains(sStoreTypeConfig.getId())) {
|
||||
long startTime, endTime;
|
||||
switch (sStoreTypeConfig.getStoreOpenRule()){
|
||||
case 3:
|
||||
startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_TIME, 0, 1);
|
||||
endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_TIME, 0, 2);
|
||||
if (startTime != 0 && endTime != 0 && now > startTime && now < endTime && !openStoreInfo.contains(sStoreTypeConfig.getId())) {
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
if (session.getFiveReady() == 1) {
|
||||
try {
|
||||
updateUsersStoreAyync(UserManager.getUser(session.getUid()), user1 -> {
|
||||
initOneStore(user1, sStoreTypeConfig.getId());
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception::=>{}", e.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isStartServer) {
|
||||
openStoreInfo.add(sStoreTypeConfig.getId());
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 6:
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
if (session.getFiveReady() == 1) {
|
||||
try {
|
||||
User user = UserManager.getUser(session.getUid(), true);
|
||||
if (user == null) {
|
||||
LOGGER.info("user null removeid=>{}", session.getUid());
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
continue;
|
||||
}
|
||||
long userCreateTime = user.getPlayerInfoManager().getCreateTime();
|
||||
startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_ROLE, userCreateTime, 1);
|
||||
endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_ROLE, userCreateTime, 2);
|
||||
if (now < startTime || now > endTime) {
|
||||
continue;
|
||||
}
|
||||
if (!user.getStoreManager().getStoreInfoMap().containsKey(sStoreTypeConfig.getId())) {
|
||||
updateUsersStoreAyync(UserManager.getUser(session.getUid()), user1 -> {
|
||||
initOneStore(user1, sStoreTypeConfig.getId());
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 7:
|
||||
startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER, 0, 1);
|
||||
endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER, 0, 2);
|
||||
if (now < startTime || now > endTime) {
|
||||
continue;
|
||||
}
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
if (session.getFiveReady() == 1) {
|
||||
User user = UserManager.getUser(session.getUid(), true);
|
||||
if (user == null) {
|
||||
LOGGER.info("user null removeid=>{}", session.getUid());
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
continue;
|
||||
}
|
||||
if (!user.getStoreManager().getStoreInfoMap().containsKey(sStoreTypeConfig.getId())) {
|
||||
updateUsersStoreAyync(UserManager.getUser(session.getUid()), user1 -> {
|
||||
initOneStore(user1, sStoreTypeConfig.getId());
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
});
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("Exception::=>{}", e.toString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
if (isStartServer) {
|
||||
openStoreInfo.add(sStoreTypeConfig.getId());
|
||||
}
|
||||
}
|
||||
} else if (sStoreTypeConfig.getStoreOpenRule() == 6) {
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
if (session.getFiveReady() == 1) {
|
||||
User user = UserManager.getUser(session.getUid(), true);
|
||||
if (user == null) {
|
||||
LOGGER.info("user null removeid=>{}", session.getUid());
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
continue;
|
||||
}
|
||||
long userCreateTime = user.getPlayerInfoManager().getCreateTime();
|
||||
long startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_ROLE, userCreateTime, 1);
|
||||
long endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_ROLE, userCreateTime, 2);
|
||||
if (now < startTime || now > endTime) {
|
||||
continue;
|
||||
}
|
||||
if (!user.getStoreManager().getStoreInfoMap().containsKey(sStoreTypeConfig.getId())) {
|
||||
updateUsersStoreAyync(UserManager.getUser(session.getUid()), user1 -> {
|
||||
initOneStore(user1, sStoreTypeConfig.getId());
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (sStoreTypeConfig.getStoreOpenRule() == 7) {
|
||||
long startTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER, 0, 1);
|
||||
long endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(), sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER, 0, 2);
|
||||
if (now < startTime || now > endTime) {
|
||||
continue;
|
||||
}
|
||||
for (ISession session : OnlineUserManager.sessionMap.values()) {
|
||||
if (session.getFiveReady() == 1) {
|
||||
User user = UserManager.getUser(session.getUid(), true);
|
||||
if (user == null) {
|
||||
LOGGER.info("user null removeid=>{}", session.getUid());
|
||||
OnlineUserManager.userOffline(session.getUid());
|
||||
continue;
|
||||
}
|
||||
if (!user.getStoreManager().getStoreInfoMap().containsKey(sStoreTypeConfig.getId())) {
|
||||
updateUsersStoreAyync(UserManager.getUser(session.getUid()), user1 -> {
|
||||
initOneStore(user1, sStoreTypeConfig.getId());
|
||||
MongoUtil.getInstence().lastUpdate();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (sStoreTypeConfig.getRefreshType()[0] == 2 && calendar.get(Calendar.MINUTE) == 0) {
|
||||
|
||||
for (int i = 1; i < sStoreTypeConfig.getRefreshType().length; i++) {
|
||||
if (sStoreTypeConfig.getRefreshType()[i] != calendar.get(Calendar.HOUR_OF_DAY)) {
|
||||
continue;
|
||||
|
@ -152,7 +142,7 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void sendRefreshIndication(SStoreTypeConfig sStoreTypeConfig,long lastRefreshTime) throws Exception {
|
||||
private void sendRefreshIndication(SStoreTypeConfig sStoreTypeConfig,long lastRefreshTime) throws Exception {
|
||||
for(ISession session : OnlineUserManager.sessionMap.values()){
|
||||
if(session.getFiveReady() == 1){
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
|
@ -174,18 +164,20 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
private static void updateUsersStoreAyync(User user, AyncWorkerRunnable ayncWorkerRunnable){
|
||||
private void updateUsersStoreAyync(User user, AyncWorkerRunnable ayncWorkerRunnable){
|
||||
AyyncWorker ayyncWorker = new AyyncWorker(user,true,ayncWorkerRunnable);
|
||||
ProtocolsManager.getInstance().updateAyncWorker(ayyncWorker);
|
||||
}
|
||||
|
||||
public static void getAllStoreInfo(ISession iSession) throws Exception {
|
||||
int msgId = MessageTypeProto.MessageType.GET_STARE_INFOS_RESPONSE_VALUE;
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
/**
|
||||
* 获取全部商店信息
|
||||
* @param iSession
|
||||
* @throws Exception
|
||||
*/
|
||||
public void getAllStoreInfo(ISession iSession) throws Exception {
|
||||
User user = UserManager.getUser(iSession.getUid());
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
initStoreInfo(user,storeManager);
|
||||
PlayerInfoProto.GetStoreInfosResponse.Builder builder = PlayerInfoProto.GetStoreInfosResponse.newBuilder();
|
||||
Map<Integer, StoreInfo> storeInfoMap = storeManager.getStoreInfoMap();
|
||||
checkStoreRefresh(user,storeInfoMap);
|
||||
List<CommonProto.StoreInfo> storeInfos = new ArrayList<>(storeInfoMap.size());
|
||||
|
@ -193,35 +185,39 @@ public class StoreLogic implements IEventHandler {
|
|||
CommonProto.StoreInfo.Builder storeBuilder = getBuilder(entry.getValue());
|
||||
storeInfos.add(storeBuilder.build());
|
||||
}
|
||||
PlayerInfoProto.GetStoreInfosResponse.Builder builder = PlayerInfoProto.GetStoreInfosResponse.newBuilder();
|
||||
builder.addAllStoreInfo(storeInfos);
|
||||
MessageUtil.sendMessage(iSession, 1,msgId, builder.build(), true);
|
||||
MessageUtil.sendMessage(iSession, 1,MessageTypeProto.MessageType.GET_STARE_INFOS_RESPONSE_VALUE, builder.build(), true);
|
||||
}
|
||||
|
||||
private static CommonProto.StoreInfo.Builder getBuilder(StoreInfo storeInfo) {
|
||||
/**
|
||||
* 商店对象转proto
|
||||
* @param storeInfo
|
||||
* @return
|
||||
*/
|
||||
private CommonProto.StoreInfo.Builder getBuilder(StoreInfo storeInfo) {
|
||||
// 初始化商店信息
|
||||
CommonProto.StoreInfo.Builder storeBuilder = CommonProto.StoreInfo.newBuilder();
|
||||
storeBuilder.setId(storeInfo.getId());
|
||||
storeBuilder.setLastRefreshTime(storeInfo.getLastRefreshTime());
|
||||
storeBuilder.setStartTime(storeInfo.getStartTime());
|
||||
storeBuilder.setEndTime(storeInfo.getEndTime());
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
List<CommonProto.StoreItem> builderList = new CopyOnWriteArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry1: itemNumMap.entrySet()){
|
||||
int itemId = entry1.getKey();
|
||||
if (!SStoreConfig.getSstoreConfigMap().containsKey(itemId)) {
|
||||
continue;
|
||||
}
|
||||
int buyNum = entry1.getValue();
|
||||
CommonProto.StoreItem.Builder storeItemBuilder = CommonProto.StoreItem.newBuilder();
|
||||
storeItemBuilder.setId(itemId);
|
||||
storeItemBuilder.setBuyNum(buyNum);
|
||||
builderList.add(storeItemBuilder.build());
|
||||
storeItemBuilder.setBuyNum(entry1.getValue());
|
||||
storeBuilder.addStoreItem(storeItemBuilder.build());
|
||||
}
|
||||
storeBuilder.addAllStoreItem(builderList);
|
||||
return storeBuilder;
|
||||
}
|
||||
|
||||
//检测商店刷新
|
||||
public static void checkStoreRefresh(User user,Map<Integer, StoreInfo> storeInfoMap) throws Exception {
|
||||
public void checkStoreRefresh(User user,Map<Integer, StoreInfo> storeInfoMap) throws Exception {
|
||||
long nowTime = System.currentTimeMillis();
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
Iterator<Map.Entry<Integer, StoreInfo>> it = storeInfoMap.entrySet().iterator();
|
||||
|
@ -265,11 +261,9 @@ public class StoreLogic implements IEventHandler {
|
|||
initOneStore(user,openId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static void sendStoreUpdateIndication(int uid,StoreInfo storeInfo){
|
||||
public void sendStoreUpdateIndication(int uid,StoreInfo storeInfo){
|
||||
CommonProto.StoreInfo.Builder builder = getBuilder(storeInfo);
|
||||
PlayerInfoProto.storeUpdateIndication build = PlayerInfoProto.storeUpdateIndication.newBuilder().addStoreInfo(builder).build();
|
||||
ISession session = OnlineUserManager.getSessionByUid(uid);
|
||||
|
@ -278,7 +272,7 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void initOnsStoereWithTime(User user,int storeType,long startTime,long endTime) throws Exception {
|
||||
public void initOnsStoereWithTime(User user,int storeType,long startTime,long endTime) throws Exception {
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
SStoreTypeConfig sStoreTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeType);
|
||||
if(sStoreTypeConfig == null){
|
||||
|
@ -289,7 +283,7 @@ public class StoreLogic implements IEventHandler {
|
|||
sendStoreUpdateIndication(user.getId(),storeManager.getStoreInfoMap().get(sStoreTypeConfig.getId()));
|
||||
}
|
||||
|
||||
public static void initOneStore(User user,int storeType) throws Exception {
|
||||
public void initOneStore(User user,int storeType) throws Exception {
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
SStoreTypeConfig sStoreTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeType);
|
||||
if(sStoreTypeConfig == null){
|
||||
|
@ -318,7 +312,7 @@ public class StoreLogic implements IEventHandler {
|
|||
sendStoreUpdateIndication(user.getId(),storeManager.getStoreInfoMap().get(sStoreTypeConfig.getId()));
|
||||
}
|
||||
|
||||
public static void initOrUpdateOneStore(User user,int storeType,int sort) throws Exception {
|
||||
public void initOrUpdateOneStore(User user,int storeType,int sort) throws Exception {
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
SStoreTypeConfig sStoreTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeType);
|
||||
if(sStoreTypeConfig == null){
|
||||
|
@ -354,22 +348,25 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
|
||||
//初始化商店
|
||||
private static void initStoreInfo(User user,StoreManager storeManager) throws Exception {
|
||||
private void initStoreInfo(User user, StoreManager storeManager) throws Exception {
|
||||
Map<Integer, SStoreTypeConfig> sstoreTypeConfigMap = SStoreTypeConfig.getsStoreTypeConfigMap();
|
||||
for ( Map.Entry<Integer, SStoreTypeConfig> entry :sstoreTypeConfigMap.entrySet()){
|
||||
for (Map.Entry<Integer, SStoreTypeConfig> entry :sstoreTypeConfigMap.entrySet()){
|
||||
SStoreTypeConfig sStoreTypeConfig = entry.getValue();
|
||||
long refreshTimeDelay = System.currentTimeMillis();
|
||||
// 整合
|
||||
long refreshTimeDelay = TimeUtils.now();
|
||||
int storeId = sStoreTypeConfig.getId();
|
||||
//如果有免费次数,在初始化时候把相对时间减去
|
||||
if(sStoreTypeConfig.getIfManualRefresh()[0]!=0){
|
||||
refreshTimeDelay-=sStoreTypeConfig.getIfManualRefresh()[0]*sStoreTypeConfig.getIfManualRefresh()[1]*TimeUtils.HOUR;
|
||||
int[] manualRefresh = sStoreTypeConfig.getIfManualRefresh();
|
||||
if(manualRefresh[0] != 0){
|
||||
refreshTimeDelay -= manualRefresh[0] * manualRefresh[1] * TimeUtils.HOUR;
|
||||
}
|
||||
StoreInfo storeInfo = storeManager.getStoreInfoMap().get(sStoreTypeConfig.getId());
|
||||
StoreInfo storeInfo = storeManager.getStoreInfoMap().get(storeId);
|
||||
if(sStoreTypeConfig.getStoreOpenRule() == 8){
|
||||
TimeControllerOfFunction openTimeOfFuntionCacheByType = GlobalDataManaager.getInstance().getOpenTimeOfFuntionCacheByType(FunctionIdEnum.getFunctionIdEnumByType(sStoreTypeConfig.getOpenLevel()[1]));
|
||||
if(openTimeOfFuntionCacheByType!=null ){
|
||||
if(storeInfo == null || storeInfo.getStartTime()!=openTimeOfFuntionCacheByType.getStartTime()){
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig,user);
|
||||
storeManager.newStoreInfo(sStoreTypeConfig.getId(),refreshTimeDelay,openTimeOfFuntionCacheByType.getStartTime(),openTimeOfFuntionCacheByType.getEndTime(),itemNumMap);
|
||||
if(storeInfo == null || storeInfo.getStartTime() != openTimeOfFuntionCacheByType.getStartTime()){
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(storeId,sStoreTypeConfig,user);
|
||||
storeManager.newStoreInfo(storeId,refreshTimeDelay,openTimeOfFuntionCacheByType.getStartTime(),openTimeOfFuntionCacheByType.getEndTime(),itemNumMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +374,7 @@ public class StoreLogic implements IEventHandler {
|
|||
// 探索商店用
|
||||
if (storeInfo.getId() == 91){
|
||||
//根据条件更新商品
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig,user);
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(storeId,sStoreTypeConfig,user);
|
||||
if (!itemNumMap.isEmpty()){
|
||||
Map<Integer, Integer> map = storeInfo.getItemNumMap();
|
||||
for (Integer itemId : itemNumMap.keySet()) {
|
||||
|
@ -395,13 +392,12 @@ public class StoreLogic implements IEventHandler {
|
|||
long endTime = ToolsUtil.getTimeLong(sStoreTypeConfig.getStartTimeLong(),sStoreTypeConfig.getEndTimeLong(), ActivityType.OPEN_TYPE_SERVER,0, 2);
|
||||
long now = TimeUtils.now();
|
||||
if(now>startTime&&now<endTime){
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig,user);
|
||||
storeManager.newStoreInfo(sStoreTypeConfig.getId(),refreshTimeDelay,startTime,endTime,itemNumMap);
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(storeId,sStoreTypeConfig,user);
|
||||
storeManager.newStoreInfo(storeId,refreshTimeDelay,startTime,endTime,itemNumMap);
|
||||
}
|
||||
|
||||
}
|
||||
if (sStoreTypeConfig.getStoreOpenRule() == 1 && sStoreTypeConfig.getId() !=8){ //固定商店
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig,user);
|
||||
if (sStoreTypeConfig.getStoreOpenRule() == 1 && storeId !=8){ //固定商店
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(storeId,sStoreTypeConfig,user);
|
||||
long startTime = 0;
|
||||
long endTime = 0;
|
||||
if (!sStoreTypeConfig.getStartTime().equals("0")){
|
||||
|
@ -410,16 +406,15 @@ public class StoreLogic implements IEventHandler {
|
|||
if (!sStoreTypeConfig.getEndTime().equals("0")){
|
||||
endTime = TimeUtils.parseTimeToMiles(sStoreTypeConfig.getEndTime(), TimeUtils.Stand_CeHua_Data_format);
|
||||
}
|
||||
storeManager.newStoreInfo(sStoreTypeConfig.getId(),refreshTimeDelay,startTime,endTime,itemNumMap);
|
||||
storeManager.newStoreInfo(storeId,refreshTimeDelay,startTime,endTime,itemNumMap);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 随机获得商店物品
|
||||
*/
|
||||
private static Map<Integer,Integer> getStoreItem(int storeId, SStoreTypeConfig sStoreTypeConfig ,User user) {
|
||||
private Map<Integer,Integer> getStoreItem(int storeId, SStoreTypeConfig sStoreTypeConfig, User user) {
|
||||
Map<Integer, Integer> itemNumMap = new ConcurrentHashMap<>();
|
||||
for (int i = 1; i <= sStoreTypeConfig.getNumber(); i ++){
|
||||
int rewardId = getRewardId(storeId,i,user);
|
||||
|
@ -431,7 +426,7 @@ public class StoreLogic implements IEventHandler {
|
|||
return itemNumMap;
|
||||
}
|
||||
|
||||
private static int getRewardId(int storeId,int sort,User user) {
|
||||
private int getRewardId(int storeId,int sort,User user) {
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
List<SStoreConfig> sstoreConfigBuyStore = SStoreConfig.getSstoreConfigBuyStore().get(storeId);
|
||||
List<SStoreConfig> randomSstoreConfigList = new CopyOnWriteArrayList<>();
|
||||
|
@ -476,153 +471,246 @@ public class StoreLogic implements IEventHandler {
|
|||
return rewardId;
|
||||
}
|
||||
|
||||
/**
|
||||
* 购买商店物品
|
||||
*/
|
||||
public static CommonProto.Drop buyStoreItem(int uid,int storeId, int itemId,int itemNum) throws Exception {
|
||||
User user = UserManager.getUser(uid);
|
||||
boolean update = checkBuyGoodsAndUpdate(user, storeId, itemId, itemNum);
|
||||
if (!update){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId==8?itemId%100000:itemId);
|
||||
int[][] goods = sStoreConfig.getGoods();
|
||||
int length = goods.length;
|
||||
int[][] extraAdd = sStoreConfig.getExtraAdd();
|
||||
int add = 10000;
|
||||
if(extraAdd != null){
|
||||
for(int[] extra : extraAdd){
|
||||
int type = extra[0];
|
||||
if(type == 2){
|
||||
int addPrivageId = extra[1];
|
||||
add = PlayerLogic.getInstance().getMaxCountByPrivilegeType(user,addPrivageId);
|
||||
public void buyStoreToBuilder(User user, int storeId, Map<Integer, Integer> map, CommonProto.Drop.Builder drop) throws Exception {
|
||||
int total = 0;
|
||||
SStoreTypeConfig storeTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeId);
|
||||
ArrayList<int[][]> reward = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry : map.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getStoreItem(storeId, id);
|
||||
Integer num = entry.getValue();
|
||||
int[][] goods = sStoreConfig.getGoods();
|
||||
int length = goods.length;
|
||||
int[][] extraAdd = sStoreConfig.getExtraAdd();
|
||||
int add = 10000;
|
||||
if(extraAdd != null){
|
||||
for(int[] extra : extraAdd){
|
||||
int type = extra[0];
|
||||
if(type == 2){
|
||||
int addPrivageId = extra[1];
|
||||
add = PlayerLogic.getInstance().getMaxCountByPrivilegeType(user,addPrivageId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
int[][] dropItems = new int[length][];
|
||||
for(int i=0;i<length;i++){
|
||||
dropItems[i] = new int[2];
|
||||
dropItems[i][0]= goods[i][0];
|
||||
int levelAdd = 0;
|
||||
if(storeId==Global.GODSTORID){
|
||||
if (sStoreConfig.getSort() == 1) {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum1();
|
||||
} else if (sStoreConfig.getSort() == 2) {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum2();
|
||||
} else {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum3();
|
||||
int[][] dropItems = new int[length][];
|
||||
for(int i=0;i<length;i++){
|
||||
dropItems[i] = new int[2];
|
||||
dropItems[i][0]= goods[i][0];
|
||||
int levelAdd = 0;
|
||||
if(storeId==Global.GODSTORID){
|
||||
if (sStoreConfig.getSort() == 1) {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum1();
|
||||
}
|
||||
else if (sStoreConfig.getSort() == 2) {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum2();
|
||||
}
|
||||
else {
|
||||
levelAdd = SPlayerLevelConfig.getsPlayerLevelConfigMap().get(user.getPlayerInfoManager().getLevel()).getGoldExtraNum3();
|
||||
}
|
||||
}
|
||||
dropItems[i][1] = ((goods[i][1] + levelAdd) * num * (add / 1000)) / 10;
|
||||
}
|
||||
dropItems[i][1] = ((goods[i][1] + levelAdd) * itemNum * (add / 1000)) / 10;
|
||||
// 解锁特权
|
||||
int[] openPrivilege = sStoreConfig.getOpenPrivilege();
|
||||
if(openPrivilege != null){
|
||||
PlayerInfoProto.PrivilegeIndication.Builder indication = PlayerInfoProto.PrivilegeIndication.newBuilder();
|
||||
for(int i=0;i<num;i++){
|
||||
for(int privilege:openPrivilege){
|
||||
BuyGoodsNewLogic.addNewPrivilege(user,privilege,indication);
|
||||
}
|
||||
}
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(user.getId());
|
||||
MessageUtil.sendIndicationMessage(sessionByUid,1, MessageTypeProto.MessageType.PRIVILLEGE_ADD_INDICATION_VALUE,indication.build(),true);
|
||||
}
|
||||
reward.add(dropItems);
|
||||
total += num;
|
||||
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.BUY_MATERIAL, goods[0][0], num, storeTypeConfig.getStoreType());
|
||||
}
|
||||
CommonProto.Drop.Builder drop = ItemUtil.drop(user, dropItems, BIReason.STORE_BUY_ITEM);
|
||||
if(!storeGiftType.contains(SStoreTypeConfig.getsStoreTypeConfigMap().get(storeId).getStoreType() )){
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.BUY_MATERIAL,sStoreConfig.getGoods()[0][0],itemNum,SStoreTypeConfig.getsStoreTypeConfigMap().get(storeId).getStoreType());
|
||||
}
|
||||
if(SStoreTypeConfig.getsStoreTypeConfigMap().get(storeId).getStoreType() == 10){
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.BUY_SEVEN_GIFT,storeId,itemNum);
|
||||
ItemUtil.drop(user, reward, drop, BIReason.STORE_BUY_ITEM);
|
||||
|
||||
// 任务和数据推送
|
||||
if(storeTypeConfig.getStoreType() == 10){
|
||||
user.getUserMissionManager().onGameEvent(user, GameEvent.BUY_SEVEN_GIFT, storeId, total);
|
||||
}
|
||||
if(storeId==Global.GODSTORID){
|
||||
Poster.getPoster().dispatchEvent(new GoldEvent(user.getId(),itemNum));
|
||||
Poster.getPoster().dispatchEvent(new GoldEvent(user.getId(),total));
|
||||
}
|
||||
if(storeId==Global.VIPSTORID){
|
||||
int vipLeve = user.getPlayerInfoManager().getVipLevel();
|
||||
user.getPlayerInfoManager().setHadTakeLevelBoxVip(vipLeve);
|
||||
}
|
||||
if(sStoreConfig.getOpenPrivilege()!=null){
|
||||
PlayerInfoProto.PrivilegeIndication.Builder indication = PlayerInfoProto.PrivilegeIndication.newBuilder();
|
||||
int[] openPrivilege = sStoreConfig.getOpenPrivilege();
|
||||
|
||||
for(int i=0;i<itemNum;i++){
|
||||
for(int privilege:openPrivilege){
|
||||
BuyGoodsNewLogic.addNewPrivilege(user,privilege,indication);
|
||||
}
|
||||
}
|
||||
ISession sessionByUid = OnlineUserManager.getSessionByUid(uid);
|
||||
MessageUtil.sendIndicationMessage(sessionByUid,1, MessageTypeProto.MessageType.PRIVILLEGE_ADD_INDICATION_VALUE,indication.build(),true);
|
||||
}
|
||||
|
||||
return drop.build();
|
||||
}
|
||||
|
||||
public static boolean checkBuyGoodsAndUpdate(User user,int storeId,int itemId,int itemNum) throws Exception {
|
||||
/**
|
||||
* 购买商店物品
|
||||
*/
|
||||
public void buyStoreItem(ISession session, PlayerInfoProto.BuyStoreItemRequest proto) throws Exception {
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
int storeId = proto.getStoreId();
|
||||
int itemId = proto.getItemId();
|
||||
int itemNum = proto.getItemNum();
|
||||
boolean update = checkBuyGoodsAndUpdate(user, storeId, itemId, itemNum);
|
||||
if (!update){
|
||||
throw new ErrorCodeException(ErrorCode.SYS_ERROR_CODE);
|
||||
}
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
map.put(itemId,itemNum);
|
||||
|
||||
CommonProto.Drop.Builder drop = CommonProto.Drop.newBuilder();
|
||||
buyStoreToBuilder(user,storeId,map, drop);
|
||||
|
||||
if (itemId==1106){
|
||||
Poster.getPoster().dispatchEvent(new NewWelfareEvent(user, NewWelfareTypeEnum.BUY_1106.getType(),0));
|
||||
}
|
||||
if (itemId==1107){
|
||||
Poster.getPoster().dispatchEvent(new NewWelfareEvent(user, NewWelfareTypeEnum.BUY_1107.getType(),0));
|
||||
}
|
||||
PlayerInfoProto.BuyStoreItemResponse builder = PlayerInfoProto.BuyStoreItemResponse.newBuilder().setDrop(drop).build();
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.BUY_STORE_ITEM_RESPONSE_VALUE, builder, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品是否可以购买
|
||||
* @param user
|
||||
* @param storeId
|
||||
* @param items
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean checkBuyGoods(User user,int storeId, Map<Integer, Integer> items) throws Exception{
|
||||
Map<Integer, StoreInfo> storeInfoMap = user.getStoreManager().getStoreInfoMap();
|
||||
if (!storeInfoMap.containsKey(storeId)){
|
||||
String format = MessageFormat.format("购买商品退出,商店已关闭,uid:{0},storeId:{1}", user.getId(), storeId);
|
||||
throw new ErrorCodeException(ErrorCode.SHOP_COLSE,format);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getSstoreConfigMap().get(storeId == 8 ? itemId % 100000 : itemId);
|
||||
if (sStoreConfig == null) {
|
||||
String format = MessageFormat.format("购买商品退出,商品已下架,uid:{0},storeId:{1},itemId:{2}", user.getId(), storeId,itemId);
|
||||
throw new ErrorCodeException(ErrorCode.SHOP_XIA_JIA,format);
|
||||
}
|
||||
StoreInfo storeInfo = storeInfoMap.get(storeId);
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
if (!itemNumMap.containsKey(itemId)){
|
||||
String format = MessageFormat.format("购买商品退出,商品不存在,uid:{0},storeId:{1},itemId:{2}", user.getId(), storeId,itemId);
|
||||
throw new ErrorCodeException(ErrorCode.SHOP_NO_ITEM,format);
|
||||
}
|
||||
int[] buyRule = sStoreConfig.getBuyRule();
|
||||
if (buyRule != null && buyRule.length > 0){
|
||||
switch (buyRule[0]){
|
||||
case 1://充值金额购买条件判断
|
||||
double amount = BuyGoodsNewLogic.getAllAmount(user);
|
||||
if (amount < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,充值金额不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
throw new ErrorCodeException(format);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
int godPrivilegeLv = PlayerLogic.getInstance().getGodPrivilegeLv(user);
|
||||
if (godPrivilegeLv < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,神尊等级不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
throw new ErrorCodeException(format);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
int renownPrivilegeLv = PlayerLogic.getInstance().getRenownPrivilegeLv(user);
|
||||
if (renownPrivilegeLv < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,名望等级不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
throw new ErrorCodeException(format);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
String format = MessageFormat.format("购买商品退出,未知的条件类型,请联系策划确认,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
throw new ErrorCodeException(format);
|
||||
ArrayList<int[][]> costList = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry : items.entrySet()) {
|
||||
// 商品信息
|
||||
Integer itemId = entry.getKey();
|
||||
Integer itemNum = entry.getValue();
|
||||
// 配置信息
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getStoreItem(storeId, itemId);
|
||||
if (sStoreConfig == null) {
|
||||
String format = MessageFormat.format("购买商品退出,商品已下架,uid:{0},storeId:{1},itemId:{2}", user.getId(), storeId,itemId);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
StoreInfo storeInfo = storeInfoMap.get(storeId);
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
if (!itemNumMap.containsKey(itemId)){
|
||||
String format = MessageFormat.format("购买商品退出,商品不存在,uid:{0},storeId:{1},itemId:{2}", user.getId(), storeId,itemId);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
// 购买条件
|
||||
int[] buyRule = sStoreConfig.getBuyRule();
|
||||
if (buyRule != null && buyRule.length > 0){
|
||||
switch (buyRule[0]){
|
||||
case 1://充值金额购买条件判断
|
||||
double amount = BuyGoodsNewLogic.getAllAmount(user);
|
||||
if (amount < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,充值金额不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
int godPrivilegeLv = PlayerLogic.getInstance().getGodPrivilegeLv(user);
|
||||
if (godPrivilegeLv < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,神尊等级不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
int renownPrivilegeLv = PlayerLogic.getInstance().getRenownPrivilegeLv(user);
|
||||
if (renownPrivilegeLv < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,名望等级不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
case 4:
|
||||
int shuachongLv = user.getPlayerInfoManager().getVipPrivilageValue(VipPrivilegeType.SHUACHONG_VIP_LV);
|
||||
if (shuachongLv < buyRule[1]){
|
||||
String format = MessageFormat.format("购买商品退出,刷冲等级不足,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
String format = MessageFormat.format("购买商品退出,未知的条件类型,请联系策划确认,uid:{0},storeId:{1},itemId:{2},itemNum:{3}", user.getId(), storeId,itemId,itemNum);
|
||||
LOGGER.error(format);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 限购次数验证
|
||||
int buyTimes = itemNumMap.get(itemId);
|
||||
int limit = sStoreConfig.getLimit();
|
||||
int relatedtoVIP = sStoreConfig.getRelatedtoVIP();
|
||||
if(limit != 0){
|
||||
boolean check;
|
||||
if(relatedtoVIP == 1){
|
||||
if(limit == 6){
|
||||
int goodsNum = sStoreConfig.getGoods()[0][1]*itemNum;
|
||||
check = PlayerLogic.getInstance().check(user,limit, goodsNum);
|
||||
}else{
|
||||
check = PlayerLogic.getInstance().check(user,limit, itemNum);
|
||||
}
|
||||
}else{
|
||||
check = limit > buyTimes;
|
||||
}
|
||||
if(!check){
|
||||
LOGGER.error("购买商店商品校验,超过限购次数,uid:{},store:{},itemid:{},num:{}",user.getId(),storeId,itemId,itemNum);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// 消耗道具累加
|
||||
int[][] cost = getCost(buyTimes ,itemNum, sStoreConfig.getCost(), sStoreConfig.getPremiumType(),sStoreConfig.getIsDiscount(),sStoreConfig.getDiscountDegree());
|
||||
costList.add(cost);
|
||||
}
|
||||
// 消耗道具
|
||||
Map<Integer, Long> costMap = Utils.getItemMapObject(costList);
|
||||
return ItemUtil.checkCostLong(user, costMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* 校验商品并购买
|
||||
* @param user
|
||||
* @param storeId
|
||||
* @param itemId
|
||||
* @param itemNum
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public boolean checkBuyGoodsAndUpdate(User user,int storeId,int itemId,int itemNum) throws Exception {
|
||||
HashMap<Integer, Integer> map = new HashMap<>();
|
||||
map.put(itemId, itemNum);
|
||||
// 校验是否满足购买条件
|
||||
boolean checked = checkBuyGoods(user, storeId, map);
|
||||
if (!checked){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
|
||||
Map<Integer, StoreInfo> storeInfoMap = user.getStoreManager().getStoreInfoMap();
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getStoreItem(storeId, itemId);
|
||||
StoreInfo storeInfo = storeInfoMap.get(storeId);
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
int buyTimes = itemNumMap.get(itemId);
|
||||
int limit = sStoreConfig.getLimit();
|
||||
int relatedtoVIP = sStoreConfig.getRelatedtoVIP();
|
||||
if(limit!=0){
|
||||
boolean check;
|
||||
if(relatedtoVIP == 1){
|
||||
if(limit == 6){
|
||||
int goodsNum = sStoreConfig.getGoods()[0][1]*itemNum;
|
||||
check = PlayerLogic.getInstance().checkAndUpdate(user,limit, goodsNum);
|
||||
}else{
|
||||
check = PlayerLogic.getInstance().checkAndUpdate(user,limit, itemNum);
|
||||
}
|
||||
}else{
|
||||
check = limit > buyTimes;
|
||||
}
|
||||
if(!check){
|
||||
throw new ErrorCodeException(ErrorCode.SERVER_SELF_DEFINE);
|
||||
}
|
||||
}
|
||||
// 校验道具小孩
|
||||
int[][] cost = getCost(buyTimes ,itemNum, sStoreConfig.getCost(), sStoreConfig.getPremiumType(),sStoreConfig.getIsDiscount(),sStoreConfig.getDiscountDegree());
|
||||
boolean result = ItemUtil.itemCost(user, cost, BIReason.BUY_GOODS_CONSUME, storeId);
|
||||
if (!result){
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
|
||||
}
|
||||
itemNumMap.put(itemId,buyTimes +itemNum);
|
||||
itemNumMap.put(itemId,buyTimes + itemNum);
|
||||
storeInfo.setItemNumMap(itemNumMap);
|
||||
KtEventUtils.onKtEvent(user, ParamEventBean.UserStoreEvent,storeId,itemId,cost[0][0],itemNum,cost[0][1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static int[][] getCost(int buyTimes,int itemNum,int[][] costs,int premiumType,int isDiscount,int discountDegree) {
|
||||
public int[][] getCost(int buyTimes,int itemNum,int[][] costs,int premiumType,int isDiscount,int discountDegree) {
|
||||
int costItemId = costs[0][0];
|
||||
int[] ints = costs[1];
|
||||
int nums = buyTimes+itemNum;
|
||||
|
@ -644,18 +732,11 @@ public class StoreLogic implements IEventHandler {
|
|||
if(isDiscount == 1){
|
||||
totalCost = totalCost * discountDegree/10;
|
||||
}
|
||||
|
||||
int[][] value1 = new int[1][];
|
||||
int[] value2 = new int[2];
|
||||
value2[0] = costItemId;
|
||||
value2[1] = totalCost;
|
||||
value1[0] =value2;
|
||||
return value1;
|
||||
return new int[][]{{costItemId, totalCost}};
|
||||
}
|
||||
|
||||
//手动刷新商店
|
||||
public static void handRefreStore(ISession iSession,int storeId) throws Exception {
|
||||
int msgId = MessageTypeProto.MessageType.STORE_GOODS_REFRESH_RESPONSE_VALUE;
|
||||
public void handRefreStore(ISession iSession,int storeId) throws Exception {
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
StoreManager storeManager = user.getStoreManager();
|
||||
|
@ -692,17 +773,15 @@ public class StoreLogic implements IEventHandler {
|
|||
storeInfo.setLastRefreshTime(refreshTime);
|
||||
}
|
||||
}
|
||||
|
||||
// playerInfoManager.updateVipPrivilage(refreshPrivilege,1);
|
||||
Map<Integer, Integer> itemNumMap = getStoreItem(sStoreTypeConfig.getId(),sStoreTypeConfig,user);
|
||||
storeInfo.setItemNumMap(itemNumMap);
|
||||
CommonProto.StoreInfo.Builder storeBuilder = getBuilder(storeInfo);
|
||||
PlayerInfoProto.StoreGoodsRefreshResponse builder = PlayerInfoProto.StoreGoodsRefreshResponse.newBuilder().setStoreInfo(storeBuilder).build();
|
||||
MessageUtil.sendMessage(iSession, 1,msgId, builder, true);
|
||||
MessageUtil.sendMessage(iSession, 1, MessageTypeProto.MessageType.STORE_GOODS_REFRESH_RESPONSE_VALUE, builder, true);
|
||||
}
|
||||
|
||||
//无免费刷新
|
||||
private static void noFreeRefreshStore(User user,SStoreTypeConfig sStoreTypeConfig,int storeId) throws Exception {
|
||||
private void noFreeRefreshStore(User user,SStoreTypeConfig sStoreTypeConfig,int storeId) throws Exception {
|
||||
PlayerManager playerInfoManager = user.getPlayerInfoManager();
|
||||
int refreshPrivilege = sStoreTypeConfig.getRefreshPrivilege();
|
||||
int refreshNum = playerInfoManager.getVipPrivilageValue(refreshPrivilege);
|
||||
|
@ -718,7 +797,7 @@ public class StoreLogic implements IEventHandler {
|
|||
|
||||
|
||||
//自动刷新商店
|
||||
public static void automaticRefreStore(ISession iSession,int storeId) throws Exception {
|
||||
public void automaticRefreStore(ISession iSession,int storeId) throws Exception {
|
||||
int msgId = MessageTypeProto.MessageType.STORE_GOODS_REFRESH_RESPONSE_VALUE;
|
||||
int uid = iSession.getUid();
|
||||
User user = UserManager.getUser(uid);
|
||||
|
@ -770,10 +849,10 @@ public class StoreLogic implements IEventHandler {
|
|||
MessageUtil.sendMessage(iSession, 1,msgId, builder, true);
|
||||
}
|
||||
|
||||
public static boolean checkContainsStore(User user,StoreType storeType,boolean isRefresh) throws Exception {
|
||||
public boolean checkContainsStore(User user,StoreType storeType,boolean isRefresh) throws Exception {
|
||||
Map<Integer, StoreInfo> storeInfoMap = user.getStoreManager().getStoreInfoMap();
|
||||
if(isRefresh){
|
||||
StoreLogic.checkStoreRefresh(user, storeInfoMap);
|
||||
checkStoreRefresh(user, storeInfoMap);
|
||||
}
|
||||
for(Integer storeId : storeInfoMap.keySet()){
|
||||
SStoreTypeConfig sStoreTypeConfig = SStoreTypeConfig.getsStoreTypeConfigMap().get(storeId);
|
||||
|
@ -787,7 +866,7 @@ public class StoreLogic implements IEventHandler {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void checkAllowOfFunction(FunctionRefreshEvent functionRefreshEvent) throws Exception {
|
||||
public void checkAllowOfFunction(FunctionRefreshEvent functionRefreshEvent) throws Exception {
|
||||
if(functionRefreshEvent.getInvokeId()!=-1){
|
||||
return;
|
||||
}
|
||||
|
@ -812,7 +891,7 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
public static void reloadStoreInfo(User user,int type){
|
||||
public void reloadStoreInfo(User user,int type){
|
||||
Map<Integer, StoreInfo> storeInfoMap = user.getStoreManager().getStoreInfoMap();
|
||||
if(!storeInfoMap.containsKey(type)){
|
||||
return;
|
||||
|
@ -829,12 +908,65 @@ public class StoreLogic implements IEventHandler {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(IEvent event) throws Exception {
|
||||
if(!(event instanceof FunctionRefreshEvent)){
|
||||
return;
|
||||
/**
|
||||
* 一键购买商店全部商品
|
||||
* @param session
|
||||
* @param storeId
|
||||
*/
|
||||
public void oneClickPurchase(ISession session, int storeId) throws Exception {
|
||||
User user = UserManager.getUser(session.getUid());
|
||||
StoreInfo storeInfo = user.getStoreManager().getStoreInfoMap().get(storeId);
|
||||
if (storeInfo == null){
|
||||
String format = MessageFormat.format("一键购买商店退出,商店已关闭,uid:{0},storeId:{1}", user.getId(), storeId);
|
||||
throw new ErrorCodeException(format);
|
||||
}
|
||||
checkAllowOfFunction((FunctionRefreshEvent)event);
|
||||
Map<Integer, SStoreConfig> configMap = SStoreConfig.getSstoreConfigMap();
|
||||
HashMap<Integer, Integer> itemMap = new HashMap<>();
|
||||
for (Map.Entry<Integer, Integer> entry : storeInfo.getItemNumMap().entrySet()) {
|
||||
Integer itemId = entry.getKey();
|
||||
Integer num = entry.getValue();
|
||||
SStoreConfig config = configMap.get(itemId);
|
||||
if (config == null){
|
||||
LOGGER.error("一键购买商店存在未配置的商品,uid:{},storeid:{},itemid:{}",user.getId(), storeId, itemId);
|
||||
continue;
|
||||
}
|
||||
// 最多一次买100个
|
||||
int count = Math.min(config.getLimit()-num, 100);
|
||||
if (count <= 0){
|
||||
LOGGER.error("一键购买商店,商品已购买,uid:{},storeid:{},itemid:{},num:{}, limit:{}",user.getId(), storeId, itemId, num, config.getLimit());
|
||||
continue;
|
||||
}
|
||||
itemMap.put(itemId, count);
|
||||
}
|
||||
// 校验是否可以购买
|
||||
boolean checked = checkBuyGoods(user, storeId, itemMap);
|
||||
if (!checked){
|
||||
throw new ErrorCodeException(ErrorCode.ITEM_NOT_ENOUGH);
|
||||
}
|
||||
Map<Integer, Integer> itemNumMap = storeInfo.getItemNumMap();
|
||||
ArrayList<int[][]> list = new ArrayList<>();
|
||||
for (Map.Entry<Integer, Integer> entry : itemMap.entrySet()) {
|
||||
Integer id = entry.getKey();
|
||||
Integer num = entry.getValue();
|
||||
int buyTimes = itemNumMap.get(id);
|
||||
SStoreConfig sStoreConfig = SStoreConfig.getStoreItem(storeId, id);
|
||||
int[][] cost = getCost(buyTimes ,num, sStoreConfig.getCost(), sStoreConfig.getPremiumType(),sStoreConfig.getIsDiscount(),sStoreConfig.getDiscountDegree());
|
||||
list.add(cost);
|
||||
itemNumMap.put(id,buyTimes + num);
|
||||
}
|
||||
// 消耗并存储
|
||||
ItemUtil.itemCost(user, list, BIReason.BUY_GOODS_CONSUME, 0);
|
||||
storeInfo.setItemNumMap(itemNumMap);
|
||||
|
||||
// 获取奖励
|
||||
CommonProto.Drop.Builder drop = CommonProto.Drop.newBuilder();
|
||||
buyStoreToBuilder(user, storeId, itemMap, drop);
|
||||
|
||||
// 推送商城数据
|
||||
sendStoreUpdateIndication(user.getId(), storeInfo);
|
||||
|
||||
PlayerInfoProto.StoreOneClickPurchaseResponse.Builder builder = PlayerInfoProto.StoreOneClickPurchaseResponse.newBuilder().setDrop(drop);
|
||||
MessageUtil.sendMessage(session, 1, MessageTypeProto.MessageType.StoreOneClickPurchaseResponse_VALUE, builder.build(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -252,7 +252,7 @@ public class SessionManager implements INetSession<ISession>, INetReceived<ISess
|
|||
MissionEventDistributor.requestStart();
|
||||
ActivityLogic.getInstance().updateActivityMissionProgress(userInMem, ActivityType.OnlineReward,0);
|
||||
try {
|
||||
StoreLogic.checkStoreRefresh(userInMem,userInMem.getStoreManager().getStoreInfoMap());
|
||||
StoreLogic.getInstance().checkStoreRefresh(userInMem,userInMem.getStoreManager().getStoreInfoMap());
|
||||
GlobalDataManaager.checkNeedReFlush(session, userInMem, PlayerInfoProto.FivePlayerUpdateIndication.newBuilder());
|
||||
List<CommonProto.Item> allItemList = ItemUtil.getAllItem(userInMem,false);
|
||||
if(!allItemList.isEmpty()){
|
||||
|
|
|
@ -66,7 +66,7 @@ public class MinuteTask extends Thread {
|
|||
STableManager.updateTablesWithTableNames(true);
|
||||
//计算世界等级
|
||||
ActivityLogic.getInstance().checkSecretBoxSeason();
|
||||
StoreLogic.checkGlobalStore(false);
|
||||
StoreLogic.getInstance().checkGlobalStore(false);
|
||||
|
||||
try {
|
||||
MapLogic.getInstance().minuteCheckAndRemoveMapRank();
|
||||
|
|
|
@ -10,9 +10,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
|
||||
@Table(name ="StoreConfig")
|
||||
public class SStoreConfig implements BaseConfig {
|
||||
private static Map<Integer, SStoreConfig> sStoreConfigMap;
|
||||
//key: type 商店类型
|
||||
private static Map<Integer, List<SStoreConfig>> sStoreConfigMapBuyType;
|
||||
|
||||
private int id;
|
||||
|
||||
|
@ -48,6 +45,9 @@ public class SStoreConfig implements BaseConfig {
|
|||
|
||||
private int[] buyRule;
|
||||
|
||||
private static Map<Integer, SStoreConfig> sStoreConfigMap;
|
||||
//key: type 商店类型
|
||||
private static Map<Integer, List<SStoreConfig>> sStoreConfigMapBuyType;
|
||||
|
||||
@Override
|
||||
public void init() throws Exception {
|
||||
|
@ -56,7 +56,7 @@ public class SStoreConfig implements BaseConfig {
|
|||
for (Map.Entry<Integer, SStoreConfig> entry :sStoreConfigMap.entrySet()){
|
||||
SStoreConfig data = entry.getValue();
|
||||
if (!sStoreConfigMapBuyType.containsKey(data.getStoreId())) {
|
||||
sStoreConfigMapBuyType.put((data.getStoreId()), new ArrayList<SStoreConfig>());
|
||||
sStoreConfigMapBuyType.put((data.getStoreId()), new ArrayList<>());
|
||||
}
|
||||
sStoreConfigMapBuyType.get(data.getStoreId()).add(data);
|
||||
}
|
||||
|
@ -67,6 +67,11 @@ public class SStoreConfig implements BaseConfig {
|
|||
return sStoreConfigMap;
|
||||
}
|
||||
|
||||
public static SStoreConfig getStoreItem(int storeId, int itemId) {
|
||||
int id = storeId == 8 ? itemId % 100000 : itemId;
|
||||
return sStoreConfigMap.get(id);
|
||||
}
|
||||
|
||||
public static Map<Integer, List<SStoreConfig>> getSstoreConfigBuyStore() {
|
||||
return sStoreConfigMapBuyType;
|
||||
}
|
||||
|
|
|
@ -45,12 +45,14 @@ public class SStoreTypeConfig implements BaseConfig {
|
|||
int time = sStoreTypeConfig.getStoreOpenRule();
|
||||
String startTime = sStoreTypeConfig.getStartTime();
|
||||
String endtime = sStoreTypeConfig.getEndTime();
|
||||
// 竞技场
|
||||
if(time == 8 && sStoreTypeConfig.getOpenLevel().length>0 && sStoreTypeConfig.getOpenLevel()[0] == 3){
|
||||
if(!storeIdByFunctionMapTmp.containsKey(sStoreTypeConfig.getOpenLevel()[1])){
|
||||
storeIdByFunctionMapTmp.put(sStoreTypeConfig.getOpenLevel()[1],new ArrayList<>());
|
||||
}
|
||||
storeIdByFunctionMapTmp.get(sStoreTypeConfig.getOpenLevel()[1]).add(sStoreTypeConfig.getId());
|
||||
}
|
||||
// 常驻
|
||||
if(time == 1 ){//ActivityType.OPEN_TYPE_TIME
|
||||
if (!sStoreTypeConfig.getStartTime().equals("0")){
|
||||
sStoreTypeConfig.setStartTimeLong(TimeUtils.parseTimeToMiles(sStoreTypeConfig.getStartTime(), TimeUtils.Stand_CeHua_Data_format));
|
||||
|
|
Loading…
Reference in New Issue