GuildHangoutHandler.java
资源名称:src.rar [点击查看]
上传用户:gwt600
上传日期:2021-06-03
资源大小:704k
文件大小:14k
源码类别:
游戏
开发平台:
Java
- /*
- 此文件是 MapleMs 核心服务器 -<MapleStory Server>
- Copyright (C) 2008 Patrick Huy <patrick.huy@frz.cc>
- Matthias Butz <matze@odinms.de>
- Jan Christian Meyer <vimes@odinms.de>
- 此文件原作者为德国 OdinMS 团队 以上是开发人员联系信息 本程序遵守
- 版本首要发布 GNU 协议进行修改发布 你可以无偿使用此文件或者进行修改
- 但是禁止使用本程序进行一切商业行为,如有发现 根据当地法律的制度 导致
- 任何法律责任,我们将不于承担 本程序发布是免费的 并不收取额外费用 拥有
- 此文件副本的人遵守 GNU 规定 但请保留修改发布人的信息 谢谢!
- 此二次开发修整版本: MapleMs
- 基于Xotic进行修改,融合ThePack DestinySource 等服务端的优点制作。
- ==============================================================
- 当前版本修复制作维护人员: MapleMs
- ==============================================================
- 您应该已经收到一份拷贝的GNU通用公共许可证Affero程式一起。如果不是,请参阅
- <http://www.gnu.org/licenses/>.
- */
- /*
- * Made and created by Red Hat.
- * QQ : 185544419 / -Red Hat-
- * Website :-MapleMs-
- *
- */
- package net.sf.odinms.net.channel.handler;
- import java.rmi.RemoteException;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import net.sf.odinms.client.MapleClient;
- import net.sf.odinms.database.DatabaseConnection;
- import net.sf.odinms.net.MaplePacket;
- import net.sf.odinms.server.life.MapleLifeFactory;
- import net.sf.odinms.server.life.MapleMonster;
- import net.sf.odinms.server.life.MapleNPC;
- import net.sf.odinms.server.maps.MapleMap;
- import net.sf.odinms.tools.MaplePacketCreator;
- /**
- *
- * @author MapleMs
- *
- */
- public class GuildHangoutHandler {
- public static void buyMap(MapleClient c, int map) {
- if (c.getChannelServer().getMapFactory().getMap(map).isOwned()) {
- //int price = c.getChannelServer().getMapFactory().getMap(map).getPrice();
- int price = 188;
- MapleMap targetMap = c.getChannelServer().getMapFactory().getMap(map);
- if (c.getPlayer().getDonatorPoints() >= price && c.getPlayer().getGuildRank() == 1) {
- targetMap.saveNPCS(targetMap.getOwner());
- if (!targetMap.isPubic()) {
- targetMap.setPublic(true);
- }
- targetMap.removeNpcs();
- targetMap.removeMobs();
- targetMap.setOwner(c.getPlayer().getGuild().getName());
- c.getPlayer().gainDonatorPoints(-price);
- targetMap.setPrice(price + 0);
- targetMap.setPublic(true);
- targetMap.saveGuildMaps(false);
- MaplePacket packet = MaplePacketCreator.serverNotice(6, "[家族领地] " + c.getPlayer().getGuild().getName() + " 刚刚购买了: " + targetMap.getOwner() + " 领地 " + c.getChannelServer().getMapFactory().getMap(map).getMapName() + ".");
- try {
- c.getChannelServer().getWorldInterface().broadcastMessage(c.getPlayer().getName(), packet.getBytes());
- } catch (RemoteException e) {
- c.getChannelServer().reconnectWorld();
- }
- } else {
- c.getPlayer().dropMessage("您必须拥有 " + price + " 冒险币才可以购买这个领地。并且你要是族长!");
- }
- } else {
- int price = 188;
- MapleMap targetMap = c.getChannelServer().getMapFactory().getMap(map);
- if (c.getPlayer().getDonatorPoints() >= price && c.getPlayer().getGuildRank() == 1) {
- targetMap.setOwner(c.getPlayer().getGuild().getName());
- c.getPlayer().gainDonatorPoints(-188);
- targetMap.setPrice(price + 0);
- targetMap.setPublic(true);
- targetMap.setOwned(true);
- targetMap.saveGuildMaps(true);
- MaplePacket packet = MaplePacketCreator.serverNotice(6, "[家族领地] " + c.getPlayer().getGuild().getName() + " 刚刚购买了 " + c.getChannelServer().getMapFactory().getMap(map).getMapName() + "这个领地.");
- try {
- c.getChannelServer().getWorldInterface().broadcastMessage(c.getPlayer().getName(), packet.getBytes());
- } catch (RemoteException e) {
- c.getChannelServer().reconnectWorld();
- }
- c.getChannelServer().getMapFactory().getMap(map).saveGuildMaps(true);
- } else {
- c.getPlayer().dropMessage("你必须有 " + price + " 冒险币才可以购买这个领地,并且你是族长!");
- }
- }
- }
- public static void setState(MapleClient c, int map) {
- int price = 20;
- MapleMap targetMap = c.getChannelServer().getMapFactory().getMap(map);
- if (!targetMap.isOwned()) {
- return;
- }
- if (c.getPlayer().getDonatorPoints() <= price) {
- c.getPlayer().dropMessage("你至少要有20香熏币.");
- return;
- }
- targetMap.setPublic(!targetMap.isPubic());
- c.getPlayer().dropMessage("修改成功!");
- c.getPlayer().gainDonatorPoints(-price);
- targetMap.saveGuildMaps(false);
- }
- public static void buyMonster(MapleClient c, int mobId) {
- MapleMonster mob = MapleLifeFactory.getMonster(mobId);
- if (mob != null && !mob.getName().equals("MISSINGNO") && !mob.isBoss() && mob.getLevel() <= 100 && c.getPlayer().getMeso() >= 50000000) {
- if (mob.getLevel() <= 50) {
- int price = 10;
- addMonster(c, mobId);
- c.getPlayer().gainDonatorPoints(-price);
- } else {
- int price = 15;
- if (c.getPlayer().getDonatorPoints() >= price) {
- addMonster(c, mobId);
- c.getPlayer().gainDonatorPoints(-price);
- } else {
- c.getPlayer().dropMessage("你必须要有15个香熏币,并且怪物等级不能超过100级。");
- }
- }
- } else {
- c.getPlayer().dropMessage("你至少要有10个香熏币,怪物必须存在,并且怪物不是BOSS,怪物等级不能大于100级。");
- }
- }
- public static void addMonster(MapleClient c, int mobId) {
- int mobTime = 120000;
- MapleMonster mob = MapleLifeFactory.getMonster(mobId);
- if (mob != null && !mob.getName().equals("MISSINGNO")) { //Just to be sure :P
- mob.setPosition(c.getPlayer().getPosition());
- mob.setCy(c.getPlayer().getPosition().y);
- mob.setRx0(c.getPlayer().getPosition().x + 50);
- mob.setRx1(c.getPlayer().getPosition().x - 50);
- mob.setFh(c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
- Connection con = DatabaseConnection.getConnection();
- try {
- PreparedStatement ps = con.prepareStatement("INSERT INTO spawns ( idd, f, fh, cy, rx0, rx1, type, x, y, mid, mobtime ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )");
- ps.setInt(1, mobId);
- ps.setInt(2, 0);
- ps.setInt(3, c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId());
- ps.setInt(4, c.getPlayer().getPosition().y);
- ps.setInt(5, c.getPlayer().getPosition().x + 50);
- ps.setInt(6, c.getPlayer().getPosition().x - 50);
- ps.setString(7, "m");
- ps.setInt(8, c.getPlayer().getPosition().x);
- ps.setInt(9, c.getPlayer().getPosition().y);
- ps.setInt(10, c.getPlayer().getMapId());
- ps.setInt(11, mobTime);
- ps.executeUpdate();
- c.getPlayer().getMap().addMonsterSpawn(mob, mobTime);
- } catch (SQLException e) {
- System.out.print("领地添加怪物时发生错误 : " + e);
- }
- }
- }
- public static void buyNpc(MapleClient c, int npcId) {
- MapleNPC npc = MapleLifeFactory.getNPC(npcId);
- if (c.getPlayer().getDonatorPoints() <= 20) {
- c.getPlayer().dropMessage("购买一个NPC必须要有20个香熏币。");
- return;
- }
- int xpos = c.getPlayer().getPosition().x;
- int ypos = c.getPlayer().getPosition().y;
- int fh = c.getPlayer().getMap().getFootholds().findBelow(c.getPlayer().getPosition()).getId();
- if (npc != null && !npc.getName().equals("MISSINGNO")) {
- npc.setPosition(c.getPlayer().getPosition());
- npc.setCy(ypos);
- npc.setRx0(xpos + 50);
- npc.setRx1(xpos - 50);
- npc.setFh(fh);
- npc.setCustom(true);
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("INSERT INTO guildspawns ( idd, f, fh, cy, rx0, rx1, type, x, y, mid, guild) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
- ps.setInt(1, npcId);
- ps.setInt(2, 0);
- ps.setInt(3, fh);
- ps.setInt(4, ypos);
- ps.setInt(4, ypos);
- ps.setInt(5, xpos + 50);
- ps.setInt(6, xpos - 50);
- ps.setString(7, "n");
- ps.setInt(8, xpos);
- ps.setInt(9, ypos);
- ps.setInt(10, c.getPlayer().getMapId());
- ps.setString(11, c.getPlayer().getGuild().getName());
- ps.executeUpdate();
- ps.close();
- } catch (SQLException e) {
- c.getPlayer().dropMessage("NPC无法保存到数据库!");
- }
- c.getPlayer().getMap().addMapObject(npc);
- c.getPlayer().getMap().broadcastMessage(MaplePacketCreator.spawnNPC(npc));
- c.getPlayer().gainDonatorPoints(-20);
- } else {
- c.getPlayer().dropMessage("请输入一个有效的NPC代码。");
- }
- }
- public static boolean hasHiddenNPC(String guild) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT * FROM guildspawns WHERE hidden = 1 AND guild = ?");
- ps.setString(1, guild);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- ps.close();
- rs.close();
- return true;
- }
- ps.close();
- rs.close();
- } catch (SQLException e) {
- }
- return false;
- }
- public static void replaceHiddenNPCS(MapleClient c, String guild, int newMap) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT * FROM guildspawns WHERE hidden = 1 AND guild = ?");
- ps.setString(1, guild);
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- int map = rs.getInt("mid");
- PreparedStatement psx = con.prepareStatement("UPDATE guildspawns SET mid = ? WHERE mid = ? AND guild = ?");
- psx.setInt(1, newMap);
- psx.setInt(2, map);
- psx.setString(3, guild);
- psx.executeUpdate();
- psx.close();
- ps.close();
- rs.close();
- }
- ps.close();
- rs.close();
- } catch (SQLException e) {
- }
- }
- public static boolean checkAlliance(MapleClient c, String guild) {
- try {
- Connection con = DatabaseConnection.getConnection();
- PreparedStatement ps = con.prepareStatement("SELECT * FROM guilds where name = ?");
- ps.setString(1, c.getPlayer().getGuild().getName());
- ResultSet rs = ps.executeQuery();
- while (rs.next()) {
- int eId = rs.getInt("guildid");
- ps.close();
- rs.close();
- PreparedStatement psx = con.prepareStatement("SELECT * FROM alliance WHERE guild1 = ? OR guild2 = ? OR guild3 = ? OR guild4 = ? OR guild5 = ?");
- psx.setInt(1, eId);
- psx.setInt(2, eId);
- psx.setInt(3, eId);
- psx.setInt(4, eId);
- psx.setInt(5, eId);
- ResultSet rsx = psx.executeQuery();
- while (rsx.next()) {
- int aId = rs.getInt("id");
- rsx.close();
- psx.close();
- PreparedStatement psa = con.prepareStatement("SELECT * FROM guilds where name = ?");
- psa.setString(1, guild);
- ResultSet rsa = psa.executeQuery();
- while (rsa.next()) {
- int id = rs.getInt("allianceId");
- if (aId == id) {
- rsa.close();
- psa.close();
- return true;
- }
- }
- rsa.close();
- psa.close();
- }
- rsx.close();
- psx.close();
- }
- ps.close();
- rs.close();
- } catch (Exception e) {
- return false;
- }
- return false;
- }
- }