/
pc.c
12119 lines (10690 loc) · 369 KB
/
pc.c
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* This file is part of Hercules.
* http://herc.ws - http://github.com/HerculesWS/Hercules
*
* Copyright (C) 2012-2016 Hercules Dev Team
* Copyright (C) Athena Dev Teams
*
* Hercules is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#define HERCULES_CORE
#include "config/core.h" // DBPATH, GP_BOUND_ITEMS, MAX_SPIRITBALL, RENEWAL, RENEWAL_ASPD, RENEWAL_CAST, RENEWAL_DROP, RENEWAL_EXP, SECURE_NPCTIMEOUT
#include "pc.h"
#include "map/atcommand.h" // get_atcommand_level()
#include "map/battle.h" // battle_config
#include "map/battleground.h"
#include "map/channel.h"
#include "map/chat.h"
#include "map/chrif.h"
#include "map/clif.h"
#include "map/date.h" // is_day_of_*()
#include "map/duel.h"
#include "map/elemental.h"
#include "map/guild.h" // guild-"search(), guild_request_info()
#include "map/homunculus.h"
#include "map/instance.h"
#include "map/intif.h"
#include "map/itemdb.h"
#include "map/log.h"
#include "map/mail.h"
#include "map/map.h"
#include "map/mercenary.h"
#include "map/mob.h" // struct mob_data
#include "map/npc.h" // fake_nd
#include "map/party.h" // party-"search()
#include "map/path.h"
#include "map/pc_groups.h"
#include "map/pet.h" // pet_unlocktarget()
#include "map/quest.h"
#include "map/script.h" // script_config
#include "map/skill.h"
#include "map/status.h" // struct status_data
#include "map/storage.h"
#include "common/cbasetypes.h"
#include "common/conf.h"
#include "common/core.h" // get_svn_revision()
#include "common/HPM.h"
#include "common/memmgr.h"
#include "common/mmo.h" // NAME_LENGTH, MAX_CARTS, NEW_CARTS
#include "common/nullpo.h"
#include "common/random.h"
#include "common/showmsg.h"
#include "common/socket.h"
#include "common/sql.h"
#include "common/strlib.h" // safestrncpy()
#include "common/sysinfo.h"
#include "common/timer.h"
#include "common/utils.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
struct pc_interface pc_s;
struct pc_interface *pc;
//Converts a class to its array index for CLASS_COUNT defined arrays.
//Note that it does not do a validity check for speed purposes, where parsing
//player input make sure to use a pc->db_checkid first!
int pc_class2idx(int class_) {
if (class_ >= JOB_NOVICE_HIGH) {
class_ += - JOB_NOVICE_HIGH + JOB_MAX_BASIC;
}
Assert_ret(class_ >= 0 && class_ < CLASS_COUNT);
return class_;
}
/**
* Creates a new dummy map session data.
* Used when there is no real player attached, but it is
* required to provide a session.
* Caller must release dummy on its own when it's no longer needed.
*/
struct map_session_data* pc_get_dummy_sd(void)
{
struct map_session_data *dummy_sd;
CREATE(dummy_sd, struct map_session_data, 1);
dummy_sd->group = pcg->get_dummy_group(); // map_session_data.group is expected to be non-NULL at all times
return dummy_sd;
}
/**
* Sets player's group.
* Caller should handle error (preferably display message and disconnect).
* @param group_id Group ID
* @return 1 on error, 0 on success
*/
int pc_set_group(struct map_session_data *sd, int group_id)
{
GroupSettings *group = pcg->id2group(group_id);
nullpo_retr(1, sd);
if (group == NULL)
return 1;
sd->group_id = group_id;
sd->group = group;
return 0;
}
/**
* Checks if commands used by player should be logged.
*/
bool pc_should_log_commands(struct map_session_data *sd)
{
nullpo_retr(true, sd);
return pcg->should_log_commands(sd->group);
}
int pc_invincible_timer(int tid, int64 tick, int id, intptr_t data)
{
struct map_session_data *sd = map->id2sd(id);
if (sd == NULL)
return 1;
if(sd->invincible_timer != tid){
ShowError("invincible_timer %d != %d\n",sd->invincible_timer,tid);
return 0;
}
sd->invincible_timer = INVALID_TIMER;
skill->unit_move(&sd->bl,tick,1);
return 0;
}
void pc_setinvincibletimer(struct map_session_data* sd, int val)
{
nullpo_retv(sd);
val += map->list[sd->bl.m].invincible_time_inc;
if( sd->invincible_timer != INVALID_TIMER )
timer->delete(sd->invincible_timer,pc->invincible_timer);
sd->invincible_timer = timer->add(timer->gettick()+val,pc->invincible_timer,sd->bl.id,0);
}
void pc_delinvincibletimer(struct map_session_data* sd)
{
nullpo_retv(sd);
if( sd->invincible_timer != INVALID_TIMER )
{
timer->delete(sd->invincible_timer,pc->invincible_timer);
sd->invincible_timer = INVALID_TIMER;
skill->unit_move(&sd->bl,timer->gettick(),1);
}
}
int pc_spiritball_timer(int tid, int64 tick, int id, intptr_t data) {
struct map_session_data *sd = map->id2sd(id);
int i;
if (sd == NULL)
return 1;
if( sd->spiritball <= 0 )
{
ShowError("pc_spiritball_timer: %d spiritball's available. (aid=%d cid=%d tid=%d)\n", sd->spiritball, sd->status.account_id, sd->status.char_id, tid);
sd->spiritball = 0;
return 0;
}
ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == tid);
if( i == sd->spiritball )
{
ShowError("pc_spiritball_timer: timer not found (aid=%d cid=%d tid=%d)\n", sd->status.account_id, sd->status.char_id, tid);
return 0;
}
sd->spiritball--;
if( i != sd->spiritball )
memmove(sd->spirit_timer+i, sd->spirit_timer+i+1, (sd->spiritball-i)*sizeof(int));
sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
clif->spiritball(&sd->bl);
return 0;
}
/**
* Get the possible number of spiritball that a player can call.
* @param sd the affected player structure
* @param min the minimum number of spiritball regardless the level of MO_CALLSPIRITS
* @retval total number of spiritball
**/
int pc_getmaxspiritball(struct map_session_data *sd, int min) {
int result;
nullpo_ret(sd);
result = pc->checkskill(sd, MO_CALLSPIRITS);
if ( min && result < min )
result = min;
else if ( sd->sc.data[SC_RAISINGDRAGON] )
result += sd->sc.data[SC_RAISINGDRAGON]->val1;
if ( result > MAX_SPIRITBALL )
result = MAX_SPIRITBALL;
return result;
}
int pc_addspiritball(struct map_session_data *sd,int interval,int max)
{
int tid, i;
nullpo_ret(sd);
if(max > MAX_SPIRITBALL)
max = MAX_SPIRITBALL;
if(sd->spiritball < 0)
sd->spiritball = 0;
if( sd->spiritball && sd->spiritball >= max ) {
if(sd->spirit_timer[0] != INVALID_TIMER)
timer->delete(sd->spirit_timer[0],pc->spiritball_timer);
sd->spiritball--;
if( sd->spiritball != 0 )
memmove(sd->spirit_timer+0, sd->spirit_timer+1, (sd->spiritball)*sizeof(int));
sd->spirit_timer[sd->spiritball] = INVALID_TIMER;
}
tid = timer->add(timer->gettick()+interval, pc->spiritball_timer, sd->bl.id, 0);
ARR_FIND(0, sd->spiritball, i, sd->spirit_timer[i] == INVALID_TIMER || DIFF_TICK(timer->get(tid)->tick, timer->get(sd->spirit_timer[i])->tick) < 0);
if( i != sd->spiritball )
memmove(sd->spirit_timer+i+1, sd->spirit_timer+i, (sd->spiritball-i)*sizeof(int));
sd->spirit_timer[i] = tid;
sd->spiritball++;
if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
clif->millenniumshield(&sd->bl,sd->spiritball);
else
clif->spiritball(&sd->bl);
return 0;
}
int pc_delspiritball(struct map_session_data *sd,int count,int type)
{
int i;
nullpo_ret(sd);
if(sd->spiritball <= 0) {
sd->spiritball = 0;
return 0;
}
if(count <= 0)
return 0;
if(count > sd->spiritball)
count = sd->spiritball;
sd->spiritball -= count;
if(count > MAX_SPIRITBALL)
count = MAX_SPIRITBALL;
for(i=0;i<count;i++) {
if(sd->spirit_timer[i] != INVALID_TIMER) {
timer->delete(sd->spirit_timer[i],pc->spiritball_timer);
sd->spirit_timer[i] = INVALID_TIMER;
}
}
for(i=count;i<MAX_SPIRITBALL;i++) {
sd->spirit_timer[i-count] = sd->spirit_timer[i];
sd->spirit_timer[i] = INVALID_TIMER;
}
if(!type) {
if( (sd->class_&MAPID_THIRDMASK) == MAPID_ROYAL_GUARD )
clif->millenniumshield(&sd->bl,sd->spiritball);
else
clif->spiritball(&sd->bl);
}
return 0;
}
int pc_check_banding(struct block_list *bl, va_list ap)
{
int *c, *b_sd;
struct block_list *src;
const struct map_session_data *tsd;
struct status_change *sc;
nullpo_ret(bl);
Assert_ret(bl->type == BL_PC);
tsd = BL_UCCAST(BL_PC, bl);
nullpo_ret(src = va_arg(ap,struct block_list *));
c = va_arg(ap,int *);
b_sd = va_arg(ap, int *);
if(pc_isdead(tsd))
return 0;
sc = status->get_sc(bl);
if( sc && sc->data[SC_BANDING] )
{
b_sd[(*c)++] = tsd->bl.id;
return 1;
}
return 0;
}
int pc_banding(struct map_session_data *sd, uint16 skill_lv) {
int c;
int b_sd[MAX_PARTY]; // In case of a full Royal Guard party.
int i, j, hp, extra_hp = 0, tmp_qty = 0;
struct map_session_data *bsd;
struct status_change *sc;
int range = skill->get_splash(LG_BANDING,skill_lv);
nullpo_ret(sd);
c = 0;
memset(b_sd, 0, sizeof(b_sd));
i = party->foreachsamemap(pc->check_banding,sd,range,&sd->bl,&c,&b_sd);
if( c < 1 ) {
//just recalc status no need to recalc hp
if( (sc = status->get_sc(&sd->bl)) != NULL && sc->data[SC_BANDING] ) {
// No more Royal Guards in Banding found.
sc->data[SC_BANDING]->val2 = 0; // Reset the counter
status_calc_bl(&sd->bl, status->sc2scb_flag(SC_BANDING));
}
return 0;
}
//Add yourself
hp = status_get_hp(&sd->bl);
i++;
// Get total HP of all Royal Guards in party.
for( j = 0; j < i; j++ ) {
bsd = map->id2sd(b_sd[j]);
if( bsd != NULL )
hp += status_get_hp(&bsd->bl);
}
// Set average HP.
hp = hp / i;
// If a Royal Guard have full HP, give more HP to others that haven't full HP.
for (j = 0; j < i; j++) {
int tmp_hp;
bsd = map->id2sd(b_sd[j]);
if (bsd != NULL && (tmp_hp = hp - status_get_max_hp(&bsd->bl)) > 0) {
extra_hp += tmp_hp;
tmp_qty++;
}
}
if( extra_hp > 0 && tmp_qty > 0 )
hp += extra_hp / tmp_qty;
for( j = 0; j < i; j++ ) {
bsd = map->id2sd(b_sd[j]);
if( bsd != NULL ) {
status->set_hp(&bsd->bl,hp,0); // Set hp
if( (sc = status->get_sc(&bsd->bl)) != NULL && sc->data[SC_BANDING] ) {
sc->data[SC_BANDING]->val2 = c; // Set the counter. It doesn't count your self.
status_calc_bl(&bsd->bl, status->sc2scb_flag(SC_BANDING)); // Set atk and def.
}
}
}
return c;
}
// Increases a player's fame points and displays a notice to him
void pc_addfame(struct map_session_data *sd,int count)
{
int ranktype = -1;
nullpo_retv(sd);
sd->status.fame += count;
if(sd->status.fame > MAX_FAME)
sd->status.fame = MAX_FAME;
switch(sd->class_&MAPID_UPPERMASK){
case MAPID_BLACKSMITH: ranktype = RANKTYPE_BLACKSMITH; break;
case MAPID_ALCHEMIST: ranktype = RANKTYPE_ALCHEMIST; break;
case MAPID_TAEKWON: ranktype = RANKTYPE_TAEKWON; break;
}
clif->update_rankingpoint(sd, ranktype, count);
chrif->updatefamelist(sd);
}
// Check whether a player ID is in the fame rankers' list of its job, returns his/her position if so, 0 else
unsigned char pc_famerank(int char_id, int job)
{
int i;
switch(job){
case MAPID_BLACKSMITH: // Blacksmith
for(i = 0; i < MAX_FAME_LIST; i++){
if(pc->smith_fame_list[i].id == char_id)
return i + 1;
}
break;
case MAPID_ALCHEMIST: // Alchemist
for(i = 0; i < MAX_FAME_LIST; i++){
if(pc->chemist_fame_list[i].id == char_id)
return i + 1;
}
break;
case MAPID_TAEKWON: // Taekwon
for(i = 0; i < MAX_FAME_LIST; i++){
if(pc->taekwon_fame_list[i].id == char_id)
return i + 1;
}
break;
}
return 0;
}
int pc_setrestartvalue(struct map_session_data *sd,int type) {
struct status_data *st, *bst;
nullpo_ret(sd);
bst = &sd->base_status;
st = &sd->battle_status;
if (type&1) {
//Normal resurrection
st->hp = 1; //Otherwise status->heal may fail if dead.
status->heal(&sd->bl, bst->hp, 0, 1);
if( st->sp < bst->sp )
status->set_sp(&sd->bl, bst->sp, 1);
} else { //Just for saving on the char-server (with values as if respawned)
sd->status.hp = bst->hp;
sd->status.sp = (st->sp < bst->sp) ? bst->sp : st->sp;
}
return 0;
}
/*==========================================
Rental System
*------------------------------------------*/
int pc_inventory_rental_end(int tid, int64 tick, int id, intptr_t data) {
struct map_session_data *sd = map->id2sd(id);
if( sd == NULL )
return 0;
if( tid != sd->rental_timer )
{
ShowError("pc_inventory_rental_end: invalid timer id.\n");
return 0;
}
pc->inventory_rentals(sd);
return 1;
}
int pc_inventory_rental_clear(struct map_session_data *sd)
{
nullpo_ret(sd);
if( sd->rental_timer != INVALID_TIMER )
{
timer->delete(sd->rental_timer, pc->inventory_rental_end);
sd->rental_timer = INVALID_TIMER;
}
return 1;
}
/* assumes i is valid (from default areas where it is called, it is) */
void pc_rental_expire(struct map_session_data *sd, int i) {
short nameid;
nullpo_retv(sd);
Assert_retv(i >= 0 && i < MAX_INVENTORY);
nameid = sd->status.inventory[i].nameid;
/* Soon to be dropped, we got plans to integrate it with item db */
switch( nameid ) {
case ITEMID_REINS_OF_MOUNT:
status_change_end(&sd->bl,SC_ALL_RIDING,INVALID_TIMER);
break;
case ITEMID_LOVE_ANGEL:
if( sd->status.font == 1 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_SQUIRREL:
if( sd->status.font == 2 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_GOGO:
if( sd->status.font == 3 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_PICTURE_DIARY:
if( sd->status.font == 4 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_MINI_HEART:
if( sd->status.font == 5 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_NEWCOMER:
if( sd->status.font == 6 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_KID:
if( sd->status.font == 7 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_MAGIC_CASTLE:
if( sd->status.font == 8 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
case ITEMID_BULGING_HEAD:
if( sd->status.font == 9 ) {
sd->status.font = 0;
clif->font(sd);
}
break;
}
clif->rental_expired(sd->fd, i, sd->status.inventory[i].nameid);
pc->delitem(sd, i, sd->status.inventory[i].amount, 0, DELITEM_NORMAL, LOG_TYPE_RENTAL);
}
void pc_inventory_rentals(struct map_session_data *sd)
{
int i, c = 0;
int64 expire_tick, next_tick = INT64_MAX;
nullpo_retv(sd);
for( i = 0; i < MAX_INVENTORY; i++ )
{ // Check for Rentals on Inventory
if( sd->status.inventory[i].nameid == 0 )
continue; // Nothing here
if( sd->status.inventory[i].expire_time == 0 )
continue;
if( sd->status.inventory[i].expire_time <= time(NULL) ) {
pc->rental_expire(sd,i);
} else {
expire_tick = (int64)(sd->status.inventory[i].expire_time - time(NULL)) * 1000;
clif->rental_time(sd->fd, sd->status.inventory[i].nameid, (int)(expire_tick / 1000));
next_tick = min(expire_tick, next_tick);
c++;
}
}
if( c > 0 ) // min(next_tick,3600000) 1 hour each timer to keep announcing to the owner, and to avoid a but with rental time > 15 days
sd->rental_timer = timer->add(timer->gettick() + min(next_tick,3600000), pc->inventory_rental_end, sd->bl.id, 0);
else
sd->rental_timer = INVALID_TIMER;
}
void pc_inventory_rental_add(struct map_session_data *sd, int seconds)
{
int tick = seconds * 1000;
if( sd == NULL )
return;
if( sd->rental_timer != INVALID_TIMER )
{
const struct TimerData * td;
td = timer->get(sd->rental_timer);
if( DIFF_TICK(td->tick, timer->gettick()) > tick )
{ // Update Timer as this one ends first than the current one
pc->inventory_rental_clear(sd);
sd->rental_timer = timer->add(timer->gettick() + tick, pc->inventory_rental_end, sd->bl.id, 0);
}
}
else
sd->rental_timer = timer->add(timer->gettick() + min(tick,3600000), pc->inventory_rental_end, sd->bl.id, 0);
}
/*==========================================
* prepares character for saving.
*------------------------------------------*/
int pc_makesavestatus(struct map_session_data *sd)
{
nullpo_ret(sd);
if(!battle_config.save_clothcolor)
sd->status.clothes_color=0;
if (!battle_config.save_body_style)
sd->status.body = 0;
//Only copy the Cart/Peco/Falcon options, the rest are handled via
//status change load/saving. [Skotlex]
#ifdef NEW_CARTS
sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
#else
sd->status.option = sd->sc.option&(OPTION_INVISIBLE|OPTION_CART|OPTION_FALCON|OPTION_RIDING|OPTION_DRAGON|OPTION_WUG|OPTION_WUGRIDER|OPTION_MADOGEAR);
#endif
if (sd->sc.data[SC_JAILED]) { //When Jailed, do not move last point.
if(pc_isdead(sd)){
pc->setrestartvalue(sd,0);
} else {
sd->status.hp = sd->battle_status.hp;
sd->status.sp = sd->battle_status.sp;
}
sd->status.last_point.map = sd->mapindex;
sd->status.last_point.x = sd->bl.x;
sd->status.last_point.y = sd->bl.y;
return 0;
}
if(pc_isdead(sd)){
pc->setrestartvalue(sd,0);
memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
} else {
sd->status.hp = sd->battle_status.hp;
sd->status.sp = sd->battle_status.sp;
sd->status.last_point.map = sd->mapindex;
sd->status.last_point.x = sd->bl.x;
sd->status.last_point.y = sd->bl.y;
}
if( ( map->list[sd->bl.m].flag.nosave && sd->state.autotrade != 2 ) || map->list[sd->bl.m].instance_id >= 0) {
struct map_data *m=&map->list[sd->bl.m];
if(m->save.map)
memcpy(&sd->status.last_point,&m->save,sizeof(sd->status.last_point));
else
memcpy(&sd->status.last_point,&sd->status.save_point,sizeof(sd->status.last_point));
}
if( sd->status.last_point.map == 0 ) {
sd->status.last_point.map = 1;
sd->status.last_point.x = 0;
sd->status.last_point.y = 0;
}
if( sd->status.save_point.map == 0 ) {
sd->status.save_point.map = 1;
sd->status.save_point.x = 0;
sd->status.save_point.y = 0;
}
return 0;
}
/*==========================================
* Off init ? Connection?
*------------------------------------------*/
int pc_setnewpc(struct map_session_data *sd, int account_id, int char_id, int login_id1, unsigned int client_tick, int sex, int fd)
{
nullpo_ret(sd);
sd->bl.id = account_id;
sd->status.account_id = account_id;
sd->status.char_id = char_id;
sd->status.sex = sex;
sd->login_id1 = login_id1;
sd->login_id2 = 0; // at this point, we can not know the value :(
sd->client_tick = client_tick;
sd->state.active = 0; //to be set to 1 after player is fully authed and loaded.
sd->bl.type = BL_PC;
sd->canlog_tick = timer->gettick();
//Required to prevent homunculus copuing a base speed of 0.
sd->battle_status.speed = sd->base_status.speed = DEFAULT_WALK_SPEED;
sd->state.warp_clean = 1;
sd->catch_target_class = -1;
return 0;
}
int pc_equippoint(struct map_session_data *sd,int n)
{
int ep = 0;
nullpo_ret(sd);
Assert_ret(n >= 0 && n < MAX_INVENTORY);
if(!sd->inventory_data[n])
return 0;
if (!itemdb->isequip2(sd->inventory_data[n]))
return 0; //Not equippable by players.
ep = sd->inventory_data[n]->equip;
if (sd->inventory_data[n]->look == W_DAGGER
|| sd->inventory_data[n]->look == W_1HSWORD
|| sd->inventory_data[n]->look == W_1HAXE
) {
if (pc->checkskill(sd,AS_LEFT) > 0
|| (sd->class_&MAPID_UPPERMASK) == MAPID_ASSASSIN
|| (sd->class_&MAPID_UPPERMASK) == MAPID_KAGEROUOBORO
) {
//Kagerou and Oboro can dual wield daggers. [Rytech]
if( ep == EQP_HAND_R )
return EQP_ARMS;
if( ep == EQP_SHADOW_WEAPON )
return EQP_SHADOW_ARMS;
}
}
return ep;
}
int pc_setinventorydata(struct map_session_data *sd)
{
int i;
nullpo_ret(sd);
for (i = 0; i < MAX_INVENTORY; i++) {
int id = sd->status.inventory[i].nameid;
sd->inventory_data[i] = id?itemdb->search(id):NULL;
}
return 0;
}
int pc_calcweapontype(struct map_session_data *sd)
{
nullpo_ret(sd);
// single-hand
if(sd->weapontype2 == W_FIST) {
sd->status.weapon = sd->weapontype1;
return 1;
}
if(sd->weapontype1 == W_FIST) {
sd->status.weapon = sd->weapontype2;
return 1;
}
// dual-wield
sd->status.weapon = 0;
switch (sd->weapontype1){
case W_DAGGER:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DD; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_DS; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_DA; break;
}
break;
case W_1HSWORD:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DS; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_SS; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_SA; break;
}
break;
case W_1HAXE:
switch (sd->weapontype2) {
case W_DAGGER: sd->status.weapon = W_DOUBLE_DA; break;
case W_1HSWORD: sd->status.weapon = W_DOUBLE_SA; break;
case W_1HAXE: sd->status.weapon = W_DOUBLE_AA; break;
}
}
// unknown, default to right hand type
if (!sd->status.weapon)
sd->status.weapon = sd->weapontype1;
return 2;
}
int pc_setequipindex(struct map_session_data *sd)
{
int i,j;
nullpo_ret(sd);
for(i=0;i<EQI_MAX;i++)
sd->equip_index[i] = -1;
for(i=0;i<MAX_INVENTORY;i++) {
if(sd->status.inventory[i].nameid <= 0)
continue;
if(sd->status.inventory[i].equip) {
for(j=0;j<EQI_MAX;j++)
if(sd->status.inventory[i].equip & pc->equip_pos[j])
sd->equip_index[j] = i;
if(sd->status.inventory[i].equip & EQP_HAND_R)
{
if(sd->inventory_data[i])
sd->weapontype1 = sd->inventory_data[i]->look;
else
sd->weapontype1 = 0;
}
if( sd->status.inventory[i].equip & EQP_HAND_L )
{
if( sd->inventory_data[i] && sd->inventory_data[i]->type == IT_WEAPON )
sd->weapontype2 = sd->inventory_data[i]->look;
else
sd->weapontype2 = 0;
}
}
}
pc->calcweapontype(sd);
return 0;
}
bool pc_isequipped(struct map_session_data *sd, int nameid)
{
int i, j;
nullpo_retr(false, sd);
for (i = 0; i < EQI_MAX; i++) {
int index = sd->equip_index[i];
if( index < 0 ) continue;
if( i == EQI_HAND_R && sd->equip_index[EQI_HAND_L] == index ) continue;
if( i == EQI_HEAD_MID && sd->equip_index[EQI_HEAD_LOW] == index ) continue;
if( i == EQI_HEAD_TOP && (sd->equip_index[EQI_HEAD_MID] == index || sd->equip_index[EQI_HEAD_LOW] == index) ) continue;
if( !sd->inventory_data[index] ) continue;
if( sd->inventory_data[index]->nameid == nameid )
return true;
for( j = 0; j < sd->inventory_data[index]->slot; j++ )
if( sd->status.inventory[index].card[j] == nameid )
return true;
}
return false;
}
bool pc_can_Adopt(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd )
{
if( !p1_sd || !p2_sd || !b_sd )
return false;
if( b_sd->status.father || b_sd->status.mother || b_sd->adopt_invite )
return false; // already adopted baby / in adopt request
if( !p1_sd->status.partner_id || !p1_sd->status.party_id || p1_sd->status.party_id != b_sd->status.party_id )
return false; // You need to be married and in party with baby to adopt
if( p1_sd->status.partner_id != p2_sd->status.char_id || p2_sd->status.partner_id != p1_sd->status.char_id )
return false; // Not married, wrong married
if( p2_sd->status.party_id != p1_sd->status.party_id )
return false; // Both parents need to be in the same party
// Parents need to have their ring equipped
if( !pc->isequipped(p1_sd, WEDDING_RING_M) && !pc->isequipped(p1_sd, WEDDING_RING_F) )
return false;
if( !pc->isequipped(p2_sd, WEDDING_RING_M) && !pc->isequipped(p2_sd, WEDDING_RING_F) )
return false;
// Already adopted a baby
if( p1_sd->status.child || p2_sd->status.child ) {
clif->adopt_reply(p1_sd, 0);
return false;
}
// Parents need at least lvl 70 to adopt
if( p1_sd->status.base_level < 70 || p2_sd->status.base_level < 70 ) {
clif->adopt_reply(p1_sd, 1);
return false;
}
if( b_sd->status.partner_id ) {
clif->adopt_reply(p1_sd, 2);
return false;
}
if( !( ( b_sd->status.class_ >= JOB_NOVICE && b_sd->status.class_ <= JOB_THIEF ) || b_sd->status.class_ == JOB_SUPER_NOVICE ) )
return false;
return true;
}
/*==========================================
* Adoption Process
*------------------------------------------*/
bool pc_adoption(struct map_session_data *p1_sd, struct map_session_data *p2_sd, struct map_session_data *b_sd)
{
int job, joblevel;
unsigned int jobexp;
if( !pc->can_Adopt(p1_sd, p2_sd, b_sd) )
return false;
nullpo_retr(false, b_sd);
// Preserve current job levels and progress
joblevel = b_sd->status.job_level;
jobexp = b_sd->status.job_exp;
job = pc->mapid2jobid(b_sd->class_|JOBL_BABY, b_sd->status.sex);
if( job != -1 && !pc->jobchange(b_sd, job, 0) )
{ // Success, proceed to configure parents and baby skills
p1_sd->status.child = b_sd->status.char_id;
p2_sd->status.child = b_sd->status.char_id;
b_sd->status.father = p1_sd->status.char_id;
b_sd->status.mother = p2_sd->status.char_id;
// Restore progress
b_sd->status.job_level = joblevel;
clif->updatestatus(b_sd, SP_JOBLEVEL);
b_sd->status.job_exp = jobexp;
clif->updatestatus(b_sd, SP_JOBEXP);
// Baby Skills
pc->skill(b_sd, WE_BABY, 1, SKILL_GRANT_PERMANENT);
pc->skill(b_sd, WE_CALLPARENT, 1, SKILL_GRANT_PERMANENT);
// Parents Skills
pc->skill(p1_sd, WE_CALLBABY, 1, SKILL_GRANT_PERMANENT);
pc->skill(p2_sd, WE_CALLBABY, 1, SKILL_GRANT_PERMANENT);
return true;
}
return false; // Job Change Fail
}
/*=================================================
* Checks if the player can equip the item at index n in inventory.
* Returns 0 (no) or 1 (yes).
*------------------------------------------------*/
int pc_isequip(struct map_session_data *sd,int n)
{
struct item_data *item;
nullpo_ret(sd);
item = sd->inventory_data[n];
if(item == NULL)
return 0;
#if PACKETVER <= 20100707
if (itemdb_is_shadowequip(item->equip) || itemdb_is_costumeequip(item->equip))
return 0;
#endif
if(pc_has_permission(sd, PC_PERM_USE_ALL_EQUIPMENT))
return 1;
if (item->elv && sd->status.base_level < item->elv) {
clif->msgtable(sd, MSG_ITEM_CANT_EQUIP_LVL);
return 0;
}
if (item->elvmax && sd->status.base_level > item->elvmax) {
clif->msgtable(sd, MSG_ITEM_CANT_EQUIP_LVL);
return 0;
}
if(item->sex != 2 && sd->status.sex != item->sex)
return 0;
if ( item->equip & EQP_AMMO ) {
if ( (sd->state.active && !pc_iscarton(sd)) // check if sc data is already loaded.
&& (sd->status.class_ == JOB_GENETIC_T || sd->status.class_ == JOB_GENETIC) ) {
clif->msgtable(sd, MSG_ITEM_NEED_CART);
return 0;
}
if ( !pc_ismadogear(sd) && (sd->status.class_ == JOB_MECHANIC_T || sd->status.class_ == JOB_MECHANIC) ) {
clif->msgtable(sd, MSG_ITEM_NEED_MADO);
return 0;
}
}
if (sd->sc.count) {
if(item->equip & EQP_ARMS && item->type == IT_WEAPON && sd->sc.data[SC_NOEQUIPWEAPON]) // Also works with left-hand weapons [DracoRPG]
return 0;
if(item->equip & EQP_SHIELD && item->type == IT_ARMOR && sd->sc.data[SC_NOEQUIPSHIELD])
return 0;
if(item->equip & EQP_ARMOR && sd->sc.data[SC_NOEQUIPARMOR])
return 0;
if(item->equip & EQP_HEAD_TOP && sd->sc.data[SC_NOEQUIPHELM])
return 0;
if(item->equip & EQP_ACC && sd->sc.data[SC__STRIPACCESSARY])
return 0;
if(item->equip && sd->sc.data[SC_KYOUGAKU])
return 0;
if (sd->sc.data[SC_SOULLINK] && sd->sc.data[SC_SOULLINK]->val2 == SL_SUPERNOVICE) {