2023-07-23 09:20:48 +01:00
|
|
|
package main
|
|
|
|
|
2023-07-23 15:27:31 +01:00
|
|
|
import ()
|
2023-07-23 09:20:48 +01:00
|
|
|
|
2023-07-23 15:27:31 +01:00
|
|
|
// The player struct
|
2023-07-23 09:20:48 +01:00
|
|
|
type Player struct {
|
2023-07-23 15:27:31 +01:00
|
|
|
health int
|
2023-07-23 21:37:24 +01:00
|
|
|
health_max int
|
|
|
|
defence int
|
2023-07-23 15:27:31 +01:00
|
|
|
level int
|
|
|
|
exp float32
|
|
|
|
ambition float32
|
|
|
|
ambition_max float32
|
2023-07-23 09:20:48 +01:00
|
|
|
}
|
|
|
|
|
2023-07-23 15:27:31 +01:00
|
|
|
// Create the maps for the level/(max) ambition gates
|
|
|
|
var level_gates = make(map[int]float32)
|
|
|
|
var level_ambition = make(map[int]float32)
|
2023-07-23 09:20:48 +01:00
|
|
|
|
|
|
|
// TODO(midnadimple): Move player initialization to server upon login
|
|
|
|
func initPlayer() Player {
|
|
|
|
return Player{
|
2023-07-23 15:27:31 +01:00
|
|
|
health: 100,
|
2023-07-23 21:37:24 +01:00
|
|
|
health_max: 100,
|
|
|
|
defence: 0,
|
2023-07-23 15:27:31 +01:00
|
|
|
level: 1,
|
|
|
|
exp: 0.0,
|
|
|
|
ambition: 0.0, // NOTE(midnadimple): In the future this will be affected by player activity
|
|
|
|
ambition_max: level_ambition[1], // NOTE(midnadimple): In the future this will be affected by player activity
|
2023-07-23 09:20:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-23 15:27:31 +01:00
|
|
|
// Formula for XP gain - extremely simple
|
|
|
|
func gain(basexp float32, modifier float32) float32 {
|
|
|
|
gain := basexp * modifier
|
|
|
|
return gain
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the player
|
2023-07-23 09:20:48 +01:00
|
|
|
func (p *Player) update() {
|
|
|
|
// TODO(midnadimple): update health upon damage
|
2023-07-23 15:27:31 +01:00
|
|
|
|
|
|
|
// Auto-generate the level gates
|
|
|
|
level_gates[1] = 500
|
|
|
|
for i := 0; i <= 1000; i++ {
|
|
|
|
if i >= 2 {
|
|
|
|
switch {
|
|
|
|
case i <= 10:
|
|
|
|
level_gates[i] = level_gates[i-1] * 1.2
|
|
|
|
case (i <= 100) && (i > 10):
|
|
|
|
level_gates[i] = level_gates[i-1] * 1.1
|
|
|
|
case (i <= 1000) && (i > 100):
|
|
|
|
level_gates[i] = level_gates[i-1] * 1.005
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Auto-generate maximum ambition gates
|
|
|
|
level_ambition[1] = 10
|
|
|
|
for i := 0; i <= 1000; i++ {
|
|
|
|
if i >= 2 {
|
|
|
|
switch {
|
|
|
|
case i <= 10:
|
|
|
|
level_ambition[i] = level_ambition[i-1] * 1.1
|
|
|
|
case (i <= 100) && (i > 10):
|
|
|
|
level_ambition[i] = level_ambition[i-1] * 1.05
|
|
|
|
case (i <= 1000) && (i > 100):
|
|
|
|
level_ambition[i] = level_ambition[i-1] * 1.00005
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the XP to 0 and increase both the level and max ambition on level up
|
2023-07-23 09:20:48 +01:00
|
|
|
if p.exp >= level_gates[p.level] {
|
|
|
|
p.exp = 0.0
|
|
|
|
p.level += 1
|
2023-07-23 15:27:31 +01:00
|
|
|
p.ambition_max = level_ambition[p.level]
|
2023-07-23 09:20:48 +01:00
|
|
|
}
|
2023-07-23 15:27:31 +01:00
|
|
|
}
|