This commit is contained in:
thefish 2019-11-15 21:24:42 +03:00
parent b3c7beec2b
commit 62f45b920f
12 changed files with 144 additions and 21 deletions

22
TODO
View File

@ -16,16 +16,22 @@ Basics:
- ai
- dijkstra maps
Tech:
- fix connector position - 1 tile inside
+ fix connector position
- xecutors fov algo
- M.Kitsch fov algo
- milazzo fov algo
- naive bresenham algo
Assets and i18n:
- move tile settings to json, generate from there (part of prefabs)
move tile settings to json:
+ tile export
- tile import
- prepare all interface entries for i18n
- all texts (terrain, mobs, quests) also in at least 2 languages
ECS & engine:
- implement time queue (how to deal with closures?) (?) github.com/thefish/scheduleq - get rid od time.Now inside
- systems message queue
- implement timeQueue (how to deal with closures?) (?) github.com/thefish/scheduleq - get rid od time.Now inside
- move all rendering to systems
- try to move input handling to systems
@ -47,14 +53,12 @@ Dungeon and branches:
Combat:
- generate skeleton / intesines / muscle / eyes&ears & fingers from templates
- serializable
- config in outer files
- config in json files
- mass
- damage from skill / mass / speed / material density
- no hitpoints! blood is the life source
- pain is measure of nervous system load, lose conscience if its aboe threshold
Quest engine:
- look at parsers like URQL etc
- distorted Aschenputtel story / partisans / rapist prince / Grey Mountains
- distorted Aschenputtel story / partisans / rapist prince / Grey Mountains

View File

@ -13,6 +13,7 @@ const ArmsComponent = "arms"
const RangedComponent = "ranged"
const AmmoComponent = "ammo"
const ArmorComponent = "armor"
const BackpackComponent = "backpack"
type Component interface {
Type() string

View File

@ -21,3 +21,18 @@ func TypeInSlice(a string, list []string) bool {
}
return false
}
func DeleteFromEntitySlice(haystack []Entity, needle Entity) ([]Entity, Entity) {
var excluded Entity
for i, _ := range haystack {
if haystack[i] == needle {
excluded = haystack[i]
if len(haystack) - 1 > i {
haystack = append(haystack[:i], haystack[i+1:] ...)
} else {
haystack = haystack[:i]
}
}
}
return haystack, excluded
}

View File

@ -9,6 +9,6 @@ type Ammo struct {
itemprops.DamageProfile
}
func (a *Ammo) Type() string {
func (a Ammo) Type() string {
return ecs.AmmoComponent
}

View File

@ -6,6 +6,6 @@ type Armor struct {
DefenceProfile struct{}
}
func (a *Armor) Type() string {
func (a Armor) Type() string {
return ecs.ArmorComponent
}

33
engine/items/backpack.go Normal file
View File

@ -0,0 +1,33 @@
package items
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
type Backpack struct {
MaxNumber int
MaxBulk int
MaxMass int
items []ecs.Entity
}
func (b Backpack) Type() string {
return ecs.BackpackComponent
}
func (b *Backpack) HasFreeSpace(Bulk, Mass int) bool {
totalBulk, totalMass := 0, 0
for i, _ := range b.items {
tmp := Controller.GetComponent(b.items[i], Carried{}.Type()).(Carried)
carried := tmp
totalBulk += carried.Bulk
totalMass += carried.Mass
}
if totalMass >= b.MaxMass {
//fixme return message along - 'too heavy'
return false
}
if totalBulk >= b.MaxMass {
//fixme return message along - 'doesnt fit to your backpack'
return false
}
return true
}

View File

@ -1,6 +1,9 @@
package items
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
import (
"lab.zaar.be/thefish/alchemyst-go/engine/ecs"
"lab.zaar.be/thefish/alchemyst-go/engine/types"
)
type CarriedFace interface {
Drop()
@ -12,16 +15,74 @@ type Carried struct {
Bulk int //внешний размер, см3
}
func (c *Carried) Type() string {
func (c Carried) Type() string {
return ecs.CarriedComponent
}
func (c *Carried) Pickup() {}
func (c *Carried) Drop() {}
func (c Carried) Pickup(who, what ecs.Entity) {
// check if im lying on ground
if !Controller.HasComponent(what, ecs.CoordsComponent) {
return
}
// something inexistent on map trying to pickup an item?!
if !Controller.HasComponent(who, ecs.CoordsComponent) {
//todo log error - investigate this situation
return
}
//check if who and what are on the same tile
whoCoords := Controller.GetComponent(who, ecs.CoordsComponent).(types.Coords)
whatCoords := Controller.GetComponent(what, ecs.CoordsComponent).(types.Coords)
if whoCoords != whatCoords {
//todo log error - something strange happened
return
}
//does not have inventory?
if !Controller.HasComponent(who, ecs.BackpackComponent) {
//todo send message - you cant carry items
return
}
bp := Controller.GetComponent(who, Backpack{}.Type()).(Backpack)
if !bp.HasFreeSpace(c.Bulk, c.Mass) {
//todo send message - does not fit to your inventory
return
}
//do not remove appearance
//remove coords instead (does not exist on map anymore)
Controller.RemoveComponent(what, ecs.CoordsComponent)
bp.items = append(bp.items, what)
}
func (c *Carried) GetMass() int {
func (c Carried) Drop(who, what ecs.Entity) {
var coords types.Coords
// something inexistent on map trying to drop an item?!
if !Controller.HasComponent(who, ecs.CoordsComponent) {
//todo log error - investigate this situation
return
} else {
coords = Controller.GetComponent(who, types.Coords{}.Type()).(types.Coords)
}
//does not have inventory?
if !Controller.HasComponent(who, ecs.BackpackComponent) {
//todo send message - you cant carry items
return
}
bp := Controller.GetComponent(who, Backpack{}.Type()).(Backpack)
var dropped ecs.Entity
bp.items, dropped = ecs.DeleteFromEntitySlice(bp.items, what)
if dropped != what {
//todo log error - something strange happened
return
}
//Give dropped back coordinated
Controller.AddComponent(dropped, coords)
//Controller.UpdateComponent(what, coords.Type(), coords) //even we need that?
Controller.UpdateComponent(who, bp.Type(), bp)
}
func (c Carried) GetMass(what ecs.Entity) int {
return c.Mass
}
func (c *Carried) GetBulk() int {
func (c *Carried) GetBulk(what ecs.Entity) int {
return c.Bulk
}

9
engine/items/common.go Normal file
View File

@ -0,0 +1,9 @@
package items
import "lab.zaar.be/thefish/alchemyst-go/engine/ecs"
var Controller ecs.Controller
func Init(ctrl ecs.Controller) {
Controller = ctrl
}

View File

@ -6,6 +6,6 @@ type Ranged struct {
RangeProfile struct{} //это зависимость дальности-скорости от характеристик и атрибутов
}
func (r *Ranged) Type() string {
func (r Ranged) Type() string {
return ecs.RangedComponent
}

View File

@ -9,7 +9,7 @@ type UsableFace interface {
type Usable struct {}
func (u *Usable) Type() string {
func (u Usable) Type() string {
return ecs.UsableComponent
}

View File

@ -11,6 +11,6 @@ type Wearable struct {
Bodypart int //куда собстно одевать
}
func (w *Wearable) Type() string {
func (w Wearable) Type() string {
return ecs.WearableComponent
}

View File

@ -9,7 +9,7 @@ type Coords struct {
X, Y int
}
func (сс Coords) Type() string {
func (cc Coords) Type() string {
return ecs.CoordsComponent
}