Skip to main content

Installation

First, add the Pixocracy SDK to your project:
<dependency>
    <groupId>io.pixocracy</groupId>
    <artifactId>pixocracy-sdk</artifactId>
    <version>1.0.0-alpha</version>
</dependency>

Initialize the SDK

Initialize the SDK with your application token:
// Initialize the SDK with your application token
PixocracySDK.initialize("your-application-token");

Create and Manage an Instance

Start by creating a new instance for your game:
// Generate a new UUID for your instance
UUID uuid = UUID.randomUUID();

// Register the instance
Instance instance = PixocracySDK.InstanceManager().registerInstance(uuid);

// Store the UUID somewhere safe for future use
// You'll need it to retrieve the instance later

// Set up the instance's tax rate
double taxRate = 10.0;
instance = PixocracySDK.InstanceManager().updateTaxRate(instance, taxRate);

Working with NPCs

Create and manage regular NPCs in your game:
// Create a new NPC
UUID npcUuid = UUID.randomUUID();
String name = "Village Guard";
SpawnType spawnType = SpawnType.MANUAL;

NPCSpawnEvent spawnEvent = PixocracySDK.NPCManager().registerSpawnEvent(
    instance,
    npcUuid,
    name,
    spawnType
);

NPC npc = spawnEvent.getNpc();

// When the NPC dies
NPCDeathEvent deathEvent = PixocracySDK.NPCManager().registerDeathEvent(instance, npc);

Working with Agent NPCs

Create and manage AI-powered Agent NPCs:
// Create a new Agent NPC
UUID agentNpcUuid = UUID.randomUUID();
SpawnType spawnType = SpawnType.NATURAL;

AgentNPCSpawnEvent spawnEvent = PixocracySDK.AgentNPCManager().registerSpawnEvent(
    instance,
    agentNpcUuid,
    "Villager",
    spawnType
);

AgentNPC agentNpc = spawnEvent.getAgentNpc();

// Check Agent NPC's status
double wealth = agentNpc.getWealth();
double mood = agentNpc.getMood();

Agent NPC Interactions

Enable social and economic interactions between Agent NPCs:
// Trade between Agent NPCs
double tradeAmount = 100.0;
TradeEvent tradeEvent = PixocracySDK.AgentNPCManager().registerTradeEvent(
    instance,
    trader,      // The Agent NPC giving the wealth
    recipient,   // The Agent NPC receiving the wealth
    tradeAmount
);

// Social interactions between Agent NPCs
InteractEvent interactEvent = PixocracySDK.AgentNPCManager().registerInteractEvent(
    instance,
    initiator,  // The Agent NPC starting the conversation
    responder   // The Agent NPC responding
);

// Process the conversation
List<Chat> conversation = interactEvent.getChat();
for (Chat message : conversation) {
    String content = message.getMessage();
    AgentNPC speaker = message.getAgentNpc();
    // Handle the conversation
}

Instance Economy

Manage your instance’s economy through tax collection:
// Collect taxes from all Agent NPCs
Instance updatedInstance = PixocracySDK.InstanceManager().collectTaxes(instance);

// Check the total collected taxes
double totalCollectedTaxes = updatedInstance.getCollectedTaxes();

Error Handling

The SDK uses exceptions to handle various error cases:
try {
    Instance instance = PixocracySDK.InstanceManager().registerInstance(uuid);
} catch (UnauthorizedException e) {
    // Handle authentication errors
} catch (PaymentRequiredException e) {
    // Handle insufficient credits
} catch (ConflictException e) {
    // Handle duplicate instance UUID
} catch (InternalException e) {
    // Handle server errors
} catch (PixocracyAPIException e) {
    // Handle other API errors
}

Best Practices

  1. Always store instance and NPC UUIDs for future reference
  2. Handle exceptions appropriately to ensure smooth gameplay
  3. Monitor Agent NPC wealth and mood to maintain game balance
  4. Use appropriate spawn types for NPCs and Agent NPCs
  5. Implement proper error handling for all SDK calls

Next Steps