/
character.rb
93 lines (75 loc) · 2.22 KB
/
character.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
class Character < ActiveRecord::Base
attr_accessible :gender, :name, :species, :location_id
has_one :profile
has_one :ship
belongs_to :location
has_many :properties
has_many :possessions, :as => :ownable
has_many :wares, :as => :vendable
PLAYER_ATTRIBUTES = [:compassion, :courage, :dependability,
:endurance, :honesty, :honor,
:charisma, :leadership, :logistics,
:perception, :pilot, :quickness,
:tactical, :technical, :wit]
PLAYER_TURNS = 2016
#include Owning
#include Vending
include Transactionable
def increment_turn(turns)
self.turns_spent += turns
end
def current_ship
ship
end
def turns_remaining
PLAYER_TURNS - self.turns_spent
end
def game_over?
turns_remaining == 0 #true
end
def inventory_items
possessions
end
def will_buy?(good)
true
end
#
# def initialize_inventory_item(good, quantity)
# character_inventory_items.create!(good_id: good.id, quantity: quantity)
# end
#
# def increase_inventory_item(good, quantity)
# add_good(good, quantity)
# end
# def quantity_of(good)
# character_inventory_items.find_by_good_id(good.id) ? character_inventory_items.find_by_good_id(good.id).quantity : 0
# end
# def buy_good(good, quantity)
# stock(good, quantity)
# end
# def valid_quantity?(good, quantity)
# character_inventory_items.find_by_good_id(good.id) && quantity_of(good) >= quantity
# end
# def sell_good(good, quantity)
# if valid_quantity?(good, quantity)
# item = character_inventory_items.find_by_good_id(good.id)
# updated_quantity = item.quantity - quantity
# item.update_attribute(:quantity, updated_quantity)
# else
# false #mark review - should these be exceptions instead?
# end
# end
def enough_turns?(turns_required)
turns_remaining >= turns_required
end
def travel(destination)
turns_required = current_ship.time_to_travel_to(destination)
if enough_turns?(turns_required)
increment_turn(turns_required)
self.location = destination
self.save!
else
false
end
end
end