Partial solution on Guild Alliances
Revamped DB tables and enabled some functionalities on Guild Alliances, such as create one, expel/quit one and rank players.
This commit is contained in:
@@ -55,6 +55,7 @@ import net.server.PlayerCoolDownValueHolder;
|
||||
import net.server.PlayerDiseaseValueHolder;
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.world.MapleMessenger;
|
||||
@@ -2205,6 +2206,18 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MapleAlliance getAlliance() {
|
||||
if(mgc != null) {
|
||||
try {
|
||||
return Server.getInstance().getAlliance(getGuild().getAllianceId());
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getGuildId() {
|
||||
return guildid;
|
||||
@@ -3351,7 +3364,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ret.dojoStage = rs.getInt("lastDojoStage");
|
||||
ret.dataString = rs.getString("dataString");
|
||||
if (ret.guildid > 0) {
|
||||
ret.mgc = new MapleGuildCharacter(ret);
|
||||
ret.mgc = new MapleGuildCharacter(ret); // oh boy, that's quite funny
|
||||
}
|
||||
int buddyCapacity = rs.getInt("buddyCapacity");
|
||||
ret.buddylist = new BuddyList(buddyCapacity);
|
||||
@@ -4147,8 +4160,8 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
}
|
||||
}
|
||||
|
||||
public void resetMGC() {
|
||||
this.mgc = null;
|
||||
public void resetMGC(MapleGuildCharacter mgc) {
|
||||
this.mgc = mgc;
|
||||
}
|
||||
|
||||
public synchronized void saveCooldowns() {
|
||||
@@ -4179,7 +4192,7 @@ public class MapleCharacter extends AbstractAnimatedMapleMapObject {
|
||||
ps.setInt(2, guildrank);
|
||||
ps.setInt(3, allianceRank);
|
||||
ps.setInt(4, id);
|
||||
ps.execute();
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
|
||||
@@ -786,6 +786,8 @@ public class MapleClient {
|
||||
final MapleGuild guild = player.getGuild();
|
||||
|
||||
if (channel == -1 || shutdown) {
|
||||
chrg.setCharacter(null);
|
||||
|
||||
removePlayer();
|
||||
player.saveCooldowns();
|
||||
player.saveToDB();
|
||||
@@ -944,7 +946,7 @@ public class MapleClient {
|
||||
}
|
||||
if (rs.getInt("guildid") > 0) {
|
||||
try {
|
||||
Server.getInstance().deleteGuildCharacter(new MapleGuildCharacter(cid, 0, rs.getString("name"), (byte) -1, (byte) -1, 0, rs.getInt("guildrank"), rs.getInt("guildid"), false, rs.getInt("allianceRank")));
|
||||
Server.getInstance().deleteGuildCharacter(new MapleGuildCharacter(player, cid, 0, rs.getString("name"), (byte) -1, (byte) -1, 0, rs.getInt("guildrank"), rs.getInt("guildid"), false, rs.getInt("allianceRank")));
|
||||
} catch (Exception re) {
|
||||
re.printStackTrace();
|
||||
return false;
|
||||
|
||||
@@ -316,7 +316,12 @@ public class Commands {
|
||||
switch (sub[0]) {
|
||||
case "help":
|
||||
case "commands":
|
||||
player.yellowMessage("After you vote, talk to Rooney to get a leaf and redeem it for prizes!");
|
||||
|
||||
|
||||
case "playercommands":
|
||||
player.message("============================================================");
|
||||
player.message("MapleSolaxiaV2 Player Commands");
|
||||
player.message("============================================================");
|
||||
player.message("@dispose: Fixes your character if it is stuck.");
|
||||
player.message("@online: Displays a list of all online players.");
|
||||
player.message("@time: Displays the current server time.");
|
||||
@@ -368,10 +373,6 @@ public class Commands {
|
||||
player.yellowMessage("Solaxia has been online for " + days + " days " + hours + " hours " + minutes + " minutes and " + seconds + " seconds.");
|
||||
break;
|
||||
case "gacha":
|
||||
if (player.gmLevel() == 0) { // Sigh, need it for now...
|
||||
player.yellowMessage("Player Command " + heading + sub[0] + " does not exist, see @help for a list of commands.");
|
||||
return false;
|
||||
}
|
||||
Gachapon gacha = null;
|
||||
String search = joinStringFrom(sub, 1);
|
||||
String gachaName = "";
|
||||
@@ -478,7 +479,11 @@ public class Commands {
|
||||
player.message("You've been disposed.");
|
||||
break;
|
||||
case "rates":
|
||||
c.resetVoteTime();
|
||||
//c.resetVoteTime();
|
||||
player.yellowMessage("BOSSDROP RATE");
|
||||
player.message(">>Total BOSSDROP Rate: " + c.getWorldServer().getBossDropRate() + "x");
|
||||
player.message(">>------------------------------------------------");
|
||||
|
||||
player.yellowMessage("DROP RATE");
|
||||
player.message(">>Base DROP Rate: " + c.getWorldServer().getDropRate() + "x");
|
||||
player.message(">>Your DROP Rate: " + player.getDropRate() / c.getWorldServer().getDropRate() + "x");
|
||||
@@ -671,7 +676,7 @@ public class Commands {
|
||||
|
||||
default:
|
||||
if (player.gmLevel() == 0) {
|
||||
player.yellowMessage("Player Command " + heading + sub[0] + " does not exist, see @help for a list of commands.");
|
||||
player.yellowMessage("Player Command " + heading + sub[0] + " does not exist, see @playercommands for a list of commands.");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -683,7 +688,12 @@ public class Commands {
|
||||
Channel cserv = c.getChannelServer();
|
||||
Server srv = Server.getInstance();
|
||||
|
||||
if (sub[0].equals("sp")) {
|
||||
if (sub[0].equals("commands")) {
|
||||
player.message("============================================================");
|
||||
player.message("MapleSolaxiaV2 GM/Admin Commands Available");
|
||||
player.message("============================================================");
|
||||
}
|
||||
else if (sub[0].equals("sp")) {
|
||||
if (sub.length < 2){
|
||||
player.yellowMessage("Syntax: !sp [<playername>] <newsp>");
|
||||
return true;
|
||||
@@ -1571,7 +1581,6 @@ public class Commands {
|
||||
SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player);
|
||||
} else if (sub[0].equals("unhide")) {
|
||||
SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player);
|
||||
|
||||
} else if (sub[0].equals("healmap")) {
|
||||
for (MapleCharacter mch : player.getMap().getCharacters()) {
|
||||
if (mch != null) {
|
||||
@@ -1581,6 +1590,39 @@ public class Commands {
|
||||
mch.updateSingleStat(MapleStat.MP, mch.getMaxMp());
|
||||
}
|
||||
}
|
||||
} else if (sub[0].equals("healperson")) {
|
||||
MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
|
||||
victim.setHp(victim.getMaxHp());
|
||||
victim.updateSingleStat(MapleStat.HP, victim.getMaxHp());
|
||||
victim.setMp(victim.getMaxMp());
|
||||
victim.updateSingleStat(MapleStat.MP, victim.getMaxMp());
|
||||
} else if (sub[0].equals("hurt")) {
|
||||
MapleCharacter victim = cserv.getPlayerStorage().getCharacterByName(sub[1]);
|
||||
victim.setHp(1);
|
||||
victim.updateSingleStat(MapleStat.HP, 1);
|
||||
} else if (sub[0].equals("killmap")) {
|
||||
for (MapleCharacter mch : player.getMap().getCharacters()) {
|
||||
mch.setHp(0);
|
||||
mch.updateSingleStat(MapleStat.HP, 0);
|
||||
}
|
||||
} else if (sub[0].equals("mesorate")) {
|
||||
if (sub.length < 2){
|
||||
player.yellowMessage("Syntax: !mesorate <newrate>");
|
||||
return true;
|
||||
}
|
||||
c.getWorldServer().setMesoRate(Integer.parseInt(sub[1]));
|
||||
} else if (sub[0].equals("droprate")) {
|
||||
if (sub.length < 2){
|
||||
player.yellowMessage("Syntax: !droprate <newrate>");
|
||||
return true;
|
||||
}
|
||||
c.getWorldServer().setDropRate(Integer.parseInt(sub[1]));
|
||||
} else if (sub[0].equals("bossdroprate")) {
|
||||
if (sub.length < 2){
|
||||
player.yellowMessage("Syntax: !bossdroprate <newrate>");
|
||||
return true;
|
||||
}
|
||||
c.getWorldServer().setBossDropRate(Integer.parseInt(sub[1]));
|
||||
} else if (sub[0].equalsIgnoreCase("night")) {
|
||||
player.getMap().broadcastNightEffect();
|
||||
player.yellowMessage("Done.");
|
||||
@@ -1806,14 +1848,14 @@ public class Commands {
|
||||
break;
|
||||
case "clearquest":
|
||||
if(sub.length < 1) {
|
||||
player.dropMessage(5, "Plese include a quest ID.");
|
||||
player.dropMessage(5, "Please include a quest ID.");
|
||||
return;
|
||||
}
|
||||
MapleQuest.clearCache(Integer.parseInt(sub[1]));
|
||||
player.dropMessage(5, "Quest Cache for quest " + sub[1] + " cleared.");
|
||||
break;
|
||||
default:
|
||||
player.yellowMessage("Command " + heading + sub[0] + " does not exist.");
|
||||
player.yellowMessage("Command " + heading + sub[0] + " does not exist. See !commands for a list of available commands.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,6 +130,8 @@ public class MapleServerHandler extends IoHandlerAdapter {
|
||||
SeekableLittleEndianAccessor slea = new GenericSeekableLittleEndianAccessor(new ByteArrayByteStream(content));
|
||||
short packetId = slea.readShort();
|
||||
MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
|
||||
|
||||
//System.out.println("Received packet id " + packetId);
|
||||
final MaplePacketHandler packetHandler = processor.getHandler(packetId);
|
||||
if (packetHandler != null && packetHandler.validateState(client)) {
|
||||
try {
|
||||
|
||||
@@ -134,11 +134,11 @@ public enum RecvOpcode {
|
||||
RPS_ACTION(0x88),
|
||||
RING_ACTION(0x89),
|
||||
WEDDING_ACTION(0x8A),
|
||||
ALLIANCE_OPERATION(0x8F),
|
||||
OPEN_FAMILY(0x92),
|
||||
ADD_FAMILY(0x93),
|
||||
ACCEPT_FAMILY(0x96),
|
||||
USE_FAMILY(0x97),
|
||||
ALLIANCE_OPERATION(0x98),
|
||||
BBS_OPERATION(0x9B),
|
||||
ENTER_MTS(0x9C),
|
||||
USE_SOLOMON_ITEM(0x9D),
|
||||
|
||||
@@ -287,6 +287,7 @@ public class Server implements Runnable {
|
||||
MapleAlliance alliance = alliances.get(aId);
|
||||
if (alliance != null) {
|
||||
alliance.addGuild(guildId);
|
||||
guilds.get(guildId).setAllianceId(aId);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -296,6 +297,7 @@ public class Server implements Runnable {
|
||||
MapleAlliance alliance = alliances.get(aId);
|
||||
if (alliance != null) {
|
||||
alliance.removeGuild(guildId);
|
||||
guilds.get(guildId).setAllianceId(0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@@ -346,6 +348,16 @@ public class Server implements Runnable {
|
||||
public int createGuild(int leaderId, String name) {
|
||||
return MapleGuild.createGuild(leaderId, name);
|
||||
}
|
||||
|
||||
public MapleGuild getGuild(int id) {
|
||||
synchronized (guilds) {
|
||||
if (guilds.get(id) != null) {
|
||||
return guilds.get(id);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public MapleGuild getGuild(int id, int world, MapleGuildCharacter mgc) {
|
||||
synchronized (guilds) {
|
||||
@@ -393,6 +405,10 @@ public class Server implements Runnable {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void resetAllianceGuildPlayersRank(int gId) {
|
||||
guilds.get(gId).resetAllianceGuildPlayersRank();
|
||||
}
|
||||
|
||||
public void leaveGuild(MapleGuildCharacter mgc) {
|
||||
MapleGuild g = guilds.get(mgc.getGuildId());
|
||||
@@ -473,16 +489,16 @@ public class Server implements Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
public void guildMessage(int gid, byte[] packet) {
|
||||
guildMessage(gid, packet, -1);
|
||||
}
|
||||
public void guildMessage(int gid, byte[] packet) {
|
||||
guildMessage(gid, packet, -1);
|
||||
}
|
||||
|
||||
public void guildMessage(int gid, byte[] packet, int exception) {
|
||||
MapleGuild g = guilds.get(gid);
|
||||
if(g != null) {
|
||||
g.broadcast(packet, exception);
|
||||
}
|
||||
}
|
||||
public void guildMessage(int gid, byte[] packet, int exception) {
|
||||
MapleGuild g = guilds.get(gid);
|
||||
if(g != null) {
|
||||
g.broadcast(packet, exception);
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerBuffStorage getPlayerBuffStorage() {
|
||||
return buffStorage;
|
||||
|
||||
@@ -26,6 +26,7 @@ import client.MapleClient;
|
||||
import net.AbstractMaplePacketHandler;
|
||||
import net.SendOpcode;
|
||||
import net.server.Server;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import net.server.guild.MapleAlliance;
|
||||
import tools.MaplePacketCreator;
|
||||
import tools.data.input.SeekableLittleEndianAccessor;
|
||||
@@ -39,47 +40,67 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
|
||||
@Override
|
||||
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
|
||||
System.out.print("aop ");
|
||||
|
||||
MapleAlliance alliance = null;
|
||||
if (c.getPlayer().getGuild() != null && c.getPlayer().getGuild().getAllianceId() > 0) {
|
||||
alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId());
|
||||
alliance = c.getPlayer().getAlliance();
|
||||
}
|
||||
if (alliance == null) {
|
||||
c.getPlayer().dropMessage("You are not in an alliance.");
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
} else if (c.getPlayer().getMGC().getAllianceRank() > 2 || !alliance.getGuilds().contains(c.getPlayer().getGuildId())) {
|
||||
c.announce(MaplePacketCreator.enableActions());
|
||||
return;
|
||||
}
|
||||
switch (slea.readByte()) {
|
||||
|
||||
byte b = slea.readByte();
|
||||
System.out.print(b);
|
||||
switch (b) {
|
||||
case 0x01:
|
||||
System.out.print(" case 1");
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendShowInfo(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId()), -1, -1);
|
||||
break;
|
||||
case 0x02: { // Leave Alliance
|
||||
System.out.print(" case 2");
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1 || c.getPlayer().getGuildRank() != 1) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(c.getPlayer().getGuildId(), c.getPlayer().getId(), c.getPlayer().getGuildId(), 2), -1, -1);
|
||||
int guildid = c.getPlayer().getGuildId();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.removeGuildFromAlliance(alliance, guildid, c), -1, -1);
|
||||
Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1);
|
||||
Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(alliance.getId()));
|
||||
break;
|
||||
}
|
||||
case 0x03: // send alliance invite
|
||||
System.out.print(" case 3 avail is " + slea.available());
|
||||
String charName = slea.readMapleAsciiString();
|
||||
int channel;
|
||||
channel = c.getWorldServer().find(charName);
|
||||
if (channel == -1) {
|
||||
c.getPlayer().dropMessage("The player is not online.");
|
||||
|
||||
if(alliance.getGuilds().size() == alliance.getCapacity()) {
|
||||
c.getPlayer().dropMessage("Your alliance can not comport any more guild at the moment.");
|
||||
} else {
|
||||
MapleCharacter victim = Server.getInstance().getChannel(c.getWorld(), channel).getPlayerStorage().getCharacterByName(charName);
|
||||
if (victim.getGuildId() == 0) {
|
||||
c.getPlayer().dropMessage("The person you are trying to invite does not have a guild.");
|
||||
} else if (victim.getGuildRank() != 1) {
|
||||
c.getPlayer().dropMessage("The player is not the leader of his/her guild.");
|
||||
int channel;
|
||||
channel = c.getWorldServer().find(charName);
|
||||
if (channel == -1) {
|
||||
c.getPlayer().dropMessage("The player is not online.");
|
||||
} else {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readMapleAsciiString()), -1, -1);
|
||||
MapleCharacter victim = Server.getInstance().getChannel(c.getWorld(), channel).getPlayerStorage().getCharacterByName(charName);
|
||||
if (victim.getGuildId() == 0) {
|
||||
c.getPlayer().dropMessage("The person you are trying to invite does not have a guild.");
|
||||
} else if (victim.getGuildRank() != 1) {
|
||||
c.getPlayer().dropMessage("The player is not the leader of his/her guild.");
|
||||
} else {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendInvitation(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), charName), -1, -1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case 0x04: {
|
||||
System.out.print(" case 4");
|
||||
int guildid = slea.readInt();
|
||||
// slea.readMapleAsciiString();//guild name
|
||||
if (c.getPlayer().getGuild().getAllianceId() != 0 || c.getPlayer().getGuildRank() != 1 || c.getPlayer().getGuildId() < 1) {
|
||||
@@ -89,22 +110,36 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
break;
|
||||
}
|
||||
case 0x06: { // Expel Guild
|
||||
System.out.print(" case 6");
|
||||
int guildid = slea.readInt();
|
||||
int allianceid = slea.readInt();
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuild().getAllianceId() != allianceid) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeGuild(allianceid, c.getPlayer().getId(), guildid, 1), -1, -1);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.removeGuildFromAlliance(alliance, guildid, c), -1, -1);
|
||||
Server.getInstance().removeGuildFromAlliance(alliance.getId(), guildid);
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, c), -1, -1);
|
||||
Server.getInstance().guildMessage(guildid, MaplePacketCreator.disbandAlliance(allianceid));
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x07: { // Change Alliance Leader
|
||||
System.out.print(" case 7");
|
||||
if (c.getPlayer().getGuild().getAllianceId() == 0 || c.getPlayer().getGuildId() < 1) {
|
||||
return;
|
||||
}
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readInt()), -1, -1);
|
||||
int victimid = slea.readInt();
|
||||
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(victimid);
|
||||
|
||||
//Server.getInstance().allianceMessage(alliance.getId(), sendChangeLeader(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), slea.readInt()), -1, -1);
|
||||
changeLeaderAllianceRank(alliance, player);
|
||||
break;
|
||||
}
|
||||
case 0x08:
|
||||
System.out.print(" case 8");
|
||||
String ranks[] = new String[5];
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ranks[i] = slea.readMapleAsciiString();
|
||||
@@ -113,12 +148,18 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.changeAllianceRankTitle(alliance.getId(), ranks), -1, -1);
|
||||
break;
|
||||
case 0x09: {
|
||||
System.out.print(" case 9");
|
||||
int int1 = slea.readInt();
|
||||
byte byte1 = slea.readByte();
|
||||
Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), int1, byte1), -1, -1);
|
||||
|
||||
//Server.getInstance().allianceMessage(alliance.getId(), sendChangeRank(c.getPlayer().getGuild().getAllianceId(), c.getPlayer().getId(), int1, byte1), -1, -1);
|
||||
MapleCharacter player = Server.getInstance().getWorld(c.getWorld()).getPlayerStorage().getCharacterById(int1);
|
||||
changePlayerAllianceRank(alliance, player, (byte1 > 0));
|
||||
|
||||
break;
|
||||
}
|
||||
case 0x0A:
|
||||
System.out.print(" case A");
|
||||
String notice = slea.readMapleAsciiString();
|
||||
Server.getInstance().setAllianceNotice(alliance.getId(), notice);
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.allianceNotice(alliance.getId(), notice), -1, -1);
|
||||
@@ -126,9 +167,34 @@ public final class AllianceOperationHandler extends AbstractMaplePacketHandler {
|
||||
default:
|
||||
c.getPlayer().dropMessage("Feature not available");
|
||||
}
|
||||
System.out.println("end");
|
||||
|
||||
alliance.saveToDB();
|
||||
}
|
||||
|
||||
private void changeLeaderAllianceRank(MapleAlliance alliance, MapleCharacter newLeader) {
|
||||
MapleGuildCharacter lmgc = alliance.getLeader();
|
||||
MapleCharacter leader = Server.getInstance().getWorld(newLeader.getWorld()).getPlayerStorage().getCharacterById(lmgc.getId());
|
||||
leader.setAllianceRank(2);
|
||||
leader.saveGuildStatus();
|
||||
|
||||
newLeader.setAllianceRank(1);
|
||||
newLeader.saveGuildStatus();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, newLeader.getClient()), -1, -1);
|
||||
alliance.dropAllianceMessage("'" + newLeader.getName() + "' has been appointed as the new head of this Alliance.");
|
||||
}
|
||||
|
||||
private void changePlayerAllianceRank(MapleAlliance alliance, MapleCharacter chr, boolean raise) {
|
||||
int newRank = chr.getAllianceRank() + (raise ? -1 : 1);
|
||||
if(newRank < 2 || newRank > 5) return;
|
||||
|
||||
chr.setAllianceRank(newRank);
|
||||
chr.saveGuildStatus();
|
||||
|
||||
Server.getInstance().allianceMessage(alliance.getId(), MaplePacketCreator.getGuildAlliances(alliance, chr.getClient()), -1, -1);
|
||||
alliance.dropAllianceMessage("'" + chr.getName() + "' has moved ranks to '" + alliance.getRankTitle(newRank) + "' in this Alliance.");
|
||||
}
|
||||
|
||||
private static byte[] sendShowInfo(int allianceid, int playerid) {
|
||||
MaplePacketLittleEndianWriter mplew = new MaplePacketLittleEndianWriter();
|
||||
|
||||
@@ -186,9 +186,11 @@ public final class PlayerLoggedinHandler extends AbstractMaplePacketHandler {
|
||||
MapleGuild playerGuild = server.getGuild(player.getGuildId(), player.getWorld(), player.getMGC());
|
||||
if (playerGuild == null) {
|
||||
player.deleteGuild(player.getGuildId());
|
||||
player.resetMGC();
|
||||
player.resetMGC(null);
|
||||
player.setGuildId(0);
|
||||
} else {
|
||||
playerGuild.getMGC(player.getId()).setCharacter(player);
|
||||
player.resetMGC(playerGuild.getMGC(player.getId()));
|
||||
server.setGuildMemberOnline(player.getMGC(), true, c.getChannel());
|
||||
c.announce(MaplePacketCreator.showGuildInfo(player));
|
||||
int allianceId = player.getGuild().getAllianceId();
|
||||
|
||||
@@ -27,57 +27,188 @@ import java.sql.SQLException;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import client.MapleCharacter;
|
||||
import net.server.Server;
|
||||
import net.server.world.MapleParty;
|
||||
import net.server.world.MaplePartyCharacter;
|
||||
import net.server.guild.MapleGuild;
|
||||
import net.server.guild.MapleGuildCharacter;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author XoticStory.
|
||||
* @author XoticStory, Ronan.
|
||||
*/
|
||||
public class MapleAlliance {
|
||||
private int[] guilds = new int[5];
|
||||
final private List<Integer> guilds = new LinkedList<>();
|
||||
|
||||
private int allianceId = -1;
|
||||
private int capacity;
|
||||
private String name;
|
||||
private String notice = "";
|
||||
private String rankTitles[] = new String[5];
|
||||
|
||||
public MapleAlliance(String name, int id, int guild1, int guild2) {
|
||||
public MapleAlliance(String name, int id) {
|
||||
this.name = name;
|
||||
allianceId = id;
|
||||
int[] guild = {guild1, guild2, -1, -1, -1};
|
||||
String[] ranks = {"Master", "Jr.Master", "Member", "Member", "Member"};
|
||||
for (int i = 0; i < 5; i++) {
|
||||
guilds[i] = guild[i];
|
||||
rankTitles[i] = ranks[i];
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canBeUsedAllianceName(String name) {
|
||||
if (name.contains(" ") || name.length() > 12) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
ps.close();
|
||||
rs.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static List<MapleCharacter> getPartyGuildMasters(MapleParty party) {
|
||||
List<MapleCharacter> mcl = new LinkedList<>();
|
||||
|
||||
for(MaplePartyCharacter mpc: party.getMembers()) {
|
||||
if(mpc.getPlayer().getGuildRank() == 1 && mpc.getPlayer().getMapId() == party.getLeader().getPlayer().getMapId())
|
||||
mcl.add(mpc.getPlayer());
|
||||
}
|
||||
|
||||
if(!mcl.isEmpty() && !mcl.get(0).isPartyLeader()) {
|
||||
for(int i = 1; i < mcl.size(); i++) {
|
||||
if(mcl.get(i).isPartyLeader()) {
|
||||
MapleCharacter temp = mcl.get(0);
|
||||
mcl.set(0, mcl.get(i));
|
||||
mcl.set(i, temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return mcl;
|
||||
}
|
||||
|
||||
public static MapleAlliance createAlliance(MapleParty party, String name) {
|
||||
List<MapleCharacter> guildMasters = getPartyGuildMasters(party);
|
||||
if(guildMasters.size() != 2) return null;
|
||||
|
||||
List<Integer> guilds = new LinkedList<>();
|
||||
for(MapleCharacter mc: guildMasters) guilds.add(mc.getGuildId());
|
||||
MapleAlliance alliance = MapleAlliance.createAllianceOnDb(guilds, name);
|
||||
if(alliance != null) {
|
||||
alliance.setCapacity(guilds.size());
|
||||
for(Integer g: guilds)
|
||||
alliance.addGuild(g);
|
||||
|
||||
int id = alliance.getId();
|
||||
try {
|
||||
for(int i = 0; i < guildMasters.size(); i++) {
|
||||
Server.getInstance().setGuildAllianceId(guilds.get(i), id);
|
||||
Server.getInstance().resetAllianceGuildPlayersRank(guilds.get(i));
|
||||
|
||||
MapleCharacter chr = guildMasters.get(i);
|
||||
chr.setAllianceRank((i == 0) ? 1 : 2);
|
||||
chr.saveGuildStatus();
|
||||
}
|
||||
|
||||
Server.getInstance().addAlliance(id, alliance);
|
||||
Server.getInstance().allianceMessage(id, MaplePacketCreator.makeNewAlliance(alliance, guildMasters.get(0).getClient()), -1, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
return alliance;
|
||||
}
|
||||
|
||||
public static MapleAlliance createAllianceOnDb(List<Integer> guilds, String name) {
|
||||
// will create an alliance, where the first guild listed is the leader and the alliance name MUST BE already checked for unicity.
|
||||
|
||||
int id = -1;
|
||||
try {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO `alliance` (`name`) VALUES (?)", PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
|
||||
ps.setString(1, name);
|
||||
ps.executeUpdate();
|
||||
try (ResultSet rs = ps.getGeneratedKeys()) {
|
||||
rs.next();
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
|
||||
for(int i = 0; i < guilds.size(); i++) {
|
||||
int guild = guilds.get(i);
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO `allianceguilds` (`allianceid`, `guildid`) VALUES (?, ?)");
|
||||
ps.setInt(1, id);
|
||||
ps.setInt(2, guild);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
ps.close();
|
||||
con.close();
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return (new MapleAlliance(name, id));
|
||||
}
|
||||
|
||||
public static MapleAlliance loadAlliance(int id) {
|
||||
if (id <= 0) {
|
||||
return null;
|
||||
}
|
||||
MapleAlliance alliance = new MapleAlliance(null, -1, -1, -1);
|
||||
MapleAlliance alliance = new MapleAlliance(null, -1);
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
ps.setInt(1, id);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (!rs.next()) {
|
||||
rs.close();
|
||||
ps.close();
|
||||
con.close();
|
||||
return null;
|
||||
}
|
||||
alliance.allianceId = id;
|
||||
alliance.capacity = rs.getInt("capacity");
|
||||
alliance.name = rs.getString("name");
|
||||
alliance.notice = rs.getString("notice");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
alliance.rankTitles[i - 1] = rs.getString("rank_title" + i);
|
||||
}
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
alliance.guilds[i - 1] = rs.getInt("guild" + i);
|
||||
}
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
ps = con.prepareStatement("SELECT * FROM allianceguilds WHERE allianceid = ?");
|
||||
ps.setInt(1, id);
|
||||
rs = ps.executeQuery();
|
||||
|
||||
while(rs.next()) {
|
||||
alliance.addGuild(rs.getInt("guildid"));
|
||||
}
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -85,132 +216,73 @@ public class MapleAlliance {
|
||||
}
|
||||
|
||||
public void saveToDB() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("capacity = ?, ");
|
||||
sb.append("notice = ?, ");
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
sb.append("rank_title").append(i).append(" = ?, ");
|
||||
}
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
sb.append("guild").append(i).append(" = ?, ");
|
||||
}
|
||||
try {
|
||||
PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE `alliance` SET " + sb.toString() + " WHERE id = ?");
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE `alliance` SET capacity = ?, notice = ? WHERE id = ?");
|
||||
ps.setInt(1, this.capacity);
|
||||
ps.setString(2, this.notice);
|
||||
for (int i = 0; i < rankTitles.length; i++) {
|
||||
ps.setString(i + 3, rankTitles[i]);
|
||||
}
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
ps.setInt(i + 8, guilds[i]);
|
||||
}
|
||||
ps.setInt(13, this.allianceId);
|
||||
ps.executeQuery();
|
||||
ps.setInt(3, this.allianceId);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addRemGuildFromDB(int gid, boolean add) {
|
||||
Connection con = DatabaseConnection.getConnection();
|
||||
boolean ret = false;
|
||||
try {
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM alliance WHERE id = ?");
|
||||
|
||||
ps = con.prepareStatement("DELETE FROM `allianceguilds` WHERE allianceid = ?");
|
||||
ps.setInt(1, this.allianceId);
|
||||
ResultSet rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
int avail = -1;
|
||||
for (int i = 1; i <= 5; i++) {
|
||||
int guildId = rs.getInt("guild" + i);
|
||||
if (add) {
|
||||
if (guildId == -1) {
|
||||
avail = i;
|
||||
break;
|
||||
}
|
||||
} else if (guildId == gid) {
|
||||
avail = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
if (avail != -1) { // empty slot
|
||||
ps = con.prepareStatement("UPDATE alliance SET guild" + avail + " = ? WHERE id = ?");
|
||||
if (add) {
|
||||
ps.setInt(1, gid);
|
||||
} else {
|
||||
ps.setInt(1, -1);
|
||||
}
|
||||
ps.setInt(2, this.allianceId);
|
||||
ps.executeUpdate();
|
||||
ret = true;
|
||||
}
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
|
||||
for(int i = 0; i < guilds.size(); i++) {
|
||||
int guild = guilds.get(i);
|
||||
|
||||
ps = con.prepareStatement("INSERT INTO `allianceguilds` (`allianceid`, `guildid`) VALUES (?, ?)");
|
||||
ps.setInt(1, this.allianceId);
|
||||
ps.setInt(2, guild);
|
||||
ps.executeUpdate();
|
||||
ps.close();
|
||||
}
|
||||
|
||||
con.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public boolean removeGuild(int gid) {
|
||||
synchronized (guilds) {
|
||||
int gIndex = getGuildIndex(gid);
|
||||
if (gIndex != -1) {
|
||||
guilds[gIndex] = -1;
|
||||
}
|
||||
return addRemGuildFromDB(gid, false);
|
||||
int index = getGuildIndex(gid);
|
||||
if(index == -1) return false;
|
||||
|
||||
guilds.remove(index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean addGuild(int gid) {
|
||||
synchronized (guilds) {
|
||||
if (getGuildIndex(gid) == -1) {
|
||||
int emptyIndex = getGuildIndex(-1);
|
||||
if (emptyIndex != -1) {
|
||||
guilds[emptyIndex] = gid;
|
||||
return addRemGuildFromDB(gid, true);
|
||||
}
|
||||
}
|
||||
if(guilds.size() == capacity || getGuildIndex(gid) > -1) return false;
|
||||
guilds.add(gid);
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
private int getGuildIndex(int gid) {
|
||||
for (int i = 0; i < guilds.length; i++) {
|
||||
if (guilds[i] == gid) {
|
||||
for (int i = 0; i < guilds.size(); i++) {
|
||||
if (guilds.get(i) == gid) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
public void setRankTitle(String[] ranks) {
|
||||
rankTitles = ranks;
|
||||
}
|
||||
|
||||
public void setNotice(String notice) {
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return allianceId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getRankTitle(int rank) {
|
||||
return rankTitles[rank - 1];
|
||||
}
|
||||
|
||||
public String getAllianceNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
|
||||
public List<Integer> getGuilds() {
|
||||
List<Integer> guilds_ = new LinkedList<Integer>();
|
||||
List<Integer> guilds_ = new LinkedList<>();
|
||||
for (int guild : guilds) {
|
||||
if (guild != -1) {
|
||||
guilds_.add(guild);
|
||||
@@ -218,16 +290,58 @@ public class MapleAlliance {
|
||||
}
|
||||
return guilds_;
|
||||
}
|
||||
|
||||
public String getAllianceNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public String getNotice() {
|
||||
return notice;
|
||||
}
|
||||
|
||||
public void setNotice(String notice) {
|
||||
this.notice = notice;
|
||||
}
|
||||
|
||||
public void increaseCapacity(int inc) {
|
||||
capacity += inc;
|
||||
this.capacity += inc;
|
||||
}
|
||||
|
||||
public void setCapacity(int newCapacity) {
|
||||
this.capacity = newCapacity;
|
||||
}
|
||||
|
||||
public int getCapacity() {
|
||||
return capacity;
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return allianceId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public MapleGuildCharacter getLeader() {
|
||||
for(Integer gId: guilds) {
|
||||
MapleGuild guild = Server.getInstance().getGuild(gId);
|
||||
MapleGuildCharacter mgc = guild.getMGC(guild.getLeaderId());
|
||||
|
||||
if(mgc.getAllianceRank() == 1) return mgc;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void dropAllianceMessage(String message) {
|
||||
dropAllianceMessage(5, message);
|
||||
}
|
||||
|
||||
public void dropAllianceMessage(int type, String message) {
|
||||
for(Integer gId: guilds) {
|
||||
MapleGuild guild = Server.getInstance().getGuild(gId);
|
||||
guild.dropGuildMessage(type, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,6 @@ import java.util.Set;
|
||||
|
||||
import net.server.Server;
|
||||
import net.server.channel.Channel;
|
||||
import tools.LogHelper;
|
||||
import tools.DatabaseConnection;
|
||||
import tools.MaplePacketCreator;
|
||||
|
||||
@@ -46,7 +45,7 @@ public class MapleGuild {
|
||||
public final static int CHANGE_EMBLEM_COST = 5000000;
|
||||
|
||||
private enum BCOp {
|
||||
NONE, DISBAND, EMBELMCHANGE
|
||||
NONE, DISBAND, EMBLEMCHANGE
|
||||
}
|
||||
private List<MapleGuildCharacter> members;
|
||||
private String rankTitles[] = new String[5]; // 1 = master, 2 = jr, 5 = lowest member
|
||||
@@ -56,8 +55,6 @@ public class MapleGuild {
|
||||
private Map<Integer, List<Integer>> notifications = new LinkedHashMap<>();
|
||||
private boolean bDirty = true;
|
||||
|
||||
|
||||
|
||||
public MapleGuild(int guildid, int world) {
|
||||
this.world = world;
|
||||
members = new ArrayList<>();
|
||||
@@ -97,14 +94,14 @@ public class MapleGuild {
|
||||
return;
|
||||
}
|
||||
do {
|
||||
members.add(new MapleGuildCharacter(rs.getInt("id"), rs.getInt("level"), rs.getString("name"), (byte) -1, world, rs.getInt("job"), rs.getInt("guildrank"), guildid, false, rs.getInt("allianceRank")));
|
||||
members.add(new MapleGuildCharacter(null, rs.getInt("id"), rs.getInt("level"), rs.getString("name"), (byte) -1, world, rs.getInt("job"), rs.getInt("guildrank"), guildid, false, rs.getInt("allianceRank")));
|
||||
} while (rs.next());
|
||||
|
||||
ps.close();
|
||||
rs.close();
|
||||
} catch (SQLException se) {
|
||||
se.printStackTrace();
|
||||
System.out.println("unable to read guild information from sql" + se);
|
||||
System.out.println("Unable to read guild information from sql" + se);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -261,7 +258,7 @@ public class MapleGuild {
|
||||
if (notifications.get(b).size() > 0) {
|
||||
if (bcop == BCOp.DISBAND) {
|
||||
Server.getInstance().getWorld(world).setGuildAndRank(notifications.get(b), 0, 5, exceptionId);
|
||||
} else if (bcop == BCOp.EMBELMCHANGE) {
|
||||
} else if (bcop == BCOp.EMBLEMCHANGE) {
|
||||
Server.getInstance().getWorld(world).changeEmblem(this.id, notifications.get(b), new MapleGuildSummary(this));
|
||||
} else {
|
||||
Server.getInstance().getWorld(world).sendPacket(notifications.get(b), packet, exceptionId);
|
||||
@@ -285,6 +282,16 @@ public class MapleGuild {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void dropGuildMessage(String message) {
|
||||
dropGuildMessage(5, message);
|
||||
}
|
||||
|
||||
public void dropGuildMessage(int type, String message) {
|
||||
for (MapleGuildCharacter mgc : members) {
|
||||
mgc.getCharacter().dropMessage(type, message);
|
||||
}
|
||||
}
|
||||
|
||||
public final void setOnline(int cid, boolean online, int channel) {
|
||||
boolean bBroadcast = true;
|
||||
@@ -480,7 +487,7 @@ public class MapleGuild {
|
||||
this.logo = logo;
|
||||
this.logoColor = logocolor;
|
||||
this.writeToDB(false);
|
||||
this.broadcast(null, -1, BCOp.EMBELMCHANGE);
|
||||
this.broadcast(null, -1, BCOp.EMBLEMCHANGE);
|
||||
}
|
||||
|
||||
public MapleGuildCharacter getMGC(int cid) {
|
||||
@@ -557,6 +564,20 @@ public class MapleGuild {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void resetAllianceGuildPlayersRank() {
|
||||
try {
|
||||
for(MapleGuildCharacter mgc: members) mgc.setAllianceRank(5);
|
||||
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("UPDATE characters SET allianceRank = ? WHERE guildid = ?")) {
|
||||
ps.setInt(1, 5);
|
||||
ps.setInt(2, id);
|
||||
ps.executeUpdate();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public int getIncreaseGuildCost(int size) {
|
||||
return 500000 * (size - 6) / 6;
|
||||
|
||||
@@ -24,6 +24,7 @@ package net.server.guild;
|
||||
import client.MapleCharacter;
|
||||
|
||||
public class MapleGuildCharacter {
|
||||
private MapleCharacter character;
|
||||
private int level;
|
||||
private int id;
|
||||
private int world, channel;
|
||||
@@ -35,6 +36,7 @@ public class MapleGuildCharacter {
|
||||
private String name;
|
||||
|
||||
public MapleGuildCharacter(MapleCharacter c) {
|
||||
this.character = c;
|
||||
this.name = c.getName();
|
||||
this.level = c.getLevel();
|
||||
this.id = c.getId();
|
||||
@@ -47,7 +49,8 @@ public class MapleGuildCharacter {
|
||||
this.allianceRank = c.getAllianceRank();
|
||||
}
|
||||
|
||||
public MapleGuildCharacter(int _id, int _lv, String _name, int _channel, int _world, int _job, int _rank, int _gid, boolean _on, int _allianceRank) {
|
||||
public MapleGuildCharacter(MapleCharacter c, int _id, int _lv, String _name, int _channel, int _world, int _job, int _rank, int _gid, boolean _on, int _allianceRank) {
|
||||
this.character = c;
|
||||
this.level = _lv;
|
||||
this.id = _id;
|
||||
this.name = _name;
|
||||
@@ -61,6 +64,14 @@ public class MapleGuildCharacter {
|
||||
this.guildid = _gid;
|
||||
this.allianceRank = _allianceRank;
|
||||
}
|
||||
|
||||
public void setCharacter(MapleCharacter ch) {
|
||||
this.character = ch;
|
||||
}
|
||||
|
||||
public MapleCharacter getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return level;
|
||||
|
||||
@@ -152,6 +152,16 @@ public class World {
|
||||
public int getBossDropRate() {
|
||||
return bossdroprate;
|
||||
}
|
||||
|
||||
public void setBossDropRate(int bossdrop) {
|
||||
for(MapleCharacter chr : getPlayerStorage().getAllCharacters()) {
|
||||
chr.revertRates(false);
|
||||
}
|
||||
this.bossdroprate = bossdrop;
|
||||
for(MapleCharacter chr : getPlayerStorage().getAllCharacters()) {
|
||||
chr.setRates();
|
||||
}
|
||||
}
|
||||
|
||||
public PlayerStorage getPlayerStorage() {
|
||||
return players;
|
||||
|
||||
@@ -25,6 +25,8 @@ import java.io.File;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.server.Server;
|
||||
import net.server.guild.MapleAlliance;
|
||||
@@ -344,6 +346,11 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
Server.getInstance().broadcastMessage(MaplePacketCreator.gachaponMessage(itemGained, map, getPlayer()));
|
||||
}
|
||||
}
|
||||
|
||||
public void upgradeAlliance() {
|
||||
MapleAlliance alliance = Server.getInstance().getAlliance(c.getPlayer().getGuild().getAllianceId());
|
||||
alliance.increaseCapacity(1);
|
||||
}
|
||||
|
||||
public void disbandAlliance(MapleClient c, int allianceId) {
|
||||
PreparedStatement ps = null;
|
||||
@@ -368,63 +375,16 @@ public class NPCConversationManager extends AbstractPlayerInteraction {
|
||||
}
|
||||
|
||||
public boolean canBeUsedAllianceName(String name) {
|
||||
if (name.contains(" ") || name.length() > 12) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
ResultSet rs;
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("SELECT name FROM alliance WHERE name = ?")) {
|
||||
ps.setString(1, name);
|
||||
rs = ps.executeQuery();
|
||||
if (rs.next()) {
|
||||
ps.close();
|
||||
rs.close();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
return true;
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static MapleAlliance createAlliance(MapleCharacter chr1, MapleCharacter chr2, String name) {
|
||||
int id;
|
||||
int guild1 = chr1.getGuildId();
|
||||
int guild2 = chr2.getGuildId();
|
||||
try {
|
||||
try (PreparedStatement ps = DatabaseConnection.getConnection().prepareStatement("INSERT INTO `alliance` (`name`, `guild1`, `guild2`) VALUES (?, ?, ?)", PreparedStatement.RETURN_GENERATED_KEYS)) {
|
||||
ps.setString(1, name);
|
||||
ps.setInt(2, guild1);
|
||||
ps.setInt(3, guild2);
|
||||
ps.executeUpdate();
|
||||
try (ResultSet rs = ps.getGeneratedKeys()) {
|
||||
rs.next();
|
||||
id = rs.getInt(1);
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
MapleAlliance alliance = new MapleAlliance(name, id, guild1, guild2);
|
||||
try {
|
||||
Server.getInstance().setGuildAllianceId(guild1, id);
|
||||
Server.getInstance().setGuildAllianceId(guild2, id);
|
||||
chr1.setAllianceRank(1);
|
||||
chr1.saveGuildStatus();
|
||||
chr2.setAllianceRank(2);
|
||||
chr2.saveGuildStatus();
|
||||
Server.getInstance().addAlliance(id, alliance);
|
||||
Server.getInstance().allianceMessage(id, MaplePacketCreator.makeNewAlliance(alliance, chr1.getClient()), -1, -1);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
return alliance;
|
||||
return MapleAlliance.canBeUsedAllianceName(name);
|
||||
}
|
||||
|
||||
public MapleAlliance createAlliance(String name) {
|
||||
return MapleAlliance.createAlliance(getParty(), name);
|
||||
}
|
||||
|
||||
public int getAllianceCapacity() {
|
||||
return Server.getInstance().getAlliance(getPlayer().getGuild().getAllianceId()).getCapacity();
|
||||
}
|
||||
|
||||
public boolean hasMerchant() {
|
||||
return getPlayer().hasMerchant();
|
||||
|
||||
@@ -5891,6 +5891,7 @@ public class MaplePacketCreator {
|
||||
mplew.writeInt(mgc.isOnline() ? 1 : 0);
|
||||
mplew.writeInt(guild.getSignature());
|
||||
mplew.writeInt(mgc.getAllianceRank());
|
||||
System.out.println("alliance rank found " + mgc.getAllianceRank());
|
||||
}
|
||||
mplew.writeInt(guild.getCapacity());
|
||||
mplew.writeShort(guild.getLogoBG());
|
||||
|
||||
Reference in New Issue
Block a user