Browse Source

server side race/cass restrictions

combat-2
FatBoy-DOTC 9 months ago
parent
commit
726d68df31
  1. 7
      src/engine/Enum.java
  2. 63
      src/engine/db/handlers/dbGuildHandler.java
  3. 15
      src/engine/db/handlers/dbItemBaseHandler.java
  4. 5
      src/engine/objects/AbstractCharacter.java
  5. 86
      src/engine/objects/ItemBase.java
  6. 11
      src/engine/objects/PlayerCharacter.java

7
src/engine/Enum.java

@ -10,6 +10,7 @@ package engine; @@ -10,6 +10,7 @@ package engine;
import ch.claude_martin.enumbitset.EnumBitSetHelper;
import engine.gameManager.ConfigManager;
import engine.gameManager.DbManager;
import engine.gameManager.PowersManager;
import engine.gameManager.ZoneManager;
import engine.math.Vector2f;
@ -2518,11 +2519,17 @@ public class Enum { @@ -2518,11 +2519,17 @@ public class Enum {
private final String name;
private final String[][] ranks; //Stored Rank#->Gender(M,F)
private final String[] leadershipTypes;
public final ArrayList<PromoteType> requiredClasses;
public final ArrayList<MonsterType> requiredRaces;
public final SexType sexRequired;
GuildType(String name, String[][] ranks, String[] leadershipTypes) {
this.name = name;
this.ranks = ranks;
this.leadershipTypes = leadershipTypes;
this.requiredClasses = DbManager.GuildQueries.LOAD_CHARTER_CLASS_RESTRICTIONS(this.name);
this.requiredRaces = DbManager.GuildQueries.LOAD_CHARTER_RACE_RESTRICTIONS(this.name);
this.sexRequired = DbManager.GuildQueries.LOAD_CHARTER_SEX_RESTRICTIONS(this.name);
}
public static GuildType getGuildTypeFromCharter(ItemBase itemBase) {

63
src/engine/db/handlers/dbGuildHandler.java

@ -714,5 +714,68 @@ public class dbGuildHandler extends dbHandlerBase { @@ -714,5 +714,68 @@ public class dbGuildHandler extends dbHandlerBase {
//
// }
public ArrayList<Enum.MonsterType> LOAD_CHARTER_RACE_RESTRICTIONS(String name){
ArrayList<Enum.MonsterType> reqRaces= new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) {
preparedStatement.setString(1, name);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String read = rs.getString("RACE_REQUIRED");
if(read != null){
for(String entry : read.split(";"))
reqRaces.add(Enum.MonsterType.valueOf(entry.replace("-","")));
}
}
} catch (SQLException e) {
Logger.error(e);
}
return reqRaces;
}
public ArrayList<Enum.PromoteType> LOAD_CHARTER_CLASS_RESTRICTIONS(String name){
ArrayList<Enum.PromoteType> reqClasses= new ArrayList<>();
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) {
preparedStatement.setString(1, name);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String read = rs.getString("CLASS_REQUIRED");
if(read != null){
for(String entry : read.split(";"))
reqClasses.add(Enum.PromoteType.valueOf(entry));
}
}
} catch (SQLException e) {
Logger.error(e);
}
return reqClasses;
}
public Enum.SexType LOAD_CHARTER_SEX_RESTRICTIONS(String name){
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM `lore_charter_restrictions` WHERE `GUILDTYPE` = ?")) {
preparedStatement.setString(1, name);
ResultSet rs = preparedStatement.executeQuery();
while (rs.next()) {
String read = rs.getString("SEX_REQUIRED");
if(read != null){
if(read == "Female")
return Enum.SexType.FEMALE;
}
}
} catch (SQLException e) {
Logger.error(e);
}
return Enum.SexType.NONE;
}
}

15
src/engine/db/handlers/dbItemBaseHandler.java

@ -86,6 +86,7 @@ public class dbItemBaseHandler extends dbHandlerBase { @@ -86,6 +86,7 @@ public class dbItemBaseHandler extends dbHandlerBase {
while (rs.next()) {
recordsRead++;
itemBase = new ItemBase(rs);
ItemBase.addToCache(itemBase);
}
@ -95,7 +96,19 @@ public class dbItemBaseHandler extends dbHandlerBase { @@ -95,7 +96,19 @@ public class dbItemBaseHandler extends dbHandlerBase {
Logger.info("read: " + recordsRead + " cached: " + ItemBase.getUUIDCache().size());
}
public void LOAD_ALL_ITEM_REQUIREMENTS(){
for(ItemBase itemBase : ItemBase._itemBaseByUUID.values())
try (Connection connection = DbManager.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement("SELECT * FROM static_item_requirements WHERE 'itemID' = ?")) {
preparedStatement.setInt(1, itemBase.getUUID());
ResultSet rs = preparedStatement.executeQuery();
while(rs.next()) {
itemBase.LoadRequirements(rs.getString("racesRequired"),rs.getString("racesRestricted"),rs.getString("classesRequired"),rs.getString("classesRestricted"),rs.getString("discsRequired"),rs.getString("discsRestricted"));
}
} catch (SQLException e) {
Logger.error("No Entry In static_item_requirements for item UUID: " + itemBase.getUUID());
}
}
public HashMap<Integer, ArrayList<Integer>> LOAD_RUNES_FOR_NPC_AND_MOBS() {
HashMap<Integer, ArrayList<Integer>> runeSets = new HashMap<>();

5
src/engine/objects/AbstractCharacter.java

@ -125,6 +125,11 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -125,6 +125,11 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
public ArrayList<CharacterRune> runes;
public Enum.MonsterType absRace = null;
public Enum.PromoteType absClass = null;
public Enum.SexType absGender = null;
public AbstractCharacter() {
super();
this.firstName = "";

86
src/engine/objects/ItemBase.java

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
package engine.objects;
import engine.Enum;
import engine.Enum.DamageType;
import engine.Enum.GameObjectType;
import engine.Enum.ItemType;
@ -77,6 +78,15 @@ public class ItemBase { @@ -77,6 +78,15 @@ public class ItemBase {
private ArrayList<Integer> offHandAnimations = new ArrayList<>();
private boolean autoID = false;
//requirements/restrictions
public ArrayList<Enum.MonsterType> restrictedRaces;
public ArrayList<Enum.MonsterType> requiredRaces;
public ArrayList<Enum.PromoteType> restrictedClasses;
public ArrayList<Enum.PromoteType> requiredClasses;
public ArrayList<Integer> requiredDiscs;
public ArrayList<Integer> restrictedDiscs;
public Enum.SexType requiredSex;
/**
* ResultSet Constructor
*/
@ -212,6 +222,7 @@ public class ItemBase { @@ -212,6 +222,7 @@ public class ItemBase {
public static void loadAllItemBases() {
DbManager.ItemBaseQueries.LOAD_ALL_ITEMBASES();
DbManager.ItemBaseQueries.LOAD_ALL_ITEM_REQUIREMENTS();
AnniverseryGifts.add(971000);
AnniverseryGifts.add(971001);
AnniverseryGifts.add(971002);
@ -468,6 +479,15 @@ public class ItemBase { @@ -468,6 +479,15 @@ public class ItemBase {
if (!validForSkills(abstractCharacter.getSkills()))
return false;
if (!validRace(item.getItemBase(), abstractCharacter))
return false;
if (!validClass(item.getItemBase(), abstractCharacter))
return false;
if (!validDisc(item.getItemBase(), abstractCharacter))
return false;
return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid);
//players can't wear 0 value items.
@ -476,6 +496,33 @@ public class ItemBase { @@ -476,6 +496,33 @@ public class ItemBase {
return true; //Mobiles and NPC's don't need to check equip
}
public static boolean validRace(ItemBase ib, AbstractCharacter absChar){
if(ib.requiredRaces == null || ib.requiredRaces.isEmpty())
if(ib.restrictedRaces == null || ib.restrictedRaces.isEmpty())
return true;
return ib.requiredRaces.contains(absChar.absRace) && !ib.restrictedRaces.contains(absChar.absRace);
}
public static boolean validClass(ItemBase ib, AbstractCharacter absChar){
if(ib.requiredClasses == null || ib.requiredClasses.isEmpty())
if(ib.restrictedClasses == null || ib.restrictedClasses.isEmpty())
return true;
return ib.requiredClasses.contains(absChar.absClass) && !ib.restrictedClasses.contains(absChar.absClass);
}
public static boolean validDisc(ItemBase ib, AbstractCharacter absChar){
if(ib.requiredDiscs == null || ib.requiredDiscs.isEmpty())
if(ib.restrictedDiscs == null || ib.restrictedDiscs.isEmpty())
return true;
for(CharacterRune rune : absChar.runes)
if(ib.requiredDiscs.contains(rune.getRuneBaseID()) == true && ib.restrictedDiscs.contains(rune.getRuneBaseID()) == false)
return true;
return false;
}
public int getValidSlot() {
int slotValue = 0;
@ -931,4 +978,43 @@ public class ItemBase { @@ -931,4 +978,43 @@ public class ItemBase {
return false;
}
public void LoadRequirements(String racesRequired, String racesRestricted, String classesRequired, String classesRestricted, String discsRequired, String discsRestricted){
this.requiredRaces = new ArrayList<>();
this.restrictedRaces = new ArrayList<>();
this.requiredClasses = new ArrayList<>();
this.restrictedClasses = new ArrayList<>();
this.requiredDiscs = new ArrayList<>();
this.restrictedDiscs = new ArrayList<>();
if(racesRequired != null){
for(String entry : racesRequired.split(";")){
requiredRaces.add(Enum.MonsterType.valueOf(entry));
}
}
if(racesRestricted != null){
for(String entry : racesRestricted.split(";")){
restrictedRaces.add(Enum.MonsterType.valueOf(entry));
}
}
if(classesRequired != null){
for(String entry : classesRequired.split(";")){
requiredClasses.add(Enum.PromoteType.valueOf(entry));
}
}
if(classesRestricted != null){
for(String entry : classesRestricted.split(";")){
restrictedClasses.add(Enum.PromoteType.valueOf(entry));
}
}
if(discsRequired != null){
for(String entry : discsRequired.split(";")){
//TODO find way to load disc runebaseID from name
}
}
if(discsRestricted != null){
for(String entry : discsRestricted.split(";")) {
//TODO find way to load disc runebaseID from name
}
}
}
}

11
src/engine/objects/PlayerCharacter.java

@ -4559,6 +4559,17 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4559,6 +4559,17 @@ public class PlayerCharacter extends AbstractCharacter {
Bounds playerBounds = Bounds.borrow();
playerBounds.setBounds(this.getLoc());
this.setBounds(playerBounds);
//assign enum values for restrictions
this.absRace = Enum.MonsterType.valueOf(this.getRace().getName().replace("-",""));
if(this.promotionClass != null)
this.absClass = Enum.PromoteType.valueOf(this.getPromotionClass().getName());
if(this.isMale())
this.absGender = SexType.MALE;
else
this.absGender = SexType.FEMALE;
}
@Override

Loading…
Cancel
Save