mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-05 00:38:14 +00:00
Add shops support.
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
require 'java'
|
||||
|
||||
java_import 'org.apollo.cache.def.ItemDefinition'
|
||||
|
||||
# A currency that can be used to purchase items in a Shop.
|
||||
class Currency
|
||||
attr_reader :name
|
||||
|
||||
# Creates the Currency.
|
||||
def initialize(id, name = ItemDefinition.lookup(id).name)
|
||||
fail 'Currency must have a name.' if name.nil?
|
||||
@id = id
|
||||
@name = name.to_s
|
||||
end
|
||||
|
||||
# Adds the specified amount of this `Currency` to the specified `Player`'s inventory.
|
||||
def add(player, amount)
|
||||
player.inventory.add(@id, amount)
|
||||
end
|
||||
|
||||
# Removes the specified amount of this `Currency` from the specified `Player`'s inventory.
|
||||
def remove(player, amount)
|
||||
player.inventory.remove(@id, amount)
|
||||
end
|
||||
|
||||
# Gets the amount of this Currency in the specified player's inventory.
|
||||
def total(player)
|
||||
player.inventory.get_amount(@id)
|
||||
end
|
||||
|
||||
def sell_value(id)
|
||||
(ItemDefinition.lookup(id).value * 0.60).floor
|
||||
end
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user