Module: Lich::Gemstone::Infomon::Parser

Defined in:
documented/gemstone/infomon/parser.rb

Overview

this module handles all of the logic for parsing game lines that infomon depends on

Defined Under Namespace

Modules: Pattern, State

Class Method Summary collapse

Class Method Details

.find_cat(category) ⇒ String?

Maps a full PSM category name to its short database key.

Converts the verbose category names from game server output (e.g., "Armor Specializations") to the short form stored in infomon.db (e.g., "Armor"). Used during PSM learning/unlearning to normalize the category before database lookup.

Examples:

Parser.find_cat("Armor Specializations") #=> "Armor"
Parser.find_cat("Combat Maneuvers") #=> "CMan"

Parameters:

  • category (String)

    the full category name (e.g., "Combat Maneuvers", "Weapon Techniques")

Returns:

  • (String, nil)

    the short form ("Armor", "Ascension", "CMan", "Feat", "Shield", "Weapon"), or nil if the category is not recognized

See Also:



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'documented/gemstone/infomon/parser.rb', line 292

def self.find_cat(category)
  case category
  when /Armor/
    'Armor'
  when /Ascension/
    'Ascension'
  when /Combat/
    'CMan'
  when /Feat/
    'Feat'
  when /Shield/
    'Shield'
  when /Weapon/
    'Weapon'
  end
end

.parse(line) ⇒ Symbol

Note:

Callers should not rely on the return value to determine action; handlers trigger side effects (database writes, state transitions) directly

Parses a single game server output line and updates infomon database state accordingly.

This is the main entry point for the infomon parser. It employs a fast-path guard (Pattern::AllStart) to check only line-start patterns on non-matching lines, then uses a case statement to dispatch the line to specific handlers. Each handler extracts values via regex captures and calls Infomon.set or Infomon.upsert_batch to update the database.

For multi-line commands (SKILL GOALS, PROFILE, INVENTORY ENHANCIVE TOTALS), the parser manages state transitions via Parser.State. Batch operations (stats, experience, skills) use mutex locks to synchronize with the database.

Mid-line patterns (e.g., CutthroatActiveMid) are also checked to catch status conditions that may not be anchored to the start of the line.

Examples:

line = "Gender: Male  Age: 42  Expr: 1,234,567  Level: 28"
Parser.parse(line) #=> :ok
# infomon database now contains updated experience value

Parameters:

  • line (String)

    a single physical line from the game server output, typically stripped of trailing whitespace and already split from the \r\n-delimited server stream

Returns:

  • (Symbol)

    :ok if the line matched and was processed, :noop if the line did not match or processing was skipped (e.g., mutex not held), or in rare error cases after logging

Raises:

  • (StandardError)

    lines that raise exceptions are caught, logged with line content, and converted to :noop to prevent parser crashes

See Also:



339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'documented/gemstone/infomon/parser.rb', line 339

def self.parse(line)
  # O(1) vs O(N): the anchored union is attempted only at line start; mid-line
  # patterns (AllMid) are checked separately.
  #
  # No multi-line fallback is needed here (unlike infomon/xmlparser.rb, which
  # is handed the raw, possibly multi-line server_string). Parser.parse is fed
  # one physical line at a time -- Game.process_xml_data does
  # stripped_server.split("\r\n").each { |l| Infomon::Parser.parse(l) } -- and
  # the server stream is \r\n-aligned, so +line+ never carries an interior
  # newline whose 2nd+ line an inner ^ anchor would need to match.
  return :noop unless Pattern::AllStart.match?(line) || Pattern::AllMid.match?(line)

  begin
    case line
    # blob saves
    when Pattern::CharRaceProf
      # name captured here, but do not rely on it - use XML instead
      @stat_hold = []
      Infomon.mutex_lock
      match = Regexp.last_match
      @stat_hold.push(['stat.race', match[:race].to_s],
                      ['stat.profession', match[:profession].to_s]) unless Effects::Spells.active?(1212)
      :ok
    when Pattern::CharGenderAgeExpLevel
      # level captured here, but do not rely on it - use XML instead
      match = Regexp.last_match
      @stat_hold.push(['stat.gender', match[:gender].to_s],
                      ['stat.age', match[:age].delete(',').to_i]) unless Effects::Spells.active?(1212)
      @stat_hold.push(['stat.experience', match[:experience].delete(',').to_i])
      :ok
    when Pattern::Stat
      match = Regexp.last_match
      @stat_hold.push(['stat.%s' % match[:stat], match[:value].to_i],
                      ['stat.%s_bonus' % match[:stat], match[:bonus].to_i],
                      ['stat.%s.enhanced' % match[:stat], match[:enhanced_value].to_i],
                      ['stat.%s.enhanced_bonus' % match[:stat], match[:enhanced_bonus].to_i])
      # Store base stats if present (from 'info full' command)
      if match[:base_value]
        @stat_hold.push(['stat.%s.base' % match[:stat], match[:base_value].to_i],
                        ['stat.%s.base_bonus' % match[:stat], match[:base_bonus].to_i])
      end
      :ok
    when Pattern::StatEnd
      match = Regexp.last_match
      @stat_hold.push(['currency.silver', match[:silver].delete(',').to_i])
      Infomon.upsert_batch(@stat_hold)
      Infomon.mutex_unlock
      :ok
    when Pattern::Fame # serves as ExprStart
      @expr_hold = []
      Infomon.mutex_lock
      match = Regexp.last_match
      @expr_hold.push(['experience.fame', match[:fame].delete(',').to_i])
      :ok
    when Pattern::RealExp
      match = Regexp.last_match
      @expr_hold.push(['experience.field_experience_current', match[:fxp_current].delete(',').to_i],
                      ['experience.field_experience_max', match[:fxp_max].delete(',').to_i])
      :ok
    when Pattern::AscExp
      match = Regexp.last_match
      @expr_hold.push(['experience.ascension_experience', match[:ascension_experience].delete(',').to_i])
      :ok
    when Pattern::TotalExp
      match = Regexp.last_match
      @expr_hold.push(['experience.total_experience', match[:total_experience].delete(',').to_i])
      @expr_hold.push(['experience.deaths_sting', match[:deaths_sting]])
      :ok
    when Pattern::LTE
      match = Regexp.last_match
      @expr_hold.push(['experience.long_term_experience', match[:long_term_experience].delete(',').to_i],
                      ['experience.deeds', match[:deeds].to_i])
      :ok
    when Pattern::ExprEnd
      Infomon.upsert_batch(@expr_hold)
      Infomon.mutex_unlock
      :ok
    when Pattern::SkillStart
      @skills_hold = []
      Infomon.mutex_lock
      :ok
    when Pattern::Skill
      if Infomon.mutex.owned?
        match = Regexp.last_match
        @skills_hold.push(['skill.%s' % match[:name].downcase, match[:ranks].to_i],
                          ['skill.%s_bonus' % match[:name], match[:bonus].to_i])
        :ok
      else
        :noop
      end
    when Pattern::SpellRanks
      if Infomon.mutex.owned?
        match = Regexp.last_match
        @skills_hold.push(['spell.%s' % match[:name].downcase, match[:rank].to_i])
        :ok
      else
        :noop
      end
    when Pattern::SkillEnd
      if Infomon.mutex.owned?
        Infomon.upsert_batch(@skills_hold)
        Infomon.mutex_unlock
        :ok
      else
        :noop
      end
    when Pattern::GoalsDetected
      State.set(State::Goals)
      :ok
    when Pattern::GoalsEnded
      if State.get.eql?(State::Goals)
        State.set(State::Ready)
        respond
        _respond Lich::Messaging.monsterbold('You just trained your character.  Lich will gather your updated skills.')
        respond
        # temporary inform for users about command
        # fixme: update ExecCommand to consistently perform local API actions from lib files
        respond "[infomon_sync]#{$SEND_CHARACTER}skills"
        Game._puts("#{$cmd_prefix}skills")
        :ok
      else
        :noop
      end
    when Pattern::InnCheckedOut
      respond
      _respond Lich::Messaging.monsterbold('You just left an Inn.  Lich will gather your updated Stats and skills.')
      respond
      respond "[infomon_sync]#{$SEND_CHARACTER}skills"
      Game._puts("#{$cmd_prefix}skills")
      respond "[infomon_sync]#{$SEND_CHARACTER}info"
      Game._puts("#{$cmd_prefix}info")
      :ok
    when Pattern::PSMStart
      match = Regexp.last_match
      @psm_hold = []
      @psm_cat = find_cat(match[:cat])
      Infomon.mutex_lock
      :ok
    when Pattern::PSM
      match = Regexp.last_match
      @psm_hold.push(["#{@psm_cat.downcase}.%s" % match[:command], match[:ranks].to_i])
      :ok
    when Pattern::PSMEnd
      Infomon.upsert_batch(@psm_hold)
      Infomon.mutex_unlock
      :ok
    when Pattern::NoWarcries
      Infomon.upsert_batch([['warcry.bertrandts_bellow', 0],
                            ['warcry.yerties_yowlp', 0],
                            ['warcry.gerrelles_growl', 0],
                            ['warcry.seanettes_shout', 0],
                            ['warcry.carns_cry', 0],
                            ['warcry.horlands_holler', 0]])
      :ok
    # end of blob saves
    when Pattern::Warcries
      match = Regexp.last_match
      Infomon.set('warcry.%s' % match[:name].split(' ')[1], 1)
      :ok
    when Pattern::Levelup
      match = Regexp.last_match
      Infomon.upsert_batch([['stat.%s' % match[:stat], match[:value].to_i],
                            ['stat.%s_bonus' % match[:stat], match[:bonus].to_i]])
      :ok
    when Pattern::SpellsSolo
      match = Regexp.last_match
      Infomon.set('spell.%s' % match[:name].downcase, match[:rank].to_i)
      :ok
    when Pattern::Citizenship
      Infomon.set('citizenship', Regexp.last_match[:town].to_s)
      :ok
    when Pattern::NoCitizenship
      Infomon.set('citizenship', 'None')
      :ok
    when Pattern::Society
      match = Regexp.last_match
      Infomon.set('society.status', match[:society].to_s)
      Infomon.set('society.rank', match[:rank].to_i)
      case match[:standing] # if Master in society the rank match is nil
      when 'Master'
        if /Voln/.match?(match[:society])
          Infomon.set('society.rank', 26)
        elsif /Council of Light|Guardians of Sunfist/.match?(match[:society])
          Infomon.set('society.rank', 20)
        end
      end
      :ok
    when Pattern::NoSociety
      Infomon.set('society.status', 'None')
      Infomon.set('society.rank', 0)
      :ok
    when Pattern::SocietyJoin
      match = Regexp.last_match.to_s
      case match[/Order|Council|Guardians/]
      when 'Order'
        Infomon.set('society.status', 'Order of Voln')
        Infomon.set('society.rank', 1)
      when 'Guardians'
        Infomon.set('society.status', "Guardians of Sunfist")
        Infomon.set('society.rank', 0)
      when 'Lodge'
        Infomon.set('society.status', 'Council of Light')
        Infomon.set('society.rank', 1)
      end
      :ok
    when Pattern::SocietyStep
      Infomon.set('society.rank', Infomon.get('society.rank') + 1)
      :ok
    when Pattern::SocietyResign
      Infomon.set('society.status', 'None')
      Infomon.set('society.rank', 0)
      :ok
    when Pattern::LearnPSM, Pattern::LearnTechnique
      match = Regexp.last_match
      @psm_cat = find_cat(match[:cat])
      seek_name = PSMS.name_normal(match[:psm])
      db_name = PSMS.find_name(seek_name, @psm_cat)
      Infomon.set("#{@psm_cat.downcase}.#{db_name[:short_name]}", match[:rank].to_i)
      :ok
    when Pattern::UnlearnPSM, Pattern::UnlearnTechnique
      match = Regexp.last_match
      @psm_cat = find_cat(match[:cat])
      seek_name = PSMS.name_normal(match[:psm])
      no_decrement = (match.string =~ /have decreased to/)
      db_name = PSMS.find_name(seek_name, @psm_cat)
      Infomon.set("#{@psm_cat.downcase}.#{db_name[:short_name]}", (no_decrement ? match[:rank].to_i : match[:rank].to_i - 1))
      :ok
    when Pattern::LostTechnique
      match = Regexp.last_match
      @psm_cat = find_cat(match[:cat])
      seek_name = PSMS.name_normal(match[:psm])
      db_name = PSMS.find_name(seek_name, @psm_cat)
      Infomon.set("#{@psm_cat.downcase}.#{db_name[:short_name]}", 0)
      :ok
    when Pattern::Resource
      match = Regexp.last_match
      Infomon.set('resources.weekly', match[:weekly].delete(',').to_i)
      Infomon.set('resources.total', match[:total].delete(',').to_i)
      :ok
    when Pattern::Suffused
      match = Regexp.last_match
      Infomon.set('resources.type', match[:type].to_s)
      Infomon.set('resources.suffused', match[:suffused].delete(',').to_i)
      :ok
    when Pattern::VolnFavor
      match = Regexp.last_match
      Infomon.set('resources.voln_favor', match[:favor].delete(',').to_i)
      :ok
    when Pattern::CovertArtsCharges
      match = Regexp.last_match
      Infomon.set('resources.covert_arts_charges', match[:charges].delete(',').to_i)
      :ok
    when Pattern::ShadowEssence
      match = Regexp.last_match
      Infomon.set('resources.shadow_essence', match[:essence].to_i.clamp(0, 5))
      :ok
    when Pattern::ShadowEssenceGain
      Infomon.set('resources.shadow_essence', (Lich::Resources.shadow_essence.to_i + 1).clamp(0, 5))
      :ok
    when Pattern::ShadowEssenceCap
      Infomon.set('resources.shadow_essence', 5)
      :ok
    when Pattern::SacrificeMana
      match = Regexp.last_match
      # Calculate effective mana control ranks
      effective_mana_ranks = [Skills.elemental_mana_control, Skills.spirit_mana_control].max + [Skills.elemental_mana_control, Skills.spirit_mana_control].min / 2

      # Base mana for first essence
      base_mana = Char.level + 20

      # Mana per essence after
      mana_per_essence = (base_mana * (0.5 + effective_mana_ranks.clamp(0, 60) / 120))

      # Estimate of essences used
      essences_used = (((match[:amount].to_i - mana_per_essence) / (base_mana * 0.5))).round.clamp(1, 5)
      Infomon.set('resources.shadow_essence', (Lich::Resources.shadow_essence.to_i - essences_used).clamp(0, 5))
      :ok
    when Pattern::SacrificeChannel, Pattern::SacrificeInfest, Pattern::SacrificeFate, Pattern::SacrificeShift
      Infomon.set('resources.shadow_essence', (Lich::Resources.shadow_essence.to_i - 1).clamp(0, 5))
      :ok
    when Pattern::GigasArtifactFragments
      match = Regexp.last_match
      Infomon.set('currency.gigas_artifact_fragments', match[:gigas_artifact_fragments].delete(',').to_i)
      :ok
    when Pattern::RedsteelMarks
      match = Regexp.last_match
      Infomon.set('currency.redsteel_marks', match[:redsteel_marks].delete(',').to_i)
      :ok
    when Pattern::GemstoneDust
      match = Regexp.last_match
      Infomon.set('currency.gemstone_dust', match[:gemstone_dust].delete(',').to_i)
      :ok
    when Pattern::TicketGeneral
      match = Regexp.last_match
      Infomon.set('currency.tickets', match[:tickets].delete(',').to_i)
      :ok
    when Pattern::TicketBlackscrip
      match = Regexp.last_match
      Infomon.set('currency.blackscrip', match[:blackscrip].delete(',').to_i)
      :ok
    when Pattern::TicketBloodscrip
      match = Regexp.last_match
      Infomon.set('currency.bloodscrip', match[:bloodscrip].delete(',').to_i)
      :ok
    when Pattern::TicketEtherealScrip
      match = Regexp.last_match
      Infomon.set('currency.ethereal_scrip', match[:ethereal_scrip].delete(',').to_i)
      :ok
    when Pattern::TicketSoulShards
      match = Regexp.last_match
      Infomon.set('currency.soul_shards', match[:soul_shards].delete(',').to_i)
      :ok
    when Pattern::TicketGold
      match = Regexp.last_match
      Infomon.set('currency.gold', match[:gold].delete(',').to_i)
      :ok
    when Pattern::TicketRaikhen
      match = Regexp.last_match
      Infomon.set('currency.raikhen', match[:raikhen].delete(',').to_i)
      :ok
    when Pattern::TicketAevit
      match = Regexp.last_match
      Infomon.set('currency.aevit', match[:aevit].delete(',').to_i)
      :ok
    when Pattern::WealthSilver
      match = Regexp.last_match
      case match[:silver]
      when 'no'
        Infomon.set('currency.silver', 0)
      when 'but one'
        Infomon.set('currency.silver', 1)
      else
        Infomon.set('currency.silver', match[:silver].delete(',').to_i)
      end
      :ok
    when Pattern::WealthSilverContainer
      match = Regexp.last_match
      Infomon.set('currency.silver_container', match[:silver].delete(',').to_i)
      :ok
    when Pattern::AccountName
      if Lich::Common::Account.name.nil?
        match = Regexp.last_match
        Lich::Common::Account.name = match[:name].upcase
        :ok
      else
        :noop
      end
    when Pattern::AccountSubscription
      match = Regexp.last_match
      Lich::Common::Account.subscription = match[:subscription].gsub('Standard', 'Normal').gsub('F2P', 'Free').gsub('Platinum', 'Premium').upcase
      Infomon.set('account.type', match[:subscription].gsub('Standard', 'Normal').gsub('F2P', 'Free').upcase)
      :ok
    when Pattern::ProfileStart
      State.set(State::Profile)
      :ok
    when Pattern::ProfileName
      match = Regexp.last_match
      if State.get.eql?(State::Profile) && !match[:name].split(' ').include?(Char.name)
        State.set(State::Ready)
        :ok
      else
        :noop
      end
    when Pattern::ProfileHouseCHE
      if State.get.eql?(State::Profile)
        match = Regexp.last_match
        Infomon.set('che', (match[:none] ? 'none' : Lich::Util.normalize_name(match[:house])))
        State.set(State::Ready)
        :ok
      else
        :noop
      end
    when Pattern::ResignCHE
      match = Regexp.last_match
      Infomon.set('che', (match[:none] ? 'none' : Lich::Util.normalize_name(match[:house])))
      :ok
    when Pattern::ResignConfirmCHE
      Infomon.set('che', 'none')
      :ok

    # TODO: refactor / streamline?
    when Pattern::ThornPoisonStart, Pattern::ThornPoisonProgression, Pattern::ThornPoisonDeprogression
      Infomon.set('status.thorned', true)
      :ok
    when Pattern::ThornPoisonEnd
      Infomon.set('status.thorned', false)
      :ok
    when Pattern::SleepActive
      Infomon.set('status.sleeping', true)
      :ok
    when Pattern::SleepNoActive
      Infomon.set('status.sleeping', false)
      :ok
    when Pattern::BindActive
      Infomon.set('status.bound', true)
      :ok
    when Pattern::BindNoActive
      Infomon.set('status.bound', false)
      :ok
    when Pattern::SilenceActive
      Infomon.set('status.silenced', true)
      :ok
    when Pattern::SilenceNoActive
      Infomon.set('status.silenced', false)
      :ok
    when Pattern::CalmActive
      Infomon.set('status.calmed', true)
      :ok
    when Pattern::CalmNoActive
      Infomon.set('status.calmed', false)
      :ok
    when Pattern::CutthroatActive
      Infomon.set('status.cutthroat', true)
      :ok
    when Pattern::CutthroatNoActive
      Infomon.set('status.cutthroat', false)
      :ok
    when Pattern::SpellUpMsgs
      spell = Spell.list.find do |s|
        line =~ /^#{s.msgup}$/
      end
      spell.putup unless spell.active?
      # add various cooldowns back without affecting parse speed
      Spells.require_cooldown(spell)
      :ok
    when Pattern::SpellDnMsgs
      spell = Spell.list.find do |s|
        line =~ /^#{s.msgdn}$/
      end
      spell.putdown if spell.active?
      :ok
    when Pattern::SpellsongRenewed
      Spellsong.renewed
      :ok
    # === ENHANCIVE PARSING ===
    # Any section header can start enhancive parsing (output may not include all sections)
    when Pattern::EnhanciveStart
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveStats)
      :ok
    when Pattern::EnhanciveStat
      if State.get == State::EnhanciveStats
        match = Regexp.last_match
        stat_key = Lich::Gemstone::Enhancive::STAT_ABBREV[match[:abbr]]
        @enhancive_hold.push(["enhancive.stat.#{stat_key}", match[:value].to_i]) if stat_key
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveSkillsSection
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveSkills)
      :ok
    when Pattern::EnhanciveSkillRanks
      if State.get == State::EnhanciveSkills
        match = Regexp.last_match
        skill_key = Lich::Gemstone::Enhancive::SKILL_NAME_MAP[match[:name].strip]
        @enhancive_hold.push(["enhancive.skill.#{skill_key}.ranks", match[:value].to_i]) if skill_key
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveSkillBonus
      if State.get == State::EnhanciveSkills
        match = Regexp.last_match
        skill_key = Lich::Gemstone::Enhancive::SKILL_NAME_MAP[match[:name].strip]
        @enhancive_hold.push(["enhancive.skill.#{skill_key}.bonus", match[:value].to_i]) if skill_key
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveResourcesSection
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveResources)
      :ok
    when Pattern::EnhanciveResource
      if State.get == State::EnhanciveResources
        match = Regexp.last_match
        resource_key = Lich::Gemstone::Enhancive::RESOURCE_NAME_MAP[match[:name].strip]
        @enhancive_hold.push(["enhancive.resource.#{resource_key}", match[:value].to_i]) if resource_key
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveMartialSection
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveMartial)
      :ok
    when Pattern::EnhanciveMartialSkill
      if State.get == State::EnhanciveMartial
        match = Regexp.last_match
        martial_key = Lich::Gemstone::Enhancive.martial_display_to_symbol(match[:name].strip)
        @enhancive_hold.push(["enhancive.martial.#{martial_key}", match[:value].to_i]) if martial_key
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveSpellsSection
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveSpells)
      :ok
    when Pattern::EnhanciveSpells
      if State.get == State::EnhanciveSpells
        match = Regexp.last_match
        spell_nums = match[:spells].split(',').map { |s| s.strip.to_i }
        @enhancive_hold.push(["enhancive.spells", spell_nums.join(',')])
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveStatisticsSection
      unless State.enhancive_state?
        @enhancive_hold = []
        Infomon.mutex_lock
        Lich::Gemstone::Enhancive.reset_all
      end
      State.set(State::EnhanciveStatistics)
      :ok
    when Pattern::EnhanciveStatistic
      if State.get == State::EnhanciveStatistics
        match = Regexp.last_match
        case match[:name]
        when 'Enhancive Items'
          @enhancive_hold.push(['enhancive.stats.item_count', match[:value].to_i])
        when 'Enhancive Properties'
          @enhancive_hold.push(['enhancive.stats.property_count', match[:value].to_i])
        when 'Total Enhancive Amount'
          @enhancive_hold.push(['enhancive.stats.total_amount', match[:value].to_i])
        end
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveEnd
      if State.enhancive_state?
        Infomon.upsert_batch(@enhancive_hold)
        Infomon.mutex_unlock
        State.set(State::Ready)
        :ok
      else
        :noop
      end
    when Pattern::EnhanciveNone
      # Player has no enhancives - reset all values to 0
      Lich::Gemstone::Enhancive.reset_all
      :ok
    when Pattern::EnhanciveOn
      Infomon.set('enhancive.active', true)
      :ok
    when Pattern::EnhanciveOff
      Infomon.set('enhancive.active', false)
      :ok
    when Pattern::EnhancivePauses
      match = Regexp.last_match
      Infomon.set('enhancive.pauses', match[:pauses].to_i)
      :ok
    else
      :noop
    end
  rescue StandardError
    respond "--- Lich: error: Infomon::Parser.parse: #{$!}"
    respond "--- Lich: error: line: #{line}"
    Lich.log "error: Infomon::Parser.parse: #{$!}\n\t#{$!.backtrace.join("\n\t")}"
    Lich.log "error: line: #{line}\n\t"
  end
end