Files
Server/src/engine/objects/MobBaseEffects.java
T

93 lines
3.3 KiB
Java
Raw Normal View History

2026-07-26 19:08:44 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2026
// https://www.magicbane.com
2022-04-30 09:41:17 -04:00
package engine.objects;
import engine.parsers.objects.RuneTemplate;
import engine.parsers.objects.UserPowerAction;
import engine.parsers.objects.wpak.PowerActionTemplate;
import engine.server.MBServerStatics;
import engine.util.Hasher;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.concurrent.ConcurrentHashMap;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public class MobBaseEffects {
2022-04-30 09:41:17 -04:00
private static final ConcurrentHashMap<Integer, ArrayList<MobBaseEffects>> effectsByRune = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
2023-07-15 09:23:48 -04:00
private int token;
private int rank;
private int reqLvl;
2022-04-30 09:41:17 -04:00
public MobBaseEffects(int token, int rank, int reqLvl) {
this.token = token;
this.rank = rank;
this.reqLvl = reqLvl;
}
public static ArrayList<MobBaseEffects> getEffectsForRune(int runeID) {
return effectsByRune.computeIfAbsent(runeID, MobBaseEffects::loadEffectsForRune);
}
// item_user_power_action entries are {action id, [rank, reqLvl]}; the action names the effect to apply
private static ArrayList<MobBaseEffects> loadEffectsForRune(int runeID) {
ArrayList<MobBaseEffects> runeEffects = new ArrayList<>();
HashSet<String> seenEntries = new HashSet<>();
RuneTemplate rune = RuneTemplate._runes.get(runeID);
PowerActionTemplate powerAction;
String effectID;
int rank;
int reqLvl;
if (rune == null)
return runeEffects;
for (UserPowerAction userPowerAction : rune.item_user_power_action) {
rank = userPowerAction.arguments.length > 0 ? userPowerAction.arguments[0] : 0;
reqLvl = userPowerAction.arguments.length > 1 ? userPowerAction.arguments[1] : 0;
// 54 rune files repeat their whole list; the DB kept each entry once
if (!seenEntries.add(userPowerAction.power + ":" + rank + ":" + reqLvl))
continue;
powerAction = PowerActionTemplate._powerActions.get(userPowerAction.power);
if (powerAction != null && !powerAction.effect_ids.isEmpty())
effectID = powerAction.effect_ids.get(0);
else
effectID = userPowerAction.power;
runeEffects.add(new MobBaseEffects(Hasher.SBStringHash(effectID), rank, reqLvl));
}
return runeEffects;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getToken() {
return token;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getRank() {
return rank;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getReqLvl() {
return reqLvl;
}
2022-04-30 09:41:17 -04:00
}