space_age_1861/_plugins/gear.rb

158 lines
5.2 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')
return eval(dmg).to_i
end
def dmg_max(dmg)
dmg.sub!(/(\d)d(\d+)/, '\1 * \2') #2d62 -> 62*2
dmg.sub!(/Рукопашный Урон|РУ/, '5')
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
class FirearmWeaponTag < WeaponTag
def initialize(tag_name, text, tokens)
super
values = text.split(',')
@ammo = values[0]
@ammo_count = values[1].to_i # ёмкость
@AP_reload = values[2].to_i
@AP_hit = values[3].to_i
@AP_aim = values[4].to_i
@dmg = values[5]
@distance = values[6].to_i
end
def damage(ammo_type)
case ammo_type
when '.30'
return '1d6'
when '.31'
return '1d6'
when '.35'
return '1d8'
when '.45'
return '1d10'
when '.52'
return '1d10'
when '.58'
return '1d12'
when 'Стрела'
return '1d4'
when 'Арбалетная стрела'
return '1d6'
end
end
def render(context)
value = "ОД на перезарядку | #{@AP_reload}\nОД на выстрел (одиночный) | #{@AP_hit}\n"
value = value + "ОД на выстрел (прицельный) | #{@AP_aim}\nПовреждения | #{@dmg}\n"
if (@ammo_count) then value = value + "Ёмкость | #{@ammo_count}\n" end
if (@ammo && @ammo != 'Стрела' && @ammo != 'Арбалетная стрела') then
value = value + "Калибр | #{@ammo}\n"
end
if (@distance) then value = value + "Дальность, м | #{@distance}\n" end
shots = (10 / @AP_aim).round
if (shots > @ammo_count) then
# не могу придумать ничего умного, проще смоделировать бой
shots = 0
reloads = 0
count = @ammo_count
ap = 10
while (ap > @AP_aim)
#puts "\nAP: #{ap}\nПатронов:#{count}"
if (count > 0) then
#puts "Выстрел на #{@AP_aim} ОД\n"
shots = shots + 1
count = count - 1
ap = ap - @AP_aim
else
#puts "Перезарядка\n"
if (ap < @AP_reload) then break end
reloads = reloads + 1
count = @ammo_count
ap = ap - @AP_reload
end
end
end
fic_min = shots * dmg_min(@dmg.clone + damage(@ammo))
shots = (10 / @AP_hit).round
if (shots > @ammo_count) then
shots = 0
reloads = 0
count = @ammo_count
ap = 10
while (ap > @AP_hit)
if (count > 0) then
shots = shots + 1
count = count - 1
ap = ap - @AP_hit
else
if (ap < @AP_reload) then break end
reloads = reloads + 1
count = @ammo_count
ap = ap - @AP_reload
end
end
end
fic_max = shots * dmg_max(@dmg.clone + damage(@ammo))
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)
Liquid::Template.register_tag('firearm', Jekyll::FirearmWeaponTag)