2022-04-30 09:41:17 -04:00
// • ▌ ▄ ·. ▄▄▄· ▄▄ • ▪ ▄▄· ▄▄▄▄· ▄▄▄· ▐▄▄▄ ▄▄▄ .
// ·██ ▐███▪▐█ ▀█ ▐█ ▀ ▪██ ▐█ ▌▪▐█ ▀█▪▐█ ▀█ •█▌ ▐█▐▌·
// ▐█ ▌▐▌▐█·▄█▀▀█ ▄█ ▀█▄▐█·██ ▄▄▐█▀▀█▄▄█▀▀█ ▐█▐ ▐▌▐▀▀▀
// ██ ██▌▐█▌▐█ ▪▐▌▐█▄▪▐█▐█▌▐███▌██▄▪▐█▐█ ▪▐▌██▐ █▌▐█▄▄▌
// ▀▀ █▪▀▀▀ ▀ ▀ ·▀▀▀▀ ▀▀▀·▀▀▀ ·▀▀▀▀ ▀ ▀ ▀▀ █▪ ▀▀▀
// Magicbane Emulator Project © 2013 - 2022
// www.magicbane.com
package engine.objects ;
import engine.Enum ;
import engine.Enum.RaceType ;
import engine.gameManager.DbManager ;
2024-03-10 18:27:09 -05:00
import engine.math.Vector3f ;
2022-04-30 09:41:17 -04:00
import engine.net.ByteBufferWriter ;
import engine.server.MBServerStatics ;
import java.sql.ResultSet ;
import java.sql.SQLException ;
import java.util.ArrayList ;
import java.util.HashSet ;
import java.util.concurrent.ConcurrentHashMap ;
public class Race {
2023-07-15 09:23:48 -04:00
// Local class cache
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private static ConcurrentHashMap < Integer , Race > _raceByID = new ConcurrentHashMap <> ( MBServerStatics . CHM_INIT_CAP , MBServerStatics . CHM_LOAD , MBServerStatics . CHM_THREAD_LOW );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
private final String name ;
private final String description ;
private final int raceRuneID ;
private final short strStart ;
private final short strMin ;
private final short strMax ;
private final short dexStart ;
private final short dexMin ;
private final short dexMax ;
private final short conStart ;
private final short conMin ;
private final short conMax ;
private final short intStart ;
private final short intMin ;
private final short intMax ;
private final short spiStart ;
private final short spiMin ;
private final short spiMax ;
private final short healthBonus ;
private final short manaBonus ;
private final short staminaBonus ;
private final byte startingPoints ;
private final float minHeight ;
private final float strHeightMod ;
private final HashSet < Integer > skinColors ;
private final HashSet < Integer > beardColors ;
private final HashSet < Integer > hairColors ;
private final ArrayList < BaseClass > baseClasses ;
private final ArrayList < SkillReq > skillsGranted ;
private final ArrayList < PowerReq > powersGranted ;
private Enum . RaceType raceType ;
private int token = 0 ;
private HashSet < Integer > hairStyles ;
private HashSet < Integer > beardStyles ;
private ArrayList < MobBaseEffects > effectsList = new ArrayList <> ();
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/**
* ResultSet Constructor
*/
public Race ( ResultSet rs ) throws SQLException {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
this . raceRuneID = rs . getInt ( "ID" );
this . raceType = Enum . RaceType . getRaceTypebyRuneID ( raceRuneID );
this . name = rs . getString ( "name" );
this . description = rs . getString ( "description" );
this . strStart = rs . getShort ( "strStart" );
this . strMin = rs . getShort ( "strMin" );
this . strMax = rs . getShort ( "strMax" );
this . dexStart = rs . getShort ( "dexStart" );
this . dexMin = rs . getShort ( "dexMin" );
this . dexMax = rs . getShort ( "dexMax" );
this . conStart = rs . getShort ( "conStart" );
this . conMin = rs . getShort ( "conMin" );
this . conMax = rs . getShort ( "conMax" );
this . intStart = rs . getShort ( "intStart" );
this . intMin = rs . getShort ( "intMin" );
this . intMax = rs . getShort ( "intMax" );
this . spiStart = rs . getShort ( "spiStart" );
this . spiMin = rs . getShort ( "spiMin" );
this . spiMax = rs . getShort ( "spiMax" );
this . token = rs . getInt ( "token" );
this . healthBonus = rs . getShort ( "healthBonus" );
this . manaBonus = rs . getShort ( "manaBonus" );
this . staminaBonus = rs . getShort ( "staminaBonus" );
this . startingPoints = rs . getByte ( "startingPoints" );
this . raceType = RaceType . getRaceTypebyRuneID ( this . raceRuneID );
this . minHeight = rs . getFloat ( "minHeight" );
this . strHeightMod = rs . getFloat ( "strHeightMod" );
this . hairStyles = DbManager . RaceQueries . HAIR_STYLES_FOR_RACE ( raceRuneID );
this . beardStyles = DbManager . RaceQueries . BEARD_STYLES_FOR_RACE ( raceRuneID );
this . skinColors = DbManager . RaceQueries . SKIN_COLOR_FOR_RACE ( raceRuneID );
this . beardColors = DbManager . RaceQueries . BEARD_COLORS_FOR_RACE ( raceRuneID );
this . hairColors = DbManager . RaceQueries . HAIR_COLORS_FOR_RACE ( raceRuneID );
this . baseClasses = DbManager . BaseClassQueries . GET_BASECLASS_FOR_RACE ( raceRuneID );
this . skillsGranted = DbManager . SkillReqQueries . GET_REQS_FOR_RUNE ( raceRuneID );
this . powersGranted = PowerReq . getPowerReqsForRune ( raceRuneID );
this . effectsList = DbManager . MobBaseQueries . GET_RUNEBASE_EFFECTS ( this . raceRuneID );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2024-03-10 18:27:09 -05:00
//Custom Race constructor
Race ( int id , String name , String description , Vector3f str , Vector3f dex , Vector3f con , Vector3f intel , Vector3f spi , byte startingPoints , int token , short healthBonus , short stamBonus , float minHeight , short manaBonus , ArrayList < BaseClass > baseClasses , ArrayList < SkillReq > skillsGranted , ArrayList < PowerReq > powersGranted , ArrayList < MobBaseEffects > effectsList ){
this . raceRuneID = id ;
this . raceType = Enum . RaceType . getRaceTypebyRuneID ( raceRuneID );
this . name = name ;
this . description = description ;
this . strStart = ( short ) str . x ;
this . strMin = ( short ) str . y ;
this . strMax = ( short ) str . z ;
this . dexStart = ( short ) dex . x ;
this . dexMin = ( short ) dex . y ;
this . dexMax = ( short ) dex . z ;
this . conStart = ( short ) con . x ;
this . conMin = ( short ) con . y ;
this . conMax = ( short ) con . z ;
this . intStart = ( short ) intel . x ;
this . intMin = ( short ) intel . y ;
this . intMax = ( short ) intel . z ;
this . spiStart = ( short ) spi . x ;
this . spiMin = ( short ) spi . y ;
this . spiMax = ( short ) spi . z ;
this . token = token ;
this . healthBonus = healthBonus ;
this . manaBonus = manaBonus ;
this . staminaBonus = stamBonus ;
this . startingPoints = startingPoints ;
this . raceType = RaceType . getRaceTypebyRuneID ( this . raceRuneID );
this . minHeight = minHeight ;
this . strHeightMod = 0 . 005882f ;
this . hairStyles = null ;
this . beardStyles = null ;
this . skinColors = null ;
this . beardColors = null ;
this . hairColors = null ;
this . baseClasses = baseClasses ;
this . skillsGranted = skillsGranted ;
this . powersGranted = powersGranted ;
this . effectsList = effectsList ;
}
2023-07-15 09:23:48 -04:00
public static void loadAllRaces () {
Race . _raceByID = DbManager . RaceQueries . LOAD_ALL_RACES ();
2024-03-10 18:27:09 -05:00
//create Saetor race
ArrayList < BaseClass > baseClassesSaetor = new ArrayList <> ();
2024-03-10 18:31:19 -05:00
baseClassesSaetor . add ( BaseClass . getBaseClass ( 2500 ));
baseClassesSaetor . add ( BaseClass . getBaseClass ( 2501 ));
baseClassesSaetor . add ( BaseClass . getBaseClass ( 2502 ));
baseClassesSaetor . add ( BaseClass . getBaseClass ( 2503 ));
2024-03-10 18:27:09 -05:00
ArrayList < SkillReq > skillsGrantedSaetor = new ArrayList <> ();
2024-03-27 21:08:08 -05:00
skillsGrantedSaetor . add ( new SkillReq ( 37 , ( short ) 10 )); // staff
skillsGrantedSaetor . add ( new SkillReq ( 36 , ( short ) 1 )); // staff mastery
skillsGrantedSaetor . add ( new SkillReq ( 27 , ( short ) 1 )); // parry
2024-03-10 18:27:09 -05:00
ArrayList < PowerReq > powersGrantedSaetor = new ArrayList <> ();
ArrayList < MobBaseEffects > effectsListSaetor = new ArrayList <> ();
2024-03-19 19:12:44 -05:00
Race saetor = new Race ( 1999 , "Saetor" , "Half goat half man, the Saetor race does the bidding of the Choas Gods." , new Vector3f ( 35 , 30 , 85 ), new Vector3f ( 55 , 50 , 120 ), new Vector3f ( 50 , 45 , 115 ), new Vector3f ( 45 , 40 , 110 ), new Vector3f ( 35 , 30 , 85 ),( byte ) 20 , 19991999 ,( short ) 0 ,( short ) 0 , 5 . 0f ,( short ) 0 , baseClassesSaetor , skillsGrantedSaetor , powersGrantedSaetor , effectsListSaetor );
2024-03-10 18:27:09 -05:00
Race . _raceByID . put ( 1999 , saetor );
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public static Race getRace ( int id ) {
return _raceByID . get ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
public boolean equals ( Object object ) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if (( object instanceof Race ) == false )
return false ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
Race race = ( Race ) object ;
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
return this . raceRuneID == race . raceRuneID ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
@Override
public int hashCode () {
return this . raceRuneID ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/*
* Getters
*/
public String getName () {
return name ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public String getDescription () {
return description ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getStrStart () {
return strStart ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getStrMin () {
return strMin ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getStrMax () {
return strMax ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getDexStart () {
return dexStart ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getDexMin () {
return dexMin ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getDexMax () {
return dexMax ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getConStart () {
return conStart ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getConMin () {
return conMin ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getConMax () {
return conMax ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getIntStart () {
return intStart ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getIntMin () {
return intMin ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getIntMax () {
return intMax ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getSpiStart () {
return spiStart ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getSpiMin () {
return spiMin ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public short getSpiMax () {
return spiMax ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public byte getStartingPoints () {
return startingPoints ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getToken () {
return token ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public final HashSet < Integer > getHairStyles () {
return hairStyles ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public final HashSet < Integer > getBeardStyles () {
return beardStyles ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public final HashSet < Integer > getBeardColors () {
return beardColors ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public HashSet < Integer > getHairColors () {
return hairColors ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public HashSet < Integer > getSkinColors () {
return skinColors ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getNumSkinColors () {
return this . skinColors . size ();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getNumHairColors () {
return this . hairColors . size ();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getNumBeardColors () {
return this . beardColors . size ();
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public final ArrayList < BaseClass > getValidBaseClasses () {
return baseClasses ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ArrayList < Integer > getAllowedRunes () {
2022-04-30 09:41:17 -04:00
return RuneBase . AllowedRaceRunesMap . get ( raceRuneID );
2023-07-15 09:23:48 -04:00
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ArrayList < SkillReq > getSkillsGranted () {
return this . skillsGranted ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ArrayList < PowerReq > getPowersGranted () {
return this . powersGranted ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ArrayList < RuneBaseEffect > getEffectsGranted () {
return RuneBaseEffect . RuneIDBaseEffectMap . get ( this . raceRuneID );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/*
* Validators
*/
public boolean isValidBeardStyle ( int id ) {
return this . beardStyles . contains ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isValidBeardColor ( int id ) {
return this . beardColors . contains ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isValidHairStyle ( int id ) {
return this . hairStyles . contains ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isValidHairColor ( int id ) {
return this . hairColors . contains ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isValidSkinColor ( int id ) {
return this . skinColors . contains ( id );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public boolean isAllowedRune ( RuneBase rb ) {
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
if ( this . getAllowedRunes () != null )
if ( this . getAllowedRunes (). contains ( rb . getObjectUUID ()))
return true ;
if ( RuneBase . AllowedBaseClassRunesMap . containsKey ( 111111 )) {
if ( RuneBase . AllowedRaceRunesMap . get ( 111111 ). contains ( rb . getObjectUUID ()))
return true ;
}
return false ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getHealthBonus () {
return this . healthBonus ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getManaBonus () {
return this . manaBonus ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getStaminaBonus () {
return this . staminaBonus ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getMinHeight () {
return this . minHeight ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getStrHeightMod () {
return this . strHeightMod ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getHeight ( short str ) {
return this . minHeight + ( this . strHeightMod * str );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
/*
* Serializing
*/
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public float getCenterHeight ( short str ) {
return getHeight ( str ) / 2f ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public void serializeForClientMsg ( ByteBufferWriter writer ) {
writer . putInt ( 1 ); // For Race
writer . putInt ( 0 ); // Pad
writer . putInt ( this . raceRuneID );
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
writer . putInt ( Enum . GameObjectType . Race . ordinal ());
writer . putInt ( raceRuneID );
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public int getRaceRuneID () {
return raceRuneID ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public Enum . RaceType getRaceType () {
return raceType ;
}
2022-04-30 09:41:17 -04:00
2023-07-15 09:23:48 -04:00
public ArrayList < MobBaseEffects > getEffectsList () {
return effectsList ;
}
2022-04-30 09:41:17 -04:00
}