Browse Source

implement server side restrictions

combat-2
FatBoy-DOTC 9 months ago
parent
commit
8a769c60f2
  1. 3
      src/engine/Enum.java
  2. 7
      src/engine/objects/AbstractCharacter.java
  3. 79
      src/engine/objects/ItemBase.java
  4. 12
      src/engine/objects/PlayerCharacter.java

3
src/engine/Enum.java

@ -2767,6 +2767,9 @@ public class Enum { @@ -2767,6 +2767,9 @@ public class Enum {
return leadershipTypes[i];
}
public boolean canJoin(AbstractCharacter character){
return this.requiredRaces.contains(character.absRace) && this.requiredClasses.contains(character.absPromotionClass) && this.sexRequired.contains(character.absGender);
}
}
public enum MinionClass {

7
src/engine/objects/AbstractCharacter.java

@ -35,6 +35,7 @@ import org.pmw.tinylog.Logger; @@ -35,6 +35,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.HashSet;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
@ -124,10 +125,12 @@ public abstract class AbstractCharacter extends AbstractWorldObject { @@ -124,10 +125,12 @@ public abstract class AbstractCharacter extends AbstractWorldObject {
public ArrayList<CharacterRune> runes;
public Enum.MonsterType absRace = null;
public ClassType absClass = null;
public Enum.MonsterType absRace;
public ClassType absBaseClass = null;
public ClassType absPromotionClass = null;
public Enum.SexType absGender = null;
public EnumSet<DisciplineType> absDisciplines;
public AbstractCharacter() {
super();

79
src/engine/objects/ItemBase.java

@ -486,13 +486,7 @@ public class ItemBase { @@ -486,13 +486,7 @@ 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))
if(this.canCharacterEquip(abstractCharacter) == false)
return false;
return item.getItemBase().value != 0 || Kit.IsNoobGear(item.getItemBase().uuid);
@ -502,34 +496,6 @@ public class ItemBase { @@ -502,34 +496,6 @@ 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;
@ -985,5 +951,48 @@ public class ItemBase { @@ -985,5 +951,48 @@ public class ItemBase {
return false;
}
public Boolean canCharacterEquip(AbstractCharacter character){
return ValidRace(character.absRace) && ValidClass(character.absBaseClass,character.absPromotionClass) && ValidDiscipline(character.absDisciplines);
}
public Boolean ValidRace(Enum.MonsterType race){
if(this.requiredRaces.isEmpty() && this.restrictedRaces.isEmpty())
return true;
if(this.requiredRaces.isEmpty() == false && race.elementOf(this.requiredRaces) == true)
return true;
if(this.restrictedRaces.isEmpty() == false && race.elementOf(this.restrictedRaces) == false)
return true;
return false;
}
public Boolean ValidClass(Enum.ClassType base,Enum.ClassType profession){
if(this.requiredClasses.isEmpty() && this.restrictedClasses.isEmpty())
return true;
if(this.requiredClasses.isEmpty() == false)
if(this.requiredClasses.contains(base) || this.requiredClasses.contains(profession))
return true;
if(this.restrictedClasses.isEmpty() == false)
if(this.restrictedClasses.contains(base) == false && this.restrictedClasses.contains(profession) == false)
return true;
return false;
}
public Boolean ValidDiscipline(EnumSet<Enum.DisciplineType> discs){
if(this.requiredDiscs.isEmpty() && this.restrictedDiscs.isEmpty())
return true;
for(Enum.DisciplineType disc : discs){
if(this.requiredDiscs.isEmpty() == false && this.requiredDiscs.contains(disc))
return true;
if(this.restrictedDiscs.isEmpty() == false && this.restrictedDiscs.contains(disc))
return false;
}
return false;
}
}

12
src/engine/objects/PlayerCharacter.java

@ -4564,13 +4564,23 @@ public class PlayerCharacter extends AbstractCharacter { @@ -4564,13 +4564,23 @@ public class PlayerCharacter extends AbstractCharacter {
String race = this.getRace().getName().replace("-","").replace(", Male","").replace(", Female","");
this.absRace = Enum.MonsterType.valueOf(race);
if(this.baseClass != null)
this.absBaseClass = ClassType.valueOf(this.getBaseClass().getName());
if(this.promotionClass != null)
this.absClass = ClassType.valueOf(this.getPromotionClass().getName());
this.absPromotionClass = ClassType.valueOf(this.getPromotionClass().getName());
if(this.isMale())
this.absGender = SexType.MALE;
else
this.absGender = SexType.FEMALE;
for(CharacterRune rune : this.runes){
DisciplineType disc = DisciplineType.valueOf(RuneBase.getRuneBase(rune.getRuneBaseID()).getName().replace("-", "").replace(" ", ""));
if(disc != null){
this.absDisciplines.add(disc);
}
}
}
@Override

Loading…
Cancel
Save