[1] | 1 | // Copyright (c) Athena Dev Teams - Licensed under GNU GPL |
---|
| 2 | // For more information, see LICENCE in the main folder |
---|
| 3 | |
---|
| 4 | #include "../common/cbasetypes.h" |
---|
| 5 | #include "../common/socket.h" |
---|
| 6 | #include "../common/timer.h" |
---|
| 7 | #include "../common/malloc.h" |
---|
| 8 | #include "../common/version.h" |
---|
| 9 | #include "../common/nullpo.h" |
---|
| 10 | #include "../common/showmsg.h" |
---|
| 11 | #include "../common/strlib.h" |
---|
| 12 | #include "../common/utils.h" |
---|
| 13 | |
---|
| 14 | #include "map.h" |
---|
| 15 | #include "chrif.h" |
---|
| 16 | #include "pc.h" |
---|
| 17 | #include "npc.h" |
---|
| 18 | #include "itemdb.h" |
---|
| 19 | #include "script.h" |
---|
| 20 | #include "intif.h" |
---|
| 21 | #include "battle.h" |
---|
| 22 | #include "mob.h" |
---|
| 23 | #include "party.h" |
---|
| 24 | #include "unit.h" |
---|
| 25 | #include "log.h" |
---|
| 26 | #include "clif.h" |
---|
| 27 | #include "quest.h" |
---|
| 28 | #include "intif.h" |
---|
| 29 | |
---|
| 30 | #include <stdio.h> |
---|
| 31 | #include <stdlib.h> |
---|
| 32 | #include <string.h> |
---|
| 33 | #include <stdarg.h> |
---|
| 34 | #include <time.h> |
---|
| 35 | |
---|
| 36 | //Send quest info on login |
---|
| 37 | int quest_pc_login(TBL_PC * sd) |
---|
| 38 | { |
---|
| 39 | |
---|
| 40 | if(sd->num_quests == 0) |
---|
| 41 | return 1; |
---|
| 42 | |
---|
| 43 | clif_send_questlog(sd); |
---|
| 44 | clif_send_questlog_info(sd); |
---|
| 45 | return 0; |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | int quest_add(TBL_PC * sd, struct quest * qd) |
---|
| 49 | { |
---|
| 50 | |
---|
| 51 | int i; |
---|
| 52 | |
---|
| 53 | //Search to see if this quest exists |
---|
| 54 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == qd->quest_id); |
---|
| 55 | |
---|
| 56 | //Already have this quest |
---|
| 57 | if(i!=MAX_QUEST) |
---|
| 58 | return 1; |
---|
| 59 | |
---|
| 60 | //Find empty quest log spot |
---|
| 61 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == 0); |
---|
| 62 | |
---|
| 63 | //Quest log is full |
---|
| 64 | if(i == MAX_QUEST) |
---|
| 65 | return -1; |
---|
| 66 | |
---|
| 67 | //Copy over quest data |
---|
| 68 | memcpy(&sd->quest_log[i], qd, sizeof(struct quest)); |
---|
| 69 | sd->num_quests++; |
---|
| 70 | |
---|
| 71 | //Notify inter server |
---|
| 72 | intif_quest_add(sd->status.char_id, qd); |
---|
| 73 | |
---|
| 74 | return 0; |
---|
| 75 | |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | int quest_add_ack(int char_id, int quest_id, int success) |
---|
| 79 | { |
---|
| 80 | int i; |
---|
| 81 | TBL_PC * sd = map_charid2sd(char_id); |
---|
| 82 | |
---|
| 83 | ///Player no longer on map |
---|
| 84 | if(!sd) |
---|
| 85 | return -1; |
---|
| 86 | |
---|
| 87 | //Search for quest |
---|
| 88 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id); |
---|
| 89 | |
---|
| 90 | //Quest not found, shouldn't happen? |
---|
| 91 | if(i == MAX_QUEST) |
---|
| 92 | return -1; |
---|
| 93 | |
---|
| 94 | if(success) |
---|
| 95 | { |
---|
| 96 | //Notify client |
---|
| 97 | clif_send_quest_info(sd, &sd->quest_log[i]); |
---|
| 98 | } |
---|
| 99 | else |
---|
| 100 | { |
---|
| 101 | ShowError("Quest %d for character %d could not be added!\n", quest_id, char_id); |
---|
| 102 | |
---|
| 103 | //Zero quest |
---|
| 104 | memset(&sd->quest_log[i], 0, sizeof(struct quest)); |
---|
| 105 | sd->num_quests--; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | return 0; |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | int quest_delete(TBL_PC * sd, int quest_id) |
---|
| 112 | { |
---|
| 113 | |
---|
| 114 | int i; |
---|
| 115 | |
---|
| 116 | //Search for quest |
---|
| 117 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id); |
---|
| 118 | |
---|
| 119 | //Quest not found |
---|
| 120 | if(i == MAX_QUEST) |
---|
| 121 | return -1; |
---|
| 122 | |
---|
| 123 | intif_quest_delete(sd->status.char_id, quest_id); |
---|
| 124 | |
---|
| 125 | return 0; |
---|
| 126 | |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | int quest_delete_ack(int char_id, int quest_id, int success) |
---|
| 130 | { |
---|
| 131 | |
---|
| 132 | int i; |
---|
| 133 | TBL_PC * sd = map_charid2sd(char_id); |
---|
| 134 | |
---|
| 135 | ///Player no longer on map |
---|
| 136 | if(!sd) |
---|
| 137 | return -1; |
---|
| 138 | |
---|
| 139 | //Search for quest |
---|
| 140 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id); |
---|
| 141 | |
---|
| 142 | //Quest not found |
---|
| 143 | if(i == MAX_QUEST) |
---|
| 144 | return -1; |
---|
| 145 | |
---|
| 146 | if(success) |
---|
| 147 | { |
---|
| 148 | |
---|
| 149 | //Zero quest |
---|
| 150 | memset(&sd->quest_log[i], 0, sizeof(struct quest)); |
---|
| 151 | sd->num_quests--; |
---|
| 152 | |
---|
| 153 | //Notify client |
---|
| 154 | clif_send_quest_delete(sd, quest_id); |
---|
| 155 | |
---|
| 156 | return 1; |
---|
| 157 | |
---|
| 158 | } |
---|
| 159 | else |
---|
| 160 | ShowError("Quest %d for character %d could not be deleted!\n", quest_id, char_id); |
---|
| 161 | |
---|
| 162 | return 0; |
---|
| 163 | |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | int quest_update_objective(TBL_PC * sd, int quest_id, int objective_num, const char * name, int count) |
---|
| 167 | { |
---|
| 168 | |
---|
| 169 | int i; |
---|
| 170 | |
---|
| 171 | //Search for quest |
---|
| 172 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id); |
---|
| 173 | |
---|
| 174 | //Quest not found |
---|
| 175 | if(i == MAX_QUEST) |
---|
| 176 | return -1; |
---|
| 177 | |
---|
| 178 | memcpy(&sd->quest_log[i].objectives[objective_num].name, name, NAME_LENGTH); |
---|
| 179 | sd->quest_log[i].objectives[objective_num].count = count; |
---|
| 180 | |
---|
| 181 | //Notify client |
---|
| 182 | clif_send_quest_info(sd, &sd->quest_log[i]); |
---|
| 183 | |
---|
| 184 | return 0; |
---|
| 185 | |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | bool quest_has_quest(TBL_PC * sd, int quest_id) |
---|
| 189 | { |
---|
| 190 | int i; |
---|
| 191 | |
---|
| 192 | ARR_FIND(0, MAX_QUEST, i, sd->quest_log[i].quest_id == quest_id); |
---|
| 193 | |
---|
| 194 | return (i != MAX_QUEST); |
---|
| 195 | } |
---|
| 196 | |
---|
| 197 | int quest_update_status(TBL_PC * sd, int quest_id, bool status) |
---|
| 198 | { |
---|
| 199 | |
---|
| 200 | return 0; |
---|
| 201 | } |
---|