Skip to content

Commit

Permalink
Merge branch 'RPKit-17' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
renbinden committed Mar 3, 2017
2 parents ccca961 + f49cb42 commit ddfb02e
Show file tree
Hide file tree
Showing 20 changed files with 1,063 additions and 1 deletion.
79 changes: 79 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,42 @@ project(":bukkit:rpk-skill-lib-bukkit") {

}

project(":bukkit:rpk-class-lib-bukkit") {

dependencies {
compile project(":bukkit:rpk-core-bukkit")
compile project(":bukkit:rpk-character-lib-bukkit")
compile project(":bukkit:rpk-stat-lib-bukkit")
compile project(":bukkit:rpk-skill-lib-bukkit")
compile project(":bukkit:rpk-experience-lib-bukkit")
}

processResources {
filter ReplaceTokens, tokens: [
"version": version
]
}

artifacts {
archives jar
}

uploadArchives {
repositories.mavenDeployer {

repository(url: "https://repo.seventh-root.com/artifactory/libs-release-local/") {
authentication(userName: repoUserName, password: repoPassword)
}

pom.version = project(":bukkit:rpk-class-lib-bukkit").version
pom.artifactId = project(":bukkit:rpk-class-lib-bukkit").name
pom.groupId = project(":bukkit:rpk-class-lib-bukkit").group

}
}

}

// Bukkit implementations

project(":bukkit:rpk-players-bukkit") {
Expand Down Expand Up @@ -1466,9 +1502,52 @@ project(":bukkit:rpk-skills-bukkit") {

uploadArchives {
repositories.mavenDeployer {

repository(url: "https://repo.seventh-root.com/artifactory/libs-release-local/") {
authentication(userName: repoUserName, password: repoPassword)
}

pom.version = project(":bukkit:rpk-skills-bukkit").version
pom.artifactId = project(":bukkit:rpk-skills-bukkit").name
pom.groupId = project(":bukkit:rpk-skills-bukkit").group
}

}

}

project(":bukkit:rpk-classes-bukkit") {

dependencies {
compile project(":bukkit:rpk-core-bukkit")
compile project(":bukkit:rpk-character-lib-bukkit")
compile project(":bukkit:rpk-stat-lib-bukkit")
compile project(":bukkit:rpk-skill-lib-bukkit")
compile project(":bukkit:rpk-experience-lib-bukkit")
compile project(":bukkit:rpk-class-lib-bukkit")
}

processResources {
filter ReplaceTokens, tokens: [
"version": version
]
}

artifacts {
archives jar
}

uploadArchives {
repositories.mavenDeployer {

repository(url: "https://repo.seventh-root.com/artifactory/libs-release-local/") {
authentication(userName: repoUserName, password: repoPassword)
}

pom.version = project(":bukkit:rpk-classes-bukkit").version
pom.artifactId = project(":bukkit:rpk-classes-bukkit").name
pom.groupId = project(":bukkit:rpk-classes-bukkit").group

}
}

Expand Down
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() {



}
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

}
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)

}
10 changes: 10 additions & 0 deletions bukkit/rpk-class-lib-bukkit/src/main/resources/plugin.yml
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
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) {}
}

}
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"
}

}
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
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
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)
}

}
Loading

0 comments on commit ddfb02e

Please sign in to comment.