Rename legacy PowerGrant to PowerGrantedTrains
Ends the name clash with the parser's engine.parsers.objects.PowerGrant. It no longer extends AbstractGameObject: it was never cached or sent as a game object, and the renamed class has no GameObjectType entry. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fae15889f7
commit
3c57a8bb0e
2 files changed
+14
-19
No files matched your search
@@ -0,0 +1,136 @@
|
||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
||||
// Magicbane Emulator Project © 2013 - 2026
|
||||
// https://www.magicbane.com
|
||||
|
||||
|
||||
package engine.objects;
|
||||
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
|
||||
public class PowerGrantedTrains {
|
||||
|
||||
private static ConcurrentHashMap<Integer, PowerGrantedTrains> grantedPowers = null;
|
||||
private int token;
|
||||
private ConcurrentHashMap<Integer, Short> runeGrants = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
/**
|
||||
* ResultSet Constructor
|
||||
*/
|
||||
public PowerGrantedTrains(ResultSet rs) throws SQLException {
|
||||
this.token = rs.getInt("powerToken");
|
||||
runeGrants.put(rs.getInt("runeID"), rs.getShort("grantAmount"));
|
||||
}
|
||||
|
||||
/*
|
||||
* Getters
|
||||
*/
|
||||
|
||||
public static Short getGrantedTrains(int token, PlayerCharacter pc) {
|
||||
if (pc == null)
|
||||
return (short) 0;
|
||||
|
||||
if (PowerGrantedTrains.grantedPowers == null)
|
||||
fillGrantedPowers();
|
||||
|
||||
if (PowerGrantedTrains.grantedPowers.containsKey(token)) {
|
||||
PowerGrantedTrains pg = PowerGrantedTrains.grantedPowers.get(token);
|
||||
ConcurrentHashMap<Integer, Short> runeGrants = pg.runeGrants;
|
||||
ArrayList<Integer> toks = new ArrayList<>();
|
||||
|
||||
//get race ID
|
||||
Race race = pc.race;
|
||||
if (race != null)
|
||||
toks.add(race.getRaceRuneID());
|
||||
|
||||
//get baseClass ID
|
||||
BaseClass bc = pc.baseClass;
|
||||
if (bc != null)
|
||||
toks.add(bc.getObjectUUID());
|
||||
|
||||
//get promoClass ID
|
||||
PromotionClass pcc = pc.getPromotionClass();
|
||||
if (pcc != null)
|
||||
toks.add(pcc.getObjectUUID());
|
||||
|
||||
//get promotion and base class combined ID
|
||||
if (bc != null && pcc != null)
|
||||
toks.add(((pcc.getObjectUUID() * 10) + bc.getObjectUUID()));
|
||||
|
||||
//get any other rune IDs
|
||||
ArrayList<CharacterRune> runes = pc.getRunes();
|
||||
for (CharacterRune rune : runes)
|
||||
toks.add(rune.getRuneBaseID());
|
||||
|
||||
//Add any power bonuses granted from runes up
|
||||
short amount = (short) 0;
|
||||
for (Integer tok : toks) {
|
||||
if (runeGrants.containsKey(tok))
|
||||
amount += runeGrants.get(tok);
|
||||
}
|
||||
|
||||
return amount;
|
||||
} else
|
||||
return (short) 0;
|
||||
}
|
||||
|
||||
public static void fillGrantedPowers() {
|
||||
|
||||
PowerGrantedTrains.grantedPowers = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
|
||||
|
||||
try (Connection connection = DbManager.getConnection();
|
||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_power_powergrant")) {
|
||||
|
||||
|
||||
ResultSet rs = preparedStatement.executeQuery();
|
||||
|
||||
if (PowerGrantedTrains.grantedPowers.size() > 0) {
|
||||
rs.close();
|
||||
return;
|
||||
}
|
||||
|
||||
while (rs.next()) {
|
||||
|
||||
int token = rs.getInt("powerToken");
|
||||
|
||||
PowerGrantedTrains pg;
|
||||
|
||||
if (PowerGrantedTrains.grantedPowers.containsKey(token)) {
|
||||
pg = PowerGrantedTrains.grantedPowers.get(token);
|
||||
pg.addRuneGrant(rs.getInt("runeID"), rs.getShort("grantAmount"));
|
||||
} else {
|
||||
pg = new PowerGrantedTrains(rs);
|
||||
PowerGrantedTrains.grantedPowers.put(token, pg);
|
||||
}
|
||||
}
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
Logger.error("SQL Error number: " + e.getErrorCode(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Database
|
||||
*/
|
||||
|
||||
public int getToken() {
|
||||
return this.token;
|
||||
}
|
||||
|
||||
private void addRuneGrant(int runeID, short amount) {
|
||||
this.runeGrants.put(runeID, amount);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user