Created
January 8, 2010 11:01
-
-
Save boj/271981 to your computer and use it in GitHub Desktop.
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
class Achievement | |
include MongoMapper::Document | |
key :name, String | |
key :description, String | |
key :requirements, String | |
key :lang, String | |
end |
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
class AchievementSystem | |
# Scans to see if the character has completed any Achievements of type | |
def self.scan(player, type) | |
completed = [] | |
achievements = Achievement.find(:all, :type => type) | |
for achievement in achievements | |
found = false | |
player.character_achievements.each do |pach| | |
if pach.achievement_id == achievement.id | |
found = true | |
end | |
end | |
next if found | |
case type | |
when "FAMILIAR" | |
completed << achievement if eval("player.character_familiars.count %s" % achievement.requirements) | |
when "QUEST" | |
completed_quests = player.character_quests.find(:all, :is_completed => true) | |
completed << achievement if eval("completed_quests.size %s" % achievement.requirements) | |
when "GOLD" | |
completed << achievement if eval("player.total_gold %s" % achievement.requirements) | |
end | |
end | |
return completed.collect do |ach| | |
CharacterAchievement.create(:character_id => player.id, :achievement_id => ach.id) | |
end | |
end | |
end |
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
- name: A Familiar! | |
description: Received first familiar. | |
requirements: " == 1" | |
type: FAMILIAR | |
- name: A Quest! | |
description: Completed first quest. | |
requirements: " == 1" | |
type: QUEST | |
- name: The Rich Get Richer | |
description: Received 100 gold. | |
requirements: " >= 100" | |
type: GOLD |
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
####################################### | |
# Achievements | |
####################################### | |
puts "Populating Achievements..." | |
achievements = YAML.load(File.open("#{RAILS_ROOT}/db/load/en/achievements.yml")) | |
for achievement in achievements | |
Achievement.create( | |
:name => achievement['name'], | |
:description => achievement['description'], | |
:requirements => achievement['requirements'], | |
:type => achievement['type'], | |
:lang => 'en' | |
) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment