Skip to content

Instantly share code, notes, and snippets.

@volgar1x
Created July 31, 2012 15:42
Show Gist options
  • Save volgar1x/3217932 to your computer and use it in GitHub Desktop.
Save volgar1x/3217932 to your computer and use it in GitHub Desktop.
essai d'une action d'objet utilisable en Ruby
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