forked from MagicBane/Server
Equipment slot refactor started.
This commit is contained in:
@@ -13,7 +13,6 @@ import engine.Enum;
|
||||
import engine.Enum.GameObjectType;
|
||||
import engine.Enum.ItemType;
|
||||
import engine.gameManager.DbManager;
|
||||
import engine.server.MBServerStatics;
|
||||
import org.pmw.tinylog.Logger;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
@@ -386,7 +385,7 @@ public class ItemBase {
|
||||
}
|
||||
|
||||
|
||||
public boolean canEquip(int slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) {
|
||||
public boolean canEquip(Enum.EquipSlotType slot, CharacterItemManager itemManager, AbstractCharacter abstractCharacter, Item item) {
|
||||
|
||||
if (itemManager == null || abstractCharacter == null)
|
||||
return false;
|
||||
@@ -410,244 +409,30 @@ public class ItemBase {
|
||||
return true; //Mobiles and NPC's don't need to check equip
|
||||
}
|
||||
|
||||
public int getValidSlot() {
|
||||
int slotValue = 0;
|
||||
|
||||
switch (this.type) {
|
||||
case WEAPON:
|
||||
if ((this.equipFlag & 1) != 0)
|
||||
slotValue = MBServerStatics.SLOT_MAINHAND;
|
||||
else if ((this.equipFlag & 2) != 0)
|
||||
slotValue = MBServerStatics.SLOT_OFFHAND;
|
||||
break;
|
||||
case ARMOR:
|
||||
if ((this.equipFlag & 2) != 0)
|
||||
slotValue = MBServerStatics.SLOT_OFFHAND;
|
||||
else if ((this.equipFlag & 4) != 0)
|
||||
slotValue = MBServerStatics.SLOT_HELMET;
|
||||
else if ((this.equipFlag & 8) != 0)
|
||||
slotValue = MBServerStatics.SLOT_CHEST;
|
||||
else if ((this.equipFlag & 16) != 0)
|
||||
slotValue = MBServerStatics.SLOT_ARMS;
|
||||
else if ((this.equipFlag & 32) != 0)
|
||||
slotValue = MBServerStatics.SLOT_GLOVES;
|
||||
else if ((this.equipFlag & 64) != 0)
|
||||
slotValue = MBServerStatics.SLOT_RING2;
|
||||
else if ((this.equipFlag & 128) != 0)
|
||||
slotValue = MBServerStatics.SLOT_RING1;
|
||||
else if ((this.equipFlag & 256) != 0)
|
||||
slotValue = MBServerStatics.SLOT_NECKLACE;
|
||||
else if ((this.equipFlag & 512) != 0)
|
||||
slotValue = MBServerStatics.SLOT_LEGGINGS;
|
||||
else if ((this.equipFlag & 1024) != 0)
|
||||
slotValue = MBServerStatics.SLOT_FEET;
|
||||
break;
|
||||
|
||||
case HAIR:
|
||||
if (this.equipFlag == 131072)
|
||||
slotValue = MBServerStatics.SLOT_HAIRSTYLE;
|
||||
else if (this.equipFlag == 65536)
|
||||
slotValue = MBServerStatics.SLOT_BEARDSTYLE;
|
||||
break;
|
||||
|
||||
}
|
||||
return slotValue;
|
||||
|
||||
}
|
||||
|
||||
public boolean validSlotFlag(long flags) {
|
||||
|
||||
boolean validSlot = false;
|
||||
|
||||
switch (this.type) {
|
||||
case WEAPON:
|
||||
if (this.isMelee())
|
||||
validSlot = ((flags & 1) != 0);
|
||||
else if (this.isThrowing())
|
||||
validSlot = ((flags & 2) != 0);
|
||||
else if (this.isArchery())
|
||||
validSlot = ((flags & 4) != 0);
|
||||
else if (this.isScepter())
|
||||
validSlot = ((flags & 8) != 0);
|
||||
else if (this.isStaff())
|
||||
validSlot = ((flags & 16) != 0);
|
||||
break;
|
||||
case JEWELRY:
|
||||
if (this.isNecklace())
|
||||
validSlot = ((flags & 2147483648L) != 0L);
|
||||
else
|
||||
validSlot = ((flags & 4294967296L) != 0L);
|
||||
break;
|
||||
case ARMOR:
|
||||
|
||||
if (this.isShield()) {
|
||||
validSlot = ((flags & 32) != 0);
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isClothArmor()) {
|
||||
|
||||
if (this.getEquipFlag() == 4) //hood
|
||||
validSlot = ((flags & 64) != 0);
|
||||
else if (this.getEquipFlag() == 8) {
|
||||
if ((restrictFlag & 512) != 0) //Robe
|
||||
validSlot = ((flags & 128) != 0);
|
||||
else
|
||||
validSlot = ((flags & 1024) != 0); //Tunic/Shirt
|
||||
|
||||
break;
|
||||
} else if (this.getEquipFlag() == 16) //Sleeves
|
||||
validSlot = ((flags & 2048) != 0);
|
||||
else if (this.getEquipFlag() == 32) //Gloves
|
||||
validSlot = ((flags & 512) != 0);
|
||||
else if (this.getEquipFlag() == 512) //Pants
|
||||
validSlot = ((flags & 4096) != 0);
|
||||
else if (this.getEquipFlag() == 1024) //Boots
|
||||
validSlot = ((flags & 256) != 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isLightArmor()) {
|
||||
if (this.getEquipFlag() == 4) //helm
|
||||
validSlot = ((flags & 8192) != 0);
|
||||
else if (this.getEquipFlag() == 8) //Chest
|
||||
validSlot = ((flags & 16384) != 0);
|
||||
else if (this.getEquipFlag() == 16) //Sleeves
|
||||
validSlot = ((flags & 32768) != 0);
|
||||
else if (this.getEquipFlag() == 32) //Gloves
|
||||
validSlot = ((flags & 65536) != 0);
|
||||
else if (this.getEquipFlag() == 512) //Pants
|
||||
validSlot = ((flags & 131072) != 0);
|
||||
else if (this.getEquipFlag() == 1024) //Boots
|
||||
validSlot = ((flags & 262144) != 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isMediumArmor()) {
|
||||
if (this.getEquipFlag() == 4) //helm
|
||||
validSlot = ((flags & 524288) != 0);
|
||||
else if (this.getEquipFlag() == 8) //Chest
|
||||
validSlot = ((flags & 1048576) != 0);
|
||||
else if (this.getEquipFlag() == 16) //Sleeves
|
||||
validSlot = ((flags & 2097152) != 0);
|
||||
else if (this.getEquipFlag() == 32) //Gloves
|
||||
validSlot = ((flags & 4194304) != 0);
|
||||
else if (this.getEquipFlag() == 512) //Pants
|
||||
validSlot = ((flags & 8388608) != 0);
|
||||
else if (this.getEquipFlag() == 1024) //Boots
|
||||
validSlot = ((flags & 16777216) != 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (this.isHeavyArmor())
|
||||
if (this.getEquipFlag() == 4) //helm
|
||||
validSlot = ((flags & 33554432) != 0);
|
||||
else if (this.getEquipFlag() == 8) //Chest
|
||||
validSlot = ((flags & 67108864) != 0);
|
||||
else if (this.getEquipFlag() == 16) //Sleeves
|
||||
validSlot = ((flags & 134217728) != 0);
|
||||
else if (this.getEquipFlag() == 32) //Gloves
|
||||
validSlot = ((flags & 268435456) != 0);
|
||||
else if (this.getEquipFlag() == 512) //Pants
|
||||
validSlot = ((flags & 536870912) != 0);
|
||||
else if (this.getEquipFlag() == 1024) //Boots
|
||||
validSlot = ((flags & 1073741824) != 0);
|
||||
break;
|
||||
}
|
||||
return validSlot;
|
||||
}
|
||||
|
||||
public boolean validForSlot(int slot, ConcurrentHashMap<Integer, Item> equipped, Item item) {
|
||||
public static boolean validForSlot(Enum.EquipSlotType slot, ConcurrentHashMap<Enum.EquipSlotType, Item> equipped, Item item) {
|
||||
|
||||
boolean validSlot = false;
|
||||
|
||||
if (equipped == null)
|
||||
return validSlot;
|
||||
return false;
|
||||
|
||||
// Slot is taken
|
||||
|
||||
// Cannot equip an item in a slot already taken
|
||||
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
||||
return validSlot;
|
||||
return false;
|
||||
|
||||
switch (item.getItemBase().type) {
|
||||
case WEAPON:
|
||||
// Two handed weapons take up two slots
|
||||
|
||||
// Only two slots available for weapons
|
||||
if ((slot != MBServerStatics.SLOT_MAINHAND) && (slot != MBServerStatics.SLOT_OFFHAND))
|
||||
break;
|
||||
if ((ItemTemplate.isTwoHanded(item)) &&
|
||||
((slot == Enum.EquipSlotType.LHELD && equipped.get(Enum.EquipSlotType.RHELD) != null) ||
|
||||
(slot == Enum.EquipSlotType.RHELD && equipped.get(Enum.EquipSlotType.LHELD) != null)))
|
||||
return false;
|
||||
|
||||
//make sure weapon is valid for slot
|
||||
if ((slot & this.equipFlag) == 0)
|
||||
break;
|
||||
if (item.template.item_type.equals(ItemType.WEAPON))
|
||||
if (equipped.get(slot) != null && equipped.get(slot).equals(item) == false)
|
||||
return false;
|
||||
|
||||
// Two handed weapons take up two slots
|
||||
if ((this.twoHanded == true) &&
|
||||
((slot == MBServerStatics.SLOT_OFFHAND && equipped.get(MBServerStatics.SLOT_MAINHAND) != null) ||
|
||||
(slot == MBServerStatics.SLOT_MAINHAND && equipped.get(MBServerStatics.SLOT_OFFHAND) != null)))
|
||||
break;
|
||||
|
||||
// Validation passed, must be a valid weapon
|
||||
|
||||
validSlot = true;
|
||||
break;
|
||||
case JEWELRY:
|
||||
// Not a valid slot for ring
|
||||
|
||||
if (this.isRing() &&
|
||||
((slot != MBServerStatics.SLOT_RING1) && (slot != MBServerStatics.SLOT_RING2)))
|
||||
break;
|
||||
|
||||
// Not a valid slot for necklace
|
||||
|
||||
if (this.isNecklace() && slot != MBServerStatics.SLOT_NECKLACE)
|
||||
break;
|
||||
|
||||
// Passed validation, must be valid bling bling
|
||||
|
||||
validSlot = true;
|
||||
break;
|
||||
case ARMOR:
|
||||
|
||||
// Invalid slot for armor?
|
||||
if (slot == MBServerStatics.SLOT_OFFHAND && ((2 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_HELMET && ((4 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_CHEST && ((8 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_ARMS && ((16 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_GLOVES && ((32 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_LEGGINGS && ((512 & this.equipFlag) == 0))
|
||||
break;
|
||||
if (slot == MBServerStatics.SLOT_FEET && ((1024 & this.equipFlag) == 0))
|
||||
break;
|
||||
|
||||
// Is slot for this piece already taken?
|
||||
if (((this.restrictFlag & 2) != 0) && (equipped.get(MBServerStatics.SLOT_OFFHAND) != null) && slot != MBServerStatics.SLOT_OFFHAND)
|
||||
break;
|
||||
if (((this.restrictFlag & 4) != 0) && (equipped.get(MBServerStatics.SLOT_HELMET) != null) && slot != MBServerStatics.SLOT_HELMET)
|
||||
break;
|
||||
if (((this.restrictFlag & 8) != 0) && (equipped.get(MBServerStatics.SLOT_CHEST) != null) && slot != MBServerStatics.SLOT_CHEST)
|
||||
break;
|
||||
if (((this.restrictFlag & 16) != 0) && (equipped.get(MBServerStatics.SLOT_ARMS) != null) && slot != MBServerStatics.SLOT_ARMS)
|
||||
break;
|
||||
if (((this.restrictFlag & 32) != 0) && (equipped.get(MBServerStatics.SLOT_GLOVES) != null) && slot != MBServerStatics.SLOT_GLOVES)
|
||||
break;
|
||||
if (((this.restrictFlag & 512) != 0) && (equipped.get(MBServerStatics.SLOT_LEGGINGS) != null) && slot != MBServerStatics.SLOT_LEGGINGS)
|
||||
break;
|
||||
if (((this.restrictFlag & 1024) != 0) && (equipped.get(MBServerStatics.SLOT_FEET) != null) && slot != MBServerStatics.SLOT_FEET)
|
||||
break;
|
||||
|
||||
// Passed validation. Is a valid armor piece
|
||||
|
||||
validSlot = true;
|
||||
break;
|
||||
}
|
||||
return validSlot;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user