123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- /*
- * 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 custom.Validators;
- import com.l2jserver.Config;
- import com.l2jserver.gameserver.datatables.SkillTreesData;
- import com.l2jserver.gameserver.model.L2Skill;
- import com.l2jserver.gameserver.model.L2SkillLearn;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.quest.Quest;
- import com.l2jserver.gameserver.model.quest.QuestState;
- import com.l2jserver.gameserver.util.Util;
- /**
- * @author Zoey76
- */
- public final class SkillTransferValidator extends Quest
- {
- public SkillTransferValidator(int id, String name, String descr)
- {
- super(id, name, descr);
- setOnEnterWorld(true);
- }
-
- private static final String qn = "SkillTransfer";
-
- private static final int[][] PORMANDERS =
- {
- { 15307, 1 }, // Cardinal (97)
- { 15308, 1 }, // Eva's Saint (105)
- { 15309, 4 } // Shillen Saint (112)
- };
-
- @Override
- public String onEnterWorld(L2PcInstance player)
- {
- givePormanders(player);
- return null;
- }
-
- private void givePormanders(L2PcInstance player)
- {
- final int index = getTransferClassIndex(player);
-
- if (index >= 0)
- {
- QuestState st = player.getQuestState(qn);
- if (st == null)
- st = newQuestState(player);
-
- final String name = qn + String.valueOf(player.getClassId().getId());
- if (st.getInt(name) == 0)
- {
- st.setInternal(name, "1");
- if (st.getGlobalQuestVar(name).isEmpty())
- {
- st.saveGlobalQuestVar(name, "1");
- player.addItem(qn, PORMANDERS[index][0], PORMANDERS[index][1], null, true);
- }
- }
-
- if (Config.SKILL_CHECK_ENABLE && (!player.isGM() || Config.SKILL_CHECK_GM))
- {
- int count = PORMANDERS[index][1] - (int)player.getInventory().getInventoryItemCount(PORMANDERS[index][0], -1, false);
- for (L2Skill sk : player.getAllSkills())
- {
- for (L2SkillLearn s : SkillTreesData.getInstance().getTransferSkillTree(player.getClassId()).values())
- {
- if (s.getSkillId() == sk.getId())
- {
- // Holy Weapon allowed for Shilien Saint/Inquisitor stance
- if (sk.getId() == 1043 && index == 2 && player.isInStance())
- continue;
-
- count--;
- if (count < 0)
- {
- Util.handleIllegalPlayerAction(player, "Player " + player.getName() + " has too many transfered skills or items, skill:" + s.getName() + " ("+sk.getId() + "/" + sk.getLevel() + "), class:" + player.getTemplate().className, 1);
- if (Config.SKILL_CHECK_REMOVE)
- player.removeSkill(sk);
- }
- }
- }
- }
- }
- }
- }
-
- private int getTransferClassIndex(L2PcInstance player)
- {
- switch (player.getClassId().getId())
- {
- case 97: // Cardinal
- return 0;
- case 105: // Eva's Saint
- return 1;
- case 112: // Shillien Saint
- return 2;
- default:
- return -1;
- }
- }
-
- public static void main(String[] args)
- {
- new SkillTransferValidator(-1, qn, "custom");
- }
- }
|