# 4.1.3 Play-to-Earn (P2E) Mechanics

AI MONSTER implements a robust P2E model that rewards players for various activities:

1. **Combat Rewards**
2. Earn tokens for defeating AI monsters or other players
3. Bonus rewards for exceptional performance or defeating rare monsters
4. **Capture and Training**
5. Rewards for successfully capturing wild AI monsters
6. Incentives for training and evolving monsters to higher levels
7. **Trading and Marketplace**
8. Earn commissions from monster trades in the marketplace
9. Rewards for providing liquidity to trading pools
10. **Content Creation**
11. Incentives for creating popular monster designs
12. Rewards for contributing to the AI training data

**Example: P2E Reward Distribution**

```javascript
class P2ERewardSystem {
  constructor(player, actionType, actionData) {
    this.player = player;
    this.actionType = actionType;
    this.actionData = actionData;
  }

  async distributeRewards() {
    const baseReward = this.calculateBaseReward();
    const bonusReward = await this.calculateBonusReward();
    const totalReward = baseReward + bonusReward;

    await this.mintRewardTokens(totalReward);
    this.updatePlayerStats(totalReward);

    return totalReward;
  }

  calculateBaseReward() {
    const rewardRates = {
      combat: 10,
      capture: 20,
      trade: 5,
      training: 15
    };
    return rewardRates[this.actionType] || 0;
  }

  async calculateBonusReward() {
    // Complex bonus calculation, potentially using AI to assess performance
    const response = await fetch('https://ai.monster.api/calculate-bonus', {
      method: 'POST',
      body: JSON.stringify({
        actionType: this.actionType,
        actionData: this.actionData,
        playerHistory: this.player.recentActions
      }),
      headers: { 'Content-Type': 'application/json' }
    });
    const { bonusReward } = await response.json();
    return bonusReward;
  }

  async mintRewardTokens(amount) {
    // Interact with blockchain to mint and transfer tokens
    const transaction = await tokenContract.methods.mintAndTransfer(
      this.player.walletAddress,
      amount
    ).send({ from: gameWalletAddress });
    console.log(`Minted ${amount} tokens to ${this.player.walletAddress}`);
    return transaction;
  }

  updatePlayerStats(rewardAmount) {
    this.player.totalEarnings += rewardAmount;
    this.player.recentActions.push({
      type: this.actionType,
      reward: rewardAmount,
      timestamp: Date.now()
    });
  }
}

// Usage
const rewardSystem = new P2ERewardSystem(currentPlayer, 'combat', combatResult);
const rewardAmount = await rewardSystem.distributeRewards();
console.log(`Player earned ${rewardAmount} tokens`);
```

This example demonstrates a P2E reward system that calculates and distributes rewards based on player actions, incorporating both base rates and AI-calculated bonuses.
