Let PacketCreator create Packet - initial test

This commit is contained in:
P0nk
2021-08-20 16:12:56 +02:00
parent d8b0929975
commit b5cd6887ae
4 changed files with 26 additions and 20 deletions
+6
View File
@@ -38,6 +38,7 @@ import constants.game.ExpTable;
import constants.game.GameConstants; import constants.game.GameConstants;
import constants.inventory.ItemConstants; import constants.inventory.ItemConstants;
import constants.skills.*; import constants.skills.*;
import net.packet.Packet;
import net.server.PlayerBuffValueHolder; import net.server.PlayerBuffValueHolder;
import net.server.PlayerCoolDownValueHolder; import net.server.PlayerCoolDownValueHolder;
import net.server.Server; import net.server.Server;
@@ -10048,10 +10049,15 @@ public class MapleCharacter extends AbstractMapleCharacterObject {
announce(PacketCreator.updatePlayerStats(Collections.singletonList(new Pair<>(stat, Integer.valueOf(newval))), itemReaction, this)); announce(PacketCreator.updatePlayerStats(Collections.singletonList(new Pair<>(stat, Integer.valueOf(newval))), itemReaction, this));
} }
@Deprecated(forRemoval = true)
public void announce(final byte[] packet) { public void announce(final byte[] packet) {
client.announce(packet); client.announce(packet);
} }
public void sendPacket(Packet packet) {
client.sendPacket(packet);
}
@Override @Override
public int getObjectId() { public int getObjectId() {
return getId(); return getId();
@@ -427,7 +427,7 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth"); npcsIds.put(YamlConfig.config.server.REBIRTH_NPC_ID, "Rebirth");
} }
c.announce(PacketCreator.setNPCScriptable(npcsIds)); c.sendPacket(PacketCreator.setNPCScriptable(npcsIds));
} }
if (newcomer) player.setLoginTime(System.currentTimeMillis()); if (newcomer) player.setLoginTime(System.currentTimeMillis());
+2 -2
View File
@@ -3314,10 +3314,10 @@ public class MapleMap {
} }
// not really costly to keep generating imo // not really costly to keep generating imo
public void sendNightEffect(MapleCharacter mc) { public void sendNightEffect(MapleCharacter chr) {
for (Entry<Integer, Integer> types : backgroundTypes.entrySet()) { for (Entry<Integer, Integer> types : backgroundTypes.entrySet()) {
if (types.getValue() >= 3) { // 3 is a special number if (types.getValue() >= 3) { // 3 is a special number
mc.announce(PacketCreator.changeBackgroundEffect(true, types.getKey(), 0)); chr.sendPacket(PacketCreator.changeBackgroundEffect(true, types.getKey(), 0));
} }
} }
} }
+17 -17
View File
@@ -38,6 +38,8 @@ import constants.skills.Corsair;
import constants.skills.ThunderBreaker; import constants.skills.ThunderBreaker;
import net.encryption.InitializationVector; import net.encryption.InitializationVector;
import net.opcodes.SendOpcode; import net.opcodes.SendOpcode;
import net.packet.OutPacket;
import net.packet.Packet;
import net.server.PlayerCoolDownValueHolder; import net.server.PlayerCoolDownValueHolder;
import net.server.Server; import net.server.Server;
import net.server.channel.Channel; import net.server.channel.Channel;
@@ -8337,14 +8339,13 @@ public class PacketCreator {
* @param transition the time it takes to transition the effect. * @param transition the time it takes to transition the effect.
* @return a packet to change the background effect of a specified layer. * @return a packet to change the background effect of a specified layer.
*/ */
public static byte[] changeBackgroundEffect(boolean remove, int layer, int transition) { public static Packet changeBackgroundEffect(boolean remove, int layer, int transition) {
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); OutPacket p = OutPacket.create(SendOpcode.SET_BACK_EFFECT);
mplew.writeShort(SendOpcode.SET_BACK_EFFECT.getValue()); p.writeBool(remove);
mplew.writeBool(remove); p.writeInt(0); // not sure what this int32 does yet
mplew.writeInt(0); // not sure what this int32 does yet p.writeByte(layer);
mplew.write(layer); p.writeInt(transition);
mplew.writeInt(transition); return p;
return mplew.getPacket();
} }
/** /**
@@ -8354,18 +8355,17 @@ public class PacketCreator {
* @param scriptableNpcIds Ids of npcs to enable scripts for. * @param scriptableNpcIds Ids of npcs to enable scripts for.
* @return a packet which makes the npc's provided scriptable. * @return a packet which makes the npc's provided scriptable.
*/ */
public static byte[] setNPCScriptable(Map<Integer, String> scriptableNpcIds) { // thanks to GabrielSin public static Packet setNPCScriptable(Map<Integer, String> scriptableNpcIds) { // thanks to GabrielSin
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter(); OutPacket p = OutPacket.create(SendOpcode.SET_NPC_SCRIPTABLE);
mplew.writeShort(SendOpcode.SET_NPC_SCRIPTABLE.getValue()); p.writeByte(scriptableNpcIds.size());
mplew.write(scriptableNpcIds.size());
scriptableNpcIds.forEach((id, name) -> { scriptableNpcIds.forEach((id, name) -> {
mplew.writeInt(id); p.writeInt(id);
// The client needs a name for the npc conversation, which is displayed under etc when the npc has a quest available. // The client needs a name for the npc conversation, which is displayed under etc when the npc has a quest available.
mplew.writeMapleAsciiString(name); p.writeString(name);
mplew.writeInt(0); // start time p.writeInt(0); // start time
mplew.writeInt(Integer.MAX_VALUE); // end time p.writeInt(Integer.MAX_VALUE); // end time
}); });
return mplew.getPacket(); return p;
} }
private static byte[] MassacreResult(byte nRank, int nIncExp) { private static byte[] MassacreResult(byte nRank, int nIncExp) {