Skip to content

Commit

Permalink
Rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
rpherbig committed Oct 4, 2018
1 parent e55d168 commit c378cec
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 69 deletions.
10 changes: 4 additions & 6 deletions bootstrap.lic
Expand Up @@ -9,7 +9,6 @@ arg_definitions = [[{ name: 'wipe_constants', regex: /wipe_constants/i, optional

args = parse_args(arg_definitions, true)


def constant_defined?(symbol)
if $MODERN_LICH && $MODERN_RUBY
Object.constants.include?(symbol)
Expand All @@ -20,17 +19,16 @@ end

def remove_constant(symbol)
if $MODERN_LICH && $MODERN_RUBY
Object.send(:remove_const,symbol)
Object.send(:remove_const, symbol)
else
Scripting.send(:remove_const,symbol)
Scripting.send(:remove_const, symbol)
end
end


RUBY_VERSION =~ /^(\d+)\.(\d+)\./
$MODERN_RUBY = $1.to_i > 2 || ($1.to_i == 2 && $2.to_i > 2)
$MODERN_RUBY = Regexp.last_match(1).to_i > 2 || (Regexp.last_match(1).to_i == 2 && Regexp.last_match(2).to_i > 2)
LICH_VERSION =~ /^(\d+)\.(\d+)\./
$MODERN_LICH = $1.to_i > 4 || ($1.to_i == 4 && $2.to_i > 11)
$MODERN_LICH = Regexp.last_match(1).to_i > 4 || (Regexp.last_match(1).to_i == 4 && Regexp.last_match(2).to_i > 11)

if args.wipe_constants
class_defs.each_value { |symb| remove_constant(symb) if constant_defined?(symb) }
Expand Down
76 changes: 38 additions & 38 deletions combat-trainer.lic
Expand Up @@ -38,7 +38,7 @@ class SetupProcess
@last_warhorn = Time.now - 305

validate_regalia(settings)

return unless @warhorn

if DRCI.wearing?(@warhorn)
Expand Down Expand Up @@ -130,14 +130,14 @@ class SetupProcess
def regalia_hysteresis?(game_state)
return false unless @armor_hysteresis
# Override hysteresis logic if regalia is about to expire.
return false if @cycle_regalia.any? { |skill| DRSkill.getxp(skill) < 22 } || game_state.last_regalia_type.nil? || Flags['ct-regalia-expired']
if @cycle_regalia.all? { |skill| DRSkill.getxp(skill) > 24 } && game_state.last_regalia_type != @default_armor
return false if Time.now - @last_cycle_time < @cycle_armors_time
game_state.swap_regalia_type = @cycle_regalia.include?(@default_armor) ? @default_armor : @cycle_regalia.max_by { |skill| DRSkill.getrank(skill) } # If no default type declared, go by the highest rank.
return false if @cycle_regalia.any? { |skill| DRSkill.getxp(skill) < 22 } || game_state.last_regalia_type.nil? || Flags['ct-regalia-expired']
if @cycle_regalia.all? { |skill| DRSkill.getxp(skill) > 24 } && game_state.last_regalia_type != @default_armor
return false if Time.now - @last_cycle_time < @cycle_armors_time
game_state.swap_regalia_type = @cycle_regalia.include?(@default_armor) ? @default_armor : @cycle_regalia.max_by { |skill| DRSkill.getrank(skill) } # If no default type declared, go by the highest rank.
end
true
end

def check_armor_swap(game_state)
return if armor_hysteresis?
return if Time.now - @last_cycle_time < @cycle_armors_time
Expand All @@ -164,20 +164,20 @@ class SetupProcess

game_state.wield_whirlwind_offhand
end

def check_regalia_swap(game_state)
return if regalia_hysteresis?(game_state)
return if Time.now - @last_cycle_time < @cycle_armors_time && !Flags['ct-regalia-expired']
# if CT is done with regalia (usually starlight depleted) don't process anymore until it starts to expire naturally, then close it down.
if game_state.regalia_cancel
regalia_shutdown(game_state) if Flags['ct-regalia-expired']
if game_state.regalia_cancel
regalia_shutdown(game_state) if Flags['ct-regalia-expired']
return
end
armor_types = @cycle_regalia
next_armor_type = armor_types.min_by { |skill| [DRSkill.getxp(skill), DRSkill.getrank(skill)] }
return if next_armor_type == @last_worn_type unless Flags['ct-regalia-expired']
return if DRSkill.getxp(next_armor_type) >= @combat_training_abilities_target unless Flags['ct-regalia-expired'] || game_state.last_regalia_type.nil?
return unless Flags['ct-regalia-expired'] || next_armor_type != @last_worn_type
return unless Flags['ct-regalia-expired'] || game_state.last_regalia_type.nil? || DRSkill.getxp(next_armor_type) < @combat_training_abilities_target

@last_cycle_time = Time.now
game_state.swap_regalia_type = next_armor_type # Mark for SpellProcess casting in check_regalia
end
Expand Down Expand Up @@ -294,31 +294,31 @@ class SetupProcess
game_state.update_whirlwind_weapon_info(offhand_skill)
game_state.wield_whirlwind_offhand
end

def validate_regalia(settings)
return unless @cycle_regalia
if @cycle_armors
echo "ERROR - Regalia cycling and armorswap cycling at the same time not currently supported! Removing Regalia from combat-training!"
echo 'ERROR - Regalia cycling and armorswap cycling at the same time not currently supported! Removing Regalia from combat-training!'
@cycle_regalia = nil
end
if (settings.gear_sets['regalia'].empty? || settings.gear_sets['regalia'].nil?)

if settings.gear_sets['regalia'].empty? || settings.gear_sets['regalia'].nil?
echo "ERROR - Regalia cycling requires a gear_set named 'regalia' that will be worn immediately before casting. Removing Regalia from combat-training!"
@cycle_regalia = nil
end
# reset swap clock if you start CT already wearing a regalia.
@last_cycle_time = Time.now unless DRCA.parse_regalia.empty?
end
def regalia_shutdown(game_state)

def regalia_shutdown(game_state)
DRCA.shatter_regalia?
game_state.last_regalia_type = nil
game_state.swap_regalia_type = nil
game_state.regalia_cancel = nil
@cycle_regalia = nil
Flags.reset('ct-regalia-expired')
@equipment_manager.wear_equipment_set?('standard')
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if (@gearsets['standard'].include?(game_state.weapon_name)) # The above will put away worn weapons
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if @gearsets['standard'].include?(game_state.weapon_name) # The above will put away worn weapons
end
end

Expand Down Expand Up @@ -992,7 +992,7 @@ class SpellProcess

@regalia_spell = settings.waggle_sets['regalia']['Regalia']
echo(" @regalia_spell: #{@regalia_spell}") if $debug_mode_ct

@perc_health_timer = Time.now

@symbiosis_learning_threshold = settings.symbiosis_learning_threshold
Expand Down Expand Up @@ -1023,11 +1023,11 @@ class SpellProcess
@tk_spell = @offensive_spells.find { |spell| spell['abbrev'] =~ /tkt|tks/i }
drop_tkt_ammo
Flags.add('need-tkt-ammo', 'There is nothing here that can be thrown')
if DRStats.trader? && @regalia_array
@regalia_spell = get_data('spells').spell_data['Regalia'] if (@regalia_array && @regalia_spell.nil?) # get data from the regalia waggle or base-spells
bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") unless checkprep == 'None' # prepare to check for bespoke regalia
@know_bespoke = DRC.bput('pre bspk', 'Bespoke Regalia', 'You have no idea', 'fully prepared', 'already preparing') == 'Bespoke Regalia' # check for bespoke regalia
end

return unless DRStats.trader? && @regalia_array
@regalia_spell = get_data('spells').spell_data['Regalia'] if @regalia_array && @regalia_spell.nil? # get data from the regalia waggle or base-spells
bput('release spell', 'You let your concentration lapse', "You aren't preparing a spell") unless checkprep == 'None' # prepare to check for bespoke regalia
@know_bespoke = DRC.bput('pre bspk', 'Bespoke Regalia', 'You have no idea', 'fully prepared', 'already preparing') == 'Bespoke Regalia' # check for bespoke regalia
end

def drop_tkt_ammo
Expand Down Expand Up @@ -1140,7 +1140,7 @@ class SpellProcess
return if game_state.casting
return if game_state.loaded
return if mana < @buff_spell_mana_threshold

case game_state.swap_regalia_type
when 'Light Armor'
armor_word = 'light'
Expand All @@ -1151,11 +1151,11 @@ class SpellProcess
when 'Plate Armor'
armor_word = 'plate'
end
@regalia_spell['cast'] = @know_bespoke ? "cast #{armor_word} all" : "cast"

@regalia_spell['cast'] = @know_bespoke ? "cast #{armor_word} all" : 'cast'
prepare_spell(@regalia_spell, game_state)
end

def check_bless(game_state)
return if game_state.casting
return unless @buff_spells['Bless']
Expand Down Expand Up @@ -1241,12 +1241,12 @@ class SpellProcess
if result.empty? # if not wearing a regalia, retreat, swap to regalia gearset, then cast
DRCT.retreat
@equipment_manager.wear_equipment_set?('regalia')
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if (@settings.gear_sets['regalia'].include?(game_state.weapon_name))
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if @settings.gear_sets['regalia'].include?(game_state.weapon_name)
else # otherwise break what you're already wearing then cast.
DRCA.shatter_regalia?(result)
end
end

snapshot = DRSkill.getxp(@skill)
success = cast?(@custom_cast, @symbiosis, @before, @after)
if @symbiosis && @use_auto_mana
Expand Down Expand Up @@ -1404,16 +1404,16 @@ class SpellProcess
def check_trader_magic(game_state) # handles starlight-related effects and cleans flags
return unless DRStats.trader?
if Flags['ct-starlight-depleted']
echo "----OUT OF STARLIGHT - DELETING STARLIGHT MAGIC----"
echo '----OUT OF STARLIGHT - DELETING STARLIGHT MAGIC----'
@buff_spells.reject! { |spell| @buff_spells[spell]['starlight_threshold'] > -1 } # delete all buffs and offensive spells. Potential to add stellar collector support later
@offensive_spells.reject! { |spell| spell['starlight_threshold'] > -1 }
game_state.regalia_cancel = true # stop all regalia swap functions and clean it up next time it expires.
end
if game_state.casting_regalia
if Flags['ct-starlight-depleted'] # In some conditions, regalia can run out of starlight partway through creation. Don't want a partial regalia on.
if Flags['ct-starlight-depleted'] # In some conditions, regalia can run out of starlight partway through creation. Don't want a partial regalia on.
DRCA.shatter_regalia?
@equipment_manager.wear_equipment_set?('standard')
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if (@settings.gear_sets['standard'].include?(game_state.weapon_name))
@equipment_manager.wield_weapon(game_state.weapon_name, game_state.weapon_skill) if @settings.gear_sets['standard'].include?(game_state.weapon_name)
game_state.last_regalia_type = nil
game_state.swap_regalia_type = nil
end
Expand All @@ -1427,7 +1427,7 @@ class SpellProcess
end
Flags.reset('ct-starlight-depleted')
end

def check_cfb(game_state)
return unless DRStats.necromancer?
return unless @necromancer_zombie['Call from Beyond']
Expand Down Expand Up @@ -1566,9 +1566,9 @@ class SpellProcess
data['cast'] = "cast #{moon}"
end
end

game_state.casting_regalia = data['abbrev'].casecmp('REGAL').zero?

prepare?(data['abbrev'], data['mana'], data['symbiosis'], command)
game_state.casting = true
game_state.cambrinth_charges(data['cambrinth'])
Expand Down Expand Up @@ -2678,7 +2678,7 @@ class CombatTrainer
@equipment_manager = EquipmentManager.new(settings)
setup(settings)
settings.storage_containers.each { |container| fput("open my #{container}") }
@equipment_manager.wear_equipment_set?('standard') if (settings.cycle_armors_regalia.nil? || DRCA.parse_regalia.empty?)
@equipment_manager.wear_equipment_set?('standard') if settings.cycle_armors_regalia.nil? || DRCA.parse_regalia.empty?
end

def set_dance(message, settings)
Expand Down
22 changes: 11 additions & 11 deletions common-arcana.lic
Expand Up @@ -234,33 +234,33 @@ module DRCA
.map { |_name, properties| properties['abbrev'] }
.each { |abbrev| fput("release #{abbrev}") }
end
def parse_regalia # generates an array of currently-worn regalia armor nouns

def parse_regalia # generates an array of currently-worn regalia armor nouns
return unless DRStats.trader?
DRC.bput('inv armor', 'Type INVENTORY HELP for more options')
snapshot = reget(40)
if snapshot.grep(/All of your armor|You aren't wearing anything like that/).any? && snapshot.grep(/Type INVENTORY HELP/).any?
result = snapshot
snapshot
.map(&:strip)
.reverse
.take_while { |item| !['All of your armor:', "You aren't wearing anything like that."].include?(item) }
.drop_while { |item| item != '[Type INVENTORY HELP for more options]' }
.drop(1)
.select { |item| item.include?('rough-cut crystal') || item.include?('faceted crystal') || item.include?('resplendent crystal')}
.map { |item| DRC.get_noun(item)}
.select { |item| item.include?('rough-cut crystal') || item.include?('faceted crystal') || item.include?('resplendent crystal') }
.map { |item| DRC.get_noun(item) }
else
parse_regalia
end
end

def shatter_regalia?(worn_regalia = nil) # takes an array of armor nouns to remove or gets its own from parse_regalia
return false unless DRStats.trader?
worn_regalia = parse_regalia unless worn_regalia
return false unless DRStats.trader?
worn_regalia ||= parse_regalia
return false if worn_regalia.empty?
worn_regalia.each do |item|
DRC.bput("remove my #{item}", "into motes of silvery", "Remove what?", "You .*#{item}")
worn_regalia.each do |item|
DRC.bput("remove my #{item}", 'into motes of silvery', 'Remove what?', "You .*#{item}")
end
return true
true
end

def parse_mana_message(mana_msg)
Expand Down
4 changes: 2 additions & 2 deletions sanowret-crystal.lic
Expand Up @@ -16,7 +16,7 @@ class SanowretCrystal
args = parse_args(arg_definitions)
@no_use_scripts = get_settings.sanowret_no_use_scripts
check_crystal if args.run && !hiding? && !invisible?
passive unless args.run
passive unless args.run
end

def use_crystal
Expand All @@ -38,7 +38,7 @@ class SanowretCrystal
return if DRStats.concentration < 100
return if DRSkill.getxp('Arcana') >= 25
return if hiding? || invisible?
return if @no_use_scripts.any?{|name| Script.running?(name) }
return if @no_use_scripts.any? { |name| Script.running?(name) }
return if @invalid_rooms.include?(Room.current.id)

if @worn_crystal
Expand Down
6 changes: 3 additions & 3 deletions stack-scrolls.lic
Expand Up @@ -48,16 +48,16 @@ class ScrollStack
search_container(args.container, scroll_nouns)
end

def display_scrolls(scroll_stackers, mana_type = "")
def display_scrolls(scroll_stackers, mana_type = '')
unless UserVars.stackers
stow_hands
populate_stackers(scroll_stackers)
end
normalized_data = normalize_stacker_data

unless mana_type == ""
unless mana_type == ''
spells = get_data('spells').spell_data
normalized_data.select! { |data| spells[data.first]['mana_type'] == mana_type}
normalized_data.select! { |data| spells[data.first]['mana_type'] == mana_type }
end

normalized_data.each do |data|
Expand Down
18 changes: 9 additions & 9 deletions validate.lic
Expand Up @@ -646,38 +646,38 @@ class DRYamlValidator
def assert_that_regalia_waggle_is_defined(settings)
return unless settings.cycle_armors_regalia
return if settings.waggle_sets['regalia']['Regalia']

warn("No Regalia waggle defined. Combat-trainer will use min prep unless you declare a waggle named 'regalia' with different values")
end

def assert_that_regalia_waggle_has_abbrev(settings)
return unless settings.cycle_armors_regalia
return if settings.waggle_sets['regalia']['Regalia']['abbrev'].casecmp('REGAL').zero?

error("Regalia waggle's abbreviation differs from default. Change to abbrev: REGAL")
end

def assert_that_regalia_gearset_is_defined(settings)
return unless settings.cycle_armors_regalia
return unless settings.gear_sets['regalia'].empty? || settings.gear_sets['regalia'].nil?

error("Regalia cycling requires a gear_set named 'regalia' that is missing any armor you wish Regalia to replace.")
end

def assert_that_regalia_does_not_conflict_with_armor_swap(settings)
return unless settings.cycle_armors && settings.cycle_armors_regalia

error('cycle_armors and cycle_armors_regalia at the same time not currently supported! Combat-trainer will default to cycle_armors only!')
end

def assert_that_cycle_regalia_are_skills(settings)
return unless settings.cycle_armors_regalia

settings.cycle_armors_regalia
.reject { |skill| ['Light Armor', 'Chain Armor', 'Brigandine', 'Plate Armor'].include?(skill) }
.any? { |skill| error("Skill name in cycle_armors_regalia is not valid: #{skill}") }
end

private

def warn(message)
Expand Down

0 comments on commit c378cec

Please sign in to comment.