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


C++ PropWriteStream类代码示例

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


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

示例1: serialize

bool ConditionRegeneration::serialize(PropWriteStream& propWriteStream)
{
	if (!Condition::serialize(propWriteStream)) {
		return false;
	}

	propWriteStream.ADD_UCHAR(CONDITIONATTR_HEALTHTICKS);
	propWriteStream.ADD_VALUE(healthTicks);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_HEALTHGAIN);
	propWriteStream.ADD_VALUE(healthGain);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_MANATICKS);
	propWriteStream.ADD_VALUE(manaTicks);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_MANAGAIN);
	propWriteStream.ADD_VALUE(manaGain);
	return true;
}
开发者ID:caiohp,项目名称:forgottenserver,代码行数:19,代码来源:condition.cpp

示例2: serialize

bool ConditionLight::serialize(PropWriteStream& propWriteStream)
{
	if(!Condition::serialize(propWriteStream))
		return false;

	propWriteStream.addByte(CONDITIONATTR_LIGHTCOLOR);
	propWriteStream.addType(lightInfo.color);

	propWriteStream.addByte(CONDITIONATTR_LIGHTLEVEL);
	propWriteStream.addType(lightInfo.level);

	propWriteStream.addByte(CONDITIONATTR_LIGHTTICKS);
	propWriteStream.addType(internalLightTicks);

	propWriteStream.addByte(CONDITIONATTR_LIGHTINTERVAL);
	propWriteStream.addType(lightChangeInterval);

	return true;
}
开发者ID:Fir3element,项目名称:0.3.7,代码行数:19,代码来源:condition.cpp

示例3: serialize

bool ConditionDamage::serialize(PropWriteStream& propWriteStream)
{
	if(!Condition::serialize(propWriteStream))
		return false;

	propWriteStream.ADD_UCHAR(CONDITIONATTR_DELAYED);
	propWriteStream.ADD_VALUE(delayed);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_PERIODDAMAGE);
	propWriteStream.ADD_VALUE(periodDamage);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_OWNER);
	propWriteStream.ADD_VALUE(owner);

	for(DamageList::const_iterator it = damageList.begin(); it != damageList.end(); ++it)
	{
		propWriteStream.ADD_UCHAR(CONDITIONATTR_INTERVALDATA);
		propWriteStream.ADD_VALUE((*it));
	}
	return true;
}
开发者ID:armadaazteca,项目名称:tfs0.2.15,代码行数:21,代码来源:condition.cpp

示例4: serialize

bool ConditionOutfit::serialize(PropWriteStream& propWriteStream)
{
	if(!Condition::serialize(propWriteStream)){
		return false;
	}

	for(std::vector<Outfit_t>::const_iterator it = outfits.begin(); it != outfits.end(); ++it){
		propWriteStream.ADD_UINT8(CONDITIONATTR_OUTFIT);
		propWriteStream.ADD_UINT32((*it).lookType);
		propWriteStream.ADD_UINT32((*it).lookTypeEx);
		propWriteStream.ADD_UINT32((*it).lookHead);
		propWriteStream.ADD_UINT32((*it).lookBody);
		propWriteStream.ADD_UINT32((*it).lookLegs);
		propWriteStream.ADD_UINT32((*it).lookFeet);
		propWriteStream.ADD_UINT32((*it).lookAddons);
	}

	return true;
}
开发者ID:JoseEduardo,项目名称:otserv,代码行数:19,代码来源:condition.cpp

示例5: serialize

bool ConditionDamage::serialize(PropWriteStream& propWriteStream)
{
	if (!Condition::serialize(propWriteStream)) {
		return false;
	}

	propWriteStream.ADD_UCHAR(CONDITIONATTR_DELAYED);
	propWriteStream.ADD_VALUE(delayed);

	propWriteStream.ADD_UCHAR(CONDITIONATTR_PERIODDAMAGE);
	propWriteStream.ADD_VALUE(periodDamage);

	// propWriteStream.ADD_UCHAR(CONDITIONATTR_OWNER);
	// propWriteStream.ADD_VALUE(owner);

	for (const IntervalInfo& intervalInfo : damageList) {
		propWriteStream.ADD_UCHAR(CONDITIONATTR_INTERVALDATA);
		propWriteStream.ADD_VALUE(intervalInfo);
	}
	return true;
}
开发者ID:A-Dirty-Rag,项目名称:forgottenserver,代码行数:21,代码来源:condition.cpp

示例6: serialize

bool ConditionAttributes::serialize(PropWriteStream& propWriteStream)
{
	if(!Condition::serialize(propWriteStream)){
		return false;
	}

	for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i){
		propWriteStream.ADD_UCHAR(CONDITIONATTR_SKILLS);
		propWriteStream.ADD_VALUE(skills[i]);
	}

	for(int32_t i = SKILL_FIRST; i <= SKILL_LAST; ++i){
		propWriteStream.ADD_UCHAR(CONDITIONATTR_SKILLSPERCENT);
		propWriteStream.ADD_VALUE(skillsPercent[i]);
	}

	for(int32_t i = STAT_FIRST; i <= STAT_LAST; ++i){
		propWriteStream.ADD_UCHAR(CONDITIONATTR_STATS);
		propWriteStream.ADD_VALUE(stats[i]);
	}

	return true;
}
开发者ID:gianflogao,项目名称:divinity-ots,代码行数:23,代码来源:condition.cpp

示例7: stmt

bool IOMapSerialize::saveItems(Database* db, uint32_t& tileId, uint32_t houseId, const Tile* tile)
{
	int32_t thingCount = tile->getThingCount();
	if(!thingCount)
		return true;

	Item* item = NULL;
	int32_t runningId = 0, parentId = 0;
	ContainerStackList containerStackList;

	bool stored = false;
	DBInsert stmt(db);
	stmt.setQuery("INSERT INTO `tile_items` (`tile_id`, `world_id`, `sid`, `pid`, `itemtype`, `count`, `attributes`) VALUES ");

	DBQuery query;
	for(int32_t i = 0; i < thingCount; ++i)
	{
		if(!(item = tile->__getThing(i)->getItem()) || (!item->isMovable() && !item->forceSerialize()))
			continue;

		if(!stored)
		{
			Position tilePosition = tile->getPosition();
			query << "INSERT INTO `tiles` (`id`, `world_id`, `house_id`, `x`, `y`, `z`) VALUES ("
				<< tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << houseId << ", "
				<< tilePosition.x << ", " << tilePosition.y << ", " << tilePosition.z << ")";
			if(!db->query(query.str()))
				return false;

			stored = true;
			query.str("");
		}

		PropWriteStream propWriteStream;
		item->serializeAttr(propWriteStream);

		uint32_t attributesSize = 0;
		const char* attributes = propWriteStream.getStream(attributesSize);

		query << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << ++runningId << ", " << parentId << ", "
			<< item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);
		if(!stmt.addRow(query.str()))
			return false;

		query.str("");
		if(item->getContainer())
			containerStackList.push_back(std::make_pair(item->getContainer(), runningId));
	}

	Container* container = NULL;
	for(ContainerStackList::iterator cit = containerStackList.begin(); cit != containerStackList.end(); ++cit)
	{
		container = cit->first;
		parentId = cit->second;
		for(ItemList::const_iterator it = container->getItems(); it != container->getEnd(); ++it)
		{
			if(!(item = *it))
				continue;

			PropWriteStream propWriteStream;
			item->serializeAttr(propWriteStream);

			uint32_t attributesSize = 0;
			const char* attributes = propWriteStream.getStream(attributesSize);

			query << tileId << ", " << g_config.getNumber(ConfigManager::WORLD_ID) << ", " << ++runningId << ", " << parentId << ", "
				<< item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);
			if(!stmt.addRow(query.str()))
				return false;

			query.str("");
			if(item->getContainer())
				containerStackList.push_back(std::make_pair(item->getContainer(), runningId));
		}
	}

	if(stored)
		++tileId;

	return stmt.execute();
}
开发者ID:Codex-NG,项目名称:TheImaginedServer,代码行数:81,代码来源:iomapserialize.cpp

示例8: savePlayer

bool IOLoginData::savePlayer(Player* player)
{
	if (player->getHealth() <= 0) {
		player->changeHealth(1);
	}

	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();
	DBResult_ptr result = db->storeQuery(query.str());
	if (!result) {
		return false;
	}

	if (result->getDataInt("save") == 0) {
		query.str("");
		query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID();
		return db->executeQuery(query.str());
	}

	//serialize conditions
	PropWriteStream propWriteStream;
	for (Condition* condition : player->conditions) {
		if (condition->isPersistent()) {
			condition->serialize(propWriteStream);
			propWriteStream.write<uint8_t>(CONDITIONATTR_END);
		}
	}

	size_t conditionsSize;
	const char* conditions = propWriteStream.getStream(conditionsSize);

	//First, an UPDATE query to write the player itself
	query.str("");
	query << "UPDATE `players` SET ";
	query << "`level` = " << player->level << ',';
	query << "`group_id` = " << player->group->id << ',';
	query << "`vocation` = " << player->getVocationId() << ',';
	query << "`health` = " << player->health << ',';
	query << "`healthmax` = " << player->healthMax << ',';
	query << "`experience` = " << player->experience << ',';
	query << "`lookbody` = " << static_cast<uint32_t>(player->defaultOutfit.lookBody) << ',';
	query << "`lookfeet` = " << static_cast<uint32_t>(player->defaultOutfit.lookFeet) << ',';
	query << "`lookhead` = " << static_cast<uint32_t>(player->defaultOutfit.lookHead) << ',';
	query << "`looklegs` = " << static_cast<uint32_t>(player->defaultOutfit.lookLegs) << ',';
	query << "`looktype` = " << player->defaultOutfit.lookType << ',';
	query << "`lookaddons` = " << static_cast<uint32_t>(player->defaultOutfit.lookAddons) << ',';
	query << "`maglevel` = " << player->magLevel << ',';
	query << "`mana` = " << player->mana << ',';
	query << "`manamax` = " << player->manaMax << ',';
	query << "`manaspent` = " << player->manaSpent << ',';
	query << "`soul` = " << player->soul << ',';
	query << "`town_id` = " << player->town->getID() << ',';

	const Position& loginPosition = player->getLoginPosition();
	query << "`posx` = " << loginPosition.getX() << ',';
	query << "`posy` = " << loginPosition.getY() << ',';
	query << "`posz` = " << loginPosition.getZ() << ',';

	query << "`cap` = " << (player->capacity / 100) << ',';
	query << "`sex` = " << player->sex << ',';

	if (player->lastLoginSaved != 0) {
		query << "`lastlogin` = " << player->lastLoginSaved << ',';
	}

	if (player->lastIP != 0) {
		query << "`lastip` = " << player->lastIP << ',';
	}

	query << "`conditions` = " << db->escapeBlob(conditions, conditionsSize) << ',';

	if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
		int32_t skullTime = 0;

		if (player->skullTicks > 0) {
			skullTime = time(nullptr) + player->skullTicks / 1000;
		}

		query << "`skulltime` = " << skullTime << ',';

		Skulls_t skull = SKULL_NONE;
		if (player->skull == SKULL_RED) {
			skull = SKULL_RED;
		} else if (player->skull == SKULL_BLACK) {
			skull = SKULL_BLACK;
		}
		query << "`skull` = " << static_cast<uint32_t>(skull) << ',';
	}

	query << "`lastlogout` = " << player->getLastLogout() << ',';
	query << "`balance` = " << player->bankBalance << ',';
	query << "`offlinetraining_time` = " << player->getOfflineTrainingTime() / 1000 << ',';
	query << "`offlinetraining_skill` = " << player->getOfflineTrainingSkill() << ',';
	query << "`stamina` = " << player->getStaminaMinutes() << ',';

	query << "`skill_fist` = " << player->skills[SKILL_FIST].level << ',';
	query << "`skill_fist_tries` = " << player->skills[SKILL_FIST].tries << ',';
	query << "`skill_club` = " << player->skills[SKILL_CLUB].level << ',';
//.........这里部分代码省略.........
开发者ID:JoseEduardo,项目名称:o_487qpaos89PsIQ,代码行数:101,代码来源:iologindata.cpp

示例9: transaction

bool IOPlayer::savePlayer(Player* player)
{
	player->preSave();

	Database* db = Database::instance();
	DBQuery query;
	DBResult* result;

	//check if the player have to be saved or not
	query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();

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

	if(result->getDataInt("save") == 0){
		db->freeResult(result);

		query.str("");
		query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved
		        << ", `lastip` = " << player->lastip
				<< " WHERE `id` = " << player->getGUID();

		DBTransaction transaction(db);
		if(!transaction.begin()){
			return false;
		}

		if(!db->executeQuery(query.str())){
			return false;
		}

		transaction.commit();

		return true;
	}
	db->freeResult(result);

	//serialize conditions
	PropWriteStream propWriteStream;

	for(ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it){
		if((*it)->isPersistent()){
			if(!(*it)->serialize(propWriteStream)){
				return false;
			}

			propWriteStream.ADD_UCHAR(CONDITIONATTR_END);
		}
	}

	uint32_t conditionsSize;
	const char* conditions = propWriteStream.getStream(conditionsSize);

	//First, an UPDATE query to write the player itself
	query.str("");
	query << "UPDATE `players` SET `level` = " << player->level
    << ", `vocation` = " << (int)player->getVocationId()
	<< ", `health` = " << player->health
	<< ", `healthmax` = " << player->healthMax
	<< ", `direction` = " << (int)player->getDirection()
	<< ", `experience` = " << player->experience
	<< ", `lookbody` = " << (int)player->defaultOutfit.lookBody
	<< ", `lookfeet` = " << (int)player->defaultOutfit.lookFeet
	<< ", `lookhead` = " << (int)player->defaultOutfit.lookHead
	<< ", `looklegs` = " << (int)player->defaultOutfit.lookLegs
	<< ", `looktype` = " << (int)player->defaultOutfit.lookType
	<< ", `maglevel` = " << player->magLevel
	<< ", `mana` = " << player->mana
	<< ", `manamax` = " << player->manaMax
	<< ", `manaspent` = " << player->manaSpent
	<< ", `soul` = " << player->soul
	<< ", `town_id` = " << player->town
	<< ", `posx` = " << player->getLoginPosition().x
	<< ", `posy` = " << player->getLoginPosition().y
	<< ", `posz` = " << player->getLoginPosition().z
	<< ", `cap` = " << player->getCapacity()
	<< ", `sex` = " << player->sex
	<< ", `lastlogin` = " << player->lastLoginSaved
	<< ", `lastip` = " << player->lastip
	<< ", `conditions` = " << db->escapeBlob(conditions, conditionsSize)
	<< ", `loss_experience` = " << (int)player->getLossPercent(LOSS_EXPERIENCE)
	<< ", `loss_mana` = " << (int)player->getLossPercent(LOSS_MANASPENT)
	<< ", `loss_skills` = " << (int)player->getLossPercent(LOSS_SKILLTRIES)
	<< ", `loss_items` = " << (int)player->getLossPercent(LOSS_ITEMS)
	<< ", `balance` = " << player->balance;

#ifdef __SKULLSYSTEM__
	int32_t redSkullTime = 0;
	if(player->redSkullTicks > 0){
		redSkullTime = std::time(NULL) + player->redSkullTicks/1000;
	}

	query << ", `redskulltime` = " << redSkullTime;

	int32_t redSkull = 0;
	if(player->skull == SKULL_RED){
		redSkull = 1;
	}

//.........这里部分代码省略.........
开发者ID:gianflogao,项目名称:divinity-ots,代码行数:101,代码来源:ioplayer.cpp

示例10: while

bool IOPlayer::saveItems(Player* player, const ItemBlockList& itemList, DBInsert& query_insert)
{
	std::list<Container*> listContainer;
	std::stringstream stream;

	typedef std::pair<Container*, int32_t> containerBlock;
	std::list<containerBlock> stack;

	int32_t parentId = 0;
	int32_t runningId = 100;

	Database* db = Database::instance();
	Item* item;
	int32_t pid;

	for(ItemBlockList::const_iterator it = itemList.begin(); it != itemList.end(); ++it){
		pid = it->first;
		item = it->second;
		++runningId;

		uint32_t attributesSize;

		PropWriteStream propWriteStream;
		item->serializeAttr(propWriteStream);
		const char* attributes = propWriteStream.getStream(attributesSize);

		stream << player->getGUID() << ", " << pid << ", " << runningId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);

		if(!query_insert.addRow(stream)){
			return false;
		}

		if(Container* container = item->getContainer()){
			stack.push_back(containerBlock(container, runningId));
		}
	}

	while(stack.size() > 0){
		const containerBlock& cb = stack.front();
		Container* container = cb.first;
		parentId = cb.second;
		stack.pop_front();

		for(uint32_t i = 0; i < container->size(); ++i){
			++runningId;
			item = container->getItem(i);
			if(Container* sub = item->getContainer()){
				stack.push_back(containerBlock(sub, runningId));
			}

			uint32_t attributesSize;

			PropWriteStream propWriteStream;
			item->serializeAttr(propWriteStream);
			const char* attributes = propWriteStream.getStream(attributesSize);

			stream << player->getGUID() << ", " << parentId << ", " << runningId << ", " << item->getID() << ", " << (int32_t)item->getSubType() << ", " << db->escapeBlob(attributes, attributesSize);

			if(!query_insert.addRow(stream))
				return false;
		}
	}

	return true;
}
开发者ID:gianflogao,项目名称:divinity-ots,代码行数:65,代码来源:ioplayer.cpp

示例11: serializeAttr

bool Item::serializeAttr(PropWriteStream& propWriteStream) const
{
	if (isStackable() || isFluidContainer() || isSplash()) {
		uint8_t _count = getSubType();
		propWriteStream.ADD_UCHAR(ATTR_COUNT);
		propWriteStream.ADD_UCHAR(_count);
	}

	if (hasCharges()) {
		uint16_t _count = getCharges();
		propWriteStream.ADD_UCHAR(ATTR_CHARGES);
		propWriteStream.ADD_USHORT(_count);
	}

	if (!isNotMoveable()) {
		uint16_t _actionId = getActionId();
		if (_actionId) {
			propWriteStream.ADD_UCHAR(ATTR_ACTION_ID);
			propWriteStream.ADD_USHORT(_actionId);
		}
	}

	const std::string& _text = getText();
	if (!_text.empty()) {
		propWriteStream.ADD_UCHAR(ATTR_TEXT);
		propWriteStream.ADD_STRING(_text);
	}

	const time_t _writtenDate = getDate();
	if (_writtenDate > 0) {
		propWriteStream.ADD_UCHAR(ATTR_WRITTENDATE);
		propWriteStream.ADD_ULONG(_writtenDate);
	}

	const std::string& _writer = getWriter();
	if (!_writer.empty()) {
		propWriteStream.ADD_UCHAR(ATTR_WRITTENBY);
		propWriteStream.ADD_STRING(_writer);
	}

	const std::string& _specialDesc = getSpecialDescription();
	if (!_specialDesc.empty()) {
		propWriteStream.ADD_UCHAR(ATTR_DESC);
		propWriteStream.ADD_STRING(_specialDesc);
	}

	if (hasAttribute(ATTR_ITEM_DURATION)) {
		uint32_t duration = getDuration();
		propWriteStream.ADD_UCHAR(ATTR_DURATION);
		propWriteStream.ADD_ULONG(duration);
	}

	ItemDecayState_t decayState = getDecaying();
	if (decayState == DECAYING_TRUE || decayState == DECAYING_PENDING) {
		propWriteStream.ADD_UCHAR(ATTR_DECAYING_STATE);
		propWriteStream.ADD_UCHAR(decayState);
	}

	return true;
}
开发者ID:HeberPcL,项目名称:forgottenserver,代码行数:60,代码来源:item.cpp

示例12: serialize

bool ConditionEffect::serialize(PropWriteStream& propWriteStream)
{
	propWriteStream.ADD_UCHAR(*CONDITIONATTRIBUTE_EFFECT);
	propWriteStream.ADD_VALUE((uint32_t)type);
	propWriteStream.ADD_VALUE(interval);

	switch(type){
		case ConditionEffect::PERIODIC_HEAL:
		case ConditionEffect::PERIODIC_DAMAGE:
		{
			ConditionEffect::ModPeriodicDamage& mod = getModEffect<ConditionEffect::ModPeriodicDamage>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE((uint32_t)mod.type.value());
			propWriteStream.ADD_VALUE(mod.min);
			propWriteStream.ADD_VALUE(mod.max);
			propWriteStream.ADD_VALUE(mod.value);
			propWriteStream.ADD_VALUE(mod.total);
			propWriteStream.ADD_VALUE(mod.percent);
			propWriteStream.ADD_VALUE(mod.first);
			propWriteStream.ADD_VALUE(mod.rounds);
			break;
		}
		case ConditionEffect::PERIODIC_MOD_STAMINA:
		{
			ConditionEffect::ModPeriodicStamina& mod = getModEffect<ConditionEffect::ModPeriodicStamina>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE(mod.value);
			break;
		}
		case ConditionEffect::REGEN_HEALTH:
		case ConditionEffect::REGEN_MANA:
		case ConditionEffect::REGEN_SOUL:
		{
			ConditionEffect::ModRegen& mod = getModEffect<ConditionEffect::ModRegen>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE((uint32_t)mod.type.value());
			propWriteStream.ADD_VALUE(mod.percent);
			propWriteStream.ADD_VALUE(mod.value);
			break;
		}
		case ConditionEffect::MOD_SPEED:
		{
			ConditionEffect::ModSpeed& mod = getModEffect<ConditionEffect::ModSpeed>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE(mod.percent);
			propWriteStream.ADD_VALUE(mod.value);
			propWriteStream.ADD_VALUE(mod.delta);
			break;
		}
		case ConditionEffect::MOD_STAT:
		{
			ConditionEffect::ModStat& mod = getModEffect<ConditionEffect::ModStat>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE((uint32_t)mod.type.value());
			propWriteStream.ADD_VALUE(mod.percent);
			propWriteStream.ADD_VALUE(mod.value);
			propWriteStream.ADD_VALUE(mod.delta);
			break;
		}
		case ConditionEffect::MOD_SKILL:
		{
			ConditionEffect::ModSkill& mod = getModEffect<ConditionEffect::ModSkill>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE((uint32_t)mod.type.value());
			propWriteStream.ADD_VALUE(mod.percent);
			propWriteStream.ADD_VALUE(mod.value);
			propWriteStream.ADD_VALUE(mod.delta);
			break;
		}
		case ConditionEffect::SHAPESHIFT:
		{
			ConditionEffect::ModShapeShift& mod = getModEffect<ConditionEffect::ModShapeShift>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE(mod.lookType);
			propWriteStream.ADD_VALUE(mod.lookTypeEx);
			propWriteStream.ADD_VALUE(mod.lookHead);
			propWriteStream.ADD_VALUE(mod.lookBody);
			propWriteStream.ADD_VALUE(mod.lookLegs);
			propWriteStream.ADD_VALUE(mod.lookFeet);
			propWriteStream.ADD_VALUE(mod.lookAddons);
			break;
		}
		case ConditionEffect::LIGHT:
		{
			ConditionEffect::ModLight& mod = getModEffect<ConditionEffect::ModLight>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_VALUE(mod.level);
			propWriteStream.ADD_VALUE(mod.color);
			break;
		}
		case ConditionEffect::DISPEL:
		{
			ConditionEffect::ModDispel& mod = getModEffect<ConditionEffect::ModDispel>();
			propWriteStream.ADD_USHORT(1); //revision
			propWriteStream.ADD_STRING(mod.name);
			break;
		}
		case ConditionEffect::SCRIPT:
		{
			ConditionEffect::ModScript& mod = getModEffect<ConditionEffect::ModScript>();
//.........这里部分代码省略.........
开发者ID:Ablankzin,项目名称:server,代码行数:101,代码来源:condition.cpp

示例13: savePlayer

bool IOLoginData::savePlayer(Player* player)
{
	if (player->getHealth() <= 0) {
		player->changeHealth(1);
	}

	Database* db = Database::getInstance();

	std::ostringstream query;
	query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();

	DBResult* result = db->storeQuery(query.str());

	if (!result) {
		return false;
	}

	if (result->getDataInt("save") == 0) {
		db->freeResult(result);
		query.str("");
		query << "UPDATE `players` SET `lastlogin` = " << player->lastLoginSaved << ", `lastip` = " << player->lastIP << " WHERE `id` = " << player->getGUID();
		return db->executeQuery(query.str());
	}

	db->freeResult(result);

	//serialize conditions
	PropWriteStream propWriteStream;

	for (ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it) {
		Condition* condition = *it;

		if (condition->isPersistent()) {
			if (!condition->serialize(propWriteStream)) {
				return false;
			}

			propWriteStream.ADD_UCHAR(CONDITIONATTR_END);
		}
	}

	uint32_t conditionsSize = 0;
	const char* conditions = propWriteStream.getStream(conditionsSize);

	//First, an UPDATE query to write the player itself
	query.str("");
	query << "UPDATE `players` SET ";
	query << "`level` = " << player->level << ", ";
	query << "`group_id` = " << player->groupId << ", ";
	query << "`vocation` = " << (int32_t)player->getVocationId() << ", ";
	query << "`health` = " << player->health << ", ";
	query << "`healthmax` = " << player->healthMax << ", ";
	query << "`experience` = " << player->experience << ", ";
	query << "`lookbody` = " << (int32_t)player->defaultOutfit.lookBody << ", ";
	query << "`lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet << ", ";
	query << "`lookhead` = " << (int32_t)player->defaultOutfit.lookHead << ", ";
	query << "`looklegs` = " << (int32_t)player->defaultOutfit.lookLegs << ", ";
	query << "`looktype` = " << (int32_t)player->defaultOutfit.lookType << ", ";
	query << "`lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons << ", ";
	query << "`maglevel` = " << player->magLevel << ", ";
	query << "`mana` = " << player->mana << ", ";
	query << "`manamax` = " << player->manaMax << ", ";
	query << "`manaspent` = " << player->manaSpent << ", ";
	query << "`soul` = " << player->soul << ", ";
	query << "`town_id` = " << player->town << ", ";

	const Position& loginPosition = player->getLoginPosition();
	query << "`posx` = " << loginPosition.x << ", ";
	query << "`posy` = " << loginPosition.y << ", ";
	query << "`posz` = " << loginPosition.z << ", ";

	query << "`cap` = " << player->getCapacity() << ", ";
	query << "`sex` = " << player->sex << ", ";

	if (player->lastLoginSaved != 0) {
		query << "`lastlogin` = " << player->lastLoginSaved << ", ";
	}

	if (player->lastIP != 0) {
		query << "`lastip` = " << player->lastIP << ", ";
	}

	query << "`conditions` = " << db->escapeBlob(conditions, conditionsSize) << ", ";

	if (g_game.getWorldType() != WORLD_TYPE_PVP_ENFORCED) {
		int32_t skullTime = 0;

		if (player->skullTicks > 0) {
			skullTime = time(NULL) + player->skullTicks / 1000;
		}

		query << "`skulltime` = " << skullTime << ", ";
		int32_t skull = 0;

		if (player->skull == SKULL_RED) {
			skull = SKULL_RED;
		} else if (player->skull == SKULL_BLACK) {
			skull = SKULL_BLACK;
		}

//.........这里部分代码省略.........
开发者ID:24312108k,项目名称:forgottenserver,代码行数:101,代码来源:iologindata.cpp

示例14: savePlayer

bool IOPlayer::savePlayer(Player* player, bool shallow)
{
	player->preSave();

	DatabaseDriver* db = DatabaseDriver::instance();
	DBQuery query;
	DBResult_ptr result;

	//check if the player has to be saved or not
	query << "SELECT `save` FROM `players` WHERE `id` = " << player->getGUID();
	if(!(result = db->storeQuery(query))){
		return false;
	}

	const uint32_t save = result->getDataInt("save");

	if(save == 0)
		return true;

	//serialize conditions
	PropWriteStream propWriteStream;
	for(ConditionList::const_iterator it = player->conditions.begin(); it != player->conditions.end(); ++it){
		if((*it)->isPersistent()){
			if(!(*it)->serialize(propWriteStream)){
				return false;
			}

			propWriteStream.ADD_UCHAR(*CONDITIONATTR_END);
		}
	}

	uint32_t conditionsSize;
	const char* conditions = propWriteStream.getStream(conditionsSize);

	//First, an UPDATE query to write the player itself
	query.reset();
	query << "UPDATE `players` SET `level` = " << player->level
	<< ", `vocation` = " << (int32_t)player->getVocationId()
	<< ", `health` = " << player->health
	<< ", `healthmax` = " << player->healthMax
	<< ", `direction` = " << player->getDirection().value()
	<< ", `experience` = " << player->experience
	<< ", `lookbody` = " << (int32_t)player->defaultOutfit.lookBody
	<< ", `lookfeet` = " << (int32_t)player->defaultOutfit.lookFeet
	<< ", `lookhead` = " << (int32_t)player->defaultOutfit.lookHead
	<< ", `looklegs` = " << (int32_t)player->defaultOutfit.lookLegs
	<< ", `looktype` = " << (int32_t)player->defaultOutfit.lookType
	<< ", `lookaddons` = " << (int32_t)player->defaultOutfit.lookAddons
	<< ", `maglevel` = " << player->magLevel
	<< ", `mana` = " << player->mana
	<< ", `manamax` = " << player->manaMax
	<< ", `manaspent` = " << player->manaSpent
	<< ", `soul` = " << player->soul
	<< ", `town_id` = " << player->town
	<< ", `posx` = " << player->getLoginPosition().x
	<< ", `posy` = " << player->getLoginPosition().y
	<< ", `posz` = " << player->getLoginPosition().z
	<< ", `cap` = " << player->getCapacity()
	<< ", `sex` = " << player->sex.value()
	<< ", `conditions` = " << db->escapeBlob(conditions, conditionsSize)
	<< ", `loss_experience` = " << (int32_t)player->getLossPercent(LOSS_EXPERIENCE)
	<< ", `loss_mana` = " << (int32_t)player->getLossPercent(LOSS_MANASPENT)
	<< ", `loss_skills` = " << (int32_t)player->getLossPercent(LOSS_SKILLTRIES)
	<< ", `loss_items` = " << (int32_t)player->getLossPercent(LOSS_ITEMS)
	<< ", `loss_containers` = " << (int32_t)player->getLossPercent(LOSS_CONTAINERS)
	<< ", `stamina` = " << player->stamina;

#ifdef __SKULLSYSTEM__
	query << ", `skull_type` = " << (player->getSkull() == SKULL_RED || player->getSkull() == SKULL_BLACK ? player->getSkull().value() : 0);
	query << ", `skull_time` = " << player->lastSkullTime;
#endif

	query << " WHERE `id` = " << player->getGUID();

	DBTransaction transaction(db);
	if(!transaction.begin())
		return false;

	if(!db->executeQuery(query)){
		return false;
	}

	//skills
	for(int32_t i = 0; i <= 6; i++){
		query.reset();
		query << "UPDATE `player_skills` SET `value` = " << player->skills[i][SKILL_LEVEL] << ", `count` = " << player->skills[i][SKILL_TRIES] << " WHERE `player_id` = " << player->getGUID() << " AND `skill_id` = " << i;

		if(!db->executeQuery(query)){
			return false;
		}
	}

	if(shallow)
		return transaction.commit();

	// deletes all player-related stuff

	/*
	query << "DELETE FROM `player_items` WHERE `player_id` = " << player->getGUID();

//.........这里部分代码省略.........
开发者ID:Pietia10,项目名称:server,代码行数:101,代码来源:ioplayer.cpp


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