Class: RuneRb::Game::Entity::Context

Inherits:
Mob
  • Object
show all
Includes:
Helpers::Command, Helpers::Equipment, Helpers::Inventory, System::Log
Defined in:
app/game/entity/context.rb

Overview

A Mob that is representing the context of a connected Session.

Since:

  • 0.9.3

Instance Attribute Summary collapse

Attributes inherited from Mob

#animation, #definition, #graphic, #index, #message, #regional

Attributes included from Helpers::Flags

#flags

Attributes included from Helpers::Movement

#locals, #movement, #position

Instance Method Summary collapse

Methods included from Helpers::Command

#fetch_command, #load_commands

Methods included from Helpers::Inventory

#add_item, #remove_item

Methods included from Helpers::Equipment

#[], #[]=, #unequip

Methods included from System::Log

#class_name, #err, #err!, #log, #log!, #symbolize_file

Methods inherited from Mob

#post_sync, #pre_sync, #register

Methods included from Helpers::Flags

#load_flags, #reset_flags, #update

Methods included from Helpers::Movement

#clear_waypoints, #load_movement, #parse_movement, #push_path, #reset_movement, #teleport, #toggle_run, #waypoint_size

Constructor Details

#initialize(session, profile, world) ⇒ Context

Constructs a new Context entity.

Parameters:

Since:

  • 0.9.3


50
51
52
53
54
55
# File 'app/game/entity/context.rb', line 50

def initialize(session, profile, world)
  @session = session
  @profile = profile
  @world = world
  super(profile)
end

Instance Attribute Details

#appearanceRuneRb::Database::PlayerAppearance (readonly)

Returns the appearance of the Context.

Returns:

Since:

  • 0.9.3


24
25
26
# File 'app/game/entity/context.rb', line 24

def appearance
  @appearance
end

#equipmentHash (readonly)

Returns the Equipment database for a context.

Returns:

  • (Hash)

    the Equipment database for a context.

Since:

  • 0.9.3


12
13
14
# File 'app/game/entity/context.rb', line 12

def equipment
  @equipment
end

#inventoryRuneRb::Game::Item::Container (readonly)

Returns the Inventory database for the Context.

Returns:

Since:

  • 0.9.3


16
17
18
# File 'app/game/entity/context.rb', line 16

def inventory
  @inventory
end

#profileRuneRb::Database::PlayerProfile (readonly)

Returns the Profile of the Context which acts as it's definition.

Returns:

Since:

  • 0.9.3


28
29
30
# File 'app/game/entity/context.rb', line 28

def profile
  @profile
end

#sessionRuneRb::Network::Session (readonly)

Returns the Session for the Context.

Returns:

Since:

  • 0.9.3


20
21
22
# File 'app/game/entity/context.rb', line 20

def session
  @session
end

#settingsRuneRb::Database::PlayerSettings (readonly)

Returns:

Since:

  • 0.9.3


36
37
38
# File 'app/game/entity/context.rb', line 36

def settings
  @settings
end

#statsRuneRb::Database::PlayerStats (readonly)

Returns:

Since:

  • 0.9.3


40
41
42
# File 'app/game/entity/context.rb', line 40

def stats
  @stats
end

#statusRuneRb::Database::PlayerStatus (readonly)

Returns:

Since:

  • 0.9.3


32
33
34
# File 'app/game/entity/context.rb', line 32

def status
  @status
end

#worldRuneRb::Game::World::Instance (readonly)

Returns the world Instance the Context is registered to.

Returns:

Since:

  • 0.9.3


44
45
46
# File 'app/game/entity/context.rb', line 44

def world
  @world
end

Instance Method Details

#inspectString

Returns an inspection of the Context.

Returns:

  • (String)

    an inspection of the Context

Since:

  • 0.9.3


100
101
102
103
104
# File 'app/game/entity/context.rb', line 100

def inspect
  str = super
  str << "[INVENTORY]: #{@inventory.inspect}"
  str << "[POSITION]: #{@position.inspect}"
end

#load_appearanceObject

Initializes Appearance for the Context.

Since:

  • 0.9.3


116
117
118
119
# File 'app/game/entity/context.rb', line 116

def load_appearance
  @appearance = @profile.appearance
  update(:state)
end

#load_statsObject

Initializes Stats for the Context.

Since:

  • 0.9.3


122
123
124
125
# File 'app/game/entity/context.rb', line 122

def load_stats
  @stats = @profile.stats
  update(:state)
end

#load_statusObject

Initializes Status for the Context.

Since:

  • 0.9.3


128
129
130
# File 'app/game/entity/context.rb', line 128

def load_status
  @status = @profile.status
end

#login(first: true) ⇒ Object

Performs a series of task related with constructing and initializing a context's data and attaching the context to the <@world> instance.

Since:

  • 0.9.3


80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/game/entity/context.rb', line 80

def (first: true)
  @session.register(self)
  log! "Attached to Session #{@session.id}!" if RuneRb::GLOBAL[:DEBUG]
  load_status
  load_appearance
  load_inventory(first)
  load_equipment(first)
  load_commands
  load_stats

  @session.write_message(:MembersAndIndexMessage, members: @status.members, player_idx: @index)
  @session.write_message(:UpdateItemsMessage, data: @inventory[:container].data, size: 28)
  @session.write_message(:SystemTextMessage, message: 'Check the repository for updates! https://gitlab.com/Sickday/rune.rb')
  @session.write_message(:SystemTextMessage, message: "VERSION: #{RuneRb::GLOBAL[:VERSION]}")
  update(:stats)
  update(:sidebars)
  @session.status[:auth] = :LOGGED_IN
end

#logoutObject

Performs a series of tasks associated with deserializing and saving player information to relevant datastores.

Since:

  • 0.9.3


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/game/entity/context.rb', line 58

def logout
  # Dump the inventory database
  dump_inventory if @inventory

  # Dump the equipment database
  dump_equipment if @equipment

  # Set the position.
  @profile.location.set(@position[:current])

  # Post the session
  @profile.status.post_session(session)

  # Write the actual logout.
  @session.write_message(:LogoutMessage, @session)

  # Detach from the world.
  @world&.release(self)
  log! 'Detached from World instance!' if RuneRb::GLOBAL[:DEBUG]
end

#syncObject

Dispatches a ContextSynchronizationMessage to the <@session> assuming the Context meets the requirements for doing so. If a region change is needed, a CenterRegionMessage is written before the ContextSynchronizationMessage.

Since:

  • 0.9.3


107
108
109
110
111
112
113
# File 'app/game/entity/context.rb', line 107

def sync
  # Write region message if an update is required.
  @session.write_message(:CenterRegionMessage, @regional) if @flags[:region?]

  # Write synchronization message.
  @session.write_message(:ContextSynchronizationMessage, self) if @world && @session.status[:auth] == :LOGGED_IN && @session.status[:active]
end