diff --git a/cardinal/component/effect.go b/cardinal/component/effect.go index 254f777..63260f9 100644 --- a/cardinal/component/effect.go +++ b/cardinal/component/effect.go @@ -13,8 +13,9 @@ func GetAllEffectTypes() []EffectType { } type Effect struct { - Type EffectType `json:"type"` - Amount int `json:"amount"` + Type EffectType `json:"type"` + Amount int `json:"amount"` + Capacity int `json:"capacity,omitempty"` } func (Effect) Name() string { diff --git a/cardinal/component/farming.go b/cardinal/component/farming.go index d7f1535..93edf8f 100644 --- a/cardinal/component/farming.go +++ b/cardinal/component/farming.go @@ -1,8 +1,9 @@ package component type Farming struct { - Type ResourceType `json:"type"` - Speed float32 `json:"speed"` + Type ResourceType `json:"type"` + Speed float32 `json:"speed"` + Capacity int `json:"capacity,omitempty"` } func (Farming) Name() string { diff --git a/cardinal/component/player_resources.go b/cardinal/component/player_resources.go index a844126..b3ce2a7 100644 --- a/cardinal/component/player_resources.go +++ b/cardinal/component/player_resources.go @@ -3,7 +3,6 @@ package component type PlayerResources struct { Resources []Resource `json:"resources"` Effects []Effect `json:"effects"` - // Farming []Farming `json:"farming"` } func (PlayerResources) Name() string { diff --git a/cardinal/component/resource.go b/cardinal/component/resource.go index 4dd875a..4379652 100644 --- a/cardinal/component/resource.go +++ b/cardinal/component/resource.go @@ -21,8 +21,9 @@ func GetAllResourceTypes() []ResourceType { } type Resource struct { - Type ResourceType `json:"type"` - Amount float32 `json:"amount"` + Type ResourceType `json:"type"` + Amount float32 `json:"amount"` + Capacity int `json:"capacity,omitempty"` } func (Resource) Name() string { diff --git a/cardinal/query/building_info.go b/cardinal/query/building_info.go index feaf690..0244e5b 100644 --- a/cardinal/query/building_info.go +++ b/cardinal/query/building_info.go @@ -10,25 +10,34 @@ type BuildingsInfoRequest struct { } type BuildingInfoResponse struct { - Building comp.BuildingType `json:"building"` - TileType comp.TileType `json:"tileType"` - Resources []comp.Resource `json:"resources"` - Effect *comp.Effect `json:"effect,omitempty"` - Farming *comp.Farming `json:"farming,omitempty"` + Building comp.BuildingType `json:"building"` + TileType comp.TileType `json:"tileType"` + Resources []comp.Resource `json:"resources"` + Effect *comp.Effect `json:"effect,omitempty"` + Farming *comp.Farming `json:"farming,omitempty"` + UnitLimit int `json:"unitLimit,omitempty"` + StorageCapacity int `json:"storageCapacity,omitempty"` } func AllBuildings(_ cardinal.WorldContext, _ *BuildingsInfoRequest) (*[]BuildingInfoResponse, error) { + return GetAllBuildings(), nil +} + +func GetAllBuildings() *[]BuildingInfoResponse { buildings := make([]BuildingInfoResponse, len(comp.GetAllBuildingTypes())) for i, buildingType := range comp.GetAllBuildingTypes() { buildingConf := comp.BuildingConfigs[buildingType] buildings[i] = BuildingInfoResponse{ - Building: buildingType, - TileType: buildingConf.TileType, - Resources: buildingConf.Resources, - Effect: buildingConf.Effect, - Farming: buildingConf.Farming, + Building: buildingType, + TileType: buildingConf.TileType, + Resources: buildingConf.Resources, + Effect: buildingConf.Effect, + Farming: buildingConf.Farming, + UnitLimit: buildingConf.UnitLimit, + StorageCapacity: buildingConf.StorageCapacity, } } - return &buildings, nil + + return &buildings } diff --git a/cardinal/query/player_resources.go b/cardinal/query/player_resources.go index 6e09353..b6f48da 100644 --- a/cardinal/query/player_resources.go +++ b/cardinal/query/player_resources.go @@ -40,7 +40,6 @@ func PlayerResources(world cardinal.WorldContext, req *PlayerResourcesRequest) ( } aggregatedfarmingSlice := make([]comp.Farming, 0, len(aggregatedFarmingMap)) - for resourceType, speed := range aggregatedFarmingMap { aggregatedfarmingSlice = append(aggregatedfarmingSlice, comp.Farming{ Type: resourceType, @@ -52,9 +51,31 @@ func PlayerResources(world cardinal.WorldContext, req *PlayerResourcesRequest) ( return nil, fmt.Errorf("error querying player %s resources", req.Nickname) } + effectsMap := make(map[comp.EffectType]int) + capacity := 0 + for _, building := range *GetAllBuildings() { + if building.Effect != nil { + effectsMap[building.Effect.Type] += building.Effect.Amount + } + + capacity += building.StorageCapacity + } + + resourcesResponse := make([]comp.Resource, 0, len(playerResources.Resources)) + for _, resource := range playerResources.Resources { + resource.Capacity = capacity + resourcesResponse = append(resourcesResponse, resource) + } + + effectsResponse := make([]comp.Effect, 0, len(playerResources.Effects)) + for _, effect := range playerResources.Effects { + effect.Capacity = effectsMap[effect.Type] + effectsResponse = append(effectsResponse, effect) + } + return &PlayerResourcesResponse{ - Resources: playerResources.Resources, - Effects: playerResources.Effects, + Resources: resourcesResponse, + Effects: effectsResponse, Farming: aggregatedfarmingSlice, }, err }