{
if (_state != ACCEPTING_BETS) return;
int npcId = getTemplate().npcId;
SystemMessage sm;
String filename, search, replace;
NpcHtmlMessage html = new NpcHtmlMessage(getObjectId());
if (val < 10)
{
filename = getHtmlPath(npcId, 2);
html.setFile(filename);
for (int i = 0; i < 8; i++)
{
int n = i + 1;
search = "Mob" + n;
html.replace(search, MonsterRace.getInstance().getMonsters()[i].getTemplate().name);
}
search = "No1";
if (val == 0) html.replace(search, "");
else
{
html.replace(search, "" + val);
player.setRace(0, val);
}
}
else if (val < 20)
{
if (player.getRace(0) == 0) return;
filename = getHtmlPath(npcId, 3);
html.setFile(filename);
html.replace("0place", "" + player.getRace(0));
search = "Mob1";
replace = MonsterRace.getInstance().getMonsters()[player.getRace(0) - 1].getTemplate().name;
html.replace(search, replace);
search = "0adena";
if (val == 10) html.replace(search, "");
else
{
html.replace(search, "" + _cost[val - 11]);
player.setRace(1, val - 10);
}
}
else if (val == 20)
{
if (player.getRace(0) == 0 || player.getRace(1) == 0) return;
filename = getHtmlPath(npcId, 4);
html.setFile(filename);
html.replace("0place", "" + player.getRace(0));
search = "Mob1";
replace = MonsterRace.getInstance().getMonsters()[player.getRace(0) - 1].getTemplate().name;
html.replace(search, replace);
search = "0adena";
int price = _cost[player.getRace(1) - 1];
html.replace(search, "" + price);
search = "0tax";
int tax = 0;
html.replace(search, "" + tax);
search = "0total";
int total = price + tax;
html.replace(search, "" + total);
}
else
{
if (player.getRace(0) == 0 || player.getRace(1) == 0) return;
int ticket = player.getRace(0);
int priceId = player.getRace(1);
if (!player.reduceAdena("Race", _cost[priceId - 1], this, true)) return;
player.setRace(0, 0);
player.setRace(1, 0);
sm = new SystemMessage(SystemMessageId.ACQUIRED);
sm.addNumber(_raceNumber);
sm.addItemName(4443);
player.sendPacket(sm);
L2ItemInstance item = new L2ItemInstance(IdFactory.getInstance().getNextId(), 4443);
item.setCount(1);
item.setEnchantLevel(_raceNumber);
item.setCustomType1(ticket);
item.setCustomType2(_cost[priceId - 1] / 100);
player.getInventory().addItem("Race", item, player, this);
InventoryUpdate iu = new InventoryUpdate();
iu.addItem(item);
L2ItemInstance adenaupdate = player.getInventory().getItemByItemId(57);
iu.addModifiedItem(adenaupdate);
player.sendPacket(iu);
return;
}
html.replace("1race", String.valueOf(_raceNumber));
html.replace("%objectId%", String.valueOf(getObjectId()));
player.sendPacket(html);
player.sendPacket(new ActionFailed());
}