Refactored fake player system.

This commit is contained in:
MobiusDevelopment 2020-06-30 01:45:28 +00:00
parent c126283ceb
commit c9c46a8c2a
14 changed files with 325 additions and 364 deletions

View File

@ -1,7 +1,7 @@
-- ---------------------------
-- Table structure for `npc_to_pc_polymorph`
-- Table structure for `fake_players`
-- ---------------------------
CREATE TABLE IF NOT EXISTS `npc_to_pc_polymorph` (
CREATE TABLE IF NOT EXISTS `fake_players` (
`spawn` int(9) NOT NULL default '0',
`template` int(9) NOT NULL default '0',
`name` varchar(35) default NULL,

View File

@ -14,7 +14,7 @@
* 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 org.l2jmobius.gameserver.instancemanager;
package org.l2jmobius.gameserver.datatables.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -27,13 +27,13 @@ import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.util.Rnd;
/**
* control for Custom Npcs that look like players.
* Table for custom NPCs that look like players.
* @version 1.00
* @author Darki699
*/
public class CustomNpcInstanceManager
public class FakePlayerTable
{
private static final Logger LOGGER = Logger.getLogger(CustomNpcInstanceManager.class.getName());
private static final Logger LOGGER = Logger.getLogger(FakePlayerTable.class.getName());
private Map<Integer, customInfo> spawns; // <Object id , info>
private Map<Integer, customInfo> templates; // <Npc Template Id , info>
@ -52,7 +52,7 @@ public class CustomNpcInstanceManager
/**
* Constructor Calls to load the data
*/
CustomNpcInstanceManager()
FakePlayerTable()
{
load();
}
@ -75,7 +75,7 @@ public class CustomNpcInstanceManager
}
/**
* Just load the data for mysql...
* Just load the data from mysql...
*/
private final void load()
{
@ -88,7 +88,7 @@ public class CustomNpcInstanceManager
try (Connection con = DatabaseFactory.getConnection())
{
int count = 0;
final PreparedStatement statement = con.prepareStatement("SELECT spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM npc_to_pc_polymorph");
final PreparedStatement statement = con.prepareStatement("SELECT spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM fake_players");
final ResultSet rset = statement.executeQuery();
while (rset.next())
@ -265,7 +265,7 @@ public class CustomNpcInstanceManager
{
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement = con.prepareStatement("REPLACE INTO npc_to_pc_polymorph VALUES spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM npc_to_pc_polymorph");
final PreparedStatement statement = con.prepareStatement("REPLACE INTO fake_players VALUES spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM fake_players");
final ResultSet rset = statement.executeQuery();
statement.close();
@ -284,13 +284,13 @@ public class CustomNpcInstanceManager
}
}
public static CustomNpcInstanceManager getInstance()
public static FakePlayerTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomNpcInstanceManager INSTANCE = new CustomNpcInstanceManager();
protected static final FakePlayerTable INSTANCE = new FakePlayerTable();
}
}

View File

@ -17,15 +17,15 @@
package org.l2jmobius.gameserver.model.actor.instance;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.instancemanager.CustomNpcInstanceManager;
import org.l2jmobius.gameserver.datatables.sql.FakePlayerTable;
import org.l2jmobius.gameserver.model.base.ClassId;
import org.l2jmobius.gameserver.model.items.type.WeaponType;
/**
* This class manages Npc Polymorph into player instances, they look like regular players. This effect will show up on all clients.
* This class manages Fake Player instances, they look like regular players. This effect will show up on all clients.
* @author Darki699
*/
public class CustomNpcInstance
public class FakePlayerInstance
{
private boolean _allowRandomWeapons = true; // Default value
private boolean _allowRandomClass = true; // Default value
@ -39,10 +39,9 @@ public class CustomNpcInstance
private ClassId _classId; // ClassId of this (N)Pc
/**
* A constructor
* @param myNpc - Receives the NpcInstance as a reference.
*/
public CustomNpcInstance(NpcInstance myNpc)
public FakePlayerInstance(NpcInstance myNpc)
{
_npcInstance = myNpc;
if ((_npcInstance != null) && (_npcInstance.getSpawn() != null))
@ -65,15 +64,15 @@ public class CustomNpcInstance
_boolean = new boolean[4]; // pvp=0 , noble=1, hero=2, isFemaleSex=3
// load the Pc Morph Data
final CustomNpcInstanceManager.customInfo ci = CustomNpcInstanceManager.getInstance().getCustomData(_npcInstance.getSpawn().getId(), _npcInstance.getNpcId());
final FakePlayerTable.customInfo ci = FakePlayerTable.getInstance().getCustomData(_npcInstance.getSpawn().getId(), _npcInstance.getNpcId());
if (ci == null)
{
_npcInstance.setCustomNpcInstance(null);
_npcInstance.setFakePlayerInstance(null);
_npcInstance = null;
return;
}
_npcInstance.setCustomNpcInstance(this);
_npcInstance.setFakePlayerInstance(this);
setPcInstanceData(ci);
@ -445,7 +444,7 @@ public class CustomNpcInstance
* Sets the data received from the CustomNpcInstanceManager
* @param ci the customInfo data
*/
public void setPcInstanceData(CustomNpcInstanceManager.customInfo ci)
public void setPcInstanceData(FakePlayerTable.customInfo ci)
{
if (ci == null)
{

View File

@ -29,6 +29,7 @@ import org.l2jmobius.gameserver.datatables.ItemTable;
import org.l2jmobius.gameserver.datatables.MobGroupTable;
import org.l2jmobius.gameserver.datatables.SkillTable;
import org.l2jmobius.gameserver.datatables.sql.ClanTable;
import org.l2jmobius.gameserver.datatables.sql.FakePlayerTable;
import org.l2jmobius.gameserver.datatables.sql.HelperBuffTable;
import org.l2jmobius.gameserver.datatables.sql.SpawnTable;
import org.l2jmobius.gameserver.datatables.xml.MultisellData;
@ -36,7 +37,6 @@ import org.l2jmobius.gameserver.datatables.xml.ZoneData;
import org.l2jmobius.gameserver.enums.ChatType;
import org.l2jmobius.gameserver.idfactory.IdFactory;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.CustomNpcInstanceManager;
import org.l2jmobius.gameserver.instancemanager.DimensionalRiftManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
@ -108,7 +108,7 @@ public class NpcInstance extends Creature
protected static final Logger LOGGER = Logger.getLogger(NpcInstance.class.getName());
public static final int INTERACTION_DISTANCE = 150;
private CustomNpcInstance _customNpcInstance;
private FakePlayerInstance _fakePlayerInstance;
private Spawn _spawn;
private boolean _isBusy = false;
private String _busyMessage = "";
@ -2683,9 +2683,9 @@ public class NpcInstance extends Creature
{
_spawn = spawn;
// Does this Npc morph into a PlayerInstance?
if ((_spawn != null) && CustomNpcInstanceManager.getInstance().isCustomNpcInstance(_spawn.getId(), getNpcId()))
if ((_spawn != null) && FakePlayerTable.getInstance().isCustomNpcInstance(_spawn.getId(), getNpcId()))
{
new CustomNpcInstance(this);
new FakePlayerInstance(this);
}
}
@ -2867,21 +2867,21 @@ public class NpcInstance extends Creature
}
/**
* Gets the custom npc instance.
* @return the custom npc instance
* Gets the fake player instance.
* @return the fake player instance
*/
public CustomNpcInstance getCustomNpcInstance()
public FakePlayerInstance getFakePlayerInstance()
{
return _customNpcInstance;
return _fakePlayerInstance;
}
/**
* Sets the custom npc instance.
* @param arg the new custom npc instance
* Sets the fake player instance.
* @param value the new fake player instance
*/
public void setCustomNpcInstance(CustomNpcInstance arg)
public void setFakePlayerInstance(FakePlayerInstance value)
{
_customNpcInstance = arg;
_fakePlayerInstance = value;
}
@Override

View File

@ -1,147 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.gameserver.datatables.xml.PlayerTemplateData;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
public class CustomNpcInfo extends GameServerPacket
{
private final NpcInstance _activeChar;
/**
* @param cha
*/
public CustomNpcInfo(NpcInstance cha)
{
_activeChar = cha;
_activeChar.setClientX(_activeChar.getPosition().getX());
_activeChar.setClientY(_activeChar.getPosition().getY());
_activeChar.setClientZ(_activeChar.getPosition().getZ());
}
@Override
protected final void writeImpl()
{
writeC(0x03);
writeD(_activeChar.getX());
writeD(_activeChar.getY());
writeD(_activeChar.getZ());
writeD(_activeChar.getHeading());
writeD(_activeChar.getObjectId());
writeS(_activeChar.getCustomNpcInstance().getName());
writeD(_activeChar.getCustomNpcInstance().getRace());
writeD(_activeChar.getCustomNpcInstance().isFemaleSex() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getClassId());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_LHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_GLOVES());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_CHEST());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_LEGS());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_FEET());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR2());
write('H', 0, 24);
writeD(_activeChar.getCustomNpcInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getKarma());
writeD(_activeChar.getMAtkSpd());
writeD(_activeChar.getPAtkSpd());
writeD(_activeChar.getCustomNpcInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getKarma());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed() / 2);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeF(_activeChar.getStat().getMovementSpeedMultiplier());
writeF(_activeChar.getStat().getAttackSpeedMultiplier());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getCustomNpcInstance().getClassId()).getCollisionRadius());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getCustomNpcInstance().getClassId()).getCollisionHeight());
writeD(_activeChar.getCustomNpcInstance().getHairStyle());
writeD(_activeChar.getCustomNpcInstance().getHairColor());
writeD(_activeChar.getCustomNpcInstance().getFace());
writeS(_activeChar.getCustomNpcInstance().getTitle());
writeD(_activeChar.getCustomNpcInstance().getClanId());
writeD(_activeChar.getCustomNpcInstance().getClanCrestId());
writeD(_activeChar.getCustomNpcInstance().getAllyId());
writeD(_activeChar.getCustomNpcInstance().getAllyCrestId());
writeD(0);
writeC(1);
writeC(_activeChar.isRunning() ? 1 : 0);
writeC(_activeChar.isInCombat() ? 1 : 0);
writeC(_activeChar.isAlikeDead() ? 1 : 0);
write('C', 0, 3);
writeH(0);
writeC(0x00);
writeD(_activeChar.getAbnormalEffect());
writeC(0);
writeH(0);
writeD(_activeChar.getCustomNpcInstance().getClassId());
writeD(_activeChar.getMaxCp());
writeD((int) _activeChar.getStatus().getCurrentCp());
writeC(_activeChar.getCustomNpcInstance().getEnchantWeapon());
writeC(0x00);
writeD(0); // clan crest
writeC(_activeChar.getCustomNpcInstance().isNoble() ? 1 : 0);
writeC(_activeChar.getCustomNpcInstance().isHero() ? 1 : 0);
writeC(0);
write('D', 0, 3);
writeD(_activeChar.getCustomNpcInstance().nameColor());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().getPledgeClass());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().titleColor());
writeD(0x00);
}
private final void write(char type, int value, int times)
{
for (int i = 0; i < times; i++)
{
switch (type)
{
case 'C':
{
writeC(value);
break;
}
case 'D':
{
writeD(value);
break;
}
case 'F':
{
writeF(value);
break;
}
case 'H':
{
writeH(value);
break;
}
}
}
}
}

View File

@ -0,0 +1,112 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.gameserver.datatables.xml.PlayerTemplateData;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
public class FakePlayerInfo extends GameServerPacket
{
private final NpcInstance _activeChar;
public FakePlayerInfo(NpcInstance cha)
{
_activeChar = cha;
_activeChar.setClientX(_activeChar.getPosition().getX());
_activeChar.setClientY(_activeChar.getPosition().getY());
_activeChar.setClientZ(_activeChar.getPosition().getZ());
}
@Override
protected final void writeImpl()
{
writeC(0x03);
writeD(_activeChar.getX());
writeD(_activeChar.getY());
writeD(_activeChar.getZ());
writeD(_activeChar.getHeading());
writeD(_activeChar.getObjectId());
writeS(_activeChar.getFakePlayerInstance().getName());
writeD(_activeChar.getFakePlayerInstance().getRace());
writeD(_activeChar.getFakePlayerInstance().isFemaleSex() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getClassId());
writeD(0);
writeD(0);
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_LHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_GLOVES());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_CHEST());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_LEGS());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_FEET());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getFakePlayerInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getKarma());
writeD(_activeChar.getMAtkSpd());
writeD(_activeChar.getPAtkSpd());
writeD(_activeChar.getFakePlayerInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getKarma());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed() / 2);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeF(_activeChar.getStat().getMovementSpeedMultiplier());
writeF(_activeChar.getStat().getAttackSpeedMultiplier());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getFakePlayerInstance().getClassId()).getCollisionRadius());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getFakePlayerInstance().getClassId()).getCollisionHeight());
writeD(_activeChar.getFakePlayerInstance().getHairStyle());
writeD(_activeChar.getFakePlayerInstance().getHairColor());
writeD(_activeChar.getFakePlayerInstance().getFace());
writeS(_activeChar.getFakePlayerInstance().getTitle());
writeD(_activeChar.getFakePlayerInstance().getClanId());
writeD(_activeChar.getFakePlayerInstance().getClanCrestId());
writeD(_activeChar.getFakePlayerInstance().getAllyId());
writeD(_activeChar.getFakePlayerInstance().getAllyCrestId());
writeD(0);
writeC(1);
writeC(_activeChar.isRunning() ? 1 : 0);
writeC(_activeChar.isInCombat() ? 1 : 0);
writeC(_activeChar.isAlikeDead() ? 1 : 0);
writeC(0);
writeC(0);
writeC(0);
writeH(0);
writeC(0);
writeD(_activeChar.getAbnormalEffect());
writeC(0);
writeH(0);
writeD(_activeChar.getFakePlayerInstance().getClassId());
writeD(_activeChar.getMaxCp());
writeD((int) _activeChar.getStatus().getCurrentCp());
writeC(_activeChar.getFakePlayerInstance().getEnchantWeapon());
writeC(0);
writeD(0); // clan crest
writeC(_activeChar.getFakePlayerInstance().isNoble() ? 1 : 0);
writeC(_activeChar.getFakePlayerInstance().isHero() ? 1 : 0);
writeC(0);
writeD(0);
writeD(0);
writeD(0);
writeD(_activeChar.getFakePlayerInstance().nameColor());
}
}

View File

@ -61,12 +61,13 @@ public class NpcInfo extends GameServerPacket
*/
public NpcInfo(NpcInstance cha, Creature attacker)
{
if (cha.getCustomNpcInstance() != null)
if (cha.getFakePlayerInstance() != null)
{
attacker.sendPacket(new CustomNpcInfo(cha));
attacker.sendPacket(new FakePlayerInfo(cha));
attacker.broadcastPacket(new FinishRotation(cha));
return;
}
_creature = cha;
_displayId = cha.getTemplate().getDisplayId();
_isAttackable = cha.isAutoAttackable(attacker);

View File

@ -1,7 +1,7 @@
-- ---------------------------
-- Table structure for `npc_to_pc_polymorph`
-- Table structure for `fake_players`
-- ---------------------------
CREATE TABLE IF NOT EXISTS `npc_to_pc_polymorph` (
CREATE TABLE IF NOT EXISTS `fake_players` (
`spawn` int(9) NOT NULL default '0',
`template` int(9) NOT NULL default '0',
`name` varchar(35) default NULL,

View File

@ -14,7 +14,7 @@
* 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 org.l2jmobius.gameserver.instancemanager;
package org.l2jmobius.gameserver.datatables.sql;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -27,13 +27,13 @@ import org.l2jmobius.commons.database.DatabaseFactory;
import org.l2jmobius.commons.util.Rnd;
/**
* control for Custom Npcs that look like players.
* Table for custom NPCs that look like players.
* @version 1.00
* @author Darki699
*/
public class CustomNpcInstanceManager
public class FakePlayerTable
{
private static final Logger LOGGER = Logger.getLogger(CustomNpcInstanceManager.class.getName());
private static final Logger LOGGER = Logger.getLogger(FakePlayerTable.class.getName());
private Map<Integer, customInfo> spawns; // <Object id , info>
private Map<Integer, customInfo> templates; // <Npc Template Id , info>
@ -52,7 +52,7 @@ public class CustomNpcInstanceManager
/**
* Constructor Calls to load the data
*/
CustomNpcInstanceManager()
FakePlayerTable()
{
load();
}
@ -75,7 +75,7 @@ public class CustomNpcInstanceManager
}
/**
* Just load the data for mysql...
* Just load the data from mysql...
*/
private final void load()
{
@ -88,7 +88,7 @@ public class CustomNpcInstanceManager
try (Connection con = DatabaseFactory.getConnection())
{
int count = 0;
final PreparedStatement statement = con.prepareStatement("SELECT spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM npc_to_pc_polymorph");
final PreparedStatement statement = con.prepareStatement("SELECT spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM fake_players");
final ResultSet rset = statement.executeQuery();
while (rset.next())
@ -265,7 +265,7 @@ public class CustomNpcInstanceManager
{
try (Connection con = DatabaseFactory.getConnection())
{
final PreparedStatement statement = con.prepareStatement("REPLACE INTO npc_to_pc_polymorph VALUES spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM npc_to_pc_polymorph");
final PreparedStatement statement = con.prepareStatement("REPLACE INTO fake_players VALUES spawn,template,name,title,class_id,female,hair_style,hair_color,face,name_color,title_color, noble,hero,pvp,karma,wpn_enchant,right_hand,left_hand,gloves,chest,legs,feet,hair,hair2, pledge,cw_level,clan_id,ally_id,clan_crest,ally_crest,rnd_class,rnd_appearance,rnd_weapon,rnd_armor,max_rnd_enchant FROM fake_players");
final ResultSet rset = statement.executeQuery();
statement.close();
@ -284,13 +284,13 @@ public class CustomNpcInstanceManager
}
}
public static CustomNpcInstanceManager getInstance()
public static FakePlayerTable getInstance()
{
return SingletonHolder.INSTANCE;
}
private static class SingletonHolder
{
protected static final CustomNpcInstanceManager INSTANCE = new CustomNpcInstanceManager();
protected static final FakePlayerTable INSTANCE = new FakePlayerTable();
}
}

View File

@ -17,15 +17,15 @@
package org.l2jmobius.gameserver.model.actor.instance;
import org.l2jmobius.commons.util.Rnd;
import org.l2jmobius.gameserver.instancemanager.CustomNpcInstanceManager;
import org.l2jmobius.gameserver.datatables.sql.FakePlayerTable;
import org.l2jmobius.gameserver.model.base.ClassId;
import org.l2jmobius.gameserver.model.items.type.WeaponType;
/**
* This class manages Npc Polymorph into player instances, they look like regular players. This effect will show up on all clients.
* This class manages Fake Player instances, they look like regular players. This effect will show up on all clients.
* @author Darki699
*/
public class CustomNpcInstance
public class FakePlayerInstance
{
private boolean _allowRandomWeapons = true; // Default value
private boolean _allowRandomClass = true; // Default value
@ -39,10 +39,9 @@ public class CustomNpcInstance
private ClassId _classId; // ClassId of this (N)Pc
/**
* A constructor
* @param myNpc - Receives the NpcInstance as a reference.
*/
public CustomNpcInstance(NpcInstance myNpc)
public FakePlayerInstance(NpcInstance myNpc)
{
_npcInstance = myNpc;
if ((_npcInstance != null) && (_npcInstance.getSpawn() != null))
@ -65,15 +64,15 @@ public class CustomNpcInstance
_boolean = new boolean[4]; // pvp=0 , noble=1, hero=2, isFemaleSex=3
// load the Pc Morph Data
final CustomNpcInstanceManager.customInfo ci = CustomNpcInstanceManager.getInstance().getCustomData(_npcInstance.getSpawn().getId(), _npcInstance.getNpcId());
final FakePlayerTable.customInfo ci = FakePlayerTable.getInstance().getCustomData(_npcInstance.getSpawn().getId(), _npcInstance.getNpcId());
if (ci == null)
{
_npcInstance.setCustomNpcInstance(null);
_npcInstance.setFakePlayerInstance(null);
_npcInstance = null;
return;
}
_npcInstance.setCustomNpcInstance(this);
_npcInstance.setFakePlayerInstance(this);
setPcInstanceData(ci);
@ -445,7 +444,7 @@ public class CustomNpcInstance
* Sets the data received from the CustomNpcInstanceManager
* @param ci the customInfo data
*/
public void setPcInstanceData(CustomNpcInstanceManager.customInfo ci)
public void setPcInstanceData(FakePlayerTable.customInfo ci)
{
if (ci == null)
{

View File

@ -29,6 +29,7 @@ import org.l2jmobius.gameserver.datatables.ItemTable;
import org.l2jmobius.gameserver.datatables.MobGroupTable;
import org.l2jmobius.gameserver.datatables.SkillTable;
import org.l2jmobius.gameserver.datatables.sql.ClanTable;
import org.l2jmobius.gameserver.datatables.sql.FakePlayerTable;
import org.l2jmobius.gameserver.datatables.sql.HelperBuffTable;
import org.l2jmobius.gameserver.datatables.sql.SpawnTable;
import org.l2jmobius.gameserver.datatables.xml.MultisellData;
@ -36,7 +37,6 @@ import org.l2jmobius.gameserver.datatables.xml.ZoneData;
import org.l2jmobius.gameserver.enums.ChatType;
import org.l2jmobius.gameserver.idfactory.IdFactory;
import org.l2jmobius.gameserver.instancemanager.CastleManager;
import org.l2jmobius.gameserver.instancemanager.CustomNpcInstanceManager;
import org.l2jmobius.gameserver.instancemanager.DimensionalRiftManager;
import org.l2jmobius.gameserver.instancemanager.FortManager;
import org.l2jmobius.gameserver.instancemanager.QuestManager;
@ -110,7 +110,7 @@ public class NpcInstance extends Creature
protected static final Logger LOGGER = Logger.getLogger(NpcInstance.class.getName());
public static final int INTERACTION_DISTANCE = 150;
private CustomNpcInstance _customNpcInstance;
private FakePlayerInstance _fakePlayerInstance;
private Spawn _spawn;
private boolean _isBusy = false;
private String _busyMessage = "";
@ -2886,9 +2886,9 @@ public class NpcInstance extends Creature
{
_spawn = spawn;
// Does this Npc morph into a PlayerInstance?
if ((_spawn != null) && CustomNpcInstanceManager.getInstance().isCustomNpcInstance(_spawn.getId(), getNpcId()))
if ((_spawn != null) && FakePlayerTable.getInstance().isCustomNpcInstance(_spawn.getId(), getNpcId()))
{
new CustomNpcInstance(this);
new FakePlayerInstance(this);
}
}
@ -3070,21 +3070,21 @@ public class NpcInstance extends Creature
}
/**
* Gets the custom npc instance.
* @return the custom npc instance
* Gets the fake player instance.
* @return the fake player instance
*/
public CustomNpcInstance getCustomNpcInstance()
public FakePlayerInstance getFakePlayerInstance()
{
return _customNpcInstance;
return _fakePlayerInstance;
}
/**
* Sets the custom npc instance.
* @param arg the new custom npc instance
* Sets the fake player instance.
* @param value the new fake player instance
*/
public void setCustomNpcInstance(CustomNpcInstance arg)
public void setFakePlayerInstance(FakePlayerInstance value)
{
_customNpcInstance = arg;
_fakePlayerInstance = value;
}
@Override

View File

@ -1,147 +0,0 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.gameserver.datatables.xml.PlayerTemplateData;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
public class CustomNpcInfo extends GameServerPacket
{
private final NpcInstance _activeChar;
/**
* @param cha
*/
public CustomNpcInfo(NpcInstance cha)
{
_activeChar = cha;
_activeChar.setClientX(_activeChar.getPosition().getX());
_activeChar.setClientY(_activeChar.getPosition().getY());
_activeChar.setClientZ(_activeChar.getPosition().getZ());
}
@Override
protected final void writeImpl()
{
writeC(0x03);
writeD(_activeChar.getX());
writeD(_activeChar.getY());
writeD(_activeChar.getZ());
writeD(_activeChar.getHeading());
writeD(_activeChar.getObjectId());
writeS(_activeChar.getCustomNpcInstance().getName());
writeD(_activeChar.getCustomNpcInstance().getRace());
writeD(_activeChar.getCustomNpcInstance().isFemaleSex() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getClassId());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_LHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_GLOVES());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_CHEST());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_LEGS());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_FEET());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getCustomNpcInstance().PAPERDOLL_HAIR2());
write('H', 0, 24);
writeD(_activeChar.getCustomNpcInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getKarma());
writeD(_activeChar.getMAtkSpd());
writeD(_activeChar.getPAtkSpd());
writeD(_activeChar.getCustomNpcInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getCustomNpcInstance().getKarma());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed() / 2);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeF(_activeChar.getStat().getMovementSpeedMultiplier());
writeF(_activeChar.getStat().getAttackSpeedMultiplier());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getCustomNpcInstance().getClassId()).getCollisionRadius());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getCustomNpcInstance().getClassId()).getCollisionHeight());
writeD(_activeChar.getCustomNpcInstance().getHairStyle());
writeD(_activeChar.getCustomNpcInstance().getHairColor());
writeD(_activeChar.getCustomNpcInstance().getFace());
writeS(_activeChar.getCustomNpcInstance().getTitle());
writeD(_activeChar.getCustomNpcInstance().getClanId());
writeD(_activeChar.getCustomNpcInstance().getClanCrestId());
writeD(_activeChar.getCustomNpcInstance().getAllyId());
writeD(_activeChar.getCustomNpcInstance().getAllyCrestId());
writeD(0);
writeC(1);
writeC(_activeChar.isRunning() ? 1 : 0);
writeC(_activeChar.isInCombat() ? 1 : 0);
writeC(_activeChar.isAlikeDead() ? 1 : 0);
write('C', 0, 3);
writeH(0);
writeC(0x00);
writeD(_activeChar.getAbnormalEffect());
writeC(0);
writeH(0);
writeD(_activeChar.getCustomNpcInstance().getClassId());
writeD(_activeChar.getMaxCp());
writeD((int) _activeChar.getStatus().getCurrentCp());
writeC(_activeChar.getCustomNpcInstance().getEnchantWeapon());
writeC(0x00);
writeD(0); // clan crest
writeC(_activeChar.getCustomNpcInstance().isNoble() ? 1 : 0);
writeC(_activeChar.getCustomNpcInstance().isHero() ? 1 : 0);
writeC(0);
write('D', 0, 3);
writeD(_activeChar.getCustomNpcInstance().nameColor());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().getPledgeClass());
writeD(0);
writeD(_activeChar.getCustomNpcInstance().titleColor());
writeD(0x00);
}
private final void write(char type, int value, int times)
{
for (int i = 0; i < times; i++)
{
switch (type)
{
case 'C':
{
writeC(value);
break;
}
case 'D':
{
writeD(value);
break;
}
case 'F':
{
writeF(value);
break;
}
case 'H':
{
writeH(value);
break;
}
}
}
}
}

View File

@ -0,0 +1,143 @@
/*
* This file is part of the L2J Mobius project.
*
* 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 org.l2jmobius.gameserver.network.serverpackets;
import org.l2jmobius.gameserver.datatables.xml.PlayerTemplateData;
import org.l2jmobius.gameserver.model.actor.instance.NpcInstance;
public class FakePlayerInfo extends GameServerPacket
{
private final NpcInstance _activeChar;
public FakePlayerInfo(NpcInstance cha)
{
_activeChar = cha;
_activeChar.setClientX(_activeChar.getPosition().getX());
_activeChar.setClientY(_activeChar.getPosition().getY());
_activeChar.setClientZ(_activeChar.getPosition().getZ());
}
@Override
protected final void writeImpl()
{
writeC(0x03);
writeD(_activeChar.getX());
writeD(_activeChar.getY());
writeD(_activeChar.getZ());
writeD(_activeChar.getHeading());
writeD(_activeChar.getObjectId());
writeS(_activeChar.getFakePlayerInstance().getName());
writeD(_activeChar.getFakePlayerInstance().getRace());
writeD(_activeChar.getFakePlayerInstance().isFemaleSex() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getClassId());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR());
writeD(0);
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_LHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_GLOVES());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_CHEST());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_LEGS());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_FEET());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_RHAND());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR());
writeD(_activeChar.getFakePlayerInstance().PAPERDOLL_HAIR2());
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeH(0);
writeD(_activeChar.getFakePlayerInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getKarma());
writeD(_activeChar.getMAtkSpd());
writeD(_activeChar.getPAtkSpd());
writeD(_activeChar.getFakePlayerInstance().getPvpFlag() ? 1 : 0);
writeD(_activeChar.getFakePlayerInstance().getKarma());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed() / 2);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed() / 3);
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeD(_activeChar.getRunSpeed());
writeF(_activeChar.getStat().getMovementSpeedMultiplier());
writeF(_activeChar.getStat().getAttackSpeedMultiplier());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getFakePlayerInstance().getClassId()).getCollisionRadius());
writeF(PlayerTemplateData.getInstance().getTemplate(_activeChar.getFakePlayerInstance().getClassId()).getCollisionHeight());
writeD(_activeChar.getFakePlayerInstance().getHairStyle());
writeD(_activeChar.getFakePlayerInstance().getHairColor());
writeD(_activeChar.getFakePlayerInstance().getFace());
writeS(_activeChar.getFakePlayerInstance().getTitle());
writeD(_activeChar.getFakePlayerInstance().getClanId());
writeD(_activeChar.getFakePlayerInstance().getClanCrestId());
writeD(_activeChar.getFakePlayerInstance().getAllyId());
writeD(_activeChar.getFakePlayerInstance().getAllyCrestId());
writeD(0);
writeC(1);
writeC(_activeChar.isRunning() ? 1 : 0);
writeC(_activeChar.isInCombat() ? 1 : 0);
writeC(_activeChar.isAlikeDead() ? 1 : 0);
writeC(0);
writeC(0);
writeC(0);
writeH(0);
writeC(0);
writeD(_activeChar.getAbnormalEffect());
writeC(0);
writeH(0);
writeD(_activeChar.getFakePlayerInstance().getClassId());
writeD(_activeChar.getMaxCp());
writeD((int) _activeChar.getStatus().getCurrentCp());
writeC(_activeChar.getFakePlayerInstance().getEnchantWeapon());
writeC(0);
writeD(0); // clan crest
writeC(_activeChar.getFakePlayerInstance().isNoble() ? 1 : 0);
writeC(_activeChar.getFakePlayerInstance().isHero() ? 1 : 0);
writeC(0);
writeD(0);
writeD(0);
writeD(0);
writeD(_activeChar.getFakePlayerInstance().nameColor());
writeD(0);
writeD(_activeChar.getFakePlayerInstance().getPledgeClass());
writeD(0);
writeD(_activeChar.getFakePlayerInstance().titleColor());
writeD(0x00);
}
}

View File

@ -61,12 +61,13 @@ public class NpcInfo extends GameServerPacket
*/
public NpcInfo(NpcInstance cha, Creature attacker)
{
if (cha.getCustomNpcInstance() != null)
if (cha.getFakePlayerInstance() != null)
{
attacker.sendPacket(new CustomNpcInfo(cha));
attacker.sendPacket(new FakePlayerInfo(cha));
attacker.broadcastPacket(new FinishRotation(cha));
return;
}
_creature = cha;
_displayId = cha.getTemplate().getDisplayId();
_isAttackable = cha.isAutoAttackable(attacker);