Rename all V2 stuff

This commit is contained in:
Miroslav Vasilev 2024-06-06 23:28:06 +03:00
parent ec51edb7c0
commit 82bc886b88
25 changed files with 200 additions and 997 deletions

View file

@ -47,24 +47,6 @@ func MovementDirectionOffset(dir Direction) (int, int) {
return 0, 0
}
// type Entity interface {
// UniqueId() uuid.UUID
// Presentation() (rune, tcell.Style)
// }
// type MovableEntity interface {
// Position() engine.Position
// MoveTo(newPosition engine.Position)
// Entity
// }
// type EquippedEntity interface {
// Inventory() *EquippedInventory
// Entity
// }
type Entity_NamedComponent struct {
Name string
}
@ -97,7 +79,7 @@ type Entity_HealthComponent struct {
IsDead bool
}
type Entity_V2 interface {
type Entity interface {
UniqueId() uuid.UUID
Named() *Entity_NamedComponent
@ -109,7 +91,7 @@ type Entity_V2 interface {
HealthData() *Entity_HealthComponent
}
type BaseEntity_V2 struct {
type BaseEntity struct {
id uuid.UUID
named *Entity_NamedComponent
@ -121,40 +103,40 @@ type BaseEntity_V2 struct {
damageable *Entity_HealthComponent
}
func (be *BaseEntity_V2) UniqueId() uuid.UUID {
func (be *BaseEntity) UniqueId() uuid.UUID {
return be.id
}
func (be *BaseEntity_V2) Named() *Entity_NamedComponent {
func (be *BaseEntity) Named() *Entity_NamedComponent {
return be.named
}
func (be *BaseEntity_V2) Described() *Entity_DescribedComponent {
func (be *BaseEntity) Described() *Entity_DescribedComponent {
return be.described
}
func (be *BaseEntity_V2) Presentable() *Entity_PresentableComponent {
func (be *BaseEntity) Presentable() *Entity_PresentableComponent {
return be.presentable
}
func (be *BaseEntity_V2) Positioned() *Entity_PositionedComponent {
func (be *BaseEntity) Positioned() *Entity_PositionedComponent {
return be.positioned
}
func (be *BaseEntity_V2) Equipped() *Entity_EquippedComponent {
func (be *BaseEntity) Equipped() *Entity_EquippedComponent {
return be.equipped
}
func (be *BaseEntity_V2) Stats() *Entity_StatsHolderComponent {
func (be *BaseEntity) Stats() *Entity_StatsHolderComponent {
return be.stats
}
func (be *BaseEntity_V2) HealthData() *Entity_HealthComponent {
func (be *BaseEntity) HealthData() *Entity_HealthComponent {
return be.damageable
}
func CreateEntity(components ...func(*BaseEntity_V2)) *BaseEntity_V2 {
e := &BaseEntity_V2{
func CreateEntity(components ...func(*BaseEntity)) *BaseEntity {
e := &BaseEntity{
id: uuid.New(),
}
@ -165,24 +147,24 @@ func CreateEntity(components ...func(*BaseEntity_V2)) *BaseEntity_V2 {
return e
}
func WithName(name string) func(*BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithName(name string) func(*BaseEntity) {
return func(e *BaseEntity) {
e.named = &Entity_NamedComponent{
Name: name,
}
}
}
func WithDescription(description string) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithDescription(description string) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.described = &Entity_DescribedComponent{
Description: description,
}
}
}
func WithPresentation(symbol rune, style tcell.Style) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithPresentation(symbol rune, style tcell.Style) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.presentable = &Entity_PresentableComponent{
Rune: symbol,
Style: style,
@ -190,24 +172,24 @@ func WithPresentation(symbol rune, style tcell.Style) func(e *BaseEntity_V2) {
}
}
func WithPosition(pos engine.Position) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithPosition(pos engine.Position) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.positioned = &Entity_PositionedComponent{
Position: pos,
}
}
}
func WithInventory(inv *EquippedInventory) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithInventory(inv *EquippedInventory) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.equipped = &Entity_EquippedComponent{
Inventory: inv,
}
}
}
func WithStats(baseStats map[Stat]int, statModifiers ...StatModifier) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithStats(baseStats map[Stat]int, statModifiers ...StatModifier) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.stats = &Entity_StatsHolderComponent{
BaseStats: baseStats,
// StatModifiers: statModifiers,
@ -215,8 +197,8 @@ func WithStats(baseStats map[Stat]int, statModifiers ...StatModifier) func(e *Ba
}
}
func WithHealthData(health, maxHealth int, isDead bool) func(e *BaseEntity_V2) {
return func(e *BaseEntity_V2) {
func WithHealthData(health, maxHealth int, isDead bool) func(e *BaseEntity) {
return func(e *BaseEntity) {
e.damageable = &Entity_HealthComponent{
Health: health,
MaxHealth: maxHealth,

View file

@ -1 +0,0 @@
package model

View file

@ -6,13 +6,13 @@ import (
"github.com/gdamore/tcell/v2"
)
type Player_V2 struct {
Entity_V2
type Player struct {
Entity
}
func CreatePlayer_V2(x, y int, playerBaseStats map[Stat]int) *Player_V2 {
p := &Player_V2{
Entity_V2: CreateEntity(
func CreatePlayer(x, y int, playerBaseStats map[Stat]int) *Player {
p := &Player{
Entity: CreateEntity(
WithName("Player"),
WithPosition(engine.PositionAt(x, y)),
WithPresentation('@', tcell.StyleDefault),
@ -28,22 +28,22 @@ func CreatePlayer_V2(x, y int, playerBaseStats map[Stat]int) *Player_V2 {
return p
}
func (p *Player_V2) Inventory() *EquippedInventory {
return p.Entity_V2.Equipped().Inventory
func (p *Player) Inventory() *EquippedInventory {
return p.Entity.Equipped().Inventory
}
func (p *Player_V2) Position() engine.Position {
return p.Entity_V2.Positioned().Position
func (p *Player) Position() engine.Position {
return p.Entity.Positioned().Position
}
func (p *Player_V2) Presentation() (rune, tcell.Style) {
func (p *Player) Presentation() (rune, tcell.Style) {
return p.Presentable().Rune, p.Presentable().Style
}
func (p *Player_V2) Stats() *Entity_StatsHolderComponent {
return p.Entity_V2.Stats()
func (p *Player) Stats() *Entity_StatsHolderComponent {
return p.Entity.Stats()
}
func (p *Player_V2) HealthData() *Entity_HealthComponent {
return p.Entity_V2.HealthData()
func (p *Player) HealthData() *Entity_HealthComponent {
return p.Entity.HealthData()
}

View file

@ -1,57 +0,0 @@
package model
// import (
// "mvvasilev/last_light/engine"
// "mvvasilev/last_light/game/item"
// "mvvasilev/last_light/game/rpg"
// "github.com/gdamore/tcell/v2"
// )
// type RPGNPC interface {
// NPC
// rpg.RPGEntity
// EquippedEntity
// }
// type BasicRPGNPC struct {
// inventory *item.EquippedInventory
// *BasicNPC
// *rpg.BasicRPGEntity
// }
// func CreateRPGNPC(x, y int, name string, representation rune, style tcell.Style, stats map[rpg.Stat]int) *BasicRPGNPC {
// rpgnpc := &BasicRPGNPC{
// inventory: item.CreateEquippedInventory(),
// BasicNPC: CreateNPC(
// engine.PositionAt(x, y),
// name,
// representation,
// style,
// ),
// BasicRPGEntity: rpg.CreateBasicRPGEntity(
// stats,
// map[rpg.Stat][]rpg.StatModifier{},
// ),
// }
// rpgnpc.Heal(rpg.BaseMaxHealth(rpgnpc))
// return rpgnpc
// }
// func (rnpc *BasicRPGNPC) Inventory() *item.EquippedInventory {
// return rnpc.inventory
// }
// func (p *BasicRPGNPC) CalculateAttack(other rpg.RPGEntity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType rpg.DamageType) {
// mainHand := p.inventory.AtSlot(item.EquippedSlotDominantHand)
// switch mh := mainHand.(type) {
// case rpg.RPGItem:
// return rpg.PhysicalWeaponAttack(p, mh, other)
// default:
// return rpg.UnarmedAttack(p, other)
// }
// }

View file

@ -5,28 +5,28 @@ import (
)
type Inventory interface {
Items() []Item_V2
Items() []Item
Shape() engine.Size
Push(item Item_V2) bool
Drop(x, y int) Item_V2
ItemAt(x, y int) Item_V2
Push(item Item) bool
Drop(x, y int) Item
ItemAt(x, y int) Item
}
type BasicInventory struct {
contents []Item_V2
contents []Item
shape engine.Size
}
func CreateInventory(shape engine.Size) *BasicInventory {
inv := new(BasicInventory)
inv.contents = make([]Item_V2, 0, shape.Height()*shape.Width())
inv.contents = make([]Item, 0, shape.Height()*shape.Width())
inv.shape = shape
return inv
}
func (i *BasicInventory) Items() (items []Item_V2) {
func (i *BasicInventory) Items() (items []Item) {
return i.contents
}
@ -34,7 +34,7 @@ func (i *BasicInventory) Shape() engine.Size {
return i.shape
}
func (inv *BasicInventory) Push(i Item_V2) (success bool) {
func (inv *BasicInventory) Push(i Item) (success bool) {
if len(inv.contents) == inv.shape.Area() {
return false
}
@ -91,7 +91,7 @@ func (inv *BasicInventory) Push(i Item_V2) (success bool) {
return true
}
func (i *BasicInventory) Drop(x, y int) Item_V2 {
func (i *BasicInventory) Drop(x, y int) Item {
index := y*i.shape.Width() + x
if index > len(i.contents)-1 {
@ -125,7 +125,7 @@ func (i *BasicInventory) ReduceQuantityAt(x, y int, amount int) {
}
}
func (i *BasicInventory) ItemAt(x, y int) (item Item_V2) {
func (i *BasicInventory) ItemAt(x, y int) (item Item) {
index := y*i.shape.Width() + x
if index > len(i.contents)-1 {

View file

@ -18,13 +18,13 @@ const (
)
type EquippedInventory struct {
offHand Item_V2
dominantHand Item_V2
offHand Item
dominantHand Item
head Item_V2
chestplate Item_V2
leggings Item_V2
shoes Item_V2
head Item
chestplate Item
leggings Item
shoes Item
*BasicInventory
}
@ -35,7 +35,7 @@ func CreateEquippedInventory() *EquippedInventory {
}
}
func (ei *EquippedInventory) AtSlot(slot EquippedSlot) Item_V2 {
func (ei *EquippedInventory) AtSlot(slot EquippedSlot) Item {
switch slot {
case EquippedSlotOffhand:
return ei.offHand
@ -54,7 +54,7 @@ func (ei *EquippedInventory) AtSlot(slot EquippedSlot) Item_V2 {
}
}
func (ei *EquippedInventory) Equip(item Item_V2, slot EquippedSlot) Item_V2 {
func (ei *EquippedInventory) Equip(item Item, slot EquippedSlot) Item {
switch slot {
case EquippedSlotOffhand:
ei.offHand = item

View file

@ -19,7 +19,7 @@ const (
MetaItemType_Potion
)
type Item_V2 interface {
type Item interface {
TileIcon() rune
Icon() string
Style() tcell.Style
@ -41,8 +41,8 @@ type Item_QuantifiableComponent struct {
}
type Item_UsableComponent struct {
IsUsableBy func(Entity_V2) bool
Use func(*engine.GameEventLog, *Dungeon, Entity_V2)
IsUsableBy func(Entity) bool
Use func(*engine.GameEventLog, *Dungeon, Entity)
}
type Item_EquippableComponent struct {
@ -71,7 +71,7 @@ type Item_MetaTypesComponent struct {
Types []ItemMetaType
}
type BaseItem_V2 struct {
type BaseItem struct {
tileIcon rune
icon string
style tcell.Style
@ -87,56 +87,56 @@ type BaseItem_V2 struct {
metaTypes *Item_MetaTypesComponent
}
func (i *BaseItem_V2) TileIcon() rune {
func (i *BaseItem) TileIcon() rune {
return i.tileIcon
}
func (i *BaseItem_V2) Icon() string {
func (i *BaseItem) Icon() string {
return i.icon
}
func (i *BaseItem_V2) Style() tcell.Style {
func (i *BaseItem) Style() tcell.Style {
return i.style
}
func (i *BaseItem_V2) Type() ItemType {
func (i *BaseItem) Type() ItemType {
return i.itemType
}
func (i *BaseItem_V2) Quantifiable() *Item_QuantifiableComponent {
func (i *BaseItem) Quantifiable() *Item_QuantifiableComponent {
return i.quantifiable
}
func (i *BaseItem_V2) Usable() *Item_UsableComponent {
func (i *BaseItem) Usable() *Item_UsableComponent {
return i.usable
}
func (i *BaseItem_V2) Equippable() *Item_EquippableComponent {
func (i *BaseItem) Equippable() *Item_EquippableComponent {
return i.equippable
}
func (i *BaseItem_V2) Named() *Item_NamedComponent {
func (i *BaseItem) Named() *Item_NamedComponent {
return i.named
}
func (i *BaseItem_V2) Described() *Item_DescribedComponent {
func (i *BaseItem) Described() *Item_DescribedComponent {
return i.described
}
func (i *BaseItem_V2) Damaging() *Item_DamagingComponent {
func (i *BaseItem) Damaging() *Item_DamagingComponent {
return i.damaging
}
func (i *BaseItem_V2) StatModifier() *Item_StatModifierComponent {
func (i *BaseItem) StatModifier() *Item_StatModifierComponent {
return i.statModifier
}
func (i *BaseItem_V2) MetaTypes() *Item_MetaTypesComponent {
func (i *BaseItem) MetaTypes() *Item_MetaTypesComponent {
return i.metaTypes
}
func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.Style, components ...func(*BaseItem_V2)) *BaseItem_V2 {
i := &BaseItem_V2{
func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.Style, components ...func(*BaseItem)) *BaseItem {
i := &BaseItem{
itemType: itemType,
tileIcon: tileIcon,
icon: icon,
@ -150,8 +150,8 @@ func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.S
return i
}
func item_WithQuantity(quantity, maxQuantity int) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithQuantity(quantity, maxQuantity int) func(*BaseItem) {
return func(bi *BaseItem) {
bi.quantifiable = &Item_QuantifiableComponent{
CurrentQuantity: quantity,
MaxQuantity: maxQuantity,
@ -159,8 +159,8 @@ func item_WithQuantity(quantity, maxQuantity int) func(*BaseItem_V2) {
}
}
func item_WithUsable(usabilityCheck func(Entity_V2) bool, useFunc func(*engine.GameEventLog, *Dungeon, Entity_V2)) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithUsable(usabilityCheck func(Entity) bool, useFunc func(*engine.GameEventLog, *Dungeon, Entity)) func(*BaseItem) {
return func(bi *BaseItem) {
bi.usable = &Item_UsableComponent{
IsUsableBy: usabilityCheck,
Use: useFunc,
@ -168,24 +168,24 @@ func item_WithUsable(usabilityCheck func(Entity_V2) bool, useFunc func(*engine.G
}
}
func item_WithEquippable(slot EquippedSlot) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithEquippable(slot EquippedSlot) func(*BaseItem) {
return func(bi *BaseItem) {
bi.equippable = &Item_EquippableComponent{
Slot: slot,
}
}
}
func item_WithDamaging(damageFunc func() (damage int, dmgType DamageType)) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithDamaging(damageFunc func() (damage int, dmgType DamageType)) func(*BaseItem) {
return func(bi *BaseItem) {
bi.damaging = &Item_DamagingComponent{
DamageRoll: damageFunc,
}
}
}
func item_WithName(name string, style tcell.Style) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithName(name string, style tcell.Style) func(*BaseItem) {
return func(bi *BaseItem) {
bi.named = &Item_NamedComponent{
Name: name,
Style: style,
@ -193,8 +193,8 @@ func item_WithName(name string, style tcell.Style) func(*BaseItem_V2) {
}
}
func item_WithDescription(description string, style tcell.Style) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithDescription(description string, style tcell.Style) func(*BaseItem) {
return func(bi *BaseItem) {
bi.described = &Item_DescribedComponent{
Description: description,
Style: style,
@ -202,107 +202,18 @@ func item_WithDescription(description string, style tcell.Style) func(*BaseItem_
}
}
func item_WithStatModifiers(statModifiers []StatModifier) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithStatModifiers(statModifiers []StatModifier) func(*BaseItem) {
return func(bi *BaseItem) {
bi.statModifier = &Item_StatModifierComponent{
StatModifiers: statModifiers,
}
}
}
func item_WithMetaTypes(metaTypes []ItemMetaType) func(*BaseItem_V2) {
return func(bi *BaseItem_V2) {
func item_WithMetaTypes(metaTypes []ItemMetaType) func(*BaseItem) {
return func(bi *BaseItem) {
bi.metaTypes = &Item_MetaTypesComponent{
Types: metaTypes,
}
}
}
// type Item interface {
// Name() (string, tcell.Style)
// Description() string
// Type() ItemType
// Quantity() int
// SetQuantity(quant int) Item
// }
// type BasicItem struct {
// name string
// nameStyle tcell.Style
// description string
// itemType ItemType
// quantity int
// }
// func EmptyItem() BasicItem {
// return BasicItem{
// nameStyle: tcell.StyleDefault,
// itemType: &BasicItemType{
// name: "",
// description: "",
// tileIcon: ' ',
// itemIcon: " ",
// style: tcell.StyleDefault,
// maxStack: 0,
// },
// }
// }
// func CreateBasicItem(itemType ItemType, quantity int) BasicItem {
// return BasicItem{
// itemType: itemType,
// quantity: quantity,
// }
// }
// func CreateBasicItemWithName(name string, style tcell.Style, itemType ItemType, quantity int) BasicItem {
// return BasicItem{
// name: name,
// nameStyle: style,
// itemType: itemType,
// quantity: quantity,
// }
// }
// func (i BasicItem) WithName(name string, style tcell.Style) BasicItem {
// i.name = name
// i.nameStyle = style
// return i
// }
// func (i BasicItem) Name() (string, tcell.Style) {
// if i.name == "" {
// return i.itemType.Name(), i.nameStyle
// }
// return i.name, i.nameStyle
// }
// func (i BasicItem) Description() string {
// if i.description == "" {
// return i.itemType.Description()
// }
// return i.description
// }
// func (i BasicItem) WithDescription(description string) BasicItem {
// i.description = description
// return i
// }
// func (i BasicItem) Type() ItemType {
// return i.itemType
// }
// func (i BasicItem) Quantity() int {
// return i.quantity
// }
// func (i BasicItem) SetQuantity(amount int) Item {
// i.quantity = i.quantity - amount
// return i
// }

View file

@ -34,7 +34,7 @@ const (
// Special
)
func Item_Fish() Item_V2 {
func Item_Fish() Item {
return createBaseItem(
ItemType_Fish,
'>',
@ -44,10 +44,10 @@ func Item_Fish() Item_V2 {
item_WithName("Fish", tcell.StyleDefault),
item_WithDescription("On use heals for 1d4", tcell.StyleDefault),
item_WithUsable(
func(e Entity_V2) bool {
func(e Entity) bool {
return e.HealthData() != nil
},
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) {
func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData()
if damageable != nil {
@ -67,7 +67,7 @@ func Item_Fish() Item_V2 {
)
}
func Item_SmallHealthPotion() Item_V2 {
func Item_SmallHealthPotion() Item {
return createBaseItem(
ItemType_SmallHealthPotion,
'ó',
@ -77,10 +77,10 @@ func Item_SmallHealthPotion() Item_V2 {
item_WithName("Small Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 2d6", tcell.StyleDefault),
item_WithUsable(
func(e Entity_V2) bool {
func(e Entity) bool {
return e.HealthData() != nil
},
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) {
func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData()
if damageable != nil {
@ -100,7 +100,7 @@ func Item_SmallHealthPotion() Item_V2 {
)
}
func Item_HealthPotion() Item_V2 {
func Item_HealthPotion() Item {
return createBaseItem(
ItemType_HealthPotion,
'ó',
@ -110,10 +110,10 @@ func Item_HealthPotion() Item_V2 {
item_WithName("Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 3d6", tcell.StyleDefault),
item_WithUsable(
func(e Entity_V2) bool {
func(e Entity) bool {
return e.HealthData() != nil
},
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) {
func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData()
if damageable != nil {
@ -133,7 +133,7 @@ func Item_HealthPotion() Item_V2 {
)
}
func Item_LargeHealthPotion() Item_V2 {
func Item_LargeHealthPotion() Item {
return createBaseItem(
ItemType_LargeHealthPotion,
'ó',
@ -143,10 +143,10 @@ func Item_LargeHealthPotion() Item_V2 {
item_WithName("Large Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 4d6", tcell.StyleDefault),
item_WithUsable(
func(e Entity_V2) bool {
func(e Entity) bool {
return e.HealthData() != nil
},
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) {
func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData()
if damageable != nil {
@ -166,7 +166,7 @@ func Item_LargeHealthPotion() Item_V2 {
)
}
func Item_Bow() Item_V2 {
func Item_Bow() Item {
return createBaseItem(
ItemType_Bow,
')',
@ -183,7 +183,7 @@ func Item_Bow() Item_V2 {
)
}
func Item_Longsword() Item_V2 {
func Item_Longsword() Item {
return createBaseItem(
ItemType_Longsword,
'/',
@ -200,7 +200,7 @@ func Item_Longsword() Item_V2 {
)
}
func Item_Club() Item_V2 {
func Item_Club() Item {
return createBaseItem(
ItemType_Club,
'!',
@ -217,7 +217,7 @@ func Item_Club() Item_V2 {
)
}
func Item_Dagger() Item_V2 {
func Item_Dagger() Item {
return createBaseItem(
ItemType_Dagger,
'-',
@ -234,7 +234,7 @@ func Item_Dagger() Item_V2 {
)
}
func Item_Handaxe() Item_V2 {
func Item_Handaxe() Item {
return createBaseItem(
ItemType_Handaxe,
'¶',
@ -251,7 +251,7 @@ func Item_Handaxe() Item_V2 {
)
}
func Item_Javelin() Item_V2 {
func Item_Javelin() Item {
return createBaseItem(
ItemType_Javelin,
'Î',
@ -268,7 +268,7 @@ func Item_Javelin() Item_V2 {
)
}
func Item_LightHammer() Item_V2 {
func Item_LightHammer() Item {
return createBaseItem(
ItemType_LightHammer,
'i',
@ -285,7 +285,7 @@ func Item_LightHammer() Item_V2 {
)
}
func Item_Mace() Item_V2 {
func Item_Mace() Item {
return createBaseItem(
ItemType_Mace,
'i',
@ -302,7 +302,7 @@ func Item_Mace() Item_V2 {
)
}
func Item_Quarterstaff() Item_V2 {
func Item_Quarterstaff() Item {
return createBaseItem(
ItemType_Quarterstaff,
'|',
@ -319,7 +319,7 @@ func Item_Quarterstaff() Item_V2 {
)
}
func Item_Sickle() Item_V2 {
func Item_Sickle() Item {
return createBaseItem(
ItemType_Sickle,
'?',
@ -336,7 +336,7 @@ func Item_Sickle() Item_V2 {
)
}
func Item_Spear() Item_V2 {
func Item_Spear() Item {
return createBaseItem(
ItemType_Spear,
'Î',
@ -353,99 +353,6 @@ func Item_Spear() Item_V2 {
)
}
// import (
// "github.com/gdamore/tcell/v2"
// )
// type ItemType interface {
// Id() int
// Name() string
// Description() string
// TileIcon() rune
// Icon() string
// Style() tcell.Style
// MaxStack() int
// EquippableSlot() EquippedSlot
// }
// type BasicItemType struct {
// id int
// name string
// description string
// tileIcon rune
// itemIcon string
// maxStack int
// equippableSlot EquippedSlot
// style tcell.Style
// }
// func CreateBasicItemType(
// id int,
// name, description string,
// tileIcon rune,
// icon string,
// maxStack int,
// equippableSlot EquippedSlot,
// style tcell.Style,
// ) *BasicItemType {
// return &BasicItemType{
// id: id,
// name: name,
// description: description,
// tileIcon: tileIcon,
// itemIcon: icon,
// style: style,
// maxStack: maxStack,
// equippableSlot: equippableSlot,
// }
// }
// func (it *BasicItemType) Id() int {
// return it.id
// }
// func (it *BasicItemType) Name() string {
// return it.name
// }
// func (it *BasicItemType) Description() string {
// return it.description
// }
// func (it *BasicItemType) TileIcon() rune {
// return it.tileIcon
// }
// func (it *BasicItemType) Icon() string {
// return it.itemIcon
// }
// func (it *BasicItemType) Style() tcell.Style {
// return it.style
// }
// func (it *BasicItemType) MaxStack() int {
// return it.maxStack
// }
// func (it *BasicItemType) EquippableSlot() EquippedSlot {
// return it.equippableSlot
// }
// func ItemTypeFish() ItemType {
// return &BasicItemType{
// id: 0,
// name: "Fish",
// description: "What's a fish doing down here?",
// tileIcon: '>',
// itemIcon: "»o>",
// style: tcell.StyleDefault.Foreground(tcell.ColorDarkCyan),
// equippableSlot: EquippedSlotNone,
// maxStack: 16,
// }
// }
// func ItemTypeGold() ItemType {
// return &BasicItemType{
// id: 1,

View file

@ -1,116 +0,0 @@
package model
// import "slices"
// type RPGEntity interface {
// BaseStat(stat Stat) int
// SetBaseStat(stat Stat, value int)
// CollectModifiersForStat(stat Stat) []StatModifier
// AddStatModifier(modifier StatModifier)
// RemoveStatModifier(id StatModifierId)
// IsDead() bool
// CurrentHealth() int
// Heal(health int)
// Damage(damage int)
// CalculateAttack(other RPGEntity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType)
// }
// type BasicRPGEntity struct {
// stats map[Stat]int
// statModifiers map[Stat][]StatModifier
// currentHealth int
// }
// func CreateBasicRPGEntity(baseStats map[Stat]int, statModifiers map[Stat][]StatModifier) *BasicRPGEntity {
// ent := &BasicRPGEntity{
// stats: baseStats,
// statModifiers: statModifiers,
// }
// ent.currentHealth = BaseMaxHealth(ent)
// return ent
// }
// func (brpg *BasicRPGEntity) BaseStat(stat Stat) int {
// return brpg.stats[stat]
// }
// func (brpg *BasicRPGEntity) SetBaseStat(stat Stat, value int) {
// brpg.stats[stat] = value
// }
// func (brpg *BasicRPGEntity) CollectModifiersForStat(stat Stat) []StatModifier {
// modifiers := brpg.statModifiers[stat]
// if modifiers == nil {
// return []StatModifier{}
// }
// return modifiers
// }
// func (brpg *BasicRPGEntity) AddStatModifier(modifier StatModifier) {
// existing := brpg.statModifiers[modifier.Stat]
// if existing == nil {
// existing = make([]StatModifier, 0)
// }
// existing = append(existing, modifier)
// brpg.statModifiers[modifier.Stat] = existing
// }
// func (brpg *BasicRPGEntity) RemoveStatModifier(id StatModifierId) {
// for k, v := range brpg.statModifiers {
// for i, sm := range v {
// if sm.Id == id {
// brpg.statModifiers[k] = slices.Delete(v, i, i+1)
// }
// }
// }
// }
// func (brpg *BasicRPGEntity) CurrentHealth() int {
// return brpg.currentHealth
// }
// func (brpg *BasicRPGEntity) IsDead() bool {
// return brpg.CurrentHealth() <= 0
// }
// func (brpg *BasicRPGEntity) Heal(health int) {
// if brpg.IsDead() {
// return
// }
// maxHealth := BaseMaxHealth(brpg)
// if brpg.currentHealth+health > maxHealth {
// brpg.currentHealth = maxHealth
// return
// }
// brpg.currentHealth += health
// }
// func (brpg *BasicRPGEntity) Damage(damage int) {
// if brpg.currentHealth-damage < 0 {
// brpg.currentHealth = 0
// return
// }
// brpg.currentHealth -= damage
// }
// func (brpg *BasicRPGEntity) CalculateAttack(other RPGEntity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType) {
// return UnarmedAttack(brpg, other)
// }

View file

@ -13,7 +13,7 @@ import (
const MaxNumberOfModifiers = 6
type ItemSupplier func() Item_V2
type ItemSupplier func() Item
type LootTable struct {
table []ItemSupplier
@ -31,7 +31,7 @@ func (igt *LootTable) Add(weight int, createItemFunction ItemSupplier) {
}
}
func (igt *LootTable) Generate() Item_V2 {
func (igt *LootTable) Generate() Item {
return igt.table[rand.Intn(len(igt.table))]()
}
@ -264,7 +264,7 @@ func generateItemStatModifiers(itemMetaTypes []ItemMetaType, rarity ItemRarity)
// Each rarity gets an amount of generation points, the higher the rarity, the more points
// Each stat modifier consumes points. The higher the stat bonus, the more points it consumes.
func GenerateItemOfTypeAndRarity(prototype Item_V2, rarity ItemRarity) Item_V2 {
func GenerateItemOfTypeAndRarity(prototype Item, rarity ItemRarity) Item {
if prototype.Named() == nil {
return prototype
}
@ -275,8 +275,6 @@ func GenerateItemOfTypeAndRarity(prototype Item_V2, rarity ItemRarity) Item_V2 {
existingName := prototype.Named().Name
metaTypes := prototype.MetaTypes().Types
// points := pointPerRarity(rarity)
name, style := generateItemName(existingName, rarity)
statModifiers := generateItemStatModifiers(metaTypes, rarity)

View file

@ -1,73 +0,0 @@
package model
// type RPGItemType interface {
// RollDamage(victim, attacker RPGEntity) (damage int, dmgType DamageType)
// Use(eventLogger *engine.GameEventLog, user RPGEntity)
// MetaTypes() []ItemMetaType
// item.ItemType
// }
// type BasicRPGItemType struct {
// damageRollFunc func(victim, attacker RPGEntity) (damage int, dmgType DamageType)
// useFunc func(eventLogger *engine.GameEventLog, user RPGEntity)
// metaTypes []ItemMetaType
// *item.BasicItemType
// }
// func (it *BasicRPGItemType) Use(eventLogger *engine.GameEventLog, user RPGEntity) {
// if it.useFunc == nil {
// return
// }
// it.useFunc(eventLogger, user)
// }
// func (it *BasicRPGItemType) RollDamage(victim, attacker RPGEntity) (damage int, dmgType DamageType) {
// if it.damageRollFunc == nil {
// return 0, DamageType_Physical_Unarmed
// }
// return it.damageRollFunc(victim, attacker)
// }
// func (it *BasicRPGItemType) MetaTypes() []ItemMetaType {
// return it.metaTypes
// }
// type RPGItem interface {
// Modifiers() []StatModifier
// RPGType() RPGItemType
// item.Item
// }
// type BasicRPGItem struct {
// modifiers []StatModifier
// rpgType RPGItemType
// item.BasicItem
// }
// func (i *BasicRPGItem) Modifiers() []StatModifier {
// return i.modifiers
// }
// func (i *BasicRPGItem) RPGType() RPGItemType {
// return i.rpgType
// }
// func CreateRPGItem(name string, style tcell.Style, itemType RPGItemType, modifiers []StatModifier) RPGItem {
// return &BasicRPGItem{
// modifiers: modifiers,
// rpgType: itemType,
// BasicItem: item.CreateBasicItemWithName(
// name,
// style,
// itemType,
// 1,
// ),
// }
// }

View file

@ -275,7 +275,7 @@ func statValue(stats *Entity_StatsHolderComponent, stat Stat) int {
// Base Max Health is determined from constitution:
// 5*Constitution + Max Health Bonus
func BaseMaxHealth(entity Entity_V2) int {
func BaseMaxHealth(entity Entity) int {
stats := entity.Stats()
if stats == nil {
@ -286,7 +286,7 @@ func BaseMaxHealth(entity Entity_V2) int {
}
// Dexterity + Evasion bonus + luck roll
func EvasionRoll(victim Entity_V2) int {
func EvasionRoll(victim Entity) int {
if victim.Stats() == nil {
return 0
}
@ -295,7 +295,7 @@ func EvasionRoll(victim Entity_V2) int {
}
// Strength + Precision bonus ( melee + total ) + luck roll
func PhysicalPrecisionRoll(attacker Entity_V2) int {
func PhysicalPrecisionRoll(attacker Entity) int {
if attacker.Stats() == nil {
return 0
}
@ -304,7 +304,7 @@ func PhysicalPrecisionRoll(attacker Entity_V2) int {
}
// Intelligence + Precision bonus ( magic + total ) + luck roll
func MagicPrecisionRoll(attacker Entity_V2) int {
func MagicPrecisionRoll(attacker Entity) int {
if attacker.Stats() == nil {
return 0
}
@ -313,12 +313,12 @@ func MagicPrecisionRoll(attacker Entity_V2) int {
}
// true = hit lands, false = hit does not land
func MagicHitRoll(attacker Entity_V2, victim Entity_V2) bool {
func MagicHitRoll(attacker Entity, victim Entity) bool {
return hitRoll(EvasionRoll(victim), MagicPrecisionRoll(attacker))
}
// true = hit lands, false = hit does not land
func PhysicalHitRoll(attacker Entity_V2, victim Entity_V2) (hit bool, evasion, precision int) {
func PhysicalHitRoll(attacker Entity, victim Entity) (hit bool, evasion, precision int) {
evasion = EvasionRoll(victim)
precision = PhysicalPrecisionRoll(attacker)
hit = hitRoll(evasion, precision)
@ -330,7 +330,7 @@ func hitRoll(evasionRoll, precisionRoll int) bool {
return evasionRoll < precisionRoll
}
func UnarmedDamage(attacker Entity_V2) int {
func UnarmedDamage(attacker Entity) int {
if attacker.Stats() == nil {
return 0
}
@ -338,7 +338,7 @@ func UnarmedDamage(attacker Entity_V2) int {
return RollD4(1) + statValue(attacker.Stats(), Stat_DamageBonus_Physical_Unarmed)
}
func PhysicalWeaponDamage(attacker Entity_V2, weapon Item_V2, victim Entity_V2) (totalDamage int, dmgType DamageType) {
func PhysicalWeaponDamage(attacker Entity, weapon Item, victim Entity) (totalDamage int, dmgType DamageType) {
if attacker.Stats() == nil || weapon.Damaging() == nil || victim.Stats() == nil {
return 0, DamageType_Physical_Unarmed
}
@ -353,7 +353,7 @@ func PhysicalWeaponDamage(attacker Entity_V2, weapon Item_V2, victim Entity_V2)
return
}
func UnarmedAttack(attacker Entity_V2, victim Entity_V2) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType) {
func UnarmedAttack(attacker Entity, victim Entity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType) {
hit, evasionRoll, precisionRoll = PhysicalHitRoll(attacker, victim)
if !hit {
@ -366,7 +366,7 @@ func UnarmedAttack(attacker Entity_V2, victim Entity_V2) (hit bool, precisionRol
return
}
func PhysicalWeaponAttack(attacker Entity_V2, weapon Item_V2, victim Entity_V2) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType) {
func PhysicalWeaponAttack(attacker Entity, weapon Item, victim Entity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType DamageType) {
hit, evasionRoll, precisionRoll = PhysicalHitRoll(attacker, victim)
if !hit {

View file

@ -89,20 +89,20 @@ func (d *Dungeon) HasNextLevel() bool {
}
type DungeonLevel struct {
ground Map_V2
entitiesByPosition map[engine.Position]Entity_V2
entities map[uuid.UUID]Entity_V2
ground Map
entitiesByPosition map[engine.Position]Entity
entities map[uuid.UUID]Entity
}
func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *DungeonLevel) {
genTable := CreateLootTable()
genTable.Add(1, func() Item_V2 {
genTable.Add(1, func() Item {
return Item_HealthPotion()
})
itemPool := []Item_V2{
itemPool := []Item{
Item_Bow(),
Item_Longsword(),
Item_Club(),
@ -116,7 +116,7 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
Item_Spear(),
}
genTable.Add(1, func() Item_V2 {
genTable.Add(1, func() Item {
item := itemPool[rand.Intn(len(itemPool))]
rarities := []ItemRarity{
@ -130,7 +130,7 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
return GenerateItemOfTypeAndRarity(item, rarities[rand.Intn(len(rarities))])
})
var groundLevel Map_V2
var groundLevel Map
switch dungeonType {
case DungeonTypeBSP:
@ -141,8 +141,8 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
dLevel = &DungeonLevel{
ground: groundLevel,
entities: map[uuid.UUID]Entity_V2{},
entitiesByPosition: map[engine.Position]Entity_V2{},
entities: map[uuid.UUID]Entity{},
entitiesByPosition: map[engine.Position]Entity{},
}
if groundLevel.Rooms() == nil {
@ -183,10 +183,10 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
return dLevel
}
func SpawnItems(spawnableAreas []engine.BoundingBox, maxItemRatio float32, genTable *LootTable, forbiddenPositions []engine.Position) map[engine.Position]Item_V2 {
func SpawnItems(spawnableAreas []engine.BoundingBox, maxItemRatio float32, genTable *LootTable, forbiddenPositions []engine.Position) map[engine.Position]Item {
rooms := spawnableAreas
itemLocations := make(map[engine.Position]Item_V2, 0)
itemLocations := make(map[engine.Position]Item, 0)
for _, r := range rooms {
maxItems := int(maxItemRatio * float32(r.Size().Area()))
@ -220,7 +220,7 @@ func SpawnItems(spawnableAreas []engine.BoundingBox, maxItemRatio float32, genTa
return itemLocations
}
func (d *DungeonLevel) Ground() Map_V2 {
func (d *DungeonLevel) Ground() Map {
return d.ground
}
@ -234,7 +234,7 @@ func (d *DungeonLevel) DropEntity(uuid uuid.UUID) {
delete(d.entities, uuid)
}
func (d *DungeonLevel) AddEntity(entity Entity_V2) {
func (d *DungeonLevel) AddEntity(entity Entity) {
d.entities[entity.UniqueId()] = entity
if entity.Positioned() != nil {
@ -260,7 +260,7 @@ func (d *DungeonLevel) RemoveEntityAt(x, y int) {
delete(d.entitiesByPosition, engine.PositionAt(x, y))
}
func (d *DungeonLevel) RemoveItemAt(x, y int) (item Item_V2) {
func (d *DungeonLevel) RemoveItemAt(x, y int) (item Item) {
if !Map_IsInBounds(d.ground, x, y) {
return nil
}
@ -278,7 +278,7 @@ func (d *DungeonLevel) RemoveItemAt(x, y int) (item Item_V2) {
return
}
func (d *DungeonLevel) SetItemAt(x, y int, it Item_V2) (success bool) {
func (d *DungeonLevel) SetItemAt(x, y int, it Item) (success bool) {
if !d.TileAt(x, y).Passable() {
return false
}
@ -290,7 +290,7 @@ func (d *DungeonLevel) SetItemAt(x, y int, it Item_V2) (success bool) {
return true
}
func (d *DungeonLevel) TileAt(x, y int) Tile_V2 {
func (d *DungeonLevel) TileAt(x, y int) Tile {
entity := d.entitiesByPosition[engine.PositionAt(x, y)]
tile := Map_TileAt(d.ground, x, y)
@ -315,7 +315,7 @@ func (d *DungeonLevel) IsTilePassable(x, y int) bool {
return tile.Passable()
}
func (d *DungeonLevel) EntityAt(x, y int) (e Entity_V2) {
func (d *DungeonLevel) EntityAt(x, y int) (e Entity) {
return d.entitiesByPosition[engine.PositionAt(x, y)]
}

View file

@ -1,50 +0,0 @@
package model
// import "mvvasilev/last_light/engine"
// type EmptyDungeonMap struct {
// level *BasicMap
// }
// func (edl *EmptyDungeonMap) Size() engine.Size {
// return edl.level.Size()
// }
// func (edl *EmptyDungeonMap) SetTileAt(x int, y int, t Tile) Tile {
// return edl.level.SetTileAt(x, y, t)
// }
// func (edl *EmptyDungeonMap) TileAt(x int, y int) Tile {
// return edl.level.TileAt(x, y)
// }
// func (edl *EmptyDungeonMap) IsInBounds(x, y int) bool {
// return edl.level.IsInBounds(x, y)
// }
// func (edl *EmptyDungeonMap) Tick(dt int64) {
// }
// func (edl *EmptyDungeonMap) Rooms() []engine.BoundingBox {
// rooms := make([]engine.BoundingBox, 1)
// rooms = append(rooms, engine.BoundingBox{
// Sized: engine.WithSize(edl.Size()),
// Positioned: engine.WithPosition(engine.PositionAt(0, 0)),
// })
// return rooms
// }
// func (edl *EmptyDungeonMap) PlayerSpawnPoint() engine.Position {
// return engine.PositionAt(edl.Size().Width()/2, edl.Size().Height()/2)
// }
// func (edl *EmptyDungeonMap) NextLevelStaircasePosition() engine.Position {
// return engine.PositionAt(edl.Size().Width()/3, edl.Size().Height()/3)
// }
// func (bsp *EmptyDungeonMap) PreviousLevelStaircasePosition() engine.Position {
// return bsp.PlayerSpawnPoint()
// }

View file

@ -1,140 +0,0 @@
package model
// import (
// "maps"
// "mvvasilev/last_light/engine"
// "mvvasilev/last_light/game/npc"
// "github.com/google/uuid"
// )
// type EntityMap struct {
// entities map[int]EntityTile
// engine.Sized
// }
// func CreateEntityMap(width, height int) *EntityMap {
// return &EntityMap{
// entities: make(map[int]EntityTile, 0),
// Sized: engine.WithSize(engine.SizeOf(width, height)),
// }
// }
// func (em *EntityMap) SetTileAt(x int, y int, t Tile) Tile {
// return nil
// // if !em.FitsWithin(x, y) {
// // return
// // }
// // index := em.Size().AsArrayIndex(x, y)
// // TODO? May not be necessary
// }
// func (em *EntityMap) FindEntityByUuid(uuid uuid.UUID) (key int, entity EntityTile) {
// for i, e := range em.entities {
// if e.Entity().UniqueId() == uuid {
// return i, e
// }
// }
// return -1, nil
// }
// func (em *EntityMap) AddEntity(entity Entity_V2) {
// if entity.Positioned() == nil {
// return
// }
// if !em.FitsWithin(entity.Positioned().Position.XY()) {
// return
// }
// key := em.Size().AsArrayIndex(entity.Positioned().Position.XY())
// et := CreateBasicEntityTile(entity)
// em.entities[key] = et
// }
// func (em *EntityMap) DropEntity(uuid uuid.UUID) {
// maps.DeleteFunc(em.entities, func(i int, et EntityTile) bool {
// return et.Entity().UniqueId() == uuid
// })
// }
// func (em *EntityMap) MoveEntity(uuid uuid.UUID, dx, dy int) {
// oldKey, e := em.FindEntityByUuid(uuid)
// if e == nil {
// return
// }
// if !em.FitsWithin(e.Entity().Positioned().Position.WithOffset(dx, dy).XY()) {
// return
// }
// delete(em.entities, oldKey)
// newPos := e.Entity().Position().WithOffset(dx, dy)
// e.Entity().MoveTo(newPos)
// newKey := em.Size().AsArrayIndex(e.Entity().Position().XY())
// em.entities[newKey] = e
// }
// func (em *EntityMap) MoveEntityTo(uuid uuid.UUID, x, y int) {
// oldKey, e := em.FindEntityByUuid(uuid)
// if e == nil {
// return
// }
// if !em.FitsWithin(x, y) {
// return
// }
// delete(em.entities, oldKey)
// e.Entity().MoveTo(engine.PositionAt(x, y))
// newKey := em.Size().AsArrayIndex(e.Entity().Position().XY())
// em.entities[newKey] = e
// }
// func (em *EntityMap) TileAt(x int, y int) Tile {
// if !em.FitsWithin(x, y) {
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// key := em.Size().AsArrayIndex(x, y)
// return em.entities[key]
// }
// func (em *EntityMap) EntityAt(x, y int) (ent npc.MovableEntity) {
// tile := em.TileAt(x, y)
// if tile == nil {
// return nil
// }
// return tile.(EntityTile).Entity()
// }
// func (em *EntityMap) IsInBounds(x, y int) bool {
// return em.FitsWithin(x, y)
// }
// func (em *EntityMap) MarkExplored(x, y int) {
// }
// func (em *EntityMap) ExploredTileAt(x, y int) Tile {
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// func (em *EntityMap) Tick(dt int64) {
// }

View file

@ -27,7 +27,7 @@ type bspNode struct {
splitDir splitDirection
}
func CreateBSPDungeonMap(width, height int, numSplits int) Map_V2 {
func CreateBSPDungeonMap(width, height int, numSplits int) Map {
root := new(bspNode)
root.origin = engine.PositionAt(0, 0)
@ -35,10 +35,10 @@ func CreateBSPDungeonMap(width, height int, numSplits int) Map_V2 {
split(root, numSplits)
tiles := make([][]Tile_V2, height)
tiles := make([][]Tile, height)
for h := range height {
tiles[h] = make([]Tile_V2, width)
tiles[h] = make([]Tile, width)
}
rooms := make([]engine.BoundingBox, 0, numSplits*numSplits)
@ -113,24 +113,6 @@ func CreateBSPDungeonMap(width, height int, numSplits int) Map_V2 {
Map_SetTileAt(newBsp, newBsp.NextLevelStaircase().Position.X(), newBsp.NextLevelStaircase().Position.Y(), Tile_StaircaseDown())
Map_SetTileAt(newBsp, newBsp.PreviousLevelStaircase().Position.X(), newBsp.PreviousLevelStaircase().Position.Y(), Tile_StaircaseUp())
// bsp := new(BSPDungeonMap)
// bsp.rooms = rooms
// bsp.level = CreateBasicMap(tiles, tcell.StyleDefault.Foreground(tcell.ColorLightSlateGrey))
// bsp.playerSpawnPoint = engine.PositionAt(
// spawnRoom.Position().X()+spawnRoom.Size().Width()/2,
// spawnRoom.Position().Y()+spawnRoom.Size().Height()/2,
// )
// bsp.nextLevelStaircase = engine.PositionAt(
// staircaseRoom.Position().X()+staircaseRoom.Size().Width()/2,
// staircaseRoom.Position().Y()+staircaseRoom.Size().Height()/2,
// )
// bsp.level.SetTileAt(bsp.nextLevelStaircase.X(), bsp.nextLevelStaircase.Y(), CreateStaticTile(bsp.nextLevelStaircase.X(), bsp.nextLevelStaircase.Y(), TileTypeStaircaseDown()))
// bsp.level.SetTileAt(bsp.playerSpawnPoint.X(), bsp.playerSpawnPoint.Y(), CreateStaticTile(bsp.playerSpawnPoint.X(), bsp.playerSpawnPoint.Y(), TileTypeStaircaseUp()))
return newBsp
}
@ -146,7 +128,7 @@ func findRoom(parent *bspNode) engine.BoundingBox {
}
}
func zCorridor(tiles [][]Tile_V2, from engine.Position, to engine.Position, direction splitDirection) {
func zCorridor(tiles [][]Tile, from engine.Position, to engine.Position, direction splitDirection) {
switch direction {
case splitDirectionHorizontal:
xMidPoint := (from.X() + to.X()) / 2
@ -228,7 +210,7 @@ func split(parent *bspNode, numSplits int) {
split(parent.right, numSplits-1)
}
func horizontalTunnel(tiles [][]Tile_V2, x1, x2, y int) {
func horizontalTunnel(tiles [][]Tile, x1, x2, y int) {
if x1 > x2 {
tx := x2
x2 = x1
@ -255,7 +237,7 @@ func horizontalTunnel(tiles [][]Tile_V2, x1, x2, y int) {
placeWallAtIfNotPassable(tiles, x2, y+1)
}
func verticalTunnel(tiles [][]Tile_V2, y1, y2, x int) {
func verticalTunnel(tiles [][]Tile, y1, y2, x int) {
if y1 > y2 {
ty := y2
y2 = y1
@ -282,7 +264,7 @@ func verticalTunnel(tiles [][]Tile_V2, y1, y2, x int) {
placeWallAtIfNotPassable(tiles, x+1, y2)
}
func placeWallAtIfNotPassable(tiles [][]Tile_V2, x, y int) {
func placeWallAtIfNotPassable(tiles [][]Tile, x, y int) {
if tiles[y][x] != nil && tiles[y][x].Passable() {
return
}
@ -290,7 +272,7 @@ func placeWallAtIfNotPassable(tiles [][]Tile_V2, x, y int) {
tiles[y][x] = Tile_Wall()
}
func makeRoom(tiles [][]Tile_V2, room engine.BoundingBox) {
func makeRoom(tiles [][]Tile, room engine.BoundingBox) {
width := room.Size().Width()
height := room.Size().Height()
x := room.Position().X()

View file

@ -1,13 +0,0 @@
package model
// import "github.com/gdamore/tcell/v2"
// func CreateEmptyDungeonLevel(width, height int) *BasicMap {
// tiles := make([][]Tile, height)
// for h := range height {
// tiles[h] = make([]Tile, width)
// }
// return CreateBasicMap(tiles, tcell.StyleDefault.Foreground(tcell.ColorLightSlateGrey))
// }

View file

@ -6,12 +6,12 @@ import (
"github.com/gdamore/tcell/v2"
)
type Map_V2 interface {
type Map interface {
Size() engine.Size
Tiles() [][]Tile_V2
ExploredTiles() map[engine.Position]Tile_V2
Tiles() [][]Tile
ExploredTiles() map[engine.Position]Tile
ExploredTileStyle() tcell.Style
DefaultTile() Tile_V2
DefaultTile() Tile
PlayerSpawnPoint() *Map_PlayerSpawnPointComponent
Rooms() *Map_RoomsComponent
@ -37,10 +37,10 @@ type Map_PreviousLevelStaircaseComponent struct {
type BaseMap struct {
size engine.Size
tiles [][]Tile_V2
exploredTiles map[engine.Position]Tile_V2
tiles [][]Tile
exploredTiles map[engine.Position]Tile
exploredStyle tcell.Style
defaultTile Tile_V2
defaultTile Tile
playerSpawnPos *Map_PlayerSpawnPointComponent
rooms *Map_RoomsComponent
@ -48,11 +48,11 @@ type BaseMap struct {
prevLevel *Map_PreviousLevelStaircaseComponent
}
func CreateMap(size engine.Size, tiles [][]Tile_V2, exploredStyle tcell.Style, defaultTile Tile_V2, components ...func(*BaseMap)) Map_V2 {
func CreateMap(size engine.Size, tiles [][]Tile, exploredStyle tcell.Style, defaultTile Tile, components ...func(*BaseMap)) Map {
m := &BaseMap{
size: size,
tiles: tiles,
exploredTiles: make(map[engine.Position]Tile_V2, 0),
exploredTiles: make(map[engine.Position]Tile, 0),
exploredStyle: exploredStyle,
defaultTile: defaultTile,
}
@ -68,11 +68,11 @@ func (m *BaseMap) Size() engine.Size {
return m.size
}
func (m *BaseMap) Tiles() [][]Tile_V2 {
func (m *BaseMap) Tiles() [][]Tile {
return m.tiles
}
func (m *BaseMap) ExploredTiles() map[engine.Position]Tile_V2 {
func (m *BaseMap) ExploredTiles() map[engine.Position]Tile {
return m.exploredTiles
}
@ -80,7 +80,7 @@ func (m *BaseMap) ExploredTileStyle() tcell.Style {
return m.exploredStyle
}
func (m *BaseMap) DefaultTile() Tile_V2 {
func (m *BaseMap) DefaultTile() Tile {
return m.defaultTile
}
@ -132,7 +132,7 @@ func Map_WithPreviousLevelStaircase(pos engine.Position) func(*BaseMap) {
}
}
func Map_SetTileAt(bm Map_V2, x int, y int, t Tile_V2) Tile_V2 {
func Map_SetTileAt(bm Map, x int, y int, t Tile) Tile {
if !Map_IsInBounds(bm, x, y) {
return bm.DefaultTile()
}
@ -142,7 +142,7 @@ func Map_SetTileAt(bm Map_V2, x int, y int, t Tile_V2) Tile_V2 {
return bm.Tiles()[y][x]
}
func Map_TileAt(bm Map_V2, x int, y int) Tile_V2 {
func Map_TileAt(bm Map, x int, y int) Tile {
if !Map_IsInBounds(bm, x, y) {
return bm.DefaultTile()
}
@ -156,7 +156,7 @@ func Map_TileAt(bm Map_V2, x int, y int) Tile_V2 {
return tile
}
func Map_IsInBounds(bm Map_V2, x, y int) bool {
func Map_IsInBounds(bm Map, x, y int) bool {
if x < 0 || y < 0 {
return false
}
@ -168,11 +168,11 @@ func Map_IsInBounds(bm Map_V2, x, y int) bool {
return true
}
func Map_ExploredTileAt(bm Map_V2, x, y int) Tile_V2 {
func Map_ExploredTileAt(bm Map, x, y int) Tile {
return bm.ExploredTiles()[engine.PositionAt(x, y)]
}
func Map_MarkExplored(bm Map_V2, x, y int) {
func Map_MarkExplored(bm Map, x, y int) {
if !Map_IsInBounds(bm, x, y) {
return
}

View file

@ -1,127 +0,0 @@
package model
// import "mvvasilev/last_light/engine"
// type MultilevelMap struct {
// layers []Map
// }
// func CreateMultilevelMap(maps ...Map) *MultilevelMap {
// m := new(MultilevelMap)
// m.layers = maps
// return m
// }
// func (mm *MultilevelMap) Size() engine.Size {
// if len(mm.layers) == 0 {
// return engine.SizeOf(0, 0)
// }
// return mm.layers[0].Size()
// }
// func (mm *MultilevelMap) SetTileAt(x, y int, t Tile) Tile {
// return mm.layers[0].SetTileAt(x, y, t)
// }
// func (mm *MultilevelMap) UnsetTileAtHeight(x, y, height int) {
// if len(mm.layers) < height {
// return
// }
// mm.layers[height].SetTileAt(x, y, nil)
// }
// func (mm *MultilevelMap) SetTileAtHeight(x, y, height int, t Tile) {
// if len(mm.layers) < height {
// return
// }
// mm.layers[height].SetTileAt(x, y, t)
// }
// func (mm *MultilevelMap) CollectTilesAt(x, y int, filter func(t Tile) bool) []Tile {
// tiles := make([]Tile, len(mm.layers))
// if !mm.IsInBounds(x, y) {
// return tiles
// }
// for i := len(mm.layers) - 1; i >= 0; i-- {
// tile := mm.layers[i].TileAt(x, y)
// if tile != nil && !tile.Transparent() && filter(tile) {
// tiles = append(tiles, tile)
// }
// }
// return tiles
// }
// func (mm *MultilevelMap) TileAt(x int, y int) Tile {
// if !mm.IsInBounds(x, y) {
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// for i := len(mm.layers) - 1; i >= 0; i-- {
// tile := mm.layers[i].TileAt(x, y)
// if tile != nil && !tile.Transparent() {
// return tile
// }
// }
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// func (mm *MultilevelMap) IsInBounds(x, y int) bool {
// if x < 0 || y < 0 {
// return false
// }
// if x >= mm.Size().Width() || y >= mm.Size().Height() {
// return false
// }
// return true
// }
// func (mm *MultilevelMap) MarkExplored(x, y int) {
// for _, m := range mm.layers {
// m.MarkExplored(x, y)
// }
// }
// func (mm *MultilevelMap) ExploredTileAt(x, y int) Tile {
// for i := len(mm.layers) - 1; i >= 0; i-- {
// tile := mm.layers[i].ExploredTileAt(x, y)
// if tile != nil && !tile.Transparent() {
// return tile
// }
// }
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// func (mm *MultilevelMap) TileAtHeight(x, y, height int) Tile {
// if !mm.IsInBounds(x, y) {
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// if height > len(mm.layers)-1 {
// return CreateStaticTile(x, y, TileTypeVoid())
// }
// return mm.layers[height].TileAt(x, y)
// }
// func (mm *MultilevelMap) Tick(dt int64) {
// for _, l := range mm.layers {
// l.Tick(dt)
// }
// }

View file

@ -19,14 +19,14 @@ const (
)
type Tile_ItemComponent struct {
Item Item_V2
Item Item
}
type Tile_EntityComponent struct {
Entity Entity_V2
Entity Entity
}
type Tile_V2 interface {
type Tile interface {
DefaultPresentation() (rune, tcell.Style)
Material() Material
Passable() bool
@ -35,11 +35,11 @@ type Tile_V2 interface {
Item() *Tile_ItemComponent
RemoveItem()
WithItem(item Item_V2)
WithItem(item Item)
Entity() *Tile_EntityComponent
RemoveEntity()
WithEntity(entity Entity_V2)
WithEntity(entity Entity)
}
type BaseTile struct {
@ -53,7 +53,7 @@ type BaseTile struct {
entity *Tile_EntityComponent
}
func CreateTileFromPrototype(prototype Tile_V2, components ...func(*BaseTile)) Tile_V2 {
func CreateTileFromPrototype(prototype Tile, components ...func(*BaseTile)) Tile {
defaultSymbol, defaultStyle := prototype.DefaultPresentation()
return CreateTile(
@ -67,7 +67,7 @@ func CreateTileFromPrototype(prototype Tile_V2, components ...func(*BaseTile)) T
)
}
func CreateTile(defaultSymbol rune, defaultStyle tcell.Style, material Material, passable, opaque, transparent bool, components ...func(*BaseTile)) Tile_V2 {
func CreateTile(defaultSymbol rune, defaultStyle tcell.Style, material Material, passable, opaque, transparent bool, components ...func(*BaseTile)) Tile {
t := &BaseTile{
defaultSymbol: defaultSymbol,
defaultStyle: defaultStyle,
@ -112,7 +112,7 @@ func (t *BaseTile) RemoveItem() {
t.item = nil
}
func (t *BaseTile) WithItem(item Item_V2) {
func (t *BaseTile) WithItem(item Item) {
t.item = &Tile_ItemComponent{
Item: item,
}
@ -126,13 +126,13 @@ func (t *BaseTile) RemoveEntity() {
t.entity = nil
}
func (t *BaseTile) WithEntity(entity Entity_V2) {
func (t *BaseTile) WithEntity(entity Entity) {
t.entity = &Tile_EntityComponent{
Entity: entity,
}
}
func Tile_WithEntity(entity Entity_V2) func(*BaseTile) {
func Tile_WithEntity(entity Entity) func(*BaseTile) {
return func(bt *BaseTile) {
bt.entity = &Tile_EntityComponent{
Entity: entity,
@ -140,7 +140,7 @@ func Tile_WithEntity(entity Entity_V2) func(*BaseTile) {
}
}
func Tile_WithItem(item Item_V2) func(*BaseTile) {
func Tile_WithItem(item Item) func(*BaseTile) {
return func(bt *BaseTile) {
bt.item = &Tile_ItemComponent{
Item: item,
@ -148,7 +148,7 @@ func Tile_WithItem(item Item_V2) func(*BaseTile) {
}
}
func Tile_Void() Tile_V2 {
func Tile_Void() Tile {
return CreateTile(
' ',
tcell.StyleDefault,
@ -157,7 +157,7 @@ func Tile_Void() Tile_V2 {
)
}
func Tile_Ground() Tile_V2 {
func Tile_Ground() Tile {
return CreateTile(
'.',
tcell.StyleDefault,
@ -166,7 +166,7 @@ func Tile_Ground() Tile_V2 {
)
}
func Tile_Rock() Tile_V2 {
func Tile_Rock() Tile {
return CreateTile(
'█',
tcell.StyleDefault,
@ -175,7 +175,7 @@ func Tile_Rock() Tile_V2 {
)
}
func Tile_Wall() Tile_V2 {
func Tile_Wall() Tile {
return CreateTile(
'#',
tcell.StyleDefault.Background(tcell.ColorGray),
@ -206,7 +206,7 @@ func Tile_Wall() Tile_V2 {
// }
// }
func Tile_StaircaseDown() Tile_V2 {
func Tile_StaircaseDown() Tile {
return CreateTile(
'≡',
tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray).Attributes(tcell.AttrBold),
@ -215,7 +215,7 @@ func Tile_StaircaseDown() Tile_V2 {
)
}
func Tile_StaircaseUp() Tile_V2 {
func Tile_StaircaseUp() Tile {
return CreateTile(
'^',
tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray).Attributes(tcell.AttrBold),

View file

@ -21,10 +21,10 @@ type InventoryScreenState struct {
inventoryMenu *menu.PlayerInventoryMenu
selectedInventorySlot engine.Position
player *model.Player_V2
player *model.Player
}
func CreateInventoryScreenState(eventLog *engine.GameEventLog, dungeon *model.Dungeon, inputSystem *systems.InputSystem, turnSystem *systems.TurnSystem, player *model.Player_V2, prevState GameState) *InventoryScreenState {
func CreateInventoryScreenState(eventLog *engine.GameEventLog, dungeon *model.Dungeon, inputSystem *systems.InputSystem, turnSystem *systems.TurnSystem, player *model.Player, prevState GameState) *InventoryScreenState {
iss := new(InventoryScreenState)
iss.eventLog = eventLog

View file

@ -15,8 +15,8 @@ type PlayingState struct {
turnSystem *systems.TurnSystem
inputSystem *systems.InputSystem
player *model.Player_V2
someNPC model.Entity_V2
player *model.Player
someNPC model.Entity
eventLog *engine.GameEventLog
uiEventLog *ui.UIEventLog
@ -44,7 +44,7 @@ func CreatePlayingState(turnSystem *systems.TurnSystem, inputSystem *systems.Inp
s.dungeon = model.CreateDungeon(mapSize.Width(), mapSize.Height(), 1)
s.player = model.CreatePlayer_V2(
s.player = model.CreatePlayer(
s.dungeon.CurrentLevel().Ground().PlayerSpawnPoint().Position.X(),
s.dungeon.CurrentLevel().Ground().PlayerSpawnPoint().Position.Y(),
playerStats,
@ -156,7 +156,7 @@ func (ps *PlayingState) MovePlayer(direction model.Direction) {
}
}
func ExecuteAttack(eventLog *engine.GameEventLog, attacker, victim model.Entity_V2) {
func ExecuteAttack(eventLog *engine.GameEventLog, attacker, victim model.Entity) {
hit, precision, evasion, dmg, dmgType := CalculateAttack(attacker, victim)
attackerName := "Unknown"
@ -187,7 +187,7 @@ func ExecuteAttack(eventLog *engine.GameEventLog, attacker, victim model.Entity_
eventLog.Log(fmt.Sprintf("%s attacked %s, and hit for %v %v damage", attackerName, victimName, dmg, model.DamageTypeName(dmgType)))
}
func CalculateAttack(attacker, victim model.Entity_V2) (hit bool, precisionRoll, evasionRoll int, damage int, damageType model.DamageType) {
func CalculateAttack(attacker, victim model.Entity) (hit bool, precisionRoll, evasionRoll int, damage int, damageType model.DamageType) {
if attacker.Equipped() != nil && attacker.Equipped().Inventory.AtSlot(model.EquippedSlotDominantHand) != nil {
weapon := attacker.Equipped().Inventory.AtSlot(model.EquippedSlotDominantHand)
@ -403,7 +403,7 @@ func (ps *PlayingState) OnTick(dt int64) (nextState GameState) {
func (ps *PlayingState) CollectDrawables() []engine.Drawable {
mainCameraDrawingInstructions := engine.CreateDrawingInstructions(func(v views.View) {
visibilityMap := engine.ComputeFOV(
func(x, y int) model.Tile_V2 {
func(x, y int) model.Tile {
model.Map_MarkExplored(ps.dungeon.CurrentLevel().Ground(), x, y)
return ps.dungeon.CurrentLevel().TileAt(x, y)

View file

@ -122,7 +122,7 @@ func CreatePlayerInventoryMenu(x, y int, playerInventory *model.EquippedInventor
return menu
}
func (pim *PlayerInventoryMenu) drawItemSlot(screenX, screenY int, item model.Item_V2, style tcell.Style, v views.View) {
func (pim *PlayerInventoryMenu) drawItemSlot(screenX, screenY int, item model.Item, style tcell.Style, v views.View) {
if item.Quantifiable() != nil {
ui.CreateSingleLineUILabel(
screenX,

View file

@ -14,14 +14,14 @@ import (
type UIHealthBar struct {
id uuid.UUID
player *model.Player_V2
player *model.Player
window *UIWindow
style tcell.Style
}
func CreateHealthBar(x, y, w, h int, player *model.Player_V2, style tcell.Style) *UIHealthBar {
func CreateHealthBar(x, y, w, h int, player *model.Player, style tcell.Style) *UIHealthBar {
return &UIHealthBar{
window: CreateWindow(x, y, w, h, "HP", style),
player: player,

View file

@ -13,7 +13,7 @@ import (
type UIItem struct {
id uuid.UUID
item model.Item_V2
item model.Item
window UIWindow
@ -21,7 +21,7 @@ type UIItem struct {
engine.Sized
}
func CreateUIItem(x, y int, item model.Item_V2, style tcell.Style) *UIItem {
func CreateUIItem(x, y int, item model.Item, style tcell.Style) *UIItem {
return &UIItem{
id: uuid.New(),
item: item,