【天堂】怪物防卡打系統
伺服器有幾個版本,都會有隔牆打怪的問題。
而怪物無法過牆攻擊,就會傻傻的呆站在原地被打死。
而這類情況,主要都是因為「鎖鏈劍」的問題以及圖檔編碼的使然。
在防堵上,目前是用了一個非正規的方式去勉強解決。
解決原理:
隔牆卡打代表「怪物無法攻擊到玩家」,
所以只要判斷怪物多久時間都無法攻擊到玩家後,就會自動瞬間移動到玩家身旁。
上CODE:
(1)新增L1IdleAttack .java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package l1j.extendsSys; | |
import l1j.server.server.model.Instance.L1MonsterInstance; | |
import l1j.server.server.model.Instance.L1NpcInstance; | |
import l1j.server.server.model.Instance.L1PcInstance; | |
/** | |
* 怪物智商解卡系統 | |
* @author RR- | |
* | |
*/ | |
public class L1IdleAttack { | |
public static void _addIdleAtk(L1PcInstance pc, L1NpcInstance targetNpc) { | |
if (targetNpc instanceof L1MonsterInstance) { | |
targetNpc._addAttack(1); | |
} | |
} | |
public static void _resetIdleAtk(L1NpcInstance targetNpc) { | |
if (targetNpc instanceof L1MonsterInstance) { | |
targetNpc._setidleAttack(0); | |
} | |
} | |
} |
(2)L1NpcInstance.java更改
到最後新增下面
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int _idleAttack = 0; | |
public void _addAttack(int i) | |
{ | |
if (is_boss()) { | |
_idleAttack += i; | |
} | |
} | |
public void _setidleAttack(int i) | |
{ | |
_idleAttack = i; | |
} | |
public int _getidleAttack() | |
{ | |
return _idleAttack; | |
} |
L1NpcInstance.java更改onTarget 方法
搜尋if (isAttackPosition(target.getX(), target.getY(), getAtkRanged()))
找到後,在else的部分添加紅字部分及可
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (isAttackPosition(target.getX(), target.getY(), getAtkRanged())) { // 攻撃可能位置 | |
if (mobSkill.isSkillTrigger(target)) { | |
if (mobSkill.skillUse(target, true)) { | |
setSleepTime(calcSleepTime(mobSkill.getSleepTime(), MAGIC_SPEED)); | |
} else { | |
setHeading(targetDirection(target.getX(), target.getY())); | |
attackTarget(target); | |
} | |
} else { | |
setHeading(targetDirection(target.getX(), target.getY())); | |
attackTarget(target); | |
} | |
} else { // 攻撃不可能位置 | |
//------------------------ add -------------------------------------- | |
if (_getidleAttack() > 20 && target != null) { | |
this.broadcastPacket(new S_NpcChatPacket(this, "竟敢愚弄我的智商!", 0)); | |
this._setidleAttack(0); | |
if (nearTeleport(target.getX(), target.getY()) == true) { | |
return; | |
} | |
} | |
//----------------------- add end ------------------------------------- |
(3)L1Attack.java更改
到L1Attack去找到PC對NPC的函式 - calcPcNpcDamage搜尋private int calcPcNpcDamage()
到calcPcNpcDamage函式最後面將判斷更改為以下
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (dmg <= 0) | |
{ | |
_isHit = false; | |
_drainHp = 0; | |
} else | |
{ | |
// BOSS智商解卡 | |
L1IdleAttack._addIdleAtk(_pc, _targetNpc); | |
} |
到L1Attack去找到npc對pc的函式 - calcNpcPcDamage
搜尋private int calcNpcPcDamage()
到calcNpcPcDamage函式最後面將判斷更改為以下
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (dmg <= 0) { | |
_isHit = false; | |
} | |
else { | |
// 智商解卡 | |
L1IdleAttack._resetIdleAtk(_npc); | |
} |
(4)L1Magic.java更改
到L1Magic去找到commitPc函式搜尋private void commitPc(int damage, int drainMana)
到commitPc函式將裡面判斷改如下
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
else if (_calcType == NPC_PC) | |
{ | |
_targetPc.receiveDamage(_npc, damage, true); | |
// 智商解卡 | |
L1IdleAttack._resetIdleAtk(_npc); | |
} |
張貼留言