Browse Source

Start mobequip refactor

combat-2
MagicBot 8 months ago
parent
commit
0590ae64e7
  1. 1
      src/engine/Enum.java
  2. 4
      src/engine/db/handlers/dbContractHandler.java
  3. 4
      src/engine/devcmd/cmds/PrintEffectsCmd.java
  4. 4
      src/engine/devcmd/cmds/PrintEquipCmd.java
  5. 4
      src/engine/devcmd/cmds/PrintRunesCmd.java
  6. 2
      src/engine/devcmd/cmds/PrintStatsCmd.java
  7. 2
      src/engine/devcmd/cmds/SimulateBootyCmd.java
  8. 2
      src/engine/gameManager/LootManager.java
  9. 8
      src/engine/gameManager/NPCManager.java
  10. 2
      src/engine/net/client/ClientMessagePump.java
  11. 6
      src/engine/net/client/handlers/BuyFromNPCMsgHandler.java
  12. 6
      src/engine/net/client/msg/BuyFromNPCWindowMsg.java
  13. 30
      src/engine/net/client/msg/LootMsg.java
  14. 8
      src/engine/objects/AbstractCharacter.java
  15. 4
      src/engine/objects/CharacterItemManager.java
  16. 4
      src/engine/objects/Contract.java
  17. 80
      src/engine/objects/Mob.java
  18. 15
      src/engine/objects/MobBase.java
  19. 320
      src/engine/objects/MobEquipment.java
  20. 8
      src/engine/objects/NPC.java

1
src/engine/Enum.java

@ -1648,7 +1648,6 @@ public class Enum { @@ -1648,7 +1648,6 @@ public class Enum {
Mine,
Mob,
MobBase,
MobEquipment,
MobLoot,
MobType,
NPC,

4
src/engine/db/handlers/dbContractHandler.java

@ -13,7 +13,7 @@ import engine.Enum; @@ -13,7 +13,7 @@ import engine.Enum;
import engine.gameManager.DbManager;
import engine.objects.Contract;
import engine.objects.ItemTemplate;
import engine.objects.MobEquipment;
import engine.objects.Item;
import org.pmw.tinylog.Logger;
import java.sql.Connection;
@ -65,7 +65,7 @@ public class dbContractHandler extends dbHandlerBase { @@ -65,7 +65,7 @@ public class dbContractHandler extends dbHandlerBase {
int templateID = rs.getInt("itembaseID");
MobEquipment me = new MobEquipment(ItemTemplate.templates.get(templateID), Enum.EquipSlotType.NONE, 0);
Item me = new Item(ItemTemplate.templates.get(templateID), Enum.EquipSlotType.NONE, 0);
contract.getSellInventory().add(me);
//handle magic effects

4
src/engine/devcmd/cmds/PrintEffectsCmd.java

@ -25,9 +25,9 @@ public class PrintEffectsCmd extends AbstractDevCmd { @@ -25,9 +25,9 @@ public class PrintEffectsCmd extends AbstractDevCmd {
// super("printstats", MBServerStatics.ACCESS_LEVEL_ADMIN);
}
public static ItemBase getWeaponBase(int slot, HashMap<Integer, MobEquipment> equip) {
public static ItemBase getWeaponBase(int slot, HashMap<Integer, Item> equip) {
if (equip.containsKey(slot)) {
MobEquipment item = equip.get(slot);
Item item = equip.get(slot);
if (item != null && item.getItemBase() != null) {
return item.getItemBase();
}

4
src/engine/devcmd/cmds/PrintEquipCmd.java

@ -65,7 +65,7 @@ public class PrintEquipCmd extends AbstractDevCmd { @@ -65,7 +65,7 @@ public class PrintEquipCmd extends AbstractDevCmd {
Mob tarMob = (Mob) tar;
throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')');
for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) {
MobEquipment equip = tarMob.getEquip().get(slot);
Item equip = tarMob.getEquip().get(slot);
throwbackInfo(pc, equip.templateID + " : " + equip.template.item_base_name + ", slot: " + slot);
}
return;
@ -75,7 +75,7 @@ public class PrintEquipCmd extends AbstractDevCmd { @@ -75,7 +75,7 @@ public class PrintEquipCmd extends AbstractDevCmd {
NPC tarMob = (NPC) tar;
throwbackInfo(pc, "Equip for " + type + ' ' + name + " (" + tar.getObjectUUID() + ')');
for (Enum.EquipSlotType slot : tarMob.getEquip().keySet()) {
MobEquipment equip = tarMob.getEquip().get(slot);
Item equip = tarMob.getEquip().get(slot);
throwbackInfo(pc, equip.templateID + " : " + equip.template.item_base_name + ", slot: " + slot);
}
return;

4
src/engine/devcmd/cmds/PrintRunesCmd.java

@ -25,9 +25,9 @@ public class PrintRunesCmd extends AbstractDevCmd { @@ -25,9 +25,9 @@ public class PrintRunesCmd extends AbstractDevCmd {
// super("printstats", MBServerStatics.ACCESS_LEVEL_ADMIN);
}
public static ItemBase getWeaponBase(int slot, HashMap<Integer, MobEquipment> equip) {
public static ItemBase getWeaponBase(int slot, HashMap<Integer, Item> equip) {
if (equip.containsKey(slot)) {
MobEquipment item = equip.get(slot);
Item item = equip.get(slot);
if (item != null && item.getItemBase() != null) {
return item.getItemBase();
}

2
src/engine/devcmd/cmds/PrintStatsCmd.java

@ -86,7 +86,7 @@ public class PrintStatsCmd extends AbstractDevCmd { @@ -86,7 +86,7 @@ public class PrintStatsCmd extends AbstractDevCmd {
out += "Defense: " + tar.getDefenseRating() + newline;
//get weapons
HashMap<Enum.EquipSlotType, MobEquipment> equip = tar.getEquip();
HashMap<Enum.EquipSlotType, Item> equip = tar.getEquip();
if(equip != null){
if (equip.get(2) != null && !ItemTemplate.isShield(equip.get(2).template)) {

2
src/engine/devcmd/cmds/SimulateBootyCmd.java

@ -88,7 +88,7 @@ public class SimulateBootyCmd extends AbstractDevCmd { @@ -88,7 +88,7 @@ public class SimulateBootyCmd extends AbstractDevCmd {
failures++;
}
if (mob.getEquip() != null) {
for (MobEquipment me : mob.getEquip().values()) {
for (Item me : mob.getEquip().values()) {
if (me.getDropChance() == 0)
continue;

2
src/engine/gameManager/LootManager.java

@ -337,7 +337,7 @@ public enum LootManager { @@ -337,7 +337,7 @@ public enum LootManager {
//do equipment here
int dropCount = 0;
if (mob.getEquip() != null)
for (MobEquipment me : mob.getEquip().values()) {
for (Item me : mob.getEquip().values()) {
if (me.getDropChance() == 0)
continue;

8
src/engine/gameManager/NPCManager.java

@ -300,7 +300,7 @@ public enum NPCManager { @@ -300,7 +300,7 @@ public enum NPCManager {
}else{
if (guard.equip.containsKey(Enum.EquipSlotType.RHELD)) {
//has main hand weapon
MobEquipment weapon = guard.equip.get(Enum.EquipSlotType.RHELD);
Item weapon = guard.equip.get(Enum.EquipSlotType.RHELD);
if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength))
primaryStat = guard.getStatStrCurrent();
@ -313,7 +313,7 @@ public enum NPCManager { @@ -313,7 +313,7 @@ public enum NPCManager {
guard.rangeHandOne = weapon.template.item_weapon_max_range;
} else if (guard.equip.containsKey(Enum.EquipSlotType.LHELD) && !ItemTemplate.isShield(guard.equip.get(Enum.EquipSlotType.LHELD).template)) {
//has off hand weapon
MobEquipment weapon = guard.equip.get(Enum.EquipSlotType.LHELD);
Item weapon = guard.equip.get(Enum.EquipSlotType.LHELD);
if (weapon.template.item_primary_attr.equals(Enum.AttributeType.Strength))
primaryStat = guard.getStatStrCurrent();
else
@ -338,7 +338,7 @@ public enum NPCManager { @@ -338,7 +338,7 @@ public enum NPCManager {
dexterity = 1;
int baseDef = guard.mobBase.getDefenseRating();
int armorDefense = 0;
for(MobEquipment equipped : guard.equip.values())
for(Item equipped : guard.equip.values())
if (equipped.template.item_type.equals(Enum.ItemType.ARMOR) || ItemTemplate.isShield(equipped.template))
armorDefense += equipped.template.item_defense_rating;
guard.defenseRating = dexterity + baseDef + armorDefense;
@ -427,7 +427,7 @@ public enum NPCManager { @@ -427,7 +427,7 @@ public enum NPCManager {
if (mob.equip == null)
return;
for (MobEquipment equipped : mob.equip.values()) {
for (Item equipped : mob.equip.values()) {
if (equipped.template.item_type.equals(Enum.ItemType.ARMOR)) {
mob.resists.setResist(Enum.SourceType.SLASHING, mob.resists.getResist(Enum.SourceType.SLASHING, 0) + equipped.template.combat_attack_resist.get("SLASHING"));
mob.resists.setResist(Enum.SourceType.CRUSHING, mob.resists.getResist(Enum.SourceType.CRUSHING, 0) + equipped.template.combat_attack_resist.get("CRUSHING"));

2
src/engine/net/client/ClientMessagePump.java

@ -699,7 +699,7 @@ public class ClientMessagePump implements NetMsgHandler { @@ -699,7 +699,7 @@ public class ClientMessagePump implements NetMsgHandler {
if (item != null && item.getObjectType() == GameObjectType.MobLoot) {
for (MobEquipment equip : mobTarget.getEquip().values()) {
for (Item equip : mobTarget.getEquip().values()) {
TransferItemFromEquipToInventoryMsg back = new TransferItemFromEquipToInventoryMsg(mobTarget, equip.slot);
DispatchMessage.dispatchMsgToInterestArea(mobTarget, back, DispatchChannel.SECONDARY, MBServerStatics.CHARACTER_LOAD_RANGE, false, false);

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

@ -63,14 +63,14 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler { @@ -63,14 +63,14 @@ public class BuyFromNPCMsgHandler extends AbstractClientMsgHandler {
Item buy = null;
if (buyFromNPCMsg.getItemType() == Enum.GameObjectType.MobEquipment.ordinal()) {
if (buyFromNPCMsg.getItemType() == Enum.GameObjectType.Item.ordinal()) {
ArrayList<MobEquipment> sellInventory = npc.getContract().getSellInventory();
ArrayList<Item> sellInventory = npc.getContract().getSellInventory();
if (sellInventory == null)
return true;
for (MobEquipment me : sellInventory) {
for (Item me : sellInventory) {
if (me.getObjectUUID() == buyFromNPCMsg.getItemID()) {

6
src/engine/net/client/msg/BuyFromNPCWindowMsg.java

@ -94,7 +94,7 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { @@ -94,7 +94,7 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg {
NPC npc = NPC.getFromCache(npcID);
CharacterItemManager man = null;
ArrayList<Item> inventory = null;
ArrayList<MobEquipment> sellInventory = null;
ArrayList<Item> sellInventory = null;
if (npc != null) {
man = npc.getCharItemManager();
@ -147,9 +147,9 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg { @@ -147,9 +147,9 @@ public class BuyFromNPCWindowMsg extends ClientNetMsg {
//add generic sell inventory from contract
if (sellInventory != null) {
for (MobEquipment mobEquipment : sellInventory) {
for (Item Item : sellInventory) {
try {
MobEquipment.serializeForVendor(mobEquipment, writer, sellPercent);
Item.serializeForVendor(Item, writer, sellPercent);
} catch (SerializationException se) {
continue;
}

30
src/engine/net/client/msg/LootMsg.java

@ -16,7 +16,7 @@ import engine.net.ByteBufferReader; @@ -16,7 +16,7 @@ import engine.net.ByteBufferReader;
import engine.net.ByteBufferWriter;
import engine.net.client.Protocol;
import engine.objects.Item;
import engine.objects.MobEquipment;
import engine.objects.Item;
public class LootMsg extends ClientNetMsg {
@ -37,7 +37,7 @@ public class LootMsg extends ClientNetMsg { @@ -37,7 +37,7 @@ public class LootMsg extends ClientNetMsg {
private int unknown07;
private int unknown08;
private MobEquipment mobEquipment = null;
private Item Item = null;
/**
* This is the general purpose constructor.
@ -60,28 +60,6 @@ public class LootMsg extends ClientNetMsg { @@ -60,28 +60,6 @@ public class LootMsg extends ClientNetMsg {
this.unknown08 = 0;
}
//for MobEquipment
public LootMsg(int sourceType, int sourceID, int targetType, int targetID, MobEquipment mobEquipment) {
super(Protocol.MOVEOBJECTTOCONTAINER);
this.sourceType1 = sourceType;
this.sourceID1 = sourceID;
this.targetType = targetType;
this.targetID = targetID;
this.sourceType2 = sourceType;
this.sourceID2 = sourceID;
this.item = null;
this.mobEquipment = mobEquipment;
this.unknown01 = 0;
this.unknown02 = 0;
this.unknown03 = 0;
this.unknown04 = 0;
this.unknown05 = 0;
this.unknown07 = 0;
this.unknown08 = 0;
}
/**
* This constructor is used by NetMsgFactory. It attempts to deserialize the
* ByteBuffer into a message. If a BufferUnderflow occurs (based on reading
@ -100,9 +78,9 @@ public class LootMsg extends ClientNetMsg { @@ -100,9 +78,9 @@ public class LootMsg extends ClientNetMsg {
if (this.item != null)
Item.serializeForClientMsgWithoutSlot(this.item, writer);
else if (this.mobEquipment != null)
else if (this.Item != null)
try {
MobEquipment._serializeForClientMsg(this.mobEquipment, writer, false);
Item._serializeForClientMsg(this.Item, writer, false);
} catch (SerializationException e) {
// TODO Auto-generated catch block
e.printStackTrace();

8
src/engine/objects/AbstractCharacter.java

@ -990,10 +990,10 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -990,10 +990,10 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
return 300;
}
float range = 8;
if (((Mob) this).getEquip().get(1) != null) {
range = ((Mob) this).getEquip().get(1).template.item_weapon_max_range;
} else if (((Mob) this).getEquip().get(2) != null) {
range = ((Mob) this).getEquip().get(2).template.item_weapon_max_range;
if (( this).charItemManager.equipped.get(EquipSlotType.RHELD) != null) {
range = ((Mob) this).charItemManager.equipped.get(EquipSlotType.RHELD).template.item_weapon_max_range;
} else if (((Mob) this).charItemManager.equipped.get(EquipSlotType.LHELD) != null) {
range = ((Mob) this).charItemManager.equipped.get(EquipSlotType.LHELD).template.item_weapon_max_range;
}
// TODO Is this clamp from live?

4
src/engine/objects/CharacterItemManager.java

@ -43,7 +43,7 @@ public class CharacterItemManager { @@ -43,7 +43,7 @@ public class CharacterItemManager {
private final ConcurrentHashMap<Integer, Integer> itemIDtoType = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
// Mapping of all items equipped in this Manager
// Key = Item Slot
public final ConcurrentHashMap<Enum.EquipSlotType, Item> equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
public ConcurrentHashMap<Enum.EquipSlotType, Item> equipped = new ConcurrentHashMap<>(MBServerStatics.CHM_INIT_CAP, MBServerStatics.CHM_LOAD, MBServerStatics.CHM_THREAD_LOW);
private final HashSet<Item> inventory = new HashSet<>();
private final HashSet<Item> bank = new HashSet<>();
private final HashSet<Item> vault = new HashSet<>();
@ -1203,7 +1203,7 @@ public class CharacterItemManager { @@ -1203,7 +1203,7 @@ public class CharacterItemManager {
return true;
}
//Used for buying MobEquipment from NPC
//Used for buying Item from NPC
//Handles the gold transfer aspect
// This removes ingame item from inventory for loot.

4
src/engine/objects/Contract.java

@ -35,7 +35,7 @@ public class Contract extends AbstractGameObject { @@ -35,7 +35,7 @@ public class Contract extends AbstractGameObject {
private ArrayList<Integer> npcModTypeTable = new ArrayList<>();
private ArrayList<Integer> npcModSuffixTable = new ArrayList<>();
private ArrayList<Byte> itemModTable = new ArrayList<>();
private ArrayList<MobEquipment> sellInventory = new ArrayList<>();
private ArrayList<Item> sellInventory = new ArrayList<>();
private EnumBitSet<Enum.BuildingGroup> allowedBuildings;
private ArrayList<Integer> buyItemType = new ArrayList<>();
private ArrayList<Integer> buySkillToken = new ArrayList<>();
@ -197,7 +197,7 @@ public class Contract extends AbstractGameObject { @@ -197,7 +197,7 @@ public class Contract extends AbstractGameObject {
return itemModTable;
}
public ArrayList<MobEquipment> getSellInventory() {
public ArrayList<Item> getSellInventory() {
return this.sellInventory;
}

80
src/engine/objects/Mob.java

@ -74,7 +74,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -74,7 +74,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
private int currentID;
private long lastAttackTime = 0;
private int lastMobPowerToken = 0;
public HashMap<Enum.EquipSlotType, MobEquipment> equip = null;
private DeferredPowerJob weaponPower;
private DateTime upgradeDateTime = null;
private boolean lootSync = false;
@ -257,12 +256,12 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -257,12 +256,12 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
// get a copy of the equipped items.
if (mob.equip != null) {
if (!mob.charItemManager.equipped.isEmpty()) {
writer.putInt(mob.equip.size());
writer.putInt(mob.charItemManager.equipped.size());
for (MobEquipment me : mob.equip.values())
MobEquipment.serializeForClientMsg(me, writer);
for (Item me : mob.charItemManager.equipped.values())
Item._serializeForClientMsg(me, writer);
} else
writer.putInt(0);
@ -934,7 +933,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -934,7 +933,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
playerAgroMap.clear();
if (!this.isPlayerGuard() && this.equip != null)
if (!this.isPlayerGuard() && this.charItemManager.equipped != null)
LootManager.GenerateEquipmentDrop(this);
}
@ -1122,7 +1121,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1122,7 +1121,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
public void calculateAtrDefenseDamage() {
if (this.charItemManager == null || this.equip == null) {
if (this.charItemManager == null || this.charItemManager.equipped == null) {
Logger.error("Player " + currentID + " missing skills or equipment");
defaultAtrAndDamage(true);
defaultAtrAndDamage(false);
@ -1141,16 +1140,16 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1141,16 +1140,16 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
this.rangeHandTwo = 6.5f;
this.speedHandTwo = 20;
if (this.equip.get(EquipSlotType.RHELD) != null)
calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), true); //has mainhand weapon to calculate
if (this.charItemManager.equipped.get(EquipSlotType.RHELD) != null)
calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), true); //has mainhand weapon to calculate
if (this.equip.get(EquipSlotType.LHELD) != null && !ItemTemplate.isShield(this.equip.get(EquipSlotType.LHELD).template))
calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), false); //has offhand weapon to calculate
if (this.charItemManager.equipped.get(EquipSlotType.LHELD) != null && !ItemTemplate.isShield(this.charItemManager.equipped.get(EquipSlotType.LHELD).template))
calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false); //has offhand weapon to calculate
try {
calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.RHELD), true);
calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.RHELD), true);
} catch (Exception e) {
this.atrHandOne = (short) this.mobBase.getAttackRating();
@ -1162,7 +1161,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1162,7 +1161,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
}
try {
calculateAtrDamageForWeapon(this.equip.get(EquipSlotType.LHELD), false);
calculateAtrDamageForWeapon(this.charItemManager.equipped.get(EquipSlotType.LHELD), false);
} catch (Exception e) {
@ -1176,14 +1175,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1176,14 +1175,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
try {
float defense = this.mobBase.getDefenseRating();
defense += getShieldDefense(equip.get(EquipSlotType.LHELD));
defense += getArmorDefense(equip.get(EquipSlotType.HELM));
defense += getArmorDefense(equip.get(EquipSlotType.CHEST));
defense += getArmorDefense(equip.get(EquipSlotType.UPARM));
defense += getArmorDefense(equip.get(EquipSlotType.HANDS));
defense += getArmorDefense(equip.get(EquipSlotType.LEGS));
defense += getArmorDefense(equip.get(EquipSlotType.FEET));
defense += getWeaponDefense(equip);
defense += getShieldDefense(charItemManager.equipped.get(EquipSlotType.LHELD));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HELM));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.CHEST));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.UPARM));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.HANDS));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.LEGS));
defense += getArmorDefense(charItemManager.equipped.get(EquipSlotType.FEET));
defense += getWeaponDefense(charItemManager.equipped);
// TODO add error log here
if (this.bonuses != null) {
@ -1217,9 +1216,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1217,9 +1216,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
// calculate defense for equipment
}
private float getWeaponDefense(HashMap<Enum.EquipSlotType, MobEquipment> equipped) {
private float getWeaponDefense(ConcurrentHashMap<Enum.EquipSlotType, Item> equipped) {
MobEquipment weapon = equipped.get(EquipSlotType.RHELD);
Item weapon = equipped.get(EquipSlotType.RHELD);
ItemBase wb = null;
CharacterSkill skill, mastery;
float val = 0;
@ -1256,7 +1255,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1256,7 +1255,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
return val;
}
private float getShieldDefense(MobEquipment shield) {
private float getShieldDefense(Item shield) {
if (shield == null)
return 0;
@ -1285,7 +1284,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1285,7 +1284,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
return (def * (1 + ((int) skillMod / 100f)));
}
private float getArmorDefense(MobEquipment armor) {
private float getArmorDefense(Item armor) {
if (armor == null)
return 0;
@ -1313,7 +1312,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1313,7 +1312,7 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
return (def * (1 + ((int) armorSkill.getModifiedAmount() / 50f)));
}
private void calculateAtrDamageForWeapon(MobEquipment weapon, boolean mainHand) {
private void calculateAtrDamageForWeapon(Item weapon, boolean mainHand) {
int baseStrength = 0;
@ -1501,13 +1500,13 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1501,13 +1500,13 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
public ItemBase getWeaponItemBase(boolean mainHand) {
if (this.equipmentSetID != 0)
if (equip != null) {
MobEquipment me;
if (charItemManager.equipped != null) {
Item me;
if (mainHand)
me = equip.get(1); //mainHand
me = charItemManager.equipped.get(EquipSlotType.RHELD); //mainHand
else
me = equip.get(2); //offHand
me = charItemManager.equipped.get(EquipSlotType.LHELD); //offHand
if (me != null) {
@ -1521,14 +1520,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1521,14 +1520,14 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
MobBase mb = this.mobBase;
if (mb != null)
if (equip != null) {
if (this.charItemManager.equipped.isEmpty() == false) {
MobEquipment me;
Item me;
if (mainHand)
me = equip.get(1); //mainHand
me = this.charItemManager.equipped.get(EquipSlotType.RHELD); //mainHand
else
me = equip.get(2); //offHand
me = this.charItemManager.equipped.get(EquipSlotType.LHELD); //offHand
if (me != null)
return me.getItemBase();
@ -1670,14 +1669,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1670,14 +1669,9 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
this.loadInventory();
if (this.equipmentSetID != 0)
this.equip = MobBase.loadEquipmentSet(this.equipmentSetID);
this.charItemManager.equipped = MobBase.loadEquipmentSet(this.equipmentSetID);
else
this.equip = new HashMap<>();
if (this.equip == null) {
Logger.error("Null equipset returned for uuid " + currentID);
this.equip = new HashMap<>(0);
}
this.charItemManager.equipped = new ConcurrentHashMap<>();
// Combine mobbase and mob aggro arrays into one bitvector
//skip for pets
@ -1835,10 +1829,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed { @@ -1835,10 +1829,6 @@ public class Mob extends AbstractIntelligenceAgent implements Delayed {
this.lootSync = lootSync;
}
public HashMap<Enum.EquipSlotType, MobEquipment> getEquip() {
return equip;
}
public String getNameOverride() {
return firstName + " " + lastName;
}

15
src/engine/objects/MobBase.java

@ -20,6 +20,7 @@ import java.sql.ResultSet; @@ -20,6 +20,7 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
public class MobBase extends AbstractGameObject {
@ -110,10 +111,10 @@ public class MobBase extends AbstractGameObject { @@ -110,10 +111,10 @@ public class MobBase extends AbstractGameObject {
}
public static HashMap<Enum.EquipSlotType, MobEquipment> loadEquipmentSet(int equipmentSetID) {
public static ConcurrentHashMap<Enum.EquipSlotType, Item> loadEquipmentSet(int equipmentSetID) {
ArrayList<BootySetEntry> equipList;
HashMap<Enum.EquipSlotType, MobEquipment> equip = new HashMap<>();
ConcurrentHashMap<Enum.EquipSlotType, Item> equip = new ConcurrentHashMap<>();
if (equipmentSetID == 0)
return equip;
@ -125,14 +126,10 @@ public class MobBase extends AbstractGameObject { @@ -125,14 +126,10 @@ public class MobBase extends AbstractGameObject {
for (BootySetEntry equipmentSetEntry : equipList) {
MobEquipment mobEquipment = new MobEquipment(equipmentSetEntry.templateID, equipmentSetEntry.dropChance);
ItemBase itemBase = mobEquipment.getItemBase();
Item item = new Item(equipmentSetEntry.templateID);
item.drop_chance = equipmentSetEntry.dropChance;
// if (itemBase.getType().equals(Enum.ItemType.WEAPON))
// if (mobEquipment.getSlot() == 1 && itemBase.getEquipFlag() == 2)
// mobEquipment.setSlot(2);
equip.put(mobEquipment.slot, mobEquipment);
equip.put(item.slot, Item);
}

320
src/engine/objects/MobEquipment.java

@ -1,320 +0,0 @@ @@ -1,320 +0,0 @@
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects;
import engine.Enum;
import engine.exception.SerializationException;
import engine.gameManager.PowersManager;
import engine.net.ByteBufferWriter;
import engine.powers.EffectsBase;
import engine.powers.poweractions.AbstractPowerAction;
import java.util.concurrent.atomic.AtomicInteger;
public class MobEquipment extends AbstractGameObject {
private static AtomicInteger equipCounter = new AtomicInteger(0);
private final ItemBase itemBase;
public Enum.EquipSlotType slot;
private int parentID;
//effects
private boolean enchanted;
private boolean isID = false;
private AbstractPowerAction prefix;
private AbstractPowerAction suffix;
private int pValue;
private int sValue;
private int magicValue;
private float dropChance = 0;
public int templateID;
public ItemTemplate template;
/**
* No Id Constructor
*/
public MobEquipment(ItemTemplate template, Enum.EquipSlotType slot, int parentID) {
super(MobEquipment.getNewID());
this.templateID = template.template_id;
this.template = ItemTemplate.templates.get(templateID);
this.itemBase = ItemBase.getItemBase(templateID);
this.slot = slot;
this.parentID = parentID;
this.enchanted = false;
this.prefix = null;
this.suffix = null;
this.pValue = 0;
this.sValue = 0;
setMagicValue();
}
public MobEquipment(int templateID, float dropChance) {
super(MobEquipment.getNewID());
this.itemBase = ItemBase.getItemBase(templateID);
this.templateID = templateID;
this.template = ItemTemplate.templates.get(this.templateID);
Enum.EquipSlotType equipSlot = template.item_eq_slots_or.iterator().next();
this.slot = equipSlot;
this.dropChance = dropChance;
this.parentID = 0;
setMagicValue();
}
public static int getNewID() {
return MobEquipment.equipCounter.incrementAndGet();
}
public static void serializeForVendor(MobEquipment mobEquipment, ByteBufferWriter writer, float percent) throws SerializationException {
_serializeForClientMsg(mobEquipment, writer, false);
writer.putInt(mobEquipment.magicValue);
writer.putInt(mobEquipment.magicValue);
}
public static void serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer) throws SerializationException {
_serializeForClientMsg(mobEquipment, writer, true);
}
public static void _serializeForClientMsg(MobEquipment mobEquipment, ByteBufferWriter writer, boolean useSlot) throws SerializationException {
if (useSlot)
writer.putInt(mobEquipment.slot.ordinal());
writer.putInt(0); // Pad
writer.putInt(mobEquipment.templateID);
writer.putInt(mobEquipment.getObjectType().ordinal());
writer.putInt(mobEquipment.getObjectUUID());
// Unknown statics
for (int i = 0; i < 3; i++) {
writer.putInt(0); // Pad
}
for (int i = 0; i < 4; i++) {
writer.putInt(0x3F800000); // Static
}
for (int i = 0; i < 5; i++) {
writer.putInt(0); // Pad
}
for (int i = 0; i < 2; i++) {
writer.putInt(0xFFFFFFFF); // Static
}
writer.putInt(0);
writer.put((byte) 1); // End Datablock byte
writer.putInt(0); // Unknown. pad?
writer.put((byte) 1); // End Datablock byte
writer.putFloat(mobEquipment.template.item_health_full);
writer.putFloat(mobEquipment.template.item_health_full);
writer.put((byte) 1); // End Datablock byte
writer.putInt(0); // Pad
writer.putInt(0); // Pad
writer.putInt(mobEquipment.template.item_value);
writer.putInt(mobEquipment.magicValue);
serializeEffects(mobEquipment, writer);
writer.putInt(0x00000000);
//name color, think mobEquipment is where mobEquipment goes
if (mobEquipment.enchanted)
if (mobEquipment.isID)
writer.putInt(36);
else
writer.putInt(40);
else
writer.putInt(4);
writer.putInt(0);
writer.putInt(0); // Pad
writer.putInt(1);
writer.putShort((short) 0);
writer.put((byte) 0);
}
public static void serializeEffects(MobEquipment mobEquipment, ByteBufferWriter writer) {
//skip sending effects if not IDed
if (!mobEquipment.isID) {
writer.putInt(0);
return;
}
//handle effect count
int cnt = 0;
EffectsBase pre = null;
EffectsBase suf = null;
if (mobEquipment.prefix != null) {
pre = PowersManager.getEffectByIDString(mobEquipment.prefix.getIDString());
if (pre != null)
cnt++;
}
if (mobEquipment.suffix != null) {
suf = PowersManager.getEffectByIDString(mobEquipment.suffix.getIDString());
if (suf != null)
cnt++;
}
writer.putInt(cnt);
//serialize prefix
if (pre != null)
serializeEffect(mobEquipment, writer, pre, mobEquipment.pValue);
//serialize suffix
if (suf != null)
serializeEffect(mobEquipment, writer, suf, mobEquipment.sValue);
}
public static void serializeEffect(MobEquipment mobEquipment, ByteBufferWriter writer, EffectsBase eb, int rank) {
String name;
if (eb.isPrefix()) {
if (mobEquipment.itemBase == null)
name = eb.getName();
else
name = eb.getName() + ' ' + ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name;
} else if (eb.isSuffix()) {
if (mobEquipment.itemBase == null)
name = eb.getName();
else
name = ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name + ' ' + eb.getName();
} else {
if (mobEquipment.itemBase == null)
name = "";
else
name = ItemTemplate.templates.get(mobEquipment.itemBase.getUUID()).item_base_name;
}
writer.putInt(eb.getToken());
writer.putInt(rank);
writer.putInt(1);
writer.put((byte) 1);
writer.putInt(mobEquipment.getObjectType().ordinal());
writer.putInt(mobEquipment.getObjectUUID());
writer.putString(name);
writer.putFloat(-1000f);
}
public ItemBase getItemBase() {
return itemBase;
}
public final void setMagicValue() {
float value = 1;
if (itemBase != null)
value = template.item_value;
if (this.prefix != null) {
if (this.prefix.getEffectsBase() != null)
value += this.prefix.getEffectsBase().getValue();
if (this.prefix.getEffectsBase2() != null)
value += this.prefix.getEffectsBase2().getValue();
}
if (this.suffix != null) {
if (this.suffix.getEffectsBase() != null)
value += this.suffix.getEffectsBase().getValue();
if (this.suffix.getEffectsBase2() != null)
value += this.suffix.getEffectsBase2().getValue();
}
if (itemBase != null)
for (String effectID : this.template.item_user_power_action.keySet()) {
AbstractPowerAction apa = PowersManager.getPowerActionByIDString(effectID);
if (apa.getEffectsBase() != null)
if (apa.getEffectsBase().getValue() > 0)
value += apa.getEffectsBase().getValue();
if (apa.getEffectsBase2() != null)
value += apa.getEffectsBase2().getValue();
}
this.magicValue = (int) value;
}
public int getMagicValue() {
if (!this.isID) {
return template.item_value;
}
return this.magicValue;
}
public void setPrefix(String pIDString, int pValue) {
AbstractPowerAction apa = PowersManager.getPowerActionByIDString(pIDString);
if (apa != null) {
this.prefix = apa;
this.pValue = pValue;
} else
this.prefix = null;
this.enchanted = this.prefix != null || this.suffix != null;
setMagicValue();
}
public void setSuffix(String sIDString, int sValue) {
AbstractPowerAction apa = PowersManager.getPowerActionByIDString(sIDString);
if (apa != null) {
this.suffix = apa;
this.sValue = sValue;
} else
this.suffix = null;
this.enchanted = this.prefix != null || this.suffix != null;
setMagicValue();
}
public void setIsID(boolean value) {
this.isID = value;
}
public boolean isID() {
return this.isID;
}
public void transferEnchants(Item item) {
if (this.prefix != null) {
String IDString = this.prefix.getIDString();
item.addPermanentEnchantment(IDString, this.pValue);
}
if (this.suffix != null) {
String IDString = this.suffix.getIDString();
item.addPermanentEnchantment(IDString, this.sValue);
}
if (this.isID)
item.setIsID(true);
}
/*
* Database
*/
@Override
public void updateDatabase() {
}
public float getDropChance() {
return dropChance;
}
public void setDropChance(float dropChance) {
this.dropChance = dropChance;
}
}

8
src/engine/objects/NPC.java

@ -52,7 +52,7 @@ public class NPC extends AbstractCharacter { @@ -52,7 +52,7 @@ public class NPC extends AbstractCharacter {
private final ArrayList<MobLoot> rolling = new ArrayList<>();
public ReentrantReadWriteLock minionLock = new ReentrantReadWriteLock();
public ArrayList<ProducedItem> forgedItems = new ArrayList<>();
public HashMap<Enum.EquipSlotType, MobEquipment> equip = null;
public HashMap<Enum.EquipSlotType, Item> equip = null;
public int runeSetID = 0;
public int extraRune2 = 0;
protected int loadID;
@ -344,8 +344,8 @@ public class NPC extends AbstractCharacter { @@ -344,8 +344,8 @@ public class NPC extends AbstractCharacter {
if (npc.equip != null) {
writer.putInt(npc.equip.size());
for (MobEquipment me : npc.equip.values())
MobEquipment.serializeForClientMsg(me, writer);
for (Item me : npc.equip.values())
Item.serializeForClientMsg(me, writer);
} else
writer.putInt(0);
@ -1265,7 +1265,7 @@ public class NPC extends AbstractCharacter { @@ -1265,7 +1265,7 @@ public class NPC extends AbstractCharacter {
return true;
}
public HashMap<Enum.EquipSlotType, MobEquipment> getEquip() {
public HashMap<Enum.EquipSlotType, Item> getEquip() {
return equip;
}

Loading…
Cancel
Save