From a636f63114d5a30c94b92963e6a2e2cb83f47563 Mon Sep 17 00:00:00 2001 From: ronancpl Date: Wed, 24 May 2017 19:52:00 -0300 Subject: [PATCH] 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. --- mychanges_ptbr.txt | 6 +- nbproject/private/private.xml | 39 +-- scripts/npc/world0/2010009.js | 71 +++- sql/db_database.sql | 17 +- src/client/MapleCharacter.java | 21 +- src/client/MapleClient.java | 4 +- src/client/command/Commands.java | 64 +++- src/net/MapleServerHandler.java | 2 + src/net/RecvOpcode.java | 2 +- src/net/server/Server.java | 34 +- .../handlers/AllianceOperationHandler.java | 100 +++++- .../handlers/PlayerLoggedinHandler.java | 4 +- src/net/server/guild/MapleAlliance.java | 326 ++++++++++++------ src/net/server/guild/MapleGuild.java | 37 +- src/net/server/guild/MapleGuildCharacter.java | 13 +- src/net/server/world/World.java | 10 + src/scripting/npc/NPCConversationManager.java | 72 +--- src/tools/MaplePacketCreator.java | 1 + todo.txt | 3 +- 19 files changed, 553 insertions(+), 273 deletions(-) diff --git a/mychanges_ptbr.txt b/mychanges_ptbr.txt index d6efc59b57..96280cc0c1 100644 --- a/mychanges_ptbr.txt +++ b/mychanges_ptbr.txt @@ -242,4 +242,8 @@ Retiradas inconsist Foi retirado o gargalo no sistema sempre que jogador incorpora um novo card ao mobbook. Consertado bug em potencial ao tentar completar quest que requer item equipado. Adição de scrolls: Scroll for cold protection, Scroll for spike for shoes. -Consertado quest-evento Dollhouse. \ No newline at end of file +Consertado quest-evento Dollhouse. + +23 - 24 Maio 2017, +Revamp na DB referente às Alliances. +Solução parcial ao problema das Guild Alliances. Pode-se criar uma, sair, expulsar e trocar ranks de jogadores. \ No newline at end of file diff --git a/nbproject/private/private.xml b/nbproject/private/private.xml index fa073e16d3..1252af1b6b 100644 --- a/nbproject/private/private.xml +++ b/nbproject/private/private.xml @@ -3,37 +3,16 @@ - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/command/Commands.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/maps/HiredMerchant.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/MapleStatEffect.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/scripting/AbstractPlayerInteraction.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/npc/world0/2040020.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/npc/world0/2040002.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/PlayerInteractionHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/MapleItemInformationProvider.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/StorageHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/UseCashItemHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/inventory/Equip.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/scripting/event/EventInstanceManager.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/MapleBuffStat.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/maps/MapleMap.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/MapleCharacter.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/npc/world0/2040028.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/PlayerLoggedinHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/event/EllinPQ.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/constants/ItemConstants.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/maps/MapleReactor.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/maps/MapleDragon.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/npc/world0/2133000.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/inventory/MapleInventory.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/scripts/event/DollHouse.js - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/ScrollHandler.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/maps/AbstractMapleMapObject.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/quest/MapleQuestRequirementType.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/channel/handlers/AllianceOperationHandler.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleGuild.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleAlliance.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/guild/MapleGuildCharacter.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/Server.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/world/World.java file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/scripting/npc/NPCConversationManager.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/MapleInventoryManipulator.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/quest/actions/PetSkillAction.java - file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/server/quest/MapleQuest.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/client/MapleCharacter.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/net/server/handlers/login/GuestLoginHandler.java + file:/C:/Nexon/MapleSolaxia/MapleSolaxiaV2/src/tools/MaplePacketCreator.java diff --git a/scripts/npc/world0/2010009.js b/scripts/npc/world0/2010009.js index cbe35a6bf0..de3d358424 100644 --- a/scripts/npc/world0/2010009.js +++ b/scripts/npc/world0/2010009.js @@ -24,6 +24,10 @@ var choice; var guildName; var partymembers; +var allianceCost = 2000000; +var increaseCost = 1000000; +var allianceLimit = 5; + function start() { partymembers = cm.getPartyMembers(); status = -1; @@ -37,22 +41,40 @@ function action(mode, type, selection) { cm.dispose(); return; } - if (status == 0) - cm.sendSimple("Hello there! I'm #bLenario#k\r\n#b#L0#Can you please tell me what Guild Union is all about?#l\r\n#L1#How do I make a Guild Union?#l\r\n#L2#I want to make a Guild Union.#l\r\n#L3#I want to add more guilds for the Guild Union.#l\r\n#L4#I want to break up the Guild Union.#l"); + if (status == 0) { + if(cm.getPlayer().getGuildId() < 1 || cm.getPlayer().getGuildRank() != 1) { + cm.sendNext("Hello there! I'm #bLenario#k. Just guild masters can attempt to form guild unions."); + cm.dispose(); + return; + } + if(!cm.isLeader()) { + cm.sendNext("Hello there! I'm #bLenario#k. If you want to form a guild, please tell your party leader to talk to me. He/She will be assigned as the Leader of the Guild Union."); + cm.dispose(); + return; + } + + cm.sendSimple("Hello there! I'm #bLenario#k.\r\n#b#L0#Can you please tell me what Guild Union is all about?#l\r\n#L1#How do I make a Guild Union?#l\r\n#L2#I want to make a Guild Union.#l\r\n#L3#I want to add more guilds for the Guild Union.#l\r\n#L4#I want to break up the Guild Union.#l"); + } else if (status == 1) { choice = selection; if (selection == 0) { cm.sendNext("Guild Union is just as it says, a union of a number of guilds to form a super group. I am in charge of managing these Guild Unions."); cm.dispose(); } else if (selection == 1) { - cm.sendNext("To make a Guild Union, 2 Guild Masters need to be in a party. The leader of this party will be assigned as the Guild Union Master."); + cm.sendNext("To make a Guild Union, two and only two Guild Masters need to be in a party and both must be present on this room on the same channel. The leader of this party will be assigned as the Guild Union Master."); cm.dispose(); } else if(selection == 2) { - cm.sendYesNo("Oh, are you interested in forming a Guild Union?"); + if(cm.getPlayer().getGuild().getAllianceId() > 0) { + cm.sendOk("You can not create a Guild Union while your guild is already registered in another."); + cm.dispose(); + return; + } + + cm.sendYesNo("Oh, are you interested in forming a Guild Union? The current fee for this operation is #b" + allianceCost + " mesos#k."); } else if (selection == 3) { var rank = cm.getPlayer().getMGC().getAllianceRank(); if (rank == 1) - cm.sendOk("Not done yet"); //ExpandGuild Text + cm.sendYesNo("Do you want to increase your Alliance by one guild slot? The fee for this procedure is #b" + increaseCost + " mesos#k."); else { cm.sendNext("Only the Guild Union Master can expand the number of guilds in the Union."); cm.dispose(); @@ -68,12 +90,29 @@ function action(mode, type, selection) { } } else if(status == 2) { if (choice == 2) { - cm.sendGetText("Now please enter the name of your new Guild Union. (max. 12 letters)"); - } else if (choice == 4) { - if (cm.getPlayer().getGuild() == null) { - cm.sendNext("You cannot disband a non-existant Guild Union."); + if(cm.getMeso() < allianceCost) { + cm.sendOk("You don't have enough mesos for this request."); cm.dispose(); - } else if (cm.getPlayer().getGuild().getAllianceId() <= 0) { + return; + } + cm.sendGetText("Now please enter the name of your new Guild Union. (max. 12 letters)"); + } else if (choice == 3) { + if(cm.getAllianceCapacity() == allianceLimit) { + cm.sendOk("Your alliance already reached the maximum capacity for guilds."); + cm.dispose(); + return; + } + if(cm.getMeso() < increaseCost) { + cm.sendOk("You don't have enough mesos for this request."); + cm.dispose(); + return; + } + + cm.upgradeAlliance(); + cm.gainMeso(-increaseCost); + cm.sendOk("Your alliance can now accept one more guild."); + } else if (choice == 4) { + if (cm.getPlayer().getGuild() == null || cm.getPlayer().getGuild().getAllianceId() <= 0) { cm.sendNext("You cannot disband a non-existant Guild Union."); cm.dispose(); } else { @@ -84,17 +123,19 @@ function action(mode, type, selection) { } } else if (status == 3) { guildName = cm.getText(); - cm.sendYesNo("Will "+ guildName + " be the name of your Guild Union?"); + cm.sendYesNo("Will '"+ guildName + "' be the name of your Guild Union?"); } else if (status == 4) { if (!cm.canBeUsedAllianceName(guildName)) { - cm.sendNext("This name is unavailable, please choose another one"); //Not real text + cm.sendNext("This name is unavailable, please choose another one."); //Not real text status = 1; choice = 2; } else { - if (cm.createAlliance(partymembers.get(0), partymembers.get(1), guildName) == null) - cm.sendOk("An unknown system error has occured."); - else + if (cm.createAlliance(guildName) == null) + cm.sendOk("Please check if you and the other one guild leader in your party are both here on this room right now. No other guild leaders should be present with you 2 on this process."); + else { + cm.gainMeso(-allianceCost); cm.sendOk("You have successfully formed a Guild Union."); + } cm.dispose(); } } diff --git a/sql/db_database.sql b/sql/db_database.sql index a06e7120f4..bd8b8e4e70 100644 --- a/sql/db_database.sql +++ b/sql/db_database.sql @@ -52,16 +52,13 @@ CREATE TABLE IF NOT EXISTS `alliance` ( `name` varchar(13) NOT NULL, `notice` varchar(128) NOT NULL DEFAULT '', `capacity` int(10) unsigned NOT NULL DEFAULT '2', - `rank_title1` varchar(45) NOT NULL DEFAULT 'Master', - `rank_title2` varchar(45) NOT NULL DEFAULT 'Jr.Master', - `rank_title3` varchar(45) NOT NULL DEFAULT 'Member', - `rank_title4` varchar(45) NOT NULL DEFAULT 'Member', - `rank_title5` varchar(45) NOT NULL DEFAULT 'Member', - `guild1` int(10) NOT NULL DEFAULT '-1', - `guild2` int(10) NOT NULL DEFAULT '-1', - `guild3` int(10) NOT NULL DEFAULT '-1', - `guild4` int(10) NOT NULL DEFAULT '-1', - `guild5` int(10) NOT NULL DEFAULT '-1', + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; + +CREATE TABLE IF NOT EXISTS `allianceguilds` ( + `id` int(10) unsigned NOT NULL AUTO_INCREMENT, + `allianceid` int(10) NOT NULL DEFAULT '-1', + `guildid` int(10) NOT NULL DEFAULT '-1', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; diff --git a/src/client/MapleCharacter.java b/src/client/MapleCharacter.java index e5bb21b0cb..4b7092fd4c 100644 --- a/src/client/MapleCharacter.java +++ b/src/client/MapleCharacter.java @@ -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(); diff --git a/src/client/MapleClient.java b/src/client/MapleClient.java index 651b6fbd7f..4b71878196 100644 --- a/src/client/MapleClient.java +++ b/src/client/MapleClient.java @@ -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; diff --git a/src/client/command/Commands.java b/src/client/command/Commands.java index 1b06629a45..cf68806c6d 100644 --- a/src/client/command/Commands.java +++ b/src/client/command/Commands.java @@ -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 [] "); 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 "); + return true; + } + c.getWorldServer().setMesoRate(Integer.parseInt(sub[1])); + } else if (sub[0].equals("droprate")) { + if (sub.length < 2){ + player.yellowMessage("Syntax: !droprate "); + return true; + } + c.getWorldServer().setDropRate(Integer.parseInt(sub[1])); + } else if (sub[0].equals("bossdroprate")) { + if (sub.length < 2){ + player.yellowMessage("Syntax: !bossdroprate "); + 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; } } diff --git a/src/net/MapleServerHandler.java b/src/net/MapleServerHandler.java index e1aacb9027..83ef54705f 100644 --- a/src/net/MapleServerHandler.java +++ b/src/net/MapleServerHandler.java @@ -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 { diff --git a/src/net/RecvOpcode.java b/src/net/RecvOpcode.java index bfbb0406ef..97311eb842 100644 --- a/src/net/RecvOpcode.java +++ b/src/net/RecvOpcode.java @@ -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), diff --git a/src/net/server/Server.java b/src/net/server/Server.java index 236e236ea7..fa24e67c88 100644 --- a/src/net/server/Server.java +++ b/src/net/server/Server.java @@ -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; diff --git a/src/net/server/channel/handlers/AllianceOperationHandler.java b/src/net/server/channel/handlers/AllianceOperationHandler.java index e4cf6e8d47..9e18c3d25d 100644 --- a/src/net/server/channel/handlers/AllianceOperationHandler.java +++ b/src/net/server/channel/handlers/AllianceOperationHandler.java @@ -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(); diff --git a/src/net/server/channel/handlers/PlayerLoggedinHandler.java b/src/net/server/channel/handlers/PlayerLoggedinHandler.java index c2ed617358..6236aa2a28 100644 --- a/src/net/server/channel/handlers/PlayerLoggedinHandler.java +++ b/src/net/server/channel/handlers/PlayerLoggedinHandler.java @@ -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(); diff --git a/src/net/server/guild/MapleAlliance.java b/src/net/server/guild/MapleAlliance.java index 213bb261dc..bdcbe9362e 100644 --- a/src/net/server/guild/MapleAlliance.java +++ b/src/net/server/guild/MapleAlliance.java @@ -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 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 getPartyGuildMasters(MapleParty party) { + List 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 guildMasters = getPartyGuildMasters(party); + if(guildMasters.size() != 2) return null; + + List 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 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 getGuilds() { - List guilds_ = new LinkedList(); + List 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); + } } } diff --git a/src/net/server/guild/MapleGuild.java b/src/net/server/guild/MapleGuild.java index 0d37842538..6cd04b04d6 100644 --- a/src/net/server/guild/MapleGuild.java +++ b/src/net/server/guild/MapleGuild.java @@ -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 members; private String rankTitles[] = new String[5]; // 1 = master, 2 = jr, 5 = lowest member @@ -56,8 +55,6 @@ public class MapleGuild { private Map> 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; diff --git a/src/net/server/guild/MapleGuildCharacter.java b/src/net/server/guild/MapleGuildCharacter.java index eab452e147..e38e04eae5 100644 --- a/src/net/server/guild/MapleGuildCharacter.java +++ b/src/net/server/guild/MapleGuildCharacter.java @@ -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; diff --git a/src/net/server/world/World.java b/src/net/server/world/World.java index f31de9bfba..5b21549a77 100644 --- a/src/net/server/world/World.java +++ b/src/net/server/world/World.java @@ -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; diff --git a/src/scripting/npc/NPCConversationManager.java b/src/scripting/npc/NPCConversationManager.java index b627ab138f..26a1979b8e 100644 --- a/src/scripting/npc/NPCConversationManager.java +++ b/src/scripting/npc/NPCConversationManager.java @@ -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(); diff --git a/src/tools/MaplePacketCreator.java b/src/tools/MaplePacketCreator.java index 9d8e1b2ff3..70b54af610 100644 --- a/src/tools/MaplePacketCreator.java +++ b/src/tools/MaplePacketCreator.java @@ -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()); diff --git a/todo.txt b/todo.txt index d0190a78d9..3265476950 100644 --- a/todo.txt +++ b/todo.txt @@ -1,3 +1,2 @@ guild npc -PQs -scrolls for weather resistance \ No newline at end of file +PQs \ No newline at end of file