add monster images, fix level up calc

This commit is contained in:
Sky Johnson 2025-08-22 10:04:23 -05:00
parent 8a3486487b
commit 49bf5f28cf
16 changed files with 40 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 54 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

View File

@ -32,19 +32,16 @@ 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)
r.UserUpdates = map[string]any{ r.UserUpdates = map[string]any{
"fight_id": 0, "fight_id": 0,
"currently": "Exploring", "currently": "Exploring",
"gold": user.Gold + rewardGold, "gold": user.Gold + rewardGold,
"exp": user.Exp + rewardExp, "exp": newExp,
} "level": newLevel,
"strength": newStr,
// Handle level up "dexterity": newDex,
newLevel, newStats := calculateLevelUp(user.Level, user.Exp+rewardExp, user.Strength, user.Dexterity)
if newLevel > user.Level {
r.UserUpdates["level"] = newLevel
r.UserUpdates["strength"] = newStats.Strength
r.UserUpdates["dexterity"] = newStats.Dexterity
} }
r.Ended = true r.Ended = true
@ -295,17 +292,11 @@ func calculateRewards(monster *monsters.Monster, user *users.User) (int, int) {
// More generous reward range: 90-100% of max instead of 83-100% // More generous reward range: 90-100% of max instead of 83-100%
minExp := (monster.MaxExp * 9) / 10 minExp := (monster.MaxExp * 9) / 10
maxExp := monster.MaxExp maxExp := monster.MaxExp
exp := rand.Intn(maxExp-minExp+1) + minExp exp := max(rand.Intn(maxExp-minExp+1)+minExp, 1)
if exp < 1 {
exp = 1 // Guaranteed minimum
}
minGold := (monster.MaxGold * 9) / 10 minGold := (monster.MaxGold * 9) / 10
maxGold := monster.MaxGold maxGold := monster.MaxGold
gold := rand.Intn(maxGold-minGold+1) + minGold gold := max(rand.Intn(maxGold-minGold+1)+minGold, 1)
if gold < 1 {
gold = 1 // Guaranteed minimum
}
// Apply bonuses // Apply bonuses
expBonus := (user.ExpBonus * exp) / 100 expBonus := (user.ExpBonus * exp) / 100

View File

@ -279,29 +279,42 @@ func (u *User) ExpNeededForNextLevel() int {
return exp.Calc(u.Level + 1) return exp.Calc(u.Level + 1)
} }
func (u *User) GrantExp(expAmount int) { func (u *User) GrantExp(expAmount int) map[string]any {
u.Exp += expAmount newLevel, newStr, newDex, newExp := u.CalculateLevelUp(expAmount)
u.checkLevelUp()
updates := map[string]any{
"exp": newExp,
}
// Only include level/stats if they actually changed
if newLevel > u.Level {
updates["level"] = newLevel
updates["strength"] = newStr
updates["dexterity"] = newDex
}
return updates
} }
func (u *User) checkLevelUp() { func (u *User) CalculateLevelUp(expGain int) (newLevel, newStr, newDex, newExp int) {
expNeeded := u.ExpNeededForNextLevel() level := u.Level
str := u.Strength
dex := u.Dexterity
totalExp := u.Exp + expGain
if u.Exp >= expNeeded { for {
// Level up expNeeded := exp.Calc(level + 1)
u.Level++ if totalExp < expNeeded {
u.Strength++ break
u.Dexterity++
// Reset exp and carry over excess
excessExp := u.Exp - expNeeded
u.Exp = 0
// Recursive level up if enough excess exp
if excessExp > 0 {
u.GrantExp(excessExp)
} }
level++
str++
dex++
totalExp -= expNeeded
} }
return level, str, dex, totalExp
} }
func (u *User) ExpProgress() float64 { func (u *User) ExpProgress() float64 {

View File

@ -5,7 +5,7 @@
<h2>{monster.Name}</h2> <h2>{monster.Name}</h2>
<h3>Level {monster.Level}</h3> <h3>Level {monster.Level}</h3>
<img id="monster-image" src="/assets/images/monsters/{monster.Name}.png" alt="{monster.Name}" title="{monster.Name}"> <img id="monster-image" src="/assets/images/monsters/{monster.Name}.png" alt="{monster.Name}" title="{monster.Name}" onerror="this.onerror=null; this.src='/assets/images/monsters/Arcane Crystal.png';">
</div> </div>
<div>{action}</div> <div>{action}</div>