Можно переделать по своему вкусу. Так же не зашла на проекте. Подойдет для ПВП сервера. ЯДРО Код: /* * M.O.G. Devs Team * www.mmorpg-onlinegames.ru * Teg's {/aiononline, /eveonline} * * Thieves Guild Service 5.0.6 */ package com.mog.gameserver.services.dlc.thievesGuild; import java.sql.Timestamp; import java.util.concurrent.Future; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mog.gameserver.configs.main.CustomConfig; import com.mog.gameserver.configs.main.SecurityConfig; import com.mog.gameserver.dao.PlayerThievesListDAO; import com.mog.gameserver.model.TaskId; import com.mog.gameserver.model.actions.PlayerActions; import com.mog.gameserver.model.gameobjects.player.Player; import com.mog.gameserver.model.team.legion.Legion; import com.mog.gameserver.network.aion.serverpackets.SM_CAPTCHA; import com.mog.gameserver.network.aion.serverpackets.SM_SYSTEM_MESSAGE; import com.mog.gameserver.services.LegionService; import com.mog.gameserver.services.greatinvasion.DateTimeService; import com.mog.gameserver.utils.MathUtil; import com.mog.gameserver.utils.PacketSendUtility; import com.mog.gameserver.utils.ThreadPoolManager; import com.mog.gameserver.utils.captcha.CAPTCHAUtil; import com.mog.gameserver.utils.commons.database.dao.DAOManager; /** * @author Dision */ public class ThievesGuildService { private static final Logger log = LoggerFactory.getLogger(ThievesGuildService.class); public void onEnterWorld(Player player) { if (!CustomConfig.THIEVES_ENABLE) return; try { ThievesStatusList thieves = DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(player.getObjectId()); if(thieves == null) { player.setThieves(new ThievesStatusList(player.getObjectId(), 0, 0, 0l, 0, "Нет", 0, new Timestamp(System.currentTimeMillis()))); DAOManager.getDAO(PlayerThievesListDAO.class).saveNewThieves(player.getThieves()); } log.info("ThievesGuildService loadThievesStatus try [Player = " + player.getThieves().getPlayerId() + "]"); } catch (Exception ex) { log.error("Error in ThievesGuildService.onEnterWorld [Player = " + player.getName() + "]", ex); } } public void thieves(Player player) { if (!CustomConfig.THIEVES_ENABLE) return; for (Player target : player.getKnownList().getKnownPlayers().values()) { if (!PlayerActions.isAlreadyDead(target) && MathUtil.isIn3dRange(target, player, 2)) { if (!player.isThieves()) player.setIsThieves(true); player.setCaptchaWord(CAPTCHAUtil.getRandomWord()); player.setCaptchaImage(CAPTCHAUtil.createCAPTCHA(player.getCaptchaWord()).array()); captchaCheck(player, target, 0, true, SecurityConfig.CAPTCHA_EXTRACTION_BAN_TIME * 1000L); } } } public void createRevenge(Player player, Player target) { if (!CustomConfig.THIEVES_ENABLE) return; if (player.isThievesDuel()) return; target.setThieves(DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(target.getObjectId())); ThievesStatusList thieves = target.getThieves(); if (thieves.getRevengeName().equals(player.getName()) && !PlayerActions.isAlreadyDead(target) && MathUtil.isIn3dRange(target, player, 2)) { player.setThievesDuel(true); thievesMessage(player, "Вор " + target.getName() + " в зоне досягаемости. Начинается дуэль.", 0); thievesMessage(target, "Жертва " + player.getName() + " в зоне мщения. Начинается дуэль.", 0); //DuelService.getInstance().startDuel(player, target); } log.info("M.O.G. Console: ThievesGuildService createRevenge [Player = " + player.getName() + "]"); } public void revenge(Player player, Player target) { if (!CustomConfig.THIEVES_ENABLE) return; player.setThieves(DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(player.getObjectId())); target.setThieves(DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(target.getObjectId())); ThievesStatusList thievesPlayer = player.getThieves(); ThievesStatusList thievesTarget = target.getThieves(); if (thievesPlayer == null || thievesTarget == null) return; Timestamp nextTime = thievesTarget.getRevengeDate(); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); int revengeCount = thievesPlayer.getRevengeCount(); long kinahResult = (target.getInventory().getKinah() / thievesPlayer.getRankId()) + thievesTarget.getLastThievesKinah(); if (!player.getName().equals(thievesTarget.getRevengeName()) && currentTime.after(nextTime) && !currentTime.equals(nextTime)) { return; } else { player.getInventory().increaseKinah(kinahResult); target.getInventory().decreaseKinah(kinahResult); thievesPlayer.setRevengeCount(revengeCount + 1); thievesMessage(player, "Вы наказали вора " + target.getName() + " и вернули " + kinahResult + " кинар.", 0); } thievesTarget.setLastThievesKinah(0l); thievesTarget.setRevengeName("Нет"); thievesTarget.setRevengeDate(new Timestamp(System.currentTimeMillis())); DAOManager.getDAO(PlayerThievesListDAO.class).storeThieves(thievesPlayer); DAOManager.getDAO(PlayerThievesListDAO.class).storeThieves(thievesTarget); log.info("M.O.G. Console: ThievesGuildService revenge [Player = " + player.getName() + "]"); } private void thievesIn(Player player) { player.setThieves(DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(player.getObjectId())); ThievesStatusList thieves = player.getThieves(); if (thieves.getRankId() >= 3) { for (Legion legion : LegionService.getInstance().getCachedLegions()) { if (legion.getLegionName() == "ThievesGuild" && !player.getLegion().getLegionName().equals(legion.getLegionName())) { LegionService.getInstance().directAddPlayer(legion, player); log.info("M.O.G. Console: ThievesGuildService thievesIn [Player = " + player.getName() + "]"); } } } } private void thievesLegionCreate(Player player) { for (Legion legion : LegionService.getInstance().getCachedLegions()) { if (!legion.getLegionName().contains("ThievesGuild")) { LegionService.getInstance().createLegion(player, "ThievesGuild"); log.info("M.O.G. Console: ThievesGuildService thievesLegionCreate done"); } } } public void captchaCheck(Player player, int captchaCount, boolean state, long delay) { captchaCheck(player, null, captchaCount, state, delay); } public void captchaCheck(Player player, Player target, int captchaCount, boolean state, long delay) { stopThievesTask(player, false); if (state) { if (captchaCount < 3) { PacketSendUtility.sendPacket(player, new SM_CAPTCHA(captchaCount + 1, player.getCaptchaImage())); } else { player.setCaptchaWord(null); player.setCaptchaImage(null); } player.setThievesTimer(delay); player.setStopThieves(System.currentTimeMillis()); scheduleThievesTask(player, delay); log.info("M.O.G. Console: ThievesGuildService captchaCheck state [Player = " + player.getName() + "]"); } else { PacketSendUtility.sendPacket(player, new SM_SYSTEM_MESSAGE(1400269)); player.setCaptchaWord(null); player.setCaptchaImage(null); player.setThievesTimer(0); player.setStopThieves(0); player.setIsThieves(false); // Thieves success player.setThieves(DAOManager.getDAO(PlayerThievesListDAO.class).loadThieves(player.getObjectId())); ThievesStatusList thieves = player.getThieves(); Timestamp nextTime = thieves.getRevengeDate(); Timestamp currentTime = new Timestamp(System.currentTimeMillis()); int thievesCount = thieves.getThievesCount(); if (target != null && target.getName().equals(thieves.getRevengeName()) && currentTime.after(nextTime) && !currentTime.equals(nextTime)) { long kinah = 0; switch (ThievesType.getThievesType(thieves.getRankId())) { case SILVER: kinah = 1000 * thieves.getRankId(); break; case GOLD: kinah = 2000 * thieves.getRankId(); break; case PLATINUM: kinah = 3000 * thieves.getRankId(); break; case MITHRIL: kinah = 4000 * thieves.getRankId(); break; case SERAMIUM: kinah = 5000 * thieves.getRankId(); break; default: kinah = 600; break; } int rank = 0; switch (thieves.getThievesCount()) { case 10: rank = 1; thievesMessage(player, "Вор", 1); break; case 50: rank = 2; thievesMessage(player, "Карманник", 1); break; case 100: rank = 3; thievesMessage(player, "Воряга", 1); thievesLegionCreate(player); thievesIn(player); break; case 150: rank = 4; thievesMessage(player, "Ловкие руки", 1); break; case 200: rank = 5; thievesMessage(player, "Быстрые руки", 1); break; case 300: rank = 6; thievesMessage(player, "Неуловимый", 1); break; } thieves.setRankId(rank); thieves.setThievesCount(thievesCount + 1); thieves.setRevengeName(target.getName()); thieves.setRevengeDate(DateTimeService.getInstance().countNextRepeatTimeDay(1)); thieves.setLastThievesKinah(kinah); player.getInventory().increaseKinah(kinah); target.getInventory().decreaseKinah(kinah); DAOManager.getDAO(PlayerThievesListDAO.class).storeThieves(thieves); thievesMessage(player, "Вы обокрали " + target.getName(), 0); thievesMessage(player, "Будьте осторожней! Месть может быть быстрой от " + target.getName(), 0); thievesMessage(player, target.getName() + " получил возможность атаковать вас в любое время", 0); thievesMessage(player, "Если " + target.getName() + " вас убьет. Он получит краденое с % а вы потеряете этот %", 0); log.info("M.O.G. Console: ThievesGuildService captchaCheck [Player = " + player.getName() + "]"); } } } private void thievesMessage(Player player, String msg, int type) { String typeMsg = ""; switch (type) { case 1: typeMsg = "Получен новый ранг воровства: "; break; default: break; } PacketSendUtility.sendMessage(player, "[color:Гильд;0 255 0][color:ия во;0 255 0][color:ров;0 255 0]: " + typeMsg + msg + "."); } private void stopThievesTask(Player player, boolean state) { Future<?> thievesTask = player.getController().getTask(TaskId.THIEVES); if (thievesTask != null) { if (state) { long delay = player.getThievesTimer(); if (delay < 0) delay = 0; player.setThievesTimer(delay); } player.getController().cancelTask(TaskId.THIEVES); } } private void scheduleThievesTask(final Player player, long thievesTimer) { player.setThievesTimer(thievesTimer); player.getController().addTask(TaskId.THIEVES, ThreadPoolManager.getInstance().schedule(new Runnable() { @Override public void run() { captchaCheck(player, 0, false, 0); } }, thievesTimer)); } public static ThievesGuildService getInstance() { return ThievesGuildService.SingletonHolder.instance; } private static class SingletonHolder { protected static final ThievesGuildService instance = new ThievesGuildService(); } } Код: /* * M.O.G. Devs Team * www.mmorpg-onlinegames.ru * Teg's {/aiononline, /eveonline} */ package com.mog.gameserver.services.dlc.thievesGuild; import java.sql.Timestamp; /** * @author Dision */ public class ThievesStatusList { private int playerId; private int rankId; private int thievesCount; private Long lastThievesKinah; private int prisonCount; private String revengeName; private int revengeCount; private Timestamp revengeDate; public ThievesStatusList() { } public ThievesStatusList(int playerId, int rankId, int thievesCount, Long lastThievesKinah, int prisonCount, String revengeName, int revengeCount, Timestamp revengeDate) { this.playerId = playerId; this.rankId = rankId; this.thievesCount = thievesCount; this.lastThievesKinah = lastThievesKinah; this.prisonCount = prisonCount; this.revengeName = revengeName; this.revengeCount = revengeCount; this.revengeDate = revengeDate; } public int getPlayerId() { return playerId; } public void setPlayerId(int playerId) { this.playerId = playerId; } public int getRankId() { return rankId; } public void setRankId(int rankId) { this.rankId = rankId; } public int getThievesCount() { return thievesCount; } public void setThievesCount(int thievesCount) { this.thievesCount = thievesCount; } public Long getLastThievesKinah() { return lastThievesKinah; } public void setLastThievesKinah(Long lastThievesKinah) { this.lastThievesKinah = lastThievesKinah; } public int getPrisonCount() { return prisonCount; } public void setPrisonCount(int prisonCount) { this.prisonCount = prisonCount; } public String getRevengeName() { return revengeName; } public void setRevengeName(String revengeName) { this.revengeName = revengeName; } public int getRevengeCount() { return revengeCount; } public void setRevengeCount(int revengeCount) { this.revengeCount = revengeCount; } public Timestamp getRevengeDate() { return revengeDate; } public void setRevengeDate(Timestamp revengeDate) { this.revengeDate = revengeDate; } } Код: /* * M.O.G. Devs Team * www.mmorpg-onlinegames.ru * Teg's {/aiononline, /eveonline} */ package com.mog.gameserver.services.dlc.thievesGuild; /** * @author M.O.G. Dision */ public enum ThievesType { NONE(0), // Нет BRONZE(1), SILVER(2), GOLD(3), PLATINUM(4), MITHRIL(5), SERAMIUM(6); private int id; private ThievesType(int id) { this.id = id; } public int getId() { return id; } public static ThievesType getThievesType(int id) { for (ThievesType type : values()) { if (id == type.getId()) { return type; } } return ThievesType.NONE; } } Код: /* * Player Thieves List */ package com.mog.gameserver.dao; import com.mog.gameserver.services.dlc.thievesGuild.ThievesStatusList; import com.mog.gameserver.utils.commons.database.dao.DAO; /** * @author Dision */ public abstract class PlayerThievesListDAO implements DAO { @Override public final String getClassName() { return PlayerThievesListDAO.class.getName(); } public abstract ThievesStatusList loadThieves(int playerId); public abstract boolean saveNewThieves(ThievesStatusList thieves); public abstract void storeThieves(ThievesStatusList thieves); } Mysql5 Код: /* * MySQL5PlayerThievesDAO */ package mysql5; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.mog.gameserver.dao.MySQL5DAOUtils; import com.mog.gameserver.dao.PlayerThievesListDAO; import com.mog.gameserver.services.dlc.thievesGuild.ThievesStatusList; import com.mog.gameserver.utils.commons.database.DB; import com.mog.gameserver.utils.commons.database.DatabaseFactory; import com.mog.gameserver.utils.commons.database.IUStH; /** * @author Dision */ public class MySQL5PlayerThievesDAO extends PlayerThievesListDAO { private static final Logger log = LoggerFactory.getLogger(MySQL5PlayerThievesDAO.class); private static final String UPDATE_THIEVES_QUERY = "UPDATE player_thieves SET rank=?, thieves_count=?, prison_count=?, last_kinah=?, revenge_name=?, revenge_count=?, revenge_date=? WHERE player_id=?"; /** * {@inheritDoc} */ @Override public ThievesStatusList loadThieves(int playerId) { ThievesStatusList thieves = null; PreparedStatement st = DB.prepareStatement("SELECT * FROM player_thieves WHERE `player_id`=?"); try { st.setInt(1, playerId); ResultSet rs = st.executeQuery(); if (rs.next()) { thieves = new ThievesStatusList(); thieves.setPlayerId(playerId); thieves.setRankId(rs.getInt("rank")); thieves.setThievesCount(rs.getInt("thieves_count")); thieves.setPrisonCount(rs.getInt("prison_count")); thieves.setLastThievesKinah(rs.getLong("last_kinah")); thieves.setRevengeName(rs.getString("revenge_name")); thieves.setRevengeCount(rs.getInt("revenge_count")); thieves.setRevengeDate(rs.getTimestamp("revenge_date")); } } catch (Exception e) { log.error("Error in MySQL5PlayerThievesDAO.loadThieves, playerId: "+playerId, e); } finally { DB.close(st); } return thieves; } /** * {@inheritDoc} */ @Override public boolean saveNewThieves(ThievesStatusList thieves) { Connection con = null; try { con = DatabaseFactory.getConnection(); PreparedStatement preparedStatement = con.prepareStatement("INSERT INTO player_thieves (`player_id`, rank, thieves_count, prison_count, last_kinah, `revenge_name`, revenge_count, revenge_date) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)"); preparedStatement.setInt(1, thieves.getPlayerId()); // Default preparedStatement.setInt(2, thieves.getRankId()); preparedStatement.setInt(3, thieves.getThievesCount()); preparedStatement.setInt(4, thieves.getPrisonCount()); preparedStatement.setLong(5, thieves.getLastThievesKinah()); preparedStatement.setString(6, thieves.getRevengeName()); preparedStatement.setInt(7, thieves.getRevengeCount()); preparedStatement.setTimestamp(8, thieves.getRevengeDate()); preparedStatement.execute(); preparedStatement.close(); } catch (Exception e) { log.error("Error in MySQL5PlayerThievesDAO.saveNewThieves", e); return false; } finally { DatabaseFactory.close(con); } return true; } @Override public void storeThieves(final ThievesStatusList thieves) { DB.insertUpdate(UPDATE_THIEVES_QUERY, new IUStH() { @Override public void handleInsertUpdate(PreparedStatement stmt) throws SQLException { stmt.setInt(1, thieves.getRankId()); stmt.setInt(2, thieves.getThievesCount()); stmt.setInt(3, thieves.getPrisonCount()); stmt.setLong(4, thieves.getLastThievesKinah()); stmt.setString(5, thieves.getRevengeName()); stmt.setInt(6, thieves.getRevengeCount()); stmt.setString(7, thieves.getRevengeName()); stmt.setTimestamp(8, thieves.getRevengeDate()); stmt.setInt(9, thieves.getPlayerId()); // Default stmt.execute(); } }); } /** * {@inheritDoc} */ @Override public boolean supports(String database, int majorVersion, int minorVersion) { return MySQL5DAOUtils.supports(database, majorVersion, minorVersion); } } Sql Код: SET FOREIGN_KEY_CHECKS=0; -- ---------------------------- -- Table structure for player_thieves -- ---------------------------- DROP TABLE IF EXISTS `player_thieves`; CREATE TABLE `player_thieves` ( `player_id` int(11) NOT NULL, `rank` int(255) NOT NULL DEFAULT '0', `thieves_count` int(255) NOT NULL DEFAULT '0', `prison_count` int(255) NOT NULL DEFAULT '0', `last_kinah` bigint(20) NOT NULL DEFAULT '0', `revenge_name` varchar(25) NOT NULL DEFAULT 'Нет', `revenge_count` int(255) NOT NULL DEFAULT '0', `revenge_date` timestamp NOT NULL DEFAULT '2016-07-30 00:00:00', PRIMARY KEY (`player_id`), UNIQUE KEY `unique_name` (`player_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Bài viết hay quá, nếu bạn có nhu cầu Please login or register to view links, Amazon, Ebay, HM, Zara thì ghé thăm Verung.com nhé. Cảm ơn nhiều!