Class: GamesParadise::ShakesAndFidgets::Character
- Inherits:
-
Object
- Object
- GamesParadise::ShakesAndFidgets::Character
show all
- Defined in:
- lib/games_paradise/shakes_and_fidgets/character/character.rb
Overview
GamesParadise::ShakesAndFidgets::Character
Constant Summary
collapse
- ARRAY_RACES =
#
ARRAY_RACES
Different races can be picked. Orc adds +1 to strength for instance but deduct -1 from intelligence.
#
%w(
elf
dwarf
human
gnome
orc
goblin
demon
)+['dark elf']
- RJUST =
14
- ARRAY_AVAILABLE_LAYERS =
#
ARRAY_AVAILABLE_LAYERS
#
[
:head, :torso, :waist,
:neck, :left_hand, :right_hand,
:feet, :charm, :weapon,
:inventory
]
Instance Method Summary
collapse
Constructor Details
#initialize(run_already = true) ⇒ Character
51
52
53
54
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 51
def initialize(run_already = true)
reset
run if run_already
end
|
Instance Method Details
#abenteuerlust? ⇒ Boolean
Also known as:
motivation, abenteuerlust
601
602
603
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 601
def abenteuerlust?
@abenteuerlust end
|
#add_honour(i) ⇒ Object
202
203
204
205
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 202
def add_honour(i)
i = i.to_i
@honour += i
end
|
#add_money(i) ⇒ Object
Also known as:
add_cash
#
add_money
Use this money to add some coins to the character in question.
#
369
370
371
372
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 369
def add_money(i)
i = i.to_i
set_money(@n_silver_coins+i)
end
|
#add_motivation(i = '10-50') ⇒ Object
Also known as:
add_abenteuerlust
#
add_motivation
Use this method when you wish to add motivation to a weary hero.
#
249
250
251
252
253
254
255
256
257
258
259
260
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 249
def add_motivation(i = '10-50')
if i.is_a? String
i.delete!('+') if i.include? '+'
if i.include? '-'
min, max = i.split('-')
i = (min..max).map(&:to_i)
end
end
i = i.sample if i.is_a? Array
i = i.to_i
@abenteuerlust += i
end
|
#add_to_inventory(i) ⇒ Object
125
126
127
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 125
def add_to_inventory(i)
@inventory << i
end
|
#add_xp(i) ⇒ Object
301
302
303
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 301
def add_xp(i)
@xp += i.to_i
end
|
#all_armours ⇒ Object
#
all_armours
This method will return a hash with all armours.
#
286
287
288
289
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 286
def all_armours result = @layers.keys.map {|x| x.name? } return result
end
|
#armours? ⇒ Boolean
Also known as:
layers
691
692
693
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 691
def armours?
@layers end
|
#available_stats? ⇒ Boolean
Also known as:
attributes, attributes?
543
544
545
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 543
def available_stats?
@attributes
end
|
#calculate_bonus_from_armours ⇒ Object
#
calculate_bonus_from_armours
#
139
140
141
142
143
144
145
146
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 139
def calculate_bonus_from_armours
get_all_layers.each { |layer| possible_armour = @layers[layer]
if possible_armour.respond_to? :attribute_boosts
modify_attribute(possible_armour.attribute_boosts)
end
}
end
|
#calculate_level_from_xp ⇒ Object
Also known as:
calculate_level_from_xp?
#
calculate_level_from_xp
#
385
386
387
388
389
390
391
392
393
394
395
396
397
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 385
def calculate_level_from_xp
xp = xp?
between_these_two_levels = [] INVERTED_XP_LEVELS.each_pair {|key, value|
if key < xp
between_these_two_levels[0] = value unless between_these_two_levels.size > 1
end
if key > xp
between_these_two_levels << value unless between_these_two_levels.size > 1
end
}
return between_these_two_levels.first end
|
#cash? ⇒ Boolean
Also known as:
money?, coins?, silver_coins?, n_money?, gold, gold?
721
722
723
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 721
def cash?
@n_silver_coins
end
|
#character_class? ⇒ Boolean
650
651
652
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 650
def character_class?
@character_class
end
|
#debug ⇒ Object
265
266
267
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 265
def debug
pp @attributes
end
|
#deduct_money(i) ⇒ Object
377
378
379
380
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 377
def deduct_money(i)
i = i.to_i
set_money(@n_silver_coins-i)
end
|
#deduct_motivation(i = 5) ⇒ Object
239
240
241
242
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 239
def deduct_motivation(i = 5)
@abenteuerlust -= i.to_i
@abenteuerlust = 0 if @abenteuerlust < 0 end
|
#dex? ⇒ Boolean
522
523
524
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 522
def dex?
get_value_for_this_attribute('geschick')
end
|
#ehre? ⇒ Boolean
Also known as:
ehre
#
ehre?
How much fame (“ehre”) this character has.
#
735
736
737
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 735
def ehre?
@ehre
end
|
#endurance? ⇒ Boolean
508
509
510
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 508
def endurance?
get_value_for_this_attribute('ausdauer')
end
|
#feedback_name ⇒ Object
224
225
226
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 224
def feedback_name
e @name
end
|
#find_proper_name_for_this_attribute(i) ⇒ Object
#
find_proper_name_for_this_attribute
#
416
417
418
419
420
421
422
423
424
425
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 416
def find_proper_name_for_this_attribute(i)
if @attributes.has_key? i
result = i
else
all_matches = @attributes.keys.select {|entry| entry =~ /#{i}/ }
all_matches = all_matches.first unless all_matches.empty?
result = all_matches
end
return result
end
|
#get_all_layers ⇒ Object
#
get_all_layers
This returns an array of all layers that can change the Attributes.
#
153
154
155
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 153
def get_all_layers
ARRAY_AVAILABLE_LAYERS
end
|
#get_value_for_this_attribute(i = '') ⇒ Object
#
get_value_for_this_attribute
You can use this method to query the value of an attribute.
Usage example:
get_value_for_this_attribute('int')
#
576
577
578
579
580
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 576
def get_value_for_this_attribute(i = '')
result = find_proper_name_for_this_attribute(i)
result = @attributes[result]
return result
end
|
#increase(this_attribute, by_how_much = 1) ⇒ Object
#
increase
Use this method to increase an attribute of the character.
#
432
433
434
435
436
437
438
439
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 432
def increase(
this_attribute, by_how_much = 1
)
this_attribute = find_proper_name_for_this_attribute(this_attribute)
value = get_value_for_this_attribute(this_attribute) + by_how_much
_ = this_attribute+' = '+value.to_s
set_attribute(_)
end
|
#int? ⇒ Boolean
515
516
517
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 515
def int?
get_value_for_this_attribute('int')
end
|
#inventory? ⇒ Boolean
Also known as:
inventory
132
133
134
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 132
def inventory?
@inventory end
|
#level? ⇒ Boolean
Also known as:
level
174
175
176
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 174
def level?
@level
end
|
#luck? ⇒ Boolean
501
502
503
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 501
def luck?
get_value_for_this_attribute('glück')
end
|
#modify_attribute(array) ⇒ Object
#
modify_attribute
Use this to modify an attribute.
#
162
163
164
165
166
167
168
169
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 162
def modify_attribute(array)
unless array.empty?
array = array.flatten
attribute = array[0].downcase
boost = array[1] @attributes[attribute] = @attributes[attribute] + boost
end
end
|
#name=(i) ⇒ Object
360
361
362
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 360
def name=(i)
@name = i
end
|
#name? ⇒ Boolean
Also known as:
name
353
354
355
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 353
def name?
@name
end
|
#original_attributes? ⇒ Boolean
Also known as:
original_attributes
487
488
489
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 487
def original_attributes?
@original_attributes
end
|
#padding? ⇒ Boolean
320
321
322
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 320
def padding?
18
end
|
#pick_random_race ⇒ Object
#
pick_random_race
This method will select a random race.
#
684
685
686
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 684
def pick_random_race
set_race(ARRAY_RACES.sample)
end
|
#pilze(i = '-1') ⇒ Object
308
309
310
311
312
313
314
315
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 308
def pilze(i = '-1')
if i.to_s.include? '-'
i = i.to_s.delete('-')
@n_pilze -= i.to_i
end
i = i.to_i
@n_pilze = i
end
|
#race? ⇒ Boolean
698
699
700
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 698
def race?
@race
end
|
#report_abenteuerlust ⇒ Object
444
445
446
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 444
def report_abenteuerlust
eparse ('Abenteuerlust:').ljust(padding?)+abenteuerlust?.to_s.rjust(RJUST)
end
|
#report_character_class ⇒ Object
#
report_character_class
#
657
658
659
660
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 657
def report_character_class
eparse ('Character class:').ljust(padding?)+
character_class?.to_s.capitalize.rjust(RJUST)
end
|
#report_fame ⇒ Object
Also known as:
fame?
402
403
404
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 402
def report_fame
eparse ('Fame:').ljust(padding?)+ehre?.to_s.rjust(RJUST)
end
|
#report_level ⇒ Object
409
410
411
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 409
def report_level
eparse ('Level:').ljust(padding?)+calculate_level_from_xp?.to_s.rjust(RJUST)
end
|
#report_money ⇒ Object
#
report_money
Report how much money the character has.
#
707
708
709
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 707
def report_money
eparse ('Money:').ljust(padding?)+gold?.to_s.rjust(RJUST)
end
|
#report_name ⇒ Object
334
335
336
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 334
def report_name
eparse ('Name:').ljust(padding?)+name?.to_s.rjust(RJUST)
end
|
#report_race ⇒ Object
714
715
716
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 714
def report_race
eparse ('Race:').ljust(padding?)+race?.to_s.rjust(RJUST)
end
|
#report_stats ⇒ Object
451
452
453
454
455
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 451
def report_stats
attributes?.each_pair {|key, value|
eparse (key.to_s.capitalize+':').ljust(padding?)+value.to_s.rjust(RJUST)
}
end
|
#report_xp ⇒ Object
327
328
329
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 327
def report_xp
eparse ('XP:').ljust(padding?)+xp?.to_s.rjust(RJUST)
end
|
#reset ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 59
def reset
@original_attributes = {} pick_random_race
reset_layers
reset_attributes
set_attributes '
stärke: 0
geschick: 0
intelligenz: 0
ausdauer: 0
glück: 0
'
set_abenteuerlust set_xp
set_name
set_ehre
set_money
@n_pilze = 0
@honour = 0
@level = 0
end
|
#reset_attributes ⇒ Object
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 94
def reset_attributes
@attributes = {}
@inventory = []
end
|
#reset_layers ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 108
def reset_layers @layers = {} @layers[:head] = ''
@layers[:torso] = ''
@layers[:waist] = ''
@layers[:neck] = ''
@layers[:left_hand] = '' @layers[:right_hand] = ''
@layers[:feet] = ''
@layers[:charm] = '' @layers[:weapon] = ''
@layers[:inventory] = [] end
|
#run ⇒ Object
#
run
General run method.
#
744
745
746
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 744
def run
set_class
end
|
#set_abenteuerlust(i = 100) ⇒ Object
Also known as:
abenteuerlust=
231
232
233
234
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 231
def set_abenteuerlust(i = 100) i = i.to_i @abenteuerlust = i
end
|
#set_agility(i) ⇒ Object
181
182
183
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 181
def set_agility(i)
set_attribute('geschick: '+i.to_s)
end
|
#set_attribute(i) ⇒ Object
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 551
def set_attribute(i) if i.is_a? String
i.strip!
if i.include? '='
i = i.split('=')
else
i = i.gsub(/:/,'').split(' ')
end
end
splitted = i
value = splitted[1]
value.strip! if value.is_a? String
value = value.to_i
this_attribute = splitted.first.dup.force_encoding(ENCODING_ISO).strip
@attributes[this_attribute] = value end
|
#set_attributes(i) ⇒ Object
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 460
def set_attributes(i)
if i.is_a? String
i = i.split(N)
i.map! {|entry| entry.strip }
i.reject! {|entry| entry.empty? }
i.each {|entry|
splitted = entry.split(':')
attribute_value = splitted.last
case entry
when /stärke/ set_strength(attribute_value)
when /geschick/ set_agility(attribute_value)
when /intelligenz/ set_intelligence(attribute_value)
when /ausdauer/
set_endurance(attribute_value)
when /glück/
set_luck(attribute_value)
end
}
end
end
|
#set_character_class(i) ⇒ Object
665
666
667
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 665
def set_character_class(i)
@character_class = i
end
|
#set_class(i = 'kundschafter') ⇒ Object
#
set_class
There are four classes to pick from:
(1) Kundschafter
(2) Magier
(3) Krieger
(4) Berserker
#
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 617
def set_class(i = 'kundschafter') case i.to_s when '1','scout','kundschafter'
i = 'scout'
when '2','mage','magier'
i = 'mage'
when '3','fighter','warrior','default','krieger'
i = 'warrior'
when '4','berserker'
i = 'berserker'
end
@yaml_dataset = YAML.load_file(BASE_STATS_FOR_THE_CLASSES)
@yaml_dataset[i].each { |line|
line[0] = line[0].to_s.dup.force_encoding(Encoding::ENCODING_ISO)
first = line.first
last = line.last
set_attribute(line)
@original_attributes[first] = last
}
remove_instance_variable(:@yaml_dataset) set_character_class(i)
end
|
#set_ehre(i = '0') ⇒ Object
210
211
212
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 210
def set_ehre(i = '0') @ehre = i.to_i
end
|
#set_endurance(i) ⇒ Object
188
189
190
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 188
def set_endurance(i)
set_attribute('ausdauer: '+i.to_s)
end
|
#set_intelligence(i) ⇒ Object
195
196
197
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 195
def set_intelligence(i)
set_attribute('intelligenz: '+i.to_s)
end
|
#set_luck(i) ⇒ Object
529
530
531
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 529
def set_luck(i)
set_attribute('glück: '+i.to_s)
end
|
#set_money(i = 500) ⇒ Object
#
set_money
10 silver coins is 1 gold coin.
We will calculate in silver coins.
#
345
346
347
348
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 345
def set_money(i = 500)
i = 0 if i < 0
@n_silver_coins = i
end
|
#set_name(i = 'shevegen') ⇒ Object
217
218
219
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 217
def set_name(i = 'shevegen')
@name = i
end
|
#set_portrait(file_location) ⇒ Object
87
88
89
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 87
def set_portrait(file_location) @portrait_location = file_location
end
|
#set_race(i = :elf) ⇒ Object
Also known as:
race=
#
set_race
These 7 races are possible:
elf, dwarf, human, gnome, orc, dark elf, goblin, demon
#
675
676
677
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 675
def set_race(i = :elf)
@race = i.to_s
end
|
#set_strength(i) ⇒ Object
536
537
538
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 536
def set_strength(i)
set_attribute('stärke: '+i.to_s)
end
|
#set_xp(i = 0) ⇒ Object
294
295
296
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 294
def set_xp(i = 0)
@xp = i
end
|
#stats? ⇒ Boolean
#
stats?
This method will return a Hash.
#
594
595
596
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 594
def stats?
attributes?
end
|
#strength? ⇒ Boolean
494
495
496
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 494
def strength?
get_value_for_this_attribute('stärke')
end
|
#try_to_equip(this_armour = Armour.new) ⇒ Object
Also known as:
equip_randomly
272
273
274
275
276
277
278
279
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 272
def try_to_equip(this_armour = Armour.new) if this_armour.is_armour?
@layers[this_armour.type?] = this_armour calculate_bonus_from_armours else
warn 'Sorry, '+this_armour.name+' is not an armour.'
end
end
|
#xp? ⇒ Boolean
Also known as:
xp
585
586
587
|
# File 'lib/games_paradise/shakes_and_fidgets/character/character.rb', line 585
def xp?
@xp
end
|