init -1:
    define Enable_PhoneJobMod = True
init python:
    # Activity(**{
    #     "name": "nap",
    #     "conditions": [
    #         HeroTarget(
    #             MinStat("energy", 0),
    #             MinStat("hunger", 0),
    #             MinStat("grooming", 0),
    #             MinStat("fun", 0),
    #             ),
    #         ],
    #     "energy": 1.5,
    #     "hunger": 0.3,
    #     "grooming": 0.1,
    #     "display_name": "Nap for One Hour",
    #     "icon": "wait",
    #     "label": "nap",
    #     "order": 1,
    #     })

    Activity(**{
        "name": "set_alarm_next",
        "duration": 0,
        "rooms": ("bedroom1", "bedroom4"),
        "conditions": [
            HeroTarget(
                MinStat("energy", 0),
                MinStat("hunger", 0),
                MinStat("grooming", 0),
                MinStat("fun", 0),
                ),
            ],
        "icon": "alarm",
        "label": "set_alarm_next",
        "display_name": "Set Alarm at Next Hour",
        })

    Activity(**{
        "name": "set_alarm_six",
        "duration": 0,
        "rooms": ("bedroom1", "bedroom4"),
        "conditions": [
            HeroTarget(
                MinStat("energy", 0),
                MinStat("hunger", 0),
                MinStat("grooming", 0),
                MinStat("fun", 0),
                ),
            ],
        "icon": "alarm",
        "label": "set_alarm_six",
        "display_name": "Set Alarm at 6:00",
        })

    Activity(**{
        "name": "PhoneJob",
        "duration": 0,
        # "rooms": ("bedroom1", "bedroom4"),
        "conditions": [HeroTarget(Not(OnDate())),"Enable_PhoneJobMod"],
        "icon": "study",
        "label": "phone_task",
        "display_name": "Send Message or Call a Girl",
        })

    # Activity(**{
    #     "name": "maidcafe_order_nap",
    #     "money_cost": 25,
    #     "energy": 1.5,
    #     "hunger": 0.3,
    #     "grooming": 0.1,
    #     "rooms": "maidcafe",
    #     "conditions": [
    #         HeroTarget(IsGender("male")),
    #         PersonTarget(bree,
    #             IsPresent(),
    #             Not(IsHidden()),
    #             ),
    #         ],
    #     "display_name": "Order something and nap for one hour",
    #     "icon": "coffee",
    #     "once_day": True,
    #     "label": "maidcafe_order_nap",
    #     })

    # Event(**{
    #     "name": "kiara_special_coffee_nap",
    #     "conditions": [
    #         HeroTarget(
    #             IsGender("male"),
    #             IsRoom("maidcafe"),
    #             IsFlag("kiara_bj"),
    #             IsActivity("maidcafe_order_nap"),
    #             ),
    #         ],
    #     "label": "kiara_special_coffee",
    #     "chances": 20,
    #     "do_once": False,
    #     "once_week": True,
    #     })

    Event(**{
        "name": "bree_event_04_MOD",
        "label": "bree_event_04_MOD",
        "duration": 2,
        "conditions": [
            IsDone("bree_event_05"),
            IsDayOfWeek("12345"),
            IsHour(12, 18),
            HeroTarget(
                IsGender("male"),
                Not(OnDate())),
            PersonTarget(bree,
                Not(IsPresent()),
                Not(IsHidden()),
                MinStat("love", 80),
                MinStat("sub", 25),
                ),
            ],
        "priority": 500,
        "music": "music/roa_music/juice.ogg",
        "do_once": True,
        })

    InteractEvent(**{
        "name": "bree_event_05_MOD",
        "label": "bree_event_05_MOD",
        "duration": 2,
        "conditions": [
            IsDone("bree_event_04"),
            IsDayOfWeek("123456"),
            IsHour(18, 20),
            HeroTarget(
                IsGender("male"),
                IsRoom("livingroom")),
            HasSkill("video_games"),
            PersonTarget(bree,
                IsActive(),
                MinStat("love", 80),
                ),
            ],
        "priority": 500,
        "do_once": True,
        "music": "music/roa_music/juice.ogg",
        })

    Event(**{
        "name": "bree_event_set_delay",
        "label": "bree_event_set_delay",
        "duration": 0,
        "conditions": [
            Or(
                And(
                    IsDone("bree_event_07"),
                    Not(IsDone("bree_event_08")),
                    ),
                And(
                    IsDone("bree_event_08b"),
                    Not(IsDone("bree_event_09b")),
                    ),
                ),
            PersonTarget(bree,
                IsFlag("breedelay"),
                Not(IsFlag("breedelay2")),
                ),
            ],
        "do_once": False,
        "once_day": True,
        })

    Event(**{
        "name": "bree_event_09b_MOD",
        "label": "bree_event_check_delay",
        "duration": 0,
        "conditions": [
            IsDone("bree_event_09b"),
            ],
        "do_once": True,
        "once_day": False,
        })

    Event(**{
        "name": "bree_event_08_MOD",
        "label": "bree_event_check_delay",
        "duration": 0,
        "conditions": [
            IsDone("bree_event_08"),
            ],
        "do_once": True,
        "once_day": False,
        })

#     DayTransitionEvent(**{
#         "name": "video_game_gain",
#         "label": "video_game_gain",
#         })

# label video_game_gain:
#     if not hero.has_skill("video_games"):
#         $ tmp = hero.skills["video_games"].value // 6
#         if tmp:
#             $ hero.gain_skill("video_games", tmp)
#     return

label maidcafe_order_nap:
    if hero.has_skill("no_sleep"):
        $ hero.energy += 0.25
    if "luxury_bed" in hero.inventory:
        $ hero.energy += 0.25
    jump maidcafe_order

label set_alarm_next:
    python:
        game.flags.alarm_clock = True
        game.flags.alarm_time = (game.hour + 1) % 24
    return

label set_alarm_six:
    python:
        game.flags.alarm_clock = True
        game.flags.alarm_time = 6
        # def process_file(filename):
        #     def unquote(s):
        #         s = s.replace("\\\\", "\\")
        #         s = s.replace("\\n", "\n")
        #         s = s.replace("\\\"", '\"')
        #         s = s.replace("\\\'", "\'")
        #         return s

        #     line_re = re.compile(r"^[^\"]*\"(.*)\"$")
        #     with open(filename, 'r') as file:
        #         a = 0
        #         ll = ""
        #         try:
        #             for l in file:
        #                 line = l.strip()
        #                 if line and not line.startswith('#'):
        #                     i = line_re.search(line)
        #                     if i:
        #                         a += 1
        #                         b = chinese_stl.translate(unquote(i.group(1)))
        #                 ll = line
        #         except:
        #             raise Exception(ll)

        # process_file('game/batch_translate.txt')
    return

label nap:
    if hero.has_skill("no_sleep"):
        $ hero.energy += 0.25
    if "luxury_bed" in hero.inventory:
        $ hero.energy += 0.25
    jump wait

label phone_task:
    $ tmp_task = 0
    python:
        for girl in Person.all_people(True):
            if girl.id in hero.smartphone_contacts and girl.activity_name != "sleep" and not girl.hidden:
                g = girl
                if g.love < g.love.max:
                    if not Conditioned.done_today("smartphone_send_friendly_text_" + g.id):
                        tmp_task = 1
                        break
                    if not Conditioned.done_today("smartphone_send_flirty_text_" + g.id) and hero.charm >= 15 and not g.flags.noFlirtyText and g.flags.kiss >= 1:
                        tmp_task = 2
                        break
                    if not Conditioned.done_today("smartphone_send_dirty_text_" + g.id) and hero.charm >= 30 and not g.flags.noDirtyText and g.sexperience >= 1:
                        tmp_task = 3
                        break
        if (not tmp_task) and hero.fun < hero.fun.max:
            for girl in Person.all_people(True):
                if girl.id in hero.smartphone_contacts and girl.activity_name != "sleep" and not girl.hidden:
                    g = girl
                    if not Conditioned.done_today("smartphone_send_friendly_text_" + g.id):
                        tmp_task = 1
                        break
                    if not Conditioned.done_today("smartphone_send_flirty_text_" + g.id) and hero.charm >= 15 and not g.flags.noFlirtyText and g.flags.kiss >= 1:
                        tmp_task = 2
                        break
                    if not Conditioned.done_today("smartphone_send_dirty_text_" + g.id) and hero.charm >= 30 and not g.flags.noDirtyText and g.sexperience >= 1:
                        tmp_task = 3
                        break
        if not tmp_task:
            for girl in Person.all_people(True):
                if girl.id in hero.smartphone_contacts and girl.activity_name != "sleep" and not girl.hidden:
                    g = girl
                    if g.sub < g.sub.max or g.love < g.love.max  or g.id.lower() == 'morgan' or (g.id.lower() == 'minami' and g.siscon < g.siscon.max):
                        if not Conditioned.done_today("smartphone_call_" + g.id):                    
                            tmp_task = 4
                            break
    if tmp_task == 1:
        call smartphone_send_friendly_text(g) from _smartphone_send_friendly_text
    elif tmp_task == 2:
        call smartphone_send_flirty_text(g) from _smartphone_send_flirty_text
    elif tmp_task == 3:
        call smartphone_send_dirty_text(g) from _smartphone_send_dirty_text
    elif tmp_task == 4:
        call smartphone_call(g) from _smartphone_call
    return

label bree_event_04_MOD:
    if not "bree_event_04" in DONE:
        call bree_event_04 from  _call_bree_event_04_MOD
        if not do_event.flags.canceled:
            $ DONE["bree_event_04"] = game.days_played
    return

label bree_event_05_MOD:
    if not "bree_event_05" in DONE:
        $ DONE["bree_event_05"] = game.days_played
        jump bree_event_05
    return

label bree_event_set_delay:
    $ bree.flags.breedelay2 = TemporaryFlag(True, bree.get_flag("breedelay").duration)

label bree_event_check_delay:
    if bree.flags.breedelay2:
        $ tmp = bree.get_flag("breedelay2").duration
        if not bree.flags.breedelay or bree.get_flag("breedelay").duration < tmp:
            $ bree.flags.breedelay = TemporaryFlag(True, tmp)
            $ bree.flags.breedelay2 = False
    return

init 20 python:
    def after_load_YWMOD():
        if hero.has_skill("iron_stomach"):
            hero.hunger.decay_value = 0.64
        else:
            hero.hunger.decay_value = 0.8
    config.after_load_callbacks += [after_load_YWMOD]
    config.console = True