Advertisement
jbrocky

magic-training.lic

Jun 23rd, 2019
807
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 3.44 KB | None | 0 0
  1. =begin
  2.   Version:
  3.     Chuno, v1.0 - 6/23/19
  4.  
  5.   Dragonrealms Magic Training Script
  6.   This is mainly useful for befores and afters. It doesn't use combat_spell_training:
  7.     Reason: Sometimes you want different spells apart from those and it supports straight sorcery
  8.     Requirements:
  9.       Dependency: https://elanthipedia.play.net/Dependency
  10.       You can remove or add any of the magics listed below and it will adjust.
  11.       YAML Setup with a "magic_training" section:
  12.         Example:
  13.           magic_training
  14.             Augmentation:
  15.               abbrev: sap
  16.               symbiosis: true
  17.               cast: cast debil
  18.               mana: 25
  19.               cambrinth:
  20.               - 25
  21.             Warding:
  22.               abbrev: maf
  23.               symbiosis: true
  24.               mana: 25
  25.               cambrinth:
  26.               - 25
  27.             Utility:
  28.               abbrev: bless
  29.               symbiosis: true
  30.               mana: 25
  31.               cambrinth:
  32.               - 25
  33.             Sorcery:
  34.               abbrev: pg
  35.               symbiosis: false
  36.               mana: 15
  37.               cambrinth:
  38.               - 15
  39.  
  40.   Note:
  41.     You can change and save settings on the fly, and the trainer
  42.     will get the new mana levels/spell on the next time through.
  43.     * This is very useful for finding max training limits for spells
  44. =end
  45.  
  46. custom_require.call(%w[common common-arcana])
  47.  
  48. class MagicTraining
  49.   include DRC
  50.   include DRCA
  51.  
  52.   def initialize
  53.     settings = get_settings
  54.  
  55.     #Change these values to whatever you want in your yaml, or use these defaults
  56.     #stops training if mana falls below threshold and waits for more mana
  57.     mana_threshold = settings.training_spell_mana_threshold || 40 #percentage
  58.     #stops training specfic skill after threshold, and quits program when all are above
  59.     exp_threshold = settings.combat_spell_training_max_threshold || 20
  60.  
  61.     loop do
  62.       if mana > mana_threshold
  63.         return unless train_magics(mana_threshold, exp_threshold)
  64.       else
  65.         echo "Waiting for mana..."
  66.         pause 10
  67.       end
  68.     end
  69.   end
  70.  
  71.   def train_magics(mana_threshold, exp_threshold)
  72.     settings = get_settings # This is redone purposely so you can adjust this on the fly, it's great for finding mana values
  73.     magics = settings.magic_training
  74.     skills_to_train = magics.keys
  75.                             .select { |skill| %w[Utility Warding Augmentation Sorcery].include? skill }
  76.                             .reject { |skill| DRSkill.getxp(skill) > exp_threshold }
  77.  
  78.     return false if skills_to_train.empty?
  79.  
  80.     skills_to_train.sort_by { |skill| DRSkill.getxp(skill) }
  81.                    .each    { |skill|
  82.                               # Get settings here so I can update on the fly
  83.                               echo "Training: #{skill}"
  84.                               spell_data = magics[skill]
  85.                               before_xp = DRSkill.getxp(skill)
  86.                               if mana < mana_threshold
  87.                                 echo "Waiting on mana..."  
  88.                                 pause 2 until mana > mana_threshold
  89.                               end
  90.                               cast_spell(spell_data, settings, true)
  91.                               echo "#{skill} gains: #{DRSkill.getxp(skill) - before_xp}"
  92.                             }
  93.     true
  94.   end
  95. end
  96.  
  97. before_dying do
  98.   fput('release spell')
  99.   fput('release sym')
  100. end
  101.  
  102. MagicTraining.new
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement