任务系统解析

任务系统解析

Scroll Down

前言

任务有主线,日常,也有和活动相连的活动任务,很多项目用得到,例如饿了吗接单,消费等任务

TaskParser任务解析类

这里和活动有区别,任务实现类统一管理任务,各任务解析器触发任务事件

public interface TaskParser {
	/**
	 * 初始化
	 * @param task
	 * @param taskConfig
	 */
	void init(Task task, TaskConfig taskConfig);
	/**
	 * 解析
	 * @param t
	 * @param task
	 * @param taskConfig
	 */
	boolean parser(GameEvent event, Task task, TaskConfig taskConfig);
}

AbstractTaskParser实现类

public abstract class AbstractTaskParser<T> implements TaskParser {
	protected final Logger LOGGER = LoggerFactory.getLogger(getClass());
	@Autowired
	private TaskContext taskContext;
	@Autowired
	protected GlobalConfigService globalConfigService;
	@PostConstruct
	private void init() {
		taskContext.register(getType(), this);
	}
	protected abstract TaskConditionType getType();
	@Override
	public boolean parser(GameEvent event, Task task, TaskConfig taskConfig) {
		T t = event.convert();
		return this.parseCondition(t, task, taskConfig);
	}
	protected abstract boolean parseCondition(T event, Task task, TaskConfig taskConfig);
}

具体任务实现

添加好友任务

添加好友时触发事件

DispatchHelper.postEvent(new FriendAddEvent(actorId));

任务解析,如果条件达到则完成

@Component
public class FriendAddTaskParser extends AbstractTaskParser<FriendAddEvent> {
	@Override
	public void init(Task task, TaskConfig taskConfig) {
	}
	@Override
	protected TaskConditionType getType() {
		return TaskConditionType.FRIEND_ADD;
	}
	@Override
	protected boolean parseCondition(FriendAddEvent event, Task task, TaskConfig taskConfig) {
		task.setValue(task.getValue() + 1);
		if (task.getValue() >= taskConfig.getValue()) {
			task.setStatus(TaskStatus.FINISH);
		}
		return true;
	}
}

TaskParser解析方法parser,具体解析方式任务类实现

@Override
	public void onEvent(GameEvent event) {
		Collection<Task> refreshTaskList = Lists.newArrayList();
		this.refreshTaskOpenStatus(event, refreshTaskList);
		long actorId = event.getUniqueId();
		Collection<TaskConditionType> types = taskContext.getTypes(event.name);
		if (types != null) {
			for (TaskConditionType conditionType : types) {
				TaskParser parser = taskContext.getParser(conditionType);
				if (parser == null) {
					LOGGER.error("TaskParser not found, conditionType:{}", conditionType);
					continue;
				}

TaskFacade任务接口

public interface TaskFacade {
	/**
	 * 获取任务列表
	 * @param actorId
	 * @return
	 */
	Collection<Task> getTaskList(long actorId);
	/**
	 * 获取活跃值
	 * @param actorId
	 * @return
	 */
	TResult<Active> getActive(long actorId);
	/**
	 * 领取任务奖励
	 * @param actorId
	 * @param taskId
	 * @return
	 */
	TResult<RewardResult> receiveTask(long actorId, int taskId);
	/**
	 * 领取活跃值奖励
	 * @param actorId
	 * @param value
	 * @return
	 */
	TResult<RewardResult> receiveActive(long actorId, int value);
	/**
	 * 创建任务
	 * @param actorId
	 * @param taskConfig
	 */
	TResult<Task> creatTask(long actorId, TaskConfig taskConfig);
	/**
	 * 创建任务(不会初始化)
	 * @param actorId
	 * @param taskIds
	 */
	void createTask(long actorId, Collection<Integer> taskIds);
	/**
	 * 一键领取任务奖励
	 * @param actorId
	 * @return
	 */
	TResult<RewardResult> quickReceiveTask(long actorId, int taskType);
}

TaskFacadeImpl任务实现类

这里和活动有区别,任务实现类统一管理任务,各任务解析器触发任务事件,直接贴代码看吧

@Component
public class TaskFacadeImpl extends GameBaseFacade implements TaskFacade, OnEventListener {
	@Autowired
	private TaskDao taskDao;
	@Autowired
	private TaskContext taskContext;
	@Autowired
	private ActiveDao activeDao;
	@Autowired
	private ActivityGlobalDao activityGlobalDao;
	@Override
	public Collection<Task> getTaskList(long actorId) {
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		if (taskList.isEmpty()) {
			Collection<TaskConfig> taskConfigList = TaskConfigService.getInitTaskConfigList();
			TResult<Active> activeResult = this.getActive(actorId);
			Active active = activeResult.item;
			Map<Integer, Integer> titleTaskDiffcultMap = globalConfigService.findGlobalObject(GlobalConfigKey.TITLE_DIFFCULT_NUM, IntMapConfig.class)
					.getMap();
			if (!DateUtils.isToday(active.getLastResetTitleTaskTime())) {
				Collection<TaskConfig> titleTaskList = TaskConfigService.randomTask(titleTaskDiffcultMap, getExcludeTaskGroupIdList(actorId));
				if (!titleTaskList.isEmpty()) {
					taskConfigList.addAll(titleTaskList);
					active.setLastResetTitleTaskTime(System.currentTimeMillis());
					dbQueue.updateQueue(active);
				}
			}
			for (TaskConfig taskConfig : taskConfigList) {
				this.creatTask(actorId, taskConfig);
			}
			taskList = taskDao.getTaskList(actorId);
		}
		return taskList;
	}

	private List<Integer> getExcludeTaskGroupIdList(long actorId) {
		int titleId = ActorHelper.getTitleId(actorId);
		ActorTitleConfig actorTitleConfig = globalConfigService.findConfig(IdentiyKey.build(titleId), ActorTitleConfig.class);
		if (actorTitleConfig == null) {
			List<Integer> initExcludeGroupIdList = globalConfigService
					.findGlobalObject(GlobalConfigKey.TITLE_INIT_EXCLUDE_TASK_GROUP_LIST, IntListConfig.class).getVs();
			return initExcludeGroupIdList;
		}
		return actorTitleConfig.getExcludeTaskGroupIdList();
	}

	/**
	 * 创建任务
	 * @param actorId
	 * @param taskConfig
	 * @return
	 */
	@Override
	public TResult<Task> creatTask(long actorId, TaskConfig taskConfig) {
		if (taskConfig.getTaskType() == TaskType.CARNIVAL
				&& SettingsHelper.getServerStartDays() > globalConfigService.findGlobalConfig(GlobalConfigKey.CARNIVAL_DURATION_DAYS).findInt()) {
			return TResult.fail();
		}
		if (taskConfig.getTaskType() == TaskType.HALF_MONTH_FESTIVAL && (SettingsHelper.getServerStartDays() > globalConfigService
				.findGlobalConfig(GlobalConfigKey.HALF_MONTH_DAYS).findInt()
				|| SettingsHelper.getServerStartDays() <= globalConfigService.findGlobalConfig(GlobalConfigKey.CARNIVAL_DURATION_DAYS).findInt())) {
			return TResult.fail();
		}
		if (taskConfig.getTaskType() == TaskType.TREASURE_GIFT
				&& ActivityOpenConfigService.getActivityOpenConfigList(ActivityType.ACTIVITY_TYPE_41).isEmpty()) {
			return TResult.fail();
		} else if (taskConfig.getTaskType() == TaskType.HAPPY_CELEBRATION
				&& ActivityOpenConfigService.getActivityOpenConfigList(ActivityType.ACTIVITY_TYPE_75).isEmpty()) {
			return TResult.fail();
		} else if (taskConfig.getTaskType() == TaskType.ACTIVITY_85
				&& ActivityOpenConfigService.getActivityOpenConfigList(ActivityType.ACTIVITY_TYPE_85).isEmpty()) {
			return TResult.fail();
		} else if (taskConfig.getTaskType() == TaskType.LEVEL_UP_DROP) {
			return TResult.fail();
		}
		TaskStatus status = this.getOpenStatus(actorId, taskConfig);
		Task task = taskDao.createTask(actorId, taskConfig.getGroupId(), taskConfig.getTaskId(), taskConfig.getTaskType(), status);
		if (task.getStatus() == TaskStatus.PROGRESS) {
			initTask(task, taskConfig);
			dbQueue.updateQueue(task);
		} else {
			if (task.getType() == TaskType.TITLE_DAILY) {
				initTask(task, taskConfig);
				dbQueue.updateQueue(task);
			}
		}
		return TResult.sucess(task);
	}

	@Override
	public TResult<Active> getActive(long actorId) {
		Active active = activeDao.getActive(actorId);
		return TResult.sucess(active);
	}

	@Override
	public TResult<RewardResult> receiveTask(long actorId, int taskId) {
		TaskConfig taskConfig = TaskConfigService.getTaskConfig(taskId);
		if (taskConfig == null) {
			LOGGER.error("TaskConfig not found, taskId:{}", taskId);
			return TResult.valueOf(CONFIG_NOT_FOUND);
		}
		Task task = taskDao.getTask(actorId, taskConfig.getGroupId());
		if (task == null) {
			return TResult.valueOf(TASK_NOT_FOUND);
		}
		if (task.getTaskId() != taskId) {
			return TResult.valueOf(TASK_ID_ERROR);
		}
		if (task.getStatus() != TaskStatus.FINISH) {
			return TResult.valueOf(TASK_STATUS_ERROR);
		}
		if (taskConfig.getTaskType() == TaskType.HAPPY_CELEBRATION
				&& !ActivityOpenConfigService.getActivityOpenConfigList(ActivityType.ACTIVITY_TYPE_75).isEmpty()) {
			List<ActivityOpenConfig> configList = ActivityOpenConfigService.getActivityOpenConfigList(ActivityType.ACTIVITY_TYPE_75);
			for (ActivityOpenConfig activityOpenConfig : configList) {
				ActivityGlobal activityGlobal = activityGlobalDao.getActivityGlobal(activityOpenConfig.getId());
				if (activityGlobal.getStatus() == ActivityStatus.SHOW.getId()) {
					return TResult.valueOf(TASK_STATUS_ERROR);
				}
			}
		}
		task.setStatus(TaskStatus.RECEIVED);
		TaskPushHelper.pushTaskList(actorId, Lists.newArrayList(task));
		RewardResult rewardResult = RewardHelper.sendRewardList(actorId, taskConfig.getRewardList(), OperationType.TASK_RECEIVE);
		this.openNextTask(task);
		dbQueue.updateQueue(task);
		TaskPushHelper.pushTaskList(actorId, Lists.newArrayList(task));
		if (taskConfig.getTaskType() == TaskType.DAILY) {
			this.addActive(actorId, taskConfig.getActive());
		}
		DispatchHelper.postEvent(new TaskCompleteEvent(actorId, taskConfig.getActive(), taskConfig.getTaskType(), taskId));
		return TResult.sucess(rewardResult);
	}

	/**
	 * 添加活跃值
	 * @param actorId
	 * @param value
	 */
	private void addActive(long actorId, int value) {
		TResult<Active> activeResult = this.getActive(actorId);
		if (activeResult.isFail()) {
			return;
		}
		Active active = activeResult.item;
		active.addActive(value);
		dbQueue.updateQueue(active);
		TaskPushHelper.pushActiveInfo(actorId, active.getActive(), active.getActiveEntityList());
	}

	@Override
	public TResult<RewardResult> receiveActive(long actorId, int value) {
		TResult<Active> activeResult = this.getActive(actorId);
		if (activeResult.isFail()) {
			return TResult.valueOf(activeResult.statusCode);
		}
		Active active = activeResult.item;
		if (active.getActive() < value) {
			return TResult.valueOf(ACTIVE_RECEIVE_ERROR);
		}
		ActiveEntity entity = active.getActiveEntity(value);
		if (entity == null || entity.isReceive()) {
			return TResult.valueOf(ACTIVE_RECEIVE_ERROR);
		}
		RewardResult rewardResult = RewardHelper.sendRewardList(actorId, entity.getRewards(), OperationType.ACTIVE_RECEIVE);
		entity.setReceive(true);
		dbQueue.updateQueue(active);
		TaskPushHelper.pushActiveInfo(actorId, active.getActive(), active.getActiveEntityList());
		return TResult.sucess(rewardResult);
	}

	private void openNextTask(Task task) {
		TaskConfig nextConfig = TaskConfigService.getNextTaskConfig(task.getTaskId());
		if (nextConfig != null) {
			TaskStatus status = this.getOpenStatus(task.getActorId(), nextConfig);
			task.next(nextConfig.getTaskId(), status);
			if (task.getStatus() == TaskStatus.PROGRESS) {
				initTask(task, nextConfig);
			}
			dbQueue.updateQueue(task);
		}
	}

	/**
	 * 获取开启状态
	 * @param actorId
	 * @param config
	 * @return
	 */
	private TaskStatus getOpenStatus(long actorId, TaskConfig config) {
		TaskStatus status = TaskStatus.UNOPENED;
		if (ActorHelper.unlock(actorId, config.getUnlockIdList()).isOk()) {
			status = TaskStatus.PROGRESS;
		}
		return status;
	}

	@EventOnline(trigger = TriggerTime.FIXED_HOUR, triggerValue = 0)
	public void onEvery0Hour(GameEvent e) {
		this.sendActiveOssLogger(e.getUniqueId());
		this.resetTask(e.getUniqueId(), true);
		this.resetActive(e.getUniqueId(), true);
		this.reloadTask(e.getUniqueId(), true);
	}

	@Event(name = EventKey.ACTOR_LOGIN)
	public void onActorLogin(GameEvent e) {
		this.resetTask(e.getUniqueId(), false);
		this.resetActive(e.getUniqueId(), false);
		this.reloadTask(e.getUniqueId(), false);
	}

	/**
	 * 定点发送日常任务活跃值日志
	 * @param uniqueId
	 */
	private void sendActiveOssLogger(long actorId) {
		TResult<Active> activeResult = this.getActive(actorId);
		if (activeResult.isFail()) {
			return;
		}
		Active active = activeResult.item;
		GameOssLogger.active(actorId, active.getActive());
	}

	/**
	 * 重置活跃值
	 * @param actorId
	 * @param push
	 */
	private void resetActive(long actorId, boolean push) {
		TResult<Active> activeResult = this.getActive(actorId);
		if (activeResult.isFail()) {
			return;
		}
		Active active = activeResult.item;
		if (DateUtils.isToday(active.getLastResetTime())) {
			return;
		}
		Collection<ActiveConfig> activeConfigList = ActiveConfigService.getActivityMap(ActorHelper.getActorLevel(actorId));
		active.reset(activeConfigList);
		dbQueue.updateQueue(active);
		if (push) {
			TaskPushHelper.pushActiveInfo(actorId, active.getActive(), active.getActiveEntityList());
		}
		this.processCarnivalReward(actorId);
		this.processHalfMonthCarnivalReward(actorId);
	}

	/**
	 * 重置任务
	 * @param actorId
	 * @param push
	 */
	private void resetTask(long actorId, boolean push) {
		Collection<Task> resetList = Lists.newArrayList();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		for (Task task : taskList) {
			if (DateUtils.isToday(task.getLastResetTime())) {
				continue;
			}
			if (task.getType() == TaskType.TITLE_DAILY) {
				task.setStatus(TaskStatus.DELETE);
				resetList.add(task);
				continue;
			}
			if (task.getStatus() == TaskStatus.UNOPENED) {
				continue;
			}
			if (task.getType() == TaskType.DAILY || task.getType() == TaskType.TOKEN) {
				task.reset();
				resetList.add(task);
				dbQueue.updateQueue(task);
			}
		}
		if (!resetList.isEmpty()) {
			Collection<Integer> vipCardTypeList = ActorHelper.getVipCardType(actorId);
			if (!vipCardTypeList.isEmpty()) {
				DispatchHelper.postEvent(new ActorVipCardRefreshEvent(actorId, vipCardTypeList));
			}
			if (push) {
				TaskPushHelper.pushTaskList(actorId, resetList);
			}
		}
	}

	@Event(name = EventKey.ACTIVITY_41_END_EVENT)
	public void onActivity41End(GameEvent e) {
		long actorId = e.getUniqueId();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<Task> refreshTaskList = Lists.newArrayList();
		for (Task task : taskList) {
			if (task.getType() == TaskType.TREASURE_GIFT) {
				taskDao.removeTask(task);
				task.setStatus(TaskStatus.DELETE);
				refreshTaskList.add(task);
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

	@Event(name = EventKey.ACTIVITY_75_END_EVENT)
	public void onActivity75End(GameEvent e) {
		long actorId = e.getUniqueId();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<Task> refreshTaskList = Lists.newArrayList();
		for (Task task : taskList) {
			if (task.getType() == TaskType.HAPPY_CELEBRATION) {
				taskDao.removeTask(task);
				task.setStatus(TaskStatus.DELETE);
				refreshTaskList.add(task);
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}
	
	@Event(name = EventKey.ACTIVITY_85_END_EVENT)
	public void onActivity85End(GameEvent e) {
		long actorId = e.getUniqueId();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<Task> refreshTaskList = Lists.newArrayList();
		for (Task task : taskList) {
			if (task.getType() == TaskType.ACTIVITY_85) {
				taskDao.removeTask(task);
				task.setStatus(TaskStatus.DELETE);
				refreshTaskList.add(task);
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

	@Event(name = EventKey.ACTIVITY_ACTIVE_TASK_END_EVENT)
	public void onActivityActiveTaskEnd(GameEvent e) {
		ActivityActiveTaskEndEvent event = e.convert();
		long actorId = event.getActorId();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<Task> refreshTaskList = Lists.newArrayList();
		for (Task task : taskList) {
			if (event.taskIds.contains(task.getTaskId())) {
				taskDao.removeTask(task);
				task.setStatus(TaskStatus.DELETE);
				refreshTaskList.add(task);
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

	/**
	 * 重载任务
	 * @param actorId
	 */
	private void reloadTask(long actorId, boolean isPush) {
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		if (taskList.isEmpty()) {
			return;
		}
		TResult<Active> activeResult = this.getActive(actorId);
		if (activeResult.isFail()) {
			return;
		}
		Collection<TaskConfig> taskConfigList = TaskConfigService.getInitTaskConfigList();
		Active active = activeResult.item;
		Collection<Task> refreshTaskList = Lists.newArrayList();
		// 加载新的任务组
		if (!DateUtils.isToday(active.getLastResetTitleTaskTime())) {
			Map<Integer, Integer> titleTaskDiffcultMap = globalConfigService.findGlobalObject(GlobalConfigKey.TITLE_DIFFCULT_NUM, IntMapConfig.class)
					.getMap();
			Collection<TaskConfig> titleTaskList = TaskConfigService.randomTask(titleTaskDiffcultMap, getExcludeTaskGroupIdList(actorId));
			if (!titleTaskList.isEmpty()) {
				taskConfigList.addAll(titleTaskList);
				active.setLastResetTitleTaskTime(System.currentTimeMillis());
				dbQueue.updateQueue(active);
			}
		}
		for (TaskConfig taskConfig : taskConfigList) {
			Task task = taskDao.getTask(actorId, taskConfig.getGroupId());
			if (task == null || task.getStatus() == TaskStatus.DELETE) {
				TResult<Task> taskResult = this.creatTask(actorId, taskConfig);
				if (taskResult.isOk()) {
					refreshTaskList.add(taskResult.item);
				}
			}
		}
		// 加载新配置的任务
		for (Task task : taskList) {
			if (task.getStatus() == TaskStatus.DELETE) {
				taskDao.removeTask(task);
			}
			if (task.getStatus() != TaskStatus.RECEIVED) {
				continue;
			}
			this.openNextTask(task);
		}
		if (!refreshTaskList.isEmpty() && isPush) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

	@Override
	public void registerEvent(Set<String> eventSet) {
		eventSet.addAll(taskContext.getEvents());
		eventSet.addAll(TaskConfigService.getOpenStatusEventList());
	}

	@Override
	public void onEvent(GameEvent event) {
		Collection<Task> refreshTaskList = Lists.newArrayList();
		this.refreshTaskOpenStatus(event, refreshTaskList);
		long actorId = event.getUniqueId();
		Collection<TaskConditionType> types = taskContext.getTypes(event.name);
		if (types != null) {
			for (TaskConditionType conditionType : types) {
				TaskParser parser = taskContext.getParser(conditionType);
				if (parser == null) {
					LOGGER.error("TaskParser not found, conditionType:{}", conditionType);
					continue;
				}
				Collection<Integer> taskGroupIdList = TaskConfigService.getTaskGroupIdList(conditionType);
				for (Integer groupId : taskGroupIdList) {
					Task task = taskDao.getTask(actorId, groupId);
					if (task == null || task.getStatus() != TaskStatus.PROGRESS) {
						continue;
					}
					TaskConfig taskConfig = TaskConfigService.getTaskConfig(task.getTaskId());
					if (taskConfig == null) {
						LOGGER.error("TaskConfig not found, taskId:{}", task.getTaskId());
						continue;
					}
					try {
						if (parser.parser(event, task, taskConfig)) {
							dbQueue.updateQueue(task);
							refreshTaskList.add(task);
						}
					} catch (Exception e) {
						LOGGER.error("actorId:{},taskId:{}", actorId, task.getTaskId());
						LOGGER.error("{}", e);
					}
				}
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

	private void refreshTaskOpenStatus(GameEvent event, Collection<Task> refreshTaskList) {
		if (!TaskConfigService.isOpenStatusEvent(event.getName())) {
			return;
		}
		long actorId = event.getUniqueId();
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		for (Task task : taskList) {
			if (task.getStatus() != TaskStatus.UNOPENED) {
				continue;
			}
			TaskConfig taskConfig = TaskConfigService.getTaskConfig(task.getTaskId());
			if (taskConfig == null) {
				LOGGER.error("TaskConfig not found, taskId:{}", task.getTaskId());
				continue;
			}
			if (ActorHelper.unlock(actorId, taskConfig.getUnlockIdList()).isOk()) {
				task.setStatus(TaskStatus.PROGRESS);
				task.reset();
				initTask(task, taskConfig);
				dbQueue.updateQueue(task);
				refreshTaskList.add(task);
			}
		}
	}

	private void initTask(Task task, TaskConfig taskConfig) {
		TaskParser parser = taskContext.getParser(taskConfig.getTaskConditionType());
		if (parser == null) {
			LOGGER.error("TaskParser not found,taskId:{}.conditionType:{}", taskConfig.getTaskId(), taskConfig.getTaskConditionType());
			return;
		}
		parser.init(task, taskConfig);
	}

	private void processCarnivalReward(long actorId) {
		if (SettingsHelper.getServerStartDays() <= globalConfigService.findGlobalConfig(GlobalConfigKey.CARNIVAL_DURATION_DAYS).findInt()) {
			return;
		}
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<RewardObject> rewardList = Lists.newArrayList();
		for (Task task : taskList) {
			if (task.getType() != TaskType.CARNIVAL) {
				continue;
			}
			taskDao.removeTask(task);
			TaskConfig taskConfig = TaskConfigService.getTaskConfig(task.getTaskId());
			if (taskConfig == null) {
				LOGGER.error("TaskConfig not found, taskId:{}", task.getTaskId());
				continue;
			}
			if (task.getStatus() == TaskStatus.FINISH) {
				rewardList.addAll(taskConfig.getRewardList());
			}
		}
		if (!rewardList.isEmpty()) {
			Map<String, String> params = Maps.newHashMap();
			params.put("name", ActorHelper.getActorName(actorId));
			MailAddEvent event = new MailAddEvent(actorId, MailTemplateType.CARNIVAL_REWARD, params, rewardList);
			DispatchHelper.postEvent(event);
		}
	}

	private void processHalfMonthCarnivalReward(long actorId) {
		if (SettingsHelper.getServerStartDays() <= globalConfigService.findGlobalConfig(GlobalConfigKey.HALF_MONTH_DAYS).findInt()
				&& SettingsHelper.getServerStartDays() > globalConfigService.findGlobalConfig(GlobalConfigKey.CARNIVAL_DURATION_DAYS).findInt()) {
			return;
		}
		Collection<Task> taskList = taskDao.getTaskList(actorId);
		Collection<RewardObject> rewardList = Lists.newArrayList();
		for (Task task : taskList) {
			if (task.getType() != TaskType.HALF_MONTH_FESTIVAL) {
				continue;
			}
			taskDao.removeTask(task);
			TaskConfig taskConfig = TaskConfigService.getTaskConfig(task.getTaskId());
			if (taskConfig == null) {
				LOGGER.error("TaskConfig not found, taskId:{}", task.getTaskId());
				continue;
			}
			if (task.getStatus() == TaskStatus.FINISH) {
				rewardList.addAll(taskConfig.getRewardList());
			}
		}
		if (!rewardList.isEmpty()) {
			Map<String, String> params = Maps.newHashMap();
			params.put("name", ActorHelper.getActorName(actorId));
			MailAddEvent event = new MailAddEvent(actorId, MailTemplateType.HALF_MONTH_FESTIVAL_REWARD, params, rewardList);
			DispatchHelper.postEvent(event);
		}
	}

	@Override
	public void createTask(long actorId, Collection<Integer> taskIds) {
		// 这里创建的任务不会初始化任务
		Collection<Task> taskList = Lists.newArrayList();
		for (int taskId : taskIds) {
			TaskConfig taskConfig = TaskConfigService.getTaskConfig(taskId);
			if (taskConfig == null) {
				LOGGER.error("TaskConfig not found, taskId:{}", taskId);
			}
			TaskStatus status = this.getOpenStatus(actorId, taskConfig);
			Task task = taskDao.createTask(actorId, taskConfig.getGroupId(), taskConfig.getTaskId(), taskConfig.getTaskType(), status);
			taskList.add(task);
		}
		TaskPushHelper.pushTaskList(actorId, taskList);
	}

	@Override
	public TResult<RewardResult> quickReceiveTask(long actorId, int taskType) {
		Collection<Task> taskList = this.getTaskList(actorId);
		Collection<RewardObject> rewardList = Lists.newArrayList();
		for (Task task : taskList) {
			while (true) {
				if (task.getStatus() == TaskStatus.FINISH && task.getType() == TaskType.getType(taskType)) {
					TaskConfig taskConfig = TaskConfigService.getTaskConfig(task.getTaskId());
					if (taskConfig == null) {
						LOGGER.error("TaskConfig not found, taskId:{}", task.getTaskId());
						return TResult.valueOf(CONFIG_NOT_FOUND);
					}
					task.setStatus(TaskStatus.RECEIVED);
					TaskPushHelper.pushTaskList(actorId, Lists.newArrayList(task));
					rewardList.addAll(taskConfig.getRewardList());
					this.openNextTask(task);
					dbQueue.updateQueue(task);
					TaskPushHelper.pushTaskList(actorId, Lists.newArrayList(task));
					if (taskConfig.getTaskType() == TaskType.DAILY) {
						this.addActive(actorId, taskConfig.getActive());
					}
					DispatchHelper.postEvent(new TaskCompleteEvent(actorId, taskConfig.getActive(), taskConfig.getTaskType(), task.getTaskId()));
				} else {
					break;
				}
			}
		}
		if (TaskType.getType(taskType) == TaskType.DAILY) {
			TResult<Active> activeResult = this.getActive(actorId);
			if (activeResult.isFail()) {
				return TResult.valueOf(activeResult.statusCode);
			}
			Active active = activeResult.item;
			Collection<ActiveEntity> activeEntityList = active.getActiveEntityList();
			for (ActiveEntity activeEntity : activeEntityList) {
				if (activeEntity.isReceive()) {
					continue;
				}
				if (activeEntity.getActive() <= active.getActive()) {
					rewardList.addAll(activeEntity.getRewards());
					activeEntity.setReceive(true);
				}
			}
			dbQueue.updateQueue(active);
			TaskPushHelper.pushActiveInfo(actorId, active.getActive(), active.getActiveEntityList());
		}
		RewardResult rewardResult = RewardHelper.sendRewardList(actorId, rewardList, OperationType.TASK_RECEIVE);
		return TResult.sucess(rewardResult);
	}

	@Event(name = EventKey.LEVEL_UP_DROP_TASK_EVENT)
	public void onLevelUpDropTask(GameEvent e) {
		long actorId = e.getUniqueId();
		LevelUpDropTaskEvent event = e.convert();
		Collection<Integer> taskIdList = event.taskIdList;
		Collection<Task> refreshTaskList = Lists.newArrayList();
		if (event.type == LevelUpDropTaskType.CREATE.getId()) {
			for (Integer taskId : taskIdList) {
				TaskConfig taskConfig = TaskConfigService.getTaskConfig(taskId);
				if (taskConfig == null) {
					LOGGER.error("TaskConfig not found, taskId:{}", taskId);
					continue;
				}
				TaskStatus status = this.getOpenStatus(actorId, taskConfig);
				Task task = taskDao.createTask(actorId, taskConfig.getGroupId(), taskConfig.getTaskId(), taskConfig.getTaskType(), status);
				if (task.getStatus() == TaskStatus.PROGRESS) {
					initTask(task, taskConfig);
					dbQueue.updateQueue(task);
				}
				refreshTaskList.add(task);
			}
		} else if (event.type == LevelUpDropTaskType.DELETE.getId()) {
			Collection<Task> taskList = taskDao.getTaskList(actorId);
			for (Task task : taskList) {
				if (taskIdList.contains(task.getTaskId())) {
					taskDao.removeTask(task);
					task.setStatus(TaskStatus.DELETE);
					refreshTaskList.add(task);
				}
			}
		}
		if (!refreshTaskList.isEmpty()) {
			TaskPushHelper.pushTaskList(actorId, refreshTaskList);
		}
	}

}