Make DoomRLA info only parse once per program instance

master
Marrub 2017-08-15 16:49:09 -04:00
parent 9bb1c4dad9
commit 97c0e107ce
1 changed files with 11 additions and 6 deletions

View File

@ -14,6 +14,9 @@ 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
@ -24,11 +27,11 @@ class Mod_DoomRLA < Vrobot4::Module::Module
register :c_monsterinfo, "monsterinfo", "Prints DRLA monster info."
register :c_reloadinfo, "reloadinfo", "", roles: "h"
reload_info
reload_info false
end
def c_weaponinfo m, argv
w = @winfo.select {|wep| wep if wep["Name"].casecmp? argv}[0]
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
@ -80,13 +83,15 @@ class Mod_DoomRLA < Vrobot4::Module::Module
end
def c_reloadinfo m, argv
reload_info
reload_info true
end
private
def reload_info
@winfo = JSON.parse(open(@info["wep_info"]).read)
@minfo = JSON.parse(open(@info["mon_info"]).read)
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