forked from MagicBane/Server
Refactor boon handling
This commit is contained in:
@@ -1,51 +0,0 @@
|
|||||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
||||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
||||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
||||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
||||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
||||||
// Magicbane Emulator Project © 2013 - 2022
|
|
||||||
// www.magicbane.com
|
|
||||||
|
|
||||||
|
|
||||||
package engine.db.handlers;
|
|
||||||
|
|
||||||
import engine.gameManager.DbManager;
|
|
||||||
import engine.objects.Boon;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class dbBoonHandler extends dbHandlerBase {
|
|
||||||
|
|
||||||
public dbBoonHandler() {
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ArrayList<Boon> GET_BOON_AMOUNTS_FOR_ITEMBASE(int itemBaseUUID) {
|
|
||||||
|
|
||||||
ArrayList<Boon> boons = new ArrayList<>();
|
|
||||||
Boon thisBoon;
|
|
||||||
|
|
||||||
try (Connection connection = DbManager.getConnection();
|
|
||||||
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `static_item_boons` WHERE `itemBaseID` = ?")) {
|
|
||||||
|
|
||||||
preparedStatement.setInt(1, itemBaseUUID);
|
|
||||||
|
|
||||||
ResultSet rs = preparedStatement.executeQuery();
|
|
||||||
|
|
||||||
while (rs.next()) {
|
|
||||||
thisBoon = new Boon(rs);
|
|
||||||
boons.add(thisBoon);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
Logger.error(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return boons;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -69,7 +69,6 @@ public enum DbManager {
|
|||||||
public static final dbZoneHandler ZoneQueries = new dbZoneHandler();
|
public static final dbZoneHandler ZoneQueries = new dbZoneHandler();
|
||||||
public static final dbRealmHandler RealmQueries = new dbRealmHandler();
|
public static final dbRealmHandler RealmQueries = new dbRealmHandler();
|
||||||
public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler();
|
public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler();
|
||||||
public static final dbBoonHandler BoonQueries = new dbBoonHandler();
|
|
||||||
public static final dbShrineHandler ShrineQueries = new dbShrineHandler();
|
public static final dbShrineHandler ShrineQueries = new dbShrineHandler();
|
||||||
public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler();
|
public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler();
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +0,0 @@
|
|||||||
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
|
|
||||||
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
|
|
||||||
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
|
|
||||||
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
|
|
||||||
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
|
|
||||||
// Magicbane Emulator Project © 2013 - 2022
|
|
||||||
// www.magicbane.com
|
|
||||||
|
|
||||||
|
|
||||||
package engine.objects;
|
|
||||||
|
|
||||||
import engine.Enum.ShrineType;
|
|
||||||
import engine.gameManager.DbManager;
|
|
||||||
|
|
||||||
import java.sql.ResultSet;
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
|
|
||||||
public class Boon {
|
|
||||||
|
|
||||||
public static HashMap<Integer, ArrayList<Boon>> GetBoonsForItemBase = new HashMap<>();
|
|
||||||
private ShrineType shrineType;
|
|
||||||
private int amount;
|
|
||||||
private int itemBaseID;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* ResultSet Constructor
|
|
||||||
*/
|
|
||||||
public Boon(ResultSet rs) throws SQLException {
|
|
||||||
|
|
||||||
this.shrineType = ShrineType.valueOf(rs.getString("shrineType"));
|
|
||||||
this.itemBaseID = rs.getInt("itemBaseID");
|
|
||||||
this.amount = rs.getInt("amount");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void HandleBoonListsForItemBase(int itemBaseID) {
|
|
||||||
ArrayList<Boon> boons = null;
|
|
||||||
boons = DbManager.BoonQueries.GET_BOON_AMOUNTS_FOR_ITEMBASE(itemBaseID);
|
|
||||||
if (boons != null)
|
|
||||||
GetBoonsForItemBase.put(itemBaseID, boons);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getAmount() {
|
|
||||||
return this.amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getItemBaseID() {
|
|
||||||
return itemBaseID;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ShrineType getShrineType() {
|
|
||||||
return shrineType;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -89,11 +89,8 @@ public class ItemBase {
|
|||||||
case BUCKET:
|
case BUCKET:
|
||||||
case REALMCHARTER:
|
case REALMCHARTER:
|
||||||
case TREASURE:
|
case TREASURE:
|
||||||
this.isConsumable = true;
|
|
||||||
break;
|
|
||||||
case OFFERING:
|
case OFFERING:
|
||||||
this.isConsumable = true;
|
this.isConsumable = true;
|
||||||
Boon.HandleBoonListsForItemBase(uuid);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public class ItemTemplate {
|
|||||||
public String item_skill_mastery_used = "";
|
public String item_skill_mastery_used = "";
|
||||||
public int item_parry_anim_id;
|
public int item_parry_anim_id;
|
||||||
public float item_bulk_factor;
|
public float item_bulk_factor;
|
||||||
public HashMap<String, Integer> item_offering_info = new HashMap<>();
|
public HashMap<Enum.ShrineType, Integer> item_offering_info = new HashMap<>();
|
||||||
public int item_defense_rating;
|
public int item_defense_rating;
|
||||||
public float item_weapon_wepspeed;
|
public float item_weapon_wepspeed;
|
||||||
public float item_weapon_max_range;
|
public float item_weapon_max_range;
|
||||||
@@ -186,7 +186,7 @@ public class ItemTemplate {
|
|||||||
JSONObject offering_entry = (JSONObject) entry;
|
JSONObject offering_entry = (JSONObject) entry;
|
||||||
String offering_type = ((String) offering_entry.get("offering_type")).replaceAll("-", "");
|
String offering_type = ((String) offering_entry.get("offering_type")).replaceAll("-", "");
|
||||||
int offering_value = ((Long) offering_entry.get("offering_value")).intValue();
|
int offering_value = ((Long) offering_entry.get("offering_value")).intValue();
|
||||||
item_offering_info.put(offering_type, offering_value);
|
item_offering_info.put(Enum.ShrineType.valueOf(offering_type), offering_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fields only present for ARMOR
|
// Fields only present for ARMOR
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ import org.pmw.tinylog.Logger;
|
|||||||
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
public class Shrine extends AbstractWorldObject implements Comparable<Shrine> {
|
public class Shrine extends AbstractWorldObject implements Comparable<Shrine> {
|
||||||
@@ -254,28 +253,16 @@ public class Shrine extends AbstractWorldObject implements Comparable<Shrine> {
|
|||||||
if (boonItem == null)
|
if (boonItem == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ItemBase ib = boonItem.getItemBase();
|
|
||||||
|
|
||||||
if (ib == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!boonOwner.getCharItemManager().doesCharOwnThisItem(boonItem.getObjectUUID()))
|
if (!boonOwner.getCharItemManager().doesCharOwnThisItem(boonItem.getObjectUUID()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ArrayList<Boon> boonList = Boon.GetBoonsForItemBase.get(ib.getUUID());
|
for (ShrineType boonShrineType : boonItem.template.item_offering_info.keySet()) {
|
||||||
|
|
||||||
if (boonList == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
for (Boon boon : boonList) {
|
|
||||||
|
|
||||||
ShrineType boonShrineType = boon.getShrineType();
|
|
||||||
|
|
||||||
if (boonShrineType != shrineType)
|
if (boonShrineType != shrineType)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
//Same Shrine Type, add favors and stop loop.
|
//Same Shrine Type, add favors and stop loop.
|
||||||
int amount = boon.getAmount() * boonItem.getNumOfItems();
|
int amount = boonItem.template.item_offering_info.get(boonShrineType) * boonItem.getNumOfItems();
|
||||||
int oldAmount = this.favors;
|
int oldAmount = this.favors;
|
||||||
|
|
||||||
if (!DbManager.ShrineQueries.updateFavors(this, this.favors + amount, oldAmount)) {
|
if (!DbManager.ShrineQueries.updateFavors(this, this.favors + amount, oldAmount)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user