Module: RuneRb::Game::Entity::Helpers::Flags

Included in:
Mob
Defined in:
app/game/entity/helpers/flags.rb

Overview

Functions to toggle, load and reset update flags for an Entity.

Since:

  • 0.9.3

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#flagsHash (readonly)

Returns a collection of flags to observe when constructing a SynchronizationMessage.

Returns:

  • (Hash)

    a collection of flags to observe when constructing a SynchronizationMessage

Since:

  • 0.9.3


4
5
6
# File 'app/game/entity/helpers/flags.rb', line 4

def flags
  @flags
end

Instance Method Details

#load_flagsObject

Initializes and sets the state of required update flags.

Since:

  • 0.9.3


7
8
9
10
11
12
# File 'app/game/entity/helpers/flags.rb', line 7

def load_flags
  @flags ||= {}
  @flags[:state?] = true
  @flags[:region?] = true
  @flags[:teleport?] = true
end

#reset_flagsObject

Resets the update flags for the Mob.

Since:

  • 0.9.3


15
16
17
18
19
20
21
22
23
24
# File 'app/game/entity/helpers/flags.rb', line 15

def reset_flags
  @flags[:chat?] = false
  @flags[:graphic?] = false
  @flags[:animation?] = false
  #@flags[:state?] = false
  @flags[:region?] = false
  @flags[:forced_chat?] = false
  @flags[:teleport?] = false
  @flags[:moved?] = false
end

#update(type, assets = {}) ⇒ Object

Toggles the Mob's corresponding value for the passed update type within <@flags>. For example, if we want to schedule a graphic update, we would pass the type :graphic as well as the actual graphic object:

Mob#update(:graphic, gfx: RuneRb::Game::Entity::Graphic)

This will toggle the value of the Mob#flags key to true which will cause a graphic update flag mask and the Graphic object's data to be added to the context's state block in the next ContextSynchronizationMessage.

Parameters:

  • type (Symbol)

    the type of update to schedule

  • assets (Hash) (defaults to: {})

    the assets for the update

Since:

  • 0.9.3


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/game/entity/helpers/flags.rb', line 35

def update(type, assets = {})
  case type
  when :teleport
    @profile.location.set(assets[:to])
    @position[:current] = @profile.location.to_position
    @movement[:type] = :TELEPORT
    @flags[:teleport?] = true
    @flags[:region?] = true
    @flags[:state?] = true
  when :level_up
    if @profile.stats.level_up?
      level_info = @profile.stats.level_up
      if level_info[:level] == 99
        @session.write_text("Congratulations, you've reached the highest possible #{level_info[:skill].to_s.capitalize} level of 99!")
      else
        @session.write_text("Congratulations, your #{level_info[:skill].to_s.capitalize} level is now #{level_info[:level]}!")
      end
    end
    update(:stats)
    @flags[:state?] = true
  when :equipment
    @equipment.each { |slot_label, stack| @session.write_message(:UpdateSlottedItemMessage, slot: @equipment.keys.index(slot_label), slot_data: stack) }
    @flags[:state?] = true
  when :inventory then @session.write_message(:UpdateItemsMessage, data: @inventory[:container].data, size: 28)
  when :sidebars then RuneRb::Network::SIDEBAR_INTERFACES.each { |key, value| @session.write_message(:DisplaySidebarMessage, menu_id: key, form: value) }
  when :stats
    @session.write_message(:StatUpdateMessage, skill_id: 0, level: @stats[:attack_level], experience: @stats[:attack_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 1, level: @stats[:defence_level], experience: @stats[:defence_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 2, level: @stats[:strength_level], experience: @stats[:strength_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 3, level: @stats[:hit_points_level], experience: @stats[:hit_points_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 4, level: @stats[:range_level], experience: @stats[:range_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 5, level: @stats[:prayer_level], experience: @stats[:prayer_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 6, level: @stats[:magic_level], experience: @stats[:magic_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 7, level: @stats[:cooking_level], experience: @stats[:cooking_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 8, level: @stats[:woodcutting_level], experience: @stats[:woodcutting_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 9, level: @stats[:fletching_level], experience: @stats[:fletching_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 10, level: @stats[:fishing_level], experience: @stats[:fishing_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 11, level: @stats[:firemaking_level], experience: @stats[:firemaking_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 12, level: @stats[:crafting_level], experience: @stats[:crafting_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 13, level: @stats[:smithing_level], experience: @stats[:smithing_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 14, level: @stats[:mining_level], experience: @stats[:mining_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 15, level: @stats[:herblore_level], experience: @stats[:herblore_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 16, level: @stats[:agility_level], experience: @stats[:agility_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 17, level: @stats[:thieving_level], experience: @stats[:thieving_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 18, level: @stats[:slayer_level], experience: @stats[:slayer_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 19, level: @stats[:farming_level], experience: @stats[:farming_exp])
    @session.write_message(:StatUpdateMessage, skill_id: 20, level: @stats[:runecrafting_level], experience: @stats[:runecrafting_exp])
    @flags[:state?] = true
  when :morph
    @profile.appearance.to_mob(assets[:mob_id])
    @flags[:state?] = true
  when :overhead
    @profile.appearance.to_head(assets[:head_icon] <= 7 && assets[:head_icon] >= -1 ? assets[:head_icon] : 0)
    @flags[:state?] = true
  when :region
    @regional = @position[:current].regional
    @flags[:region?] = true
  when :state
    @flags[:state?] = true
  when :graphic
    @graphic = assets[:graphic]
    @flags[:graphic?] = true
    @flags[:state?] = true
  when :animation
    @animation = assets[:animation]
    @flags[:animation?] = true
    @flags[:state?] = true
  when :message, :chat
    @message = assets[:message]
    @flags[:chat?] = true
    @flags[:state?] = true
  else err "Unrecognized update type! #{type}"
  end
end