gt: 				htmltext = htmltext.replace("%level%", String.valueOf(level));
context: /*
   * This file is part of the L2J Global project.
   * 
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   * 
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   * General Public License for more details.
   * 
   * You should have received a copy of the GNU General Public License
   * along with this program. If not, see <http://www.gnu.org/licenses/>.
   */
  package ai.areas.TalkingIsland.Trandon;
  
  import java.util.Set;
  
  import com.l2jglobal.Config;
  import com.l2jglobal.gameserver.data.xml.impl.SkillData;
  import com.l2jglobal.gameserver.enums.Race;
  import com.l2jglobal.gameserver.model.actor.L2Npc;
  import com.l2jglobal.gameserver.model.actor.instance.L2PcInstance;
  import com.l2jglobal.gameserver.model.events.EventType;
  import com.l2jglobal.gameserver.model.events.ListenerRegisterType;
  import com.l2jglobal.gameserver.model.events.annotations.RegisterEvent;
  import com.l2jglobal.gameserver.model.events.annotations.RegisterType;
  import com.l2jglobal.gameserver.model.events.impl.character.player.OnPlayerLogin;
  import com.l2jglobal.gameserver.model.events.impl.character.player.OnPlayerSubChange;
  import com.l2jglobal.gameserver.model.itemcontainer.Inventory;
  import com.l2jglobal.gameserver.model.skills.Skill;
  import com.l2jglobal.gameserver.model.variables.PlayerVariables;
  import com.l2jglobal.gameserver.network.clientpackets.RequestAcquireSkill;
  
  import ai.AbstractNpcAI;
  
  /**
   * Trandon AI.
   * @author malyelfik
   */
  public final class Trandon extends AbstractNpcAI
  {
  	// NPC
  	private static final int NPC_ID = 33490;
  	// Items
  	private static final int SUB_CERTIFICATE = 10280;
  	private static final int DUAL_CERTIFICATE = 36078;
  	// Misc @formatter:off
  	private static final int[] SUB_SKILL_LEVELS = {65, 70, 75, 80};
  	private static final int[] DUAL_SKILL_LEVELS = {85, 90, 95, 99};
  	// @formatter:on
  	
  	private Trandon()
  	{
  		addStartNpc(NPC_ID);
  		addFirstTalkId(NPC_ID);
  		addTalkId(NPC_ID);
  	}
  	
  	@Override
  	public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
  	{
  		final String[] substrings = event.split(" ");
  		if (substrings.length < 1)
  		{
  			return null;
  		}
  		String htmltext = substrings[0];
  		switch (htmltext)
  		{
  			case "33490.html":
  			case "33490-01.html":
  			case "33490-02.html":
  			case "33490-03.html":
  			case "33490-04.html":
  			case "33490-05.html":
  			case "33490-06.html":
  			case "33490-07.html":
  			case "33490-08.html":
  			case "33490-09.html":
  			case "33490-10.html":
  			case "33490-11.html":
  			case "33490-19.html":
  				break;
  			case "33490-12.html":
  			{
  				if (player.getRace().equals(Race.ERTHEIA) || hasAllSubCertifications(player))
  				{
  					htmltext = "33490-15.html";
  				}
  				else if (!player.isSubClassActive())
  				{
  					htmltext = "33490-13.html";
  				}
  				else if (!player.isInventoryUnder90(false) || (player.getWeightPenalty() >= 2))
  				{
  					htmltext = "33490-14.html";
  				}
  				break;
  			}
  			case "subCertify":
  			{
  				if ((substrings.length < 2) || !player.isSubClassActive())
  				{
  					return null;
  				}
  				
  				final int index = Integer.parseInt(substrings[1]);
  				if ((index < 0) || (index > 3))
  				{
  					return null;
  				}
  				
  				final int level = SUB_SKILL_LEVELS[index];
  				if (player.getLevel() < level)
  				{
  					htmltext = getHtm(player.getHtmlPrefix(), "33490-16.html").replace("%level%", String.valueOf(level));
  				}
  				else if (player.getVariables().hasVariable(getSubSkillVariableName(player, level)))
  				{
  					htmltext = "33490-17.html";
  				}
  				else
  				{
  					htmltext = getHtm(player.getHtmlPrefix(), "33490-18.html");
  					htmltext = htmltext.replace("%level%", String.valueOf(level));
  					htmltext = htmltext.replace("%index%", String.valueOf(index));
  				}
  				break;
  			}
  			case "giveSubCertify":
  			{
  				if ((substrings.length < 2) || !player.isSubClassActive() || player.getRace().equals(Race.ERTHEIA))
  				{
  					return null;
  				}
  				
  				final int index = Integer.parseInt(substrings[1]);
  				if ((index < 0) || (index > 3))
  				{
  					return null;
  				}
  				
  				final int level = SUB_SKILL_LEVELS[index];
  				final PlayerVariables vars = player.getVariables();
  				if ((player.getLevel() < level) || vars.hasVariable(getSubSkillVariableName(player, level)))
  				{
  					htmltext = null;
  				}
  				else
  				{
  					vars.set(getSubSkillVariableName(player, level), true);
  					giveItems(player, SUB_CERTIFICATE, 1);
  					htmltext = "33490-20.html";
  				}
  				break;
  			}
  			case "learnSubSkill":
  			{
  				if (player.getRace().equals(Race.ERTHEIA))
  				{
  					htmltext = "33490-15.html";
  				}
  				else if (player.isSubClassActive() || !hasQuestItems(player, SUB_CERTIFICATE))
  				{
  					htmltext = "33490-21.html";
  				}
  				else
  				{
  					RequestAcquireSkill.showSubSkillList(player);
  					htmltext = null;
  				}
  				break;
  			}
  			case "deleteSubSkill":
  			{
  				if (player.getRace().equals(Race.ERTHEIA))
  				{
  					htmltext = "33490-15.html";
  				}
  				else if (player.isSubClassActive())
  				{
  					htmltext = "33490-21.html";
  				}
  				else if (player.getAdena() < Config.FEE_DELETE_SUBCLASS_SKILLS)
  				{
  					htmltext = "33490-22.html";
  				}
  				else if (!hasSubCertificate(player))
  				{
  					htmltext = "33490-23.html";
  				}
  				else
  				{
  					htmltext = null; // TODO: Unknown html
  					takeItems(player, SUB_CERTIFICATE, -1);
  					takeItems(player, Inventory.ADENA_ID, Config.FEE_DELETE_SUBCLASS_SKILLS);
  					
  					final PlayerVariables vars = player.getVariables();
  					for (int i = 1; i <= 3; i++)
  					{
  						for (int lv : SUB_SKILL_LEVELS)
  						{
  							vars.remove("SubSkill-" + i + "-" + lv);
  						}
  					}
  					takeSkills(player, "SubSkillList");
  				}
  				break;
  			}
  			case "33490-26.html":
  			{
  				// TODO: What happens when you have all dual certificates?
  				if (!player.isDualClassActive())
  				{
  					htmltext = "33490-24.html";
  				}
  				else if (!player.isInventoryUnder90(false) || (player.getWeightPenalty() >= 2))
  				{
  					htmltext = "33490-25.html";
  				}
  				break;
  			}
  			case "dualCertify":
  			{
  				if ((substrings.length < 2) || !player.isDualClassActive())
  				{
  					return null;
  				}
  				
  				final int index = Integer.parseInt(substrings[1]);
  				if ((index < 0) || (index > 3))
  				{
  					return null;
  				}
  				
  				final int level = DUAL_SKILL_LEVELS[index];
  				final PlayerVariables vars = player.getVariables();
  				if (vars.hasVariable(getDualSkillVariableName(level)))
  				{
  					htmltext = getHtm(player.getHtmlPrefix(), "33490-27.html");
  				}
  				else if ((player.getLevel() < level) || (player.getStat().getBaseLevel() < level))
  				{
  					htmltext = getHtm(player.getHtmlPrefix(), "33490-28.html");
  				}
  				else
  				{
  					vars.set(getDualSkillVariableName(level), true);
  					giveItems(player, DUAL_CERTIFICATE, 1);
  					htmltext = getHtm(player.getHtmlPrefix(), "33490-29.html");
  				}
  