Class: RuneRb::Game::Entity::Commands::Item

Inherits:
RuneRb::Game::Entity::Command show all
Defined in:
app/game/entity/commands/item.rb

Overview

A Command to spawn items for the player.

Since:

  • 0.9.3

Instance Method Summary collapse

Methods inherited from RuneRb::Game::Entity::Command

#initialize

Methods included from System::Log

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

Constructor Details

This class inherits a constructor from RuneRb::Game::Entity::Command

Instance Method Details

#executeObject

Since:

  • 0.9.3


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/game/entity/commands/item.rb', line 5

def execute
  unless @assets[:command].size >= 2
    @assets[:context].session.write_message(:SystemTextMessage, message: "Not enough parameters for this command! Required: 2 or more, Provided: #{@assets[:command].size}")
    return
  end
  stack = RuneRb::Game::Item::Stack.new(@assets[:command][0].to_i)
  if stack.definition[:stackable]
    stack.size = @assets[:command][1].to_i
    @assets[:context].inventory[:container].add(stack)
    log RuneRb::GLOBAL[:COLOR].green("Adding #{stack.definition[:name]} x #{stack.size}") if RuneRb::GLOBAL[:DEBUG]
  else
    @assets[:command][1].to_i.times do
      @assets[:context].inventory[:container].add(stack)
      log RuneRb::GLOBAL[:COLOR].green("Adding #{stack.definition[:name]} x #{stack.size}") if RuneRb::GLOBAL[:DEBUG]
    end
  end
  @assets[:context].update(:inventory)
end