Parsing Your Character’s Loot

yesterday at 9:05 am

Here’s a quick teaser for a new project I’m working on, almost ready for public beta.

def loot(character_sheet_file)
  @xml ||= Hpricot::XML(character_sheet_file.read)
  @loot ||= @xml.search("//LootTally/loot[@count!='0']").map do |item|
    res = item.search("//RulesElement")
    case res.size
      when 0: nil
      when 1: coder.decode(res.first.attributes["name"])
      when 2: coder.decode(res.last.attributes["name"].sub(res.first.attributes["type"], res.first.attributes["name"]))
      else    res.map { |re| coder.decode(re.attributes["name"]) }.join(" ")
    end
  end.compact
end

Character files from D&DI Character Builder store loot as a list, but the names of magic items are concatenated with names of their connected mundane items, so you have to mix them based on the magic item’s @type.

Also, the Character Builder stores every item you’ve ever added, even if you deleted it immediately, so you have to filter out items with a count of zero. You have no way to tell if this was an intentional item purchase, an item accidentally clicked on or a found item from a module, so items with @count=0 are useless.

What could I possibly be building‽‽‽

Previously on RyanCannon.com

Epic

31 May 2009

Last weekend, at [Gamex][], I spent a grueling three days grinding through [Living Forgotten Realms][lfr] modules in order to level up in time for the convention’s finale: SPEC1-2: Zhent’s Ancient Shadows. [Gamex]: “One of the three yearly Strategicon Conventions” [lfr]:

The Watchmen: A review in bullet points

8 March 2009

I took my fiancée to see Watchmen last night. We were unprepared. I give it ★★★★ out of five. Below sums up my thoughts. It’s violent enough that I cringed. The movie is “patently too adult for … children 17 and under” and the fact that it’s not rated NC-17 is evidence of a moronic and/or [...]

Adventure Log: CORE1-1, Inheritance

27 January 2009

Six strangers find themselves in the cramped room sitting room of a once-wealthy merchant, who fidgets and stammers through his words. In a nearby city—shrouded in a bizarre permanent darkness—lies his family’s former wealth, and he begs them to return what remains of it. Can these strangers band together to enter the walled Forbidden zones [...]

Sayonara, Mr. Bush

17 January 2009

The only person who could summarize the current political situation correctly is John Stewart—reading the future from 2004.

hCard

About the author

RyanCannon.com is written, designed and programmed by Ryan Cannon, an Application Developer for NFL Enterprises in Los Angeles (N 34º 00' 42.98", W 118º 24' 37.18"), California, U.S.A.

Send flowers and cards on 1 November.

Visit the contact page to send me a note, or use my PGP Public Key to send me an .

If you'd like to learn more, visit the About page.