deyan4you

Untitled

Oct 27th, 2016
130
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "stdafx.h"
  2.  
  3. #include "../../common/teen_packet.h"
  4. #include "../../common/VnumHelper.h"
  5.  
  6. #include "char.h"
  7.  
  8. #include "config.h"
  9. #include "utils.h"
  10. #include "crc32.h"
  11. #include "char_manager.h"
  12. #include "desc_client.h"
  13. #include "desc_manager.h"
  14. #include "buffer_manager.h"
  15. #include "item_manager.h"
  16. #include "motion.h"
  17. #include "vector.h"
  18. #include "packet.h"
  19. #include "cmd.h"
  20. #include "fishing.h"
  21. #include "exchange.h"
  22. #include "battle.h"
  23. #include "affect.h"
  24. #include "shop.h"
  25. #include "shop_manager.h"
  26. #include "safebox.h"
  27. #include "regen.h"
  28. #include "pvp.h"
  29. #include "party.h"
  30. #include "start_position.h"
  31. #include "questmanager.h"
  32. #include "log.h"
  33. #include "p2p.h"
  34. #include "guild.h"
  35. #include "guild_manager.h"
  36. #include "dungeon.h"
  37. #include "messenger_manager.h"
  38. #include "unique_item.h"
  39. #include "priv_manager.h"
  40. #include "war_map.h"
  41. #include "xmas_event.h"
  42. #include "banword.h"
  43. #include "target.h"
  44. #include "wedding.h"
  45. #include "mob_manager.h"
  46. #include "mining.h"
  47. #include "monarch.h"
  48. #include "castle.h"
  49. #include "arena.h"
  50. #include "dev_log.h"
  51. #include "horsename_manager.h"
  52. #include "pcbang.h"
  53. #include "gm.h"
  54. #include "map_location.h"
  55. #include "BlueDragon_Binder.h"
  56. #include "HackShield.h"
  57. #include "skill_power.h"
  58. #include "XTrapManager.h"
  59. #include "buff_on_attributes.h"
  60.  
  61. #ifdef __PET_SYSTEM__
  62. #include "PetSystem.h"
  63. #endif
  64. #ifdef NEW_PET_SYSTEM
  65. #include "New_PetSystem.h"
  66. #endif
  67. #include "DragonSoul.h"
  68.  
  69. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  70. #include "offline_shop.h"
  71. #include "offlineshop_manager.h"
  72. #include "offlineshop_config.h"
  73. #endif
  74.  
  75. extern bool offlineshop_map_allow_find(int mapIndex);
  76. extern const BYTE g_aBuffOnAttrPoints;
  77. extern bool RaceToJob(unsigned race, unsigned *ret_job);
  78.  
  79. extern int g_nPortalLimitTime;
  80. extern int test_server;
  81.  
  82. extern bool IS_SUMMONABLE_ZONE(int map_index); // char_item.cpp
  83. bool CAN_ENTER_ZONE(const LPCHARACTER& ch, int map_index);
  84.  
  85. bool CAN_ENTER_ZONE(const LPCHARACTER& ch, int map_index)
  86. {
  87. switch (map_index)
  88. {
  89. case 301:
  90. case 302:
  91. case 303:
  92. case 304:
  93. if (ch->GetLevel() < 90)
  94. return false;
  95. }
  96. return true;
  97. }
  98.  
  99. // <Factor> DynamicCharacterPtr member function definitions
  100.  
  101. LPCHARACTER DynamicCharacterPtr::Get() const {
  102. LPCHARACTER p = NULL;
  103. if (is_pc) {
  104. p = CHARACTER_MANAGER::instance().FindByPID(id);
  105. } else {
  106. p = CHARACTER_MANAGER::instance().Find(id);
  107. }
  108. return p;
  109. }
  110.  
  111. DynamicCharacterPtr& DynamicCharacterPtr::operator=(LPCHARACTER character) {
  112. if (character == NULL) {
  113. Reset();
  114. return *this;
  115. }
  116. if (character->IsPC()) {
  117. is_pc = true;
  118. id = character->GetPlayerID();
  119. } else {
  120. is_pc = false;
  121. id = character->GetVID();
  122. }
  123. return *this;
  124. }
  125.  
  126. CHARACTER::CHARACTER()
  127. {
  128. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateIdle, &CHARACTER::EndStateEmpty);
  129. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateMove, &CHARACTER::EndStateEmpty);
  130. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateBattle, &CHARACTER::EndStateEmpty);
  131.  
  132. Initialize();
  133. }
  134.  
  135. CHARACTER::~CHARACTER()
  136. {
  137. Destroy();
  138. }
  139.  
  140. void CHARACTER::SetLastPMPulse(void)
  141. {
  142. m_iLastPMPulse = thecore_pulse() + 25;
  143. }
  144.  
  145. void CHARACTER::Initialize()
  146. {
  147. CEntity::Initialize(ENTITY_CHARACTER);
  148.  
  149. m_bNoOpenedShop = true;
  150.  
  151. m_bOpeningSafebox = false;
  152.  
  153. m_fSyncTime = get_float_time()-3;
  154. m_dwPlayerID = 0;
  155. #ifdef NEW_PET_SYSTEM
  156. m_stImmortalSt = 0;
  157.  
  158. m_newpetskillcd[0] = 0;
  159. m_newpetskillcd[1] = 0;
  160. m_newpetskillcd[2] = 0;
  161. #endif
  162. m_dwKillerPID = 0;
  163. m_iLastPMPulse = 0;
  164. m_iPMCounter = 0;
  165.  
  166. m_iMoveCount = 0;
  167.  
  168. m_pkRegen = NULL;
  169. regen_id_ = 0;
  170. m_posRegen.x = m_posRegen.y = m_posRegen.z = 0;
  171. m_posStart.x = m_posStart.y = 0;
  172. m_posDest.x = m_posDest.y = 0;
  173. m_fRegenAngle = 0.0f;
  174.  
  175. m_pkMobData = NULL;
  176. m_pkMobInst = NULL;
  177.  
  178. m_pkShop = NULL;
  179. m_pkChrShopOwner = NULL;
  180. m_pkMyShop = NULL;
  181. m_pkExchange = NULL;
  182. m_pkParty = NULL;
  183. m_pkPartyRequestEvent = NULL;
  184.  
  185. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  186. // Offline Shop
  187. m_pkOfflineShop = NULL;
  188. m_pkChrOfflineShopOwner = NULL;
  189. m_pkOfflineShopUpdateEvent = NULL;
  190. m_bOfflineShopStatus = 0;
  191. // End Of Offline Shop
  192. #endif
  193.  
  194. m_pGuild = NULL;
  195.  
  196. m_pkChrTarget = NULL;
  197.  
  198. m_pkMuyeongEvent = NULL;
  199.  
  200. m_pkWarpNPCEvent = NULL;
  201. m_pkDeadEvent = NULL;
  202. m_pkStunEvent = NULL;
  203. m_pkSaveEvent = NULL;
  204. m_pkRecoveryEvent = NULL;
  205. m_pkTimedEvent = NULL;
  206. m_pkFishingEvent = NULL;
  207. m_pkWarpEvent = NULL;
  208.  
  209. // MINING
  210. m_pkMiningEvent = NULL;
  211. // END_OF_MINING
  212.  
  213. m_pkPoisonEvent = NULL;
  214. m_pkBleedingEvent = NULL;
  215. m_pkFireEvent = NULL;
  216. m_pkCheckSpeedHackEvent = NULL;
  217. m_speed_hack_count = 0;
  218.  
  219. m_pkAffectEvent = NULL;
  220. m_afAffectFlag = TAffectFlag(0, 0);
  221.  
  222. m_pkDestroyWhenIdleEvent = NULL;
  223.  
  224. m_pkChrSyncOwner = NULL;
  225.  
  226. memset(&m_points, 0, sizeof(m_points));
  227. memset(&m_pointsInstant, 0, sizeof(m_pointsInstant));
  228. memset(&m_quickslot, 0, sizeof(m_quickslot));
  229.  
  230. m_bCharType = CHAR_TYPE_MONSTER;
  231.  
  232. SetPosition(POS_STANDING);
  233.  
  234. m_dwPlayStartTime = m_dwLastMoveTime = get_dword_time();
  235.  
  236. GotoState(m_stateIdle);
  237. m_dwStateDuration = 1;
  238.  
  239. m_dwLastAttackTime = get_dword_time() - 20000;
  240.  
  241. m_bAddChrState = 0;
  242.  
  243. m_pkChrStone = NULL;
  244.  
  245. m_pkSafebox = NULL;
  246. m_iSafeboxSize = -1;
  247. m_iSafeboxLoadTime = 0;
  248.  
  249. m_pkMall = NULL;
  250. m_iMallLoadTime = 0;
  251.  
  252. m_posWarp.x = m_posWarp.y = m_posWarp.z = 0;
  253. m_lWarpMapIndex = 0;
  254.  
  255. m_posExit.x = m_posExit.y = m_posExit.z = 0;
  256. m_lExitMapIndex = 0;
  257.  
  258. m_pSkillLevels = NULL;
  259.  
  260. m_dwMoveStartTime = 0;
  261. m_dwMoveDuration = 0;
  262.  
  263. m_dwFlyTargetID = 0;
  264.  
  265. m_dwNextStatePulse = 0;
  266.  
  267. m_dwLastDeadTime = get_dword_time()-180000;
  268.  
  269. m_bSkipSave = false;
  270.  
  271. m_bItemLoaded = false;
  272.  
  273. m_bHasPoisoned = false;
  274. m_bHasBleeded = false;
  275.  
  276. m_pkDungeon = NULL;
  277. m_iEventAttr = 0;
  278.  
  279. m_kAttackLog.dwVID = 0;
  280. m_kAttackLog.dwTime = 0;
  281.  
  282. m_bNowWalking = m_bWalking = false;
  283. ResetChangeAttackPositionTime();
  284.  
  285. m_bDetailLog = false;
  286. m_bMonsterLog = false;
  287.  
  288. m_bDisableCooltime = false;
  289.  
  290. m_iAlignment = 0;
  291. m_iRealAlignment = 0;
  292.  
  293. m_iKillerModePulse = 0;
  294. m_bPKMode = PK_MODE_PEACE;
  295.  
  296. m_dwQuestNPCVID = 0;
  297. m_dwQuestByVnum = 0;
  298. m_pQuestItem = NULL;
  299.  
  300. m_szMobileAuth[0] = '\0';
  301.  
  302. m_dwUnderGuildWarInfoMessageTime = get_dword_time()-60000;
  303.  
  304. m_bUnderRefine = false;
  305.  
  306. // REFINE_NPC
  307. m_dwRefineNPCVID = 0;
  308. // END_OF_REFINE_NPC
  309.  
  310. m_dwPolymorphRace = 0;
  311.  
  312. m_bStaminaConsume = false;
  313.  
  314. ResetChainLightningIndex();
  315.  
  316. m_dwMountVnum = 0;
  317. m_chHorse = NULL;
  318. m_chRider = NULL;
  319.  
  320. m_pWarMap = NULL;
  321. m_pWeddingMap = NULL;
  322. m_bChatCounter = 0;
  323.  
  324. ResetStopTime();
  325.  
  326. m_dwLastVictimSetTime = get_dword_time() - 3000;
  327. m_iMaxAggro = -100;
  328.  
  329. m_bSendHorseLevel = 0;
  330. m_bSendHorseHealthGrade = 0;
  331. m_bSendHorseStaminaGrade = 0;
  332.  
  333. m_dwLoginPlayTime = 0;
  334.  
  335. m_pkChrMarried = NULL;
  336.  
  337. m_posSafeboxOpen.x = -1000;
  338. m_posSafeboxOpen.y = -1000;
  339.  
  340. // EQUIP_LAST_SKILL_DELAY
  341. m_dwLastSkillTime = get_dword_time();
  342. // END_OF_EQUIP_LAST_SKILL_DELAY
  343.  
  344. // MOB_SKILL_COOLTIME
  345. memset(m_adwMobSkillCooltime, 0, sizeof(m_adwMobSkillCooltime));
  346. // END_OF_MOB_SKILL_COOLTIME
  347.  
  348. m_isinPCBang = false;
  349.  
  350. // ARENA
  351. m_pArena = NULL;
  352. m_nPotionLimit = quest::CQuestManager::instance().GetEventFlag("arena_potion_limit_count");
  353. // END_ARENA
  354.  
  355. //PREVENT_TRADE_WINDOW
  356. m_isOpenSafebox = 0;
  357. //END_PREVENT_TRADE_WINDOW
  358.  
  359. //PREVENT_REFINE_HACK
  360. m_iRefineTime = 0;
  361. //END_PREVENT_REFINE_HACK
  362.  
  363. //RESTRICT_USE_SEED_OR_MOONBOTTLE
  364. m_iSeedTime = 0;
  365. //END_RESTRICT_USE_SEED_OR_MOONBOTTLE
  366. //PREVENT_PORTAL_AFTER_EXCHANGE
  367. m_iExchangeTime = 0;
  368. //END_PREVENT_PORTAL_AFTER_EXCHANGE
  369. //
  370. m_iSafeboxLoadTime = 0;
  371.  
  372. m_iMyShopTime = 0;
  373.  
  374. InitMC();
  375.  
  376. m_deposit_pulse = 0;
  377.  
  378. SET_OVER_TIME(this, OT_NONE);
  379.  
  380. m_strNewName = "";
  381.  
  382. m_known_guild.clear();
  383.  
  384. m_dwLogOffInterval = 0;
  385.  
  386. m_bComboSequence = 0;
  387. m_dwLastComboTime = 0;
  388. m_bComboIndex = 0;
  389. m_iComboHackCount = 0;
  390. m_dwSkipComboAttackByTime = 0;
  391.  
  392. m_dwMountTime = 0;
  393.  
  394. m_dwLastGoldDropTime = 0;
  395.  
  396. m_HackShieldCheckEvent = NULL;
  397. m_HackShieldCheckMode = false;
  398.  
  399. m_bIsLoadedAffect = false;
  400. cannot_dead = false;
  401.  
  402. #ifdef __PET_SYSTEM__
  403. m_petSystem = 0;
  404. m_bIsPet = false;
  405. #endif
  406. #ifdef NEW_PET_SYSTEM
  407. m_newpetSystem = 0;
  408. m_bIsNewPet = false;
  409. m_eggvid = 0;
  410. #endif
  411.  
  412.  
  413. m_fAttMul = 1.0f;
  414. m_fDamMul = 1.0f;
  415.  
  416. m_pointsInstant.iDragonSoulActiveDeck = -1;
  417.  
  418. memset(&m_tvLastSyncTime, 0, sizeof(m_tvLastSyncTime));
  419. m_iSyncHackCount = 0;
  420. }
  421.  
  422. void CHARACTER::Create(const char * c_pszName, DWORD vid, bool isPC)
  423. {
  424. static int s_crc = 172814;
  425.  
  426. char crc_string[128+1];
  427. snprintf(crc_string, sizeof(crc_string), "%s%p%d", c_pszName, this, ++s_crc);
  428. m_vid = VID(vid, GetCRC32(crc_string, strlen(crc_string)));
  429.  
  430. if (isPC)
  431. m_stName = c_pszName;
  432. }
  433.  
  434. void CHARACTER::Destroy()
  435. {
  436. CloseMyShop();
  437.  
  438. if (m_pkRegen)
  439. {
  440. if (m_pkDungeon) {
  441. // Dungeon regen may not be valid at this point
  442. if (m_pkDungeon->IsValidRegen(m_pkRegen, regen_id_)) {
  443. --m_pkRegen->count;
  444. }
  445. } else {
  446. // Is this really safe?
  447. --m_pkRegen->count;
  448. }
  449. m_pkRegen = NULL;
  450. }
  451.  
  452. if (m_pkDungeon)
  453. {
  454. SetDungeon(NULL);
  455. }
  456.  
  457. #ifdef __PET_SYSTEM__
  458. if (m_petSystem)
  459. {
  460. m_petSystem->Destroy();
  461. delete m_petSystem;
  462.  
  463. m_petSystem = 0;
  464. }
  465. #endif
  466. #ifdef NEW_PET_SYSTEM
  467. if (m_newpetSystem)
  468. {
  469. m_newpetSystem->Destroy();
  470. delete m_newpetSystem;
  471.  
  472. m_newpetSystem = 0;
  473. }
  474. #endif
  475.  
  476. HorseSummon(false);
  477.  
  478. if (GetRider())
  479. GetRider()->ClearHorseInfo();
  480.  
  481. if( IsPC() )
  482. {
  483. if (isHackShieldEnable)
  484. {
  485. CHackShieldManager::instance().DeleteClientHandle(GetPlayerID());
  486. }
  487. }
  488.  
  489. if (GetDesc())
  490. {
  491. GetDesc()->BindCharacter(NULL);
  492. // BindDesc(NULL);
  493. }
  494.  
  495. if (m_pkExchange)
  496. m_pkExchange->Cancel();
  497.  
  498. SetVictim(NULL);
  499.  
  500. if (GetShop())
  501. {
  502. GetShop()->RemoveGuest(this);
  503. SetShop(NULL);
  504. }
  505.  
  506. ClearStone();
  507. ClearSync();
  508. ClearTarget();
  509.  
  510. if (NULL == m_pkMobData)
  511. {
  512. DragonSoul_CleanUp();
  513. ClearItem();
  514. }
  515.  
  516. // <Factor> m_pkParty becomes NULL after CParty destructor call!
  517. LPPARTY party = m_pkParty;
  518. if (party)
  519. {
  520. if (party->GetLeaderPID() == GetVID() && !IsPC())
  521. {
  522. M2_DELETE(party);
  523. }
  524. else
  525. {
  526. party->Unlink(this);
  527.  
  528. if (!IsPC())
  529. party->Quit(GetVID());
  530. }
  531.  
  532. SetParty(NULL); // 안해도 되지만 안전하게.
  533. }
  534.  
  535. if (m_pkMobInst)
  536. {
  537. M2_DELETE(m_pkMobInst);
  538. m_pkMobInst = NULL;
  539. }
  540.  
  541. m_pkMobData = NULL;
  542.  
  543. if (m_pkSafebox)
  544. {
  545. M2_DELETE(m_pkSafebox);
  546. m_pkSafebox = NULL;
  547. }
  548.  
  549. if (m_pkMall)
  550. {
  551. M2_DELETE(m_pkMall);
  552. m_pkMall = NULL;
  553. }
  554.  
  555. for (TMapBuffOnAttrs::iterator it = m_map_buff_on_attrs.begin(); it != m_map_buff_on_attrs.end(); it++)
  556. {
  557. if (NULL != it->second)
  558. {
  559. M2_DELETE(it->second);
  560. }
  561. }
  562. m_map_buff_on_attrs.clear();
  563.  
  564. m_set_pkChrSpawnedBy.clear();
  565.  
  566. StopMuyeongEvent();
  567. event_cancel(&m_pkWarpNPCEvent);
  568. event_cancel(&m_pkRecoveryEvent);
  569. event_cancel(&m_pkDeadEvent);
  570. event_cancel(&m_pkSaveEvent);
  571. event_cancel(&m_pkTimedEvent);
  572. event_cancel(&m_pkStunEvent);
  573. event_cancel(&m_pkFishingEvent);
  574. event_cancel(&m_pkPoisonEvent);
  575. event_cancel(&m_pkBleedingEvent);
  576. event_cancel(&m_pkFireEvent);
  577. event_cancel(&m_pkBleedingEvent);
  578. event_cancel(&m_pkPartyRequestEvent);
  579. //DELAYED_WARP
  580. event_cancel(&m_pkWarpEvent);
  581. event_cancel(&m_pkCheckSpeedHackEvent);
  582. //END_DELAYED_WARP
  583.  
  584. // RECALL_DELAY
  585. //event_cancel(&m_pkRecallEvent);
  586. // END_OF_RECALL_DELAY
  587.  
  588. // MINING
  589. event_cancel(&m_pkMiningEvent);
  590. // END_OF_MINING
  591.  
  592. StopHackShieldCheckCycle();
  593.  
  594. for (itertype(m_mapMobSkillEvent) it = m_mapMobSkillEvent.begin(); it != m_mapMobSkillEvent.end(); ++it)
  595. {
  596. LPEVENT pkEvent = it->second;
  597. event_cancel(&pkEvent);
  598. }
  599. m_mapMobSkillEvent.clear();
  600.  
  601. //event_cancel(&m_pkAffectEvent);
  602. ClearAffect();
  603.  
  604. event_cancel(&m_pkDestroyWhenIdleEvent);
  605.  
  606. if (m_pSkillLevels)
  607. {
  608. M2_DELETE_ARRAY(m_pSkillLevels);
  609. m_pSkillLevels = NULL;
  610. }
  611.  
  612. CEntity::Destroy();
  613.  
  614. if (GetSectree())
  615. GetSectree()->RemoveEntity(this);
  616.  
  617. if (m_bMonsterLog)
  618. CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
  619. }
  620.  
  621. const char * CHARACTER::GetName() const
  622. {
  623. return m_stName.empty() ? (m_pkMobData ? m_pkMobData->m_table.szLocaleName : "") : m_stName.c_str();
  624. }
  625.  
  626. void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)
  627. {
  628. if (GetPart(PART_MAIN) > 2)
  629. {
  630. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("갑옷을 벗어야 개인 상점을 열 수 있습니다."));
  631. return;
  632. }
  633.  
  634. if (GetMyShop()) // 이미 샵이 열려 있으면 닫는다.
  635. {
  636. CloseMyShop();
  637. return;
  638. }
  639.  
  640. // 진행중인 퀘스트가 있으면 상점을 열 수 없다.
  641. quest::PC * pPC = quest::CQuestManager::instance().GetPCForce(GetPlayerID());
  642.  
  643. // GetPCForce는 NULL일 수 없으므로 따로 확인하지 않음
  644. if (pPC->IsRunning())
  645. return;
  646.  
  647. if (bItemCount == 0)
  648. return;
  649.  
  650. long long nTotalMoney = 0;
  651.  
  652. for (int n = 0; n < bItemCount; ++n)
  653. {
  654. nTotalMoney += static_cast<long long>((pTable+n)->price);
  655. }
  656.  
  657. nTotalMoney += static_cast<long long>(GetGold());
  658.  
  659. if (GOLD_MAX <= nTotalMoney)
  660. {
  661. sys_err("[OVERFLOW_GOLD] Overflow (GOLD_MAX) id %u name %s", GetPlayerID(), GetName());
  662. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("20? ?? ???? ??? ??? ????"));
  663. return;
  664. }
  665.  
  666. char szSign[SHOP_SIGN_MAX_LEN+1];
  667. strlcpy(szSign, c_pszSign, sizeof(szSign));
  668.  
  669. m_stShopSign = szSign;
  670.  
  671. if (m_stShopSign.length() == 0)
  672. return;
  673.  
  674. if (LC_IsCanada() == false)
  675. {
  676. if (CBanwordManager::instance().CheckString(m_stShopSign.c_str(), m_stShopSign.length()))
  677. {
  678. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("비속어나 은어가 포함된 상점 이름으로 상점을 열 수 없습니다."));
  679. return;
  680. }
  681. }
  682.  
  683. // MYSHOP_PRICE_LIST
  684. std::map<DWORD, DWORD> itemkind; // 아이템 종류별 가격, first: vnum, second: 단일 수량 가격
  685. // END_OF_MYSHOP_PRICE_LIST
  686.  
  687. std::set<TItemPos> cont;
  688. for (BYTE i = 0; i < bItemCount; ++i)
  689. {
  690. if (cont.find((pTable + i)->pos) != cont.end())
  691. {
  692. sys_err("MYSHOP: duplicate shop item detected! (name: %s)", GetName());
  693. return;
  694. }
  695.  
  696. // ANTI_GIVE, ANTI_MYSHOP check
  697. LPITEM pkItem = GetItem((pTable + i)->pos);
  698.  
  699. if (pkItem)
  700. {
  701. const TItemTable * item_table = pkItem->GetProto();
  702.  
  703. if (item_table && (IS_SET(item_table->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MYSHOP)))
  704. {
  705. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("유료화 아이템은 개인상점에서 판매할 수 없습니다."));
  706. return;
  707. }
  708.  
  709. if (pkItem->IsEquipped() == true)
  710. {
  711. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("장비중인 아이템은 개인상점에서 판매할 수 없습니다."));
  712. return;
  713. }
  714.  
  715. if (true == pkItem->isLocked())
  716. {
  717. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("사용중인 아이템은 개인상점에서 판매할 수 없습니다."));
  718. return;
  719. }
  720.  
  721.  
  722. // MYSHOP_PRICE_LIST
  723. itemkind[pkItem->GetVnum()] = (pTable + i)->price / pkItem->GetCount();
  724. // END_OF_MYSHOP_PRICE_LIST
  725. }
  726.  
  727. cont.insert((pTable + i)->pos);
  728. }
  729.  
  730. // MYSHOP_PRICE_LIST
  731. // 보따리 개수를 감소시킨다.
  732. if (CountSpecifyItem(71049)) { // 비단 보따리는 없애지 않고 가격정보를 저장한다.
  733.  
  734. //
  735. // 아이템 가격정보를 저장하기 위해 아이템 가격정보 패킷을 만들어 DB 캐시에 보낸다.
  736. //
  737. TPacketMyshopPricelistHeader header;
  738. TItemPriceInfo info;
  739.  
  740. header.dwOwnerID = GetPlayerID();
  741. header.byCount = itemkind.size();
  742.  
  743. TEMP_BUFFER buf;
  744. buf.write(&header, sizeof(header));
  745.  
  746. for (itertype(itemkind) it = itemkind.begin(); it != itemkind.end(); ++it)
  747. {
  748. info.dwVnum = it->first;
  749. info.dwPrice = it->second;
  750.  
  751. buf.write(&info, sizeof(info));
  752. }
  753.  
  754. db_clientdesc->DBPacket(HEADER_GD_MYSHOP_PRICELIST_UPDATE, 0, buf.read_peek(), buf.size());
  755. }
  756. // END_OF_MYSHOP_PRICE_LIST
  757. else if (CountSpecifyItem(50200))
  758. RemoveSpecifyItem(50200, 1);
  759. else
  760. return; // 보따리가 없으면 중단.
  761.  
  762. if (m_pkExchange)
  763. m_pkExchange->Cancel();
  764.  
  765. TPacketGCShopSign p;
  766.  
  767. p.bHeader = HEADER_GC_SHOP_SIGN;
  768. p.dwVID = GetVID();
  769. strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  770.  
  771. PacketAround(&p, sizeof(TPacketGCShopSign));
  772.  
  773. m_pkMyShop = CShopManager::instance().CreatePCShop(this, pTable, bItemCount);
  774.  
  775. if (IsPolymorphed() == true)
  776. {
  777. RemoveAffect(AFFECT_POLYMORPH);
  778. }
  779.  
  780. if (GetHorse())
  781. {
  782. HorseSummon( false, true );
  783. }
  784. // new mount 이용 중에, 개인 상점 열면 자동 unmount
  785. // StopRiding으로 뉴마운트까지 처리하면 좋은데 왜 그렇게 안해놨는지 알 수 없다.
  786. else if (GetMountVnum())
  787. {
  788. RemoveAffect(AFFECT_MOUNT);
  789. RemoveAffect(AFFECT_MOUNT_BONUS);
  790. }
  791. //if (!LC_IsNewCIBN())
  792. SetPolymorph(30000, true);
  793.  
  794. }
  795.  
  796. void CHARACTER::CloseMyShop()
  797. {
  798. if (GetMyShop())
  799. {
  800. m_stShopSign.clear();
  801. CShopManager::instance().DestroyPCShop(this);
  802. m_pkMyShop = NULL;
  803.  
  804. TPacketGCShopSign p;
  805.  
  806. p.bHeader = HEADER_GC_SHOP_SIGN;
  807. p.dwVID = GetVID();
  808. p.szSign[0] = '\0';
  809.  
  810. PacketAround(&p, sizeof(p));
  811.  
  812. //if (!LC_IsNewCIBN())
  813. SetPolymorph(GetJob(), true);
  814. }
  815. }
  816.  
  817. void EncodeMovePacket(TPacketGCMove & pack, DWORD dwVID, BYTE bFunc, BYTE bArg, DWORD x, DWORD y, DWORD dwDuration, DWORD dwTime, BYTE bRot)
  818. {
  819. pack.bHeader = HEADER_GC_MOVE;
  820. pack.bFunc = bFunc;
  821. pack.bArg = bArg;
  822. pack.dwVID = dwVID;
  823. pack.dwTime = dwTime ? dwTime : get_dword_time();
  824. pack.bRot = bRot;
  825. pack.lX = x;
  826. pack.lY = y;
  827. pack.dwDuration = dwDuration;
  828. }
  829.  
  830. void CHARACTER::RestartAtSamePos()
  831. {
  832. if (m_bIsObserver)
  833. return;
  834.  
  835. EncodeRemovePacket(this);
  836. EncodeInsertPacket(this);
  837.  
  838. ENTITY_MAP::iterator it = m_map_view.begin();
  839.  
  840. while (it != m_map_view.end())
  841. {
  842. LPENTITY entity = (it++)->first;
  843.  
  844. EncodeRemovePacket(entity);
  845. if (!m_bIsObserver)
  846. EncodeInsertPacket(entity);
  847.  
  848. if( entity->IsType(ENTITY_CHARACTER) )
  849. {
  850. LPCHARACTER lpChar = (LPCHARACTER)entity;
  851. if( lpChar->IsPC() || lpChar->IsNPC() || lpChar->IsMonster() )
  852. {
  853. if (!entity->IsObserverMode())
  854. entity->EncodeInsertPacket(this);
  855. }
  856. }
  857. else
  858. {
  859. if( !entity->IsObserverMode())
  860. {
  861. entity->EncodeInsertPacket(this);
  862. }
  863. }
  864. }
  865. }
  866.  
  867.  
  868. // Entity에 내가 나타났다고 패킷을 보낸다.
  869. void CHARACTER::EncodeInsertPacket(LPENTITY entity)
  870. {
  871.  
  872. LPDESC d;
  873.  
  874. if (!(d = entity->GetDesc()))
  875. return;
  876.  
  877. CItem * pWeapon = GetWear(WEAR_COSTUME_WEAPON);
  878. if (pWeapon)
  879. SetPart(PART_WEAPON, pWeapon->GetVnum());
  880.  
  881. // 길드이름 버그 수정 코드
  882. LPCHARACTER ch = (LPCHARACTER) entity;
  883. ch->SendGuildName(GetGuild());
  884. // 길드이름 버그 수정 코드
  885.  
  886. TPacketGCCharacterAdd pack;
  887.  
  888. pack.header = HEADER_GC_CHARACTER_ADD;
  889. pack.dwVID = m_vid;
  890. pack.bType = GetCharType();
  891. pack.angle = GetRotation();
  892. pack.x = GetX();
  893. pack.y = GetY();
  894. pack.z = GetZ();
  895. pack.wRaceNum = GetRaceNum();
  896. #ifdef NEW_PET_SYSTEM
  897. if (IsPet() || IsNewPet())
  898. #else
  899. if (IsPet())
  900. #endif
  901. {
  902. pack.bMovingSpeed = 150;
  903. }
  904. else
  905. {
  906. pack.bMovingSpeed = GetLimitPoint(POINT_MOV_SPEED);
  907. }
  908. pack.bAttackSpeed = GetLimitPoint(POINT_ATT_SPEED);
  909. pack.dwAffectFlag[0] = m_afAffectFlag.bits[0];
  910. pack.dwAffectFlag[1] = m_afAffectFlag.bits[1];
  911.  
  912. pack.bStateFlag = m_bAddChrState;
  913.  
  914. int iDur = 0;
  915.  
  916. if (m_posDest.x != pack.x || m_posDest.y != pack.y)
  917. {
  918. iDur = (m_dwMoveStartTime + m_dwMoveDuration) - get_dword_time();
  919.  
  920. if (iDur <= 0)
  921. {
  922. pack.x = m_posDest.x;
  923. pack.y = m_posDest.y;
  924. }
  925. }
  926.  
  927. d->Packet(&pack, sizeof(pack));
  928.  
  929. if (IsPC() == true || m_bCharType == CHAR_TYPE_NPC)
  930. {
  931. TPacketGCCharacterAdditionalInfo addPacket;
  932. memset(&addPacket, 0, sizeof(TPacketGCCharacterAdditionalInfo));
  933.  
  934. addPacket.header = HEADER_GC_CHAR_ADDITIONAL_INFO;
  935. addPacket.dwVID = m_vid;
  936.  
  937. addPacket.awPart[CHR_EQUIPPART_ARMOR] = GetPart(PART_MAIN);
  938. addPacket.awPart[CHR_EQUIPPART_WEAPON] = GetPart(PART_WEAPON);
  939. addPacket.awPart[CHR_EQUIPPART_HEAD] = GetPart(PART_HEAD);
  940. addPacket.awPart[CHR_EQUIPPART_HAIR] = GetPart(PART_HAIR);
  941. addPacket.awPart[CHR_EQUIPPART_ACCE] = GetPart(PART_ACCE);
  942.  
  943. addPacket.bPKMode = m_bPKMode;
  944. addPacket.dwMountVnum = GetMountVnum();
  945. addPacket.bEmpire = m_bEmpire;
  946.  
  947. #ifdef NEW_PET_SYSTEM
  948. if (IsPC() == true || IsNewPet() == true)
  949. #else
  950. if (IsPC() == true && (LC_IsEurope() == true || LC_IsCanada() == true || LC_IsSingapore() == true))
  951. #endif
  952. {
  953. addPacket.dwLevel = GetLevel();
  954. }
  955. else
  956. {
  957. addPacket.dwLevel = 0;
  958. }
  959.  
  960. if (false)
  961. {
  962. LPCHARACTER ch = (LPCHARACTER) entity;
  963.  
  964. if (GetEmpire() == ch->GetEmpire() || ch->GetGMLevel() > GM_PLAYER || m_bCharType == CHAR_TYPE_NPC)
  965. {
  966. goto show_all_info;
  967. }
  968. else
  969. {
  970. memset(addPacket.name, 0, CHARACTER_NAME_MAX_LEN);
  971. addPacket.dwGuildID = 0;
  972. addPacket.sAlignment = 0;
  973. }
  974. }
  975. else
  976. {
  977. show_all_info:
  978. strlcpy(addPacket.name, GetName(), sizeof(addPacket.name));
  979.  
  980. if (GetGuild() != NULL)
  981. {
  982. addPacket.dwGuildID = GetGuild()->GetID();
  983. }
  984. else
  985. {
  986. addPacket.dwGuildID = 0;
  987. }
  988.  
  989. addPacket.sAlignment = m_iAlignment / 10;
  990. }
  991.  
  992. d->Packet(&addPacket, sizeof(TPacketGCCharacterAdditionalInfo));
  993. }
  994.  
  995. if (iDur)
  996. {
  997. TPacketGCMove pack;
  998. EncodeMovePacket(pack, GetVID(), FUNC_MOVE, 0, m_posDest.x, m_posDest.y, iDur, 0, (BYTE) (GetRotation() / 5));
  999. d->Packet(&pack, sizeof(pack));
  1000.  
  1001. TPacketGCWalkMode p;
  1002. p.vid = GetVID();
  1003. p.header = HEADER_GC_WALK_MODE;
  1004. p.mode = m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  1005.  
  1006. d->Packet(&p, sizeof(p));
  1007. }
  1008.  
  1009. if (entity->IsType(ENTITY_CHARACTER) && GetDesc())
  1010. {
  1011. LPCHARACTER ch = (LPCHARACTER) entity;
  1012. if (ch->IsWalking())
  1013. {
  1014. TPacketGCWalkMode p;
  1015. p.vid = ch->GetVID();
  1016. p.header = HEADER_GC_WALK_MODE;
  1017. p.mode = ch->m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  1018. GetDesc()->Packet(&p, sizeof(p));
  1019. }
  1020. }
  1021.  
  1022. if (GetMyShop())
  1023. {
  1024. TPacketGCShopSign p;
  1025.  
  1026. p.bHeader = HEADER_GC_SHOP_SIGN;
  1027. p.dwVID = GetVID();
  1028. strlcpy(p.szSign, m_stShopSign.c_str(), sizeof(p.szSign));
  1029.  
  1030. d->Packet(&p, sizeof(TPacketGCShopSign));
  1031. }
  1032.  
  1033. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  1034. if (IsOfflineShopNPC() && GetRaceNum() == 30000)
  1035. {
  1036. TPacketGCShopSign p;
  1037.  
  1038. p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  1039. p.dwVID = GetVID();
  1040. if (m_stOfflineShopSign.empty())
  1041. {
  1042. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT sign FROM player2.offline_shop_npc WHERE owner_id = %u", GetOfflineShopRealOwner()));
  1043. if (pMsg->Get()->uiNumRows > 0)
  1044. {
  1045. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  1046. strlcpy(p.szSign, row[0], sizeof(p.szSign));
  1047. }
  1048. }
  1049. else
  1050. {
  1051. strlcpy(p.szSign, m_stOfflineShopSign.c_str(), sizeof(p.szSign));
  1052. }
  1053.  
  1054. d->Packet(&p, sizeof(TPacketGCShopSign));
  1055. }
  1056. #endif
  1057. if (entity->IsType(ENTITY_CHARACTER))
  1058. {
  1059. sys_log(3, "EntityInsert %s (RaceNum %d) (%d %d) TO %s",
  1060. GetName(), GetRaceNum(), GetX() / SECTREE_SIZE, GetY() / SECTREE_SIZE, ((LPCHARACTER)entity)->GetName());
  1061. }
  1062. }
  1063.  
  1064. void CHARACTER::EncodeRemovePacket(LPENTITY entity)
  1065. {
  1066. if (entity->GetType() != ENTITY_CHARACTER)
  1067. return;
  1068.  
  1069. LPDESC d;
  1070.  
  1071. if (!(d = entity->GetDesc()))
  1072. return;
  1073.  
  1074. TPacketGCCharacterDelete pack;
  1075.  
  1076. pack.header = HEADER_GC_CHARACTER_DEL;
  1077. pack.id = m_vid;
  1078.  
  1079. d->Packet(&pack, sizeof(TPacketGCCharacterDelete));
  1080.  
  1081. if (entity->IsType(ENTITY_CHARACTER))
  1082. sys_log(3, "EntityRemove %s(%d) FROM %s", GetName(), (DWORD) m_vid, ((LPCHARACTER) entity)->GetName());
  1083. }
  1084.  
  1085. void CHARACTER::UpdatePacket()
  1086. {
  1087. if (GetSectree() == NULL) return;
  1088.  
  1089. TPacketGCCharacterUpdate pack;
  1090. TPacketGCCharacterUpdate pack2;
  1091.  
  1092. pack.header = HEADER_GC_CHARACTER_UPDATE;
  1093. pack.dwVID = m_vid;
  1094.  
  1095. pack.awPart[CHR_EQUIPPART_ARMOR] = GetPart(PART_MAIN);
  1096. pack.awPart[CHR_EQUIPPART_WEAPON] = GetPart(PART_WEAPON);
  1097. pack.awPart[CHR_EQUIPPART_HEAD] = GetPart(PART_HEAD);
  1098. pack.awPart[CHR_EQUIPPART_HAIR] = GetPart(PART_HAIR);
  1099. pack.awPart[CHR_EQUIPPART_ACCE] = GetPart(PART_ACCE);
  1100.  
  1101.  
  1102. pack.bMovingSpeed = GetLimitPoint(POINT_MOV_SPEED);
  1103. pack.bAttackSpeed = GetLimitPoint(POINT_ATT_SPEED);
  1104. pack.bStateFlag = m_bAddChrState;
  1105. pack.dwAffectFlag[0] = m_afAffectFlag.bits[0];
  1106. pack.dwAffectFlag[1] = m_afAffectFlag.bits[1];
  1107. pack.dwGuildID = 0;
  1108. pack.sAlignment = m_iAlignment / 10;
  1109. #ifdef NEW_PET_SYSTEM
  1110. pack.dwLevel = GetLevel();
  1111. #endif
  1112.  
  1113. pack.bPKMode = m_bPKMode;
  1114.  
  1115. if (GetGuild())
  1116. pack.dwGuildID = GetGuild()->GetID();
  1117.  
  1118. pack.dwMountVnum = GetMountVnum();
  1119.  
  1120. pack2 = pack;
  1121. pack2.dwGuildID = 0;
  1122. pack2.sAlignment = 0;
  1123. #ifdef NEW_PET_SYSTEM
  1124. pack2.dwLevel = 0;
  1125. #endif
  1126.  
  1127. if (false)
  1128. {
  1129. if (m_bIsObserver != true)
  1130. {
  1131. for (ENTITY_MAP::iterator iter = m_map_view.begin(); iter != m_map_view.end(); iter++)
  1132. {
  1133. LPENTITY pEntity = iter->first;
  1134.  
  1135. if (pEntity != NULL)
  1136. {
  1137. if (pEntity->IsType(ENTITY_CHARACTER) == true)
  1138. {
  1139. if (pEntity->GetDesc() != NULL)
  1140. {
  1141. LPCHARACTER pChar = (LPCHARACTER)pEntity;
  1142.  
  1143. if (GetEmpire() == pChar->GetEmpire() || pChar->GetGMLevel() > GM_PLAYER)
  1144. {
  1145. pEntity->GetDesc()->Packet(&pack, sizeof(pack));
  1146. }
  1147. else
  1148. {
  1149. pEntity->GetDesc()->Packet(&pack2, sizeof(pack2));
  1150. }
  1151. }
  1152. }
  1153. else
  1154. {
  1155. if (pEntity->GetDesc() != NULL)
  1156. {
  1157. pEntity->GetDesc()->Packet(&pack, sizeof(pack));
  1158. }
  1159. }
  1160. }
  1161. }
  1162. }
  1163.  
  1164. if (GetDesc() != NULL)
  1165. {
  1166. GetDesc()->Packet(&pack, sizeof(pack));
  1167. }
  1168. }
  1169. else
  1170. {
  1171. PacketAround(&pack, sizeof(pack));
  1172. }
  1173. }
  1174.  
  1175. LPCHARACTER CHARACTER::FindCharacterInView(const char * c_pszName, bool bFindPCOnly)
  1176. {
  1177. ENTITY_MAP::iterator it = m_map_view.begin();
  1178.  
  1179. for (; it != m_map_view.end(); ++it)
  1180. {
  1181. if (!it->first->IsType(ENTITY_CHARACTER))
  1182. continue;
  1183.  
  1184. LPCHARACTER tch = (LPCHARACTER) it->first;
  1185.  
  1186. if (bFindPCOnly && tch->IsNPC())
  1187. continue;
  1188.  
  1189. if (!strcasecmp(tch->GetName(), c_pszName))
  1190. return (tch);
  1191. }
  1192.  
  1193. return NULL;
  1194. }
  1195.  
  1196. void CHARACTER::SetPosition(int pos)
  1197. {
  1198. if (pos == POS_STANDING)
  1199. {
  1200. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_DEAD);
  1201. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_STUN);
  1202.  
  1203. event_cancel(&m_pkDeadEvent);
  1204. event_cancel(&m_pkStunEvent);
  1205. }
  1206. else if (pos == POS_DEAD)
  1207. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_DEAD);
  1208.  
  1209. if (!IsStone())
  1210. {
  1211. switch (pos)
  1212. {
  1213. case POS_FIGHTING:
  1214. if (!IsState(m_stateBattle))
  1215. MonsterLog("[BATTLE] 싸우는 상태");
  1216.  
  1217. GotoState(m_stateBattle);
  1218. break;
  1219.  
  1220. default:
  1221. if (!IsState(m_stateIdle))
  1222. MonsterLog("[IDLE] 쉬는 상태");
  1223.  
  1224. GotoState(m_stateIdle);
  1225. break;
  1226. }
  1227. }
  1228.  
  1229. m_pointsInstant.position = pos;
  1230. }
  1231.  
  1232. void CHARACTER::Save()
  1233. {
  1234. if (!m_bSkipSave)
  1235. CHARACTER_MANAGER::instance().DelayedSave(this);
  1236. }
  1237.  
  1238. void CHARACTER::CreatePlayerProto(TPlayerTable & tab)
  1239. {
  1240. memset(&tab, 0, sizeof(TPlayerTable));
  1241.  
  1242. if (GetNewName().empty())
  1243. {
  1244. strlcpy(tab.name, GetName(), sizeof(tab.name));
  1245. }
  1246. else
  1247. {
  1248. strlcpy(tab.name, GetNewName().c_str(), sizeof(tab.name));
  1249. }
  1250.  
  1251. strlcpy(tab.ip, GetDesc()->GetHostName(), sizeof(tab.ip));
  1252.  
  1253. tab.id = m_dwPlayerID;
  1254. tab.voice = GetPoint(POINT_VOICE);
  1255. tab.level = GetLevel();
  1256. tab.level_step = GetPoint(POINT_LEVEL_STEP);
  1257. tab.exp = GetExp();
  1258. tab.gold = GetGold();
  1259. tab.job = m_points.job;
  1260. tab.part_base = m_pointsInstant.bBasePart;
  1261. tab.skill_group = m_points.skill_group;
  1262.  
  1263. DWORD dwPlayedTime = (get_dword_time() - m_dwPlayStartTime);
  1264.  
  1265. if (dwPlayedTime > 60000)
  1266. {
  1267. if (GetSectree() && !GetSectree()->IsAttr(GetX(), GetY(), ATTR_BANPK))
  1268. {
  1269. if (GetRealAlignment() < 0)
  1270. {
  1271. if (IsEquipUniqueItem(UNIQUE_ITEM_FASTER_ALIGNMENT_UP_BY_TIME))
  1272. UpdateAlignment(120 * (dwPlayedTime / 60000));
  1273. else
  1274. UpdateAlignment(60 * (dwPlayedTime / 60000));
  1275. }
  1276. else
  1277. UpdateAlignment(5 * (dwPlayedTime / 60000));
  1278. }
  1279.  
  1280. SetRealPoint(POINT_PLAYTIME, GetRealPoint(POINT_PLAYTIME) + dwPlayedTime / 60000);
  1281. ResetPlayTime(dwPlayedTime % 60000);
  1282. }
  1283.  
  1284. tab.playtime = GetRealPoint(POINT_PLAYTIME);
  1285. tab.lAlignment = m_iRealAlignment;
  1286.  
  1287. if (m_posWarp.x != 0 || m_posWarp.y != 0)
  1288. {
  1289. tab.x = m_posWarp.x;
  1290. tab.y = m_posWarp.y;
  1291. tab.z = 0;
  1292. tab.lMapIndex = m_lWarpMapIndex;
  1293. }
  1294. else
  1295. {
  1296. tab.x = GetX();
  1297. tab.y = GetY();
  1298. tab.z = GetZ();
  1299. tab.lMapIndex = GetMapIndex();
  1300. }
  1301.  
  1302. if (m_lExitMapIndex == 0)
  1303. {
  1304. tab.lExitMapIndex = tab.lMapIndex;
  1305. tab.lExitX = tab.x;
  1306. tab.lExitY = tab.y;
  1307. }
  1308. else
  1309. {
  1310. tab.lExitMapIndex = m_lExitMapIndex;
  1311. tab.lExitX = m_posExit.x;
  1312. tab.lExitY = m_posExit.y;
  1313. }
  1314.  
  1315. sys_log(0, "SAVE: %s %dx%d", GetName(), tab.x, tab.y);
  1316.  
  1317. tab.st = GetRealPoint(POINT_ST);
  1318. tab.ht = GetRealPoint(POINT_HT);
  1319. tab.dx = GetRealPoint(POINT_DX);
  1320. tab.iq = GetRealPoint(POINT_IQ);
  1321.  
  1322. tab.stat_point = GetPoint(POINT_STAT);
  1323. tab.skill_point = GetPoint(POINT_SKILL);
  1324. tab.sub_skill_point = GetPoint(POINT_SUB_SKILL);
  1325. tab.horse_skill_point = GetPoint(POINT_HORSE_SKILL);
  1326.  
  1327. tab.stat_reset_count = GetPoint(POINT_STAT_RESET_COUNT);
  1328.  
  1329. tab.hp = GetHP();
  1330. tab.sp = GetSP();
  1331.  
  1332. tab.stamina = GetStamina();
  1333.  
  1334. tab.sRandomHP = m_points.iRandomHP;
  1335. tab.sRandomSP = m_points.iRandomSP;
  1336.  
  1337. for (int i = 0; i < QUICKSLOT_MAX_NUM; ++i)
  1338. tab.quickslot[i] = m_quickslot[i];
  1339.  
  1340. if (m_stMobile.length() && !*m_szMobileAuth)
  1341. strlcpy(tab.szMobile, m_stMobile.c_str(), sizeof(tab.szMobile));
  1342.  
  1343. thecore_memcpy(tab.parts, m_pointsInstant.parts, sizeof(tab.parts));
  1344.  
  1345. // REMOVE_REAL_SKILL_LEVLES
  1346. thecore_memcpy(tab.skills, m_pSkillLevels, sizeof(TPlayerSkill) * SKILL_MAX_NUM);
  1347. // END_OF_REMOVE_REAL_SKILL_LEVLES
  1348.  
  1349. tab.horse = GetHorseData();
  1350. }
  1351.  
  1352.  
  1353. void CHARACTER::SaveReal()
  1354. {
  1355. if (m_bSkipSave)
  1356. return;
  1357.  
  1358. if (!GetDesc())
  1359. {
  1360. sys_err("Character::Save : no descriptor when saving (name: %s)", GetName());
  1361. return;
  1362. }
  1363.  
  1364. TPlayerTable table;
  1365. CreatePlayerProto(table);
  1366.  
  1367. db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, GetDesc()->GetHandle(), &table, sizeof(TPlayerTable));
  1368.  
  1369. quest::PC * pkQuestPC = quest::CQuestManager::instance().GetPCForce(GetPlayerID());
  1370.  
  1371. if (!pkQuestPC)
  1372. sys_err("CHARACTER::Save : null quest::PC pointer! (name %s)", GetName());
  1373. else
  1374. {
  1375. pkQuestPC->Save();
  1376. }
  1377.  
  1378. marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(GetPlayerID());
  1379. if (pMarriage)
  1380. pMarriage->Save();
  1381. }
  1382.  
  1383. void CHARACTER::FlushDelayedSaveItem()
  1384. {
  1385. // 저장 안된 소지품을 전부 저장시킨다.
  1386. LPITEM item;
  1387.  
  1388. for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
  1389. if ((item = GetInventoryItem(i)))
  1390. ITEM_MANAGER::instance().FlushDelayedSave(item);
  1391. }
  1392.  
  1393. void CHARACTER::Disconnect(const char * c_pszReason)
  1394. {
  1395. assert(GetDesc() != NULL);
  1396.  
  1397. sys_log(0, "DISCONNECT: %s (%s)", GetName(), c_pszReason ? c_pszReason : "unset" );
  1398.  
  1399. if (GetShop())
  1400. {
  1401. GetShop()->RemoveGuest(this);
  1402. SetShop(NULL);
  1403. }
  1404.  
  1405. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  1406. if (GetOfflineShop())
  1407. {
  1408. GetOfflineShop()->RemoveGuest(this);
  1409. SetOfflineShop(NULL);
  1410. }
  1411. #endif
  1412.  
  1413. if (GetArena() != NULL)
  1414. {
  1415. GetArena()->OnDisconnect(GetPlayerID());
  1416. }
  1417.  
  1418. if (GetParty() != NULL)
  1419. {
  1420. GetParty()->UpdateOfflineState(GetPlayerID());
  1421. }
  1422.  
  1423. marriage::CManager::instance().Logout(this);
  1424. //NEW
  1425. LPITEM item_mount = GetWear(WEAR_COSTUME_MOUNT);
  1426. if(item_mount){
  1427. UnequipItem(item_mount);
  1428. }
  1429.  
  1430. //NEW END
  1431.  
  1432. // P2P Logout
  1433. TPacketGGLogout p;
  1434. p.bHeader = HEADER_GG_LOGOUT;
  1435. strlcpy(p.szName, GetName(), sizeof(p.szName));
  1436. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGLogout));
  1437. char buf[51];
  1438. snprintf(buf, sizeof(buf), "%s %lld %d %ld %d",
  1439. inet_ntoa(GetDesc()->GetAddr().sin_addr), GetGold(), g_bChannel, GetMapIndex(), GetAlignment());
  1440.  
  1441. LogManager::instance().CharLog(this, 0, "LOGOUT", buf);
  1442.  
  1443. if (LC_IsYMIR() || LC_IsKorea() || LC_IsBrazil())
  1444. {
  1445. long playTime = GetRealPoint(POINT_PLAYTIME) - m_dwLoginPlayTime;
  1446. LogManager::instance().LoginLog(false, GetDesc()->GetAccountTable().id, GetPlayerID(), GetLevel(), GetJob(), playTime);
  1447.  
  1448. if (LC_IsBrazil() != true)
  1449. CPCBangManager::instance().Log(GetDesc()->GetHostName(), GetPlayerID(), playTime);
  1450. }
  1451.  
  1452. if (m_pWarMap)
  1453. SetWarMap(NULL);
  1454.  
  1455. if (m_pWeddingMap)
  1456. {
  1457. SetWeddingMap(NULL);
  1458. }
  1459.  
  1460. if (GetGuild())
  1461. GetGuild()->LogoutMember(this);
  1462.  
  1463. quest::CQuestManager::instance().LogoutPC(this);
  1464.  
  1465. if (GetParty())
  1466. GetParty()->Unlink(this);
  1467.  
  1468. // 죽었을 때 접속끊으면 경험치 줄게 하기
  1469. if (IsStun() || IsDead())
  1470. {
  1471. DeathPenalty(0);
  1472. PointChange(POINT_HP, 50 - GetHP());
  1473. }
  1474.  
  1475.  
  1476. if (!CHARACTER_MANAGER::instance().FlushDelayedSave(this))
  1477. {
  1478. SaveReal();
  1479. }
  1480.  
  1481. FlushDelayedSaveItem();
  1482.  
  1483. SaveAffect();
  1484. m_bIsLoadedAffect = false;
  1485.  
  1486. m_bSkipSave = true; // 이 이후에는 더이상 저장하면 안된다.
  1487.  
  1488. quest::CQuestManager::instance().DisconnectPC(this);
  1489.  
  1490. CloseSafebox();
  1491.  
  1492. CloseMall();
  1493.  
  1494. CPVPManager::instance().Disconnect(this);
  1495.  
  1496. CTargetManager::instance().Logout(GetPlayerID());
  1497.  
  1498. MessengerManager::instance().Logout(GetName());
  1499.  
  1500. if (g_TeenDesc)
  1501. {
  1502. int offset = 0;
  1503. char buf[245] = {0};
  1504.  
  1505. buf[0] = HEADER_GT_LOGOUT;
  1506. offset += 1;
  1507.  
  1508. memset(buf+offset, 0x00, 2);
  1509. offset += 2;
  1510.  
  1511. TAccountTable &acc_table = GetDesc()->GetAccountTable();
  1512. memcpy(buf+offset, &acc_table.id, 4);
  1513. offset += 4;
  1514.  
  1515. g_TeenDesc->Packet(buf, offset);
  1516. }
  1517.  
  1518. if (GetDesc())
  1519. {
  1520. GetDesc()->BindCharacter(NULL);
  1521. // BindDesc(NULL);
  1522. }
  1523.  
  1524. CXTrapManager::instance().DestroyClientSession(this);
  1525.  
  1526. M2_DESTROY_CHARACTER(this);
  1527. }
  1528.  
  1529. bool CHARACTER::Show(long lMapIndex, long x, long y, long z, bool bShowSpawnMotion/* = false */)
  1530. {
  1531. LPSECTREE sectree = SECTREE_MANAGER::instance().Get(lMapIndex, x, y);
  1532.  
  1533. if (!sectree)
  1534. {
  1535. sys_log(0, "cannot find sectree by %dx%d mapindex %d", x, y, lMapIndex);
  1536. return false;
  1537. }
  1538.  
  1539. SetMapIndex(lMapIndex);
  1540.  
  1541. bool bChangeTree = false;
  1542.  
  1543. if (!GetSectree() || GetSectree() != sectree)
  1544. bChangeTree = true;
  1545.  
  1546. if (bChangeTree)
  1547. {
  1548. if (GetSectree())
  1549. GetSectree()->RemoveEntity(this);
  1550.  
  1551. ViewCleanup();
  1552. }
  1553.  
  1554. if (!IsNPC())
  1555. {
  1556. sys_log(0, "SHOW: %s %dx%dx%d", GetName(), x, y, z);
  1557. if (GetStamina() < GetMaxStamina())
  1558. StartAffectEvent();
  1559. }
  1560. else if (m_pkMobData)
  1561. {
  1562. m_pkMobInst->m_posLastAttacked.x = x;
  1563. m_pkMobInst->m_posLastAttacked.y = y;
  1564. m_pkMobInst->m_posLastAttacked.z = z;
  1565. }
  1566.  
  1567. if (bShowSpawnMotion)
  1568. {
  1569. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  1570. m_afAffectFlag.Set(AFF_SPAWN);
  1571. }
  1572.  
  1573. SetXYZ(x, y, z);
  1574.  
  1575. m_posDest.x = x;
  1576. m_posDest.y = y;
  1577. m_posDest.z = z;
  1578.  
  1579. m_posStart.x = x;
  1580. m_posStart.y = y;
  1581. m_posStart.z = z;
  1582.  
  1583. if (bChangeTree)
  1584. {
  1585. EncodeInsertPacket(this);
  1586. sectree->InsertEntity(this);
  1587.  
  1588. UpdateSectree();
  1589. }
  1590. else
  1591. {
  1592. ViewReencode();
  1593. sys_log(0, " in same sectree");
  1594. }
  1595.  
  1596. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  1597.  
  1598. SetValidComboInterval(0);
  1599. return true;
  1600. }
  1601.  
  1602. // BGM_INFO
  1603. struct BGMInfo
  1604. {
  1605. std::string name;
  1606. float vol;
  1607. };
  1608.  
  1609. typedef std::map<unsigned, BGMInfo> BGMInfoMap;
  1610.  
  1611. static BGMInfoMap gs_bgmInfoMap;
  1612. static bool gs_bgmVolEnable = false;
  1613.  
  1614. void CHARACTER_SetBGMVolumeEnable()
  1615. {
  1616. gs_bgmVolEnable = true;
  1617. sys_log(0, "bgm_info.set_bgm_volume_enable");
  1618. }
  1619.  
  1620. void CHARACTER_AddBGMInfo(unsigned mapIndex, const char* name, float vol)
  1621. {
  1622. BGMInfo newInfo;
  1623. newInfo.name = name;
  1624. newInfo.vol = vol;
  1625.  
  1626. gs_bgmInfoMap[mapIndex] = newInfo;
  1627.  
  1628. //sys_log(0, "bgm_info.add_info(%d, '%s', %f)", mapIndex, name, vol);
  1629. }
  1630.  
  1631. const BGMInfo& CHARACTER_GetBGMInfo(unsigned mapIndex)
  1632. {
  1633. BGMInfoMap::iterator f = gs_bgmInfoMap.find(mapIndex);
  1634. if (gs_bgmInfoMap.end() == f)
  1635. {
  1636. static BGMInfo s_empty = {"", 0.0f};
  1637. return s_empty;
  1638. }
  1639. return f->second;
  1640. }
  1641.  
  1642. bool CHARACTER_IsBGMVolumeEnable()
  1643. {
  1644. return gs_bgmVolEnable;
  1645. }
  1646. // END_OF_BGM_INFO
  1647.  
  1648. void CHARACTER::MainCharacterPacket()
  1649. {
  1650. const unsigned mapIndex = GetMapIndex();
  1651. const BGMInfo& bgmInfo = CHARACTER_GetBGMInfo(mapIndex);
  1652.  
  1653. // SUPPORT_BGM
  1654. if (!bgmInfo.name.empty())
  1655. {
  1656. if (CHARACTER_IsBGMVolumeEnable())
  1657. {
  1658. sys_log(1, "bgm_info.play_bgm_vol(%d, name='%s', vol=%f)", mapIndex, bgmInfo.name.c_str(), bgmInfo.vol);
  1659. TPacketGCMainCharacter4_BGM_VOL mainChrPacket;
  1660. mainChrPacket.header = HEADER_GC_MAIN_CHARACTER4_BGM_VOL;
  1661. mainChrPacket.dwVID = m_vid;
  1662. mainChrPacket.wRaceNum = GetRaceNum();
  1663. mainChrPacket.lx = GetX();
  1664. mainChrPacket.ly = GetY();
  1665. mainChrPacket.lz = GetZ();
  1666. mainChrPacket.empire = GetDesc()->GetEmpire();
  1667. mainChrPacket.skill_group = GetSkillGroup();
  1668. strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
  1669.  
  1670. mainChrPacket.fBGMVol = bgmInfo.vol;
  1671. strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
  1672. GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter4_BGM_VOL));
  1673. }
  1674. else
  1675. {
  1676. sys_log(1, "bgm_info.play(%d, '%s')", mapIndex, bgmInfo.name.c_str());
  1677. TPacketGCMainCharacter3_BGM mainChrPacket;
  1678. mainChrPacket.header = HEADER_GC_MAIN_CHARACTER3_BGM;
  1679. mainChrPacket.dwVID = m_vid;
  1680. mainChrPacket.wRaceNum = GetRaceNum();
  1681. mainChrPacket.lx = GetX();
  1682. mainChrPacket.ly = GetY();
  1683. mainChrPacket.lz = GetZ();
  1684. mainChrPacket.empire = GetDesc()->GetEmpire();
  1685. mainChrPacket.skill_group = GetSkillGroup();
  1686. strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
  1687. strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
  1688. GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter3_BGM));
  1689. }
  1690. //if (m_stMobile.length())
  1691. // ChatPacket(CHAT_TYPE_COMMAND, "sms");
  1692. }
  1693. // END_OF_SUPPORT_BGM
  1694. else
  1695. {
  1696. sys_log(0, "bgm_info.play(%d, DEFAULT_BGM_NAME)", mapIndex);
  1697.  
  1698. TPacketGCMainCharacter pack;
  1699. pack.header = HEADER_GC_MAIN_CHARACTER;
  1700. pack.dwVID = m_vid;
  1701. pack.wRaceNum = GetRaceNum();
  1702. pack.lx = GetX();
  1703. pack.ly = GetY();
  1704. pack.lz = GetZ();
  1705. pack.empire = GetDesc()->GetEmpire();
  1706. pack.skill_group = GetSkillGroup();
  1707. strlcpy(pack.szName, GetName(), sizeof(pack.szName));
  1708. GetDesc()->Packet(&pack, sizeof(TPacketGCMainCharacter));
  1709.  
  1710. if (m_stMobile.length())
  1711. ChatPacket(CHAT_TYPE_COMMAND, "sms");
  1712. }
  1713. }
  1714.  
  1715. void CHARACTER::PointsPacket()
  1716. {
  1717. if (!GetDesc())
  1718. return;
  1719.  
  1720. TPacketGCPoints pack;
  1721. pack.header = HEADER_GC_CHARACTER_POINTS;
  1722. pack.points[POINT_LEVEL] = GetLevel();
  1723. pack.points[POINT_EXP] = GetExp();
  1724. pack.points[POINT_NEXT_EXP] = GetNextExp();
  1725. pack.points[POINT_HP] = GetHP();
  1726. pack.points[POINT_MAX_HP] = GetMaxHP();
  1727. pack.points[POINT_SP] = GetSP();
  1728. pack.points[POINT_MAX_SP] = GetMaxSP();
  1729. pack.points[POINT_GOLD] = GetGold();
  1730. pack.points[POINT_STAMINA] = GetStamina();
  1731. pack.points[POINT_MAX_STAMINA] = GetMaxStamina();
  1732. for (int i = POINT_ST; i < POINT_MAX_NUM; ++i)
  1733. pack.points[i] = GetPoint(i);
  1734.  
  1735. GetDesc()->Packet(&pack, sizeof(TPacketGCPoints));
  1736.  
  1737. if (!IsAcceOpen())
  1738. {
  1739. LPITEM item;
  1740. for (int j = 0; j < INVENTORY_AND_EQUIP_SLOT_MAX; ++j)
  1741. {
  1742. if ((item = GetInventoryItem(j)))
  1743. if (item->GetType() == ITEM_COSTUME && item->GetSubType() == COSTUME_ACCE && item->GetSocket(0) == 1)
  1744. item->SetSocket(0, 0);
  1745. }
  1746. }
  1747. }
  1748.  
  1749. bool CHARACTER::ChangeSex()
  1750. {
  1751. int src_race = GetRaceNum();
  1752.  
  1753. switch (src_race)
  1754. {
  1755. case MAIN_RACE_WARRIOR_M:
  1756. m_points.job = MAIN_RACE_WARRIOR_W;
  1757. break;
  1758.  
  1759. case MAIN_RACE_WARRIOR_W:
  1760. m_points.job = MAIN_RACE_WARRIOR_M;
  1761. break;
  1762.  
  1763. case MAIN_RACE_ASSASSIN_M:
  1764. m_points.job = MAIN_RACE_ASSASSIN_W;
  1765. break;
  1766.  
  1767. case MAIN_RACE_ASSASSIN_W:
  1768. m_points.job = MAIN_RACE_ASSASSIN_M;
  1769. break;
  1770.  
  1771. case MAIN_RACE_SURA_M:
  1772. m_points.job = MAIN_RACE_SURA_W;
  1773. break;
  1774.  
  1775. case MAIN_RACE_SURA_W:
  1776. m_points.job = MAIN_RACE_SURA_M;
  1777. break;
  1778.  
  1779. case MAIN_RACE_SHAMAN_M:
  1780. m_points.job = MAIN_RACE_SHAMAN_W;
  1781. break;
  1782.  
  1783. case MAIN_RACE_SHAMAN_W:
  1784. m_points.job = MAIN_RACE_SHAMAN_M;
  1785. break;
  1786.  
  1787. case MAIN_RACE_WOLFMAN_M:
  1788. m_points.job = MAIN_RACE_WOLFMAN_M;
  1789. break;
  1790.  
  1791. default:
  1792. sys_err("CHANGE_SEX: %s unknown race %d", GetName(), src_race);
  1793. return false;
  1794. }
  1795.  
  1796. sys_log(0, "CHANGE_SEX: %s (%d -> %d)", GetName(), src_race, m_points.job);
  1797. return true;
  1798. }
  1799.  
  1800. WORD CHARACTER::GetRaceNum() const
  1801. {
  1802. if (m_dwPolymorphRace)
  1803. return m_dwPolymorphRace;
  1804.  
  1805. if (m_pkMobData)
  1806. return m_pkMobData->m_table.dwVnum;
  1807.  
  1808. return m_points.job;
  1809. }
  1810.  
  1811. void CHARACTER::SetRace(BYTE race)
  1812. {
  1813. if (race >= MAIN_RACE_MAX_NUM)
  1814. {
  1815. sys_err("CHARACTER::SetRace(name=%s, race=%d).OUT_OF_RACE_RANGE", GetName(), race);
  1816. return;
  1817. }
  1818.  
  1819. m_points.job = race;
  1820. }
  1821.  
  1822. BYTE CHARACTER::GetJob() const
  1823. {
  1824. unsigned race = m_points.job;
  1825. unsigned job;
  1826.  
  1827. if (RaceToJob(race, &job))
  1828. return job;
  1829.  
  1830. sys_err("CHARACTER::GetJob(name=%s, race=%d).OUT_OF_RACE_RANGE", GetName(), race);
  1831. return JOB_WARRIOR;
  1832. }
  1833.  
  1834. void CHARACTER::SetLevel(BYTE level)
  1835. {
  1836. m_points.level = level;
  1837.  
  1838. if (IsPC())
  1839. {
  1840. if (level < PK_PROTECT_LEVEL)
  1841. SetPKMode(PK_MODE_PROTECT);
  1842. else if (GetGMLevel() != GM_PLAYER)
  1843. SetPKMode(PK_MODE_PROTECT);
  1844. else if (m_bPKMode == PK_MODE_PROTECT)
  1845. SetPKMode(PK_MODE_PEACE);
  1846. }
  1847. }
  1848.  
  1849. void CHARACTER::SetEmpire(BYTE bEmpire)
  1850. {
  1851. m_bEmpire = bEmpire;
  1852. }
  1853.  
  1854. void CHARACTER::SetPlayerProto(const TPlayerTable * t)
  1855. {
  1856. if (!GetDesc() || !*GetDesc()->GetHostName())
  1857. sys_err("cannot get desc or hostname");
  1858. else
  1859. SetGMLevel();
  1860.  
  1861. m_bCharType = CHAR_TYPE_PC;
  1862.  
  1863. m_dwPlayerID = t->id;
  1864.  
  1865. m_iAlignment = t->lAlignment;
  1866. m_iRealAlignment = t->lAlignment;
  1867.  
  1868. m_points.voice = t->voice;
  1869.  
  1870. m_points.skill_group = t->skill_group;
  1871.  
  1872. m_pointsInstant.bBasePart = t->part_base;
  1873. SetPart(PART_HAIR, t->parts[PART_HAIR]);
  1874. SetPart(PART_ACCE, t->parts[PART_ACCE]);
  1875.  
  1876. m_points.iRandomHP = t->sRandomHP;
  1877. m_points.iRandomSP = t->sRandomSP;
  1878.  
  1879. // REMOVE_REAL_SKILL_LEVLES
  1880. if (m_pSkillLevels)
  1881. M2_DELETE_ARRAY(m_pSkillLevels);
  1882.  
  1883. m_pSkillLevels = M2_NEW TPlayerSkill[SKILL_MAX_NUM];
  1884. thecore_memcpy(m_pSkillLevels, t->skills, sizeof(TPlayerSkill) * SKILL_MAX_NUM);
  1885. // END_OF_REMOVE_REAL_SKILL_LEVLES
  1886.  
  1887. if (t->lMapIndex >= 10000)
  1888. {
  1889. m_posWarp.x = t->lExitX;
  1890. m_posWarp.y = t->lExitY;
  1891. m_lWarpMapIndex = t->lExitMapIndex;
  1892. }
  1893.  
  1894. SetRealPoint(POINT_PLAYTIME, t->playtime);
  1895. m_dwLoginPlayTime = t->playtime;
  1896. SetRealPoint(POINT_ST, t->st);
  1897. SetRealPoint(POINT_HT, t->ht);
  1898. SetRealPoint(POINT_DX, t->dx);
  1899. SetRealPoint(POINT_IQ, t->iq);
  1900.  
  1901. SetPoint(POINT_ST, t->st);
  1902. SetPoint(POINT_HT, t->ht);
  1903. SetPoint(POINT_DX, t->dx);
  1904. SetPoint(POINT_IQ, t->iq);
  1905.  
  1906. SetPoint(POINT_STAT, t->stat_point);
  1907. SetPoint(POINT_SKILL, t->skill_point);
  1908. SetPoint(POINT_SUB_SKILL, t->sub_skill_point);
  1909. SetPoint(POINT_HORSE_SKILL, t->horse_skill_point);
  1910.  
  1911. SetPoint(POINT_STAT_RESET_COUNT, t->stat_reset_count);
  1912.  
  1913. SetPoint(POINT_LEVEL_STEP, t->level_step);
  1914. SetRealPoint(POINT_LEVEL_STEP, t->level_step);
  1915.  
  1916. SetRace(t->job);
  1917.  
  1918. SetLevel(t->level);
  1919. SetExp(t->exp);
  1920. SetGold(t->gold);
  1921.  
  1922. SetMapIndex(t->lMapIndex);
  1923. SetXYZ(t->x, t->y, t->z);
  1924.  
  1925. ComputePoints();
  1926.  
  1927. SetHP(t->hp);
  1928. SetSP(t->sp);
  1929. SetStamina(t->stamina);
  1930.  
  1931. //GM일때 보호모드
  1932. if (!test_server)
  1933. {
  1934. if (GetGMLevel() > GM_LOW_WIZARD)
  1935. {
  1936. m_afAffectFlag.Set(AFF_YMIR);
  1937. m_bPKMode = PK_MODE_PROTECT;
  1938. }
  1939. }
  1940.  
  1941. if (GetLevel() < PK_PROTECT_LEVEL)
  1942. m_bPKMode = PK_MODE_PROTECT;
  1943.  
  1944. m_stMobile = t->szMobile;
  1945.  
  1946. SetHorseData(t->horse);
  1947.  
  1948. if (GetHorseLevel() > 0)
  1949. UpdateHorseDataByLogoff(t->logoff_interval);
  1950.  
  1951. thecore_memcpy(m_aiPremiumTimes, t->aiPremiumTimes, sizeof(t->aiPremiumTimes));
  1952.  
  1953. m_dwLogOffInterval = t->logoff_interval;
  1954.  
  1955. sys_log(0, "PLAYER_LOAD: %s PREMIUM %d %d, LOGGOFF_INTERVAL %u PTR: %p", t->name, m_aiPremiumTimes[0], m_aiPremiumTimes[1], t->logoff_interval, this);
  1956.  
  1957. if (GetGMLevel() != GM_PLAYER)
  1958. {
  1959. LogManager::instance().CharLog(this, GetGMLevel(), "GM_LOGIN", "");
  1960. sys_log(0, "GM_LOGIN(gmlevel=%d, name=%s(%d), pos=(%d, %d)", GetGMLevel(), GetName(), GetPlayerID(), GetX(), GetY());
  1961. }
  1962.  
  1963. #ifdef __PET_SYSTEM__
  1964. // NOTE: 일단 캐릭터가 PC인 경우에만 PetSystem을 갖도록 함. 유럽 머신당 메모리 사용률때문에 NPC까지 하긴 좀..
  1965. if (m_petSystem)
  1966. {
  1967. m_petSystem->Destroy();
  1968. delete m_petSystem;
  1969. }
  1970.  
  1971. m_petSystem = M2_NEW CPetSystem(this);
  1972. #endif
  1973. #ifdef NEW_PET_SYSTEM
  1974. if (m_newpetSystem)
  1975. {
  1976. m_newpetSystem->Destroy();
  1977. delete m_newpetSystem;
  1978. }
  1979.  
  1980. m_newpetSystem = M2_NEW CNewPetSystem(this);
  1981. #endif
  1982.  
  1983. SetOfflineShopVID(COfflineShopManager::instance().FindMyOfflineShop(GetPlayerID()));
  1984. }
  1985.  
  1986. EVENTFUNC(kill_ore_load_event)
  1987. {
  1988. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  1989. if ( info == NULL )
  1990. {
  1991. sys_err( "kill_ore_load_even> <Factor> Null pointer" );
  1992. return 0;
  1993. }
  1994.  
  1995. LPCHARACTER ch = info->ch;
  1996. if (ch == NULL) { // <Factor>
  1997. return 0;
  1998. }
  1999.  
  2000. ch->m_pkMiningEvent = NULL;
  2001. M2_DESTROY_CHARACTER(ch);
  2002. return 0;
  2003. }
  2004.  
  2005. void CHARACTER::SetProto(const CMob * pkMob)
  2006. {
  2007. if (m_pkMobInst)
  2008. M2_DELETE(m_pkMobInst);
  2009.  
  2010. m_pkMobData = pkMob;
  2011. m_pkMobInst = M2_NEW CMobInstance;
  2012.  
  2013. m_bPKMode = PK_MODE_FREE;
  2014.  
  2015. const TMobTable * t = &m_pkMobData->m_table;
  2016.  
  2017. m_bCharType = t->bType;
  2018.  
  2019. SetLevel(t->bLevel);
  2020. SetEmpire(t->bEmpire);
  2021.  
  2022. SetExp(t->dwExp);
  2023. SetRealPoint(POINT_ST, t->bStr);
  2024. SetRealPoint(POINT_DX, t->bDex);
  2025. SetRealPoint(POINT_HT, t->bCon);
  2026. SetRealPoint(POINT_IQ, t->bInt);
  2027.  
  2028. ComputePoints();
  2029.  
  2030. SetHP(GetMaxHP());
  2031. SetSP(GetMaxSP());
  2032.  
  2033. ////////////////////
  2034. m_pointsInstant.dwAIFlag = t->dwAIFlag;
  2035. SetImmuneFlag(t->dwImmuneFlag);
  2036.  
  2037. AssignTriggers(t);
  2038.  
  2039. ApplyMobAttribute(t);
  2040.  
  2041. if (IsStone())
  2042. {
  2043. DetermineDropMetinStone();
  2044. }
  2045.  
  2046. if (IsWarp() || IsGoto())
  2047. {
  2048. StartWarpNPCEvent();
  2049. }
  2050.  
  2051. CHARACTER_MANAGER::instance().RegisterRaceNumMap(this);
  2052.  
  2053. // XXX X-mas santa hardcoding
  2054. if (GetRaceNum() == xmas::MOB_SANTA_VNUM)
  2055. {
  2056. SetPoint(POINT_ATT_GRADE_BONUS, 10);
  2057. if (g_iUseLocale)
  2058. SetPoint(POINT_DEF_GRADE_BONUS, 6);
  2059. else
  2060. SetPoint(POINT_DEF_GRADE_BONUS, 15);
  2061.  
  2062. //산타용
  2063. //m_dwPlayStartTime = get_dword_time() + 10 * 60 * 1000;
  2064. //신선자 노해
  2065. m_dwPlayStartTime = get_dword_time() + 30 * 1000;
  2066. if (test_server)
  2067. m_dwPlayStartTime = get_dword_time() + 30 * 1000;
  2068. }
  2069.  
  2070. // XXX CTF GuildWar hardcoding
  2071. if (warmap::IsWarFlag(GetRaceNum()))
  2072. {
  2073. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  2074. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  2075. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  2076. }
  2077.  
  2078. if (warmap::IsWarFlagBase(GetRaceNum()))
  2079. {
  2080. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  2081. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  2082. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  2083. }
  2084.  
  2085. if (m_bCharType == CHAR_TYPE_HORSE ||
  2086. GetRaceNum() == 20101 ||
  2087. GetRaceNum() == 20102 ||
  2088. GetRaceNum() == 20103 ||
  2089. GetRaceNum() == 20104 ||
  2090. GetRaceNum() == 20105 ||
  2091. GetRaceNum() == 20106 ||
  2092. GetRaceNum() == 20107 ||
  2093. GetRaceNum() == 20108 ||
  2094. GetRaceNum() == 20109
  2095. )
  2096. {
  2097. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateHorse, &CHARACTER::EndStateEmpty);
  2098. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateMove, &CHARACTER::EndStateEmpty);
  2099. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateHorse, &CHARACTER::EndStateEmpty);
  2100. }
  2101.  
  2102. // MINING
  2103. if (mining::IsVeinOfOre (GetRaceNum()))
  2104. {
  2105. char_event_info* info = AllocEventInfo<char_event_info>();
  2106.  
  2107. info->ch = this;
  2108.  
  2109. m_pkMiningEvent = event_create(kill_ore_load_event, info, PASSES_PER_SEC(number(7 * 60, 15 * 60)));
  2110. }
  2111. // END_OF_MINING
  2112. }
  2113.  
  2114. const TMobTable & CHARACTER::GetMobTable() const
  2115. {
  2116. return m_pkMobData->m_table;
  2117. }
  2118.  
  2119. bool CHARACTER::IsRaceFlag(DWORD dwBit) const
  2120. {
  2121. return m_pkMobData ? IS_SET(m_pkMobData->m_table.dwRaceFlag, dwBit) : 0;
  2122. }
  2123.  
  2124. DWORD CHARACTER::GetMobDamageMin() const
  2125. {
  2126. return m_pkMobData->m_table.dwDamageRange[0];
  2127. }
  2128.  
  2129. DWORD CHARACTER::GetMobDamageMax() const
  2130. {
  2131. return m_pkMobData->m_table.dwDamageRange[1];
  2132. }
  2133.  
  2134. float CHARACTER::GetMobDamageMultiply() const
  2135. {
  2136. float fDamMultiply = GetMobTable().fDamMultiply;
  2137.  
  2138. if (IsBerserk())
  2139. fDamMultiply = fDamMultiply * 2.0f; // BALANCE: 광폭화 시 두배
  2140.  
  2141. return fDamMultiply;
  2142. }
  2143.  
  2144. DWORD CHARACTER::GetMobDropItemVnum() const
  2145. {
  2146. return m_pkMobData->m_table.dwDropItemVnum;
  2147. }
  2148.  
  2149. bool CHARACTER::IsSummonMonster() const
  2150. {
  2151. return GetSummonVnum() != 0;
  2152. }
  2153.  
  2154. DWORD CHARACTER::GetSummonVnum() const
  2155. {
  2156. return m_pkMobData ? m_pkMobData->m_table.dwSummonVnum : 0;
  2157. }
  2158.  
  2159. DWORD CHARACTER::GetPolymorphItemVnum() const
  2160. {
  2161. return m_pkMobData ? m_pkMobData->m_table.dwPolymorphItemVnum : 0;
  2162. }
  2163.  
  2164. DWORD CHARACTER::GetMonsterDrainSPPoint() const
  2165. {
  2166. return m_pkMobData ? m_pkMobData->m_table.dwDrainSP : 0;
  2167. }
  2168.  
  2169. BYTE CHARACTER::GetMobRank() const
  2170. {
  2171. if (!m_pkMobData)
  2172. return MOB_RANK_KNIGHT; // PC일 경우 KNIGHT급
  2173.  
  2174. return m_pkMobData->m_table.bRank;
  2175. }
  2176.  
  2177. BYTE CHARACTER::GetMobSize() const
  2178. {
  2179. if (!m_pkMobData)
  2180. return MOBSIZE_MEDIUM;
  2181.  
  2182. return m_pkMobData->m_table.bSize;
  2183. }
  2184.  
  2185. WORD CHARACTER::GetMobAttackRange() const
  2186. {
  2187. switch (GetMobBattleType())
  2188. {
  2189. case BATTLE_TYPE_RANGE:
  2190. case BATTLE_TYPE_MAGIC:
  2191. return m_pkMobData->m_table.wAttackRange + GetPoint(POINT_BOW_DISTANCE);
  2192. default:
  2193. return m_pkMobData->m_table.wAttackRange;
  2194. }
  2195. }
  2196.  
  2197. BYTE CHARACTER::GetMobBattleType() const
  2198. {
  2199. if (!m_pkMobData)
  2200. return BATTLE_TYPE_MELEE;
  2201.  
  2202. return (m_pkMobData->m_table.bBattleType);
  2203. }
  2204.  
  2205. void CHARACTER::ComputeBattlePoints()
  2206. {
  2207. if (IsPC())
  2208. {
  2209. SetPoint(POINT_ATT_GRADE, 0);
  2210. SetPoint(POINT_DEF_GRADE, 0);
  2211. SetPoint(POINT_CLIENT_DEF_GRADE, 0);
  2212. SetPoint(POINT_MAGIC_ATT_GRADE, GetPoint(POINT_ATT_GRADE));
  2213. SetPoint(POINT_MAGIC_DEF_GRADE, GetPoint(POINT_DEF_GRADE));
  2214.  
  2215. int iAtk = GetLevel() * 2;
  2216. int iStatAtk = 0;
  2217. switch (GetJob())
  2218. {
  2219. case JOB_WARRIOR:
  2220. case JOB_SURA:
  2221. iStatAtk = (2 * GetPoint(POINT_ST));
  2222. break;
  2223.  
  2224. case JOB_ASSASSIN:
  2225. iStatAtk = (4 * GetPoint(POINT_ST) + 2 * GetPoint(POINT_DX)) / 3;
  2226. break;
  2227.  
  2228. case JOB_SHAMAN:
  2229. iStatAtk = (4 * GetPoint(POINT_ST) + 2 * GetPoint(POINT_IQ)) / 3;
  2230. break;
  2231.  
  2232. case JOB_WOLFMAN:
  2233. iStatAtk = (2 * GetPoint(POINT_ST));
  2234. break;
  2235.  
  2236. default:
  2237. sys_err("invalid job %d", GetJob());
  2238. iStatAtk = (2 * GetPoint(POINT_ST));
  2239. break;
  2240. }
  2241.  
  2242. if (GetMountVnum() && iStatAtk < 2 * GetPoint(POINT_ST))
  2243. iStatAtk = (2 * GetPoint(POINT_ST));
  2244.  
  2245. iAtk += iStatAtk;
  2246. if (GetMountVnum())
  2247. {
  2248. if (GetJob() == JOB_SURA && GetSkillGroup() == 1)
  2249. {
  2250. iAtk += (iAtk * GetHorseLevel()) / 60;
  2251. }
  2252. else
  2253. {
  2254. iAtk += (iAtk * GetHorseLevel()) / 30;
  2255. }
  2256. }
  2257.  
  2258. //
  2259. // ATK Setting
  2260. //
  2261. iAtk += GetPoint(POINT_ATT_GRADE_BONUS);
  2262.  
  2263. PointChange(POINT_ATT_GRADE, iAtk);
  2264.  
  2265. // DEF = LEV + CON + ARMOR
  2266. int iShowDef = GetLevel() + GetPoint(POINT_HT); // For Ymir(천마)
  2267. int iDef = GetLevel() + (int) (GetPoint(POINT_HT) / 1.25); // For Other
  2268. int iArmor = 0;
  2269.  
  2270. LPITEM pkItem;
  2271. for (int i = 0; i < WEAR_MAX_NUM; ++i)
  2272. if ((pkItem = GetWear(i)) && pkItem->GetType() == ITEM_ARMOR)
  2273. {
  2274. if (pkItem->GetSubType() == ARMOR_BODY || pkItem->GetSubType() == ARMOR_HEAD || pkItem->GetSubType() == ARMOR_FOOTS || pkItem->GetSubType() == ARMOR_SHIELD)
  2275. {
  2276. iArmor += pkItem->GetValue(1);
  2277. iArmor += (2 * pkItem->GetValue(5));
  2278. }
  2279. }
  2280.  
  2281. if( true == IsHorseRiding() )
  2282. {
  2283. if (iArmor < GetHorseArmor())
  2284. iArmor = GetHorseArmor();
  2285.  
  2286. const char* pHorseName = CHorseNameManager::instance().GetHorseName(GetPlayerID());
  2287. if (pHorseName != NULL && strlen(pHorseName))
  2288. {
  2289. iArmor += 20;
  2290. }
  2291. }
  2292.  
  2293. iArmor += GetPoint(POINT_DEF_GRADE_BONUS);
  2294. iArmor += GetPoint(POINT_PARTY_DEFENDER_BONUS);
  2295. if (LC_IsYMIR())
  2296. {
  2297. PointChange(POINT_DEF_GRADE, iShowDef + iArmor);
  2298. }
  2299. else
  2300. {
  2301. PointChange(POINT_DEF_GRADE, iDef + iArmor);
  2302. PointChange(POINT_CLIENT_DEF_GRADE, (iShowDef + iArmor) - GetPoint(POINT_DEF_GRADE));
  2303. }
  2304.  
  2305. PointChange(POINT_MAGIC_ATT_GRADE, GetLevel() * 2 + GetPoint(POINT_IQ) * 2 + GetPoint(POINT_MAGIC_ATT_GRADE_BONUS));
  2306. PointChange(POINT_MAGIC_DEF_GRADE, GetLevel() + (GetPoint(POINT_IQ) * 3 + GetPoint(POINT_HT)) / 3 + iArmor / 2 + GetPoint(POINT_MAGIC_DEF_GRADE_BONUS));
  2307. }
  2308. else
  2309. {
  2310. int iAtt = GetLevel() * 2 + GetPoint(POINT_ST) * 2;
  2311. int iDef = GetLevel() + GetPoint(POINT_HT) + GetMobTable().wDef;
  2312.  
  2313. SetPoint(POINT_ATT_GRADE, iAtt);
  2314. SetPoint(POINT_DEF_GRADE, iDef);
  2315. SetPoint(POINT_MAGIC_ATT_GRADE, GetPoint(POINT_ATT_GRADE));
  2316. SetPoint(POINT_MAGIC_DEF_GRADE, GetPoint(POINT_DEF_GRADE));
  2317. }
  2318. }
  2319.  
  2320. void CHARACTER::ComputePoints()
  2321. {
  2322. long lStat = GetPoint(POINT_STAT);
  2323. long lStatResetCount = GetPoint(POINT_STAT_RESET_COUNT);
  2324. long lSkillActive = GetPoint(POINT_SKILL);
  2325. long lSkillSub = GetPoint(POINT_SUB_SKILL);
  2326. long lSkillHorse = GetPoint(POINT_HORSE_SKILL);
  2327. long lLevelStep = GetPoint(POINT_LEVEL_STEP);
  2328.  
  2329. long lAttackerBonus = GetPoint(POINT_PARTY_ATTACKER_BONUS);
  2330. long lTankerBonus = GetPoint(POINT_PARTY_TANKER_BONUS);
  2331. long lBufferBonus = GetPoint(POINT_PARTY_BUFFER_BONUS);
  2332. long lSkillMasterBonus = GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  2333. long lHasteBonus = GetPoint(POINT_PARTY_HASTE_BONUS);
  2334. long lDefenderBonus = GetPoint(POINT_PARTY_DEFENDER_BONUS);
  2335.  
  2336. long lHPRecovery = GetPoint(POINT_HP_RECOVERY);
  2337. long lSPRecovery = GetPoint(POINT_SP_RECOVERY);
  2338.  
  2339. memset(m_pointsInstant.points, 0, sizeof(m_pointsInstant.points));
  2340. BuffOnAttr_ClearAll();
  2341. m_SkillDamageBonus.clear();
  2342.  
  2343. SetPoint(POINT_STAT, lStat);
  2344. SetPoint(POINT_SKILL, lSkillActive);
  2345. SetPoint(POINT_SUB_SKILL, lSkillSub);
  2346. SetPoint(POINT_HORSE_SKILL, lSkillHorse);
  2347. SetPoint(POINT_LEVEL_STEP, lLevelStep);
  2348. SetPoint(POINT_STAT_RESET_COUNT, lStatResetCount);
  2349.  
  2350. SetPoint(POINT_ST, GetRealPoint(POINT_ST));
  2351. SetPoint(POINT_HT, GetRealPoint(POINT_HT));
  2352. SetPoint(POINT_DX, GetRealPoint(POINT_DX));
  2353. SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
  2354.  
  2355. SetPart(PART_MAIN, GetOriginalPart(PART_MAIN));
  2356. SetPart(PART_WEAPON, GetOriginalPart(PART_WEAPON));
  2357. SetPart(PART_HEAD, GetOriginalPart(PART_HEAD));
  2358. SetPart(PART_HAIR, GetOriginalPart(PART_HAIR));
  2359. SetPart(PART_ACCE, GetOriginalPart(PART_ACCE));
  2360.  
  2361. SetPoint(POINT_PARTY_ATTACKER_BONUS, lAttackerBonus);
  2362. SetPoint(POINT_PARTY_TANKER_BONUS, lTankerBonus);
  2363. SetPoint(POINT_PARTY_BUFFER_BONUS, lBufferBonus);
  2364. SetPoint(POINT_PARTY_SKILL_MASTER_BONUS, lSkillMasterBonus);
  2365. SetPoint(POINT_PARTY_HASTE_BONUS, lHasteBonus);
  2366. SetPoint(POINT_PARTY_DEFENDER_BONUS, lDefenderBonus);
  2367.  
  2368. SetPoint(POINT_HP_RECOVERY, lHPRecovery);
  2369. SetPoint(POINT_SP_RECOVERY, lSPRecovery);
  2370.  
  2371. // PC_BANG_ITEM_ADD
  2372. SetPoint(POINT_PC_BANG_EXP_BONUS, 0);
  2373. SetPoint(POINT_PC_BANG_DROP_BONUS, 0);
  2374. // END_PC_BANG_ITEM_ADD
  2375.  
  2376. int iMaxHP, iMaxSP;
  2377. int iMaxStamina;
  2378.  
  2379. if (IsPC())
  2380. {
  2381. // 최대 생명력/정신력
  2382. iMaxHP = JobInitialPoints[GetJob()].max_hp + m_points.iRandomHP + GetPoint(POINT_HT) * JobInitialPoints[GetJob()].hp_per_ht;
  2383. iMaxSP = JobInitialPoints[GetJob()].max_sp + m_points.iRandomSP + GetPoint(POINT_IQ) * JobInitialPoints[GetJob()].sp_per_iq;
  2384. iMaxStamina = JobInitialPoints[GetJob()].max_stamina + GetPoint(POINT_HT) * JobInitialPoints[GetJob()].stamina_per_con;
  2385.  
  2386. {
  2387. CSkillProto* pkSk = CSkillManager::instance().Get(SKILL_ADD_HP);
  2388.  
  2389. if (NULL != pkSk)
  2390. {
  2391. pkSk->SetPointVar("k", 1.0f * GetSkillPower(SKILL_ADD_HP) / 100.0f);
  2392.  
  2393. iMaxHP += static_cast<int>(pkSk->kPointPoly.Eval());
  2394. }
  2395. }
  2396.  
  2397. // 기본 값들
  2398. SetPoint(POINT_MOV_SPEED, 100);
  2399. SetPoint(POINT_ATT_SPEED, 100);
  2400. PointChange(POINT_ATT_SPEED, GetPoint(POINT_PARTY_HASTE_BONUS));
  2401. SetPoint(POINT_CASTING_SPEED, 100);
  2402. }
  2403. else
  2404. {
  2405. iMaxHP = m_pkMobData->m_table.dwMaxHP;
  2406. iMaxSP = 0;
  2407. iMaxStamina = 0;
  2408.  
  2409. SetPoint(POINT_ATT_SPEED, m_pkMobData->m_table.sAttackSpeed);
  2410. SetPoint(POINT_MOV_SPEED, m_pkMobData->m_table.sMovingSpeed);
  2411. SetPoint(POINT_CASTING_SPEED, m_pkMobData->m_table.sAttackSpeed);
  2412. }
  2413.  
  2414. if (IsPC())
  2415. {
  2416. // 말 타고 있을 때는 기본 스탯이 말의 기준 스탯보다 낮으면 높게 만든다.
  2417. // 따라서 말의 기준 스탯이 무사 기준이므로, 수라/무당은 전체 스탯 합이
  2418. // 대채적으로 더 올라가게 될 것이다.
  2419. if (GetMountVnum())
  2420. {
  2421. if (GetHorseST() > GetPoint(POINT_ST))
  2422. PointChange(POINT_ST, GetHorseST() - GetPoint(POINT_ST));
  2423.  
  2424. if (GetHorseDX() > GetPoint(POINT_DX))
  2425. PointChange(POINT_DX, GetHorseDX() - GetPoint(POINT_DX));
  2426.  
  2427. if (GetHorseHT() > GetPoint(POINT_HT))
  2428. PointChange(POINT_HT, GetHorseHT() - GetPoint(POINT_HT));
  2429.  
  2430. if (GetHorseIQ() > GetPoint(POINT_IQ))
  2431. PointChange(POINT_IQ, GetHorseIQ() - GetPoint(POINT_IQ));
  2432. }
  2433.  
  2434. }
  2435.  
  2436. ComputeBattlePoints();
  2437.  
  2438. // 기본 HP/SP 설정
  2439. if (iMaxHP != GetMaxHP())
  2440. {
  2441. SetRealPoint(POINT_MAX_HP, iMaxHP); // 기본HP를 RealPoint에 저장해 놓는다.
  2442. }
  2443.  
  2444. PointChange(POINT_MAX_HP, 0);
  2445.  
  2446. if (iMaxSP != GetMaxSP())
  2447. {
  2448. SetRealPoint(POINT_MAX_SP, iMaxSP); // 기본SP를 RealPoint에 저장해 놓는다.
  2449. }
  2450.  
  2451. PointChange(POINT_MAX_SP, 0);
  2452.  
  2453. SetMaxStamina(iMaxStamina);
  2454.  
  2455. m_pointsInstant.dwImmuneFlag = 0;
  2456.  
  2457. for (int i = 0 ; i < WEAR_MAX_NUM; i++)
  2458. {
  2459. LPITEM pItem = GetWear(i);
  2460. if (pItem)
  2461. {
  2462. pItem->ModifyPoints(true);
  2463. SET_BIT(m_pointsInstant.dwImmuneFlag, GetWear(i)->GetImmuneFlag());
  2464. }
  2465. }
  2466.  
  2467. // 용혼석 시스템
  2468. // ComputePoints에서는 케릭터의 모든 속성값을 초기화하고,
  2469. // 아이템, 버프 등에 관련된 모든 속성값을 재계산하기 때문에,
  2470. // 용혼석 시스템도 ActiveDeck에 있는 모든 용혼석의 속성값을 다시 적용시켜야 한다.
  2471. if (DragonSoul_IsDeckActivated())
  2472. {
  2473. for (int i = WEAR_MAX_NUM + DS_SLOT_MAX * DragonSoul_GetActiveDeck();
  2474. i < WEAR_MAX_NUM + DS_SLOT_MAX * (DragonSoul_GetActiveDeck() + 1); i++)
  2475. {
  2476. LPITEM pItem = GetWear(i);
  2477. if (pItem)
  2478. {
  2479. if (DSManager::instance().IsTimeLeftDragonSoul(pItem))
  2480. pItem->ModifyPoints(true);
  2481. }
  2482. }
  2483. }
  2484.  
  2485.  
  2486.  
  2487.  
  2488.  
  2489. ComputeSkillPoints();
  2490.  
  2491. RefreshAffect();
  2492. CPetSystem* pPetSystem = GetPetSystem();
  2493. if (NULL != pPetSystem)
  2494. {
  2495. pPetSystem->RefreshBuff();
  2496. }
  2497.  
  2498. for (TMapBuffOnAttrs::iterator it = m_map_buff_on_attrs.begin(); it != m_map_buff_on_attrs.end(); it++)
  2499. {
  2500. it->second->GiveAllAttributes();
  2501. }
  2502.  
  2503. if (GetHP() > GetMaxHP())
  2504. PointChange(POINT_HP, GetMaxHP() - GetHP());
  2505.  
  2506. if (GetSP() > GetMaxSP())
  2507. PointChange(POINT_SP, GetMaxSP() - GetSP());
  2508.  
  2509. UpdatePacket();
  2510. }
  2511.  
  2512. // m_dwPlayStartTime의 단위는 milisecond다. 데이터베이스에는 분단위로 기록하기
  2513. // 때문에 플레이시간을 계산할 때 / 60000 으로 나눠서 하는데, 그 나머지 값이 남았
  2514. // 을 때 여기에 dwTimeRemain으로 넣어서 제대로 계산되도록 해주어야 한다.
  2515. void CHARACTER::ResetPlayTime(DWORD dwTimeRemain)
  2516. {
  2517. m_dwPlayStartTime = get_dword_time() - dwTimeRemain;
  2518. }
  2519.  
  2520. const int aiRecoveryPercents[10] = { 1, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
  2521.  
  2522. EVENTFUNC(recovery_event)
  2523. {
  2524. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  2525. if ( info == NULL )
  2526. {
  2527. sys_err( "recovery_event> <Factor> Null pointer" );
  2528. return 0;
  2529. }
  2530.  
  2531. LPCHARACTER ch = info->ch;
  2532.  
  2533. if (ch == NULL) { // <Factor>
  2534. return 0;
  2535. }
  2536.  
  2537. if (!ch->IsPC())
  2538. {
  2539. //
  2540. // 몬스터 회복
  2541. //
  2542. if (ch->IsAffectFlag(AFF_POISON) || ch->IsAffectFlag(AFF_BLEEDING))
  2543. return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
  2544.  
  2545. if (2493 == ch->GetMobTable().dwVnum)
  2546. {
  2547. int regenPct = BlueDragon_GetRangeFactor("hp_regen", ch->GetHPPct());
  2548. regenPct += ch->GetMobTable().bRegenPercent;
  2549.  
  2550. for (int i=1 ; i <= 4 ; ++i)
  2551. {
  2552. if (REGEN_PECT_BONUS == BlueDragon_GetIndexFactor("DragonStone", i, "effect_type"))
  2553. {
  2554. DWORD dwDragonStoneID = BlueDragon_GetIndexFactor("DragonStone", i, "vnum");
  2555. size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val");
  2556. size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID );
  2557.  
  2558. regenPct += (val*cnt);
  2559.  
  2560. break;
  2561. }
  2562. }
  2563.  
  2564. ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * regenPct) / 100));
  2565. }
  2566. else if (!ch->IsDoor())
  2567. {
  2568. ch->MonsterLog("HP_REGEN +%d", MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
  2569. ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
  2570. }
  2571.  
  2572. if (ch->GetHP() >= ch->GetMaxHP())
  2573. {
  2574. ch->m_pkRecoveryEvent = NULL;
  2575. return 0;
  2576. }
  2577.  
  2578. if (2493 == ch->GetMobTable().dwVnum)
  2579. {
  2580. for (int i=1 ; i <= 4 ; ++i)
  2581. {
  2582. if (REGEN_TIME_BONUS == BlueDragon_GetIndexFactor("DragonStone", i, "effect_type"))
  2583. {
  2584. DWORD dwDragonStoneID = BlueDragon_GetIndexFactor("DragonStone", i, "vnum");
  2585. size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val");
  2586. size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID );
  2587.  
  2588. return PASSES_PER_SEC(MAX(1, (ch->GetMobTable().bRegenCycle - (val*cnt))));
  2589. }
  2590. }
  2591. }
  2592.  
  2593. return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
  2594. }
  2595. else
  2596. {
  2597. //
  2598. // PC 회복
  2599. //
  2600. ch->CheckTarget();
  2601. //ch->UpdateSectree(); // 여기서 이걸 왜하지?
  2602. ch->UpdateKillerMode();
  2603.  
  2604. if (ch->IsAffectFlag(AFF_POISON) == true || ch->IsAffectFlag(AFF_BLEEDING))
  2605. {
  2606. // 중독인 경우 자동회복 금지
  2607. // 파법술인 경우 자동회복 금지
  2608. return 3;
  2609. }
  2610.  
  2611. int iSec = (get_dword_time() - ch->GetLastMoveTime()) / 3000;
  2612.  
  2613. // SP 회복 루틴.
  2614. // 왜 이걸로 해서 함수로 빼놨는가 ?!
  2615. ch->DistributeSP(ch);
  2616.  
  2617. if (ch->GetMaxHP() <= ch->GetHP())
  2618. return PASSES_PER_SEC(3);
  2619.  
  2620. int iPercent = 0;
  2621. int iAmount = 0;
  2622.  
  2623. {
  2624. iPercent = aiRecoveryPercents[MIN(9, iSec)];
  2625. iAmount = 15 + (ch->GetMaxHP() * iPercent) / 100;
  2626. }
  2627.  
  2628. iAmount += (iAmount * ch->GetPoint(POINT_HP_REGEN)) / 100;
  2629.  
  2630. sys_log(1, "RECOVERY_EVENT: %s %d HP_REGEN %d HP +%d", ch->GetName(), iPercent, ch->GetPoint(POINT_HP_REGEN), iAmount);
  2631.  
  2632. ch->PointChange(POINT_HP, iAmount, false);
  2633. return PASSES_PER_SEC(3);
  2634. }
  2635. }
  2636.  
  2637. void CHARACTER::StartRecoveryEvent()
  2638. {
  2639. if (m_pkRecoveryEvent)
  2640. return;
  2641.  
  2642. if (IsDead() || IsStun())
  2643. return;
  2644.  
  2645. if (IsNPC() && GetHP() >= GetMaxHP()) // 몬스터는 체력이 다 차있으면 시작 안한다.
  2646. return;
  2647.  
  2648. char_event_info* info = AllocEventInfo<char_event_info>();
  2649.  
  2650. info->ch = this;
  2651.  
  2652. int iSec = IsPC() ? 3 : (MAX(1, GetMobTable().bRegenCycle));
  2653. m_pkRecoveryEvent = event_create(recovery_event, info, PASSES_PER_SEC(iSec));
  2654. }
  2655.  
  2656. void CHARACTER::Standup()
  2657. {
  2658. struct packet_position pack_position;
  2659.  
  2660. if (!IsPosition(POS_SITTING))
  2661. return;
  2662.  
  2663. SetPosition(POS_STANDING);
  2664.  
  2665. sys_log(1, "STANDUP: %s", GetName());
  2666.  
  2667. pack_position.header = HEADER_GC_CHARACTER_POSITION;
  2668. pack_position.vid = GetVID();
  2669. pack_position.position = POSITION_GENERAL;
  2670.  
  2671. PacketAround(&pack_position, sizeof(pack_position));
  2672. }
  2673.  
  2674. void CHARACTER::Sitdown(int is_ground)
  2675. {
  2676. struct packet_position pack_position;
  2677.  
  2678. if (IsPosition(POS_SITTING))
  2679. return;
  2680.  
  2681. SetPosition(POS_SITTING);
  2682. sys_log(1, "SITDOWN: %s", GetName());
  2683.  
  2684. pack_position.header = HEADER_GC_CHARACTER_POSITION;
  2685. pack_position.vid = GetVID();
  2686. pack_position.position = POSITION_SITTING_GROUND;
  2687. PacketAround(&pack_position, sizeof(pack_position));
  2688. }
  2689.  
  2690. void CHARACTER::SetRotation(float fRot)
  2691. {
  2692. m_pointsInstant.fRot = fRot;
  2693. }
  2694.  
  2695. // x, y 방향으로 보고 선다.
  2696. void CHARACTER::SetRotationToXY(long x, long y)
  2697. {
  2698. SetRotation(GetDegreeFromPositionXY(GetX(), GetY(), x, y));
  2699. }
  2700.  
  2701. bool CHARACTER::CannotMoveByAffect() const
  2702. {
  2703. return (IsAffectFlag(AFF_STUN));
  2704. }
  2705.  
  2706. bool CHARACTER::CanMove() const
  2707. {
  2708. if (CannotMoveByAffect())
  2709. return false;
  2710.  
  2711. if (GetMyShop()) // 상점 연 상태에서는 움직일 수 없음
  2712. return false;
  2713.  
  2714. // 0.2초 전이라면 움직일 수 없다.
  2715. /*
  2716. if (get_float_time() - m_fSyncTime < 0.2f)
  2717. return false;
  2718. */
  2719. return true;
  2720. }
  2721.  
  2722. // 무조건 x, y 위치로 이동 시킨다.
  2723. bool CHARACTER::Sync(long x, long y)
  2724. {
  2725. if (!GetSectree())
  2726. return false;
  2727.  
  2728. LPSECTREE new_tree = SECTREE_MANAGER::instance().Get(GetMapIndex(), x, y);
  2729.  
  2730. if (!new_tree)
  2731. {
  2732. if (GetDesc())
  2733. {
  2734. sys_err("cannot find tree at %d %d (name: %s)", x, y, GetName());
  2735. GetDesc()->SetPhase(PHASE_CLOSE);
  2736. }
  2737. else
  2738. {
  2739. sys_err("no tree: %s %d %d %d", GetName(), x, y, GetMapIndex());
  2740. Dead();
  2741. }
  2742.  
  2743. return false;
  2744. }
  2745.  
  2746. SetRotationToXY(x, y);
  2747. SetXYZ(x, y, 0);
  2748.  
  2749. if (GetDungeon())
  2750. {
  2751. // 던젼용 이벤트 속성 변화
  2752. int iLastEventAttr = m_iEventAttr;
  2753. m_iEventAttr = new_tree->GetEventAttribute(x, y);
  2754.  
  2755. if (m_iEventAttr != iLastEventAttr)
  2756. {
  2757. if (GetParty())
  2758. {
  2759. quest::CQuestManager::instance().AttrOut(GetParty()->GetLeaderPID(), this, iLastEventAttr);
  2760. quest::CQuestManager::instance().AttrIn(GetParty()->GetLeaderPID(), this, m_iEventAttr);
  2761. }
  2762. else
  2763. {
  2764. quest::CQuestManager::instance().AttrOut(GetPlayerID(), this, iLastEventAttr);
  2765. quest::CQuestManager::instance().AttrIn(GetPlayerID(), this, m_iEventAttr);
  2766. }
  2767. }
  2768. }
  2769.  
  2770. if (GetSectree() != new_tree)
  2771. {
  2772. if (!IsNPC())
  2773. {
  2774. SECTREEID id = new_tree->GetID();
  2775. SECTREEID old_id = GetSectree()->GetID();
  2776.  
  2777. sys_log(0, "SECTREE DIFFER: %s %dx%d was %dx%d",
  2778. GetName(),
  2779. id.coord.x,
  2780. id.coord.y,
  2781. old_id.coord.x,
  2782. old_id.coord.y);
  2783. }
  2784.  
  2785. new_tree->InsertEntity(this);
  2786. }
  2787.  
  2788. return true;
  2789. }
  2790.  
  2791. void CHARACTER::Stop()
  2792. {
  2793. if (!IsState(m_stateIdle))
  2794. MonsterLog("[IDLE] 정지");
  2795.  
  2796. GotoState(m_stateIdle);
  2797.  
  2798. m_posDest.x = m_posStart.x = GetX();
  2799. m_posDest.y = m_posStart.y = GetY();
  2800. }
  2801.  
  2802. bool CHARACTER::Goto(long x, long y)
  2803. {
  2804. // TODO 거리체크 필요
  2805. // 같은 위치면 이동할 필요 없음 (자동 성공)
  2806. if (GetX() == x && GetY() == y)
  2807. return false;
  2808.  
  2809. if (m_posDest.x == x && m_posDest.y == y)
  2810. {
  2811. if (!IsState(m_stateMove))
  2812. {
  2813. m_dwStateDuration = 4;
  2814. GotoState(m_stateMove);
  2815. }
  2816. return false;
  2817. }
  2818.  
  2819. m_posDest.x = x;
  2820. m_posDest.y = y;
  2821.  
  2822. CalculateMoveDuration();
  2823.  
  2824. m_dwStateDuration = 4;
  2825.  
  2826.  
  2827. if (!IsState(m_stateMove))
  2828. {
  2829. MonsterLog("[MOVE] %s", GetVictim() ? "대상추적" : "그냥이동");
  2830.  
  2831. if (GetVictim())
  2832. {
  2833. //MonsterChat(MONSTER_CHAT_CHASE);
  2834. MonsterChat(MONSTER_CHAT_ATTACK);
  2835. }
  2836. }
  2837.  
  2838. GotoState(m_stateMove);
  2839.  
  2840. return true;
  2841. }
  2842.  
  2843.  
  2844. DWORD CHARACTER::GetMotionMode() const
  2845. {
  2846. DWORD dwMode = MOTION_MODE_GENERAL;
  2847.  
  2848. if (IsPolymorphed())
  2849. return dwMode;
  2850.  
  2851. LPITEM pkItem;
  2852. if ((pkItem = GetWear(WEAR_WEAPON)))
  2853. {
  2854. switch (pkItem->GetProto()->bSubType)
  2855. {
  2856. case WEAPON_SWORD:
  2857. dwMode = MOTION_MODE_ONEHAND_SWORD;
  2858. break;
  2859.  
  2860. case WEAPON_TWO_HANDED:
  2861. dwMode = MOTION_MODE_TWOHAND_SWORD;
  2862. break;
  2863.  
  2864. case WEAPON_DAGGER:
  2865. dwMode = MOTION_MODE_DUALHAND_SWORD;
  2866. break;
  2867.  
  2868. case WEAPON_BOW:
  2869. dwMode = MOTION_MODE_BOW;
  2870. break;
  2871.  
  2872. case WEAPON_BELL:
  2873. dwMode = MOTION_MODE_BELL;
  2874. break;
  2875.  
  2876. case WEAPON_FAN:
  2877. dwMode = MOTION_MODE_FAN;
  2878. break;
  2879.  
  2880. case WEAPON_CLAW:
  2881. dwMode = MOTION_MODE_CLAW;
  2882. break;
  2883. }
  2884. }
  2885.  
  2886. return dwMode;
  2887. }
  2888.  
  2889. float CHARACTER::GetMoveMotionSpeed() const
  2890. {
  2891. DWORD dwMode = GetMotionMode();
  2892.  
  2893. const CMotion * pkMotion = NULL;
  2894.  
  2895. if (!GetMountVnum())
  2896. pkMotion = CMotionManager::instance().GetMotion(GetRaceNum(), MAKE_MOTION_KEY(dwMode, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2897. else
  2898. {
  2899. pkMotion = CMotionManager::instance().GetMotion(GetMountVnum(), MAKE_MOTION_KEY(MOTION_MODE_GENERAL, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2900.  
  2901. if (!pkMotion)
  2902. pkMotion = CMotionManager::instance().GetMotion(GetRaceNum(), MAKE_MOTION_KEY(MOTION_MODE_HORSE, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2903. }
  2904.  
  2905. if (pkMotion)
  2906. return -pkMotion->GetAccumVector().y / pkMotion->GetDuration();
  2907. else
  2908. {
  2909. //sys_err("cannot find motion (name %s race %d mode %d)", GetName(), GetRaceNum(), dwMode);
  2910. return 300.0f;
  2911. }
  2912. }
  2913.  
  2914. float CHARACTER::GetMoveSpeed() const
  2915. {
  2916. return GetMoveMotionSpeed() * 10000 / CalculateDuration(GetLimitPoint(POINT_MOV_SPEED), 10000);
  2917. }
  2918.  
  2919. void CHARACTER::CalculateMoveDuration()
  2920. {
  2921. m_posStart.x = GetX();
  2922. m_posStart.y = GetY();
  2923.  
  2924. float fDist = DISTANCE_SQRT(m_posStart.x - m_posDest.x, m_posStart.y - m_posDest.y);
  2925.  
  2926. float motionSpeed = GetMoveMotionSpeed();
  2927.  
  2928. m_dwMoveDuration = CalculateDuration(GetLimitPoint(POINT_MOV_SPEED),
  2929. (int) ((fDist / motionSpeed) * 1000.0f));
  2930.  
  2931. if (IsNPC())
  2932. sys_log(1, "Maxmi - Char.cpp",
  2933. GetName(), fDist, GetLimitPoint(POINT_MOV_SPEED), m_dwMoveDuration, motionSpeed,
  2934. m_posStart.x, m_posStart.y, m_posDest.x, m_posDest.y);
  2935.  
  2936. m_dwMoveStartTime = get_dword_time();
  2937. }
  2938.  
  2939. // x y 위치로 이동 한다. (이동할 수 있는 가 없는 가를 확인 하고 Sync 메소드로 실제 이동 한다)
  2940. // 서버는 char의 x, y 값을 바로 바꾸지만,
  2941. // 클라에서는 이전 위치에서 바꾼 x, y까지 interpolation한다.
  2942. // 걷거나 뛰는 것은 char의 m_bNowWalking에 달려있다.
  2943. // Warp를 의도한 것이라면 Show를 사용할 것.
  2944. bool CHARACTER::Move(long x, long y)
  2945. {
  2946. // 같은 위치면 이동할 필요 없음 (자동 성공)
  2947. if (GetX() == x && GetY() == y)
  2948. return true;
  2949.  
  2950. if (test_server)
  2951. if (m_bDetailLog)
  2952. sys_log(0, "%s position %u %u", GetName(), x, y);
  2953.  
  2954. OnMove();
  2955. return Sync(x, y);
  2956. }
  2957.  
  2958. void CHARACTER::SendMovePacket(BYTE bFunc, BYTE bArg, DWORD x, DWORD y, DWORD dwDuration, DWORD dwTime, int iRot)
  2959. {
  2960. TPacketGCMove pack;
  2961.  
  2962. if (bFunc == FUNC_WAIT)
  2963. {
  2964. x = m_posDest.x;
  2965. y = m_posDest.y;
  2966. dwDuration = m_dwMoveDuration;
  2967. }
  2968.  
  2969. EncodeMovePacket(pack, GetVID(), bFunc, bArg, x, y, dwDuration, dwTime, iRot == -1 ? (int) GetRotation() / 5 : iRot);
  2970. PacketView(&pack, sizeof(TPacketGCMove), this);
  2971. }
  2972.  
  2973. int CHARACTER::GetRealPoint(BYTE type) const
  2974. {
  2975. return m_points.points[type];
  2976. }
  2977.  
  2978. void CHARACTER::SetRealPoint(BYTE type, int val)
  2979. {
  2980. m_points.points[type] = val;
  2981. }
  2982.  
  2983. int CHARACTER::GetPolymorphPoint(BYTE type) const
  2984. {
  2985. if (IsPolymorphed() && !IsPolyMaintainStat())
  2986. {
  2987. DWORD dwMobVnum = GetPolymorphVnum();
  2988. const CMob * pMob = CMobManager::instance().Get(dwMobVnum);
  2989. int iPower = GetPolymorphPower();
  2990.  
  2991. if (pMob)
  2992. {
  2993. switch (type)
  2994. {
  2995. case POINT_ST:
  2996. if (GetJob() == JOB_SHAMAN || GetJob() == JOB_SURA && GetSkillGroup() == 2)
  2997. return pMob->m_table.bStr * iPower / 100 + GetPoint(POINT_IQ);
  2998. return pMob->m_table.bStr * iPower / 100 + GetPoint(POINT_ST);
  2999.  
  3000. case POINT_HT:
  3001. return pMob->m_table.bCon * iPower / 100 + GetPoint(POINT_HT);
  3002.  
  3003. case POINT_IQ:
  3004. return pMob->m_table.bInt * iPower / 100 + GetPoint(POINT_IQ);
  3005.  
  3006. case POINT_DX:
  3007. return pMob->m_table.bDex * iPower / 100 + GetPoint(POINT_DX);
  3008. }
  3009. }
  3010. }
  3011.  
  3012. return GetPoint(type);
  3013. }
  3014.  
  3015. long long CHARACTER::GetPoint(BYTE type) const
  3016. {
  3017. if (type >= POINT_MAX_NUM)
  3018. {
  3019. sys_err("Point type overflow (type %u)", type);
  3020. return 0;
  3021. }
  3022.  
  3023. long long val = m_pointsInstant.points[type];
  3024. long long max_val = LLONG_MAX;
  3025.  
  3026. switch (type)
  3027. {
  3028. case POINT_STEAL_HP:
  3029. case POINT_STEAL_SP:
  3030. max_val = 50;
  3031. break;
  3032. case POINT_GOLD:
  3033. max_val = GOLD_MAX;
  3034. break;
  3035. }
  3036.  
  3037. if (val > max_val)
  3038. sys_err("POINT_ERROR: %s type %d val %lld (max: %lld)", GetName(), val, max_val);
  3039.  
  3040. return (val);
  3041. }
  3042.  
  3043. int CHARACTER::GetLimitPoint(BYTE type) const
  3044. {
  3045. if (type >= POINT_MAX_NUM)
  3046. {
  3047. sys_err("Point type overflow (type %u)", type);
  3048. return 0;
  3049. }
  3050.  
  3051. int val = m_pointsInstant.points[type];
  3052. int max_val = INT_MAX;
  3053. int limit = INT_MAX;
  3054. int min_limit = -INT_MAX;
  3055.  
  3056. switch (type)
  3057. {
  3058. case POINT_ATT_SPEED:
  3059. min_limit = 0;
  3060.  
  3061. if (IsPC())
  3062. limit = 170;
  3063. else
  3064. limit = 250;
  3065. break;
  3066.  
  3067. case POINT_MOV_SPEED:
  3068. min_limit = 0;
  3069.  
  3070. if (IsPC())
  3071. limit = 200;
  3072. else
  3073. limit = 250;
  3074. break;
  3075.  
  3076. case POINT_STEAL_HP:
  3077. case POINT_STEAL_SP:
  3078. limit = 50;
  3079. max_val = 50;
  3080. break;
  3081.  
  3082. case POINT_MALL_ATTBONUS:
  3083. case POINT_MALL_DEFBONUS:
  3084. limit = 20;
  3085. max_val = 50;
  3086. break;
  3087. }
  3088.  
  3089. if (val > max_val)
  3090. sys_err("POINT_ERROR: %s type %d val %d (max: %d)", GetName(), val, max_val);
  3091.  
  3092. if (val > limit)
  3093. val = limit;
  3094.  
  3095. if (val < min_limit)
  3096. val = min_limit;
  3097.  
  3098. return (val);
  3099. }
  3100.  
  3101. void CHARACTER::SetPoint(BYTE type, long long val)
  3102. {
  3103. if (type >= POINT_MAX_NUM)
  3104. {
  3105. sys_err("Point type overflow (type %u)", type);
  3106. return;
  3107. }
  3108.  
  3109. m_pointsInstant.points[type] = val;
  3110.  
  3111. // 아직 이동이 다 안끝났다면 이동 시간 계산을 다시 해야 한다.
  3112. if (type == POINT_MOV_SPEED && get_dword_time() < m_dwMoveStartTime + m_dwMoveDuration)
  3113. {
  3114. CalculateMoveDuration();
  3115. }
  3116. }
  3117.  
  3118. long long CHARACTER::GetAllowedGold() const
  3119. {
  3120. if (GetLevel() <= 10)
  3121. return 100000;
  3122. else if (GetLevel() <= 20)
  3123. return 500000;
  3124. else
  3125. return 50000000;
  3126. }
  3127.  
  3128. void CHARACTER::CheckMaximumPoints()
  3129. {
  3130. if (GetMaxHP() < GetHP())
  3131. PointChange(POINT_HP, GetMaxHP() - GetHP());
  3132.  
  3133. if (GetMaxSP() < GetSP())
  3134. PointChange(POINT_SP, GetMaxSP() - GetSP());
  3135. }
  3136.  
  3137. void CHARACTER::PointChange(BYTE type, long long amount, bool bAmount, bool bBroadcast)
  3138. {
  3139. long long val = 0;
  3140.  
  3141. //sys_log(0, "PointChange %d %d | %d -> %d cHP %d mHP %d", type, amount, GetPoint(type), GetPoint(type)+amount, GetHP(), GetMaxHP());
  3142.  
  3143. switch (type)
  3144. {
  3145. case POINT_NONE:
  3146. return;
  3147.  
  3148. case POINT_LEVEL:
  3149. if ((GetLevel() + amount) > gPlayerMaxLevel)
  3150. return;
  3151.  
  3152. SetLevel(GetLevel() + amount);
  3153. val = GetLevel();
  3154.  
  3155. sys_log(0, "LEVELUP: %s %d NEXT EXP %d", GetName(), GetLevel(), GetNextExp());
  3156.  
  3157. PointChange(POINT_NEXT_EXP, GetNextExp(), false);
  3158.  
  3159. if (amount)
  3160. {
  3161. quest::CQuestManager::instance().LevelUp(GetPlayerID());
  3162.  
  3163. LogManager::instance().LevelLog(this, val, GetRealPoint(POINT_PLAYTIME) + (get_dword_time() - m_dwPlayStartTime) / 60000);
  3164.  
  3165. if (GetGuild())
  3166. {
  3167. GetGuild()->LevelChange(GetPlayerID(), GetLevel());
  3168. }
  3169.  
  3170. if (GetParty())
  3171. {
  3172. GetParty()->RequestSetMemberLevel(GetPlayerID(), GetLevel());
  3173. }
  3174. }
  3175. break;
  3176.  
  3177. case POINT_NEXT_EXP:
  3178. val = GetNextExp();
  3179. bAmount = false;
  3180. break;
  3181.  
  3182. case POINT_EXP:
  3183. {
  3184. DWORD exp = GetExp();
  3185. DWORD next_exp = GetNextExp();
  3186.  
  3187. if (LC_IsNewCIBN())
  3188. {
  3189. if (IsOverTime(OT_NONE))
  3190. {
  3191. dev_log(LOG_DEB0, "<EXP_LOG> %s = NONE", GetName());
  3192. }
  3193. else if (IsOverTime(OT_3HOUR))
  3194. {
  3195. amount = (amount / 2);
  3196. dev_log(LOG_DEB0, "<EXP_LOG> %s = 3HOUR", GetName());
  3197. }
  3198. else if (IsOverTime(OT_5HOUR))
  3199. {
  3200. amount = 0;
  3201. dev_log(LOG_DEB0, "<EXP_LOG> %s = 5HOUR", GetName());
  3202. }
  3203. }
  3204.  
  3205. // exp가 0 이하로 가지 않도록 한다
  3206. if (amount < 0 && exp < -amount)
  3207. {
  3208. sys_log(1, "%s AMOUNT < 0 %d, CUR EXP: %d", GetName(), -amount, exp);
  3209. amount = -exp;
  3210.  
  3211. SetExp(exp + amount);
  3212. val = GetExp();
  3213. }
  3214. else
  3215. {
  3216. if (gPlayerMaxLevel <= GetLevel())
  3217. return;
  3218. if (block_exp && amount > 0)
  3219. {
  3220. return;
  3221. }
  3222. if (test_server)
  3223. ChatPacket(CHAT_TYPE_INFO, "You have gained %d exp.", amount);
  3224.  
  3225. DWORD iExpBalance = 0;
  3226. if (exp + amount >= next_exp)
  3227. {
  3228. iExpBalance = (exp + amount) - next_exp;
  3229. amount = next_exp - exp;
  3230.  
  3231. SetExp(0);
  3232. exp = next_exp;
  3233. }
  3234. else
  3235. {
  3236. SetExp(exp + amount);
  3237. exp = GetExp();
  3238. }
  3239.  
  3240. DWORD q = DWORD(next_exp / 4.0f);
  3241. int iLevStep = GetRealPoint(POINT_LEVEL_STEP);
  3242. if (iLevStep >= 4)
  3243. {
  3244. sys_err("%s LEVEL_STEP bigger than 4! (%d)", GetName(), iLevStep);
  3245. iLevStep = 4;
  3246. }
  3247.  
  3248. if (exp >= next_exp && iLevStep < 4)
  3249. {
  3250. for (int i = 0; i < 4 - iLevStep; ++i)
  3251. PointChange(POINT_LEVEL_STEP, 1, false, true);
  3252. }
  3253. else if (exp >= q * 3 && iLevStep < 3)
  3254. {
  3255. for (int i = 0; i < 3 - iLevStep; ++i)
  3256. PointChange(POINT_LEVEL_STEP, 1, false, true);
  3257. }
  3258. else if (exp >= q * 2 && iLevStep < 2)
  3259. {
  3260. for (int i = 0; i < 2 - iLevStep; ++i)
  3261. PointChange(POINT_LEVEL_STEP, 1, false, true);
  3262. }
  3263. else if (exp >= q && iLevStep < 1)
  3264. PointChange(POINT_LEVEL_STEP, 1);
  3265.  
  3266. if (iExpBalance)
  3267. {
  3268. PointChange(POINT_EXP, iExpBalance);
  3269. }
  3270.  
  3271. val = GetExp();
  3272. }
  3273. }
  3274. break;
  3275.  
  3276. case POINT_LEVEL_STEP:
  3277. if (amount > 0)
  3278. {
  3279. val = GetPoint(POINT_LEVEL_STEP) + amount;
  3280.  
  3281. switch (val)
  3282. {
  3283. case 1:
  3284. case 2:
  3285. case 3:
  3286. if (GetLevel() < 107) PointChange(POINT_STAT, 1);
  3287. break;
  3288.  
  3289. case 4:
  3290. {
  3291. int iHP = number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end);
  3292. int iSP = number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end);
  3293.  
  3294. m_points.iRandomHP += iHP;
  3295. m_points.iRandomSP += iSP;
  3296. if (GetSkillGroup())
  3297. {
  3298. if (GetLevel() >= 5)
  3299. PointChange(POINT_SKILL, 1);
  3300.  
  3301. if (GetLevel() >= 9)
  3302. PointChange(POINT_SUB_SKILL, 1);
  3303. }
  3304.  
  3305. PointChange(POINT_MAX_HP, iHP);
  3306. PointChange(POINT_MAX_SP, iSP);
  3307. PointChange(POINT_LEVEL, 1, false, true);
  3308.  
  3309. val = 0;
  3310. }
  3311. break;
  3312. }
  3313.  
  3314. PointChange(POINT_HP, GetMaxHP() - GetHP());
  3315. PointChange(POINT_SP, GetMaxSP() - GetSP());
  3316. PointChange(POINT_STAMINA, GetMaxStamina() - GetStamina());
  3317.  
  3318. SetPoint(POINT_LEVEL_STEP, val);
  3319. SetRealPoint(POINT_LEVEL_STEP, val);
  3320.  
  3321. Save();
  3322. }
  3323. else
  3324. val = GetPoint(POINT_LEVEL_STEP);
  3325.  
  3326. break;
  3327.  
  3328. case POINT_HP:
  3329. {
  3330. if (IsDead() || IsStun())
  3331. return;
  3332.  
  3333. int prev_hp = GetHP();
  3334.  
  3335. amount = MIN(GetMaxHP() - GetHP(), amount);
  3336. SetHP(GetHP() + amount);
  3337. val = GetHP();
  3338.  
  3339. BroadcastTargetPacket();
  3340.  
  3341. if (GetParty() && IsPC() && val != prev_hp)
  3342. GetParty()->SendPartyInfoOneToAll(this);
  3343. }
  3344. break;
  3345.  
  3346. case POINT_SP:
  3347. {
  3348. if (IsDead() || IsStun())
  3349. return;
  3350.  
  3351. amount = MIN(GetMaxSP() - GetSP(), amount);
  3352. SetSP(GetSP() + amount);
  3353. val = GetSP();
  3354. }
  3355. break;
  3356.  
  3357. case POINT_STAMINA:
  3358. {
  3359. if (IsDead() || IsStun())
  3360. return;
  3361.  
  3362. int prev_val = GetStamina();
  3363. amount = MIN(GetMaxStamina() - GetStamina(), amount);
  3364. SetStamina(GetStamina() + amount);
  3365. val = GetStamina();
  3366.  
  3367. if (val == 0)
  3368. {
  3369. SetNowWalking(true);
  3370. }
  3371. else if (prev_val == 0)
  3372. {
  3373. ResetWalking();
  3374. }
  3375.  
  3376. if (amount < 0 && val != 0)
  3377. return;
  3378. }
  3379. break;
  3380.  
  3381. case POINT_MAX_HP:
  3382. {
  3383. SetPoint(type, GetPoint(type) + amount);
  3384. int hp = GetRealPoint(POINT_MAX_HP);
  3385. int add_hp = MIN(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100);
  3386. add_hp += GetPoint(POINT_MAX_HP);
  3387. add_hp += GetPoint(POINT_PARTY_TANKER_BONUS);
  3388.  
  3389. SetMaxHP(hp + add_hp);
  3390. val = GetMaxHP();
  3391. }
  3392. break;
  3393.  
  3394. case POINT_MAX_SP:
  3395. {
  3396. SetPoint(type, GetPoint(type) + amount);
  3397. int sp = GetRealPoint(POINT_MAX_SP);
  3398. int add_sp = MIN(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100);
  3399. add_sp += GetPoint(POINT_MAX_SP);
  3400. add_sp += GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  3401.  
  3402. SetMaxSP(sp + add_sp);
  3403. val = GetMaxSP();
  3404. }
  3405. break;
  3406.  
  3407. case POINT_MAX_HP_PCT:
  3408. SetPoint(type, GetPoint(type) + amount);
  3409. val = GetPoint(type);
  3410.  
  3411. PointChange(POINT_MAX_HP, 0);
  3412. break;
  3413.  
  3414. case POINT_MAX_SP_PCT:
  3415. SetPoint(type, GetPoint(type) + amount);
  3416. val = GetPoint(type);
  3417.  
  3418. PointChange(POINT_MAX_SP, 0);
  3419. break;
  3420.  
  3421. case POINT_MAX_STAMINA:
  3422. SetMaxStamina(GetMaxStamina() + amount);
  3423. val = GetMaxStamina();
  3424. break;
  3425.  
  3426. case POINT_GOLD:
  3427. {
  3428. const long long nTotalMoney = static_cast<long long>(GetGold()) + static_cast<long long>(amount);
  3429.  
  3430. if (GOLD_MAX <= nTotalMoney)
  3431. {
  3432. sys_err("[OVERFLOW_GOLD] OriGold %lld AddedGold %lld id %u Name %s ", GetGold(), amount, GetPlayerID(), GetName());
  3433. LogManager::instance().CharLog(this, GetGold() + amount, "OVERFLOW_GOLD", "");
  3434. return;
  3435. }
  3436.  
  3437. // 청소년보호
  3438. if (LC_IsNewCIBN() && amount > 0)
  3439. {
  3440. if (IsOverTime(OT_NONE))
  3441. {
  3442. dev_log(LOG_DEB0, "<GOLD_LOG> %s = NONE", GetName());
  3443. }
  3444. else if (IsOverTime(OT_3HOUR))
  3445. {
  3446. amount = (amount / 2);
  3447. dev_log(LOG_DEB0, "<GOLD_LOG> %s = 3HOUR", GetName());
  3448. }
  3449. else if (IsOverTime(OT_5HOUR))
  3450. {
  3451. amount = 0;
  3452. dev_log(LOG_DEB0, "<GOLD_LOG> %s = 5HOUR", GetName());
  3453. }
  3454. }
  3455.  
  3456. SetGold(GetGold() + amount);
  3457. val = GetGold();
  3458. }
  3459. break;
  3460.  
  3461. case POINT_SKILL:
  3462. case POINT_STAT:
  3463. case POINT_SUB_SKILL:
  3464. case POINT_STAT_RESET_COUNT:
  3465. case POINT_HORSE_SKILL:
  3466. SetPoint(type, GetPoint(type) + amount);
  3467. val = GetPoint(type);
  3468.  
  3469. SetRealPoint(type, val);
  3470. break;
  3471.  
  3472. case POINT_DEF_GRADE:
  3473. SetPoint(type, GetPoint(type) + amount);
  3474. val = GetPoint(type);
  3475.  
  3476. PointChange(POINT_CLIENT_DEF_GRADE, amount);
  3477. break;
  3478.  
  3479. case POINT_CLIENT_DEF_GRADE:
  3480. SetPoint(type, GetPoint(type) + amount);
  3481. val = GetPoint(type);
  3482. break;
  3483.  
  3484. case POINT_ST:
  3485. case POINT_HT:
  3486. case POINT_DX:
  3487. case POINT_IQ:
  3488. case POINT_HP_REGEN:
  3489. case POINT_SP_REGEN:
  3490. case POINT_ATT_SPEED:
  3491. case POINT_ATT_GRADE:
  3492. case POINT_MOV_SPEED:
  3493. case POINT_CASTING_SPEED:
  3494. case POINT_MAGIC_ATT_GRADE:
  3495. case POINT_MAGIC_DEF_GRADE:
  3496. case POINT_BOW_DISTANCE:
  3497. case POINT_HP_RECOVERY:
  3498. case POINT_SP_RECOVERY:
  3499. case POINT_ATTBONUS_HUMAN:
  3500. case POINT_ATTBONUS_ANIMAL:
  3501. case POINT_ATTBONUS_ORC:
  3502. case POINT_ATTBONUS_MILGYO:
  3503. case POINT_ATTBONUS_UNDEAD:
  3504. case POINT_ATTBONUS_DEVIL:
  3505. case POINT_ATTBONUS_MONSTER:
  3506. case POINT_ATTBONUS_SURA:
  3507. case POINT_ATTBONUS_ASSASSIN:
  3508. case POINT_ATTBONUS_WARRIOR:
  3509. case POINT_ATTBONUS_SHAMAN:
  3510. case POINT_ATTBONUS_WOLFMAN:
  3511. case POINT_POISON_PCT:
  3512. case POINT_BLEEDING_PCT:
  3513. case POINT_STUN_PCT:
  3514. case POINT_SLOW_PCT:
  3515. case POINT_BLOCK:
  3516. case POINT_DODGE:
  3517. case POINT_CRITICAL_PCT:
  3518. case POINT_RESIST_CRITICAL:
  3519. case POINT_PENETRATE_PCT:
  3520. case POINT_RESIST_PENETRATE:
  3521. case POINT_CURSE_PCT:
  3522. case POINT_STEAL_HP:
  3523. case POINT_STEAL_SP:
  3524. case POINT_MANA_BURN_PCT:
  3525. case POINT_DAMAGE_SP_RECOVER:
  3526. case POINT_RESIST_NORMAL_DAMAGE:
  3527. case POINT_RESIST_SWORD:
  3528. case POINT_RESIST_TWOHAND:
  3529. case POINT_RESIST_DAGGER:
  3530. case POINT_RESIST_BELL:
  3531. case POINT_RESIST_FAN:
  3532. case POINT_RESIST_BOW:
  3533. case POINT_RESIST_CLAW:
  3534. case POINT_RESIST_FIRE:
  3535. case POINT_RESIST_ELEC:
  3536. case POINT_RESIST_MAGIC:
  3537. case POINT_RESIST_WIND:
  3538. case POINT_RESIST_ICE:
  3539. case POINT_RESIST_EARTH:
  3540. case POINT_RESIST_DARK:
  3541. case POINT_REFLECT_MELEE:
  3542. case POINT_REFLECT_CURSE:
  3543. case POINT_POISON_REDUCE:
  3544. case POINT_BLEEDING_REDUCE:
  3545. case POINT_KILL_SP_RECOVER:
  3546. case POINT_KILL_HP_RECOVERY:
  3547. case POINT_HIT_HP_RECOVERY:
  3548. case POINT_HIT_SP_RECOVERY:
  3549. case POINT_MANASHIELD:
  3550. case POINT_ATT_BONUS:
  3551. case POINT_DEF_BONUS:
  3552. case POINT_SKILL_DAMAGE_BONUS:
  3553. case POINT_NORMAL_HIT_DAMAGE_BONUS:
  3554. case POINT_SKILL_DEFEND_BONUS:
  3555. case POINT_NORMAL_HIT_DEFEND_BONUS:
  3556. SetPoint(type, GetPoint(type) + amount);
  3557. val = GetPoint(type);
  3558. break;
  3559.  
  3560. case POINT_PARTY_ATTACKER_BONUS:
  3561. case POINT_PARTY_TANKER_BONUS:
  3562. case POINT_PARTY_BUFFER_BONUS:
  3563. case POINT_PARTY_SKILL_MASTER_BONUS:
  3564. case POINT_PARTY_HASTE_BONUS:
  3565. case POINT_PARTY_DEFENDER_BONUS:
  3566. case POINT_RESIST_WARRIOR:
  3567. case POINT_RESIST_ASSASSIN:
  3568. case POINT_RESIST_SURA:
  3569. case POINT_RESIST_SHAMAN:
  3570. case POINT_RESIST_WOLFMAN:
  3571. SetPoint(type, GetPoint(type) + amount);
  3572. val = GetPoint(type);
  3573. break;
  3574.  
  3575. case POINT_MALL_ATTBONUS:
  3576. case POINT_MALL_DEFBONUS:
  3577. case POINT_MALL_EXPBONUS:
  3578. case POINT_MALL_ITEMBONUS:
  3579. case POINT_MALL_GOLDBONUS:
  3580. case POINT_MELEE_MAGIC_ATT_BONUS_PER:
  3581. if (GetPoint(type) + amount > 100)
  3582. {
  3583. sys_err("MALL_BONUS exceeded over 100!! point type: %d name: %s amount %d", type, GetName(), amount);
  3584. amount = 100 - GetPoint(type);
  3585. }
  3586.  
  3587. SetPoint(type, GetPoint(type) + amount);
  3588. val = GetPoint(type);
  3589. break;
  3590.  
  3591. case POINT_PC_BANG_EXP_BONUS :
  3592. case POINT_PC_BANG_DROP_BONUS :
  3593. case POINT_RAMADAN_CANDY_BONUS_EXP:
  3594. SetPoint(type, amount);
  3595. val = GetPoint(type);
  3596. break;
  3597.  
  3598. case POINT_EXP_DOUBLE_BONUS:
  3599. case POINT_GOLD_DOUBLE_BONUS:
  3600. case POINT_ITEM_DROP_BONUS:
  3601. case POINT_POTION_BONUS:
  3602. if (GetPoint(type) + amount > 100)
  3603. {
  3604. sys_err("BONUS exceeded over 100!! point type: %d name: %s amount %d", type, GetName(), amount);
  3605. amount = 100 - GetPoint(type);
  3606. }
  3607.  
  3608. SetPoint(type, GetPoint(type) + amount);
  3609. val = GetPoint(type);
  3610. break;
  3611.  
  3612. case POINT_IMMUNE_STUN:
  3613. SetPoint(type, GetPoint(type) + amount);
  3614. val = GetPoint(type);
  3615. if (val)
  3616. {
  3617. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_STUN);
  3618. }
  3619. else
  3620. {
  3621. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_STUN);
  3622. }
  3623. break;
  3624.  
  3625. case POINT_IMMUNE_SLOW:
  3626. SetPoint(type, GetPoint(type) + amount);
  3627. val = GetPoint(type);
  3628. if (val)
  3629. {
  3630. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_SLOW);
  3631. }
  3632. else
  3633. {
  3634. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_SLOW);
  3635. }
  3636. break;
  3637.  
  3638. case POINT_IMMUNE_FALL:
  3639. SetPoint(type, GetPoint(type) + amount);
  3640. val = GetPoint(type);
  3641. if (val)
  3642. {
  3643. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_FALL);
  3644. }
  3645. else
  3646. {
  3647. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_FALL);
  3648. }
  3649. break;
  3650.  
  3651. case POINT_ATT_GRADE_BONUS:
  3652. SetPoint(type, GetPoint(type) + amount);
  3653. PointChange(POINT_ATT_GRADE, amount);
  3654. val = GetPoint(type);
  3655. break;
  3656.  
  3657. case POINT_DEF_GRADE_BONUS:
  3658. SetPoint(type, GetPoint(type) + amount);
  3659. PointChange(POINT_DEF_GRADE, amount);
  3660. val = GetPoint(type);
  3661. break;
  3662.  
  3663. case POINT_MAGIC_ATT_GRADE_BONUS:
  3664. SetPoint(type, GetPoint(type) + amount);
  3665. PointChange(POINT_MAGIC_ATT_GRADE, amount);
  3666. val = GetPoint(type);
  3667. break;
  3668.  
  3669. case POINT_MAGIC_DEF_GRADE_BONUS:
  3670. SetPoint(type, GetPoint(type) + amount);
  3671. PointChange(POINT_MAGIC_DEF_GRADE, amount);
  3672. val = GetPoint(type);
  3673. break;
  3674.  
  3675. case POINT_VOICE:
  3676. case POINT_EMPIRE_POINT:
  3677. val = GetRealPoint(type);
  3678. break;
  3679.  
  3680. case POINT_POLYMORPH:
  3681. SetPoint(type, GetPoint(type) + amount);
  3682. val = GetPoint(type);
  3683. SetPolymorph(val);
  3684. break;
  3685.  
  3686. case POINT_MOUNT:
  3687. SetPoint(type, GetPoint(type) + amount);
  3688. val = GetPoint(type);
  3689. MountVnum(val);
  3690. break;
  3691.  
  3692. case POINT_ENERGY:
  3693. case POINT_COSTUME_ATTR_BONUS:
  3694. {
  3695. int old_val = GetPoint(type);
  3696. SetPoint(type, old_val + amount);
  3697. val = GetPoint(type);
  3698. BuffOnAttr_ValueChange(type, old_val, val);
  3699. }
  3700. break;
  3701.  
  3702. default:
  3703. sys_err("CHARACTER::PointChange: %s: unknown point change type %d", GetName(), type);
  3704. return;
  3705. }
  3706.  
  3707. switch (type)
  3708. {
  3709. case POINT_LEVEL:
  3710. case POINT_ST:
  3711. case POINT_DX:
  3712. case POINT_IQ:
  3713. case POINT_HT:
  3714. ComputeBattlePoints();
  3715. break;
  3716.  
  3717. case POINT_MAX_HP:
  3718. case POINT_MAX_SP:
  3719. case POINT_MAX_STAMINA:
  3720. break;
  3721. }
  3722.  
  3723. if (type == POINT_HP && amount == 0)
  3724. return;
  3725.  
  3726. if (GetDesc())
  3727. {
  3728. struct packet_point_change pack;
  3729. pack.header = HEADER_GC_CHARACTER_POINT_CHANGE;
  3730. pack.dwVID = m_vid;
  3731. pack.type = type;
  3732. pack.value = val;
  3733.  
  3734. if (bAmount)
  3735. pack.amount = amount;
  3736. else
  3737. pack.amount = 0;
  3738.  
  3739. if (!bBroadcast)
  3740. GetDesc()->Packet(&pack, sizeof(struct packet_point_change));
  3741. else
  3742. PacketAround(&pack, sizeof(pack));
  3743. }
  3744. }
  3745.  
  3746. #ifdef NEW_PET_SYSTEM
  3747. void CHARACTER::SendPetLevelUpEffect(int vid, int type, int value, int amount) {
  3748. struct packet_point_change pack;
  3749.  
  3750. pack.header = HEADER_GC_CHARACTER_POINT_CHANGE;
  3751. pack.dwVID = vid;
  3752. pack.type = type;
  3753. pack.value = value;
  3754. pack.amount = amount;
  3755. PacketAround(&pack, sizeof(pack));
  3756. }
  3757. #endif
  3758.  
  3759. void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
  3760. {
  3761. switch (bApplyType)
  3762. {
  3763. case APPLY_NONE:
  3764. break;
  3765.  
  3766. case APPLY_CON:
  3767. PointChange(POINT_HT, iVal);
  3768. PointChange(POINT_MAX_HP, (iVal * JobInitialPoints[GetJob()].hp_per_ht));
  3769. PointChange(POINT_MAX_STAMINA, (iVal * JobInitialPoints[GetJob()].stamina_per_con));
  3770. break;
  3771.  
  3772. case APPLY_INT:
  3773. PointChange(POINT_IQ, iVal);
  3774. PointChange(POINT_MAX_SP, (iVal * JobInitialPoints[GetJob()].sp_per_iq));
  3775. break;
  3776.  
  3777. case APPLY_SKILL:
  3778. {
  3779. BYTE bSkillVnum = (BYTE) (((DWORD)iVal) >> 24);
  3780. int iAdd = iVal & 0x00800000;
  3781. int iChange = iVal & 0x007fffff;
  3782.  
  3783. sys_log(1, "APPLY_SKILL skill %d add? %d change %d", bSkillVnum, iAdd ? 1 : 0, iChange);
  3784. if (0 == iAdd)
  3785. iChange = -iChange;
  3786.  
  3787. boost::unordered_map<BYTE, int>::iterator iter = m_SkillDamageBonus.find(bSkillVnum);
  3788. if (iter == m_SkillDamageBonus.end())
  3789. m_SkillDamageBonus.insert(std::make_pair(bSkillVnum, iChange));
  3790. else
  3791. iter->second += iChange;
  3792. }
  3793. break;
  3794.  
  3795. case APPLY_STR:
  3796. case APPLY_DEX:
  3797. case APPLY_MAX_HP:
  3798. case APPLY_MAX_SP:
  3799. case APPLY_MAX_HP_PCT:
  3800. case APPLY_MAX_SP_PCT:
  3801. case APPLY_ATT_SPEED:
  3802. case APPLY_MOV_SPEED:
  3803. case APPLY_CAST_SPEED:
  3804. case APPLY_HP_REGEN:
  3805. case APPLY_SP_REGEN:
  3806. case APPLY_POISON_PCT:
  3807. case APPLY_BLEEDING_PCT:
  3808. case APPLY_STUN_PCT:
  3809. case APPLY_SLOW_PCT:
  3810. case APPLY_CRITICAL_PCT:
  3811. case APPLY_PENETRATE_PCT:
  3812. case APPLY_ATTBONUS_HUMAN:
  3813. case APPLY_ATTBONUS_ANIMAL:
  3814. case APPLY_ATTBONUS_ORC:
  3815. case APPLY_ATTBONUS_MILGYO:
  3816. case APPLY_ATTBONUS_UNDEAD:
  3817. case APPLY_ATTBONUS_DEVIL:
  3818. case APPLY_ATTBONUS_WARRIOR:
  3819. case APPLY_ATTBONUS_ASSASSIN:
  3820. case APPLY_ATTBONUS_SURA:
  3821. case APPLY_ATTBONUS_SHAMAN:
  3822. case APPLY_ATTBONUS_MONSTER:
  3823. case APPLY_STEAL_HP:
  3824. case APPLY_STEAL_SP:
  3825. case APPLY_MANA_BURN_PCT:
  3826. case APPLY_DAMAGE_SP_RECOVER:
  3827. case APPLY_BLOCK:
  3828. case APPLY_DODGE:
  3829. case APPLY_RESIST_SWORD:
  3830. case APPLY_RESIST_TWOHAND:
  3831. case APPLY_RESIST_DAGGER:
  3832. case APPLY_RESIST_BELL:
  3833. case APPLY_RESIST_FAN:
  3834. case APPLY_RESIST_BOW:
  3835. case APPLY_RESIST_FIRE:
  3836. case APPLY_RESIST_ELEC:
  3837. case APPLY_RESIST_MAGIC:
  3838. case APPLY_RESIST_WIND:
  3839. case APPLY_RESIST_ICE:
  3840. case APPLY_RESIST_EARTH:
  3841. case APPLY_RESIST_DARK:
  3842. case APPLY_REFLECT_MELEE:
  3843. case APPLY_REFLECT_CURSE:
  3844. case APPLY_ANTI_CRITICAL_PCT:
  3845. case APPLY_ANTI_PENETRATE_PCT:
  3846. case APPLY_POISON_REDUCE:
  3847. case APPLY_BLEEDING_REDUCE:
  3848. case APPLY_KILL_SP_RECOVER:
  3849. case APPLY_EXP_DOUBLE_BONUS:
  3850. case APPLY_GOLD_DOUBLE_BONUS:
  3851. case APPLY_ITEM_DROP_BONUS:
  3852. case APPLY_POTION_BONUS:
  3853. case APPLY_KILL_HP_RECOVER:
  3854. case APPLY_IMMUNE_STUN:
  3855. case APPLY_IMMUNE_SLOW:
  3856. case APPLY_IMMUNE_FALL:
  3857. case APPLY_BOW_DISTANCE:
  3858. case APPLY_ATT_GRADE_BONUS:
  3859. case APPLY_DEF_GRADE_BONUS:
  3860. case APPLY_MAGIC_ATT_GRADE:
  3861. case APPLY_MAGIC_DEF_GRADE:
  3862. case APPLY_CURSE_PCT:
  3863. case APPLY_MAX_STAMINA:
  3864. case APPLY_MALL_ATTBONUS:
  3865. case APPLY_MALL_DEFBONUS:
  3866. case APPLY_MALL_EXPBONUS:
  3867. case APPLY_MALL_ITEMBONUS:
  3868. case APPLY_MALL_GOLDBONUS:
  3869. case APPLY_SKILL_DAMAGE_BONUS:
  3870. case APPLY_NORMAL_HIT_DAMAGE_BONUS:
  3871. case APPLY_SKILL_DEFEND_BONUS:
  3872. case APPLY_NORMAL_HIT_DEFEND_BONUS:
  3873. case APPLY_PC_BANG_EXP_BONUS:
  3874. case APPLY_PC_BANG_DROP_BONUS:
  3875. case APPLY_RESIST_WARRIOR:
  3876. case APPLY_RESIST_ASSASSIN:
  3877. case APPLY_RESIST_SURA:
  3878. case APPLY_RESIST_SHAMAN:
  3879. case APPLY_ENERGY:
  3880. case APPLY_DEF_GRADE:
  3881. case APPLY_COSTUME_ATTR_BONUS:
  3882. case APPLY_MAGIC_ATTBONUS_PER:
  3883. case APPLY_MELEE_MAGIC_ATTBONUS_PER:
  3884. case APPLY_ATTBONUS_WOLFMAN:
  3885. case APPLY_RESIST_WOLFMAN:
  3886. case APPLY_RESIST_CLAW:
  3887. PointChange(aApplyInfo[bApplyType].bPointType, iVal);
  3888. break;
  3889.  
  3890. default:
  3891. sys_err("Unknown apply type %d name %s", bApplyType, GetName());
  3892. break;
  3893. }
  3894. }
  3895.  
  3896. void CHARACTER::MotionPacketEncode(BYTE motion, LPCHARACTER victim, struct packet_motion * packet)
  3897. {
  3898. packet->header = HEADER_GC_MOTION;
  3899. packet->vid = m_vid;
  3900. packet->motion = motion;
  3901.  
  3902. if (victim)
  3903. packet->victim_vid = victim->GetVID();
  3904. else
  3905. packet->victim_vid = 0;
  3906. }
  3907.  
  3908. void CHARACTER::Motion(BYTE motion, LPCHARACTER victim)
  3909. {
  3910. struct packet_motion pack_motion;
  3911. MotionPacketEncode(motion, victim, &pack_motion);
  3912. PacketAround(&pack_motion, sizeof(struct packet_motion));
  3913. }
  3914.  
  3915. EVENTFUNC(save_event)
  3916. {
  3917. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  3918. if ( info == NULL )
  3919. {
  3920. sys_err( "save_event> <Factor> Null pointer" );
  3921. return 0;
  3922. }
  3923.  
  3924. LPCHARACTER ch = info->ch;
  3925.  
  3926. if (ch == NULL) { // <Factor>
  3927. return 0;
  3928. }
  3929. sys_log(1, "SAVE_EVENT: %s", ch->GetName());
  3930. ch->Save();
  3931. ch->FlushDelayedSaveItem();
  3932. return (save_event_second_cycle);
  3933. }
  3934.  
  3935. void CHARACTER::StartSaveEvent()
  3936. {
  3937. if (m_pkSaveEvent)
  3938. return;
  3939.  
  3940. char_event_info* info = AllocEventInfo<char_event_info>();
  3941.  
  3942. info->ch = this;
  3943. m_pkSaveEvent = event_create(save_event, info, save_event_second_cycle);
  3944. }
  3945.  
  3946. void CHARACTER::MonsterLog(const char* format, ...)
  3947. {
  3948. if (!test_server)
  3949. return;
  3950.  
  3951. if (IsPC())
  3952. return;
  3953.  
  3954. char chatbuf[CHAT_MAX_LEN + 1];
  3955. int len = snprintf(chatbuf, sizeof(chatbuf), "%u)", (DWORD)GetVID());
  3956.  
  3957. if (len < 0 || len >= (int) sizeof(chatbuf))
  3958. len = sizeof(chatbuf) - 1;
  3959.  
  3960. va_list args;
  3961.  
  3962. va_start(args, format);
  3963.  
  3964. int len2 = vsnprintf(chatbuf + len, sizeof(chatbuf) - len, format, args);
  3965.  
  3966. if (len2 < 0 || len2 >= (int) sizeof(chatbuf) - len)
  3967. len += (sizeof(chatbuf) - len) - 1;
  3968. else
  3969. len += len2;
  3970.  
  3971. // \0 문자 포함
  3972. ++len;
  3973.  
  3974. va_end(args);
  3975.  
  3976. TPacketGCChat pack_chat;
  3977.  
  3978. pack_chat.header = HEADER_GC_CHAT;
  3979. pack_chat.size = sizeof(TPacketGCChat) + len;
  3980. pack_chat.type = CHAT_TYPE_TALKING;
  3981. pack_chat.id = (DWORD)GetVID();
  3982. pack_chat.bEmpire = 0;
  3983.  
  3984. TEMP_BUFFER buf;
  3985. buf.write(&pack_chat, sizeof(TPacketGCChat));
  3986. buf.write(chatbuf, len);
  3987.  
  3988. CHARACTER_MANAGER::instance().PacketMonsterLog(this, buf.read_peek(), buf.size());
  3989. }
  3990.  
  3991. void CHARACTER::ChatPacket(BYTE type, const char * format, ...)
  3992. {
  3993. LPDESC d = GetDesc();
  3994.  
  3995. if (!d || !format)
  3996. return;
  3997.  
  3998. char chatbuf[CHAT_MAX_LEN + 1];
  3999. va_list args;
  4000.  
  4001. va_start(args, format);
  4002. int len = vsnprintf(chatbuf, sizeof(chatbuf), format, args);
  4003. va_end(args);
  4004.  
  4005. struct packet_chat pack_chat;
  4006.  
  4007. pack_chat.header = HEADER_GC_CHAT;
  4008. pack_chat.size = sizeof(struct packet_chat) + len;
  4009. pack_chat.type = type;
  4010. pack_chat.id = 0;
  4011. pack_chat.bEmpire = d->GetEmpire();
  4012.  
  4013. TEMP_BUFFER buf;
  4014. buf.write(&pack_chat, sizeof(struct packet_chat));
  4015. buf.write(chatbuf, len);
  4016.  
  4017. d->Packet(buf.read_peek(), buf.size());
  4018.  
  4019. if (type == CHAT_TYPE_COMMAND && test_server)
  4020. sys_log(0, "SEND_COMMAND %s %s", GetName(), chatbuf);
  4021. }
  4022.  
  4023. // MINING
  4024. void CHARACTER::mining_take()
  4025. {
  4026. m_pkMiningEvent = NULL;
  4027. }
  4028.  
  4029. void CHARACTER::mining_cancel()
  4030. {
  4031. if (m_pkMiningEvent)
  4032. {
  4033. sys_log(0, "XXX MINING CANCEL");
  4034. event_cancel(&m_pkMiningEvent);
  4035. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("채광을 중단하였습니다."));
  4036. }
  4037. }
  4038.  
  4039. void CHARACTER::mining(LPCHARACTER chLoad)
  4040. {
  4041. if (m_pkMiningEvent)
  4042. {
  4043. mining_cancel();
  4044. return;
  4045. }
  4046.  
  4047. if (!chLoad)
  4048. return;
  4049.  
  4050. if (mining::GetRawOreFromLoad(chLoad->GetRaceNum()) == 0)
  4051. return;
  4052.  
  4053. LPITEM pick = GetWear(WEAR_WEAPON);
  4054.  
  4055. if (!pick || pick->GetType() != ITEM_PICK)
  4056. {
  4057. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("곡괭이를 장착하세요."));
  4058. return;
  4059. }
  4060.  
  4061. int count = number(5, 15); // 동작 횟수, 한 동작당 2초
  4062.  
  4063. // 채광 동작을 보여줌
  4064. TPacketGCDigMotion p;
  4065. p.header = HEADER_GC_DIG_MOTION;
  4066. p.vid = GetVID();
  4067. p.target_vid = chLoad->GetVID();
  4068. p.count = count;
  4069.  
  4070. PacketAround(&p, sizeof(p));
  4071.  
  4072. m_pkMiningEvent = mining::CreateMiningEvent(this, chLoad, count);
  4073. }
  4074. // END_OF_MINING
  4075.  
  4076. void CHARACTER::fishing()
  4077. {
  4078. if (m_pkFishingEvent)
  4079. {
  4080. fishing_take();
  4081. return;
  4082. }
  4083.  
  4084. // 못감 속성에서 낚시를 시도한다?
  4085. {
  4086. LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(GetMapIndex());
  4087.  
  4088. int x = GetX();
  4089. int y = GetY();
  4090.  
  4091. LPSECTREE tree = pkSectreeMap->Find(x, y);
  4092. DWORD dwAttr = tree->GetAttribute(x, y);
  4093.  
  4094. if (IS_SET(dwAttr, ATTR_BLOCK))
  4095. {
  4096. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("낚시를 할 수 있는 곳이 아닙니다"));
  4097. return;
  4098. }
  4099. }
  4100.  
  4101. LPITEM rod = GetWear(WEAR_WEAPON);
  4102.  
  4103. // 낚시대 장착
  4104. if (!rod || rod->GetType() != ITEM_ROD)
  4105. {
  4106. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("낚시대를 장착 하세요."));
  4107. return;
  4108. }
  4109.  
  4110. if (0 == rod->GetSocket(2))
  4111. {
  4112. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("미끼를 끼고 던져 주세요."));
  4113. return;
  4114. }
  4115.  
  4116. float fx, fy;
  4117. GetDeltaByDegree(GetRotation(), 400.0f, &fx, &fy);
  4118.  
  4119. m_pkFishingEvent = fishing::CreateFishingEvent(this);
  4120. }
  4121.  
  4122. void CHARACTER::fishing_take()
  4123. {
  4124. LPITEM rod = GetWear(WEAR_WEAPON);
  4125. if (rod && rod->GetType() == ITEM_ROD)
  4126. {
  4127. using fishing::fishing_event_info;
  4128. if (m_pkFishingEvent)
  4129. {
  4130. struct fishing_event_info* info = dynamic_cast<struct fishing_event_info*>(m_pkFishingEvent->info);
  4131.  
  4132. if (info)
  4133. fishing::Take(info, this);
  4134. }
  4135. }
  4136. else
  4137. {
  4138. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("낚시대가 아닌 물건으로 낚시를 할 수 없습니다!"));
  4139. }
  4140.  
  4141. event_cancel(&m_pkFishingEvent);
  4142. }
  4143.  
  4144. bool CHARACTER::StartStateMachine(int iNextPulse)
  4145. {
  4146. if (CHARACTER_MANAGER::instance().AddToStateList(this))
  4147. {
  4148. m_dwNextStatePulse = thecore_heart->pulse + iNextPulse;
  4149. return true;
  4150. }
  4151.  
  4152. return false;
  4153. }
  4154.  
  4155. void CHARACTER::StopStateMachine()
  4156. {
  4157. CHARACTER_MANAGER::instance().RemoveFromStateList(this);
  4158. }
  4159.  
  4160. void CHARACTER::UpdateStateMachine(DWORD dwPulse)
  4161. {
  4162. if (dwPulse < m_dwNextStatePulse)
  4163. return;
  4164.  
  4165. if (IsDead())
  4166. return;
  4167.  
  4168. Update();
  4169. m_dwNextStatePulse = dwPulse + m_dwStateDuration;
  4170. }
  4171.  
  4172. void CHARACTER::SetNextStatePulse(int iNextPulse)
  4173. {
  4174. CHARACTER_MANAGER::instance().AddToStateList(this);
  4175. m_dwNextStatePulse = iNextPulse;
  4176.  
  4177. if (iNextPulse < 10)
  4178. MonsterLog("다음상태로어서가자");
  4179. }
  4180.  
  4181.  
  4182. // 캐릭터 인스턴스 업데이트 함수.
  4183. void CHARACTER::UpdateCharacter(DWORD dwPulse)
  4184. {
  4185. CFSM::Update();
  4186. }
  4187.  
  4188. void CHARACTER::SetShop(LPSHOP pkShop)
  4189. {
  4190. if ((m_pkShop = pkShop))
  4191. SET_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_SHOP);
  4192. else
  4193. {
  4194. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_SHOP);
  4195. SetShopOwner(NULL);
  4196. }
  4197. }
  4198.  
  4199. void CHARACTER::SetOfflineShop(LPOFFLINESHOP pkOfflineShop)
  4200. {
  4201. if ((m_pkOfflineShop = pkOfflineShop))
  4202. SET_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_OFFLINE_SHOP);
  4203. else
  4204. {
  4205. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_OFFLINE_SHOP);
  4206. SetOfflineShopOwner(NULL);
  4207. }
  4208. }
  4209.  
  4210. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  4211. void CHARACTER::OpenMyOfflineShop(const char * c_pszSign, TOfflineShopItemTable * pTable, BYTE bItemCount, BYTE bTime)
  4212. #else
  4213. void CHARACTER::OpenMyOfflineShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount, BYTE bTime)
  4214. #endif
  4215. {
  4216. quest::PC * pPC = quest::CQuestManager::instance().GetPC(GetPlayerID());
  4217.  
  4218. if (pPC && pPC->IsRunning())
  4219. return;
  4220.  
  4221. if (bItemCount == 0)
  4222. return;
  4223.  
  4224. if (GetShop() || GetOfflineShop())
  4225. return;
  4226.  
  4227. if (g_bEnableEmpireLimit)
  4228. {
  4229. if (GetEmpire() == 1 && (GetMapIndex() == 41 || GetMapIndex() == 21))
  4230. {
  4231. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline in acest oras!");
  4232. return;
  4233. }
  4234. else if (GetEmpire() == 2 && (GetMapIndex() == 1 || GetMapIndex() == 41))
  4235. {
  4236. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline in acest oras!");
  4237. return;
  4238. }
  4239. else if (GetEmpire() == 3 && (GetMapIndex() == 1 || GetMapIndex() == 21))
  4240. {
  4241. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline in acest oras!");
  4242. return;
  4243. }
  4244. }
  4245.  
  4246. {
  4247. if (!test_server)
  4248. {
  4249. if (IsGM())
  4250. {
  4251. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline, esti GM!");
  4252. return;
  4253. }
  4254. }
  4255. }
  4256.  
  4257. {
  4258. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_item WHERE owner_id = %u and status = 1", get_table_postfix(), GetPlayerID()));
  4259. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  4260.  
  4261. BYTE bResult = 0;
  4262. str_to_number(bResult, row[0]);
  4263.  
  4264. if (bResult)
  4265. {
  4266. ChatPacket(CHAT_TYPE_INFO, "Prima data trebuie sa-ti recuperezi obiectele nevandute!");
  4267. return;
  4268. }
  4269. }
  4270.  
  4271. {
  4272. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetPlayerID()));
  4273. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  4274.  
  4275. BYTE bResult = 0;
  4276. str_to_number(bResult, row[0]);
  4277.  
  4278. if (bResult)
  4279. {
  4280. ChatPacket(CHAT_TYPE_INFO, "Ai deja un magazin offline!");
  4281. ChatPacket(CHAT_TYPE_INFO, "Poti face altul,dupa ce il inchizi pe cel vechi.");
  4282. return;
  4283. }
  4284. }
  4285.  
  4286. if (g_bOfflineShopMapAllowLimit)
  4287. {
  4288. if (!offlineshop_map_allow_find(GetMapIndex()))
  4289. {
  4290. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline aici!");
  4291. return;
  4292. }
  4293. }
  4294.  
  4295.  
  4296. if (g_bNeededItem)
  4297. {
  4298. BYTE bCount = quest::CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(g_iItemVnum);
  4299. if (bCount < g_iItemVnum)
  4300. {
  4301. LPITEM pItem = ITEM_MANAGER::instance().CreateItem(g_iItemVnum);
  4302. ChatPacket(CHAT_TYPE_INFO, "Momentan nu-ti poti face un magazin offline, ai nevoie de x%d %s", g_bItemCount, pItem->GetName());
  4303. return;
  4304. }
  4305. }
  4306.  
  4307.  
  4308. if (g_bNeededMoney)
  4309. {
  4310. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  4311. if (GetGold() < static_cast<long long>(g_dwNeedMoney))
  4312. #else
  4313. if (GetGold() < static_cast<int>(g_dwNeedMoney))
  4314. #endif
  4315. {
  4316. ChatPacket(CHAT_TYPE_INFO, "Nu ai suficient yang pentru a face un magazin offline!");
  4317. ChatPacket(CHAT_TYPE_INFO, "Ai nevoie de : %u", g_dwNeedMoney);
  4318. return;
  4319. }
  4320. }
  4321.  
  4322.  
  4323. if (g_bNeedMinLevel && GetLevel() < g_bMinLevel)
  4324. {
  4325. ChatPacket(CHAT_TYPE_INFO, "Lv. tau este prea mic pentru ati deschide un magazin offline!");
  4326. return;
  4327. }
  4328.  
  4329. {
  4330. if (g_wCoinsForUnlimited > 0 && bTime == 4)
  4331. {
  4332. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT coins FROM account.account WHERE id = %u", GetAID()));
  4333. if (pMsg->Get()->uiNumRows == 0) return;
  4334. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  4335. long lCoins = 0;
  4336. str_to_number(lCoins, row[0]);
  4337.  
  4338. if (lCoins < static_cast<long>(g_wCoinsForUnlimited))
  4339. {
  4340. ChatPacket(CHAT_TYPE_INFO, "Ca sa-ti poti creea un magazin offline cu timpul NELIMITAT,");
  4341. ChatPacket(CHAT_TYPE_INFO, "Ai nevoie de %d Monede Dragon(MD) ,care le poti cumpara doar din ITEM-SHOP.", g_wCoinsForUnlimited);
  4342. return;
  4343. }
  4344.  
  4345. DBManager::instance().DirectQuery("UPDATE account.account SET coins = coins - %d where id = %u", g_wCoinsForUnlimited, GetAID());
  4346. }
  4347. }
  4348.  
  4349. if (CBanwordManager::instance().CheckString(m_stShopSign.c_str(), m_stShopSign.length()))
  4350. {
  4351. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("비속어나 은어가 포함된 상점 이름으로 상점을 열 수 없습니다."));
  4352. return;
  4353. }
  4354.  
  4355. char szSign[SHOP_SIGN_MAX_LEN + 1] = { 0 };
  4356. DBManager::instance().EscapeString(szSign, sizeof(szSign), c_pszSign, strlen(c_pszSign));
  4357.  
  4358. if (strlen(szSign) == 0)
  4359. {
  4360. ChatPacket(CHAT_TYPE_INFO, "Nu poti face un magazin offline fara un titlu/nume.");
  4361. return;
  4362. }
  4363.  
  4364. m_stOfflineShopSign = szSign;
  4365. if (m_stOfflineShopSign.length() == 0)
  4366. return;
  4367.  
  4368. LPCHARACTER npc = CHARACTER_MANAGER::instance().SpawnMob(30000, GetMapIndex(), GetX(), GetY(), GetZ(), false, -1, false, true, GetPlayerID());
  4369.  
  4370. if (!npc)
  4371. {
  4372. ChatPacket(CHAT_TYPE_INFO, "Magazinul offline nu a fost creat,incearca din nou!");
  4373. return;
  4374. }
  4375.  
  4376. std::map<DWORD, DWORD> itemkind;
  4377. std::set<TItemPos> cont;
  4378.  
  4379. for (BYTE i = 0; i < bItemCount; ++i)
  4380. {
  4381. if (cont.find((pTable + i)->pos) != cont.end())
  4382. {
  4383. sys_err("MY_OFFLINE_SHOP: duplicate shop item detected! (name: %s)", GetName());
  4384. return;
  4385. }
  4386.  
  4387. // ANTI_GIVE, ANTI_MYSHOP check
  4388. LPITEM pkItem = GetItem((pTable + i)->pos);
  4389.  
  4390. if (pkItem)
  4391. {
  4392. const TItemTable * item_table = pkItem->GetProto();
  4393.  
  4394. if (item_table && (IS_SET(item_table->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MY_OFFLINE_SHOP)))
  4395. {
  4396. ChatPacket(CHAT_TYPE_INFO, "Nu poti vinde acest obiect!");
  4397. return;
  4398. }
  4399.  
  4400. if (pkItem->IsEquipped() == true)
  4401. {
  4402. return;
  4403. }
  4404.  
  4405. if (true == pkItem->isLocked())
  4406. {
  4407. ChatPacket(CHAT_TYPE_INFO, "Nu poti vinde obiectele blocate!");
  4408. return;
  4409. }
  4410.  
  4411. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  4412. if ((pTable + i)->price >= GOLD_MAX)
  4413. {
  4414. ChatPacket(CHAT_TYPE_INFO, "Nu poti construi acest shop offline intrucat ai depasit limita de yang!");
  4415. return;
  4416. }
  4417. #else
  4418. if ((pTable + i)->price >= GOLD_MAX - 1)
  4419. {
  4420. ChatPacket(CHAT_TYPE_INFO, "Nu poti construi acest shop offline intrucat ai depasit limita de yang!");
  4421. return;
  4422. }
  4423. #endif
  4424.  
  4425. itemkind[pkItem->GetVnum()] = (pTable + i)->price / pkItem->GetCount();
  4426.  
  4427. char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
  4428.  
  4429. int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,vnum");
  4430. #ifdef ENABLE_MAXIMUM_YANG_FOR_OFFLINE_SHOP
  4431. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%lld,%u", pkItem->GetID(), GetPlayerID(), (pTable + i)->display_pos, pkItem->GetCount(), (pTable + i)->price, pkItem->GetVnum());
  4432. #else
  4433. int iUpdateLen = snprintf(szValues, sizeof(szValues), "%u,%u,%d,%u,%u,%u", pkItem->GetID(), GetPlayerID(), (pTable + i)->display_pos, pkItem->GetCount(), (pTable + i)->price, pkItem->GetVnum());
  4434. #endif
  4435.  
  4436. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
  4437. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
  4438.  
  4439. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ", attrtype0, attrvalue0, attrtype1, attrvalue1, attrtype2, attrvalue2, attrtype3, attrvalue3, attrtype4, attrvalue4, attrtype5, attrvalue5, attrtype6, attrvalue6, applytype0, applyvalue0, applytype1, applyvalue1, applytype2, applyvalue2, applytype3, applyvalue3, applytype4, applyvalue4, applytype5, applyvalue5, applytype6, applyvalue6, applytype7, applyvalue7");
  4440. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d, %d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  4441. pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
  4442. pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
  4443. pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
  4444. pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
  4445. pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
  4446. pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
  4447. pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6),
  4448. pkItem->GetAttributeType(7), pkItem->GetAttributeValue(7),
  4449. pkItem->GetAttributeType(8), pkItem->GetAttributeValue(8),
  4450. pkItem->GetAttributeType(9), pkItem->GetAttributeValue(9),
  4451. pkItem->GetAttributeType(10), pkItem->GetAttributeValue(10),
  4452. pkItem->GetAttributeType(11), pkItem->GetAttributeValue(11),
  4453. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(12),
  4454. pkItem->GetAttributeType(12), pkItem->GetAttributeValue(13),
  4455. pkItem->GetAttributeType(14), pkItem->GetAttributeValue(14));
  4456.  
  4457. char szInsertQuery[QUERY_MAX_LEN];
  4458. snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO %soffline_shop_item (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
  4459. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
  4460. pkItem->RemoveFromCharacter();
  4461. }
  4462.  
  4463. cont.insert((pTable + i)->pos);
  4464. }
  4465.  
  4466. int iTime = 0;
  4467. switch (bTime)
  4468. {
  4469. case 1:
  4470. iTime = 2 * 60 * 60;
  4471. break;
  4472. case 2:
  4473. iTime = 6 * 60 * 60;
  4474. break;
  4475. case 3:
  4476. iTime = 12 * 60 * 60;
  4477. break;
  4478. }
  4479.  
  4480. // If bTime is not equal to unlimited time, start the time!
  4481. if (bTime != 4)
  4482. {
  4483. npc->SetOfflineShopTimer(iTime);
  4484. npc->StartOfflineShopUpdateEvent();
  4485. }
  4486.  
  4487. // Insert
  4488. char szQuery2[512];
  4489. snprintf(szQuery2, sizeof(szQuery2), "INSERT INTO %soffline_shop_npc(owner_id, sign, name, time, x, y, z, mapIndex, channel) VALUES(%u, '%s', '%s', %d, %ld, %ld, %ld, %ld, %d)", get_table_postfix(), GetPlayerID(), szSign, GetName(), iTime, GetX(), GetY(), GetZ(), GetMapIndex(), g_bChannel);
  4490. DBManager::Instance().DirectQuery(szQuery2);
  4491.  
  4492. // Create Offline Shop
  4493. LPOFFLINESHOP pkOfflineShop = COfflineShopManager::instance().CreateOfflineShop(npc, GetPlayerID());
  4494.  
  4495. if (!pkOfflineShop)
  4496. {
  4497. ChatPacket(CHAT_TYPE_INFO, "Magazinul offline nu a fost creat,incearca din nou!");
  4498. return;
  4499. }
  4500.  
  4501. npc->SetOfflineShop(pkOfflineShop);
  4502. npc->SetOfflineShopChannel(g_bChannel);
  4503. // End Of Create Offline Shop
  4504.  
  4505. // Set Name
  4506. char szName[CHARACTER_NAME_MAX_LEN + 1];
  4507. snprintf(szName, sizeof(szName), "%s ,magazin", GetName());
  4508. npc->SetName(szName);
  4509. // End Of Set Name
  4510.  
  4511. SetOfflineShopVID(npc->GetVID());
  4512. npc->Show(GetMapIndex(), GetX(), GetY(), GetZ(), true);
  4513.  
  4514. // Send Offline Shop Sign to Everyone
  4515. TPacketGCShopSign p;
  4516. p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  4517. p.dwVID = npc->GetVID();
  4518. strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  4519.  
  4520. PacketAround(&p, sizeof(TPacketGCShopSign));
  4521. // End Of Send Offline Shop Sign to Everyone
  4522.  
  4523. if (bTime != 4)
  4524. ChatPacket(CHAT_TYPE_INFO, "Magazinul tau offline expira in %d ore.", iTime / 60 / 60);
  4525. else
  4526. ChatPacket(CHAT_TYPE_INFO, "Timpul magazinului tau offline este setat ca si NELIMITAT.");
  4527.  
  4528. if (g_bNeededItem)
  4529. {
  4530. LPITEM item = FindSpecifyItem(g_iItemVnum);
  4531. if (!item)
  4532. {
  4533. ChatPacket(CHAT_TYPE_INFO, "Ups! Ceva nu e bine!");
  4534. return;
  4535. }
  4536.  
  4537. if (item->IsStackable())
  4538. if (item->GetCount() == g_bItemCount)
  4539. ITEM_MANAGER::instance().RemoveItem(item);
  4540. else
  4541. item->SetCount(item->GetCount() - g_bItemCount);
  4542. else
  4543. ITEM_MANAGER::instance().RemoveItem(item);
  4544. }
  4545.  
  4546. if (g_bNeededMoney)
  4547. PointChange(POINT_GOLD, -g_dwNeedMoney, false);
  4548.  
  4549. SetOfflineShopStatus(2);
  4550. }
  4551.  
  4552.  
  4553. EVENTFUNC(offline_shop_update_event)
  4554. {
  4555. char_event_info* pInfo = dynamic_cast<char_event_info*>(event->info);
  4556.  
  4557. if (pInfo == NULL)
  4558. {
  4559. sys_err("offline_shop_update_event> <Factor> Null pointer");
  4560. return 0;
  4561. }
  4562.  
  4563. LPCHARACTER npc = pInfo->ch;
  4564.  
  4565. if (npc == NULL)
  4566. return 0;
  4567.  
  4568. int remain_time = npc->GetOfflineShopTimer() - processing_time / passes_per_sec;
  4569. if (remain_time <= 0)
  4570. {
  4571. sys_log(0, "OFFLINE SHOP EXPIRED : expired %s", npc->GetName());
  4572. LPCHARACTER pChar = CHARACTER_MANAGER::Instance().FindByPID(npc->GetOfflineShopRealOwner());
  4573. if (pChar)
  4574. {
  4575. pChar->ChatPacket(CHAT_TYPE_INFO, "Timpul magazinului tau offline a expirat! Recupereaza obiectele nevandute!");
  4576. COfflineShopManager::Instance().DestroyOfflineShop(pChar, npc->GetVID());
  4577. }
  4578. else
  4579. COfflineShopManager::Instance().DestroyOfflineShop(NULL, npc->GetVID());
  4580.  
  4581. DBManager::instance().DirectQuery("UPDATE %soffline_shop_item SET status = 1 WHERE owner_id = %u and status = 0", get_table_postfix(), npc->GetOfflineShopRealOwner());
  4582. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), npc->GetOfflineShopRealOwner());
  4583. M2_DESTROY_CHARACTER(npc);
  4584. return 0;
  4585. }
  4586.  
  4587. // If the variable is reach to maximum, start to save it
  4588. if (npc->GetOfflineShopSaveTime() >= g_bOfflineShopSaveTime)
  4589. {
  4590. DBManager::instance().DirectQuery("UPDATE %soffline_shop_npc SET time = %d WHERE owner_id = %u", get_table_postfix(), npc->GetOfflineShopTimer(), npc->GetOfflineShopRealOwner());
  4591. npc->SetOfflineShopTimer(1);
  4592. }
  4593.  
  4594. npc->SetOfflineShopTimer(remain_time);
  4595. npc->SetOfflineShopSaveTime(npc->GetOfflineShopSaveTime() + 1);
  4596. return PASSES_PER_SEC(MIN(60, remain_time));
  4597. }
  4598.  
  4599. void CHARACTER::StartOfflineShopUpdateEvent()
  4600. {
  4601. if (m_pkOfflineShopUpdateEvent)
  4602. return;
  4603.  
  4604. if (IsPC() || IsMonster())
  4605. return;
  4606.  
  4607. char_event_info * pInfo = AllocEventInfo<char_event_info>();
  4608. pInfo->ch = this;
  4609. m_pkOfflineShopUpdateEvent = event_create(offline_shop_update_event, pInfo, PASSES_PER_SEC(60));
  4610. }
  4611.  
  4612.  
  4613. void CHARACTER::StopOfflineShopUpdateEvent()
  4614. {
  4615. m_pointsInstant.bSaveTime = 0;
  4616. m_pointsInstant.leftTime = 0;
  4617. event_cancel(&m_pkOfflineShopUpdateEvent);
  4618. }
  4619.  
  4620. void CHARACTER::SetExchange(CExchange * pkExchange)
  4621. {
  4622. m_pkExchange = pkExchange;
  4623. }
  4624.  
  4625. void CHARACTER::SetPart(BYTE bPartPos, WORD wVal)
  4626. {
  4627. assert(bPartPos < PART_MAX_NUM);
  4628. m_pointsInstant.parts[bPartPos] = wVal;
  4629. }
  4630.  
  4631. WORD CHARACTER::GetPart(BYTE bPartPos) const
  4632. {
  4633. assert(bPartPos < PART_MAX_NUM);
  4634. return m_pointsInstant.parts[bPartPos];
  4635. }
  4636.  
  4637. WORD CHARACTER::GetOriginalPart(BYTE bPartPos) const
  4638. {
  4639. switch (bPartPos)
  4640. {
  4641. case PART_MAIN:
  4642. if (!IsPC())
  4643. return GetPart(PART_MAIN);
  4644. else
  4645. return m_pointsInstant.bBasePart;
  4646. case PART_HAIR:
  4647. return GetPart(PART_HAIR);
  4648. case PART_ACCE:
  4649. return GetPart(PART_ACCE);
  4650. default:
  4651. return 0;
  4652. }
  4653. }
  4654.  
  4655. BYTE CHARACTER::GetCharType() const
  4656. {
  4657. return m_bCharType;
  4658. }
  4659.  
  4660. bool CHARACTER::SetSyncOwner(LPCHARACTER ch, bool bRemoveFromList)
  4661. {
  4662. // TRENT_MONSTER
  4663. if (IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
  4664. return false;
  4665. // END_OF_TRENT_MONSTER
  4666.  
  4667. if (ch == this)
  4668. {
  4669. sys_err("SetSyncOwner owner == this (%p)", this);
  4670. return false;
  4671. }
  4672.  
  4673. if (!ch)
  4674. {
  4675. if (bRemoveFromList && m_pkChrSyncOwner)
  4676. {
  4677. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.remove(this);
  4678. }
  4679.  
  4680. if (m_pkChrSyncOwner)
  4681. sys_log(1, "SyncRelease %s %p from %s", GetName(), this, m_pkChrSyncOwner->GetName());
  4682.  
  4683. // 리스트에서 제거하지 않더라도 포인터는 NULL로 셋팅되어야 한다.
  4684. m_pkChrSyncOwner = NULL;
  4685. }
  4686. else
  4687. {
  4688. if (!IsSyncOwner(ch))
  4689. return false;
  4690.  
  4691. // 거리가 200 이상이면 SyncOwner가 될 수 없다.
  4692. if (DISTANCE_APPROX(GetX() - ch->GetX(), GetY() - ch->GetY()) > 250)
  4693. {
  4694. sys_log(1, "SetSyncOwner distance over than 250 %s %s", GetName(), ch->GetName());
  4695.  
  4696. // SyncOwner일 경우 Owner로 표시한다.
  4697. if (m_pkChrSyncOwner == ch)
  4698. return true;
  4699.  
  4700. return false;
  4701. }
  4702.  
  4703. if (m_pkChrSyncOwner != ch)
  4704. {
  4705. if (m_pkChrSyncOwner)
  4706. {
  4707. sys_log(1, "SyncRelease %s %p from %s", GetName(), this, m_pkChrSyncOwner->GetName());
  4708. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.remove(this);
  4709. }
  4710.  
  4711. m_pkChrSyncOwner = ch;
  4712. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.push_back(this);
  4713.  
  4714. // SyncOwner가 바뀌면 LastSyncTime을 초기화한다.
  4715. static const timeval zero_tv = {0, 0};
  4716. SetLastSyncTime(zero_tv);
  4717.  
  4718. sys_log(1, "SetSyncOwner set %s %p to %s", GetName(), this, ch->GetName());
  4719. }
  4720.  
  4721. m_fSyncTime = get_float_time();
  4722. }
  4723.  
  4724. // TODO: Sync Owner가 같더라도 계속 패킷을 보내고 있으므로,
  4725. // 동기화 된 시간이 3초 이상 지났을 때 풀어주는 패킷을
  4726. // 보내는 방식으로 하면 패킷을 줄일 수 있다.
  4727. TPacketGCOwnership pack;
  4728.  
  4729. pack.bHeader = HEADER_GC_OWNERSHIP;
  4730. pack.dwOwnerVID = ch ? ch->GetVID() : 0;
  4731. pack.dwVictimVID = GetVID();
  4732.  
  4733. PacketAround(&pack, sizeof(TPacketGCOwnership));
  4734. return true;
  4735. }
  4736.  
  4737. struct FuncClearSync
  4738. {
  4739. void operator () (LPCHARACTER ch)
  4740. {
  4741. assert(ch != NULL);
  4742. ch->SetSyncOwner(NULL, false); // false 플래그로 해야 for_each 가 제대로 돈다.
  4743. }
  4744. };
  4745.  
  4746. void CHARACTER::ClearSync()
  4747. {
  4748. SetSyncOwner(NULL);
  4749.  
  4750. // 아래 for_each에서 나를 m_pkChrSyncOwner로 가진 자들의 포인터를 NULL로 한다.
  4751. std::for_each(m_kLst_pkChrSyncOwned.begin(), m_kLst_pkChrSyncOwned.end(), FuncClearSync());
  4752. m_kLst_pkChrSyncOwned.clear();
  4753. }
  4754.  
  4755. bool CHARACTER::IsSyncOwner(LPCHARACTER ch) const
  4756. {
  4757. if (m_pkChrSyncOwner == ch)
  4758. return true;
  4759.  
  4760. // 마지막으로 동기화 된 시간이 3초 이상 지났다면 소유권이 아무에게도
  4761. // 없다. 따라서 아무나 SyncOwner이므로 true 리턴
  4762. if (get_float_time() - m_fSyncTime >= 3.0f)
  4763. return true;
  4764.  
  4765. return false;
  4766. }
  4767.  
  4768. void CHARACTER::SetParty(LPPARTY pkParty)
  4769. {
  4770. if (pkParty == m_pkParty)
  4771. return;
  4772.  
  4773. if (pkParty && m_pkParty)
  4774. sys_err("%s is trying to reassigning party (current %p, new party %p)", GetName(), get_pointer(m_pkParty), get_pointer(pkParty));
  4775.  
  4776. sys_log(1, "PARTY set to %p", get_pointer(pkParty));
  4777.  
  4778. //if (m_pkDungeon && IsPC())
  4779. //SetDungeon(NULL);
  4780. m_pkParty = pkParty;
  4781.  
  4782. if (IsPC())
  4783. {
  4784. if (m_pkParty)
  4785. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_PARTY);
  4786. else
  4787. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_PARTY);
  4788.  
  4789. UpdatePacket();
  4790. }
  4791. }
  4792.  
  4793. // PARTY_JOIN_BUG_FIX
  4794. /// 파티 가입 event 정보
  4795. EVENTINFO(TPartyJoinEventInfo)
  4796. {
  4797. DWORD dwGuestPID; ///< 파티에 참여할 캐릭터의 PID
  4798. DWORD dwLeaderPID; ///< 파티 리더의 PID
  4799.  
  4800. TPartyJoinEventInfo()
  4801. : dwGuestPID( 0 )
  4802. , dwLeaderPID( 0 )
  4803. {
  4804. }
  4805. } ;
  4806.  
  4807. EVENTFUNC(party_request_event)
  4808. {
  4809. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>( event->info );
  4810.  
  4811. if ( info == NULL )
  4812. {
  4813. sys_err( "party_request_event> <Factor> Null pointer" );
  4814. return 0;
  4815. }
  4816.  
  4817. LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(info->dwGuestPID);
  4818.  
  4819. if (ch)
  4820. {
  4821. sys_log(0, "PartyRequestEvent %s", ch->GetName());
  4822. ch->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  4823. ch->SetPartyRequestEvent(NULL);
  4824. }
  4825.  
  4826. return 0;
  4827. }
  4828.  
  4829. bool CHARACTER::RequestToParty(LPCHARACTER leader)
  4830. {
  4831. if (leader->GetParty())
  4832. leader = leader->GetParty()->GetLeaderCharacter();
  4833.  
  4834. if (!leader)
  4835. {
  4836. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("파티장이 접속 상태가 아니라서 요청을 할 수 없습니다."));
  4837. return false;
  4838. }
  4839.  
  4840. if (m_pkPartyRequestEvent)
  4841. return false;
  4842.  
  4843. if (!IsPC() || !leader->IsPC())
  4844. return false;
  4845.  
  4846. if (leader->IsBlockMode(BLOCK_PARTY_REQUEST))
  4847. return false;
  4848.  
  4849. PartyJoinErrCode errcode = IsPartyJoinableCondition(leader, this);
  4850.  
  4851. switch (errcode)
  4852. {
  4853. case PERR_NONE:
  4854. break;
  4855.  
  4856. case PERR_SERVER:
  4857. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 서버 문제로 파티 관련 처리를 할 수 없습니다."));
  4858. return false;
  4859.  
  4860. case PERR_DIFFEMPIRE:
  4861. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 다른 제국과 파티를 이룰 수 없습니다."));
  4862. return false;
  4863.  
  4864. case PERR_DUNGEON:
  4865. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 던전 안에서는 파티 초대를 할 수 없습니다."));
  4866. return false;
  4867.  
  4868. case PERR_OBSERVER:
  4869. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 관전 모드에선 파티 초대를 할 수 없습니다."));
  4870. return false;
  4871.  
  4872. case PERR_LVBOUNDARY:
  4873. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> -30 ~ +30 레벨 이내의 상대방만 초대할 수 있습니다."));
  4874. return false;
  4875.  
  4876. case PERR_LOWLEVEL:
  4877. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최고 레벨 보다 30레벨이 낮아 초대할 수 없습니다."));
  4878. return false;
  4879.  
  4880. case PERR_HILEVEL:
  4881. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최저 레벨 보다 30레벨이 높아 초대할 수 없습니다."));
  4882. return false;
  4883.  
  4884. case PERR_ALREADYJOIN:
  4885. return false;
  4886.  
  4887. case PERR_PARTYISFULL:
  4888. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 더 이상 파티원을 초대할 수 없습니다."));
  4889. return false;
  4890.  
  4891. default:
  4892. sys_err("Do not process party join error(%d)", errcode);
  4893. return false;
  4894. }
  4895.  
  4896. TPartyJoinEventInfo* info = AllocEventInfo<TPartyJoinEventInfo>();
  4897.  
  4898. info->dwGuestPID = GetPlayerID();
  4899. info->dwLeaderPID = leader->GetPlayerID();
  4900.  
  4901. SetPartyRequestEvent(event_create(party_request_event, info, PASSES_PER_SEC(10)));
  4902.  
  4903. leader->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequest %u", (DWORD) GetVID());
  4904. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s 님에게 파티가입 신청을 했습니다."), leader->GetName());
  4905. return true;
  4906. }
  4907.  
  4908. void CHARACTER::DenyToParty(LPCHARACTER member)
  4909. {
  4910. sys_log(1, "DenyToParty %s member %s %p", GetName(), member->GetName(), get_pointer(member->m_pkPartyRequestEvent));
  4911.  
  4912. if (!member->m_pkPartyRequestEvent)
  4913. return;
  4914.  
  4915. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>(member->m_pkPartyRequestEvent->info);
  4916.  
  4917. if (!info)
  4918. {
  4919. sys_err( "CHARACTER::DenyToParty> <Factor> Null pointer" );
  4920. return;
  4921. }
  4922.  
  4923. if (info->dwGuestPID != member->GetPlayerID())
  4924. return;
  4925.  
  4926. if (info->dwLeaderPID != GetPlayerID())
  4927. return;
  4928.  
  4929. event_cancel(&member->m_pkPartyRequestEvent);
  4930.  
  4931. member->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  4932. }
  4933.  
  4934. void CHARACTER::AcceptToParty(LPCHARACTER member)
  4935. {
  4936. sys_log(1, "AcceptToParty %s member %s %p", GetName(), member->GetName(), get_pointer(member->m_pkPartyRequestEvent));
  4937.  
  4938. if (!member->m_pkPartyRequestEvent)
  4939. return;
  4940.  
  4941. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>(member->m_pkPartyRequestEvent->info);
  4942.  
  4943. if (!info)
  4944. {
  4945. sys_err( "CHARACTER::AcceptToParty> <Factor> Null pointer" );
  4946. return;
  4947. }
  4948.  
  4949. if (info->dwGuestPID != member->GetPlayerID())
  4950. return;
  4951.  
  4952. if (info->dwLeaderPID != GetPlayerID())
  4953. return;
  4954.  
  4955. event_cancel(&member->m_pkPartyRequestEvent);
  4956.  
  4957. if (!GetParty())
  4958. member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 파티에 속해있지 않습니다."));
  4959. else
  4960. {
  4961. if (GetPlayerID() != GetParty()->GetLeaderPID())
  4962. return;
  4963.  
  4964. PartyJoinErrCode errcode = IsPartyJoinableCondition(this, member);
  4965. switch (errcode)
  4966. {
  4967. case PERR_NONE: member->PartyJoin(this); return;
  4968. case PERR_SERVER: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 서버 문제로 파티 관련 처리를 할 수 없습니다.")); break;
  4969. case PERR_DUNGEON: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 던전 안에서는 파티 초대를 할 수 없습니다.")); break;
  4970. case PERR_OBSERVER: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 관전 모드에선 파티 초대를 할 수 없습니다.")); break;
  4971. case PERR_LVBOUNDARY: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> -30 ~ +30 레벨 이내의 상대방만 초대할 수 있습니다.")); break;
  4972. case PERR_LOWLEVEL: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최고 레벨 보다 30레벨이 낮아 초대할 수 없습니다.")); break;
  4973. case PERR_HILEVEL: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최저 레벨 보다 30레벨이 높아 초대할 수 없습니다.")); break;
  4974. case PERR_ALREADYJOIN: break;
  4975. case PERR_PARTYISFULL: {
  4976. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 더 이상 파티원을 초대할 수 없습니다."));
  4977. member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티의 인원제한이 초과하여 파티에 참가할 수 없습니다."));
  4978. break;
  4979. }
  4980. default: sys_err("Do not process party join error(%d)", errcode);
  4981. }
  4982. }
  4983.  
  4984. member->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  4985. }
  4986.  
  4987. /**
  4988. * 파티 초대 event callback 함수.
  4989. * event 가 발동하면 초대 거절로 처리한다.
  4990. */
  4991. EVENTFUNC(party_invite_event)
  4992. {
  4993. TPartyJoinEventInfo * pInfo = dynamic_cast<TPartyJoinEventInfo *>( event->info );
  4994.  
  4995. if ( pInfo == NULL )
  4996. {
  4997. sys_err( "party_invite_event> <Factor> Null pointer" );
  4998. return 0;
  4999. }
  5000.  
  5001. LPCHARACTER pchInviter = CHARACTER_MANAGER::instance().FindByPID(pInfo->dwLeaderPID);
  5002.  
  5003. if (pchInviter)
  5004. {
  5005. sys_log(1, "PartyInviteEvent %s", pchInviter->GetName());
  5006. pchInviter->PartyInviteDeny(pInfo->dwGuestPID);
  5007. }
  5008.  
  5009. return 0;
  5010. }
  5011.  
  5012. void CHARACTER::PartyInvite(LPCHARACTER pchInvitee)
  5013. {
  5014. if (GetParty() && GetParty()->GetLeaderPID() != GetPlayerID())
  5015. {
  5016. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티원을 초대할 수 있는 권한이 없습니다."));
  5017. return;
  5018. }
  5019. else if (pchInvitee->IsBlockMode(BLOCK_PARTY_INVITE))
  5020. {
  5021. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> %s 님이 파티 거부 상태입니다."), pchInvitee->GetName());
  5022. return;
  5023. }
  5024.  
  5025. PartyJoinErrCode errcode = IsPartyJoinableCondition(this, pchInvitee);
  5026.  
  5027. switch (errcode)
  5028. {
  5029. case PERR_NONE:
  5030. break;
  5031.  
  5032. case PERR_SERVER:
  5033. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 서버 문제로 파티 관련 처리를 할 수 없습니다."));
  5034. return;
  5035.  
  5036. case PERR_DIFFEMPIRE:
  5037. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 다른 제국과 파티를 이룰 수 없습니다."));
  5038. return;
  5039.  
  5040. case PERR_DUNGEON:
  5041. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 던전 안에서는 파티 초대를 할 수 없습니다."));
  5042. return;
  5043.  
  5044. case PERR_OBSERVER:
  5045. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 관전 모드에선 파티 초대를 할 수 없습니다."));
  5046. return;
  5047.  
  5048. case PERR_LVBOUNDARY:
  5049. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> -30 ~ +30 레벨 이내의 상대방만 초대할 수 있습니다."));
  5050. return;
  5051.  
  5052. case PERR_LOWLEVEL:
  5053. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최고 레벨 보다 30레벨이 낮아 초대할 수 없습니다."));
  5054. return;
  5055.  
  5056. case PERR_HILEVEL:
  5057. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최저 레벨 보다 30레벨이 높아 초대할 수 없습니다."));
  5058. return;
  5059.  
  5060. case PERR_ALREADYJOIN:
  5061. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 이미 %s님은 파티에 속해 있습니다."), pchInvitee->GetName());
  5062. return;
  5063.  
  5064. case PERR_PARTYISFULL:
  5065. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 더 이상 파티원을 초대할 수 없습니다."));
  5066. return;
  5067.  
  5068. default:
  5069. sys_err("Do not process party join error(%d)", errcode);
  5070. return;
  5071. }
  5072.  
  5073. if (m_PartyInviteEventMap.end() != m_PartyInviteEventMap.find(pchInvitee->GetPlayerID()))
  5074. return;
  5075.  
  5076. //
  5077. // EventMap 에 이벤트 추가
  5078. //
  5079. TPartyJoinEventInfo* info = AllocEventInfo<TPartyJoinEventInfo>();
  5080.  
  5081. info->dwGuestPID = pchInvitee->GetPlayerID();
  5082. info->dwLeaderPID = GetPlayerID();
  5083.  
  5084. m_PartyInviteEventMap.insert(EventMap::value_type(pchInvitee->GetPlayerID(), event_create(party_invite_event, info, PASSES_PER_SEC(10))));
  5085.  
  5086. //
  5087. // 초대 받는 character 에게 초대 패킷 전송
  5088. //
  5089.  
  5090. TPacketGCPartyInvite p;
  5091. p.header = HEADER_GC_PARTY_INVITE;
  5092. p.leader_vid = GetVID();
  5093. pchInvitee->GetDesc()->Packet(&p, sizeof(p));
  5094. }
  5095.  
  5096. void CHARACTER::PartyInviteAccept(LPCHARACTER pchInvitee)
  5097. {
  5098. EventMap::iterator itFind = m_PartyInviteEventMap.find(pchInvitee->GetPlayerID());
  5099.  
  5100. if (itFind == m_PartyInviteEventMap.end())
  5101. {
  5102. sys_log(1, "PartyInviteAccept from not invited character(%s)", pchInvitee->GetName());
  5103. return;
  5104. }
  5105.  
  5106. event_cancel(&itFind->second);
  5107. m_PartyInviteEventMap.erase(itFind);
  5108.  
  5109. if (GetParty() && GetParty()->GetLeaderPID() != GetPlayerID())
  5110. {
  5111. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티원을 초대할 수 있는 권한이 없습니다."));
  5112. return;
  5113. }
  5114.  
  5115. PartyJoinErrCode errcode = IsPartyJoinableMutableCondition(this, pchInvitee);
  5116.  
  5117. switch (errcode)
  5118. {
  5119. case PERR_NONE:
  5120. break;
  5121.  
  5122. case PERR_SERVER:
  5123. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 서버 문제로 파티 관련 처리를 할 수 없습니다."));
  5124. return;
  5125.  
  5126. case PERR_DUNGEON:
  5127. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 던전 안에서는 파티 초대에 응할 수 없습니다."));
  5128. return;
  5129.  
  5130. case PERR_OBSERVER:
  5131. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 관전 모드에선 파티 초대를 할 수 없습니다."));
  5132. return;
  5133.  
  5134. case PERR_LVBOUNDARY:
  5135. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> -30 ~ +30 레벨 이내의 상대방만 초대할 수 있습니다."));
  5136. return;
  5137.  
  5138. case PERR_LOWLEVEL:
  5139. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최고 레벨 보다 30레벨이 낮아 초대할 수 없습니다."));
  5140. return;
  5141.  
  5142. case PERR_HILEVEL:
  5143. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티내 최저 레벨 보다 30레벨이 높아 초대할 수 없습니다."));
  5144. return;
  5145.  
  5146. case PERR_ALREADYJOIN:
  5147. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티 초대에 응할 수 없습니다."));
  5148. return;
  5149.  
  5150. case PERR_PARTYISFULL:
  5151. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 더 이상 파티원을 초대할 수 없습니다."));
  5152. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> 파티의 인원제한이 초과하여 파티에 참가할 수 없습니다."));
  5153. return;
  5154.  
  5155. default:
  5156. sys_err("ignore party join error(%d)", errcode);
  5157. return;
  5158. }
  5159.  
  5160. //
  5161. // 파티 가입 처리
  5162. //
  5163.  
  5164. if (GetParty())
  5165. pchInvitee->PartyJoin(this);
  5166. else
  5167. {
  5168. LPPARTY pParty = CPartyManager::instance().CreateParty(this);
  5169.  
  5170. pParty->Join(pchInvitee->GetPlayerID());
  5171. pParty->Link(pchInvitee);
  5172. pParty->SendPartyInfoAllToOne(this);
  5173. }
  5174. }
  5175.  
  5176. void CHARACTER::PartyInviteDeny(DWORD dwPID)
  5177. {
  5178. EventMap::iterator itFind = m_PartyInviteEventMap.find(dwPID);
  5179.  
  5180. if (itFind == m_PartyInviteEventMap.end())
  5181. {
  5182. sys_log(1, "PartyInviteDeny to not exist event(inviter PID: %d, invitee PID: %d)", GetPlayerID(), dwPID);
  5183. return;
  5184. }
  5185.  
  5186. event_cancel(&itFind->second);
  5187. m_PartyInviteEventMap.erase(itFind);
  5188.  
  5189. LPCHARACTER pchInvitee = CHARACTER_MANAGER::instance().FindByPID(dwPID);
  5190. if (pchInvitee)
  5191. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> %s님이 파티 초대를 거절하셨습니다."), pchInvitee->GetName());
  5192. }
  5193.  
  5194. void CHARACTER::PartyJoin(LPCHARACTER pLeader)
  5195. {
  5196. pLeader->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> %s님이 파티에 참가하셨습니다."), GetName());
  5197. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<파티> %s님의 파티에 참가하셨습니다."), pLeader->GetName());
  5198.  
  5199. pLeader->GetParty()->Join(GetPlayerID());
  5200. pLeader->GetParty()->Link(this);
  5201. }
  5202.  
  5203. CHARACTER::PartyJoinErrCode CHARACTER::IsPartyJoinableCondition(const LPCHARACTER pchLeader, const LPCHARACTER pchGuest)
  5204. {
  5205. if (pchLeader->GetEmpire() != pchGuest->GetEmpire())
  5206. return PERR_DIFFEMPIRE;
  5207.  
  5208. return IsPartyJoinableMutableCondition(pchLeader, pchGuest);
  5209. }
  5210.  
  5211. static bool __party_can_join_by_level(LPCHARACTER leader, LPCHARACTER quest)
  5212. {
  5213. int level_limit = 30;
  5214.  
  5215. if (LC_IsCanada())
  5216. level_limit = 15;
  5217. else if (LC_IsBrazil() == true)
  5218. {
  5219. level_limit = 10;
  5220. }
  5221. else
  5222. level_limit = 30;
  5223.  
  5224. return (abs(leader->GetLevel() - quest->GetLevel()) <= level_limit);
  5225. }
  5226.  
  5227. CHARACTER::PartyJoinErrCode CHARACTER::IsPartyJoinableMutableCondition(const LPCHARACTER pchLeader, const LPCHARACTER pchGuest)
  5228. {
  5229. if (!CPartyManager::instance().IsEnablePCParty())
  5230. return PERR_SERVER;
  5231. else if (pchLeader->GetDungeon())
  5232. return PERR_DUNGEON;
  5233. else if (pchGuest->IsObserverMode())
  5234. return PERR_OBSERVER;
  5235. else if (false == __party_can_join_by_level(pchLeader, pchGuest))
  5236. return PERR_LVBOUNDARY;
  5237. else if (pchGuest->GetParty())
  5238. return PERR_ALREADYJOIN;
  5239. else if (pchLeader->GetParty())
  5240. {
  5241. if (pchLeader->GetParty()->GetMemberCount() == PARTY_MAX_MEMBER)
  5242. return PERR_PARTYISFULL;
  5243. }
  5244.  
  5245. return PERR_NONE;
  5246. }
  5247. // END_OF_PARTY_JOIN_BUG_FIX
  5248.  
  5249. void CHARACTER::SetDungeon(LPDUNGEON pkDungeon)
  5250. {
  5251. if (pkDungeon && m_pkDungeon)
  5252. sys_err("%s is trying to reassigning dungeon (current %p, new party %p)", GetName(), get_pointer(m_pkDungeon), get_pointer(pkDungeon));
  5253.  
  5254. if (m_pkDungeon == pkDungeon) {
  5255. return;
  5256. }
  5257.  
  5258. if (m_pkDungeon)
  5259. {
  5260. if (IsPC())
  5261. {
  5262. if (GetParty())
  5263. m_pkDungeon->DecPartyMember(GetParty(), this);
  5264. else
  5265. m_pkDungeon->DecMember(this);
  5266. }
  5267. else if (IsMonster() || IsStone())
  5268. {
  5269. m_pkDungeon->DecMonster();
  5270. }
  5271. }
  5272.  
  5273. m_pkDungeon = pkDungeon;
  5274.  
  5275. if (pkDungeon)
  5276. {
  5277. sys_log(0, "%s DUNGEON set to %p, PARTY is %p", GetName(), get_pointer(pkDungeon), get_pointer(m_pkParty));
  5278.  
  5279. if (IsPC())
  5280. {
  5281. if (GetParty())
  5282. m_pkDungeon->IncPartyMember(GetParty(), this);
  5283. else
  5284. m_pkDungeon->IncMember(this);
  5285. }
  5286. else if (IsMonster() || IsStone())
  5287. {
  5288. m_pkDungeon->IncMonster();
  5289. }
  5290. }
  5291. }
  5292.  
  5293. void CHARACTER::SetWarMap(CWarMap * pWarMap)
  5294. {
  5295. if (m_pWarMap)
  5296. m_pWarMap->DecMember(this);
  5297.  
  5298. m_pWarMap = pWarMap;
  5299.  
  5300. if (m_pWarMap)
  5301. m_pWarMap->IncMember(this);
  5302. }
  5303.  
  5304. void CHARACTER::SetWeddingMap(marriage::WeddingMap* pMap)
  5305. {
  5306. if (m_pWeddingMap)
  5307. m_pWeddingMap->DecMember(this);
  5308.  
  5309. m_pWeddingMap = pMap;
  5310.  
  5311. if (m_pWeddingMap)
  5312. m_pWeddingMap->IncMember(this);
  5313. }
  5314.  
  5315. void CHARACTER::SetRegen(LPREGEN pkRegen)
  5316. {
  5317. m_pkRegen = pkRegen;
  5318. if (pkRegen != NULL) {
  5319. regen_id_ = pkRegen->id;
  5320. }
  5321. m_fRegenAngle = GetRotation();
  5322. m_posRegen = GetXYZ();
  5323. }
  5324.  
  5325. bool CHARACTER::OnIdle()
  5326. {
  5327. return false;
  5328. }
  5329.  
  5330. void CHARACTER::OnMove(bool bIsAttack)
  5331. {
  5332. m_dwLastMoveTime = get_dword_time();
  5333.  
  5334. if (bIsAttack)
  5335. {
  5336. m_dwLastAttackTime = m_dwLastMoveTime;
  5337.  
  5338. if (IsAffectFlag(AFF_REVIVE_INVISIBLE))
  5339. RemoveAffect(AFFECT_REVIVE_INVISIBLE);
  5340.  
  5341. if (IsAffectFlag(AFF_EUNHYUNG))
  5342. {
  5343. RemoveAffect(SKILL_EUNHYUNG);
  5344. SetAffectedEunhyung();
  5345. }
  5346. else
  5347. {
  5348. ClearAffectedEunhyung();
  5349. }
  5350.  
  5351. /*if (IsAffectFlag(AFF_JEONSIN))
  5352. RemoveAffect(SKILL_JEONSINBANGEO);*/
  5353. }
  5354.  
  5355. /*if (IsAffectFlag(AFF_GUNGON))
  5356. RemoveAffect(SKILL_GUNGON);*/
  5357.  
  5358. // MINING
  5359. mining_cancel();
  5360. // END_OF_MINING
  5361. }
  5362.  
  5363. void CHARACTER::OnClick(LPCHARACTER pkChrCauser)
  5364. {
  5365. if (!pkChrCauser)
  5366. {
  5367. sys_err("OnClick %s by NULL", GetName());
  5368. return;
  5369. }
  5370.  
  5371. DWORD vid = GetVID();
  5372. sys_log(0, "OnClick %s[vnum %d ServerUniqueID %d, pid %d] by %s", GetName(), GetRaceNum(), vid, GetPlayerID(), pkChrCauser->GetName());
  5373.  
  5374. // 상점을 연상태로 퀘스트를 진행할 수 없다.
  5375. {
  5376. // 단, 자신은 자신의 상점을 클릭할 수 있다.
  5377. if (pkChrCauser->GetMyShop() && pkChrCauser != this)
  5378. {
  5379. sys_err("OnClick Fail (%s->%s) - pc has shop", pkChrCauser->GetName(), GetName());
  5380. return;
  5381. }
  5382. }
  5383.  
  5384. // 교환중일때 퀘스트를 진행할 수 없다.
  5385. {
  5386. if (pkChrCauser->GetExchange())
  5387. {
  5388. sys_err("OnClick Fail (%s->%s) - pc is exchanging", pkChrCauser->GetName(), GetName());
  5389. return;
  5390. }
  5391. }
  5392.  
  5393. if (IsPC())
  5394. {
  5395. // 타겟으로 설정된 경우는 PC에 의한 클릭도 퀘스트로 처리하도록 합니다.
  5396. if (!CTargetManager::instance().GetTargetInfo(pkChrCauser->GetPlayerID(), TARGET_TYPE_VID, GetVID()))
  5397. {
  5398. // 2005.03.17.myevan.타겟이 아닌 경우는 개인 상점 처리 기능을 작동시킨다.
  5399. if (GetMyShop())
  5400. {
  5401. if (pkChrCauser->IsDead() == true) return;
  5402.  
  5403. //PREVENT_TRADE_WINDOW
  5404. if (pkChrCauser == this) // 자기는 가능
  5405. {
  5406. if ((GetExchange() || IsOpenSafebox() || GetShopOwner()) || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner())
  5407. {
  5408. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("다른 거래중(창고,교환,상점)에는 개인상점을 사용할 수 없습니다."));
  5409. return;
  5410. }
  5411. }
  5412. else // 다른 사람이 클릭했을때
  5413. {
  5414. // 클릭한 사람이 교환/창고/개인상점/상점이용중이라면 불가
  5415. if ((pkChrCauser->GetExchange() || pkChrCauser->IsOpenSafebox() || pkChrCauser->GetMyShop() || pkChrCauser->GetShopOwner()) || pkChrCauser->IsCubeOpen() || pkChrCauser->IsAcceOpen() || pkChrCauser->GetOfflineShopOwner())
  5416. {
  5417. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("다른 거래중(창고,교환,상점)에는 개인상점을 사용할 수 없습니다."));
  5418. return;
  5419. }
  5420.  
  5421. // 클릭한 대상이 교환/창고/상점이용중이라면 불가
  5422. //if ((GetExchange() || IsOpenSafebox() || GetShopOwner()))
  5423. if ((GetExchange() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner()))
  5424. {
  5425. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 다른 거래를 하고 있는 중입니다."));
  5426. return;
  5427. }
  5428. }
  5429. //END_PREVENT_TRADE_WINDOW
  5430.  
  5431. if (pkChrCauser->GetShop())
  5432. {
  5433. pkChrCauser->GetShop()->RemoveGuest(pkChrCauser);
  5434. pkChrCauser->SetShop(NULL);
  5435. }
  5436.  
  5437. GetMyShop()->AddGuest(pkChrCauser, GetVID(), false);
  5438. pkChrCauser->SetShopOwner(this);
  5439. return;
  5440. }
  5441.  
  5442. if (test_server)
  5443. sys_err("%s.OnClickFailure(%s) - target is PC", pkChrCauser->GetName(), GetName());
  5444.  
  5445. return;
  5446. }
  5447. }
  5448.  
  5449. // Offline Shop
  5450. if (IsOfflineShopNPC() && GetOfflineShop())
  5451. {
  5452. pkChrCauser->SetOfflineShopOwner(this);
  5453. GetOfflineShop()->AddGuest(pkChrCauser, this);
  5454. return;
  5455. }
  5456.  
  5457. // 청소년은 퀘스트 못함
  5458. if (LC_IsNewCIBN())
  5459. {
  5460. if (pkChrCauser->IsOverTime(OT_3HOUR))
  5461. {
  5462. sys_log(0, "Teen OverTime : name = %s, hour = %d)", pkChrCauser->GetName(), 3);
  5463. return;
  5464. }
  5465. else if (pkChrCauser->IsOverTime(OT_5HOUR))
  5466. {
  5467. sys_log(0, "Teen OverTime : name = %s, hour = %d)", pkChrCauser->GetName(), 5);
  5468. return;
  5469. }
  5470. }
  5471.  
  5472.  
  5473. pkChrCauser->SetQuestNPCID(GetVID());
  5474.  
  5475. if (quest::CQuestManager::instance().Click(pkChrCauser->GetPlayerID(), this))
  5476. {
  5477. return;
  5478. }
  5479.  
  5480.  
  5481. // NPC 전용 기능 수행 : 상점 열기 등
  5482. if (!IsPC())
  5483. {
  5484. if (!m_triggerOnClick.pFunc)
  5485. {
  5486. // NPC 트리거 시스템 로그 보기
  5487. //sys_err("%s.OnClickFailure(%s) : triggerOnClick.pFunc is EMPTY(pid=%d)",
  5488. // pkChrCauser->GetName(),
  5489. // GetName(),
  5490. // pkChrCauser->GetPlayerID());
  5491. return;
  5492. }
  5493.  
  5494. m_triggerOnClick.pFunc(this, pkChrCauser);
  5495. }
  5496.  
  5497. }
  5498.  
  5499. BYTE CHARACTER::GetGMLevel() const
  5500. {
  5501. if (test_server)
  5502. return GM_IMPLEMENTOR;
  5503. return m_pointsInstant.gm_level;
  5504. }
  5505.  
  5506. void CHARACTER::SetGMLevel()
  5507. {
  5508. if (GetDesc())
  5509. {
  5510. m_pointsInstant.gm_level = gm_get_level(GetName(), GetDesc()->GetHostName(), GetDesc()->GetAccountTable().login);
  5511. }
  5512. else
  5513. {
  5514. m_pointsInstant.gm_level = GM_PLAYER;
  5515. }
  5516. }
  5517.  
  5518. BOOL CHARACTER::IsGM() const
  5519. {
  5520. if (m_pointsInstant.gm_level != GM_PLAYER)
  5521. return true;
  5522. if (test_server)
  5523. return true;
  5524. return false;
  5525. }
  5526.  
  5527. void CHARACTER::SetStone(LPCHARACTER pkChrStone)
  5528. {
  5529. m_pkChrStone = pkChrStone;
  5530.  
  5531. if (m_pkChrStone)
  5532. {
  5533. if (pkChrStone->m_set_pkChrSpawnedBy.find(this) == pkChrStone->m_set_pkChrSpawnedBy.end())
  5534. pkChrStone->m_set_pkChrSpawnedBy.insert(this);
  5535. }
  5536. }
  5537.  
  5538. struct FuncDeadSpawnedByStone
  5539. {
  5540. void operator () (LPCHARACTER ch)
  5541. {
  5542. ch->Dead(NULL);
  5543. ch->SetStone(NULL);
  5544. }
  5545. };
  5546.  
  5547. void CHARACTER::ClearStone()
  5548. {
  5549. if (!m_set_pkChrSpawnedBy.empty())
  5550. {
  5551. // 내가 스폰시킨 몬스터들을 모두 죽인다.
  5552. FuncDeadSpawnedByStone f;
  5553. std::for_each(m_set_pkChrSpawnedBy.begin(), m_set_pkChrSpawnedBy.end(), f);
  5554. m_set_pkChrSpawnedBy.clear();
  5555. }
  5556.  
  5557. if (!m_pkChrStone)
  5558. return;
  5559.  
  5560. m_pkChrStone->m_set_pkChrSpawnedBy.erase(this);
  5561. m_pkChrStone = NULL;
  5562. }
  5563.  
  5564. void CHARACTER::ClearTarget()
  5565. {
  5566. if (m_pkChrTarget)
  5567. {
  5568. m_pkChrTarget->m_set_pkChrTargetedBy.erase(this);
  5569. m_pkChrTarget = NULL;
  5570. }
  5571.  
  5572. TPacketGCTarget p;
  5573.  
  5574. p.header = HEADER_GC_TARGET;
  5575. p.dwVID = 0;
  5576. p.bHPPercent = 0;
  5577.  
  5578. CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin();
  5579.  
  5580. while (it != m_set_pkChrTargetedBy.end())
  5581. {
  5582. LPCHARACTER pkChr = *(it++);
  5583. pkChr->m_pkChrTarget = NULL;
  5584.  
  5585. if (!pkChr->GetDesc())
  5586. {
  5587. sys_err("%s %p does not have desc", pkChr->GetName(), get_pointer(pkChr));
  5588. abort();
  5589. }
  5590.  
  5591. pkChr->GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  5592. }
  5593.  
  5594. m_set_pkChrTargetedBy.clear();
  5595. }
  5596.  
  5597. void CHARACTER::SetTarget(LPCHARACTER pkChrTarget)
  5598. {
  5599. if (m_pkChrTarget == pkChrTarget)
  5600. return;
  5601.  
  5602. // CASTLE
  5603. if (IS_CASTLE_MAP(GetMapIndex()) && !IsGM())
  5604. return;
  5605. // CASTLE
  5606.  
  5607. if (m_pkChrTarget)
  5608. m_pkChrTarget->m_set_pkChrTargetedBy.erase(this);
  5609.  
  5610. m_pkChrTarget = pkChrTarget;
  5611.  
  5612. TPacketGCTarget p;
  5613.  
  5614. p.header = HEADER_GC_TARGET;
  5615.  
  5616. if (m_pkChrTarget)
  5617. {
  5618. m_pkChrTarget->m_set_pkChrTargetedBy.insert(this);
  5619.  
  5620. p.dwVID = m_pkChrTarget->GetVID();
  5621.  
  5622. if (m_pkChrTarget->IsPC() && !m_pkChrTarget->IsPolymorphed() || m_pkChrTarget->GetMaxHP() <= 0)
  5623. p.bHPPercent = 0;
  5624. else
  5625. {
  5626. if (m_pkChrTarget->GetRaceNum() == 20101 ||
  5627. m_pkChrTarget->GetRaceNum() == 20102 ||
  5628. m_pkChrTarget->GetRaceNum() == 20103 ||
  5629. m_pkChrTarget->GetRaceNum() == 20104 ||
  5630. m_pkChrTarget->GetRaceNum() == 20105 ||
  5631. m_pkChrTarget->GetRaceNum() == 20106 ||
  5632. m_pkChrTarget->GetRaceNum() == 20107 ||
  5633. m_pkChrTarget->GetRaceNum() == 20108 ||
  5634. m_pkChrTarget->GetRaceNum() == 20109)
  5635. {
  5636. LPCHARACTER owner = m_pkChrTarget->GetVictim();
  5637.  
  5638. if (owner)
  5639. {
  5640. int iHorseHealth = owner->GetHorseHealth();
  5641. int iHorseMaxHealth = owner->GetHorseMaxHealth();
  5642.  
  5643. if (iHorseMaxHealth)
  5644. p.bHPPercent = MINMAX(0, iHorseHealth * 100 / iHorseMaxHealth, 100);
  5645. else
  5646. p.bHPPercent = 100;
  5647. }
  5648. else
  5649. p.bHPPercent = 100;
  5650. }
  5651. else
  5652. p.bHPPercent = MINMAX(0, (m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 100);
  5653. }
  5654. }
  5655. else
  5656. {
  5657. p.dwVID = 0;
  5658. p.bHPPercent = 0;
  5659. }
  5660.  
  5661. GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  5662. }
  5663.  
  5664. void CHARACTER::BroadcastTargetPacket()
  5665. {
  5666. if (m_set_pkChrTargetedBy.empty())
  5667. return;
  5668.  
  5669. TPacketGCTarget p;
  5670.  
  5671. p.header = HEADER_GC_TARGET;
  5672. p.dwVID = GetVID();
  5673.  
  5674. if (IsPC())
  5675. p.bHPPercent = 0;
  5676. else
  5677. p.bHPPercent = MINMAX(0, (GetHP() * 100) / GetMaxHP(), 100);
  5678.  
  5679. CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin();
  5680.  
  5681. while (it != m_set_pkChrTargetedBy.end())
  5682. {
  5683. LPCHARACTER pkChr = *it++;
  5684.  
  5685. if (!pkChr->GetDesc())
  5686. {
  5687. sys_err("%s %p does not have desc", pkChr->GetName(), get_pointer(pkChr));
  5688. abort();
  5689. }
  5690.  
  5691. pkChr->GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  5692. }
  5693. }
  5694.  
  5695. void CHARACTER::CheckTarget()
  5696. {
  5697. if (!m_pkChrTarget)
  5698. return;
  5699.  
  5700. if (DISTANCE_APPROX(GetX() - m_pkChrTarget->GetX(), GetY() - m_pkChrTarget->GetY()) >= 4800)
  5701. SetTarget(NULL);
  5702. }
  5703.  
  5704. void CHARACTER::SetWarpLocation(long lMapIndex, long x, long y)
  5705. {
  5706. m_posWarp.x = x * 100;
  5707. m_posWarp.y = y * 100;
  5708. m_lWarpMapIndex = lMapIndex;
  5709. }
  5710.  
  5711. void CHARACTER::SaveExitLocation()
  5712. {
  5713. m_posExit = GetXYZ();
  5714. m_lExitMapIndex = GetMapIndex();
  5715. }
  5716.  
  5717. void CHARACTER::ExitToSavedLocation()
  5718. {
  5719. sys_log (0, "ExitToSavedLocation");
  5720. WarpSet(m_posWarp.x, m_posWarp.y, m_lWarpMapIndex);
  5721.  
  5722. m_posExit.x = m_posExit.y = m_posExit.z = 0;
  5723. m_lExitMapIndex = 0;
  5724. }
  5725.  
  5726. // fixme
  5727. // 지금까진 privateMapIndex 가 현재 맵 인덱스와 같은지 체크 하는 것을 외부에서 하고,
  5728. // 다르면 warpset을 불렀는데
  5729. // 이를 warpset 안으로 넣자.
  5730. bool CHARACTER::WarpSet(long x, long y, long lPrivateMapIndex)
  5731. {
  5732. if (!IsPC())
  5733. return false;
  5734.  
  5735. long lAddr;
  5736. long lMapIndex;
  5737. WORD wPort;
  5738.  
  5739. if (!CMapLocation::instance().Get(x, y, lMapIndex, lAddr, wPort))
  5740. {
  5741. sys_err("cannot find map location index %d x %d y %d name %s", lMapIndex, x, y, GetName());
  5742. return false;
  5743. }
  5744.  
  5745. //Send Supplementary Data Block if new map requires security packages in loading this map
  5746. {
  5747. long lCurAddr;
  5748. long lCurMapIndex = 0;
  5749. WORD wCurPort;
  5750.  
  5751. CMapLocation::instance().Get(GetX(), GetY(), lCurMapIndex, lCurAddr, wCurPort);
  5752.  
  5753. //do not send SDB files if char is in the same map
  5754. if( lCurMapIndex != lMapIndex )
  5755. {
  5756. const TMapRegion * rMapRgn = SECTREE_MANAGER::instance().GetMapRegion(lMapIndex);
  5757. {
  5758. DESC_MANAGER::instance().SendClientPackageSDBToLoadMap( GetDesc(), rMapRgn->strMapName.c_str() );
  5759. }
  5760. }
  5761. }
  5762.  
  5763. if (lPrivateMapIndex >= 10000)
  5764. {
  5765. if (lPrivateMapIndex / 10000 != lMapIndex)
  5766. {
  5767. sys_err("Invalid map inedx %d, must be child of %d", lPrivateMapIndex, lMapIndex);
  5768. return false;
  5769. }
  5770.  
  5771. lMapIndex = lPrivateMapIndex;
  5772. }
  5773.  
  5774. Stop();
  5775. Save();
  5776.  
  5777. if (GetSectree())
  5778. {
  5779. GetSectree()->RemoveEntity(this);
  5780. ViewCleanup();
  5781.  
  5782. EncodeRemovePacket(this);
  5783. }
  5784.  
  5785. m_lWarpMapIndex = lMapIndex;
  5786. m_posWarp.x = x;
  5787. m_posWarp.y = y;
  5788.  
  5789. sys_log(0, "WarpSet %s %d %d current map %d target map %d", GetName(), x, y, GetMapIndex(), lMapIndex);
  5790.  
  5791. TPacketGCWarp p;
  5792.  
  5793. p.bHeader = HEADER_GC_WARP;
  5794. p.lX = x;
  5795. p.lY = y;
  5796. p.lAddr = lAddr;
  5797. p.wPort = wPort;
  5798.  
  5799. GetDesc()->Packet(&p, sizeof(TPacketGCWarp));
  5800.  
  5801. //if (!LC_IsNewCIBN())
  5802. {
  5803. char buf[256];
  5804. snprintf(buf, sizeof(buf), "%s MapIdx %ld DestMapIdx%ld DestX%ld DestY%ld Empire%d", GetName(), GetMapIndex(), lPrivateMapIndex, x, y, GetEmpire());
  5805. LogManager::instance().CharLog(this, 0, "WARP", buf);
  5806. }
  5807.  
  5808. return true;
  5809. }
  5810.  
  5811. void CHARACTER::WarpEnd()
  5812. {
  5813. if (test_server)
  5814. sys_log(0, "WarpEnd %s", GetName());
  5815.  
  5816. if (m_posWarp.x == 0 && m_posWarp.y == 0)
  5817. return;
  5818.  
  5819. int index = m_lWarpMapIndex;
  5820.  
  5821. if (index > 10000)
  5822. index /= 10000;
  5823.  
  5824. if (!map_allow_find(index))
  5825. GoHome();
  5826.  
  5827. sys_log(0, "WarpEnd %s %d %u %u", GetName(), m_lWarpMapIndex, m_posWarp.x, m_posWarp.y);
  5828.  
  5829. Show(m_lWarpMapIndex, m_posWarp.x, m_posWarp.y, 0);
  5830. Stop();
  5831.  
  5832. m_lWarpMapIndex = 0;
  5833. m_posWarp.x = m_posWarp.y = m_posWarp.z = 0;
  5834.  
  5835. {
  5836. // P2P Login
  5837. TPacketGGLogin p;
  5838.  
  5839. p.bHeader = HEADER_GG_LOGIN;
  5840. strlcpy(p.szName, GetName(), sizeof(p.szName));
  5841. p.dwPID = GetPlayerID();
  5842. p.bEmpire = GetEmpire();
  5843. p.lMapIndex = SECTREE_MANAGER::instance().GetMapIndex(GetX(), GetY());
  5844. p.bChannel = g_bChannel;
  5845.  
  5846. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGLogin));
  5847. }
  5848. }
  5849.  
  5850. bool CHARACTER::Return()
  5851. {
  5852. if (!IsNPC())
  5853. return false;
  5854.  
  5855. int x, y;
  5856. /*
  5857. float fDist = DISTANCE_SQRT(m_pkMobData->m_posLastAttacked.x - GetX(), m_pkMobData->m_posLastAttacked.y - GetY());
  5858. float fx, fy;
  5859. GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);
  5860. x = GetX() + (int) fx;
  5861. y = GetY() + (int) fy;
  5862. */
  5863. SetVictim(NULL);
  5864.  
  5865. x = m_pkMobInst->m_posLastAttacked.x;
  5866. y = m_pkMobInst->m_posLastAttacked.y;
  5867.  
  5868. SetRotationToXY(x, y);
  5869.  
  5870. if (!Goto(x, y))
  5871. return false;
  5872.  
  5873. SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
  5874.  
  5875. if (test_server)
  5876. sys_log(0, "%s %p 포기하고 돌아가자! %d %d", GetName(), this, x, y);
  5877.  
  5878. if (GetParty())
  5879. GetParty()->SendMessage(this, PM_RETURN, x, y);
  5880.  
  5881. return true;
  5882. }
  5883.  
  5884. bool CHARACTER::Follow(LPCHARACTER pkChr, float fMinDistance)
  5885. {
  5886. if (IsPC())
  5887. {
  5888. sys_err("CHARACTER::Follow : PC cannot use this method", GetName());
  5889. return false;
  5890. }
  5891.  
  5892. // TRENT_MONSTER
  5893. if (IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
  5894. {
  5895. if (pkChr->IsPC()) // 쫓아가는 상대가 PC일 때
  5896. {
  5897. // If i'm in a party. I must obey party leader's AI.
  5898. if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
  5899. {
  5900. if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000) // 마지막으로 공격받은지 15초가 지났고
  5901. {
  5902. // 마지막 맞은 곳으로 부터 50미터 이상 차이나면 포기하고 돌아간다.
  5903. if (m_pkMobData->m_table.wAttackRange < DISTANCE_APPROX(pkChr->GetX() - GetX(), pkChr->GetY() - GetY()))
  5904. if (Return())
  5905. return true;
  5906. }
  5907. }
  5908. }
  5909. return false;
  5910. }
  5911. // END_OF_TRENT_MONSTER
  5912.  
  5913. long x = pkChr->GetX();
  5914. long y = pkChr->GetY();
  5915.  
  5916. if (pkChr->IsPC()) // 쫓아가는 상대가 PC일 때
  5917. {
  5918. // If i'm in a party. I must obey party leader's AI.
  5919. if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
  5920. {
  5921. if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000) // 마지막으로 공격받은지 15초가 지났고
  5922. {
  5923. // 마지막 맞은 곳으로 부터 50미터 이상 차이나면 포기하고 돌아간다.
  5924. if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
  5925. if (Return())
  5926. return true;
  5927. }
  5928. }
  5929. }
  5930.  
  5931. if (IsGuardNPC())
  5932. {
  5933. if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
  5934. if (Return())
  5935. return true;
  5936. }
  5937. #ifdef NEW_PET_SYSTEM
  5938. if (pkChr->IsState(pkChr->m_stateMove) &&
  5939. GetMobBattleType() != BATTLE_TYPE_RANGE &&
  5940. GetMobBattleType() != BATTLE_TYPE_MAGIC &&
  5941. false == IsPet() && false == IsNewPet())
  5942. #else
  5943. if (pkChr->IsState(pkChr->m_stateMove) &&
  5944. GetMobBattleType() != BATTLE_TYPE_RANGE &&
  5945. GetMobBattleType() != BATTLE_TYPE_MAGIC &&
  5946. false == IsPet())
  5947. #endif
  5948. {
  5949. // 대상이 이동중이면 예측 이동을 한다
  5950. // 나와 상대방의 속도차와 거리로부터 만날 시간을 예상한 후
  5951. // 상대방이 그 시간까지 직선으로 이동한다고 가정하여 거기로 이동한다.
  5952. float rot = pkChr->GetRotation();
  5953. float rot_delta = GetDegreeDelta(rot, GetDegreeFromPositionXY(GetX(), GetY(), pkChr->GetX(), pkChr->GetY()));
  5954.  
  5955. float yourSpeed = pkChr->GetMoveSpeed();
  5956. float mySpeed = GetMoveSpeed();
  5957.  
  5958. float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());
  5959. float fFollowSpeed = mySpeed - yourSpeed * cos(rot_delta * M_PI / 180);
  5960.  
  5961. if (fFollowSpeed >= 0.1f)
  5962. {
  5963. float fMeetTime = fDist / fFollowSpeed;
  5964. float fYourMoveEstimateX, fYourMoveEstimateY;
  5965.  
  5966. if( fMeetTime * yourSpeed <= 100000.0f )
  5967. {
  5968. GetDeltaByDegree(pkChr->GetRotation(), fMeetTime * yourSpeed, &fYourMoveEstimateX, &fYourMoveEstimateY);
  5969.  
  5970. x += (long) fYourMoveEstimateX;
  5971. y += (long) fYourMoveEstimateY;
  5972.  
  5973. float fDistNew = sqrt(((double)x - GetX())*(x-GetX())+((double)y - GetY())*(y-GetY()));
  5974. if (fDist < fDistNew)
  5975. {
  5976. x = (long)(GetX() + (x - GetX()) * fDist / fDistNew);
  5977. y = (long)(GetY() + (y - GetY()) * fDist / fDistNew);
  5978. }
  5979. }
  5980. }
  5981. }
  5982.  
  5983. // 가려는 위치를 바라봐야 한다.
  5984. SetRotationToXY(x, y);
  5985.  
  5986. float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());
  5987.  
  5988. if (fDist <= fMinDistance)
  5989. return false;
  5990.  
  5991. float fx, fy;
  5992.  
  5993. if (IsChangeAttackPosition(pkChr) && GetMobRank() < MOB_RANK_BOSS)
  5994. {
  5995. // 상대방 주변 랜덤한 곳으로 이동
  5996. SetChangeAttackPositionTime();
  5997.  
  5998. int retry = 16;
  5999. int dx, dy;
  6000. int rot = (int) GetDegreeFromPositionXY(x, y, GetX(), GetY());
  6001.  
  6002. while (--retry)
  6003. {
  6004. if (fDist < 500.0f)
  6005. GetDeltaByDegree((rot + number(-90, 90) + number(-90, 90)) % 360, fMinDistance, &fx, &fy);
  6006. else
  6007. GetDeltaByDegree(number(0, 359), fMinDistance, &fx, &fy);
  6008.  
  6009. dx = x + (int) fx;
  6010. dy = y + (int) fy;
  6011.  
  6012. LPSECTREE tree = SECTREE_MANAGER::instance().Get(GetMapIndex(), dx, dy);
  6013.  
  6014. if (NULL == tree)
  6015. break;
  6016.  
  6017. if (0 == (tree->GetAttribute(dx, dy) & (ATTR_BLOCK | ATTR_OBJECT)))
  6018. break;
  6019. }
  6020.  
  6021. //sys_log(0, "근처 어딘가로 이동 %s retry %d", GetName(), retry);
  6022. if (!Goto(dx, dy))
  6023. return false;
  6024. }
  6025. else
  6026. {
  6027. // 직선 따라가기
  6028. float fDistToGo = fDist - fMinDistance;
  6029. GetDeltaByDegree(GetRotation(), fDistToGo, &fx, &fy);
  6030.  
  6031. //sys_log(0, "직선으로 이동 %s", GetName());
  6032. if (!Goto(GetX() + (int) fx, GetY() + (int) fy))
  6033. return false;
  6034. }
  6035.  
  6036. SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
  6037. //MonsterLog("쫓아가기; %s", pkChr->GetName());
  6038. return true;
  6039. }
  6040.  
  6041. float CHARACTER::GetDistanceFromSafeboxOpen() const
  6042. {
  6043. return DISTANCE_APPROX(GetX() - m_posSafeboxOpen.x, GetY() - m_posSafeboxOpen.y);
  6044. }
  6045.  
  6046. void CHARACTER::SetSafeboxOpenPosition()
  6047. {
  6048. m_posSafeboxOpen = GetXYZ();
  6049. }
  6050.  
  6051. CSafebox * CHARACTER::GetSafebox() const
  6052. {
  6053. return m_pkSafebox;
  6054. }
  6055.  
  6056. void CHARACTER::ReqSafeboxLoad(const char* pszPassword)
  6057. {
  6058. if (!*pszPassword || strlen(pszPassword) > SAFEBOX_PASSWORD_MAX_LEN)
  6059. {
  6060. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<창고> 잘못된 암호를 입력하셨습니다."));
  6061. return;
  6062. }
  6063. else if (m_pkSafebox)
  6064. {
  6065. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<창고> 창고가 이미 열려있습니다."));
  6066. return;
  6067. }
  6068.  
  6069. int iPulse = thecore_pulse();
  6070.  
  6071. if (iPulse - GetSafeboxLoadTime() < PASSES_PER_SEC(10))
  6072. {
  6073. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<창고> 창고를 닫은지 10초 안에는 열 수 없습니다."));
  6074. return;
  6075. }
  6076. else if (GetDistanceFromSafeboxOpen() > 1000)
  6077. {
  6078. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<창고> 거리가 멀어서 창고를 열 수 없습니다."));
  6079. return;
  6080. }
  6081. else if (m_bOpeningSafebox)
  6082. {
  6083. sys_log(0, "Overlapped safebox load request from %s", GetName());
  6084. return;
  6085. }
  6086.  
  6087. SetSafeboxLoadTime();
  6088. m_bOpeningSafebox = true;
  6089.  
  6090. TSafeboxLoadPacket p;
  6091. p.dwID = GetDesc()->GetAccountTable().id;
  6092. strlcpy(p.szLogin, GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
  6093. strlcpy(p.szPassword, pszPassword, sizeof(p.szPassword));
  6094.  
  6095. db_clientdesc->DBPacket(HEADER_GD_SAFEBOX_LOAD, GetDesc()->GetHandle(), &p, sizeof(p));
  6096. }
  6097.  
  6098. void CHARACTER::LoadSafebox(int iSize, DWORD dwGold, int iItemCount, TPlayerItem * pItems)
  6099. {
  6100. bool bLoaded = false;
  6101.  
  6102. //PREVENT_TRADE_WINDOW
  6103. SetOpenSafebox(true);
  6104. //END_PREVENT_TRADE_WINDOW
  6105.  
  6106. if (m_pkSafebox)
  6107. bLoaded = true;
  6108.  
  6109. if (!m_pkSafebox)
  6110. m_pkSafebox = M2_NEW CSafebox(this, iSize, dwGold);
  6111. else
  6112. m_pkSafebox->ChangeSize(iSize);
  6113.  
  6114. m_iSafeboxSize = iSize;
  6115.  
  6116. TPacketCGSafeboxSize p;
  6117.  
  6118. p.bHeader = HEADER_GC_SAFEBOX_SIZE;
  6119. p.bSize = iSize;
  6120.  
  6121. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  6122.  
  6123. if (!bLoaded)
  6124. {
  6125. for (int i = 0; i < iItemCount; ++i, ++pItems)
  6126. {
  6127. if (!m_pkSafebox->IsValidPosition(pItems->pos))
  6128. continue;
  6129.  
  6130. LPITEM item = ITEM_MANAGER::instance().CreateItem(pItems->vnum, pItems->count, pItems->id);
  6131.  
  6132. if (!item)
  6133. {
  6134. sys_err("cannot create item vnum %d id %u (name: %s)", pItems->vnum, pItems->id, GetName());
  6135. continue;
  6136. }
  6137.  
  6138. item->SetSkipSave(true);
  6139. item->SetSockets(pItems->alSockets);
  6140. item->SetAttributes(pItems->aAttr);
  6141.  
  6142. if (!m_pkSafebox->Add(pItems->pos, item))
  6143. {
  6144. M2_DESTROY_ITEM(item);
  6145. }
  6146. else
  6147. item->SetSkipSave(false);
  6148. }
  6149. }
  6150. }
  6151.  
  6152. void CHARACTER::ChangeSafeboxSize(BYTE bSize)
  6153. {
  6154. //if (!m_pkSafebox)
  6155. //return;
  6156.  
  6157. TPacketCGSafeboxSize p;
  6158.  
  6159. p.bHeader = HEADER_GC_SAFEBOX_SIZE;
  6160. p.bSize = bSize;
  6161.  
  6162. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  6163.  
  6164. if (m_pkSafebox)
  6165. m_pkSafebox->ChangeSize(bSize);
  6166.  
  6167. m_iSafeboxSize = bSize;
  6168. }
  6169.  
  6170. void CHARACTER::CloseSafebox()
  6171. {
  6172. if (!m_pkSafebox)
  6173. return;
  6174.  
  6175. //PREVENT_TRADE_WINDOW
  6176. SetOpenSafebox(false);
  6177. //END_PREVENT_TRADE_WINDOW
  6178.  
  6179. m_pkSafebox->Save();
  6180.  
  6181. M2_DELETE(m_pkSafebox);
  6182. m_pkSafebox = NULL;
  6183.  
  6184. ChatPacket(CHAT_TYPE_COMMAND, "CloseSafebox");
  6185.  
  6186. SetSafeboxLoadTime();
  6187. m_bOpeningSafebox = false;
  6188.  
  6189. Save();
  6190. }
  6191.  
  6192. CSafebox * CHARACTER::GetMall() const
  6193. {
  6194. return m_pkMall;
  6195. }
  6196.  
  6197. void CHARACTER::LoadMall(int iItemCount, TPlayerItem * pItems)
  6198. {
  6199. bool bLoaded = false;
  6200.  
  6201. if (m_pkMall)
  6202. bLoaded = true;
  6203.  
  6204. if (!m_pkMall)
  6205. m_pkMall = M2_NEW CSafebox(this, 3 * SAFEBOX_PAGE_SIZE, 0);
  6206. else
  6207. m_pkMall->ChangeSize(3 * SAFEBOX_PAGE_SIZE);
  6208.  
  6209. m_pkMall->SetWindowMode(MALL);
  6210.  
  6211. TPacketCGSafeboxSize p;
  6212.  
  6213. p.bHeader = HEADER_GC_MALL_OPEN;
  6214. p.bSize = 3 * SAFEBOX_PAGE_SIZE;
  6215.  
  6216. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  6217.  
  6218. if (!bLoaded)
  6219. {
  6220. for (int i = 0; i < iItemCount; ++i, ++pItems)
  6221. {
  6222. if (!m_pkMall->IsValidPosition(pItems->pos))
  6223. continue;
  6224.  
  6225. LPITEM item = ITEM_MANAGER::instance().CreateItem(pItems->vnum, pItems->count, pItems->id);
  6226.  
  6227. if (!item)
  6228. {
  6229. sys_err("cannot create item vnum %d id %u (name: %s)", pItems->vnum, pItems->id, GetName());
  6230. continue;
  6231. }
  6232.  
  6233. item->SetSkipSave(true);
  6234. item->SetSockets(pItems->alSockets);
  6235. item->SetAttributes(pItems->aAttr);
  6236.  
  6237. if (!m_pkMall->Add(pItems->pos, item))
  6238. M2_DESTROY_ITEM(item);
  6239. else
  6240. item->SetSkipSave(false);
  6241. }
  6242. }
  6243. }
  6244.  
  6245. void CHARACTER::CloseMall()
  6246. {
  6247. if (!m_pkMall)
  6248. return;
  6249.  
  6250. m_pkMall->Save();
  6251.  
  6252. M2_DELETE(m_pkMall);
  6253. m_pkMall = NULL;
  6254.  
  6255. ChatPacket(CHAT_TYPE_COMMAND, "CloseMall");
  6256. }
  6257.  
  6258. bool CHARACTER::BuildUpdatePartyPacket(TPacketGCPartyUpdate & out)
  6259. {
  6260. if (!GetParty())
  6261. return false;
  6262.  
  6263. memset(&out, 0, sizeof(out));
  6264.  
  6265. out.header = HEADER_GC_PARTY_UPDATE;
  6266. out.pid = GetPlayerID();
  6267. out.percent_hp = MINMAX(0, GetHP() * 100 / GetMaxHP(), 100);
  6268. out.role = GetParty()->GetRole(GetPlayerID());
  6269.  
  6270. sys_log(1, "PARTY %s role is %d", GetName(), out.role);
  6271.  
  6272. LPCHARACTER l = GetParty()->GetLeaderCharacter();
  6273.  
  6274. if (l && DISTANCE_APPROX(GetX() - l->GetX(), GetY() - l->GetY()) < PARTY_DEFAULT_RANGE)
  6275. {
  6276. if (g_iUseLocale)
  6277. out.affects[0] = GetParty()->GetPartyBonusExpPercent();
  6278. else
  6279. out.affects[0] = GetParty()->GetExpBonusPercent();
  6280. out.affects[1] = GetPoint(POINT_PARTY_ATTACKER_BONUS);
  6281. out.affects[2] = GetPoint(POINT_PARTY_TANKER_BONUS);
  6282. out.affects[3] = GetPoint(POINT_PARTY_BUFFER_BONUS);
  6283. out.affects[4] = GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  6284. out.affects[5] = GetPoint(POINT_PARTY_HASTE_BONUS);
  6285. out.affects[6] = GetPoint(POINT_PARTY_DEFENDER_BONUS);
  6286. }
  6287.  
  6288. return true;
  6289. }
  6290.  
  6291. int CHARACTER::GetLeadershipSkillLevel() const
  6292. {
  6293. return GetSkillLevel(SKILL_LEADERSHIP);
  6294. }
  6295.  
  6296. void CHARACTER::QuerySafeboxSize()
  6297. {
  6298. if (m_iSafeboxSize == -1)
  6299. {
  6300. DBManager::instance().ReturnQuery(QID_SAFEBOX_SIZE,
  6301. GetPlayerID(),
  6302. NULL,
  6303. "SELECT size FROM safebox%s WHERE account_id = %u",
  6304. get_table_postfix(),
  6305. GetDesc()->GetAccountTable().id);
  6306. }
  6307. }
  6308.  
  6309. void CHARACTER::SetSafeboxSize(int iSize)
  6310. {
  6311. sys_log(1, "SetSafeboxSize: %s %d", GetName(), iSize);
  6312. m_iSafeboxSize = iSize;
  6313. DBManager::instance().Query("UPDATE safebox%s SET size = %d WHERE account_id = %u", get_table_postfix(), iSize / SAFEBOX_PAGE_SIZE, GetDesc()->GetAccountTable().id);
  6314. }
  6315.  
  6316. int CHARACTER::GetSafeboxSize() const
  6317. {
  6318. return m_iSafeboxSize;
  6319. }
  6320.  
  6321. void CHARACTER::SetNowWalking(bool bWalkFlag)
  6322. {
  6323. //if (m_bNowWalking != bWalkFlag || IsNPC())
  6324. if (m_bNowWalking != bWalkFlag)
  6325. {
  6326. if (bWalkFlag)
  6327. {
  6328. m_bNowWalking = true;
  6329. m_dwWalkStartTime = get_dword_time();
  6330. }
  6331. else
  6332. {
  6333. m_bNowWalking = false;
  6334. }
  6335.  
  6336. //if (m_bNowWalking)
  6337. {
  6338. TPacketGCWalkMode p;
  6339. p.vid = GetVID();
  6340. p.header = HEADER_GC_WALK_MODE;
  6341. p.mode = m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  6342.  
  6343. PacketView(&p, sizeof(p));
  6344. }
  6345.  
  6346. if (IsNPC())
  6347. {
  6348. if (m_bNowWalking)
  6349. MonsterLog("걷는다");
  6350. else
  6351. MonsterLog("뛴다");
  6352. }
  6353.  
  6354. //sys_log(0, "%s is now %s", GetName(), m_bNowWalking?"walking.":"running.");
  6355. }
  6356. }
  6357.  
  6358. void CHARACTER::StartStaminaConsume()
  6359. {
  6360. if (m_bStaminaConsume)
  6361. return;
  6362. PointChange(POINT_STAMINA, 0);
  6363. m_bStaminaConsume = true;
  6364. //ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec, GetStamina());
  6365. if (IsStaminaHalfConsume())
  6366. ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec / 2, GetStamina());
  6367. else
  6368. ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec, GetStamina());
  6369. }
  6370.  
  6371. void CHARACTER::StopStaminaConsume()
  6372. {
  6373. if (!m_bStaminaConsume)
  6374. return;
  6375. PointChange(POINT_STAMINA, 0);
  6376. m_bStaminaConsume = false;
  6377. ChatPacket(CHAT_TYPE_COMMAND, "StopStaminaConsume %d", GetStamina());
  6378. }
  6379.  
  6380. bool CHARACTER::IsStaminaConsume() const
  6381. {
  6382. return m_bStaminaConsume;
  6383. }
  6384.  
  6385. bool CHARACTER::IsStaminaHalfConsume() const
  6386. {
  6387. return IsEquipUniqueItem(UNIQUE_ITEM_HALF_STAMINA);
  6388. }
  6389.  
  6390. void CHARACTER::ResetStopTime()
  6391. {
  6392. m_dwStopTime = get_dword_time();
  6393. }
  6394.  
  6395. DWORD CHARACTER::GetStopTime() const
  6396. {
  6397. return m_dwStopTime;
  6398. }
  6399.  
  6400. void CHARACTER::ResetPoint(int iLv)
  6401. {
  6402. BYTE bJob = GetJob();
  6403.  
  6404. PointChange(POINT_LEVEL, iLv - GetLevel());
  6405.  
  6406. SetRealPoint(POINT_ST, JobInitialPoints[bJob].st);
  6407. SetPoint(POINT_ST, GetRealPoint(POINT_ST));
  6408.  
  6409. SetRealPoint(POINT_HT, JobInitialPoints[bJob].ht);
  6410. SetPoint(POINT_HT, GetRealPoint(POINT_HT));
  6411.  
  6412. SetRealPoint(POINT_DX, JobInitialPoints[bJob].dx);
  6413. SetPoint(POINT_DX, GetRealPoint(POINT_DX));
  6414.  
  6415. SetRealPoint(POINT_IQ, JobInitialPoints[bJob].iq);
  6416. SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
  6417.  
  6418. SetRandomHP((iLv - 1) * number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end));
  6419. SetRandomSP((iLv - 1) * number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end));
  6420.  
  6421. //PointChange(POINT_STAT, ((MINMAX(1, iLv, 99) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
  6422. PointChange(POINT_STAT, ((MINMAX(1, iLv, 106) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
  6423.  
  6424. ComputePoints();
  6425.  
  6426. // 회복
  6427. PointChange(POINT_HP, GetMaxHP() - GetHP());
  6428. PointChange(POINT_SP, GetMaxSP() - GetSP());
  6429.  
  6430. PointsPacket();
  6431.  
  6432. LogManager::instance().CharLog(this, 0, "RESET_POINT", "");
  6433. }
  6434.  
  6435. bool CHARACTER::IsChangeAttackPosition(LPCHARACTER target) const
  6436. {
  6437. if (!IsNPC())
  6438. return true;
  6439.  
  6440. DWORD dwChangeTime = AI_CHANGE_ATTACK_POISITION_TIME_NEAR;
  6441.  
  6442. if (DISTANCE_APPROX(GetX() - target->GetX(), GetY() - target->GetY()) >
  6443. AI_CHANGE_ATTACK_POISITION_DISTANCE + GetMobAttackRange())
  6444. dwChangeTime = AI_CHANGE_ATTACK_POISITION_TIME_FAR;
  6445.  
  6446. return get_dword_time() - m_dwLastChangeAttackPositionTime > dwChangeTime;
  6447. }
  6448.  
  6449. void CHARACTER::GiveRandomSkillBook()
  6450. {
  6451. LPITEM item = AutoGiveItem(50300);
  6452. if (NULL != item)
  6453. {
  6454. BYTE bJob = 0;
  6455. if (!number(0, 1))
  6456. bJob = GetJob() + 1;
  6457.  
  6458. DWORD dwSkillVnum = 0;
  6459. do
  6460. {
  6461. if (number(1, 3) == 2)
  6462. {
  6463. dwSkillVnum = number(170, 175);
  6464. }
  6465. else
  6466. {
  6467. dwSkillVnum = number(1, 111);
  6468. }
  6469. const CSkillProto* pkSk = CSkillManager::instance().Get(dwSkillVnum);
  6470.  
  6471. if (NULL == pkSk)
  6472. continue;
  6473.  
  6474. if (bJob && bJob != pkSk->dwType)
  6475. continue;
  6476.  
  6477. break;
  6478. } while (true);
  6479.  
  6480. item->SetSocket(0, dwSkillVnum);
  6481. }
  6482. }
  6483.  
  6484. void CHARACTER::ReviveInvisible(int iDur)
  6485. {
  6486. AddAffect(AFFECT_REVIVE_INVISIBLE, POINT_NONE, 0, AFF_REVIVE_INVISIBLE, iDur, 0, true);
  6487. }
  6488.  
  6489. void CHARACTER::ToggleMonsterLog()
  6490. {
  6491. m_bMonsterLog = !m_bMonsterLog;
  6492.  
  6493. if (m_bMonsterLog)
  6494. {
  6495. CHARACTER_MANAGER::instance().RegisterForMonsterLog(this);
  6496. }
  6497. else
  6498. {
  6499. CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
  6500. }
  6501. }
  6502.  
  6503. void CHARACTER::SetGuild(CGuild* pGuild)
  6504. {
  6505. if (m_pGuild != pGuild)
  6506. {
  6507. m_pGuild = pGuild;
  6508. UpdatePacket();
  6509. }
  6510. }
  6511.  
  6512. void CHARACTER::SendGreetMessage()
  6513. {
  6514. typeof(DBManager::instance().GetGreetMessage()) v = DBManager::instance().GetGreetMessage();
  6515.  
  6516. for (itertype(v) it = v.begin(); it != v.end(); ++it)
  6517. {
  6518. ChatPacket(CHAT_TYPE_NOTICE, it->c_str());
  6519. }
  6520. }
  6521.  
  6522. void CHARACTER::BeginStateEmpty()
  6523. {
  6524. MonsterLog("!");
  6525. }
  6526.  
  6527. void CHARACTER::EffectPacket(int enumEffectType)
  6528. {
  6529. TPacketGCSpecialEffect p;
  6530.  
  6531. p.header = HEADER_GC_SEPCIAL_EFFECT;
  6532. p.type = enumEffectType;
  6533. p.vid = GetVID();
  6534.  
  6535. PacketAround(&p, sizeof(TPacketGCSpecialEffect));
  6536. }
  6537.  
  6538. void CHARACTER::SpecificEffectPacket(const char filename[MAX_EFFECT_FILE_NAME])
  6539. {
  6540. TPacketGCSpecificEffect p;
  6541.  
  6542. p.header = HEADER_GC_SPECIFIC_EFFECT;
  6543. p.vid = GetVID();
  6544. memcpy (p.effect_file, filename, MAX_EFFECT_FILE_NAME);
  6545.  
  6546. PacketAround(&p, sizeof(TPacketGCSpecificEffect));
  6547. }
  6548.  
  6549. void CHARACTER::MonsterChat(BYTE bMonsterChatType)
  6550. {
  6551. if (IsPC())
  6552. return;
  6553.  
  6554. char sbuf[256+1];
  6555.  
  6556. if (IsMonster())
  6557. {
  6558. if (number(0, 60))
  6559. return;
  6560.  
  6561. snprintf(sbuf, sizeof(sbuf),
  6562. "(locale.monster_chat[%i] and locale.monster_chat[%i][%d] or '')",
  6563. GetRaceNum(), GetRaceNum(), bMonsterChatType*3 + number(1, 3));
  6564. }
  6565. else
  6566. {
  6567. if (bMonsterChatType != MONSTER_CHAT_WAIT)
  6568. return;
  6569.  
  6570. if (IsGuardNPC())
  6571. {
  6572. if (number(0, 6))
  6573. return;
  6574. }
  6575. else
  6576. {
  6577. if (number(0, 30))
  6578. return;
  6579. }
  6580.  
  6581. snprintf(sbuf, sizeof(sbuf), "(locale.monster_chat[%i] and locale.monster_chat[%i][number(1, table.getn(locale.monster_chat[%i]))] or '')", GetRaceNum(), GetRaceNum(), GetRaceNum());
  6582. }
  6583.  
  6584. std::string text = quest::ScriptToString(sbuf);
  6585.  
  6586. if (text.empty())
  6587. return;
  6588.  
  6589. struct packet_chat pack_chat;
  6590.  
  6591. pack_chat.header = HEADER_GC_CHAT;
  6592. pack_chat.size = sizeof(struct packet_chat) + text.size() + 1;
  6593. pack_chat.type = CHAT_TYPE_TALKING;
  6594. pack_chat.id = GetVID();
  6595. pack_chat.bEmpire = 0;
  6596.  
  6597. TEMP_BUFFER buf;
  6598. buf.write(&pack_chat, sizeof(struct packet_chat));
  6599. buf.write(text.c_str(), text.size() + 1);
  6600.  
  6601. PacketAround(buf.read_peek(), buf.size());
  6602. }
  6603.  
  6604. void CHARACTER::SetQuestNPCID(DWORD vid)
  6605. {
  6606. m_dwQuestNPCVID = vid;
  6607. }
  6608.  
  6609. LPCHARACTER CHARACTER::GetQuestNPC() const
  6610. {
  6611. return CHARACTER_MANAGER::instance().Find(m_dwQuestNPCVID);
  6612. }
  6613.  
  6614. void CHARACTER::SetQuestItemPtr(LPITEM item)
  6615. {
  6616. m_pQuestItem = item;
  6617. }
  6618.  
  6619. void CHARACTER::ClearQuestItemPtr()
  6620. {
  6621. m_pQuestItem = NULL;
  6622. }
  6623.  
  6624. LPITEM CHARACTER::GetQuestItemPtr() const
  6625. {
  6626. return m_pQuestItem;
  6627. }
  6628.  
  6629. LPDUNGEON CHARACTER::GetDungeonForce() const
  6630. {
  6631. if (m_lWarpMapIndex > 10000)
  6632. return CDungeonManager::instance().FindByMapIndex(m_lWarpMapIndex);
  6633.  
  6634. return m_pkDungeon;
  6635. }
  6636.  
  6637. void CHARACTER::SetBlockMode(BYTE bFlag)
  6638. {
  6639. m_pointsInstant.bBlockMode = bFlag;
  6640.  
  6641. ChatPacket(CHAT_TYPE_COMMAND, "setblockmode %d", m_pointsInstant.bBlockMode);
  6642.  
  6643. SetQuestFlag("game_option.block_exchange", bFlag & BLOCK_EXCHANGE ? 1 : 0);
  6644. SetQuestFlag("game_option.block_party_invite", bFlag & BLOCK_PARTY_INVITE ? 1 : 0);
  6645. SetQuestFlag("game_option.block_guild_invite", bFlag & BLOCK_GUILD_INVITE ? 1 : 0);
  6646. SetQuestFlag("game_option.block_whisper", bFlag & BLOCK_WHISPER ? 1 : 0);
  6647. SetQuestFlag("game_option.block_messenger_invite", bFlag & BLOCK_MESSENGER_INVITE ? 1 : 0);
  6648. SetQuestFlag("game_option.block_party_request", bFlag & BLOCK_PARTY_REQUEST ? 1 : 0);
  6649. }
  6650.  
  6651. void CHARACTER::SetBlockModeForce(BYTE bFlag)
  6652. {
  6653. m_pointsInstant.bBlockMode = bFlag;
  6654. ChatPacket(CHAT_TYPE_COMMAND, "setblockmode %d", m_pointsInstant.bBlockMode);
  6655. }
  6656.  
  6657. bool CHARACTER::IsGuardNPC() const
  6658. {
  6659. return IsNPC() && (GetRaceNum() == 11000 || GetRaceNum() == 11002 || GetRaceNum() == 11004);
  6660. }
  6661.  
  6662. int CHARACTER::GetPolymorphPower() const
  6663. {
  6664. if (test_server)
  6665. {
  6666. int value = quest::CQuestManager::instance().GetEventFlag("poly");
  6667. if (value)
  6668. return value;
  6669. }
  6670. return aiPolymorphPowerByLevel[MINMAX(0, GetSkillLevel(SKILL_POLYMORPH), 40)];
  6671. }
  6672.  
  6673. void CHARACTER::SetPolymorph(DWORD dwRaceNum, bool bMaintainStat)
  6674. {
  6675. if (dwRaceNum < JOB_MAX_NUM)
  6676. {
  6677. dwRaceNum = 0;
  6678. bMaintainStat = false;
  6679. }
  6680.  
  6681. if (m_dwPolymorphRace == dwRaceNum)
  6682. return;
  6683.  
  6684. m_bPolyMaintainStat = bMaintainStat;
  6685. m_dwPolymorphRace = dwRaceNum;
  6686.  
  6687. sys_log(0, "POLYMORPH: %s race %u ", GetName(), dwRaceNum);
  6688.  
  6689. if (dwRaceNum != 0)
  6690. StopRiding();
  6691.  
  6692. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  6693. m_afAffectFlag.Set(AFF_SPAWN);
  6694.  
  6695. ViewReencode();
  6696.  
  6697. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  6698.  
  6699. if (!bMaintainStat)
  6700. {
  6701. PointChange(POINT_ST, 0);
  6702. PointChange(POINT_DX, 0);
  6703. PointChange(POINT_IQ, 0);
  6704. PointChange(POINT_HT, 0);
  6705. }
  6706.  
  6707. // 폴리모프 상태에서 죽는 경우, 폴리모프가 풀리게 되는데
  6708. // 폴리 모프 전후로 valid combo interval이 다르기 때문에
  6709. // Combo 핵 또는 Hacker로 인식하는 경우가 있다.
  6710. // 따라서 폴리모프를 풀거나 폴리모프 하게 되면,
  6711. // valid combo interval을 reset한다.
  6712. SetValidComboInterval(0);
  6713. SetComboSequence(0);
  6714.  
  6715. ComputeBattlePoints();
  6716. }
  6717.  
  6718. int CHARACTER::GetQuestFlag(const std::string& flag) const
  6719. {
  6720. quest::CQuestManager& q = quest::CQuestManager::instance();
  6721. quest::PC* pPC = q.GetPC(GetPlayerID());
  6722. return pPC->GetFlag(flag);
  6723. }
  6724.  
  6725. void CHARACTER::SetQuestFlag(const std::string& flag, int value)
  6726. {
  6727. quest::CQuestManager& q = quest::CQuestManager::instance();
  6728. quest::PC* pPC = q.GetPC(GetPlayerID());
  6729. pPC->SetFlag(flag, value);
  6730. }
  6731.  
  6732. void CHARACTER::DetermineDropMetinStone()
  6733. {
  6734. const int METIN_STONE_NUM = 14;
  6735. static DWORD c_adwMetin[METIN_STONE_NUM] =
  6736. {
  6737. 28030,
  6738. 28031,
  6739. 28032,
  6740. 28033,
  6741. 28034,
  6742. 28035,
  6743. 28036,
  6744. 28037,
  6745. 28038,
  6746. 28039,
  6747. 28040,
  6748. 28041,
  6749. 28042,
  6750. 28043,
  6751. };
  6752. DWORD stone_num = GetRaceNum();
  6753. int idx = std::lower_bound(aStoneDrop, aStoneDrop+STONE_INFO_MAX_NUM, stone_num) - aStoneDrop;
  6754. if (idx >= STONE_INFO_MAX_NUM || aStoneDrop[idx].dwMobVnum != stone_num)
  6755. {
  6756. m_dwDropMetinStone = 0;
  6757. }
  6758. else
  6759. {
  6760. const SStoneDropInfo & info = aStoneDrop[idx];
  6761. m_bDropMetinStonePct = info.iDropPct;
  6762. {
  6763. m_dwDropMetinStone = c_adwMetin[number(0, METIN_STONE_NUM - 1)];
  6764. int iGradePct = number(1, 100);
  6765. for (int iStoneLevel = 0; iStoneLevel < STONE_LEVEL_MAX_NUM; iStoneLevel ++)
  6766. {
  6767. int iLevelGradePortion = info.iLevelPct[iStoneLevel];
  6768. if (iGradePct <= iLevelGradePortion)
  6769. {
  6770. break;
  6771. }
  6772. else
  6773. {
  6774. iGradePct -= iLevelGradePortion;
  6775. m_dwDropMetinStone += 100; // 돌 +a -> +(a+1)이 될때마다 100씩 증가
  6776. }
  6777. }
  6778. }
  6779. }
  6780. }
  6781.  
  6782. void CHARACTER::SendEquipment(LPCHARACTER ch)
  6783. {
  6784. TPacketViewEquip p;
  6785. p.header = HEADER_GC_VIEW_EQUIP;
  6786. p.vid = GetVID();
  6787. int pos[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 19, 20, 21, 22, 23 };
  6788. for (int i = 0; i < 16; i++)
  6789. {
  6790. LPITEM item = GetWear(pos[i]);
  6791. if (item)
  6792. {
  6793. p.equips[i].vnum = item->GetVnum();
  6794. p.equips[i].count = item->GetCount();
  6795.  
  6796. thecore_memcpy(p.equips[i].alSockets, item->GetSockets(), sizeof(p.equips[i].alSockets));
  6797. thecore_memcpy(p.equips[i].aAttr, item->GetAttributes(), sizeof(p.equips[i].aAttr));
  6798. }
  6799. else
  6800. {
  6801. p.equips[i].vnum = 0;
  6802. }
  6803. }
  6804. ch->GetDesc()->Packet(&p, sizeof(p));
  6805. }
  6806.  
  6807. bool CHARACTER::CanSummon(int iLeaderShip)
  6808. {
  6809. return (iLeaderShip >= 20 || iLeaderShip >= 12 && m_dwLastDeadTime + 180 > get_dword_time());
  6810. }
  6811.  
  6812.  
  6813. void CHARACTER::MountVnum(DWORD vnum)
  6814. {
  6815. if (m_dwMountVnum == vnum)
  6816. return;
  6817.  
  6818. m_dwMountVnum = vnum;
  6819. m_dwMountTime = get_dword_time();
  6820.  
  6821. if (m_bIsObserver)
  6822. return;
  6823.  
  6824. //NOTE : Mount한다고 해서 Client Side의 객체를 삭제하진 않는다.
  6825. //그리고 서버Side에서 탔을때 위치 이동은 하지 않는다. 왜냐하면 Client Side에서 Coliision Adjust를 할수 있는데
  6826. //객체를 소멸시켰다가 서버위치로 이동시키면 이때 collision check를 하지는 않으므로 배경에 끼거나 뚫고 나가는 문제가 존재한다.
  6827. m_posDest.x = m_posStart.x = GetX();
  6828. m_posDest.y = m_posStart.y = GetY();
  6829. //EncodeRemovePacket(this);
  6830. EncodeInsertPacket(this);
  6831.  
  6832. ENTITY_MAP::iterator it = m_map_view.begin();
  6833.  
  6834. while (it != m_map_view.end())
  6835. {
  6836. LPENTITY entity = (it++)->first;
  6837.  
  6838. //Mount한다고 해서 Client Side의 객체를 삭제하진 않는다.
  6839. //EncodeRemovePacket(entity);
  6840. //if (!m_bIsObserver)
  6841. EncodeInsertPacket(entity);
  6842.  
  6843. //if (!entity->IsObserverMode())
  6844. // entity->EncodeInsertPacket(this);
  6845. }
  6846.  
  6847. SetValidComboInterval(0);
  6848. SetComboSequence(0);
  6849.  
  6850. ComputePoints();
  6851. }
  6852.  
  6853. namespace {
  6854. class FuncCheckWarp
  6855. {
  6856. public:
  6857. FuncCheckWarp(LPCHARACTER pkWarp)
  6858. {
  6859. m_lTargetY = 0;
  6860. m_lTargetX = 0;
  6861.  
  6862. m_lX = pkWarp->GetX();
  6863. m_lY = pkWarp->GetY();
  6864.  
  6865. m_bInvalid = false;
  6866. m_bEmpire = pkWarp->GetEmpire();
  6867.  
  6868. char szTmp[64];
  6869.  
  6870. if (3 != sscanf(pkWarp->GetName(), " %s %ld %ld ", szTmp, &m_lTargetX, &m_lTargetY))
  6871. {
  6872. if (number(1, 100) < 5)
  6873. //sys_err("Warp NPC name wrong : vnum(%d) name(%s)", pkWarp->GetRaceNum(), pkWarp->GetName());
  6874.  
  6875. m_bInvalid = true;
  6876.  
  6877. return;
  6878. }
  6879.  
  6880. m_lTargetX *= 100;
  6881. m_lTargetY *= 100;
  6882.  
  6883. m_bUseWarp = true;
  6884.  
  6885. if (pkWarp->IsGoto())
  6886. {
  6887. LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(pkWarp->GetMapIndex());
  6888. m_lTargetX += pkSectreeMap->m_setting.iBaseX;
  6889. m_lTargetY += pkSectreeMap->m_setting.iBaseY;
  6890. m_bUseWarp = false;
  6891. }
  6892. }
  6893.  
  6894. bool Valid()
  6895. {
  6896. return !m_bInvalid;
  6897. }
  6898.  
  6899. void operator () (LPENTITY ent)
  6900. {
  6901. if (!Valid())
  6902. return;
  6903.  
  6904. if (!ent->IsType(ENTITY_CHARACTER))
  6905. return;
  6906.  
  6907. LPCHARACTER pkChr = (LPCHARACTER) ent;
  6908.  
  6909. if (!pkChr->IsPC())
  6910. return;
  6911.  
  6912. int iDist = DISTANCE_APPROX(pkChr->GetX() - m_lX, pkChr->GetY() - m_lY);
  6913.  
  6914. if (iDist > 300)
  6915. return;
  6916.  
  6917. if (m_bEmpire && pkChr->GetEmpire() && m_bEmpire != pkChr->GetEmpire())
  6918. return;
  6919.  
  6920. if (pkChr->IsHack())
  6921. return;
  6922.  
  6923. if (!pkChr->CanHandleItem(false, true))
  6924. return;
  6925.  
  6926. if (m_bUseWarp)
  6927. pkChr->WarpSet(m_lTargetX, m_lTargetY);
  6928. else
  6929. {
  6930. pkChr->Show(pkChr->GetMapIndex(), m_lTargetX, m_lTargetY);
  6931. pkChr->Stop();
  6932. }
  6933. }
  6934.  
  6935. bool m_bInvalid;
  6936. bool m_bUseWarp;
  6937.  
  6938. long m_lX;
  6939. long m_lY;
  6940. long m_lTargetX;
  6941. long m_lTargetY;
  6942.  
  6943. BYTE m_bEmpire;
  6944. };
  6945. }
  6946.  
  6947. EVENTFUNC(warp_npc_event)
  6948. {
  6949. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  6950. if ( info == NULL )
  6951. {
  6952. sys_err( "warp_npc_event> <Factor> Null pointer" );
  6953. return 0;
  6954. }
  6955.  
  6956. LPCHARACTER ch = info->ch;
  6957.  
  6958. if (ch == NULL) { // <Factor>
  6959. return 0;
  6960. }
  6961.  
  6962. if (!ch->GetSectree())
  6963. {
  6964. ch->m_pkWarpNPCEvent = NULL;
  6965. return 0;
  6966. }
  6967.  
  6968. FuncCheckWarp f(ch);
  6969. if (f.Valid())
  6970. ch->GetSectree()->ForEachAround(f);
  6971.  
  6972. return passes_per_sec / 2;
  6973. }
  6974.  
  6975.  
  6976. void CHARACTER::StartWarpNPCEvent()
  6977. {
  6978. if (m_pkWarpNPCEvent)
  6979. return;
  6980.  
  6981. if (!IsWarp() && !IsGoto())
  6982. return;
  6983.  
  6984. char_event_info* info = AllocEventInfo<char_event_info>();
  6985.  
  6986. info->ch = this;
  6987.  
  6988. m_pkWarpNPCEvent = event_create(warp_npc_event, info, passes_per_sec / 2);
  6989. }
  6990.  
  6991. void CHARACTER::SyncPacket()
  6992. {
  6993. TEMP_BUFFER buf;
  6994.  
  6995. TPacketCGSyncPositionElement elem;
  6996.  
  6997. elem.dwVID = GetVID();
  6998. elem.lX = GetX();
  6999. elem.lY = GetY();
  7000.  
  7001. TPacketGCSyncPosition pack;
  7002.  
  7003. pack.bHeader = HEADER_GC_SYNC_POSITION;
  7004. pack.wSize = sizeof(TPacketGCSyncPosition) + sizeof(elem);
  7005.  
  7006. buf.write(&pack, sizeof(pack));
  7007. buf.write(&elem, sizeof(elem));
  7008.  
  7009. PacketAround(buf.read_peek(), buf.size());
  7010. }
  7011.  
  7012. LPCHARACTER CHARACTER::GetMarryPartner() const
  7013. {
  7014. return m_pkChrMarried;
  7015. }
  7016.  
  7017. void CHARACTER::SetMarryPartner(LPCHARACTER ch)
  7018. {
  7019. m_pkChrMarried = ch;
  7020. }
  7021.  
  7022. int CHARACTER::GetMarriageBonus(DWORD dwItemVnum, bool bSum)
  7023. {
  7024. if (IsNPC())
  7025. return 0;
  7026.  
  7027. marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(GetPlayerID());
  7028.  
  7029. if (!pMarriage)
  7030. return 0;
  7031.  
  7032. return pMarriage->GetBonus(dwItemVnum, bSum, this);
  7033. }
  7034.  
  7035. void CHARACTER::ConfirmWithMsg(const char* szMsg, int iTimeout, DWORD dwRequestPID)
  7036. {
  7037. if (!IsPC())
  7038. return;
  7039.  
  7040. TPacketGCQuestConfirm p;
  7041.  
  7042. p.header = HEADER_GC_QUEST_CONFIRM;
  7043. p.requestPID = dwRequestPID;
  7044. p.timeout = iTimeout;
  7045. strlcpy(p.msg, szMsg, sizeof(p.msg));
  7046.  
  7047. GetDesc()->Packet(&p, sizeof(p));
  7048. }
  7049.  
  7050. int CHARACTER::GetPremiumRemainSeconds(BYTE bType) const
  7051. {
  7052. if (bType >= PREMIUM_MAX_NUM)
  7053. return 0;
  7054.  
  7055. return m_aiPremiumTimes[bType] - get_global_time();
  7056. }
  7057.  
  7058. bool CHARACTER::WarpToPID(DWORD dwPID)
  7059. {
  7060. LPCHARACTER victim;
  7061. if ((victim = (CHARACTER_MANAGER::instance().FindByPID(dwPID))))
  7062. {
  7063. int mapIdx = victim->GetMapIndex();
  7064. if (IS_SUMMONABLE_ZONE(mapIdx))
  7065. {
  7066. if (CAN_ENTER_ZONE(this, mapIdx))
  7067. {
  7068. WarpSet(victim->GetX(), victim->GetY());
  7069. }
  7070. else
  7071. {
  7072. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 있는 곳으로 워프할 수 없습니다."));
  7073. return false;
  7074. }
  7075. }
  7076. else
  7077. {
  7078. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 있는 곳으로 워프할 수 없습니다."));
  7079. return false;
  7080. }
  7081. }
  7082. else
  7083. {
  7084. // 다른 서버에 로그인된 사람이 있음 -> 메시지 보내 좌표를 받아오자
  7085. // 1. A.pid, B.pid 를 뿌림
  7086. // 2. B.pid를 가진 서버가 뿌린서버에게 A.pid, 좌표 를 보냄
  7087. // 3. 워프
  7088. CCI * pcci = P2P_MANAGER::instance().FindByPID(dwPID);
  7089.  
  7090. if (!pcci)
  7091. {
  7092. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 온라인 상태가 아닙니다."));
  7093. return false;
  7094. }
  7095.  
  7096. if (pcci->bChannel != g_bChannel)
  7097. {
  7098. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 %d 채널에 있습니다. (현재 채널 %d)"), pcci->bChannel, g_bChannel);
  7099. return false;
  7100. }
  7101. else if (false == IS_SUMMONABLE_ZONE(pcci->lMapIndex))
  7102. {
  7103. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 있는 곳으로 워프할 수 없습니다."));
  7104. return false;
  7105. }
  7106. else
  7107. {
  7108. if (!CAN_ENTER_ZONE(this, pcci->lMapIndex))
  7109. {
  7110. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("상대방이 있는 곳으로 워프할 수 없습니다."));
  7111. return false;
  7112. }
  7113.  
  7114. TPacketGGFindPosition p;
  7115. p.header = HEADER_GG_FIND_POSITION;
  7116. p.dwFromPID = GetPlayerID();
  7117. p.dwTargetPID = dwPID;
  7118. pcci->pkDesc->Packet(&p, sizeof(TPacketGGFindPosition));
  7119.  
  7120. if (test_server)
  7121. ChatPacket(CHAT_TYPE_PARTY, "sent find position packet for teleport");
  7122. }
  7123. }
  7124. return true;
  7125. }
  7126.  
  7127. // ADD_REFINE_BUILDING
  7128. CGuild* CHARACTER::GetRefineGuild() const
  7129. {
  7130. LPCHARACTER chRefineNPC = CHARACTER_MANAGER::instance().Find(m_dwRefineNPCVID);
  7131.  
  7132. return (chRefineNPC ? chRefineNPC->GetGuild() : NULL);
  7133. }
  7134.  
  7135. bool CHARACTER::IsRefineThroughGuild() const
  7136. {
  7137. return GetRefineGuild() != NULL;
  7138. }
  7139.  
  7140. int CHARACTER::ComputeRefineFee(int iCost, int iMultiply) const
  7141. {
  7142. CGuild* pGuild = GetRefineGuild();
  7143. if (pGuild)
  7144. {
  7145. if (pGuild == GetGuild())
  7146. return iCost * iMultiply * 9 / 10;
  7147.  
  7148. // 다른 제국 사람이 시도하는 경우 추가로 3배 더
  7149. LPCHARACTER chRefineNPC = CHARACTER_MANAGER::instance().Find(m_dwRefineNPCVID);
  7150. if (chRefineNPC && chRefineNPC->GetEmpire() != GetEmpire())
  7151. return iCost * iMultiply * 3;
  7152.  
  7153. return iCost * iMultiply;
  7154. }
  7155. else
  7156. return iCost;
  7157. }
  7158.  
  7159. void CHARACTER::PayRefineFee(int iTotalMoney)
  7160. {
  7161. int iFee = iTotalMoney / 10;
  7162. CGuild* pGuild = GetRefineGuild();
  7163.  
  7164. int iRemain = iTotalMoney;
  7165.  
  7166. if (pGuild)
  7167. {
  7168. // 자기 길드이면 iTotalMoney에 이미 10%가 제외되어있다
  7169. if (pGuild != GetGuild())
  7170. {
  7171. pGuild->RequestDepositMoney(this, iFee);
  7172. iRemain -= iFee;
  7173. }
  7174. }
  7175.  
  7176. PointChange(POINT_GOLD, -iRemain);
  7177. }
  7178. // END_OF_ADD_REFINE_BUILDING
  7179.  
  7180. //Hack 방지를 위한 체크.
  7181. bool CHARACTER::IsHack(bool bSendMsg, bool bCheckShopOwner, int limittime)
  7182. {
  7183. const int iPulse = thecore_pulse();
  7184.  
  7185. if (test_server)
  7186. bSendMsg = true;
  7187.  
  7188. //창고 연후 체크
  7189. if (iPulse - GetSafeboxLoadTime() < PASSES_PER_SEC(limittime))
  7190. {
  7191. if (bSendMsg)
  7192. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("창고를 연후 %d초 이내에는 다른곳으로 이동할수 없습니다."), limittime);
  7193.  
  7194. if (test_server)
  7195. ChatPacket(CHAT_TYPE_INFO, "[TestOnly]Pulse %d LoadTime %d PASS %d", iPulse, GetSafeboxLoadTime(), PASSES_PER_SEC(limittime));
  7196. return true;
  7197. }
  7198.  
  7199. //거래관련 창 체크
  7200. if (bCheckShopOwner)
  7201. {
  7202. if (GetExchange() || GetMyShop() || GetShopOwner() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner())
  7203. {
  7204. if (bSendMsg)
  7205. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("거래창,창고 등을 연 상태에서는 다른곳으로 이동,종료 할수 없습니다"));
  7206.  
  7207. return true;
  7208. }
  7209. }
  7210. else
  7211. {
  7212. if (GetExchange() || GetMyShop() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen())
  7213. {
  7214. if (bSendMsg)
  7215. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("거래창,창고 등을 연 상태에서는 다른곳으로 이동,종료 할수 없습니다"));
  7216.  
  7217. return true;
  7218. }
  7219. }
  7220.  
  7221. //PREVENT_PORTAL_AFTER_EXCHANGE
  7222. //교환 후 시간체크
  7223. if (iPulse - GetExchangeTime() < PASSES_PER_SEC(limittime))
  7224. {
  7225. if (bSendMsg)
  7226. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("거래 후 %d초 이내에는 다른지역으로 이동 할 수 없습니다."), limittime );
  7227. return true;
  7228. }
  7229. //END_PREVENT_PORTAL_AFTER_EXCHANGE
  7230.  
  7231. //PREVENT_ITEM_COPY
  7232. if (iPulse - GetMyShopTime() < PASSES_PER_SEC(limittime))
  7233. {
  7234. if (bSendMsg)
  7235. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("거래 후 %d초 이내에는 다른지역으로 이동 할 수 없습니다."), limittime);
  7236. return true;
  7237. }
  7238.  
  7239. if (iPulse - GetRefineTime() < PASSES_PER_SEC(limittime))
  7240. {
  7241. if (bSendMsg)
  7242. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("아이템 개량후 %d초 이내에는 귀환부,귀환기억부를 사용할 수 없습니다."), limittime);
  7243. return true;
  7244. }
  7245. //END_PREVENT_ITEM_COPY
  7246.  
  7247. return false;
  7248. }
  7249.  
  7250. BOOL CHARACTER::IsMonarch() const
  7251. {
  7252. //MONARCH_LIMIT
  7253. if (CMonarch::instance().IsMonarch(GetPlayerID(), GetEmpire()))
  7254. return true;
  7255.  
  7256. return false;
  7257.  
  7258. //END_MONARCH_LIMIT
  7259. }
  7260. void CHARACTER::Say(const std::string & s)
  7261. {
  7262. struct ::packet_script packet_script;
  7263.  
  7264. packet_script.header = HEADER_GC_SCRIPT;
  7265. packet_script.skin = 1;
  7266. packet_script.src_size = s.size();
  7267. packet_script.size = packet_script.src_size + sizeof(struct packet_script);
  7268.  
  7269. TEMP_BUFFER buf;
  7270.  
  7271. buf.write(&packet_script, sizeof(struct packet_script));
  7272. buf.write(&s[0], s.size());
  7273.  
  7274. if (IsPC())
  7275. {
  7276. GetDesc()->Packet(buf.read_peek(), buf.size());
  7277. }
  7278. }
  7279.  
  7280. //
  7281. // Monarch
  7282. //
  7283. void CHARACTER::InitMC()
  7284. {
  7285. for (int n = 0; n < MI_MAX; ++n)
  7286. {
  7287. m_dwMonarchCooltime[n] = thecore_pulse();
  7288. }
  7289.  
  7290. m_dwMonarchCooltimelimit[MI_HEAL] = PASSES_PER_SEC(MC_HEAL);
  7291. m_dwMonarchCooltimelimit[MI_WARP] = PASSES_PER_SEC(MC_WARP);
  7292. m_dwMonarchCooltimelimit[MI_TRANSFER] = PASSES_PER_SEC(MC_TRANSFER);
  7293. m_dwMonarchCooltimelimit[MI_TAX] = PASSES_PER_SEC(MC_TAX);
  7294. m_dwMonarchCooltimelimit[MI_SUMMON] = PASSES_PER_SEC(MC_SUMMON);
  7295.  
  7296. m_dwMonarchCooltime[MI_HEAL] -= PASSES_PER_SEC(GetMCL(MI_HEAL));
  7297. m_dwMonarchCooltime[MI_WARP] -= PASSES_PER_SEC(GetMCL(MI_WARP));
  7298. m_dwMonarchCooltime[MI_TRANSFER] -= PASSES_PER_SEC(GetMCL(MI_TRANSFER));
  7299. m_dwMonarchCooltime[MI_TAX] -= PASSES_PER_SEC(GetMCL(MI_TAX));
  7300. m_dwMonarchCooltime[MI_SUMMON] -= PASSES_PER_SEC(GetMCL(MI_SUMMON));
  7301. }
  7302.  
  7303. DWORD CHARACTER::GetMC(enum MONARCH_INDEX e) const
  7304. {
  7305. return m_dwMonarchCooltime[e];
  7306. }
  7307.  
  7308. void CHARACTER::SetMC(enum MONARCH_INDEX e)
  7309. {
  7310. m_dwMonarchCooltime[e] = thecore_pulse();
  7311. }
  7312.  
  7313. bool CHARACTER::IsMCOK(enum MONARCH_INDEX e) const
  7314. {
  7315. int iPulse = thecore_pulse();
  7316.  
  7317. if ((iPulse - GetMC(e)) < GetMCL(e))
  7318. {
  7319. if (test_server)
  7320. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  7321.  
  7322. return false;
  7323. }
  7324.  
  7325. if (test_server)
  7326. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  7327.  
  7328. return true;
  7329. }
  7330.  
  7331. DWORD CHARACTER::GetMCL(enum MONARCH_INDEX e) const
  7332. {
  7333. return m_dwMonarchCooltimelimit[e];
  7334. }
  7335.  
  7336. DWORD CHARACTER::GetMCLTime(enum MONARCH_INDEX e) const
  7337. {
  7338. int iPulse = thecore_pulse();
  7339.  
  7340. if (test_server)
  7341. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  7342.  
  7343. return (GetMCL(e)) / passes_per_sec - (iPulse - GetMC(e)) / passes_per_sec;
  7344. }
  7345.  
  7346. bool CHARACTER::IsSiegeNPC() const
  7347. {
  7348. return IsNPC() && (GetRaceNum() == 11000 || GetRaceNum() == 11002 || GetRaceNum() == 11004);
  7349. }
  7350.  
  7351. //------------------------------------------------
  7352. void CHARACTER::UpdateDepositPulse()
  7353. {
  7354. m_deposit_pulse = thecore_pulse() + PASSES_PER_SEC(60*5); // 5분
  7355. }
  7356.  
  7357. bool CHARACTER::CanDeposit() const
  7358. {
  7359. return (m_deposit_pulse == 0 || (m_deposit_pulse < thecore_pulse()));
  7360. }
  7361. //------------------------------------------------
  7362.  
  7363. ESex GET_SEX(LPCHARACTER ch)
  7364. {
  7365. switch (ch->GetRaceNum())
  7366. {
  7367. case MAIN_RACE_WARRIOR_M:
  7368. case MAIN_RACE_SURA_M:
  7369. case MAIN_RACE_ASSASSIN_M:
  7370. case MAIN_RACE_SHAMAN_M:
  7371. case MAIN_RACE_WOLFMAN_M:
  7372. return SEX_MALE;
  7373.  
  7374. case MAIN_RACE_ASSASSIN_W:
  7375. case MAIN_RACE_SHAMAN_W:
  7376. case MAIN_RACE_WARRIOR_W:
  7377. case MAIN_RACE_SURA_W:
  7378. return SEX_FEMALE;
  7379. }
  7380.  
  7381. /* default sex = male */
  7382. return SEX_MALE;
  7383. }
  7384.  
  7385. int CHARACTER::GetHPPct() const
  7386. {
  7387. return (GetHP() * 100) / GetMaxHP();
  7388. }
  7389.  
  7390. bool CHARACTER::IsBerserk() const
  7391. {
  7392. if (m_pkMobInst != NULL)
  7393. return m_pkMobInst->m_IsBerserk;
  7394. else
  7395. return false;
  7396. }
  7397.  
  7398. void CHARACTER::SetBerserk(bool mode)
  7399. {
  7400. if (m_pkMobInst != NULL)
  7401. m_pkMobInst->m_IsBerserk = mode;
  7402. }
  7403.  
  7404. bool CHARACTER::IsGodSpeed() const
  7405. {
  7406. if (m_pkMobInst != NULL)
  7407. {
  7408. return m_pkMobInst->m_IsGodSpeed;
  7409. }
  7410. else
  7411. {
  7412. return false;
  7413. }
  7414. }
  7415.  
  7416. void CHARACTER::SetGodSpeed(bool mode)
  7417. {
  7418. if (m_pkMobInst != NULL)
  7419. {
  7420. m_pkMobInst->m_IsGodSpeed = mode;
  7421.  
  7422. if (mode == true)
  7423. {
  7424. SetPoint(POINT_ATT_SPEED, 250);
  7425. }
  7426. else
  7427. {
  7428. SetPoint(POINT_ATT_SPEED, m_pkMobData->m_table.sAttackSpeed);
  7429. }
  7430. }
  7431. }
  7432.  
  7433. bool CHARACTER::IsDeathBlow() const
  7434. {
  7435. if (number(1, 100) <= m_pkMobData->m_table.bDeathBlowPoint)
  7436. {
  7437. return true;
  7438. }
  7439. else
  7440. {
  7441. return false;
  7442. }
  7443. }
  7444.  
  7445. struct FFindReviver
  7446. {
  7447. FFindReviver()
  7448. {
  7449. pChar = NULL;
  7450. HasReviver = false;
  7451. }
  7452.  
  7453. void operator() (LPCHARACTER ch)
  7454. {
  7455. if (ch->IsMonster() != true)
  7456. {
  7457. return;
  7458. }
  7459.  
  7460. if (ch->IsReviver() == true && pChar != ch && ch->IsDead() != true)
  7461. {
  7462. if (number(1, 100) <= ch->GetMobTable().bRevivePoint)
  7463. {
  7464. HasReviver = true;
  7465. pChar = ch;
  7466. }
  7467. }
  7468. }
  7469.  
  7470. LPCHARACTER pChar;
  7471. bool HasReviver;
  7472. };
  7473.  
  7474. bool CHARACTER::HasReviverInParty() const
  7475. {
  7476. LPPARTY party = GetParty();
  7477.  
  7478. if (party != NULL)
  7479. {
  7480. if (party->GetMemberCount() == 1) return false;
  7481.  
  7482. FFindReviver f;
  7483. party->ForEachMemberPtr(f);
  7484. return f.HasReviver;
  7485. }
  7486.  
  7487. return false;
  7488. }
  7489.  
  7490. bool CHARACTER::IsRevive() const
  7491. {
  7492. if (m_pkMobInst != NULL)
  7493. {
  7494. return m_pkMobInst->m_IsRevive;
  7495. }
  7496.  
  7497. return false;
  7498. }
  7499.  
  7500. void CHARACTER::SetRevive(bool mode)
  7501. {
  7502. if (m_pkMobInst != NULL)
  7503. {
  7504. m_pkMobInst->m_IsRevive = mode;
  7505. }
  7506. }
  7507.  
  7508. #define IS_SPEED_HACK_PLAYER(ch) (ch->m_speed_hack_count > SPEEDHACK_LIMIT_COUNT * 3)
  7509.  
  7510. EVENTFUNC(check_speedhack_event)
  7511. {
  7512. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  7513. if ( info == NULL )
  7514. {
  7515. sys_err( "check_speedhack_event> <Factor> Null pointer" );
  7516. return 0;
  7517. }
  7518.  
  7519. LPCHARACTER ch = info->ch;
  7520.  
  7521. if (NULL == ch || ch->IsNPC())
  7522. return 0;
  7523.  
  7524. if (IS_SPEED_HACK_PLAYER(ch))
  7525. {
  7526. // write hack log
  7527. LogManager::instance().SpeedHackLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), ch->m_speed_hack_count);
  7528.  
  7529. if (false == LC_IsEurope())
  7530. {
  7531. // close connection
  7532. LPDESC desc = ch->GetDesc();
  7533.  
  7534. if (desc)
  7535. {
  7536. DESC_MANAGER::instance().DestroyDesc(desc);
  7537. return 0;
  7538. }
  7539. }
  7540. }
  7541.  
  7542. ch->m_speed_hack_count = 0;
  7543.  
  7544. ch->ResetComboHackCount();
  7545. return PASSES_PER_SEC(60);
  7546. }
  7547.  
  7548. void CHARACTER::StartCheckSpeedHackEvent()
  7549. {
  7550. if (m_pkCheckSpeedHackEvent)
  7551. return;
  7552.  
  7553. char_event_info* info = AllocEventInfo<char_event_info>();
  7554.  
  7555. info->ch = this;
  7556.  
  7557. m_pkCheckSpeedHackEvent = event_create(check_speedhack_event, info, PASSES_PER_SEC(60)); // 1분
  7558. }
  7559.  
  7560. void CHARACTER::GoHome()
  7561. {
  7562. WarpSet(EMPIRE_START_X(GetEmpire()), EMPIRE_START_Y(GetEmpire()));
  7563. }
  7564.  
  7565. void CHARACTER::SendGuildName(CGuild* pGuild)
  7566. {
  7567. if (NULL == pGuild) return;
  7568.  
  7569. DESC *desc = GetDesc();
  7570.  
  7571. if (NULL == desc) return;
  7572. if (m_known_guild.find(pGuild->GetID()) != m_known_guild.end()) return;
  7573.  
  7574. m_known_guild.insert(pGuild->GetID());
  7575.  
  7576. TPacketGCGuildName pack;
  7577. memset(&pack, 0x00, sizeof(pack));
  7578.  
  7579. pack.header = HEADER_GC_GUILD;
  7580. pack.subheader = GUILD_SUBHEADER_GC_GUILD_NAME;
  7581. pack.size = sizeof(TPacketGCGuildName);
  7582. pack.guildID = pGuild->GetID();
  7583. memcpy(pack.guildName, pGuild->GetName(), GUILD_NAME_MAX_LEN);
  7584.  
  7585. desc->Packet(&pack, sizeof(pack));
  7586. }
  7587.  
  7588. void CHARACTER::SendGuildName(DWORD dwGuildID)
  7589. {
  7590. SendGuildName(CGuildManager::instance().FindGuild(dwGuildID));
  7591. }
  7592.  
  7593. EVENTFUNC(destroy_when_idle_event)
  7594. {
  7595. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  7596. if ( info == NULL )
  7597. {
  7598. sys_err( "destroy_when_idle_event> <Factor> Null pointer" );
  7599. return 0;
  7600. }
  7601.  
  7602. LPCHARACTER ch = info->ch;
  7603. if (ch == NULL) { // <Factor>
  7604. return 0;
  7605. }
  7606.  
  7607. if (ch->GetVictim())
  7608. {
  7609. return PASSES_PER_SEC(300);
  7610. }
  7611.  
  7612. sys_log(1, "DESTROY_WHEN_IDLE: %s", ch->GetName());
  7613.  
  7614. ch->m_pkDestroyWhenIdleEvent = NULL;
  7615. M2_DESTROY_CHARACTER(ch);
  7616. return 0;
  7617. }
  7618.  
  7619. void CHARACTER::StartDestroyWhenIdleEvent()
  7620. {
  7621. if (m_pkDestroyWhenIdleEvent)
  7622. return;
  7623.  
  7624. char_event_info* info = AllocEventInfo<char_event_info>();
  7625.  
  7626. info->ch = this;
  7627.  
  7628. m_pkDestroyWhenIdleEvent = event_create(destroy_when_idle_event, info, PASSES_PER_SEC(300));
  7629. }
  7630.  
  7631. void CHARACTER::SetComboSequence(BYTE seq)
  7632. {
  7633. m_bComboSequence = seq;
  7634. }
  7635.  
  7636. BYTE CHARACTER::GetComboSequence() const
  7637. {
  7638. return m_bComboSequence;
  7639. }
  7640.  
  7641. void CHARACTER::SetLastComboTime(DWORD time)
  7642. {
  7643. m_dwLastComboTime = time;
  7644. }
  7645.  
  7646. DWORD CHARACTER::GetLastComboTime() const
  7647. {
  7648. return m_dwLastComboTime;
  7649. }
  7650.  
  7651. void CHARACTER::SetValidComboInterval(int interval)
  7652. {
  7653. m_iValidComboInterval = interval;
  7654. }
  7655.  
  7656. int CHARACTER::GetValidComboInterval() const
  7657. {
  7658. return m_iValidComboInterval;
  7659. }
  7660.  
  7661. BYTE CHARACTER::GetComboIndex() const
  7662. {
  7663. return m_bComboIndex;
  7664. }
  7665.  
  7666. void CHARACTER::IncreaseComboHackCount(int k)
  7667. {
  7668. m_iComboHackCount += k;
  7669. if (m_iComboHackCount >= 10)
  7670. {
  7671. if (GetJob() == JOB_WOLFMAN && m_iComboHackCount <= 20)
  7672. {
  7673. return;
  7674. }
  7675.  
  7676. if (GetDesc())
  7677. {
  7678. if (GetDesc()->DelayedDisconnect(number(2, 7)))
  7679. {
  7680. sys_log(0, "COMBO_HACK_DISCONNECT: %s count: %d", GetName(), m_iComboHackCount);
  7681. LogManager::instance().HackLog("Combo", this);
  7682. }
  7683. }
  7684. }
  7685. }
  7686.  
  7687. void CHARACTER::ResetComboHackCount()
  7688. {
  7689. m_iComboHackCount = 0;
  7690. }
  7691.  
  7692. void CHARACTER::SkipComboAttackByTime(int interval)
  7693. {
  7694. m_dwSkipComboAttackByTime = get_dword_time() + interval;
  7695. }
  7696.  
  7697. DWORD CHARACTER::GetSkipComboAttackByTime() const
  7698. {
  7699. return m_dwSkipComboAttackByTime;
  7700. }
  7701.  
  7702. void CHARACTER::ResetChatCounter()
  7703. {
  7704. m_bChatCounter = 0;
  7705. }
  7706.  
  7707. BYTE CHARACTER::IncreaseChatCounter()
  7708. {
  7709. return ++m_bChatCounter;
  7710. }
  7711.  
  7712. BYTE CHARACTER::GetChatCounter() const
  7713. {
  7714. return m_bChatCounter;
  7715. }
  7716.  
  7717. // 말이나 다른것을 타고 있나?
  7718. bool CHARACTER::IsRiding() const
  7719. {
  7720. return IsHorseRiding() || GetMountVnum();
  7721. }
  7722.  
  7723. bool CHARACTER::CanWarp() const
  7724. {
  7725. const int iPulse = thecore_pulse();
  7726. const int limit_time = PASSES_PER_SEC(g_nPortalLimitTime);
  7727.  
  7728. if ((iPulse - GetSafeboxLoadTime()) < limit_time)
  7729. return false;
  7730.  
  7731. if ((iPulse - GetExchangeTime()) < limit_time)
  7732. return false;
  7733.  
  7734. if ((iPulse - GetMyShopTime()) < limit_time)
  7735. return false;
  7736.  
  7737. if ((iPulse - GetRefineTime()) < limit_time)
  7738. return false;
  7739.  
  7740. if (GetExchange() || GetMyShop() || GetShopOwner() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner())
  7741. return false;
  7742.  
  7743. return true;
  7744. }
  7745.  
  7746. DWORD CHARACTER::GetNextExp() const
  7747. {
  7748. if (PLAYER_EXP_TABLE_MAX < GetLevel())
  7749. return 2500000000;
  7750. else
  7751. return exp_table[GetLevel()];
  7752. }
  7753.  
  7754. #ifdef NEW_PET_SYSTEM
  7755. DWORD CHARACTER::PetGetNextExp() const
  7756. {
  7757. if (IsNewPet()) {
  7758. if (120 < GetLevel())
  7759. return 2500000000;
  7760. else
  7761. return exppet_table[GetLevel()];
  7762. }
  7763. }
  7764. #endif
  7765.  
  7766. int CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const
  7767. {
  7768. return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob);
  7769. }
  7770.  
  7771. void CHARACTER::SetOfflineShopSign(const char * c_szSign)
  7772. {
  7773. char szSign[SHOP_SIGN_MAX_LEN + 1];
  7774. strlcpy(szSign, c_szSign, sizeof(szSign));
  7775. m_stOfflineShopSign = szSign;
  7776. }
  7777.  
  7778. void CHARACTER::DestroyOfflineShop()
  7779. {
  7780. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetOfflineShopRealOwner());
  7781. LPOFFLINESHOP pkOfflineShop = GetOfflineShop();
  7782. if (pkOfflineShop)
  7783. pkOfflineShop->RemoveAllGuest();
  7784. M2_DESTROY_CHARACTER(this);
  7785. }
RAW Paste Data