Browse Source

Refactor boon handling

combat-2
MagicBot 8 months ago
parent
commit
15d2f2b9d8
  1. 51
      src/engine/db/handlers/dbBoonHandler.java
  2. 1
      src/engine/gameManager/DbManager.java
  3. 59
      src/engine/objects/Boon.java
  4. 3
      src/engine/objects/ItemBase.java
  5. 4
      src/engine/objects/ItemTemplate.java
  6. 17
      src/engine/objects/Shrine.java

51
src/engine/db/handlers/dbBoonHandler.java

@ -1,51 +0,0 @@ @@ -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;
}
}

1
src/engine/gameManager/DbManager.java

@ -69,7 +69,6 @@ public enum DbManager { @@ -69,7 +69,6 @@ public enum DbManager {
public static final dbZoneHandler ZoneQueries = new dbZoneHandler();
public static final dbRealmHandler RealmQueries = new dbRealmHandler();
public static final dbBlueprintHandler BlueprintQueries = new dbBlueprintHandler();
public static final dbBoonHandler BoonQueries = new dbBoonHandler();
public static final dbShrineHandler ShrineQueries = new dbShrineHandler();
public static final dbRunegateHandler RunegateQueries = new dbRunegateHandler();

59
src/engine/objects/Boon.java

@ -1,59 +0,0 @@ @@ -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;
}
}

3
src/engine/objects/ItemBase.java

@ -89,11 +89,8 @@ public class ItemBase { @@ -89,11 +89,8 @@ public class ItemBase {
case BUCKET:
case REALMCHARTER:
case TREASURE:
this.isConsumable = true;
break;
case OFFERING:
this.isConsumable = true;
Boon.HandleBoonListsForItemBase(uuid);
break;
}

4
src/engine/objects/ItemTemplate.java

@ -55,7 +55,7 @@ public class ItemTemplate { @@ -55,7 +55,7 @@ public class ItemTemplate {
public String item_skill_mastery_used = "";
public int item_parry_anim_id;
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 float item_weapon_wepspeed;
public float item_weapon_max_range;
@ -186,7 +186,7 @@ public class ItemTemplate { @@ -186,7 +186,7 @@ public class ItemTemplate {
JSONObject offering_entry = (JSONObject) entry;
String offering_type = ((String) offering_entry.get("offering_type")).replaceAll("-", "");
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

17
src/engine/objects/Shrine.java

@ -18,7 +18,6 @@ import org.pmw.tinylog.Logger; @@ -18,7 +18,6 @@ import org.pmw.tinylog.Logger;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
public class Shrine extends AbstractWorldObject implements Comparable<Shrine> {
@ -254,28 +253,16 @@ public class Shrine extends AbstractWorldObject implements Comparable<Shrine> { @@ -254,28 +253,16 @@ public class Shrine extends AbstractWorldObject implements Comparable<Shrine> {
if (boonItem == null)
return false;
ItemBase ib = boonItem.getItemBase();
if (ib == null)
return false;
if (!boonOwner.getCharItemManager().doesCharOwnThisItem(boonItem.getObjectUUID()))
return false;
ArrayList<Boon> boonList = Boon.GetBoonsForItemBase.get(ib.getUUID());
if (boonList == null)
return false;
for (Boon boon : boonList) {
ShrineType boonShrineType = boon.getShrineType();
for (ShrineType boonShrineType : boonItem.template.item_offering_info.keySet()) {
if (boonShrineType != shrineType)
continue;
//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;
if (!DbManager.ShrineQueries.updateFavors(this, this.favors + amount, oldAmount)) {

Loading…
Cancel
Save