修改以下原碼:
l1j\server\server\datatables\NpcTable.java
l1j\server\server\templates\L1Npc.java
l1j\server\server\model\Instance\L1MonsterInstance.java
步驟1:
L1Npc.java
找個地方加入這一段
- //怪死變身機率
- private int _TransChance;
-
- public int getTransChance() {
99天堂1游戏发布站,天堂1游戏发布网
- return _TransChance;
- }
-
- public void setTransChance(int TransChance) {
- _TransChance = TransChance;
- }
- //怪死變身機率
复制代码 步驟2:
NpcTable.java
在這一段的迴圈中找個地方插入這一句:
con = L1DatabaseFactory.getInstance().getConnection();
pstm = con.prepareStatement("SELECT * FROM npc");
rs = pstm.executeQuery();
while (rs.next()) {
- //怪死變身機率
- npc.setTransChance(rs.getInt("TransChance"));
- //怪死變身機率
复制代码 步驟3:
L1MonsterInstance.java
匯入宣告加入以下:
import java.util.Random;
接著在public class L1MonsterInstance extends L1NpcInstance {
的迴圈中找個地方加入以下:
private static Random _random = new Random();
找到這一段落:
- int newHp = getCurrentHp() - damage;
- if (newHp <= 0 && !isDead()) {
- int transformId = getNpcTemplate().getTransformId();
- // 變身
- if (transformId == -1) {
- setCurrentHpDirect(0);
- setDead(true);
- setStatus(ActionCodes.ACTION_Die);
- openDoorWhenNpcDied(this);
- Death death = new Death(attacker);
- GeneralThreadPool.getInstance().execute(death);
- // Death(attacker);
- } else { // 變身
- // distributeExpDropKarma(attacker);
- transform(transformId);
- }
- }
- if (newHp > 0) {
- setCurrentHp(newHp);
- hide();
- }
- } else if (!isDead()) { // 念
- setDead(true);
- setStatus(ActionCodes.ACTION_Die);
- Death death = new Death(attacker);
- GeneralThreadPool.getInstance().execute(death);
- // Death(attacker);
- }
- }
复制代码 將他修改為以下:
- int newHp = getCurrentHp() - damage;
- if (newHp <= 0 && !isDead()) {
- int transformId = getNpcTemplate().getTransformId();
- int chance = getNpcTemplate().getTransChance();
- // 變身
- if (transformId == -1) {
- setCurrentHpDirect(0);
- setDead(true);
- setStatus(ActionCodes.ACTION_Die);
- openDoorWhenNpcDied(this);
- Death death = new Death(attacker);
- GeneralThreadPool.getInstance().execute(death);
- // Death(attacker);
- /*刪除} else { // 變身
- // distributeExpDropKarma(attacker);
- transform(transformId);
- }
- }刪除*/
-
- //怪死變身機率
- }
- if (transformId !=-1 && chance == 0) {
- chance = 101;
- }
- if (chance >= 1) {
- Random random = new Random();
- int rnd = random.nextInt(100) + 1;
- if (transformId !=-1 && rnd <= chance) {
- transform(transformId);
- } else {
- setCurrentHpDirect(0);
- setDead(true);
- setStatus(ActionCodes.ACTION_Die);
- openDoorWhenNpcDied(this);
- Death death = new Death(attacker);
- GeneralThreadPool.getInstance().execute(death);
- }
- }
- }
- //怪死變身機率
复制代码 步驟4:
db的npc資料表新增以下欄位:
TransChance int 10 0 不允許空白
預設值為0
TranceChance(怪死變身機率)
輸入0的時候,以及transform_id有輸入編號的時候,
那麼0等於100%變身。
如果輸入1以上的數字,那麼就會隨著機率變身。