Add durable recipe discovery and profession crafting
This commit is contained in:
@@ -17,15 +17,19 @@ var ErrCatalogInvalid = errors.New("invalid catalog change")
|
||||
var catalogRequestID = regexp.MustCompile(`^[a-f0-9-]{32,36}$`)
|
||||
|
||||
type CatalogChange struct {
|
||||
TargetID string `json:"targetId,omitempty"`
|
||||
Attack *content.CombatAttack `json:"attack,omitempty"`
|
||||
Mob *content.MobDefinition `json:"mob,omitempty"`
|
||||
Loot *content.LootTable `json:"loot,omitempty"`
|
||||
Spawn *content.MobSpawn `json:"spawn,omitempty"`
|
||||
GatheringSkill *content.GatheringSkill `json:"gatheringSkill,omitempty"`
|
||||
Resource *content.ResourceDefinition `json:"resource,omitempty"`
|
||||
Biome *content.BiomeDefinition `json:"biome,omitempty"`
|
||||
Consumable *content.GatheringConsumable `json:"consumable,omitempty"`
|
||||
CraftRecipe *content.CraftRecipe `json:"craftRecipe,omitempty"`
|
||||
CraftProfession *content.GatheringSkill `json:"craftProfession,omitempty"`
|
||||
CraftMaterial *content.CraftMaterial `json:"craftMaterial,omitempty"`
|
||||
CraftRules *content.CraftRules `json:"craftRules,omitempty"`
|
||||
TargetID string `json:"targetId,omitempty"`
|
||||
Attack *content.CombatAttack `json:"attack,omitempty"`
|
||||
Mob *content.MobDefinition `json:"mob,omitempty"`
|
||||
Loot *content.LootTable `json:"loot,omitempty"`
|
||||
Spawn *content.MobSpawn `json:"spawn,omitempty"`
|
||||
GatheringSkill *content.GatheringSkill `json:"gatheringSkill,omitempty"`
|
||||
Resource *content.ResourceDefinition `json:"resource,omitempty"`
|
||||
Biome *content.BiomeDefinition `json:"biome,omitempty"`
|
||||
Consumable *content.GatheringConsumable `json:"consumable,omitempty"`
|
||||
|
||||
ID string `json:"id"`
|
||||
ExpectedVersion int64 `json:"expectedVersion"`
|
||||
@@ -47,7 +51,7 @@ type CatalogResult struct {
|
||||
// Explicit definition IDs are reserved for trusted seed/import code. Browser
|
||||
// publications omit them; the server assigns an ID after resolving request replay.
|
||||
func (c CatalogChange) HasDefinitionID() bool {
|
||||
return (c.Attack != nil && c.Attack.ID != "") || (c.Mob != nil && c.Mob.ID != "") || (c.Loot != nil && c.Loot.ID != "") || (c.Spawn != nil && c.Spawn.ID != "") || (c.GatheringSkill != nil && c.GatheringSkill.ID != "") || (c.Resource != nil && c.Resource.ID != "") || (c.Biome != nil && c.Biome.ID != "") || (c.Consumable != nil && c.Consumable.ID != "") || (c.Title != nil && c.Title.ID != "") || (c.Item != nil && c.Item.ID != "") || (c.RequirementSet != nil && c.RequirementSet.ID != "") || (c.EffectSet != nil && c.EffectSet.ID != "")
|
||||
return (c.CraftRecipe != nil && c.CraftRecipe.ID != "") || (c.CraftProfession != nil && c.CraftProfession.ID != "") || (c.CraftMaterial != nil && c.CraftMaterial.ID != "") || (c.Attack != nil && c.Attack.ID != "") || (c.Mob != nil && c.Mob.ID != "") || (c.Loot != nil && c.Loot.ID != "") || (c.Spawn != nil && c.Spawn.ID != "") || (c.GatheringSkill != nil && c.GatheringSkill.ID != "") || (c.Resource != nil && c.Resource.ID != "") || (c.Biome != nil && c.Biome.ID != "") || (c.Consumable != nil && c.Consumable.ID != "") || (c.Title != nil && c.Title.ID != "") || (c.Item != nil && c.Item.ID != "") || (c.RequirementSet != nil && c.RequirementSet.ID != "") || (c.EffectSet != nil && c.EffectSet.ID != "")
|
||||
}
|
||||
|
||||
type CatalogAudit struct {
|
||||
@@ -118,6 +122,13 @@ func decodeCatalog(version int64, raw string) (content.Catalog, error) {
|
||||
}
|
||||
catalog.Combat = b.Combat
|
||||
}
|
||||
if catalog.Crafting == nil {
|
||||
defaults, e := content.Load()
|
||||
if e != nil {
|
||||
return catalog, e
|
||||
}
|
||||
catalog.RestoreCrafting(defaults)
|
||||
}
|
||||
return catalog, catalog.Validate()
|
||||
}
|
||||
func (d *DB) Catalog(ctx context.Context) (content.Catalog, error) {
|
||||
@@ -142,10 +153,10 @@ func (d *DB) CatalogAfter(ctx context.Context, after int64) (*content.Catalog, e
|
||||
return &catalog, err
|
||||
}
|
||||
func (c CatalogChange) validate() error {
|
||||
if (c.Op == "update-biome") != (c.TargetID != "") {
|
||||
return fmt.Errorf("%w: only biome edits require an existing target", ErrCatalogInvalid)
|
||||
if (c.Op == "update-biome" || c.Op == "update-craft-recipe") != (c.TargetID != "") {
|
||||
return fmt.Errorf("%w: only biome and recipe edits require an existing target", ErrCatalogInvalid)
|
||||
}
|
||||
if c.Biome != nil && c.Biome.Revision != 0 {
|
||||
if (c.Biome != nil && c.Biome.Revision != 0) || (c.CraftRecipe != nil && c.CraftRecipe.Revision != 0) {
|
||||
return fmt.Errorf("%w: revisions are assigned by the server", ErrCatalogInvalid)
|
||||
}
|
||||
if !catalogRequestID.MatchString(c.ID) || c.ExpectedVersion < 1 || len(c.Reason) < 5 || len(c.Reason) > 240 {
|
||||
@@ -153,12 +164,20 @@ func (c CatalogChange) validate() error {
|
||||
}
|
||||
valid := false
|
||||
count := 0
|
||||
for _, present := range []bool{c.Attack != nil, c.Mob != nil, c.Loot != nil, c.Spawn != nil, c.GatheringSkill != nil, c.Resource != nil, c.Biome != nil, c.Consumable != nil, c.Title != nil, c.Item != nil, c.Stats != nil, c.RequirementSet != nil, c.EffectSet != nil} {
|
||||
for _, present := range []bool{c.CraftRecipe != nil, c.CraftProfession != nil, c.CraftMaterial != nil, c.CraftRules != nil, c.Attack != nil, c.Mob != nil, c.Loot != nil, c.Spawn != nil, c.GatheringSkill != nil, c.Resource != nil, c.Biome != nil, c.Consumable != nil, c.Title != nil, c.Item != nil, c.Stats != nil, c.RequirementSet != nil, c.EffectSet != nil} {
|
||||
if present {
|
||||
count++
|
||||
}
|
||||
}
|
||||
switch c.Op {
|
||||
case "create-craft-recipe", "update-craft-recipe":
|
||||
valid = c.CraftRecipe != nil
|
||||
case "create-craft-profession":
|
||||
valid = c.CraftProfession != nil
|
||||
case "create-craft-material":
|
||||
valid = c.CraftMaterial != nil
|
||||
case "update-craft-rules":
|
||||
valid = c.CraftRules != nil
|
||||
case "create-attack":
|
||||
valid = c.Attack != nil
|
||||
case "create-mob":
|
||||
|
||||
Reference in New Issue
Block a user