summaryrefslogtreecommitdiff
path: root/app/lib/activity_processor.rb
diff options
context:
space:
mode:
Diffstat (limited to 'app/lib/activity_processor.rb')
-rw-r--r--app/lib/activity_processor.rb63
1 files changed, 55 insertions, 8 deletions
diff --git a/app/lib/activity_processor.rb b/app/lib/activity_processor.rb
index b5dd11c..cca2185 100644
--- a/app/lib/activity_processor.rb
+++ b/app/lib/activity_processor.rb
@@ -90,6 +90,13 @@ class ActivityProcessor
item = Item.find_by_gid(result[:gid])
hp = @character.hearth.hearth_plantings.create(item: item)
@results.push({ type: type, hearth_planting: hp })
+ when "condition"
+ Character.transaction do
+ condition = Condition.find_by_gid(result[:gid])
+ @character.states.create!(condition: condition, expires_at: Time.now + result[:duration])
+ @results.push({ type: "message", body: result[:message] })
+ @results.push({ type: type, condition: condition })
+ end
when "activity"
next if rand > (result[:chance] || 1)
table_roll = rand
@@ -97,6 +104,7 @@ class ActivityProcessor
score = table_entry[:score]
if table_roll >= score
new_activity = Activity.find_by_gid(table_entry[:gid])
+ raise "Invalid activity gid (#{table_entry[:gid]})" unless new_activity
unless @character.learned_activities.exists?(activity: new_activity)
@character.learned_activities.create(activity: new_activity)
@results.push({ type: type, activity: new_activity })
@@ -108,6 +116,26 @@ class ActivityProcessor
end
end
+ # Note: This will result in equipment being checked for breakage twice (after combat, and now) if it provides the
+ # `beastslay_speed` stat. At the time of this writing, that stat doesn't exist.
+ # But just something to keep in mind.
+ # Note: This will result in equipment being checked twice if it provides two speed stats.
+ # Fine for now since no equipment gives two skill speed stats, but may want to refine in the future.
+ if @activity.whatnot[:requirements]&.any?
+ required_skill_gids = @activity.whatnot[:requirements].select { |r| r[:type] == "skill" }.map { |r| r[:gid] }.uniq
+ required_skill_gids.each do |required_skill_gid|
+ skill = Skill.find_by_gid(required_skill_gid)
+ broken_item = @character.do_equipment_break_check(skill: skill)
+ if broken_item
+ @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" })
+ end
+ broken_infix_item = @character.do_item_infix_break_check(skill: skill)
+ if broken_infix_item
+ @results.push({ type: "warning", message: "Your #{broken_infix_item.name} omen faded away." })
+ end
+ end
+ end
+
if @character.activity && @character.queued_actions
if @character.queued_actions > 0
@character.queued_actions -= 1
@@ -166,7 +194,8 @@ class ActivityProcessor
end
def handle_title_result(data)
- if @character.award_title(data[:gid])
+ title = Title.find_by_gid(data[:gid])
+ if @character.award_title(title)
@results.push({ type: "title", title: title })
end
end
@@ -230,8 +259,13 @@ class ActivityProcessor
turn_order = [[char, mon], [mon, char]].shuffle
end
turn_order.cycle do |actor, target|
+
base_accuracy_roll = roll(20)
accuracy_roll = base_accuracy_roll + actor.accuracy(with_combat_style: true)
+ if actor == mon
+ accuracy_roll += char.total_enemy_stat_change("accuracy")
+ end
+
evasion_roll = roll(20) + target.evasion(with_combat_style: true)
if accuracy_roll >= evasion_roll || base_accuracy_roll == 20
@@ -273,8 +307,22 @@ class ActivityProcessor
combat_message.call("#{target.name} evaded #{actor.name}'s attack.")
end
+ # HACK: DoT is char-only, and one-damage-type-only for now.
+ if actor == char
+ actor.dots.each do |data|
+ damage_roll = rand(data[:min]..data[:max])
+ effective_resistance = [target.resistance(data[:gid]), damage_roll].min
+ resolved_damage = damage_roll - (effective_resistance * rand(0.5..1)).round
+ mon_hp -= resolved_damage
+ combat_message.call("#{data[:message]} (#{resolved_damage} #{data[:gid]})")
+ end
+ end
+
if char_hp < 1 || mon_hp < 1
- break_check
+ broken_item = @character.do_equipment_break_check
+ if broken_item
+ @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" })
+ end
if monster_spawn
hp_lost = monster_spawn.remaining_hp - mon_hp
@@ -295,6 +343,11 @@ class ActivityProcessor
end
else
@results.push({ type: "message", body: "You slew the #{mon.name}." })
+
+ monster_kills = character.monster_kills.find_or_initialize_by(monster: mon)
+ monster_kills.quantity ? monster_kills.quantity += 1 : monster_kills.quantity = 1
+ monster_kills.save
+
if monster_spawn
char.stop_activity
return
@@ -317,10 +370,4 @@ class ActivityProcessor
end
end
end
-
- def break_check
- @character.do_equipment_break_checks.each do |broken_item|
- @results.push({ type: "warning", message: "Your #{broken_item.name} was damaged beyond repair!" })
- end
- end
end