Jump to content
  • 0

[Request] Rebirth System


NumL0ck

Question

In frozen is rebirth system but you can't select skills

bypass -h custom_rebirth_requestrebirth

don't working. I need rebirth like in l2gold you can choose skills to rebirth.

I think you understand me, because my english is not very good, so please help me, THANKS!

Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

/*
* 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 com.l2jfrozen.gameserver.model.entity;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.HashMap;

import com.l2jfrozen.Config;
import com.l2jfrozen.gameserver.datatables.SkillTable;
import com.l2jfrozen.gameserver.datatables.sql.ItemTable;
import com.l2jfrozen.gameserver.datatables.xml.ExperienceData;
import com.l2jfrozen.gameserver.model.L2Skill;
import com.l2jfrozen.gameserver.model.actor.instance.L2ItemInstance;
import com.l2jfrozen.gameserver.model.actor.instance.L2PcInstance;
import com.l2jfrozen.gameserver.network.serverpackets.CreatureSay;
import com.l2jfrozen.gameserver.network.serverpackets.SocialAction;
import com.l2jfrozen.util.CloseUtil;
import com.l2jfrozen.util.database.L2DatabaseFactory;

/**
* <strong>This 'Custom Engine' was developed for L2J Forum Member 'sauron3256' on November 1st, 2008.</strong><br>
* <br>
* <strong>Quick Summary:</strong><br>
* This engine will grant the player special bonus skills at the cost of reseting him to level 1.<br>
* The -USER- can set up to X Rebirths, the skills received and their respective levels, and the item and price of each
* rebirth.<br>
* PLAYER's information is stored in an SQL Db under the table name: REBIRTH_MANAGER.<br>
* 
* @author <strong>Beetle and Shyla</strong>
*/
public class L2Rebirth
{

/** The current instance - static repeller. */
private static L2Rebirth _instance = null;

/** Basically, this will act as a cache so it doesnt have to read DB information on relog. */
private HashMap<Integer, Integer> _playersRebirthInfo = new HashMap<Integer, Integer>();

/**
 * Creates a new NON-STATIC instance.
 */
private L2Rebirth()
{
//Do Nothing ^_-
}

/**
 * Receives the non-static instance of the RebirthManager.
 *
 * @return single instance of L2Rebirth
 */
public static L2Rebirth getInstance()
{
	if(_instance == null)
	{
		_instance = new L2Rebirth();
	}
	return _instance;
}

/**
 * This is what it called from the Bypass Handler. (I think that's all thats needed here).
 *
 * @param player the player
 * @param command the command
 */
public void handleCommand(L2PcInstance player, String command)
{
	if(command.startsWith("custom_rebirth_requestrebirth"))
	{
		displayRebirthWindow(player);
	}
	else if(command.startsWith("custom_rebirth_confirmrequest"))
	{
		requestRebirth(player);
	}
}

/**
 * Display's an HTML window with the Rebirth Options.
 *
 * @param player the player
 */
public void displayRebirthWindow(L2PcInstance player)
{
	try
	{
		int currBirth = getRebirthLevel(player); //Returns the player's current birth level

		//Don't send html if player is already at max rebirth count.
		if(currBirth >= Config.REBIRTH_MAX)
		{
			player.sendMessage("You are currently at your maximum rebirth count!");
			return;
		}

		//Returns true if BASE CLASS is a mage.
		boolean isMage = player.getBaseTemplate().classId.isMage();
		//Returns the skill based on next Birth and if isMage.
		L2Skill skill = getRebirthSkill((currBirth + 1), isMage);

		String icon = "" + skill.getId();//Returns the skill's id.

		//Incase the skill is only 3 digits.
		if(icon.length() < 4)
		{
			icon = "0" + icon;
		}

		skill = null;
		icon = null;

	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

/**
 * Checks to see if the player is eligible for a Rebirth, if so it grants it and stores information.
 *
 * @param player the player
 */
public void requestRebirth(L2PcInstance player)
{
	//Check the player's level.
	if(player.getLevel() < Config.REBIRTH_MIN_LEVEL)
	{
		player.sendMessage("You do not meet the level requirement for a Rebirth!");
		return;
	}

	else if(player.isSubClassActive())
	{
		player.sendMessage("Please switch to your Main Class before attempting a Rebirth.");
		return;
	}

	int currBirth = getRebirthLevel(player);
	int itemNeeded = 0;
	int itemAmount = 0;

	if(currBirth >= Config.REBIRTH_MAX)
	{
		player.sendMessage("You are currently at your maximum rebirth count!");
		return;
	}

	//Get the requirements
	int loopBirth = 0;
	for(String readItems : Config.REBIRTH_ITEM_PRICE) {
		String[] currItem = readItems.split(",");
		if (loopBirth == currBirth) {
			itemNeeded = Integer.parseInt(currItem[0]);
			itemAmount = Integer.parseInt(currItem[1]);
			break;
		}
		loopBirth++;
	}

	//Their is an item required
	if(itemNeeded != 0)
	{
		//Checks to see if player has required items, and takes them if so.
		if(!playerIsEligible(player, itemNeeded, itemAmount))
			return;
	}

	//Check and see if its the player's first Rebirth calling.
	boolean firstBirth = currBirth == 0;
	//Player meets requirements and starts Rebirth Process.
	grantRebirth(player, (currBirth + 1), firstBirth);
}

/**
 * Physically rewards player and resets status to nothing.
 *
 * @param player the player
 * @param newBirthCount the new birth count
 * @param firstBirth the first birth
 */
public void grantRebirth(L2PcInstance player, int newBirthCount, boolean firstBirth)
{
	try
	{
		double actual_hp = player.getCurrentHp();
		double actual_cp = player.getCurrentCp();

		int max_level = ExperienceData.getInstance().getMaxLevel();

		if(player.isSubClassActive())
		{
			max_level = Config.MAX_SUBCLASS_LEVEL;
		}

		//Protections
		Integer returnToLevel = Config.REBIRTH_RETURN_TO_LEVEL;
		if (returnToLevel < 1) 
			returnToLevel = 1; 
		if (returnToLevel > max_level) 
			returnToLevel = max_level;

		//Resets character to first class.
		player.setClassId(player.getBaseClass());

		player.broadcastUserInfo();

		final byte lvl = Byte.parseByte(returnToLevel+"");

		final long pXp = player.getStat().getExp();
		final long tXp = ExperienceData.getInstance().getExpForLevel(lvl);

		if(pXp > tXp)
		{
			player.getStat().removeExpAndSp(pXp - tXp, 0);
		}
		else if(pXp < tXp)
		{
			player.getStat().addExpAndSp(tXp - pXp, 0);
		}

		//Remove the player's current skills.
		for(L2Skill skill : player.getAllSkills())
		{
			player.removeSkill(skill);
		}
		//Give players their eligible skills.
		player.giveAvailableSkills();

		//restore Hp-Mp-Cp
		player.setCurrentCpDirect(actual_cp);
		player.setCurrentMpDirect(player.getMaxMp());
		player.setCurrentHpDirect(actual_hp);
		player.broadcastStatusUpdate();

		//Updates the player's information in the Character Database.
		player.store();

		if(firstBirth)
		{
			storePlayerBirth(player);
		}
		else
		{
			updatePlayerBirth(player, newBirthCount);
		}

		//Give the player his new Skills.
		grantRebirthSkills(player);


		//Displays a congratulation message to the player.
		displayCongrats(player);
		returnToLevel = null;
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
}

/**
 * Special effects when the player levels.
 *
 * @param player the player
 */
public void displayCongrats(L2PcInstance player)
{
	//Victory Social Action.
	player.setTarget(player);
	player.broadcastPacket(new SocialAction(player.getObjectId(), 3));
	player.sendMessage("Congratulations " + player.getName() + ". You have been REBORN!");
	player.sendMessage("You got the passive skill!");
}

/**
 * Check and verify the player DOES have the item required for a request. Also, remove the item if he has.
 *
 * @param player the player
 * @param itemId the item id
 * @param itemAmount the item amount
 * @return true, if successful
 */
public boolean playerIsEligible(L2PcInstance player, int itemId, int itemAmount)
{
	String itemName = ItemTable.getInstance().getTemplate(itemId).getName();
	L2ItemInstance itemNeeded = player.getInventory().getItemByItemId(itemId);

	if(itemNeeded == null || itemNeeded.getCount() < itemAmount)
	{
		player.sendMessage("You need atleast " + itemAmount + "  [ " + itemName + " ] to request a Rebirth!");
		return false;
	}

	//Player has the required items, so we're going to take them!
	player.getInventory().destroyItemByItemId("Rebirth Engine", itemId, itemAmount, player, null);
	player.sendMessage("Removed " + itemAmount + " " + itemName + " from your inventory!");

	itemName = null;
	itemNeeded = null;

	return true;
}

/**
 * Gives the available Bonus Skills to the player.
 *
 * @param player the player
 */
public void grantRebirthSkills(L2PcInstance player)
{
	//returns the current Rebirth Level
	int rebirthLevel = getRebirthLevel(player);
	//Returns true if BASE CLASS is a mage.
	boolean isMage = player.getBaseTemplate().classId.isMage();

	//Simply return since no bonus skills are granted.
	if(rebirthLevel == 0)
		return;

	  //Load the bonus skills unto the player.
	  CreatureSay rebirthText = null;
	  for(int i = 0; i < rebirthLevel; i++)
	  {
	   L2Skill bonusSkill = getRebirthSkill((i + 1), isMage);
	   player.addSkill(bonusSkill, false);
	  }
}
/**
 * Return the player's current Rebirth Level.
 *
 * @param player the player
 * @return the rebirth level
 */
public int getRebirthLevel(L2PcInstance player)
{
	int playerId = player.getObjectId();

	if(_playersRebirthInfo.get(playerId) == null)
	{
		loadRebirthInfo(player);
	}

	return _playersRebirthInfo.get(playerId);
}

/**
 * Return the L2Skill the player is going to be rewarded.
 *
 * @param rebirthLevel the rebirth level
 * @param mage the mage
 * @return the rebirth skill
 */
public L2Skill getRebirthSkill(int rebirthLevel, boolean mage)
{
	L2Skill skill = null;

	//Player is a Mage.
	if(mage)
	{	
		int loopBirth = 0;
		for(String readSkill : Config.REBIRTH_MAGE_SKILL) {
			String[] currSkill = readSkill.split(",");
			if (loopBirth == (rebirthLevel-1)) {
				skill = SkillTable.getInstance().getInfo(Integer.parseInt(currSkill[0]), Integer.parseInt(currSkill[1]));
				break;
			}
			loopBirth++;
		}
	}
	//Player is a Fighter.
	else
	{
		int loopBirth = 0;
		for(String readSkill : Config.REBIRTH_FIGHTER_SKILL) {
			String[] currSkill = readSkill.split(",");
			if (loopBirth == (rebirthLevel-1)) {
				skill = SkillTable.getInstance().getInfo(Integer.parseInt(currSkill[0]), Integer.parseInt(currSkill[1]));
				break;
			}
			loopBirth++;
		}
	}
	return skill;
}

/**
 * Database caller to retrieve player's current Rebirth Level.
 *
 * @param player the player
 */
public void loadRebirthInfo(L2PcInstance player)
{
	int playerId = player.getObjectId();
	int rebirthCount = 0;

	Connection con = null;
	try
	{
		ResultSet rset;
		con = L2DatabaseFactory.getInstance().getConnection(false);
		PreparedStatement statement = con.prepareStatement("SELECT * FROM `rebirth_manager` WHERE playerId = ?");
		statement.setInt(1, playerId);
		rset = statement.executeQuery();

		while(rset.next())
		{
			rebirthCount = rset.getInt("rebirthCount");
		}

		rset.close();
		statement.close();
		statement = null;
		rset = null;

	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	finally
	{
		CloseUtil.close(con);
		con = null;
	}
	_playersRebirthInfo.put(playerId, rebirthCount);
}

/**
 * Stores the player's information in the DB.
 *
 * @param player the player
 */
public void storePlayerBirth(L2PcInstance player)
{
	Connection con = null;
	try
	{
		con = L2DatabaseFactory.getInstance().getConnection(false);
		PreparedStatement statement = con.prepareStatement("INSERT INTO `rebirth_manager` (playerId,rebirthCount) VALUES (?,1)");
		statement.setInt(1, player.getObjectId());
		statement.execute();
		statement = null;

		_playersRebirthInfo.put(player.getObjectId(), 1);

	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	finally
	{
		CloseUtil.close(con);
		con = null;
	}
}

/**
 * Updates the player's information in the DB.
 *
 * @param player the player
 * @param newRebirthCount the new rebirth count
 */
public void updatePlayerBirth(L2PcInstance player, int newRebirthCount)
{
	Connection con = null;
	try
	{
		int playerId = player.getObjectId();

		con = L2DatabaseFactory.getInstance().getConnection(false);
		PreparedStatement statement = con.prepareStatement("UPDATE `rebirth_manager` SET rebirthCount = ? WHERE playerId = ?");
		statement.setInt(1, newRebirthCount);
		statement.setInt(2, playerId);
		statement.execute();
		statement = null;

		_playersRebirthInfo.put(playerId, newRebirthCount);
	}
	catch(Exception e)
	{
		e.printStackTrace();
	}
	finally
	{
		CloseUtil.close(con);
		con = null;
	}
}
}

 

as i understand in npc need put this custom_rebirth_requestrebirth to popout window with skill choose, but this don't working, working only custom_rebirth_confirmrequest

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.


  • Posts

    • Hello,   I am looking for someone who understands about websites, knows coding etc.   I am dealing with situation where after i bought web hosting my website is loading really slowly or not loading at all at some points. I have tried dealing with the company who provides the web hosting but they could not find issue on their end so i am asking for help, someone who knows their thing about this.   Drop your discord details i will contact you.   Thank you
    • Good afternoon I am selling a list of forums, which contains more than 100 lines of active and current RU forums.   - topics: dark, crypto, SMM, programming, services, cheats, etc.; - sorting from more popular to less popular (by traffic, by the number of new posts per day);   Are you looking for where to advertise your services? This base will definitely suit you! In addition, on the forums you can find a bunch of useful information, software, as well as advertisements about sales and services from other users.   Payment: 12 USTD   After payment you receive a text document with a list of forums (PS. all information is provided for informational purposes only); TELEGRAM - https://t.me/milozare
    • I strongly concur with some opinions shared. As I've previously mentioned on different posts, it's shocking to see how seasonal servers gather this much population. However, being back in the game some months I did start understanding how the current community of L2 plays and thinks.   It's a huge problem, but in my opinion the guilt is shared between server owners and community. To keep a long term project running (more than a year on) you need to have the equivalent community that will support the project, which unfortunately is not that big. The current player community of L2 hops on new servers with such a haste to get full and "dominate" which does indeed give a lot of activity for some weeks but after that it's just downfall, population gets reduced drastically day by day. The reason is, while the community is busy "grinding" to win on their current server, a "new" server is being advertised which most likely is from the same owner. As I've mentioned, the guilt is shared since the server-owners focus on bringing up "new" servers for the cash grab but also since the community doesn't have the patience to support a long-term project. Besides, let's not forget about clans/CPs being invited directly to the server with some benefits. I'll give an example. An admin opens a server, invites 3 groups (either CPs or clans) by promising them some small benefits. Those three groups will invite more players and so on. It's like an investment, they spent 5$ to earn 20$. Therefore, most admins willing to play "fair" do not succeed, except for a few. Most of us "old-timers" play for nostalgia trips and are fine with low populated servers but lets take a step back and think about the owners that really want to provide a good server, no income will slowly dry out the server and eventually die.   Don't get me wrong, there are some great servers out there, but not everything is for everyone. I'll finish by quoting someone I saw few days ago on YouTube, he said something along the lines that we shouldn't expect fair play while we play an "illegal" version of the game.
    • You have to create the "voiced" handler in the core too, or at the very least make sure that the delimiter is underscore and not an empty space. Alternatively, you can try changing all references of the strings below to start with "voiced_", or remove the "voiced_" portion from the button bypass.   private static final String[] VOICED_COMMANDS = { "siege", "siege_gludio", "siege_dion", "siege_giran", "siege_oren", "siege_aden", "siege_innadril", "siege_goddard", "siege_rune", "siege_schuttgart" };
    • Hi maxcheaters, I recently added some code to my l2jacis revision and everything works fine with the .siege commands but when I click on the html options to open the registry I don't succeed!   registerHandler(new Castles());   package net.sf.l2j.gameserver.handler.voicedcommandhandlers;   import net.sf.l2j.Config; import net.sf.l2j.gameserver.handler.IVoicedCommandHandler; import net.sf.l2j.gameserver.data.manager.CastleManager; import net.sf.l2j.gameserver.model.actor.Player; import net.sf.l2j.gameserver.model.entity.Castle; import net.sf.l2j.gameserver.network.SystemMessageId; import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.network.serverpackets.SiegeInfo;   public class Castles implements IVoicedCommandHandler { private static final String[] VOICED_COMMANDS = { "siege", "siege_gludio", "siege_dion", "siege_giran", "siege_oren", "siege_aden", "siege_innadril", "siege_goddard", "siege_rune", "siege_schuttgart" };   @Override public boolean useVoicedCommand(String command, Player player, String target) { if (command.equals("siege") && Config.ENABLE_MENU) showHtm(player); else if (command.startsWith("siege_")) { if (player.getClan() != null && !player.isClanLeader()) { player.sendPacket(SystemMessageId.YOU_ARE_NOT_AUTHORIZED_TO_DO_THAT); return false; }   int castleId = 0; if (command.startsWith("siege_gludio") && Config.SIEGE_GLUDIO) castleId = 1; else if (command.startsWith("siege_dion") && Config.SIEGE_DION) castleId = 2; else if (command.startsWith("siege_giran") && Config.SIEGE_GIRAN) castleId = 3; else if (command.startsWith("siege_oren") && Config.SIEGE_OREN) castleId = 4; else if (command.startsWith("siege_aden") && Config.SIEGE_ADEN) castleId = 5; else if (command.startsWith("siege_innadril") && Config.SIEGE_INNADRIL) castleId = 6; else if (command.startsWith("siege_goddard") && Config.SIEGE_GODDARD) castleId = 7; else if (command.startsWith("siege_rune") && Config.SIEGE_RUNE) castleId = 8; else if (command.startsWith("siege_schuttgart") && Config.SIEGE_SCHUT) castleId = 9; else player.sendMessage("This Castle has been disabled");   Castle castle = CastleManager.getInstance().getCastleById(castleId); if ((castle != null) && (castleId != 0)) player.sendPacket(new SiegeInfo(castle)); } return true; }   private static void showHtm(Player player) { NpcHtmlMessage htm = new NpcHtmlMessage(0); htm.setFile(player.isLang() + "mods/menu/CastleManager.htm"); player.sendPacket(htm); }   @Override public String[] getVoicedCommandList() { return VOICED_COMMANDS; } }     <button value="Giran" action="bypass voiced_siege_giran" width=75 height=22 back="L2UI_ch3.Btn1_normalOn" fore="L2UI_ch3.Btn1_normal">
  • Topics

×
×
  • Create New...