https://mmo-dev.info/rules/#rule-4_5
- Хроники
- The 2nd Throne: Freya
- Исходники
- Отсутствуют
- Сборка
- overworld
Кто может создать таблицу для БД. постоянно ошибки в ГС. C меня ?
package l2p.gameserver.model.actor.instances.player;
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import l2p.gameserver.serverpackets.components.IStaticPacket;
import l2p.gameserver.serverpackets.ExVoteSystemInfo;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.Statement;
import l2p.commons.dbutils.DbUtils;
import l2p.gameserver.database.DatabaseFactory;
import l2p.gameserver.model.GameObjectTasks;
import l2p.gameserver.ThreadPoolManager;
import l2p.gameserver.model.Player;
import java.util.concurrent.ScheduledFuture;
import org.slf4j.Logger;
public final class RecoBonus
{
private static final Logger _log;
private static final int[][] RECO_BONUS;
private final int _objectId;
private long _recomBonusTime;
private int _recomHave;
private int _recomLeft;
private ScheduledFuture<?> _recoBonusTask;
private ScheduledFuture<?> _recoGiveTask;
private boolean _recoTwoHoursGiven;
public RecoBonus(final Player owner) {
this._recoTwoHoursGiven = false;
this._objectId = owner.getObjectId();
this.checkRecoBonusTask(owner);
}
private void checkRecoBonusTask(final Player player) {
this._recomBonusTime = this.loadRecommendations();
this._recoGiveTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().scheduleAtFixedRate((Runnable)new GameObjectTasks.RecoGiveTask(player), 7200000L, 3600000L);
this.storeRecommendations();
}
private long loadRecommendations() {
long time_left = 0L;
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
try {
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT rec_have,rec_left,time_left FROM character_reco_bonus WHERE char_obj_id=? LIMIT 1");
statement.setInt(1, this._objectId);
rset = statement.executeQuery();
if (rset.next()) {
this.setRecomHave(rset.getInt("rec_have"));
this.setRecomLeft(rset.getInt("rec_left"));
time_left = rset.getLong("time_left");
}
else {
time_left = 3600000L;
}
}
catch (Exception e) {
RecoBonus._log.error("Could not restore Recommendations for player: " + this._objectId, (Throwable)e);
}
finally {
DbUtils.closeQuietly(con, (Statement)statement, rset);
}
return time_left;
}
public void storeRecommendations() {
Connection con = null;
PreparedStatement statement = null;
try {
this.stopRecoBonusTask();
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("INSERT INTO character_reco_bonus (char_obj_id,rec_have,rec_left,time_left) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE rec_have=?, rec_left=?, time_left=?");
statement.setInt(1, this._objectId);
statement.setInt(2, this.getRecomHave());
statement.setInt(3, this.getRecomLeft());
statement.setLong(4, this._recomBonusTime);
statement.setInt(5, this.getRecomHave());
statement.setInt(6, this.getRecomLeft());
statement.setLong(7, this._recomBonusTime);
statement.execute();
}
catch (Exception e) {
RecoBonus._log.error("Could not update Recommendations for player: " + this._objectId, (Throwable)e);
}
finally {
DbUtils.closeQuietly(con, (Statement)statement);
}
}
public void stopAllTimers() {
this.stopRecoBonusTask();
this.stopRecoGiveTask();
}
public boolean isRecomTimerActive() {
return this._recoBonusTask != null;
}
public void setRecomTimerActive(final Player player, final boolean start) {
if (start) {
if (this._recoBonusTask == null && this._recomBonusTime > 0L) {
this._recoBonusTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().schedule((Runnable)new GameObjectTasks.RecoBonusTaskEnd(player), this._recomBonusTime);
}
}
else {
this.stopRecoBonusTask();
}
player.sendPacket((IStaticPacket)new ExVoteSystemInfo(player));
}
public void restartRecoBonusTask(final Player player, final int days) {
this.stopAllTimers();
for (int i = 1; i < days; ++i) {
this.setRecomHave(this.getRecomHave() - 20);
}
this.setRecomLeft(20);
this._recomBonusTime = 3600000L;
this._recoBonusTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().schedule((Runnable)new GameObjectTasks.RecoBonusTaskEnd(player), this._recomBonusTime);
this._recoGiveTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().scheduleAtFixedRate((Runnable)new GameObjectTasks.RecoGiveTask(player), 7200000L, 3600000L);
player.sendUserInfo(true);
player.sendPacket((IStaticPacket)new ExVoteSystemInfo(player));
}
private void stopRecoBonusTask() {
if (this._recoBonusTask != null) {
this._recomBonusTime = Math.max(0L, this._recoBonusTask.getDelay(TimeUnit.MILLISECONDS));
this._recoBonusTask.cancel(false);
this._recoBonusTask = null;
}
}
public void stopRecoGiveTask() {
if (this._recoGiveTask != null) {
this._recoGiveTask.cancel(false);
this._recoGiveTask = null;
}
}
public int getRecomHave() {
return this._recomHave;
}
protected void incRecomHave() {
if (this._recomHave < 255) {
++this._recomHave;
}
}
public void setRecomHave(final int value) {
if (value > 255) {
this._recomHave = 255;
}
else if (value < 0) {
this._recomHave = 0;
}
else {
this._recomHave = value;
}
}
public void setRecomLeft(final int value) {
if (value > 255) {
this._recomLeft = 255;
}
else if (value < 0) {
this._recomLeft = 0;
}
else {
this._recomLeft = value;
}
}
public int getRecomLeft() {
return this._recomLeft;
}
protected void decRecomLeft() {
if (this._recomLeft > 0) {
--this._recomLeft;
}
}
public void giveRecom(final Player target) {
target.getRecoBonus().incRecomHave();
this.decRecomLeft();
}
public int getRecomBonusTime() {
if (this._recoBonusTask != null) {
return (int)Math.max(0L, this._recoBonusTask.getDelay(TimeUnit.SECONDS));
}
return (int)(this._recomBonusTime / 1000L);
}
public int getRecomBonusType() {
return 0;
}
public final void setRecoTwoHoursGiven(final boolean val) {
this._recoTwoHoursGiven = val;
}
public boolean isRecoTwoHoursGiven() {
return this._recoTwoHoursGiven;
}
public static int getRecoBonus(final Player activeChar) {
if (activeChar == null || !activeChar.isOnline()) {
return 0;
}
if (activeChar.getRecoBonus().getRecomHave() == 0 || activeChar.getRecoBonus().getRecomBonusTime() < 1) {
return 0;
}
final int _lvl = (int)Math.ceil(activeChar.getLevel() / 10);
final int _exp = (int)Math.ceil((Math.min(100, activeChar.getRecoBonus().getRecomHave()) - 1) / 10);
return RecoBonus.RECO_BONUS[_lvl][_exp];
}
public static double getRecoMultiplier(final Player activeChar) {
final double bonus = getRecoBonus(activeChar);
if (bonus > 0.0) {
return 1.0 + bonus / 100.0;
}
return 1.0;
}
static {
_log = LoggerFactory.getLogger(RecoBonus.class.getName());
RECO_BONUS = new int[][] { { 25, 50, 50, 50, 50, 50, 50, 50, 50, 50 }, { 16, 33, 50, 50, 50, 50, 50, 50, 50, 50 }, { 12, 25, 37, 50, 50, 50, 50, 50, 50, 50 }, { 10, 20, 30, 40, 50, 50, 50, 50, 50, 50 }, { 8, 16, 25, 33, 41, 50, 50, 50, 50, 50 }, { 7, 14, 21, 28, 35, 42, 50, 50, 50, 50 }, { 6, 12, 18, 25, 31, 37, 43, 50, 50, 50 }, { 5, 11, 16, 22, 27, 33, 38, 44, 50, 50 }, { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 } };
}
}
import org.slf4j.LoggerFactory;
import java.util.concurrent.TimeUnit;
import l2p.gameserver.serverpackets.components.IStaticPacket;
import l2p.gameserver.serverpackets.ExVoteSystemInfo;
import java.sql.ResultSet;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.Statement;
import l2p.commons.dbutils.DbUtils;
import l2p.gameserver.database.DatabaseFactory;
import l2p.gameserver.model.GameObjectTasks;
import l2p.gameserver.ThreadPoolManager;
import l2p.gameserver.model.Player;
import java.util.concurrent.ScheduledFuture;
import org.slf4j.Logger;
public final class RecoBonus
{
private static final Logger _log;
private static final int[][] RECO_BONUS;
private final int _objectId;
private long _recomBonusTime;
private int _recomHave;
private int _recomLeft;
private ScheduledFuture<?> _recoBonusTask;
private ScheduledFuture<?> _recoGiveTask;
private boolean _recoTwoHoursGiven;
public RecoBonus(final Player owner) {
this._recoTwoHoursGiven = false;
this._objectId = owner.getObjectId();
this.checkRecoBonusTask(owner);
}
private void checkRecoBonusTask(final Player player) {
this._recomBonusTime = this.loadRecommendations();
this._recoGiveTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().scheduleAtFixedRate((Runnable)new GameObjectTasks.RecoGiveTask(player), 7200000L, 3600000L);
this.storeRecommendations();
}
private long loadRecommendations() {
long time_left = 0L;
Connection con = null;
PreparedStatement statement = null;
ResultSet rset = null;
try {
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("SELECT rec_have,rec_left,time_left FROM character_reco_bonus WHERE char_obj_id=? LIMIT 1");
statement.setInt(1, this._objectId);
rset = statement.executeQuery();
if (rset.next()) {
this.setRecomHave(rset.getInt("rec_have"));
this.setRecomLeft(rset.getInt("rec_left"));
time_left = rset.getLong("time_left");
}
else {
time_left = 3600000L;
}
}
catch (Exception e) {
RecoBonus._log.error("Could not restore Recommendations for player: " + this._objectId, (Throwable)e);
}
finally {
DbUtils.closeQuietly(con, (Statement)statement, rset);
}
return time_left;
}
public void storeRecommendations() {
Connection con = null;
PreparedStatement statement = null;
try {
this.stopRecoBonusTask();
con = DatabaseFactory.getInstance().getConnection();
statement = con.prepareStatement("INSERT INTO character_reco_bonus (char_obj_id,rec_have,rec_left,time_left) VALUES (?,?,?,?) ON DUPLICATE KEY UPDATE rec_have=?, rec_left=?, time_left=?");
statement.setInt(1, this._objectId);
statement.setInt(2, this.getRecomHave());
statement.setInt(3, this.getRecomLeft());
statement.setLong(4, this._recomBonusTime);
statement.setInt(5, this.getRecomHave());
statement.setInt(6, this.getRecomLeft());
statement.setLong(7, this._recomBonusTime);
statement.execute();
}
catch (Exception e) {
RecoBonus._log.error("Could not update Recommendations for player: " + this._objectId, (Throwable)e);
}
finally {
DbUtils.closeQuietly(con, (Statement)statement);
}
}
public void stopAllTimers() {
this.stopRecoBonusTask();
this.stopRecoGiveTask();
}
public boolean isRecomTimerActive() {
return this._recoBonusTask != null;
}
public void setRecomTimerActive(final Player player, final boolean start) {
if (start) {
if (this._recoBonusTask == null && this._recomBonusTime > 0L) {
this._recoBonusTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().schedule((Runnable)new GameObjectTasks.RecoBonusTaskEnd(player), this._recomBonusTime);
}
}
else {
this.stopRecoBonusTask();
}
player.sendPacket((IStaticPacket)new ExVoteSystemInfo(player));
}
public void restartRecoBonusTask(final Player player, final int days) {
this.stopAllTimers();
for (int i = 1; i < days; ++i) {
this.setRecomHave(this.getRecomHave() - 20);
}
this.setRecomLeft(20);
this._recomBonusTime = 3600000L;
this._recoBonusTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().schedule((Runnable)new GameObjectTasks.RecoBonusTaskEnd(player), this._recomBonusTime);
this._recoGiveTask = (ScheduledFuture<?>)ThreadPoolManager.getInstance().scheduleAtFixedRate((Runnable)new GameObjectTasks.RecoGiveTask(player), 7200000L, 3600000L);
player.sendUserInfo(true);
player.sendPacket((IStaticPacket)new ExVoteSystemInfo(player));
}
private void stopRecoBonusTask() {
if (this._recoBonusTask != null) {
this._recomBonusTime = Math.max(0L, this._recoBonusTask.getDelay(TimeUnit.MILLISECONDS));
this._recoBonusTask.cancel(false);
this._recoBonusTask = null;
}
}
public void stopRecoGiveTask() {
if (this._recoGiveTask != null) {
this._recoGiveTask.cancel(false);
this._recoGiveTask = null;
}
}
public int getRecomHave() {
return this._recomHave;
}
protected void incRecomHave() {
if (this._recomHave < 255) {
++this._recomHave;
}
}
public void setRecomHave(final int value) {
if (value > 255) {
this._recomHave = 255;
}
else if (value < 0) {
this._recomHave = 0;
}
else {
this._recomHave = value;
}
}
public void setRecomLeft(final int value) {
if (value > 255) {
this._recomLeft = 255;
}
else if (value < 0) {
this._recomLeft = 0;
}
else {
this._recomLeft = value;
}
}
public int getRecomLeft() {
return this._recomLeft;
}
protected void decRecomLeft() {
if (this._recomLeft > 0) {
--this._recomLeft;
}
}
public void giveRecom(final Player target) {
target.getRecoBonus().incRecomHave();
this.decRecomLeft();
}
public int getRecomBonusTime() {
if (this._recoBonusTask != null) {
return (int)Math.max(0L, this._recoBonusTask.getDelay(TimeUnit.SECONDS));
}
return (int)(this._recomBonusTime / 1000L);
}
public int getRecomBonusType() {
return 0;
}
public final void setRecoTwoHoursGiven(final boolean val) {
this._recoTwoHoursGiven = val;
}
public boolean isRecoTwoHoursGiven() {
return this._recoTwoHoursGiven;
}
public static int getRecoBonus(final Player activeChar) {
if (activeChar == null || !activeChar.isOnline()) {
return 0;
}
if (activeChar.getRecoBonus().getRecomHave() == 0 || activeChar.getRecoBonus().getRecomBonusTime() < 1) {
return 0;
}
final int _lvl = (int)Math.ceil(activeChar.getLevel() / 10);
final int _exp = (int)Math.ceil((Math.min(100, activeChar.getRecoBonus().getRecomHave()) - 1) / 10);
return RecoBonus.RECO_BONUS[_lvl][_exp];
}
public static double getRecoMultiplier(final Player activeChar) {
final double bonus = getRecoBonus(activeChar);
if (bonus > 0.0) {
return 1.0 + bonus / 100.0;
}
return 1.0;
}
static {
_log = LoggerFactory.getLogger(RecoBonus.class.getName());
RECO_BONUS = new int[][] { { 25, 50, 50, 50, 50, 50, 50, 50, 50, 50 }, { 16, 33, 50, 50, 50, 50, 50, 50, 50, 50 }, { 12, 25, 37, 50, 50, 50, 50, 50, 50, 50 }, { 10, 20, 30, 40, 50, 50, 50, 50, 50, 50 }, { 8, 16, 25, 33, 41, 50, 50, 50, 50, 50 }, { 7, 14, 21, 28, 35, 42, 50, 50, 50, 50 }, { 6, 12, 18, 25, 31, 37, 43, 50, 50, 50 }, { 5, 11, 16, 22, 27, 33, 38, 44, 50, 50 }, { 5, 10, 15, 20, 25, 30, 35, 40, 45, 50 } };
}
}