package handler.bbs.custom.privateOffice.services.player;
import handler.bbs.abstracts.AbstractCommunityBoard;
import handler.bbs.custom.privateOffice.engine.annotations.Init;
import handler.bbs.custom.privateOffice.engine.enums.Services;
import handler.bbs.custom.privateOffice.engine.interfaces.IService;
import org.mmocore.commons.converter.Converter;
import org.mmocore.gameserver.configuration.config.FormulasConfig;
import org.mmocore.gameserver.configuration.config.community.CBasicConfig;
import org.mmocore.gameserver.network.lineage.components.CustomMessage;
import org.mmocore.gameserver.object.Player;
import org.mmocore.gameserver.utils.Log;
import org.mmocore.gameserver.utils.Util;
/**
* @author Mangol
* @since 18.02.2016
*/
@Init(service = Services.buy_fame)
public class BuyFameService extends AbstractCommunityBoard implements IService<Services>
{
@Override
public void content(final Services service, final Player player, final String bypass, final Object... params)
{
String htm = getCache().getHtml(CBasicConfig.BBS_PATH + "/cabinet/player/buy_fame.htm", player);
htm = htm.replace("<?correct_fame?>", String.valueOf(player.getFame()));
htm = htm.replace("<?price?>", String.valueOf(service.getItemCount()));
htm = htm.replace("<?item_name?>", getItemName(player.getLanguage(), service.getItemId()));
separateAndSend(htm, player);
}
@Override
public void request(final Services service, final Player player, final String bypass, final Object... params)
{
if(player == null)
{
return;
}
final String[] str = bypass.split(":");
if(str.length < 5)
{
player.sendPacket(new CustomMessage("bbs.service.buyFame.error"));
useSaveCommand(player);
}
if(!player.isInPeaceZone())
{
player.sendPacket(new CustomMessage("bbs.service.buyFame.noIsInPeaceZone"));
useSaveCommand(player);
return;
}
if(player.getFame() >= FormulasConfig.LIM_FAME)
{
player.sendPacket(new CustomMessage("bbs.service.buyFame.maxFame"));
useSaveCommand(player);
return;
}
final String strFame = str[4].trim();
final int fame = Converter.convert(Integer.class, strFame);
final int fameFinish = Math.min(FormulasConfig.LIM_FAME, player.getFame() + fame);
final int currectCount = (player.getFame() + fame) - fameFinish;
final long price = service.getItemCount() * (fame - currectCount);
if(!getCheckAndPick(player, service.getItemId(), price, true))
{
useSaveCommand(player);
return;
}
reply(service, player, fameFinish);
}
@Override
public void reply(final Services service, final Player player, final Object... params)
{
final int fame = (int) params[0];
player.setFame(fame, "");
useSaveCommand(player);
player.sendPacket(new CustomMessage("bbs.service.successfully"));
}
}