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

View file

@ -1 +0,0 @@
package model

View file

@ -6,13 +6,13 @@ import (
"github.com/gdamore/tcell/v2" "github.com/gdamore/tcell/v2"
) )
type Player_V2 struct { type Player struct {
Entity_V2 Entity
} }
func CreatePlayer_V2(x, y int, playerBaseStats map[Stat]int) *Player_V2 { func CreatePlayer(x, y int, playerBaseStats map[Stat]int) *Player {
p := &Player_V2{ p := &Player{
Entity_V2: CreateEntity( Entity: CreateEntity(
WithName("Player"), WithName("Player"),
WithPosition(engine.PositionAt(x, y)), WithPosition(engine.PositionAt(x, y)),
WithPresentation('@', tcell.StyleDefault), WithPresentation('@', tcell.StyleDefault),
@ -28,22 +28,22 @@ func CreatePlayer_V2(x, y int, playerBaseStats map[Stat]int) *Player_V2 {
return p return p
} }
func (p *Player_V2) Inventory() *EquippedInventory { func (p *Player) Inventory() *EquippedInventory {
return p.Entity_V2.Equipped().Inventory return p.Entity.Equipped().Inventory
} }
func (p *Player_V2) Position() engine.Position { func (p *Player) Position() engine.Position {
return p.Entity_V2.Positioned().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 return p.Presentable().Rune, p.Presentable().Style
} }
func (p *Player_V2) Stats() *Entity_StatsHolderComponent { func (p *Player) Stats() *Entity_StatsHolderComponent {
return p.Entity_V2.Stats() return p.Entity.Stats()
} }
func (p *Player_V2) HealthData() *Entity_HealthComponent { func (p *Player) HealthData() *Entity_HealthComponent {
return p.Entity_V2.HealthData() 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 { type Inventory interface {
Items() []Item_V2 Items() []Item
Shape() engine.Size Shape() engine.Size
Push(item Item_V2) bool Push(item Item) bool
Drop(x, y int) Item_V2 Drop(x, y int) Item
ItemAt(x, y int) Item_V2 ItemAt(x, y int) Item
} }
type BasicInventory struct { type BasicInventory struct {
contents []Item_V2 contents []Item
shape engine.Size shape engine.Size
} }
func CreateInventory(shape engine.Size) *BasicInventory { func CreateInventory(shape engine.Size) *BasicInventory {
inv := new(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 inv.shape = shape
return inv return inv
} }
func (i *BasicInventory) Items() (items []Item_V2) { func (i *BasicInventory) Items() (items []Item) {
return i.contents return i.contents
} }
@ -34,7 +34,7 @@ func (i *BasicInventory) Shape() engine.Size {
return i.shape 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() { if len(inv.contents) == inv.shape.Area() {
return false return false
} }
@ -91,7 +91,7 @@ func (inv *BasicInventory) Push(i Item_V2) (success bool) {
return true 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 index := y*i.shape.Width() + x
if index > len(i.contents)-1 { 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 index := y*i.shape.Width() + x
if index > len(i.contents)-1 { if index > len(i.contents)-1 {

View file

@ -18,13 +18,13 @@ const (
) )
type EquippedInventory struct { type EquippedInventory struct {
offHand Item_V2 offHand Item
dominantHand Item_V2 dominantHand Item
head Item_V2 head Item
chestplate Item_V2 chestplate Item
leggings Item_V2 leggings Item
shoes Item_V2 shoes Item
*BasicInventory *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 { switch slot {
case EquippedSlotOffhand: case EquippedSlotOffhand:
return ei.offHand 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 { switch slot {
case EquippedSlotOffhand: case EquippedSlotOffhand:
ei.offHand = item ei.offHand = item

View file

@ -19,7 +19,7 @@ const (
MetaItemType_Potion MetaItemType_Potion
) )
type Item_V2 interface { type Item interface {
TileIcon() rune TileIcon() rune
Icon() string Icon() string
Style() tcell.Style Style() tcell.Style
@ -41,8 +41,8 @@ type Item_QuantifiableComponent struct {
} }
type Item_UsableComponent struct { type Item_UsableComponent struct {
IsUsableBy func(Entity_V2) bool IsUsableBy func(Entity) bool
Use func(*engine.GameEventLog, *Dungeon, Entity_V2) Use func(*engine.GameEventLog, *Dungeon, Entity)
} }
type Item_EquippableComponent struct { type Item_EquippableComponent struct {
@ -71,7 +71,7 @@ type Item_MetaTypesComponent struct {
Types []ItemMetaType Types []ItemMetaType
} }
type BaseItem_V2 struct { type BaseItem struct {
tileIcon rune tileIcon rune
icon string icon string
style tcell.Style style tcell.Style
@ -87,56 +87,56 @@ type BaseItem_V2 struct {
metaTypes *Item_MetaTypesComponent metaTypes *Item_MetaTypesComponent
} }
func (i *BaseItem_V2) TileIcon() rune { func (i *BaseItem) TileIcon() rune {
return i.tileIcon return i.tileIcon
} }
func (i *BaseItem_V2) Icon() string { func (i *BaseItem) Icon() string {
return i.icon return i.icon
} }
func (i *BaseItem_V2) Style() tcell.Style { func (i *BaseItem) Style() tcell.Style {
return i.style return i.style
} }
func (i *BaseItem_V2) Type() ItemType { func (i *BaseItem) Type() ItemType {
return i.itemType return i.itemType
} }
func (i *BaseItem_V2) Quantifiable() *Item_QuantifiableComponent { func (i *BaseItem) Quantifiable() *Item_QuantifiableComponent {
return i.quantifiable return i.quantifiable
} }
func (i *BaseItem_V2) Usable() *Item_UsableComponent { func (i *BaseItem) Usable() *Item_UsableComponent {
return i.usable return i.usable
} }
func (i *BaseItem_V2) Equippable() *Item_EquippableComponent { func (i *BaseItem) Equippable() *Item_EquippableComponent {
return i.equippable return i.equippable
} }
func (i *BaseItem_V2) Named() *Item_NamedComponent { func (i *BaseItem) Named() *Item_NamedComponent {
return i.named return i.named
} }
func (i *BaseItem_V2) Described() *Item_DescribedComponent { func (i *BaseItem) Described() *Item_DescribedComponent {
return i.described return i.described
} }
func (i *BaseItem_V2) Damaging() *Item_DamagingComponent { func (i *BaseItem) Damaging() *Item_DamagingComponent {
return i.damaging return i.damaging
} }
func (i *BaseItem_V2) StatModifier() *Item_StatModifierComponent { func (i *BaseItem) StatModifier() *Item_StatModifierComponent {
return i.statModifier return i.statModifier
} }
func (i *BaseItem_V2) MetaTypes() *Item_MetaTypesComponent { func (i *BaseItem) MetaTypes() *Item_MetaTypesComponent {
return i.metaTypes return i.metaTypes
} }
func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.Style, components ...func(*BaseItem_V2)) *BaseItem_V2 { func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.Style, components ...func(*BaseItem)) *BaseItem {
i := &BaseItem_V2{ i := &BaseItem{
itemType: itemType, itemType: itemType,
tileIcon: tileIcon, tileIcon: tileIcon,
icon: icon, icon: icon,
@ -150,8 +150,8 @@ func createBaseItem(itemType ItemType, tileIcon rune, icon string, style tcell.S
return i return i
} }
func item_WithQuantity(quantity, maxQuantity int) func(*BaseItem_V2) { func item_WithQuantity(quantity, maxQuantity int) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.quantifiable = &Item_QuantifiableComponent{ bi.quantifiable = &Item_QuantifiableComponent{
CurrentQuantity: quantity, CurrentQuantity: quantity,
MaxQuantity: maxQuantity, 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) { func item_WithUsable(usabilityCheck func(Entity) bool, useFunc func(*engine.GameEventLog, *Dungeon, Entity)) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.usable = &Item_UsableComponent{ bi.usable = &Item_UsableComponent{
IsUsableBy: usabilityCheck, IsUsableBy: usabilityCheck,
Use: useFunc, 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) { func item_WithEquippable(slot EquippedSlot) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.equippable = &Item_EquippableComponent{ bi.equippable = &Item_EquippableComponent{
Slot: slot, Slot: slot,
} }
} }
} }
func item_WithDamaging(damageFunc func() (damage int, dmgType DamageType)) func(*BaseItem_V2) { func item_WithDamaging(damageFunc func() (damage int, dmgType DamageType)) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.damaging = &Item_DamagingComponent{ bi.damaging = &Item_DamagingComponent{
DamageRoll: damageFunc, DamageRoll: damageFunc,
} }
} }
} }
func item_WithName(name string, style tcell.Style) func(*BaseItem_V2) { func item_WithName(name string, style tcell.Style) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.named = &Item_NamedComponent{ bi.named = &Item_NamedComponent{
Name: name, Name: name,
Style: style, 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) { func item_WithDescription(description string, style tcell.Style) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.described = &Item_DescribedComponent{ bi.described = &Item_DescribedComponent{
Description: description, Description: description,
Style: style, Style: style,
@ -202,107 +202,18 @@ func item_WithDescription(description string, style tcell.Style) func(*BaseItem_
} }
} }
func item_WithStatModifiers(statModifiers []StatModifier) func(*BaseItem_V2) { func item_WithStatModifiers(statModifiers []StatModifier) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.statModifier = &Item_StatModifierComponent{ bi.statModifier = &Item_StatModifierComponent{
StatModifiers: statModifiers, StatModifiers: statModifiers,
} }
} }
} }
func item_WithMetaTypes(metaTypes []ItemMetaType) func(*BaseItem_V2) { func item_WithMetaTypes(metaTypes []ItemMetaType) func(*BaseItem) {
return func(bi *BaseItem_V2) { return func(bi *BaseItem) {
bi.metaTypes = &Item_MetaTypesComponent{ bi.metaTypes = &Item_MetaTypesComponent{
Types: metaTypes, 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 // Special
) )
func Item_Fish() Item_V2 { func Item_Fish() Item {
return createBaseItem( return createBaseItem(
ItemType_Fish, ItemType_Fish,
'>', '>',
@ -44,10 +44,10 @@ func Item_Fish() Item_V2 {
item_WithName("Fish", tcell.StyleDefault), item_WithName("Fish", tcell.StyleDefault),
item_WithDescription("On use heals for 1d4", tcell.StyleDefault), item_WithDescription("On use heals for 1d4", tcell.StyleDefault),
item_WithUsable( item_WithUsable(
func(e Entity_V2) bool { func(e Entity) bool {
return e.HealthData() != nil return e.HealthData() != nil
}, },
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) { func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData() damageable := e.HealthData()
if damageable != nil { if damageable != nil {
@ -67,7 +67,7 @@ func Item_Fish() Item_V2 {
) )
} }
func Item_SmallHealthPotion() Item_V2 { func Item_SmallHealthPotion() Item {
return createBaseItem( return createBaseItem(
ItemType_SmallHealthPotion, ItemType_SmallHealthPotion,
'ó', 'ó',
@ -77,10 +77,10 @@ func Item_SmallHealthPotion() Item_V2 {
item_WithName("Small Health Potion", tcell.StyleDefault), item_WithName("Small Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 2d6", tcell.StyleDefault), item_WithDescription("On use heals for 2d6", tcell.StyleDefault),
item_WithUsable( item_WithUsable(
func(e Entity_V2) bool { func(e Entity) bool {
return e.HealthData() != nil return e.HealthData() != nil
}, },
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) { func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData() damageable := e.HealthData()
if damageable != nil { if damageable != nil {
@ -100,7 +100,7 @@ func Item_SmallHealthPotion() Item_V2 {
) )
} }
func Item_HealthPotion() Item_V2 { func Item_HealthPotion() Item {
return createBaseItem( return createBaseItem(
ItemType_HealthPotion, ItemType_HealthPotion,
'ó', 'ó',
@ -110,10 +110,10 @@ func Item_HealthPotion() Item_V2 {
item_WithName("Health Potion", tcell.StyleDefault), item_WithName("Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 3d6", tcell.StyleDefault), item_WithDescription("On use heals for 3d6", tcell.StyleDefault),
item_WithUsable( item_WithUsable(
func(e Entity_V2) bool { func(e Entity) bool {
return e.HealthData() != nil return e.HealthData() != nil
}, },
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) { func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData() damageable := e.HealthData()
if damageable != nil { if damageable != nil {
@ -133,7 +133,7 @@ func Item_HealthPotion() Item_V2 {
) )
} }
func Item_LargeHealthPotion() Item_V2 { func Item_LargeHealthPotion() Item {
return createBaseItem( return createBaseItem(
ItemType_LargeHealthPotion, ItemType_LargeHealthPotion,
'ó', 'ó',
@ -143,10 +143,10 @@ func Item_LargeHealthPotion() Item_V2 {
item_WithName("Large Health Potion", tcell.StyleDefault), item_WithName("Large Health Potion", tcell.StyleDefault),
item_WithDescription("On use heals for 4d6", tcell.StyleDefault), item_WithDescription("On use heals for 4d6", tcell.StyleDefault),
item_WithUsable( item_WithUsable(
func(e Entity_V2) bool { func(e Entity) bool {
return e.HealthData() != nil return e.HealthData() != nil
}, },
func(log *engine.GameEventLog, d *Dungeon, e Entity_V2) { func(log *engine.GameEventLog, d *Dungeon, e Entity) {
damageable := e.HealthData() damageable := e.HealthData()
if damageable != nil { if damageable != nil {
@ -166,7 +166,7 @@ func Item_LargeHealthPotion() Item_V2 {
) )
} }
func Item_Bow() Item_V2 { func Item_Bow() Item {
return createBaseItem( return createBaseItem(
ItemType_Bow, ItemType_Bow,
')', ')',
@ -183,7 +183,7 @@ func Item_Bow() Item_V2 {
) )
} }
func Item_Longsword() Item_V2 { func Item_Longsword() Item {
return createBaseItem( return createBaseItem(
ItemType_Longsword, ItemType_Longsword,
'/', '/',
@ -200,7 +200,7 @@ func Item_Longsword() Item_V2 {
) )
} }
func Item_Club() Item_V2 { func Item_Club() Item {
return createBaseItem( return createBaseItem(
ItemType_Club, ItemType_Club,
'!', '!',
@ -217,7 +217,7 @@ func Item_Club() Item_V2 {
) )
} }
func Item_Dagger() Item_V2 { func Item_Dagger() Item {
return createBaseItem( return createBaseItem(
ItemType_Dagger, ItemType_Dagger,
'-', '-',
@ -234,7 +234,7 @@ func Item_Dagger() Item_V2 {
) )
} }
func Item_Handaxe() Item_V2 { func Item_Handaxe() Item {
return createBaseItem( return createBaseItem(
ItemType_Handaxe, ItemType_Handaxe,
'¶', '¶',
@ -251,7 +251,7 @@ func Item_Handaxe() Item_V2 {
) )
} }
func Item_Javelin() Item_V2 { func Item_Javelin() Item {
return createBaseItem( return createBaseItem(
ItemType_Javelin, ItemType_Javelin,
'Î', 'Î',
@ -268,7 +268,7 @@ func Item_Javelin() Item_V2 {
) )
} }
func Item_LightHammer() Item_V2 { func Item_LightHammer() Item {
return createBaseItem( return createBaseItem(
ItemType_LightHammer, ItemType_LightHammer,
'i', 'i',
@ -285,7 +285,7 @@ func Item_LightHammer() Item_V2 {
) )
} }
func Item_Mace() Item_V2 { func Item_Mace() Item {
return createBaseItem( return createBaseItem(
ItemType_Mace, ItemType_Mace,
'i', 'i',
@ -302,7 +302,7 @@ func Item_Mace() Item_V2 {
) )
} }
func Item_Quarterstaff() Item_V2 { func Item_Quarterstaff() Item {
return createBaseItem( return createBaseItem(
ItemType_Quarterstaff, ItemType_Quarterstaff,
'|', '|',
@ -319,7 +319,7 @@ func Item_Quarterstaff() Item_V2 {
) )
} }
func Item_Sickle() Item_V2 { func Item_Sickle() Item {
return createBaseItem( return createBaseItem(
ItemType_Sickle, ItemType_Sickle,
'?', '?',
@ -336,7 +336,7 @@ func Item_Sickle() Item_V2 {
) )
} }
func Item_Spear() Item_V2 { func Item_Spear() Item {
return createBaseItem( return createBaseItem(
ItemType_Spear, 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 { // func ItemTypeGold() ItemType {
// return &BasicItemType{ // return &BasicItemType{
// id: 1, // 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 const MaxNumberOfModifiers = 6
type ItemSupplier func() Item_V2 type ItemSupplier func() Item
type LootTable struct { type LootTable struct {
table []ItemSupplier 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))]() 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 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. // 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 { if prototype.Named() == nil {
return prototype return prototype
} }
@ -275,8 +275,6 @@ func GenerateItemOfTypeAndRarity(prototype Item_V2, rarity ItemRarity) Item_V2 {
existingName := prototype.Named().Name existingName := prototype.Named().Name
metaTypes := prototype.MetaTypes().Types metaTypes := prototype.MetaTypes().Types
// points := pointPerRarity(rarity)
name, style := generateItemName(existingName, rarity) name, style := generateItemName(existingName, rarity)
statModifiers := generateItemStatModifiers(metaTypes, 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: // Base Max Health is determined from constitution:
// 5*Constitution + Max Health Bonus // 5*Constitution + Max Health Bonus
func BaseMaxHealth(entity Entity_V2) int { func BaseMaxHealth(entity Entity) int {
stats := entity.Stats() stats := entity.Stats()
if stats == nil { if stats == nil {
@ -286,7 +286,7 @@ func BaseMaxHealth(entity Entity_V2) int {
} }
// Dexterity + Evasion bonus + luck roll // Dexterity + Evasion bonus + luck roll
func EvasionRoll(victim Entity_V2) int { func EvasionRoll(victim Entity) int {
if victim.Stats() == nil { if victim.Stats() == nil {
return 0 return 0
} }
@ -295,7 +295,7 @@ func EvasionRoll(victim Entity_V2) int {
} }
// Strength + Precision bonus ( melee + total ) + luck roll // Strength + Precision bonus ( melee + total ) + luck roll
func PhysicalPrecisionRoll(attacker Entity_V2) int { func PhysicalPrecisionRoll(attacker Entity) int {
if attacker.Stats() == nil { if attacker.Stats() == nil {
return 0 return 0
} }
@ -304,7 +304,7 @@ func PhysicalPrecisionRoll(attacker Entity_V2) int {
} }
// Intelligence + Precision bonus ( magic + total ) + luck roll // Intelligence + Precision bonus ( magic + total ) + luck roll
func MagicPrecisionRoll(attacker Entity_V2) int { func MagicPrecisionRoll(attacker Entity) int {
if attacker.Stats() == nil { if attacker.Stats() == nil {
return 0 return 0
} }
@ -313,12 +313,12 @@ func MagicPrecisionRoll(attacker Entity_V2) int {
} }
// true = hit lands, false = hit does not land // 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)) return hitRoll(EvasionRoll(victim), MagicPrecisionRoll(attacker))
} }
// true = hit lands, false = hit does not land // 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) evasion = EvasionRoll(victim)
precision = PhysicalPrecisionRoll(attacker) precision = PhysicalPrecisionRoll(attacker)
hit = hitRoll(evasion, precision) hit = hitRoll(evasion, precision)
@ -330,7 +330,7 @@ func hitRoll(evasionRoll, precisionRoll int) bool {
return evasionRoll < precisionRoll return evasionRoll < precisionRoll
} }
func UnarmedDamage(attacker Entity_V2) int { func UnarmedDamage(attacker Entity) int {
if attacker.Stats() == nil { if attacker.Stats() == nil {
return 0 return 0
} }
@ -338,7 +338,7 @@ func UnarmedDamage(attacker Entity_V2) int {
return RollD4(1) + statValue(attacker.Stats(), Stat_DamageBonus_Physical_Unarmed) 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 { if attacker.Stats() == nil || weapon.Damaging() == nil || victim.Stats() == nil {
return 0, DamageType_Physical_Unarmed return 0, DamageType_Physical_Unarmed
} }
@ -353,7 +353,7 @@ func PhysicalWeaponDamage(attacker Entity_V2, weapon Item_V2, victim Entity_V2)
return 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) hit, evasionRoll, precisionRoll = PhysicalHitRoll(attacker, victim)
if !hit { if !hit {
@ -366,7 +366,7 @@ func UnarmedAttack(attacker Entity_V2, victim Entity_V2) (hit bool, precisionRol
return 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) hit, evasionRoll, precisionRoll = PhysicalHitRoll(attacker, victim)
if !hit { if !hit {

View file

@ -89,20 +89,20 @@ func (d *Dungeon) HasNextLevel() bool {
} }
type DungeonLevel struct { type DungeonLevel struct {
ground Map_V2 ground Map
entitiesByPosition map[engine.Position]Entity_V2 entitiesByPosition map[engine.Position]Entity
entities map[uuid.UUID]Entity_V2 entities map[uuid.UUID]Entity
} }
func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *DungeonLevel) { func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *DungeonLevel) {
genTable := CreateLootTable() genTable := CreateLootTable()
genTable.Add(1, func() Item_V2 { genTable.Add(1, func() Item {
return Item_HealthPotion() return Item_HealthPotion()
}) })
itemPool := []Item_V2{ itemPool := []Item{
Item_Bow(), Item_Bow(),
Item_Longsword(), Item_Longsword(),
Item_Club(), Item_Club(),
@ -116,7 +116,7 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
Item_Spear(), Item_Spear(),
} }
genTable.Add(1, func() Item_V2 { genTable.Add(1, func() Item {
item := itemPool[rand.Intn(len(itemPool))] item := itemPool[rand.Intn(len(itemPool))]
rarities := []ItemRarity{ rarities := []ItemRarity{
@ -130,7 +130,7 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
return GenerateItemOfTypeAndRarity(item, rarities[rand.Intn(len(rarities))]) return GenerateItemOfTypeAndRarity(item, rarities[rand.Intn(len(rarities))])
}) })
var groundLevel Map_V2 var groundLevel Map
switch dungeonType { switch dungeonType {
case DungeonTypeBSP: case DungeonTypeBSP:
@ -141,8 +141,8 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
dLevel = &DungeonLevel{ dLevel = &DungeonLevel{
ground: groundLevel, ground: groundLevel,
entities: map[uuid.UUID]Entity_V2{}, entities: map[uuid.UUID]Entity{},
entitiesByPosition: map[engine.Position]Entity_V2{}, entitiesByPosition: map[engine.Position]Entity{},
} }
if groundLevel.Rooms() == nil { if groundLevel.Rooms() == nil {
@ -183,10 +183,10 @@ func CreateDungeonLevel(width, height int, dungeonType DungeonType) (dLevel *Dun
return dLevel 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 rooms := spawnableAreas
itemLocations := make(map[engine.Position]Item_V2, 0) itemLocations := make(map[engine.Position]Item, 0)
for _, r := range rooms { for _, r := range rooms {
maxItems := int(maxItemRatio * float32(r.Size().Area())) maxItems := int(maxItemRatio * float32(r.Size().Area()))
@ -220,7 +220,7 @@ func SpawnItems(spawnableAreas []engine.BoundingBox, maxItemRatio float32, genTa
return itemLocations return itemLocations
} }
func (d *DungeonLevel) Ground() Map_V2 { func (d *DungeonLevel) Ground() Map {
return d.ground return d.ground
} }
@ -234,7 +234,7 @@ func (d *DungeonLevel) DropEntity(uuid uuid.UUID) {
delete(d.entities, uuid) delete(d.entities, uuid)
} }
func (d *DungeonLevel) AddEntity(entity Entity_V2) { func (d *DungeonLevel) AddEntity(entity Entity) {
d.entities[entity.UniqueId()] = entity d.entities[entity.UniqueId()] = entity
if entity.Positioned() != nil { if entity.Positioned() != nil {
@ -260,7 +260,7 @@ func (d *DungeonLevel) RemoveEntityAt(x, y int) {
delete(d.entitiesByPosition, engine.PositionAt(x, y)) 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) { if !Map_IsInBounds(d.ground, x, y) {
return nil return nil
} }
@ -278,7 +278,7 @@ func (d *DungeonLevel) RemoveItemAt(x, y int) (item Item_V2) {
return 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() { if !d.TileAt(x, y).Passable() {
return false return false
} }
@ -290,7 +290,7 @@ func (d *DungeonLevel) SetItemAt(x, y int, it Item_V2) (success bool) {
return true 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)] entity := d.entitiesByPosition[engine.PositionAt(x, y)]
tile := Map_TileAt(d.ground, x, y) tile := Map_TileAt(d.ground, x, y)
@ -315,7 +315,7 @@ func (d *DungeonLevel) IsTilePassable(x, y int) bool {
return tile.Passable() 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)] 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 splitDir splitDirection
} }
func CreateBSPDungeonMap(width, height int, numSplits int) Map_V2 { func CreateBSPDungeonMap(width, height int, numSplits int) Map {
root := new(bspNode) root := new(bspNode)
root.origin = engine.PositionAt(0, 0) root.origin = engine.PositionAt(0, 0)
@ -35,10 +35,10 @@ func CreateBSPDungeonMap(width, height int, numSplits int) Map_V2 {
split(root, numSplits) split(root, numSplits)
tiles := make([][]Tile_V2, height) tiles := make([][]Tile, height)
for h := range height { for h := range height {
tiles[h] = make([]Tile_V2, width) tiles[h] = make([]Tile, width)
} }
rooms := make([]engine.BoundingBox, 0, numSplits*numSplits) 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.NextLevelStaircase().Position.X(), newBsp.NextLevelStaircase().Position.Y(), Tile_StaircaseDown())
Map_SetTileAt(newBsp, newBsp.PreviousLevelStaircase().Position.X(), newBsp.PreviousLevelStaircase().Position.Y(), Tile_StaircaseUp()) 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 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 { switch direction {
case splitDirectionHorizontal: case splitDirectionHorizontal:
xMidPoint := (from.X() + to.X()) / 2 xMidPoint := (from.X() + to.X()) / 2
@ -228,7 +210,7 @@ func split(parent *bspNode, numSplits int) {
split(parent.right, numSplits-1) 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 { if x1 > x2 {
tx := x2 tx := x2
x2 = x1 x2 = x1
@ -255,7 +237,7 @@ func horizontalTunnel(tiles [][]Tile_V2, x1, x2, y int) {
placeWallAtIfNotPassable(tiles, x2, y+1) 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 { if y1 > y2 {
ty := y2 ty := y2
y2 = y1 y2 = y1
@ -282,7 +264,7 @@ func verticalTunnel(tiles [][]Tile_V2, y1, y2, x int) {
placeWallAtIfNotPassable(tiles, x+1, y2) 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() { if tiles[y][x] != nil && tiles[y][x].Passable() {
return return
} }
@ -290,7 +272,7 @@ func placeWallAtIfNotPassable(tiles [][]Tile_V2, x, y int) {
tiles[y][x] = Tile_Wall() tiles[y][x] = Tile_Wall()
} }
func makeRoom(tiles [][]Tile_V2, room engine.BoundingBox) { func makeRoom(tiles [][]Tile, room engine.BoundingBox) {
width := room.Size().Width() width := room.Size().Width()
height := room.Size().Height() height := room.Size().Height()
x := room.Position().X() 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" "github.com/gdamore/tcell/v2"
) )
type Map_V2 interface { type Map interface {
Size() engine.Size Size() engine.Size
Tiles() [][]Tile_V2 Tiles() [][]Tile
ExploredTiles() map[engine.Position]Tile_V2 ExploredTiles() map[engine.Position]Tile
ExploredTileStyle() tcell.Style ExploredTileStyle() tcell.Style
DefaultTile() Tile_V2 DefaultTile() Tile
PlayerSpawnPoint() *Map_PlayerSpawnPointComponent PlayerSpawnPoint() *Map_PlayerSpawnPointComponent
Rooms() *Map_RoomsComponent Rooms() *Map_RoomsComponent
@ -37,10 +37,10 @@ type Map_PreviousLevelStaircaseComponent struct {
type BaseMap struct { type BaseMap struct {
size engine.Size size engine.Size
tiles [][]Tile_V2 tiles [][]Tile
exploredTiles map[engine.Position]Tile_V2 exploredTiles map[engine.Position]Tile
exploredStyle tcell.Style exploredStyle tcell.Style
defaultTile Tile_V2 defaultTile Tile
playerSpawnPos *Map_PlayerSpawnPointComponent playerSpawnPos *Map_PlayerSpawnPointComponent
rooms *Map_RoomsComponent rooms *Map_RoomsComponent
@ -48,11 +48,11 @@ type BaseMap struct {
prevLevel *Map_PreviousLevelStaircaseComponent 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{ m := &BaseMap{
size: size, size: size,
tiles: tiles, tiles: tiles,
exploredTiles: make(map[engine.Position]Tile_V2, 0), exploredTiles: make(map[engine.Position]Tile, 0),
exploredStyle: exploredStyle, exploredStyle: exploredStyle,
defaultTile: defaultTile, defaultTile: defaultTile,
} }
@ -68,11 +68,11 @@ func (m *BaseMap) Size() engine.Size {
return m.size return m.size
} }
func (m *BaseMap) Tiles() [][]Tile_V2 { func (m *BaseMap) Tiles() [][]Tile {
return m.tiles return m.tiles
} }
func (m *BaseMap) ExploredTiles() map[engine.Position]Tile_V2 { func (m *BaseMap) ExploredTiles() map[engine.Position]Tile {
return m.exploredTiles return m.exploredTiles
} }
@ -80,7 +80,7 @@ func (m *BaseMap) ExploredTileStyle() tcell.Style {
return m.exploredStyle return m.exploredStyle
} }
func (m *BaseMap) DefaultTile() Tile_V2 { func (m *BaseMap) DefaultTile() Tile {
return m.defaultTile 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) { if !Map_IsInBounds(bm, x, y) {
return bm.DefaultTile() 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] 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) { if !Map_IsInBounds(bm, x, y) {
return bm.DefaultTile() return bm.DefaultTile()
} }
@ -156,7 +156,7 @@ func Map_TileAt(bm Map_V2, x int, y int) Tile_V2 {
return tile 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 { if x < 0 || y < 0 {
return false return false
} }
@ -168,11 +168,11 @@ func Map_IsInBounds(bm Map_V2, x, y int) bool {
return true 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)] 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) { if !Map_IsInBounds(bm, x, y) {
return 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 { type Tile_ItemComponent struct {
Item Item_V2 Item Item
} }
type Tile_EntityComponent struct { type Tile_EntityComponent struct {
Entity Entity_V2 Entity Entity
} }
type Tile_V2 interface { type Tile interface {
DefaultPresentation() (rune, tcell.Style) DefaultPresentation() (rune, tcell.Style)
Material() Material Material() Material
Passable() bool Passable() bool
@ -35,11 +35,11 @@ type Tile_V2 interface {
Item() *Tile_ItemComponent Item() *Tile_ItemComponent
RemoveItem() RemoveItem()
WithItem(item Item_V2) WithItem(item Item)
Entity() *Tile_EntityComponent Entity() *Tile_EntityComponent
RemoveEntity() RemoveEntity()
WithEntity(entity Entity_V2) WithEntity(entity Entity)
} }
type BaseTile struct { type BaseTile struct {
@ -53,7 +53,7 @@ type BaseTile struct {
entity *Tile_EntityComponent 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() defaultSymbol, defaultStyle := prototype.DefaultPresentation()
return CreateTile( 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{ t := &BaseTile{
defaultSymbol: defaultSymbol, defaultSymbol: defaultSymbol,
defaultStyle: defaultStyle, defaultStyle: defaultStyle,
@ -112,7 +112,7 @@ func (t *BaseTile) RemoveItem() {
t.item = nil t.item = nil
} }
func (t *BaseTile) WithItem(item Item_V2) { func (t *BaseTile) WithItem(item Item) {
t.item = &Tile_ItemComponent{ t.item = &Tile_ItemComponent{
Item: item, Item: item,
} }
@ -126,13 +126,13 @@ func (t *BaseTile) RemoveEntity() {
t.entity = nil t.entity = nil
} }
func (t *BaseTile) WithEntity(entity Entity_V2) { func (t *BaseTile) WithEntity(entity Entity) {
t.entity = &Tile_EntityComponent{ t.entity = &Tile_EntityComponent{
Entity: entity, Entity: entity,
} }
} }
func Tile_WithEntity(entity Entity_V2) func(*BaseTile) { func Tile_WithEntity(entity Entity) func(*BaseTile) {
return func(bt *BaseTile) { return func(bt *BaseTile) {
bt.entity = &Tile_EntityComponent{ bt.entity = &Tile_EntityComponent{
Entity: entity, 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) { return func(bt *BaseTile) {
bt.item = &Tile_ItemComponent{ bt.item = &Tile_ItemComponent{
Item: item, 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( return CreateTile(
' ', ' ',
tcell.StyleDefault, tcell.StyleDefault,
@ -157,7 +157,7 @@ func Tile_Void() Tile_V2 {
) )
} }
func Tile_Ground() Tile_V2 { func Tile_Ground() Tile {
return CreateTile( return CreateTile(
'.', '.',
tcell.StyleDefault, tcell.StyleDefault,
@ -166,7 +166,7 @@ func Tile_Ground() Tile_V2 {
) )
} }
func Tile_Rock() Tile_V2 { func Tile_Rock() Tile {
return CreateTile( return CreateTile(
'█', '█',
tcell.StyleDefault, tcell.StyleDefault,
@ -175,7 +175,7 @@ func Tile_Rock() Tile_V2 {
) )
} }
func Tile_Wall() Tile_V2 { func Tile_Wall() Tile {
return CreateTile( return CreateTile(
'#', '#',
tcell.StyleDefault.Background(tcell.ColorGray), 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( return CreateTile(
'≡', '≡',
tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray).Attributes(tcell.AttrBold), 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( return CreateTile(
'^', '^',
tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray).Attributes(tcell.AttrBold), tcell.StyleDefault.Foreground(tcell.ColorDarkSlateGray).Attributes(tcell.AttrBold),

View file

@ -21,10 +21,10 @@ type InventoryScreenState struct {
inventoryMenu *menu.PlayerInventoryMenu inventoryMenu *menu.PlayerInventoryMenu
selectedInventorySlot engine.Position 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 := new(InventoryScreenState)
iss.eventLog = eventLog iss.eventLog = eventLog

View file

@ -15,8 +15,8 @@ type PlayingState struct {
turnSystem *systems.TurnSystem turnSystem *systems.TurnSystem
inputSystem *systems.InputSystem inputSystem *systems.InputSystem
player *model.Player_V2 player *model.Player
someNPC model.Entity_V2 someNPC model.Entity
eventLog *engine.GameEventLog eventLog *engine.GameEventLog
uiEventLog *ui.UIEventLog 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.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.X(),
s.dungeon.CurrentLevel().Ground().PlayerSpawnPoint().Position.Y(), s.dungeon.CurrentLevel().Ground().PlayerSpawnPoint().Position.Y(),
playerStats, 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) hit, precision, evasion, dmg, dmgType := CalculateAttack(attacker, victim)
attackerName := "Unknown" 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))) 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 { if attacker.Equipped() != nil && attacker.Equipped().Inventory.AtSlot(model.EquippedSlotDominantHand) != nil {
weapon := attacker.Equipped().Inventory.AtSlot(model.EquippedSlotDominantHand) 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 { func (ps *PlayingState) CollectDrawables() []engine.Drawable {
mainCameraDrawingInstructions := engine.CreateDrawingInstructions(func(v views.View) { mainCameraDrawingInstructions := engine.CreateDrawingInstructions(func(v views.View) {
visibilityMap := engine.ComputeFOV( 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) model.Map_MarkExplored(ps.dungeon.CurrentLevel().Ground(), x, y)
return ps.dungeon.CurrentLevel().TileAt(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 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 { if item.Quantifiable() != nil {
ui.CreateSingleLineUILabel( ui.CreateSingleLineUILabel(
screenX, screenX,

View file

@ -14,14 +14,14 @@ import (
type UIHealthBar struct { type UIHealthBar struct {
id uuid.UUID id uuid.UUID
player *model.Player_V2 player *model.Player
window *UIWindow window *UIWindow
style tcell.Style 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{ return &UIHealthBar{
window: CreateWindow(x, y, w, h, "HP", style), window: CreateWindow(x, y, w, h, "HP", style),
player: player, player: player,

View file

@ -13,7 +13,7 @@ import (
type UIItem struct { type UIItem struct {
id uuid.UUID id uuid.UUID
item model.Item_V2 item model.Item
window UIWindow window UIWindow
@ -21,7 +21,7 @@ type UIItem struct {
engine.Sized 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{ return &UIItem{
id: uuid.New(), id: uuid.New(),
item: item, item: item,