feat: entity definitions — player classes, monsters, items
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
96
entity/player.go
Normal file
96
entity/player.go
Normal file
@@ -0,0 +1,96 @@
|
||||
package entity
|
||||
|
||||
type Class int
|
||||
|
||||
const (
|
||||
ClassWarrior Class = iota
|
||||
ClassMage
|
||||
ClassHealer
|
||||
ClassRogue
|
||||
)
|
||||
|
||||
func (c Class) String() string {
|
||||
return [...]string{"Warrior", "Mage", "Healer", "Rogue"}[c]
|
||||
}
|
||||
|
||||
type classStats struct {
|
||||
HP, ATK, DEF int
|
||||
}
|
||||
|
||||
var classBaseStats = map[Class]classStats{
|
||||
ClassWarrior: {120, 12, 8},
|
||||
ClassMage: {70, 20, 3},
|
||||
ClassHealer: {90, 8, 5},
|
||||
ClassRogue: {85, 15, 4},
|
||||
}
|
||||
|
||||
type Player struct {
|
||||
Name string
|
||||
Fingerprint string
|
||||
Class Class
|
||||
HP, MaxHP int
|
||||
ATK, DEF int
|
||||
Gold int
|
||||
Inventory []Item
|
||||
Relics []Relic
|
||||
Dead bool
|
||||
}
|
||||
|
||||
func NewPlayer(name string, class Class) *Player {
|
||||
stats := classBaseStats[class]
|
||||
return &Player{
|
||||
Name: name,
|
||||
Class: class,
|
||||
HP: stats.HP,
|
||||
MaxHP: stats.HP,
|
||||
ATK: stats.ATK,
|
||||
DEF: stats.DEF,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) TakeDamage(dmg int) {
|
||||
p.HP -= dmg
|
||||
if p.HP <= 0 {
|
||||
p.HP = 0
|
||||
p.Dead = true
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) Heal(amount int) {
|
||||
p.HP += amount
|
||||
if p.HP > p.MaxHP {
|
||||
p.HP = p.MaxHP
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) IsDead() bool {
|
||||
return p.Dead
|
||||
}
|
||||
|
||||
func (p *Player) Revive(hpPercent float64) {
|
||||
p.Dead = false
|
||||
p.HP = int(float64(p.MaxHP) * hpPercent)
|
||||
if p.HP < 1 {
|
||||
p.HP = 1
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Player) EffectiveATK() int {
|
||||
atk := p.ATK
|
||||
for _, item := range p.Inventory {
|
||||
if item.Type == ItemWeapon {
|
||||
atk += item.Bonus
|
||||
}
|
||||
}
|
||||
return atk
|
||||
}
|
||||
|
||||
func (p *Player) EffectiveDEF() int {
|
||||
def := p.DEF
|
||||
for _, item := range p.Inventory {
|
||||
if item.Type == ItemArmor {
|
||||
def += item.Bonus
|
||||
}
|
||||
}
|
||||
return def
|
||||
}
|
||||
Reference in New Issue
Block a user