Reduced queries for storing clan values.
This commit is contained in:
@@ -189,7 +189,7 @@ public class AdminPledge implements IAdminCommandHandler
|
||||
try
|
||||
{
|
||||
final int points = Integer.parseInt(param);
|
||||
clan.addReputationScore(points, true);
|
||||
clan.addReputationScore(points);
|
||||
BuilderUtil.sendSysMessage(activeChar, "You " + (points > 0 ? "add " : "remove ") + Math.abs(points) + " points " + (points > 0 ? "to " : "from ") + clan.getName() + "'s reputation. Their current score is " + clan.getReputationScore());
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -52,7 +52,7 @@ public class GiveClanReputation extends AbstractEffect
|
||||
return;
|
||||
}
|
||||
|
||||
effector.getActingPlayer().getClan().addReputationScore(_reputation, true);
|
||||
effector.getActingPlayer().getClan().addReputationScore(_reputation);
|
||||
|
||||
for (ClanMember member : effector.getActingPlayer().getClan().getMembers())
|
||||
{
|
||||
|
||||
@@ -477,7 +477,8 @@ public class ClanTable
|
||||
{
|
||||
for (Clan clan : _clans.values())
|
||||
{
|
||||
clan.updateInDB();
|
||||
clan.updateClanInDB();
|
||||
clan.getVariables().storeMe();
|
||||
for (ClanWar war : clan.getWarList().values())
|
||||
{
|
||||
storeClanWars(war);
|
||||
|
||||
@@ -300,7 +300,7 @@ public class Attackable extends Npc
|
||||
{
|
||||
if ((killer.getClan() != null) && (Rnd.get(100) < 2))
|
||||
{
|
||||
killer.getClan().addExp(killer.getObjectId(), 1, true);
|
||||
killer.getClan().addExp(killer.getObjectId(), 1);
|
||||
}
|
||||
|
||||
// Delayed notification
|
||||
|
||||
@@ -2419,15 +2419,15 @@ public class Player extends Playable
|
||||
{
|
||||
if (_lvlJoinedAcademy <= 16)
|
||||
{
|
||||
_clan.addReputationScore(Config.JOIN_ACADEMY_MAX_REP_SCORE, true);
|
||||
_clan.addReputationScore(Config.JOIN_ACADEMY_MAX_REP_SCORE);
|
||||
}
|
||||
else if (_lvlJoinedAcademy >= 39)
|
||||
{
|
||||
_clan.addReputationScore(Config.JOIN_ACADEMY_MIN_REP_SCORE, true);
|
||||
_clan.addReputationScore(Config.JOIN_ACADEMY_MIN_REP_SCORE);
|
||||
}
|
||||
else
|
||||
{
|
||||
_clan.addReputationScore((Config.JOIN_ACADEMY_MAX_REP_SCORE - ((_lvlJoinedAcademy - 16) * 20)), true);
|
||||
_clan.addReputationScore((Config.JOIN_ACADEMY_MAX_REP_SCORE - ((_lvlJoinedAcademy - 16) * 20)));
|
||||
}
|
||||
setLvlJoinedAcademy(0);
|
||||
// oust pledge member from the academy, cuz he has finished his 2nd class transfer
|
||||
|
||||
@@ -353,7 +353,7 @@ public class PlayableStat extends CreatureStat
|
||||
|
||||
reputation = (int) Math.ceil(reputation * Config.LVL_OBTAINED_REP_SCORE_MULTIPLIER);
|
||||
|
||||
clan.addReputationScore(reputation, true);
|
||||
clan.addReputationScore(reputation);
|
||||
|
||||
for (ClanMember member : clan.getMembers())
|
||||
{
|
||||
|
||||
@@ -965,28 +965,6 @@ public class Clan implements IIdentifiable, INamable
|
||||
}
|
||||
}
|
||||
|
||||
public void updateInDB()
|
||||
{
|
||||
// Update reputation
|
||||
try (Connection con = DatabaseFactory.getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE clan_data SET reputation_score=? WHERE clan_id=?"))
|
||||
{
|
||||
ps.setInt(1, _reputationScore);
|
||||
ps.setInt(2, _clanId);
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LOGGER.log(Level.WARNING, "Exception on updateClanScoreInDb(): " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
// Update variables at database
|
||||
if (_vars != null)
|
||||
{
|
||||
_vars.storeMe();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates in database clan information:
|
||||
* <ul>
|
||||
@@ -1131,7 +1109,7 @@ public class Clan implements IIdentifiable, INamable
|
||||
setAllyCrestId(clanData.getInt("ally_crest_id"));
|
||||
|
||||
_exp = clanData.getInt("exp");
|
||||
setReputationScore(clanData.getInt("reputation_score"), false);
|
||||
setReputationScore(clanData.getInt("reputation_score"));
|
||||
setAuctionBiddedAt(clanData.getInt("auction_bid_at"), false);
|
||||
setNewLeaderId(clanData.getInt("new_leader_id"), false);
|
||||
|
||||
@@ -1917,11 +1895,11 @@ public class Clan implements IIdentifiable, INamable
|
||||
// Order of Knights 10000 points per each
|
||||
if (pledgeType < SUBUNIT_KNIGHT1)
|
||||
{
|
||||
setReputationScore(_reputationScore - Config.ROYAL_GUARD_COST, true);
|
||||
setReputationScore(_reputationScore - Config.ROYAL_GUARD_COST);
|
||||
}
|
||||
else
|
||||
{
|
||||
setReputationScore(_reputationScore - Config.KNIGHT_UNIT_COST, true);
|
||||
setReputationScore(_reputationScore - Config.KNIGHT_UNIT_COST);
|
||||
// TODO: clan lvl9 or more can reinforce knights cheaper if first knight unit already created, use Config.KNIGHT_REINFORCE_COST
|
||||
}
|
||||
}
|
||||
@@ -2115,17 +2093,17 @@ public class Clan implements IIdentifiable, INamable
|
||||
return id;
|
||||
}
|
||||
|
||||
public synchronized void addReputationScore(int value, boolean save)
|
||||
public synchronized void addReputationScore(int value)
|
||||
{
|
||||
setReputationScore(_reputationScore + value, save);
|
||||
setReputationScore(_reputationScore + value);
|
||||
}
|
||||
|
||||
public synchronized void takeReputationScore(int value, boolean save)
|
||||
public synchronized void takeReputationScore(int value)
|
||||
{
|
||||
setReputationScore(_reputationScore - value, save);
|
||||
setReputationScore(_reputationScore - value);
|
||||
}
|
||||
|
||||
private void setReputationScore(int value, boolean save)
|
||||
private void setReputationScore(int value)
|
||||
{
|
||||
if ((_reputationScore >= 0) && (value < 0))
|
||||
{
|
||||
@@ -2159,11 +2137,8 @@ public class Clan implements IIdentifiable, INamable
|
||||
{
|
||||
_reputationScore = -100000000;
|
||||
}
|
||||
|
||||
broadcastToOnlineMembers(new PledgeShowInfoUpdate(this));
|
||||
if (save)
|
||||
{
|
||||
updateInDB();
|
||||
}
|
||||
}
|
||||
|
||||
public int getReputationScore()
|
||||
@@ -3110,7 +3085,7 @@ public class Clan implements IIdentifiable, INamable
|
||||
return _exp;
|
||||
}
|
||||
|
||||
public void addExp(int objId, int value, boolean save)
|
||||
public void addExp(int objId, int value)
|
||||
{
|
||||
_exp += value;
|
||||
broadcastToOnlineMembers(new ExPledgeV3Info(_exp, getRank(), getNotice(), isNoticeEnabled()));
|
||||
@@ -3120,13 +3095,9 @@ public class Clan implements IIdentifiable, INamable
|
||||
changeLevel(_level + 1);
|
||||
}
|
||||
|
||||
if (save)
|
||||
{
|
||||
final int contribution = getClanContribution(objId);
|
||||
setClanContribution(objId, contribution + value);
|
||||
setClanContributionWeekly(objId, contribution + value);
|
||||
updateClanInDB();
|
||||
}
|
||||
final int contribution = getClanContribution(objId);
|
||||
setClanContribution(objId, contribution + value);
|
||||
setClanContributionWeekly(objId, contribution + value);
|
||||
}
|
||||
|
||||
public void setExp(int objId, int value)
|
||||
@@ -3137,6 +3108,7 @@ public class Clan implements IIdentifiable, INamable
|
||||
final int contribution = getClanContribution(objId);
|
||||
setClanContribution(objId, contribution + value);
|
||||
setClanContributionWeekly(objId, contribution + value);
|
||||
|
||||
updateClanInDB();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,8 +110,8 @@ public class ClanWar
|
||||
// however, when the other side reputation score is 0 or below, your clan cannot acquire any reputation points from them.
|
||||
if (victimClan.getReputationScore() > 0)
|
||||
{
|
||||
victimClan.takeReputationScore(Config.REPUTATION_SCORE_PER_KILL, false);
|
||||
killerClan.addReputationScore(Config.REPUTATION_SCORE_PER_KILL, false);
|
||||
victimClan.takeReputationScore(Config.REPUTATION_SCORE_PER_KILL);
|
||||
killerClan.addReputationScore(Config.REPUTATION_SCORE_PER_KILL);
|
||||
}
|
||||
|
||||
// System Message notification to clan members
|
||||
@@ -167,7 +167,7 @@ public class ClanWar
|
||||
final Clan winnerClan = cancelor.getId() == _attackerClanId ? ClanTable.getInstance().getClan(_attackedClanId) : ClanTable.getInstance().getClan(_attackerClanId);
|
||||
|
||||
// Reduce reputation.
|
||||
cancelor.takeReputationScore(500, true);
|
||||
cancelor.takeReputationScore(500);
|
||||
player.sendPacket(new SurrenderPledgeWar(cancelor.getName(), player.getName()));
|
||||
SystemMessage sm = new SystemMessage(SystemMessageId.THE_WAR_ENDED_BY_YOUR_DEFEAT_DECLARATION_WITH_THE_S1_CLAN);
|
||||
sm.addString(winnerClan.getName());
|
||||
|
||||
@@ -931,7 +931,7 @@ public class Hero
|
||||
final Clan clan = player.getClan();
|
||||
if ((clan != null) && (clan.getLevel() >= 3))
|
||||
{
|
||||
clan.addReputationScore(Config.HERO_POINTS, true);
|
||||
clan.addReputationScore(Config.HERO_POINTS);
|
||||
final SystemMessage sm = new SystemMessage(SystemMessageId.CLAN_MEMBER_C1_WAS_NAMED_A_HERO_S2_POINTS_HAVE_BEEN_ADDED_TO_YOUR_CLAN_REPUTATION);
|
||||
sm.addString(CharNameTable.getInstance().getNameById(player.getObjectId()));
|
||||
sm.addInt(Config.HERO_POINTS);
|
||||
|
||||
@@ -1015,16 +1015,16 @@ public class Castle extends AbstractResidence
|
||||
if (_formerOwner != ClanTable.getInstance().getClan(getOwnerId()))
|
||||
{
|
||||
final int maxreward = Math.max(0, _formerOwner.getReputationScore());
|
||||
_formerOwner.takeReputationScore(Config.LOOSE_CASTLE_POINTS, true);
|
||||
_formerOwner.takeReputationScore(Config.LOOSE_CASTLE_POINTS);
|
||||
final Clan owner = ClanTable.getInstance().getClan(getOwnerId());
|
||||
if (owner != null)
|
||||
{
|
||||
owner.addReputationScore(Math.min(Config.TAKE_CASTLE_POINTS, maxreward), true);
|
||||
owner.addReputationScore(Math.min(Config.TAKE_CASTLE_POINTS, maxreward));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_formerOwner.addReputationScore(Config.CASTLE_DEFENDED_POINTS, true);
|
||||
_formerOwner.addReputationScore(Config.CASTLE_DEFENDED_POINTS);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -1032,7 +1032,7 @@ public class Castle extends AbstractResidence
|
||||
final Clan owner = ClanTable.getInstance().getClan(getOwnerId());
|
||||
if (owner != null)
|
||||
{
|
||||
owner.addReputationScore(Config.TAKE_CASTLE_POINTS, true);
|
||||
owner.addReputationScore(Config.TAKE_CASTLE_POINTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -939,11 +939,11 @@ public class Fort extends AbstractResidence
|
||||
{
|
||||
if (removePoints)
|
||||
{
|
||||
owner.takeReputationScore(Config.LOOSE_FORT_POINTS, true);
|
||||
owner.takeReputationScore(Config.LOOSE_FORT_POINTS);
|
||||
}
|
||||
else
|
||||
{
|
||||
owner.addReputationScore(Config.TAKE_FORT_POINTS, true);
|
||||
owner.addReputationScore(Config.TAKE_FORT_POINTS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -392,7 +392,7 @@ public class SkillCaster implements Runnable
|
||||
player.sendPacket(SystemMessageId.THE_CLAN_REPUTATION_IS_TOO_LOW);
|
||||
return false;
|
||||
}
|
||||
clan.takeReputationScore(_skill.getClanRepConsume(), true);
|
||||
clan.takeReputationScore(_skill.getClanRepConsume());
|
||||
|
||||
final SystemMessage msg = new SystemMessage(SystemMessageId.S1_CLAN_REPUTATION_HAS_BEEN_CONSUMED);
|
||||
msg.addInt(_skill.getClanRepConsume());
|
||||
|
||||
@@ -339,7 +339,7 @@ public class MultiSellChoose implements IClientIncomingPacket
|
||||
{
|
||||
if (clan != null)
|
||||
{
|
||||
clan.takeReputationScore((int) totalCount, true);
|
||||
clan.takeReputationScore((int) totalCount);
|
||||
final SystemMessage smsg = new SystemMessage(SystemMessageId.S1_POINT_S_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_S_REPUTATION);
|
||||
smsg.addLong(totalCount);
|
||||
player.sendPacket(smsg);
|
||||
@@ -464,7 +464,7 @@ public class MultiSellChoose implements IClientIncomingPacket
|
||||
{
|
||||
if (clan != null)
|
||||
{
|
||||
clan.addReputationScore((int) totalCount, true);
|
||||
clan.addReputationScore((int) totalCount);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ public class RequestAcquireSkill implements IClientIncomingPacket
|
||||
}
|
||||
}
|
||||
|
||||
clan.takeReputationScore(repCost, true);
|
||||
clan.takeReputationScore(repCost);
|
||||
|
||||
final SystemMessage cr = new SystemMessage(SystemMessageId.S1_POINT_S_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_S_REPUTATION);
|
||||
cr.addInt(repCost);
|
||||
@@ -266,7 +266,7 @@ public class RequestAcquireSkill implements IClientIncomingPacket
|
||||
|
||||
if (repCost > 0)
|
||||
{
|
||||
clan.takeReputationScore(repCost, true);
|
||||
clan.takeReputationScore(repCost);
|
||||
final SystemMessage cr = new SystemMessage(SystemMessageId.S1_POINT_S_HAVE_BEEN_DEDUCTED_FROM_THE_CLAN_S_REPUTATION);
|
||||
cr.addInt(repCost);
|
||||
player.sendPacket(cr);
|
||||
|
||||
@@ -88,7 +88,7 @@ public class RequestStopPledgeWar implements IClientIncomingPacket
|
||||
}
|
||||
|
||||
// Reduce reputation.
|
||||
playerClan.takeReputationScore(500, true);
|
||||
playerClan.takeReputationScore(500);
|
||||
ClanTable.getInstance().deleteClanWars(playerClan.getId(), clan.getId());
|
||||
for (Player member : playerClan.getOnlineMembers(0))
|
||||
{
|
||||
|
||||
@@ -90,7 +90,7 @@ public class RequestExPledgeEnemyDelete implements IClientIncomingPacket
|
||||
}
|
||||
|
||||
// Reduce reputation.
|
||||
playerClan.takeReputationScore(500, true);
|
||||
playerClan.takeReputationScore(500);
|
||||
ClanTable.getInstance().deleteClanWars(playerClan.getId(), clan.getId());
|
||||
for (Player member : playerClan.getOnlineMembers(0))
|
||||
{
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RequestExPledgeDonationRequest implements IClientIncomingPacket
|
||||
{
|
||||
if (player.reduceAdena("pledge donation", 10000, null, true))
|
||||
{
|
||||
clan.addExp(player.getObjectId(), 9, true);
|
||||
clan.addExp(player.getObjectId(), 9);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -79,7 +79,7 @@ public class RequestExPledgeDonationRequest implements IClientIncomingPacket
|
||||
{
|
||||
if (player.getInventory().destroyItemByItemId("pledge donation", Inventory.LCOIN_ID, 100, player, null) != null)
|
||||
{
|
||||
clan.addExp(player.getObjectId(), 30, true);
|
||||
clan.addExp(player.getObjectId(), 30);
|
||||
player.setHonorCoins(player.getHonorCoins() + 100);
|
||||
}
|
||||
else
|
||||
@@ -99,7 +99,7 @@ public class RequestExPledgeDonationRequest implements IClientIncomingPacket
|
||||
{
|
||||
if (player.getInventory().destroyItemByItemId("pledge donation", Inventory.LCOIN_ID, 500, player, null) != null)
|
||||
{
|
||||
clan.addExp(player.getObjectId(), 150, true);
|
||||
clan.addExp(player.getObjectId(), 150);
|
||||
player.setHonorCoins(player.getHonorCoins() + 500);
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user