fix lots of fight/level up components
This commit is contained in:
parent
73d946e011
commit
4288619520
BIN
data/dk.db
BIN
data/dk.db
Binary file not shown.
@ -9,6 +9,7 @@ import (
|
|||||||
"dk/internal/models/towns"
|
"dk/internal/models/towns"
|
||||||
"dk/internal/models/users"
|
"dk/internal/models/users"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"maps"
|
||||||
"math"
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
)
|
)
|
||||||
@ -33,18 +34,18 @@ func (r *FightResult) EndFightWithVictory(monster *monsters.Monster, user *users
|
|||||||
r.FightUpdates["reward_gold"] = rewardGold
|
r.FightUpdates["reward_gold"] = rewardGold
|
||||||
r.FightUpdates["reward_exp"] = rewardExp
|
r.FightUpdates["reward_exp"] = rewardExp
|
||||||
|
|
||||||
newLevel, newStr, newDex, newExp := user.CalculateLevelUp(rewardExp)
|
levelUpResults := user.GrantExp(rewardExp)
|
||||||
|
|
||||||
r.UserUpdates = map[string]any{
|
if r.UserUpdates == nil {
|
||||||
"fight_id": 0,
|
r.UserUpdates = make(map[string]any)
|
||||||
"currently": "Exploring",
|
|
||||||
"gold": user.Gold + rewardGold,
|
|
||||||
"exp": newExp,
|
|
||||||
"level": newLevel,
|
|
||||||
"strength": newStr,
|
|
||||||
"dexterity": newDex,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.UserUpdates["fight_id"] = 0
|
||||||
|
r.UserUpdates["currently"] = "Exploring"
|
||||||
|
r.UserUpdates["gold"] = user.Gold + rewardGold
|
||||||
|
|
||||||
|
maps.Copy(r.UserUpdates, levelUpResults)
|
||||||
|
|
||||||
r.Ended = true
|
r.Ended = true
|
||||||
r.Victory = true
|
r.Victory = true
|
||||||
r.Won = true
|
r.Won = true
|
||||||
@ -167,6 +168,7 @@ func HandleSpell(fight *fights.Fight, user *users.User, spellID int) *FightResul
|
|||||||
monster, err := monsters.Find(fight.MonsterID)
|
monster, err := monsters.Find(fight.MonsterID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result.EndFightWithVictory(monster, user)
|
result.EndFightWithVictory(monster, user)
|
||||||
|
result.UserUpdates["mp"] = user.MP - spell.MP
|
||||||
result.ActionText += " " + fmt.Sprintf("%s has been defeated!", monster.Name)
|
result.ActionText += " " + fmt.Sprintf("%s has been defeated!", monster.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -182,6 +184,7 @@ func HandleSpell(fight *fights.Fight, user *users.User, spellID int) *FightResul
|
|||||||
monster, err := monsters.Find(fight.MonsterID)
|
monster, err := monsters.Find(fight.MonsterID)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result.EndFightWithVictory(monster, user)
|
result.EndFightWithVictory(monster, user)
|
||||||
|
result.UserUpdates["mp"] = user.MP - spell.MP
|
||||||
result.ActionText += " " + fmt.Sprintf("%s has been defeated!", monster.Name)
|
result.ActionText += " " + fmt.Sprintf("%s has been defeated!", monster.Name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,16 @@ func RightAside(ctx sushi.Ctx) map[string]any {
|
|||||||
user := ctx.GetCurrentUser().(*users.User)
|
user := ctx.GetCurrentUser().(*users.User)
|
||||||
data["_class"] = user.Class()
|
data["_class"] = user.Class()
|
||||||
|
|
||||||
|
if user.Level == 1 {
|
||||||
|
data["_exp_display"] = user.Exp
|
||||||
|
data["_exp_needed"] = helpers.ExpAtLevel(2)
|
||||||
|
} else {
|
||||||
|
currentLevelExp := helpers.ExpAtLevel(user.Level)
|
||||||
|
nextLevelExp := helpers.ExpAtLevel(user.Level + 1)
|
||||||
|
data["_exp_display"] = user.Exp - currentLevelExp
|
||||||
|
data["_exp_needed"] = nextLevelExp - currentLevelExp
|
||||||
|
}
|
||||||
|
|
||||||
data["_expprog"] = fmt.Sprintf("%.1f", user.ExpProgress())
|
data["_expprog"] = fmt.Sprintf("%.1f", user.ExpProgress())
|
||||||
|
|
||||||
hpPct := helpers.ClampPct(float64(user.HP), float64(user.MaxHP), 0, 100)
|
hpPct := helpers.ClampPct(float64(user.HP), float64(user.MaxHP), 0, 100)
|
||||||
|
@ -295,17 +295,22 @@ func (u *User) ExpNeededForNextLevel() int {
|
|||||||
|
|
||||||
func (u *User) GrantExp(expAmount int) map[string]any {
|
func (u *User) GrantExp(expAmount int) map[string]any {
|
||||||
oldLevel := u.Level
|
oldLevel := u.Level
|
||||||
newLevel, newStr, newDex, newExp := u.CalculateLevelUp(expAmount)
|
results := u.CalculateLevelUp(expAmount)
|
||||||
|
|
||||||
updates := map[string]any{
|
updates := map[string]any{
|
||||||
"exp": newExp,
|
"exp": results["exp"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newLevel := results["level"].(int)
|
||||||
|
|
||||||
// Only include level/stats if they actually changed
|
// Only include level/stats if they actually changed
|
||||||
if newLevel > oldLevel {
|
if newLevel > oldLevel {
|
||||||
updates["level"] = newLevel
|
updates["level"] = newLevel
|
||||||
updates["strength"] = newStr
|
updates["strength"] = results["strength"]
|
||||||
updates["dexterity"] = newDex
|
updates["dexterity"] = results["dexterity"]
|
||||||
|
updates["max_hp"] = results["max_hp"]
|
||||||
|
updates["max_mp"] = results["max_mp"]
|
||||||
|
updates["max_tp"] = results["max_tp"]
|
||||||
|
|
||||||
// Learn new spells for each level gained
|
// Learn new spells for each level gained
|
||||||
for level := oldLevel + 1; level <= newLevel; level++ {
|
for level := oldLevel + 1; level <= newLevel; level++ {
|
||||||
@ -319,10 +324,15 @@ func (u *User) GrantExp(expAmount int) map[string]any {
|
|||||||
return updates
|
return updates
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) CalculateLevelUp(expGain int) (newLevel, newStr, newDex, newExp int) {
|
func (u *User) CalculateLevelUp(expGain int) map[string]any {
|
||||||
|
class := u.Class()
|
||||||
|
|
||||||
level := u.Level
|
level := u.Level
|
||||||
str := u.Strength
|
str := u.Strength
|
||||||
dex := u.Dexterity
|
dex := u.Dexterity
|
||||||
|
maxHP := u.MaxHP
|
||||||
|
maxMP := u.MaxMP
|
||||||
|
maxTP := u.MaxTP
|
||||||
totalExp := u.Exp + expGain
|
totalExp := u.Exp + expGain
|
||||||
|
|
||||||
for {
|
for {
|
||||||
@ -332,24 +342,36 @@ func (u *User) CalculateLevelUp(expGain int) (newLevel, newStr, newDex, newExp i
|
|||||||
}
|
}
|
||||||
|
|
||||||
level++
|
level++
|
||||||
str++
|
str += class.RateSTR
|
||||||
dex++
|
dex += class.RateDEX
|
||||||
totalExp -= expNeeded
|
maxHP += class.RateHP
|
||||||
|
maxMP += class.RateMP
|
||||||
|
maxTP += 2
|
||||||
}
|
}
|
||||||
|
|
||||||
return level, str, dex, totalExp
|
return map[string]any{
|
||||||
|
"level": level,
|
||||||
|
"strength": str,
|
||||||
|
"dexterity": dex,
|
||||||
|
"max_hp": maxHP,
|
||||||
|
"max_mp": maxMP,
|
||||||
|
"max_tp": maxTP,
|
||||||
|
"exp": totalExp,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) ExpProgress() float64 {
|
func (u *User) ExpProgress() float64 {
|
||||||
|
nextLevelExp := helpers.ExpAtLevel(u.Level + 1)
|
||||||
|
|
||||||
if u.Level == 1 {
|
if u.Level == 1 {
|
||||||
return float64(u.Exp) / float64(u.ExpNeededForNextLevel()) * 100
|
return float64(u.Exp) / float64(nextLevelExp) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
currentLevelExp := helpers.ExpAtLevel(u.Level)
|
currentLevelExp := helpers.ExpAtLevel(u.Level)
|
||||||
nextLevelExp := u.ExpNeededForNextLevel()
|
expIntoLevel := u.Exp - currentLevelExp
|
||||||
progressExp := u.Exp
|
expNeededForLevel := nextLevelExp - currentLevelExp
|
||||||
|
|
||||||
return float64(progressExp) / float64(nextLevelExp-currentLevelExp) * 100
|
return float64(expIntoLevel) / float64(expNeededForLevel) * 100
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *User) Class() *classes.Class {
|
func (u *User) Class() *classes.Class {
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<ul class="unstyled">
|
<ul class="unstyled">
|
||||||
<li><b>{user.Username}</b></li>
|
<li><b>{user.Username}</b></li>
|
||||||
<li>Level {user.Level} {_class.Name}</li>
|
<li>Level {user.Level} {_class.Name}</li>
|
||||||
<li>Exp: {user.Exp} ({_expprog}%)</li>
|
<li>Exp: {_exp_display} ({_expprog}%)</li>
|
||||||
<li>Gold: {user.Gold}</li>
|
<li>Gold: {user.Gold}</li>
|
||||||
<li>HP: {user.HP}/{user.MaxHP}</li>
|
<li>HP: {user.HP}/{user.MaxHP}</li>
|
||||||
<li>MP: {user.MP}/{user.MaxMP}</li>
|
<li>MP: {user.MP}/{user.MaxMP}</li>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user