Autor Tema: Aporte ClassMaster (De mientras)  (Leído 152 veces)

Mordor

  • Jr. Member
  • **
  • Mensajes: 83
  • Karma: +0/-0
    • Ver Perfil
Aporte ClassMaster (De mientras)
« en: Mayo 07, 2018, 08:22:14 pm »
Aca les dejo el class master que meti en scripts de mientras hasta que fiss lo terminde de incorporar a la parte de mods:

Ruta: net.sf.l2j.gameserver.script.ai.npc

Código
/*
 * Copyright (C) 2014-2020 L2jAdjmins
 *
 * This file is part of L2jAdmins.
 *
 * L2jAdmins 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.
 *
 * L2jAdmins 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 net.sf.l2j.gameserver.scripts.ai.npc;

import java.util.ArrayList;
import java.util.List;

import net.sf.l2j.gameserver.data.ItemData;
import net.sf.l2j.gameserver.scripts.Script;
import net.sf.l2j.gameserver.model.actor.L2Npc;
import net.sf.l2j.gameserver.model.actor.base.ClassId;
import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
import net.sf.l2j.gameserver.model.holder.LocationHolder;
import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
import net.sf.l2j.gameserver.network.serverpackets.PlaySound.PlaySoundType;
import net.sf.l2j.gameserver.network.serverpackets.SystemMessage;
import net.sf.l2j.gameserver.network.serverpackets.TutorialShowQuestionMark;

/**
 * @author fissban
 */
public class ClassMaster extends Script
{
private static final int NPC = 93002;

// format:
// PriceItemId
// PriceItemCount
// ReardItemId
// RewardItemCount

// Usar el 0 para no definir ningun valor
private static final List<ClassMasterList> ITEM_LIST = new ArrayList<>();
{
// Primer cambio de clase ----------------------
ClassMasterList job1 = new ClassMasterList();
job1.setPriceItemId(57);
job1.setPriceItemCount(100000);
job1.setRewardItemId(0);
job1.setRewardItemCount(0);
ITEM_LIST.add(job1);
// Segundo cambio de clase ----------------------
ClassMasterList job2 = new ClassMasterList();
job2.setPriceItemId(57);
job2.setPriceItemCount(300000);
job2.setRewardItemId(0);
job2.setRewardItemCount(0);
ITEM_LIST.add(job2);
// Tercer cambio de clase -----------------------
ClassMasterList job3 = new ClassMasterList();
job3.setPriceItemId(7999);
job3.setPriceItemCount(1);
job3.setRewardItemId(0);
job3.setRewardItemCount(0);
ITEM_LIST.add(job3);
}
// Spawns
private static final List<LocationHolder> SPAWNS = new ArrayList<>();
{
SPAWNS.add(new LocationHolder(11283, 15951, -4584));// ClassChange_DE
SPAWNS.add(new LocationHolder(115774, -178666, -958));// ClassChange_DW
SPAWNS.add(new LocationHolder(45036, 48384, -3060));// ClassChange_E
SPAWNS.add(new LocationHolder(-44747, -113865, -208));// ClassChange_ORC
SPAWNS.add(new LocationHolder(-84466, 243171, -3729));// ClassChange_TI
}
// Html
private static final String HTML_PATH = "data/html/events/classmaster/";

public ClassMaster()
{
super(-1, "ai/npc");

addFirstTalkId(NPC);
addTalkId(NPC);
addStartNpc(NPC);


}

@Override
public String onEnterWorld(L2PcInstance player)
{
// Las accion de anuncio del evento ya fue asignada en la super clase.
return super.onEnterWorld(player);
}

@Override
public String onFirstTalk(L2Npc npc, L2PcInstance player)
{
return HTML_PATH + "index.htm";
}

@Override
public String onAdvEvent(String event, L2Npc npc, L2PcInstance player)
{
if (event.equals("1stClass"))
{
showHtmlMenu(player, npc.getObjectId(), 1);
}
else if (event.equals("2ndClass"))
{
showHtmlMenu(player, npc.getObjectId(), 2);
}
else if (event.equals("3rdClass"))
{
showHtmlMenu(player, npc.getObjectId(), 3);
}
else if (event.startsWith("change_class"))
{
int val = Integer.parseInt(event.substring(13));

if (checkAndChangeClass(player, val))
{
player.playSound(PlaySoundType.QUEST_FANFARE_2);
player.playSound(PlaySoundType.CHAR_CHANGE);
NpcHtmlMessage html = new NpcHtmlMessage(npc.getObjectId());
html.setFile(HTML_PATH + "ok.htm");
html.replace("%name%", ClassId.getById(val).getName());
player.sendPacket(html);
}
}

return null;
}

public static final void showHtmlMenu(L2PcInstance player, int objectId, int level)
{
NpcHtmlMessage html = new NpcHtmlMessage(objectId);

final ClassId currentClassId = player.getClassId();
if (currentClassId.level() >= level)
{
html.setFile(HTML_PATH + "nomore.htm");
}
else
{
final int minLevel = getMinLevel(currentClassId.level());
if (player.getLevel() >= minLevel)
{
final StringBuilder menu = new StringBuilder(100);
for (ClassId cid : ClassId.values())
{
if (validateClassId(currentClassId, cid) && (cid.level() == level))
{
menu.append("<button value=\"");
menu.append(cid.getName() + "\" ");
menu.append("action=\"bypass -h Quest ClassMaster change_class ");
menu.append(String.valueOf(cid.getId()) + "\"");
menu.append(" width=204 height=20 back=\"sek.cbui77\" fore=\"sek.cbui75\"><br>");
}
}

if (menu.length() > 0)
{
html.setFile(HTML_PATH + "template.htm");
html.replace("%name%", currentClassId.name());
html.replace("%menu%", menu.toString());
}
else
{
html.setFile(HTML_PATH + "comebacklater.htm");
html.replace("%level%", String.valueOf(getMinLevel(level - 1)));
}
}
else
{
if (minLevel < Integer.MAX_VALUE)
{
html.setFile(HTML_PATH + "comebacklater.htm");
html.replace("%level%", String.valueOf(minLevel));
}
else
{
html.setFile(HTML_PATH + "nomore.htm");
}
}
}

html.replace("%objectId%", String.valueOf(objectId));
html.replace("%req_items%", getRequiredItems(level));
player.sendPacket(html);
}

private static final void showQuestionMark(L2PcInstance player)
{
final ClassId classId = player.getClassId();
if (getMinLevel(classId.level()) > player.getLevel())
{
return;
}

player.sendPacket(new TutorialShowQuestionMark(1001));
}

/**
* Returns minimum player level required for next class transfer
* @param level - current skillId level (0 - start, 1 - first, etc)
* @return
*/
private static final int getMinLevel(int level)
{
switch (level)
{
case 0:
return 20;
case 1:
return 40;
case 2:
return 76;
default:
return Integer.MAX_VALUE;
}
}

/**
* Returns true if class change is possible
* @param oldCID current player ClassId
* @param val new class index
* @return
*/
private static final boolean validateClassId(ClassId oldCID, int val)
{
try
{
return validateClassId(oldCID, ClassId.getById(val));
}
catch (Exception e)
{
// possible ArrayOutOfBoundsException
}
return false;
}

/**
* Returns true if class change is possible
* @param oldCID current player ClassId
* @param newCID new ClassId
* @return true if class change is possible
*/
private static final boolean validateClassId(ClassId oldCID, ClassId newCID)
{
if ((newCID == null) || (newCID.getRace() == null))
{
return false;
}

if (oldCID.equals(newCID.getParent()))
{
return true;
}

return false;
}

private static String getRequiredItems(int level)
{
level--;
StringBuilder sb = new StringBuilder();
if ((ITEM_LIST.get(level).getPriceItemId() != 0) && (ITEM_LIST.get(level).getPriceItemCount() != 0))
{
int count = ITEM_LIST.get(level).getPriceItemCount();
String itemName = ItemData.getInstance().getTemplate(ITEM_LIST.get(level).getPriceItemId()).getName();
sb.append("<tr><td><img src=\"Icon.Item_System04\" width=32 height=32></td>");
sb.append("<td><font color=\"LEVEL\">[" + count + "]</font></td>");
sb.append("<td>[" + itemName + "]</td>");
sb.append("<td><img src=\"Icon.Item_System05\" width=32 height=32></td></tr>");
}
else
{
sb.append("<tr><td>None</td></tr>");
}
return sb.toString();
}

private static final boolean checkAndChangeClass(L2PcInstance player, int val)
{
final ClassId currentClassId = player.getClassId();
if ((getMinLevel(currentClassId.level()) > player.getLevel()))
{
return false;
}

if (!validateClassId(currentClassId, val))
{
return false;
}

int newJobLevel = currentClassId.level();

// Weight/Inventory check
if (ITEM_LIST.get(newJobLevel).getRewardItemId() != 0)
{
if ((player.getWeightPenalty() >= 3) || ((player.getInventoryLimit() * 0.8) <= player.getInventory().getSize()))
{
player.sendPacket(SystemMessage.INVENTORY_LESS_THAN_80_PERCENT);
return false;
}
}

// get all required items for class transfer
int priceCount = ITEM_LIST.get(newJobLevel).getPriceItemCount();
int priceItemId = ITEM_LIST.get(newJobLevel).getPriceItemId();

if (!player.getInventory().destroyItemByItemId("ClassMaster", priceItemId, priceCount, player, true))
{
player.sendPacket(SystemMessage.NOT_ENOUGH_ITEMS);
return false;
}

// reward player with items
int rewardCount = ITEM_LIST.get(newJobLevel).getRewardItemCount();
int rewardItemId = ITEM_LIST.get(newJobLevel).getRewardItemId();
player.getInventory().addItem("ClassMaster", rewardItemId, rewardCount, player, true);

player.setClassId(val);

if (player.isSubClassActive())
{
player.getSubClasses().get(player.getClassIndex()).setClassId(player.getActiveClass());
}
else
{
player.setBaseClass(player.getActiveClass());
}

player.broadcastUserInfo();

if ((((player.getClassId().level() == 1) && (player.getLevel() >= 40)) || ((player.getClassId().level() == 2) && (player.getLevel() >= 76))))
{
showQuestionMark(player);
}

return true;
}

public class ClassMasterList
{
private int priceItemId;
private int priceItemCount;

private int rewardItemId;
private int rewardItemCount;

public ClassMasterList()
{
//
}

public int getPriceItemId()
{
return priceItemId;
}

public void setPriceItemId(int priceItemId)
{
this.priceItemId = priceItemId;
}

public int getPriceItemCount()
{
return priceItemCount;
}

public void setPriceItemCount(int priceItemCount)
{
this.priceItemCount = priceItemCount;
}

public int getRewardItemId()
{
return rewardItemId;
}

public void setRewardItemId(int rewardItemId)
{
this.rewardItemId = rewardItemId;
}

public int getRewardItemCount()
{
return rewardItemCount;
}

public void setRewardItemCount(int rewardItemCount)
{
this.rewardItemCount = rewardItemCount;
}
}
}


fissban

  • Administrador
  • Full Member
  • *
  • Mensajes: 156
  • Karma: +0/-0
    • Ver Perfil
Re:Aporte ClassMaster (De mientras)
« Respuesta #1 en: Mayo 07, 2018, 08:48:54 pm »
gracias aunque de echo ya agrege uno, faltaria terminar de revisarlo y pienso agregarle su propio propertie pero aun tengo otra cosa q quiero terminar antes