last_light/game/player/player.go

68 lines
1.3 KiB
Go
Raw Normal View History

2024-05-21 23:08:51 +03:00
package player
2024-04-24 17:11:33 +03:00
import (
2024-05-06 21:19:08 +03:00
"mvvasilev/last_light/engine"
2024-05-21 23:08:51 +03:00
"mvvasilev/last_light/game/item"
"mvvasilev/last_light/game/rpg"
2024-04-24 17:11:33 +03:00
"github.com/gdamore/tcell/v2"
"github.com/google/uuid"
)
type Player struct {
id uuid.UUID
2024-05-06 21:19:08 +03:00
position engine.Position
2024-05-03 13:46:32 +03:00
2024-05-21 23:08:51 +03:00
inventory *item.EquippedInventory
*rpg.BasicRPGEntity
2024-04-24 17:11:33 +03:00
}
2024-05-31 23:37:06 +03:00
func CreatePlayer(x, y int, playerStats map[rpg.Stat]int) *Player {
2024-04-24 17:11:33 +03:00
p := new(Player)
p.id = uuid.New()
2024-05-06 21:19:08 +03:00
p.position = engine.PositionAt(x, y)
2024-05-21 23:08:51 +03:00
p.inventory = item.CreateEquippedInventory()
2024-05-30 23:39:54 +03:00
p.BasicRPGEntity = rpg.CreateBasicRPGEntity(
2024-06-01 11:20:51 +03:00
0,
2024-05-31 23:37:06 +03:00
playerStats,
2024-05-30 23:39:54 +03:00
map[rpg.Stat][]rpg.StatModifier{},
)
2024-04-24 17:11:33 +03:00
2024-06-01 11:20:51 +03:00
p.Heal(rpg.BaseMaxHealth(p))
2024-04-24 17:11:33 +03:00
return p
}
func (p *Player) UniqueId() uuid.UUID {
return p.id
}
2024-05-06 21:19:08 +03:00
func (p *Player) Position() engine.Position {
return p.position
}
2024-05-06 21:19:08 +03:00
func (p *Player) MoveTo(newPos engine.Position) {
2024-05-06 18:59:14 +03:00
p.position = newPos
}
2024-04-24 17:11:33 +03:00
2024-05-03 13:46:32 +03:00
func (p *Player) Presentation() (rune, tcell.Style) {
return '@', tcell.StyleDefault
2024-04-24 17:11:33 +03:00
}
2024-05-21 23:08:51 +03:00
func (p *Player) Inventory() *item.EquippedInventory {
2024-05-03 13:46:32 +03:00
return p.inventory
}
2024-06-01 11:20:51 +03:00
func (p *Player) CalculateAttack(other rpg.RPGEntity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType rpg.DamageType) {
mainHand := p.inventory.AtSlot(item.EquippedSlotDominantHand)
2024-04-24 17:11:33 +03:00
2024-06-01 11:20:51 +03:00
switch mh := mainHand.(type) {
case rpg.RPGItem:
return rpg.PhysicalWeaponAttack(p, mh, other)
default:
return rpg.UnarmedAttack(p, other)
}
2024-04-24 17:11:33 +03:00
}