/* * Copyright (C) 2004-2015 L2J DataPack * * This file is part of L2J DataPack. * * L2J DataPack 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. * * L2J DataPack 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 . */ package handlers.admincommandhandlers; import java.util.List; import java.util.StringTokenizer; import com.l2jserver.gameserver.data.xml.impl.NpcData; import com.l2jserver.gameserver.handler.IAdminCommandHandler; import com.l2jserver.gameserver.model.actor.L2Character; import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance; import com.l2jserver.gameserver.model.actor.instance.L2PcInstance; import com.l2jserver.gameserver.model.actor.templates.L2NpcTemplate; import com.l2jserver.gameserver.model.stats.Formulas; import com.l2jserver.gameserver.network.SystemMessageId; import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage; import com.l2jserver.util.StringUtil; /** * This class handles following admin commands: - gm = turns gm mode on/off * @version $Revision: 1.1.2.1 $ $Date: 2005/03/15 21:32:48 $ */ public class AdminFightCalculator implements IAdminCommandHandler { private static final String[] ADMIN_COMMANDS = { "admin_fight_calculator", "admin_fight_calculator_show", "admin_fcs", }; // TODO: remove from gm list etc etc @Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { try { if (command.startsWith("admin_fight_calculator_show")) { handleShow(command.substring("admin_fight_calculator_show".length()), activeChar); } else if (command.startsWith("admin_fcs")) { handleShow(command.substring("admin_fcs".length()), activeChar); } else if (command.startsWith("admin_fight_calculator")) { handleStart(command.substring("admin_fight_calculator".length()), activeChar); } } catch (StringIndexOutOfBoundsException e) { } return true; } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } private void handleStart(String params, L2PcInstance activeChar) { StringTokenizer st = new StringTokenizer(params); int lvl1 = 0; int lvl2 = 0; int mid1 = 0; int mid2 = 0; while (st.hasMoreTokens()) { String s = st.nextToken(); if (s.equals("lvl1")) { lvl1 = Integer.parseInt(st.nextToken()); continue; } if (s.equals("lvl2")) { lvl2 = Integer.parseInt(st.nextToken()); continue; } if (s.equals("mid1")) { mid1 = Integer.parseInt(st.nextToken()); continue; } if (s.equals("mid2")) { mid2 = Integer.parseInt(st.nextToken()); continue; } } L2NpcTemplate npc1 = null; if (mid1 != 0) { npc1 = NpcData.getInstance().getTemplate(mid1); } L2NpcTemplate npc2 = null; if (mid2 != 0) { npc2 = NpcData.getInstance().getTemplate(mid2); } final NpcHtmlMessage adminReply = new NpcHtmlMessage(); final String replyMSG; if ((npc1 != null) && (npc2 != null)) { replyMSG = StringUtil.concat("Selected mobs to fight" + "" + "" + "" + "" + "" + "" + "
FirstSecond
level ", String.valueOf(lvl1), "level ", String.valueOf(lvl2), "
id ", String.valueOf(npc1.getId()), "id ", String.valueOf(npc2.getId()), "
", npc1.getName(), "", npc2.getName(), "
" + "



" + "
" + ""); } else if ((lvl1 != 0) && (npc1 == null)) { final List npcs = NpcData.getInstance().getAllOfLevel(lvl1); final StringBuilder sb = StringUtil.startAppend(50 + (npcs.size() * 200), "Select first mob to fight" + ""); for (L2NpcTemplate n : npcs) { StringUtil.append(sb, ""); } sb.append("
", n.getName(), "
"); replyMSG = sb.toString(); } else if ((lvl2 != 0) && (npc2 == null)) { final List npcs = NpcData.getInstance().getAllOfLevel(lvl2); final StringBuilder sb = StringUtil.startAppend(50 + (npcs.size() * 200), "Select second mob to fight" + ""); for (L2NpcTemplate n : npcs) { StringUtil.append(sb, ""); } sb.append("
", n.getName(), "
"); replyMSG = sb.toString(); } else { replyMSG = "Select mobs to fight" + "" + "" + "" + "" + "
FirstSecond
" + "



" + "
" + ""; } adminReply.setHtml(replyMSG); activeChar.sendPacket(adminReply); } private void handleShow(String params, L2PcInstance activeChar) { params = params.trim(); L2Character npc1 = null; L2Character npc2 = null; if (params.length() == 0) { npc1 = activeChar; npc2 = (L2Character) activeChar.getTarget(); if (npc2 == null) { activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET); return; } } else { int mid1 = 0; int mid2 = 0; StringTokenizer st = new StringTokenizer(params); mid1 = Integer.parseInt(st.nextToken()); mid2 = Integer.parseInt(st.nextToken()); npc1 = new L2MonsterInstance(NpcData.getInstance().getTemplate(mid1)); npc2 = new L2MonsterInstance(NpcData.getInstance().getTemplate(mid2)); } int miss1 = 0; int miss2 = 0; int shld1 = 0; int shld2 = 0; int crit1 = 0; int crit2 = 0; double patk1 = 0; double patk2 = 0; double pdef1 = 0; double pdef2 = 0; double dmg1 = 0; double dmg2 = 0; // ATTACK speed in milliseconds int sAtk1 = npc1.calculateTimeBetweenAttacks(npc2, null); int sAtk2 = npc2.calculateTimeBetweenAttacks(npc1, null); // number of ATTACK per 100 seconds sAtk1 = 100000 / sAtk1; sAtk2 = 100000 / sAtk2; for (int i = 0; i < 10000; i++) { boolean _miss1 = Formulas.calcHitMiss(npc1, npc2); if (_miss1) { miss1++; } byte _shld1 = Formulas.calcShldUse(npc1, npc2, null, false); if (_shld1 > 0) { shld1++; } boolean _crit1 = Formulas.calcCrit(npc1, npc2); if (_crit1) { crit1++; } double _patk1 = npc1.getPAtk(npc2); _patk1 += npc1.getRandomDamageMultiplier(); patk1 += _patk1; double _pdef1 = npc1.getPDef(npc2); pdef1 += _pdef1; if (!_miss1) { double _dmg1 = Formulas.calcPhysDam(npc1, npc2, null, _shld1, _crit1, false); dmg1 += _dmg1; npc1.abortAttack(); } } for (int i = 0; i < 10000; i++) { boolean _miss2 = Formulas.calcHitMiss(npc2, npc1); if (_miss2) { miss2++; } byte _shld2 = Formulas.calcShldUse(npc2, npc1, null, false); if (_shld2 > 0) { shld2++; } boolean _crit2 = Formulas.calcCrit(npc2, npc1); if (_crit2) { crit2++; } double _patk2 = npc2.getPAtk(npc1); _patk2 *= npc2.getRandomDamageMultiplier(); patk2 += _patk2; double _pdef2 = npc2.getPDef(npc1); pdef2 += _pdef2; if (!_miss2) { double _dmg2 = Formulas.calcPhysDam(npc2, npc1, null, _shld2, _crit2, false); dmg2 += _dmg2; npc2.abortAttack(); } } miss1 /= 100; miss2 /= 100; shld1 /= 100; shld2 /= 100; crit1 /= 100; crit2 /= 100; patk1 /= 10000; patk2 /= 10000; pdef1 /= 10000; pdef2 /= 10000; dmg1 /= 10000; dmg2 /= 10000; // total damage per 100 seconds int tdmg1 = (int) (sAtk1 * dmg1); int tdmg2 = (int) (sAtk2 * dmg2); // HP restored per 100 seconds double maxHp1 = npc1.getMaxHp(); int hp1 = (int) ((Formulas.calcHpRegen(npc1) * 100000) / Formulas.getRegeneratePeriod(npc1)); double maxHp2 = npc2.getMaxHp(); int hp2 = (int) ((Formulas.calcHpRegen(npc2) * 100000) / Formulas.getRegeneratePeriod(npc2)); final NpcHtmlMessage adminReply = new NpcHtmlMessage(); final StringBuilder replyMSG = StringUtil.startAppend(1000, "Selected mobs to fight" + "" + ""); if (params.length() == 0) { replyMSG.append(""); } else { StringUtil.append(replyMSG, ""); } StringUtil.append(replyMSG, "" + "" + "" + "" + "" + "" + "" + "" + "" + ""); if ((tdmg2 - hp1) > 1) { StringUtil.append(replyMSG, ""); } else { replyMSG.append(""); } if ((tdmg1 - hp2) > 1) { StringUtil.append(replyMSG, ""); } else { replyMSG.append(""); } replyMSG.append("" + "
Parametermetarget
Parameter", ((L2NpcTemplate) npc1.getTemplate()).getName(), "", ((L2NpcTemplate) npc2.getTemplate()).getName(), "
miss", String.valueOf(miss1), "%", String.valueOf(miss2), "%
shld", String.valueOf(shld2), "%", String.valueOf(shld1), "%
crit", String.valueOf(crit1), "%", String.valueOf(crit2), "%
pAtk / pDef", String.valueOf((int) patk1), " / ", String.valueOf((int) pdef1), "", String.valueOf((int) patk2), " / ", String.valueOf((int) pdef2), "
made hits", String.valueOf(sAtk1), "", String.valueOf(sAtk2), "
dmg per hit", String.valueOf((int) dmg1), "", String.valueOf((int) dmg2), "
got dmg", String.valueOf(tdmg2), "", String.valueOf(tdmg1), "
got regen", String.valueOf(hp1), "", String.valueOf(hp2), "
had HP", String.valueOf((int) maxHp1), "", String.valueOf((int) maxHp2), "
die", String.valueOf((int) ((100 * maxHp1) / (tdmg2 - hp1))), " secnever", String.valueOf((int) ((100 * maxHp2) / (tdmg1 - hp2))), " secnever
" + "

"); if (params.length() == 0) { replyMSG.append("
" + ""); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); if (params.length() != 0) { ((L2MonsterInstance) npc1).deleteMe(); ((L2MonsterInstance) npc2).deleteMe(); } } }