Rename and clean up MapleFamily
This commit is contained in:
@@ -1154,7 +1154,7 @@ public class Character extends AbstractCharacterObject {
|
||||
if (this.guildid > 0) {
|
||||
getGuild().broadcast(PacketCreator.jobMessage(0, job.getId(), name), this.getId());
|
||||
}
|
||||
MapleFamily family = getFamily();
|
||||
Family family = getFamily();
|
||||
if (family != null) {
|
||||
family.broadcast(PacketCreator.jobMessage(1, job.getId(), name), this.getId());
|
||||
}
|
||||
@@ -1183,7 +1183,7 @@ public class Character extends AbstractCharacterObject {
|
||||
|
||||
public void broadcastAcquaintances(Packet packet) {
|
||||
buddylist.broadcast(packet, getWorldServer().getPlayerStorage());
|
||||
MapleFamily family = getFamily();
|
||||
Family family = getFamily();
|
||||
if (family != null) {
|
||||
family.broadcast(packet, id);
|
||||
}
|
||||
@@ -4955,7 +4955,7 @@ public class Character extends AbstractCharacterObject {
|
||||
return fame;
|
||||
}
|
||||
|
||||
public MapleFamily getFamily() {
|
||||
public Family getFamily() {
|
||||
if (familyEntry != null) {
|
||||
return familyEntry.getFamily();
|
||||
} else {
|
||||
@@ -10419,7 +10419,7 @@ public class Character extends AbstractCharacterObject {
|
||||
guild.broadcast(PacketCreator.marriageMessage(0, name));
|
||||
}
|
||||
|
||||
MapleFamily family = this.getFamily();
|
||||
Family family = this.getFamily();
|
||||
if (family != null) {
|
||||
family.broadcast(PacketCreator.marriageMessage(1, name));
|
||||
}
|
||||
|
||||
@@ -983,7 +983,7 @@ public class Client extends ChannelInboundHandlerAdapter {
|
||||
}
|
||||
/*
|
||||
if (fid > 0) {
|
||||
final MapleFamily family = worlda.getFamily(fid);
|
||||
final Family family = worlda.getFamily(fid);
|
||||
family.
|
||||
}
|
||||
*/
|
||||
|
||||
@@ -41,11 +41,10 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Jay Estrella - Mr.Trash :3
|
||||
* @author Ubaware
|
||||
*/
|
||||
public class MapleFamily {
|
||||
public class Family {
|
||||
|
||||
private static final AtomicInteger familyIDCounter = new AtomicInteger();
|
||||
|
||||
@@ -56,11 +55,11 @@ public class MapleFamily {
|
||||
private String preceptsMessage = "";
|
||||
private int totalGenerations;
|
||||
|
||||
public MapleFamily(int id, int world) {
|
||||
public Family(int id, int world) {
|
||||
int newId = id;
|
||||
if(id == -1) {
|
||||
if (id == -1) {
|
||||
// get next available family id
|
||||
while(idInUse(newId = familyIDCounter.incrementAndGet())) {
|
||||
while (idInUse(newId = familyIDCounter.incrementAndGet())) {
|
||||
}
|
||||
}
|
||||
this.id = newId;
|
||||
@@ -68,8 +67,10 @@ public class MapleFamily {
|
||||
}
|
||||
|
||||
private static boolean idInUse(int id) {
|
||||
for(World world : Server.getInstance().getWorlds()) {
|
||||
if(world.getFamily(id) != null) return true;
|
||||
for (World world : Server.getInstance().getWorlds()) {
|
||||
if (world.getFamily(id) != null) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -98,11 +99,11 @@ public class MapleFamily {
|
||||
public int getTotalMembers() {
|
||||
return members.size();
|
||||
}
|
||||
|
||||
|
||||
public int getTotalGenerations() {
|
||||
return totalGenerations;
|
||||
}
|
||||
|
||||
|
||||
public void setTotalGenerations(int generations) {
|
||||
this.totalGenerations = generations;
|
||||
}
|
||||
@@ -113,13 +114,13 @@ public class MapleFamily {
|
||||
|
||||
public void setMessage(String message, boolean save) {
|
||||
this.preceptsMessage = message;
|
||||
if(save) {
|
||||
if (save) {
|
||||
try (Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE family_character SET precepts = ? WHERE cid = ?")) {
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE family_character SET precepts = ? WHERE cid = ?")) {
|
||||
ps.setString(1, message);
|
||||
ps.setInt(2, getLeader().getChrId());
|
||||
ps.executeUpdate();
|
||||
} catch(SQLException e) {
|
||||
} catch (SQLException e) {
|
||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not save new precepts for family " + getID() + ".");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -136,15 +137,19 @@ public class MapleFamily {
|
||||
|
||||
public void removeEntryBranch(MapleFamilyEntry root) {
|
||||
members.remove(root.getChrId());
|
||||
for(MapleFamilyEntry junior : root.getJuniors()) {
|
||||
if(junior != null) removeEntryBranch(junior);
|
||||
for (MapleFamilyEntry junior : root.getJuniors()) {
|
||||
if (junior != null) {
|
||||
removeEntryBranch(junior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void addEntryTree(MapleFamilyEntry root) {
|
||||
members.put(root.getChrId(), root);
|
||||
for(MapleFamilyEntry junior : root.getJuniors()) {
|
||||
if(junior != null) addEntryTree(junior);
|
||||
for (MapleFamilyEntry junior : root.getJuniors()) {
|
||||
if (junior != null) {
|
||||
addEntryTree(junior);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,26 +162,28 @@ public class MapleFamily {
|
||||
}
|
||||
|
||||
public void broadcast(Packet packet, int ignoreID) {
|
||||
for(MapleFamilyEntry entry : members.values()) {
|
||||
for (MapleFamilyEntry entry : members.values()) {
|
||||
Character chr = entry.getChr();
|
||||
if(chr != null) {
|
||||
if(chr.getId() == ignoreID) continue;
|
||||
if (chr != null) {
|
||||
if (chr.getId() == ignoreID) {
|
||||
continue;
|
||||
}
|
||||
chr.sendPacket(packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void broadcastFamilyInfoUpdate() {
|
||||
for(MapleFamilyEntry entry : members.values()) {
|
||||
for (MapleFamilyEntry entry : members.values()) {
|
||||
Character chr = entry.getChr();
|
||||
if(chr != null) {
|
||||
if (chr != null) {
|
||||
chr.sendPacket(PacketCreator.getFamilyInfo(entry));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void resetDailyReps() {
|
||||
for(MapleFamilyEntry entry : members.values()) {
|
||||
for (MapleFamilyEntry entry : members.values()) {
|
||||
entry.setTodaysRep(0);
|
||||
entry.setRepsToSenior(0);
|
||||
entry.resetEntitlementUsages();
|
||||
@@ -221,9 +228,9 @@ public class MapleFamily {
|
||||
if (wserv == null) {
|
||||
continue;
|
||||
}
|
||||
MapleFamily family = wserv.getFamily(familyid);
|
||||
Family family = wserv.getFamily(familyid);
|
||||
if (family == null) {
|
||||
family = new MapleFamily(familyid, world);
|
||||
family = new Family(familyid, world);
|
||||
Server.getInstance().getWorld(world).addFamily(familyid, family);
|
||||
}
|
||||
MapleFamilyEntry familyEntry = new MapleFamilyEntry(family, cid, name, level, MapleJob.getById(jobID));
|
||||
@@ -271,30 +278,32 @@ public class MapleFamily {
|
||||
}
|
||||
|
||||
for (World world : Server.getInstance().getWorlds()) {
|
||||
for (MapleFamily family : world.getFamilies()) {
|
||||
for (Family family : world.getFamilies()) {
|
||||
family.getLeader().doFullCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void saveAllMembersRep() { //was used for autosave task, but character autosave should be enough
|
||||
try(Connection con = DatabaseConnection.getConnection()) {
|
||||
try (Connection con = DatabaseConnection.getConnection()) {
|
||||
con.setAutoCommit(false);
|
||||
boolean success = true;
|
||||
for(MapleFamilyEntry entry : members.values()) {
|
||||
for (MapleFamilyEntry entry : members.values()) {
|
||||
success = entry.saveReputation(con);
|
||||
if(!success) break;
|
||||
if (!success) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!success) {
|
||||
if (!success) {
|
||||
con.rollback();
|
||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Family rep autosave failed for family " + getID() + " on " + Calendar.getInstance().getTime().toString() + ".");
|
||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, "Family rep autosave failed for family " + getID() + " on " + Calendar.getInstance().getTime() + ".");
|
||||
}
|
||||
con.setAutoCommit(true);
|
||||
//reset repChanged after successful save
|
||||
for(MapleFamilyEntry entry : members.values()) {
|
||||
for (MapleFamilyEntry entry : members.values()) {
|
||||
entry.savedSuccessfully();
|
||||
}
|
||||
} catch(SQLException e) {
|
||||
} catch (SQLException e) {
|
||||
FilePrinter.printError(FilePrinter.FAMILY_ERROR, e, "Could not get connection to DB.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -39,7 +39,7 @@ import java.util.List;
|
||||
|
||||
public class MapleFamilyEntry {
|
||||
private final int characterID;
|
||||
private volatile MapleFamily family;
|
||||
private volatile Family family;
|
||||
private volatile Character character;
|
||||
|
||||
private volatile MapleFamilyEntry senior;
|
||||
@@ -58,7 +58,7 @@ public class MapleFamilyEntry {
|
||||
private int level;
|
||||
private MapleJob job;
|
||||
|
||||
public MapleFamilyEntry(MapleFamily family, int characterID, String charName, int level, MapleJob job) {
|
||||
public MapleFamilyEntry(Family family, int characterID, String charName, int level, MapleJob job) {
|
||||
this.family = family;
|
||||
this.characterID = characterID;
|
||||
this.charName = charName;
|
||||
@@ -86,8 +86,8 @@ public class MapleFamilyEntry {
|
||||
|
||||
public synchronized void join(MapleFamilyEntry senior) {
|
||||
if(senior == null || getSenior() != null) return;
|
||||
MapleFamily oldFamily = getFamily();
|
||||
MapleFamily newFamily = senior.getFamily();
|
||||
Family oldFamily = getFamily();
|
||||
Family newFamily = senior.getFamily();
|
||||
setSenior(senior, false);
|
||||
addSeniorCount(newFamily.getTotalGenerations(), newFamily); //count will be overwritten by doFullCount()
|
||||
newFamily.getLeader().doFullCount(); //easier than keeping track of numbers
|
||||
@@ -117,9 +117,9 @@ public class MapleFamilyEntry {
|
||||
}
|
||||
|
||||
public synchronized void fork() {
|
||||
MapleFamily oldFamily = getFamily();
|
||||
Family oldFamily = getFamily();
|
||||
MapleFamilyEntry oldSenior = getSenior();
|
||||
family = new MapleFamily(-1, oldFamily.getWorld());
|
||||
family = new Family(-1, oldFamily.getWorld());
|
||||
Server.getInstance().getWorld(family.getWorld()).addFamily(family.getID(), family);
|
||||
setSenior(null, false);
|
||||
family.setLeader(this);
|
||||
@@ -185,7 +185,7 @@ public class MapleFamilyEntry {
|
||||
return true;
|
||||
}
|
||||
|
||||
private synchronized void addSeniorCount(int seniorCount, MapleFamily 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;
|
||||
setTotalSeniors(getTotalSeniors() + seniorCount);
|
||||
this.generation += seniorCount;
|
||||
@@ -200,7 +200,7 @@ public class MapleFamilyEntry {
|
||||
if(senior != null) senior.addJuniorCount(juniorCount);
|
||||
}
|
||||
|
||||
public MapleFamily getFamily() {
|
||||
public Family getFamily() {
|
||||
return family;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ package net.server;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import client.SkillFactory;
|
||||
import client.command.CommandsExecutor;
|
||||
import client.inventory.Item;
|
||||
@@ -857,7 +857,7 @@ public class Server {
|
||||
applyAllWorldTransfers(con);
|
||||
|
||||
if (YamlConfig.config.server.USE_FAMILY_SYSTEM) {
|
||||
MapleFamily.loadAllFamilies(con);
|
||||
Family.loadAllFamilies(con);
|
||||
}
|
||||
} catch (SQLException sqle) {
|
||||
log.error("Failed to run all startup-bound database tasks", sqle);
|
||||
|
||||
@@ -23,7 +23,7 @@ package net.server.channel.handlers;
|
||||
|
||||
import client.Character;
|
||||
import client.Client;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import client.MapleFamilyEntry;
|
||||
import config.YamlConfig;
|
||||
import net.AbstractPacketHandler;
|
||||
@@ -76,7 +76,7 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
|
||||
}
|
||||
} else { //absorb target family
|
||||
MapleFamilyEntry targetEntry = chr.getFamilyEntry();
|
||||
MapleFamily targetFamily = targetEntry.getFamily();
|
||||
Family targetFamily = targetEntry.getFamily();
|
||||
if(targetFamily.getLeader() != targetEntry) return;
|
||||
if(inviter.getFamily().getTotalGenerations() + targetFamily.getTotalGenerations() <= YamlConfig.config.server.FAMILY_MAX_GENERATIONS) {
|
||||
targetEntry.join(inviter.getFamilyEntry());
|
||||
@@ -92,7 +92,7 @@ public final class AcceptFamilyHandler extends AbstractPacketHandler {
|
||||
chr.sendPacket(PacketCreator.sendFamilyMessage(76, 0));
|
||||
return;
|
||||
}
|
||||
MapleFamily newFamily = new MapleFamily(-1, c.getWorld());
|
||||
Family newFamily = new Family(-1, c.getWorld());
|
||||
c.getWorldServer().addFamily(newFamily.getID(), newFamily);
|
||||
MapleFamilyEntry inviterEntry = new MapleFamilyEntry(newFamily, inviter.getId(), inviter.getName(), inviter.getLevel(), inviter.getJob());
|
||||
inviterEntry.setCharacter(inviter);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.server.channel.handlers;
|
||||
|
||||
import client.Client;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import net.AbstractPacketHandler;
|
||||
import net.packet.InPacket;
|
||||
import tools.PacketCreator;
|
||||
@@ -10,7 +10,7 @@ public class FamilyPreceptsHandler extends AbstractPacketHandler {
|
||||
|
||||
@Override
|
||||
public void handlePacket(InPacket p, Client c) {
|
||||
MapleFamily family = c.getPlayer().getFamily();
|
||||
Family family = c.getPlayer().getFamily();
|
||||
if(family == null) return;
|
||||
if(family.getLeader().getChr() != c.getPlayer()) return; //only the leader can set the precepts
|
||||
String newPrecepts = p.readString();
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
package net.server.channel.handlers;
|
||||
|
||||
import client.Client;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import client.MapleFamilyEntry;
|
||||
import config.YamlConfig;
|
||||
import net.AbstractPacketHandler;
|
||||
@@ -32,7 +32,7 @@ public class FamilySeparateHandler extends AbstractPacketHandler {
|
||||
@Override
|
||||
public void handlePacket(InPacket p, Client c) {
|
||||
if(!YamlConfig.config.server.USE_FAMILY_SYSTEM) return;
|
||||
MapleFamily oldFamily = c.getPlayer().getFamily();
|
||||
Family oldFamily = c.getPlayer().getFamily();
|
||||
if(oldFamily == null) return;
|
||||
MapleFamilyEntry forkOn = null;
|
||||
boolean isSenior;
|
||||
|
||||
@@ -247,7 +247,7 @@ public final class PlayerLoggedinHandler extends AbstractPacketHandler {
|
||||
|
||||
c.sendPacket(PacketCreator.loadFamily(player));
|
||||
if (player.getFamilyId() > 0) {
|
||||
MapleFamily f = wserv.getFamily(player.getFamilyId());
|
||||
Family f = wserv.getFamily(player.getFamilyId());
|
||||
if (f != null) {
|
||||
MapleFamilyEntry familyEntry = f.getEntryByID(player.getId());
|
||||
if (familyEntry != null) {
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
package net.server.handlers.login;
|
||||
|
||||
import client.Client;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import net.AbstractPacketHandler;
|
||||
import net.packet.InPacket;
|
||||
import net.server.Server;
|
||||
@@ -60,7 +60,7 @@ public final class DeleteCharHandler extends AbstractPacketHandler {
|
||||
c.sendPacket(PacketCreator.deleteCharResponse(cid, 0x16));
|
||||
return;
|
||||
} else if (familyId != -1) {
|
||||
MapleFamily family = Server.getInstance().getWorld(world).getFamily(familyId);
|
||||
Family family = Server.getInstance().getWorld(world).getFamily(familyId);
|
||||
if (family != null && family.getTotalMembers() > 1) {
|
||||
c.sendPacket(PacketCreator.deleteCharResponse(cid, 0x1D));
|
||||
return;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package net.server.task;
|
||||
|
||||
import client.Family;
|
||||
import net.server.world.World;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Calendar;
|
||||
|
||||
import client.MapleFamily;
|
||||
import net.server.world.World;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.FilePrinter;
|
||||
|
||||
public class FamilyDailyResetTask implements Runnable {
|
||||
|
||||
private final World world;
|
||||
@@ -21,7 +21,7 @@ public class FamilyDailyResetTask implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
resetEntitlementUsage(world);
|
||||
for(MapleFamily family : world.getFamilies()) {
|
||||
for(Family family : world.getFamilies()) {
|
||||
family.resetDailyReps();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import client.BuddyList.BuddyAddResult;
|
||||
import client.BuddyList.BuddyOperation;
|
||||
import client.BuddylistEntry;
|
||||
import client.Character;
|
||||
import client.MapleFamily;
|
||||
import client.Family;
|
||||
import config.YamlConfig;
|
||||
import constants.game.GameConstants;
|
||||
import net.packet.Packet;
|
||||
@@ -82,7 +82,7 @@ public class World {
|
||||
private Map<Integer, Short> pnpcPodium = new HashMap<>();
|
||||
private Map<Integer, MapleMessenger> messengers = new HashMap<>();
|
||||
private AtomicInteger runningMessengerId = new AtomicInteger();
|
||||
private Map<Integer, MapleFamily> families = new LinkedHashMap<>();
|
||||
private Map<Integer, Family> families = new LinkedHashMap<>();
|
||||
private Map<Integer, Integer> relationships = new HashMap<>();
|
||||
private Map<Integer, Pair<Integer, Integer>> relationshipCouples = new HashMap<>();
|
||||
private Map<Integer, MapleGuildSummary> gsStore = new HashMap<>();
|
||||
@@ -547,7 +547,7 @@ public class World {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void addFamily(int id, MapleFamily f) {
|
||||
public void addFamily(int id, Family f) {
|
||||
synchronized (families) {
|
||||
if (!families.containsKey(id)) {
|
||||
families.put(id, f);
|
||||
@@ -561,7 +561,7 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public MapleFamily getFamily(int id) {
|
||||
public Family getFamily(int id) {
|
||||
synchronized (families) {
|
||||
if (families.containsKey(id)) {
|
||||
return families.get(id);
|
||||
@@ -570,7 +570,7 @@ public class World {
|
||||
}
|
||||
}
|
||||
|
||||
public Collection<MapleFamily> getFamilies() {
|
||||
public Collection<Family> getFamilies() {
|
||||
synchronized(families) {
|
||||
return Collections.unmodifiableCollection(families.values());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user