Example #1
0
void BedItem::regeneratePlayer(Player* player) const
{
	int32_t sleptTime = int32_t(time(NULL) - sleepStart);

	Condition* condition = player->getCondition(CONDITION_REGENERATION, CONDITIONID_DEFAULT);

	if (condition) {
		int32_t regen = 0;

		if (condition->getTicks() != -1) {
			regen = std::min<int32_t>((condition->getTicks() / 1000), sleptTime) / 30;
			int32_t newRegenTicks = condition->getTicks() - (regen * 30000);

			if (newRegenTicks <= 0) {
				player->removeCondition(condition);
				condition = NULL;
			} else {
				condition->setTicks(newRegenTicks);
			}
		} else {
			regen = sleptTime / 30;
		}

		player->changeHealth(regen, false);
		player->changeMana(regen);
	}

	int32_t soulRegen = sleptTime / (60 * 15);
	player->changeSoul(soulRegen);
}
Example #2
0
void ProtocolGameBase::AddPlayerStats(NetworkMessage& msg)
{
	msg.addByte(0xA0);

	msg.add<uint16_t>(std::min<int32_t>(player->getHealth(), std::numeric_limits<uint16_t>::max()));
	msg.add<uint16_t>(std::min<int32_t>(player->getPlayerInfo(PLAYERINFO_MAXHEALTH), std::numeric_limits<uint16_t>::max()));

	msg.add<uint32_t>(player->getFreeCapacity());
	msg.add<uint32_t>(player->getCapacity());

	msg.add<uint64_t>(player->getExperience());

	msg.add<uint16_t>(player->getLevel());
	msg.addByte(player->getPlayerInfo(PLAYERINFO_LEVELPERCENT));
	msg.addDouble(0, 3); // experience bonus

	msg.add<uint16_t>(std::min<int32_t>(player->getMana(), std::numeric_limits<uint16_t>::max()));
	msg.add<uint16_t>(std::min<int32_t>(player->getPlayerInfo(PLAYERINFO_MAXMANA), std::numeric_limits<uint16_t>::max()));

	msg.addByte(std::min<uint32_t>(player->getMagicLevel(), std::numeric_limits<uint8_t>::max()));
	msg.addByte(std::min<uint32_t>(player->getBaseMagicLevel(), std::numeric_limits<uint8_t>::max()));
	msg.addByte(player->getPlayerInfo(PLAYERINFO_MAGICLEVELPERCENT));

	msg.addByte(player->getSoul());

	msg.add<uint16_t>(player->getStaminaMinutes());

	msg.add<uint16_t>(player->getBaseSpeed() / 2);

	Condition* condition = player->getCondition(CONDITION_REGENERATION);
	msg.add<uint16_t>(condition ? condition->getTicks() / 1000 : 0x00);

	msg.add<uint16_t>(player->getOfflineTrainingTime() / 60 / 1000);
}
Example #3
0
bool Chat::talkToChannel(Player* player, SpeakClasses type, const std::string& text, uint16_t channelId)
{
	ChatChannel* channel = getChannel(player, channelId);

	if (!channel || !player) {
		return false;
	}

	if (player->getAccountType() < ACCOUNT_TYPE_GAMEMASTER) {
		if (player->getLevel() < 2 && channelId < CHANNEL_PARTY && channelId != CHANNEL_ADVERTISINGROOKGAARD) {
			player->sendCancel("You may not speak into channels as long as you are on level 1.");
			return false;
		} else if ((channelId == CHANNEL_ADVERTISING || channelId == CHANNEL_ADVERTISINGROOKGAARD) && player->hasCondition(CONDITION_CHANNELMUTEDTICKS, channelId)) {
			player->sendCancel("You may only place one offer in two minutes.");
			return false;
		} else if (channelId == CHANNEL_HELP && player->hasCondition(CONDITION_CHANNELMUTEDTICKS, CHANNEL_HELP)) {
			player->sendCancel("You are muted from the Help channel for using it inappropriately.");
			return false;
		}
	}

	if (channelId == CHANNEL_HELP && player->getAccountType() >= ACCOUNT_TYPE_TUTOR && text.length() > 6) {
		if (text.length() > 6 && text.substr(0, 6) == "!mute ") {
			std::string param = text.substr(6);
			trimString(param);
			Player* paramPlayer = g_game.getPlayerByName(param);

			if (paramPlayer && paramPlayer->getAccountType() < player->getAccountType()) {
				if (!paramPlayer->hasCondition(CONDITION_CHANNELMUTEDTICKS, CHANNEL_HELP)) {
					Condition* condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_CHANNELMUTEDTICKS, 3600000, 0, false, CHANNEL_HELP);
					paramPlayer->addCondition(condition);

					std::ostringstream ss;
					ss << paramPlayer->getName() << " has been muted by " << player->getName() << " for using Help Channel inappropriately.";
					channel->sendToAll(ss.str(), SPEAK_CHANNEL_R1);
				} else {
					player->sendCancel("That player is already muted.");
				}
			} else {
				player->sendCancel("A player with that name is not online.");
			}

			return true;
		} else if (text.length() > 8 && text.substr(0, 8) == "!unmute ") {
			std::string param = text.substr(8);
			trimString(param);
			Player* paramPlayer = g_game.getPlayerByName(param);

			if (paramPlayer && paramPlayer->getAccountType() < player->getAccountType()) {
				Condition* condition = paramPlayer->getCondition(CONDITION_CHANNELMUTEDTICKS, CONDITIONID_DEFAULT, CHANNEL_HELP);

				if (condition && condition->getTicks() > 0) {
					paramPlayer->removeCondition(condition);

					std::ostringstream ss;
					ss << paramPlayer->getName() << " has been unmuted by " << player->getName() << ".";
					channel->sendToAll(ss.str(), SPEAK_CHANNEL_R1);
				} else {
					player->sendCancel("That player is not muted.");
				}
			} else {
				player->sendCancel("A player with that name is not online.");
			}

			return true;
		}
	}

	if (channelId == CHANNEL_GUILD && player->getGuildLevel() > 1) {
		type = SPEAK_CHANNEL_O;
	}

	return channel->talk(player, type, text);
}