📄 l1mobskilluse.java
字号:
_attacker.setHeading(_attacker.targetDirection(_target.getX(), _target
.getY())); // 向きのセット
if (areaHeight > 0) {
// 範囲攻撃
ArrayList<L1Object> objs = L1World.getInstance()
.getVisibleBoxObjects(_attacker, _attacker.getHeading(),
areaWidth, areaHeight);
for (L1Object obj : objs) {
if (!(obj instanceof L1Character)) { // ターゲットがキャラクター以外の場合何もしない。
continue;
}
L1Character cha = (L1Character) obj;
if (cha.isDead()) { // 死んでるキャラクターは対象外
continue;
}
// ゴースト状態は対象外
if (cha instanceof L1PcInstance) {
if (((L1PcInstance) cha).isGhost()) {
continue;
}
}
// 障害物がある場合は対象外
if (!_attacker.glanceCheck(cha.getX(), cha.getY())) {
continue;
}
if (_target instanceof L1PcInstance
|| _target instanceof L1SummonInstance
|| _target instanceof L1PetInstance) {
// 対PC
if (obj instanceof L1PcInstance
&& !((L1PcInstance) obj).isGhost()
&& !((L1PcInstance) obj).isGmInvis()
|| obj instanceof L1SummonInstance
|| obj instanceof L1PetInstance) {
targetList.put(obj.getId(), 0);
}
} else {
// 対NPC
if (obj instanceof L1MonsterInstance) {
targetList.put(obj.getId(), 0);
}
}
}
} else {
// 単体攻撃
targetList.put(_target.getId(), 0); // ターゲットのみ追加
}
if (targetList.size() == 0) {
return false;
}
Iterator<Integer> ite = targetList.keySet().iterator();
while (ite.hasNext()) {
int targetId = ite.next();
L1Attack attack = new L1Attack(_attacker, (L1Character) L1World
.getInstance().findObject(targetId));
if (attack.calcHit()) {
if (getMobSkillTemplate().getLeverage(idx) > 0) {
attack.setLeverage(getMobSkillTemplate().getLeverage(idx));
}
attack.calcDamage();
}
if (actId > 0) {
attack.setActId(actId);
}
// 攻撃モーションは実際のターゲットに対してのみ行う
if (targetId == _target.getId()) {
if (gfxId > 0) {
_attacker.broadcastPacket(new S_SkillSound(_attacker
.getId(), gfxId));
}
attack.action();
}
attack.commit();
}
_sleepTime = _attacker.getAtkspeed();
return true;
}
/*
* トリガーの条件のみチェック
*/
private boolean isSkillUseble(int skillIdx) {
boolean useble = false;
if (getMobSkillTemplate().getTriggerRandom(skillIdx) > 0) {
int chance = _rnd.nextInt(100) + 1;
if (chance < getMobSkillTemplate().getTriggerRandom(skillIdx)) {
useble = true;
} else {
return false;
}
}
if (getMobSkillTemplate().getTriggerHp(skillIdx) > 0) {
int hpRatio = (_attacker.getCurrentHp() * 100)
/ _attacker.getMaxHp();
if (hpRatio <= getMobSkillTemplate().getTriggerHp(skillIdx)) {
useble = true;
} else {
return false;
}
}
if (getMobSkillTemplate().getTriggerCompanionHp(skillIdx) > 0) {
L1NpcInstance companionNpc = searchMinCompanionHp();
if (companionNpc == null) {
return false;
}
int hpRatio = (companionNpc.getCurrentHp() * 100)
/ companionNpc.getMaxHp();
if (hpRatio <= getMobSkillTemplate()
.getTriggerCompanionHp(skillIdx)) {
useble = true;
_target = companionNpc; // ターゲットの入れ替え
} else {
return false;
}
}
if (getMobSkillTemplate().getTriggerRange(skillIdx) != 0) {
int distance = _attacker.getLocation().getTileLineDistance(
_target.getLocation());
if (getMobSkillTemplate().isTriggerDistance(skillIdx, distance)) {
useble = true;
} else {
return false;
}
}
if (getMobSkillTemplate().getTriggerCount(skillIdx) > 0) {
if (getSkillUseCount(skillIdx) < getMobSkillTemplate()
.getTriggerCount(skillIdx)) {
useble = true;
} else {
return false;
}
}
return useble;
}
private L1NpcInstance searchMinCompanionHp() {
L1NpcInstance npc;
L1NpcInstance minHpNpc = null;
int hpRatio = 100;
int companionHpRatio;
int family = _attacker.getNpcTemplate().get_family();
for (L1Object object : L1World.getInstance().getVisibleObjects(
_attacker)) {
if (object instanceof L1NpcInstance) {
npc = (L1NpcInstance) object;
if (npc.getNpcTemplate().get_family() == family) {
companionHpRatio = (npc.getCurrentHp() * 100)
/ npc.getMaxHp();
if (companionHpRatio < hpRatio) {
hpRatio = companionHpRatio;
minHpNpc = npc;
}
}
}
}
return minHpNpc;
}
private void mobspawn(int summonId, int count) {
int i;
for (i = 0; i < count; i++) {
mobspawn(summonId);
}
}
private void mobspawn(int summonId) {
try {
L1Npc spawnmonster = NpcTable.getInstance().getTemplate(summonId);
if (spawnmonster != null) {
L1NpcInstance mob = null;
try {
String implementationName = spawnmonster.getImpl();
Constructor _constructor = Class.forName(
(new StringBuilder()).append(
"l1j.server.server.model.Instance.")
.append(implementationName).append(
"Instance").toString())
.getConstructors()[0];
mob = (L1NpcInstance) _constructor
.newInstance(new Object[] { spawnmonster });
mob.setId(IdFactory.getInstance().nextId());
L1Location loc = _attacker.getLocation().randomLocation(8,
false);
int heading = _rnd.nextInt(8);
mob.setX(loc.getX());
mob.setY(loc.getY());
mob.setHomeX(loc.getX());
mob.setHomeY(loc.getY());
short mapid = _attacker.getMapId();
mob.setMap(mapid);
mob.setHeading(heading);
L1World.getInstance().storeObject(mob);
L1World.getInstance().addVisibleObject(mob);
L1Object object = L1World.getInstance().findObject(
mob.getId());
L1MonsterInstance newnpc = (L1MonsterInstance) object;
newnpc.set_storeDroped(true); // 召喚されたモンスターはドロップ無し
if (summonId == 45061 // カーズドスパルトイ
|| summonId == 45161 // スパルトイ
|| summonId == 45181 // スパルトイ
|| summonId == 45455) { // デッドリースパルトイ
newnpc.broadcastPacket(new S_DoActionGFX(
newnpc.getId(), ActionCodes.ACTION_Hide));
newnpc.setStatus(13);
newnpc.broadcastPacket(new S_NPCPack(newnpc));
newnpc.broadcastPacket(new S_DoActionGFX(
newnpc.getId(), ActionCodes.ACTION_Appear));
newnpc.setStatus(0);
newnpc.broadcastPacket(new S_NPCPack(newnpc));
}
newnpc.onNpcAI();
newnpc.turnOnOffLight();
newnpc.startChat(L1NpcInstance.CHAT_TIMING_APPEARANCE); // チャット開始
} catch (Exception e) {
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
} catch (Exception e) {
_log.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
// 現在ChangeTargetで有效な値は2,3のみ
private L1Character changeTarget(int type, int idx) {
L1Character target;
switch (type) {
case L1MobSkill.CHANGE_TARGET_ME:
target = _attacker;
break;
case L1MobSkill.CHANGE_TARGET_RANDOM:
// ターゲット候補の選定
List<L1Character> targetList = new ArrayList<L1Character>();
for (L1Object obj : L1World.getInstance().getVisibleObjects(
_attacker)) {
if (obj instanceof L1PcInstance || obj instanceof L1PetInstance
|| obj instanceof L1SummonInstance) {
L1Character cha = (L1Character) obj;
int distance = _attacker.getLocation().getTileLineDistance(
cha.getLocation());
// 発動範囲外のキャラクターは対象外
if (!getMobSkillTemplate().isTriggerDistance(idx, distance)) {
continue;
}
// 障害物がある場合は対象外
if (!_attacker.glanceCheck(cha.getX(), cha.getY())) {
continue;
}
if (!_attacker.getHateList().containsKey(cha)) { // ヘイトがない場合対象外
continue;
}
if (cha.isDead()) { // 死んでるキャラクターは対象外
continue;
}
// ゴースト状態は対象外
if (cha instanceof L1PcInstance) {
if (((L1PcInstance) cha).isGhost()) {
continue;
}
}
targetList.add((L1Character) obj);
}
}
if (targetList.size() == 0) {
target = _target;
} else {
int randomSize = targetList.size() * 100;
int targetIndex = _rnd.nextInt(randomSize) / 100;
target = targetList.get(targetIndex);
}
break;
default:
target = _target;
break;
}
return target;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -