This commit is contained in:
Phillip Thelen 2021-09-23 14:28:15 +02:00
parent 2720b15e32
commit eae24e2391
3 changed files with 22 additions and 30 deletions

View file

@ -58,17 +58,7 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
} else null
if (user != null && localData != null) {
val stats = user.stats
val result = TaskScoringResult()
result.healthDelta = localData.hp - (stats?.hp ?: 0.0)
result.experienceDelta = localData.exp - (stats?.exp ?: 0.0)
result.manaDelta = localData.mp - (stats?.mp ?: 0.0)
result.goldDelta = localData.gp - (stats?.gp ?: 0.0)
result.hasLeveledUp = localData.lvl > stats?.lvl ?: 0
result.level = localData.lvl
result.questDamage = localData._tmp?.quest?.progressDelta
result.questItemsFound = localData._tmp?.quest?.collection
result.drop = localData._tmp?.drop
val result = TaskScoringResult(localData, stats)
notifyFunc?.invoke(result)
handleTaskResponse(user, localData, task, up, 0f)
@ -100,22 +90,11 @@ class TaskRepositoryImpl(localRepository: TaskLocalRepository, apiClient: ApiCli
Pair("value", task.value)
)
)
val result = TaskScoringResult()
if (res.lvl == 0) {
// Team tasks that require approval have weird data that we should just ignore.
return@map result
return@map TaskScoringResult()
}
val stats = user.stats
result.healthDelta = res.hp - (stats?.hp ?: 0.0)
result.experienceDelta = res.exp - (stats?.exp ?: 0.0)
result.manaDelta = res.mp - (stats?.mp ?: 0.0)
result.goldDelta = res.gp - (stats?.gp ?: 0.0)
result.hasLeveledUp = res.lvl > stats?.lvl ?: 0
result.level = res.lvl
result.questDamage = res._tmp?.quest?.progressDelta
result.questItemsFound = res._tmp?.quest?.collection
result.drop = res._tmp?.drop
val result = TaskScoringResult(res, user.stats)
if (localData == null) {
notifyFunc?.invoke(result)
}

View file

@ -11,14 +11,9 @@ open class Tag : RealmObject(), BaseObject {
var id: String = ""
var userId: String? = null
var tasks: RealmList<Task>? = null
var name: String = ""
internal var challenge: Boolean = false
fun getTasks(): List<Task>? {
return tasks
}
override fun equals(other: Any?): Boolean {
if (other is Tag) {
return this.id == other.id

View file

@ -1,6 +1,24 @@
package com.habitrpg.android.habitica.models.responses
class TaskScoringResult {
import com.habitrpg.android.habitica.models.user.Stats
class TaskScoringResult() {
constructor(data: TaskDirectionData, stats: Stats?) : this() {
hasLeveledUp = data.lvl > stats?.lvl ?: 0
healthDelta = data.hp - (stats?.hp ?: 0.0)
if (hasLeveledUp) {
experienceDelta = (stats?.toNextLevel ?: 0).toDouble() - (stats?.exp ?: 0.0) + data.exp
} else {
experienceDelta = data.exp - (stats?.exp ?: 0.0)
}
manaDelta = data.mp - (stats?.mp ?: 0.0)
goldDelta = data.gp - (stats?.gp ?: 0.0)
level = data.lvl
questDamage = data._tmp?.quest?.progressDelta
questItemsFound = data._tmp?.quest?.collection
drop = data._tmp?.drop
}
var drop: TaskDirectionDataDrop? = null
var experienceDelta: Double? = null
var healthDelta: Double? = null