The CafeCosmos VisionContracts solution is the core logic for the Unity3D interface of the game which is also reused in the CafeCosmos Blazor implementation, this can also be used to understand the internal mechanics of the game and create your own automations if wanted.
The heart of the solution is the VisionContracts project, which has the essential services, models, and contracts necessary to interact with and manipulate the game state. Several auxiliary projects expand the functionality, including REST APIs, data normalization services, and database processing components to extract / index the data from the smart contracts into a database.
If you are interested on how to interact with the project, a good starting point is the CafeCosmos automation example.
-
Visions Contracts. The central part of the solution, includes all the core logic.
-
Cafe Cosmos Blazor. The game in an html / wasm / hybrid windows / macos version using Blazor.
-
CafeCosmos.AutomationExample The best place to get started to programmatically interact with the game
-
VisionsContracts.LogProcessing.Postgres Mud tables event changes indexer in postgres.
-
VisionContracts.Normarliser.Console Normalizes the mud table into separate tables already decoded
-
VisionContracts.StoredRecordsRestApi Rest service to query remotely the postgress database.
The VisionContracts project is the central part of the solution.
NOTE THIS DOCUMENT IS WIP
- To load a new land into the
PlayerLocalState, theGetNewPlayerLocalStateAsyncmethod ofPlayerServiceis used. This retrieves the latest player state, including the associated land.
- The
PlayerLocalStateis a comprehensive representation of the player's game state. It includes:- Land: Data about the player's land, including all the items, positions and stack.
- Inventory: A list of items the player has in her backpack, and not placed in the land.
- LandInfo: Metadata about the land including the size, active tables, xp, etc
- Players interact with the
PlayerLocalStateto perform various operations, such as:-
Placing Items:
playerLocalState.PlaceItem(0, 1, DefaultItems.Furniture.GREEN_CHAIR.Id);
Every time you place an item is validated against the capability of the item to be placed in that position or the transformations rules that drive the behaviour of that item.
-
Crafting Items:
playerLocalState.CraftItem(DefaultItems.Cooking.BURGER_RECIPE);
This crafts an item :). When calling this method it validates if you have the items in the inventory and if valid creates the new item.
-
- The
PlayerLocalStatecontains much of the smart contract logic to validate actions offline. Enhancements can be made to this logic to ensure consistency with on-chain validation.
- Transformations define how items evolve over time or actions. Examples include:
- Wheat Growth Cycle:
new Transformation { Base = Wheat.WHEAT_SEED.Id, Input = Tools.WATERING_CAN_FULL.Id, Next = Wheat.WHEAT_SMALL.Id, UnlockTime = 120, Yield = Ingredients.WHEAT.Id };
- Robot Transformations:
new Transformation { Base = DefaultItems.Machines.ROBOT.Id, Input = DefaultItems.Ingredients.RASPBERRY.Id, Next = DefaultItems.Machines.ROBOT_MAKING_MEAT.Id, Yield = DefaultItems.Ingredients.MEAT.Id };
- Wheat Growth Cycle:
- Recipes define how to craft new items from inputs. Examples include:
- Burger Recipe:
new CraftingRecipe { Inputs = { new LBINT { Ingredients.LETTUCE.Id, Ingredients.CHEESE.Id }, new LBINT { Ingredients.MEAT.Id, Ingredients.TOMATO.Id }, new LBINT { Ingredients.DOUGH.Id } }, Output = Recipes.BURGER, XP = 4 };
- Burger Recipe:
- Items are organized into categories such as:
-
Furniture: Includes items like
GREEN_CHAIRandGREEN_TABLE. -
Cooking Appliances: Examples are
BASIC_OVENandCRAZY_OVEN. -
Raw Materials: Used in crafting recipes, e.g.,
BISMUTH_INGOTandWOOD_PINK. -
Decorations: Items like
WALL_MENUandWINDOW.public static readonly Item COFFEE_MACHINE = new(name: "Coffee Machine", id: 79, category: ItemCategory.Cooking, isTool: false, isPlaceable: false, isRotatable: true, isInventory: true, isRemovable: true);
-
- Common exceptions encountered while interacting with
PlayerLocalState:- CraftRecipeInvalidRecipeException: Thrown when attempting to craft an invalid recipe.
- CraftRecipeNoEnoughItemsInInventoryException: Raised if there aren't enough materials to craft an item.
The LandNamespace represents the namespace of the Mud World in the smart contracts and acts as a structured interface for managing land-related systems and tables. It organizes SystemServices and TableServices, which interact directly with blockchain systems and stored game data, respectively.
SystemServices are code-generated interfaces akin to Nethereum-generated smart contract wrappers but extended with business logic and models to manage dynamic behaviors of the game. Key services include:
-
LandItemInteractionSystemService
- Handles placing, removing, and transforming items on land.
- Example interaction:
await LandItemInteractionSystemService.PlaceItemAsync(landId, itemId, x, y);
-
CraftingSystemService
- Enables crafting items using recipes.
public async Task<TransactionReceipt> CraftRecipeAsync(BigInteger landId, BigInteger recipeId, BigInteger quantity);
- Enables crafting items using recipes.
-
TransformationsSystemService
- Manages item transformations based on specific actions or time-based events.
-
MarketplaceSystemService
- Supports listing and buying items in the player marketplace.
-
LandTokensSystemService
- Manages land-related tokens and balances.
-
QuestsSystemService
- Tracks and manages quest progression and rewards.
TableServices handle stored game data and provide query and update capabilities for various components.
-
LandItemTableService
- Tracks item placements and statuses on land.
var items = await LandItemTableService.GetTableRecordsAsync(landId);
- Tracks item placements and statuses on land.
-
LandInfoTableService
- Stores metadata about land configurations, expansions, and active tables.
-
InventoryTableService
- Manages player inventory, including items and quantities.
-
CraftingRecipeTableService
- Maintains crafting recipe data.
-
TransformationsTableService
- Records active transformations and their progress.
-
QuestTableService
- Tracks quest data, including progress and completion.
-
CafeCosmosConfigTableService
- Stores global configuration parameters for items, crafting, and land management.


