mail.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. // Copyright (c) Athena Dev Teams - Licensed under GNU GPL
  2. // For more information, see LICENCE in the main folder
  3. #ifndef TXT_ONLY
  4. #include "../common/nullpo.h"
  5. #include "mail.h"
  6. #include "itemdb.h"
  7. #include "clif.h"
  8. #include "pc.h"
  9. #include <time.h>
  10. #include <string.h>
  11. time_t mail_calctimes(void)
  12. {
  13. time_t temp = time(NULL);
  14. return mktime(localtime(&temp));
  15. }
  16. int mail_removeitem(struct map_session_data *sd, short flag)
  17. {
  18. nullpo_retr(0,sd);
  19. if( sd->mail.amount )
  20. {
  21. if (flag)
  22. pc_delitem(sd, sd->mail.index, sd->mail.amount, 1);
  23. else
  24. clif_additem(sd, sd->mail.index, sd->mail.amount, 0);
  25. }
  26. sd->mail.index = 0;
  27. sd->mail.amount = 0;
  28. return 1;
  29. }
  30. int mail_removezeny(struct map_session_data *sd, short flag)
  31. {
  32. nullpo_retr(0,sd);
  33. if (flag && sd->mail.zeny > 0)
  34. sd->status.zeny -= sd->mail.zeny;
  35. sd->mail.zeny = 0;
  36. clif_updatestatus(sd, SP_ZENY);
  37. return 1;
  38. }
  39. char mail_setitem(struct map_session_data *sd, int idx, int amount)
  40. {
  41. nullpo_retr(-1,sd);
  42. if (idx == 0)
  43. { // Zeny Transfer
  44. if (amount < 0)
  45. return 2;
  46. if (amount > sd->status.zeny)
  47. amount = sd->status.zeny;
  48. sd->mail.zeny = amount;
  49. clif_updatestatus(sd, SP_ZENY);
  50. }
  51. else
  52. { // Item Transfer
  53. idx -= 2;
  54. mail_removeitem(sd, 0);
  55. if( idx < 0 || idx > MAX_INVENTORY )
  56. return 2;
  57. if( amount < 0 || amount > sd->status.inventory[idx].amount )
  58. return 2;
  59. if( itemdb_isdropable(&sd->status.inventory[idx], pc_isGM(sd)) == 0 )
  60. return 2;
  61. sd->mail.index = idx;
  62. sd->mail.amount = amount;
  63. clif_delitem(sd, idx, amount);
  64. return 0;
  65. }
  66. return -1;
  67. }
  68. int mail_getattach(struct map_session_data *sd, struct mail_message *msg)
  69. {
  70. int n;
  71. nullpo_retr(0,sd);
  72. nullpo_retr(0,msg);
  73. if( sd->mail.zeny < 0 || sd->mail.zeny > sd->status.zeny )
  74. return 0;
  75. n = sd->mail.index;
  76. if( sd->mail.amount )
  77. {
  78. if( sd->status.inventory[n].amount < sd->mail.amount )
  79. return 0;
  80. memcpy(&msg->item, &sd->status.inventory[n], sizeof(struct item));
  81. msg->item.amount = sd->mail.amount;
  82. }
  83. msg->zeny = sd->mail.zeny;
  84. return 1;
  85. }
  86. int mail_openmail(struct map_session_data *sd)
  87. {
  88. nullpo_retr(0,sd);
  89. if( sd->state.finalsave == 1 || sd->state.storage_flag || sd->vender_id || sd->state.trading )
  90. return 0;
  91. clif_Mail_openmail(sd->fd);
  92. return 0;
  93. }
  94. #endif