forked from MagicBane/Server
implement server side restrictions
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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();
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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 {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user