Created
July 31, 2012 15:42
-
-
Save volgar1x/3217932 to your computer and use it in GitHub Desktop.
essai d'une action d'objet utilisable en Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.shivas.data.entity.ItemTemplate | |
import org.shivas.data.entity.ItemAction | |
import org.shivas.server.database.model.Player | |
import org.shivas.protocol.formatters.ItemGameMessageFormatter | |
class GiveItemAction < ItemAction | |
TYPE = 4 | |
def self.make(parameters, datas) | |
raw = parameters.get("item") | |
tplId = Integer.parseInt raw | |
tpl = datas.get(ItemTemplate.java_class).byId tplId | |
GiveItemAction.new tpl | |
end | |
def initialize(tpl) | |
@tpl = tpl | |
end | |
def type | |
TYPE | |
end | |
def able?(target) | |
target.java_kind_of? Player | |
end | |
def apply(target) | |
item = tpl.generate | |
target.bag.persist item | |
target.client.write(ItemGameMessageFormatter.addItemMessage item.toBaseItemType) | |
end | |
end | |
Shivas.add_item_action GiveItemAction.TYPE, do |parameters| | |
GiveItemAction.make parameters, Shivas.datas | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment