Files
Server/src/engine/powers/RunePowerEntry.java
T

79 lines
3.0 KiB
Java
Raw Normal View History

2026-07-26 19:08:44 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
2023-09-03 09:48:37 -04:00
package engine.powers;
import engine.parsers.objects.PowerGrant;
import engine.parsers.objects.RuneTemplate;
import engine.util.Hasher;
import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class RunePowerEntry {
public String name;
public int token;
public String power_type;
public int rank;
public RunePowerEntry(ResultSet rs) throws SQLException {
this.name = rs.getString("name");
this.token = rs.getInt("token");
this.power_type = rs.getString("power_type");
this.rank = rs.getInt("rank");
}
public RunePowerEntry(RuneTemplate rune, PowerGrant powerGrant) {
this.name = rune.obj_name;
this.token = Hasher.SBStringHash(powerGrant.power_type);
this.power_type = powerGrant.power_type;
this.rank = powerGrant.power_value;
}
// Guard contract powers have no client source, so ids without a rune keep their DB rows.
public static HashMap<Integer, ArrayList<RunePowerEntry>> loadAllRunePowers(HashMap<Integer, ArrayList<RunePowerEntry>> dbRunePowers) {
HashMap<Integer, ArrayList<RunePowerEntry>> runePowers = new HashMap<>();
ArrayList<RunePowerEntry> powerList;
int entryCount = 0;
int fallbackCount = 0;
for (RuneTemplate rune : RuneTemplate._runes.values()) {
if (rune.item_power_grant.isEmpty())
continue;
powerList = new ArrayList<>();
for (PowerGrant powerGrant : rune.item_power_grant)
powerList.add(new RunePowerEntry(rune, powerGrant));
runePowers.put(rune.template_id, powerList);
entryCount += powerList.size();
}
for (Map.Entry<Integer, ArrayList<RunePowerEntry>> dbEntry : dbRunePowers.entrySet()) {
if (RuneTemplate._runes.containsKey(dbEntry.getKey()))
continue;
runePowers.put(dbEntry.getKey(), dbEntry.getValue());
fallbackCount++;
}
Logger.info("Loaded " + entryCount + " rune powers from runes, " + fallbackCount + " ids from the DB; " + runePowers.size() + " ids");
return runePowers;
}
}