Permalink
Browse files

crafting experience - refactoring

  • Loading branch information...
1 parent 5d6d09c commit 3e0c47cd369433ee4557e889e19c597234898585 @jana4u committed May 20, 2012
@@ -1,4 +1,6 @@
require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/version')
+require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/craft_experience_level')
+require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/craft_experience')
require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/list_item')
require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/skill_list')
require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/craft_list')
@@ -11,5 +13,4 @@
require File.join(File.dirname(__FILE__), 'atlantica_online_craft_calculator/crafter')
module AtlanticaOnlineCraftCalculator
- CRAFT_XP_TO_WORKLOAD_RATIO = 50
end
@@ -0,0 +1,47 @@
+module AtlanticaOnlineCraftCalculator
+ class CraftExperience
+ if RUBY_VERSION >= "1.9"
+ require 'csv'
+ FasterCSV = CSV
+ else
+ require 'rubygems'
+ require 'fastercsv'
+ end
+
+ def self.load_levels_from_csv(data_file = File.join(File.dirname(__FILE__), '../../data', 'craft_experience_levels.csv'))
+ csv_data = FasterCSV.read(data_file, :headers => true)
+
+ self.load_levels_from_array(csv_data)
+ end
+
+ def self.load_levels_from_array(array)
+ levels = []
+
+ array.each do |item|
+ levels << CraftExperienceLevel.new(item["lvl"], item["xp"])
+ end
+
+ @levels = levels.sort_by { |level| level.lvl }
+ end
+
+ def self.levels
+ @levels ||= []
+ end
+
+ def self.multiplier
+ @multiplier ||= 1
+ end
+
+ def self.multiplier=(value)
+ @multiplier = value.to_f.abs
+
+ if @multiplier.zero?
+ @multiplier = nil
+ end
+ end
+
+ def self.from_workload(workload)
+ (workload.to_i.abs * multiplier / 50).floor
+ end
+ end
+end
@@ -0,0 +1,10 @@
+module AtlanticaOnlineCraftCalculator
+ class CraftExperienceLevel
+ attr_reader :lvl, :xp
+
+ def initialize(lvl, xp)
+ @lvl = lvl.to_i.abs
+ @xp = xp.to_i.abs
+ end
+ end
+end
@@ -17,7 +17,7 @@ def total_workload
end
def total_craft_xp_gained
- total_workload / CRAFT_XP_TO_WORKLOAD_RATIO
+ CraftXp.from_workload(total_workload)
end
end
@@ -26,7 +26,7 @@ def skills
result = SkillList::ItemArray.new
self.each do |i|
- if skill = result.find(i.skill)
+ if skill = result.find_by_name(i.skill)
skill.workload += i.total_workload
if i.skill_lvl > skill.lvl
skill.lvl = i.skill_lvl
@@ -50,7 +50,7 @@ def total_workload
end
def total_craft_xp_gained
- total_workload / CRAFT_XP_TO_WORKLOAD_RATIO
+ CraftExperience.from_workload(total_workload)
end
end
end
@@ -1,55 +1,30 @@
module AtlanticaOnlineCraftCalculator
+ # When auto-crafting, you will periodically receive some workload each auto-craft tick.
+ # The amount of workload you receive is dependent on the level of your expression Auto Craft.
+ # You receive 100 for the first level, then 20 for each additional level.
+ # Auto-craft ticks occur approximately every 5.35 seconds.
+ # http://www.atlanticaonlinewiki.com/index.php?title=Crafting
class Crafter
- if RUBY_VERSION >= "1.9"
- require 'csv'
- FasterCSV = CSV
- else
- require 'rubygems'
- require 'fastercsv'
- end
-
- def self.load_data_from_csv(data_file = File.join(File.dirname(__FILE__), '../../data', 'craft_experience_levels.csv'))
- csv_data = FasterCSV.read(data_file, :headers => true)
-
- self.levels = csv_data
- end
-
- def self.levels=(array)
- @@levels = []
-
- array.each do |item|
- @@levels << { :lvl => item["lvl"].to_i, :xp => item["xp"].to_i }
- end
- end
-
- def self.levels
- @@levels || {}
- end
-
attr_reader :auto_craft_lvl
+ # auto-craft level is integer 1 - 120
def initialize(auto_craft_lvl)
- @auto_craft_lvl = auto_craft_lvl
+ @auto_craft_lvl = [ [ auto_craft_lvl.to_i, 1 ].max, 120 ].min
end
+ # 100 workload for first auto-craft level, 20 for each additional level per tick
def tick_workload
- 100 + (@auto_craft_lvl - 1) * 20
+ 100 + (auto_craft_lvl - 1) * 20
end
+ # how many ticks are needed to finish workload
def ticks_for_workload(workload)
(workload / tick_workload.to_f).ceil
end
+ # how many seconds are needed to finish workload
def seconds_duration_for_workload(workload)
(ticks_for_workload(workload) * 5.35).ceil
end
-
- def batches_per_hour(workload, hours = 1)
- (hours * 3600 / seconds_duration_for_workload(workload)).floor
- end
-
- def items_per_hour(workload, batch_size, hours = 1)
- batches_per_hour(workload, hours) * batch_size
- end
end
end
@@ -15,15 +15,15 @@ def self.load_data_from_yaml(custom_prices = {}, data_file = File.join(File.dirn
end
def self.all=(hash)
- @@all = {}
+ @all = {}
hash.each do |item_name, item_data|
- @@all[item_name] = new(item_data.merge({ "name" => item_name}))
+ @all[item_name] = new(item_data.merge({ "name" => item_name}))
end
end
def self.all
- @@all || {}
+ @all || {}
end
def self.find(item_name)
@@ -199,7 +199,7 @@ def unit_price
end
def craft_xp_gained_per_batch
- workload / CRAFT_XP_TO_WORKLOAD_RATIO
+ CraftExperience.from_workload(workload)
end
def craft_xp_gained_per_item
@@ -75,7 +75,7 @@ def workload
end
def craft_xp_gained
- @craft_xp_gained ||= workload / CRAFT_XP_TO_WORKLOAD_RATIO
+ @craft_xp_gained ||= CraftExperience.from_workload(workload)
end
def ingredient_list
@@ -1,23 +1,30 @@
module AtlanticaOnlineCraftCalculator
module SkillList
class Item
- attr_reader :name
- attr_accessor :lvl, :workload
+ attr_reader :name, :lvl, :workload
def initialize(name, lvl, workload)
@name = name
- @lvl = lvl
- @workload = workload
+ self.lvl = lvl
+ self.workload = workload
+ end
+
+ def lvl=(lvl)
+ @lvl = lvl.to_i.abs
+ end
+
+ def workload=(workload)
+ @workload = workload.to_i.abs
end
def craft_xp_gained
- workload / CRAFT_XP_TO_WORKLOAD_RATIO
+ CraftExperience.from_workload(workload)
end
end
class ItemArray < Array
- def find(skill_name)
- detect { |s| s.name == skill_name }
+ def find_by_name(name)
+ detect { |s| s.name == name }
end
end
end

0 comments on commit 3e0c47c

Please sign in to comment.