Class: RuneRb::Database::PlayerProfile

Inherits:
Object
  • Object
show all
Defined in:
app/database/models/player/profile.rb

Overview

Collection of data related to a registered player

Models a row of the <player_profiles> table.

Since:

  • 0.9.3

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fetch_profile(credentials) ⇒ Object

Attempts to fetch a profile with the supplied credentials. If no profile is found matching the credentials, a new one is registered and returned.

Parameters:

  • credentials (Hash, Struct)

    credentials containing a username to search for.

Since:

  • 0.9.3


38
39
40
# File 'app/database/models/player/profile.rb', line 38

def fetch_profile(credentials)
  RuneRb::Database::PlayerProfile[credentials[:Username]] || RuneRb::Database::PlayerProfile.register(credentials)
end

.register(data) ⇒ RuneRb::Database::PlayerProfile

Registers a new profile

Parameters:

  • data (Hash, Struct)

    profile data to insert.

Returns:

Since:

  • 0.9.3


15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/database/models/player/profile.rb', line 15

def self.register(data)
  # Create the profile and associations
  RuneRb::GLOBAL[:PLAYER_PROFILES].insert(name: data[:Username], password: data[:Password], name_hash: data[:NameHash])
  RuneRb::GLOBAL[:PLAYER_APPEARANCES].insert(name: data[:Username])
  RuneRb::GLOBAL[:PLAYER_SETTINGS].insert(name: data[:Username])
  RuneRb::GLOBAL[:PLAYER_STATS].insert(name: data[:Username])
  RuneRb::GLOBAL[:PLAYER_STATUS].insert(name: data[:Username])
  RuneRb::GLOBAL[:PLAYER_LOCATIONS].insert(name: data[:Username])

  # Return the created profile
  RuneRb::Database::PlayerProfile[data[:Username]]
end

Instance Method Details

#positionRuneRb::Game::Map::Position

Position for the Location associated with the Profile.

Returns:

Since:

  • 0.9.3


30
31
32
# File 'app/database/models/player/profile.rb', line 30

def position
  location.to_position
end