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:
ronancpl
2017-05-24 19:52:00 -03:00
parent 53927576e7
commit a636f63114
19 changed files with 553 additions and 273 deletions

View File

@@ -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();

View File

@@ -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();