Demo entry 6356530

fdsafsadtest

   

Submitted by anonymous on Apr 19, 2017 at 03:59
Language: Java. Code size: 48.4 kB.

package com.hoolai.sango.activity;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

import com.hoolai.game.event.CoreEventType;
import com.hoolai.game.event.Event;
import com.hoolai.game.event.EventListener;
import com.hoolai.game.event.ListenerRegistrator;
import com.hoolai.game.event.player.PlayerLevelUpEvent;
import com.hoolai.game.event.soldier.SoldierEventType;
import com.hoolai.game.global.task.DefaultDailyTask;
import com.hoolai.game.log.produce.ProduceSource;
import com.hoolai.game.player.callable.ModularCallable;
import com.hoolai.game.protocol.activity.ActivityMsgProto.ActivityListMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.ActivityRedPointMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.BuyFromMainPanelMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.BuyFromMyCrowdfundingPanelMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.BuyPanelFromMainPanelMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.CloseActivityMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.GainGoodsMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.GroupBuyRewardDataMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.GroupBuyRewardListMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MainPanelDataMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MainPanelMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MyCrowdfundingAllMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MyCrowdfundingIsEndDataMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MyCrowdfundingNotEndDataMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.MyCrowdfundingPanelMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.OpenActivityMsg;
import com.hoolai.game.protocol.activity.ActivityMsgProto.UpdateAchievementMsg;
import com.hoolai.game.ranking.RankingContext;
import com.hoolai.game.reward.Reward;
import com.hoolai.game.reward.entity.RewardStatus;
import com.hoolai.injection.Inject;
import com.hoolai.modular.ModularDependence;
import com.hoolai.net.codec.Message;
import com.hoolai.sango.activity.components.grouppurchase.GroupPurchaseActivity;
import com.hoolai.sango.activity.components.grouppurchase.GroupPurchaseItem;
import com.hoolai.sango.activity.components.grouppurchase.GroupPurchaseItemTemplate;
import com.hoolai.sango.activity.entity.ActivityRepo;
import com.hoolai.sango.activity.entity.ActivityTemplateInfo;
import com.hoolai.sango.activity.entity.ActivityType;
import com.hoolai.sango.activity.entity.CrowdfundingActivityTemplate;
import com.hoolai.sango.activity.entity.achievement.AchievementInfo;
import com.hoolai.sango.activity.entity.achievement.ActSevenGoalTemplate;
import com.hoolai.sango.activity.entity.base.ActivityInfo;
import com.hoolai.sango.activity.entity.base.ActivityItemInfo;
import com.hoolai.sango.activity.entity.base.ActivityItemTemplate;
import com.hoolai.sango.activity.entity.crowdfundingActivity.CrowdfundingActivityCommunal;
import com.hoolai.sango.activity.entity.crowdfundingActivity.CrowdfundingActivityPlayer;
import com.hoolai.sango.activity.entity.getenergy.EnergyInfo;
import com.hoolai.sango.activity.entity.groupbuy.CurrentDayRechargeInfo;
import com.hoolai.sango.activity.entity.groupbuy.GroupBuyRewardTemplateInfo;
import com.hoolai.sango.activity.event.AchievementCompleteEvent;
import com.hoolai.sango.activity.event.AchievementSubmitEvent;
import com.hoolai.sango.activity.event.ActSevenGoalDayEvent;
import com.hoolai.sango.activity.event.ActSevenGoalScoreEvent;
import com.hoolai.sango.activity.event.ActivityCompleteEvent;
import com.hoolai.sango.activity.event.ActivityEventType;
import com.hoolai.sango.activity.event.AddRedPointEvent;
import com.hoolai.sango.activity.event.OnlineTimeEvent;
import com.hoolai.sango.activity.event.OpenActivityEvent;
import com.hoolai.sango.activity.event.OverActivityEvent;
import com.hoolai.sango.activity.event.RechargeRankingEvent;
import com.hoolai.sango.activity.event.RemoveRedPointEvent;
import com.hoolai.sango.activity.event.ShenjiangScoreEvent;
import com.hoolai.sango.activity.protocol.ActivityProtocol;
import com.hoolai.sango.activity.template.ActivityTemplates;
import com.hoolai.sango.bag.event.BagEventType;
import com.hoolai.sango.bag.event.ItemConsumeEvent;
import com.hoolai.sango.constant.GameConstantTemplates.ConstantKey;
import com.hoolai.sango.global.IdGenerator;
import com.hoolai.sango.global.TransientInventory;
import com.hoolai.sango.mail.MailContext;
import com.hoolai.sango.player.GamePlayer;
import com.hoolai.sango.player.event.PlayerEventType;
import com.hoolai.sango.player.module.DailyResetter;
import com.hoolai.sango.player.module.DataSynchronizer;
import com.hoolai.sango.quest.QuestInventory;
import com.hoolai.sango.quest.entity.Change;
import com.hoolai.sango.quest.entity.ConditionType;
import com.hoolai.sango.quest.entity.Quest;
import com.hoolai.sango.quest.entity.QuestTemplateInfo;
import com.hoolai.sango.quest.entity.QuestType;
import com.hoolai.sango.quest.processor.MainQuestsProcessor;
import com.hoolai.sango.quest.processor.QuestsNotifier;
import com.hoolai.sango.quest.processor.QuestsProcessor;
import com.hoolai.sango.quest.template.QuestTemplates;
import com.hoolai.sango.reward.RewardHandler;
import com.hoolai.sango.vip.entiy.recharge.RechargeTemplate;
import com.hoolai.sango.vip.event.RechargeActivityEvent;
import com.hoolai.sango.vip.event.RechargeCoinEvent;
import com.hoolai.sango.vip.event.RechargeEvent;
import com.hoolai.sango.vip.event.RechargeEventType;
import com.hoolai.sango.vip.template.RechargeTemplates;
import com.hoolai.sango.vip.template.VipTemplates;
import com.hoolai.util.collection.IntHashMap;


@ModularDependence({ QuestInventory.class })
public class ActivityInventory extends TransientInventory<GamePlayer, SharableActivity> implements SharableActivity, DailyResetter, DataSynchronizer {

	//所有活动信息 key : activityType
	private Map<Integer, ActivityInfo> activityInfoMap;
	
	private Map<Integer, Integer> redPointActivityMap;

	private GamePlayer player;
	@Inject
	private ActivityRepo activityRepo;
	@Inject
	private ActivityContext activityContext;
	@Inject
	private ActivityTemplates templates;
	@Inject
	private QuestTemplates questTemplates;
	@Inject
	private VipTemplates vipTemplates;
	@Inject
	private RankingContext rankingContext;
	@Inject
	private MailContext mailContext;
    @Inject
    private RechargeTemplates rechargeTemplates;
    @Inject
    private IdGenerator idGenerator;
    @Inject
    private CrowdfundingContext crowdfundingContext;
	

	private IntHashMap<CrowdfundingActivityPlayer> crowdfundingActivityPlayerMap;//获取本角色众筹数据

	//7日目标
	private AchievementInfo achievementInfo;

	//当日充值信息(每日首充团购)
	private CurrentDayRechargeInfo currRechargeInfo;
	//领取体力活动
	private EnergyInfo energyInfo;
	
	//消钻团购 玩家购买的次数
	private IntHashMap<Integer> purchaseCountMap;
	
	@Override
	public boolean load(GamePlayer player) {
		
		this.player = player;

		long playerId = player.getPlayerId();

		//所有活动
		this.activityInfoMap = new ConcurrentHashMap<>();
		for (ActivityInfo activityInfo : activityRepo.fetchActivityInfos(playerId)) {
			activityInfo.setItemInfos(activityRepo.fetchActivityItemInfos(playerId, activityInfo.getActivityType()));
			activityInfoMap.put(activityInfo.getActivityType(), activityInfo);
		}
		//**************************************************************************************//
		loadAchievementInfo(playerId);

		currRechargeInfo = activityRepo.fetchCurrentDayRechargeInfo(playerId);
		
		energyInfo = activityRepo.fetchEnergyInfo(playerId);
		
		redPointActivityMap = new ConcurrentHashMap<>();

		//获取本角色众筹数据
		crowdfundingActivityPlayerMap = crowdfundingContext.getCrowdfundingActivityPlayerMap(playerId);
        
		return true;
	}

	private void loadAchievementInfo(long playerId) {
		achievementInfo = activityRepo.fetchAchievementInfo(playerId);
		if (achievementInfo != null) {
			return;
		}
		achievementInfo = new AchievementInfo(playerId);
		for (int i = achievementInfo.stepDayStartIndex(); i <= achievementInfo.getStepOpenDay(); i++) {
			ActSevenGoalTemplate sevenGoalTemplate = templates.getSevenGoalTemplate(achievementInfo.getStep(), i);
			sevenGoalPrepare(sevenGoalTemplate.allQuestList());
		}
	}

	private void calRedPoint() {
		for (ActivityInfo activityInfo : activityInfoMap.values()) {
			ActivityType activityType = activityInfo.getActivityType0();
			if (!this.isOpen(activityType)) {
				continue;
			}
			boolean hasRedPoint = activityInfo.hasRedPoint();
			if (hasRedPoint) {
				addRedPoint(activityType);
			}
		}
		
		if (isOpen(ActivityType.GROUP_BUY) && currRechargeInfo.hasRedPoint(templates, activityContext.getTotalRechargePerson())) {
			addRedPoint(ActivityType.GROUP_BUY);
		}
		
		if (isOpen(ActivityType.SEVENGOAL) && achievementInfo.hasRedPoint(player, templates)) {
			addRedPoint(ActivityType.SEVENGOAL);
		}
		
		if(isOpen(ActivityType.GET_ENERGY) && energyInfo.hasRedPoint()){
			addRedPoint(ActivityType.GET_ENERGY);
		}
		sendActivityRedPointMsg();
	}
	
	public boolean isVisible(ActivityType activityType) {
		Activity activity = activityContext.getActivity(activityType);
		if (activity == null) {
			return false;
		}
		return activity.isVisible(player);
	}

	public boolean isOpen(ActivityType activityType) {
		Activity activity = activityContext.getActivity(activityType);
//		if (activity == null) {
//			return false;
//		}
		return activity.isOpen(player);
	}
	
	
	private void addRedPoint(ActivityType activityType) {
		redPointActivityMap.put(activityType.getCode(), activityType.getCode());
	}
	
	private void removeRedPointAndSync(ActivityType activityType) {
		if (!redPointActivityMap.containsKey(activityType.getCode())) {
			return;
		}
		redPointActivityMap.remove(activityType.getCode());
		sendActivityRedPointMsg();
	}

	@Override
	public SharableActivity share() {
		return this;
	}

	@Override
	public void registListener(ListenerRegistrator registrator) {
		registrator.regist(new EventListener(ActivityEventType.OPEN_ACTIVITY) {
			@Override
			public void onEvent(Event event) {
				OpenActivityEvent openEvent = (OpenActivityEvent)event;
				ActivityType activityType = ActivityType.getTypeByCode(openEvent.activityType);
				Activity activity = activityContext.getActivity(activityType);
				if (activityType.isSeries()) {
					activityType.getActivityHandler().init(activityType, player);
				}
				sendOpenActivityMsg(activity);
				if (activityType.isSeries()) {
					ActivityInfo activityInfo = getActivityInfo(activityType);
					sendActivityInfoMsg(activityInfo);
				}
			}
		});

		registrator.regist(new EventListener(ActivityEventType.OVER_ACTIVITY) {
			@Override
			public void onEvent(Event event) {
				OverActivityEvent overEvent = (OverActivityEvent)event;
				int activityType = overEvent.activityType;
				Activity activity = activityContext.getActivity(ActivityType.getTypeByCode(activityType));
				removeRedPointAndSync(activity.getActivityType0());
				sendOverActivityMsg(activity);
				
				ActivityInfo activityInfo = activityInfoMap.get(activityType);
				if (activityInfo != null) {
					activityInfo.overTime();
					triggerNewActivity();
				}
			}
		});

		registrator.regist(new EventListener(ActivityEventType.ACTIVITY_COMPLETE) {
			@Override
			public void onEvent(Event event) {
				ActivityCompleteEvent disappearEvent = (ActivityCompleteEvent)event;
				ActivityType activityType = ActivityType.getTypeByCode(disappearEvent.activityType);
				Activity activity = activityContext.getActivity(activityType);
				if (activity.isCompleteDisappear()) {
					sendOverActivityMsg(activity);
				}
				triggerNewActivity();
			}
		});
		
		registrator.regist(new EventListener(ActivityEventType.ACHIEVEMENT_COMPLETE) {
			@Override
			public void onEvent(Event event) {
				if (!isOpen(ActivityType.SEVENGOAL)) {
					return;
				}
				AchievementCompleteEvent completeEvent = (AchievementCompleteEvent)event;
				int questId = completeEvent.questId;
				int day = templates.getDayByQuestId(achievementInfo.getStep(), questId);
//				boolean isQuestOpen = achievementInfo.isOpenQuest(day);
//				if (!isQuestOpen) {
//					return;
//				}
				player.notifyEvent(new AddRedPointEvent(ActivityType.SEVENGOAL.getCode()));
				if (day > 0) {
					achievementInfo.incrProgress();
					sendSevenGoalInfoMsg();
					player.notifyEvent(new ActSevenGoalScoreEvent(achievementInfo.getProgress()));
				}
			}
		});

		registrator.regist(new EventListener(ActivityEventType.ACHIEVEMENT_SUBMIT) {
			@Override
			public void onEvent(Event event) {
				AchievementSubmitEvent completeEvent = (AchievementSubmitEvent)event;
				int questId = completeEvent.questId;
				submitQuest(questId);

				if (!achievementInfo.hasRedPoint(player, templates)) {
					removeRedPointAndSync(ActivityType.SEVENGOAL);
				}
				if (achievementInfo.isComplete(player, templates)) {
					player.notifyEvent(new ActivityCompleteEvent(ActivityType.SEVENGOAL.getCode()));
				}
			}
		});
		
		registrator.regist(new EventListener(RechargeEventType.RECHARGE_COIN) {
			@Override
			public void onEvent(Event event) {
				RechargeCoinEvent rechargeCoinEvent = (RechargeCoinEvent)event;
				int addCoin = rechargeCoinEvent.buyCoin;
				List<ActivityInfo> effectActivities = effectActivities(ConditionType.RECHARGE);
				for (ActivityInfo activityInfo : effectActivities) {
					if (!isOpen(activityInfo.getActivityType0())) {
						continue;
					}
					activityInfo.accumulateProgress(addCoin);
					//充值排行榜
					if(activityInfo.getActivityType0()==ActivityType.RECHARGE_RANKING){
						if(checkRechargeCount(activityInfo.getProgress())){
							player.notifyEvent(new RechargeRankingEvent(activityInfo.getProgress()));
						}
					}

					applyChange(activityInfo, ConditionType.RECHARGE, 0, activityInfo.getProgress(), 1);
					sendActivityInfoMsg(activityInfo);
				}

				if (isOpen(ActivityType.GROUP_BUY)) {
					currRechargeInfo.incrRechargeCount(addCoin);

					if (currRechargeInfo.hasRedPoint(templates, activityContext.getTotalRechargePerson())) {
						player.notifyEvent(new AddRedPointEvent(ActivityType.GROUP_BUY.getCode()));
					}
					activityContext.addRechargePerson(player.getPlayerId());
					sendGroupBuyRewardListMsg();
				}
			}
		});
		
		registrator.regist(new EventListener(ActivityEventType.GROUP_BUY_EVENT) {
			@Override
			public void onEvent(Event event) {
				if (!isOpen(ActivityType.GROUP_BUY)) {
					return;
				}
				if (currRechargeInfo.hasRedPoint(templates, activityContext.getTotalRechargePerson())) {
					player.notifyEvent(new AddRedPointEvent(ActivityType.GROUP_BUY.getCode()));
				}
			}
		});
		
		registrator.regist(new EventListener(BagEventType.ITEM_CONSUME) {
			@Override
			public void onEvent(Event event) {
				ItemConsumeEvent consumeEvent = (ItemConsumeEvent)event;
				if(!consumeEvent.isConsumeCoin() || consumeEvent.isTradeConsume() || consumeEvent.isMoneyTreeConsume()){
					return;
				}
				List<ActivityInfo> effectActivities = effectActivities(ConditionType.CONSUME_COIN);
				int changeCount = consumeEvent.changeCount;
				
				for (ActivityInfo activityInfo : effectActivities) {
					if (!isOpen(activityInfo.getActivityType0())) {
						continue;
					}
					activityInfo.accumulateProgress(changeCount);
					applyChange(activityInfo, ConditionType.CONSUME_COIN, 0, activityInfo.getProgress(), 1);
					//sendActivityInfoMsg(activityInfo);
				}
			}
		});

		registrator.regist(new EventListener(RechargeEventType.RECHARGE_FIRST) {
			@Override
			public void onEvent(Event event) {
				ActivityInfo activityInfo = getActivityInfo(ActivityType.FIRSTRECHARGE);
				if (activityInfo.getIsFinish()) {
					return;
				}
				applyChange(activityInfo, ConditionType.RECHARGE, 0, 0, 1);
				player.notifyEvent(new AddRedPointEvent(ActivityType.FIRSTRECHARGE.getCode()));
				sendActivityInfoMsg(activityInfo);
			}
		});
		
		registrator.regist(new EventListener(RechargeEventType.RECHARGE_ACTIVITY) {
			@Override
			public void onEvent(Event event) {
				RechargeActivityEvent purchaseEvent = (RechargeActivityEvent)event;
				ActivityType activityType = ActivityType.getTypeByCode(purchaseEvent.activityType);
				if (!isOpen(activityType)) {
					return;
				}
				ActivityInfo activityInfo = getActivityInfo(activityType);
				if (activityInfo == null) {
					return;
				}
				activated(activityType, activityInfo);
			}

			private void activated(ActivityType activityType, ActivityInfo activityInfo) {
				if (activityInfo.isActivated()) {
					return;
				}
				activityInfo.activated();
				if (activityType == ActivityType.HORSE_GIFT) {
					applyChange(activityInfo, ConditionType.HORSE_GIFT_ACTIVITY, 0, 0, 1);
				} else if (activityType == ActivityType.GUANYU_GIFT || activityType == ActivityType.TIME_LIMIT_GUANYU_GIFT) {
					applyChange(activityInfo, ConditionType.GUANYU_GIFT_ACTIVITY, 0, 0, 1);
				} else if (activityType == ActivityType.GROWTHFUND) {
					applyChange(activityInfo, ConditionType.PLAYER_LEVEL_UP, 0,  player.displayer().level(), 1);
				} else if(activityType==ActivityType.SOLIDER_ADVANCE_GIFT_RMB){
					applyChange(activityInfo, ConditionType.SOLDIER_ADVANCE_GIFT, 0, 0, 1);
				}else if(activityType==ActivityType.LUCKY_EQUIP_GIFT){
					applyChange(activityInfo, ConditionType.LUCKY_EQUIP_GIFT, 0, 0, 1);
				}
				sendActivityInfoMsg(activityInfo);
			}
		});
		
		registrator.regist(new EventListener(ActivityEventType.SHENJIANG_SCORE) {
			@Override
			public void onEvent(Event event) {
				ShenjiangScoreEvent sjEvent = (ShenjiangScoreEvent)event;
				int activityType = sjEvent.activityType;
				int score = sjEvent.score;
				ActivityType type = ActivityType.getTypeByCode(activityType);
				if (!isOpen(type)) {
					return;
				}
				ActivityInfo activityInfo = getActivityInfo(type);
				if (activityInfo == null) {
					return;
				}
				applyChange(activityInfo, ConditionType.SHENJIANG_SCORE, 0, score, 1);
			}
		});

		
		registrator.regist(new EventListener(CoreEventType.PLAYER_LEVEL_UP) {
			@Override
			public void onEvent(Event event) {
				for (ActivityInfo activityInfo : activityInfoMap.values()) {
					if (!isOpen(activityInfo.getActivityType0())) {
						continue;
					}
					applyChange(activityInfo, ConditionType.PLAYER_LEVEL_UP, 0, event.<PlayerLevelUpEvent>cast().curLevel, 1);
				}
			}
		});

		registrator.regist(new EventListener(ActivityEventType.ADD_RED_POINT) {
			@Override
			public void onEvent(Event event) {
				AddRedPointEvent redPoint = (AddRedPointEvent)event;
				ActivityType activityType = ActivityType.getTypeByCode(redPoint.activityType);
				if (redPointActivityMap.containsKey(activityType.getCode())) {
					return;
				}
				addRedPoint(activityType);
				sendActivityRedPointMsg();
			}
		});

		registrator.regist(new EventListener(ActivityEventType.REMOVE_RED_POINT) {
			@Override
			public void onEvent(Event event) {
				RemoveRedPointEvent redPoint = (RemoveRedPointEvent)event;
				removeRedPointAndSync(ActivityType.getTypeByCode(redPoint.activityType));
			}
		});

		registrator.regist(new EventListener(ActivityEventType.ONLINE_TIME) {
			@Override
			public void onEvent(Event event) {
				OnlineTimeEvent onlineTimeEvent = (OnlineTimeEvent)event;
				ConditionType conditionType = ConditionType.ACTIVITY_ONLINE_TIME;
				if (!isOpen(ActivityType.ONLINEAWARD)) {
					return;
				}
				ActivityInfo activityInfo = getActivityInfo(ActivityType.ONLINEAWARD);
				if (activityInfo == null) {
					return;
				}
				activityInfo.accumulateProgress(onlineTimeEvent.accumulateTime);
				applyChange(activityInfo, conditionType, 0, activityInfo.getProgress(), 1);
			}
		});
		registrator.regist(new EventListener(PlayerEventType.LOGIN){
			@Override
			public void onEvent(Event event){
				player.notifyEvent(new ActSevenGoalDayEvent(achievementInfo.getStepOpenDay()));
			}
		});

		registrator.regist(new EventListener(RechargeEventType.RECHARGE){
			@Override
			public void onEvent(Event event){
				triggerNewActivity();
				RechargeEvent re = (RechargeEvent)event;
				RechargeTemplate purchaseTemplate = rechargeTemplates.getRechargeTemplateById(re.rechargeId);
				RewardHandler.handle(player, ProduceSource.CROWDFUNDING_ITEM , new Reward(0 , 2500101 , purchaseTemplate.getRmb()));
				
				GainGoodsMsg.Builder builder = GainGoodsMsg.newBuilder();
				builder.setGoodsId(2500101);
				builder.setGoodsQuantity(player.itemHandler.get(2500101));
				builder.setGoodsType(0);
				player.sendMessage(Message.build(ActivityProtocol.Server.CROWDFUNDING_ITEM , builder.build()));
			}
		});
		registrator.regist(new EventListener(SoldierEventType.SOLDIER_PRODUCE) {
			@Override
			public void onEvent(Event event) {
				triggerNewActivity();
			}
		});
	}
	
	private List<ActivityInfo> effectActivities(ConditionType conditionType) {
		List<ActivityInfo> effectActivities = new ArrayList<ActivityInfo>();
		
		for (ActivityInfo activityInfo : activityInfoMap.values()) {
			ActivityTemplateInfo activityTempInfo = templates.getActivityTempInfoByType(activityInfo.getActivityType());
			if (activityTempInfo.getConditionType() != conditionType.code) {
				continue;
			}
			effectActivities.add(activityInfo);
		}
		return effectActivities;
	}
	
	public void applyChange(ActivityInfo activityInfo, ConditionType conditionType, int targetId, int targetValue, int delta) {
		Change change = new Change(conditionType, targetId, targetValue, delta);
		
		ActivityType activityType0 = activityInfo.getActivityType0();
		if ((activityType0 == ActivityType.HORSE_GIFT || activityType0 == ActivityType.GROWTHFUND) && !activityInfo.isActivated()) {
			return;
		}

		for (ActivityItemInfo activityItemInfo : activityInfo.getItemInfos()) {
			if (activityItemInfo.isSatisfied()) {
				continue;
			}
			activityItemInfo.apply(change);
		}
		
		if (activityInfo.hasRedPoint()) {
			player.notifyEvent(new AddRedPointEvent(activityInfo.getActivityType()));
		}
	}
	
	private void triggerNewActivity() {
		List<Activity> appearActivitys = activityContext.appearActivity();
		for (Activity activity : appearActivitys) {
			if (!activity.isVisible(player)) {
				continue;
			}
			int activityType = activity.getActivityType();
			if (this.activityInfoMap.containsKey(activityType)) {
				continue;
			}
			if (activity.isCompleteDisappear() && isComplete(activityType)) {
				continue;
			}
			if (!activity.getActivityType0().isSeries()) {
				continue;
			}
			player.notifyEvent(new OpenActivityEvent(activityType));
		}
	}
	
	private void submitQuest(int questId){
		UpdateAchievementMsg.Builder builder = UpdateAchievementMsg.newBuilder();
		builder.setDay(templates.getDayByQuestId(achievementInfo.getStep(), questId));
		builder.setQuestId(questId);
		builder.setState(player.quest.getQuest(questId).getState().code);
		
		Message message = Message.build(ActivityProtocol.Server.UPDATE_ACHIEVEMENT_MSG, builder.build());
		player.sendMessage(message);
	}
	
	@Override
	public boolean save() {
		activityRepo.saveAchievementInfo(achievementInfo);
		activityRepo.saveCurrDayRechargeInfo(currRechargeInfo);
		activityRepo.saveEnergyInfo(energyInfo);
		
		Collection<ActivityInfo> values = new ArrayList<>(this.activityInfoMap.values());
        for (ActivityInfo activityInfo : values) {
			activityRepo.saveActivityInfo(activityInfo);
			activityRepo.updateBatchActivityItemInfos(new ArrayList<>(activityInfo.getItemInfos()));
		}
		return true;
	}
	
	public void sendSevenGoalInfoMsg(){
		Message message = Message.build(ActivityProtocol.Server.ACHIEVEMENT_LIST_MSG, achievementInfo.buildMsg(player, templates));
		player.sendMessage(message);
	}

	public boolean isComplete(int activityType0) {
		ActivityType activityType = ActivityType.getTypeByCode(activityType0);
		switch(activityType){
		case SEVENGOAL : {
			return getAchievementInfo().isComplete(player, templates);
		}
        default : {
        	ActivityInfo activityInfo = this.getActivityInfo(activityType);
        	if (activityInfo == null) {
        		return false;
        	}
        	return activityInfo.getIsFinish();
        }
		}
	}
	
	private void sendVisibleActivities() {
		List<Activity> appearActivitys = activityContext.appearActivity();
		ActivityListMsg.Builder builder = ActivityListMsg.newBuilder();
		for (Activity activity : appearActivitys) {
			if (!activity.isVisible(player)) {
				continue;
			}
			ActivityType activityType = activity.getActivityType0();
			if (activity.isCompleteDisappear() && isComplete(activity.getActivityType())) {
				continue;
			}
			if (activityType.isSeries()) {
				activityType.getActivityHandler().init(activityType, player);
			}
			builder.addActivityMsg(activity.createActivityMsg(player));
		}
		
		Message message = Message.build(ActivityProtocol.Server.ACTIVITY_LIST, builder.build());
		player.sendMessage(message);
	}
	
	public void sendActivityAwardRecordMsg(int activityType) {
		player.sendMessage(Message.build(ActivityProtocol.Server.ACTIVITY_AWARD_RECORD_MSG, activityContext.buildActivityAwardRewardMsg(activityType)));
	}

	private void sendActivityRedPointMsg() {
		ActivityRedPointMsg.Builder builder = ActivityRedPointMsg.newBuilder();
		builder.addAllActivtyType(this.redPointActivityMap.values());
		player.sendMessage(Message.build(ActivityProtocol.Server.ACTIVITY_RED_POINT_MSG, builder.build()));
	}

	private void sendOverActivityMsg(Activity closeActivity) {
		CloseActivityMsg.Builder builder = CloseActivityMsg.newBuilder();
		builder.addActivityMsg(closeActivity.createActivityMsg(player));
		
		Message message = Message.build(ActivityProtocol.Server.CLOSE_ACTIVITY_LIST, builder.build());
		player.sendMessage(message);
	}
	
	private void sendOpenActivityMsg(Activity activity) {
		OpenActivityMsg.Builder builder = OpenActivityMsg.newBuilder();
		builder.addActivityMsg(activity.createActivityMsg(player));
		Message message = Message.build(ActivityProtocol.Server.OPEN_ACTIVITY_LIST, builder.build());
		player.sendMessage(message);
	}

	public AchievementInfo getAchievementInfo() {
		return achievementInfo;
	}

	@Override
	public int getCurrentAchievementStep() {
	    return achievementInfo.getStep();
	}

	@Override
    public long getCurrentAchievementCreateDay() {
        return achievementInfo.getCreateDay();
    }

    /** 团购活动奖励信息 */
	public void sendGroupBuyRewardListMsg() {
		GroupBuyRewardListMsg.Builder builder = GroupBuyRewardListMsg.newBuilder();
		builder.setTotalPerson(activityContext.getTotalRechargePerson());
		builder.setCoinCount(currRechargeInfo.getRechargeCoin());
		builder.setResetTime(getTomorrowZeroHour());
		for(GroupBuyRewardTemplateInfo info : templates.getGroupBuyTemplateInfos()){
			GroupBuyRewardDataMsg.Builder dataBuilder = GroupBuyRewardDataMsg.newBuilder();
			dataBuilder.setAwardId(info.getId());
			if(currRechargeInfo.getPickedRecordList().contains(info.getId())){
				dataBuilder.setPickStatus(RewardStatus.hasReceive.getValue());
			}else{
				if(currRechargeInfo.canPickGroupBuyAward(info, activityContext.getTotalRechargePerson())){
					dataBuilder.setPickStatus(RewardStatus.canReceive.getValue());
				}else{
					dataBuilder.setPickStatus(RewardStatus.canntReceive.getValue());
				}
			}
			builder.addDatas(dataBuilder);
		}
		player.sendMessage(Message.build(ActivityProtocol.Server.GROUP_BUY_LIST_MSG, builder.build()));
	}

	private long getTomorrowZeroHour() {
		Calendar c = Calendar.getInstance();
		c.add(Calendar.DATE, 1);
		c.set(Calendar.HOUR_OF_DAY, 0);
		c.set(Calendar.MINUTE, 0);
		c.set(Calendar.SECOND, 0);
		c.set(Calendar.MILLISECOND, 0);
		return c.getTimeInMillis();
	}

	@Override
	public void resetRechargeData() {
		if(this.currRechargeInfo.isNeedReset()){
			this.currRechargeInfo.reset();
		}
		if(!currRechargeInfo.hasRedPoint(templates, activityContext.getTotalRechargePerson())){
			player.notifyEvent(new RemoveRedPointEvent(ActivityType.GROUP_BUY.getCode()));
		}
	}
	
	@Override
	public CurrentDayRechargeInfo getCurrRechargeInfo() {
		return this.currRechargeInfo;
	}

	public ActivityInfo getActivityAndCreate(ActivityType activityType) {
		ActivityInfo activityInfo = activityInfoMap.get(activityType.getCode());
		if (activityInfo == null) {
			activityInfo = createActivity(activityType);
		}
		return activityInfo;
	}
	
	@Override
	public ActivityInfo getActivityInfo(ActivityType activityType) {
		return activityInfoMap.get(activityType.getCode());
	}

	@Override
	public ActivityInfo createActivity(ActivityType activityType) {
		Activity activity = activityContext.getActivity(activityType);
		ActivityInfo activityInfo = new ActivityInfo(player.getPlayerId(), activity);
		activityRepo.saveActivityInfo(activityInfo);
		activityInfoMap.put(activityType.getCode(), activityInfo);
		for (ActivityItemTemplate itemTemplate : templates.getInitActivityItemTemplates(activityType.getCode())) {
			ActivityItemInfo itemInfo = new ActivityItemInfo(player.getPlayerId(), itemTemplate);
			activityInfo.addItemInfo(itemInfo);
		}
		List<ActivityItemInfo> itemInfos = activityInfo.getItemInfos();
		if (!itemInfos.isEmpty()) {
			activityRepo.insertBatchActivityItemInfos(itemInfos);
		}
		return activityInfo;
	}

	public ActivityItemInfo getActivityItem(int activityType, int activityItemId) {
		ActivityInfo activityInfo = activityInfoMap.get(activityType);
		return activityInfo.getItemInfo(activityItemId);
	}
	
	public void sendActivityInfoMsg(ActivityInfo activityInfo) {
		player.sendMessage(Message.build(ActivityProtocol.Server.ACTIVITY_INFO_MSG, activityContext.buildMsg(activityInfo)));
	}

	@Override
	public void dailyReset() {
		refreshSevenGoal();
		refreshActivity();
		resetAwardEnergy();
		triggerNewActivity();
	}

	@Override
    public void sendSyncMessage() {
	    calRedPoint();
        sendVisibleActivities();
        
        if(isVisible(ActivityType.SEVENGOAL)){
        	this.sendSevenGoalInfoMsg();
		}
    }

    private void refreshActivity() {
		activityInfoMap.keySet().forEach(activityTypeValue -> {
			ActivityType type = ActivityType.getTypeByCode(activityTypeValue);
			if (!isOpen(type)) {
				return;
			}
			type.getActivityHandler().reset(type, player);
		});
	}

	private void refreshSevenGoal() {
//		if (!isOpen(ActivityType.SEVENGOAL)) {
//			return;
//		}
		if (achievementInfo.isOver()) {
			return;
		}
		long currentDay = DefaultDailyTask.time.asOffsetGetDays();//TimeUtil.currentTimeDays();
		long createDay = achievementInfo.getCreateDay();
		long maxOpenDay = currentDay - createDay + 1;
		
		int step = calStep(maxOpenDay);
		int stepOpenDay = calStepOpenDay(maxOpenDay);
		
		if (step > AchievementInfo.MAX_STEP) {
			return;
		}
		if (step > achievementInfo.getStep()) {
			//放弃当前阶段的所有任务
			for (int i = achievementInfo.stepDayStartIndex(); i <= 7; i++) {
				ActSevenGoalTemplate sevenGoalTemplate = templates.getSevenGoalTemplate(achievementInfo.getStep(), i);
				if (sevenGoalTemplate == null) {
					continue;
				}
				sevenGoalAbandon(sevenGoalTemplate.allQuestList());
			}
			achievementInfo.openNewStep(step);
		}
		
		long executeCount = stepOpenDay - achievementInfo.getStepOpenDay();
		for (int i = 0; i < executeCount; i++) {
			if (achievementInfo.isOpenMaxDay()) {
				break;
			}
			int openNewDay = achievementInfo.openNewDay();
			ActSevenGoalTemplate sevenGoalTemplate = templates.getSevenGoalTemplate(achievementInfo.getStep(), openNewDay);
			sevenGoalPrepare(sevenGoalTemplate.allQuestList());
			if (openNewDay != stepOpenDay) {
				sevenGoalAbandon(sevenGoalTemplate.getDailyQuestList());
			}
		}
		player.notifyEvent(new ActSevenGoalDayEvent(achievementInfo.getStepOpenDay()));
		if (achievementInfo.hasRedPoint(player, templates)) {
			player.notifyEvent(new AddRedPointEvent(ActivityType.SEVENGOAL.getCode()));
		}
	}
	
	private int calStepOpenDay(long maxOpenDay) {
		int remainder = (int) (maxOpenDay % 7);
		return remainder == 0 ? 7 : remainder;
	}

	private int calStep(long maxOpenDay) {
		int remainder = (int) (maxOpenDay % 7);
		int wholeNumber = (int) (maxOpenDay / 7);
		return remainder == 0 ? wholeNumber : wholeNumber + 1;
	}
	
	public EnergyInfo getEnergyInfo() {
		return this.energyInfo;
	}
	
	public void sendEnergyMsg() {
		player.sendMessage(Message.build(ActivityProtocol.Server.ENERGY_MSG, this.energyInfo.buildMsg()));
	}
	
	public void resetAwardEnergy(){
		energyInfo.resetState();
	}
	
	private void sevenGoalAbandon(List<Integer> questList) {
		new ModularCallable<GamePlayer, QuestInventory >() {
			@Override
			protected void call(GamePlayer player, QuestInventory module) {
				MainQuestsProcessor questsProcessor = (MainQuestsProcessor)module.getQuestsProcessor(QuestType.SEVENGOAL);
				questList.forEach(questId -> {
					Quest quest = module.getQuest(questId);
					if (quest == null) {
						return;
					}
					questsProcessor.abandon(quest);
				});
			}
		}.call(player);
	}
	
	private void sevenGoalPrepare(List<Integer> prepareQuestList) {
		new ModularCallable<GamePlayer, QuestInventory >() {
			@Override
			protected void call(GamePlayer player, QuestInventory module) {
				QuestsProcessor questsProcessor = module.getQuestsProcessor(QuestType.SEVENGOAL);
				prepareQuestList.forEach(questId -> {
					QuestTemplateInfo questInfo = questTemplates.getQuestTemInfo(questId);
					questsProcessor.prepare(questInfo);
				});
				questsProcessor.satisfy(new QuestsNotifier());
			}
		}.call(player);
	}
	
	public void sendEnergyRedPoint(){
		if(isOpen(ActivityType.GET_ENERGY) && energyInfo.hasRedPoint()){
			addRedPoint(ActivityType.GET_ENERGY);
			sendActivityRedPointMsg();
		}else{
			removeRedPointAndSync(ActivityType.GET_ENERGY);
		}
	}

	@Override
	public void managerActivity() {
		activityInfoMap.values().forEach(activityInfo -> {
			if (activityInfo.getIsFinish() || activityInfo.getIsOverTime()) {
				return;
			}
			ActivityType activityType0 = activityInfo.getActivityType0();
			Activity activity = activityContext.getActivity(activityType0);
			if (activity.isVisible(this.player)) {
				return;
			}
			player.notifyEvent(new OverActivityEvent(activityInfo.getActivityType()));
		});
	}

	public boolean checkMoneyTreeCount(int vipLevel,int count){
		return vipTemplates.getVipPrerogativeTempInfo(vipLevel).getMoneyTreeCount()>=count;
	}

	public boolean checkRechargeCount(int progress){
		return progress >= ConstantKey.RECHARGE_RANK.getAsInt() ;
	}

	/**
	 * 开启众筹主面板返回消息
	 */
	public void sendMainPanelMsg(){
		MainPanelMsg.Builder builder = MainPanelMsg.newBuilder();
		//获取众筹公共数据
        for (CrowdfundingActivityCommunal crowdfundingActivityCommunal : crowdfundingContext.getCrowdfundingActivityCommunalMap().values()){
        	if(crowdfundingActivityCommunal.getCurrentQuantity() < crowdfundingActivityCommunal.getTotalQuantity()){
	        	MainPanelDataMsg.Builder mainPanelDataMsgBuilder = MainPanelDataMsg.newBuilder();
	        	mainPanelDataMsgBuilder.setTemplateId(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
	        	mainPanelDataMsgBuilder.setGoodsId(crowdfundingActivityCommunal.getId());
	        	mainPanelDataMsgBuilder.setCurrentQuantity(crowdfundingActivityCommunal.getCurrentQuantity());
	        	builder.addMainPanelDataMsg(mainPanelDataMsgBuilder.build());
        	}
        }
		player.sendMessage(Message.build(ActivityProtocol.Server.MAIN_PANEL_DATA , builder.build()));
	}
	
	
	/**
	 * 开启众筹活动购买面板,来源于主面板接口
	 * @param goodsId 公共数据表id(非模板id)
	 */
	public void sendBuyPanelFromMainPanelMsg(int goodsId){
		//获取众筹公共数据
		CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(goodsId);
//		//列表中没有该物品
//		if(crowdfundingActivityCommunal == null)
//			return;
		
		BuyPanelFromMainPanelMsg.Builder builder = BuyPanelFromMainPanelMsg.newBuilder();
		builder.setGoodsId(goodsId);
		builder.setCurrentQuantity(crowdfundingActivityCommunal.getCurrentQuantity());
		
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(goodsId))
			builder.setPlayerHaveQuantity(crowdfundingActivityPlayerMap.get(goodsId).getBuyQuantity());
		
		player.sendMessage(Message.build(ActivityProtocol.Server.BUY_PANEL_FROM_MAIN_PANEL_DATA , builder.build()));
	}
	
	
	/**
	 * 开启众筹活动购买面板,来源于我的众筹面板接口
	 * @param goodsId 公共数据表id(非模板id)
	 */
	public void sendBuyPanelFromMyCrowdfundingPanelMsg(int goodsId){
		//获取众筹公共数据
		CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(goodsId);
//		//列表中没有该物品
//		if(crowdfundingActivityCommunal == null)
//			return;
		
		BuyPanelFromMainPanelMsg.Builder builder = BuyPanelFromMainPanelMsg.newBuilder();
		builder.setGoodsId(goodsId);
		builder.setCurrentQuantity(crowdfundingActivityCommunal.getCurrentQuantity());
		
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(goodsId))
			builder.setPlayerHaveQuantity(crowdfundingActivityPlayerMap.get(goodsId).getBuyQuantity());
		
		player.sendMessage(Message.build(ActivityProtocol.Server.BUY_PANEL_FROM_MY_PANEL_DATA , builder.build()));
	}
	
	
	
	/**
	 * 众筹物品购买,来源于主面板
	 * @param goodsId
	 * @param goodsQuantity
	 */
	public void sendBuyFromMainPanelDataMsg(int goodsId , int goodsQuantity){
		//获取众筹公共数据
		CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(goodsId);
		
//		//列表中没有该物品
//		if(crowdfundingActivityCommunal == null)
//			return;
		
		//返回消费结果
		boolean isOk = crowdfundingContext.buyCrowdfundingGoods(goodsQuantity , crowdfundingActivityCommunal , player);
		if(!isOk){
			return;
		}
		
		//获取本角色众筹数据
		crowdfundingActivityPlayerMap = crowdfundingContext.getCrowdfundingActivityPlayerMap(player.getPlayerId());
		/*
		 * 嵌套主页面数据
		 * */
		BuyFromMainPanelMsg.Builder builder = BuyFromMainPanelMsg.newBuilder();
		//获取众筹公共数据 , 嵌套主面板数据集合,加入限制
        for (CrowdfundingActivityCommunal temp : crowdfundingContext.getCrowdfundingActivityCommunalMap().values()) 
        	if(crowdfundingActivityCommunal.getCurrentQuantity() < crowdfundingActivityCommunal.getTotalQuantity()){
            	MainPanelDataMsg.Builder mainPanelDataMsgBuilder = MainPanelDataMsg.newBuilder();
            	mainPanelDataMsgBuilder.setTemplateId(temp.getCrowdfundingActivityTemplateId());
            	mainPanelDataMsgBuilder.setGoodsId(temp.getId());
            	mainPanelDataMsgBuilder.setCurrentQuantity(temp.getCurrentQuantity());
            	builder.addMainPanelDataMsg(mainPanelDataMsgBuilder.build());
        	}
        
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(goodsId))
			builder.setPlayerHaveQuantity(crowdfundingActivityPlayerMap.get(goodsId).getBuyQuantity());//众筹活动当前拥有数量
		
        builder.setMyGold(player.itemHandler.get(crowdfundingActivityCommunal.getConsumeGoodsId()));//我的众筹币
        builder.setGoodsId(goodsId);//众筹活动物品id
        builder.setCurrentQuantity(crowdfundingActivityCommunal.getCurrentQuantity());//众筹活动当前已经完成数量
         
		player.sendMessage(Message.build(ActivityProtocol.Server.BUY_FROM_MAIN_PANEL_DATA , builder.build()));
		
		sendMainPanelMsg();
	}
	
	
	/**
	 * 众筹活动商品购买,源于我的众筹面板接口
	 * @param goodsId 购买的物品id(非模板id)
	 * @param goodsQuantity
	 */
	public void sendBuyFromMyCrowdfundingPanelMsg(int goodsId , int goodsQuantity){
		BuyFromMyCrowdfundingPanelMsg.Builder builder = BuyFromMyCrowdfundingPanelMsg.newBuilder();
		//获取众筹公共数据
		CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(goodsId);
		
//		//列表中没有该物品
//		if(crowdfundingActivityCommunal == null)
//			return;
		
		//返回消费结果
		boolean isOk = crowdfundingContext.buyCrowdfundingGoods(goodsQuantity , crowdfundingActivityCommunal , player);
		if(!isOk)
			return;
		
		//获取本角色众筹数据
		crowdfundingActivityPlayerMap = crowdfundingContext.getCrowdfundingActivityPlayerMap(player.getPlayerId());
		//角色众筹数据
        CrowdfundingActivityPlayer crowdfundingActivityPlayer = null;
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(crowdfundingActivityCommunal.getId()))
			crowdfundingActivityPlayer = crowdfundingActivityPlayerMap.get(crowdfundingActivityCommunal.getId());
		
		builder.setGoodsId(goodsId);
		builder.setGoodsQuantity(crowdfundingActivityPlayer.getBuyQuantity());
		builder.setCurrentGoodsQuantity(crowdfundingActivityCommunal.getCurrentQuantity());
		builder.setGold(player.itemHandler.get(crowdfundingActivityCommunal.getConsumeGoodsId()));
		
		//角色众筹数据
		for(CrowdfundingActivityPlayer temp : crowdfundingActivityPlayerMap.values()){
			MyCrowdfundingAllMsg.Builder myCrowdfundingAllMsgBuider = MyCrowdfundingAllMsg.newBuilder();
			myCrowdfundingAllMsgBuider.setGoodsId(temp.getCrowdfundingActivityCommunalId());
			crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(temp.getCrowdfundingActivityCommunalId());
			myCrowdfundingAllMsgBuider.setGoodsStatus(crowdfundingStatus(crowdfundingActivityCommunal , player.getPlayerId()));
			builder.addMyCrowdfundingAllMsg(myCrowdfundingAllMsgBuider.build());
		}
        
		player.sendMessage(Message.build(ActivityProtocol.Server.BUY_FROM_MY_CROWDFUNDING_PANEL_DATA , builder.build()));
	}

	
	/**
	 * 开启我的众筹面板,获得左面板数据集合,该数据为我购买过的物品
	 * @param
	 */
	public void sendMyCrowdfundingListMsg(){
		MyCrowdfundingPanelMsg.Builder buider = MyCrowdfundingPanelMsg.newBuilder();
		//角色众筹数据
		for(CrowdfundingActivityPlayer temp : crowdfundingActivityPlayerMap.values()){
			MyCrowdfundingAllMsg.Builder myCrowdfundingAllMsgBuider = MyCrowdfundingAllMsg.newBuilder();
			myCrowdfundingAllMsgBuider.setGoodsId(temp.getCrowdfundingActivityCommunalId());
			CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(temp.getCrowdfundingActivityCommunalId());
			myCrowdfundingAllMsgBuider.setGoodsStatus(crowdfundingStatus(crowdfundingActivityCommunal , player.getPlayerId()));
			myCrowdfundingAllMsgBuider.setTemplateId(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
			buider.addMyCrowdfundingAllMsg(myCrowdfundingAllMsgBuider.build());
		}
		player.sendMessage(Message.build(ActivityProtocol.Server.MY_CROWDFUNDING_PANEL_DATA , buider.build()));
	}
	
	
	/**
	 * 查询我的众筹中的某一个物品数据
	 * @param goodsId
	 */
	public void sendQueryMyCrowdfundingDataMsg(int goodsId){
		//获取众筹公共数据
		CrowdfundingActivityCommunal crowdfundingActivityCommunal = crowdfundingContext.getCrowdfundingActivityCommunal(goodsId);
//		//列表中没有该物品
//		if(crowdfundingActivityCommunal == null)
//			return;
		
		if(crowdfundingActivityCommunal.getWonPlayerId() != 0){
			sendMyCrowdfundingIsEndDataMsg(goodsId , crowdfundingActivityCommunal);
		}else{
			sendMyCrowdfundingNotEndDataMsg(goodsId , crowdfundingActivityCommunal);
		}
	}
	
	/**
	 * 我的众筹面板数据(已开奖)
	 * @param goodsId
	 */
	public void sendMyCrowdfundingIsEndDataMsg(int goodsId , CrowdfundingActivityCommunal crowdfundingActivityCommunal){
		//获取模板数据,进行金钱运算
		CrowdfundingActivityTemplate crowdfundingActivityTemplate = templates.getCrowdfundingActivityTemplate(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
		if(crowdfundingActivityTemplate == null)
			return;
		
		//通过公共数据模板表外键关联到角色个人数据
        CrowdfundingActivityPlayer crowdfundingActivityPlayer = null;
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(crowdfundingActivityCommunal.getId()))
			crowdfundingActivityPlayer = crowdfundingActivityPlayerMap.get(crowdfundingActivityCommunal.getId());
		
//		int spend = crowdfundingActivityTemplate.getPrice();
		
		//消息封装
		MyCrowdfundingIsEndDataMsg.Builder builder = MyCrowdfundingIsEndDataMsg.newBuilder();
		builder.setGoodsId(goodsId);//我购买的众筹物品id
//		builder.setQuantity(spend * crowdfundingActivityPlayer.getBuyQuantity());//我购买的众筹物品数量
		builder.setQuantity(crowdfundingActivityPlayer.getBuyQuantity());//我购买的众筹物品数量
		builder.setAwardWinnersHeadPortrait(crowdfundingActivityCommunal.getWonPlayerHeadPortrait());//获奖玩家头像
		builder.setAwardWinnersName(crowdfundingActivityCommunal.getWonPlayerName());//获奖玩家昵称
		builder.setAwardWinnersBuyQuantity(crowdfundingActivityCommunal.getWonPlayerBuyQuantity());//获奖者购买的众筹物品数量
		builder.setTemplateId(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
		builder.setGoodsStatus(crowdfundingStatus(crowdfundingActivityCommunal , player.getPlayerId()));
		player.sendMessage(Message.build(ActivityProtocol.Server.MY_CROWDFUNDING_IS_END_DATA , builder.build()));
	}
	
	
	/**
	 * 我的众筹面板数据(未开奖)
	 * @param goodsId
	 */
	public void sendMyCrowdfundingNotEndDataMsg(int goodsId , CrowdfundingActivityCommunal crowdfundingActivityCommunal){
		//获取模板数据,进行金钱运算
		CrowdfundingActivityTemplate crowdfundingActivityTemplate = templates.getCrowdfundingActivityTemplate(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
		if(crowdfundingActivityTemplate == null)
			return;
		
		//通过公共数据模板表外键关联到角色个人数据
        CrowdfundingActivityPlayer crowdfundingActivityPlayer = null;
		//通过众筹公共id 获取角色众筹个人数据
		if(crowdfundingActivityPlayerMap.containsKey(goodsId))
			crowdfundingActivityPlayer = crowdfundingActivityPlayerMap.get(goodsId);
		
//		int spend = crowdfundingActivityTemplate.getPrice();
		
		//消息封装
		MyCrowdfundingNotEndDataMsg.Builder builder = MyCrowdfundingNotEndDataMsg.newBuilder();
		builder.setGoodsId(goodsId);//我购买的众筹物品id
//		builder.setQuantity(spend * crowdfundingActivityPlayer.getBuyQuantity());//我购买的众筹物品数量
		builder.setQuantity(crowdfundingActivityPlayer.getBuyQuantity());//我购买的众筹物品数量
		builder.setCurrentGoodsQuantity(crowdfundingActivityCommunal.getCurrentQuantity());//众筹购买物品数量
		builder.setTemplateId(crowdfundingActivityCommunal.getCrowdfundingActivityTemplateId());
		player.sendMessage(Message.build(ActivityProtocol.Server.MY_CROWDFUNDING_NOT_END_DATA , builder.build()));
	}
	
	/**
	 * 众筹物品状态
	 * @param crowdfundingActivityCommunal
	 * @param playerId
	 * @return
	 */
	public int crowdfundingStatus(CrowdfundingActivityCommunal crowdfundingActivityCommunal , long playerId){
		//未开奖
		int statuds = 0;
		//已开奖
		if(crowdfundingActivityCommunal.getCurrentQuantity() == crowdfundingActivityCommunal.getTotalQuantity())
			statuds = 1;
		//中奖者是不是我
		if(crowdfundingActivityCommunal.getWonPlayerId() == playerId)
			statuds = 2;
		return statuds;
	}
	
	
	/**
	 *
	 * @return
	 */
	public GroupPurchaseActivity getGpActivity() {
		
		Activity activity = this.activityContext.getActivity(ActivityType.GROUP_PURCHASE);
		
		Map<Integer, GroupPurchaseItemTemplate> itemTemplateMap = templates.getGroupPurchaseItemTemplateMap();
		
		Map<Integer, GroupPurchaseItem> gpItemMap = itemTemplateMap.values().stream()
				.map(GroupPurchaseItem::new)
				.collect(Collectors.toMap(GroupPurchaseItem::getItemId, t -> t));
		
		GroupPurchaseActivity gpActivity = new GroupPurchaseActivity(activity, gpItemMap);
		gpActivity.updateSum(this.activityContext.getGroupPurchaseSumMap());
		gpActivity.updatePurchaseCount(this.purchaseCountMap);
		return gpActivity;
		
    }
}

This snippet took 0.06 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).