party.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #include "../common/cbasetypes.h"
  4. #include "../common/timer.h"
  5. #include "../common/socket.h" // last_tick
  6. #include "../common/nullpo.h"
  7. #include "../common/malloc.h"
  8. #include "../common/showmsg.h"
  9. #include "../common/utils.h"
  10. #include "party.h"
  11. #include "atcommand.h" //msg_txt()
  12. #include "pc.h"
  13. #include "map.h"
  14. #include "battle.h"
  15. #include "intif.h"
  16. #include "clif.h"
  17. #include "log.h"
  18. #include "skill.h"
  19. #include "status.h"
  20. #include "itemdb.h"
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. static DBMap* party_db; // int party_id -> struct party_data*
  25. int party_share_level = 10;
  26. int party_send_xy_timer(int tid,unsigned int tick,int id,int data);
  27. /*==========================================
  28. * Fills the given party_member structure according to the sd provided.
  29. * Used when creating/adding people to a party. [Skotlex]
  30. *------------------------------------------*/
  31. static void party_fill_member(struct party_member *member, struct map_session_data *sd)
  32. {
  33. member->account_id = sd->status.account_id;
  34. member->char_id = sd->status.char_id;
  35. memcpy(member->name, sd->status.name, NAME_LENGTH);
  36. member->class_ = sd->status.class_;
  37. member->map = sd->mapindex;
  38. member->lv = sd->status.base_level;
  39. member->online = 1;
  40. member->leader = 0;
  41. }
  42. /*==========================================
  43. * �I—¹
  44. *------------------------------------------*/
  45. void do_final_party(void)
  46. {
  47. party_db->destroy(party_db,NULL);
  48. }
  49. // �‰Šú‰»
  50. void do_init_party(void)
  51. {
  52. party_db = idb_alloc(DB_OPT_RELEASE_DATA);
  53. add_timer_func_list(party_send_xy_timer, "party_send_xy_timer");
  54. add_timer_interval(gettick()+battle_config.party_update_interval, party_send_xy_timer, 0, 0, battle_config.party_update_interval);
  55. }
  56. /// Party data lookup using party id.
  57. struct party_data* party_search(int party_id)
  58. {
  59. if(!party_id)
  60. return NULL;
  61. return idb_get(party_db,party_id);
  62. }
  63. /// Party data lookup using party name.
  64. struct party_data* party_searchname(const char* str)
  65. {
  66. struct party_data* p;
  67. DBIterator* iter = party_db->iterator(party_db);
  68. for( p = iter->first(iter,NULL); iter->exists(iter); p = iter->next(iter,NULL) )
  69. {
  70. if( strncmpi(p->party.name,str,NAME_LENGTH) == 0 )
  71. break;
  72. }
  73. iter->destroy(iter);
  74. return p;
  75. }
  76. int party_create(struct map_session_data *sd,char *name,int item,int item2)
  77. {
  78. struct party_member leader;
  79. if(sd->status.party_id) {
  80. clif_party_created(sd,2);
  81. return 0; // "already in a party"
  82. }
  83. party_fill_member(&leader, sd);
  84. leader.leader = 1;
  85. intif_create_party(&leader,name,item,item2);
  86. return 0;
  87. }
  88. int party_created(int account_id,int char_id,int fail,int party_id,char *name)
  89. {
  90. struct map_session_data *sd;
  91. struct party_data *p;
  92. sd=map_id2sd(account_id);
  93. nullpo_retr(0, sd);
  94. if (sd->status.char_id != char_id)
  95. return 0; //unlikely failure...
  96. if(fail){
  97. clif_party_created(sd,1);
  98. return 0; // "party name already exists"
  99. }
  100. sd->status.party_id=party_id;
  101. if(idb_get(party_db,party_id)!=NULL){
  102. ShowFatalError("party: id already exists!\n");
  103. exit(EXIT_FAILURE);
  104. }
  105. p=(struct party_data *)aCalloc(1,sizeof(struct party_data));
  106. p->party.party_id=party_id;
  107. memcpy(p->party.name, name, NAME_LENGTH);
  108. idb_put(party_db,party_id,p);
  109. clif_party_created(sd,0); //Success message
  110. clif_charnameupdate(sd); //Update other people's display. [Skotlex]
  111. return 1;
  112. }
  113. int party_request_info(int party_id)
  114. {
  115. return intif_request_partyinfo(party_id);
  116. }
  117. /// Checks if each char having a party actually belongs to that party.
  118. /// If check fails, the char is marked as 'not in a party'.
  119. int party_check_member(struct party *p)
  120. {
  121. int i, users;
  122. struct map_session_data *sd, **all_sd;
  123. nullpo_retr(0, p);
  124. all_sd = map_getallusers(&users);
  125. for(i=0;i<users;i++)
  126. {
  127. sd = all_sd[i];
  128. if( sd && sd->status.party_id == p->party_id )
  129. {
  130. int j;
  131. ARR_FIND( 0, MAX_PARTY, j, p->member[j].account_id == sd->status.account_id && p->member[j].char_id == sd->status.char_id );
  132. if( j == MAX_PARTY )
  133. {
  134. ShowWarning("party_check_member: '%s' (acc:%d) is not member of party '%s' (id:%d)\n",sd->status.name,sd->status.account_id,p->name,p->party_id);
  135. sd->status.party_id = 0;
  136. }
  137. }
  138. }
  139. return 0;
  140. }
  141. /// Marks all chars belonging to this party as 'not in a party'.
  142. int party_recv_noinfo(int party_id)
  143. {
  144. int i, users;
  145. struct map_session_data *sd, **all_sd;
  146. all_sd = map_getallusers(&users);
  147. for(i=0;i<users;i++){
  148. if((sd = all_sd[i]) && sd->status.party_id==party_id)
  149. sd->status.party_id=0;
  150. }
  151. return 0;
  152. }
  153. static void* create_party(DBKey key, va_list args)
  154. {
  155. struct party_data *p;
  156. p=(struct party_data *)aCalloc(1,sizeof(struct party_data));
  157. return p;
  158. }
  159. static void party_check_state(struct party_data *p)
  160. {
  161. int i;
  162. memset(&p->state, 0, sizeof(p->state));
  163. for (i = 0; i < MAX_PARTY; i ++)
  164. {
  165. if (!p->party.member[i].online) continue; //Those not online shouldn't aport to skill usage and all that.
  166. switch (p->party.member[i].class_) {
  167. case JOB_MONK:
  168. case JOB_BABY_MONK:
  169. case JOB_CHAMPION:
  170. p->state.monk = 1;
  171. break;
  172. case JOB_STAR_GLADIATOR:
  173. p->state.sg = 1;
  174. break;
  175. case JOB_SUPER_NOVICE:
  176. case JOB_SUPER_BABY:
  177. p->state.snovice = 1;
  178. break;
  179. case JOB_TAEKWON:
  180. p->state.tk = 1;
  181. break;
  182. }
  183. }
  184. }
  185. int party_recv_info(struct party *sp)
  186. {
  187. struct map_session_data *sd;
  188. struct party_data *p;
  189. int i;
  190. nullpo_retr(0, sp);
  191. p= idb_ensure(party_db, sp->party_id, create_party);
  192. if (!p->party.party_id) //party just received.
  193. party_check_member(sp);
  194. memcpy(&p->party,sp,sizeof(struct party));
  195. memset(&p->state, 0, sizeof(p->state));
  196. memset(&p->data, 0, sizeof(p->data));
  197. for(i=0;i<MAX_PARTY;i++){
  198. if (!p->party.member[i].account_id)
  199. continue;
  200. sd = map_id2sd(p->party.member[i].account_id);
  201. if (sd && sd->status.party_id==p->party.party_id
  202. && sd->status.char_id == p->party.member[i].char_id
  203. && sd->state.auth && !sd->state.waitingdisconnect)
  204. p->data[i].sd = sd;
  205. }
  206. party_check_state(p);
  207. for(i=0;i<MAX_PARTY;i++){
  208. sd = p->data[i].sd;
  209. if(!sd || sd->state.party_sent)
  210. continue;
  211. clif_party_member_info(p,sd);
  212. clif_party_option(p,sd,0x100);
  213. clif_party_info(p,NULL);
  214. sd->state.party_sent=1;
  215. }
  216. return 0;
  217. }
  218. int party_invite(struct map_session_data *sd,struct map_session_data *tsd)
  219. {
  220. struct party_data *p=party_search(sd->status.party_id);
  221. int i,flag=0;
  222. nullpo_retr(0, sd);
  223. if (p==NULL)
  224. return 0;
  225. if(tsd==NULL) { //TODO: Find the correct reply packet.
  226. clif_displaymessage(sd->fd, msg_txt(3));
  227. return 0;
  228. }
  229. //Only leader can invite.
  230. ARR_FIND(0, MAX_PARTY, i, p->data[i].sd == sd);
  231. if (i == MAX_PARTY || !p->party.member[i].leader)
  232. { //TODO: Find the correct reply packet.
  233. clif_displaymessage(sd->fd, msg_txt(282));
  234. return 0;
  235. }
  236. if(!battle_config.invite_request_check) {
  237. if (tsd->guild_invite>0 || tsd->trade_partner) {
  238. clif_party_inviteack(sd,tsd->status.name,0);
  239. return 0;
  240. }
  241. }
  242. if (!tsd->fd) { //You can't invite someone who has already disconnected.
  243. clif_party_inviteack(sd,tsd->status.name,1);
  244. return 0;
  245. }
  246. if( tsd->status.party_id>0 || tsd->party_invite>0 ){
  247. clif_party_inviteack(sd,tsd->status.name,0);
  248. return 0;
  249. }
  250. for(i=0;i<MAX_PARTY;i++){
  251. if(p->party.member[i].account_id == 0) //Room for a new member.
  252. flag = 1;
  253. /* By default Aegis BLOCKS more than one char from the same account on a party.
  254. * But eA does support it... so this check is left commented.
  255. if(p->party.member[i].account_id==tsd->status.account_id)
  256. {
  257. clif_party_inviteack(sd,tsd->status.name,4);
  258. return 0;
  259. }
  260. */
  261. }
  262. if (!flag) { //Full party.
  263. clif_party_inviteack(sd,tsd->status.name,3);
  264. return 0;
  265. }
  266. tsd->party_invite=sd->status.party_id;
  267. tsd->party_invite_account=sd->status.account_id;
  268. clif_party_invite(sd,tsd);
  269. return 1;
  270. }
  271. int party_reply_invite(struct map_session_data *sd,int account_id,int flag)
  272. {
  273. struct map_session_data *tsd= map_id2sd(account_id);
  274. struct party_member member;
  275. if(flag==1){
  276. party_fill_member(&member, sd);
  277. intif_party_addmember(sd->party_invite, &member);
  278. return 0;
  279. }
  280. sd->party_invite=0;
  281. sd->party_invite_account=0;
  282. if(tsd==NULL)
  283. return 0;
  284. clif_party_inviteack(tsd,sd->status.name,1);
  285. return 1;
  286. }
  287. /// Invoked (from char-server) when a new member is added to the party.
  288. int party_member_added(int party_id,int account_id,int char_id, int flag)
  289. {
  290. struct map_session_data *sd = map_id2sd(account_id),*sd2;
  291. struct party_data *p = party_search(party_id);
  292. int i;
  293. if(sd == NULL || sd->status.char_id != char_id){
  294. if (flag == 0) {
  295. ShowError("party: member added error %d is not online\n",account_id);
  296. intif_party_leave(party_id,account_id,char_id);
  297. }
  298. return 0;
  299. }
  300. sd->party_invite=0;
  301. sd->party_invite_account=0;
  302. if (!p) {
  303. ShowError("party_member_added: party %d not found.\n",party_id);
  304. intif_party_leave(party_id,account_id,char_id);
  305. return 0;
  306. }
  307. if(!flag) {
  308. sd->state.party_sent=0;
  309. sd->status.party_id=party_id;
  310. party_check_conflict(sd);
  311. clif_party_member_info(p,sd);
  312. for( i = 0; i < ARRAYLENGTH(p->data); ++i )
  313. {// hp of the other party members
  314. sd2 = p->data[i].sd;
  315. if( sd2 && sd2->status.account_id != account_id && sd2->status.char_id != char_id )
  316. clif_hpmeter_single(sd->fd, sd2->bl.id, sd2->battle_status.hp, sd2->battle_status.max_hp);
  317. }
  318. clif_party_hp(sd);
  319. clif_party_xy(sd);
  320. clif_charnameupdate(sd); //Update char name's display [Skotlex]
  321. }
  322. sd2=map_id2sd(sd->party_invite_account);
  323. if (sd2)
  324. clif_party_inviteack(sd2,sd->status.name,flag?2:1);
  325. return 0;
  326. }
  327. /// Party member 'sd' requesting kick of member with <account_id, name>.
  328. int party_removemember(struct map_session_data* sd, int account_id, char* name)
  329. {
  330. struct party_data *p;
  331. int i;
  332. p = party_search(sd->status.party_id);
  333. if( p == NULL )
  334. return 0;
  335. // check the requesting char's party membership
  336. ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == sd->status.account_id && p->party.member[i].char_id == sd->status.char_id );
  337. if( i == MAX_PARTY )
  338. return 0; // request from someone not in party? o.O
  339. if( !p->party.member[i].leader )
  340. return 0; // only party leader may remove members
  341. ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && strncmp(p->party.member[i].name,name,NAME_LENGTH) == 0 );
  342. if( i == MAX_PARTY )
  343. return 0; // no such char in party
  344. intif_party_leave(p->party.party_id,account_id,p->party.member[i].char_id);
  345. return 1;
  346. }
  347. /// Party member 'sd' requesting exit from party.
  348. int party_leave(struct map_session_data *sd)
  349. {
  350. struct party_data *p;
  351. int i;
  352. p = party_search(sd->status.party_id);
  353. if( p == NULL )
  354. return 0;
  355. ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == sd->status.account_id && p->party.member[i].char_id == sd->status.char_id );
  356. if( i == MAX_PARTY )
  357. return 0;
  358. intif_party_leave(p->party.party_id,sd->status.account_id,sd->status.char_id);
  359. return 1;
  360. }
  361. /// Invoked (from char-server) when a party member leaves the party.
  362. int party_member_leaved(int party_id, int account_id, int char_id)
  363. {
  364. struct map_session_data* sd = map_id2sd(account_id);
  365. struct party_data* p = party_search(party_id);
  366. int i;
  367. if( p )
  368. {
  369. ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id );
  370. if( i < MAX_PARTY )
  371. {
  372. clif_party_leaved(p,sd,account_id,p->party.member[i].name,0x00);
  373. memset(&p->party.member[i], 0, sizeof(p->party.member[0]));
  374. memset(&p->data[i], 0, sizeof(p->data[0]));
  375. p->party.count--;
  376. party_check_state(p);
  377. }
  378. }
  379. if( sd && sd->status.party_id == party_id && sd->status.char_id == char_id )
  380. {
  381. sd->status.party_id = 0;
  382. sd->state.party_sent = 0;
  383. clif_charnameupdate(sd); //Update name display [Skotlex]
  384. //TODO: hp bars should be cleared too
  385. }
  386. return 0;
  387. }
  388. /// Invoked (from char-server) when a party is disbanded.
  389. int party_broken(int party_id)
  390. {
  391. struct party_data* p;
  392. int i;
  393. p = party_search(party_id);
  394. if( p == NULL )
  395. return 0;
  396. for(i=0;i<MAX_PARTY;i++){
  397. if(p->data[i].sd!=NULL){
  398. clif_party_leaved(p,p->data[i].sd,p->party.member[i].account_id,p->party.member[i].name,0x10);
  399. p->data[i].sd->status.party_id=0;
  400. p->data[i].sd->state.party_sent=0;
  401. }
  402. }
  403. idb_remove(party_db,party_id);
  404. return 0;
  405. }
  406. int party_changeoption(struct map_session_data *sd,int exp,int item)
  407. {
  408. nullpo_retr(0, sd);
  409. if( sd->status.party_id==0)
  410. return 0;
  411. intif_party_changeoption(sd->status.party_id,sd->status.account_id,exp,item);
  412. return 0;
  413. }
  414. int party_optionchanged(int party_id,int account_id,int exp,int item,int flag)
  415. {
  416. struct party_data *p;
  417. struct map_session_data *sd=map_id2sd(account_id);
  418. if( (p=party_search(party_id))==NULL)
  419. return 0;
  420. if(!(flag&0x01) && p->party.exp != exp) {
  421. p->party.exp=exp;
  422. clif_party_option(p,sd,flag); //This packet doesn't updates item info anymore...
  423. }
  424. if(!(flag&0x10) && p->party.item != item) {
  425. p->party.item=item;
  426. clif_party_member_info(p,sd);
  427. }
  428. if(flag&0x01) //Send denied message
  429. clif_party_option(p,sd,flag);
  430. return 0;
  431. }
  432. /// Invoked (from char-server) when a party member
  433. /// - changes maps
  434. /// - logs in or out
  435. /// - gains a level (disabled)
  436. int party_recv_movemap(int party_id,int account_id,int char_id, unsigned short map,int online,int lv)
  437. {
  438. struct map_session_data* sd;
  439. struct party_member* m;
  440. struct party_data* p;
  441. int i;
  442. p = party_search(party_id);
  443. if( p == NULL )
  444. return 0;
  445. ARR_FIND( 0, MAX_PARTY, i, p->party.member[i].account_id == account_id && p->party.member[i].char_id == char_id );
  446. if( i == MAX_PARTY )
  447. {
  448. ShowError("party_recv_movemap: char %d/%d not found in party %s (id:%d)",account_id,char_id,p->party.name,party_id);
  449. return 0;
  450. }
  451. m = &p->party.member[i];
  452. m->map = map;
  453. m->online = online;
  454. m->lv = lv;
  455. //Check if they still exist on this map server
  456. sd = map_id2sd(m->account_id);
  457. p->data[i].sd = (sd!=NULL && sd->status.party_id==p->party.party_id && sd->status.char_id == m->char_id && !sd->state.waitingdisconnect)?sd:NULL;
  458. clif_party_info(p,NULL);
  459. return 0;
  460. }
  461. void party_send_movemap(struct map_session_data *sd)
  462. {
  463. int i;
  464. struct party_data *p;
  465. if( sd->status.party_id==0 )
  466. return;
  467. intif_party_changemap(sd,1);
  468. p=party_search(sd->status.party_id);
  469. if (!p) return;
  470. if(!sd->state.party_sent) {
  471. party_check_member(&p->party);
  472. if(sd->status.party_id==p->party.party_id){
  473. clif_party_option(p,sd,0x100);
  474. clif_party_info(p,sd);
  475. clif_party_member_info(p,sd);
  476. sd->state.party_sent=1;
  477. }
  478. }
  479. if (sd->fd) { // synchronize minimap positions with the rest of the party
  480. for(i=0; i < MAX_PARTY; i++) {
  481. if (p->data[i].sd &&
  482. p->data[i].sd != sd &&
  483. p->data[i].sd->bl.m == sd->bl.m)
  484. {
  485. clif_party_xy_single(sd->fd, p->data[i].sd);
  486. clif_party_xy_single(p->data[i].sd->fd, sd);
  487. }
  488. }
  489. }
  490. return;
  491. }
  492. void party_send_levelup(struct map_session_data *sd)
  493. {
  494. intif_party_changemap(sd,1);
  495. }
  496. int party_send_logout(struct map_session_data *sd)
  497. {
  498. struct party_data *p;
  499. int i;
  500. if(!sd->status.party_id)
  501. return 0;
  502. intif_party_changemap(sd,0);
  503. p=party_search(sd->status.party_id);
  504. if(!p) return 0;
  505. ARR_FIND( 0, MAX_PARTY, i, p->data[i].sd == sd );
  506. if( i < MAX_PARTY )
  507. memset(&p->data[i], 0, sizeof(p->data[0]));
  508. return 1;
  509. }
  510. int party_send_message(struct map_session_data *sd,const char *mes,int len)
  511. {
  512. if(sd->status.party_id==0)
  513. return 0;
  514. intif_party_message(sd->status.party_id,sd->status.account_id,mes,len);
  515. party_recv_message(sd->status.party_id,sd->status.account_id,mes,len);
  516. // Chat logging type 'P' / Party Chat
  517. if( log_config.chat&1 || (log_config.chat&8 && !(agit_flag && log_config.chat&64)) )
  518. log_chat("P", sd->status.party_id, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, NULL, mes);
  519. return 0;
  520. }
  521. int party_recv_message(int party_id,int account_id,const char *mes,int len)
  522. {
  523. struct party_data *p;
  524. if( (p=party_search(party_id))==NULL)
  525. return 0;
  526. clif_party_message(p,account_id,mes,len);
  527. return 0;
  528. }
  529. int party_check_conflict(struct map_session_data *sd)
  530. {
  531. nullpo_retr(0, sd);
  532. intif_party_checkconflict(sd->status.party_id,sd->status.account_id,sd->status.char_id);
  533. return 0;
  534. }
  535. int party_skill_check(struct map_session_data *sd, int party_id, int skillid, int skilllv)
  536. {
  537. struct party_data *p;
  538. struct map_session_data *p_sd;
  539. int i;
  540. if(!party_id || (p=party_search(party_id))==NULL)
  541. return 0;
  542. switch(skillid) {
  543. case TK_COUNTER: //Increase Triple Attack rate of Monks.
  544. if (!p->state.monk) return 0;
  545. break;
  546. case MO_COMBOFINISH: //Increase Counter rate of Star Gladiators
  547. if (!p->state.sg) return 0;
  548. break;
  549. case AM_TWILIGHT2: //Twilight Pharmacy, requires Super Novice
  550. return p->state.snovice;
  551. case AM_TWILIGHT3: //Twilight Pharmacy, Requires Taekwon
  552. return p->state.tk;
  553. default:
  554. return 0; //Unknown case?
  555. }
  556. for(i=0;i<MAX_PARTY;i++){
  557. if ((p_sd = p->data[i].sd) == NULL)
  558. continue;
  559. if (sd->bl.m != p_sd->bl.m)
  560. continue;
  561. switch(skillid) {
  562. case TK_COUNTER: //Increase Triple Attack rate of Monks.
  563. if((p_sd->class_&MAPID_UPPERMASK) == MAPID_MONK
  564. && pc_checkskill(p_sd,MO_TRIPLEATTACK)) {
  565. sc_start4(&p_sd->bl,SC_SKILLRATE_UP,100,MO_TRIPLEATTACK,
  566. 50+50*skilllv, //+100/150/200% rate
  567. 0,0,skill_get_time(SG_FRIEND, 1));
  568. }
  569. break;
  570. case MO_COMBOFINISH: //Increase Counter rate of Star Gladiators
  571. if((p_sd->class_&MAPID_UPPERMASK) == MAPID_STAR_GLADIATOR
  572. && sd->sc.data[SC_READYCOUNTER]
  573. && pc_checkskill(p_sd,SG_FRIEND)) {
  574. sc_start4(&p_sd->bl,SC_SKILLRATE_UP,100,TK_COUNTER,
  575. 50+50*pc_checkskill(p_sd,SG_FRIEND), //+100/150/200% rate
  576. 0,0,skill_get_time(SG_FRIEND, 1));
  577. }
  578. break;
  579. }
  580. }
  581. return 0;
  582. }
  583. int party_send_xy_timer(int tid,unsigned int tick,int id,int data)
  584. {
  585. struct party_data* p;
  586. DBIterator* iter = party_db->iterator(party_db);
  587. // for each existing party,
  588. for( p = iter->first(iter,NULL); iter->exists(iter); p = iter->next(iter,NULL) )
  589. {
  590. int i;
  591. // for each member of this party,
  592. for( i = 0; i < MAX_PARTY; i++ )
  593. {
  594. struct map_session_data* sd = p->data[i].sd;
  595. if( !sd ) continue;
  596. if( p->data[i].x != sd->bl.x || p->data[i].y != sd->bl.y )
  597. {// perform position update
  598. clif_party_xy(sd);
  599. p->data[i].x = sd->bl.x;
  600. p->data[i].y = sd->bl.y;
  601. }
  602. if (battle_config.party_hp_mode && p->data[i].hp != sd->battle_status.hp)
  603. {// perform hp update
  604. clif_party_hp(sd);
  605. p->data[i].hp = sd->battle_status.hp;
  606. }
  607. }
  608. }
  609. iter->destroy(iter);
  610. return 0;
  611. }
  612. int party_send_xy_clear(struct party_data *p)
  613. {
  614. int i;
  615. nullpo_retr(0, p);
  616. for(i=0;i<MAX_PARTY;i++){
  617. if(!p->data[i].sd) continue;
  618. p->data[i].hp = 0;
  619. p->data[i].x = 0;
  620. p->data[i].y = 0;
  621. }
  622. return 0;
  623. }
  624. // exp share and added zeny share [Valaris]
  625. int party_exp_share(struct party_data* p, struct block_list* src, unsigned int base_exp, unsigned int job_exp, int zeny)
  626. {
  627. struct map_session_data* sd[MAX_PARTY];
  628. unsigned int i, c;
  629. nullpo_retr(0, p);
  630. // count the number of players eligible for exp sharing
  631. for (i = c = 0; i < MAX_PARTY; i++) {
  632. if( (sd[c] = p->data[i].sd) == NULL || sd[c]->bl.m != src->m || pc_isdead(sd[c]) || (battle_config.idle_no_share && pc_isidle(sd[c])) )
  633. continue;
  634. c++;
  635. }
  636. if (c < 1)
  637. return 0;
  638. base_exp/=c;
  639. job_exp/=c;
  640. zeny/=c;
  641. if (battle_config.party_even_share_bonus && c > 1)
  642. {
  643. double bonus = 100 + battle_config.party_even_share_bonus*(c-1);
  644. if (base_exp)
  645. base_exp = (unsigned int) cap_value(base_exp * bonus/100, 0, UINT_MAX);
  646. if (job_exp)
  647. job_exp = (unsigned int) cap_value(job_exp * bonus/100, 0, UINT_MAX);
  648. if (zeny)
  649. zeny = (unsigned int) cap_value(zeny * bonus/100, INT_MIN, INT_MAX);
  650. }
  651. for (i = 0; i < c; i++)
  652. {
  653. pc_gainexp(sd[i], src, base_exp, job_exp);
  654. if (zeny) // zeny from mobs [Valaris]
  655. pc_getzeny(sd[i],zeny);
  656. }
  657. return 0;
  658. }
  659. //Does party loot. first_charid holds the charid of the player who has time priority to take the item.
  660. int party_share_loot(struct party_data* p, struct map_session_data* sd, struct item* item_data, int first_charid)
  661. {
  662. TBL_PC* target = NULL;
  663. int i;
  664. if (p && p->party.item&2 && (first_charid || !(battle_config.party_share_type&1)))
  665. {
  666. //item distribution to party members.
  667. if (battle_config.party_share_type&2)
  668. { //Round Robin
  669. TBL_PC* psd;
  670. i = p->itemc;
  671. do {
  672. i++;
  673. if (i >= MAX_PARTY)
  674. i = 0; // reset counter to 1st person in party so it'll stop when it reaches "itemc"
  675. if( (psd = p->data[i].sd) == NULL || sd->bl.m != psd->bl.m || pc_isdead(psd) || (battle_config.idle_no_share && pc_isidle(psd)) )
  676. continue;
  677. if (pc_additem(psd,item_data,item_data->amount))
  678. continue; //Chosen char can't pick up loot.
  679. //Successful pick.
  680. p->itemc = i;
  681. target = psd;
  682. break;
  683. } while (i != p->itemc);
  684. }
  685. else
  686. { //Random pick
  687. TBL_PC* psd[MAX_PARTY];
  688. int count = 0;
  689. //Collect pick candidates
  690. for (i = 0; i < MAX_PARTY; i++) {
  691. if( (psd[count] = p->data[i].sd) == NULL || psd[count]->bl.m != sd->bl.m || pc_isdead(psd[count]) || (battle_config.idle_no_share && pc_isidle(psd[count])) )
  692. continue;
  693. count++;
  694. }
  695. while (count > 0) { //Pick a random member.
  696. i = rand()%count;
  697. if (pc_additem(psd[i],item_data,item_data->amount))
  698. { //Discard this receiver.
  699. psd[i] = psd[count-1];
  700. count--;
  701. } else { //Successful pick.
  702. target = psd[i];
  703. break;
  704. }
  705. }
  706. }
  707. }
  708. if (!target) {
  709. target = sd; //Give it to the char that picked it up
  710. if ((i=pc_additem(sd,item_data,item_data->amount)))
  711. return i;
  712. }
  713. if(log_config.enable_logs&0x8) //Logs items, taken by (P)layers [Lupus]
  714. log_pick_pc(target, "P", item_data->nameid, item_data->amount, item_data);
  715. if(battle_config.party_show_share_picker && target != sd) {
  716. char output[80];
  717. sprintf(output, "%s acquired %s.",target->status.name, itemdb_jname(item_data->nameid));
  718. clif_disp_onlyself(sd,output,strlen(output));
  719. }
  720. return 0;
  721. }
  722. int party_send_dot_remove(struct map_session_data *sd)
  723. {
  724. if (sd->status.party_id)
  725. clif_party_xy_remove(sd);
  726. return 0;
  727. }
  728. // To use for Taekwon's "Fighting Chant"
  729. // int c = 0;
  730. // party_foreachsamemap(party_sub_count, sd, 0, &c);
  731. int party_sub_count(struct block_list *bl, va_list ap)
  732. {
  733. struct map_session_data *sd = (TBL_PC *)bl;
  734. if (sd->state.autotrade)
  735. return 0;
  736. if (battle_config.idle_no_share && pc_isidle(sd))
  737. return 0;
  738. return 1;
  739. }
  740. /// Executes 'func' for each party member on the same map and in range (0:whole map)
  741. int party_foreachsamemap(int (*func)(struct block_list*,va_list),struct map_session_data *sd,int range,...)
  742. {
  743. struct party_data *p;
  744. va_list ap;
  745. int i;
  746. int x0,y0,x1,y1;
  747. struct block_list *list[MAX_PARTY];
  748. int blockcount=0;
  749. int total = 0; //Return value.
  750. nullpo_retr(0,sd);
  751. if((p=party_search(sd->status.party_id))==NULL)
  752. return 0;
  753. x0=sd->bl.x-range;
  754. y0=sd->bl.y-range;
  755. x1=sd->bl.x+range;
  756. y1=sd->bl.y+range;
  757. va_start(ap,range);
  758. for(i=0;i<MAX_PARTY;i++)
  759. {
  760. struct map_session_data *psd = p->data[i].sd;
  761. if(!psd) continue;
  762. if(psd->bl.m!=sd->bl.m || !psd->bl.prev)
  763. continue;
  764. if(range &&
  765. (psd->bl.x<x0 || psd->bl.y<y0 ||
  766. psd->bl.x>x1 || psd->bl.y>y1 ) )
  767. continue;
  768. list[blockcount++]=&psd->bl;
  769. }
  770. map_freeblock_lock();
  771. for(i=0;i<blockcount;i++)
  772. total += func(list[i],ap);
  773. map_freeblock_unlock();
  774. va_end(ap);
  775. return total;
  776. }