补充说明:数据库npcchardata 第一栏位已由npc_id 变更为npcId;
NpcTable.java;
文件头加入
//add by L2CN<
import com.l2jserver.gameserver.model.L2NpcCharData;
import javolution.util.FastList;
//add by L2CN>
搜索
loadNpcsAI(0);
在其后加入:
loadNpcsChar(0);//add by L2CN
搜索
loadNpcsAI(id);
在其后加入:
loadNpcsChar(id);//add by L2CN
搜索
public void loadNpcsElement(int id)
在其前面加入
//add by L2CN<
public void loadNpcsChar(int id)
{
Connection con = null;
try
{
con = L2DatabaseFactory.getInstance().getConnection();
PreparedStatement statement = null;
if (id > 0)
{
statement = con.prepareStatement("SELECT * FROM npcchardata WHERE npcId = ?");
statement.setInt(1, id);
}
else
{
statement = con.prepareStatement("SELECT * FROM npcchardata ORDER BY npcId");
}
int cont = 0;
int npcId;
while (rset.next())
{
npcId = rset.getInt("npcId");
npcDat = _npcs.get(npcId);
if (npcDat == null)
{
_log.severe(getClass().getSimpleName() + ": Char Data Error with id : " + npcId);
continue;
}
npcCharDat = new L2NpcCharData();
}
catch (Exception e)
{
_log.log(Level.SEVERE, getClass().getSimpleName() + ": Error reading NPC Char Data: " + e.getMessage(), e);
}
finally
{
L2DatabaseFactory.close(con);
}
}
//add by L2CN>
L2Npc.java;
文件头加入
//add by L2CN<
import javolution.util.FastList;
import com.l2jserver.gameserver.model.L2NpcCharData;
import com.l2jserver.gameserver.datatables.NpcTable;
//add by L2CN>
搜索
private double _currentCollisionRadius; // used for npc grow effect skills
在其后加入
//add by L2CN<
private final L2NpcCharData _ChardataStatic = getTemplate().getCharDataStatic();
public int getIsChar()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getIsChar();
}
public int getCharClass()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharClass();
}
public int getCharRace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharRace();
}
public int getLrhand()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getLrhand();
}
public int getArmors()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getArmor();
}
public int getPant()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getPant();
}
public int getHead()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getHead();
}
public int getGlove()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getGlove();
}
public int getBoot()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getBoot();
}
public int getBack()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getBack();
}
public int getDHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getDHair();
}
public int getFace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getFace();
}
public int getHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getHair();
}
public int getAugmentation()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getAugmentation();
}
public int getEnchLvl()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getEnchLvl();
}
public int getCharFace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharFace();
}
public int getCharHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHair();
}
public int getCharHairColor()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHairColor();
}
public String getCharColor()
{
if (_ChardataStatic == null)
return "0xFFFFFF";
return _ChardataStatic.getCharColor();
}
public int getCharSex()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharSex();
}
public int getCharHero()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHero();
}
//add by L2CN>
L2Summon.java;
文件头加入
//add by L2CN<
import com.l2jserver.gameserver.datatables.NpcTable;
import com.l2jserver.gameserver.model.L2NpcCharData;
//add by L2CN>
搜索
public boolean isSummon()
{
return true;
}
在其后加入
//add by L2CN<
private final L2NpcCharData _ChardataStatic = getTemplate().getCharDataStatic();
public int getIsChar()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getIsChar();
}
public int getCharClass()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharClass();
}
public int getCharRace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharRace();
}
public int getLrhand()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getLrhand();
}
public int getArmors()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getArmor();
}
public int getPant()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getPant();
}
public int getHead()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getHead();
}
public int getGlove()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getGlove();
}
public int getBoot()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getBoot();
}
public int getBack()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getBack();
}
public int getDHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getDHair();
}
public int getFace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getFace();
}
public int getHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getHair();
}
public int getAugmentation()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getAugmentation();
}
public int getEnchLvl()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getEnchLvl();
}
public int getCharFace()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharFace();
}
public int getCharHair()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHair();
}
public int getCharHairColor()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHairColor();
}
public String getCharColor()
{
if (_ChardataStatic == null)
return "0xFFFFFF";
return _ChardataStatic.getCharColor();
}
public int getCharSex()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharSex();
}
public int getCharHero()
{
if (_ChardataStatic == null)
return 0;
return _ChardataStatic.getCharHero();
}
//add by L2CN>
L2NpcTemplate.java;
文件头加入
//add by L2CN<
import com.l2jserver.gameserver.model.L2NpcCharData;
//add by L2CN>
搜索
public L2NpcAIData getAIDataStatic()
{
return _AIdataStatic;
}
在其后加入
//add by L2CN<
public L2NpcCharData getCharDataStatic()
{
return _ChardataStatic;
}
//add by L2CN>
搜索
public boolean isUndead()
{
return _race == Race.UNDEAD;
}
在其后加入
//add by L2CN<
public void setCharData(L2NpcCharData chardata)
{
_ChardataStatic = new L2NpcCharData();
_ChardataStatic = chardata;
}
//add by L2CN>
AbstractNpcInfo.java;
因格式问题,请完整替换文件代码。
/*
* This program 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.
*
* 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 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 <http://www.gnu.org/licenses/>.
*/
package com.l2jserver.gameserver.network.serverpackets;
import com.l2jserver.Config;
import com.l2jserver.gameserver.datatables.ClanTable;
import com.l2jserver.gameserver.instancemanager.TownManager;
import com.l2jserver.gameserver.model.L2Clan;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.L2Summon;
import com.l2jserver.gameserver.model.actor.L2Trap;
import com.l2jserver.gameserver.model.actor.instance.L2MonsterInstance;
import com.l2jserver.gameserver.model.actor.instance.L2NpcInstance;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.effects.AbnormalEffect;
import com.l2jserver.gameserver.datatables.MessageTable;
/**
* This class ...
*
* @version $Revision: 1.7.2.4.2.9 $ $Date: 2005/04/11 10:05:54 $
*/
public abstract class AbstractNpcInfo extends L2GameServerPacket
{
// ddddddddddddddddddffffdddcccccSSddd dddddc
// ddddddddddddddddddffffdddcccccSSddd dddddccffd
private static final String _S__22_NPCINFO = "[S] 0c NpcInfo";
protected int _x, _y, _z, _heading;
protected int _idTemplate;
protected boolean _isAttackable, _isSummoned;
protected int _mAtkSpd, _pAtkSpd;
/**
* Run speed, swimming run speed and flying run speed
*/
protected int _runSpd;
/**
* Walking speed, swimming walking speed and flying walking speed
*/
protected int _walkSpd;
@Override
public String getType()
{
return _S__22_NPCINFO;
}
/**
* Packet for Npcs
*/
public static class NpcInfo extends AbstractNpcInfo
{
private final L2Npc _npc;
private int _clanCrest = 0;
private int _allyCrest = 0;
private int _allyId = 0;
private int _clanId = 0;
private int _displayEffect = 0;
public NpcInfo(L2Npc cha, L2Character attacker)
{
super(cha);
_npc = cha;
_idTemplate = cha.getTemplate().getIdTemplate(); // On every subclass
_rhand = cha.getRightHandItem(); // On every subclass
_lhand = cha.getLeftHandItem(); // On every subclass
_enchantEffect = cha.getEnchantEffect();
_collisionHeight = cha.getCollisionHeight();// On every subclass
_collisionRadius = cha.getCollisionRadius();// On every subclass
_isAttackable = cha.isAutoAttackable(attacker);
if (cha.getTemplate().isServerSideName())
_name = cha.getName();// On every subclass
if (Config.L2JMOD_CHAMPION_ENABLE && cha.isChampion())
_title = (Config.L2JMOD_CHAMP_TITLE); // On every subclass
else if (cha.getTemplate().isServerSideTitle())
_title = cha.getTemplate().getTitle(); // On every subclass
else
_title = cha.getTitle(); // On every subclass
if (Config.SHOW_NPC_LVL && _npc instanceof L2MonsterInstance)
{
/* Move To MessageTable For L2JTW
String t = "Lv " + cha.getLevel() + (cha.getAggroRange() > 0 ? "*" : "");
*/
String t = MessageTable.Messages[211].getExtra(1) + cha.getLevel() + (cha.getAggroRange() > 0 ? MessageTable.Messages[211].getExtra(2) : "");
if (_title != null)
t += " " + _title;
writeD(_runSpd); // TODO: the order of the speeds should be confirmed
writeD(_walkSpd);
writeD(_runSpd); // swim run speed
writeD(_walkSpd); // swim walk speed
writeD(_runSpd); // fly run speed
writeD(_walkSpd); // fly walk speed
writeD(_runSpd); // fly run speed ?
writeD(_walkSpd); // fly walk speed ?
writeF(_runSpd * 1f / 120); // _activeChar.getProperMultiplier()
writeF(((1.1) * _pAtkSpd / 300)); // _activeChar.getAttackSpeedMultiplier()
writeF(_collisionRadius);
writeF(_collisionHeight);
writeC(0); // 1-on Strider, 2-on Wyvern, 3-on Great Wolf, 0-no mount
writeC(1); // 1 - sellshop
writeH(0);
writeC(0x00);
writeD(_npc.getAbnormalEffect());
writeC(0); //Changed by Thorgrim
writeH(0); //Blue value for name (0 = white, 255 = pure blue)
writeD(0);
writeD(charclass);
writeD(0);
writeC(enchlvl);
writeC(0x00); //team circle around feet 1= Blue, 2 = red
writeD(0);
writeC(0);
writeC(charhero); // Hero Aura
writeC(0); //0x01: Fishing Mode (Cant be undone by setting back to 0)
writeD(0);
writeD(0);
writeD(0);
writeD(charcolor);
writeD(_heading); // isRunning() as in UserInfo?
writeD(0);
writeD(0); // ??
writeD(0xFFFF77);
writeD(0x00);
writeD(0x00);
// T1
writeD(0x00);
writeD(0x00);
// T2
writeD(0x01);
// T2.3
writeD(_npc.getSpecialEffect());
}
else
//add by L2CN>
{
writeC(0x0c);
writeD(_npc.getObjectId());
writeD(_idTemplate + 1000000); // npctype id
writeD(_isAttackable ? 1 : 0);
writeD(_x);
writeD(_y);
writeD(_z);
writeD(_heading);
writeD(0x00);
writeD(_mAtkSpd);
writeD(_pAtkSpd);
writeD(_runSpd);
writeD(_walkSpd);
writeD(_runSpd); // swim run speed
writeD(_walkSpd); // swim walk speed
writeD(_runSpd); // swim run speed
writeD(_walkSpd); // swim walk speed
writeD(_runSpd); // fly run speed
writeD(_walkSpd); // fly run speed
writeF(_npc.getMovementSpeedMultiplier());
writeF(_npc.getAttackSpeedMultiplier());
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(_rhand); // right hand weapon
writeD(_chest);
writeD(_lhand); // left hand weapon
writeC(1); // name above char 1=true ... ??
writeC(_npc.isRunning() ? 1 : 0);
writeC(_npc.isInCombat() ? 1 : 0);
writeC(_npc.isAlikeDead() ? 1 : 0);
writeC(_isSummoned ? 2 : 0); // 0=teleported 1=default 2=summoned
writeD(-1); // High Five NPCString ID
writeS(_name);
writeD(-1); // High Five NPCString ID
writeS(_title);
writeD(0x00); // Title color 0=client default
writeD(0x00); //pvp flag
writeD(0x00); // karma
writeD(_npc.getAbnormalEffect()); // C2
writeD(_clanId); //clan id
writeD(_clanCrest); //crest id
writeD(_allyId); // ally id
writeD(_allyCrest); // all crest
writeC(_npc.isFlying() ? 2 : 0); // C2
writeC(_npc.getTeam()); // team color 0=none, 1 = blue, 2 = red
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(_enchantEffect); // C4
writeD(_npc.isFlying() ? 1 : 0); // C6
writeD(0x00);
writeD(_npc.getColorEffect());// CT1.5 Pet form and skills, Color effect
writeC(_npc.isShowName() ? 0x01 : 0x00);
writeC(_npc.isTargetable() ? 0x01 : 0x00);
writeD(_npc.getSpecialEffect());
writeD(_displayEffect);
}
}
}
public static class TrapInfo extends AbstractNpcInfo
{
private final L2Trap _trap;
public TrapInfo(L2Trap cha, L2Character attacker)
{
super(cha);
writeD(_trap.getAbnormalEffect()); // C2
writeD(0x00); //clan id
writeD(0x00); //crest id
writeD(0000); // C2
writeD(0000); // C2
writeC(0000); // C2
writeC(_trap.getTeam()); // team color 0=none, 1 = blue, 2 = red
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(0x00); // C4
writeD(0x00); // C6
writeD(0x00);
writeD(0);//CT1.5 Pet form and skills
writeC(0x01);
writeC(0x01);
writeD(0x00);
}
}
/**
* Packet for summons
*/
public static class SummonInfo extends AbstractNpcInfo
{
private final L2Summon _summon;
private int _form = 0;
private int _val = 0;
public SummonInfo(L2Summon cha, L2Character attacker, int val)
{
super(cha);
_summon = cha;
_val = val;
if (_summon.isShowSummonAnimation())
_val = 2; //override for spawn
int npcId = cha.getTemplate().getNpcId();
if (npcId == 16041 || npcId == 16042)
{
if (cha.getLevel() > 84)
_form = 3;
else if (cha.getLevel() > 79)
_form = 2;
else if (cha.getLevel() > 74)
_form = 1;
}
else if (npcId == 16025 || npcId == 16037)
{
if (cha.getLevel() > 69)
_form = 3;
else if (cha.getLevel() > 64)
_form = 2;
else if (cha.getLevel() > 59)
_form = 1;
}
// fields not set on AbstractNpcInfo
_isAttackable = cha.isAutoAttackable(attacker);
_rhand = cha.getWeapon();
_lhand = 0;
_chest = cha.getArmor();
_enchantEffect = cha.getTemplate().getEnchantEffect();
_name = cha.getName();
_title = cha.getOwner() != null ? ((!cha.getOwner().isOnline()) ? "" : cha.getOwner().getName()) : ""; // when owner online, summon will show in title owner name
_idTemplate = cha.getTemplate().getIdTemplate();
_collisionHeight = cha.getTemplate().getfCollisionHeight();
_collisionRadius = cha.getTemplate().getfCollisionRadius();
_invisible = cha.getOwner() != null ? cha.getOwner().getAppearance().getInvisible() : false;
//add by L2CN<
if ((cha).getIsChar() > 0)
{
writeD(0x00); //clan id
writeD(0x00); //crest id
writeD(0000); // C2
writeD(0000); // C2
writeC(0000); // C2
writeC(_summon.getTeam()); // team color 0=none, 1 = blue, 2 = red
writeF(_collisionRadius);
writeF(_collisionHeight);
writeD(_enchantEffect); // C4
writeD(0x00); // C6
writeD(0x00);
writeD(_form); //CT1.5 Pet form and skills
writeC(0x01);
writeC(0x01);
writeD(_summon.getSpecialEffect());
}
}
}
}
L2NpcCharData.java;
以下代码请新建JAVA文件放入gameserver\model\L2NpcCharData.java
/*
* This program 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 2, or (at your option)
* any later version.
*
* 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*
* http://www.gnu.org/copyleft/gpl.html
*/
package com.l2jserver.gameserver.model;
import javolution.util.FastList;
/**
* @Author: ShanSoft
* By L2JTW
*/
/**
* This Data is for NPC Attributes and AI relate stuffs...
* Still need to finish...Update later...
*/
public class L2NpcCharData
{
private int _ischar;
private int _charclass;
private int _charrace;
private int _charface;
private int _charhair;
private String _charcolor;
private int _charhaircolor;
private int _charsex;
private int _charhero;
private int _lrhand;
private int _armor;
private int _pant;
private int _head;
private int _boot;
private int _glove;
private int _back;
private int _hair;
private int _dhair;
private int _face;
private int _enchlvl;
private int _augmentation;
private FastList<L2NpcCharData> npcCharData;
public void NpcCharData()
{
npcCharData = new FastList<L2NpcCharData>(0);
}
public FastList<L2NpcCharData> getCharData()
{
return npcCharData;
}
public void addNpcCharData(L2NpcCharData npcdatatable)
{
npcCharData.add(npcdatatable);
}
public int getIsChar()
{
return _ischar;
}
public int getCharClass()
{
return _charclass;
}
public int getCharRace()
{
return _charrace;
}
public int getCharFace()
{
return _charface;
}
public int getCharHair()
{
return _charhair;
}
public int getCharHairColor()
{
return _charhaircolor;
}
public String getCharColor()
{
return _charcolor;
}
public int getCharSex()
{
return _charsex;
}
public int getCharHero()
{
return _charhero;
}
//Gears
public int getArmor()
{
return _armor;
}
public int getPant()
{
return _pant;
}
public int getHead()
{
return _head;
}
public int getLrhand()
{
return _lrhand;
}
public int getGlove()
{
return _glove;
}
public int getBoot()
{
return _boot;
}
public int getBack()
{
return _back;
}
public int getHair()
{
return _hair;
}
public int getDHair()
{
return _dhair;
}
public int getFace()
{
return _face;
}
public int getEnchLvl()
{
return _enchlvl;
}
public int getAugmentation()
{
return _augmentation;
}
}