当前位置: 首页>>代码示例>>C++>>正文


C++ Quest::hasStartJobRewards方法代码示例

本文整理汇总了C++中Quest::hasStartJobRewards方法的典型用法代码示例。如果您正苦于以下问题:C++ Quest::hasStartJobRewards方法的具体用法?C++ Quest::hasStartJobRewards怎么用?C++ Quest::hasStartJobRewards使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Quest的用法示例。


在下文中一共展示了Quest::hasStartJobRewards方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: giveRewards

bool PlayerQuests::giveRewards(int16_t questid, bool start) {
	Quest *questinfo = QuestDataProvider::Instance()->getInfo(questid);

	if (!questinfo->hasRewards()) {
		return true;
	}

	QuestRewardInfo info;
	vector<QuestRewardInfo> items;
	int32_t chance = 0;
	Rewards::iterator startiter;
	Rewards::iterator enditer;
	Rewards::iterator sjobiter;
	Rewards::iterator ejobiter;
	Rewards::iterator iter;
	bool jobrewards = false;
	int16_t job = m_player->getStats()->getJob();

	if (start) {
		startiter = questinfo->getStartRewardsBegin();
		enditer = questinfo->getStartRewardsEnd();
		if (questinfo->hasStartJobRewards(job)) {
			sjobiter = questinfo->getStartJobRewardsBegin(job);
			ejobiter = questinfo->getStartJobRewardsEnd(job);
			jobrewards = true;
		}
	}
	else {
		startiter = questinfo->getEndRewardsBegin();
		enditer = questinfo->getEndRewardsEnd();
		if (questinfo->hasEndJobRewards(job)) {
			sjobiter = questinfo->getEndJobRewardsBegin(job);
			ejobiter = questinfo->getEndJobRewardsEnd(job);
			jobrewards = true;
		}
	}
	if (!checkRewards(questid, startiter, enditer) || (jobrewards && !checkRewards(questid, sjobiter, ejobiter))) {
		return false;
	}
	for (iter = startiter; iter != enditer; iter++) { // Give all applicable rewards
		if (iter->isitem && iter->prop > 0) {
			chance += iter->prop;
			items.push_back(*iter);
		}
		else {
			giveRewards(*iter);
		}
	}
	if (jobrewards) {
		for (iter = sjobiter; iter != ejobiter; iter++) {
			if (iter->isitem && iter->prop > 0) {
				chance += iter->prop;
				items.push_back(*iter);
			}
			else {
				giveRewards(*iter);
			}
		}
	}
	if (chance > 0) {
		int32_t random = Randomizer::Instance()->randInt(chance - 1);
		chance = 0;
		for (size_t i = 0; i < items.size(); i++) {
			info = items[i];
			if (chance >= random) {
				QuestsPacket::giveItem(m_player, info.id, info.count);
				if (info.count > 0) {
					Inventory::addNewItem(m_player, info.id, info.count);
				}
				else {
					Inventory::takeItem(m_player, info.id, -info.count);
				}
				break;
			}
			else {
				chance += info.prop;
			}
		}
	}
	return true;
}
开发者ID:JakeShirley,项目名称:Vana,代码行数:81,代码来源:PlayerQuests.cpp


注:本文中的Quest::hasStartJobRewards方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。