-
Notifications
You must be signed in to change notification settings - Fork 0
/
turn.rb
35 lines (29 loc) · 974 Bytes
/
turn.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true
# == Schema Information
#
# Table name: turns
#
# id :bigint not null, primary key
# game_id :bigint
# line :text
# attacker_id :bigint
# attacked_id :bigint
# created_at :datetime not null
# updated_at :datetime not null
# attack :integer
# attacker_health_points :integer
# attacked_health_points :integer
#
require 'faker'
class Turn < ApplicationRecord
belongs_to :game
belongs_to :attacker, class_name: 'Character'
belongs_to :attacked, class_name: 'Character'
default_scope { order(created_at: :asc) }
def run(weapon)
update(attacker_health_points: attacker.health_points, attacked_health_points: attacked.health_points)
attack = attacker.attack(weapon)
attacked.is_attacked(attack)
update(line: Faker::Hipster.sentence(attack), attack: attack)
end
end