Forgotten Empires
  • Welcome!
  • Getting Started
  • Why On Chain Game?
  • Why MINA?
  • Architecture of Forgotten Empires
  • Prerequisites
  • Building Forgotten Empires to Unity
  • Game
    • Unity
      • Component
        • Type
          • Animation Type
          • Music Type
          • State Type
          • VFX Type
      • Entity
        • Element
          • Component
            • Enemy
              • Enemy Worker
                • Enemy Animation
                • Enemy Behaviour
                  • Component
                    • Enemy Attack Behaviour
                    • Enemy Attack Stance Behaviour
                    • Enemy Idle Behaviour
            • NPC
              • Citizen
              • Merchant
                • Merchant Interaction
                • Merchant Trade
                • Merchant Trigger
                • Merchant UI
                • Merchant Update
            • Player
              • Player Animation
              • Player Attack
              • Player Camera
              • Player Damage
              • Player Economy
              • Player Fixed Update
              • Player Input
                • Player Attack Input
                • Player Movement Input
                • Player Rotation Input
              • Player Interaction
              • Unity Late Update
              • Player Inventory
                • Player Inventory Slot
              • Player Movement
              • Player Quest
              • Player Rotation
                • Player Attack Rotation
                • Player Movement Rotation
              • Player Start
              • Player State
              • Player Stats
                • Player On Chain Stats
              • Player Trails
              • Player Update
              • Player VFX
          • Element Worker
            • Element Effect
            • Element Event
            • Element Stats
            • Element Update
        • Item
          • Potion
          • Shield
          • Sword
        • Kingdom
      • Manager
        • Client Manager
          • Client Manager Worker
            • Client Login Worker
            • Client Music Manager
            • Client Start Worker
            • Client UI Worker
            • Client Update Worker
        • Server Manager
          • Server Manager Worker
            • Server Day Night Worker
            • Server Enemy Worker
            • Server Kingdom Worker
            • Server Object Pool Worker
            • Server Player Worker
            • Server Start Worker
            • Server Update Worker
    • o1js
      • Player
      • Item
      • Character
    • o1js Tests
Powered by GitBook
On this page
  1. Game
  2. o1js

Player

Last updated 1 year ago

CtrlK

The Player class is a crucial component of the Forgotten Empires, managing player-related activities such as creating new players, leveling up, and changing kingdoms.

Structures

  • PlayerEntity: A structure to represent a player, including level, xp (experience points), and kingdom.

State

players: A mapping from a PublicKey to a PlayerEntity, representing the registered players in the game.

Methods

newPlayer(kingdom: UInt64)

Creates a new player with initial settings for this.transaction.sender

  • Parameters:

    • kingdom: The initial kingdom to which the player belongs.

  • Functionality:

    • Verifies that there isn't an existing player associated with the sender's address.

    • Initializes a new player with level 1, 1000 XP and the specified kingdom.

  • Usage:

    • This method should be called when a new player wants to play the game.

levelUP()

Levels up a player if they have enough experience points (XP).

  • Functionality:

    • Checks if a player exists at the sender's address.

    • Retrieves the player's current XP and level.

    • Verifies that the player has at least 1000 XP.

    • Increases the player's level by 1 and deducts 1000 XP.

  • Usage:

    • Players call this method to level up.

changeKingdom(kingdom: UInt64)

Changes a player's kingdom.

  • Parameters:

    • kingdom: The new kingdom to which the player wants to move.

  • Functionality:

    • Checks if a player exists at the sender's address.

    • Retrieves the player's current kingdom.

    • Ensures the new kingdom is different from the current one.

    • Updates the player's kingdom.

  • Usage:

    • Players use this method to change their allegiance to a different kingdom.