📄 abstractdealdamagehandler.java
字号:
/*
This file is part of the OdinMS Maple Story Server
Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
Matthias Butz <matze@odinms.de>
Jan Christian Meyer <vimes@odinms.de>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License version 3
as published by the Free Software Foundation. You may not use, modify
or distribute this program under any other version of the
GNU Affero General Public License.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.sf.odinms.net.channel.handler;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.sf.odinms.client.ISkill;
import net.sf.odinms.client.MapleBuffStat;
import net.sf.odinms.client.MapleCharacter;
import net.sf.odinms.client.MapleJob;
import net.sf.odinms.client.SkillFactory;
import net.sf.odinms.client.anticheat.CheatingOffense;
import net.sf.odinms.client.status.MonsterStatus;
import net.sf.odinms.client.status.MonsterStatusEffect;
import net.sf.odinms.net.AbstractMaplePacketHandler;
import net.sf.odinms.server.AutobanManager;
import net.sf.odinms.server.MapleStatEffect;
import net.sf.odinms.server.TimerManager;
import net.sf.odinms.server.life.Element;
import net.sf.odinms.server.life.MapleMonster;
import net.sf.odinms.server.maps.MapleMap;
import net.sf.odinms.server.maps.MapleMapItem;
import net.sf.odinms.server.maps.MapleMapObject;
import net.sf.odinms.server.maps.MapleMapObjectType;
import net.sf.odinms.tools.MaplePacketCreator;
import net.sf.odinms.tools.Pair;
import net.sf.odinms.tools.data.input.LittleEndianAccessor;
public abstract class AbstractDealDamageHandler extends AbstractMaplePacketHandler {
// private static Logger log = LoggerFactory.getLogger(AbstractDealDamageHandler.class);
protected static class AttackInfo {
public int numAttacked, numDamage, numAttackedAndDamage;
public int skill, stance;
public List<Pair<Integer, List<Integer>>> allDamage;
private MapleStatEffect getAttackEffect(MapleCharacter chr, ISkill theSkill) {
ISkill mySkill = theSkill;
if (mySkill == null) {
mySkill = SkillFactory.getSkill(skill);
}
int skillLevel = chr.getSkillLevel(mySkill);
if (skillLevel == 0) {
return null;
}
return mySkill.getEffect(skillLevel);
}
public MapleStatEffect getAttackEffect(MapleCharacter chr) {
return getAttackEffect(chr, null);
}
}
protected void applyAttack(AttackInfo attack, MapleCharacter player, int maxDamagePerMonster, int attackCount) {
player.getCheatTracker().resetHPRegen();
player.getCheatTracker().checkAttack();
ISkill theSkill = null;
MapleStatEffect attackEffect = null;
if (attack.skill != 0) {
theSkill = SkillFactory.getSkill(attack.skill);
attackEffect = attack.getAttackEffect(player, theSkill);
if (attackEffect == null) {
AutobanManager.getInstance().autoban(player.getClient(),
"Using a skill he doesn't have (" + attack.skill + ")");
}
if (attack.skill != 2301002) {
// heal is both an attack and a special move (healing)
// so we'll let the whole applying magic live in the special move part
if (player.isAlive()) {
attackEffect.applyTo(player);
} else {
player.getClient().getSession().write(MaplePacketCreator.enableActions());
}
}
}
if (!player.isAlive()) {
player.getCheatTracker().registerOffense(CheatingOffense.ATTACKING_WHILE_DEAD);
return;
}
// meso explosion has a variable bullet count
if (attackCount != attack.numDamage && attack.skill != 4211006) {
player.getCheatTracker().registerOffense(CheatingOffense.MISMATCHING_BULLETCOUNT,
attack.numDamage + "/" + attackCount);
}
int totDamage = 0;
MapleMap map = player.getMap();
if (attack.skill == 4211006) { // meso explosion
for (Pair<Integer, List<Integer>> oned : attack.allDamage) {
MapleMapObject mapobject = map.getMapObject(oned.getLeft().intValue());
if (mapobject != null && mapobject.getType() == MapleMapObjectType.ITEM) {
MapleMapItem mapitem = (MapleMapItem) mapobject;
if (mapitem.getMeso() > 0) {
synchronized (mapitem) {
if (mapitem.isPickedUp())
return;
map.removeMapObject(mapitem);
map.broadcastMessage(MaplePacketCreator.removeItemFromMap(mapitem.getObjectId(), 4, 0), mapitem.getPosition());
mapitem.setPickedUp(true);
}
} else if (mapitem.getMeso() == 0) {
player.getCheatTracker().registerOffense(CheatingOffense.ETC_EXPLOSION);
return;
}
} else if (mapobject.getType() != MapleMapObjectType.MONSTER) {
player.getCheatTracker().registerOffense(CheatingOffense.EXPLODING_NONEXISTANT);
return; // etc explosion, exploding nonexistant things, etc.
}
}
}
for (Pair<Integer, List<Integer>> oned : attack.allDamage) {
MapleMonster monster = map.getMonsterByOid(oned.getLeft().intValue());
if (monster != null) {
int totDamageToOneMonster = 0;
for (Integer eachd : oned.getRight()) {
totDamageToOneMonster += eachd.intValue();
}
totDamage += totDamageToOneMonster;
Point playerPos = player.getPosition();
if (monster != null) {
if (totDamageToOneMonster > attack.numDamage + 1) {
int dmgCheck = player.getCheatTracker().checkDamage(totDamageToOneMonster);
if (dmgCheck > 5) {
player.getCheatTracker().registerOffense(CheatingOffense.SAME_DAMAGE,
dmgCheck + " times: " + totDamageToOneMonster);
}
}
checkHighDamage(player, monster, attack, theSkill, attackEffect, totDamageToOneMonster, maxDamagePerMonster);
double distance = playerPos.distanceSq(monster.getPosition());
if (distance > 360000.0) { // 600^2, 550 is approximatly the range of ultis
player.getCheatTracker().registerOffense(CheatingOffense.ATTACK_FARAWAY_MONSTER,
Double.toString(Math.sqrt(distance)));
// if (distance > 1000000.0)
// AutobanManager.getInstance().addPoints(player.getClient(), 50, 120000, "Exceeding attack
// range");
}
if (!monster.isControllerHasAggro()) {
if (monster.getController() == player) {
monster.setControllerHasAggro(true);
} else {
monster.switchController(player, true);
}
}
// only ds, sb, assaulter, normal (does it work for thieves, bs, or assasinate?)
if ((attack.skill == 4001334 || attack.skill == 4201005 || attack.skill == 0 || attack.skill == 4211002) &&
player.getBuffedValue(MapleBuffStat.PICKPOCKET) != null) {
handlePickPocket(player, monster, oned);
}
if(attack.skill == 4101005) { // drain
ISkill drain = SkillFactory.getSkill(4101005);
int gainhp = (int)((double)totDamageToOneMonster * (double)drain.getEffect(player.getSkillLevel(drain)).getX() / 100.0);
gainhp = Math.min(monster.getMaxHp(), Math.min(gainhp, player.getMaxHp() / 2));
player.addHP(gainhp);
}
if (player.getJob().isA(MapleJob.WHITEKNIGHT)) {
int[] charges = new int[] {1211005, 1211006};
for (int charge : charges) {
ISkill chargeSkill = SkillFactory.getSkill(charge);
if (player.isBuffFrom(MapleBuffStat.WK_CHARGE, chargeSkill)) {
MapleStatEffect chargeEffect = chargeSkill.getEffect(player.getSkillLevel(chargeSkill));
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(Collections.singletonMap(MonsterStatus.FREEZE, 1), chargeSkill, false);
monster.applyStatus(player, monsterStatusEffect, false, chargeEffect.getY() * 2000);
break;
}
}
}
if (totDamageToOneMonster > 0 && attackEffect != null && attackEffect.getMonsterStati().size() > 0) {
if (attackEffect.makeChanceResult()) {
MonsterStatusEffect monsterStatusEffect = new MonsterStatusEffect(attackEffect.getMonsterStati(), theSkill, false);
monster.applyStatus(player, monsterStatusEffect, attackEffect.isPoison(), attackEffect.getDuration());
}
}
map.damageMonster(player, monster, totDamageToOneMonster);
}
}
}
if (totDamage > 1) {
player.getCheatTracker().setAttacksWithoutHit(player.getCheatTracker().getAttacksWithoutHit() + 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -