CabinGame/Luxe/blocks/adventures.wren

103 lines
2.3 KiB
Text
Raw Normal View History

2020-09-19 14:06:46 +00:00
import "math/observable" for Observable
import "luxe: world" for Entity, Values, Tags
2020-09-19 20:38:55 +00:00
import "globals" for Globals
2020-10-23 13:25:53 +00:00
import "blocks/resources" for Resources
2020-10-31 14:13:01 +00:00
import "math/stringUtil" for StringUtil
import "blocks/human/human" for Human
2020-09-19 14:06:46 +00:00
class Adventures{
planning{_planning}
max_distance{_max_distance}
2020-09-19 14:06:46 +00:00
construct new(){
_planning = Observable.new()
_in_progress = []
_archive = []
_max_distance = 10
2020-10-31 14:13:01 +00:00
_game = Globals["Game"]
2020-09-19 14:06:46 +00:00
}
plan_new(){
2020-10-31 14:13:01 +00:00
System.print("Start planning new Adventure")
2020-09-19 20:38:55 +00:00
var adventure = Adventure.new()
2020-10-31 14:13:01 +00:00
adventure.distance = 2
2020-09-19 14:06:46 +00:00
_planning.value = adventure
return adventure
}
2020-10-31 14:13:01 +00:00
dispatch(){
var adventure = _planning.value
if(!adventure){
System.print("Tried to dispatch adventure, but none is planned")
return
}
System.print("Dispatching adventure \"%(adventure)\"")
adventure.setup()
adventure.adventurers.each{|human|
Human.set_active(human, false)
if(_game.focus.value == human) _game.focus.value = null
2020-10-31 14:13:01 +00:00
}
adventure.resources.list().each{|resource|
_game.resources.remove(resource["base_name"], resource["amount"])
}
_in_progress.add(adventure)
_planning.value = null
}
tick(){
//check some stuff that needs to be checked from time to time
//once per second/minute/whatever should be enough
}
2020-09-19 14:06:46 +00:00
new_or_current(){
if(_planning.value) return _planning.value
return plan_new()
}
discard(){
_planning.value = null
}
2020-10-04 16:35:12 +00:00
set_max_distance(dist){
_max_distance = dist
planning.emit()
}
2020-09-19 20:38:55 +00:00
}
class Adventure{
adventurers{_adventurers}
resources{_resources}
data{_data}
2020-09-25 08:42:41 +00:00
direction{_direction}
direction=(dir){_direction = dir}
distance{_distance}
distance=(dist){_distance = dist}
2020-09-19 20:38:55 +00:00
2020-10-31 14:13:01 +00:00
toString{
return "%(adventurers.map{|id| Human.get_name(id)}.toList)"+
" travelling %(distance)km towards %(StringUtil.direction(direction))"+
" with %(resources.list().map{|resource| "%(resource["amount"]) %(resource["name"])"}.toList)"
}
2020-09-19 20:38:55 +00:00
construct new(){
_adventurers = []
2020-10-23 13:25:53 +00:00
_resources = Resources.new()
2020-09-19 20:38:55 +00:00
_data = {}
2020-09-25 08:42:41 +00:00
_direction = 0
_distance = 0
2020-09-19 20:38:55 +00:00
}
2020-10-31 14:13:01 +00:00
setup(){
}
2020-09-19 20:38:55 +00:00
add_adventurer(adventurer){
_adventurers.add(adventurer)
}
add_resource(resource){
_resources.add(resource)
}
2020-09-19 14:06:46 +00:00
}