summaryrefslogtreecommitdiff
path: root/src/npc/librarians.c
blob: d53d6387c3f9881a7cd3b4ad97b01a611fed78ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/**
 * @file librarians.c
 * @ingroup NPCs
 *
 * @brief Librarians NPC
 */
#include "entity.h"
#include "flags.h"
#include "item.h"
#include "message.h"
#include "script.h"
#include "sound.h"

extern void sub_08095BE0(Entity*, u32);

extern const u8 gUnk_08114F30[];

void Librarians(Entity* this) {
    if (this->action == 0) {
        this->action = 1;
        InitScriptForNPC(this);
        this->spriteRendering.b3 = gUnk_08114F30[this->spriteRendering.b3];
    }
    ExecuteScriptForEntity(this, NULL);
    HandleEntity0x82Actions(this);
    GetNextFrame(this);
}

void sub_0806BA34(Entity* this, ScriptExecutionContext* context) {
    u32 gotBook1;
    u32 gotBook2;
    u32 gotBook3;
    u32 message = TEXT_INDEX(TEXT_LIBRARY, 0x12);
    context->condition = 0;
    if (CheckLocalFlag(0x73)) {
        message = TEXT_INDEX(TEXT_LIBRARY, 0x13);
    } else {
        gotBook1 = GetInventoryValue(ITEM_QST_BOOK1);
        gotBook2 = GetInventoryValue(ITEM_QST_BOOK2);
        gotBook3 = GetInventoryValue(ITEM_QST_BOOK3);
        if (gotBook1 == 1) {
            message = TEXT_INDEX(TEXT_LIBRARY, 0x6);
            context->condition = 1;
            SetLocalFlag(0x6b);
            SetLocalFlag(0x6a);
        } else if (gotBook2 == 1) {
            message = TEXT_INDEX(TEXT_LIBRARY, 0x7);
            context->condition = 1;
            SetLocalFlag(0x6b);
            SetLocalFlag(0x6a);
        } else if (gotBook3 == 1) {
            message = TEXT_INDEX(TEXT_LIBRARY, 0x8);
            context->condition = 1;
            SetLocalFlag(0x6b);
            SetLocalFlag(0x6a);
        } else {
            if (CheckLocalFlag(0x6a)) {
                if (!CheckLocalFlag(0x6b)) {
                    message = TEXT_INDEX(TEXT_LIBRARY, 0x1);
                    SetLocalFlag(0x6b);
                } else {
                    if (gotBook1 == 0) {
                        message = TEXT_INDEX(TEXT_LIBRARY, 0x2);
                        SetLocalFlag(0x6b);
                    } else if (gotBook2 == 0) {
                        message = TEXT_INDEX(TEXT_LIBRARY, 0x3);
                        SetLocalFlag(0x6d);
                    } else if (gotBook3 == 0) {
                        message = TEXT_INDEX(TEXT_LIBRARY, 0x4);
                        SetLocalFlag(0x70);
                    }
                }
            }
        }
    }
    MessageNoOverlap(message, this);
}

void sub_0806BB1C(Entity* this, ScriptExecutionContext* context) {
    s32 item = -1;
    if (GetInventoryValue(ITEM_QST_BOOK1) == 1) {
        item = ITEM_QST_BOOK1;
    } else if (GetInventoryValue(ITEM_QST_BOOK2) == 1) {
        item = ITEM_QST_BOOK2;
    } else {
        if (GetInventoryValue(ITEM_QST_BOOK3) == 1) {
            item = ITEM_QST_BOOK3;
        }
        if (item < 1) {
            return;
        }
    }
    if (context->intVariable == 0) {
        sub_08095BE0(this, item);
        InitializeAnimation(this, 0xc);
        SoundReq(SFX_TASK_COMPLETE);
    } else {
        SetInventoryValue(item, 2);
    }
}

void sub_0806BB7C(Entity* this, ScriptExecutionContext* context) {
    context->condition = 0;
    if ((GetInventoryValue(ITEM_QST_BOOK1) == 2) && (GetInventoryValue(ITEM_QST_BOOK2) == 2) &&
        (GetInventoryValue(ITEM_QST_BOOK3) == 2)) {
        SetLocalFlag(0x73);
        context->condition = 1;
    }
}

void sub_0806BBB0(Entity* this) {
    static const u16 messageIndices[] = {
        TEXT_INDEX(TEXT_LIBRARY, 0xf),
        TEXT_INDEX(TEXT_LIBRARY, 0x10),
        TEXT_INDEX(TEXT_LIBRARY, 0x12),
    };
    u32 tmp;

    if (GetInventoryValue(ITEM_FLIPPERS) == 0) {
        if (CheckGlobalFlag(MIZUKAKI_START)) {
            tmp = 1;
        } else {
            tmp = 0;
        }
    } else {
        tmp = 2;
    }
    MessageNoOverlap(messageIndices[tmp], this);
}