Advertisement
Guest User

questlua_pc

a guest
Jan 20th, 2016
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 75.62 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3.  
  4. #include "config.h"
  5. #include "questmanager.h"
  6. #include "sectree_manager.h"
  7. #include "char.h"
  8. #include "char_manager.h"
  9. #include "affect.h"
  10. #include "item.h"
  11. #include "item_manager.h"
  12. #include "guild_manager.h"
  13. #include "war_map.h"
  14. #include "start_position.h"
  15. #include "marriage.h"
  16. #include "mining.h"
  17. #include "p2p.h"
  18. #include "polymorph.h"
  19. #include "desc_client.h"
  20. #include "messenger_manager.h"
  21. #include "log.h"
  22. #include "utils.h"
  23. #include "unique_item.h"
  24. #include "mob_manager.h"
  25.  
  26. #include <cctype>
  27. #undef sys_err
  28. #ifndef __WIN32__
  29. #define sys_err(fmt, args...) quest::CQuestManager::instance().QuestError(__FUNCTION__, __LINE__, fmt, ##args)
  30. #else
  31. #define sys_err(fmt, ...) quest::CQuestManager::instance().QuestError(__FUNCTION__, __LINE__, fmt, __VA_ARGS__)
  32. #endif
  33.  
  34. extern int g_nPortalLimitTime;
  35. extern LPCLIENT_DESC db_clientdesc;
  36. const int ITEM_BROKEN_METIN_VNUM = 28960;
  37.  
  38. namespace quest
  39. {
  40. //
  41. // "pc" Lua functions
  42. //
  43. int pc_has_master_skill(lua_State* L)
  44. {
  45. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  46. bool bHasMasterSkill = false;
  47. for (int i=0; i< SKILL_MAX_NUM; i++)
  48. if (ch->GetSkillMasterType(i) >= SKILL_MASTER && ch->GetSkillLevel(i) >= 21)
  49. {
  50. bHasMasterSkill = true;
  51. break;
  52. }
  53.  
  54. lua_pushboolean(L, bHasMasterSkill);
  55. return 1;
  56. }
  57.  
  58. int pc_remove_skill_book_no_delay(lua_State* L)
  59. {
  60. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  61. ch->RemoveAffect(AFFECT_SKILL_NO_BOOK_DELAY);
  62. return 0;
  63. }
  64.  
  65. int pc_is_skill_book_no_delay(lua_State* L)
  66. {
  67. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  68.  
  69. lua_pushboolean(L, ch->FindAffect(AFFECT_SKILL_NO_BOOK_DELAY) ? true : false);
  70. return 1;
  71. }
  72.  
  73. int pc_learn_grand_master_skill(lua_State* L)
  74. {
  75. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  76.  
  77. if (!lua_isnumber(L, 1))
  78. {
  79. sys_err("wrong skill index");
  80. return 0;
  81. }
  82.  
  83. lua_pushboolean(L, ch->LearnGrandMasterSkill((long)lua_tonumber(L, 1)));
  84. return 1;
  85. }
  86.  
  87. int pc_set_warp_location(lua_State * L)
  88. {
  89. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  90.  
  91. if (!lua_isnumber(L, 1))
  92. {
  93. sys_err("wrong map index");
  94. return 0;
  95. }
  96.  
  97. if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3))
  98. {
  99. sys_err("wrong coodinate");
  100. return 0;
  101. }
  102.  
  103. ch->SetWarpLocation((long)lua_tonumber(L,1), (long)lua_tonumber(L,2), (long)lua_tonumber(L,3));
  104. return 0;
  105. }
  106.  
  107. int pc_set_warp_location_local(lua_State * L)
  108. {
  109. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  110.  
  111. if (!lua_isnumber(L, 1))
  112. {
  113. sys_err("wrong map index");
  114. return 0;
  115. }
  116.  
  117. if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3))
  118. {
  119. sys_err("wrong coodinate");
  120. return 0;
  121. }
  122.  
  123. long lMapIndex = (long) lua_tonumber(L, 1);
  124. const TMapRegion * region = SECTREE_MANAGER::instance().GetMapRegion(lMapIndex);
  125.  
  126. if (!region)
  127. {
  128. sys_err("invalid map index %d", lMapIndex);
  129. return 0;
  130. }
  131.  
  132. int x = (int) lua_tonumber(L, 2);
  133. int y = (int) lua_tonumber(L, 3);
  134.  
  135. if (x > region->ex - region->sx)
  136. {
  137. sys_err("x coordinate overflow max: %d input: %d", region->ex - region->sx, x);
  138. return 0;
  139. }
  140.  
  141. if (y > region->ey - region->sy)
  142. {
  143. sys_err("y coordinate overflow max: %d input: %d", region->ey - region->sy, y);
  144. return 0;
  145. }
  146.  
  147. ch->SetWarpLocation(lMapIndex, x, y);
  148. return 0;
  149. }
  150.  
  151. int pc_get_start_location(lua_State * L)
  152. {
  153. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  154.  
  155. lua_pushnumber(L, g_start_map[ch->GetEmpire()]);
  156. lua_pushnumber(L, g_start_position[ch->GetEmpire()][0] / 100);
  157. lua_pushnumber(L, g_start_position[ch->GetEmpire()][1] / 100);
  158. return 3;
  159. }
  160.  
  161. int pc_warp(lua_State * L)
  162. {
  163. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  164.  
  165. if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2))
  166. {
  167. lua_pushboolean(L, false);
  168. return 1;
  169. }
  170.  
  171. long map_index = 0;
  172.  
  173. if (lua_isnumber(L, 3))
  174. map_index = (int) lua_tonumber(L,3);
  175.  
  176. //PREVENT_HACK
  177. if ( ch->IsHack() )
  178. {
  179. lua_pushboolean(L, false);
  180. return 1;
  181. }
  182. //END_PREVENT_HACK
  183.  
  184. if ( test_server )
  185. ch->ChatPacket( CHAT_TYPE_INFO, "pc_warp %d %d %d",(int)lua_tonumber(L,1),
  186. (int)lua_tonumber(L,2),map_index );
  187. ch->WarpSet((int)lua_tonumber(L, 1), (int)lua_tonumber(L, 2), map_index);
  188.  
  189. lua_pushboolean(L, true);
  190.  
  191. return 1;
  192. }
  193.  
  194. int pc_warp_local(lua_State * L)
  195. {
  196. if (!lua_isnumber(L, 1))
  197. {
  198. sys_err("no map index argument");
  199. return 0;
  200. }
  201.  
  202. if (!lua_isnumber(L, 2) || !lua_isnumber(L, 3))
  203. {
  204. sys_err("no coodinate argument");
  205. return 0;
  206. }
  207.  
  208. long lMapIndex = (long) lua_tonumber(L, 1);
  209. const TMapRegion * region = SECTREE_MANAGER::instance().GetMapRegion(lMapIndex);
  210.  
  211. if (!region)
  212. {
  213. sys_err("invalid map index %d", lMapIndex);
  214. return 0;
  215. }
  216.  
  217. int x = (int) lua_tonumber(L, 2);
  218. int y = (int) lua_tonumber(L, 3);
  219.  
  220. if (x > region->ex - region->sx)
  221. {
  222. sys_err("x coordinate overflow max: %d input: %d", region->ex - region->sx, x);
  223. return 0;
  224. }
  225.  
  226. if (y > region->ey - region->sy)
  227. {
  228. sys_err("y coordinate overflow max: %d input: %d", region->ey - region->sy, y);
  229. return 0;
  230. }
  231.  
  232. /*
  233. int iPulse = thecore_pulse();
  234. if ( pkChr->GetExchange() || pkChr->GetMyShop() || pkChr->GetShopOwner() || pkChr->IsOpenSafebox() )
  235. {
  236. pkChr->ChatPacket( CHAT_TYPE_INFO, LC_TEXT("거래창,창고 등을 연 상태에서는 다른곳으로 이동할수 없습니다" ));
  237.  
  238. return;
  239. }
  240. //PREVENT_PORTAL_AFTER_EXCHANGE
  241. //교환 후 시간체크
  242. if ( iPulse - pkChr->GetExchangeTime() < PASSES_PER_SEC(60) )
  243. {
  244. pkChr->ChatPacket( CHAT_TYPE_INFO, LC_TEXT("거래 후 1분 이내에는 다른지역으로 이동 할 수 없습니다." ) );
  245. return;
  246. }
  247. //END_PREVENT_PORTAL_AFTER_EXCHANGE
  248. //PREVENT_ITEM_COPY
  249. {
  250. if ( iPulse - pkChr->GetMyShopTime() < PASSES_PER_SEC(60) )
  251. {
  252. pkChr->ChatPacket( CHAT_TYPE_INFO, LC_TEXT("거래 후 1분 이내에는 다른지역으로 이동 할 수 없습니다." ) );
  253. return;
  254. }
  255.  
  256. }
  257. //END_PREVENT_ITEM_COPY
  258. */
  259.  
  260. CQuestManager::instance().GetCurrentCharacterPtr()->WarpSet(region->sx + x, region->sy + y);
  261. return 0;
  262. }
  263.  
  264. int pc_warp_exit(lua_State * L)
  265. {
  266. CQuestManager::instance().GetCurrentCharacterPtr()->ExitToSavedLocation();
  267. return 0;
  268. }
  269.  
  270. int pc_in_dungeon(lua_State * L)
  271. {
  272. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  273. lua_pushboolean(L, ch->GetDungeon()?1:0);
  274. return 1;
  275. }
  276.  
  277. int pc_hasguild(lua_State * L)
  278. {
  279. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  280. lua_pushboolean(L, ch->GetGuild() ? 1 : 0);
  281. return 1;
  282. }
  283.  
  284. int pc_getguild(lua_State * L)
  285. {
  286. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  287. lua_pushnumber(L, ch->GetGuild() ? ch->GetGuild()->GetID() : 0);
  288. return 1;
  289. }
  290.  
  291. int pc_isguildmaster(lua_State * L)
  292. {
  293. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  294. CGuild * g = ch->GetGuild();
  295.  
  296. if (g)
  297. lua_pushboolean(L, (ch->GetPlayerID() == g->GetMasterPID()));
  298. else
  299. lua_pushboolean(L, 0);
  300.  
  301. return 1;
  302. }
  303.  
  304. int pc_destroy_guild(lua_State * L)
  305. {
  306. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  307. CGuild * g = ch->GetGuild();
  308.  
  309. if (g)
  310. g->RequestDisband(ch->GetPlayerID());
  311.  
  312. return 0;
  313. }
  314.  
  315. int pc_remove_from_guild(lua_State* L)
  316. {
  317. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  318. CGuild * g = ch->GetGuild();
  319.  
  320. if (g)
  321. g->RequestRemoveMember(ch->GetPlayerID());
  322.  
  323. return 0;
  324. }
  325.  
  326. int pc_give_gold(lua_State* L)
  327. {
  328. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  329.  
  330. if (!lua_isnumber(L, 1))
  331. {
  332. sys_err("QUEST : wrong argument");
  333. return 0;
  334. }
  335.  
  336. int iAmount = (int) lua_tonumber(L, 1);
  337.  
  338. if (iAmount <= 0)
  339. {
  340. sys_err("QUEST : gold amount less then zero");
  341. return 0;
  342. }
  343.  
  344. DBManager::instance().SendMoneyLog(MONEY_LOG_QUEST, ch->GetPlayerID(), iAmount);
  345. ch->PointChange(POINT_GOLD, iAmount, true);
  346. return 0;
  347. }
  348.  
  349. int pc_warp_to_guild_war_observer_position(lua_State* L)
  350. {
  351. luaL_checknumber(L, 1);
  352. luaL_checknumber(L, 2);
  353.  
  354. DWORD gid1 = (DWORD)lua_tonumber(L, 1);
  355. DWORD gid2 = (DWORD)lua_tonumber(L, 2);
  356.  
  357. CGuild* g1 = CGuildManager::instance().FindGuild(gid1);
  358. CGuild* g2 = CGuildManager::instance().FindGuild(gid2);
  359.  
  360. if (!g1 || !g2)
  361. {
  362. luaL_error(L, "no such guild with id %d %d", gid1, gid2);
  363. }
  364.  
  365. PIXEL_POSITION pos;
  366.  
  367. DWORD dwMapIndex = g1->GetGuildWarMapIndex(gid2);
  368.  
  369. if (!CWarMapManager::instance().GetStartPosition(dwMapIndex, 2, pos))
  370. {
  371. luaL_error(L, "not under warp guild war between guild %d %d", gid1, gid2);
  372. return 0;
  373. }
  374.  
  375. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  376.  
  377. //PREVENT_HACK
  378. if ( ch->IsHack() )
  379. return 0;
  380. //END_PREVENT_HACK
  381.  
  382. ch->SetQuestFlag("war.is_war_member", 0);
  383. ch->SaveExitLocation();
  384. ch->WarpSet(pos.x, pos.y, dwMapIndex);
  385. return 0;
  386. }
  387.  
  388. int pc_give_item_from_special_item_group(lua_State* L)
  389. {
  390. luaL_checknumber(L, 1);
  391.  
  392. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  393.  
  394. DWORD dwGroupVnum = (DWORD) lua_tonumber(L,1);
  395.  
  396. std::vector <DWORD> dwVnums;
  397. std::vector <DWORD> dwCounts;
  398. std::vector <LPITEM> item_gets(NULL);
  399. int count = 0;
  400.  
  401. ch->GiveItemFromSpecialItemGroup(dwGroupVnum, dwVnums, dwCounts, item_gets, count);
  402.  
  403. for (int i = 0; i < count; i++)
  404. {
  405. if (!item_gets[i])
  406. {
  407. if (dwVnums[i] == 1)
  408. {
  409. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("돈 %d 냥을 획득했습니다."), dwCounts[i]);
  410. }
  411. else if (dwVnums[i] == 2)
  412. {
  413. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("나무에서 부터 신비한 빛이 나옵니다."));
  414. ch->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%d의 경험치를 획득했습니다."), dwCounts[i]);
  415. }
  416. }
  417. }
  418. return 0;
  419. }
  420.  
  421. int pc_enough_inventory(lua_State* L)
  422. {
  423. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  424. if (!lua_isnumber(L, 1))
  425. {
  426. lua_pushboolean(L, 0);
  427. return 1;
  428. }
  429.  
  430. DWORD item_vnum = (DWORD)lua_tonumber(L, 1);
  431. TItemTable * pTable = ITEM_MANAGER::instance().GetTable(item_vnum);
  432. if (!pTable)
  433. {
  434. lua_pushboolean(L, 0);
  435. return 1;
  436. }
  437.  
  438. bool bEnoughInventoryForItem = ch->GetEmptyInventory(pTable->bSize) != -1;
  439. lua_pushboolean(L, bEnoughInventoryForItem);
  440. return 1;
  441. }
  442.  
  443. int pc_give_item(lua_State* L)
  444. {
  445. PC* pPC = CQuestManager::instance().GetCurrentPC();
  446. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  447.  
  448. if (!lua_isstring(L, 1) || !(lua_isstring(L, 2)||lua_isnumber(L, 2)))
  449. {
  450. sys_err("QUEST : wrong argument");
  451. return 0;
  452. }
  453.  
  454. DWORD dwVnum;
  455.  
  456. if (lua_isnumber(L,2)) // 번호인경우 번호로 준다.
  457. dwVnum = (int) lua_tonumber(L, 2);
  458. else if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L, 2), dwVnum))
  459. {
  460. sys_err("QUEST Make item call error : wrong item name : %s", lua_tostring(L,1));
  461. return 0;
  462. }
  463.  
  464. int icount = 1;
  465.  
  466. if (lua_isnumber(L, 3) && lua_tonumber(L, 3) > 0)
  467. {
  468. icount = (int)rint(lua_tonumber(L, 3));
  469.  
  470. if (icount <= 0)
  471. {
  472. sys_err("QUEST Make item call error : wrong item count : %g", lua_tonumber(L, 2));
  473. return 0;
  474. }
  475. }
  476.  
  477. pPC->GiveItem(lua_tostring(L, 1), dwVnum, icount);
  478.  
  479. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), dwVnum, icount);
  480. return 0;
  481. }
  482.  
  483. int pc_give_or_drop_item(lua_State* L)
  484. {
  485. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  486.  
  487. if (!lua_isstring(L, 1) && !lua_isnumber(L, 1))
  488. {
  489. sys_err("QUEST Make item call error : wrong argument");
  490. lua_pushnumber (L, 0);
  491. return 1;
  492. }
  493.  
  494. DWORD dwVnum;
  495.  
  496. if (lua_isnumber(L, 1)) // 번호인경우 번호로 준다.
  497. {
  498. dwVnum = (int) lua_tonumber(L, 1);
  499. }
  500. else if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L, 1), dwVnum))
  501. {
  502. sys_err("QUEST Make item call error : wrong item name : %s", lua_tostring(L,1));
  503. lua_pushnumber (L, 0);
  504.  
  505. return 1;
  506. }
  507.  
  508. int icount = 1;
  509. if (lua_isnumber(L,2) && lua_tonumber(L,2)>0)
  510. {
  511. icount = (int)rint(lua_tonumber(L,2));
  512. if (icount<=0)
  513. {
  514. sys_err("QUEST Make item call error : wrong item count : %g", lua_tonumber(L,2));
  515. lua_pushnumber (L, 0);
  516. return 1;
  517. }
  518. }
  519.  
  520. sys_log(0, "QUEST [REWARD] item %s to %s", lua_tostring(L, 1), ch->GetName());
  521.  
  522. PC* pPC = CQuestManager::instance().GetCurrentPC();
  523.  
  524. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), dwVnum, icount);
  525.  
  526. LPITEM item = ch->AutoGiveItem(dwVnum, icount);
  527.  
  528. if ( dwVnum >= 80003 && dwVnum <= 80007 )
  529. {
  530. LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), QUEST, "quest: give_item2");
  531. }
  532.  
  533. if (NULL != item)
  534. lua_pushnumber (L, item->GetID());
  535. else
  536. lua_pushnumber (L, 0);
  537. return 1;
  538. }
  539.  
  540. int pc_give_or_drop_item_and_select(lua_State* L)
  541. {
  542. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  543.  
  544. if (!lua_isstring(L, 1) && !lua_isnumber(L, 1))
  545. {
  546. sys_err("QUEST Make item call error : wrong argument");
  547. return 0;
  548. }
  549.  
  550. DWORD dwVnum;
  551.  
  552. if (lua_isnumber(L, 1)) // 번호인경우 번호로 준다.
  553. {
  554. dwVnum = (int) lua_tonumber(L, 1);
  555. }
  556. else if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L, 1), dwVnum))
  557. {
  558. sys_err("QUEST Make item call error : wrong item name : %s", lua_tostring(L,1));
  559. return 0;
  560. }
  561.  
  562. int icount = 1;
  563. if (lua_isnumber(L,2) && lua_tonumber(L,2)>0)
  564. {
  565. icount = (int)rint(lua_tonumber(L,2));
  566. if (icount<=0)
  567. {
  568. sys_err("QUEST Make item call error : wrong item count : %g", lua_tonumber(L,2));
  569. return 0;
  570. }
  571. }
  572.  
  573. sys_log(0, "QUEST [REWARD] item %s to %s", lua_tostring(L, 1), ch->GetName());
  574.  
  575. PC* pPC = CQuestManager::instance().GetCurrentPC();
  576.  
  577. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), dwVnum, icount);
  578.  
  579. LPITEM item = ch->AutoGiveItem(dwVnum, icount);
  580.  
  581. if (NULL != item)
  582. CQuestManager::Instance().SetCurrentItem(item);
  583.  
  584. if ( dwVnum >= 80003 && dwVnum <= 80007 )
  585. {
  586. LogManager::instance().GoldBarLog(ch->GetPlayerID(), item->GetID(), QUEST, "quest: give_item2");
  587. }
  588.  
  589. return 0;
  590. }
  591.  
  592. int pc_get_current_map_index(lua_State* L)
  593. {
  594. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetMapIndex());
  595. return 1;
  596. }
  597.  
  598. int pc_get_x(lua_State* L)
  599. {
  600. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  601. lua_pushnumber(L, ch->GetX()/100);
  602. return 1;
  603. }
  604.  
  605. int pc_get_y(lua_State* L)
  606. {
  607. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  608. lua_pushnumber(L, ch->GetY()/100);
  609. return 1;
  610. }
  611.  
  612. int pc_get_local_x(lua_State* L)
  613. {
  614. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  615. LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(ch->GetMapIndex());
  616.  
  617. if (pMap)
  618. lua_pushnumber(L, (ch->GetX() - pMap->m_setting.iBaseX) / 100);
  619. else
  620. lua_pushnumber(L, ch->GetX() / 100);
  621.  
  622. return 1;
  623. }
  624.  
  625. int pc_get_local_y(lua_State* L)
  626. {
  627. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  628. LPSECTREE_MAP pMap = SECTREE_MANAGER::instance().GetMap(ch->GetMapIndex());
  629.  
  630. if (pMap)
  631. lua_pushnumber(L, (ch->GetY() - pMap->m_setting.iBaseY) / 100);
  632. else
  633. lua_pushnumber(L, ch->GetY() / 100);
  634.  
  635. return 1;
  636. }
  637.  
  638. int pc_count_item(lua_State* L)
  639. {
  640. if (lua_isnumber(L, -1))
  641. lua_pushnumber(L,CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem((DWORD)lua_tonumber(L, -1)));
  642. else if (lua_isstring(L, -1))
  643. {
  644. DWORD item_vnum;
  645.  
  646. if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
  647. {
  648. sys_err("QUEST count_item call error : wrong item name : %s", lua_tostring(L,1));
  649. lua_pushnumber(L, 0);
  650. }
  651. else
  652. {
  653. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(item_vnum));
  654. }
  655. }
  656. else
  657. lua_pushnumber(L, 0);
  658.  
  659. return 1;
  660. }
  661.  
  662. int pc_remove_item(lua_State* L)
  663. {
  664. if (lua_gettop(L) == 1)
  665. {
  666. DWORD item_vnum;
  667.  
  668. if (lua_isnumber(L,1))
  669. {
  670. item_vnum = (DWORD)lua_tonumber(L, 1);
  671. }
  672. else if (lua_isstring(L,1))
  673. {
  674. if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
  675. {
  676. sys_err("QUEST remove_item call error : wrong item name : %s", lua_tostring(L,1));
  677. return 0;
  678. }
  679. }
  680. else
  681. {
  682. sys_err("QUEST remove_item wrong argument");
  683. return 0;
  684. }
  685.  
  686. sys_log(0,"QUEST remove a item vnum %d of %s[%d]", item_vnum, CQuestManager::instance().GetCurrentCharacterPtr()->GetName(), CQuestManager::instance().GetCurrentCharacterPtr()->GetPlayerID());
  687. CQuestManager::instance().GetCurrentCharacterPtr()->RemoveSpecifyItem(item_vnum);
  688. }
  689. else if (lua_gettop(L) == 2)
  690. {
  691. DWORD item_vnum;
  692.  
  693. if (lua_isnumber(L, 1))
  694. {
  695. item_vnum = (DWORD)lua_tonumber(L, 1);
  696. }
  697. else if (lua_isstring(L, 1))
  698. {
  699. if (!ITEM_MANAGER::instance().GetVnum(lua_tostring(L,1), item_vnum))
  700. {
  701. sys_err("QUEST remove_item call error : wrong item name : %s", lua_tostring(L,1));
  702. return 0;
  703. }
  704. }
  705. else
  706. {
  707. sys_err("QUEST remove_item wrong argument");
  708. return 0;
  709. }
  710.  
  711. DWORD item_count = (DWORD) lua_tonumber(L, 2);
  712. sys_log(0, "QUEST remove items(vnum %d) count %d of %s[%d]",
  713. item_vnum,
  714. item_count,
  715. CQuestManager::instance().GetCurrentCharacterPtr()->GetName(),
  716. CQuestManager::instance().GetCurrentCharacterPtr()->GetPlayerID());
  717.  
  718. CQuestManager::instance().GetCurrentCharacterPtr()->RemoveSpecifyItem(item_vnum, item_count);
  719. }
  720. return 0;
  721. }
  722.  
  723. int pc_get_leadership(lua_State * L)
  724. {
  725. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetLeadershipSkillLevel());
  726. return 1;
  727. }
  728.  
  729. int pc_reset_point(lua_State * L)
  730. {
  731. CQuestManager::instance().GetCurrentCharacterPtr()->ResetPoint(CQuestManager::instance().GetCurrentCharacterPtr()->GetLevel());
  732. return 0;
  733. }
  734.  
  735. int pc_get_playtime(lua_State* L)
  736. {
  737. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetRealPoint(POINT_PLAYTIME));
  738. return 1;
  739. }
  740.  
  741. int pc_get_vid(lua_State* L)
  742. {
  743. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetVID());
  744. return 1;
  745. }
  746. int pc_get_name(lua_State* L)
  747. {
  748. lua_pushstring(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetName());
  749. return 1;
  750. }
  751.  
  752. int pc_get_next_exp(lua_State* L)
  753. {
  754. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetNextExp());
  755. return 1;
  756. }
  757.  
  758. int pc_get_exp(lua_State* L)
  759. {
  760. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetExp());
  761. return 1;
  762. }
  763.  
  764. int pc_get_race(lua_State* L)
  765. {
  766. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetRaceNum());
  767. return 1;
  768. }
  769.  
  770. int pc_change_sex(lua_State* L)
  771. {
  772. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->ChangeSex());
  773. return 1;
  774. }
  775.  
  776. int pc_get_job(lua_State* L)
  777. {
  778. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetJob());
  779. return 1;
  780. }
  781.  
  782. int pc_get_max_sp(lua_State* L)
  783. {
  784. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetMaxSP());
  785. return 1;
  786. }
  787.  
  788. int pc_get_sp(lua_State * L)
  789. {
  790. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetSP());
  791. return 1;
  792. }
  793.  
  794. int pc_change_sp(lua_State * L)
  795. {
  796. if (!lua_isnumber(L, 1))
  797. {
  798. sys_err("invalid argument");
  799. lua_pushboolean(L, 0);
  800. return 1;
  801. }
  802.  
  803. long val = (long) lua_tonumber(L, 1);
  804.  
  805. if (val == 0)
  806. {
  807. lua_pushboolean(L, 0);
  808. return 1;
  809. }
  810.  
  811. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  812.  
  813. if (val > 0) // 증가시키는 것이므로 무조건 성공 리턴
  814. ch->PointChange(POINT_SP, val);
  815. else if (val < 0)
  816. {
  817. if (ch->GetSP() < -val)
  818. {
  819. lua_pushboolean(L, 0);
  820. return 1;
  821. }
  822.  
  823. ch->PointChange(POINT_SP, val);
  824. }
  825.  
  826. lua_pushboolean(L, 1);
  827. return 1;
  828. }
  829.  
  830. int pc_get_max_hp(lua_State * L)
  831. {
  832. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetMaxHP());
  833. return 1;
  834. }
  835.  
  836. int pc_get_hp(lua_State * L)
  837. {
  838. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetHP());
  839. return 1;
  840. }
  841.  
  842. int pc_get_level(lua_State * L)
  843. {
  844. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetLevel());
  845. return 1;
  846. }
  847.  
  848. int pc_set_level(lua_State * L)
  849. {
  850. if (!lua_isnumber(L, 1))
  851. {
  852. sys_err("invalid argument");
  853. return 0;
  854. }
  855. else
  856. {
  857. int newLevel = lua_tonumber(L, 1);
  858. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  859.  
  860.  
  861. sys_log(0,"QUEST [LEVEL] %s jumpint to level %d", ch->GetName(), (int)rint(lua_tonumber(L,1)));
  862.  
  863. PC* pPC = CQuestManager::instance().GetCurrentPC();
  864. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), newLevel, 0);
  865.  
  866. //포인트 : 스킬, 서브스킬, 스탯
  867. ch->PointChange(POINT_SKILL, newLevel - ch->GetLevel());
  868. ch->PointChange(POINT_SUB_SKILL, newLevel < 10 ? 0 : newLevel - MAX(ch->GetLevel(), 9));
  869. ch->PointChange(POINT_STAT, ((MINMAX(1, newLevel, 90) - ch->GetLevel()) * 3) + ch->GetPoint(POINT_LEVEL_STEP));
  870. //레벨
  871. ch->PointChange(POINT_LEVEL, newLevel - ch->GetLevel());
  872. //HP, SP
  873. ch->SetRandomHP((newLevel - 1) * number(JobInitialPoints[ch->GetJob()].hp_per_lv_begin, JobInitialPoints[ch->GetJob()].hp_per_lv_end));
  874. ch->SetRandomSP((newLevel - 1) * number(JobInitialPoints[ch->GetJob()].sp_per_lv_begin, JobInitialPoints[ch->GetJob()].sp_per_lv_end));
  875.  
  876.  
  877. // 회복
  878. ch->PointChange(POINT_HP, ch->GetMaxHP() - ch->GetHP());
  879. ch->PointChange(POINT_SP, ch->GetMaxSP() - ch->GetSP());
  880.  
  881. ch->ComputePoints();
  882. ch->PointsPacket();
  883. ch->SkillLevelPacket();
  884.  
  885. return 0;
  886. }
  887. }
  888.  
  889. int pc_get_weapon(lua_State * L)
  890. {
  891. LPITEM item = CQuestManager::instance().GetCurrentCharacterPtr()->GetWear(WEAR_WEAPON);
  892.  
  893. if (!item)
  894. lua_pushnumber(L, 0);
  895. else
  896. lua_pushnumber(L, item->GetVnum());
  897.  
  898. return 1;
  899. }
  900.  
  901. int pc_get_armor(lua_State * L)
  902. {
  903. LPITEM item = CQuestManager::instance().GetCurrentCharacterPtr()->GetWear(WEAR_BODY);
  904.  
  905. if (!item)
  906. lua_pushnumber(L, 0);
  907. else
  908. lua_pushnumber(L, item->GetVnum());
  909.  
  910. return 1;
  911. }
  912.  
  913. int pc_get_wear(lua_State * L)
  914. {
  915. if (!lua_isnumber(L, 1))
  916. {
  917. sys_err("QUEST wrong set flag");
  918. return 0;
  919. }
  920.  
  921. BYTE bCell = (BYTE)lua_tonumber(L, 1);
  922.  
  923. LPITEM item = CQuestManager::instance().GetCurrentCharacterPtr()->GetWear(bCell);
  924.  
  925.  
  926. if (!item)
  927. lua_pushnil(L);
  928. else
  929. lua_pushnumber(L, item->GetVnum());
  930.  
  931. return 1;
  932. }
  933.  
  934. int pc_get_money(lua_State * L)
  935. {
  936. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetGold());
  937. return 1;
  938. }
  939.  
  940. // 20050725.myevan.은둔의 망토 사용중 혼석 수련시 선악치가 두배 소모되는 버그가 발생해
  941. // 실제 선악치를 이용해 계산을 하게 한다.
  942. int pc_get_real_alignment(lua_State* L)
  943. {
  944. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetRealAlignment()/10);
  945. return 1;
  946. }
  947.  
  948. int pc_get_alignment(lua_State* L)
  949. {
  950. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetAlignment()/10);
  951. return 1;
  952. }
  953.  
  954. int pc_change_alignment(lua_State * L)
  955. {
  956. int alignment = (int)(lua_tonumber(L, 1)*10);
  957. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  958.  
  959. ch->UpdateAlignment(alignment);
  960. return 0;
  961. }
  962.  
  963. int pc_change_money(lua_State * L)
  964. {
  965. int gold = (int)lua_tonumber(L, -1);
  966.  
  967. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  968.  
  969. if (gold + ch->GetGold() < 0)
  970. sys_err("QUEST wrong ChangeGold %d (now %d)", gold, ch->GetGold());
  971. else
  972. {
  973. DBManager::instance().SendMoneyLog(MONEY_LOG_QUEST, ch->GetPlayerID(), gold);
  974. ch->PointChange(POINT_GOLD, gold, true);
  975. }
  976.  
  977. return 0;
  978. }
  979.  
  980. int pc_set_another_quest_flag(lua_State* L)
  981. {
  982. if (!lua_isstring(L, 1) || !lua_isstring(L, 2) || !lua_isnumber(L, 3))
  983. {
  984. sys_err("QUEST wrong set flag");
  985. return 0;
  986. }
  987. else
  988. {
  989. const char * sz = lua_tostring(L, 1);
  990. const char * sz2 = lua_tostring(L, 2);
  991. CQuestManager & q = CQuestManager::Instance();
  992. PC * pPC = q.GetCurrentPC();
  993. pPC->SetFlag(string(sz)+"."+sz2, int(rint(lua_tonumber(L,3))));
  994. return 0;
  995. }
  996. }
  997.  
  998. int pc_get_another_quest_flag(lua_State* L)
  999. {
  1000. if (!lua_isstring(L,1) || !lua_isstring(L,2))
  1001. {
  1002. sys_err("QUEST wrong get flag");
  1003. return 0;
  1004. }
  1005. else
  1006. {
  1007. const char* sz = lua_tostring(L,1);
  1008. const char* sz2 = lua_tostring(L,2);
  1009. CQuestManager& q = CQuestManager::Instance();
  1010. PC* pPC = q.GetCurrentPC();
  1011. if (!pPC)
  1012. {
  1013. return 0;
  1014. }
  1015. lua_pushnumber(L,pPC->GetFlag(string(sz)+"."+sz2));
  1016. return 1;
  1017. }
  1018. }
  1019.  
  1020. int pc_get_flag(lua_State* L)
  1021. {
  1022. if (!lua_isstring(L,-1))
  1023. {
  1024. sys_err("QUEST wrong get flag");
  1025. return 0;
  1026. }
  1027. else
  1028. {
  1029. const char* sz = lua_tostring(L,-1);
  1030. CQuestManager& q = CQuestManager::Instance();
  1031. PC* pPC = q.GetCurrentPC();
  1032. lua_pushnumber(L,pPC->GetFlag(sz));
  1033. return 1;
  1034. }
  1035. }
  1036.  
  1037. int pc_get_quest_flag(lua_State* L)
  1038. {
  1039. if (!lua_isstring(L,-1))
  1040. {
  1041. sys_err("QUEST wrong get flag");
  1042. return 0;
  1043. }
  1044. else
  1045. {
  1046. const char* sz = lua_tostring(L,-1);
  1047. CQuestManager& q = CQuestManager::Instance();
  1048. PC* pPC = q.GetCurrentPC();
  1049. lua_pushnumber(L,pPC->GetFlag(pPC->GetCurrentQuestName() + "."+sz));
  1050. if ( test_server )
  1051. sys_log( 0 ,"GetQF ( %s . %s )", pPC->GetCurrentQuestName().c_str(), sz );
  1052. }
  1053. return 1;
  1054. }
  1055.  
  1056. int pc_set_flag(lua_State* L)
  1057. {
  1058. if (!lua_isstring(L,1) || !lua_isnumber(L,2))
  1059. {
  1060. sys_err("QUEST wrong set flag");
  1061. }
  1062. else
  1063. {
  1064. const char* sz = lua_tostring(L,1);
  1065. CQuestManager& q = CQuestManager::Instance();
  1066. PC* pPC = q.GetCurrentPC();
  1067. pPC->SetFlag(sz, int(rint(lua_tonumber(L,2))));
  1068. }
  1069. return 0;
  1070. }
  1071.  
  1072. int pc_set_quest_flag(lua_State* L)
  1073. {
  1074. if (!lua_isstring(L,1) || !lua_isnumber(L,2))
  1075. {
  1076. sys_err("QUEST wrong set flag");
  1077. }
  1078. else
  1079. {
  1080. const char* sz = lua_tostring(L,1);
  1081. CQuestManager& q = CQuestManager::Instance();
  1082. PC* pPC = q.GetCurrentPC();
  1083. pPC->SetFlag(pPC->GetCurrentQuestName()+"."+sz, int(rint(lua_tonumber(L,2))));
  1084. }
  1085. return 0;
  1086. }
  1087.  
  1088. int pc_del_quest_flag(lua_State *L)
  1089. {
  1090. if (!lua_isstring(L, 1))
  1091. {
  1092. sys_err("argument error");
  1093. return 0;
  1094. }
  1095.  
  1096. const char * sz = lua_tostring(L, 1);
  1097. PC * pPC = CQuestManager::instance().GetCurrentPC();
  1098. pPC->DeleteFlag(pPC->GetCurrentQuestName()+"."+sz);
  1099. return 0;
  1100. }
  1101.  
  1102. int pc_give_exp2(lua_State* L)
  1103. {
  1104. CQuestManager& q = CQuestManager::instance();
  1105. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1106. if (!lua_isnumber(L,1))
  1107. return 0;
  1108.  
  1109. sys_log(0,"QUEST [REWARD] %s give exp2 %d", ch->GetName(), (int)rint(lua_tonumber(L,1)));
  1110.  
  1111. DWORD exp = (DWORD)rint(lua_tonumber(L,1));
  1112.  
  1113. PC* pPC = CQuestManager::instance().GetCurrentPC();
  1114. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), exp, 0);
  1115. ch->PointChange(POINT_EXP, exp);
  1116. return 0;
  1117. }
  1118.  
  1119. int pc_give_exp(lua_State* L)
  1120. {
  1121. if (!lua_isstring(L,1) || !lua_isnumber(L,2))
  1122. return 0;
  1123.  
  1124. CQuestManager& q = CQuestManager::instance();
  1125. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1126.  
  1127. sys_log(0,"QUEST [REWARD] %s give exp %s %d", ch->GetName(), lua_tostring(L,1), (int)rint(lua_tonumber(L,2)));
  1128.  
  1129. DWORD exp = (DWORD)rint(lua_tonumber(L,2));
  1130.  
  1131. PC* pPC = CQuestManager::instance().GetCurrentPC();
  1132.  
  1133. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), exp, 0);
  1134.  
  1135. pPC->GiveExp(lua_tostring(L,1), exp);
  1136. return 0;
  1137. }
  1138.  
  1139. int pc_give_exp_perc(lua_State* L)
  1140. {
  1141. CQuestManager & q = CQuestManager::instance();
  1142. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1143.  
  1144. if (!ch || !lua_isstring(L, 1) || !lua_isnumber(L, 2) || !lua_isnumber(L, 3))
  1145. return 0;
  1146.  
  1147. int lev = (int)rint(lua_tonumber(L,2));
  1148. double proc = (lua_tonumber(L,3));
  1149.  
  1150. sys_log(0, "QUEST [REWARD] %s give exp %s lev %d percent %g%%", ch->GetName(), lua_tostring(L, 1), lev, proc);
  1151.  
  1152. DWORD exp = (DWORD)((exp_table[MINMAX(0, lev, PLAYER_EXP_TABLE_MAX)] * proc) / 100);
  1153. PC * pPC = CQuestManager::instance().GetCurrentPC();
  1154.  
  1155. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), exp, 0);
  1156.  
  1157. pPC->GiveExp(lua_tostring(L, 1), exp);
  1158. return 0;
  1159. }
  1160.  
  1161. int pc_get_empire(lua_State* L)
  1162. {
  1163. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetEmpire());
  1164. return 1;
  1165. }
  1166.  
  1167. int pc_get_part(lua_State* L)
  1168. {
  1169. CQuestManager& q = CQuestManager::instance();
  1170. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1171. if (!lua_isnumber(L,1))
  1172. {
  1173. lua_pushnumber(L, 0);
  1174. return 1;
  1175. }
  1176. int part_idx = (int)lua_tonumber(L, 1);
  1177. lua_pushnumber(L, ch->GetPart(part_idx));
  1178. return 1;
  1179. }
  1180.  
  1181. int pc_set_part(lua_State* L)
  1182. {
  1183. CQuestManager& q = CQuestManager::instance();
  1184. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1185. if (!lua_isnumber(L,1) || !lua_isnumber(L,2))
  1186. {
  1187. return 0;
  1188. }
  1189. int part_idx = (int)lua_tonumber(L, 1);
  1190. int part_value = (int)lua_tonumber(L, 2);
  1191. ch->SetPart(part_idx, part_value);
  1192. ch->UpdatePacket();
  1193. return 0;
  1194. }
  1195.  
  1196. int pc_get_skillgroup(lua_State* L)
  1197. {
  1198. lua_pushnumber(L, CQuestManager::instance().GetCurrentCharacterPtr()->GetSkillGroup());
  1199. return 1;
  1200. }
  1201.  
  1202. int pc_set_skillgroup(lua_State* L)
  1203. {
  1204. if (!lua_isnumber(L, 1))
  1205. sys_err("QUEST wrong skillgroup number");
  1206. else
  1207. {
  1208. CQuestManager & q = CQuestManager::Instance();
  1209. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1210.  
  1211. ch->SetSkillGroup((BYTE) rint(lua_tonumber(L, 1)));
  1212. }
  1213. return 0;
  1214. }
  1215.  
  1216. int pc_is_polymorphed(lua_State* L)
  1217. {
  1218. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1219. lua_pushboolean(L, ch->IsPolymorphed());
  1220. return 1;
  1221. }
  1222.  
  1223. int pc_remove_polymorph(lua_State* L)
  1224. {
  1225. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1226. ch->RemoveAffect(AFFECT_POLYMORPH);
  1227. ch->SetPolymorph(0);
  1228. return 0;
  1229. }
  1230.  
  1231. int pc_polymorph(lua_State* L)
  1232. {
  1233. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1234. DWORD dwVnum = (DWORD) lua_tonumber(L, 1);
  1235. int iDuration = (int) lua_tonumber(L, 2);
  1236. ch->AddAffect(AFFECT_POLYMORPH, POINT_POLYMORPH, dwVnum, AFF_POLYMORPH, iDuration, 0, true);
  1237. return 0;
  1238. }
  1239.  
  1240. int pc_is_mount(lua_State* L)
  1241. {
  1242. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1243. lua_pushboolean(L, ch->GetMountVnum());
  1244. return 1;
  1245. }
  1246.  
  1247. int pc_mount(lua_State* L)
  1248. {
  1249. if (!lua_isnumber(L, 1))
  1250. return 0;
  1251.  
  1252. int length = 60;
  1253.  
  1254. if (lua_isnumber(L, 2))
  1255. length = (int)lua_tonumber(L, 2);
  1256.  
  1257. DWORD mount_vnum = (DWORD)lua_tonumber(L, 1);
  1258.  
  1259. if (length < 0)
  1260. length = 60;
  1261.  
  1262. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1263.  
  1264. ch->RemoveAffect(AFFECT_MOUNT);
  1265. ch->RemoveAffect(AFFECT_MOUNT_BONUS);
  1266.  
  1267. // 말이 소환되어 따라다니는 상태라면 말부터 없앰
  1268. if (ch->GetHorse())
  1269. ch->HorseSummon(false);
  1270.  
  1271. if (mount_vnum)
  1272. {
  1273. ch->AddAffect(AFFECT_MOUNT, POINT_MOUNT, mount_vnum, AFF_NONE, length, 0, true);
  1274. switch (mount_vnum)
  1275. {
  1276. case 20201:
  1277. case 20202:
  1278. case 20203:
  1279. case 20204:
  1280. case 20213:
  1281. case 20216:
  1282. ch->AddAffect(AFFECT_MOUNT, POINT_MOV_SPEED, 30, AFF_NONE, length, 0, true, true);
  1283. break;
  1284.  
  1285. case 20205:
  1286. case 20206:
  1287. case 20207:
  1288. case 20208:
  1289. case 20214:
  1290. case 20217:
  1291. ch->AddAffect(AFFECT_MOUNT, POINT_MOV_SPEED, 40, AFF_NONE, length, 0, true, true);
  1292. break;
  1293.  
  1294. case 20209:
  1295. case 20210:
  1296. case 20211:
  1297. case 20212:
  1298. case 20215:
  1299. case 20218:
  1300. ch->AddAffect(AFFECT_MOUNT, POINT_MOV_SPEED, 50, AFF_NONE, length, 0, true, true);
  1301. break;
  1302.  
  1303. }
  1304. }
  1305.  
  1306. return 0;
  1307. }
  1308.  
  1309. int pc_mount_bonus(lua_State* L)
  1310. {
  1311. BYTE applyOn = static_cast<BYTE>(lua_tonumber(L, 1));
  1312. long value = static_cast<long>(lua_tonumber(L, 2));
  1313. long duration = static_cast<long>(lua_tonumber(L, 3));
  1314.  
  1315. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1316.  
  1317. if( NULL != ch )
  1318. {
  1319. ch->RemoveAffect(AFFECT_MOUNT_BONUS);
  1320. ch->AddAffect(AFFECT_MOUNT_BONUS, aApplyInfo[applyOn].bPointType, value, AFF_NONE, duration, 0, false);
  1321. }
  1322.  
  1323. return 0;
  1324. }
  1325.  
  1326. int pc_unmount(lua_State* L)
  1327. {
  1328. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1329. ch->RemoveAffect(AFFECT_MOUNT);
  1330. ch->RemoveAffect(AFFECT_MOUNT_BONUS);
  1331. if (ch->IsHorseRiding())
  1332. ch->StopRiding();
  1333. return 0;
  1334. }
  1335.  
  1336. int pc_get_horse_level(lua_State* L)
  1337. {
  1338. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1339. lua_pushnumber(L, ch->GetHorseLevel());
  1340. return 1;
  1341. }
  1342.  
  1343. int pc_get_horse_hp(lua_State* L)
  1344. {
  1345. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1346. if (ch->GetHorseLevel())
  1347. lua_pushnumber(L, ch->GetHorseHealth());
  1348. else
  1349. lua_pushnumber(L, 0);
  1350.  
  1351. return 1;
  1352. }
  1353.  
  1354. int pc_get_horse_stamina(lua_State* L)
  1355. {
  1356. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1357. if (ch->GetHorseLevel())
  1358. lua_pushnumber(L, ch->GetHorseStamina());
  1359. else
  1360. lua_pushnumber(L, 0);
  1361.  
  1362. return 1;
  1363. }
  1364.  
  1365. int pc_is_horse_alive(lua_State* L)
  1366. {
  1367. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1368. lua_pushboolean(L, ch->GetHorseLevel() > 0 && ch->GetHorseHealth()>0);
  1369. return 1;
  1370. }
  1371.  
  1372. int pc_revive_horse(lua_State* L)
  1373. {
  1374. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1375. ch->ReviveHorse();
  1376. return 0;
  1377. }
  1378.  
  1379. int pc_have_map_scroll(lua_State* L)
  1380. {
  1381. if (!lua_isstring(L, 1))
  1382. {
  1383. lua_pushboolean(L, 0);
  1384. return 1;
  1385. }
  1386.  
  1387. const char * szMapName = lua_tostring(L, 1);
  1388. const TMapRegion * region = SECTREE_MANAGER::instance().FindRegionByPartialName(szMapName);
  1389.  
  1390. if (!region)
  1391. {
  1392. lua_pushboolean(L, 0);
  1393. return 1;
  1394. }
  1395.  
  1396. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1397.  
  1398. bool bFind = false;
  1399. for (int iCell = 0; iCell < INVENTORY_MAX_NUM; iCell++)
  1400. {
  1401. LPITEM item = ch->GetInventoryItem(iCell);
  1402. if (!item)
  1403. continue;
  1404.  
  1405. if (item->GetType() == ITEM_USE &&
  1406. item->GetSubType() == USE_TALISMAN &&
  1407. (item->GetValue(0) == 1 || item->GetValue(0) == 2))
  1408. {
  1409. int x = item->GetSocket(0);
  1410. int y = item->GetSocket(1);
  1411. //if ((x-item_x)*(x-item_x)+(y-item_y)*(y-item_y)<r*r)
  1412. if (region->sx <=x && region->sy <= y && x <= region->ex && y <= region->ey)
  1413. {
  1414. bFind = true;
  1415. break;
  1416. }
  1417. }
  1418. }
  1419.  
  1420. lua_pushboolean(L, bFind);
  1421. return 1;
  1422. }
  1423.  
  1424. int pc_get_war_map(lua_State* L)
  1425. {
  1426. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1427. lua_pushnumber(L, ch->GetWarMap() ? ch->GetWarMap()->GetMapIndex() : 0);
  1428. return 1;
  1429. }
  1430.  
  1431. int pc_have_pos_scroll(lua_State* L)
  1432. {
  1433. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1434.  
  1435. if (!lua_isnumber(L,1) || !lua_isnumber(L,2))
  1436. {
  1437. sys_err("invalid x y position");
  1438. lua_pushboolean(L, 0);
  1439. return 1;
  1440. }
  1441.  
  1442. if (!lua_isnumber(L,2))
  1443. {
  1444. sys_err("invalid radius");
  1445. lua_pushboolean(L, 0);
  1446. return 1;
  1447. }
  1448.  
  1449. int x = (int)lua_tonumber(L, 1);
  1450. int y = (int)lua_tonumber(L, 2);
  1451. float r = (float)lua_tonumber(L, 3);
  1452.  
  1453. bool bFind = false;
  1454. for (int iCell = 0; iCell < INVENTORY_MAX_NUM; iCell++)
  1455. {
  1456. LPITEM item = ch->GetInventoryItem(iCell);
  1457. if (!item)
  1458. continue;
  1459.  
  1460. if (item->GetType() == ITEM_USE &&
  1461. item->GetSubType() == USE_TALISMAN &&
  1462. (item->GetValue(0) == 1 || item->GetValue(0) == 2))
  1463. {
  1464. int item_x = item->GetSocket(0);
  1465. int item_y = item->GetSocket(1);
  1466. if ((x-item_x)*(x-item_x)+(y-item_y)*(y-item_y)<r*r)
  1467. {
  1468. bFind = true;
  1469. break;
  1470. }
  1471. }
  1472. }
  1473.  
  1474. lua_pushboolean(L, bFind);
  1475. return 1;
  1476. }
  1477.  
  1478. int pc_get_equip_refine_level(lua_State* L)
  1479. {
  1480. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1481. int cell = (int) lua_tonumber(L, 1);
  1482. if (cell < 0 || cell >= WEAR_MAX_NUM)
  1483. {
  1484. sys_err("invalid wear position %d", cell);
  1485. lua_pushnumber(L, 0);
  1486. return 1;
  1487. }
  1488.  
  1489. LPITEM item = ch->GetWear(cell);
  1490. if (!item)
  1491. {
  1492. lua_pushnumber(L, 0);
  1493. return 1;
  1494. }
  1495.  
  1496. lua_pushnumber(L, item->GetRefineLevel());
  1497. return 1;
  1498. }
  1499.  
  1500. int pc_refine_equip(lua_State* L)
  1501. {
  1502. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1503. if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2))
  1504. {
  1505. sys_err("invalid argument");
  1506. lua_pushboolean(L, 0);
  1507. return 1;
  1508. }
  1509.  
  1510. int cell = (int) lua_tonumber(L, 1);
  1511. int level_limit = (int) lua_tonumber(L, 2);
  1512. int pct = lua_isnumber(L, 3) ? (int)lua_tonumber(L, 3) : 100;
  1513.  
  1514. LPITEM item = ch->GetWear(cell);
  1515. if (!item)
  1516. {
  1517. lua_pushboolean(L, 0);
  1518. return 1;
  1519. }
  1520.  
  1521. if (item->GetRefinedVnum() == 0)
  1522. {
  1523. lua_pushboolean(L, 0);
  1524. return 1;
  1525. }
  1526.  
  1527. if (item->GetRefineLevel()>level_limit)
  1528. {
  1529. lua_pushboolean(L, 0);
  1530. return 1;
  1531. }
  1532.  
  1533. if (pct == 100 || number(1, 100) <= pct)
  1534. {
  1535. // 개량 성공
  1536. lua_pushboolean(L, 1);
  1537.  
  1538. LPITEM pkNewItem = ITEM_MANAGER::instance().CreateItem(item->GetRefinedVnum(), 1, 0, false);
  1539.  
  1540. if (pkNewItem)
  1541. {
  1542. for (int i = 0; i < ITEM_SOCKET_MAX_NUM; ++i)
  1543. if (!item->GetSocket(i))
  1544. break;
  1545. else
  1546. pkNewItem->SetSocket(i, 1);
  1547.  
  1548. int set = 0;
  1549. for (int i=0; i<ITEM_SOCKET_MAX_NUM; i++)
  1550. {
  1551. long socket = item->GetSocket(i);
  1552. if (socket > 2 && socket != 28960)
  1553. {
  1554. pkNewItem->SetSocket(set++, socket);
  1555. }
  1556. }
  1557.  
  1558. item->CopyAttributeTo(pkNewItem);
  1559.  
  1560. ITEM_MANAGER::instance().RemoveItem(item, "REMOVE (REFINE SUCCESS)");
  1561.  
  1562. // some tuits need here -_- pkNewItem->AddToCharacter(this, bCell);
  1563. pkNewItem->EquipTo(ch, cell);
  1564.  
  1565. ITEM_MANAGER::instance().FlushDelayedSave(pkNewItem);
  1566.  
  1567. LogManager::instance().ItemLog(ch, pkNewItem, "REFINE SUCCESS (QUEST)", pkNewItem->GetName());
  1568. }
  1569. }
  1570. else
  1571. {
  1572. // 개량 실패
  1573. lua_pushboolean(L, 0);
  1574. }
  1575.  
  1576. return 1;
  1577. }
  1578.  
  1579. int pc_get_skill_level(lua_State * L)
  1580. {
  1581. if (!lua_isnumber(L, 1))
  1582. {
  1583. sys_err("invalid argument");
  1584. lua_pushnumber(L, 0);
  1585. return 1;
  1586. }
  1587.  
  1588. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1589.  
  1590. DWORD dwVnum = (DWORD) lua_tonumber(L, 1);
  1591. lua_pushnumber(L, ch->GetSkillLevel(dwVnum));
  1592.  
  1593. return 1;
  1594. }
  1595.  
  1596. int pc_give_lotto(lua_State* L)
  1597. {
  1598. CQuestManager& q = CQuestManager::instance();
  1599. LPCHARACTER ch = q.GetCurrentCharacterPtr();
  1600.  
  1601. sys_log(0, "TRY GIVE LOTTO TO pid %u", ch->GetPlayerID());
  1602.  
  1603. DWORD * pdw = M2_NEW DWORD[3];
  1604.  
  1605. pdw[0] = 50001;
  1606. pdw[1] = 1;
  1607. pdw[2] = q.GetEventFlag("lotto_round");
  1608.  
  1609. // 추첨서는 소켓을 설정한다
  1610. DBManager::instance().ReturnQuery(QID_LOTTO, ch->GetPlayerID(), pdw,
  1611. "INSERT INTO lotto_list VALUES(0, 'server%s', %u, NOW())",
  1612. get_table_postfix(), ch->GetPlayerID());
  1613.  
  1614. return 0;
  1615. }
  1616.  
  1617. int pc_aggregate_monster(lua_State* L)
  1618. {
  1619. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1620. ch->AggregateMonster();
  1621. return 0;
  1622. }
  1623.  
  1624. int pc_forget_my_attacker(lua_State* L)
  1625. {
  1626. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1627. ch->ForgetMyAttacker();
  1628. return 0;
  1629. }
  1630.  
  1631. int pc_attract_ranger(lua_State* L)
  1632. {
  1633. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1634. ch->AttractRanger();
  1635. return 0;
  1636. }
  1637.  
  1638. int pc_select_pid(lua_State* L)
  1639. {
  1640. DWORD pid = (DWORD) lua_tonumber(L, 1);
  1641.  
  1642. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1643. LPCHARACTER new_ch = CHARACTER_MANAGER::instance().FindByPID(pid);
  1644.  
  1645. if (new_ch)
  1646. {
  1647. CQuestManager::instance().GetPC(new_ch->GetPlayerID());
  1648.  
  1649. lua_pushnumber(L, ch->GetPlayerID());
  1650. }
  1651. else
  1652. {
  1653. lua_pushnumber(L, 0);
  1654. }
  1655.  
  1656. return 1;
  1657. }
  1658.  
  1659. int pc_select_vid(lua_State* L)
  1660. {
  1661. DWORD vid = (DWORD) lua_tonumber(L, 1);
  1662.  
  1663. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1664. LPCHARACTER new_ch = CHARACTER_MANAGER::instance().Find(vid);
  1665.  
  1666. if (new_ch)
  1667. {
  1668. CQuestManager::instance().GetPC(new_ch->GetPlayerID());
  1669.  
  1670. lua_pushnumber(L, (DWORD)ch->GetVID());
  1671. }
  1672. else
  1673. {
  1674. lua_pushnumber(L, 0);
  1675. }
  1676.  
  1677. return 1;
  1678. }
  1679.  
  1680. int pc_get_sex(lua_State* L)
  1681. {
  1682. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1683. lua_pushnumber(L, GET_SEX(ch)); /* 0==MALE, 1==FEMALE */
  1684. return 1;
  1685. }
  1686.  
  1687. int pc_is_engaged(lua_State* L)
  1688. {
  1689. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1690. lua_pushboolean(L, marriage::CManager::instance().IsEngaged(ch->GetPlayerID()));
  1691. return 1;
  1692. }
  1693.  
  1694. int pc_is_married(lua_State* L)
  1695. {
  1696. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1697. lua_pushboolean(L, marriage::CManager::instance().IsMarried(ch->GetPlayerID()));
  1698. return 1;
  1699. }
  1700.  
  1701. int pc_is_engaged_or_married(lua_State* L)
  1702. {
  1703. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1704. lua_pushboolean(L, marriage::CManager::instance().IsEngagedOrMarried(ch->GetPlayerID()));
  1705. return 1;
  1706. }
  1707.  
  1708. int pc_is_gm(lua_State* L)
  1709. {
  1710. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1711. lua_pushboolean(L, ch->GetGMLevel() >= GM_HIGH_WIZARD);
  1712. return 1;
  1713. }
  1714.  
  1715. int pc_get_gm_level(lua_State* L)
  1716. {
  1717. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1718. lua_pushnumber(L, ch->GetGMLevel());
  1719. return 1;
  1720. }
  1721.  
  1722. int pc_mining(lua_State* L)
  1723. {
  1724. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1725. LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();
  1726. ch->mining(npc);
  1727. return 0;
  1728. }
  1729.  
  1730. int pc_unequip_from_index(lua_State * L)
  1731. {
  1732. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1733.  
  1734. if (!lua_isnumber(L, 1))
  1735. {
  1736. sys_err("wrong map index");
  1737. return 0;
  1738. }
  1739.  
  1740. if (!lua_isnumber(L, 2))
  1741. {
  1742. sys_err("wrong vnum");
  1743. return 0;
  1744. }
  1745.  
  1746. long lMapIndex = (long) lua_tonumber(L, 1);
  1747. DWORD vnum = (DWORD) lua_tonumber(L, 2);
  1748. //sys_err("pc_unequip_from_index vnum:%d map_index:%d", vnum, lMapIndex);
  1749. LPITEM item = NULL;
  1750. bool bResult = false;
  1751. if (lMapIndex == ch->GetMapIndex())
  1752. {
  1753. for(BYTE i = 0; i < WEAR_MAX_NUM; i++)
  1754. {
  1755. item = ch->GetWear(i);
  1756. if (item && item->GetVnum() == vnum)
  1757. {
  1758. if(ch->UnequipItem(item))
  1759. bResult = true;
  1760. }
  1761. }
  1762. }
  1763. lua_pushboolean(L, bResult);
  1764. return 1;
  1765. }
  1766.  
  1767. int pc_diamond_refine(lua_State* L)
  1768. {
  1769. if (!lua_isnumber(L, 1))
  1770. {
  1771. lua_pushboolean(L, 0);
  1772. return 1;
  1773. }
  1774.  
  1775. int cost = (int) lua_tonumber(L, 1);
  1776. int pct = (int)lua_tonumber(L, 2);
  1777.  
  1778. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1779. LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();
  1780. LPITEM item = CQuestManager::instance().GetCurrentItem();
  1781.  
  1782. if (item)
  1783. lua_pushboolean(L, mining::OreRefine(ch, npc, item, cost, pct, NULL));
  1784. else
  1785. lua_pushboolean(L, 0);
  1786.  
  1787. return 1;
  1788. }
  1789.  
  1790. int pc_ore_refine(lua_State* L)
  1791. {
  1792. if (!lua_isnumber(L, 1))
  1793. {
  1794. lua_pushboolean(L, 0);
  1795. return 1;
  1796. }
  1797.  
  1798. int cost = (int) lua_tonumber(L, 1);
  1799. int pct = (int)lua_tonumber(L, 2);
  1800. int metinstone_cell = (int)lua_tonumber(L, 3);
  1801.  
  1802. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1803. LPCHARACTER npc = CQuestManager::instance().GetCurrentNPCCharacterPtr();
  1804. LPITEM item = CQuestManager::instance().GetCurrentItem();
  1805.  
  1806. LPITEM metinstone_item = ch->GetInventoryItem(metinstone_cell);
  1807.  
  1808. if (item && metinstone_item)
  1809. lua_pushboolean(L, mining::OreRefine(ch, npc, item, cost, pct, metinstone_item));
  1810. else
  1811. lua_pushboolean(L, 0);
  1812.  
  1813. return 1;
  1814. }
  1815.  
  1816. int pc_clear_skill(lua_State* L)
  1817. {
  1818. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1819. if ( ch == NULL ) return 0;
  1820.  
  1821. ch->ClearSkill();
  1822.  
  1823. return 0;
  1824. }
  1825.  
  1826. int pc_clear_sub_skill(lua_State* L)
  1827. {
  1828. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1829. if ( ch == NULL ) return 0;
  1830.  
  1831. ch->ClearSubSkill();
  1832.  
  1833. return 0;
  1834. }
  1835.  
  1836. int pc_set_skill_point(lua_State* L)
  1837. {
  1838. if (!lua_isnumber(L, 1))
  1839. {
  1840. return 0;
  1841. }
  1842.  
  1843. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1844. int newPoint = (int) lua_tonumber(L, 1);
  1845.  
  1846. ch->SetRealPoint(POINT_SKILL, newPoint);
  1847. ch->SetPoint(POINT_SKILL, ch->GetRealPoint(POINT_SKILL));
  1848. ch->PointChange(POINT_SKILL, 0);
  1849. ch->ComputePoints();
  1850. ch->PointsPacket();
  1851.  
  1852. return 0;
  1853. }
  1854.  
  1855. // RESET_ONE_SKILL
  1856. int pc_clear_one_skill(lua_State* L)
  1857. {
  1858. int vnum = (int)lua_tonumber(L, 1);
  1859. sys_log(0, "%d skill clear", vnum);
  1860.  
  1861. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1862. if ( ch == NULL )
  1863. {
  1864. sys_log(0, "skill clear fail");
  1865. lua_pushnumber(L, 0);
  1866. return 1;
  1867. }
  1868.  
  1869. sys_log(0, "%d skill clear", vnum);
  1870.  
  1871. ch->ResetOneSkill(vnum);
  1872.  
  1873. return 0;
  1874. }
  1875. // END_RESET_ONE_SKILL
  1876.  
  1877. int pc_is_clear_skill_group(lua_State* L)
  1878. {
  1879. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1880.  
  1881. lua_pushboolean(L, ch->GetQuestFlag("skill_group_clear.clear") == 1);
  1882.  
  1883. return 1;
  1884. }
  1885.  
  1886. int pc_save_exit_location(lua_State* L)
  1887. {
  1888. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1889.  
  1890. ch->SaveExitLocation();
  1891.  
  1892. return 0;
  1893. }
  1894.  
  1895. //텔레포트
  1896. int pc_teleport ( lua_State * L )
  1897. {
  1898. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1899. int x=0,y=0;
  1900. if ( lua_isnumber(L, 1) )
  1901. {
  1902. // 지역명 워프
  1903. const int TOWN_NUM = 10;
  1904. struct warp_by_town_name
  1905. {
  1906. const char* name;
  1907. DWORD x;
  1908. DWORD y;
  1909. } ws[TOWN_NUM] =
  1910. {
  1911. {"영안읍성", 4743, 9548},
  1912. {"임지곡", 3235, 9086},
  1913. {"자양현", 3531, 8829},
  1914. {"조안읍성", 638, 1664},
  1915. {"승룡곡", 1745, 1909},
  1916. {"복정현", 1455, 2400},
  1917. {"평무읍성", 9599, 2692},
  1918. {"방산곡", 8036, 2984},
  1919. {"박라현", 8639, 2460},
  1920. {"서한산", 4350, 2143},
  1921. };
  1922. int idx = (int)lua_tonumber(L, 1);
  1923.  
  1924. x = ws[idx].x;
  1925. y = ws[idx].y;
  1926. goto teleport_area;
  1927. }
  1928.  
  1929. else
  1930. {
  1931. const char * arg1 = lua_tostring(L, 1);
  1932.  
  1933. LPCHARACTER tch = CHARACTER_MANAGER::instance().FindPC(arg1);
  1934.  
  1935. if (!tch)
  1936. {
  1937. const CCI* pkCCI = P2P_MANAGER::instance().Find(arg1);
  1938.  
  1939. if (pkCCI)
  1940. {
  1941. if (pkCCI->bChannel != g_bChannel)
  1942. {
  1943. ch->ChatPacket(CHAT_TYPE_INFO, "Target is in %d channel (my channel %d)", pkCCI->bChannel, g_bChannel);
  1944. }
  1945. else
  1946. {
  1947.  
  1948. PIXEL_POSITION pos;
  1949.  
  1950. if (!SECTREE_MANAGER::instance().GetCenterPositionOfMap(pkCCI->lMapIndex, pos))
  1951. {
  1952. ch->ChatPacket(CHAT_TYPE_INFO, "Cannot find map (index %d)", pkCCI->lMapIndex);
  1953. }
  1954. else
  1955. {
  1956. ch->ChatPacket(CHAT_TYPE_INFO, "You warp to ( %d, %d )", pos.x, pos.y);
  1957. ch->WarpSet(pos.x, pos.y);
  1958. lua_pushnumber(L, 1 );
  1959. }
  1960. }
  1961. }
  1962. else if (NULL == CHARACTER_MANAGER::instance().FindPC(arg1))
  1963. {
  1964. ch->ChatPacket(CHAT_TYPE_INFO, "There is no one by that name");
  1965. }
  1966.  
  1967. lua_pushnumber(L, 0 );
  1968.  
  1969. return 1;
  1970. }
  1971. else
  1972. {
  1973. x = tch->GetX() / 100;
  1974. y = tch->GetY() / 100;
  1975. }
  1976. }
  1977.  
  1978. teleport_area:
  1979.  
  1980. x *= 100;
  1981. y *= 100;
  1982.  
  1983. ch->ChatPacket(CHAT_TYPE_INFO, "You warp to ( %d, %d )", x, y);
  1984. ch->WarpSet(x,y);
  1985. ch->Stop();
  1986. lua_pushnumber(L, 1 );
  1987. return 1;
  1988. }
  1989.  
  1990. int pc_set_skill_level(lua_State* L)
  1991. {
  1992. DWORD dwVnum = (DWORD)lua_tonumber(L, 1);
  1993. BYTE byLev = (BYTE)lua_tonumber(L, 2);
  1994.  
  1995. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  1996. ch->SetSkillLevel(dwVnum, byLev);
  1997.  
  1998. ch->SkillLevelPacket();
  1999.  
  2000. return 0;
  2001. }
  2002.  
  2003. int pc_give_polymorph_book(lua_State* L)
  2004. {
  2005. if ( lua_isnumber(L, 1) != true && lua_isnumber(L, 2) != true && lua_isnumber(L, 3) != true && lua_isnumber(L, 4) != true )
  2006. {
  2007. sys_err("Wrong Quest Function Arguments: pc_give_polymorph_book");
  2008. return 0;
  2009. }
  2010.  
  2011. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2012.  
  2013. CPolymorphUtils::instance().GiveBook(ch, (DWORD)lua_tonumber(L, 1), (DWORD)lua_tonumber(L, 2), (BYTE)lua_tonumber(L, 3), (BYTE)lua_tonumber(L, 4));
  2014.  
  2015. return 0;
  2016. }
  2017.  
  2018. int pc_upgrade_polymorph_book(lua_State* L)
  2019. {
  2020. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2021. LPITEM pItem = CQuestManager::instance().GetCurrentItem();
  2022.  
  2023. bool ret = CPolymorphUtils::instance().BookUpgrade(ch, pItem);
  2024.  
  2025. lua_pushboolean(L, ret);
  2026.  
  2027. return 1;
  2028. }
  2029.  
  2030. int pc_get_premium_remain_sec(lua_State* L)
  2031. {
  2032. int remain_seconds = 0;
  2033. int premium_type = 0;
  2034. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2035.  
  2036. if (!lua_isnumber(L, 1))
  2037. {
  2038. sys_err("wrong premium index (is not number)");
  2039. return 0;
  2040. }
  2041.  
  2042. premium_type = (int)lua_tonumber(L,1);
  2043. switch (premium_type)
  2044. {
  2045. case PREMIUM_EXP:
  2046. case PREMIUM_ITEM:
  2047. case PREMIUM_SAFEBOX:
  2048. case PREMIUM_AUTOLOOT:
  2049. case PREMIUM_FISH_MIND:
  2050. case PREMIUM_MARRIAGE_FAST:
  2051. case PREMIUM_GOLD:
  2052. break;
  2053.  
  2054. default:
  2055. sys_err("wrong premium index %d", premium_type);
  2056. return 0;
  2057. }
  2058.  
  2059. remain_seconds = ch->GetPremiumRemainSeconds(premium_type);
  2060.  
  2061. lua_pushnumber(L, remain_seconds);
  2062. return 1;
  2063. }
  2064.  
  2065. int pc_send_block_mode(lua_State* L)
  2066. {
  2067. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2068.  
  2069. ch->SetBlockModeForce((BYTE)lua_tonumber(L, 1));
  2070.  
  2071. return 0;
  2072. }
  2073.  
  2074. int pc_change_empire(lua_State* L)
  2075. {
  2076. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2077.  
  2078. lua_pushnumber(L, ch->ChangeEmpire((unsigned char)lua_tonumber(L, 1)));
  2079.  
  2080. return 1;
  2081. }
  2082.  
  2083. int pc_get_change_empire_count(lua_State* L)
  2084. {
  2085. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2086.  
  2087. lua_pushnumber(L, ch->GetChangeEmpireCount());
  2088.  
  2089. return 1;
  2090. }
  2091.  
  2092. int pc_set_change_empire_count(lua_State* L)
  2093. {
  2094. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2095.  
  2096. ch->SetChangeEmpireCount();
  2097.  
  2098. return 0;
  2099. }
  2100.  
  2101. int pc_change_name(lua_State* L)
  2102. {
  2103. // 리턴값
  2104. // 0: 새이름을 설정한 뒤 로그아웃을 안했음
  2105. // 1: 스크립트에서 문자열이 넘어오지 않았음
  2106. // 2: check_name 을 통과하지 못했음
  2107. // 3: 이미 같은 이름이 사용중
  2108. // 4: 성공
  2109.  
  2110. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2111.  
  2112. if ( ch->GetNewName().size() != 0 )
  2113. {
  2114. lua_pushnumber(L, 0);
  2115. return 1;
  2116. }
  2117.  
  2118. if ( lua_isstring(L, 1) != true )
  2119. {
  2120. lua_pushnumber(L, 1);
  2121. return 1;
  2122. }
  2123.  
  2124. const char * szName = lua_tostring(L, 1);
  2125.  
  2126. if ( check_name(szName) == false )
  2127. {
  2128. lua_pushnumber(L, 2);
  2129. return 1;
  2130. }
  2131.  
  2132. char szQuery[1024];
  2133. snprintf(szQuery, sizeof(szQuery), "SELECT COUNT(*) FROM player%s WHERE name='%s'", get_table_postfix(), szName);
  2134. std::auto_ptr<SQLMsg> pmsg(DBManager::instance().DirectQuery(szQuery));
  2135.  
  2136. if ( pmsg->Get()->uiNumRows > 0 )
  2137. {
  2138. MYSQL_ROW row = mysql_fetch_row(pmsg->Get()->pSQLResult);
  2139.  
  2140. int count = 0;
  2141. str_to_number(count, row[0]);
  2142.  
  2143. // 이미 해당 이름을 가진 캐릭터가 있음
  2144. if ( count != 0 )
  2145. {
  2146. lua_pushnumber(L, 3);
  2147. return 1;
  2148. }
  2149. }
  2150.  
  2151. DWORD pid = ch->GetPlayerID();
  2152. db_clientdesc->DBPacketHeader(HEADER_GD_FLUSH_CACHE, 0, sizeof(DWORD));
  2153. db_clientdesc->Packet(&pid, sizeof(DWORD));
  2154.  
  2155. /* delete messenger list */
  2156. MessengerManager::instance().RemoveAllList(ch->GetName());
  2157.  
  2158. /* change_name_log */
  2159. LogManager::instance().ChangeNameLog(pid, ch->GetName(), szName, ch->GetDesc()->GetHostName());
  2160.  
  2161. snprintf(szQuery, sizeof(szQuery), "UPDATE player%s SET name='%s' WHERE id=%u", get_table_postfix(), szName, pid);
  2162. SQLMsg * msg = DBManager::instance().DirectQuery(szQuery);
  2163. M2_DELETE(msg);
  2164.  
  2165. ch->SetNewName(szName);
  2166. lua_pushnumber(L, 4);
  2167. return 1;
  2168. }
  2169.  
  2170. int pc_is_dead(lua_State* L)
  2171. {
  2172. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2173.  
  2174. if ( ch != NULL )
  2175. {
  2176. lua_pushboolean(L, ch->IsDead());
  2177. return 1;
  2178. }
  2179.  
  2180. lua_pushboolean(L, true);
  2181.  
  2182. return 1;
  2183. }
  2184.  
  2185. int pc_reset_status( lua_State* L )
  2186. {
  2187. if ( lua_isnumber(L, 1) == true )
  2188. {
  2189. int idx = (int)lua_tonumber(L, 1);
  2190.  
  2191. if ( idx >= 0 && idx < 4 )
  2192. {
  2193. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2194. int point = POINT_NONE;
  2195. char buf[128];
  2196.  
  2197. switch ( idx )
  2198. {
  2199. case 0 : point = POINT_HT; break;
  2200. case 1 : point = POINT_IQ; break;
  2201. case 2 : point = POINT_ST; break;
  2202. case 3 : point = POINT_DX; break;
  2203. default : lua_pushboolean(L, false); return 1;
  2204. }
  2205.  
  2206. int old_val = ch->GetRealPoint(point);
  2207. int old_stat = ch->GetRealPoint(POINT_STAT);
  2208.  
  2209. ch->SetRealPoint(point, 1);
  2210. ch->SetPoint(point, ch->GetRealPoint(point));
  2211.  
  2212. ch->PointChange(POINT_STAT, old_val-1);
  2213.  
  2214. if ( point == POINT_HT )
  2215. {
  2216. BYTE job = ch->GetJob();
  2217. ch->SetRandomHP((ch->GetLevel()-1) * number(JobInitialPoints[job].hp_per_lv_begin, JobInitialPoints[job].hp_per_lv_end));
  2218. }
  2219. else if ( point == POINT_IQ )
  2220. {
  2221. BYTE job = ch->GetJob();
  2222. ch->SetRandomSP((ch->GetLevel()-1) * number(JobInitialPoints[job].sp_per_lv_begin, JobInitialPoints[job].sp_per_lv_end));
  2223. }
  2224.  
  2225. ch->ComputePoints();
  2226. ch->PointsPacket();
  2227.  
  2228. if ( point == POINT_HT )
  2229. {
  2230. ch->PointChange(POINT_HP, ch->GetMaxHP() - ch->GetHP());
  2231. }
  2232. else if ( point == POINT_IQ )
  2233. {
  2234. ch->PointChange(POINT_SP, ch->GetMaxSP() - ch->GetSP());
  2235. }
  2236.  
  2237. switch ( idx )
  2238. {
  2239. case 0 :
  2240. snprintf(buf, sizeof(buf), "reset ht(%d)->1 stat_point(%d)->(%d)", old_val, old_stat, ch->GetRealPoint(POINT_STAT));
  2241. break;
  2242. case 1 :
  2243. snprintf(buf, sizeof(buf), "reset iq(%d)->1 stat_point(%d)->(%d)", old_val, old_stat, ch->GetRealPoint(POINT_STAT));
  2244. break;
  2245. case 2 :
  2246. snprintf(buf, sizeof(buf), "reset st(%d)->1 stat_point(%d)->(%d)", old_val, old_stat, ch->GetRealPoint(POINT_STAT));
  2247. break;
  2248. case 3 :
  2249. snprintf(buf, sizeof(buf), "reset dx(%d)->1 stat_point(%d)->(%d)", old_val, old_stat, ch->GetRealPoint(POINT_STAT));
  2250. break;
  2251. }
  2252.  
  2253. LogManager::instance().CharLog(ch, 0, "RESET_ONE_STATUS", buf);
  2254.  
  2255. lua_pushboolean(L, true);
  2256. return 1;
  2257. }
  2258. }
  2259.  
  2260. lua_pushboolean(L, false);
  2261. return 1;
  2262. }
  2263.  
  2264. int pc_get_ht( lua_State* L )
  2265. {
  2266. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2267. lua_pushnumber(L, ch->GetRealPoint(POINT_HT));
  2268. return 1;
  2269. }
  2270.  
  2271. int pc_set_ht( lua_State* L )
  2272. {
  2273. if ( lua_isnumber(L, 1) == false )
  2274. return 1;
  2275.  
  2276. int newPoint = (int)lua_tonumber(L, 1);
  2277.  
  2278. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2279. int usedPoint = newPoint - ch->GetRealPoint(POINT_HT);
  2280. ch->SetRealPoint(POINT_HT, newPoint);
  2281. ch->PointChange(POINT_HT, 0);
  2282. ch->PointChange(POINT_STAT, -usedPoint);
  2283. ch->ComputePoints();
  2284. ch->PointsPacket();
  2285. return 1;
  2286. }
  2287.  
  2288. int pc_get_iq( lua_State* L )
  2289. {
  2290. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2291. lua_pushnumber(L, ch->GetRealPoint(POINT_IQ));
  2292. return 1;
  2293. }
  2294.  
  2295. int pc_set_iq( lua_State* L )
  2296. {
  2297. if ( lua_isnumber(L, 1) == false )
  2298. return 1;
  2299.  
  2300. int newPoint = (int)lua_tonumber(L, 1);
  2301.  
  2302. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2303. int usedPoint = newPoint - ch->GetRealPoint(POINT_IQ);
  2304. ch->SetRealPoint(POINT_IQ, newPoint);
  2305. ch->PointChange(POINT_IQ, 0);
  2306. ch->PointChange(POINT_STAT, -usedPoint);
  2307. ch->ComputePoints();
  2308. ch->PointsPacket();
  2309. return 1;
  2310. }
  2311.  
  2312. int pc_get_st( lua_State* L )
  2313. {
  2314. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2315. lua_pushnumber(L, ch->GetRealPoint(POINT_ST));
  2316. return 1;
  2317. }
  2318.  
  2319. int pc_set_st( lua_State* L )
  2320. {
  2321. if ( lua_isnumber(L, 1) == false )
  2322. return 1;
  2323.  
  2324. int newPoint = (int)lua_tonumber(L, 1);
  2325.  
  2326. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2327. int usedPoint = newPoint - ch->GetRealPoint(POINT_ST);
  2328. ch->SetRealPoint(POINT_ST, newPoint);
  2329. ch->PointChange(POINT_ST, 0);
  2330. ch->PointChange(POINT_STAT, -usedPoint);
  2331. ch->ComputePoints();
  2332. ch->PointsPacket();
  2333. return 1;
  2334. }
  2335.  
  2336. int pc_get_dx( lua_State* L )
  2337. {
  2338. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2339. lua_pushnumber(L, ch->GetRealPoint(POINT_DX));
  2340. return 1;
  2341. }
  2342.  
  2343. int pc_set_dx( lua_State* L )
  2344. {
  2345. if ( lua_isnumber(L, 1) == false )
  2346. return 1;
  2347.  
  2348. int newPoint = (int)lua_tonumber(L, 1);
  2349.  
  2350. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2351. int usedPoint = newPoint - ch->GetRealPoint(POINT_DX);
  2352. ch->SetRealPoint(POINT_DX, newPoint);
  2353. ch->PointChange(POINT_DX, 0);
  2354. ch->PointChange(POINT_STAT, -usedPoint);
  2355. ch->ComputePoints();
  2356. ch->PointsPacket();
  2357. return 1;
  2358. }
  2359.  
  2360. int pc_is_near_vid( lua_State* L )
  2361. {
  2362. if ( lua_isnumber(L, 1) != true || lua_isnumber(L, 2) != true )
  2363. {
  2364. lua_pushboolean(L, false);
  2365. }
  2366. else
  2367. {
  2368. LPCHARACTER pMe = CQuestManager::instance().GetCurrentCharacterPtr();
  2369. LPCHARACTER pOther = CHARACTER_MANAGER::instance().Find( (DWORD)lua_tonumber(L, 1) );
  2370.  
  2371. if ( pMe != NULL && pOther != NULL )
  2372. {
  2373. lua_pushboolean(L, (DISTANCE_APPROX(pMe->GetX() - pOther->GetX(), pMe->GetY() - pOther->GetY()) < (int)lua_tonumber(L, 2)*100));
  2374. }
  2375. else
  2376. {
  2377. lua_pushboolean(L, false);
  2378. }
  2379. }
  2380.  
  2381. return 1;
  2382. }
  2383.  
  2384. int pc_get_socket_items( lua_State* L )
  2385. {
  2386. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2387.  
  2388. lua_newtable( L );
  2389.  
  2390. if ( pChar == NULL ) return 1;
  2391.  
  2392. int idx = 1;
  2393.  
  2394. // 용혼석 슬롯은 할 필요 없을 듯.
  2395. // 이 함수는 탈석서용 함수인 듯 하다.
  2396. for ( int i=0; i < INVENTORY_MAX_NUM + WEAR_MAX_NUM; i++ )
  2397. {
  2398. LPITEM pItem = pChar->GetInventoryItem(i);
  2399.  
  2400. if ( pItem != NULL )
  2401. {
  2402. if ( pItem->IsEquipped() == false )
  2403. {
  2404. int j = 0;
  2405. for (; j < ITEM_SOCKET_MAX_NUM; j++ )
  2406. {
  2407. long socket = pItem->GetSocket(j);
  2408.  
  2409. if ( socket > 2 && socket != ITEM_BROKEN_METIN_VNUM )
  2410. {
  2411. TItemTable* pItemInfo = ITEM_MANAGER::instance().GetTable( socket );
  2412. if ( pItemInfo != NULL )
  2413. {
  2414. if ( pItemInfo->bType == ITEM_METIN ) break;
  2415. }
  2416. }
  2417. }
  2418.  
  2419. if ( j >= ITEM_SOCKET_MAX_NUM ) continue;
  2420.  
  2421. lua_newtable( L );
  2422.  
  2423. {
  2424. lua_pushstring( L, pItem->GetName() );
  2425. lua_rawseti( L, -2, 1 );
  2426.  
  2427. lua_pushnumber( L, i );
  2428. lua_rawseti( L, -2, 2 );
  2429. }
  2430.  
  2431. lua_rawseti( L, -2, idx++ );
  2432. }
  2433. }
  2434. }
  2435.  
  2436. return 1;
  2437. }
  2438.  
  2439. int pc_get_empty_inventory_count( lua_State* L )
  2440. {
  2441. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2442.  
  2443. if ( pChar != NULL )
  2444. {
  2445. lua_pushnumber(L, pChar->CountEmptyInventory());
  2446. }
  2447. else
  2448. {
  2449. lua_pushnumber(L, 0);
  2450. }
  2451.  
  2452. return 1;
  2453. }
  2454.  
  2455. int pc_get_logoff_interval( lua_State* L )
  2456. {
  2457. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2458.  
  2459. if ( pChar != NULL )
  2460. {
  2461. lua_pushnumber(L, pChar->GetLogOffInterval());
  2462. }
  2463. else
  2464. {
  2465. lua_pushnumber(L, 0);
  2466. }
  2467.  
  2468. return 1;
  2469. }
  2470.  
  2471. int pc_get_player_id( lua_State* L )
  2472. {
  2473. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2474.  
  2475. if ( pChar != NULL )
  2476. {
  2477. lua_pushnumber( L, pChar->GetPlayerID() );
  2478. }
  2479. else
  2480. {
  2481. lua_pushnumber( L, 0 );
  2482. }
  2483.  
  2484. return 1;
  2485. }
  2486.  
  2487. int pc_get_account_id( lua_State* L )
  2488. {
  2489. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2490.  
  2491. if ( pChar != NULL )
  2492. {
  2493. if ( pChar->GetDesc() != NULL )
  2494. {
  2495. lua_pushnumber( L, pChar->GetDesc()->GetAccountTable().id );
  2496. return 1;
  2497. }
  2498. }
  2499.  
  2500. lua_pushnumber( L, 0 );
  2501. return 1;
  2502. }
  2503.  
  2504. int pc_get_account( lua_State* L )
  2505. {
  2506. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2507.  
  2508. if( NULL != pChar )
  2509. {
  2510. if( NULL != pChar->GetDesc() )
  2511. {
  2512. lua_pushstring( L, pChar->GetDesc()->GetAccountTable().login );
  2513. return 1;
  2514. }
  2515. }
  2516.  
  2517. lua_pushstring( L, "" );
  2518. return 1;
  2519. }
  2520.  
  2521. int pc_is_riding(lua_State* L)
  2522. {
  2523. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2524.  
  2525. if( NULL != pChar )
  2526. {
  2527. bool is_riding = pChar->IsRiding();
  2528.  
  2529. lua_pushboolean(L, is_riding);
  2530.  
  2531. return 1;
  2532. }
  2533.  
  2534. lua_pushboolean(L, false);
  2535. return 1;
  2536. }
  2537.  
  2538. int pc_get_special_ride_vnum(lua_State* L)
  2539. {
  2540. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2541.  
  2542. if (NULL != pChar)
  2543. {
  2544. LPITEM Unique1 = pChar->GetWear(WEAR_UNIQUE1);
  2545. LPITEM Unique2 = pChar->GetWear(WEAR_UNIQUE2);
  2546.  
  2547. if (NULL != Unique1)
  2548. {
  2549. if (UNIQUE_GROUP_SPECIAL_RIDE == Unique1->GetSpecialGroup())
  2550. {
  2551. lua_pushnumber(L, Unique1->GetVnum());
  2552. lua_pushnumber(L, Unique1->GetSocket(2));
  2553. return 2;
  2554. }
  2555. }
  2556.  
  2557. if (NULL != Unique2)
  2558. {
  2559. if (UNIQUE_GROUP_SPECIAL_RIDE == Unique2->GetSpecialGroup())
  2560. {
  2561. lua_pushnumber(L, Unique2->GetVnum());
  2562. lua_pushnumber(L, Unique2->GetSocket(2));
  2563. return 2;
  2564. }
  2565. }
  2566. }
  2567.  
  2568. lua_pushnumber(L, 0);
  2569. lua_pushnumber(L, 0);
  2570.  
  2571. return 2;
  2572. }
  2573.  
  2574. int pc_can_warp(lua_State* L)
  2575. {
  2576. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2577.  
  2578. if (NULL != pChar)
  2579. {
  2580. lua_pushboolean(L, pChar->CanWarp());
  2581. }
  2582. else
  2583. {
  2584. lua_pushboolean(L, false);
  2585. }
  2586.  
  2587. return 1;
  2588. }
  2589.  
  2590. int pc_dec_skill_point(lua_State* L)
  2591. {
  2592. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2593.  
  2594. if (NULL != pChar)
  2595. {
  2596. pChar->PointChange(POINT_SKILL, -1);
  2597. }
  2598.  
  2599. return 0;
  2600. }
  2601.  
  2602. int pc_get_skill_point(lua_State* L)
  2603. {
  2604. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2605.  
  2606. if (NULL != pChar)
  2607. {
  2608. lua_pushnumber(L, pChar->GetPoint(POINT_SKILL));
  2609. }
  2610. else
  2611. {
  2612. lua_pushnumber(L, 0);
  2613. }
  2614.  
  2615. return 1;
  2616. }
  2617.  
  2618. int pc_get_channel_id(lua_State* L)
  2619. {
  2620. lua_pushnumber(L, g_bChannel);
  2621.  
  2622. return 1;
  2623. }
  2624.  
  2625. int pc_give_poly_marble(lua_State* L)
  2626. {
  2627. const int dwVnum = lua_tonumber(L, 1);
  2628.  
  2629. const CMob* MobInfo = CMobManager::instance().Get(dwVnum);
  2630.  
  2631. if (NULL == MobInfo)
  2632. {
  2633. lua_pushboolean(L, false);
  2634. return 1;
  2635. }
  2636.  
  2637. if (0 == MobInfo->m_table.dwPolymorphItemVnum)
  2638. {
  2639. lua_pushboolean(L, false);
  2640. return 1;
  2641. }
  2642.  
  2643. LPITEM item = ITEM_MANAGER::instance().CreateItem( MobInfo->m_table.dwPolymorphItemVnum );
  2644.  
  2645. if (NULL == item)
  2646. {
  2647. lua_pushboolean(L, false);
  2648. return 1;
  2649. }
  2650.  
  2651. item->SetSocket(0, dwVnum);
  2652.  
  2653. const LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2654.  
  2655. int iEmptyCell = ch->GetEmptyInventory(item->GetSize());
  2656.  
  2657. if (-1 == iEmptyCell)
  2658. {
  2659. M2_DESTROY_ITEM(item);
  2660. lua_pushboolean(L, false);
  2661. return 1;
  2662. }
  2663.  
  2664. item->AddToCharacter(ch, TItemPos(INVENTORY, iEmptyCell));
  2665.  
  2666. const PC* pPC = CQuestManager::instance().GetCurrentPC();
  2667.  
  2668. LogManager::instance().QuestRewardLog(pPC->GetCurrentQuestName().c_str(), ch->GetPlayerID(), ch->GetLevel(), MobInfo->m_table.dwPolymorphItemVnum, dwVnum);
  2669.  
  2670. lua_pushboolean(L, true);
  2671.  
  2672. return 1;
  2673. }
  2674.  
  2675. int pc_get_sig_items (lua_State* L)
  2676. {
  2677. DWORD group_vnum = (DWORD)lua_tonumber (L, 1);
  2678. const LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2679. int count = 0;
  2680. for (int i = 0; i < INVENTORY_MAX_NUM; ++i)
  2681. {
  2682. if (ch->GetInventoryItem(i) != NULL && ch->GetInventoryItem(i)->GetSIGVnum() == group_vnum)
  2683. {
  2684. lua_pushnumber(L, ch->GetInventoryItem(i)->GetID());
  2685. count++;
  2686. }
  2687. }
  2688.  
  2689. return count;
  2690. }
  2691.  
  2692. int pc_charge_cash(lua_State * L)
  2693. {
  2694. TRequestChargeCash packet;
  2695.  
  2696. int amount = lua_isnumber(L, 1) ? (int)lua_tonumber(L, 1) : 0;
  2697. std::string strChargeType = lua_isstring(L, 2) ? lua_tostring(L, 2) : "";
  2698.  
  2699. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2700.  
  2701. if (NULL == ch || NULL == ch->GetDesc() || 1 > amount || 50000 < amount)
  2702. {
  2703. lua_pushboolean(L, 0);
  2704. return 1;
  2705. }
  2706.  
  2707. packet.dwAID = ch->GetDesc()->GetAccountTable().id;
  2708. packet.dwAmount = (DWORD)amount;
  2709. packet.eChargeType = ERequestCharge_Cash;
  2710.  
  2711. if (0 < strChargeType.length())
  2712. std::transform(strChargeType.begin(), strChargeType.end(), strChargeType.begin(), (int(*)(int))std::tolower);
  2713.  
  2714. if ("mileage" == strChargeType)
  2715. packet.eChargeType = ERequestCharge_Mileage;
  2716.  
  2717. db_clientdesc->DBPacketHeader(HEADER_GD_REQUEST_CHARGE_CASH, 0, sizeof(TRequestChargeCash));
  2718. db_clientdesc->Packet(&packet, sizeof(packet));
  2719.  
  2720. lua_pushboolean(L, 1);
  2721. return 1;
  2722. }
  2723.  
  2724. int pc_give_award(lua_State* L)
  2725. {
  2726. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2727.  
  2728. if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isstring(L, 3) )
  2729. {
  2730. sys_err("QUEST give award call error : wrong argument");
  2731. lua_pushnumber (L, 0);
  2732. return 1;
  2733. }
  2734.  
  2735. DWORD dwVnum = (int) lua_tonumber(L, 1);
  2736.  
  2737. int icount = (int) lua_tonumber(L, 2);
  2738.  
  2739. sys_log(0, "QUEST [award] item %d to login %s", dwVnum, ch->GetDesc()->GetAccountTable().login);
  2740.  
  2741. DBManager::instance().Query("INSERT INTO item_award (login, vnum, count, given_time, why, mall)select '%s', %d, %d, now(), '%s', 1 from DUAL where not exists (select login, why from item_award where login = '%s' and why = '%s') ;",
  2742. ch->GetDesc()->GetAccountTable().login,
  2743. dwVnum,
  2744. icount,
  2745. lua_tostring(L,3),
  2746. ch->GetDesc()->GetAccountTable().login,
  2747. lua_tostring(L,3));
  2748.  
  2749. lua_pushnumber (L, 0);
  2750. return 1;
  2751. }
  2752. int pc_give_award_socket(lua_State* L)
  2753. {
  2754. LPCHARACTER ch = CQuestManager::instance().GetCurrentCharacterPtr();
  2755.  
  2756. if (!lua_isnumber(L, 1) || !lua_isnumber(L, 2) || !lua_isstring(L, 3) || !lua_isstring(L, 4) || !lua_isstring(L, 5) || !lua_isstring(L, 6) )
  2757. {
  2758. sys_err("QUEST give award call error : wrong argument");
  2759. lua_pushnumber (L, 0);
  2760. return 1;
  2761. }
  2762.  
  2763. DWORD dwVnum = (int) lua_tonumber(L, 1);
  2764.  
  2765. int icount = (int) lua_tonumber(L, 2);
  2766.  
  2767. sys_log(0, "QUEST [award] item %d to login %s", dwVnum, ch->GetDesc()->GetAccountTable().login);
  2768.  
  2769. DBManager::instance().Query("INSERT INTO item_award (login, vnum, count, given_time, why, mall, socket0, socket1, socket2)select '%s', %d, %d, now(), '%s', 1, %s, %s, %s from DUAL where not exists (select login, why from item_award where login = '%s' and why = '%s') ;",
  2770. ch->GetDesc()->GetAccountTable().login,
  2771. dwVnum,
  2772. icount,
  2773. lua_tostring(L,3),
  2774. lua_tostring(L,4),
  2775. lua_tostring(L,5),
  2776. lua_tostring(L,6),
  2777. ch->GetDesc()->GetAccountTable().login,
  2778. lua_tostring(L,3));
  2779.  
  2780. lua_pushnumber (L, 0);
  2781. return 1;
  2782. }
  2783.  
  2784. int pc_get_informer_type(lua_State* L) //독일 선물 기능
  2785. {
  2786. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2787.  
  2788. if( pChar != NULL )
  2789. {
  2790. //sys_err("quest cmd test %s", pChar->GetItemAward_cmd() );
  2791. lua_pushstring(L, pChar->GetItemAward_cmd() );
  2792. }
  2793. else
  2794. lua_pushstring(L, "" );
  2795.  
  2796. return 1;
  2797. }
  2798.  
  2799. int pc_get_informer_item(lua_State* L)
  2800. {
  2801. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2802.  
  2803. if( pChar != NULL )
  2804. {
  2805. lua_pushnumber(L, pChar->GetItemAward_vnum() );
  2806. }
  2807. else
  2808. lua_pushnumber(L,0);
  2809.  
  2810. return 1;
  2811. }
  2812.  
  2813. int pc_get_killee_drop_pct(lua_State* L)
  2814. {
  2815. LPCHARACTER pChar = CQuestManager::instance().GetCurrentCharacterPtr();
  2816. LPCHARACTER pKillee = pChar->GetQuestNPC();
  2817.  
  2818. int iDeltaPercent, iRandRange;
  2819. if (NULL == pKillee || !ITEM_MANAGER::instance().GetDropPct(pKillee, pChar, iDeltaPercent, iRandRange))
  2820. {
  2821. sys_err("killee is null");
  2822. lua_pushnumber(L, -1);
  2823. lua_pushnumber(L, -1);
  2824.  
  2825. return 2;
  2826. }
  2827.  
  2828. lua_pushnumber(L, iDeltaPercent);
  2829. lua_pushnumber(L, iRandRange);
  2830.  
  2831. return 2;
  2832. }
  2833.  
  2834. void RegisterPCFunctionTable()
  2835. {
  2836. luaL_reg pc_functions[] =
  2837. {
  2838. { "get_wear", pc_get_wear },
  2839. { "get_player_id", pc_get_player_id },
  2840. { "get_account_id", pc_get_account_id },
  2841. { "get_account", pc_get_account },
  2842. { "get_level", pc_get_level },
  2843. { "set_level", pc_set_level },
  2844. { "get_next_exp", pc_get_next_exp },
  2845. { "get_exp", pc_get_exp },
  2846. { "get_job", pc_get_job },
  2847. { "get_race", pc_get_race },
  2848. { "change_sex", pc_change_sex },
  2849. { "gethp", pc_get_hp },
  2850. { "get_hp", pc_get_hp },
  2851. { "getmaxhp", pc_get_max_hp },
  2852. { "get_max_hp", pc_get_max_hp },
  2853. { "getsp", pc_get_sp },
  2854. { "get_sp", pc_get_sp },
  2855. { "getmaxsp", pc_get_max_sp },
  2856. { "get_max_sp", pc_get_max_sp },
  2857. { "change_sp", pc_change_sp },
  2858. { "getmoney", pc_get_money },
  2859. { "get_money", pc_get_money },
  2860. { "get_real_alignment", pc_get_real_alignment },
  2861. { "get_alignment", pc_get_alignment },
  2862. { "getweapon", pc_get_weapon },
  2863. { "get_weapon", pc_get_weapon },
  2864. { "getarmor", pc_get_armor },
  2865. { "get_armor", pc_get_armor },
  2866. { "getgold", pc_get_money },
  2867. { "get_gold", pc_get_money },
  2868. { "changegold", pc_change_money },
  2869. { "changemoney", pc_change_money },
  2870. { "changealignment", pc_change_alignment },
  2871. { "change_gold", pc_change_money },
  2872. { "change_money", pc_change_money },
  2873. { "change_alignment", pc_change_alignment },
  2874. { "getname", pc_get_name },
  2875. { "get_name", pc_get_name },
  2876. { "get_vid", pc_get_vid },
  2877. { "getplaytime", pc_get_playtime },
  2878. { "get_playtime", pc_get_playtime },
  2879. { "getleadership", pc_get_leadership },
  2880. { "get_leadership", pc_get_leadership },
  2881. { "getqf", pc_get_quest_flag },
  2882. { "setqf", pc_set_quest_flag },
  2883. { "delqf", pc_del_quest_flag },
  2884. { "getf", pc_get_another_quest_flag},
  2885. { "setf", pc_set_another_quest_flag},
  2886. { "get_x", pc_get_x },
  2887. { "get_y", pc_get_y },
  2888. { "getx", pc_get_x },
  2889. { "gety", pc_get_y },
  2890. { "get_local_x", pc_get_local_x },
  2891. { "get_local_y", pc_get_local_y },
  2892. { "getcurrentmapindex", pc_get_current_map_index},
  2893. { "get_map_index", pc_get_current_map_index},
  2894. { "give_exp", pc_give_exp },
  2895. { "give_exp_perc", pc_give_exp_perc },
  2896. { "give_exp2", pc_give_exp2 },
  2897. { "give_item", pc_give_item },
  2898. { "give_item2", pc_give_or_drop_item },
  2899. { "give_item2_select", pc_give_or_drop_item_and_select },
  2900. { "give_gold", pc_give_gold },
  2901. { "count_item", pc_count_item },
  2902. { "remove_item", pc_remove_item },
  2903. { "countitem", pc_count_item },
  2904. { "removeitem", pc_remove_item },
  2905. { "reset_point", pc_reset_point },
  2906. { "has_guild", pc_hasguild },
  2907. { "hasguild", pc_hasguild },
  2908. { "get_guild", pc_getguild },
  2909. { "getguild", pc_getguild },
  2910. { "isguildmaster", pc_isguildmaster },
  2911. { "is_guild_master", pc_isguildmaster },
  2912. { "destroy_guild", pc_destroy_guild },
  2913. { "remove_from_guild", pc_remove_from_guild },
  2914. { "in_dungeon", pc_in_dungeon },
  2915. { "getempire", pc_get_empire },
  2916. { "get_empire", pc_get_empire },
  2917. { "get_skill_group", pc_get_skillgroup },
  2918. { "set_skill_group", pc_set_skillgroup },
  2919. { "warp", pc_warp },
  2920. { "warp_local", pc_warp_local },
  2921. { "warp_exit", pc_warp_exit },
  2922. { "set_warp_location", pc_set_warp_location },
  2923. { "set_warp_location_local",pc_set_warp_location_local },
  2924. { "get_start_location", pc_get_start_location },
  2925. { "has_master_skill", pc_has_master_skill },
  2926. { "set_part", pc_set_part },
  2927. { "get_part", pc_get_part },
  2928. { "is_polymorphed", pc_is_polymorphed },
  2929. { "remove_polymorph", pc_remove_polymorph },
  2930. { "is_mount", pc_is_mount },
  2931. { "polymorph", pc_polymorph },
  2932. { "mount", pc_mount },
  2933. { "mount_bonus", pc_mount_bonus },
  2934. { "unmount", pc_unmount },
  2935. { "warp_to_guild_war_observer_position", pc_warp_to_guild_war_observer_position },
  2936. { "give_item_from_special_item_group", pc_give_item_from_special_item_group },
  2937. { "learn_grand_master_skill", pc_learn_grand_master_skill },
  2938. { "is_skill_book_no_delay", pc_is_skill_book_no_delay},
  2939. { "remove_skill_book_no_delay", pc_remove_skill_book_no_delay},
  2940.  
  2941. { "enough_inventory", pc_enough_inventory },
  2942. { "get_horse_level", pc_get_horse_level }, // TO BE DELETED XXX
  2943. { "is_horse_alive", pc_is_horse_alive }, // TO BE DELETED XXX
  2944. { "revive_horse", pc_revive_horse }, // TO BE DELETED XXX
  2945. { "have_pos_scroll", pc_have_pos_scroll },
  2946. { "have_map_scroll", pc_have_map_scroll },
  2947. { "get_war_map", pc_get_war_map },
  2948. { "get_equip_refine_level", pc_get_equip_refine_level },
  2949. { "refine_equip", pc_refine_equip },
  2950. { "get_skill_level", pc_get_skill_level },
  2951. { "give_lotto", pc_give_lotto },
  2952. { "aggregate_monster", pc_aggregate_monster },
  2953. { "forget_my_attacker", pc_forget_my_attacker },
  2954. { "pc_attract_ranger", pc_attract_ranger },
  2955. { "select", pc_select_vid },
  2956. { "get_sex", pc_get_sex },
  2957. { "is_married", pc_is_married },
  2958. { "is_engaged", pc_is_engaged },
  2959. { "is_engaged_or_married", pc_is_engaged_or_married},
  2960. { "is_gm", pc_is_gm },
  2961. { "get_gm_level", pc_get_gm_level },
  2962. { "mining", pc_mining },
  2963. { "ore_refine", pc_ore_refine },
  2964. { "diamond_refine", pc_diamond_refine },
  2965.  
  2966. // RESET_ONE_SKILL
  2967. { "clear_one_skill", pc_clear_one_skill },
  2968. // END_RESET_ONE_SKILL
  2969.  
  2970. { "clear_skill", pc_clear_skill },
  2971. { "clear_sub_skill", pc_clear_sub_skill },
  2972. { "set_skill_point", pc_set_skill_point },
  2973.  
  2974. { "is_clear_skill_group", pc_is_clear_skill_group },
  2975.  
  2976. { "save_exit_location", pc_save_exit_location },
  2977. { "teleport", pc_teleport },
  2978.  
  2979. { "set_skill_level", pc_set_skill_level },
  2980.  
  2981. { "give_polymorph_book", pc_give_polymorph_book },
  2982. { "upgrade_polymorph_book", pc_upgrade_polymorph_book },
  2983. { "get_premium_remain_sec", pc_get_premium_remain_sec },
  2984.  
  2985. { "send_block_mode", pc_send_block_mode },
  2986.  
  2987. { "change_empire", pc_change_empire },
  2988. { "get_change_empire_count", pc_get_change_empire_count },
  2989. { "set_change_empire_count", pc_set_change_empire_count },
  2990.  
  2991. { "change_name", pc_change_name },
  2992.  
  2993. { "is_dead", pc_is_dead },
  2994.  
  2995. { "reset_status", pc_reset_status },
  2996. { "get_ht", pc_get_ht },
  2997. { "set_ht", pc_set_ht },
  2998. { "get_iq", pc_get_iq },
  2999. { "set_iq", pc_set_iq },
  3000. { "get_st", pc_get_st },
  3001. { "set_st", pc_set_st },
  3002. { "get_dx", pc_get_dx },
  3003. { "set_dx", pc_set_dx },
  3004.  
  3005. { "is_near_vid", pc_is_near_vid },
  3006.  
  3007. { "get_socket_items", pc_get_socket_items },
  3008. { "get_empty_inventory_count", pc_get_empty_inventory_count },
  3009.  
  3010. { "get_logoff_interval", pc_get_logoff_interval },
  3011.  
  3012. { "is_riding", pc_is_riding },
  3013. { "get_special_ride_vnum", pc_get_special_ride_vnum },
  3014.  
  3015. { "can_warp", pc_can_warp },
  3016.  
  3017. { "dec_skill_point", pc_dec_skill_point },
  3018. { "get_skill_point", pc_get_skill_point },
  3019.  
  3020. { "get_channel_id", pc_get_channel_id },
  3021.  
  3022. { "give_poly_marble", pc_give_poly_marble },
  3023. { "get_sig_items", pc_get_sig_items },
  3024.  
  3025. { "charge_cash", pc_charge_cash },
  3026.  
  3027. { "get_informer_type", pc_get_informer_type }, //독일 선물 기능
  3028. { "get_informer_item", pc_get_informer_item },
  3029.  
  3030. { "give_award", pc_give_award }, //일본 계정당 한번씩 금괴 지급
  3031. { "give_award_socket", pc_give_award_socket }, //몰 인벤토리에 아이템 지급. 소켓 설정을 위한 함수.
  3032.  
  3033. { "get_killee_drop_pct", pc_get_killee_drop_pct }, /* mob_vnum.kill 이벤트에서 killee와 pc와의 level 차이, pc의 프리미엄 드랍률 등등을 고려한 아이템 드랍 확률.
  3034. * return 값은 (분자, 분모).
  3035. * (말이 복잡한데, CreateDropItem의 GetDropPct의 iDeltaPercent, iRandRange를 return한다고 보면 됨.)
  3036. * (이 말이 더 어려울라나 ㅠㅠ)
  3037. * 주의사항 : kill event에서만 사용할 것!
  3038. */
  3039.  
  3040. { NULL, NULL }
  3041. };
  3042.  
  3043. CQuestManager::instance().AddLuaFunctionTable("pc", pc_functions);
  3044. }
  3045. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement