Blockchain-Based Time Events System
Blockchain-Based Time Events System
This system uses the Hive blockchain as a heartbeat mechanism for time-based game events, eliminating the need for traditional server-side timers.
Overview
Instead of using traditional heartbeat functions or server-side timers, this system leverages the Hive blockchain's natural flow of operations and blocks to trigger time-based events. Each block on the Hive blockchain represents approximately 3 seconds of real time, providing a reliable and decentralized timing mechanism.
How It Works
- Blockchain Listening: The system listens to new blocks on the Hive blockchain
- Time Event Registration: Rooms can be registered for time-based events with specific intervals
- Phase Management: Each time event has multiple phases that cycle based on the configured interval
- Dynamic Updates: Room exits and descriptions change automatically based on the current phase
Ferry Room Example
The ferry room demonstrates this system with 6 phases:
- Docked at Port A - Players can exit north to Port A or board the ferry
- Departing Port A - Ferry is leaving, only boarding available
- At Sea - Ferry is sailing, only boarding available
- Arriving at Port B - Ferry is approaching Port B, only boarding available
- Docked at Port B - Players can exit south to Port B or board the ferry
- Departing Port B - Ferry is returning to Port A, only boarding available
Usage
For Players
- Navigate to a ferry room (e.g.,
ferry-port-a,ferry-port-b,ferry-interior) - The room's exits will change automatically based on the ferry's current phase
- Wait for the ferry to dock at your desired port before attempting to exit
For Builders
- Click the "Time Events" button in the sidebar (requires builder permissions)
- Create new ferry rooms with custom configurations:
- Room Permlink: The unique identifier for the room
- Title: Display name for the ferry
- Description: Description of the ferry
- Interval Blocks: How many blocks between phase changes (default: 100 blocks ≈ 5 minutes)
- Start Phase: Which phase to begin with (0-5)
For Developers
Creating Custom Time Events
// Register a room for time-based events
const timeEventConfig: TimeEventConfig = {
type: 'ferry', // or 'market', 'weather', 'custom'
intervalBlocks: 100, // Change every 100 blocks
lastChangeBlock: 0, // Will be set automatically
currentPhase: 0,
phases: [
{
phase: 0,
name: "Phase 1",
description: "Description for phase 1",
exits: { "north": "destination-1", "south": "destination-2" },
duration: 100
},
// ... more phases
]
};
gameState.registerTimeEventRoom('my-room-permlink', timeEventConfig);
Listening for Time Events
// The system automatically emits 'timeEventDetected' events
hiveClient.on('timeEventDetected', (timeEvent: BlockchainTimeEvent) => {
console.log('Time event detected:', timeEvent);
// Handle the phase change
});
Technical Details
Block Timing
- Hive Block Time: ~3 seconds per block
- Default Ferry Interval: 100 blocks ≈ 5 minutes
- Customizable: Any interval can be set based on game needs
Event Types
- ferry: Transportation between locations
- market: Trading and commerce events
- weather: Environmental changes
- custom: User-defined events
Phase Structure
Each phase includes:
- phase: Numeric identifier
- name: Display name for the phase
- description: Description shown to players
- exits: Available exits during this phase
- duration: How long this phase lasts (in blocks)
Benefits
- Decentralized: No central server required for timing
- Reliable: Uses blockchain's immutable time flow
- Scalable: Can handle multiple time events simultaneously
- Transparent: All timing is based on public blockchain data
- Consistent: Same timing across all clients
Future Enhancements
- Weather Systems: Dynamic weather changes affecting gameplay
- Market Cycles: Trading opportunities that appear and disappear
- Seasonal Events: Special events tied to blockchain time
- Player Schedules: NPCs and events that follow time-based patterns
Testing
Run the test suite to verify the time event system:
npm test -- TimeEventSystem.test.tsx
The tests verify:
- Ferry room registration
- Phase change handling
- Dynamic exit application
- Phase cycling behavior
Leave Blockchain-Based Time Events System to:
Read more #leaf posts
Best Posts From Veirifin
We have not curated any of raymonjohnstone's posts yet. But you can encourage our curation team to review posts by visiting them regularly and by referring other readers. Because we give priority to frequently read content.
More Posts From Veirifin
- Ego Death | Development Update — Infrastructure, Living Worlds & A Smarter Server
- Gondola
- The Billion-Dollar Social Contract: Why Global Monopolies Require Global Rules
- Nutrient Commons
- 🎮 Ego Death Community Update: Supporting Our Builders and Content Creators
- Blockchain-Based Time Events System
- Deep Cavern
- Deep Cavern
- # 🎮 Play Ego Death - The First Live Text Adventure on Hive Blockchain
- 🌿 Introducing Leaf: A Revolutionary Framework for Text-Based Adventure Games on Hive
- Todays Work
- Description functioning again!
- Player presence functioning!!!
- Meandering Stream
- One broken
- Sources of Truth (Partially AI generated)
- Viewing Hall
- Doing Life Wrong...
- Genesis Scaffold Precipice
- Gorged Cliff Path