Browse Source

Item flags refactored

combat-2
MagicBot 8 months ago
parent
commit
eca71fa685
  1. 16
      src/engine/db/handlers/dbItemHandler.java
  2. 13
      src/engine/gameManager/LootManager.java
  3. 2
      src/engine/net/client/handlers/BuyFromNPCMsgHandler.java
  4. 46
      src/engine/objects/Item.java
  5. 1
      src/engine/objects/MobLoot.java
  6. 6
      src/engine/objects/NPC.java
  7. 7
      src/engine/powers/poweractions/SetItemFlagPowerAction.java

16
src/engine/db/handlers/dbItemHandler.java

@ -9,6 +9,7 @@
package engine.db.handlers; package engine.db.handlers;
import engine.Enum;
import engine.Enum.ItemContainerType; import engine.Enum.ItemContainerType;
import engine.Enum.ItemType; import engine.Enum.ItemType;
import engine.gameManager.DbManager; import engine.gameManager.DbManager;
@ -93,7 +94,13 @@ public class dbItemHandler extends dbHandlerBase {
} }
preparedStatement.setByte(8, (byte) toAdd.equipSlot.ordinal()); preparedStatement.setByte(8, (byte) toAdd.equipSlot.ordinal());
preparedStatement.setInt(9, toAdd.getFlags());
String flagString = "";
for (Enum.ItemFlags itemflag : toAdd.flags)
flagString += itemflag.toString() + ";";
preparedStatement.setString(9, flagString);
preparedStatement.setString(10, toAdd.name); preparedStatement.setString(10, toAdd.name);
ResultSet rs = preparedStatement.executeQuery(); ResultSet rs = preparedStatement.executeQuery();
@ -495,7 +502,12 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection(); try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) { PreparedStatement preparedStatement = connection.prepareStatement("UPDATE `obj_item` SET `item_flags`=? WHERE `UID` = ?")) {
preparedStatement.setInt(1, item.getFlags()); String flagString = "";
for (Enum.ItemFlags itemflag : item.flags)
flagString += itemflag.toString() + ";";
preparedStatement.setString(1, flagString);
preparedStatement.setLong(2, item.getObjectUUID()); preparedStatement.setLong(2, item.getObjectUUID());
return (preparedStatement.executeUpdate() > 0); return (preparedStatement.executeUpdate() > 0);

13
src/engine/gameManager/LootManager.java

@ -185,7 +185,7 @@ public enum LootManager {
if(selectedRow.pModTable != 0){ if(selectedRow.pModTable != 0){
try { try {
outItem = GeneratePrefix(mob, outItem, genTableID, genRoll, inHotzone); outItem = GeneratePrefix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.setIsID(false); outItem.flags.remove(Enum.ItemFlags.Identified);
} catch (Exception e) { } catch (Exception e) {
Logger.error("Failed to GeneratePrefix for item: " + outItem.getName()); Logger.error("Failed to GeneratePrefix for item: " + outItem.getName());
} }
@ -193,7 +193,7 @@ public enum LootManager {
if(selectedRow.sModTable != 0){ if(selectedRow.sModTable != 0){
try { try {
outItem = GenerateSuffix(mob, outItem, genTableID, genRoll, inHotzone); outItem = GenerateSuffix(mob, outItem, genTableID, genRoll, inHotzone);
outItem.setIsID(false); outItem.flags.remove(Enum.ItemFlags.Identified);
} catch (Exception e) { } catch (Exception e) {
Logger.error("Failed to GenerateSuffix for item: " + outItem.getName()); Logger.error("Failed to GenerateSuffix for item: " + outItem.getName());
} }
@ -351,7 +351,7 @@ public enum LootManager {
MobLoot ml = new MobLoot(mob, item.template, false); MobLoot ml = new MobLoot(mob, item.template, false);
if (ml != null && dropCount < 1) { if (ml != null && dropCount < 1) {
ml.setIsID(true); ml.flags.add(Enum.ItemFlags.Identified);
ml.setDurabilityCurrent((short) ((short) ml.durabilityCurrent - ThreadLocalRandom.current().nextInt(5) + 1)); ml.setDurabilityCurrent((short) ((short) ml.durabilityCurrent - ThreadLocalRandom.current().nextInt(5) + 1));
mob.charItemManager.addItemToInventory(ml); mob.charItemManager.addItemToInventory(ml);
dropCount = 1; dropCount = 1;
@ -440,13 +440,14 @@ public enum LootManager {
//determine if the winning item needs a suffix //determine if the winning item needs a suffix
if(selectedRow.sModTable != 0){ if (selectedRow.sModTable != 0) {
int suffixRoll = ThreadLocalRandom.current().nextInt(220,320 + 1); int suffixRoll = ThreadLocalRandom.current().nextInt(220, 320 + 1);
ModTableEntry suffix = ModTableEntry.rollTable(selectedRow.sModTable, suffixRoll); ModTableEntry suffix = ModTableEntry.rollTable(selectedRow.sModTable, suffixRoll);
if (suffix != null) if (suffix != null)
winnings.addPermanentEnchantment(suffix.action, 0, suffix.level, true); winnings.addPermanentEnchantment(suffix.action, 0, suffix.level, true);
} }
winnings.setIsID(true); winnings.flags.add(Enum.ItemFlags.Identified);
;
//remove gift from inventory //remove gift from inventory

2
src/engine/net/client/handlers/BuyFromNPCMsgHandler.java

@ -145,7 +145,7 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler {
//TODO CHnage this if we ever put NPc city npcs in buildings. //TODO CHnage this if we ever put NPc city npcs in buildings.
int cost = buy.template.item_value; int cost = buy.template.item_value;
if (buy.isID() || buy.isCustomValue()) if (buy.flags.contains(Enum.ItemFlags.Identified) || buy.isCustomValue())
cost = buy.getMagicValue(); cost = buy.getMagicValue();
float bargain = sourcePlayer.getBargain(); float bargain = sourcePlayer.getBargain();

46
src/engine/objects/Item.java

@ -30,6 +30,7 @@ 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.ArrayList;
import java.util.EnumSet;
import java.util.Iterator; import java.util.Iterator;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock; import java.util.concurrent.locks.ReentrantLock;
@ -44,7 +45,7 @@ public class Item extends AbstractWorldObject {
public ReentrantLock lootLock = new ReentrantLock(); public ReentrantLock lootLock = new ReentrantLock();
public int ownerID; //may be character, account, npc, mob public int ownerID; //may be character, account, npc, mob
public float drop_chance; public float drop_chance;
private int flags; //1 = isIDed public EnumSet<Enum.ItemFlags> flags; //1 = isIDed
public int numberOfItems; public int numberOfItems;
public float durabilityCurrent; public float durabilityCurrent;
public int chargesRemaining; public int chargesRemaining;
@ -148,7 +149,16 @@ public class Item extends AbstractWorldObject {
this.numberOfItems = rs.getInt("item_numberOfItems"); this.numberOfItems = rs.getInt("item_numberOfItems");
this.flags = rs.getInt("item_flags"); String flagString = rs.getString("item_flags");
for (String itemFlag : flagString.split(";"))
this.flags.add(Enum.ItemFlags.valueOf(itemFlag));
// Empty flags should default to template
if (this.flags.isEmpty())
this.flags.addAll(this.template.item_flags);
this.dateToUpgrade = rs.getLong("item_dateToUpgrade"); this.dateToUpgrade = rs.getLong("item_dateToUpgrade");
this.value = rs.getInt("item_value"); this.value = rs.getInt("item_value");
@ -244,7 +254,7 @@ public class Item extends AbstractWorldObject {
int effectsSize = item.effects.size(); int effectsSize = item.effects.size();
ArrayList<Effect> effs = null; ArrayList<Effect> effs = null;
Effect nextE = null; Effect nextE = null;
if (effectsSize > 0 && item.isID()) { if (effectsSize > 0 && item.flags.contains(ItemFlags.Identified)) {
effs = new ArrayList<>(item.effects.values()); effs = new ArrayList<>(item.effects.values());
//Don't send effects that have a token of 1 //Don't send effects that have a token of 1
@ -266,7 +276,7 @@ public class Item extends AbstractWorldObject {
if (effectsSize > 0) if (effectsSize > 0)
if (item.isID()) if (item.flags.contains(ItemFlags.Identified))
writer.putInt(36); //Magical, blue name writer.putInt(36); //Magical, blue name
else else
writer.putInt(40); //Magical, unidentified writer.putInt(40); //Magical, unidentified
@ -754,24 +764,6 @@ public class Item extends AbstractWorldObject {
return amount; return amount;
} }
public boolean isID() {
return ((this.flags & 1) > 0);
}
public void setIsID(boolean value) {
if (value)
this.flags |= 1;
else
this.flags &= ~1;
}
public void setIsComplete(boolean value) {
if (value)
this.flags |= 2;
else
this.flags &= ~2;
}
public boolean isComplete() { public boolean isComplete() {
return this.dateToUpgrade < System.currentTimeMillis() + 1000; return this.dateToUpgrade < System.currentTimeMillis() + 1000;
} }
@ -783,14 +775,6 @@ public class Item extends AbstractWorldObject {
return ret; return ret;
} }
public int getFlags() {
return this.flags;
}
public void setFlags(int value) {
this.flags = value;
}
public void addBonus(AbstractEffectModifier key, float amount) { public void addBonus(AbstractEffectModifier key, float amount) {
if (this.bonuses.containsKey(key)) if (this.bonuses.containsKey(key))
this.bonuses.put(key, (this.bonuses.get(key) + amount)); this.bonuses.put(key, (this.bonuses.get(key) + amount));
@ -1192,7 +1176,7 @@ public class Item extends AbstractWorldObject {
public int getValue() { public int getValue() {
if (this.value == 0) if (this.value == 0)
if (this.isID()) { if (this.flags.contains(ItemFlags.Identified)) {
return this.getMagicValue(); return this.getMagicValue();
} else } else
return this.template.item_value; return this.template.item_value;

1
src/engine/objects/MobLoot.java

@ -116,7 +116,6 @@ public final class MobLoot extends Item {
item.setOwner(looter); item.setOwner(looter);
item.containerType = Enum.ItemContainerType.INVENTORY; item.containerType = Enum.ItemContainerType.INVENTORY;
item.setValue(0); item.setValue(0);
item.setIsID(this.isID());
if (this.getNumOfItems() > 1) if (this.getNumOfItems() > 1)
item.setNumOfItems(this.getNumOfItems()); item.setNumOfItems(this.getNumOfItems());

6
src/engine/objects/NPC.java

@ -934,7 +934,7 @@ public class NPC extends AbstractCharacter {
} }
if (!producedItem.isRandom()) if (!producedItem.isRandom())
ml.setIsID(true); ml.flags.add(ItemFlags.Identified);
ml.loadEnchantments(); ml.loadEnchantments();
@ -957,7 +957,7 @@ public class NPC extends AbstractCharacter {
ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis()); ml.setDateToUpgrade(producedItem.getDateToUpgrade().getMillis());
ml.containerType = Enum.ItemContainerType.INVENTORY; ml.containerType = Enum.ItemContainerType.INVENTORY;
ml.setIsID(true); ml.flags.add(ItemFlags.Identified);
this.charItemManager.addItemToInventory(ml); this.charItemManager.addItemToInventory(ml);
} }
@ -1244,7 +1244,7 @@ public class NPC extends AbstractCharacter {
if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID)) if (!DbManager.NPCQueries.UPDATE_ITEM_TO_INVENTORY(targetItem.getObjectUUID(), currentID))
return false; return false;
targetItem.setIsID(true); targetItem.flags.add(ItemFlags.Identified);
this.rolling.remove(targetItem); this.rolling.remove(targetItem);
this.charItemManager.addItemToInventory(targetItem); this.charItemManager.addItemToInventory(targetItem);

7
src/engine/powers/poweractions/SetItemFlagPowerAction.java

@ -41,10 +41,13 @@ public class SetItemFlagPowerAction extends AbstractPowerAction {
return; //Send an error here? return; //Send an error here?
//until this is shown to do something else, just use it as item identify spell. //until this is shown to do something else, just use it as item identify spell.
item.setIsID(true);
item.flags.add(Enum.ItemFlags.Identified);
;
if (!DbManager.ItemQueries.UPDATE_FLAGS(item)) if (!DbManager.ItemQueries.UPDATE_FLAGS(item))
item.setIsID(false); //update failed, reset item.flags.remove(Enum.ItemFlags.Identified);
; //update failed, reset
//update inventory //update inventory
CharacterItemManager cim = source.charItemManager; CharacterItemManager cim = source.charItemManager;

Loading…
Cancel
Save