|
1
2
3
|
#include "d2char.h"
#include "d2quest.h"
|
|
4
5
|
#include <stdio.h>
|
|
6
|
int getQuestData(D2QuestData* d, D2S_QUEST_IDENTIFIER questID, D2Quest* quest, D2S_DIFFICULTY difficulty) {
|
|
7
8
9
10
11
12
|
if(difficulty != D2S_DIFFICULTY_NORMAL ||
difficulty != D2S_DIFFICULTY_NIGHTMARE ||
difficulty != D2S_DIFFICULTY_HELL) {
fprintf(stderr,"libd2char error: difficulty %d doesn't exist\n",difficulty);
return -1;
}
|
|
13
14
15
16
17
18
19
20
21
22
23
24
|
memcpy(quest,&quests[questID],sizeof(D2Quest));
quest->difficulty = difficulty;
if(questID >= D2S_QUEST_DEN_OF_EVIL && questID <= D2S_QUEST_SISTERS_TO_THE_SLAUGHTER) {
quest->questData = d->quests[difficulty].actData[D2S_ACT1].questCheckpoints[questID];
} else if(questID >= D2S_QUEST_RADAMENT_LAIR && questID <= D2S_QUEST_SEVEN_TOMBS) {
quest->questData = d->quests[difficulty].actData[D2S_ACT2].questCheckpoints[questID - D2S_QUEST_RADAMENT_LAIR];
} else if(questID >= D2S_QUEST_GOLDEN_BIRD && questID <= D2S_QUEST_GUARDIAN) {
quest->questData = d->quests[difficulty].actData[D2S_ACT3].questCheckpoints[questID - D2S_QUEST_GOLDEN_BIRD];
} else if(questID >= D2S_QUEST_FALLEN_ANGEL && questID <= D2S_QUEST_TERROR_END) {
quest->questData = d->quests[difficulty].actData[D2S_ACT4].questCheckpoints[questID - D2S_QUEST_FALLEN_ANGEL];
} else if(questID >= D2S_QUEST_SIEGE_ON_HARROGATH && questID <= D2S_QUEST_EVE_OF_DESTRUCTION) {
quest->questData = d->quests[difficulty].expansionAct.questCheckpoints[questID - D2S_QUEST_SIEGE_ON_HARROGATH];
|
|
25
|
} else {
|
|
26
|
fprintf(stderr,"libd2char error: quest %d doesn't exist\n",questID);
|
|
27
|
return -1;
|
|
28
|
}
|
|
29
|
return 0;
|
|
30
31
|
}
|
|
32
33
34
35
36
|
int setQuestData(D2QuestData* d, D2S_QUEST_IDENTIFIER questID, D2Quest* quest) {
if(quest->difficulty != D2S_DIFFICULTY_NORMAL ||
quest->difficulty != D2S_DIFFICULTY_NIGHTMARE ||
quest->difficulty != D2S_DIFFICULTY_HELL) {
fprintf(stderr,"libd2char error: difficulty %d doesn't exist\n",quest->difficulty);
|
|
37
38
|
return -1;
}
|
|
39
40
41
42
43
44
45
46
47
48
|
if(questID >= D2S_QUEST_DEN_OF_EVIL && questID <= D2S_QUEST_SISTERS_TO_THE_SLAUGHTER) {
d->quests[quest->difficulty].actData[D2S_ACT1].questCheckpoints[questID] = quest->questData;
} else if(questID >= D2S_QUEST_RADAMENT_LAIR && questID <= D2S_QUEST_SEVEN_TOMBS) {
d->quests[quest->difficulty].actData[D2S_ACT2].questCheckpoints[questID - D2S_QUEST_RADAMENT_LAIR] = quest->questData;
} else if(questID >= D2S_QUEST_GOLDEN_BIRD && questID <= D2S_QUEST_GUARDIAN) {
d->quests[quest->difficulty].actData[D2S_ACT3].questCheckpoints[questID - D2S_QUEST_GOLDEN_BIRD] = quest->questData;
} else if(questID >= D2S_QUEST_FALLEN_ANGEL && questID <= D2S_QUEST_TERROR_END) {
d->quests[quest->difficulty].actData[D2S_ACT4].questCheckpoints[questID - D2S_QUEST_FALLEN_ANGEL] = quest->questData;
} else if(questID >= D2S_QUEST_SIEGE_ON_HARROGATH && questID <= D2S_QUEST_EVE_OF_DESTRUCTION) {
d->quests[quest->difficulty].expansionAct.questCheckpoints[questID - D2S_QUEST_SIEGE_ON_HARROGATH] = quest->questData;
|
|
49
|
} else {
|
|
50
|
fprintf(stderr,"libd2char error: quest %d doesn't exist\n",questID);
|
|
51
|
return -1;
|
|
52
|
}
|
|
53
|
return 0;
|
|
54
55
|
}
|
|
56
57
|
int isQuestStarted(D2Quest* quest) {
return quest->questData & D2S_QUEST_STATUS_STARTED;
|
|
58
59
|
}
|
|
60
61
|
int isQuestRewardCollected(D2Quest* quest) {
return quest->questData & D2S_QUEST_STATUS_REWARD_AVAILABLE;
|
|
62
63
|
}
|
|
64
65
|
int isQuestCompleted(D2Quest* quest) {
return quest->questData & D2S_QUEST_STATUS_COMPLETED;
|
|
66
67
|
}
|
|
68
|
void setQuestStarted(D2Quest* quest, int bool) {
|
|
69
|
// To reset the quest, just zero out the whole thing
|
|
70
71
|
// To set as started, just set bit 2 and clear the rest
if(bool) {
|
|
72
|
quest->questData = D2S_QUEST_STATUS_STARTED;
|
|
73
|
} else {
|
|
74
|
quest->questData = 0x0000;
|
|
75
|
}
|
|
76
77
|
}
|
|
78
|
void setQuestRewardCollected(D2Quest* quest, int bool) {
|
|
79
80
|
// To reset, just clear bit 0 and set bit 1.
// Do the inverse to set reward as collected (but why whould you tho???)
|
|
81
|
if(bool) {
|
|
82
|
setQuestCompleted(quest,1);
|
|
83
|
} else {
|
|
84
85
|
setQuestCompleted(quest,0);
quest->questData |= D2S_QUEST_STATUS_REWARD_AVAILABLE;
|
|
86
|
}
|
|
87
88
|
}
|
|
89
|
void setQuestCompleted(D2Quest* quest, int bool) {
|
|
90
91
92
|
// To reset, clear bit 0, bit 12 and bit 13 (13 is kinda optional since it will be cleared by
// the game when loading the savegame).
// To set as completed, just set bit 0 and bit 12 and clear bit 1
|
|
93
|
if(bool) {
|
|
94
95
96
|
quest->questData &= ~D2S_QUEST_STATUS_REWARD_AVAILABLE;
quest->questData |= D2S_QUEST_STATUS_COMPLETED;
quest->questData |= D2S_QUEST_STATUS_SEEN_FINISH_ANIMATION;
|
|
97
|
} else {
|
|
98
99
|
quest->questData &= ~D2S_QUEST_STATUS_COMPLETED;
quest->questData &= ~D2S_QUEST_STATUS_SEEN_FINISH_ANIMATION;
|
|
100
|
}
|
|
101
102
|
}
|
|
103
104
105
106
107
108
109
|
int getSpecialQuestStatus(D2QuestData* d, D2S_SPECIALQUEST specialQuestState, D2S_DIFFICULTY difficulty) {
if(difficulty != D2S_DIFFICULTY_NORMAL ||
difficulty != D2S_DIFFICULTY_NIGHTMARE ||
difficulty != D2S_DIFFICULTY_HELL) {
fprintf(stderr,"libd2char error: difficulty %d doesn't exist\n",difficulty);
return -1;
}
|
|
110
111
112
113
114
|
int ret = 0;
switch(specialQuestState) {
case D2S_SPECIALQUEST_AKARA_RESPEC:
ret = d->quests[difficulty].akaraRespecData & D2S_QUEST_STATUS_REWARD_AVAILABLE;
break;
|
|
115
116
117
118
|
default:
fprintf(stderr,"libd2char error: invalid special quest %d\n",specialQuestState);
ret = -1;
break;
|
|
119
120
121
122
|
}
return ret;
}
|
|
123
|
int setSpecialQuestStatus(D2QuestData* d, D2S_SPECIALQUEST specialQuestState, D2S_DIFFICULTY difficulty, int bool) {
|
|
124
125
126
127
|
if(difficulty != D2S_DIFFICULTY_NORMAL ||
difficulty != D2S_DIFFICULTY_NIGHTMARE ||
difficulty != D2S_DIFFICULTY_HELL) {
fprintf(stderr,"libd2char error: difficulty %d doesn't exist\n",difficulty);
|
|
128
|
return -1;
|
|
129
|
}
|
|
130
|
int ret = 0;
|
|
131
|
D2Quest quest;
|
|
132
133
|
switch(specialQuestState) {
case D2S_SPECIALQUEST_AKARA_RESPEC:
|
|
134
|
// This operation only makes sense if the quest is actually completed, otherwise ignore request
|
|
135
136
|
getQuestData(d,D2S_QUEST_DEN_OF_EVIL,&quest,difficulty);
if(isQuestCompleted(&quest)) {
|
|
137
|
if(bool) {
|
|
138
|
d->quests[difficulty].akaraRespecData = 0x8001;
|
|
139
|
} else {
|
|
140
141
142
143
|
d->quests[difficulty].akaraRespecData = 0x2002;
}
}
break;
|
|
144
145
146
147
|
default:
fprintf(stderr,"libd2char error: invalid special quest %d\n",specialQuestState);
ret = -1;
break;
|
|
148
|
}
|
|
149
|
return ret;
|
|
150
|
}
|