-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
1,063 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
bukkit/rpk-class-lib-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/RPKClassLibBukkit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.rpkit.classes.bukkit | ||
|
||
import com.rpkit.core.bukkit.plugin.RPKBukkitPlugin | ||
|
||
|
||
class RPKClassLibBukkit: RPKBukkitPlugin() { | ||
|
||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
bukkit/rpk-class-lib-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/classes/RPKClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.rpkit.classes.bukkit.classes | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.skills.bukkit.skills.RPKSkillType | ||
|
||
|
||
interface RPKClass { | ||
|
||
val name: String | ||
val maxLevel: Int | ||
fun hasPrerequisites(character: RPKCharacter): Boolean | ||
fun getSkillPoints(skillType: RPKSkillType, level: Int): Int | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
...rpk-class-lib-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/classes/RPKClassProvider.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.rpkit.classes.bukkit.classes | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.core.service.ServiceProvider | ||
|
||
|
||
interface RPKClassProvider: ServiceProvider { | ||
|
||
val classes: List<RPKClass> | ||
fun getClass(name: String): RPKClass? | ||
fun getClass(character: RPKCharacter): RPKClass? | ||
fun setClass(character: RPKCharacter, clazz: RPKClass) | ||
fun getLevel(character: RPKCharacter, clazz: RPKClass): Int | ||
fun setLevel(character: RPKCharacter, clazz: RPKClass, level: Int) | ||
fun getExperience(character: RPKCharacter, clazz: RPKClass): Int | ||
fun setExperience(character: RPKCharacter, clazz: RPKClass, experience: Int) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: rpk-class-lib-bukkit | ||
version: @version@ | ||
author: alyphen | ||
main: com.rpkit.classes.bukkit.RPKClassLibBukkit | ||
depend: | ||
- rpk-core-bukkit | ||
- rpk-character-lib-bukkit | ||
- rpk-stat-lib-bukkit | ||
- rpk-skill-lib-bukkit | ||
- rpk-experience-lib-bukkit |
106 changes: 106 additions & 0 deletions
106
bukkit/rpk-classes-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/RPKClassesBukkit.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package com.rpkit.classes.bukkit | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.characters.bukkit.character.field.RPKCharacterCardFieldProvider | ||
import com.rpkit.classes.bukkit.character.ClassField | ||
import com.rpkit.classes.bukkit.classes.RPKClass | ||
import com.rpkit.classes.bukkit.classes.RPKClassProvider | ||
import com.rpkit.classes.bukkit.classes.RPKClassProviderImpl | ||
import com.rpkit.classes.bukkit.command.`class`.ClassCommand | ||
import com.rpkit.classes.bukkit.database.table.RPKCharacterClassTable | ||
import com.rpkit.classes.bukkit.database.table.RPKClassExperienceTable | ||
import com.rpkit.classes.bukkit.listener.PluginEnableListener | ||
import com.rpkit.core.bukkit.plugin.RPKBukkitPlugin | ||
import com.rpkit.core.database.Database | ||
import com.rpkit.core.exception.UnregisteredServiceException | ||
import com.rpkit.stats.bukkit.stat.RPKStatVariable | ||
import com.rpkit.stats.bukkit.stat.RPKStatVariableProvider | ||
|
||
|
||
class RPKClassesBukkit: RPKBukkitPlugin() { | ||
|
||
private var statsInitialized = false | ||
private var characterCardFieldsInitialized = false | ||
|
||
override fun onEnable() { | ||
saveDefaultConfig() | ||
serviceProviders = arrayOf( | ||
RPKClassProviderImpl(this) | ||
) | ||
} | ||
|
||
override fun onPostEnable() { | ||
attemptStatRegistration() | ||
attemptCharacterCardFieldRegistration() | ||
} | ||
|
||
override fun registerCommands() { | ||
getCommand("class").executor = ClassCommand(this) | ||
} | ||
|
||
override fun registerListeners() { | ||
registerListeners( | ||
PluginEnableListener(this) | ||
) | ||
} | ||
|
||
override fun createTables(database: Database) { | ||
database.addTable(RPKCharacterClassTable(database, this)) | ||
database.addTable(RPKClassExperienceTable(database, this)) | ||
} | ||
|
||
override fun setDefaultMessages() { | ||
messages.setDefault("class-usage", "&cUsage: /class [set|list]") | ||
messages.setDefault("no-permission-class-set", "&cYou do not have permission to set your class.") | ||
messages.setDefault("class-set-usage", "&cUsage: /class set [class]") | ||
messages.setDefault("not-from-console", "&cYou must be a player to perform this command.") | ||
messages.setDefault("no-character", "&cYou require a character to perform that command.") | ||
messages.setDefault("class-set-invalid-class", "&cThat class is invalid.") | ||
messages.setDefault("class-set-invalid-prerequisites", "&cYou do not have the prerequisites for that class.") | ||
messages.setDefault("class-set-valid", "&aClass set to \$class.") | ||
messages.setDefault("no-permission-class-list", "&cYou do not have permission to list classes.") | ||
messages.setDefault("class-list-title", "&fClasses:") | ||
messages.setDefault("class-list-item", "&f- &7\$class") | ||
} | ||
|
||
fun attemptStatRegistration() { | ||
if (statsInitialized) return | ||
try { | ||
val statVariableProvider = core.serviceManager.getServiceProvider(RPKStatVariableProvider::class) | ||
val classProvider = core.serviceManager.getServiceProvider(RPKClassProvider::class) | ||
statVariableProvider.addStatVariable(object: RPKStatVariable { | ||
|
||
override val name = "classLevels" | ||
|
||
override fun get(character: RPKCharacter): Map<RPKClass, Int>? { | ||
return classProvider.classes | ||
.map { clazz -> | ||
Pair(clazz, classProvider.getLevel(character, clazz)) | ||
} | ||
.toMap() | ||
} | ||
|
||
}) | ||
statVariableProvider.addStatVariable(object: RPKStatVariable { | ||
|
||
override val name = "clazz" | ||
|
||
override fun get(character: RPKCharacter): Any? { | ||
return classProvider.getClass(character) | ||
} | ||
|
||
}) | ||
statsInitialized = true | ||
} catch (ignore: UnregisteredServiceException) {} | ||
} | ||
|
||
fun attemptCharacterCardFieldRegistration() { | ||
if (characterCardFieldsInitialized) return | ||
try { | ||
val characterCardFieldProvider = core.serviceManager.getServiceProvider(RPKCharacterCardFieldProvider::class) | ||
characterCardFieldProvider.characterCardFields.add(ClassField(this)) | ||
characterCardFieldsInitialized = true | ||
} catch (ignore: UnregisteredServiceException) {} | ||
} | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
bukkit/rpk-classes-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/character/ClassField.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.rpkit.classes.bukkit.character | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.characters.bukkit.character.field.CharacterCardField | ||
import com.rpkit.classes.bukkit.RPKClassesBukkit | ||
import com.rpkit.classes.bukkit.classes.RPKClassProvider | ||
|
||
|
||
class ClassField(private val plugin: RPKClassesBukkit): CharacterCardField { | ||
|
||
override val name = "class" | ||
|
||
override fun get(character: RPKCharacter): String { | ||
return plugin.core.serviceManager.getServiceProvider(RPKClassProvider::class).getClass(character)?.name?:"unset" | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
.../rpk-classes-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/classes/RPKCharacterClass.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.rpkit.classes.bukkit.classes | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.core.database.Entity | ||
|
||
|
||
class RPKCharacterClass( | ||
override var id: Int = 0, | ||
val character: RPKCharacter, | ||
var clazz: RPKClass | ||
) : Entity |
12 changes: 12 additions & 0 deletions
12
...rpk-classes-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/classes/RPKClassExperience.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.rpkit.classes.bukkit.classes | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.core.database.Entity | ||
|
||
|
||
class RPKClassExperience( | ||
override var id: Int = 0, | ||
val character: RPKCharacter, | ||
val clazz: RPKClass, | ||
var experience: Int | ||
) : Entity |
62 changes: 62 additions & 0 deletions
62
bukkit/rpk-classes-bukkit/src/main/kotlin/com/rpkit/classes/bukkit/classes/RPKClassImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.rpkit.classes.bukkit.classes | ||
|
||
import com.rpkit.characters.bukkit.character.RPKCharacter | ||
import com.rpkit.classes.bukkit.RPKClassesBukkit | ||
import com.rpkit.skills.bukkit.skills.RPKSkillType | ||
import com.rpkit.skills.bukkit.skills.RPKSkillTypeProvider | ||
|
||
|
||
class RPKClassImpl( | ||
private val plugin: RPKClassesBukkit, | ||
override val name: String, | ||
override val maxLevel: Int, | ||
private val prerequisitesByName: Map<String, Int>, | ||
private val baseSkillPointsByName: Map<String, Int>, | ||
private val levelSkillPointsByName: Map<String, Int> | ||
) : RPKClass { | ||
|
||
val prerequisites: Map<RPKClass, Int> | ||
get() = prerequisitesByName | ||
.map { entry -> | ||
Pair( | ||
plugin.core.serviceManager.getServiceProvider(RPKClassProvider::class).getClass(entry.key)!!, | ||
entry.value | ||
) | ||
} | ||
.toMap() | ||
|
||
val baseSkillPoints: Map<RPKSkillType, Int> | ||
get() = baseSkillPointsByName | ||
.map { entry -> | ||
Pair( | ||
plugin.core.serviceManager.getServiceProvider(RPKSkillTypeProvider::class).getSkillType(entry.key)!!, | ||
entry.value | ||
) | ||
} | ||
.toMap() | ||
|
||
val levelSkillPoints: Map<RPKSkillType, Int> | ||
get() = levelSkillPointsByName | ||
.map { entry -> | ||
Pair( | ||
plugin.core.serviceManager.getServiceProvider(RPKSkillTypeProvider::class).getSkillType(entry.key)!!, | ||
entry.value | ||
) | ||
} | ||
.toMap() | ||
|
||
override fun hasPrerequisites(character: RPKCharacter): Boolean { | ||
val classProvider = plugin.core.serviceManager.getServiceProvider(RPKClassProvider::class) | ||
for ((clazz, level) in prerequisites) { | ||
if (classProvider.getLevel(character, clazz) < level) { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
override fun getSkillPoints(skillType: RPKSkillType, level: Int): Int { | ||
return baseSkillPoints[skillType]?:0 + (levelSkillPoints[skillType]?:0 * level) | ||
} | ||
|
||
} |
Oops, something went wrong.