Analyze pet packet structure correctly

This commit is contained in:
Windyboy
2022-08-17 14:07:39 +08:00
parent 2e55deebc9
commit 97f358f047
6 changed files with 45 additions and 45 deletions

View File

@@ -45,21 +45,21 @@ import java.util.List;
public class Pet extends Item { public class Pet extends Item {
private String name; private String name;
private int uniqueid; private int uniqueid;
private int closeness = 0; private int tameness = 0;
private byte level = 1; private byte level = 1;
private int fullness = 100; private int fullness = 100;
private int Fh; private int Fh;
private Point pos; private Point pos;
private int stance; private int stance;
private boolean summoned; private boolean summoned;
private int petFlag = 0; private int petAttribute = 0;
public enum PetFlag { public enum PetAttribute {
OWNER_SPEED(0x01); OWNER_SPEED(0x01);
private final int i; private final int i;
PetFlag(int i) { PetAttribute(int i) {
this.i = i; this.i = i;
} }
@@ -83,11 +83,11 @@ public class Pet extends Item {
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
rs.next(); rs.next();
ret.setName(rs.getString("name")); ret.setName(rs.getString("name"));
ret.setCloseness(Math.min(rs.getInt("closeness"), 30000)); ret.setTameness(Math.min(rs.getInt("closeness"), 30000));
ret.setLevel((byte) Math.min(rs.getByte("level"), 30)); ret.setLevel((byte) Math.min(rs.getByte("level"), 30));
ret.setFullness(Math.min(rs.getInt("fullness"), 100)); ret.setFullness(Math.min(rs.getInt("fullness"), 100));
ret.setSummoned(rs.getInt("summoned") == 1); ret.setSummoned(rs.getInt("summoned") == 1);
ret.setPetFlag(rs.getInt("flag")); ret.setPetAttribute(rs.getInt("flag"));
} }
return ret; return ret;
} catch (SQLException e) { } catch (SQLException e) {
@@ -114,10 +114,10 @@ public class Pet extends Item {
PreparedStatement ps = con.prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ?, flag = ? WHERE petid = ?")) { PreparedStatement ps = con.prepareStatement("UPDATE pets SET name = ?, level = ?, closeness = ?, fullness = ?, summoned = ?, flag = ? WHERE petid = ?")) {
ps.setString(1, getName()); ps.setString(1, getName());
ps.setInt(2, getLevel()); ps.setInt(2, getLevel());
ps.setInt(3, getCloseness()); ps.setInt(3, getTameness());
ps.setInt(4, getFullness()); ps.setInt(4, getFullness());
ps.setInt(5, isSummoned() ? 1 : 0); ps.setInt(5, isSummoned() ? 1 : 0);
ps.setInt(6, getPetFlag()); ps.setInt(6, getPetAttribute());
ps.setInt(7, getUniqueId()); ps.setInt(7, getUniqueId());
ps.executeUpdate(); ps.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@@ -139,14 +139,14 @@ public class Pet extends Item {
} }
} }
public static int createPet(int itemid, byte level, int closeness, int fullness) { public static int createPet(int itemid, byte level, int tameness, int fullness) {
try (Connection con = DatabaseConnection.getConnection(); try (Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = con.prepareStatement("INSERT INTO pets (petid, name, level, closeness, fullness, summoned, flag) VALUES (?, ?, ?, ?, ?, 0, 0)")) { PreparedStatement ps = con.prepareStatement("INSERT INTO pets (petid, name, level, closeness, fullness, summoned, flag) VALUES (?, ?, ?, ?, ?, 0, 0)")) {
int ret = CashIdGenerator.generateCashId(); int ret = CashIdGenerator.generateCashId();
ps.setInt(1, ret); ps.setInt(1, ret);
ps.setString(2, ItemInformationProvider.getInstance().getName(itemid)); ps.setString(2, ItemInformationProvider.getInstance().getName(itemid));
ps.setByte(3, level); ps.setByte(3, level);
ps.setInt(4, closeness); ps.setInt(4, tameness);
ps.setInt(5, fullness); ps.setInt(5, fullness);
ps.executeUpdate(); ps.executeUpdate();
return ret; return ret;
@@ -172,19 +172,19 @@ public class Pet extends Item {
this.uniqueid = id; this.uniqueid = id;
} }
public int getCloseness() { public int getTameness() {
return closeness; return tameness;
} }
public void setCloseness(int closeness) { public void setTameness(int tameness) {
this.closeness = closeness; this.tameness = tameness;
} }
public byte getLevel() { public byte getLevel() {
return level; return level;
} }
public void gainClosenessFullness(Character owner, int incCloseness, int incFullness, int type) { public void gainClosenessFullness(Character owner, int incTameness, int incFullness, int type) {
byte slot = owner.getPetIndex(this); byte slot = owner.getPetIndex(this);
boolean enjoyed; boolean enjoyed;
@@ -196,14 +196,14 @@ public class Pet extends Item {
} }
fullness = newFullness; fullness = newFullness;
if (incCloseness > 0 && closeness < 30000) { if (incTameness > 0 && tameness < 30000) {
int newCloseness = closeness + incCloseness; int newTameness = tameness + incTameness;
if (newCloseness > 30000) { if (newTameness > 30000) {
newCloseness = 30000; newTameness = 30000;
} }
closeness = newCloseness; tameness = newTameness;
while (newCloseness >= ExpTable.getClosenessNeededForLevel(level)) { while (newTameness >= ExpTable.getTamenessNeededForLevel(level)) {
level += 1; level += 1;
owner.sendPacket(PacketCreator.showOwnPetLevelUp(slot)); owner.sendPacket(PacketCreator.showOwnPetLevelUp(slot));
owner.getMap().broadcastMessage(PacketCreator.showPetLevelUp(owner, slot)); owner.getMap().broadcastMessage(PacketCreator.showPetLevelUp(owner, slot));
@@ -212,13 +212,13 @@ public class Pet extends Item {
enjoyed = true; enjoyed = true;
} else { } else {
int newCloseness = closeness - 1; int newTameness = tameness - 1;
if (newCloseness < 0) { if (newTameness < 0) {
newCloseness = 0; newTameness = 0;
} }
closeness = newCloseness; tameness = newTameness;
if (level > 1 && newCloseness < ExpTable.getClosenessNeededForLevel(level - 1)) { if (level > 1 && newTameness < ExpTable.getTamenessNeededForLevel(level - 1)) {
level -= 1; level -= 1;
} }
@@ -278,16 +278,16 @@ public class Pet extends Item {
this.summoned = yes; this.summoned = yes;
} }
public int getPetFlag() { public int getPetAttribute() {
return this.petFlag; return this.petAttribute;
} }
private void setPetFlag(int flag) { private void setPetAttribute(int flag) {
this.petFlag = flag; this.petAttribute = flag;
} }
public void addPetFlag(Character owner, PetFlag flag) { public void addPetAttribute(Character owner, PetAttribute flag) {
this.petFlag |= flag.getValue(); this.petAttribute |= flag.getValue();
saveToDb(); saveToDb();
Item petz = owner.getInventory(InventoryType.CASH).getItem(getPosition()); Item petz = owner.getInventory(InventoryType.CASH).getItem(getPosition());
@@ -296,8 +296,8 @@ public class Pet extends Item {
} }
} }
public void removePetFlag(Character owner, PetFlag flag) { public void removePetAttribute(Character owner, PetAttribute flag) {
this.petFlag &= 0xFFFFFFFF ^ flag.getValue(); this.petAttribute &= 0xFFFFFFFF ^ flag.getValue();
saveToDb(); saveToDb();
Item petz = owner.getInventory(InventoryType.CASH).getItem(getPosition()); Item petz = owner.getInventory(InventoryType.CASH).getItem(getPosition());

View File

@@ -31,7 +31,7 @@ public final class ExpTable {
return level > 200 ? 2000000000 : exp[level]; return level > 200 ? 2000000000 : exp[level];
} }
public static int getClosenessNeededForLevel(int level) { public static int getTamenessNeededForLevel(int level) {
return pet[level]; return pet[level];
} }

View File

@@ -588,7 +588,7 @@ public class AbstractPlayerInteraction {
evolved.setSummoned(true); evolved.setSummoned(true);
evolved.setName(from.getName().compareTo(ItemInformationProvider.getInstance().getName(from.getItemId())) != 0 ? from.getName() : ItemInformationProvider.getInstance().getName(id)); evolved.setName(from.getName().compareTo(ItemInformationProvider.getInstance().getName(from.getItemId())) != 0 ? from.getName() : ItemInformationProvider.getInstance().getName(id));
evolved.setCloseness(from.getCloseness()); evolved.setTameness(from.getTameness());
evolved.setFullness(from.getFullness()); evolved.setFullness(from.getFullness());
evolved.setLevel(from.getLevel()); evolved.setLevel(from.getLevel());
evolved.setExpiration(System.currentTimeMillis() + expires); evolved.setExpiration(System.currentTimeMillis() + expires);

View File

@@ -51,7 +51,7 @@ public class PetSpeedAction extends AbstractQuestAction {
c.lockClient(); c.lockClient();
try { try {
pet.addPetFlag(c.getPlayer(), Pet.PetFlag.OWNER_SPEED); pet.addPetAttribute(c.getPlayer(), Pet.PetAttribute.OWNER_SPEED);
} finally { } finally {
c.unlockClient(); c.unlockClient();
} }

View File

@@ -58,8 +58,8 @@ public class MinTamenessRequirement extends AbstractQuestRequirement {
continue; continue;
} }
if (pet.getCloseness() > curCloseness) { if (pet.getTameness() > curCloseness) {
curCloseness = pet.getCloseness(); curCloseness = pet.getTameness();
} }
} }

View File

@@ -382,13 +382,13 @@ public class PacketCreator {
Pet pet = item.getPet(); Pet pet = item.getPet();
p.writeFixedString(StringUtil.getRightPaddedStr(pet.getName(), '\0', 13)); p.writeFixedString(StringUtil.getRightPaddedStr(pet.getName(), '\0', 13));
p.writeByte(pet.getLevel()); p.writeByte(pet.getLevel());
p.writeShort(pet.getCloseness()); p.writeShort(pet.getTameness());
p.writeByte(pet.getFullness()); p.writeByte(pet.getFullness());
addExpirationTime(p, item.getExpiration()); addExpirationTime(p, item.getExpiration());
p.writeInt(pet.getPetFlag()); /* pet flags noticed by lrenex & Spoon */ p.writeShort(pet.getPetAttribute()); // PetAttribute noticed by lrenex & Spoon
p.writeShort(0); // PetSkill
p.writeBytes(new byte[]{(byte) 0x50, (byte) 0x46}); //wonder what this is p.writeInt(18000); // RemainLife
p.writeInt(0); p.writeShort(0); // attribute
return; return;
} }
if (equip == null) { if (equip == null) {
@@ -2705,7 +2705,7 @@ public class PacketCreator {
p.writeInt(pets[i].getItemId()); // petid p.writeInt(pets[i].getItemId()); // petid
p.writeString(pets[i].getName()); p.writeString(pets[i].getName());
p.writeByte(pets[i].getLevel()); // pet level p.writeByte(pets[i].getLevel()); // pet level
p.writeShort(pets[i].getCloseness()); // pet closeness p.writeShort(pets[i].getTameness()); // pet closeness
p.writeByte(pets[i].getFullness()); // pet fullness p.writeByte(pets[i].getFullness()); // pet fullness
p.writeShort(0); p.writeShort(0);
p.writeInt(inv != null ? inv.getItemId() : 0); p.writeInt(inv != null ? inv.getItemId() : 0);