Exemple #1
0
uint32_t Vocation::getReqSkillTries(SkillType skill, int32_t level)
{
	assert(skill.exists());

	cacheMap& skillMap = cacheSkill[skill.value()];
	cacheMap::iterator it = skillMap.find(level);
	if(it != cacheSkill[skill.value()].end())
		return it->second;
	
	uint32_t tries = (uint32_t)(skillBases[skill.value()] * std::pow((float)skillMultipliers[skill.value()], (float)(level - 11)));
	skillMap[level] = tries;
	return tries;
}
Exemple #2
0
void HRC::reportSalarySurvey(SkillType skill, DT sDate, DT eDate) {
	double avg_salary = 0, tot_salaries = 0;
	int n = 0;
	set<Placement, classcomp> db_set = placementsBySkillType[skill.to_num()];
	for (set<Placement, classcomp>::iterator it = db_set.begin(); it
			!= db_set.end(); it++) {
		tot_salaries += it->salary;
		n++;
	}
	avg_salary = tot_salaries / n;
	reporter.reportSalarySurvey(&skill, avg_salary, sDate, eDate);
	ostringstream msg;
	msg << "Salary Survey report was generated.";
	logger->Log(msg.str(), Poco::Message::PRIO_NOTICE);
}
Exemple #3
0
bool IOPlayer::loadPlayer(Player* player, const std::string& name, bool preload /*= false*/)
{
	DatabaseDriver* db = DatabaseDriver::instance();
	DBQuery query;
	DBResult_ptr result;

	query << "SELECT `players`.`id` AS `id`, `players`.`name` AS `name`, `accounts`.`name` AS `accname`, \
		`account_id`, `sex`, `vocation`, `town_id`, `experience`, `level`, `maglevel`, `health`, \
		`groups`.`name` AS `groupname`, `groups`.`flags` AS `groupflags`, `groups`.`access` AS `access`, \
		`groups`.`maxviplist` AS `maxviplist`, `groups`.`maxdepotitems` AS `maxdepotitems`, `groups`.`violation` AS `violationaccess`, \
		`healthmax`, `mana`, `manamax`, `manaspent`, `soul`, `direction`, `lookbody`, \
		`lookfeet`, `lookhead`, `looklegs`, `looktype`, `lookaddons`, `posx`, `posy`, `posz`, `cap`, \
		`lastlogin`, `lastlogout`, `lastip`, `conditions`, `skull_time`, `skull_type`, `stamina`, \
		`loss_experience`, `loss_mana`, `loss_skills`, `loss_items`, `loss_containers` \
		FROM `players` \
		LEFT JOIN `accounts` ON `account_id` = `accounts`.`id`\
		LEFT JOIN `groups` ON `groups`.`id` = `players`.`group_id` \
		WHERE `world_id` = " << g_config.getNumber(ConfigManager::WORLD_ID) << " AND `players`.`name` = " + db->escapeString(name);

	if(!(result = db->storeQuery(query))){
		return false;
	}

	player->setGUID(result->getDataInt("id"));
	player->accountId = result->getDataInt("account_id");
	player->accountName = result->getDataString("accname");

	player->groupName = result->getDataString("groupname");
	player->accessLevel = result->getDataInt("access");
	player->violationLevel = result->getDataInt("violationaccess");
	player->maxDepotLimit = result->getDataInt("maxdepotitems");
	player->maxVipLimit = result->getDataInt("maxviplist");
	player->setFlags(result->getDataLong("groupflags"));

	if(preload){
		//only loading basic info
		return true;
	}

	// Getting all player properties
	player->setSex((PlayerSex)result->getDataInt("sex"));
	player->setDirection((Direction)result->getDataInt("direction"));
	player->level = std::max((uint32_t)1, (uint32_t)result->getDataInt("level"));

	player->town = result->getDataInt("town_id");
	Town* town = Towns::getInstance()->getTown(player->town);
	if(town){
		player->masterPos = town->getTemplePosition();
	}

	uint64_t currExpCount = Player::getExpForLevel(player->level);
	uint64_t nextExpCount = Player::getExpForLevel(player->level + 1);
	uint64_t experience = (uint64_t)result->getDataLong("experience");
	if(experience < currExpCount || experience  > nextExpCount){
		experience = currExpCount;
	}

	player->experience = experience;
	player->levelPercent = Player::getPercentLevel(player->experience - currExpCount, nextExpCount - currExpCount);
	player->soul = result->getDataInt("soul");
	player->capacity = result->getDataInt("cap");
	player->stamina = result->getDataInt("stamina");
	player->lastLoginSaved = result->getDataInt("lastlogin");
	player->lastLogout = result->getDataInt("lastlogout");

	player->health = result->getDataInt("health");
	player->healthMax = result->getDataInt("healthmax");
	player->defaultOutfit.lookType = result->getDataInt("looktype");
	player->defaultOutfit.lookHead = result->getDataInt("lookhead");
	player->defaultOutfit.lookBody = result->getDataInt("lookbody");
	player->defaultOutfit.lookLegs = result->getDataInt("looklegs");
	player->defaultOutfit.lookFeet = result->getDataInt("lookfeet");
	player->defaultOutfit.lookAddons = result->getDataInt("lookaddons");

	player->currentOutfit = player->defaultOutfit;

#ifdef __SKULLSYSTEM__
	SkullType skullType = SkullType(result->getDataInt("skull_type"));
	int64_t lastSkullTime = result->getDataLong("skull_time");

	if((skullType == SKULL_RED && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::RED_SKULL_DURATION)) ||
		(skullType == SKULL_BLACK && std::time(NULL) < lastSkullTime + g_config.getNumber(ConfigManager::BLACK_SKULL_DURATION))){
		player->lastSkullTime = lastSkullTime;
		player->skullType = skullType;
	}
#endif

	unsigned long conditionsSize = 0;
	const char* conditions = result->getDataStream("conditions", conditionsSize);
	PropStream propStream;
	propStream.init(conditions, conditionsSize);

	Condition* condition;
	while((condition = Condition::createCondition(propStream))){
		if(condition->unserialize(propStream)){
			player->storedConditionList.push_back(condition);
		}
		else{
			delete condition;
		}
	}

	// you need to set the vocation after conditions in order to ensure the proper regeneration rates for the vocation
	player->setVocation(result->getDataInt("vocation"));
	// this stuff has to go after the vocation is set
	player->mana = result->getDataInt("mana");
	player->manaMax = result->getDataInt("manamax");
	player->magLevel = result->getDataInt("maglevel");

	uint32_t nextManaCount = (uint32_t)player->vocation->getReqMana(player->magLevel + 1);
	uint32_t manaSpent = (uint32_t)result->getDataInt("manaspent");
	if(manaSpent > nextManaCount){
		//make sure its not out of bound
		manaSpent = 0;
	}
	player->manaSpent = manaSpent;
	player->magLevelPercent = Player::getPercentLevel(player->manaSpent, nextManaCount);

	player->setLossPercent(LOSS_EXPERIENCE, result->getDataInt("loss_experience"));
	player->setLossPercent(LOSS_MANASPENT, result->getDataInt("loss_mana"));
	player->setLossPercent(LOSS_SKILLTRIES, result->getDataInt("loss_skills"));
	player->setLossPercent(LOSS_ITEMS, result->getDataInt("loss_items"));
	player->setLossPercent(LOSS_CONTAINERS, result->getDataInt("loss_containers"));

	player->loginPosition.x = result->getDataInt("posx");
	player->loginPosition.y = result->getDataInt("posy");
	player->loginPosition.z = result->getDataInt("posz");

// login position is temple position
	Position loginPos = player->loginPosition;
	if(loginPos.x == 0 && loginPos.y == 0 && loginPos.z == 0){
		player->loginPosition = player->masterPos;
	}

	query.reset();
	query <<
		"SELECT "
		"	`guild_ranks`.`name` as `rank`, `guild_ranks`.`guild_id` as `guildid`, "
		"	`guild_ranks`.`level` as `level`, `guilds`.`name` as `guildname`, "
		"	`guild_members`.`nick` AS `nick` "
		"FROM `guild_members` "
		"LEFT JOIN `guild_ranks` ON `guild_ranks`.`id` = `guild_members`.`rank_id` "
		"LEFT JOIN `guilds` ON `guilds`.`id` = `guild_ranks`.`guild_id` "
		"WHERE `guild_members`.`player_id` = " << player->getGUID();

	if((result = db->storeQuery(query))){
		player->guildName = result->getDataString("guildname");
		player->guildLevel = result->getDataInt("level");
		player->guildId = result->getDataInt("guildid");
		player->guildRank = result->getDataString("rank");
		player->guildNick = result->getDataString("nick");
	}

	//get password
	query.reset();
	query << "SELECT `password`, `premend` FROM `accounts` WHERE `id` = " << player->accountId;
	if(!(result = db->storeQuery(query))){
		return false;
	}

	player->password = result->getDataString("password");
	player->premiumDays = IOAccount::getPremiumDaysLeft(result->getDataInt("premend"));

	// we need to find out our skills
	// so we query the skill table
	query.reset();
	query << "SELECT `skill_id`, `value`, `count` FROM `player_skills` WHERE `player_id` = " << player->getGUID();
	for(result = db->storeQuery(query); result; result = result->advance()){
		//now iterate over the skills
		try {
			SkillType skillid = SkillType::fromInteger(result->getDataInt("skill_id"));

			uint32_t skillLevel = result->getDataInt("value");
			uint32_t skillCount = result->getDataInt("count");

			uint32_t nextSkillCount = player->vocation->getReqSkillTries(skillid, skillLevel + 1);
			if(skillCount > nextSkillCount){
				//make sure its not out of bound
				skillCount = 0;
			}

			player->skills[skillid.value()][SKILL_LEVEL] = skillLevel;
			player->skills[skillid.value()][SKILL_TRIES] = skillCount;
			player->skills[skillid.value()][SKILL_PERCENT] = Player::getPercentLevel(skillCount, nextSkillCount);
		} catch(enum_conversion_error&) {
			std::cout << "Unknown skill ID when loading player " << result->getDataInt("skillid") << std::endl;
		}
	}

	//load inventory items
	ItemMap itemMap;

	/*
	query.reset();
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_items` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if((result = db->storeQuery(query.str()))){
		loadItems(itemMap, result);

		ItemMap::reverse_iterator it;
		ItemMap::iterator it2;

		for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){
			Item* item = it->second.first;
			int pid = it->second.second;
			if(pid >= 1 && pid <= 10){
				player->__internalAddThing(pid, item);
			}
			else{
				it2 = itemMap.find(pid);
				if(it2 != itemMap.end())
					if(Container* container = it2->second.first->getContainer()){
						container->__internalAddThing(item);
					}
			}
		}

		db->freeResult(result);
	}


	//load depot items
	itemMap.clear();

	query.str("");
	query << "SELECT `pid`, `sid`, `itemtype`, `count`, `attributes` FROM `player_depotitems` WHERE `player_id` = " << player->getGUID() << " ORDER BY `sid` DESC";
	if((result = db->storeQuery(query.str()))){
		loadItems(itemMap, result);

		ItemMap::reverse_iterator it;
		ItemMap::iterator it2;

		for(it = itemMap.rbegin(); it != itemMap.rend(); ++it){
			Item* item = it->second.first;
			int pid = it->second.second;
			if(pid >= 0 && pid < 100){
				if(Container* c = item->getContainer()){
					if(Depot* depot = c->getDepot())
						player->addDepot(depot, pid);
					else
						std::cout << "Error loading depot "<< pid << " for player " << player->getGUID() << std::endl;
				}
				else{
					std::cout << "Error loading depot "<< pid << " for player " <<
						player->getGUID() << std::endl;
				}
			}
			else{
				it2 = itemMap.find(pid);
				if(it2 != itemMap.end())
					if(Container* container = it2->second.first->getContainer()){
						container->__internalAddThing(item);
					}
			}
		}

		db->freeResult(result);
	}
	*/

	//load storage map
	query.str("");
	query << "SELECT `id`, `value` FROM `player_storage` WHERE `player_id` = " << player->getGUID();
	for(result = db->storeQuery(query); result; result = result->advance()){
		std::string key = result->getDataString("id");
		std::string value = result->getDataString("value");
		player->setCustomValue(key, value);
	}

	//load vips
	query.str("");
	query << "SELECT `vip_id` FROM `player_viplist` WHERE `player_id` = " << player->getGUID();
	for(result = db->storeQuery(query); result; result = result->advance()){
		uint32_t vip_id = result->getDataInt("vip_id");
		std::string dummy_str;
		if(storeNameByGuid(*db, vip_id))
			player->addVIP(vip_id, dummy_str, false, true);
	}

	player->updateBaseSpeed();
	player->updateInventoryWeight();
	player->updateItemsLight(true);

	return true;
}