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 @@ @@ -9,6 +9,7 @@
package engine.db.handlers;
import engine.Enum;
import engine.Enum.ItemContainerType;
import engine.Enum.ItemType;
import engine.gameManager.DbManager;
@ -93,7 +94,13 @@ public class dbItemHandler extends dbHandlerBase { @@ -93,7 +94,13 @@ public class dbItemHandler extends dbHandlerBase {
}
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);
ResultSet rs = preparedStatement.executeQuery();
@ -495,7 +502,12 @@ public class dbItemHandler extends dbHandlerBase { @@ -495,7 +502,12 @@ public class dbItemHandler extends dbHandlerBase {
try (Connection connection = DbManager.getConnection();
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());
return (preparedStatement.executeUpdate() > 0);

13
src/engine/gameManager/LootManager.java

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

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

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

46
src/engine/objects/Item.java

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

1
src/engine/objects/MobLoot.java

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

6
src/engine/objects/NPC.java

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

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

@ -41,10 +41,13 @@ public class SetItemFlagPowerAction extends AbstractPowerAction { @@ -41,10 +41,13 @@ public class SetItemFlagPowerAction extends AbstractPowerAction {
return; //Send an error here?
//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))
item.setIsID(false); //update failed, reset
item.flags.remove(Enum.ItemFlags.Identified);
; //update failed, reset
//update inventory
CharacterItemManager cim = source.charItemManager;

Loading…
Cancel
Save