class Plugin::Achievement::Achievement

Attributes

plugin[R]
slug[R]

Public Class Methods

new(slug, plugin, options) click to toggle source
# File core/plugin/achievement/achievement.rb, line 7
def initialize(slug, plugin, options)
  type_strict slug => Symbol, plugin => Plugin, options => Hash
  @slug, @plugin, @options = slug, plugin, options
  @events = Set.new
end

Public Instance Methods

description() click to toggle source
# File core/plugin/achievement/achievement.rb, line 14
def description ; @options[:description] || "" end
hidden?() click to toggle source
# File core/plugin/achievement/achievement.rb, line 15
def hidden? ; @options[:hidden] end
hint() click to toggle source
# File core/plugin/achievement/achievement.rb, line 13
def hint ; @options[:hint] || "" end
method_missing(method, *args, &block) click to toggle source
# File core/plugin/achievement/achievement.rb, line 52
def method_missing(method, *args, &block)
  result = plugin.__send__(method, *args, &block)
  case method.to_s
  when /\Aon_?(.*)\Z/
    @events << [$1.to_sym, result]
  when /\Afilter_?(.*)\Z/
    @events << [$1.to_sym, result]
  end
  result
end
notachieved_parent() click to toggle source

依存してる実績の中で、解除されてない最初の一つを返す

Return

見つかった実績(Plugin::Achievement::Achievement) 依存している実績がなかった場合や、全て解除済みの場合は self を返す

# File core/plugin/achievement/achievement.rb, line 41
def notachieved_parent
  unachievements = Plugin.filtering(:unachievements, {}).first
  if @options[:depends]
    result = @options[:depends].map{ |slug| unachievements[slug] }.compact.first
    if result
      result.notachieved_parent
    else
      self end
  else
    self end end
take!() click to toggle source

解除する

# File core/plugin/achievement/achievement.rb, line 23
def take!
  unless took?
    @events.each{ |e| plugin.detach(*e) }
    @events.clear
    if @options[:depends] and not @options[:depends].empty?
      unachievements = Plugin.filtering(:unachievements, {}).first.values_at(*@options[:depends]).compact
      if not unachievements.empty?
        on_achievement_took do |ach|
          if unachievements.delete(ach) and unachievements.empty?
            _force_take! end end
        return self end end
    _force_take! end
  self end
took?() click to toggle source

解除されていれば真

# File core/plugin/achievement/achievement.rb, line 18
def took?
  (UserConfig[:achievement_took] || []).include? slug
end