vrobot4/source/modules/mod_doomrla.rb

109 lines
3.6 KiB
Ruby

require 'open-uri'
require 'json'
#--
# ===== WARNING =====
#
# !!! INCOMING SPAGHETTI !!!
#
# - BE PRAYING
# - BE PRAYING
# - BE PRAYING
#
class Mod_DoomRLA < Vrobot4::Module::Module
def self.type() "DoomRLA" end
Vrobot4::Module.add_module_type self, server: "Discord"
@@winfo = nil
@@minfo = nil
AType = ["Melee", "Ranged", "Special"].freeze
DType = ["Melee", "Bullet", "Fire", "Plasma",
"Piercing", "Holy", "Unholy", "Special"].freeze
def initialize info
super
register :c_assemblyinfo, "assemblyinfo", "Prints DRLA assembly info."
register :c_weaponinfo, "weaponinfo", "Prints DRLA weapon info."
register :c_monsterinfo, "monsterinfo", "Prints DRLA monster info."
register :c_reloadinfo, "reloadinfo", "", roles: "h"
reload_info false
end
def c_assemblyinfo m, argv
w = @@winfo.select do |wep|
wep if wep["Assembly"] and wep["AssemblyItem"].casecmp? argv
end
t = ""
w.each {|wep| t << wep["Assembly"] + " - " + wep["Name"] + "\n"}
m.chan.real.send_embed {|embed| embed.description = t} if t != ""
end
def c_weaponinfo m, argv
w = @@winfo.find {|wep| wep if wep["Name"].casecmp? argv}
raise ArgumentError, "Weapon not found" if w == nil
t = "%s %s damage\n" % [w["Damage"], w["DamageType"]]
t << "%s shots\n" % [w["Shots"]] if w["Shots"].to_i > 1
t << "Uses %s %s\n" % [w["AmmoUsage"], w["AmmoType"]] \
if w["AmmoType"] != "None"
t << "%s capacity\n" % [w["Capacity"]] if w["Capacity"]
t << "\n"
t << "%s explosion damage, %s radius\n" %
[w["ExplosionDamage"], w["ExplosionRadius"]] if w["ExplosionDamage"]
t << "Traits: %s\n" % [w["Traits"]] if w["Traits"] != "N/A"
t << "Assembly: %s with %s\n" % [w["Assembly"], w["AssemblyItem"]] \
if w["Assembly"]
t << "%s" % [w["Description"]] if w["Description"]
m.chan.real.send_embed do |embed|
embed.title = "[%s] %s" % [w["Rarity"], w["Name"]]
embed.description = t
end
end
def c_monsterinfo m, argv
mi = @@minfo.select do |mon|
mon if mon["Name"].casecmp? argv or
mon["Tags"].split(", ").include? argv
end
raise ArgumentError, "No monsters found" if mi == nil
mi.first(3).each do |w|
t = "%i Health\n" % [w["Health"]]
t << "Resistances: %s\n" % [w["Resistances"]]
t << "Drops: %s\n" % [w["ItemDrops"]] if w["ItemDrops"]
t << "%s" % [w["Description"]] if w["Description"]
t << "\n"
w["Attacks"].each do |a|
t << "\n[%s] %s\n" % [AType[a["AttackType"]], a["Name"]]
t << "%s %s damage\n" % [a["Damage"], DType[a["DamageType"]]]
t << "%s explosion damage, %s radius\n" %
[a["ExplosionDamage"], a["ExplosionRadius"]] \
if a["ExplosionDamage"]
t << "%s shots\n" % [a["Shots"]] if a["Shots"].to_i > 1
t << "%s\n" % a["Description"] if a["Description"]
end
m.chan.real.send_embed do |embed|
embed.title = "[%s] %s" % [w["Difficulty"], w["Name"]]
embed.title << " %s" % [w["Weapon"]] if w["Weapon"]
embed.image = Discordrb::Webhooks::EmbedImage.new \
url: w["Sprite"] if w["Sprite"]
embed.description = t
end
end
end
def c_reloadinfo m, argv
reload_info true
end
private
def reload_info force
if not @@winfo or not @@minfo or force
@@winfo = JSON.parse(open(@info["wep_info"]).read)
@@minfo = JSON.parse(open(@info["mon_info"]).read)
end
end
end
## EOF