module AR
  module Game

    #stands for Skull Medallion
    class SMWorld < World
      def initialize id=nil
        super 

        instantiate_game_objects do |world|
        
          #scenes 
          #(you start in forest01)
          forest01 = Forest01.new "forest01"
          forest02 = Forest02.new "forest02"
          forest03 = Forest03.new "forest03"
          forest04 = Forest04.new "forest04"
          forest05 = Forest05.new "forest05"

          hidden_forest01 = HiddenForest01.new "hidden_forest01"

          old_man_courtyard = OldManCourtyard.new "old_man_courtyard"
          old_man_house = OldManHouse.new "old_man_house"

          cave01 = Cave01.new "cave01"
          cave02 = Cave02.new "cave02"
          cave03 = Cave03.new "cave03"
          cave04 = Cave04.new "cave04"

          hidden_cave01 = HiddenCave01.new "hidden_cave01"
          hidden_cave02 = HiddenCave02.new "hidden_cave02"

          maze_forest01 = MazeForest.new "maze_forest01"
          maze_forest02 = MazeForest.new "maze_forest02"
          maze_forest03 = MazeForest.new "maze_forest03"
          maze_forest04 = MazeForest.new "maze_forest04"

          plains = Plains.new "plains"


          
          #gateways
          #forest gateways
          f01_pn = Forest01PathNorth.new "f01pn"
          f01_pn.destination = forest02
          f01_pw = Forest01PathWest.new "f01pw"
          f01_pw.destination = maze_forest01
          f01_hps = Forest01HiddenPathSouth.new "f01hps"
          f01_hps.discovery_threshold = 7
          f01_hps.destination = hidden_forest01 
          forest01.add_inhabitant f01_pn, "leading north"
          forest01.add_inhabitant f01_pw, "leading west"
          forest01.add_inhabitant f01_hps, "leading south"

          f02_pn = Forest02PathNorth.new "f02pn"
          f02_pn.destination = forest03
          f02_ps = Forest02PathSouth.new "f02ps"
          f02_ps.destination = forest01
          forest02.add_inhabitant f02_pn, "leading north"
          forest02.add_inhabitant f02_ps, "leading south"

          f03_pn = Forest03PathNorth.new "f03pn"
          f03_pn.destination = forest04
          f03_ps = Forest03PathSouth.new "f03ps"
          f03_ps.destination = forest02
          f03_ee = Forest03EntranceEast.new "f03ee"
          f03_ee.destination = cave01
          forest03.add_inhabitant f03_pn, "leading north"
          forest03.add_inhabitant f03_ps, "leading south"
          forest03.add_inhabitant f03_ee, "entering east"

          f04_ps = Forest04PathSouth.new "f04ps"
          f04_ps.destination = forest03
          f04_pe = Forest04PathEast.new "f04pe"
          f04_pe.destination = forest05
          forest04.add_inhabitant f04_pe, "leading east"
          forest04.add_inhabitant f04_ps, "leading south"


          f05_pw = Forest05PathWest.new "f05pw"
          f05_pw.destination = forest04
          f05_ge = Forest05GateToCourtyard.new "gate_to_courtyard"
          f05_ge.destination = old_man_courtyard

          forest05.add_inhabitant f05_ge, "leading into a courtyard"
          forest05.add_inhabitant f05_pw, "leading west"


          hf01_pn = HiddenForest01PathNorth.new "hf01_pn"
          hf01_pn.destination = forest01
          hidden_forest01.add_inhabitant hf01_pn, "leading north"



          #old man scenes
          omc_gtf = OldManCourtyardGateToForest.new "old_man_courtyard_gate_to_forest"
          omc_di = OldManCourtyardDoorInside.new "old_man_courtyard_door_inside"
          old_man_courtyard.add_inhabitant omc_gtf, "leading to the forest"
          old_man_courtyard.add_inhabitant omc_di, "leading into the old man's home"

          omc_gtf.destination = forest05
          omc_di.destination = old_man_house 

          omh_do = OldManHouseDoorOutside.new "old_man_house_door_outside"
          old_man_house.add_inhabitant omh_do, "door leading outside"
          omh_do.destination = old_man_courtyard

          #cavern gateways
          c01_ew = Cave01ExitWest.new "c01_ew"
          c01_pe = Cave01PassageEast.new "c01_pe"
          c01_ew.destination = forest03 
          c01_pe.destination = cave02 
          cave01.add_inhabitant c01_ew, "leading out of the caverns"
          cave01.add_inhabitant c01_pe, "leading deeper into the caverns"

          
          c02_pw = Cave02PassageWest.new "c02_ew"
          c02_pe = Cave02PassageEast.new "c02_pe"
          c02_hps = Cave02HiddenPassageSouth.new "c02_hps"
          c02_pw.destination = cave01
          c02_pe.destination = cave03
          c02_hps.destination = hidden_cave01
          cave02.add_inhabitant c02_pw, "leading toward the light of the entrance"
          cave02.add_inhabitant c02_pe, "leading deeper into the caverns"
          cave02.add_inhabitant c02_hps, "hidden behind a boulder"
 
          c03_pe = Cave03PassageEast.new "c03_pe"
          c03_pe.destination = cave04
          c03_pw = Cave03PassageWest.new "c03_ew"
          c03_pw.destination = cave02
          cave03.add_inhabitant c03_pw, "leading toward the light of the entrance"
          cave03.add_inhabitant c03_pe, "leading deeper into the caverns"
  
          c04_pw = Cave04PassageWest.new "c04_pw"
          c04_pw.destination = cave03
          cave04.add_inhabitant c04_pw, "leading toward the light of the entrance"
          #Add this in after making a chest+iron armor stuff
          #c04_hpe = Cave04HiddenPassageEast.new "c04_hpe"
          #c04_hpe.destination = hidden_cave02
          #cave04.add_inhabitant c04_hpe, "leading even deeper into the caverns"
         

          hc01_pn = HiddenCave01PassageNorth.new "hc01_pn"
          hc01_pn.destination = cave02
          hidden_cave01.add_inhabitant hc01_pn, "leading north"

          hc02_pw = HiddenCave02PassageWest.new "hc02_pw"
          hc02_pw.destination = cave04
          hidden_cave02.add_inhabitant hc02_pw, "leading west"


          #@MAZES
          #MAZE 1
          mf01_f = MazePath.new "mf01_f"
          mf01_b = MazePath.new "mf01_b"
          mf01_l = MazePath.new "mf01_l"
          mf01_r = MazePath.new "mf01_r"
          mf01_f.noun = "path going Forward"
          mf01_b.noun = "path going Backward"
          mf01_l.noun = "path going Left"
          mf01_r.noun = "path going Right"

          mf01_b.destination = forest01 
          mf01_l.destination = maze_forest01
          mf01_r.destination = maze_forest01

          #way ahead
          mf01_f.destination = maze_forest02
 
          #MAZE 2
          mf02_f = MazePath.new "mf02_f"
          mf02_b = MazePath.new "mf02_b"
          mf02_l = MazePath.new "mf02_l"
          mf02_r = MazePath.new "mf02_r"
          mf02_f.noun = "path going Forward"
          mf02_b.noun = "path going Backward"
          mf02_l.noun = "path going Left"
          mf02_r.noun = "path going Right"

          mf02_f.destination = maze_forest01
          mf02_b.destination = maze_forest01 
          mf02_r.destination = maze_forest01

          #way ahead
          mf02_l.destination = maze_forest03
          
          #maze 3
          mf03_f = MazePath.new "mf03_f"
          mf03_b = MazePath.new "mf03_b"
          mf03_l = MazePath.new "mf03_l"
          mf03_r = MazePath.new "mf03_r"
          mf03_f.noun = "path going Forward"
          mf03_b.noun = "path going Backward"
          mf03_l.noun = "path going Left"
          mf03_r.noun = "path going Right"

          
          mf03_l.destination = maze_forest01
          mf03_f.destination = maze_forest01
          mf03_r.destination = maze_forest01

          #way ahead
          mf03_b.destination = maze_forest04


          #MAZE 4
          mf04_f = MazePath.new "mf04_f"
          mf04_b = MazePath.new "mf04_b"
          mf04_l = MazePath.new "mf04_l"
          mf04_r = MazePath.new "mf04_r"
          mf04_f.noun = "path going Forward"
          mf04_b.noun = "path going Backward"
          mf04_l.noun = "path going Left"
          mf04_r.noun = "path going Right"
           
          mf04_b.destination = maze_forest01
          mf04_l.destination = maze_forest01
          mf04_r.destination = maze_forest01

          #way ahead
          mf04_f.destination = plains



          #doodads
          #quest
          iron_dagger = IronDagger.new "iron_dagger"
          iron_dagger.discovery_threshold = 4

          iron_sword= IronSword.new "iron_sword"
          iron_sword.discovery_threshold = 5
          torch = Torch.new "torch"
          hf01_skele = Skeleton.new "hf01_skele"
          hf01_skele.discovery_threshold = 3
          hf01_skele.add_inhabitant iron_dagger, "stuck in between the rib cage of the skeleton, with hilt hardly exposed"

          hc01_skele = Skeleton.new "hc01_skele"
          hc01_skele.discovery_threshold = 4
          hc01_skele.add_inhabitant iron_sword, "stuck downward, through the collar bone of the the skeleton, as if fallen deeper after flesh rotted away"

          #f01
          moldy_log = MoldyLog.new "f01_moldy_log"
          moldy_log.add_inhabitant RedMushroom.new("f01_ml"), "sprouting where the log meets the forest floor"
          poisoned_shroom = PoisonousRedShroom.new 

          #f02
          f02_grn_shr = GreenMushroom.new "f02_grn_shr"
          f02_grn_shr.discovery_threshold = 2
          forest02.add_inhabitant f02_grn_shr, "growing by a mossy rock"

          f02_bad_shr = PoisonousRedShroom.new "f02_bad_shr"
          f02_bad_shr.discovery_threshold = 4
          forest02.add_inhabitant f02_bad_shr, "sprouting under some mulch"

          nother_shroom_f02 = RedMushroom.new
          nother_shroom_f02.discovery_threshold = 7
          forest02.add_inhabitant nother_shroom_f02, "under a pile of leaves"



          #f03
          f03_red_shr = RedMushroom.new "f03_red_shr"
          f03_red_shr.discovery_threshold = 4
          forest03.add_inhabitant f03_red_shr, "sprouting by a nearby boulder"

          nother_shroom_f03 = RedMushroom.new
          nother_shroom_f03.discovery_threshold = 8
          forest03.add_inhabitant nother_shroom_f03, "in the shade of an overhanging rock"



          #f04
          f04_bad_shr = PoisonousRedShroom.new "f04_bad_shr"
          f04_bad_shr.discovery_threshold = 3
          f04_mold_log = MoldyLog.new "f04_mold_log"
          f04_mold_log.add_inhabitant f04_bad_shr, "on a patch of shrooms growing on the log"
          forest04.add_inhabitant f04_mold_log, "growing between two trees"

          nother_shroom_f04 = RedMushroom.new
          nother_shroom_f04.discovery_threshold = 7
          forest04.add_inhabitant nother_shroom_f04, "in the brush of a thick shrub"

          #f05
          f05_red_shr = RedMushroom.new "f05_red_shr"
          f05_red_shr.discovery_threshold = 6
          forest05.add_inhabitant f05_red_shr, "sprouting underneath a willow"
          f05_grn_shr = GreenMushroom.new "f05_grn_shr"
          f05_grn_shr.discovery_threshold = 8
          forest05.add_inhabitant f05_grn_shr, "sprouting underneath a willow"

          nother_shroom_f05 = RedMushroom.new
          nother_shroom_f05.discovery_threshold = 9
          forest05.add_inhabitant nother_shroom_f05, "sprouting by a willow sapling"



          #c02
          c02_red_shr = RedMushroom.new "c02_red_shr"
          c02_red_shr.discovery_threshold = 5
          cave02.add_inhabitant c02_red_shr, "in a moist section of the cave"


          #c04j
          c04_bad_shr = PoisonousRedShroom.new "c02_bad_shr"
          c04_bad_shr.discovery_threshold = 2

          scroll = Scroll.new "scroll"
          scroll.article = "the"
          scroll.noun = "old man's scroll"
          cave04.add_inhabitant scroll, "lying near the center of the chamber"

          hidden_forest01.add_inhabitant hf01_skele, "partially hidden against the wall of ivy to the north"
          hidden_cave01.add_inhabitant hc01_skele, "in a corner, beside an open, empty chest on the southern wall of the cave"


          maze_forest01.add_inhabitant mf01_f, "in the forward direction"
          maze_forest01.add_inhabitant mf01_b, "in the backward direction"
          maze_forest01.add_inhabitant mf01_l, "toward the left"
          maze_forest01.add_inhabitant mf01_r, "toward the right"

          maze_forest02.add_inhabitant mf02_f, "in the forward direction"
          maze_forest02.add_inhabitant mf02_b, "in the backward direction"
          maze_forest02.add_inhabitant mf02_l, "toward the left"
          maze_forest02.add_inhabitant mf02_r, "toward the right"

          maze_forest03.add_inhabitant mf03_f, "in the forward direction"
          maze_forest03.add_inhabitant mf03_b, "in the backward direction"
          maze_forest03.add_inhabitant mf03_l, "toward the left"
          maze_forest03.add_inhabitant mf03_r, "toward the right"

          maze_forest04.add_inhabitant mf04_f, "in the forward direction"
          maze_forest04.add_inhabitant mf04_b, "in the backward direction"
          maze_forest04.add_inhabitant mf04_l, "toward the left"
          maze_forest04.add_inhabitant mf04_r, "toward the right"



          p = Player.new "player"
          p.add_inventory_item MushroomPotion.new
          


          #characters
          old_man = OldMan.new "old_man"
          necromancers_assistant = NecromancersAssistant.new "necromancers_assistant"


          beetle = GiantBeetle.new "beetle"
          boss_cave_spider = LargeCaveSpider.new "large_cave_spider"



          forest01.add_inhabitant beetle, "in the brush"
          forest01.add_inhabitant p, "in the brush"
          forest01.add_inhabitant moldy_log, "in some mulch"
          forest01.add_inhabitant poisoned_shroom, "at the foot of a nearby tree"
          nother_shroom = RedMushroom.new
          nother_shroom.discovery_threshold = 6
          forest01.add_inhabitant nother_shroom, "in the brush of a thick shrub"

          cave04.add_inhabitant boss_cave_spider, "lurking in the dark"

          #beetle death triggers old man entrance.
          s = AR::Events::Resolution.new event_class: AR::Events::ARObjectDied, as: "ar_object" do |e|
            obj = e.ar_object
            results = []
            ev1 = AR::Events::DiscoveryMadeEvent.new dont_narrate: true, perceiver: obj.world.player, discovered: obj.world.find("old_man")
            ev2 = AR::Events::DialogBeganEvent.new player: obj.world.player, npc: obj.world.find("old_man")
            results.push(ev1)
            results.push(ev2)

            results
          end
          #temporarily removing this....
          beetle.resolutions.push(s)

=begin 
          p.add_inventory_item AR::Game::BeetleChitin.new
          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::BeetleChitin.new
          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::BeetleChitin.new
          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::BeetleChitin.new
          p.add_inventory_item AR::Game::BeetleChitin.new
          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::GreenMushroom.new
          p.add_inventory_item AR::Game::BeetleChitin.new

          p.add_inventory_item AR::Game::RedMushroom.new
          p.add_inventory_item AR::Game::BeetleMeat.new

          p.add_inventory_item AR::Game::BeetleMeat.new
=end


          e = AR::Events::NarrationEvent.new narration: "", new_paragraph: true
          e_l = AR::Events::NarrationEvent.new narration: "", new_paragraph: true
          e1 = AR::Events::DiscoveryMadeEvent.new perceiver: p,      discovered: beetle, dont_narrate: true 
          e3 = AR::Events::DiscoveryMadeEvent.new perceiver: p,      discovered: forest01, dont_narrate: true 
          e2 = AR::Events::DiscoveryMadeEvent.new perceiver: beetle, discovered: p 

          world.new_game_event = AR::Events::NarrationEvent.new(narration: "Everything is black. There is a slight friction sound, like canvas rubbing against itself.  A narrow crack of light begins to slice the dark in half near a revealing horizon. You are opening your eyes and realize you are lying on your back looking at a canopy of tree branches.  The friction noise crystalizes into ravenous chewing; you recognize the sound: Meat being torn from bone.  You turn your head toward the chewing.  Before you lies the corpse of a bat the size of a pony, being eaten by a carrion beetle the size of a wolf.  The huge insect is cleaning up the bat corpse, chunk by chunk...")

          eng  = world.events_engine

          #evt  = AR::Events::ARObjectEnteredInhabitableEvent.new enterer: p, inhabitable: plains
          #eng.after_step evt

          eng.after_step e3
          eng.after_step e2
          eng.after_step e1
          eng.after_step e
          
        end 
 
      end
    end

  end#Game
end#AR
