Rename and clean up MapleFamilyEntry

This commit is contained in:
P0nk
2021-09-09 21:19:39 +02:00
parent 0c8bef6842
commit ee503eedce
10 changed files with 256 additions and 185 deletions

View File

@@ -115,7 +115,7 @@ public class Character extends AbstractCharacterObject {
private int energybar; private int energybar;
private int gmLevel; private int gmLevel;
private int ci = 0; private int ci = 0;
private MapleFamilyEntry familyEntry; private FamilyEntry familyEntry;
private int familyId; private int familyId;
private int bookCover; private int bookCover;
private int battleshipHp = 0; private int battleshipHp = 0;
@@ -4963,11 +4963,11 @@ public class Character extends AbstractCharacterObject {
} }
} }
public MapleFamilyEntry getFamilyEntry() { public FamilyEntry getFamilyEntry() {
return familyEntry; return familyEntry;
} }
public void setFamilyEntry(MapleFamilyEntry entry) { public void setFamilyEntry(FamilyEntry entry) {
if (entry != null) { if (entry != null) {
setFamilyId(entry.getFamily().getID()); setFamilyId(entry.getFamily().getID());
} }
@@ -6495,10 +6495,10 @@ public class Character extends AbstractCharacterObject {
levelUpMessages(); levelUpMessages();
guildUpdate(); guildUpdate();
MapleFamilyEntry familyEntry = getFamilyEntry(); FamilyEntry familyEntry = getFamilyEntry();
if (familyEntry != null) { if (familyEntry != null) {
familyEntry.giveReputationToSenior(YamlConfig.config.server.FAMILY_REP_PER_LEVELUP, true); familyEntry.giveReputationToSenior(YamlConfig.config.server.FAMILY_REP_PER_LEVELUP, true);
MapleFamilyEntry senior = familyEntry.getSenior(); FamilyEntry senior = familyEntry.getSenior();
if (senior != null) { //only send the message to direct senior if (senior != null) { //only send the message to direct senior
Character seniorChr = senior.getChr(); Character seniorChr = senior.getChr();
if (seniorChr != null) { if (seniorChr != null) {
@@ -8706,12 +8706,12 @@ public class Character extends AbstractCharacterObject {
} }
} }
MapleFamilyEntry familyEntry = getFamilyEntry(); //save family rep FamilyEntry familyEntry = getFamilyEntry(); //save family rep
if (familyEntry != null) { if (familyEntry != null) {
if (familyEntry.saveReputation(con)) { if (familyEntry.saveReputation(con)) {
familyEntry.savedSuccessfully(); familyEntry.savedSuccessfully();
} }
MapleFamilyEntry senior = familyEntry.getSenior(); FamilyEntry senior = familyEntry.getSenior();
if (senior != null && senior.getChr() == null) { //only save for offline family members if (senior != null && senior.getChr() == null) { //only save for offline family members
if (senior.saveReputation(con)) { if (senior.saveReputation(con)) {
senior.savedSuccessfully(); senior.savedSuccessfully();
@@ -10529,7 +10529,7 @@ public class Character extends AbstractCharacterObject {
mpc = null; mpc = null;
mgc = null; mgc = null;
party = null; party = null;
MapleFamilyEntry familyEntry = getFamilyEntry(); FamilyEntry familyEntry = getFamilyEntry();
if (familyEntry != null) { if (familyEntry != null) {
familyEntry.setCharacter(null); familyEntry.setCharacter(null);
setFamilyEntry(null); setFamilyEntry(null);

View File

@@ -49,8 +49,8 @@ public class Family {
private static final AtomicInteger familyIDCounter = new AtomicInteger(); private static final AtomicInteger familyIDCounter = new AtomicInteger();
private final int id, world; private final int id, world;
private final Map<Integer, MapleFamilyEntry> members = new ConcurrentHashMap<>(); private final Map<Integer, FamilyEntry> members = new ConcurrentHashMap<>();
private MapleFamilyEntry leader; private FamilyEntry leader;
private String name; private String name;
private String preceptsMessage = ""; private String preceptsMessage = "";
private int totalGenerations; private int totalGenerations;
@@ -83,12 +83,12 @@ public class Family {
return world; return world;
} }
public void setLeader(MapleFamilyEntry leader) { public void setLeader(FamilyEntry leader) {
this.leader = leader; this.leader = leader;
setName(leader.getName()); setName(leader.getName());
} }
public MapleFamilyEntry getLeader() { public FamilyEntry getLeader() {
return leader; return leader;
} }
@@ -131,29 +131,29 @@ public class Family {
return preceptsMessage; return preceptsMessage;
} }
public void addEntry(MapleFamilyEntry entry) { public void addEntry(FamilyEntry entry) {
members.put(entry.getChrId(), entry); members.put(entry.getChrId(), entry);
} }
public void removeEntryBranch(MapleFamilyEntry root) { public void removeEntryBranch(FamilyEntry root) {
members.remove(root.getChrId()); members.remove(root.getChrId());
for (MapleFamilyEntry junior : root.getJuniors()) { for (FamilyEntry junior : root.getJuniors()) {
if (junior != null) { if (junior != null) {
removeEntryBranch(junior); removeEntryBranch(junior);
} }
} }
} }
public void addEntryTree(MapleFamilyEntry root) { public void addEntryTree(FamilyEntry root) {
members.put(root.getChrId(), root); members.put(root.getChrId(), root);
for (MapleFamilyEntry junior : root.getJuniors()) { for (FamilyEntry junior : root.getJuniors()) {
if (junior != null) { if (junior != null) {
addEntryTree(junior); addEntryTree(junior);
} }
} }
} }
public MapleFamilyEntry getEntryByID(int cid) { public FamilyEntry getEntryByID(int cid) {
return members.get(cid); return members.get(cid);
} }
@@ -162,7 +162,7 @@ public class Family {
} }
public void broadcast(Packet packet, int ignoreID) { public void broadcast(Packet packet, int ignoreID) {
for (MapleFamilyEntry entry : members.values()) { for (FamilyEntry entry : members.values()) {
Character chr = entry.getChr(); Character chr = entry.getChr();
if (chr != null) { if (chr != null) {
if (chr.getId() == ignoreID) { if (chr.getId() == ignoreID) {
@@ -174,7 +174,7 @@ public class Family {
} }
public void broadcastFamilyInfoUpdate() { public void broadcastFamilyInfoUpdate() {
for (MapleFamilyEntry entry : members.values()) { for (FamilyEntry entry : members.values()) {
Character chr = entry.getChr(); Character chr = entry.getChr();
if (chr != null) { if (chr != null) {
chr.sendPacket(PacketCreator.getFamilyInfo(entry)); chr.sendPacket(PacketCreator.getFamilyInfo(entry));
@@ -183,7 +183,7 @@ public class Family {
} }
public void resetDailyReps() { public void resetDailyReps() {
for (MapleFamilyEntry entry : members.values()) { for (FamilyEntry entry : members.values()) {
entry.setTodaysRep(0); entry.setTodaysRep(0);
entry.setRepsToSenior(0); entry.setRepsToSenior(0);
entry.resetEntitlementUsages(); entry.resetEntitlementUsages();
@@ -191,7 +191,7 @@ public class Family {
} }
public static void loadAllFamilies(Connection con) { public static void loadAllFamilies(Connection con) {
List<Pair<Pair<Integer, Integer>, MapleFamilyEntry>> unmatchedJuniors = new ArrayList<>(200); // <<world, seniorid> familyEntry> List<Pair<Pair<Integer, Integer>, FamilyEntry>> unmatchedJuniors = new ArrayList<>(200); // <<world, seniorid> familyEntry>
try (PreparedStatement psEntries = con.prepareStatement("SELECT * FROM family_character")) { try (PreparedStatement psEntries = con.prepareStatement("SELECT * FROM family_character")) {
ResultSet rsEntries = psEntries.executeQuery(); ResultSet rsEntries = psEntries.executeQuery();
while (rsEntries.next()) { // can be optimized while (rsEntries.next()) { // can be optimized
@@ -233,13 +233,13 @@ public class Family {
family = new Family(familyid, world); family = new Family(familyid, world);
Server.getInstance().getWorld(world).addFamily(familyid, family); Server.getInstance().getWorld(world).addFamily(familyid, family);
} }
MapleFamilyEntry familyEntry = new MapleFamilyEntry(family, cid, name, level, MapleJob.getById(jobID)); FamilyEntry familyEntry = new FamilyEntry(family, cid, name, level, MapleJob.getById(jobID));
family.addEntry(familyEntry); family.addEntry(familyEntry);
if (seniorid <= 0) { if (seniorid <= 0) {
family.setLeader(familyEntry); family.setLeader(familyEntry);
family.setMessage(precepts, false); family.setMessage(precepts, false);
} }
MapleFamilyEntry senior = family.getEntryByID(seniorid); FamilyEntry senior = family.getEntryByID(seniorid);
if (senior != null) { if (senior != null) {
familyEntry.setSenior(family.getEntryByID(seniorid), false); familyEntry.setSenior(family.getEntryByID(seniorid), false);
} else { } else {
@@ -265,11 +265,11 @@ public class Family {
e.printStackTrace(); e.printStackTrace();
} }
// link missing ones (out of order) // link missing ones (out of order)
for (Pair<Pair<Integer, Integer>, MapleFamilyEntry> unmatchedJunior : unmatchedJuniors) { for (Pair<Pair<Integer, Integer>, FamilyEntry> unmatchedJunior : unmatchedJuniors) {
int world = unmatchedJunior.getLeft().getLeft(); int world = unmatchedJunior.getLeft().getLeft();
int seniorid = unmatchedJunior.getLeft().getRight(); int seniorid = unmatchedJunior.getLeft().getRight();
MapleFamilyEntry junior = unmatchedJunior.getRight(); FamilyEntry junior = unmatchedJunior.getRight();
MapleFamilyEntry senior = Server.getInstance().getWorld(world).getFamily(junior.getFamily().getID()).getEntryByID(seniorid); FamilyEntry senior = Server.getInstance().getWorld(world).getFamily(junior.getFamily().getID()).getEntryByID(seniorid);
if (senior != null) { if (senior != null) {
junior.setSenior(senior, false); junior.setSenior(senior, false);
} else { } else {
@@ -288,7 +288,7 @@ public class Family {
try (Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
con.setAutoCommit(false); con.setAutoCommit(false);
boolean success = true; boolean success = true;
for (MapleFamilyEntry entry : members.values()) { for (FamilyEntry entry : members.values()) {
success = entry.saveReputation(con); success = entry.saveReputation(con);
if (!success) { if (!success) {
break; break;
@@ -300,7 +300,7 @@ public class Family {
} }
con.setAutoCommit(true); con.setAutoCommit(true);
//reset repChanged after successful save //reset repChanged after successful save
for (MapleFamilyEntry entry : members.values()) { for (FamilyEntry entry : members.values()) {
entry.savedSuccessfully(); entry.savedSuccessfully();
} }
} catch (SQLException e) { } catch (SQLException e) {

View File

@@ -37,13 +37,13 @@ import java.util.List;
* @author Ubaware * @author Ubaware
*/ */
public class MapleFamilyEntry { public class FamilyEntry {
private final int characterID; private final int characterID;
private volatile Family family; private volatile Family family;
private volatile Character character; private volatile Character character;
private volatile MapleFamilyEntry senior; private volatile FamilyEntry senior;
private final MapleFamilyEntry[] juniors = new MapleFamilyEntry[2]; private final FamilyEntry[] juniors = new FamilyEntry[2];
private final int[] entitlements = new int[11]; private final int[] entitlements = new int[11];
private volatile int reputation, totalReputation; private volatile int reputation, totalReputation;
private volatile int todaysRep, repsToSenior; //both are daily values private volatile int todaysRep, repsToSenior; //both are daily values
@@ -58,7 +58,7 @@ public class MapleFamilyEntry {
private int level; private int level;
private MapleJob job; private MapleJob job;
public MapleFamilyEntry(Family family, int characterID, String charName, int level, MapleJob job) { public FamilyEntry(Family family, int characterID, String charName, int level, MapleJob job) {
this.family = family; this.family = family;
this.characterID = characterID; this.characterID = characterID;
this.charName = charName; this.charName = charName;
@@ -71,21 +71,26 @@ public class MapleFamilyEntry {
} }
public void setCharacter(Character newCharacter) { public void setCharacter(Character newCharacter) {
if(newCharacter == null) cacheOffline(newCharacter); if (newCharacter == null) {
else newCharacter.setFamilyEntry(this); cacheOffline(newCharacter);
} else {
newCharacter.setFamilyEntry(this);
}
this.character = newCharacter; this.character = newCharacter;
} }
private void cacheOffline(Character chr) { private void cacheOffline(Character chr) {
if(chr != null) { if (chr != null) {
charName = chr.getName(); charName = chr.getName();
level = chr.getLevel(); level = chr.getLevel();
job = chr.getJob(); job = chr.getJob();
} }
} }
public synchronized void join(MapleFamilyEntry senior) { public synchronized void join(FamilyEntry senior) {
if(senior == null || getSenior() != null) return; if (senior == null || getSenior() != null) {
return;
}
Family oldFamily = getFamily(); Family oldFamily = getFamily();
Family newFamily = senior.getFamily(); Family newFamily = senior.getFamily();
setSenior(senior, false); setSenior(senior, false);
@@ -96,21 +101,23 @@ public class MapleFamilyEntry {
Server.getInstance().getWorld(oldFamily.getWorld()).removeFamily(oldFamily.getID()); Server.getInstance().getWorld(oldFamily.getWorld()).removeFamily(oldFamily.getID());
//db //db
try(Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
con.setAutoCommit(false); con.setAutoCommit(false);
boolean success = updateDBChangeFamily(con, getChrId(), newFamily.getID(), senior.getChrId()); boolean success = updateDBChangeFamily(con, getChrId(), newFamily.getID(), senior.getChrId());
for(MapleFamilyEntry junior : juniors) { // better to duplicate this than the SQL code for (FamilyEntry junior : juniors) { // better to duplicate this than the SQL code
if(junior != null) { if (junior != null) {
success = junior.updateNewFamilyDB(con); // recursively updates juniors in db success = junior.updateNewFamilyDB(con); // recursively updates juniors in db
if(!success) break; if (!success) {
break;
} }
} }
if(!success) { }
if (!success) {
con.rollback(); con.rollback();
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not absorb " + oldFamily.getName() + " family into " + newFamily.getName() + " family. (SQL ERROR)"); FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not absorb " + oldFamily.getName() + " family into " + newFamily.getName() + " family. (SQL ERROR)");
} }
con.setAutoCommit(true); con.setAutoCommit(true);
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB.");
e.printStackTrace(); e.printStackTrace();
} }
@@ -118,14 +125,14 @@ public class MapleFamilyEntry {
public synchronized void fork() { public synchronized void fork() {
Family oldFamily = getFamily(); Family oldFamily = getFamily();
MapleFamilyEntry oldSenior = getSenior(); FamilyEntry oldSenior = getSenior();
family = new Family(-1, oldFamily.getWorld()); family = new Family(-1, oldFamily.getWorld());
Server.getInstance().getWorld(family.getWorld()).addFamily(family.getID(), family); Server.getInstance().getWorld(family.getWorld()).addFamily(family.getID(), family);
setSenior(null, false); setSenior(null, false);
family.setLeader(this); family.setLeader(this);
addSeniorCount(-getTotalSeniors(), family); addSeniorCount(-getTotalSeniors(), family);
setTotalSeniors(0); setTotalSeniors(0);
if(oldSenior != null) { if (oldSenior != null) {
oldSenior.addJuniorCount(-getTotalJuniors()); oldSenior.addJuniorCount(-getTotalJuniors());
oldSenior.removeJunior(this); oldSenior.removeJunior(this);
oldFamily.getLeader().doFullCount(); oldFamily.getLeader().doFullCount();
@@ -137,47 +144,55 @@ public class MapleFamilyEntry {
family.setMessage("", true); family.setMessage("", true);
doFullCount(); //to make sure all counts are correct doFullCount(); //to make sure all counts are correct
// update db // update db
try(Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
con.setAutoCommit(false); con.setAutoCommit(false);
boolean success = updateDBChangeFamily(con, getChrId(), getFamily().getID(), 0); boolean success = updateDBChangeFamily(con, getChrId(), getFamily().getID(), 0);
for(MapleFamilyEntry junior : juniors) { // better to duplicate this than the SQL code for (FamilyEntry junior : juniors) { // better to duplicate this than the SQL code
if(junior != null) { if (junior != null) {
success = junior.updateNewFamilyDB(con); // recursively updates juniors in db success = junior.updateNewFamilyDB(con); // recursively updates juniors in db
if(!success) break; if (!success) {
break;
} }
} }
if(!success) { }
if (!success) {
con.rollback(); con.rollback();
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not fork family with new leader " + getName() + ". (Old senior : " + oldSenior.getName() + ", leader :" + oldFamily.getLeader().getName() + ")"); FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Could not fork family with new leader " + getName() + ". (Old senior : " + oldSenior.getName() + ", leader :" + oldFamily.getLeader().getName() + ")");
} }
con.setAutoCommit(true); con.setAutoCommit(true);
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB.");
e.printStackTrace(); e.printStackTrace();
} }
} }
private synchronized boolean updateNewFamilyDB(Connection con) { private synchronized boolean updateNewFamilyDB(Connection con) {
if(!updateFamilyEntryDB(con, getChrId(), getFamily().getID())) return false; if (!updateFamilyEntryDB(con, getChrId(), getFamily().getID())) {
if(!updateCharacterFamilyDB(con, getChrId(), getFamily().getID(), true)) return false; return false;
}
if (!updateCharacterFamilyDB(con, getChrId(), getFamily().getID(), true)) {
return false;
}
for(MapleFamilyEntry junior : juniors) { for (FamilyEntry junior : juniors) {
if(junior != null) { if (junior != null) {
if(!junior.updateNewFamilyDB(con)) return false; if (!junior.updateNewFamilyDB(con)) {
return false;
}
} }
} }
return true; return true;
} }
private static boolean updateFamilyEntryDB(Connection con, int cid, int familyid) { private static boolean updateFamilyEntryDB(Connection con, int cid, int familyid) {
try(PreparedStatement ps = con.prepareStatement("UPDATE family_character SET familyid = ? WHERE cid = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE family_character SET familyid = ? WHERE cid = ?")) {
ps.setInt(1, familyid); ps.setInt(1, familyid);
ps.setInt(2, cid); ps.setInt(2, cid);
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update family id in 'family_character' for character id " + cid + ". (fork)"); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update family id in 'family_character' for character id " + cid + ". (fork)");
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -186,18 +201,24 @@ public class MapleFamilyEntry {
} }
private synchronized void addSeniorCount(int seniorCount, Family newFamily) { // traverses tree and subtracts seniors and updates family private synchronized void addSeniorCount(int seniorCount, Family newFamily) { // traverses tree and subtracts seniors and updates family
if(newFamily != null) this.family = newFamily; if (newFamily != null) {
this.family = newFamily;
}
setTotalSeniors(getTotalSeniors() + seniorCount); setTotalSeniors(getTotalSeniors() + seniorCount);
this.generation += seniorCount; this.generation += seniorCount;
for(MapleFamilyEntry junior : juniors) { for (FamilyEntry junior : juniors) {
if(junior != null) junior.addSeniorCount(seniorCount, newFamily); if (junior != null) {
junior.addSeniorCount(seniorCount, newFamily);
}
} }
} }
private synchronized void addJuniorCount(int juniorCount) { // climbs tree and adds junior count private synchronized void addJuniorCount(int juniorCount) { // climbs tree and adds junior count
setTotalJuniors(getTotalJuniors() + juniorCount); setTotalJuniors(getTotalJuniors() + juniorCount);
MapleFamilyEntry senior = getSenior(); FamilyEntry senior = getSenior();
if(senior != null) senior.addJuniorCount(juniorCount); if (senior != null) {
senior.addJuniorCount(juniorCount);
}
} }
public Family getFamily() { public Family getFamily() {
@@ -210,20 +231,29 @@ public class MapleFamilyEntry {
public String getName() { public String getName() {
Character chr = character; Character chr = character;
if(chr != null) return chr.getName(); if (chr != null) {
else return charName; return chr.getName();
} else {
return charName;
}
} }
public int getLevel() { public int getLevel() {
Character chr = character; Character chr = character;
if(chr != null) return chr.getLevel(); if (chr != null) {
else return level; return chr.getLevel();
} else {
return level;
}
} }
public MapleJob getJob() { public MapleJob getJob() {
Character chr = character; Character chr = character;
if(chr != null) return chr.getJob(); if (chr != null) {
else return job; return chr.getJob();
} else {
return job;
}
} }
public int getReputation() { public int getReputation() {
@@ -235,12 +265,16 @@ public class MapleFamilyEntry {
} }
public void setReputation(int reputation) { public void setReputation(int reputation) {
if(reputation != this.reputation) this.repChanged = true; if (reputation != this.reputation) {
this.repChanged = true;
}
this.reputation = reputation; this.reputation = reputation;
} }
public void setTodaysRep(int today) { public void setTodaysRep(int today) {
if(today != todaysRep) this.repChanged = true; if (today != todaysRep) {
this.repChanged = true;
}
this.todaysRep = today; this.todaysRep = today;
} }
@@ -249,7 +283,9 @@ public class MapleFamilyEntry {
} }
public void setRepsToSenior(int reputation) { public void setRepsToSenior(int reputation) {
if(reputation != this.repsToSenior) this.repChanged = true; if (reputation != this.repsToSenior) {
this.repChanged = true;
}
this.repsToSenior = reputation; this.repsToSenior = reputation;
} }
@@ -257,30 +293,36 @@ public class MapleFamilyEntry {
gainReputation(gain, countTowardsTotal, this); gainReputation(gain, countTowardsTotal, this);
} }
private void gainReputation(int gain, boolean countTowardsTotal, MapleFamilyEntry from) { private void gainReputation(int gain, boolean countTowardsTotal, FamilyEntry from) {
if(gain != 0) repChanged = true; if (gain != 0) {
repChanged = true;
}
this.reputation += gain; this.reputation += gain;
this.todaysRep += gain; this.todaysRep += gain;
if(gain > 0 && countTowardsTotal) { if (gain > 0 && countTowardsTotal) {
this.totalReputation += gain; this.totalReputation += gain;
} }
Character chr = getChr(); Character chr = getChr();
if(chr != null) chr.sendPacket(PacketCreator.sendGainRep(gain, from != null ? from.getName() : "")); if (chr != null) {
chr.sendPacket(PacketCreator.sendGainRep(gain, from != null ? from.getName() : ""));
}
} }
public void giveReputationToSenior(int gain, boolean includeSuperSenior) { public void giveReputationToSenior(int gain, boolean includeSuperSenior) {
int actualGain = gain; int actualGain = gain;
MapleFamilyEntry senior = getSenior(); FamilyEntry senior = getSenior();
if(senior != null && senior.getLevel() < getLevel() && gain > 0) actualGain /= 2; //don't halve negative values if (senior != null && senior.getLevel() < getLevel() && gain > 0) {
if(senior != null) { actualGain /= 2; //don't halve negative values
}
if (senior != null) {
senior.gainReputation(actualGain, true, this); senior.gainReputation(actualGain, true, this);
if(actualGain > 0) { if (actualGain > 0) {
this.repsToSenior += actualGain; this.repsToSenior += actualGain;
this.repChanged = true; this.repChanged = true;
} }
if(includeSuperSenior) { if (includeSuperSenior) {
senior = senior.getSenior(); senior = senior.getSenior();
if(senior != null) { if (senior != null) {
senior.gainReputation(actualGain, true, this); senior.gainReputation(actualGain, true, this);
} }
} }
@@ -292,31 +334,37 @@ public class MapleFamilyEntry {
} }
public void setTotalReputation(int totalReputation) { public void setTotalReputation(int totalReputation) {
if(totalReputation != this.totalReputation) this.repChanged = true; if (totalReputation != this.totalReputation) {
this.repChanged = true;
}
this.totalReputation = totalReputation; this.totalReputation = totalReputation;
} }
public MapleFamilyEntry getSenior() { public FamilyEntry getSenior() {
return senior; return senior;
} }
public synchronized boolean setSenior(MapleFamilyEntry senior, boolean save) { public synchronized boolean setSenior(FamilyEntry senior, boolean save) {
if(this.senior == senior) return false; if (this.senior == senior) {
MapleFamilyEntry oldSenior = this.senior; return false;
}
FamilyEntry oldSenior = this.senior;
this.senior = senior; this.senior = senior;
if(senior != null) { if (senior != null) {
if(senior.addJunior(this)) { if (senior.addJunior(this)) {
if(save) { if (save) {
updateDBChangeFamily(getChrId(), senior.getFamily().getID(), senior.getChrId()); updateDBChangeFamily(getChrId(), senior.getFamily().getID(), senior.getChrId());
} }
if(this.repsToSenior != 0) this.repChanged = true; if (this.repsToSenior != 0) {
this.repChanged = true;
}
this.repsToSenior = 0; this.repsToSenior = 0;
this.addSeniorCount(1, null); this.addSeniorCount(1, null);
this.setTotalSeniors(senior.getTotalSeniors() + 1); this.setTotalSeniors(senior.getTotalSeniors() + 1);
return true; return true;
} }
} else { } else {
if(oldSenior != null) { if (oldSenior != null) {
oldSenior.removeJunior(this); oldSenior.removeJunior(this);
} }
} }
@@ -324,9 +372,9 @@ public class MapleFamilyEntry {
} }
private static boolean updateDBChangeFamily(int cid, int familyid, int seniorid) { private static boolean updateDBChangeFamily(int cid, int familyid, int seniorid) {
try(Connection con = DatabaseConnection.getConnection()) { try (Connection con = DatabaseConnection.getConnection()) {
return updateDBChangeFamily(con, cid, familyid, seniorid); return updateDBChangeFamily(con, cid, familyid, seniorid);
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB.");
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -334,12 +382,12 @@ public class MapleFamilyEntry {
} }
private static boolean updateDBChangeFamily(Connection con, int cid, int familyid, int seniorid) { private static boolean updateDBChangeFamily(Connection con, int cid, int familyid, int seniorid) {
try(PreparedStatement ps = con.prepareStatement("UPDATE family_character SET familyid = ?, seniorid = ?, reptosenior = 0 WHERE cid = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE family_character SET familyid = ?, seniorid = ?, reptosenior = 0 WHERE cid = ?")) {
ps.setInt(1, familyid); ps.setInt(1, familyid);
ps.setInt(2, seniorid); ps.setInt(2, seniorid);
ps.setInt(3, cid); ps.setInt(3, cid);
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update seniorid in 'family_character' for character id " + cid + "."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update seniorid in 'family_character' for character id " + cid + ".");
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -348,11 +396,11 @@ public class MapleFamilyEntry {
} }
private static boolean updateCharacterFamilyDB(Connection con, int charid, int familyid, boolean fork) { private static boolean updateCharacterFamilyDB(Connection con, int charid, int familyid, boolean fork) {
try(PreparedStatement ps = con.prepareStatement("UPDATE characters SET familyid = ? WHERE id = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET familyid = ? WHERE id = ?")) {
ps.setInt(1, familyid); ps.setInt(1, familyid);
ps.setInt(2, charid); ps.setInt(2, charid);
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update familyid in 'characters' for character id " + charid + " when changing family. " + (fork ? "(fork)" : "")); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not update familyid in 'characters' for character id " + charid + " when changing family. " + (fork ? "(fork)" : ""));
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -360,26 +408,33 @@ public class MapleFamilyEntry {
return true; return true;
} }
public List<MapleFamilyEntry> getJuniors() { public List<FamilyEntry> getJuniors() {
return Collections.unmodifiableList(Arrays.asList(juniors)); return Collections.unmodifiableList(Arrays.asList(juniors));
} }
public MapleFamilyEntry getOtherJunior(MapleFamilyEntry junior) { public FamilyEntry getOtherJunior(FamilyEntry junior) {
if(juniors[0] == junior) return juniors[1]; if (juniors[0] == junior) {
else if(juniors[1] == junior) return juniors[0]; return juniors[1];
} else if (juniors[1] == junior) {
return juniors[0];
}
return null; return null;
} }
public int getJuniorCount() { //close enough to be relatively consistent to multiple threads (and the result is not vital) public int getJuniorCount() { //close enough to be relatively consistent to multiple threads (and the result is not vital)
int juniorCount = 0; int juniorCount = 0;
if(juniors[0] != null) juniorCount++; if (juniors[0] != null) {
if(juniors[1] != null) juniorCount++; juniorCount++;
}
if (juniors[1] != null) {
juniorCount++;
}
return juniorCount; return juniorCount;
} }
public synchronized boolean addJunior(MapleFamilyEntry newJunior) { public synchronized boolean addJunior(FamilyEntry newJunior) {
for(int i = 0; i < juniors.length; i++) { for (int i = 0; i < juniors.length; i++) {
if(juniors[i] == null) { // successfully add new junior to family if (juniors[i] == null) { // successfully add new junior to family
juniors[i] = newJunior; juniors[i] = newJunior;
addJuniorCount(1); addJuniorCount(1);
getFamily().addEntry(newJunior); getFamily().addEntry(newJunior);
@@ -389,15 +444,15 @@ public class MapleFamilyEntry {
return false; return false;
} }
public synchronized boolean isJunior(MapleFamilyEntry entry) { //require locking since result accuracy is vital public synchronized boolean isJunior(FamilyEntry entry) { //require locking since result accuracy is vital
if(juniors[0] == entry) return true; if (juniors[0] == entry) {
else if(juniors[1] == entry) return true; return true;
return false; } else return juniors[1] == entry;
} }
public synchronized boolean removeJunior(MapleFamilyEntry junior) { public synchronized boolean removeJunior(FamilyEntry junior) {
for(int i = 0; i < juniors.length; i++) { for (int i = 0; i < juniors.length; i++) {
if(juniors[i] == junior) { if (juniors[i] == junior) {
juniors[i] = null; juniors[i] = null;
return true; return true;
} }
@@ -422,27 +477,35 @@ public class MapleFamilyEntry {
} }
public void announceToSenior(Packet packet, boolean includeSuperSenior) { public void announceToSenior(Packet packet, boolean includeSuperSenior) {
MapleFamilyEntry senior = getSenior(); FamilyEntry senior = getSenior();
if(senior != null) { if (senior != null) {
Character seniorChr = senior.getChr(); Character seniorChr = senior.getChr();
if(seniorChr != null) seniorChr.sendPacket(packet); if (seniorChr != null) {
seniorChr.sendPacket(packet);
}
senior = senior.getSenior(); senior = senior.getSenior();
if(includeSuperSenior && senior != null) { if (includeSuperSenior && senior != null) {
seniorChr = senior.getChr(); seniorChr = senior.getChr();
if(seniorChr != null) seniorChr.sendPacket(packet); if (seniorChr != null) {
seniorChr.sendPacket(packet);
}
} }
} }
} }
public void updateSeniorFamilyInfo(boolean includeSuperSenior) { public void updateSeniorFamilyInfo(boolean includeSuperSenior) {
MapleFamilyEntry senior = getSenior(); FamilyEntry senior = getSenior();
if(senior != null) { if (senior != null) {
Character seniorChr = senior.getChr(); Character seniorChr = senior.getChr();
if(seniorChr != null) seniorChr.sendPacket(PacketCreator.getFamilyInfo(senior)); if (seniorChr != null) {
seniorChr.sendPacket(PacketCreator.getFamilyInfo(senior));
}
senior = senior.getSenior(); senior = senior.getSenior();
if(includeSuperSenior && senior != null) { if (includeSuperSenior && senior != null) {
seniorChr = senior.getChr(); seniorChr = senior.getChr();
if(seniorChr != null) seniorChr.sendPacket(PacketCreator.getFamilyInfo(senior)); if (seniorChr != null) {
seniorChr.sendPacket(PacketCreator.getFamilyInfo(senior));
}
} }
} }
} }
@@ -460,11 +523,13 @@ public class MapleFamilyEntry {
this.generation = seniors; this.generation = seniors;
int juniorCount = 0; int juniorCount = 0;
int highestGeneration = this.generation; int highestGeneration = this.generation;
for(MapleFamilyEntry entry : juniors) { for (FamilyEntry entry : juniors) {
if(entry != null) { if (entry != null) {
Pair<Integer, Integer> counts = entry.traverseAndUpdateCounts(seniors + 1); Pair<Integer, Integer> counts = entry.traverseAndUpdateCounts(seniors + 1);
juniorCount += counts.getRight(); //total juniors juniorCount += counts.getRight(); //total juniors
if(counts.getLeft() > highestGeneration) highestGeneration = counts.getLeft(); if (counts.getLeft() > highestGeneration) {
highestGeneration = counts.getLeft();
}
} }
} }
setTotalJuniors(juniorCount); setTotalJuniors(juniorCount);
@@ -473,13 +538,15 @@ public class MapleFamilyEntry {
public boolean useEntitlement(FamilyEntitlement entitlement) { public boolean useEntitlement(FamilyEntitlement entitlement) {
int id = entitlement.ordinal(); int id = entitlement.ordinal();
if(entitlements[id] >= 1) return false; if (entitlements[id] >= 1) {
try(Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO family_entitlement (entitlementid, charid, timestamp) VALUES (?, ?, ?)")) { return false;
}
try (Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("INSERT INTO family_entitlement (entitlementid, charid, timestamp) VALUES (?, ?, ?)")) {
ps.setInt(1, id); ps.setInt(1, id);
ps.setInt(2, getChrId()); ps.setInt(2, getChrId());
ps.setLong(3, System.currentTimeMillis()); ps.setLong(3, System.currentTimeMillis());
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not insert new row in 'family_entitlement' for character " + getName() + "."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not insert new row in 'family_entitlement' for character " + getName() + ".");
e.printStackTrace(); e.printStackTrace();
} }
@@ -489,11 +556,11 @@ public class MapleFamilyEntry {
public boolean refundEntitlement(FamilyEntitlement entitlement) { public boolean refundEntitlement(FamilyEntitlement entitlement) {
int id = entitlement.ordinal(); int id = entitlement.ordinal();
try(Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM family_entitlement WHERE entitlementid = ? AND charid = ?")) { try (Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("DELETE FROM family_entitlement WHERE entitlementid = ? AND charid = ?")) {
ps.setInt(1, id); ps.setInt(1, id);
ps.setInt(2, getChrId()); ps.setInt(2, getChrId());
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not refund family entitlement \"" + entitlement.getName() + "\" for character " + getName() + "."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not refund family entitlement \"" + entitlement.getName() + "\" for character " + getName() + ".");
e.printStackTrace(); e.printStackTrace();
} }
@@ -514,16 +581,18 @@ public class MapleFamilyEntry {
} }
public void resetEntitlementUsages() { public void resetEntitlementUsages() {
for(FamilyEntitlement entitlement : FamilyEntitlement.values()) { for (FamilyEntitlement entitlement : FamilyEntitlement.values()) {
entitlements[entitlement.ordinal()] = 0; entitlements[entitlement.ordinal()] = 0;
} }
} }
public boolean saveReputation() { public boolean saveReputation() {
if(!repChanged) return true; if (!repChanged) {
try(Connection con = DatabaseConnection.getConnection()) { return true;
}
try (Connection con = DatabaseConnection.getConnection()) {
return saveReputation(con); return saveReputation(con);
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB."); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB.");
e.printStackTrace(); e.printStackTrace();
return false; return false;
@@ -531,7 +600,9 @@ public class MapleFamilyEntry {
} }
public boolean saveReputation(Connection con) { public boolean saveReputation(Connection con) {
if(!repChanged) return true; if (!repChanged) {
return true;
}
try (PreparedStatement ps = con.prepareStatement("UPDATE family_character SET reputation = ?, todaysrep = ?, totalreputation = ?, reptosenior = ? WHERE cid = ?")) { try (PreparedStatement ps = con.prepareStatement("UPDATE family_character SET reputation = ?, todaysrep = ?, totalreputation = ?, reptosenior = ? WHERE cid = ?")) {
ps.setInt(1, getReputation()); ps.setInt(1, getReputation());
ps.setInt(2, getTodaysRep()); ps.setInt(2, getTodaysRep());
@@ -539,7 +610,7 @@ public class MapleFamilyEntry {
ps.setInt(4, getRepsToSenior()); ps.setInt(4, getRepsToSenior());
ps.setInt(5, getChrId()); ps.setInt(5, getChrId());
ps.executeUpdate(); ps.executeUpdate();
} catch(SQLException e) { } catch (SQLException e) {
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Failed to autosave rep to 'family_character' for charid " + getChrId()); FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Failed to autosave rep to 'family_character' for charid " + getChrId());
e.printStackTrace(); e.printStackTrace();
return false; return false;

View File

@@ -24,7 +24,7 @@ package net.server.channel.handlers;
import client.Character; import client.Character;
import client.Client; import client.Client;
import client.Family; import client.Family;
import client.MapleFamilyEntry; import client.FamilyEntry;
import config.YamlConfig; import config.YamlConfig;
import net.AbstractPacketHandler; import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
@@ -64,7 +64,7 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
if(accept) { if(accept) {
if(inviter.getFamily() != null) { if(inviter.getFamily() != null) {
if(chr.getFamily() == null) { if(chr.getFamily() == null) {
MapleFamilyEntry newEntry = new MapleFamilyEntry(inviter.getFamily(), chr.getId(), chr.getName(), chr.getLevel(), chr.getJob()); FamilyEntry newEntry = new FamilyEntry(inviter.getFamily(), chr.getId(), chr.getName(), chr.getLevel(), chr.getJob());
newEntry.setCharacter(chr); newEntry.setCharacter(chr);
if(!newEntry.setSenior(inviter.getFamilyEntry(), true)) { if(!newEntry.setSenior(inviter.getFamilyEntry(), true)) {
inviter.sendPacket(PacketCreator.sendFamilyMessage(1, 0)); inviter.sendPacket(PacketCreator.sendFamilyMessage(1, 0));
@@ -75,7 +75,7 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
insertNewFamilyRecord(chr.getId(), inviter.getFamily().getID(), inviter.getId(), false); insertNewFamilyRecord(chr.getId(), inviter.getFamily().getID(), inviter.getId(), false);
} }
} else { //absorb target family } else { //absorb target family
MapleFamilyEntry targetEntry = chr.getFamilyEntry(); FamilyEntry targetEntry = chr.getFamilyEntry();
Family targetFamily = targetEntry.getFamily(); Family targetFamily = targetEntry.getFamily();
if(targetFamily.getLeader() != targetEntry) return; if(targetFamily.getLeader() != targetEntry) return;
if(inviter.getFamily().getTotalGenerations() + targetFamily.getTotalGenerations() <= YamlConfig.config.server.FAMILY_MAX_GENERATIONS) { if(inviter.getFamily().getTotalGenerations() + targetFamily.getTotalGenerations() <= YamlConfig.config.server.FAMILY_MAX_GENERATIONS) {
@@ -94,12 +94,12 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
} }
Family newFamily = new Family(-1, c.getWorld()); Family newFamily = new Family(-1, c.getWorld());
c.getWorldServer().addFamily(newFamily.getID(), newFamily); c.getWorldServer().addFamily(newFamily.getID(), newFamily);
MapleFamilyEntry inviterEntry = new MapleFamilyEntry(newFamily, inviter.getId(), inviter.getName(), inviter.getLevel(), inviter.getJob()); FamilyEntry inviterEntry = new FamilyEntry(newFamily, inviter.getId(), inviter.getName(), inviter.getLevel(), inviter.getJob());
inviterEntry.setCharacter(inviter); inviterEntry.setCharacter(inviter);
newFamily.setLeader(inviter.getFamilyEntry()); newFamily.setLeader(inviter.getFamilyEntry());
newFamily.addEntry(inviterEntry); newFamily.addEntry(inviterEntry);
if(chr.getFamily() == null) { //completely new family if(chr.getFamily() == null) { //completely new family
MapleFamilyEntry newEntry = new MapleFamilyEntry(newFamily, chr.getId(), chr.getName(), chr.getLevel(), chr.getJob()); FamilyEntry newEntry = new FamilyEntry(newFamily, chr.getId(), chr.getName(), chr.getLevel(), chr.getJob());
newEntry.setCharacter(chr); newEntry.setCharacter(chr);
newEntry.setSenior(inviterEntry, true); newEntry.setSenior(inviterEntry, true);
// save new family // save new family

View File

@@ -21,7 +21,7 @@ package net.server.channel.handlers;
import client.Client; import client.Client;
import client.Family; import client.Family;
import client.MapleFamilyEntry; import client.FamilyEntry;
import config.YamlConfig; import config.YamlConfig;
import net.AbstractPacketHandler; import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
@@ -34,7 +34,7 @@ public class FamilySeparateHandler extends AbstractPacketHandler {
if(!YamlConfig.config.server.USE_FAMILY_SYSTEM) return; if(!YamlConfig.config.server.USE_FAMILY_SYSTEM) return;
Family oldFamily = c.getPlayer().getFamily(); Family oldFamily = c.getPlayer().getFamily();
if(oldFamily == null) return; if(oldFamily == null) return;
MapleFamilyEntry forkOn = null; FamilyEntry forkOn = null;
boolean isSenior; boolean isSenior;
if(p.available() > 0) { //packet 0x95 doesn't send id, since there is only one senior if(p.available() > 0) { //packet 0x95 doesn't send id, since there is only one senior
forkOn = c.getPlayer().getFamily().getEntryByID(p.readInt()); forkOn = c.getPlayer().getFamily().getEntryByID(p.readInt());
@@ -46,7 +46,7 @@ public class FamilySeparateHandler extends AbstractPacketHandler {
} }
if(forkOn == null) return; if(forkOn == null) return;
MapleFamilyEntry senior = forkOn.getSenior(); FamilyEntry senior = forkOn.getSenior();
if(senior == null) return; if(senior == null) return;
int levelDiff = Math.abs(c.getPlayer().getLevel() - senior.getLevel()); int levelDiff = Math.abs(c.getPlayer().getLevel() - senior.getLevel());
int cost = 2500 * levelDiff; int cost = 2500 * levelDiff;
@@ -67,7 +67,7 @@ public class FamilySeparateHandler extends AbstractPacketHandler {
} }
private static int separateRepCost(MapleFamilyEntry junior) { private static int separateRepCost(FamilyEntry junior) {
int level = junior.getLevel(); int level = junior.getLevel();
int ret = level / 20; int ret = level / 20;
ret += 10; ret += 10;

View File

@@ -3,7 +3,7 @@ package net.server.channel.handlers;
import client.Character; import client.Character;
import client.Client; import client.Client;
import client.FamilyEntitlement; import client.FamilyEntitlement;
import client.MapleFamilyEntry; import client.FamilyEntry;
import config.YamlConfig; import config.YamlConfig;
import net.AbstractPacketHandler; import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
@@ -24,7 +24,7 @@ public class FamilySummonResponseHandler extends AbstractPacketHandler {
MapleInviteResult inviteResult = MapleInviteCoordinator.answerInvite(InviteType.FAMILY_SUMMON, c.getPlayer().getId(), c.getPlayer(), accept); MapleInviteResult inviteResult = MapleInviteCoordinator.answerInvite(InviteType.FAMILY_SUMMON, c.getPlayer().getId(), c.getPlayer(), accept);
if(inviteResult.result == InviteResult.NOT_FOUND) return; if(inviteResult.result == InviteResult.NOT_FOUND) return;
Character inviter = inviteResult.from; Character inviter = inviteResult.from;
MapleFamilyEntry inviterEntry = inviter.getFamilyEntry(); FamilyEntry inviterEntry = inviter.getFamilyEntry();
if(inviterEntry == null) return; if(inviterEntry == null) return;
MapleMap map = (MapleMap) inviteResult.params[0]; MapleMap map = (MapleMap) inviteResult.params[0];
if(accept && inviter.getMap() == map) { //cancel if inviter has changed maps if(accept && inviter.getMap() == map) { //cancel if inviter has changed maps

View File

@@ -24,7 +24,7 @@ package net.server.channel.handlers;
import client.Character; import client.Character;
import client.Client; import client.Client;
import client.FamilyEntitlement; import client.FamilyEntitlement;
import client.MapleFamilyEntry; import client.FamilyEntry;
import config.YamlConfig; import config.YamlConfig;
import net.AbstractPacketHandler; import net.AbstractPacketHandler;
import net.packet.InPacket; import net.packet.InPacket;
@@ -47,7 +47,7 @@ public final class FamilyUseHandler extends AbstractPacketHandler {
} }
FamilyEntitlement type = FamilyEntitlement.values()[p.readInt()]; FamilyEntitlement type = FamilyEntitlement.values()[p.readInt()];
int cost = type.getRepCost(); int cost = type.getRepCost();
MapleFamilyEntry entry = c.getPlayer().getFamilyEntry(); FamilyEntry entry = c.getPlayer().getFamilyEntry();
if(entry.getReputation() < cost || entry.isEntitlementUsed(type)) { if(entry.getReputation() < cost || entry.isEntitlementUsed(type)) {
return; // shouldn't even be able to request it return; // shouldn't even be able to request it
} }
@@ -130,7 +130,7 @@ public final class FamilyUseHandler extends AbstractPacketHandler {
} }
} }
private boolean useEntitlement(MapleFamilyEntry entry, FamilyEntitlement entitlement) { private boolean useEntitlement(FamilyEntry entry, FamilyEntitlement entitlement) {
if(entry.useEntitlement(entitlement)) { if(entry.useEntitlement(entitlement)) {
entry.gainReputation(-entitlement.getRepCost(), false); entry.gainReputation(-entitlement.getRepCost(), false);
entry.getChr().sendPacket(PacketCreator.getFamilyInfo(entry)); entry.getChr().sendPacket(PacketCreator.getFamilyInfo(entry));

View File

@@ -249,7 +249,7 @@ public final class PlayerLoggedinHandler extends AbstractPacketHandler {
if (player.getFamilyId() > 0) { if (player.getFamilyId() > 0) {
Family f = wserv.getFamily(player.getFamilyId()); Family f = wserv.getFamily(player.getFamilyId());
if (f != null) { if (f != null) {
MapleFamilyEntry familyEntry = f.getEntryByID(player.getId()); FamilyEntry familyEntry = f.getEntryByID(player.getId());
if (familyEntry != null) { if (familyEntry != null) {
familyEntry.setCharacter(player); familyEntry.setCharacter(player);
player.setFamilyEntry(familyEntry); player.setFamilyEntry(familyEntry);

View File

@@ -943,7 +943,7 @@ public class MapleMonster extends AbstractLoadedMapleLife {
} }
} }
private void giveFamilyRep(MapleFamilyEntry entry) { private void giveFamilyRep(FamilyEntry entry) {
if(entry != null) { if(entry != null) {
int repGain = isBoss() ? YamlConfig.config.server.FAMILY_REP_PER_BOSS_KILL : YamlConfig.config.server.FAMILY_REP_PER_KILL; int repGain = isBoss() ? YamlConfig.config.server.FAMILY_REP_PER_BOSS_KILL : YamlConfig.config.server.FAMILY_REP_PER_KILL;
if(getMaxHp() <= 1) repGain = 0; //don't count trash mobs if(getMaxHp() <= 1) repGain = 0; //don't count trash mobs

View File

@@ -5801,7 +5801,7 @@ public class PacketCreator {
return p; return p;
} }
public static Packet getFamilyInfo(MapleFamilyEntry f) { public static Packet getFamilyInfo(FamilyEntry f) {
if (f == null) { if (f == null) {
return getEmptyFamilyInfo(); return getEmptyFamilyInfo();
} }
@@ -5839,10 +5839,10 @@ public class PacketCreator {
return p; return p;
} }
public static Packet showPedigree(MapleFamilyEntry entry) { public static Packet showPedigree(FamilyEntry entry) {
final OutPacket p = OutPacket.create(SendOpcode.FAMILY_CHART_RESULT); final OutPacket p = OutPacket.create(SendOpcode.FAMILY_CHART_RESULT);
p.writeInt(entry.getChrId()); //ID of viewed player's pedigree, can't be leader? p.writeInt(entry.getChrId()); //ID of viewed player's pedigree, can't be leader?
List<MapleFamilyEntry> superJuniors = new ArrayList<>(4); List<FamilyEntry> superJuniors = new ArrayList<>(4);
boolean hasOtherJunior = false; boolean hasOtherJunior = false;
int entryCount = 2; //2 guaranteed, leader and self int entryCount = 2; //2 guaranteed, leader and self
entryCount += Math.min(2, entry.getTotalSeniors()); entryCount += Math.min(2, entry.getTotalSeniors());
@@ -5853,12 +5853,12 @@ public class PacketCreator {
hasOtherJunior = true; hasOtherJunior = true;
} }
} }
for (MapleFamilyEntry junior : entry.getJuniors()) { for (FamilyEntry junior : entry.getJuniors()) {
if (junior == null) { if (junior == null) {
continue; continue;
} }
entryCount++; entryCount++;
for (MapleFamilyEntry superJunior : junior.getJuniors()) { for (FamilyEntry superJunior : junior.getJuniors()) {
if (superJunior == null) { if (superJunior == null) {
continue; continue;
} }
@@ -5881,7 +5881,7 @@ public class PacketCreator {
} }
addPedigreeEntry(p, entry); addPedigreeEntry(p, entry);
if (hasOtherJunior) { //must be sent after own entry if (hasOtherJunior) { //must be sent after own entry
MapleFamilyEntry otherJunior = entry.getSenior().getOtherJunior(entry); FamilyEntry otherJunior = entry.getSenior().getOtherJunior(entry);
if (otherJunior != null) { if (otherJunior != null) {
addPedigreeEntry(p, otherJunior); addPedigreeEntry(p, otherJunior);
} }
@@ -5889,12 +5889,12 @@ public class PacketCreator {
if (missingEntries) { if (missingEntries) {
addPedigreeEntry(p, entry); addPedigreeEntry(p, entry);
} }
for (MapleFamilyEntry junior : entry.getJuniors()) { for (FamilyEntry junior : entry.getJuniors()) {
if (junior == null) { if (junior == null) {
continue; continue;
} }
addPedigreeEntry(p, junior); addPedigreeEntry(p, junior);
for (MapleFamilyEntry superJunior : junior.getJuniors()) { for (FamilyEntry superJunior : junior.getJuniors()) {
if (superJunior != null) { if (superJunior != null) {
addPedigreeEntry(p, superJunior); addPedigreeEntry(p, superJunior);
} }
@@ -5906,7 +5906,7 @@ public class PacketCreator {
p.writeInt(entry.getFamily().getTotalMembers()); p.writeInt(entry.getFamily().getTotalMembers());
p.writeInt(0); p.writeInt(0);
p.writeInt(entry.getTotalSeniors()); //client subtracts provided seniors p.writeInt(entry.getTotalSeniors()); //client subtracts provided seniors
for (MapleFamilyEntry superJunior : superJuniors) { for (FamilyEntry superJunior : superJuniors) {
p.writeInt(superJunior.getChrId()); p.writeInt(superJunior.getChrId());
p.writeInt(superJunior.getTotalJuniors()); p.writeInt(superJunior.getTotalJuniors());
} }
@@ -5917,7 +5917,7 @@ public class PacketCreator {
return p; return p;
} }
private static void addPedigreeEntry(OutPacket p, MapleFamilyEntry entry) { private static void addPedigreeEntry(OutPacket p, FamilyEntry entry) {
Character chr = entry.getChr(); Character chr = entry.getChr();
boolean isOnline = chr != null; boolean isOnline = chr != null;
p.writeInt(entry.getChrId()); //ID p.writeInt(entry.getChrId()); //ID