vrobot4/source/modules/doomrla.rb

111 lines
3.7 KiB
Ruby
Raw Normal View History

2017-08-09 00:52:45 -07:00
require 'open-uri'
require 'json'
#--
2017-08-09 00:52:45 -07:00
# ===== WARNING =====
#
# !!! INCOMING SPAGHETTI !!!
#
# - BE PRAYING
# - BE PRAYING
# - BE PRAYING
#
class Mod_DoomRLA < Vrobot4::Module::Module
def self.type() "DoomRLA" end
2017-08-09 02:57:31 -07:00
Vrobot4::Module.add_module_type self, server: "Discord"
2017-08-09 00:52:45 -07:00
AType = ["Melee", "Ranged", "Special"].freeze
DType = ["Melee", "Bullet", "Fire", "Plasma",
"Piercing", "Holy", "Unholy", "Special"].freeze
def initialize info
super
2017-09-10 21:47:50 -07:00
register :c_assemblyinfo, "assemblyinfo", "Prints DRLA assembly info."
2018-06-25 10:01:45 -07:00
register :c_weaponinfo, "weaponinfo", "Prints DRLA weapon info."
register :c_monsterinfo, "monsterinfo", "Prints DRLA monster info."
register :c_reloadinfo, "reloadinfo", "Reload DRLA info.", roles: "h"
reload_info
end
2017-08-09 00:52:45 -07:00
2018-06-25 10:01:45 -07:00
def expldamage a
"#{a["ExplosionDamage"]} explosion damage, #{a["ExplosionRadius"]} radius\n"
2017-08-09 00:52:45 -07:00
end
2017-09-10 21:47:50 -07:00
def c_assemblyinfo m, argv
t = ""
2018-06-28 22:37:19 -07:00
w = @winfo.select {|wep| wep if wep["Assembly"] and wep["AssemblyItem"].casecmp(argv) == 0}
2018-06-25 10:01:45 -07:00
raise ArgumentError, "No assemblies found" if w == nil || w.empty?
2017-09-10 21:47:50 -07:00
w.each {|wep| t << wep["Assembly"] + " - " + wep["Name"] + "\n"}
m.chan.real.send_embed {|embed| embed.description = t} if t != ""
end
2017-08-09 00:52:45 -07:00
def c_weaponinfo m, argv
2018-06-28 22:37:19 -07:00
w = @winfo.find {|wep| wep if wep["Name"].casecmp(argv) == 0}
2017-08-11 15:16:16 -07:00
raise ArgumentError, "Weapon not found" if w == nil
2018-06-25 10:01:45 -07:00
t = "#{w["Damage"]} #{w["DamageType"]} damage\n"
t << "#{w["Shots"]} shots\n" if w["Shots"].to_i > 1
t << "Uses #{w["AmmoUsage"]} #{w["AmmoType"]}\n" if w["AmmoType"] != "None"
t << "#{w["Capacity"]} capacity\n" if w["Capacity"]
2017-08-09 00:52:45 -07:00
t << "\n"
2018-06-25 10:01:45 -07:00
t << expldamage(w) if w["ExplosionDamage"]
t << "Traits: #{w["Traits"]}\n" if w["Traits"] != "N/A"
t << "Assembly: #{w["Assembly"]} with #{w["AssemblyItem"]}\n" if w["Assembly"]
t << w["Description"] if w["Description"]
2017-08-09 00:52:45 -07:00
m.chan.real.send_embed do |embed|
2018-06-25 10:01:45 -07:00
embed.title = "[#{w["Rarity"]}] #{w["Name"]}"
2017-08-09 00:52:45 -07:00
embed.description = t
end
end
def c_monsterinfo m, argv
2018-06-25 10:01:45 -07:00
mi = @minfo.select do |mon|
2018-06-28 22:37:19 -07:00
mon if mon["Name"].casecmp(argv) == 0 or mon["Tags"].split(", ").include? argv
2017-08-11 15:16:16 -07:00
end
2018-06-25 10:01:45 -07:00
raise ArgumentError, "No monsters found" if mi == nil || mi.empty?
2017-08-11 15:16:16 -07:00
mi.first(3).each do |w|
2018-06-25 10:01:45 -07:00
t = "#{w["Health"]} Health\n"
t << "Resistances: #{w["Resistances"]}\n"
t << "Drops: #{w["ItemDrops"]}\n" if w["ItemDrops"]
t << w["Description"] if w["Description"]
2017-08-09 00:52:45 -07:00
t << "\n"
2018-06-25 10:01:45 -07:00
2017-08-09 00:52:45 -07:00
w["Attacks"].each do |a|
2018-06-25 10:01:45 -07:00
t << "\n[#{AType[a["AttackType"].to_i]}] #{a["Name"]}\n"
t << "#{a["Damage"]} #{DType[a["DamageType"].to_i]} damage\n"
t << expldamage(a) if a["ExplosionDamage"]
t << "#{a["Shots"]} shots\n" if a["Shots"].to_i > 1
t << "#{a["Description"]}\n" if a["Description"]
2017-08-09 00:52:45 -07:00
end
2018-06-25 10:01:45 -07:00
2017-08-09 00:52:45 -07:00
m.chan.real.send_embed do |embed|
2018-06-25 10:01:45 -07:00
embed.title = "[#{w["Difficulty"]}] #{w["Name"]}"
embed.title << " #{w["Weapon"]}" if w["Weapon"]
embed.image = Discordrb::Webhooks::EmbedImage.new url: w["Sprite"] if w["Sprite"]
2017-08-09 00:52:45 -07:00
embed.description = t
end
end
end
2017-08-09 02:58:21 -07:00
def c_reloadinfo m, argv
2018-06-25 10:01:45 -07:00
m.reply "Reloading info..."
reload_info
m.reply "Done."
2017-08-09 02:58:21 -07:00
end
private
2018-06-25 10:01:45 -07:00
def reload_info
@winfo = []
@minfo = []
2019-02-24 03:00:41 -08:00
@info[:wep_info].each {|wi| @winfo += JSON.parse(open(wi).read)}
@info[:mon_info].each {|mi| @minfo += JSON.parse(open(mi).read)}
2017-08-09 02:58:21 -07:00
end
2017-08-09 00:52:45 -07:00
end
## EOF