space_age_1861/_plugins/gear.rb

78 lines
2.6 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/env ruby
# encoding: utf-8
module Jekyll
class WeightTag < Liquid::Tag
def initialize(tag_name, text, tokens)
super
@weight = text.to_f
end
def render(context)
strength = (@weight / 1.1).round
if (strength < 1) then strength = 1 end
return "Вес | #{@weight}\nМинимальная Сила | #{strength}"
end
end
class WeaponTag < Liquid::Tag
def dmg_min(dmg)
dmg.sub!(/(\d)d\d+/, '\1') #2d62 -> 2
dmg.sub!(/Рукопашный Урон|РУ/, '1')
if dmg.index('-') then
values = dmg.split('-')
if (values.at(0).to_i > values.at(1).to_i) then
return dmg.split('-').at(0).to_i
end
end
return eval(dmg).to_i
end
def dmg_max(dmg)
dmg.sub!(/(\d)d(\d+)/, '\1 * \2') #2d62 -> 62*2
dmg.sub!(/Рукопашный Урон|РУ/, '5')
if dmg.index('-') then
if (values.at(0).to_i > values.at(1).to_i) then
return dmg.split('-').at(1).to_i
end
end
return eval(dmg).to_i
end
end
class MeleeWeaponTag < WeaponTag
def initialize(tag_name, text, tokens)
super
values = text.split(',')
@AP_hit = values[0].to_i
@AP_aim = values[1].to_i
@dmg = values[2]
end
def render(context)
value = "ОД на удар | #{@AP_hit}\nОД на прицельный удар | #{@AP_aim}\nПовреждения | #{@dmg}\nДальность | 1\n"
fic_min = (10 / @AP_aim).round * dmg_min(@dmg.clone)
fic_max = (10 / @AP_hit).round * dmg_max(@dmg.clone)
value = value + "НЁХ (удар) | #{fic_min}-#{fic_max}"
return value
end
end
class ThrowingWeaponTag < WeaponTag
def initialize(tag_name, text, tokens)
super
values = text.split(',')
@AP_hit = values[0].to_i
@AP_aim = values[1].to_i
@dmg = values[2]
@distance = values[3]
end
def render(context)
value = "ОД на бросок | #{@AP_hit}\nОД на прицельный бросок | #{@AP_aim}\nПовреждения (бросок) | #{@dmg}\n"
if (@distance) then value = value + "Эффективная дальность (бросок) | #{@distance}\n" end
fic_min = (10 / @AP_aim).round * dmg_min(@dmg.clone)
fic_max = (10 / @AP_hit).round * dmg_max(@dmg.clone)
value = value + "НЁХ (бросок) | #{fic_min}-#{fic_max}"
return value
end
end
end
Liquid::Template.register_tag('weight', Jekyll::WeightTag)
Liquid::Template.register_tag('melee', Jekyll::MeleeWeaponTag)
Liquid::Template.register_tag('throwing', Jekyll::ThrowingWeaponTag)