-- Flower items and bouquet
define ITEM_FLOWER_RED     30169  -- Red Flower
define ITEM_FLOWER_ORANGE  30170  -- Orange Flower
define ITEM_FLOWER_YELLOW  30171  -- Yellow Flower
define ITEM_BOUQUET        30172  -- Bouquet

-- Required amounts
define NEED_RED            1
define NEED_ORANGE         1
define NEED_YELLOW         1

-- Drop chances (percent)
define DROP_RED            45
define DROP_ORANGE         30
define DROP_YELLOW         15


quest new_quest_lv7 begin
    state start begin
        -- Function declaration
        function reward()
            local div = number(1,5)
            local reward = 5000
            --notice(string.format("%d - reward | div =%d"), reward, div)
            reward = math.floor(reward/div)
            return reward
        end

        function reward_exp()
            local div = number(1,4)
            local reward_exp = 4000
            --notice(string.format("%d - reward | div =%d"), reward, div)
            reward_exp = math.floor(reward_exp/div)
            return reward_exp
        end
        -- end function declaration

        -- When level 7 target Octavio for new Quest-------------------------------------------------------------
        when login or levelup with pc.get_level() >= 7 begin
            local v = find_npc_by_vnum(20008)
            if 0 == v then
            else
                target.vid("__TARGET__", v, gameforge.new_quest_lv7._010_target)
            end
        end

        when 20008.chat.gameforge.new_quest_lv7._020_say_title with pc.get_level() >= 7 begin
            target.delete("__TARGET__")
            local empire = pc.get_empire()
            say_title(gameforge.new_quest_lv7._011_say_title)  -- A Daughters Wedding
            say(gameforge.new_quest_lv7._021_say) -- Octavio has a daughter and she is in love with a guy for a village
            if empire == 1 then -- = Shinsoo
                say(gameforge.new_quest_lv7._022_say) -- The guy lives in a village in the Jayang area
            end
            if empire == 2 then -- = Chunjo
                say(gameforge.new_quest_lv7._023_say) -- The guy lives in a village in the Bokjung area
            end
            if empire == 3 then -- = Jinno
                say(gameforge.new_quest_lv7._024_say) -- The guy lives in a village in the Bakra area
            end
            wait() -- next button 
            say_title(gameforge.new_quest_lv7._011_say_title) -- A Daughters Wedding
            say(gameforge.new_quest_lv7._030_say) -- Octavio heared that she is going to marry him there
            say(gameforge.new_quest_lv7._031_say) -- Go to the Old Lady and ask her to help with the preperations 
            local doquest = select(gameforge.subquest_06._40_select, gameforge.subquest_12._50_select, gameforge.new_quest_lv75._290_2_select)
            if doquest == 1 then
                pc.setqf("soup", 0)  -- hard reset flavour flag at quest start
                set_state(ask_oldwoman) -- Quest approved
            elseif doquest == 3 then -- abort permantenly
                say(gameforge.subquest_06._60_say)
                local abortquest = select(gameforge.subquest_06._70_select, gameforge.subquest_06._80_select)
                if abortquest == 1 then
                    set_state(__GIVEUP__)
                else
                    say_title(gameforge.new_quest_lv7._011_say_title)  -- A Daughters Wedding
                    say(gameforge.subquest_11._80_say)
                    return
                end
            else
                say_title(gameforge.new_quest_lv7._011_say_title)  -- A Daughters Wedding
                say(gameforge.subquest_11._80_say)
                return
            end
        end
    end

    ---- ask altefrau what to do --------------------------------------------------------------------------------
    state ask_oldwoman begin
        function get_old_woman_map() 
            local empire = pc.get_empire()
            if empire == 1 then 
                return 1 
            elseif empire == 2 then 
                return 21
            elseif empire == 3 then 
                return 41
            end
        end

        function is_my_vil()
            if pc.get_map_index() == new_quest_lv7.get_old_woman_map() then
                return true
            else
                return false
            end
        end
                
        when enter or login begin
            new_quest_lv7_mob1 = 173 -- kill a 173#Hungriger Alpha-Wolf
            new_quest_lv7_mob2 = 174 -- kill a 174#Hungriger Blauwolf
            new_quest_lv7_mob3 = 175 -- kill a 175#Hungriger Alpha-Blauwolf
            -- Einige deser Mobs werden auch in der Level 7 Aufgabe verwendet, was dazu führt, 
            -- dass diese dort nicht mehr hoch zählen wenn man sie tötet.

            -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No quest letter, no questbook entry
            send_letter(gameforge.new_quest_lv7._020_say_title)  -- A Daughters Wedding
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title) -- A Daughters Wedding
            -- END EDIT

            if new_quest_lv7.is_my_vil() then
                local v = find_npc_by_vnum(9006) -- Old Lady
                if 0 == v then
                else
                    target.vid("__TARGET2__", v, gameforge.new_quest_lv7._040_target ) -- Old Lady
                end
            end			
        end
        
        -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No questbook button		
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title) -- A Daughters Wedding
            say(gameforge.new_quest_lv7._041_say) -- goto old lady and ask her to help with the preperations
            say("")
            -- FIX: correct map name based on player's empire
            say(string.format(gameforge.new_quest_lv7._042_say, get_map_name_by_number(new_quest_lv7.get_old_woman_map())))  -- where the old lady can be found
        end
        --END EDIT
        
        when 9006.chat.gameforge.new_quest_lv7._020_say_title begin
            target.delete("__TARGET2__")
            say_title(gameforge.new_quest_lv7._012_say_title) -- yellow text headline
            say(gameforge.new_quest_lv7._051_say)
            wait()
            say_title(gameforge.new_quest_lv7._012_say_title) -- yellow text headline
            say(gameforge.new_quest_lv7._052_say)
            -- "vom Bräutigam an seine Liebste überreicht" versteht das unsere Zielgruppe?
            wait()	
            say(gameforge.new_quest_lv7._054_say)
            say_reward(string.format("%s x", NEED_RED))
            say_item_vnum(ITEM_FLOWER_RED) -- icon of item
            say_reward(gameforge.new_quest_lv7._055_say)
            say(mob_name(new_quest_lv7_mob1))
            wait()
            say(gameforge.new_quest_lv7._056_say)
            say_reward(string.format("%s x", NEED_ORANGE))
            say_item_vnum(ITEM_FLOWER_ORANGE) -- icon of item
            say_reward(gameforge.new_quest_lv7._055_say)
            say(mob_name(new_quest_lv7_mob2))
            wait()
            say(gameforge.new_quest_lv7._056_say)
            say_reward(string.format("%s x", NEED_YELLOW))
            say_item_vnum(ITEM_FLOWER_YELLOW) -- icon of item
            say_reward(gameforge.new_quest_lv7._055_say )
            say(mob_name(new_quest_lv7_mob3))
            wait()
            say_title(gameforge.new_quest_lv7._012_say_title)
            say(gameforge.new_quest_lv7._060_say)
            -- Wo ist die Schwester?
            q.done()
            set_state(collect_flowers)
        end
    end

    ----- collect flowers -------------------------------------------------------------------------------------------------
    state collect_flowers begin
        -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No letter, questbook entry, button						
        when enter or login begin	
            send_letter(gameforge.new_quest_lv7._020_say_title)	
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            
            -- FIX: if the player already has all flowers, go directly to return_oldwoman
            if pc.count_item(ITEM_FLOWER_RED) >= NEED_RED and pc.count_item(ITEM_FLOWER_ORANGE) >= NEED_ORANGE and pc.count_item(ITEM_FLOWER_YELLOW) >= NEED_YELLOW then
                q.done()
                set_state(return_oldwoman)
                return
            end                
        end
        --END EDIT		
        
        -- use when one of 173,174,175 is  killed
        -- collectFlag is the name of the quest flag where a amount of collected is saved
        -- itemicon vnum of flower used for icon 
        function when_one_killed(neededAmount, dropProb, itemIcon)
            if pc.count_item(itemIcon) < neededAmount then
                local drop = number(1,100)
                if drop <= dropProb then -- probability if s.th. drops
                    pc.give_item2(itemIcon) -- icon of item by vnum - Blutrote Blume
                    --  EDIT Arne 18Sept09 moved q.done    Reason: removed quest from book
                    -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No arrow on old lady for flower return	
                    --notice_multiline(gameforge.new_quest_lv7._088_notice, notice)
                    if pc.count_item(ITEM_FLOWER_YELLOW) == NEED_YELLOW and pc.count_item(ITEM_FLOWER_ORANGE) == NEED_ORANGE and pc.count_item(ITEM_FLOWER_RED) == NEED_RED then
                        return true
                    end
                else
                    --notice_multiline(gameforge.new_quest_lv7._082_say, notice)
                end
            end

            -- FIX: also check completion when there is no drop or flowers came from trade
            if pc.count_item(ITEM_FLOWER_YELLOW) >= NEED_YELLOW and pc.count_item(ITEM_FLOWER_ORANGE) >= NEED_ORANGE and pc.count_item(ITEM_FLOWER_RED) >= NEED_RED then
                return true
            end
        end

        -------------- Blutrote Blume ------------------------------------------------------
        -- kill a 173#Hungriger Alpha-Wolf
        when 173.kill begin
            if new_quest_lv7.when_one_killed(NEED_RED, DROP_RED, ITEM_FLOWER_RED) then
                q.done()
                set_state(return_oldwoman)
            end
        end

        -------------- Orangefarbene Blume ------------------------------------------------------
        -- kill a 174#Hungriger Blauwolf
        when 174.kill begin
            if new_quest_lv7.when_one_killed(NEED_ORANGE, DROP_ORANGE, ITEM_FLOWER_ORANGE) then 
                q.done()
                set_state(return_oldwoman)
            end
        end

        -------------- Duftende gelbe Blume ------------------------------------------------------
        -- kill a 175#Hungriger Alpha-Blauwolf
        when 175.kill begin		
            if new_quest_lv7.when_one_killed(NEED_YELLOW, DROP_YELLOW, ITEM_FLOWER_YELLOW) then
                q.done()
                set_state(return_oldwoman)
            end
        end
        
        -------------- info if a flower dropped
        --EDIT Arne 18Sept09: Setting up an alternate event as I could not get the other one to work properly
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title)
            say(gameforge.new_quest_lv7._092_say) -- collect flowers for the Bouquet
            if pc.count_item(ITEM_FLOWER_RED) < NEED_RED then
                say_reward(string.format(gameforge.new_quest_lv7._085_1_say_reward, NEED_RED - pc.count_item(ITEM_FLOWER_RED))) -- number of red flowers missing
            end
            if pc.count_item(ITEM_FLOWER_ORANGE) < NEED_ORANGE then
                say_reward(string.format(gameforge.new_quest_lv7._085_2_say_reward, NEED_ORANGE - pc.count_item(ITEM_FLOWER_ORANGE))) -- number of orange flowers missing
            end
            if pc.count_item(ITEM_FLOWER_YELLOW) < NEED_YELLOW then
                say_reward(string.format(gameforge.new_quest_lv7._085_3_say_reward, NEED_YELLOW - pc.count_item(ITEM_FLOWER_YELLOW))) -- number of yellow flowers missing
            end
        end
    end


    state return_oldwoman begin -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, state needed to set up quest		
        when enter or login begin
            local v = find_npc_by_vnum(9006)
            send_letter(gameforge.new_quest_lv7._020_say_title)
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            if 0 == v then
            else
                target.vid("__TARGET6__", v, gameforge.new_quest_lv7._040_target)
            end
        end
        
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title)
            say(gameforge.new_quest_lv7._091_say) -- success return to old lady
            say("")
            -- FIX: correct map name (same logic as in ask_oldwoman)
            say(string.format(gameforge.new_quest_lv7._042_say, get_map_name_by_number(new_quest_lv7.get_old_woman_map())))
        end
        --END EDIT

        -------------- try to give old woman the flowers ---------------------
        when 9006.chat.gameforge.new_quest_lv7._020_say_title begin
            target.delete("__TARGET6__")
            say_title(gameforge.new_quest_lv7._012_say_title)
            if pc.count_item(ITEM_FLOWER_RED) < NEED_RED or pc.count_item(ITEM_FLOWER_ORANGE) < NEED_ORANGE or pc.count_item(ITEM_FLOWER_YELLOW) < NEED_YELLOW then
                say(gameforge.new_quest_lv7._110_say)
                -- FIX: avoid negative numbers if player has more flowers than needed
                say_reward(string.format(gameforge.new_quest_lv7._085_say_reward, math.max(0, NEED_RED - pc.count_item(ITEM_FLOWER_RED))))
                say_reward(string.format(gameforge.new_quest_lv7._086_say_reward, math.max(0, NEED_ORANGE - pc.count_item(ITEM_FLOWER_ORANGE))))
                say_reward(string.format(gameforge.new_quest_lv7._087_say_reward, math.max(0, NEED_YELLOW - pc.count_item(ITEM_FLOWER_YELLOW))))
                say(gameforge.new_quest_lv7._081_say)
                set_state(collect_flowers)
            else
                pc.remove_item(ITEM_FLOWER_RED, NEED_RED)
                pc.remove_item(ITEM_FLOWER_ORANGE, NEED_ORANGE)
                pc.remove_item(ITEM_FLOWER_YELLOW, NEED_YELLOW)
                pc.give_item2(ITEM_BOUQUET) -- flowers
                -- game.drop_item(30169, 1)
                say(gameforge.new_quest_lv7._115_say)
                -- hier fehlt info wie man in das reich kommt
                if pc.get_empire() == 1 then -- = Shinsoo
                    say_reward(gameforge.new_quest_lv7._118_say_reward) -- you will find her in the village of the area Yayang
                end
                if pc.get_empire() == 2 then -- = Chunjo
                    say_reward(gameforge.new_quest_lv7._116_say_reward) -- you will find her in the village of the area Bokjung
                end
                if pc.get_empire() == 3 then -- = Jinno
                    say_reward(gameforge.new_quest_lv7._117_say_reward) -- you will find her in the village of the area Bakra
                end
                q.done()
                set_state(find_empire)
                return
            end
        end
    end

    --- go to twin sister of old woman in other kingdom---------------------------------------------------------------------------------------------------
    state find_empire begin
        when login or enter begin
            -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No letter
            send_letter(gameforge.new_quest_lv7._020_say_title)
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            -- END EDIT

            new_quest_lv7_DestMapIndex = 99
            if pc.get_empire() == 1 then -- = Shinsoo
                new_quest_lv7_DestMapIndex = 3 -- = Yayang
                local v = find_npc_by_vnum(10001)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._190_select)
                end
            elseif pc.get_empire() == 2 then -- = Chunjo
                new_quest_lv7_DestMapIndex = 23 -- = Bokjung
                local v = find_npc_by_vnum(10003)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._210_select)
                end
            elseif pc.get_empire() == 3 then -- = Jinno
                new_quest_lv7_DestMapIndex = 43 -- = Bakra
                local v = find_npc_by_vnum(10005)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._230_select)
                end
            end

            if pc.get_map_index() == new_quest_lv7_DestMapIndex  then
                target.delete("__TARGET7__")
                --notice_multiline(gameforge.new_quest_lv7._125_notice, notice)
                local v = find_npc_by_vnum(9006)
                if 0 == v then
                else
                    target.vid("__TARGET3__", v, gameforge.subquest_48._230_targetVid)
                end
                set_state(goto_oldwomans_sister)
            end
        end
        
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title)
            say(gameforge.new_quest_lv7._131_say)
            if new_quest_lv7_DestMapIndex == 3 then 
                say_reward(gameforge.new_quest_lv7._134_say_reward)
            elseif new_quest_lv7_DestMapIndex == 23 then 
                say_reward(gameforge.new_quest_lv7._132_say_reward)
            elseif new_quest_lv7_DestMapIndex == 43 then 
                say_reward(gameforge.new_quest_lv7._133_say_reward)
            end
        end
    end

    ------  find the sister of the old woman in a different empire ------------------------------------------------------------------------------------------------------
    state goto_oldwomans_sister begin
        when enter or login begin
            send_letter(gameforge.new_quest_lv7._020_say_title)
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)

            -- FIX: recompute destination map index to ensure correct map for the sister
            new_quest_lv7_DestMapIndex = 99
            if pc.get_empire() == 1 then -- = Shinsoo
                new_quest_lv7_DestMapIndex = 3  -- = Yayang
            elseif pc.get_empire() == 2 then -- = Chunjo
                new_quest_lv7_DestMapIndex = 23 -- = Bokjung
            elseif pc.get_empire() == 3 then -- = Jinno
                new_quest_lv7_DestMapIndex = 43 -- = Bakra
            end
        end
        
        when 9006.chat.gameforge.new_quest_lv7._020_say_title with pc.get_map_index() == new_quest_lv7_DestMapIndex begin
            if pc.count_item(ITEM_BOUQUET) >= 1 then -- has flowers in inventory
                target.delete("__TARGET3__")
                say_title(gameforge.new_quest_lv7._020_say_title) -- yellow
                pc.remove_item(ITEM_BOUQUET, pc.count_item(ITEM_BOUQUET))
                say_title(pc.get_name())
                say(gameforge.new_quest_lv7._140_say)
                say_title(gameforge.new_quest_lv7._012_say_title)
                say(gameforge.new_quest_lv7._141_say)
                wait()
                say_title(gameforge.new_quest_lv7._012_say_title)
                say(gameforge.new_quest_lv7._142_say)
                q.done()
                set_state(find_way_home)
                return
            else
                target.delete("__TARGET3__")
                say(gameforge.new_quest_lv7._143_say)
                say(gameforge.new_quest_lv7._144_say_reward)
                q.done()
                set_state(ask_oldwoman)
            end
        end

        when button or info begin
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            say(gameforge.new_quest_lv7._145_say)
        end
    end

    ------ return to first village ------------------------------------------------------------------------------------------------------
    state find_way_home begin
        when login or enter begin
            -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: No letter
            send_letter(gameforge.new_quest_lv7._020_say_title)
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            -- END EDIT
            new_quest_lv7_HomeMapIndex = 99
            if pc.get_empire() == 1 then -- = Shinsoo
                new_quest_lv7_HomeMapIndex = 1 -- = Youngan
                local v = find_npc_by_vnum(10002)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._180_select)
                end
            elseif pc.get_empire() == 2 then -- = Chunjo
                new_quest_lv7_HomeMapIndex = 21 -- = Joan
                local v = find_npc_by_vnum(10004)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._200_select)
                end
            elseif pc.get_empire() == 3 then -- = Jinno
                new_quest_lv7_HomeMapIndex = 41 -- = Pyungmoo
                local v = find_npc_by_vnum(10006)
                if 0 == v then
                else
                    target.vid("__TARGET7__", v, gameforge.map_warp._220_select)
                end
            end
            if pc.get_map_index() == new_quest_lv7_HomeMapIndex  then
                target.delete("__TARGET7__")
                --notice_multiline(gameforge.new_quest_lv7._129_say, notice)
                local v = find_npc_by_vnum(20008)
                if 0 == v then
                else
                    target.vid("__TARGET5__", v, gameforge.subquest_48._230_targetVid)
                end
                set_state(back_to_octavio)
            end
        end
        
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title)
            local empire = pc.get_empire()
            if empire == 1 then -- = Shinsoo
                say(gameforge.new_quest_lv7._135_say)
            end
            if empire == 2 then -- = Chunjo
                say(gameforge.new_quest_lv7._136_say)
            end
            if empire == 3 then -- = Jinno
                say(gameforge.new_quest_lv7._137_say)
            end			
        end		
    end

    ------  invite ocatvio to the wedding ------------------------------------------------------------------------------------------------------
    state back_to_octavio begin
        when enter or login begin
            -- BEGIN EDIT added by Arne 18Sept09, according to Mantis 0026063, REASON: no quest, no letter
            local v = find_npc_by_vnum(20008)
            if 0 == v then
            else
                target.vid("__TARGET5__", v, gameforge.new_quest_lv7._010_target)
            end
            -- adding empire name to octavio job
            send_letter(gameforge.new_quest_lv7._020_say_title)		
            q.start()
            q.set_title(gameforge.new_quest_lv7._020_say_title)
            -- END EDIT

            -- FIX: keep soup flag persistent via quest flag
            if pc.getqf("soup") == 1 then
                soup = true
            else
                soup = false
            end
        end
        
        when button or info begin
            say_title(gameforge.new_quest_lv7._020_say_title)
            say(gameforge.new_quest_lv7._129_say)
        end
        
        when 20008.chat.gameforge.new_quest_lv7._020_say_title begin
            target.delete("__TARGET5__")
            say_title(gameforge.new_quest_lv7._020_say_title)
            if npc.get_empire() == pc.get_empire() then
                if soup then
                    say(gameforge.new_quest_lv7._150_say)
                end
                say(gameforge.new_quest_lv7._151_say)
                say(gameforge.new_quest_lv7._152_say)

                -- random reward
                local reward = new_quest_lv7.reward()
                local reward_exp = new_quest_lv7.reward_exp()

                say_reward(string.format(gameforge.new_quest_lv7._154_say_reward, reward_exp))
                say_reward(string.format(gameforge.new_quest_lv7._155_say_reward, reward))
                
                -- FIX: use the same values for the actual reward
                pc.give_exp2(reward_exp)
                pc.change_money(reward)

                pc.setqf("soup", 0) -- reset flavour flag after success

                local reward_item = "0"
                local job = pc.get_job()
                if job == 0 then
                    local r = number(1,10)
                    if r == 1 then
                        reward_item = "00013"
                    elseif r == 2 then
                        reward_item = "00023"
                    elseif r == 3 then
                        reward_item = "00033"
                    elseif r == 4 then
                        reward_item = "00043"
                    elseif r == 5 then
                        reward_item = "00053"
                    elseif r == 6 then
                        reward_item = "03003"
                    elseif r == 7 then
                        reward_item = "03013"
                    elseif r == 8 then
                        reward_item = "03023"
                    elseif r == 9 then
                        reward_item = "03033"
                    elseif r == 10 then
                        reward_item = "03043"
                    end
                elseif job == 1 then
                    local r = number(1,10)
                    if r == 1 then
                        reward_item = "01003"
                    elseif r == 2 then
                        reward_item = "04003"
                    elseif r == 3 then
                        reward_item = "01013"
                    elseif r == 4 then
                        reward_item = "04013"
                    elseif r == 5 then
                        reward_item = "01023"
                    elseif r == 6 then
                        reward_item = "02003"
                    elseif r == 7 then
                        reward_item = "02013"
                    elseif r == 8 then
                        reward_item = "02023"
                    elseif r == 9 then
                        reward_item = "02033"
                    elseif r == 10 then
                        reward_item = "02043"
                    end
                elseif job == 2 then
                    local r = number(1, 6)
                    if r == 1 then
                        reward_item = "00013"
                    elseif r == 2 then
                        reward_item = "00023"
                    elseif r == 3 then
                        reward_item = "00033"
                    elseif r == 4 then
                        reward_item = "00043"
                    elseif r == 5 then
                        reward_item = "00053"
                    elseif r == 6 then
                        reward_item = "00053"
                    end
                elseif job == 3 then
                    local r = number(1, 8)
                    if r == 1 then
                        reward_item = "05003"
                    elseif r == 2 then
                        reward_item = "05013"
                    elseif r == 3 then
                        reward_item = "05023"
                    elseif r == 4 then
                        reward_item = "07003"
                    elseif r == 5 then
                        reward_item = "07013"
                    elseif r == 6 then
                        reward_item = "07023"
                    elseif r == 7 then
                        reward_item = "07033"
                    elseif r == 8 then
                        reward_item = "07043"
                    end
                end

                if reward_item != "0" then
                    wait()
                    say_reward(gameforge.new_quest_lv7._153_say_reward)
                    say_item_vnum(reward_item)
                    pc.give_item2(reward_item,1)
                end
                q.done()
                set_state(__COMPLETE__)
            else
                say(gameforge.new_quest_lv7._160_say)
                say(gameforge.new_quest_lv7._165_say)
                soup = true
                pc.setqf("soup", 1) -- FIX: remember that player talked to the wrong Octavio
            end
        end
    end
    
    ------  give up ------------------------------------------------------------------------------------------------------
    state __GIVEUP__ begin
        when button or info begin
            return
        end
    end

    ------  complete ------------------------------------------------------------------------------------------------------
    state __COMPLETE__ begin
        when button or info begin
            return
        end
    end
end
