1. #include "stdafx.h"
  2. #include "../../common/teen_packet.h"
  3. #include "../../common/VnumHelper.h"
  4. #include "char.h"
  5. #include "config.h"
  6. #include "utils.h"
  7. #include "crc32.h"
  8. #include "char_manager.h"
  9. #include "desc_client.h"
  10. #include "desc_manager.h"
  11. #include "buffer_manager.h"
  12. #include "item_manager.h"
  13. #include "motion.h"
  14. #include "vector.h"
  15. #include "packet.h"
  16. #include "cmd.h"
  17. #include "fishing.h"
  18. #include "exchange.h"
  19. #include "battle.h"
  20. #include "affect.h"
  21. #include "shop.h"
  22. #include "shop_manager.h"
  23. #include "safebox.h"
  24. #include "regen.h"
  25. #include "pvp.h"
  26. #include "party.h"
  27. #include "start_position.h"
  28. #include "questmanager.h"
  29. #include "log.h"
  30. #include "p2p.h"
  31. #include "guild.h"
  32. #include "guild_manager.h"
  33. #include "dungeon.h"
  34. #include "messenger_manager.h"
  35. #include "unique_item.h"
  36. #include "priv_manager.h"
  37. #include "war_map.h"
  38. #include "xmas_event.h"
  39. #include "banword.h"
  40. #include "target.h"
  41. #include "wedding.h"
  42. #include "mob_manager.h"
  43. #include "mining.h"
  44. #include "monarch.h"
  45. #include "castle.h"
  46. #include "arena.h"
  47. #include "dev_log.h"
  48. #include "horsename_manager.h"
  49. #include "pcbang.h"
  50. #include "gm.h"
  51. #include "map_location.h"
  52. #include "BlueDragon_Binder.h"
  53. #include "HackShield.h"
  54. #include "skill_power.h"
  55. #include "XTrapManager.h"
  56. #include "buff_on_attributes.h"
  57. #ifdef __PET_SYSTEM__
  58. #include "PetSystem.h"
  59. #endif
  60. #include "DragonSoul.h"
  61. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  62. #include "offline_shop.h"
  63. #include "offlineshop_manager.h"
  64. #include "offlineshop_config.h"
  65. #endif
  66. extern bool offlineshop_map_allow_find(int mapIndex);
  67. extern const BYTE g_aBuffOnAttrPoints;
  68. extern bool RaceToJob(unsigned race, unsigned *ret_job);
  69. extern int g_nPortalLimitTime;
  70. extern int test_server;
  71. extern bool IS_SUMMONABLE_ZONE(int map_index); // char_item.cpp
  72. bool CAN_ENTER_ZONE(const LPCHARACTER& ch, int map_index);
  73. bool CAN_ENTER_ZONE(const LPCHARACTER& ch, int map_index)
  74. {
  75. switch (map_index)
  76. {
  77. case 301:
  78. case 302:
  79. case 303:
  80. case 304:
  81. if (ch->GetLevel() < 90)
  82. return false;
  83. }
  84. return true;
  85. }
  86. // <Factor> DynamicCharacterPtr member function definitions
  87. LPCHARACTER DynamicCharacterPtr::Get() const {
  88. LPCHARACTER p = NULL;
  89. if (is_pc) {
  90. p = CHARACTER_MANAGER::instance().FindByPID(id);
  91. } else {
  92. p = CHARACTER_MANAGER::instance().Find(id);
  93. }
  94. return p;
  95. }
  96. DynamicCharacterPtr& DynamicCharacterPtr::operator=(LPCHARACTER character) {
  97. if (character == NULL) {
  98. Reset();
  99. return *this;
  100. }
  101. if (character->IsPC()) {
  102. is_pc = true;
  103. id = character->GetPlayerID();
  104. } else {
  105. is_pc = false;
  106. id = character->GetVID();
  107. }
  108. return *this;
  109. }
  110. CHARACTER::CHARACTER()
  111. {
  112. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateIdle, &CHARACTER::EndStateEmpty);
  113. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateMove, &CHARACTER::EndStateEmpty);
  114. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateBattle, &CHARACTER::EndStateEmpty);
  115. Initialize();
  116. }
  117. CHARACTER::~CHARACTER()
  118. {
  119. Destroy();
  120. }
  121. void CHARACTER::Initialize()
  122. {
  123. CEntity::Initialize(ENTITY_CHARACTER);
  124. m_bNoOpenedShop = true;
  125. m_bOpeningSafebox = false;
  126. m_fSyncTime = get_float_time()-3;
  127. m_dwPlayerID = 0;
  128. m_dwKillerPID = 0;
  129. m_iMoveCount = 0;
  130. m_pkRegen = NULL;
  131. regen_id_ = 0;
  132. m_posRegen.x = m_posRegen.y = m_posRegen.z = 0;
  133. m_posStart.x = m_posStart.y = 0;
  134. m_posDest.x = m_posDest.y = 0;
  135. m_fRegenAngle = 0.0f;
  136. m_pkMobData = NULL;
  137. m_pkMobInst = NULL;
  138. m_pkShop = NULL;
  139. m_pkChrShopOwner = NULL;
  140. m_pkMyShop = NULL;
  141. m_pkExchange = NULL;
  142. m_pkParty = NULL;
  143. m_pkPartyRequestEvent = NULL;
  144. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  145. // Offline Shop
  146. m_pkOfflineShop = NULL;
  147. m_pkChrOfflineShopOwner = NULL;
  148. m_pkOfflineShopUpdateEvent = NULL;
  149. // End Of Offline Shop
  150. #endif
  151. m_pGuild = NULL;
  152. m_pkChrTarget = NULL;
  153. m_pkMuyeongEvent = NULL;
  154. m_pkWarpNPCEvent = NULL;
  155. m_pkDeadEvent = NULL;
  156. m_pkStunEvent = NULL;
  157. m_pkSaveEvent = NULL;
  158. m_pkRecoveryEvent = NULL;
  159. m_pkTimedEvent = NULL;
  160. m_pkFishingEvent = NULL;
  161. m_pkWarpEvent = NULL;
  162. // MINING
  163. m_pkMiningEvent = NULL;
  164. // END_OF_MINING
  165. m_pkPoisonEvent = NULL;
  166. m_pkFireEvent = NULL;
  167. m_pkCheckSpeedHackEvent = NULL;
  168. m_speed_hack_count = 0;
  169. m_pkAffectEvent = NULL;
  170. m_afAffectFlag = TAffectFlag(0, 0);
  171. m_pkDestroyWhenIdleEvent = NULL;
  172. m_pkChrSyncOwner = NULL;
  173. memset(&m_points, 0, sizeof(m_points));
  174. memset(&m_pointsInstant, 0, sizeof(m_pointsInstant));
  175. memset(&m_quickslot, 0, sizeof(m_quickslot));
  176. m_bCharType = CHAR_TYPE_MONSTER;
  177. SetPosition(POS_STANDING);
  178. m_dwPlayStartTime = m_dwLastMoveTime = get_dword_time();
  179. GotoState(m_stateIdle);
  180. m_dwStateDuration = 1;
  181. m_dwLastAttackTime = get_dword_time() - 20000;
  182. m_bAddChrState = 0;
  183. m_pkChrStone = NULL;
  184. m_pkSafebox = NULL;
  185. m_iSafeboxSize = -1;
  186. m_iSafeboxLoadTime = 0;
  187. m_pkMall = NULL;
  188. m_iMallLoadTime = 0;
  189. m_posWarp.x = m_posWarp.y = m_posWarp.z = 0;
  190. m_lWarpMapIndex = 0;
  191. m_posExit.x = m_posExit.y = m_posExit.z = 0;
  192. m_lExitMapIndex = 0;
  193. m_pSkillLevels = NULL;
  194. m_dwMoveStartTime = 0;
  195. m_dwMoveDuration = 0;
  196. m_dwFlyTargetID = 0;
  197. m_dwNextStatePulse = 0;
  198. m_dwLastDeadTime = get_dword_time()-180000;
  199. m_bSkipSave = false;
  200. m_bItemLoaded = false;
  201. m_bHasPoisoned = false;
  202. m_pkDungeon = NULL;
  203. m_iEventAttr = 0;
  204. m_kAttackLog.dwVID = 0;
  205. m_kAttackLog.dwTime = 0;
  206. m_bNowWalking = m_bWalking = false;
  207. ResetChangeAttackPositionTime();
  208. m_bDetailLog = false;
  209. m_bMonsterLog = false;
  210. m_bDisableCooltime = false;
  211. m_iAlignment = 0;
  212. m_iRealAlignment = 0;
  213. m_iKillerModePulse = 0;
  214. m_bPKMode = PK_MODE_PEACE;
  215. m_dwQuestNPCVID = 0;
  216. m_dwQuestByVnum = 0;
  217. m_pQuestItem = NULL;
  218. m_szMobileAuth[0] = '\0';
  219. m_dwUnderGuildWarInfoMessageTime = get_dword_time()-60000;
  220. m_bUnderRefine = false;
  221. // REFINE_NPC
  222. m_dwRefineNPCVID = 0;
  223. // END_OF_REFINE_NPC
  224. m_dwPolymorphRace = 0;
  225. m_bStaminaConsume = false;
  226. ResetChainLightningIndex();
  227. m_dwMountVnum = 0;
  228. m_chHorse = NULL;
  229. m_chRider = NULL;
  230. m_pWarMap = NULL;
  231. m_pWeddingMap = NULL;
  232. m_bChatCounter = 0;
  233. ResetStopTime();
  234. m_dwLastVictimSetTime = get_dword_time() - 3000;
  235. m_iMaxAggro = -100;
  236. m_bSendHorseLevel = 0;
  237. m_bSendHorseHealthGrade = 0;
  238. m_bSendHorseStaminaGrade = 0;
  239. m_dwLoginPlayTime = 0;
  240. m_pkChrMarried = NULL;
  241. m_posSafeboxOpen.x = -1000;
  242. m_posSafeboxOpen.y = -1000;
  243. // EQUIP_LAST_SKILL_DELAY
  244. m_dwLastSkillTime = get_dword_time();
  245. // END_OF_EQUIP_LAST_SKILL_DELAY
  246. // MOB_SKILL_COOLTIME
  247. memset(m_adwMobSkillCooltime, 0, sizeof(m_adwMobSkillCooltime));
  248. // END_OF_MOB_SKILL_COOLTIME
  249. m_isinPCBang = false;
  250. // ARENA
  251. m_pArena = NULL;
  252. m_nPotionLimit = quest::CQuestManager::instance().GetEventFlag("arena_potion_limit_count");
  253. // END_ARENA
  254. //PREVENT_TRADE_WINDOW
  255. m_isOpenSafebox = 0;
  256. //END_PREVENT_TRADE_WINDOW
  257. //PREVENT_REFINE_HACK
  258. m_iRefineTime = 0;
  259. //END_PREVENT_REFINE_HACK
  260. //RESTRICT_USE_SEED_OR_MOONBOTTLE
  261. m_iSeedTime = 0;
  262. //END_RESTRICT_USE_SEED_OR_MOONBOTTLE
  263. //PREVENT_PORTAL_AFTER_EXCHANGE
  264. m_iExchangeTime = 0;
  265. //END_PREVENT_PORTAL_AFTER_EXCHANGE
  266. //
  267. m_iSafeboxLoadTime = 0;
  268. m_iMyShopTime = 0;
  269. InitMC();
  270. m_deposit_pulse = 0;
  271. SET_OVER_TIME(this, OT_NONE);
  272. m_strNewName = "";
  273. m_known_guild.clear();
  274. m_dwLogOffInterval = 0;
  275. m_bComboSequence = 0;
  276. m_dwLastComboTime = 0;
  277. m_bComboIndex = 0;
  278. m_iComboHackCount = 0;
  279. m_dwSkipComboAttackByTime = 0;
  280. m_dwMountTime = 0;
  281. m_dwLastGoldDropTime = 0;
  282. m_HackShieldCheckEvent = NULL;
  283. m_HackShieldCheckMode = false;
  284. m_bIsLoadedAffect = false;
  285. cannot_dead = false;
  286. #ifdef __PET_SYSTEM__
  287. m_petSystem = 0;
  288. m_bIsPet = false;
  289. #endif
  290. m_fAttMul = 1.0f;
  291. m_fDamMul = 1.0f;
  292. m_pointsInstant.iDragonSoulActiveDeck = -1;
  293. memset(&m_tvLastSyncTime, 0, sizeof(m_tvLastSyncTime));
  294. m_iSyncHackCount = 0;
  295. }
  296. void CHARACTER::Create(const char * c_pszName, DWORD vid, bool isPC)
  297. {
  298. static int s_crc = 172814;
  299. char crc_string[128+1];
  300. snprintf(crc_string, sizeof(crc_string), "%s%p%d", c_pszName, this, ++s_crc);
  301. m_vid = VID(vid, GetCRC32(crc_string, strlen(crc_string)));
  302. if (isPC)
  303. m_stName = c_pszName;
  304. }
  305. void CHARACTER::Destroy()
  306. {
  307. CloseMyShop();
  308. if (m_pkRegen)
  309. {
  310. if (m_pkDungeon) {
  311. // Dungeon regen may not be valid at this point
  312. if (m_pkDungeon->IsValidRegen(m_pkRegen, regen_id_)) {
  313. --m_pkRegen->count;
  314. }
  315. } else {
  316. // Is this really safe?
  317. --m_pkRegen->count;
  318. }
  319. m_pkRegen = NULL;
  320. }
  321. if (m_pkDungeon)
  322. {
  323. SetDungeon(NULL);
  324. }
  325. #ifdef __PET_SYSTEM__
  326. if (m_petSystem)
  327. {
  328. m_petSystem->Destroy();
  329. delete m_petSystem;
  330. m_petSystem = 0;
  331. }
  332. #endif
  333. HorseSummon(false);
  334. if (GetRider())
  335. GetRider()->ClearHorseInfo();
  336. if( IsPC() )
  337. {
  338. if (isHackShieldEnable)
  339. {
  340. CHackShieldManager::instance().DeleteClientHandle(GetPlayerID());
  341. }
  342. }
  343. if (GetDesc())
  344. {
  345. GetDesc()->BindCharacter(NULL);
  346. // BindDesc(NULL);
  347. }
  348. if (m_pkExchange)
  349. m_pkExchange->Cancel();
  350. SetVictim(NULL);
  351. if (GetShop())
  352. {
  353. GetShop()->RemoveGuest(this);
  354. SetShop(NULL);
  355. }
  356. ClearStone();
  357. ClearSync();
  358. ClearTarget();
  359. if (NULL == m_pkMobData)
  360. {
  361. DragonSoul_CleanUp();
  362. ClearItem();
  363. }
  364. // <Factor> m_pkParty becomes NULL after CParty destructor call!
  365. LPPARTY party = m_pkParty;
  366. if (party)
  367. {
  368. if (party->GetLeaderPID() == GetVID() && !IsPC())
  369. {
  370. M2_DELETE(party);
  371. }
  372. else
  373. {
  374. party->Unlink(this);
  375. if (!IsPC())
  376. party->Quit(GetVID());
  377. }
  378. SetParty(NULL); // ���ص� ���� �����ϰ�.
  379. }
  380. if (m_pkMobInst)
  381. {
  382. M2_DELETE(m_pkMobInst);
  383. m_pkMobInst = NULL;
  384. }
  385. m_pkMobData = NULL;
  386. if (m_pkSafebox)
  387. {
  388. M2_DELETE(m_pkSafebox);
  389. m_pkSafebox = NULL;
  390. }
  391. if (m_pkMall)
  392. {
  393. M2_DELETE(m_pkMall);
  394. m_pkMall = NULL;
  395. }
  396. m_set_pkChrSpawnedBy.clear();
  397. StopMuyeongEvent();
  398. event_cancel(&m_pkWarpNPCEvent);
  399. event_cancel(&m_pkRecoveryEvent);
  400. event_cancel(&m_pkDeadEvent);
  401. event_cancel(&m_pkSaveEvent);
  402. event_cancel(&m_pkTimedEvent);
  403. event_cancel(&m_pkStunEvent);
  404. event_cancel(&m_pkFishingEvent);
  405. event_cancel(&m_pkPoisonEvent);
  406. event_cancel(&m_pkFireEvent);
  407. event_cancel(&m_pkPartyRequestEvent);
  408. //DELAYED_WARP
  409. event_cancel(&m_pkWarpEvent);
  410. event_cancel(&m_pkCheckSpeedHackEvent);
  411. //END_DELAYED_WARP
  412. // RECALL_DELAY
  413. //event_cancel(&m_pkRecallEvent);
  414. // END_OF_RECALL_DELAY
  415. // MINING
  416. event_cancel(&m_pkMiningEvent);
  417. // END_OF_MINING
  418. StopHackShieldCheckCycle();
  419. for (itertype(m_mapMobSkillEvent) it = m_mapMobSkillEvent.begin(); it != m_mapMobSkillEvent.end(); ++it)
  420. {
  421. LPEVENT pkEvent = it->second;
  422. event_cancel(&pkEvent);
  423. }
  424. m_mapMobSkillEvent.clear();
  425. //event_cancel(&m_pkAffectEvent);
  426. ClearAffect();
  427. for (TMapBuffOnAttrs::iterator it = m_map_buff_on_attrs.begin(); it != m_map_buff_on_attrs.end(); it++)
  428. {
  429. if (NULL != it->second)
  430. {
  431. M2_DELETE(it->second);
  432. }
  433. }
  434. m_map_buff_on_attrs.clear();
  435. event_cancel(&m_pkDestroyWhenIdleEvent);
  436. if (m_pSkillLevels)
  437. {
  438. M2_DELETE_ARRAY(m_pSkillLevels);
  439. m_pSkillLevels = NULL;
  440. }
  441. CEntity::Destroy();
  442. if (GetSectree())
  443. GetSectree()->RemoveEntity(this);
  444. if (m_bMonsterLog)
  445. CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
  446. }
  447. const char * CHARACTER::GetName() const
  448. {
  449. return m_stName.empty() ? (m_pkMobData ? m_pkMobData->m_table.szLocaleName : "") : m_stName.c_str();
  450. }
  451. void CHARACTER::OpenMyShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount)
  452. {
  453. if (GetPart(PART_MAIN) > 2)
  454. {
  455. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("����� ����� ���� ���� �� �� �ֽ�ϴ�."));
  456. return;
  457. }
  458. if (GetMyShop()) // �̹� ���� ���� ����� �ݴ´�.
  459. {
  460. CloseMyShop();
  461. return;
  462. }
  463. // �������� ��Ʈ�� ����� ���� �� �� ���.
  464. quest::PC * pPC = quest::CQuestManager::instance().GetPCForce(GetPlayerID());
  465. // GetPCForce�� NULL�� �� ����Ƿ� ��� Ȯ������ ���
  466. if (pPC->IsRunning())
  467. return;
  468. if (bItemCount == 0)
  469. return;
  470. int64_t nTotalMoney = 0;
  471. for (int n = 0; n < bItemCount; ++n)
  472. {
  473. nTotalMoney += static_cast<int64_t>((pTable+n)->price);
  474. }
  475. nTotalMoney += static_cast<int64_t>(GetGold());
  476. if (GOLD_MAX <= nTotalMoney)
  477. {
  478. sys_err("[OVERFLOW_GOLD] Overflow (GOLD_MAX) id %u name %s", GetPlayerID(), GetName());
  479. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("20�� ��� �ʰ��Ͽ� ���� ���� ���ϴ�"));
  480. return;
  481. }
  482. char szSign[SHOP_SIGN_MAX_LEN+1];
  483. strlcpy(szSign, c_pszSign, sizeof(szSign));
  484. m_stShopSign = szSign;
  485. if (m_stShopSign.length() == 0)
  486. return;
  487. if (LC_IsCanada() == false)
  488. {
  489. if (CBanwordManager::instance().CheckString(m_stShopSign.c_str(), m_stShopSign.length()))
  490. {
  491. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("��Ӿ �� ���Ե� ��� �̸���� ���� �� �� ���ϴ�."));
  492. return;
  493. }
  494. }
  495. // MYSHOP_PRICE_LIST
  496. std::map<DWORD, DWORD> itemkind; // ������ ��� ����, first: vnum, second: ���� �� ����
  497. // END_OF_MYSHOP_PRICE_LIST
  498. std::set<TItemPos> cont;
  499. for (BYTE i = 0; i < bItemCount; ++i)
  500. {
  501. if (cont.find((pTable + i)->pos) != cont.end())
  502. {
  503. sys_err("MYSHOP: duplicate shop item detected! (name: %s)", GetName());
  504. return;
  505. }
  506. // ANTI_GIVE, ANTI_MYSHOP check
  507. LPITEM pkItem = GetItem((pTable + i)->pos);
  508. if (pkItem)
  509. {
  510. const TItemTable * item_table = pkItem->GetProto();
  511. if (item_table && (IS_SET(item_table->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MYSHOP)))
  512. {
  513. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("���ȭ ������� ���λ������ �Ǹ��� �� ���ϴ�."));
  514. return;
  515. }
  516. if (pkItem->GetType() == ITEM_WEAPON || pkItem->GetType() == ITEM_ARMOR || pkItem->GetType() == ITEM_BELT)
  517. {
  518. char szEventFlag[30];
  519. snprintf(szEventFlag, sizeof(szEventFlag), "%d.Engel", pkItem->GetID());
  520. if (*szEventFlag)
  521. {
  522. if (quest::CQuestManager::instance().GetEventFlag(szEventFlag))
  523. {
  524. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("item_engel"));
  525. return;
  526. }
  527. }
  528. }
  529. if (pkItem->IsEquipped() == true)
  530. {
  531. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������� ������� ���λ������ �Ǹ��� �� ���ϴ�."));
  532. return;
  533. }
  534. if (true == pkItem->isLocked())
  535. {
  536. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������� ������� ���λ������ �Ǹ��� �� ���ϴ�."));
  537. return;
  538. }
  539. // MYSHOP_PRICE_LIST
  540. itemkind[pkItem->GetVnum()] = (pTable + i)->price / pkItem->GetCount();
  541. // END_OF_MYSHOP_PRICE_LIST
  542. }
  543. cont.insert((pTable + i)->pos);
  544. }
  545. // MYSHOP_PRICE_LIST
  546. // ���� ���� ���ҽ�Ų��.
  547. if (CountSpecifyItem(71049)) { // ��� ����� ����� �ʰ� ��������� �����Ѵ�.
  548. //
  549. // ������ ��������� �����ϱ� ��� ������ ������� ��Ŷ� ����� DB ij�ÿ� ������.
  550. //
  551. TPacketMyshopPricelistHeader header;
  552. TItemPriceInfo info;
  553. header.dwOwnerID = GetPlayerID();
  554. header.byCount = itemkind.size();
  555. TEMP_BUFFER buf;
  556. buf.write(&header, sizeof(header));
  557. for (itertype(itemkind) it = itemkind.begin(); it != itemkind.end(); ++it)
  558. {
  559. info.dwVnum = it->first;
  560. info.dwPrice = it->second;
  561. buf.write(&info, sizeof(info));
  562. }
  563. db_clientdesc->DBPacket(HEADER_GD_MYSHOP_PRICELIST_UPDATE, 0, buf.read_peek(), buf.size());
  564. }
  565. // END_OF_MYSHOP_PRICE_LIST
  566. else if (CountSpecifyItem(50200))
  567. RemoveSpecifyItem(50200, 1);
  568. else
  569. return; // ���� ����� �ߴ�.
  570. if (m_pkExchange)
  571. m_pkExchange->Cancel();
  572. TPacketGCShopSign p;
  573. p.bHeader = HEADER_GC_SHOP_SIGN;
  574. p.dwVID = GetVID();
  575. strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  576. PacketAround(&p, sizeof(TPacketGCShopSign));
  577. m_pkMyShop = CShopManager::instance().CreatePCShop(this, pTable, bItemCount);
  578. if (IsPolymorphed() == true)
  579. {
  580. RemoveAffect(AFFECT_POLYMORPH);
  581. }
  582. if (GetHorse())
  583. {
  584. HorseSummon( false, true );
  585. }
  586. // new mount �̿� �߿�, ���� ��� ���� �ڵ� unmount
  587. // StopRiding��� ������Ʈ���� ó���ϸ� ����� �� �׷��� ���س���� �� �� ���.
  588. else if (GetMountVnum())
  589. {
  590. RemoveAffect(AFFECT_MOUNT);
  591. RemoveAffect(AFFECT_MOUNT_BONUS);
  592. }
  593. //if (!LC_IsNewCIBN())
  594. SetPolymorph(30000, true);
  595. }
  596. void CHARACTER::CloseMyShop()
  597. {
  598. if (GetMyShop())
  599. {
  600. m_stShopSign.clear();
  601. CShopManager::instance().DestroyPCShop(this);
  602. m_pkMyShop = NULL;
  603. TPacketGCShopSign p;
  604. p.bHeader = HEADER_GC_SHOP_SIGN;
  605. p.dwVID = GetVID();
  606. p.szSign[0] = '\0';
  607. PacketAround(&p, sizeof(p));
  608. //if (!LC_IsNewCIBN())
  609. SetPolymorph(GetJob(), true);
  610. }
  611. }
  612. void EncodeMovePacket(TPacketGCMove & pack, DWORD dwVID, BYTE bFunc, BYTE bArg, DWORD x, DWORD y, DWORD dwDuration, DWORD dwTime, BYTE bRot)
  613. {
  614. pack.bHeader = HEADER_GC_MOVE;
  615. pack.bFunc = bFunc;
  616. pack.bArg = bArg;
  617. pack.dwVID = dwVID;
  618. pack.dwTime = dwTime ? dwTime : get_dword_time();
  619. pack.bRot = bRot;
  620. pack.lX = x;
  621. pack.lY = y;
  622. pack.dwDuration = dwDuration;
  623. }
  624. void CHARACTER::RestartAtSamePos()
  625. {
  626. if (m_bIsObserver)
  627. return;
  628. EncodeRemovePacket(this);
  629. EncodeInsertPacket(this);
  630. ENTITY_MAP::iterator it = m_map_view.begin();
  631. while (it != m_map_view.end())
  632. {
  633. LPENTITY entity = (it++)->first;
  634. EncodeRemovePacket(entity);
  635. if (!m_bIsObserver)
  636. EncodeInsertPacket(entity);
  637. if( entity->IsType(ENTITY_CHARACTER) )
  638. {
  639. LPCHARACTER lpChar = (LPCHARACTER)entity;
  640. if( lpChar->IsPC() || lpChar->IsNPC() || lpChar->IsMonster() )
  641. {
  642. if (!entity->IsObserverMode())
  643. entity->EncodeInsertPacket(this);
  644. }
  645. }
  646. else
  647. {
  648. if( !entity->IsObserverMode())
  649. {
  650. entity->EncodeInsertPacket(this);
  651. }
  652. }
  653. }
  654. }
  655. // Entity�� ���� ��Ÿ���ٰ� ��Ŷ� ������.
  656. void CHARACTER::EncodeInsertPacket(LPENTITY entity)
  657. {
  658. LPDESC d;
  659. if (!(d = entity->GetDesc()))
  660. return;
  661. // ����̸� ��� ��� �ڵ�
  662. LPCHARACTER ch = (LPCHARACTER) entity;
  663. ch->SendGuildName(GetGuild());
  664. // ����̸� ��� ��� �ڵ�
  665. TPacketGCCharacterAdd pack;
  666. pack.header = HEADER_GC_CHARACTER_ADD;
  667. pack.dwVID = m_vid;
  668. pack.bType = GetCharType();
  669. pack.angle = GetRotation();
  670. pack.x = GetX();
  671. pack.y = GetY();
  672. pack.z = GetZ();
  673. pack.wRaceNum = GetRaceNum();
  674. if (IsPet())
  675. {
  676. pack.bMovingSpeed = 150;
  677. }
  678. else
  679. {
  680. pack.bMovingSpeed = GetLimitPoint(POINT_MOV_SPEED);
  681. }
  682. pack.bAttackSpeed = GetLimitPoint(POINT_ATT_SPEED);
  683. pack.dwAffectFlag[0] = m_afAffectFlag.bits[0];
  684. pack.dwAffectFlag[1] = m_afAffectFlag.bits[1];
  685. pack.bStateFlag = m_bAddChrState;
  686. int iDur = 0;
  687. if (m_posDest.x != pack.x || m_posDest.y != pack.y)
  688. {
  689. iDur = (m_dwMoveStartTime + m_dwMoveDuration) - get_dword_time();
  690. if (iDur <= 0)
  691. {
  692. pack.x = m_posDest.x;
  693. pack.y = m_posDest.y;
  694. }
  695. }
  696. d->Packet(&pack, sizeof(pack));
  697. if (IsPC() == true || m_bCharType == CHAR_TYPE_NPC)
  698. {
  699. TPacketGCCharacterAdditionalInfo addPacket;
  700. memset(&addPacket, 0, sizeof(TPacketGCCharacterAdditionalInfo));
  701. addPacket.header = HEADER_GC_CHAR_ADDITIONAL_INFO;
  702. addPacket.dwVID = m_vid;
  703. addPacket.awPart[CHR_EQUIPPART_ARMOR] = GetPart(PART_MAIN);
  704. addPacket.awPart[CHR_EQUIPPART_WEAPON] = GetPart(PART_WEAPON);
  705. addPacket.awPart[CHR_EQUIPPART_HEAD] = GetPart(PART_HEAD);
  706. addPacket.awPart[CHR_EQUIPPART_HAIR] = GetPart(PART_HAIR);
  707. addPacket.awPart[CHR_EQUIPPART_ACCE] = GetPart(PART_ACCE);
  708. addPacket.bPKMode = m_bPKMode;
  709. addPacket.dwMountVnum = GetMountVnum();
  710. addPacket.bEmpire = m_bEmpire;
  711. if (IsPC() == true && (LC_IsEurope() == true || LC_IsCanada() == true || LC_IsSingapore() == true))
  712. {
  713. addPacket.dwLevel = GetLevel();
  714. }
  715. else
  716. {
  717. addPacket.dwLevel = 0;
  718. }
  719. if (false)
  720. {
  721. LPCHARACTER ch = (LPCHARACTER) entity;
  722. if (GetEmpire() == ch->GetEmpire() || ch->GetGMLevel() > GM_PLAYER || m_bCharType == CHAR_TYPE_NPC)
  723. {
  724. goto show_all_info;
  725. }
  726. else
  727. {
  728. memset(addPacket.name, 0, CHARACTER_NAME_MAX_LEN);
  729. addPacket.dwGuildID = 0;
  730. addPacket.sAlignment = 0;
  731. }
  732. }
  733. else
  734. {
  735. show_all_info:
  736. strlcpy(addPacket.name, GetName(), sizeof(addPacket.name));
  737. if (GetGuild() != NULL)
  738. {
  739. addPacket.dwGuildID = GetGuild()->GetID();
  740. }
  741. else
  742. {
  743. addPacket.dwGuildID = 0;
  744. }
  745. addPacket.sAlignment = m_iAlignment / 10;
  746. }
  747. d->Packet(&addPacket, sizeof(TPacketGCCharacterAdditionalInfo));
  748. }
  749. if (iDur)
  750. {
  751. TPacketGCMove pack;
  752. EncodeMovePacket(pack, GetVID(), FUNC_MOVE, 0, m_posDest.x, m_posDest.y, iDur, 0, (BYTE) (GetRotation() / 5));
  753. d->Packet(&pack, sizeof(pack));
  754. TPacketGCWalkMode p;
  755. p.vid = GetVID();
  756. p.header = HEADER_GC_WALK_MODE;
  757. p.mode = m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  758. d->Packet(&p, sizeof(p));
  759. }
  760. if (entity->IsType(ENTITY_CHARACTER) && GetDesc())
  761. {
  762. LPCHARACTER ch = (LPCHARACTER) entity;
  763. if (ch->IsWalking())
  764. {
  765. TPacketGCWalkMode p;
  766. p.vid = ch->GetVID();
  767. p.header = HEADER_GC_WALK_MODE;
  768. p.mode = ch->m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  769. GetDesc()->Packet(&p, sizeof(p));
  770. }
  771. }
  772. if (GetMyShop())
  773. {
  774. TPacketGCShopSign p;
  775. p.bHeader = HEADER_GC_SHOP_SIGN;
  776. p.dwVID = GetVID();
  777. strlcpy(p.szSign, m_stShopSign.c_str(), sizeof(p.szSign));
  778. d->Packet(&p, sizeof(TPacketGCShopSign));
  779. }
  780. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  781. if (IsOfflineShopNPC() && GetRaceNum() == 30000)
  782. {
  783. TPacketGCShopSign p;
  784. p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  785. p.dwVID = GetVID();
  786. if (m_stOfflineShopSign.empty())
  787. {
  788. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT sign FROM player.offline_shop_npc WHERE owner_id = %u", GetOfflineShopRealOwner()));
  789. if (pMsg->Get()->uiNumRows > 0)
  790. {
  791. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  792. strlcpy(p.szSign, row[0], sizeof(p.szSign));
  793. }
  794. }
  795. else
  796. {
  797. strlcpy(p.szSign, m_stOfflineShopSign.c_str(), sizeof(p.szSign));
  798. }
  799. d->Packet(&p, sizeof(TPacketGCShopSign));
  800. }
  801. #endif
  802. if (entity->IsType(ENTITY_CHARACTER))
  803. {
  804. sys_log(3, "EntityInsert %s (RaceNum %d) (%d %d) TO %s",
  805. GetName(), GetRaceNum(), GetX() / SECTREE_SIZE, GetY() / SECTREE_SIZE, ((LPCHARACTER)entity)->GetName());
  806. }
  807. }
  808. void CHARACTER::EncodeRemovePacket(LPENTITY entity)
  809. {
  810. if (entity->GetType() != ENTITY_CHARACTER)
  811. return;
  812. LPDESC d;
  813. if (!(d = entity->GetDesc()))
  814. return;
  815. TPacketGCCharacterDelete pack;
  816. pack.header = HEADER_GC_CHARACTER_DEL;
  817. pack.id = m_vid;
  818. d->Packet(&pack, sizeof(TPacketGCCharacterDelete));
  819. if (entity->IsType(ENTITY_CHARACTER))
  820. sys_log(3, "EntityRemove %s(%d) FROM %s", GetName(), (DWORD) m_vid, ((LPCHARACTER) entity)->GetName());
  821. }
  822. void CHARACTER::UpdatePacket()
  823. {
  824. if (GetSectree() == NULL) return;
  825. TPacketGCCharacterUpdate pack;
  826. TPacketGCCharacterUpdate pack2;
  827. pack.header = HEADER_GC_CHARACTER_UPDATE;
  828. pack.dwVID = m_vid;
  829. pack.awPart[CHR_EQUIPPART_ARMOR] = GetPart(PART_MAIN);
  830. pack.awPart[CHR_EQUIPPART_WEAPON] = GetPart(PART_WEAPON);
  831. pack.awPart[CHR_EQUIPPART_HEAD] = GetPart(PART_HEAD);
  832. pack.awPart[CHR_EQUIPPART_HAIR] = GetPart(PART_HAIR);
  833. pack.awPart[CHR_EQUIPPART_ACCE] = GetPart(PART_ACCE);
  834. pack.bMovingSpeed = GetLimitPoint(POINT_MOV_SPEED);
  835. pack.bAttackSpeed = GetLimitPoint(POINT_ATT_SPEED);
  836. pack.bStateFlag = m_bAddChrState;
  837. pack.dwAffectFlag[0] = m_afAffectFlag.bits[0];
  838. pack.dwAffectFlag[1] = m_afAffectFlag.bits[1];
  839. pack.dwGuildID = 0;
  840. pack.sAlignment = m_iAlignment / 10;
  841. pack.dwLevel = GetLevel();
  842. pack.bPKMode = m_bPKMode;
  843. if (GetGuild())
  844. pack.dwGuildID = GetGuild()->GetID();
  845. pack.dwMountVnum = GetMountVnum();
  846. pack2 = pack;
  847. pack2.dwGuildID = 0;
  848. pack2.sAlignment = 0;
  849. if (false)
  850. {
  851. if (m_bIsObserver != true)
  852. {
  853. for (ENTITY_MAP::iterator iter = m_map_view.begin(); iter != m_map_view.end(); iter++)
  854. {
  855. LPENTITY pEntity = iter->first;
  856. if (pEntity != NULL)
  857. {
  858. if (pEntity->IsType(ENTITY_CHARACTER) == true)
  859. {
  860. if (pEntity->GetDesc() != NULL)
  861. {
  862. LPCHARACTER pChar = (LPCHARACTER)pEntity;
  863. if (GetEmpire() == pChar->GetEmpire() || pChar->GetGMLevel() > GM_PLAYER)
  864. {
  865. pEntity->GetDesc()->Packet(&pack, sizeof(pack));
  866. }
  867. else
  868. {
  869. pEntity->GetDesc()->Packet(&pack2, sizeof(pack2));
  870. }
  871. }
  872. }
  873. else
  874. {
  875. if (pEntity->GetDesc() != NULL)
  876. {
  877. pEntity->GetDesc()->Packet(&pack, sizeof(pack));
  878. }
  879. }
  880. }
  881. }
  882. }
  883. if (GetDesc() != NULL)
  884. {
  885. GetDesc()->Packet(&pack, sizeof(pack));
  886. }
  887. }
  888. else
  889. {
  890. PacketAround(&pack, sizeof(pack));
  891. }
  892. }
  893. LPCHARACTER CHARACTER::FindCharacterInView(const char * c_pszName, bool bFindPCOnly)
  894. {
  895. ENTITY_MAP::iterator it = m_map_view.begin();
  896. for (; it != m_map_view.end(); ++it)
  897. {
  898. if (!it->first->IsType(ENTITY_CHARACTER))
  899. continue;
  900. LPCHARACTER tch = (LPCHARACTER) it->first;
  901. if (bFindPCOnly && tch->IsNPC())
  902. continue;
  903. if (!strcasecmp(tch->GetName(), c_pszName))
  904. return (tch);
  905. }
  906. return NULL;
  907. }
  908. void CHARACTER::SetPosition(int pos)
  909. {
  910. if (pos == POS_STANDING)
  911. {
  912. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_DEAD);
  913. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_STUN);
  914. event_cancel(&m_pkDeadEvent);
  915. event_cancel(&m_pkStunEvent);
  916. }
  917. else if (pos == POS_DEAD)
  918. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_DEAD);
  919. if (!IsStone())
  920. {
  921. switch (pos)
  922. {
  923. case POS_FIGHTING:
  924. if (!IsState(m_stateBattle))
  925. MonsterLog("[BATTLE] �� ����");
  926. GotoState(m_stateBattle);
  927. break;
  928. default:
  929. if (!IsState(m_stateIdle))
  930. MonsterLog("[IDLE] ���� ����");
  931. GotoState(m_stateIdle);
  932. break;
  933. }
  934. }
  935. m_pointsInstant.position = pos;
  936. }
  937. void CHARACTER::Save()
  938. {
  939. if (!m_bSkipSave)
  940. CHARACTER_MANAGER::instance().DelayedSave(this);
  941. }
  942. void CHARACTER::CreatePlayerProto(TPlayerTable & tab)
  943. {
  944. memset(&tab, 0, sizeof(TPlayerTable));
  945. if (GetNewName().empty())
  946. {
  947. strlcpy(tab.name, GetName(), sizeof(tab.name));
  948. }
  949. else
  950. {
  951. strlcpy(tab.name, GetNewName().c_str(), sizeof(tab.name));
  952. }
  953. strlcpy(tab.ip, GetDesc()->GetHostName(), sizeof(tab.ip));
  954. tab.id = m_dwPlayerID;
  955. tab.voice = GetPoint(POINT_VOICE);
  956. tab.level = GetLevel();
  957. tab.level_step = GetPoint(POINT_LEVEL_STEP);
  958. tab.exp = GetExp();
  959. tab.gold = GetGold();
  960. tab.job = m_points.job;
  961. tab.part_base = m_pointsInstant.bBasePart;
  962. tab.skill_group = m_points.skill_group;
  963. DWORD dwPlayedTime = (get_dword_time() - m_dwPlayStartTime);
  964. if (dwPlayedTime > 60000)
  965. {
  966. if (GetSectree() && !GetSectree()->IsAttr(GetX(), GetY(), ATTR_BANPK))
  967. {
  968. if (GetRealAlignment() < 0)
  969. {
  970. if (IsEquipUniqueItem(UNIQUE_ITEM_FASTER_ALIGNMENT_UP_BY_TIME))
  971. UpdateAlignment(120 * (dwPlayedTime / 60000));
  972. else
  973. UpdateAlignment(60 * (dwPlayedTime / 60000));
  974. }
  975. else
  976. UpdateAlignment(5 * (dwPlayedTime / 60000));
  977. }
  978. SetRealPoint(POINT_PLAYTIME, GetRealPoint(POINT_PLAYTIME) + dwPlayedTime / 60000);
  979. ResetPlayTime(dwPlayedTime % 60000);
  980. }
  981. tab.playtime = GetRealPoint(POINT_PLAYTIME);
  982. tab.lAlignment = m_iRealAlignment;
  983. if (m_posWarp.x != 0 || m_posWarp.y != 0)
  984. {
  985. tab.x = m_posWarp.x;
  986. tab.y = m_posWarp.y;
  987. tab.z = 0;
  988. tab.lMapIndex = m_lWarpMapIndex;
  989. }
  990. else
  991. {
  992. tab.x = GetX();
  993. tab.y = GetY();
  994. tab.z = GetZ();
  995. tab.lMapIndex = GetMapIndex();
  996. }
  997. if (m_lExitMapIndex == 0)
  998. {
  999. tab.lExitMapIndex = tab.lMapIndex;
  1000. tab.lExitX = tab.x;
  1001. tab.lExitY = tab.y;
  1002. }
  1003. else
  1004. {
  1005. tab.lExitMapIndex = m_lExitMapIndex;
  1006. tab.lExitX = m_posExit.x;
  1007. tab.lExitY = m_posExit.y;
  1008. }
  1009. sys_log(0, "SAVE: %s %dx%d", GetName(), tab.x, tab.y);
  1010. tab.st = GetRealPoint(POINT_ST);
  1011. tab.ht = GetRealPoint(POINT_HT);
  1012. tab.dx = GetRealPoint(POINT_DX);
  1013. tab.iq = GetRealPoint(POINT_IQ);
  1014. tab.stat_point = GetPoint(POINT_STAT);
  1015. tab.skill_point = GetPoint(POINT_SKILL);
  1016. tab.sub_skill_point = GetPoint(POINT_SUB_SKILL);
  1017. tab.horse_skill_point = GetPoint(POINT_HORSE_SKILL);
  1018. tab.stat_reset_count = GetPoint(POINT_STAT_RESET_COUNT);
  1019. tab.hp = GetHP();
  1020. tab.sp = GetSP();
  1021. tab.stamina = GetStamina();
  1022. tab.sRandomHP = m_points.iRandomHP;
  1023. tab.sRandomSP = m_points.iRandomSP;
  1024. for (int i = 0; i < QUICKSLOT_MAX_NUM; ++i)
  1025. tab.quickslot[i] = m_quickslot[i];
  1026. if (m_stMobile.length() && !*m_szMobileAuth)
  1027. strlcpy(tab.szMobile, m_stMobile.c_str(), sizeof(tab.szMobile));
  1028. thecore_memcpy(tab.parts, m_pointsInstant.parts, sizeof(tab.parts));
  1029. // REMOVE_REAL_SKILL_LEVLES
  1030. thecore_memcpy(tab.skills, m_pSkillLevels, sizeof(TPlayerSkill) * SKILL_MAX_NUM);
  1031. // END_OF_REMOVE_REAL_SKILL_LEVLES
  1032. tab.horse = GetHorseData();
  1033. }
  1034. void CHARACTER::SaveReal()
  1035. {
  1036. if (m_bSkipSave)
  1037. return;
  1038. if (!GetDesc())
  1039. {
  1040. sys_err("Character::Save : no descriptor when saving (name: %s)", GetName());
  1041. return;
  1042. }
  1043. TPlayerTable table;
  1044. CreatePlayerProto(table);
  1045. db_clientdesc->DBPacket(HEADER_GD_PLAYER_SAVE, GetDesc()->GetHandle(), &table, sizeof(TPlayerTable));
  1046. quest::PC * pkQuestPC = quest::CQuestManager::instance().GetPCForce(GetPlayerID());
  1047. if (!pkQuestPC)
  1048. sys_err("CHARACTER::Save : null quest::PC pointer! (name %s)", GetName());
  1049. else
  1050. {
  1051. pkQuestPC->Save();
  1052. }
  1053. marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(GetPlayerID());
  1054. if (pMarriage)
  1055. pMarriage->Save();
  1056. }
  1057. void CHARACTER::FlushDelayedSaveItem()
  1058. {
  1059. // ���� �ȵ� ����ǰ� ��� �����Ų��.
  1060. LPITEM item;
  1061. for (int i = 0; i < INVENTORY_AND_EQUIP_SLOT_MAX; ++i)
  1062. if ((item = GetInventoryItem(i)))
  1063. ITEM_MANAGER::instance().FlushDelayedSave(item);
  1064. }
  1065. void CHARACTER::Disconnect(const char * c_pszReason)
  1066. {
  1067. assert(GetDesc() != NULL);
  1068. sys_log(0, "DISCONNECT: %s (%s)", GetName(), c_pszReason ? c_pszReason : "unset" );
  1069. if (GetShop())
  1070. {
  1071. GetShop()->RemoveGuest(this);
  1072. SetShop(NULL);
  1073. }
  1074. #ifdef ENABLE_OFFLINE_SHOP_SYSTEM
  1075. if (GetOfflineShop())
  1076. {
  1077. GetOfflineShop()->RemoveGuest(this);
  1078. SetOfflineShop(NULL);
  1079. }
  1080. #endif
  1081. if (GetArena() != NULL)
  1082. {
  1083. GetArena()->OnDisconnect(GetPlayerID());
  1084. }
  1085. if (GetParty() != NULL)
  1086. {
  1087. GetParty()->UpdateOfflineState(GetPlayerID());
  1088. }
  1089. marriage::CManager::instance().Logout(this);
  1090. // P2P Logout
  1091. TPacketGGLogout p;
  1092. p.bHeader = HEADER_GG_LOGOUT;
  1093. strlcpy(p.szName, GetName(), sizeof(p.szName));
  1094. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGLogout));
  1095. char buf[51];
  1096. snprintf(buf, sizeof(buf), "%s %d %d %ld %d",
  1097. inet_ntoa(GetDesc()->GetAddr().sin_addr), GetGold(), g_bChannel, GetMapIndex(), GetAlignment());
  1098. LogManager::instance().CharLog(this, 0, "LOGOUT", buf);
  1099. if (LC_IsYMIR() || LC_IsKorea() || LC_IsBrazil())
  1100. {
  1101. long playTime = GetRealPoint(POINT_PLAYTIME) - m_dwLoginPlayTime;
  1102. LogManager::instance().LoginLog(false, GetDesc()->GetAccountTable().id, GetPlayerID(), GetLevel(), GetJob(), playTime);
  1103. if (LC_IsBrazil() != true)
  1104. CPCBangManager::instance().Log(GetDesc()->GetHostName(), GetPlayerID(), playTime);
  1105. }
  1106. if (m_pWarMap)
  1107. SetWarMap(NULL);
  1108. if (m_pWeddingMap)
  1109. {
  1110. SetWeddingMap(NULL);
  1111. }
  1112. if (GetGuild())
  1113. GetGuild()->LogoutMember(this);
  1114. quest::CQuestManager::instance().LogoutPC(this);
  1115. if (GetParty())
  1116. GetParty()->Unlink(this);
  1117. // �׾�� �� ��Ӳ���� ����ġ �ٰ� �ϱ�
  1118. if (IsStun() || IsDead())
  1119. {
  1120. DeathPenalty(0);
  1121. PointChange(POINT_HP, 50 - GetHP());
  1122. }
  1123. if (!CHARACTER_MANAGER::instance().FlushDelayedSave(this))
  1124. {
  1125. SaveReal();
  1126. }
  1127. FlushDelayedSaveItem();
  1128. SaveAffect();
  1129. m_bIsLoadedAffect = false;
  1130. m_bSkipSave = true; // �� ���Ŀ��� ���̻� �����ϸ� �ȵȴ�.
  1131. quest::CQuestManager::instance().DisconnectPC(this);
  1132. CloseSafebox();
  1133. CloseMall();
  1134. CPVPManager::instance().Disconnect(this);
  1135. CTargetManager::instance().Logout(GetPlayerID());
  1136. MessengerManager::instance().Logout(GetName());
  1137. if (g_TeenDesc)
  1138. {
  1139. int offset = 0;
  1140. char buf[245] = {0};
  1141. buf[0] = HEADER_GT_LOGOUT;
  1142. offset += 1;
  1143. memset(buf+offset, 0x00, 2);
  1144. offset += 2;
  1145. TAccountTable &acc_table = GetDesc()->GetAccountTable();
  1146. memcpy(buf+offset, &acc_table.id, 4);
  1147. offset += 4;
  1148. g_TeenDesc->Packet(buf, offset);
  1149. }
  1150. if (GetDesc())
  1151. {
  1152. GetDesc()->BindCharacter(NULL);
  1153. // BindDesc(NULL);
  1154. }
  1155. CXTrapManager::instance().DestroyClientSession(this);
  1156. M2_DESTROY_CHARACTER(this);
  1157. }
  1158. bool CHARACTER::Show(long lMapIndex, long x, long y, long z, bool bShowSpawnMotion/* = false */)
  1159. {
  1160. LPSECTREE sectree = SECTREE_MANAGER::instance().Get(lMapIndex, x, y);
  1161. if (!sectree)
  1162. {
  1163. sys_log(0, "cannot find sectree by %dx%d mapindex %d", x, y, lMapIndex);
  1164. return false;
  1165. }
  1166. SetMapIndex(lMapIndex);
  1167. bool bChangeTree = false;
  1168. if (!GetSectree() || GetSectree() != sectree)
  1169. bChangeTree = true;
  1170. if (bChangeTree)
  1171. {
  1172. if (GetSectree())
  1173. GetSectree()->RemoveEntity(this);
  1174. ViewCleanup();
  1175. }
  1176. if (!IsNPC())
  1177. {
  1178. sys_log(0, "SHOW: %s %dx%dx%d", GetName(), x, y, z);
  1179. if (GetStamina() < GetMaxStamina())
  1180. StartAffectEvent();
  1181. }
  1182. else if (m_pkMobData)
  1183. {
  1184. m_pkMobInst->m_posLastAttacked.x = x;
  1185. m_pkMobInst->m_posLastAttacked.y = y;
  1186. m_pkMobInst->m_posLastAttacked.z = z;
  1187. }
  1188. if (bShowSpawnMotion)
  1189. {
  1190. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  1191. m_afAffectFlag.Set(AFF_SPAWN);
  1192. }
  1193. SetXYZ(x, y, z);
  1194. m_posDest.x = x;
  1195. m_posDest.y = y;
  1196. m_posDest.z = z;
  1197. m_posStart.x = x;
  1198. m_posStart.y = y;
  1199. m_posStart.z = z;
  1200. if (bChangeTree)
  1201. {
  1202. EncodeInsertPacket(this);
  1203. sectree->InsertEntity(this);
  1204. UpdateSectree();
  1205. }
  1206. else
  1207. {
  1208. ViewReencode();
  1209. sys_log(0, " in same sectree");
  1210. }
  1211. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  1212. SetValidComboInterval(0);
  1213. return true;
  1214. }
  1215. // BGM_INFO
  1216. struct BGMInfo
  1217. {
  1218. std::string name;
  1219. float vol;
  1220. };
  1221. typedef std::map<unsigned, BGMInfo> BGMInfoMap;
  1222. static BGMInfoMap gs_bgmInfoMap;
  1223. static bool gs_bgmVolEnable = false;
  1224. void CHARACTER_SetBGMVolumeEnable()
  1225. {
  1226. gs_bgmVolEnable = true;
  1227. sys_log(0, "bgm_info.set_bgm_volume_enable");
  1228. }
  1229. void CHARACTER_AddBGMInfo(unsigned mapIndex, const char* name, float vol)
  1230. {
  1231. BGMInfo newInfo;
  1232. newInfo.name = name;
  1233. newInfo.vol = vol;
  1234. gs_bgmInfoMap[mapIndex] = newInfo;
  1235. sys_log(0, "bgm_info.add_info(%d, '%s', %f)", mapIndex, name, vol);
  1236. }
  1237. const BGMInfo& CHARACTER_GetBGMInfo(unsigned mapIndex)
  1238. {
  1239. BGMInfoMap::iterator f = gs_bgmInfoMap.find(mapIndex);
  1240. if (gs_bgmInfoMap.end() == f)
  1241. {
  1242. static BGMInfo s_empty = {"", 0.0f};
  1243. return s_empty;
  1244. }
  1245. return f->second;
  1246. }
  1247. bool CHARACTER_IsBGMVolumeEnable()
  1248. {
  1249. return gs_bgmVolEnable;
  1250. }
  1251. // END_OF_BGM_INFO
  1252. void CHARACTER::MainCharacterPacket()
  1253. {
  1254. const unsigned mapIndex = GetMapIndex();
  1255. const BGMInfo& bgmInfo = CHARACTER_GetBGMInfo(mapIndex);
  1256. // SUPPORT_BGM
  1257. if (!bgmInfo.name.empty())
  1258. {
  1259. if (CHARACTER_IsBGMVolumeEnable())
  1260. {
  1261. sys_log(1, "bgm_info.play_bgm_vol(%d, name='%s', vol=%f)", mapIndex, bgmInfo.name.c_str(), bgmInfo.vol);
  1262. TPacketGCMainCharacter4_BGM_VOL mainChrPacket;
  1263. mainChrPacket.header = HEADER_GC_MAIN_CHARACTER4_BGM_VOL;
  1264. mainChrPacket.dwVID = m_vid;
  1265. mainChrPacket.wRaceNum = GetRaceNum();
  1266. mainChrPacket.lx = GetX();
  1267. mainChrPacket.ly = GetY();
  1268. mainChrPacket.lz = GetZ();
  1269. mainChrPacket.empire = GetDesc()->GetEmpire();
  1270. mainChrPacket.skill_group = GetSkillGroup();
  1271. strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
  1272. mainChrPacket.fBGMVol = bgmInfo.vol;
  1273. strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
  1274. GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter4_BGM_VOL));
  1275. }
  1276. else
  1277. {
  1278. sys_log(1, "bgm_info.play(%d, '%s')", mapIndex, bgmInfo.name.c_str());
  1279. TPacketGCMainCharacter3_BGM mainChrPacket;
  1280. mainChrPacket.header = HEADER_GC_MAIN_CHARACTER3_BGM;
  1281. mainChrPacket.dwVID = m_vid;
  1282. mainChrPacket.wRaceNum = GetRaceNum();
  1283. mainChrPacket.lx = GetX();
  1284. mainChrPacket.ly = GetY();
  1285. mainChrPacket.lz = GetZ();
  1286. mainChrPacket.empire = GetDesc()->GetEmpire();
  1287. mainChrPacket.skill_group = GetSkillGroup();
  1288. strlcpy(mainChrPacket.szChrName, GetName(), sizeof(mainChrPacket.szChrName));
  1289. strlcpy(mainChrPacket.szBGMName, bgmInfo.name.c_str(), sizeof(mainChrPacket.szBGMName));
  1290. GetDesc()->Packet(&mainChrPacket, sizeof(TPacketGCMainCharacter3_BGM));
  1291. }
  1292. //if (m_stMobile.length())
  1293. // ChatPacket(CHAT_TYPE_COMMAND, "sms");
  1294. }
  1295. // END_OF_SUPPORT_BGM
  1296. else
  1297. {
  1298. sys_log(0, "bgm_info.play(%d, DEFAULT_BGM_NAME)", mapIndex);
  1299. TPacketGCMainCharacter pack;
  1300. pack.header = HEADER_GC_MAIN_CHARACTER;
  1301. pack.dwVID = m_vid;
  1302. pack.wRaceNum = GetRaceNum();
  1303. pack.lx = GetX();
  1304. pack.ly = GetY();
  1305. pack.lz = GetZ();
  1306. pack.empire = GetDesc()->GetEmpire();
  1307. pack.skill_group = GetSkillGroup();
  1308. strlcpy(pack.szName, GetName(), sizeof(pack.szName));
  1309. GetDesc()->Packet(&pack, sizeof(TPacketGCMainCharacter));
  1310. if (m_stMobile.length())
  1311. ChatPacket(CHAT_TYPE_COMMAND, "sms");
  1312. }
  1313. }
  1314. void CHARACTER::PointsPacket()
  1315. {
  1316. if (!GetDesc())
  1317. return;
  1318. TPacketGCPoints pack;
  1319. pack.header = HEADER_GC_CHARACTER_POINTS;
  1320. pack.points[POINT_LEVEL] = GetLevel();
  1321. pack.points[POINT_EXP] = GetExp();
  1322. pack.points[POINT_NEXT_EXP] = GetNextExp();
  1323. pack.points[POINT_HP] = GetHP();
  1324. pack.points[POINT_MAX_HP] = GetMaxHP();
  1325. pack.points[POINT_SP] = GetSP();
  1326. pack.points[POINT_MAX_SP] = GetMaxSP();
  1327. pack.points[POINT_GOLD] = GetGold();
  1328. pack.points[POINT_STAMINA] = GetStamina();
  1329. pack.points[POINT_MAX_STAMINA] = GetMaxStamina();
  1330. for (int i = POINT_ST; i < POINT_MAX_NUM; ++i)
  1331. pack.points[i] = GetPoint(i);
  1332. GetDesc()->Packet(&pack, sizeof(TPacketGCPoints));
  1333. if (!IsAcceOpen())
  1334. {
  1335. LPITEM item;
  1336. for (int j = 0; j < INVENTORY_AND_EQUIP_SLOT_MAX; ++j)
  1337. {
  1338. if ((item = GetInventoryItem(j)))
  1339. if (item->GetType() == ITEM_COSTUME && item->GetSubType() == COSTUME_ACCE && item->GetSocket(0) == 1)
  1340. item->SetSocket(0, 0);
  1341. }
  1342. }
  1343. }
  1344. bool CHARACTER::ChangeSex()
  1345. {
  1346. int src_race = GetRaceNum();
  1347. switch (src_race)
  1348. {
  1349. case MAIN_RACE_WARRIOR_M:
  1350. m_points.job = MAIN_RACE_WARRIOR_W;
  1351. break;
  1352. case MAIN_RACE_WARRIOR_W:
  1353. m_points.job = MAIN_RACE_WARRIOR_M;
  1354. break;
  1355. case MAIN_RACE_ASSASSIN_M:
  1356. m_points.job = MAIN_RACE_ASSASSIN_W;
  1357. break;
  1358. case MAIN_RACE_ASSASSIN_W:
  1359. m_points.job = MAIN_RACE_ASSASSIN_M;
  1360. break;
  1361. case MAIN_RACE_SURA_M:
  1362. m_points.job = MAIN_RACE_SURA_W;
  1363. break;
  1364. case MAIN_RACE_SURA_W:
  1365. m_points.job = MAIN_RACE_SURA_M;
  1366. break;
  1367. case MAIN_RACE_SHAMAN_M:
  1368. m_points.job = MAIN_RACE_SHAMAN_W;
  1369. break;
  1370. case MAIN_RACE_SHAMAN_W:
  1371. m_points.job = MAIN_RACE_SHAMAN_M;
  1372. break;
  1373. default:
  1374. sys_err("CHANGE_SEX: %s unknown race %d", GetName(), src_race);
  1375. return false;
  1376. }
  1377. sys_log(0, "CHANGE_SEX: %s (%d -> %d)", GetName(), src_race, m_points.job);
  1378. return true;
  1379. }
  1380. WORD CHARACTER::GetRaceNum() const
  1381. {
  1382. if (m_dwPolymorphRace)
  1383. return m_dwPolymorphRace;
  1384. if (m_pkMobData)
  1385. return m_pkMobData->m_table.dwVnum;
  1386. return m_points.job;
  1387. }
  1388. void CHARACTER::SetRace(BYTE race)
  1389. {
  1390. if (race >= MAIN_RACE_MAX_NUM)
  1391. {
  1392. sys_err("CHARACTER::SetRace(name=%s, race=%d).OUT_OF_RACE_RANGE", GetName(), race);
  1393. return;
  1394. }
  1395. m_points.job = race;
  1396. }
  1397. BYTE CHARACTER::GetJob() const
  1398. {
  1399. unsigned race = m_points.job;
  1400. unsigned job;
  1401. if (RaceToJob(race, &job))
  1402. return job;
  1403. sys_err("CHARACTER::GetJob(name=%s, race=%d).OUT_OF_RACE_RANGE", GetName(), race);
  1404. return JOB_WARRIOR;
  1405. }
  1406. void CHARACTER::SetLevel(BYTE level)
  1407. {
  1408. m_points.level = level;
  1409. if (IsPC())
  1410. {
  1411. if (level < PK_PROTECT_LEVEL)
  1412. SetPKMode(PK_MODE_PROTECT);
  1413. else if (GetGMLevel() != GM_PLAYER)
  1414. SetPKMode(PK_MODE_PROTECT);
  1415. else if (m_bPKMode == PK_MODE_PROTECT)
  1416. SetPKMode(PK_MODE_PEACE);
  1417. }
  1418. }
  1419. void CHARACTER::SetEmpire(BYTE bEmpire)
  1420. {
  1421. m_bEmpire = bEmpire;
  1422. }
  1423. void CHARACTER::SetPlayerProto(const TPlayerTable * t)
  1424. {
  1425. if (!GetDesc() || !*GetDesc()->GetHostName())
  1426. sys_err("cannot get desc or hostname");
  1427. else
  1428. SetGMLevel();
  1429. m_bCharType = CHAR_TYPE_PC;
  1430. m_dwPlayerID = t->id;
  1431. m_iAlignment = t->lAlignment;
  1432. m_iRealAlignment = t->lAlignment;
  1433. m_points.voice = t->voice;
  1434. m_points.skill_group = t->skill_group;
  1435. m_pointsInstant.bBasePart = t->part_base;
  1436. SetPart(PART_HAIR, t->parts[PART_HAIR]);
  1437. SetPart(PART_ACCE, t->parts[PART_ACCE]);
  1438. m_points.iRandomHP = t->sRandomHP;
  1439. m_points.iRandomSP = t->sRandomSP;
  1440. // REMOVE_REAL_SKILL_LEVLES
  1441. if (m_pSkillLevels)
  1442. M2_DELETE_ARRAY(m_pSkillLevels);
  1443. m_pSkillLevels = M2_NEW TPlayerSkill[SKILL_MAX_NUM];
  1444. thecore_memcpy(m_pSkillLevels, t->skills, sizeof(TPlayerSkill) * SKILL_MAX_NUM);
  1445. // END_OF_REMOVE_REAL_SKILL_LEVLES
  1446. if (t->lMapIndex >= 10000)
  1447. {
  1448. m_posWarp.x = t->lExitX;
  1449. m_posWarp.y = t->lExitY;
  1450. m_lWarpMapIndex = t->lExitMapIndex;
  1451. }
  1452. SetRealPoint(POINT_PLAYTIME, t->playtime);
  1453. m_dwLoginPlayTime = t->playtime;
  1454. SetRealPoint(POINT_ST, t->st);
  1455. SetRealPoint(POINT_HT, t->ht);
  1456. SetRealPoint(POINT_DX, t->dx);
  1457. SetRealPoint(POINT_IQ, t->iq);
  1458. SetPoint(POINT_ST, t->st);
  1459. SetPoint(POINT_HT, t->ht);
  1460. SetPoint(POINT_DX, t->dx);
  1461. SetPoint(POINT_IQ, t->iq);
  1462. SetPoint(POINT_STAT, t->stat_point);
  1463. SetPoint(POINT_SKILL, t->skill_point);
  1464. SetPoint(POINT_SUB_SKILL, t->sub_skill_point);
  1465. SetPoint(POINT_HORSE_SKILL, t->horse_skill_point);
  1466. SetPoint(POINT_STAT_RESET_COUNT, t->stat_reset_count);
  1467. SetPoint(POINT_LEVEL_STEP, t->level_step);
  1468. SetRealPoint(POINT_LEVEL_STEP, t->level_step);
  1469. SetRace(t->job);
  1470. SetLevel(t->level);
  1471. SetExp(t->exp);
  1472. SetGold(t->gold);
  1473. SetMapIndex(t->lMapIndex);
  1474. SetXYZ(t->x, t->y, t->z);
  1475. ComputePoints();
  1476. SetHP(GetMaxHP());
  1477. SetSP(GetMaxSP());
  1478. SetStamina(t->stamina);
  1479. //GM�϶� ��ȣ���
  1480. if (!test_server)
  1481. {
  1482. if (GetGMLevel() > GM_LOW_WIZARD)
  1483. {
  1484. m_afAffectFlag.Set(AFF_YMIR);
  1485. m_bPKMode = PK_MODE_PROTECT;
  1486. }
  1487. }
  1488. if (GetLevel() < PK_PROTECT_LEVEL)
  1489. m_bPKMode = PK_MODE_PROTECT;
  1490. m_stMobile = t->szMobile;
  1491. SetHorseData(t->horse);
  1492. if (GetHorseLevel() > 0)
  1493. UpdateHorseDataByLogoff(t->logoff_interval);
  1494. thecore_memcpy(m_aiPremiumTimes, t->aiPremiumTimes, sizeof(t->aiPremiumTimes));
  1495. m_dwLogOffInterval = t->logoff_interval;
  1496. 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);
  1497. if (GetGMLevel() != GM_PLAYER)
  1498. {
  1499. LogManager::instance().CharLog(this, GetGMLevel(), "GM_LOGIN", "");
  1500. sys_log(0, "GM_LOGIN(gmlevel=%d, name=%s(%d), pos=(%d, %d)", GetGMLevel(), GetName(), GetPlayerID(), GetX(), GetY());
  1501. }
  1502. #ifdef __PET_SYSTEM__
  1503. // NOTE: �ϴ� ij���Ͱ� PC�� ��쿡�� PetSystem� ������ ��. ��� �ӽŴ� �޸� ����� NPC���� �ϱ� �..
  1504. if (m_petSystem)
  1505. {
  1506. m_petSystem->Destroy();
  1507. delete m_petSystem;
  1508. }
  1509. m_petSystem = M2_NEW CPetSystem(this);
  1510. #endif
  1511. }
  1512. EVENTFUNC(kill_ore_load_event)
  1513. {
  1514. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  1515. if ( info == NULL )
  1516. {
  1517. sys_err( "kill_ore_load_even> <Factor> Null pointer" );
  1518. return 0;
  1519. }
  1520. LPCHARACTER ch = info->ch;
  1521. if (ch == NULL) { // <Factor>
  1522. return 0;
  1523. }
  1524. ch->m_pkMiningEvent = NULL;
  1525. M2_DESTROY_CHARACTER(ch);
  1526. return 0;
  1527. }
  1528. void CHARACTER::SetProto(const CMob * pkMob)
  1529. {
  1530. if (m_pkMobInst)
  1531. M2_DELETE(m_pkMobInst);
  1532. m_pkMobData = pkMob;
  1533. m_pkMobInst = M2_NEW CMobInstance;
  1534. m_bPKMode = PK_MODE_FREE;
  1535. const TMobTable * t = &m_pkMobData->m_table;
  1536. m_bCharType = t->bType;
  1537. SetLevel(t->bLevel);
  1538. SetEmpire(t->bEmpire);
  1539. SetExp(t->dwExp);
  1540. SetRealPoint(POINT_ST, t->bStr);
  1541. SetRealPoint(POINT_DX, t->bDex);
  1542. SetRealPoint(POINT_HT, t->bCon);
  1543. SetRealPoint(POINT_IQ, t->bInt);
  1544. ComputePoints();
  1545. SetHP(GetMaxHP());
  1546. SetSP(GetMaxSP());
  1547. ////////////////////
  1548. m_pointsInstant.dwAIFlag = t->dwAIFlag;
  1549. SetImmuneFlag(t->dwImmuneFlag);
  1550. AssignTriggers(t);
  1551. ApplyMobAttribute(t);
  1552. if (IsStone())
  1553. {
  1554. DetermineDropMetinStone();
  1555. }
  1556. if (IsWarp() || IsGoto())
  1557. {
  1558. StartWarpNPCEvent();
  1559. }
  1560. CHARACTER_MANAGER::instance().RegisterRaceNumMap(this);
  1561. // XXX X-mas santa hardcoding
  1562. if (GetRaceNum() == xmas::MOB_SANTA_VNUM)
  1563. {
  1564. SetPoint(POINT_ATT_GRADE_BONUS, 10);
  1565. if (g_iUseLocale)
  1566. SetPoint(POINT_DEF_GRADE_BONUS, 6);
  1567. else
  1568. SetPoint(POINT_DEF_GRADE_BONUS, 15);
  1569. //��Ÿ��
  1570. //m_dwPlayStartTime = get_dword_time() + 10 * 60 * 1000;
  1571. //�ż��� ����
  1572. m_dwPlayStartTime = get_dword_time() + 30 * 1000;
  1573. if (test_server)
  1574. m_dwPlayStartTime = get_dword_time() + 30 * 1000;
  1575. }
  1576. // XXX CTF GuildWar hardcoding
  1577. if (warmap::IsWarFlag(GetRaceNum()))
  1578. {
  1579. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  1580. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  1581. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlag, &CHARACTER::EndStateEmpty);
  1582. }
  1583. if (warmap::IsWarFlagBase(GetRaceNum()))
  1584. {
  1585. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  1586. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  1587. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateFlagBase, &CHARACTER::EndStateEmpty);
  1588. }
  1589. if (m_bCharType == CHAR_TYPE_HORSE ||
  1590. GetRaceNum() == 20101 ||
  1591. GetRaceNum() == 20102 ||
  1592. GetRaceNum() == 20103 ||
  1593. GetRaceNum() == 20104 ||
  1594. GetRaceNum() == 20105 ||
  1595. GetRaceNum() == 20106 ||
  1596. GetRaceNum() == 20107 ||
  1597. GetRaceNum() == 20108 ||
  1598. GetRaceNum() == 20109
  1599. )
  1600. {
  1601. m_stateIdle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateHorse, &CHARACTER::EndStateEmpty);
  1602. m_stateMove.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateMove, &CHARACTER::EndStateEmpty);
  1603. m_stateBattle.Set(this, &CHARACTER::BeginStateEmpty, &CHARACTER::StateHorse, &CHARACTER::EndStateEmpty);
  1604. }
  1605. // MINING
  1606. if (mining::IsVeinOfOre (GetRaceNum()))
  1607. {
  1608. char_event_info* info = AllocEventInfo<char_event_info>();
  1609. info->ch = this;
  1610. m_pkMiningEvent = event_create(kill_ore_load_event, info, PASSES_PER_SEC(number(7 * 60, 15 * 60)));
  1611. }
  1612. SetOfflineShopVID(COfflineShopManager::instance().FindMyOfflineShop(GetPlayerID()));
  1613. // END_OF_MINING
  1614. }
  1615. const TMobTable & CHARACTER::GetMobTable() const
  1616. {
  1617. return m_pkMobData->m_table;
  1618. }
  1619. bool CHARACTER::IsRaceFlag(DWORD dwBit) const
  1620. {
  1621. return m_pkMobData ? IS_SET(m_pkMobData->m_table.dwRaceFlag, dwBit) : 0;
  1622. }
  1623. DWORD CHARACTER::GetMobDamageMin() const
  1624. {
  1625. return m_pkMobData->m_table.dwDamageRange[0];
  1626. }
  1627. DWORD CHARACTER::GetMobDamageMax() const
  1628. {
  1629. return m_pkMobData->m_table.dwDamageRange[1];
  1630. }
  1631. float CHARACTER::GetMobDamageMultiply() const
  1632. {
  1633. float fDamMultiply = GetMobTable().fDamMultiply;
  1634. if (IsBerserk())
  1635. fDamMultiply = fDamMultiply * 2.0f; // BALANCE: ����ȭ �� �ι�
  1636. return fDamMultiply;
  1637. }
  1638. DWORD CHARACTER::GetMobDropItemVnum() const
  1639. {
  1640. return m_pkMobData->m_table.dwDropItemVnum;
  1641. }
  1642. bool CHARACTER::IsSummonMonster() const
  1643. {
  1644. return GetSummonVnum() != 0;
  1645. }
  1646. DWORD CHARACTER::GetSummonVnum() const
  1647. {
  1648. return m_pkMobData ? m_pkMobData->m_table.dwSummonVnum : 0;
  1649. }
  1650. DWORD CHARACTER::GetPolymorphItemVnum() const
  1651. {
  1652. return m_pkMobData ? m_pkMobData->m_table.dwPolymorphItemVnum : 0;
  1653. }
  1654. DWORD CHARACTER::GetMonsterDrainSPPoint() const
  1655. {
  1656. return m_pkMobData ? m_pkMobData->m_table.dwDrainSP : 0;
  1657. }
  1658. BYTE CHARACTER::GetMobRank() const
  1659. {
  1660. if (!m_pkMobData)
  1661. return MOB_RANK_KNIGHT; // PC�� ��� KNIGHT��
  1662. return m_pkMobData->m_table.bRank;
  1663. }
  1664. BYTE CHARACTER::GetMobSize() const
  1665. {
  1666. if (!m_pkMobData)
  1667. return MOBSIZE_MEDIUM;
  1668. return m_pkMobData->m_table.bSize;
  1669. }
  1670. WORD CHARACTER::GetMobAttackRange() const
  1671. {
  1672. switch (GetMobBattleType())
  1673. {
  1674. case BATTLE_TYPE_RANGE:
  1675. case BATTLE_TYPE_MAGIC:
  1676. return m_pkMobData->m_table.wAttackRange + GetPoint(POINT_BOW_DISTANCE);
  1677. default:
  1678. return m_pkMobData->m_table.wAttackRange;
  1679. }
  1680. }
  1681. BYTE CHARACTER::GetMobBattleType() const
  1682. {
  1683. if (!m_pkMobData)
  1684. return BATTLE_TYPE_MELEE;
  1685. return (m_pkMobData->m_table.bBattleType);
  1686. }
  1687. void CHARACTER::ComputeBattlePoints()
  1688. {
  1689. if (IsPolymorphed())
  1690. {
  1691. DWORD dwMobVnum = GetPolymorphVnum();
  1692. const CMob * pMob = CMobManager::instance().Get(dwMobVnum);
  1693. int iAtt = 0;
  1694. int iDef = 0;
  1695. if (pMob)
  1696. {
  1697. iAtt = GetLevel() * 2 + GetPolymorphPoint(POINT_ST) * 2;
  1698. // lev + con
  1699. iDef = GetLevel() + GetPolymorphPoint(POINT_HT) + pMob->m_table.wDef;
  1700. }
  1701. SetPoint(POINT_ATT_GRADE, iAtt);
  1702. SetPoint(POINT_DEF_GRADE, iDef);
  1703. SetPoint(POINT_MAGIC_ATT_GRADE, GetPoint(POINT_ATT_GRADE));
  1704. SetPoint(POINT_MAGIC_DEF_GRADE, GetPoint(POINT_DEF_GRADE));
  1705. }
  1706. else if (IsPC())
  1707. {
  1708. SetPoint(POINT_ATT_GRADE, 0);
  1709. SetPoint(POINT_DEF_GRADE, 0);
  1710. SetPoint(POINT_CLIENT_DEF_GRADE, 0);
  1711. SetPoint(POINT_MAGIC_ATT_GRADE, GetPoint(POINT_ATT_GRADE));
  1712. SetPoint(POINT_MAGIC_DEF_GRADE, GetPoint(POINT_DEF_GRADE));
  1713. //
  1714. // �⺻ ATK = 2lev + 2str, ��� ���� 2str� �ٲ� �� ���
  1715. //
  1716. int iAtk = GetLevel() * 2;
  1717. int iStatAtk = 0;
  1718. switch (GetJob())
  1719. {
  1720. case JOB_WARRIOR:
  1721. case JOB_SURA:
  1722. iStatAtk = (2 * GetPoint(POINT_ST));
  1723. break;
  1724. case JOB_ASSASSIN:
  1725. iStatAtk = (4 * GetPoint(POINT_ST) + 2 * GetPoint(POINT_DX)) / 3;
  1726. break;
  1727. case JOB_SHAMAN:
  1728. iStatAtk = (4 * GetPoint(POINT_ST) + 2 * GetPoint(POINT_IQ)) / 3;
  1729. break;
  1730. default:
  1731. sys_err("invalid job %d", GetJob());
  1732. iStatAtk = (2 * GetPoint(POINT_ST));
  1733. break;
  1734. }
  1735. // ��� Ÿ�� �ְ�, ������� ���� ��ݷ��� ST*2 ���� ����� ST*2�� �Ѵ�.
  1736. // ����� �߸� ��� ��� ��ݷ��� �� ���� �ʰ� �ϱ� ��ؼ���.
  1737. if (GetMountVnum() && iStatAtk < 2 * GetPoint(POINT_ST))
  1738. iStatAtk = (2 * GetPoint(POINT_ST));
  1739. iAtk += iStatAtk;
  1740. // �¸�(��) : �˼�� ������ ����
  1741. if (GetMountVnum())
  1742. {
  1743. if (GetJob() == JOB_SURA && GetSkillGroup() == 1)
  1744. {
  1745. iAtk += (iAtk * GetHorseLevel()) / 60;
  1746. }
  1747. else
  1748. {
  1749. iAtk += (iAtk * GetHorseLevel()) / 30;
  1750. }
  1751. }
  1752. //
  1753. // ATK Setting
  1754. //
  1755. iAtk += GetPoint(POINT_ATT_GRADE_BONUS);
  1756. PointChange(POINT_ATT_GRADE, iAtk);
  1757. // DEF = LEV + CON + ARMOR
  1758. int iShowDef = GetLevel() + GetPoint(POINT_HT); // For Ymir(õ��)
  1759. int iDef = GetLevel() + (int) (GetPoint(POINT_HT) / 1.25); // For Other
  1760. int iArmor = 0;
  1761. LPITEM pkItem;
  1762. for (int i = 0; i < WEAR_MAX_NUM; ++i)
  1763. if ((pkItem = GetWear(i)) && pkItem->GetType() == ITEM_ARMOR)
  1764. {
  1765. if (pkItem->GetSubType() == ARMOR_BODY || pkItem->GetSubType() == ARMOR_HEAD || pkItem->GetSubType() == ARMOR_FOOTS || pkItem->GetSubType() == ARMOR_SHIELD)
  1766. {
  1767. iArmor += pkItem->GetValue(1);
  1768. iArmor += (2 * pkItem->GetValue(5));
  1769. }
  1770. }
  1771. // �� Ÿ�� ��� �� ������ ���� ���� ���º��� ����� ���� ������� ���
  1772. if( true == IsHorseRiding() )
  1773. {
  1774. if (iArmor < GetHorseArmor())
  1775. iArmor = GetHorseArmor();
  1776. const char* pHorseName = CHorseNameManager::instance().GetHorseName(GetPlayerID());
  1777. if (pHorseName != NULL && strlen(pHorseName))
  1778. {
  1779. iArmor += 20;
  1780. }
  1781. }
  1782. iArmor += GetPoint(POINT_DEF_GRADE_BONUS);
  1783. iArmor += GetPoint(POINT_PARTY_DEFENDER_BONUS);
  1784. // INTERNATIONAL_VERSION
  1785. if (LC_IsYMIR())
  1786. {
  1787. PointChange(POINT_DEF_GRADE, iShowDef + iArmor);
  1788. }
  1789. else
  1790. {
  1791. PointChange(POINT_DEF_GRADE, iDef + iArmor);
  1792. PointChange(POINT_CLIENT_DEF_GRADE, (iShowDef + iArmor) - GetPoint(POINT_DEF_GRADE));
  1793. }
  1794. // END_OF_INTERNATIONAL_VERSION
  1795. PointChange(POINT_MAGIC_ATT_GRADE, GetLevel() * 2 + GetPoint(POINT_IQ) * 2 + GetPoint(POINT_MAGIC_ATT_GRADE_BONUS));
  1796. PointChange(POINT_MAGIC_DEF_GRADE, GetLevel() + (GetPoint(POINT_IQ) * 3 + GetPoint(POINT_HT)) / 3 + iArmor / 2 + GetPoint(POINT_MAGIC_DEF_GRADE_BONUS));
  1797. }
  1798. else
  1799. {
  1800. // 2lev + str * 2
  1801. int iAtt = GetLevel() * 2 + GetPoint(POINT_ST) * 2;
  1802. // lev + con
  1803. int iDef = GetLevel() + GetPoint(POINT_HT) + GetMobTable().wDef;
  1804. SetPoint(POINT_ATT_GRADE, iAtt);
  1805. SetPoint(POINT_DEF_GRADE, iDef);
  1806. SetPoint(POINT_MAGIC_ATT_GRADE, GetPoint(POINT_ATT_GRADE));
  1807. SetPoint(POINT_MAGIC_DEF_GRADE, GetPoint(POINT_DEF_GRADE));
  1808. }
  1809. }
  1810. void CHARACTER::ComputePoints()
  1811. {
  1812. long lStat = GetPoint(POINT_STAT);
  1813. long lStatResetCount = GetPoint(POINT_STAT_RESET_COUNT);
  1814. long lSkillActive = GetPoint(POINT_SKILL);
  1815. long lSkillSub = GetPoint(POINT_SUB_SKILL);
  1816. long lSkillHorse = GetPoint(POINT_HORSE_SKILL);
  1817. long lLevelStep = GetPoint(POINT_LEVEL_STEP);
  1818. long lAttackerBonus = GetPoint(POINT_PARTY_ATTACKER_BONUS);
  1819. long lTankerBonus = GetPoint(POINT_PARTY_TANKER_BONUS);
  1820. long lBufferBonus = GetPoint(POINT_PARTY_BUFFER_BONUS);
  1821. long lSkillMasterBonus = GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  1822. long lHasteBonus = GetPoint(POINT_PARTY_HASTE_BONUS);
  1823. long lDefenderBonus = GetPoint(POINT_PARTY_DEFENDER_BONUS);
  1824. long lHPRecovery = GetPoint(POINT_HP_RECOVERY);
  1825. long lSPRecovery = GetPoint(POINT_SP_RECOVERY);
  1826. memset(m_pointsInstant.points, 0, sizeof(m_pointsInstant.points));
  1827. BuffOnAttr_ClearAll();
  1828. m_SkillDamageBonus.clear();
  1829. SetPoint(POINT_STAT, lStat);
  1830. SetPoint(POINT_SKILL, lSkillActive);
  1831. SetPoint(POINT_SUB_SKILL, lSkillSub);
  1832. SetPoint(POINT_HORSE_SKILL, lSkillHorse);
  1833. SetPoint(POINT_LEVEL_STEP, lLevelStep);
  1834. SetPoint(POINT_STAT_RESET_COUNT, lStatResetCount);
  1835. SetPoint(POINT_ST, GetRealPoint(POINT_ST));
  1836. SetPoint(POINT_HT, GetRealPoint(POINT_HT));
  1837. SetPoint(POINT_DX, GetRealPoint(POINT_DX));
  1838. SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
  1839. SetPart(PART_MAIN, GetOriginalPart(PART_MAIN));
  1840. SetPart(PART_WEAPON, GetOriginalPart(PART_WEAPON));
  1841. SetPart(PART_HEAD, GetOriginalPart(PART_HEAD));
  1842. SetPart(PART_HAIR, GetOriginalPart(PART_HAIR));
  1843. SetPart(PART_ACCE, GetOriginalPart(PART_ACCE));
  1844. SetPoint(POINT_PARTY_ATTACKER_BONUS, lAttackerBonus);
  1845. SetPoint(POINT_PARTY_TANKER_BONUS, lTankerBonus);
  1846. SetPoint(POINT_PARTY_BUFFER_BONUS, lBufferBonus);
  1847. SetPoint(POINT_PARTY_SKILL_MASTER_BONUS, lSkillMasterBonus);
  1848. SetPoint(POINT_PARTY_HASTE_BONUS, lHasteBonus);
  1849. SetPoint(POINT_PARTY_DEFENDER_BONUS, lDefenderBonus);
  1850. SetPoint(POINT_HP_RECOVERY, lHPRecovery);
  1851. SetPoint(POINT_SP_RECOVERY, lSPRecovery);
  1852. // PC_BANG_ITEM_ADD
  1853. SetPoint(POINT_PC_BANG_EXP_BONUS, 0);
  1854. SetPoint(POINT_PC_BANG_DROP_BONUS, 0);
  1855. // END_PC_BANG_ITEM_ADD
  1856. int iMaxHP, iMaxSP;
  1857. int iMaxStamina;
  1858. if (IsPC())
  1859. {
  1860. // �ִ� ����/��ŷ�
  1861. iMaxHP = JobInitialPoints[GetJob()].max_hp + m_points.iRandomHP + GetPoint(POINT_HT) * JobInitialPoints[GetJob()].hp_per_ht;
  1862. iMaxSP = JobInitialPoints[GetJob()].max_sp + m_points.iRandomSP + GetPoint(POINT_IQ) * JobInitialPoints[GetJob()].sp_per_iq;
  1863. iMaxStamina = JobInitialPoints[GetJob()].max_stamina + GetPoint(POINT_HT) * JobInitialPoints[GetJob()].stamina_per_con;
  1864. {
  1865. CSkillProto* pkSk = CSkillManager::instance().Get(SKILL_ADD_HP);
  1866. if (NULL != pkSk)
  1867. {
  1868. pkSk->SetPointVar("k", 1.0f * GetSkillPower(SKILL_ADD_HP) / 100.0f);
  1869. iMaxHP += static_cast<int>(pkSk->kPointPoly.Eval());
  1870. }
  1871. }
  1872. // �⺻ ����
  1873. SetPoint(POINT_MOV_SPEED, 100);
  1874. SetPoint(POINT_ATT_SPEED, 100);
  1875. PointChange(POINT_ATT_SPEED, GetPoint(POINT_PARTY_HASTE_BONUS));
  1876. SetPoint(POINT_CASTING_SPEED, 100);
  1877. }
  1878. else
  1879. {
  1880. iMaxHP = m_pkMobData->m_table.dwMaxHP;
  1881. iMaxSP = 0;
  1882. iMaxStamina = 0;
  1883. SetPoint(POINT_ATT_SPEED, m_pkMobData->m_table.sAttackSpeed);
  1884. SetPoint(POINT_MOV_SPEED, m_pkMobData->m_table.sMovingSpeed);
  1885. SetPoint(POINT_CASTING_SPEED, m_pkMobData->m_table.sAttackSpeed);
  1886. }
  1887. if (IsPC())
  1888. {
  1889. // �� Ÿ�� ��� ���� �⺻ ������ ���� ���� ���Ⱥ��� ����� ��� �����.
  1890. // ��� ���� ���� ������ ���� �����̹Ƿ�, ���/����� ��ü ���� ����
  1891. // ��ä����� �� �ö󰡰� �� ���̴�.
  1892. if (GetMountVnum())
  1893. {
  1894. if (GetHorseST() > GetPoint(POINT_ST))
  1895. PointChange(POINT_ST, GetHorseST() - GetPoint(POINT_ST));
  1896. if (GetHorseDX() > GetPoint(POINT_DX))
  1897. PointChange(POINT_DX, GetHorseDX() - GetPoint(POINT_DX));
  1898. if (GetHorseHT() > GetPoint(POINT_HT))
  1899. PointChange(POINT_HT, GetHorseHT() - GetPoint(POINT_HT));
  1900. if (GetHorseIQ() > GetPoint(POINT_IQ))
  1901. PointChange(POINT_IQ, GetHorseIQ() - GetPoint(POINT_IQ));
  1902. }
  1903. }
  1904. ComputeBattlePoints();
  1905. // �⺻ HP/SP ���
  1906. if (iMaxHP != GetMaxHP())
  1907. {
  1908. SetRealPoint(POINT_MAX_HP, iMaxHP); // �⺻HP�� RealPoint�� ������ ��´�.
  1909. }
  1910. PointChange(POINT_MAX_HP, 0);
  1911. if (iMaxSP != GetMaxSP())
  1912. {
  1913. SetRealPoint(POINT_MAX_SP, iMaxSP); // �⺻SP�� RealPoint�� ������ ��´�.
  1914. }
  1915. PointChange(POINT_MAX_SP, 0);
  1916. SetMaxStamina(iMaxStamina);
  1917. m_pointsInstant.dwImmuneFlag = 0;
  1918. for (int i = 0 ; i < WEAR_MAX_NUM; i++)
  1919. {
  1920. LPITEM pItem = GetWear(i);
  1921. if (pItem)
  1922. {
  1923. pItem->ModifyPoints(true);
  1924. SET_BIT(m_pointsInstant.dwImmuneFlag, GetWear(i)->GetImmuneFlag());
  1925. }
  1926. }
  1927. // ��ȥ�� �ý���
  1928. // ComputePoints������ �ɸ����� ��� �Ӽ���� �ʱ�ȭ�ϰ�,
  1929. // ������, ���� � ��õ� ��� �Ӽ���� �����ϱ� ������,
  1930. // ��ȥ�� �ý��۵� ActiveDeck�� �ִ� ��� ��ȥ���� �Ӽ���� �ٽ� �����Ѿ� �Ѵ�.
  1931. if (DragonSoul_IsDeckActivated())
  1932. {
  1933. for (int i = WEAR_MAX_NUM + DS_SLOT_MAX * DragonSoul_GetActiveDeck();
  1934. i < WEAR_MAX_NUM + DS_SLOT_MAX * (DragonSoul_GetActiveDeck() + 1); i++)
  1935. {
  1936. LPITEM pItem = GetWear(i);
  1937. if (pItem)
  1938. {
  1939. if (DSManager::instance().IsTimeLeftDragonSoul(pItem))
  1940. pItem->ModifyPoints(true);
  1941. }
  1942. }
  1943. }
  1944. if (GetHP() > GetMaxHP())
  1945. PointChange(POINT_HP, GetMaxHP() - GetHP());
  1946. if (GetSP() > GetMaxSP())
  1947. PointChange(POINT_SP, GetMaxSP() - GetSP());
  1948. ComputeSkillPoints();
  1949. RefreshAffect();
  1950. CPetSystem* pPetSystem = GetPetSystem();
  1951. if (NULL != pPetSystem)
  1952. {
  1953. pPetSystem->RefreshBuff();
  1954. }
  1955. for (TMapBuffOnAttrs::iterator it = m_map_buff_on_attrs.begin(); it != m_map_buff_on_attrs.end(); it++)
  1956. {
  1957. it->second->GiveAllAttributes();
  1958. }
  1959. UpdatePacket();
  1960. }
  1961. // m_dwPlayStartTime�� ����� milisecond��. �����ͺ��̽����� �д���� ����ϱ�
  1962. // ������ �÷��̽ð�� ����� �� / 60000 ��� ������ �ϴµ�, �� ������ ���� ����
  1963. // � �� ���⿡ dwTimeRemain��� �־ ���� ���ǵ��� ���־�� �Ѵ�.
  1964. void CHARACTER::ResetPlayTime(DWORD dwTimeRemain)
  1965. {
  1966. m_dwPlayStartTime = get_dword_time() - dwTimeRemain;
  1967. }
  1968. const int aiRecoveryPercents[10] = { 1, 5, 5, 5, 5, 5, 5, 5, 5, 5 };
  1969. EVENTFUNC(recovery_event)
  1970. {
  1971. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  1972. if ( info == NULL )
  1973. {
  1974. sys_err( "recovery_event> <Factor> Null pointer" );
  1975. return 0;
  1976. }
  1977. LPCHARACTER ch = info->ch;
  1978. if (ch == NULL) { // <Factor>
  1979. return 0;
  1980. }
  1981. if (!ch->IsPC())
  1982. {
  1983. //
  1984. // ���� ȸ��
  1985. //
  1986. if (ch->IsAffectFlag(AFF_POISON))
  1987. return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
  1988. if (2493 == ch->GetMobTable().dwVnum)
  1989. {
  1990. int regenPct = BlueDragon_GetRangeFactor("hp_regen", ch->GetHPPct());
  1991. regenPct += ch->GetMobTable().bRegenPercent;
  1992. for (int i=1 ; i <= 4 ; ++i)
  1993. {
  1994. if (REGEN_PECT_BONUS == BlueDragon_GetIndexFactor("DragonStone", i, "effect_type"))
  1995. {
  1996. DWORD dwDragonStoneID = BlueDragon_GetIndexFactor("DragonStone", i, "vnum");
  1997. size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val");
  1998. size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID );
  1999. regenPct += (val*cnt);
  2000. break;
  2001. }
  2002. }
  2003. ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * regenPct) / 100));
  2004. }
  2005. else if (!ch->IsDoor())
  2006. {
  2007. ch->MonsterLog("HP_REGEN +%d", MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
  2008. ch->PointChange(POINT_HP, MAX(1, (ch->GetMaxHP() * ch->GetMobTable().bRegenPercent) / 100));
  2009. }
  2010. if (ch->GetHP() >= ch->GetMaxHP())
  2011. {
  2012. ch->m_pkRecoveryEvent = NULL;
  2013. return 0;
  2014. }
  2015. if (2493 == ch->GetMobTable().dwVnum)
  2016. {
  2017. for (int i=1 ; i <= 4 ; ++i)
  2018. {
  2019. if (REGEN_TIME_BONUS == BlueDragon_GetIndexFactor("DragonStone", i, "effect_type"))
  2020. {
  2021. DWORD dwDragonStoneID = BlueDragon_GetIndexFactor("DragonStone", i, "vnum");
  2022. size_t val = BlueDragon_GetIndexFactor("DragonStone", i, "val");
  2023. size_t cnt = SECTREE_MANAGER::instance().GetMonsterCountInMap( ch->GetMapIndex(), dwDragonStoneID );
  2024. return PASSES_PER_SEC(MAX(1, (ch->GetMobTable().bRegenCycle - (val*cnt))));
  2025. }
  2026. }
  2027. }
  2028. return PASSES_PER_SEC(MAX(1, ch->GetMobTable().bRegenCycle));
  2029. }
  2030. else
  2031. {
  2032. //
  2033. // PC ȸ��
  2034. //
  2035. ch->CheckTarget();
  2036. //ch->UpdateSectree(); // ���⼭ �̰� ������?
  2037. ch->UpdateKillerMode();
  2038. if (ch->IsAffectFlag(AFF_POISON) == true)
  2039. {
  2040. // �ߵ��� ��� �ڵ�ȸ�� ����
  2041. // �Ĺ���� ��� �ڵ�ȸ�� ����
  2042. return 3;
  2043. }
  2044. int iSec = (get_dword_time() - ch->GetLastMoveTime()) / 3000;
  2045. // SP ȸ�� ��ƾ.
  2046. // �� �̰ɷ� �ؼ� �Լ�� ����°� ?!
  2047. ch->DistributeSP(ch);
  2048. if (ch->GetMaxHP() <= ch->GetHP())
  2049. return PASSES_PER_SEC(3);
  2050. int iPercent = 0;
  2051. int iAmount = 0;
  2052. {
  2053. iPercent = aiRecoveryPercents[MIN(9, iSec)];
  2054. iAmount = 15 + (ch->GetMaxHP() * iPercent) / 100;
  2055. }
  2056. iAmount += (iAmount * ch->GetPoint(POINT_HP_REGEN)) / 100;
  2057. sys_log(1, "RECOVERY_EVENT: %s %d HP_REGEN %d HP +%d", ch->GetName(), iPercent, ch->GetPoint(POINT_HP_REGEN), iAmount);
  2058. ch->PointChange(POINT_HP, iAmount, false);
  2059. return PASSES_PER_SEC(3);
  2060. }
  2061. }
  2062. void CHARACTER::StartRecoveryEvent()
  2063. {
  2064. if (m_pkRecoveryEvent)
  2065. return;
  2066. if (IsDead() || IsStun())
  2067. return;
  2068. if (IsNPC() && GetHP() >= GetMaxHP()) // ���ʹ� ü���� �� ������� ���� ���Ѵ�.
  2069. return;
  2070. char_event_info* info = AllocEventInfo<char_event_info>();
  2071. info->ch = this;
  2072. int iSec = IsPC() ? 3 : (MAX(1, GetMobTable().bRegenCycle));
  2073. m_pkRecoveryEvent = event_create(recovery_event, info, PASSES_PER_SEC(iSec));
  2074. }
  2075. void CHARACTER::Standup()
  2076. {
  2077. struct packet_position pack_position;
  2078. if (!IsPosition(POS_SITTING))
  2079. return;
  2080. SetPosition(POS_STANDING);
  2081. sys_log(1, "STANDUP: %s", GetName());
  2082. pack_position.header = HEADER_GC_CHARACTER_POSITION;
  2083. pack_position.vid = GetVID();
  2084. pack_position.position = POSITION_GENERAL;
  2085. PacketAround(&pack_position, sizeof(pack_position));
  2086. }
  2087. void CHARACTER::Sitdown(int is_ground)
  2088. {
  2089. struct packet_position pack_position;
  2090. if (IsPosition(POS_SITTING))
  2091. return;
  2092. SetPosition(POS_SITTING);
  2093. sys_log(1, "SITDOWN: %s", GetName());
  2094. pack_position.header = HEADER_GC_CHARACTER_POSITION;
  2095. pack_position.vid = GetVID();
  2096. pack_position.position = POSITION_SITTING_GROUND;
  2097. PacketAround(&pack_position, sizeof(pack_position));
  2098. }
  2099. void CHARACTER::SetRotation(float fRot)
  2100. {
  2101. m_pointsInstant.fRot = fRot;
  2102. }
  2103. // x, y ������� ���� ����.
  2104. void CHARACTER::SetRotationToXY(long x, long y)
  2105. {
  2106. SetRotation(GetDegreeFromPositionXY(GetX(), GetY(), x, y));
  2107. }
  2108. bool CHARACTER::CannotMoveByAffect() const
  2109. {
  2110. return (IsAffectFlag(AFF_STUN));
  2111. }
  2112. bool CHARACTER::CanMove() const
  2113. {
  2114. if (CannotMoveByAffect())
  2115. return false;
  2116. if (GetMyShop()) // ��� �� ���¿����� ������ �� ���
  2117. return false;
  2118. // 0.2�� ���̶�� ������ �� ���.
  2119. /*
  2120. if (get_float_time() - m_fSyncTime < 0.2f)
  2121. return false;
  2122. */
  2123. return true;
  2124. }
  2125. // ����� x, y �ġ�� �̵� ��Ų��.
  2126. bool CHARACTER::Sync(long x, long y)
  2127. {
  2128. if (!GetSectree())
  2129. return false;
  2130. LPSECTREE new_tree = SECTREE_MANAGER::instance().Get(GetMapIndex(), x, y);
  2131. if (!new_tree)
  2132. {
  2133. if (GetDesc())
  2134. {
  2135. sys_err("cannot find tree at %d %d (name: %s)", x, y, GetName());
  2136. GetDesc()->SetPhase(PHASE_CLOSE);
  2137. }
  2138. else
  2139. {
  2140. sys_err("no tree: %s %d %d %d", GetName(), x, y, GetMapIndex());
  2141. Dead();
  2142. }
  2143. return false;
  2144. }
  2145. SetRotationToXY(x, y);
  2146. SetXYZ(x, y, 0);
  2147. if (GetDungeon())
  2148. {
  2149. // ����� �̺�Ʈ �Ӽ� ��ȭ
  2150. int iLastEventAttr = m_iEventAttr;
  2151. m_iEventAttr = new_tree->GetEventAttribute(x, y);
  2152. if (m_iEventAttr != iLastEventAttr)
  2153. {
  2154. if (GetParty())
  2155. {
  2156. quest::CQuestManager::instance().AttrOut(GetParty()->GetLeaderPID(), this, iLastEventAttr);
  2157. quest::CQuestManager::instance().AttrIn(GetParty()->GetLeaderPID(), this, m_iEventAttr);
  2158. }
  2159. else
  2160. {
  2161. quest::CQuestManager::instance().AttrOut(GetPlayerID(), this, iLastEventAttr);
  2162. quest::CQuestManager::instance().AttrIn(GetPlayerID(), this, m_iEventAttr);
  2163. }
  2164. }
  2165. }
  2166. if (GetSectree() != new_tree)
  2167. {
  2168. if (!IsNPC())
  2169. {
  2170. SECTREEID id = new_tree->GetID();
  2171. SECTREEID old_id = GetSectree()->GetID();
  2172. sys_log(0, "SECTREE DIFFER: %s %dx%d was %dx%d",
  2173. GetName(),
  2174. id.coord.x,
  2175. id.coord.y,
  2176. old_id.coord.x,
  2177. old_id.coord.y);
  2178. }
  2179. new_tree->InsertEntity(this);
  2180. }
  2181. return true;
  2182. }
  2183. void CHARACTER::Stop()
  2184. {
  2185. if (!IsState(m_stateIdle))
  2186. MonsterLog("[IDLE] ���");
  2187. GotoState(m_stateIdle);
  2188. m_posDest.x = m_posStart.x = GetX();
  2189. m_posDest.y = m_posStart.y = GetY();
  2190. }
  2191. bool CHARACTER::Goto(long x, long y)
  2192. {
  2193. // TODO �Ÿ�üũ �ʿ�
  2194. // ��� �ġ�� �̵��� �ʿ� ��� (�ڵ� ����)
  2195. if (GetX() == x && GetY() == y)
  2196. return false;
  2197. if (m_posDest.x == x && m_posDest.y == y)
  2198. {
  2199. if (!IsState(m_stateMove))
  2200. {
  2201. m_dwStateDuration = 4;
  2202. GotoState(m_stateMove);
  2203. }
  2204. return false;
  2205. }
  2206. m_posDest.x = x;
  2207. m_posDest.y = y;
  2208. CalculateMoveDuration();
  2209. m_dwStateDuration = 4;
  2210. if (!IsState(m_stateMove))
  2211. {
  2212. MonsterLog("[MOVE] %s", GetVictim() ? "�������" : "�׳��̵�");
  2213. if (GetVictim())
  2214. {
  2215. //MonsterChat(MONSTER_CHAT_CHASE);
  2216. MonsterChat(MONSTER_CHAT_ATTACK);
  2217. }
  2218. }
  2219. GotoState(m_stateMove);
  2220. return true;
  2221. }
  2222. DWORD CHARACTER::GetMotionMode() const
  2223. {
  2224. DWORD dwMode = MOTION_MODE_GENERAL;
  2225. if (IsPolymorphed())
  2226. return dwMode;
  2227. LPITEM pkItem;
  2228. if ((pkItem = GetWear(WEAR_WEAPON)))
  2229. {
  2230. switch (pkItem->GetProto()->bSubType)
  2231. {
  2232. case WEAPON_SWORD:
  2233. dwMode = MOTION_MODE_ONEHAND_SWORD;
  2234. break;
  2235. case WEAPON_TWO_HANDED:
  2236. dwMode = MOTION_MODE_TWOHAND_SWORD;
  2237. break;
  2238. case WEAPON_DAGGER:
  2239. dwMode = MOTION_MODE_DUALHAND_SWORD;
  2240. break;
  2241. case WEAPON_BOW:
  2242. dwMode = MOTION_MODE_BOW;
  2243. break;
  2244. case WEAPON_BELL:
  2245. dwMode = MOTION_MODE_BELL;
  2246. break;
  2247. case WEAPON_FAN:
  2248. dwMode = MOTION_MODE_FAN;
  2249. break;
  2250. }
  2251. }
  2252. return dwMode;
  2253. }
  2254. float CHARACTER::GetMoveMotionSpeed() const
  2255. {
  2256. DWORD dwMode = GetMotionMode();
  2257. const CMotion * pkMotion = NULL;
  2258. if (!GetMountVnum())
  2259. pkMotion = CMotionManager::instance().GetMotion(GetRaceNum(), MAKE_MOTION_KEY(dwMode, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2260. else
  2261. {
  2262. pkMotion = CMotionManager::instance().GetMotion(GetMountVnum(), MAKE_MOTION_KEY(MOTION_MODE_GENERAL, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2263. if (!pkMotion)
  2264. pkMotion = CMotionManager::instance().GetMotion(GetRaceNum(), MAKE_MOTION_KEY(MOTION_MODE_HORSE, (IsWalking() && IsPC()) ? MOTION_WALK : MOTION_RUN));
  2265. }
  2266. if (pkMotion)
  2267. return -pkMotion->GetAccumVector().y / pkMotion->GetDuration();
  2268. else
  2269. {
  2270. sys_err("cannot find motion (name %s race %d mode %d)", GetName(), GetRaceNum(), dwMode);
  2271. return 300.0f;
  2272. }
  2273. }
  2274. float CHARACTER::GetMoveSpeed() const
  2275. {
  2276. return GetMoveMotionSpeed() * 10000 / CalculateDuration(GetLimitPoint(POINT_MOV_SPEED), 10000);
  2277. }
  2278. void CHARACTER::CalculateMoveDuration()
  2279. {
  2280. m_posStart.x = GetX();
  2281. m_posStart.y = GetY();
  2282. float fDist = DISTANCE_SQRT(m_posStart.x - m_posDest.x, m_posStart.y - m_posDest.y);
  2283. float motionSpeed = GetMoveMotionSpeed();
  2284. m_dwMoveDuration = CalculateDuration(GetLimitPoint(POINT_MOV_SPEED),
  2285. (int) ((fDist / motionSpeed) * 1000.0f));
  2286. if (IsNPC())
  2287. sys_log(1, "%s: GOTO: distance %f, spd %u, duration %u, motion speed %f pos %d %d -> %d %d",
  2288. GetName(), fDist, GetLimitPoint(POINT_MOV_SPEED), m_dwMoveDuration, motionSpeed,
  2289. m_posStart.x, m_posStart.y, m_posDest.x, m_posDest.y);
  2290. m_dwMoveStartTime = get_dword_time();
  2291. }
  2292. // x y �ġ�� �̵� �Ѵ�. (�̵��� �� �ִ� �� ��� ���� Ȯ�� �ϰ� Sync �޼ҵ�� ��� �̵� �Ѵ�)
  2293. // ����� char�� x, y ��� �ٷ� �ٲ���,
  2294. // Ŭ�󿡼��� ���� �ġ���� �ٲ� x, y���� interpolation�Ѵ�.
  2295. // �Ȱų� �ٴ� ��� char�� m_bNowWalking�� �޷��ִ�.
  2296. // Warp�� �ǵ��� ���̶�� Show�� ����� ��.
  2297. bool CHARACTER::Move(long x, long y)
  2298. {
  2299. // ��� �ġ�� �̵��� �ʿ� ��� (�ڵ� ����)
  2300. if (GetX() == x && GetY() == y)
  2301. return true;
  2302. if (test_server)
  2303. if (m_bDetailLog)
  2304. sys_log(0, "%s position %u %u", GetName(), x, y);
  2305. OnMove();
  2306. return Sync(x, y);
  2307. }
  2308. void CHARACTER::SendMovePacket(BYTE bFunc, BYTE bArg, DWORD x, DWORD y, DWORD dwDuration, DWORD dwTime, int iRot)
  2309. {
  2310. TPacketGCMove pack;
  2311. if (bFunc == FUNC_WAIT)
  2312. {
  2313. x = m_posDest.x;
  2314. y = m_posDest.y;
  2315. dwDuration = m_dwMoveDuration;
  2316. }
  2317. EncodeMovePacket(pack, GetVID(), bFunc, bArg, x, y, dwDuration, dwTime, iRot == -1 ? (int) GetRotation() / 5 : iRot);
  2318. PacketView(&pack, sizeof(TPacketGCMove), this);
  2319. }
  2320. int CHARACTER::GetRealPoint(BYTE type) const
  2321. {
  2322. return m_points.points[type];
  2323. }
  2324. void CHARACTER::SetRealPoint(BYTE type, int val)
  2325. {
  2326. m_points.points[type] = val;
  2327. }
  2328. int CHARACTER::GetPolymorphPoint(BYTE type) const
  2329. {
  2330. if (IsPolymorphed() && !IsPolyMaintainStat())
  2331. {
  2332. DWORD dwMobVnum = GetPolymorphVnum();
  2333. const CMob * pMob = CMobManager::instance().Get(dwMobVnum);
  2334. int iPower = GetPolymorphPower();
  2335. if (pMob)
  2336. {
  2337. switch (type)
  2338. {
  2339. case POINT_ST:
  2340. if (GetJob() == JOB_SHAMAN || GetJob() == JOB_SURA && GetSkillGroup() == 2)
  2341. return pMob->m_table.bStr * iPower / 100 + GetPoint(POINT_IQ);
  2342. return pMob->m_table.bStr * iPower / 100 + GetPoint(POINT_ST);
  2343. case POINT_HT:
  2344. return pMob->m_table.bCon * iPower / 100 + GetPoint(POINT_HT);
  2345. case POINT_IQ:
  2346. return pMob->m_table.bInt * iPower / 100 + GetPoint(POINT_IQ);
  2347. case POINT_DX:
  2348. return pMob->m_table.bDex * iPower / 100 + GetPoint(POINT_DX);
  2349. }
  2350. }
  2351. }
  2352. return GetPoint(type);
  2353. }
  2354. int CHARACTER::GetPoint(BYTE type) const
  2355. {
  2356. if (type >= POINT_MAX_NUM)
  2357. {
  2358. sys_err("Point type overflow (type %u)", type);
  2359. return 0;
  2360. }
  2361. int val = m_pointsInstant.points[type];
  2362. int max_val = INT_MAX;
  2363. switch (type)
  2364. {
  2365. case POINT_STEAL_HP:
  2366. case POINT_STEAL_SP:
  2367. max_val = 50;
  2368. break;
  2369. }
  2370. if (val > max_val)
  2371. sys_err("POINT_ERROR: %s type %d val %d (max: %d)", GetName(), val, max_val);
  2372. return (val);
  2373. }
  2374. int CHARACTER::GetLimitPoint(BYTE type) const
  2375. {
  2376. if (type >= POINT_MAX_NUM)
  2377. {
  2378. sys_err("Point type overflow (type %u)", type);
  2379. return 0;
  2380. }
  2381. int val = m_pointsInstant.points[type];
  2382. int max_val = INT_MAX;
  2383. int limit = INT_MAX;
  2384. int min_limit = -INT_MAX;
  2385. switch (type)
  2386. {
  2387. case POINT_ATT_SPEED:
  2388. min_limit = 0;
  2389. if (IsPC())
  2390. limit = 170;
  2391. else
  2392. limit = 250;
  2393. break;
  2394. case POINT_MOV_SPEED:
  2395. min_limit = 0;
  2396. if (IsPC())
  2397. limit = 200;
  2398. else
  2399. limit = 250;
  2400. break;
  2401. case POINT_STEAL_HP:
  2402. case POINT_STEAL_SP:
  2403. limit = 50;
  2404. max_val = 50;
  2405. break;
  2406. case POINT_MALL_ATTBONUS:
  2407. case POINT_MALL_DEFBONUS:
  2408. limit = 20;
  2409. max_val = 50;
  2410. break;
  2411. }
  2412. if (val > max_val)
  2413. sys_err("POINT_ERROR: %s type %d val %d (max: %d)", GetName(), val, max_val);
  2414. if (val > limit)
  2415. val = limit;
  2416. if (val < min_limit)
  2417. val = min_limit;
  2418. return (val);
  2419. }
  2420. void CHARACTER::SetPoint(BYTE type, int val)
  2421. {
  2422. if (type >= POINT_MAX_NUM)
  2423. {
  2424. sys_err("Point type overflow (type %u)", type);
  2425. return;
  2426. }
  2427. m_pointsInstant.points[type] = val;
  2428. // ���� �̵��� �� �ȳ����ٸ� �̵� �ð� ���� �ٽ� �ؾ� �Ѵ�.
  2429. if (type == POINT_MOV_SPEED && get_dword_time() < m_dwMoveStartTime + m_dwMoveDuration)
  2430. {
  2431. CalculateMoveDuration();
  2432. }
  2433. }
  2434. INT CHARACTER::GetAllowedGold() const
  2435. {
  2436. if (GetLevel() <= 10)
  2437. return 100000;
  2438. else if (GetLevel() <= 20)
  2439. return 500000;
  2440. else
  2441. return 50000000;
  2442. }
  2443. void CHARACTER::CheckMaximumPoints()
  2444. {
  2445. if (GetMaxHP() < GetHP())
  2446. PointChange(POINT_HP, GetMaxHP() - GetHP());
  2447. if (GetMaxSP() < GetSP())
  2448. PointChange(POINT_SP, GetMaxSP() - GetSP());
  2449. }
  2450. void CHARACTER::PointChange(BYTE type, int amount, bool bAmount, bool bBroadcast)
  2451. {
  2452. int val = 0;
  2453. //sys_log(0, "PointChange %d %d | %d -> %d cHP %d mHP %d", type, amount, GetPoint(type), GetPoint(type)+amount, GetHP(), GetMaxHP());
  2454. switch (type)
  2455. {
  2456. case POINT_NONE:
  2457. return;
  2458. case POINT_LEVEL:
  2459. if ((GetLevel() + amount) > gPlayerMaxLevel)
  2460. return;
  2461. SetLevel(GetLevel() + amount);
  2462. val = GetLevel();
  2463. sys_log(0, "LEVELUP: %s %d NEXT EXP %d", GetName(), GetLevel(), GetNextExp());
  2464. PointChange(POINT_NEXT_EXP, GetNextExp(), false);
  2465. if (amount)
  2466. {
  2467. quest::CQuestManager::instance().LevelUp(GetPlayerID());
  2468. LogManager::instance().LevelLog(this, val, GetRealPoint(POINT_PLAYTIME) + (get_dword_time() - m_dwPlayStartTime) / 60000);
  2469. if (GetGuild())
  2470. {
  2471. GetGuild()->LevelChange(GetPlayerID(), GetLevel());
  2472. }
  2473. if (GetParty())
  2474. {
  2475. GetParty()->RequestSetMemberLevel(GetPlayerID(), GetLevel());
  2476. }
  2477. }
  2478. break;
  2479. case POINT_NEXT_EXP:
  2480. val = GetNextExp();
  2481. bAmount = false; // ����� bAmount�� false ���� �Ѵ�.
  2482. break;
  2483. case POINT_EXP:
  2484. {
  2485. DWORD exp = GetExp();
  2486. DWORD next_exp = GetNextExp();
  2487. // û�ҳ⺸ȣ
  2488. if (LC_IsNewCIBN())
  2489. {
  2490. if (IsOverTime(OT_NONE))
  2491. {
  2492. dev_log(LOG_DEB0, "<EXP_LOG> %s = NONE", GetName());
  2493. }
  2494. else if (IsOverTime(OT_3HOUR))
  2495. {
  2496. amount = (amount / 2);
  2497. dev_log(LOG_DEB0, "<EXP_LOG> %s = 3HOUR", GetName());
  2498. }
  2499. else if (IsOverTime(OT_5HOUR))
  2500. {
  2501. amount = 0;
  2502. dev_log(LOG_DEB0, "<EXP_LOG> %s = 5HOUR", GetName());
  2503. }
  2504. }
  2505. // exp�� 0 ���Ϸ� ���� �ʵ��� �Ѵ�
  2506. if (amount < 0 && exp < -amount)
  2507. {
  2508. sys_log(1, "%s AMOUNT < 0 %d, CUR EXP: %d", GetName(), -amount, exp);
  2509. amount = -exp;
  2510. SetExp(exp + amount);
  2511. val = GetExp();
  2512. }
  2513. else
  2514. {
  2515. if (gPlayerMaxLevel <= GetLevel())
  2516. return;
  2517. if (block_exp)
  2518. {
  2519. return;
  2520. }
  2521. if (test_server)
  2522. ChatPacket(CHAT_TYPE_INFO, "You have gained %d exp.", amount);
  2523. DWORD iExpBalance = 0;
  2524. // ���� ��!
  2525. if (exp + amount >= next_exp)
  2526. {
  2527. iExpBalance = (exp + amount) - next_exp;
  2528. amount = next_exp - exp;
  2529. SetExp(0);
  2530. exp = next_exp;
  2531. }
  2532. else
  2533. {
  2534. SetExp(exp + amount);
  2535. exp = GetExp();
  2536. }
  2537. DWORD q = DWORD(next_exp / 4.0f);
  2538. int iLevStep = GetRealPoint(POINT_LEVEL_STEP);
  2539. // iLevStep�� 4 �̻��̸� ������ �ö��� �ϹǷ� ���⿡ �� �� ��� ���̴�.
  2540. if (iLevStep >= 4)
  2541. {
  2542. sys_err("%s LEVEL_STEP bigger than 4! (%d)", GetName(), iLevStep);
  2543. iLevStep = 4;
  2544. }
  2545. if (exp >= next_exp && iLevStep < 4)
  2546. {
  2547. for (int i = 0; i < 4 - iLevStep; ++i)
  2548. PointChange(POINT_LEVEL_STEP, 1, false, true);
  2549. }
  2550. else if (exp >= q * 3 && iLevStep < 3)
  2551. {
  2552. for (int i = 0; i < 3 - iLevStep; ++i)
  2553. PointChange(POINT_LEVEL_STEP, 1, false, true);
  2554. }
  2555. else if (exp >= q * 2 && iLevStep < 2)
  2556. {
  2557. for (int i = 0; i < 2 - iLevStep; ++i)
  2558. PointChange(POINT_LEVEL_STEP, 1, false, true);
  2559. }
  2560. else if (exp >= q && iLevStep < 1)
  2561. PointChange(POINT_LEVEL_STEP, 1);
  2562. if (iExpBalance)
  2563. {
  2564. PointChange(POINT_EXP, iExpBalance);
  2565. }
  2566. val = GetExp();
  2567. }
  2568. }
  2569. break;
  2570. case POINT_LEVEL_STEP:
  2571. if (amount > 0)
  2572. {
  2573. val = GetPoint(POINT_LEVEL_STEP) + amount;
  2574. switch (val)
  2575. {
  2576. case 1:
  2577. case 2:
  2578. case 3:
  2579. //if (GetLevel() < 91)
  2580. PointChange(POINT_STAT, 1);
  2581. break;
  2582. case 4:
  2583. {
  2584. int iHP = number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end);
  2585. int iSP = number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end);
  2586. m_points.iRandomHP += iHP;
  2587. m_points.iRandomSP += iSP;
  2588. if (GetSkillGroup())
  2589. {
  2590. if (GetLevel() >= 5)
  2591. PointChange(POINT_SKILL, 1);
  2592. if (GetLevel() >= 9)
  2593. PointChange(POINT_SUB_SKILL, 1);
  2594. }
  2595. PointChange(POINT_MAX_HP, iHP);
  2596. PointChange(POINT_MAX_SP, iSP);
  2597. PointChange(POINT_LEVEL, 1, false, true);
  2598. val = 0;
  2599. }
  2600. break;
  2601. }
  2602. if (GetLevel() <= 10)
  2603. {
  2604. //AutoGiveItem(27001, 2);
  2605. }
  2606. else if (GetLevel() <= 30)
  2607. {
  2608. //AutoGiveItem(27002, 2);
  2609. }
  2610. else
  2611. {
  2612. //AutoGiveItem(27002, 2);
  2613. // AutoGiveItem(27003, 2);
  2614. }
  2615. PointChange(POINT_HP, GetMaxHP() - GetHP());
  2616. PointChange(POINT_SP, GetMaxSP() - GetSP());
  2617. PointChange(POINT_STAMINA, GetMaxStamina() - GetStamina());
  2618. SetPoint(POINT_LEVEL_STEP, val);
  2619. SetRealPoint(POINT_LEVEL_STEP, val);
  2620. Save();
  2621. }
  2622. else
  2623. val = GetPoint(POINT_LEVEL_STEP);
  2624. break;
  2625. case POINT_HP:
  2626. {
  2627. if (IsDead() || IsStun())
  2628. return;
  2629. int prev_hp = GetHP();
  2630. amount = MIN(GetMaxHP() - GetHP(), amount);
  2631. SetHP(GetHP() + amount);
  2632. val = GetHP();
  2633. BroadcastTargetPacket();
  2634. if (GetParty() && IsPC() && val != prev_hp)
  2635. GetParty()->SendPartyInfoOneToAll(this);
  2636. }
  2637. break;
  2638. case POINT_SP:
  2639. {
  2640. if (IsDead() || IsStun())
  2641. return;
  2642. amount = MIN(GetMaxSP() - GetSP(), amount);
  2643. SetSP(GetSP() + amount);
  2644. val = GetSP();
  2645. }
  2646. break;
  2647. case POINT_STAMINA:
  2648. {
  2649. if (IsDead() || IsStun())
  2650. return;
  2651. int prev_val = GetStamina();
  2652. amount = MIN(GetMaxStamina() - GetStamina(), amount);
  2653. SetStamina(GetStamina() + amount);
  2654. val = GetStamina();
  2655. if (val == 0)
  2656. {
  2657. // Stamina�� ����� ����!
  2658. SetNowWalking(true);
  2659. }
  2660. else if (prev_val == 0)
  2661. {
  2662. // ��� ���׹̳��� ������ ���� ��� ����
  2663. ResetWalking();
  2664. }
  2665. if (amount < 0 && val != 0) // ���Ҵ� ������ʴ´�.
  2666. return;
  2667. }
  2668. break;
  2669. case POINT_MAX_HP:
  2670. {
  2671. SetPoint(type, GetPoint(type) + amount);
  2672. int i = GetMaxHP();
  2673. int hp = GetRealPoint(POINT_MAX_HP);
  2674. int add_hp = MIN(3500, hp * GetPoint(POINT_MAX_HP_PCT) / 100);
  2675. add_hp += GetPoint(POINT_MAX_HP);
  2676. add_hp += GetPoint(POINT_PARTY_TANKER_BONUS);
  2677. SetMaxHP(hp + add_hp);
  2678. float fRatio = (float)GetMaxHP() / (float)i;
  2679. PointChange(POINT_HP, GetHP() * fRatio - GetHP());
  2680. val = GetMaxHP();
  2681. }
  2682. break;
  2683. case POINT_MAX_SP:
  2684. {
  2685. SetPoint(type, GetPoint(type) + amount);
  2686. int i = GetMaxSP();
  2687. int sp = GetRealPoint(POINT_MAX_SP);
  2688. int add_sp = MIN(800, sp * GetPoint(POINT_MAX_SP_PCT) / 100);
  2689. add_sp += GetPoint(POINT_MAX_SP);
  2690. add_sp += GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  2691. SetMaxSP(sp + add_sp);
  2692. float fRatio = (float)GetMaxSP() / (float)i;
  2693. PointChange(POINT_SP, GetSP() * fRatio - GetSP());
  2694. val = GetMaxSP();
  2695. }
  2696. break;
  2697. case POINT_MAX_HP_PCT:
  2698. SetPoint(type, GetPoint(type) + amount);
  2699. val = GetPoint(type);
  2700. PointChange(POINT_MAX_HP, 0);
  2701. break;
  2702. case POINT_MAX_SP_PCT:
  2703. SetPoint(type, GetPoint(type) + amount);
  2704. val = GetPoint(type);
  2705. PointChange(POINT_MAX_SP, 0);
  2706. break;
  2707. case POINT_MAX_STAMINA:
  2708. SetMaxStamina(GetMaxStamina() + amount);
  2709. val = GetMaxStamina();
  2710. break;
  2711. case POINT_GOLD:
  2712. {
  2713. const int64_t nTotalMoney = static_cast<int64_t>(GetGold()) + static_cast<int64_t>(amount);
  2714. if (GOLD_MAX <= nTotalMoney)
  2715. {
  2716. sys_err("[OVERFLOW_GOLD] OriGold %d AddedGold %d id %u Name %s ", GetGold(), amount, GetPlayerID(), GetName());
  2717. LogManager::instance().CharLog(this, GetGold() + amount, "OVERFLOW_GOLD", "");
  2718. return;
  2719. }
  2720. // û�ҳ⺸ȣ
  2721. if (LC_IsNewCIBN() && amount > 0)
  2722. {
  2723. if (IsOverTime(OT_NONE))
  2724. {
  2725. dev_log(LOG_DEB0, "<GOLD_LOG> %s = NONE", GetName());
  2726. }
  2727. else if (IsOverTime(OT_3HOUR))
  2728. {
  2729. amount = (amount / 2);
  2730. dev_log(LOG_DEB0, "<GOLD_LOG> %s = 3HOUR", GetName());
  2731. }
  2732. else if (IsOverTime(OT_5HOUR))
  2733. {
  2734. amount = 0;
  2735. dev_log(LOG_DEB0, "<GOLD_LOG> %s = 5HOUR", GetName());
  2736. }
  2737. }
  2738. SetGold(GetGold() + amount);
  2739. val = GetGold();
  2740. }
  2741. break;
  2742. case POINT_SKILL:
  2743. case POINT_STAT:
  2744. case POINT_SUB_SKILL:
  2745. case POINT_STAT_RESET_COUNT:
  2746. case POINT_HORSE_SKILL:
  2747. SetPoint(type, GetPoint(type) + amount);
  2748. val = GetPoint(type);
  2749. SetRealPoint(type, val);
  2750. break;
  2751. case POINT_DEF_GRADE:
  2752. SetPoint(type, GetPoint(type) + amount);
  2753. val = GetPoint(type);
  2754. PointChange(POINT_CLIENT_DEF_GRADE, amount);
  2755. break;
  2756. case POINT_CLIENT_DEF_GRADE:
  2757. SetPoint(type, GetPoint(type) + amount);
  2758. val = GetPoint(type);
  2759. break;
  2760. case POINT_ST:
  2761. case POINT_HT:
  2762. case POINT_DX:
  2763. case POINT_IQ:
  2764. case POINT_HP_REGEN:
  2765. case POINT_SP_REGEN:
  2766. case POINT_ATT_SPEED:
  2767. case POINT_ATT_GRADE:
  2768. case POINT_MOV_SPEED:
  2769. case POINT_CASTING_SPEED:
  2770. case POINT_MAGIC_ATT_GRADE:
  2771. case POINT_MAGIC_DEF_GRADE:
  2772. case POINT_BOW_DISTANCE:
  2773. case POINT_HP_RECOVERY:
  2774. case POINT_SP_RECOVERY:
  2775. case POINT_ATTBONUS_HUMAN: // 42 ����� ����
  2776. case POINT_ATTBONUS_ANIMAL: // 43 �������� ������ % ��
  2777. case POINT_ATTBONUS_ORC: // 44 ��Ϳ��� ������ % ��
  2778. case POINT_ATTBONUS_MILGYO: // 45 ����� ������ % ��
  2779. case POINT_ATTBONUS_UNDEAD: // 46 ��ü���� ������ % ��
  2780. case POINT_ATTBONUS_DEVIL: // 47 ����(�Ǹ�)���� ������ % ��
  2781. case POINT_ATTBONUS_MONSTER:
  2782. case POINT_ATTBONUS_SURA:
  2783. case POINT_ATTBONUS_ASSASSIN:
  2784. case POINT_ATTBONUS_WARRIOR:
  2785. case POINT_ATTBONUS_SHAMAN:
  2786. case POINT_POISON_PCT:
  2787. case POINT_STUN_PCT:
  2788. case POINT_SLOW_PCT:
  2789. case POINT_BLOCK:
  2790. case POINT_DODGE:
  2791. case POINT_CRITICAL_PCT:
  2792. case POINT_RESIST_CRITICAL:
  2793. case POINT_PENETRATE_PCT:
  2794. case POINT_RESIST_PENETRATE:
  2795. case POINT_CURSE_PCT:
  2796. case POINT_STEAL_HP: // 48 ���� ���
  2797. case POINT_STEAL_SP: // 49 ��ŷ� ���
  2798. case POINT_MANA_BURN_PCT: // 50 ���� ��
  2799. case POINT_DAMAGE_SP_RECOVER: // 51 ��ݴ��� �� ��ŷ� ȸ�� Ȯ��
  2800. case POINT_RESIST_NORMAL_DAMAGE:
  2801. case POINT_RESIST_SWORD:
  2802. case POINT_RESIST_TWOHAND:
  2803. case POINT_RESIST_DAGGER:
  2804. case POINT_RESIST_BELL:
  2805. case POINT_RESIST_FAN:
  2806. case POINT_RESIST_BOW:
  2807. case POINT_RESIST_FIRE:
  2808. case POINT_RESIST_ELEC:
  2809. case POINT_RESIST_MAGIC:
  2810. case POINT_RESIST_WIND:
  2811. case POINT_RESIST_ICE:
  2812. case POINT_RESIST_EARTH:
  2813. case POINT_RESIST_DARK:
  2814. case POINT_REFLECT_MELEE: // 67 ��� �ݻ�
  2815. case POINT_REFLECT_CURSE: // 68 ���� �ݻ�
  2816. case POINT_POISON_REDUCE: // 69 �������� ����
  2817. case POINT_KILL_SP_RECOVER: // 70 �� �Ҹ�� MP ȸ��
  2818. case POINT_KILL_HP_RECOVERY: // 75
  2819. case POINT_HIT_HP_RECOVERY:
  2820. case POINT_HIT_SP_RECOVERY:
  2821. case POINT_MANASHIELD:
  2822. case POINT_ATT_BONUS:
  2823. case POINT_DEF_BONUS:
  2824. case POINT_SKILL_DAMAGE_BONUS:
  2825. case POINT_NORMAL_HIT_DAMAGE_BONUS:
  2826. // DEPEND_BONUS_ATTRIBUTES
  2827. case POINT_SKILL_DEFEND_BONUS:
  2828. case POINT_NORMAL_HIT_DEFEND_BONUS:
  2829. SetPoint(type, GetPoint(type) + amount);
  2830. val = GetPoint(type);
  2831. break;
  2832. // END_OF_DEPEND_BONUS_ATTRIBUTES
  2833. case POINT_PARTY_ATTACKER_BONUS:
  2834. case POINT_PARTY_TANKER_BONUS:
  2835. case POINT_PARTY_BUFFER_BONUS:
  2836. case POINT_PARTY_SKILL_MASTER_BONUS:
  2837. case POINT_PARTY_HASTE_BONUS:
  2838. case POINT_PARTY_DEFENDER_BONUS:
  2839. case POINT_RESIST_WARRIOR :
  2840. case POINT_RESIST_ASSASSIN :
  2841. case POINT_RESIST_SURA :
  2842. case POINT_RESIST_SHAMAN :
  2843. SetPoint(type, GetPoint(type) + amount);
  2844. val = GetPoint(type);
  2845. break;
  2846. case POINT_MALL_ATTBONUS:
  2847. case POINT_MALL_DEFBONUS:
  2848. case POINT_MALL_EXPBONUS:
  2849. case POINT_MALL_ITEMBONUS:
  2850. case POINT_MALL_GOLDBONUS:
  2851. case POINT_MELEE_MAGIC_ATT_BONUS_PER:
  2852. if (GetPoint(type) + amount > 100)
  2853. {
  2854. sys_err("MALL_BONUS exceeded over 100!! point type: %d name: %s amount %d", type, GetName(), amount);
  2855. amount = 100 - GetPoint(type);
  2856. }
  2857. SetPoint(type, GetPoint(type) + amount);
  2858. val = GetPoint(type);
  2859. break;
  2860. // PC_BANG_ITEM_ADD
  2861. case POINT_PC_BANG_EXP_BONUS :
  2862. case POINT_PC_BANG_DROP_BONUS :
  2863. case POINT_RAMADAN_CANDY_BONUS_EXP:
  2864. SetPoint(type, amount);
  2865. val = GetPoint(type);
  2866. break;
  2867. // END_PC_BANG_ITEM_ADD
  2868. case POINT_EXP_DOUBLE_BONUS: // 71
  2869. case POINT_GOLD_DOUBLE_BONUS: // 72
  2870. case POINT_ITEM_DROP_BONUS: // 73
  2871. case POINT_POTION_BONUS: // 74
  2872. if (GetPoint(type) + amount > 100)
  2873. {
  2874. sys_err("BONUS exceeded over 100!! point type: %d name: %s amount %d", type, GetName(), amount);
  2875. amount = 100 - GetPoint(type);
  2876. }
  2877. SetPoint(type, GetPoint(type) + amount);
  2878. val = GetPoint(type);
  2879. break;
  2880. case POINT_IMMUNE_STUN: // 76
  2881. SetPoint(type, GetPoint(type) + amount);
  2882. val = GetPoint(type);
  2883. if (val)
  2884. {
  2885. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_STUN);
  2886. }
  2887. else
  2888. {
  2889. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_STUN);
  2890. }
  2891. break;
  2892. case POINT_IMMUNE_SLOW: // 77
  2893. SetPoint(type, GetPoint(type) + amount);
  2894. val = GetPoint(type);
  2895. if (val)
  2896. {
  2897. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_SLOW);
  2898. }
  2899. else
  2900. {
  2901. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_SLOW);
  2902. }
  2903. break;
  2904. case POINT_IMMUNE_FALL: // 78
  2905. SetPoint(type, GetPoint(type) + amount);
  2906. val = GetPoint(type);
  2907. if (val)
  2908. {
  2909. SET_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_FALL);
  2910. }
  2911. else
  2912. {
  2913. REMOVE_BIT(m_pointsInstant.dwImmuneFlag, IMMUNE_FALL);
  2914. }
  2915. break;
  2916. case POINT_ATT_GRADE_BONUS:
  2917. SetPoint(type, GetPoint(type) + amount);
  2918. PointChange(POINT_ATT_GRADE, amount);
  2919. val = GetPoint(type);
  2920. break;
  2921. case POINT_DEF_GRADE_BONUS:
  2922. SetPoint(type, GetPoint(type) + amount);
  2923. PointChange(POINT_DEF_GRADE, amount);
  2924. val = GetPoint(type);
  2925. break;
  2926. case POINT_MAGIC_ATT_GRADE_BONUS:
  2927. SetPoint(type, GetPoint(type) + amount);
  2928. PointChange(POINT_MAGIC_ATT_GRADE, amount);
  2929. val = GetPoint(type);
  2930. break;
  2931. case POINT_MAGIC_DEF_GRADE_BONUS:
  2932. SetPoint(type, GetPoint(type) + amount);
  2933. PointChange(POINT_MAGIC_DEF_GRADE, amount);
  2934. val = GetPoint(type);
  2935. break;
  2936. case POINT_VOICE:
  2937. case POINT_EMPIRE_POINT:
  2938. //sys_err("CHARACTER::PointChange: %s: point cannot be changed. use SetPoint instead (type: %d)", GetName(), type);
  2939. val = GetRealPoint(type);
  2940. break;
  2941. case POINT_POLYMORPH:
  2942. SetPoint(type, GetPoint(type) + amount);
  2943. val = GetPoint(type);
  2944. SetPolymorph(val);
  2945. break;
  2946. case POINT_MOUNT:
  2947. SetPoint(type, GetPoint(type) + amount);
  2948. val = GetPoint(type);
  2949. MountVnum(val);
  2950. break;
  2951. case POINT_ENERGY:
  2952. case POINT_COSTUME_ATTR_BONUS:
  2953. {
  2954. int old_val = GetPoint(type);
  2955. SetPoint(type, old_val + amount);
  2956. val = GetPoint(type);
  2957. BuffOnAttr_ValueChange(type, old_val, val);
  2958. }
  2959. break;
  2960. default:
  2961. sys_err("CHARACTER::PointChange: %s: unknown point change type %d", GetName(), type);
  2962. return;
  2963. }
  2964. switch (type)
  2965. {
  2966. case POINT_LEVEL:
  2967. case POINT_ST:
  2968. case POINT_DX:
  2969. case POINT_IQ:
  2970. case POINT_HT:
  2971. ComputeBattlePoints();
  2972. break;
  2973. case POINT_MAX_HP:
  2974. case POINT_MAX_SP:
  2975. case POINT_MAX_STAMINA:
  2976. break;
  2977. }
  2978. if (type == POINT_HP && amount == 0)
  2979. return;
  2980. if (GetDesc())
  2981. {
  2982. struct packet_point_change pack;
  2983. pack.header = HEADER_GC_CHARACTER_POINT_CHANGE;
  2984. pack.dwVID = m_vid;
  2985. pack.type = type;
  2986. pack.value = val;
  2987. if (bAmount)
  2988. pack.amount = amount;
  2989. else
  2990. pack.amount = 0;
  2991. if (!bBroadcast)
  2992. GetDesc()->Packet(&pack, sizeof(struct packet_point_change));
  2993. else
  2994. PacketAround(&pack, sizeof(pack));
  2995. }
  2996. }
  2997. void CHARACTER::ApplyPoint(BYTE bApplyType, int iVal)
  2998. {
  2999. switch (bApplyType)
  3000. {
  3001. case APPLY_NONE: // 0
  3002. break;;
  3003. case APPLY_CON:
  3004. PointChange(POINT_HT, iVal);
  3005. PointChange(POINT_MAX_HP, (iVal * JobInitialPoints[GetJob()].hp_per_ht));
  3006. PointChange(POINT_MAX_STAMINA, (iVal * JobInitialPoints[GetJob()].stamina_per_con));
  3007. break;
  3008. case APPLY_INT:
  3009. PointChange(POINT_IQ, iVal);
  3010. PointChange(POINT_MAX_SP, (iVal * JobInitialPoints[GetJob()].sp_per_iq));
  3011. break;
  3012. case APPLY_SKILL:
  3013. // SKILL_DAMAGE_BONUS
  3014. {
  3015. // �ֻ�� ��Ʈ ������� 8��Ʈ vnum, 9��Ʈ add, 15��Ʈ change
  3016. // 00000000 00000000 00000000 00000000
  3017. // ^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^
  3018. // vnum ^ add change
  3019. BYTE bSkillVnum = (BYTE) (((DWORD)iVal) >> 24);
  3020. int iAdd = iVal & 0x00800000;
  3021. int iChange = iVal & 0x007fffff;
  3022. sys_log(1, "APPLY_SKILL skill %d add? %d change %d", bSkillVnum, iAdd ? 1 : 0, iChange);
  3023. if (0 == iAdd)
  3024. iChange = -iChange;
  3025. boost::unordered_map<BYTE, int>::iterator iter = m_SkillDamageBonus.find(bSkillVnum);
  3026. if (iter == m_SkillDamageBonus.end())
  3027. m_SkillDamageBonus.insert(std::make_pair(bSkillVnum, iChange));
  3028. else
  3029. iter->second += iChange;
  3030. }
  3031. // END_OF_SKILL_DAMAGE_BONUS
  3032. break;
  3033. case APPLY_STR:
  3034. case APPLY_DEX:
  3035. case APPLY_MAX_HP:
  3036. case APPLY_MAX_SP:
  3037. case APPLY_MAX_HP_PCT:
  3038. case APPLY_MAX_SP_PCT:
  3039. case APPLY_ATT_SPEED:
  3040. case APPLY_MOV_SPEED:
  3041. case APPLY_CAST_SPEED:
  3042. case APPLY_HP_REGEN:
  3043. case APPLY_SP_REGEN:
  3044. case APPLY_POISON_PCT:
  3045. case APPLY_STUN_PCT:
  3046. case APPLY_SLOW_PCT:
  3047. case APPLY_CRITICAL_PCT:
  3048. case APPLY_PENETRATE_PCT:
  3049. case APPLY_ATTBONUS_HUMAN:
  3050. case APPLY_ATTBONUS_ANIMAL:
  3051. case APPLY_ATTBONUS_ORC:
  3052. case APPLY_ATTBONUS_MILGYO:
  3053. case APPLY_ATTBONUS_UNDEAD:
  3054. case APPLY_ATTBONUS_DEVIL:
  3055. case APPLY_ATTBONUS_WARRIOR: // 59
  3056. case APPLY_ATTBONUS_ASSASSIN: // 60
  3057. case APPLY_ATTBONUS_SURA: // 61
  3058. case APPLY_ATTBONUS_SHAMAN: // 62
  3059. case APPLY_ATTBONUS_MONSTER: // 63
  3060. case APPLY_STEAL_HP:
  3061. case APPLY_STEAL_SP:
  3062. case APPLY_MANA_BURN_PCT:
  3063. case APPLY_DAMAGE_SP_RECOVER:
  3064. case APPLY_BLOCK:
  3065. case APPLY_DODGE:
  3066. case APPLY_RESIST_SWORD:
  3067. case APPLY_RESIST_TWOHAND:
  3068. case APPLY_RESIST_DAGGER:
  3069. case APPLY_RESIST_BELL:
  3070. case APPLY_RESIST_FAN:
  3071. case APPLY_RESIST_BOW:
  3072. case APPLY_RESIST_FIRE:
  3073. case APPLY_RESIST_ELEC:
  3074. case APPLY_RESIST_MAGIC:
  3075. case APPLY_RESIST_WIND:
  3076. case APPLY_RESIST_ICE:
  3077. case APPLY_RESIST_EARTH:
  3078. case APPLY_RESIST_DARK:
  3079. case APPLY_REFLECT_MELEE:
  3080. case APPLY_REFLECT_CURSE:
  3081. case APPLY_ANTI_CRITICAL_PCT:
  3082. case APPLY_ANTI_PENETRATE_PCT:
  3083. case APPLY_POISON_REDUCE:
  3084. case APPLY_KILL_SP_RECOVER:
  3085. case APPLY_EXP_DOUBLE_BONUS:
  3086. case APPLY_GOLD_DOUBLE_BONUS:
  3087. case APPLY_ITEM_DROP_BONUS:
  3088. case APPLY_POTION_BONUS:
  3089. case APPLY_KILL_HP_RECOVER:
  3090. case APPLY_IMMUNE_STUN:
  3091. case APPLY_IMMUNE_SLOW:
  3092. case APPLY_IMMUNE_FALL:
  3093. case APPLY_BOW_DISTANCE:
  3094. case APPLY_ATT_GRADE_BONUS:
  3095. case APPLY_DEF_GRADE_BONUS:
  3096. case APPLY_MAGIC_ATT_GRADE:
  3097. case APPLY_MAGIC_DEF_GRADE:
  3098. case APPLY_CURSE_PCT:
  3099. case APPLY_MAX_STAMINA:
  3100. case APPLY_MALL_ATTBONUS:
  3101. case APPLY_MALL_DEFBONUS:
  3102. case APPLY_MALL_EXPBONUS:
  3103. case APPLY_MALL_ITEMBONUS:
  3104. case APPLY_MALL_GOLDBONUS:
  3105. case APPLY_SKILL_DAMAGE_BONUS:
  3106. case APPLY_NORMAL_HIT_DAMAGE_BONUS:
  3107. // DEPEND_BONUS_ATTRIBUTES
  3108. case APPLY_SKILL_DEFEND_BONUS:
  3109. case APPLY_NORMAL_HIT_DEFEND_BONUS:
  3110. // END_OF_DEPEND_BONUS_ATTRIBUTES
  3111. case APPLY_PC_BANG_EXP_BONUS :
  3112. case APPLY_PC_BANG_DROP_BONUS :
  3113. case APPLY_RESIST_WARRIOR :
  3114. case APPLY_RESIST_ASSASSIN :
  3115. case APPLY_RESIST_SURA :
  3116. case APPLY_RESIST_SHAMAN :
  3117. case APPLY_ENERGY: // 82 ���
  3118. case APPLY_DEF_GRADE: // 83 ����. DEF_GRADE_BONUS�� Ŭ�󿡼� �ι�� ������� �ǵ��� ���(...)�� �ִ�.
  3119. case APPLY_COSTUME_ATTR_BONUS: // 84 �ڽ�Ƭ �����ۿ� ��� �Ӽ�ġ ���ʽ�
  3120. case APPLY_MAGIC_ATTBONUS_PER: // 85 ���� ��ݷ� +x%
  3121. case APPLY_MELEE_MAGIC_ATTBONUS_PER: // 86 ���� + �и� ��ݷ� +x%
  3122. PointChange(aApplyInfo[bApplyType].bPointType, iVal);
  3123. break;
  3124. default:
  3125. sys_err("Unknown apply type %d name %s", bApplyType, GetName());
  3126. break;
  3127. }
  3128. }
  3129. void CHARACTER::MotionPacketEncode(BYTE motion, LPCHARACTER victim, struct packet_motion * packet)
  3130. {
  3131. packet->header = HEADER_GC_MOTION;
  3132. packet->vid = m_vid;
  3133. packet->motion = motion;
  3134. if (victim)
  3135. packet->victim_vid = victim->GetVID();
  3136. else
  3137. packet->victim_vid = 0;
  3138. }
  3139. void CHARACTER::Motion(BYTE motion, LPCHARACTER victim)
  3140. {
  3141. struct packet_motion pack_motion;
  3142. MotionPacketEncode(motion, victim, &pack_motion);
  3143. PacketAround(&pack_motion, sizeof(struct packet_motion));
  3144. }
  3145. EVENTFUNC(save_event)
  3146. {
  3147. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  3148. if ( info == NULL )
  3149. {
  3150. sys_err( "save_event> <Factor> Null pointer" );
  3151. return 0;
  3152. }
  3153. LPCHARACTER ch = info->ch;
  3154. if (ch == NULL) { // <Factor>
  3155. return 0;
  3156. }
  3157. sys_log(1, "SAVE_EVENT: %s", ch->GetName());
  3158. ch->Save();
  3159. ch->FlushDelayedSaveItem();
  3160. return (save_event_second_cycle);
  3161. }
  3162. void CHARACTER::StartSaveEvent()
  3163. {
  3164. if (m_pkSaveEvent)
  3165. return;
  3166. char_event_info* info = AllocEventInfo<char_event_info>();
  3167. info->ch = this;
  3168. m_pkSaveEvent = event_create(save_event, info, save_event_second_cycle);
  3169. }
  3170. void CHARACTER::MonsterLog(const char* format, ...)
  3171. {
  3172. if (!test_server)
  3173. return;
  3174. if (IsPC())
  3175. return;
  3176. char chatbuf[CHAT_MAX_LEN + 1];
  3177. int len = snprintf(chatbuf, sizeof(chatbuf), "%u)", (DWORD)GetVID());
  3178. if (len < 0 || len >= (int) sizeof(chatbuf))
  3179. len = sizeof(chatbuf) - 1;
  3180. va_list args;
  3181. va_start(args, format);
  3182. int len2 = vsnprintf(chatbuf + len, sizeof(chatbuf) - len, format, args);
  3183. if (len2 < 0 || len2 >= (int) sizeof(chatbuf) - len)
  3184. len += (sizeof(chatbuf) - len) - 1;
  3185. else
  3186. len += len2;
  3187. // \0 ���� ����
  3188. ++len;
  3189. va_end(args);
  3190. TPacketGCChat pack_chat;
  3191. pack_chat.header = HEADER_GC_CHAT;
  3192. pack_chat.size = sizeof(TPacketGCChat) + len;
  3193. pack_chat.type = CHAT_TYPE_TALKING;
  3194. pack_chat.id = (DWORD)GetVID();
  3195. pack_chat.bEmpire = 0;
  3196. TEMP_BUFFER buf;
  3197. buf.write(&pack_chat, sizeof(TPacketGCChat));
  3198. buf.write(chatbuf, len);
  3199. CHARACTER_MANAGER::instance().PacketMonsterLog(this, buf.read_peek(), buf.size());
  3200. }
  3201. void CHARACTER::ChatPacket(BYTE type, const char * format, ...)
  3202. {
  3203. LPDESC d = GetDesc();
  3204. if (!d || !format)
  3205. return;
  3206. char chatbuf[CHAT_MAX_LEN + 1];
  3207. va_list args;
  3208. va_start(args, format);
  3209. int len = vsnprintf(chatbuf, sizeof(chatbuf), format, args);
  3210. va_end(args);
  3211. struct packet_chat pack_chat;
  3212. pack_chat.header = HEADER_GC_CHAT;
  3213. pack_chat.size = sizeof(struct packet_chat) + len;
  3214. pack_chat.type = type;
  3215. pack_chat.id = 0;
  3216. pack_chat.bEmpire = d->GetEmpire();
  3217. TEMP_BUFFER buf;
  3218. buf.write(&pack_chat, sizeof(struct packet_chat));
  3219. buf.write(chatbuf, len);
  3220. d->Packet(buf.read_peek(), buf.size());
  3221. if (type == CHAT_TYPE_COMMAND && test_server)
  3222. sys_log(0, "SEND_COMMAND %s %s", GetName(), chatbuf);
  3223. }
  3224. // MINING
  3225. void CHARACTER::mining_take()
  3226. {
  3227. m_pkMiningEvent = NULL;
  3228. }
  3229. void CHARACTER::mining_cancel()
  3230. {
  3231. if (m_pkMiningEvent)
  3232. {
  3233. sys_log(0, "XXX MINING CANCEL");
  3234. event_cancel(&m_pkMiningEvent);
  3235. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("ä��� �ߴ��Ͽ���ϴ�."));
  3236. }
  3237. }
  3238. void CHARACTER::mining(LPCHARACTER chLoad)
  3239. {
  3240. if (m_pkMiningEvent)
  3241. {
  3242. mining_cancel();
  3243. return;
  3244. }
  3245. if (!chLoad)
  3246. return;
  3247. if (GetMapIndex() != chLoad->GetMapIndex() || DISTANCE_APPROX(GetX() - chLoad->GetX(), GetY() - chLoad->GetY()) > 1000) //Madenci bot fixed.
  3248. return;
  3249. if (mining::GetRawOreFromLoad(chLoad->GetRaceNum()) == 0)
  3250. return;
  3251. LPITEM pick = GetWear(WEAR_WEAPON);
  3252. if (!pick || pick->GetType() != ITEM_PICK)
  3253. {
  3254. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("��̸� �����ϼ���."));
  3255. return;
  3256. }
  3257. int count = number(5, 15); // ���� Ƚ��, �� ���۴� 2��
  3258. // � ����� ������
  3259. TPacketGCDigMotion p;
  3260. p.header = HEADER_GC_DIG_MOTION;
  3261. p.vid = GetVID();
  3262. p.target_vid = chLoad->GetVID();
  3263. p.count = count;
  3264. PacketAround(&p, sizeof(p));
  3265. m_pkMiningEvent = mining::CreateMiningEvent(this, chLoad, count);
  3266. }
  3267. void CHARACTER::fishing()
  3268. {
  3269. if (m_pkFishingEvent)
  3270. {
  3271. fishing_take();
  3272. return;
  3273. }
  3274. // �� �Ӽ����� ���ø� �õ��Ѵ�?
  3275. {
  3276. LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(GetMapIndex());
  3277. int x = GetX();
  3278. int y = GetY();
  3279. LPSECTREE tree = pkSectreeMap->Find(x, y);
  3280. DWORD dwAttr = tree->GetAttribute(x, y);
  3281. if (IS_SET(dwAttr, ATTR_BLOCK))
  3282. {
  3283. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("���ø� �� �� �ִ� ���� �ƴմϴ�"));
  3284. return;
  3285. }
  3286. }
  3287. LPITEM rod = GetWear(WEAR_WEAPON);
  3288. // ���ô� ����
  3289. if (!rod || rod->GetType() != ITEM_ROD)
  3290. {
  3291. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("���ô븦 ���� �ϼ���."));
  3292. return;
  3293. }
  3294. if (0 == rod->GetSocket(2))
  3295. {
  3296. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�̳��� ���� ��� �ּ���."));
  3297. return;
  3298. }
  3299. float fx, fy;
  3300. GetDeltaByDegree(GetRotation(), 400.0f, &fx, &fy);
  3301. m_pkFishingEvent = fishing::CreateFishingEvent(this);
  3302. }
  3303. void CHARACTER::fishing_take()
  3304. {
  3305. LPITEM rod = GetWear(WEAR_WEAPON);
  3306. if (rod && rod->GetType() == ITEM_ROD)
  3307. {
  3308. using fishing::fishing_event_info;
  3309. if (m_pkFishingEvent)
  3310. {
  3311. struct fishing_event_info* info = dynamic_cast<struct fishing_event_info*>(m_pkFishingEvent->info);
  3312. if (info)
  3313. fishing::Take(info, this);
  3314. }
  3315. }
  3316. else
  3317. {
  3318. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("���ô밡 �ƴ� ������� ���ø� �� �� ���ϴ�!"));
  3319. }
  3320. event_cancel(&m_pkFishingEvent);
  3321. }
  3322. bool CHARACTER::StartStateMachine(int iNextPulse)
  3323. {
  3324. if (CHARACTER_MANAGER::instance().AddToStateList(this))
  3325. {
  3326. m_dwNextStatePulse = thecore_heart->pulse + iNextPulse;
  3327. return true;
  3328. }
  3329. return false;
  3330. }
  3331. void CHARACTER::StopStateMachine()
  3332. {
  3333. CHARACTER_MANAGER::instance().RemoveFromStateList(this);
  3334. }
  3335. void CHARACTER::UpdateStateMachine(DWORD dwPulse)
  3336. {
  3337. if (dwPulse < m_dwNextStatePulse)
  3338. return;
  3339. if (IsDead())
  3340. return;
  3341. Update();
  3342. m_dwNextStatePulse = dwPulse + m_dwStateDuration;
  3343. }
  3344. void CHARACTER::SetNextStatePulse(int iNextPulse)
  3345. {
  3346. CHARACTER_MANAGER::instance().AddToStateList(this);
  3347. m_dwNextStatePulse = iNextPulse;
  3348. if (iNextPulse < 10)
  3349. MonsterLog("������·ξ����");
  3350. }
  3351. // ij���� �ν��Ͻ� ����Ʈ �Լ�.
  3352. void CHARACTER::UpdateCharacter(DWORD dwPulse)
  3353. {
  3354. CFSM::Update();
  3355. }
  3356. void CHARACTER::SetShop(LPSHOP pkShop)
  3357. {
  3358. if ((m_pkShop = pkShop))
  3359. SET_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_SHOP);
  3360. else
  3361. {
  3362. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_SHOP);
  3363. SetShopOwner(NULL);
  3364. }
  3365. }
  3366. void CHARACTER::SetOfflineShop(LPOFFLINESHOP pkOfflineShop)
  3367. {
  3368. if ((m_pkOfflineShop = pkOfflineShop))
  3369. SET_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_OFFLINE_SHOP);
  3370. else
  3371. {
  3372. REMOVE_BIT(m_pointsInstant.instant_flag, INSTANT_FLAG_OFFLINE_SHOP);
  3373. SetOfflineShopOwner(NULL);
  3374. }
  3375. }
  3376. void CHARACTER::OpenMyOfflineShop(const char * c_pszSign, TShopItemTable * pTable, BYTE bItemCount, BYTE bTime)
  3377. {
  3378. quest::PC * pPC = quest::CQuestManager::Instance().GetPC(GetPlayerID());
  3379. if (pPC->IsRunning())
  3380. return;
  3381. if (bItemCount == 0)
  3382. return;
  3383. if (GetShop() || GetOfflineShop())
  3384. return;
  3385. // Brazil is not use for this option.
  3386. if (!LC_IsBrazil())
  3387. {
  3388. DWORD nTotalMoney = 0;
  3389. for (BYTE n = 0; n < bItemCount; ++n)
  3390. nTotalMoney += (pTable + n)->price;
  3391. if (GOLD_MAX - 1 <= nTotalMoney)
  3392. {
  3393. sys_err("[OVERFLOW_GOLD] Overflow (GOLD_MAX) id %u name %s", GetPlayerID(), GetName());
  3394. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("20��i ��EA�� AE��uCI���� ��oA��A�� ������o�Ƣ� ���A��I��U"));
  3395. return;
  3396. }
  3397. }
  3398. // Check Game admin can not open offline shop
  3399. {
  3400. if (!test_server)
  3401. {
  3402. if (IsGM())
  3403. {
  3404. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Sen adminsin, tezgah acamazsin.");
  3405. return;
  3406. }
  3407. }
  3408. }
  3409. // End Of Check Game admin can not open offline shop
  3410. // Check if player has current items in database.
  3411. {
  3412. 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()));
  3413. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  3414. BYTE bResult = 0;
  3415. str_to_number(bResult, row[0]);
  3416. if (bResult)
  3417. {
  3418. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Nesneleri alip sonra tezgah aciniz.");
  3419. COfflineShopManager::instance().Giveback2(this);
  3420. return;
  3421. }
  3422. }
  3423. // End of check if player has current items in database
  3424. // Check player is open offline shop or not
  3425. {
  3426. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery("SELECT COUNT(*) FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetPlayerID()));
  3427. MYSQL_ROW row = mysql_fetch_row(pMsg->Get()->pSQLResult);
  3428. BYTE bResult = 0;
  3429. str_to_number(bResult, row[0]);
  3430. if (bResult)
  3431. {
  3432. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Zaten acik tezgahin var tekrar acamazsin.!");
  3433. return;
  3434. }
  3435. }
  3436. // End Of check player is open offline shop or not
  3437. // Check map allows for Offline Shop
  3438. if (g_bOfflineShopMapAllowLimit)
  3439. {
  3440. if (!offlineshop_map_allow_find(GetMapIndex()))
  3441. {
  3442. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Burada tezgah acamazsin.!");
  3443. return;
  3444. }
  3445. }
  3446. // End Of Check map allows for offline shop
  3447. // Need Item For Offline Shop
  3448. if (g_bNeedItem)
  3449. {
  3450. BYTE bCount = quest::CQuestManager::instance().GetCurrentCharacterPtr()->CountSpecifyItem(g_iItemVnum);
  3451. if (bCount < g_bItemCount)
  3452. {
  3453. LPITEM item = ITEM_MANAGER::instance().CreateItem(g_iItemVnum);
  3454. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Tezgah acabilmek icin gerekli nesneler x%d %s", g_bItemCount, item->GetName());
  3455. return;
  3456. }
  3457. }
  3458. // End Of Need Item For Offline Shop
  3459. // Need Money For Offline Shop
  3460. if (g_bNeedMoney)
  3461. {
  3462. if (GetGold() < static_cast<int>(g_dwNeedMoney))
  3463. {
  3464. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Tezgah acabilmek icin gerekli: %u", g_dwNeedMoney);
  3465. return;
  3466. }
  3467. }
  3468. // End Of Need Money For Offline Shop
  3469. char szSign[SHOP_SIGN_MAX_LEN+1];
  3470. strlcpy(szSign, c_pszSign, sizeof(szSign));
  3471. m_stOfflineShopSign = szSign;
  3472. if (m_stOfflineShopSign.length() == 0)
  3473. return;
  3474. if (CBanwordManager::instance().CheckString(m_stShopSign.c_str(), m_stShopSign.length()))
  3475. {
  3476. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("��n��O��i�� A����i�Ƣ� ����CO��E ��oA�� AI����A����I ��oA��A�� ���� ��o ���A��I��U."));
  3477. return;
  3478. }
  3479. LPCHARACTER npc = CHARACTER_MANAGER::instance().SpawnMob(30000, GetMapIndex(), GetX(), GetY(), GetZ(), false, -1, false, true, GetPlayerID());
  3480. if (!npc)
  3481. {
  3482. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Tezgah olusturulamadi, tekrar deneyin.");
  3483. return;
  3484. }
  3485. std::map<DWORD, DWORD> itemkind;
  3486. std::set<TItemPos> cont;
  3487. for (BYTE i = 0; i < bItemCount; ++i)
  3488. {
  3489. if (cont.find((pTable + i)->pos) != cont.end())
  3490. {
  3491. sys_err("MY_OFFLINE_SHOP: duplicate shop item detected! (name: %s)", GetName());
  3492. return;
  3493. }
  3494. // ANTI_GIVE, ANTI_MYSHOP check
  3495. LPITEM pkItem = GetItem((pTable + i)->pos);
  3496. if (pkItem)
  3497. {
  3498. const TItemTable * item_table = pkItem->GetProto();
  3499. if (item_table && (IS_SET(item_table->dwAntiFlags, ITEM_ANTIFLAG_GIVE | ITEM_ANTIFLAG_MY_OFFLINE_SHOP)))
  3500. {
  3501. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Bu nesne satilamaz.");
  3502. return;
  3503. }
  3504. if (pkItem->IsEquipped() == true)
  3505. {
  3506. return;
  3507. }
  3508. if (true == pkItem->isLocked())
  3509. {
  3510. ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Kilitli nesneyi satamazsin.");
  3511. return;
  3512. }
  3513. itemkind[pkItem->GetVnum()] = (pTable + i)->price / pkItem->GetCount();
  3514. char szColumns[QUERY_MAX_LEN], szValues[QUERY_MAX_LEN];
  3515. int iLen = snprintf(szColumns, sizeof(szColumns), "id,owner_id,pos,count,price,vnum");
  3516. 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());
  3517. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",socket0,socket1,socket2");
  3518. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%ld,%ld,%ld", pkItem->GetSocket(0), pkItem->GetSocket(1), pkItem->GetSocket(2));
  3519. iLen += snprintf(szColumns + iLen, sizeof(szColumns) - iLen, ",attrtype0,attrvalue0,attrtype1,attrvalue1,attrtype2,attrvalue2,attrtype3,attrvalue3,attrtype4,attrvalue4,attrtype5,attrvalue5,attrtype6,attrvalue6");
  3520. iUpdateLen += snprintf(szValues + iUpdateLen, sizeof(szValues) - iUpdateLen, ",%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",
  3521. pkItem->GetAttributeType(0), pkItem->GetAttributeValue(0),
  3522. pkItem->GetAttributeType(1), pkItem->GetAttributeValue(1),
  3523. pkItem->GetAttributeType(2), pkItem->GetAttributeValue(2),
  3524. pkItem->GetAttributeType(3), pkItem->GetAttributeValue(3),
  3525. pkItem->GetAttributeType(4), pkItem->GetAttributeValue(4),
  3526. pkItem->GetAttributeType(5), pkItem->GetAttributeValue(5),
  3527. pkItem->GetAttributeType(6), pkItem->GetAttributeValue(6));
  3528. char szInsertQuery[QUERY_MAX_LEN];
  3529. snprintf(szInsertQuery, sizeof(szInsertQuery), "INSERT INTO %soffline_shop_item (%s) VALUES (%s)", get_table_postfix(), szColumns, szValues);
  3530. std::auto_ptr<SQLMsg> pMsg(DBManager::instance().DirectQuery(szInsertQuery));
  3531. pkItem->RemoveFromCharacter();
  3532. }
  3533. cont.insert((pTable + i)->pos);
  3534. }
  3535. // Time Mechanism
  3536. int iTime = 0;
  3537. switch (bTime)
  3538. {
  3539. case 1:
  3540. iTime = 1 * 60 * 60;
  3541. break;
  3542. case 2:
  3543. iTime = 2 * 60 * 60;
  3544. break;
  3545. case 3:
  3546. iTime = 4 * 60 * 60;
  3547. break;
  3548. }
  3549. // If bTime is not equal to unlimited time, start the time!
  3550. if (bTime != 4)
  3551. {
  3552. npc->SetOfflineShopTimer(iTime);
  3553. npc->StartOfflineShopUpdateEvent();
  3554. }
  3555. /*// Insert
  3556. char szQuery2[512];
  3557. 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(), c_pszSign, GetName(), iTime, GetX(), GetY(), GetZ(), GetMapIndex(), g_bChannel);
  3558. DBManager::Instance().DirectQuery(szQuery2);*/
  3559. // Insert
  3560. char szSign2[SHOP_SIGN_MAX_LEN+1];
  3561. DBManager::instance().EscapeString(szSign2,sizeof(szSign2), c_pszSign, strlen(c_pszSign));
  3562. char szQuery2[512];
  3563. 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(), szSign2,GetName(), iTime,GetX(),GetY(),GetZ(),GetMapIndex(), g_bChannel);
  3564. DBManager::Instance().DirectQuery(szQuery2);
  3565. // Create Offline Shop
  3566. LPOFFLINESHOP pkOfflineShop = COfflineShopManager::instance().CreateOfflineShop(npc, GetPlayerID());
  3567. if (!pkOfflineShop)
  3568. {
  3569. ChatPacket(CHAT_TYPE_INFO, "[Off.Tezgah] Tezgah olusturulamadi, tekrar deneyin.");
  3570. return;
  3571. }
  3572. npc->SetOfflineShop(pkOfflineShop);
  3573. npc->SetOfflineShopChannel(g_bChannel);
  3574. // End Of Create Offline Shop
  3575. // Set Name
  3576. char szName[CHARACTER_NAME_MAX_LEN + 1];
  3577. snprintf(szName, sizeof(szName), "|cFF1E90FF %s", GetName());
  3578. npc->SetName(szName);
  3579. // End Of Set Name
  3580. SetOfflineShopVID(npc->GetVID());
  3581. npc->Show(GetMapIndex(), GetX(), GetY(), GetZ(), true);
  3582. // Send Offline Shop Sign to Everyone
  3583. TPacketGCShopSign p;
  3584. p.bHeader = HEADER_GC_OFFLINE_SHOP_SIGN;
  3585. p.dwVID = npc->GetVID();
  3586. strlcpy(p.szSign, c_pszSign, sizeof(p.szSign));
  3587. PacketAround(&p, sizeof(TPacketGCShopSign));
  3588. // End Of Send Offline Shop Sign to Everyone
  3589. if (bTime != 4)
  3590. ChatPacket(CHAT_TYPE_INFO, "[Off.Tezgah] Tezgahinin suresi %d Saat(s) sonra dolacak.", bTime);
  3591. else
  3592. ChatPacket(CHAT_TYPE_INFO, "[Off.Tezgah] Tezgahinin suresi sinirsiz olarak ayarlandi.");
  3593. if (g_bNeedItem)
  3594. {
  3595. LPITEM item = FindSpecifyItem(g_iItemVnum);
  3596. if (!item)
  3597. {
  3598. ChatPacket(CHAT_TYPE_INFO, "Ups! Something going to wrong!");
  3599. return;
  3600. }
  3601. if (item->IsStackable())
  3602. if (item->GetCount() == g_bItemCount)
  3603. ITEM_MANAGER::instance().RemoveItem(item);
  3604. else
  3605. item->SetCount(item->GetCount() - g_bItemCount);
  3606. else
  3607. ITEM_MANAGER::instance().RemoveItem(item);
  3608. }
  3609. if (g_bNeedMoney)
  3610. PointChange(POINT_GOLD, -g_dwNeedMoney, false);
  3611. }
  3612. EVENTFUNC(offline_shop_update_event)
  3613. {
  3614. char_event_info* pInfo = dynamic_cast<char_event_info*>(event->info);
  3615. if (pInfo == NULL)
  3616. {
  3617. sys_err("offline_shop_update_event> <Factor> Null pointer");
  3618. return 0;
  3619. }
  3620. LPCHARACTER npc = pInfo->ch;
  3621. if (npc == NULL)
  3622. return 0;
  3623. int remain_time = npc->GetOfflineShopTimer() - processing_time / passes_per_sec;
  3624. if (remain_time <= 0)
  3625. {
  3626. sys_log(0, "OFFLINE SHOP EXPIRED : expired %s", npc->GetName());
  3627. LPCHARACTER pChar = CHARACTER_MANAGER::instance().Find(npc->GetOfflineShopRealOwner());
  3628. if (pChar)
  3629. {
  3630. pChar->ChatPacket(CHAT_TYPE_INFO, "[Off. Tezgah] Tezgahinin suresi doldu, satistaki itemler sana geri verildi..");
  3631. COfflineShopManager::instance().Giveback(pChar);
  3632. }
  3633. COfflineShopManager::instance().DestroyOfflineShop(NULL, npc->GetVID());
  3634. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), npc->GetOfflineShopRealOwner());
  3635. M2_DESTROY_CHARACTER(npc);
  3636. return 0;
  3637. }
  3638. // If the variable is reach to maximum, start to save it
  3639. if (npc->GetOfflineShopSaveTime() >= g_bOfflineShopSaveTime)
  3640. {
  3641. DBManager::instance().DirectQuery("UPDATE %soffline_shop_npc SET time = %d WHERE owner_id = %u", get_table_postfix(), npc->GetOfflineShopTimer(), npc->GetOfflineShopRealOwner());
  3642. npc->SetOfflineShopTimer(1);
  3643. }
  3644. npc->SetOfflineShopTimer(remain_time);
  3645. npc->SetOfflineShopSaveTime(npc->GetOfflineShopSaveTime() + 1);
  3646. return PASSES_PER_SEC(MIN(60, remain_time));
  3647. }
  3648. void CHARACTER::StartOfflineShopUpdateEvent()
  3649. {
  3650. if (m_pkOfflineShopUpdateEvent)
  3651. return;
  3652. if (IsPC() || IsMonster())
  3653. return;
  3654. char_event_info * pInfo = AllocEventInfo<char_event_info>();
  3655. pInfo->ch = this;
  3656. m_pkOfflineShopUpdateEvent = event_create(offline_shop_update_event, pInfo, PASSES_PER_SEC(60));
  3657. }
  3658. void CHARACTER::StopOfflineShopUpdateEvent()
  3659. {
  3660. m_pointsInstant.bSaveTime = 0;
  3661. m_pointsInstant.leftTime = 0;
  3662. event_cancel(&m_pkOfflineShopUpdateEvent);
  3663. }
  3664. void CHARACTER::SetExchange(CExchange * pkExchange)
  3665. {
  3666. m_pkExchange = pkExchange;
  3667. }
  3668. void CHARACTER::SetPart(BYTE bPartPos, WORD wVal)
  3669. {
  3670. assert(bPartPos < PART_MAX_NUM);
  3671. m_pointsInstant.parts[bPartPos] = wVal;
  3672. }
  3673. WORD CHARACTER::GetPart(BYTE bPartPos) const
  3674. {
  3675. assert(bPartPos < PART_MAX_NUM);
  3676. return m_pointsInstant.parts[bPartPos];
  3677. }
  3678. WORD CHARACTER::GetOriginalPart(BYTE bPartPos) const
  3679. {
  3680. switch (bPartPos)
  3681. {
  3682. case PART_MAIN:
  3683. if (!IsPC()) // PC�� �ƴ� ��� ���� ��Ʈ�� �״�� ����
  3684. return GetPart(PART_MAIN);
  3685. else
  3686. return m_pointsInstant.bBasePart;
  3687. case PART_HAIR:
  3688. return GetPart(PART_HAIR);
  3689. case PART_ACCE:
  3690. return GetPart(PART_ACCE);
  3691. default:
  3692. return 0;
  3693. }
  3694. }
  3695. BYTE CHARACTER::GetCharType() const
  3696. {
  3697. return m_bCharType;
  3698. }
  3699. bool CHARACTER::SetSyncOwner(LPCHARACTER ch, bool bRemoveFromList)
  3700. {
  3701. // TRENT_MONSTER
  3702. if (IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
  3703. return false;
  3704. // END_OF_TRENT_MONSTER
  3705. if (ch == this)
  3706. {
  3707. sys_err("SetSyncOwner owner == this (%p)", this);
  3708. return false;
  3709. }
  3710. if (!ch)
  3711. {
  3712. if (bRemoveFromList && m_pkChrSyncOwner)
  3713. {
  3714. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.remove(this);
  3715. }
  3716. if (m_pkChrSyncOwner)
  3717. sys_log(1, "SyncRelease %s %p from %s", GetName(), this, m_pkChrSyncOwner->GetName());
  3718. // ����Ʈ���� ������� �ʴ�� �����ʹ� NULL�� ���õǾ�� �Ѵ�.
  3719. m_pkChrSyncOwner = NULL;
  3720. }
  3721. else
  3722. {
  3723. if (!IsSyncOwner(ch))
  3724. return false;
  3725. // �Ÿ��� 200 �̻��̸� SyncOwner�� �� �� ���.
  3726. if (DISTANCE_APPROX(GetX() - ch->GetX(), GetY() - ch->GetY()) > 250)
  3727. {
  3728. sys_log(1, "SetSyncOwner distance over than 250 %s %s", GetName(), ch->GetName());
  3729. // SyncOwner�� ��� Owner�� ǥ���Ѵ�.
  3730. if (m_pkChrSyncOwner == ch)
  3731. return true;
  3732. return false;
  3733. }
  3734. if (m_pkChrSyncOwner != ch)
  3735. {
  3736. if (m_pkChrSyncOwner)
  3737. {
  3738. sys_log(1, "SyncRelease %s %p from %s", GetName(), this, m_pkChrSyncOwner->GetName());
  3739. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.remove(this);
  3740. }
  3741. m_pkChrSyncOwner = ch;
  3742. m_pkChrSyncOwner->m_kLst_pkChrSyncOwned.push_back(this);
  3743. // SyncOwner�� �ٲ�� LastSyncTime� �ʱ�ȭ�Ѵ�.
  3744. static const timeval zero_tv = {0, 0};
  3745. SetLastSyncTime(zero_tv);
  3746. sys_log(1, "SetSyncOwner set %s %p to %s", GetName(), this, ch->GetName());
  3747. }
  3748. m_fSyncTime = get_float_time();
  3749. }
  3750. // TODO: Sync Owner�� ����� ��� ��Ŷ� ������ ����Ƿ�,
  3751. // ����ȭ �� �ð��� 3�� �̻� ��� �� Ǯ���ִ� ��Ŷ�
  3752. // ������ ������ �ϸ� ��Ŷ� ���� �� �ִ�.
  3753. TPacketGCOwnership pack;
  3754. pack.bHeader = HEADER_GC_OWNERSHIP;
  3755. pack.dwOwnerVID = ch ? ch->GetVID() : 0;
  3756. pack.dwVictimVID = GetVID();
  3757. PacketAround(&pack, sizeof(TPacketGCOwnership));
  3758. return true;
  3759. }
  3760. struct FuncClearSync
  3761. {
  3762. void operator () (LPCHARACTER ch)
  3763. {
  3764. assert(ch != NULL);
  3765. ch->SetSyncOwner(NULL, false); // false �÷��׷� �ؾ� for_each �� ���� ����.
  3766. }
  3767. };
  3768. void CHARACTER::ClearSync()
  3769. {
  3770. SetSyncOwner(NULL);
  3771. // �Ʒ� for_each���� ���� m_pkChrSyncOwner�� ���� �ڵ��� �����͸� NULL�� �Ѵ�.
  3772. std::for_each(m_kLst_pkChrSyncOwned.begin(), m_kLst_pkChrSyncOwned.end(), FuncClearSync());
  3773. m_kLst_pkChrSyncOwned.clear();
  3774. }
  3775. bool CHARACTER::IsSyncOwner(LPCHARACTER ch) const
  3776. {
  3777. if (m_pkChrSyncOwner == ch)
  3778. return true;
  3779. // ������� ����ȭ �� �ð��� 3�� �̻� ��ٸ� ������� �ƹ����Ե�
  3780. // ���. ��� �ƹ��� SyncOwner�̹Ƿ� true ����
  3781. if (get_float_time() - m_fSyncTime >= 3.0f)
  3782. return true;
  3783. return false;
  3784. }
  3785. void CHARACTER::SetParty(LPPARTY pkParty)
  3786. {
  3787. if (pkParty == m_pkParty)
  3788. return;
  3789. if (pkParty && m_pkParty)
  3790. sys_err("%s is trying to reassigning party (current %p, new party %p)", GetName(), get_pointer(m_pkParty), get_pointer(pkParty));
  3791. sys_log(1, "PARTY set to %p", get_pointer(pkParty));
  3792. //if (m_pkDungeon && IsPC())
  3793. //SetDungeon(NULL);
  3794. m_pkParty = pkParty;
  3795. if (IsPC())
  3796. {
  3797. if (m_pkParty)
  3798. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_PARTY);
  3799. else
  3800. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_PARTY);
  3801. UpdatePacket();
  3802. }
  3803. }
  3804. // PARTY_JOIN_BUG_FIX
  3805. /// ��Ƽ ���� event ���
  3806. EVENTINFO(TPartyJoinEventInfo)
  3807. {
  3808. DWORD dwGuestPID; ///< ��Ƽ�� ���� ij������ PID
  3809. DWORD dwLeaderPID; ///< ��Ƽ ������ PID
  3810. TPartyJoinEventInfo()
  3811. : dwGuestPID( 0 )
  3812. , dwLeaderPID( 0 )
  3813. {
  3814. }
  3815. } ;
  3816. EVENTFUNC(party_request_event)
  3817. {
  3818. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>( event->info );
  3819. if ( info == NULL )
  3820. {
  3821. sys_err( "party_request_event> <Factor> Null pointer" );
  3822. return 0;
  3823. }
  3824. LPCHARACTER ch = CHARACTER_MANAGER::instance().FindByPID(info->dwGuestPID);
  3825. if (ch)
  3826. {
  3827. sys_log(0, "PartyRequestEvent %s", ch->GetName());
  3828. ch->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  3829. ch->SetPartyRequestEvent(NULL);
  3830. }
  3831. return 0;
  3832. }
  3833. bool CHARACTER::RequestToParty(LPCHARACTER leader)
  3834. {
  3835. if (leader->GetParty())
  3836. leader = leader->GetParty()->GetLeaderCharacter();
  3837. if (!leader)
  3838. {
  3839. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("��Ƽ���� ��� ���°� �ƴ϶� ��û� �� �� ���ϴ�."));
  3840. return false;
  3841. }
  3842. if (m_pkPartyRequestEvent)
  3843. return false;
  3844. if (!IsPC() || !leader->IsPC())
  3845. return false;
  3846. if (leader->IsBlockMode(BLOCK_PARTY_REQUEST))
  3847. return false;
  3848. PartyJoinErrCode errcode = IsPartyJoinableCondition(leader, this);
  3849. switch (errcode)
  3850. {
  3851. case PERR_NONE:
  3852. break;
  3853. case PERR_SERVER:
  3854. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ����� ��Ƽ ��� ó���� �� �� ���ϴ�."));
  3855. return false;
  3856. case PERR_DIFFEMPIRE:
  3857. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �ٸ� ����� ��Ƽ�� �̷� �� ���ϴ�."));
  3858. return false;
  3859. case PERR_DUNGEON:
  3860. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� �ȿ����� ��Ƽ �ʴ븦 �� �� ���ϴ�."));
  3861. return false;
  3862. case PERR_OBSERVER:
  3863. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ��忡�� ��Ƽ �ʴ븦 �� �� ���ϴ�."));
  3864. return false;
  3865. case PERR_LVBOUNDARY:
  3866. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> -30 ~ +30 ���� �̳��� ���游 �ʴ��� �� �ֽ�ϴ�."));
  3867. return false;
  3868. case PERR_LOWLEVEL:
  3869. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ְ� ���� ���� 30������ ���� �ʴ��� �� ���ϴ�."));
  3870. return false;
  3871. case PERR_HILEVEL:
  3872. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� ���� ���� ���� 30������ ��� �ʴ��� �� ���ϴ�."));
  3873. return false;
  3874. case PERR_ALREADYJOIN:
  3875. return false;
  3876. case PERR_PARTYISFULL:
  3877. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �� �̻� ��Ƽ��� �ʴ��� �� ���ϴ�."));
  3878. return false;
  3879. default:
  3880. sys_err("Do not process party join error(%d)", errcode);
  3881. return false;
  3882. }
  3883. TPartyJoinEventInfo* info = AllocEventInfo<TPartyJoinEventInfo>();
  3884. info->dwGuestPID = GetPlayerID();
  3885. info->dwLeaderPID = leader->GetPlayerID();
  3886. SetPartyRequestEvent(event_create(party_request_event, info, PASSES_PER_SEC(10)));
  3887. leader->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequest %u", (DWORD) GetVID());
  3888. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("%s �Կ��� ��Ƽ���� ��û� �߽�ϴ�."), leader->GetName());
  3889. return true;
  3890. }
  3891. void CHARACTER::DenyToParty(LPCHARACTER member)
  3892. {
  3893. sys_log(1, "DenyToParty %s member %s %p", GetName(), member->GetName(), get_pointer(member->m_pkPartyRequestEvent));
  3894. if (!member->m_pkPartyRequestEvent)
  3895. return;
  3896. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>(member->m_pkPartyRequestEvent->info);
  3897. if (!info)
  3898. {
  3899. sys_err( "CHARACTER::DenyToParty> <Factor> Null pointer" );
  3900. return;
  3901. }
  3902. if (info->dwGuestPID != member->GetPlayerID())
  3903. return;
  3904. if (info->dwLeaderPID != GetPlayerID())
  3905. return;
  3906. event_cancel(&member->m_pkPartyRequestEvent);
  3907. member->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  3908. }
  3909. void CHARACTER::AcceptToParty(LPCHARACTER member)
  3910. {
  3911. sys_log(1, "AcceptToParty %s member %s %p", GetName(), member->GetName(), get_pointer(member->m_pkPartyRequestEvent));
  3912. if (!member->m_pkPartyRequestEvent)
  3913. return;
  3914. TPartyJoinEventInfo * info = dynamic_cast<TPartyJoinEventInfo *>(member->m_pkPartyRequestEvent->info);
  3915. if (!info)
  3916. {
  3917. sys_err( "CHARACTER::AcceptToParty> <Factor> Null pointer" );
  3918. return;
  3919. }
  3920. if (info->dwGuestPID != member->GetPlayerID())
  3921. return;
  3922. if (info->dwLeaderPID != GetPlayerID())
  3923. return;
  3924. event_cancel(&member->m_pkPartyRequestEvent);
  3925. if (!GetParty())
  3926. member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ ��Ƽ�� �������� �ʽ�ϴ�."));
  3927. else
  3928. {
  3929. if (GetPlayerID() != GetParty()->GetLeaderPID())
  3930. return;
  3931. PartyJoinErrCode errcode = IsPartyJoinableCondition(this, member);
  3932. switch (errcode)
  3933. {
  3934. case PERR_NONE: member->PartyJoin(this); return;
  3935. case PERR_SERVER: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ����� ��Ƽ ��� ó���� �� �� ���ϴ�.")); break;
  3936. case PERR_DUNGEON: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� �ȿ����� ��Ƽ �ʴ븦 �� �� ���ϴ�.")); break;
  3937. case PERR_OBSERVER: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ��忡�� ��Ƽ �ʴ븦 �� �� ���ϴ�.")); break;
  3938. case PERR_LVBOUNDARY: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> -30 ~ +30 ���� �̳��� ���游 �ʴ��� �� �ֽ�ϴ�.")); break;
  3939. case PERR_LOWLEVEL: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ְ� ���� ���� 30������ ���� �ʴ��� �� ���ϴ�.")); break;
  3940. case PERR_HILEVEL: member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� ���� ���� ���� 30������ ��� �ʴ��� �� ���ϴ�.")); break;
  3941. case PERR_ALREADYJOIN: break;
  3942. case PERR_PARTYISFULL: {
  3943. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �� �̻� ��Ƽ��� �ʴ��� �� ���ϴ�."));
  3944. member->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ο������ �ʰ��Ͽ� ��Ƽ�� ���� �� ���ϴ�."));
  3945. break;
  3946. }
  3947. default: sys_err("Do not process party join error(%d)", errcode);
  3948. }
  3949. }
  3950. member->ChatPacket(CHAT_TYPE_COMMAND, "PartyRequestDenied");
  3951. }
  3952. /**
  3953. * ��Ƽ �ʴ� event callback �Լ�.
  3954. * event �� �ߵ��ϸ� �ʴ� ����� ó���Ѵ�.
  3955. */
  3956. EVENTFUNC(party_invite_event)
  3957. {
  3958. TPartyJoinEventInfo * pInfo = dynamic_cast<TPartyJoinEventInfo *>( event->info );
  3959. if ( pInfo == NULL )
  3960. {
  3961. sys_err( "party_invite_event> <Factor> Null pointer" );
  3962. return 0;
  3963. }
  3964. LPCHARACTER pchInviter = CHARACTER_MANAGER::instance().FindByPID(pInfo->dwLeaderPID);
  3965. if (pchInviter)
  3966. {
  3967. sys_log(1, "PartyInviteEvent %s", pchInviter->GetName());
  3968. pchInviter->PartyInviteDeny(pInfo->dwGuestPID);
  3969. }
  3970. return 0;
  3971. }
  3972. void CHARACTER::PartyInvite(LPCHARACTER pchInvitee)
  3973. {
  3974. if (GetParty() && GetParty()->GetLeaderPID() != GetPlayerID())
  3975. {
  3976. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ��� �ʴ��� �� �ִ� ������ ���ϴ�."));
  3977. return;
  3978. }
  3979. else if (pchInvitee->IsBlockMode(BLOCK_PARTY_INVITE))
  3980. {
  3981. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> %s ���� ��Ƽ �ź� �����Դϴ�."), pchInvitee->GetName());
  3982. return;
  3983. }
  3984. PartyJoinErrCode errcode = IsPartyJoinableCondition(this, pchInvitee);
  3985. switch (errcode)
  3986. {
  3987. case PERR_NONE:
  3988. break;
  3989. case PERR_SERVER:
  3990. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ����� ��Ƽ ��� ó���� �� �� ���ϴ�."));
  3991. return;
  3992. case PERR_DIFFEMPIRE:
  3993. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �ٸ� ����� ��Ƽ�� �̷� �� ���ϴ�."));
  3994. return;
  3995. case PERR_DUNGEON:
  3996. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� �ȿ����� ��Ƽ �ʴ븦 �� �� ���ϴ�."));
  3997. return;
  3998. case PERR_OBSERVER:
  3999. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ��忡�� ��Ƽ �ʴ븦 �� �� ���ϴ�."));
  4000. return;
  4001. case PERR_LVBOUNDARY:
  4002. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> -30 ~ +30 ���� �̳��� ���游 �ʴ��� �� �ֽ�ϴ�."));
  4003. return;
  4004. case PERR_LOWLEVEL:
  4005. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ְ� ���� ���� 30������ ���� �ʴ��� �� ���ϴ�."));
  4006. return;
  4007. case PERR_HILEVEL:
  4008. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� ���� ���� ���� 30������ ��� �ʴ��� �� ���ϴ�."));
  4009. return;
  4010. case PERR_ALREADYJOIN:
  4011. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �̹� %s��� ��Ƽ�� ���� �ֽ�ϴ�."), pchInvitee->GetName());
  4012. return;
  4013. case PERR_PARTYISFULL:
  4014. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �� �̻� ��Ƽ��� �ʴ��� �� ���ϴ�."));
  4015. return;
  4016. default:
  4017. sys_err("Do not process party join error(%d)", errcode);
  4018. return;
  4019. }
  4020. if (m_PartyInviteEventMap.end() != m_PartyInviteEventMap.find(pchInvitee->GetPlayerID()))
  4021. return;
  4022. //
  4023. // EventMap �� �̺�Ʈ �߰�
  4024. //
  4025. TPartyJoinEventInfo* info = AllocEventInfo<TPartyJoinEventInfo>();
  4026. info->dwGuestPID = pchInvitee->GetPlayerID();
  4027. info->dwLeaderPID = GetPlayerID();
  4028. m_PartyInviteEventMap.insert(EventMap::value_type(pchInvitee->GetPlayerID(), event_create(party_invite_event, info, PASSES_PER_SEC(10))));
  4029. //
  4030. // �ʴ� �޴� character ���� �ʴ� ��Ŷ ���
  4031. //
  4032. TPacketGCPartyInvite p;
  4033. p.header = HEADER_GC_PARTY_INVITE;
  4034. p.leader_vid = GetVID();
  4035. pchInvitee->GetDesc()->Packet(&p, sizeof(p));
  4036. }
  4037. void CHARACTER::PartyInviteAccept(LPCHARACTER pchInvitee)
  4038. {
  4039. EventMap::iterator itFind = m_PartyInviteEventMap.find(pchInvitee->GetPlayerID());
  4040. if (itFind == m_PartyInviteEventMap.end())
  4041. {
  4042. sys_log(1, "PartyInviteAccept from not invited character(%s)", pchInvitee->GetName());
  4043. return;
  4044. }
  4045. event_cancel(&itFind->second);
  4046. m_PartyInviteEventMap.erase(itFind);
  4047. if (GetParty() && GetParty()->GetLeaderPID() != GetPlayerID())
  4048. {
  4049. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ��� �ʴ��� �� �ִ� ������ ���ϴ�."));
  4050. return;
  4051. }
  4052. PartyJoinErrCode errcode = IsPartyJoinableMutableCondition(this, pchInvitee);
  4053. switch (errcode)
  4054. {
  4055. case PERR_NONE:
  4056. break;
  4057. case PERR_SERVER:
  4058. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ����� ��Ƽ ��� ó���� �� �� ���ϴ�."));
  4059. return;
  4060. case PERR_DUNGEON:
  4061. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� �ȿ����� ��Ƽ �ʴ뿡 ���� �� ���ϴ�."));
  4062. return;
  4063. case PERR_OBSERVER:
  4064. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ���� ��忡�� ��Ƽ �ʴ븦 �� �� ���ϴ�."));
  4065. return;
  4066. case PERR_LVBOUNDARY:
  4067. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> -30 ~ +30 ���� �̳��� ���游 �ʴ��� �� �ֽ�ϴ�."));
  4068. return;
  4069. case PERR_LOWLEVEL:
  4070. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ְ� ���� ���� 30������ ���� �ʴ��� �� ���ϴ�."));
  4071. return;
  4072. case PERR_HILEVEL:
  4073. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� ���� ���� ���� 30������ ��� �ʴ��� �� ���ϴ�."));
  4074. return;
  4075. case PERR_ALREADYJOIN:
  4076. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ �ʴ뿡 ���� �� ���ϴ�."));
  4077. return;
  4078. case PERR_PARTYISFULL:
  4079. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> �� �̻� ��Ƽ��� �ʴ��� �� ���ϴ�."));
  4080. pchInvitee->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> ��Ƽ�� �ο������ �ʰ��Ͽ� ��Ƽ�� ���� �� ���ϴ�."));
  4081. return;
  4082. default:
  4083. sys_err("ignore party join error(%d)", errcode);
  4084. return;
  4085. }
  4086. //
  4087. // ��Ƽ ���� ó��
  4088. //
  4089. if (GetParty())
  4090. pchInvitee->PartyJoin(this);
  4091. else
  4092. {
  4093. LPPARTY pParty = CPartyManager::instance().CreateParty(this);
  4094. pParty->Join(pchInvitee->GetPlayerID());
  4095. pParty->Link(pchInvitee);
  4096. pParty->SendPartyInfoAllToOne(this);
  4097. }
  4098. }
  4099. void CHARACTER::PartyInviteDeny(DWORD dwPID)
  4100. {
  4101. EventMap::iterator itFind = m_PartyInviteEventMap.find(dwPID);
  4102. if (itFind == m_PartyInviteEventMap.end())
  4103. {
  4104. sys_log(1, "PartyInviteDeny to not exist event(inviter PID: %d, invitee PID: %d)", GetPlayerID(), dwPID);
  4105. return;
  4106. }
  4107. event_cancel(&itFind->second);
  4108. m_PartyInviteEventMap.erase(itFind);
  4109. LPCHARACTER pchInvitee = CHARACTER_MANAGER::instance().FindByPID(dwPID);
  4110. if (pchInvitee)
  4111. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> %s���� ��Ƽ �ʴ븦 �����ϼ̽�ϴ�."), pchInvitee->GetName());
  4112. }
  4113. void CHARACTER::PartyJoin(LPCHARACTER pLeader)
  4114. {
  4115. pLeader->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> %s���� ��Ƽ�� ���ϼ̽�ϴ�."), GetName());
  4116. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<��Ƽ> %s���� ��Ƽ�� ���ϼ̽�ϴ�."), pLeader->GetName());
  4117. pLeader->GetParty()->Join(GetPlayerID());
  4118. pLeader->GetParty()->Link(this);
  4119. }
  4120. CHARACTER::PartyJoinErrCode CHARACTER::IsPartyJoinableCondition(const LPCHARACTER pchLeader, const LPCHARACTER pchGuest)
  4121. {
  4122. if (pchLeader->GetEmpire() != pchGuest->GetEmpire())
  4123. return PERR_DIFFEMPIRE;
  4124. return IsPartyJoinableMutableCondition(pchLeader, pchGuest);
  4125. }
  4126. static bool __party_can_join_by_level(LPCHARACTER leader, LPCHARACTER quest)
  4127. {
  4128. int level_limit = 30;
  4129. if (LC_IsCanada())
  4130. level_limit = 15;
  4131. else if (LC_IsBrazil() == true)
  4132. {
  4133. level_limit = 10;
  4134. }
  4135. else
  4136. level_limit = 30;
  4137. return (abs(leader->GetLevel() - quest->GetLevel()) <= level_limit);
  4138. }
  4139. CHARACTER::PartyJoinErrCode CHARACTER::IsPartyJoinableMutableCondition(const LPCHARACTER pchLeader, const LPCHARACTER pchGuest)
  4140. {
  4141. if (!CPartyManager::instance().IsEnablePCParty())
  4142. return PERR_SERVER;
  4143. else if (pchLeader->GetDungeon())
  4144. return PERR_DUNGEON;
  4145. else if (pchGuest->IsObserverMode())
  4146. return PERR_OBSERVER;
  4147. else if (false == __party_can_join_by_level(pchLeader, pchGuest))
  4148. return PERR_LVBOUNDARY;
  4149. else if (pchGuest->GetParty())
  4150. return PERR_ALREADYJOIN;
  4151. else if (pchLeader->GetParty())
  4152. {
  4153. if (pchLeader->GetParty()->GetMemberCount() == PARTY_MAX_MEMBER)
  4154. return PERR_PARTYISFULL;
  4155. }
  4156. return PERR_NONE;
  4157. }
  4158. // END_OF_PARTY_JOIN_BUG_FIX
  4159. void CHARACTER::SetDungeon(LPDUNGEON pkDungeon)
  4160. {
  4161. if (pkDungeon && m_pkDungeon)
  4162. sys_err("%s is trying to reassigning dungeon (current %p, new party %p)", GetName(), get_pointer(m_pkDungeon), get_pointer(pkDungeon));
  4163. if (m_pkDungeon == pkDungeon) {
  4164. return;
  4165. }
  4166. if (m_pkDungeon)
  4167. {
  4168. if (IsPC())
  4169. {
  4170. if (GetParty())
  4171. m_pkDungeon->DecPartyMember(GetParty(), this);
  4172. else
  4173. m_pkDungeon->DecMember(this);
  4174. }
  4175. else if (IsMonster() || IsStone())
  4176. {
  4177. m_pkDungeon->DecMonster();
  4178. }
  4179. }
  4180. m_pkDungeon = pkDungeon;
  4181. if (pkDungeon)
  4182. {
  4183. sys_log(0, "%s DUNGEON set to %p, PARTY is %p", GetName(), get_pointer(pkDungeon), get_pointer(m_pkParty));
  4184. if (IsPC())
  4185. {
  4186. if (GetParty())
  4187. m_pkDungeon->IncPartyMember(GetParty(), this);
  4188. else
  4189. m_pkDungeon->IncMember(this);
  4190. }
  4191. else if (IsMonster() || IsStone())
  4192. {
  4193. m_pkDungeon->IncMonster();
  4194. }
  4195. }
  4196. }
  4197. void CHARACTER::SetWarMap(CWarMap * pWarMap)
  4198. {
  4199. if (m_pWarMap)
  4200. m_pWarMap->DecMember(this);
  4201. m_pWarMap = pWarMap;
  4202. if (m_pWarMap)
  4203. m_pWarMap->IncMember(this);
  4204. }
  4205. void CHARACTER::SetWeddingMap(marriage::WeddingMap* pMap)
  4206. {
  4207. if (m_pWeddingMap)
  4208. m_pWeddingMap->DecMember(this);
  4209. m_pWeddingMap = pMap;
  4210. if (m_pWeddingMap)
  4211. m_pWeddingMap->IncMember(this);
  4212. }
  4213. void CHARACTER::SetRegen(LPREGEN pkRegen)
  4214. {
  4215. m_pkRegen = pkRegen;
  4216. if (pkRegen != NULL) {
  4217. regen_id_ = pkRegen->id;
  4218. }
  4219. m_fRegenAngle = GetRotation();
  4220. m_posRegen = GetXYZ();
  4221. }
  4222. bool CHARACTER::OnIdle()
  4223. {
  4224. return false;
  4225. }
  4226. void CHARACTER::OnMove(bool bIsAttack)
  4227. {
  4228. m_dwLastMoveTime = get_dword_time();
  4229. if (bIsAttack)
  4230. {
  4231. m_dwLastAttackTime = m_dwLastMoveTime;
  4232. if (IsAffectFlag(AFF_REVIVE_INVISIBLE))
  4233. RemoveAffect(AFFECT_REVIVE_INVISIBLE);
  4234. if (IsAffectFlag(AFF_EUNHYUNG))
  4235. {
  4236. RemoveAffect(SKILL_EUNHYUNG);
  4237. SetAffectedEunhyung();
  4238. }
  4239. else
  4240. {
  4241. ClearAffectedEunhyung();
  4242. }
  4243. /*if (IsAffectFlag(AFF_JEONSIN))
  4244. RemoveAffect(SKILL_JEONSINBANGEO);*/
  4245. }
  4246. /*if (IsAffectFlag(AFF_GUNGON))
  4247. RemoveAffect(SKILL_GUNGON);*/
  4248. // MINING
  4249. mining_cancel();
  4250. // END_OF_MINING
  4251. }
  4252. void CHARACTER::OnClick(LPCHARACTER pkChrCauser)
  4253. {
  4254. if (!pkChrCauser)
  4255. {
  4256. sys_err("OnClick %s by NULL", GetName());
  4257. return;
  4258. }
  4259. if (int(pkChrCauser->GetQuestFlag("Kilit.Enable")) == 1)
  4260. {
  4261. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("guvenlik_engel"));
  4262. return;
  4263. }
  4264. DWORD vid = GetVID();
  4265. sys_log(0, "OnClick %s[vnum %d ServerUniqueID %d, pid %d] by %s", GetName(), GetRaceNum(), vid, GetPlayerID(), pkChrCauser->GetName());
  4266. // ���� �����·� ��Ʈ�� ������ �� ���.
  4267. {
  4268. // ��, �ڽ�� �ڽ��� ���� Ŭ���� �� �ִ�.
  4269. if (pkChrCauser->GetMyShop() && pkChrCauser != this)
  4270. {
  4271. sys_err("OnClick Fail (%s->%s) - pc has shop", pkChrCauser->GetName(), GetName());
  4272. return;
  4273. }
  4274. }
  4275. // ��ȯ���϶� ��Ʈ�� ������ �� ���.
  4276. {
  4277. if (pkChrCauser->GetExchange())
  4278. {
  4279. sys_err("OnClick Fail (%s->%s) - pc is exchanging", pkChrCauser->GetName(), GetName());
  4280. return;
  4281. }
  4282. }
  4283. if (IsPC())
  4284. {
  4285. // Ÿ����� ����� ���� PC�� ���� Ŭ���� ��Ʈ�� ó���ϵ��� �մϴ�.
  4286. if (!CTargetManager::instance().GetTargetInfo(pkChrCauser->GetPlayerID(), TARGET_TYPE_VID, GetVID()))
  4287. {
  4288. // 2005.03.17.myevan.Ÿ���� �ƴ� ���� ���� ��� ó�� ���� �۵���Ų��.
  4289. if (GetMyShop())
  4290. {
  4291. if (pkChrCauser->IsDead() == true) return;
  4292. //PREVENT_TRADE_WINDOW
  4293. if (pkChrCauser == this) // �ڱ�� ����
  4294. {
  4295. if ((GetExchange() || IsOpenSafebox() || GetShopOwner()) || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner() )
  4296. {
  4297. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ٸ� �ŷ���(â��,��ȯ,���)���� ���λ��� ����� �� ���ϴ�."));
  4298. return;
  4299. }
  4300. }
  4301. else // �ٸ� ����� Ŭ�������
  4302. {
  4303. // Ŭ���� ����� ��ȯ/â��/���λ��/����̿����̶�� �Ұ�
  4304. if ((pkChrCauser->GetExchange() || pkChrCauser->IsOpenSafebox() || pkChrCauser->GetMyShop() || pkChrCauser->GetShopOwner()) || pkChrCauser->IsCubeOpen() || pkChrCauser->IsAcceOpen() || pkChrCauser->GetOfflineShopOwner() )
  4305. {
  4306. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ٸ� �ŷ���(â��,��ȯ,���)���� ���λ��� ����� �� ���ϴ�."));
  4307. return;
  4308. }
  4309. // Ŭ���� ����� ��ȯ/â��/����̿����̶�� �Ұ�
  4310. //if ((GetExchange() || IsOpenSafebox() || GetShopOwner()))
  4311. if ((GetExchange() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner()))
  4312. {
  4313. pkChrCauser->ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �ٸ� �ŷ��� �ϰ� �ִ� ���Դϴ�."));
  4314. return;
  4315. }
  4316. }
  4317. //END_PREVENT_TRADE_WINDOW
  4318. if (pkChrCauser->GetShop())
  4319. {
  4320. pkChrCauser->GetShop()->RemoveGuest(pkChrCauser);
  4321. pkChrCauser->SetShop(NULL);
  4322. }
  4323. GetMyShop()->AddGuest(pkChrCauser, GetVID(), false);
  4324. pkChrCauser->SetShopOwner(this);
  4325. return;
  4326. }
  4327. if (test_server)
  4328. sys_err("%s.OnClickFailure(%s) - target is PC", pkChrCauser->GetName(), GetName());
  4329. return;
  4330. }
  4331. }
  4332. // Offline Shop
  4333. if (IsOfflineShopNPC())
  4334. {
  4335. pkChrCauser->SetOfflineShopOwner(this);
  4336. GetOfflineShop()->AddGuest(pkChrCauser, this);
  4337. return;
  4338. }
  4339. // û�ҳ�� ��Ʈ ����
  4340. if (LC_IsNewCIBN())
  4341. {
  4342. if (pkChrCauser->IsOverTime(OT_3HOUR))
  4343. {
  4344. sys_log(0, "Teen OverTime : name = %s, hour = %d)", pkChrCauser->GetName(), 3);
  4345. return;
  4346. }
  4347. else if (pkChrCauser->IsOverTime(OT_5HOUR))
  4348. {
  4349. sys_log(0, "Teen OverTime : name = %s, hour = %d)", pkChrCauser->GetName(), 5);
  4350. return;
  4351. }
  4352. }
  4353. pkChrCauser->SetQuestNPCID(GetVID());
  4354. if (quest::CQuestManager::instance().Click(pkChrCauser->GetPlayerID(), this))
  4355. {
  4356. return;
  4357. }
  4358. // NPC ��� ��� ���� : ��� ���� ��
  4359. if (!IsPC())
  4360. {
  4361. if (!m_triggerOnClick.pFunc)
  4362. {
  4363. // NPC Ʈ���� �ý��� �α� ����
  4364. //sys_err("%s.OnClickFailure(%s) : triggerOnClick.pFunc is EMPTY(pid=%d)",
  4365. // pkChrCauser->GetName(),
  4366. // GetName(),
  4367. // pkChrCauser->GetPlayerID());
  4368. return;
  4369. }
  4370. m_triggerOnClick.pFunc(this, pkChrCauser);
  4371. }
  4372. }
  4373. BYTE CHARACTER::GetGMLevel() const
  4374. {
  4375. if (test_server)
  4376. return GM_IMPLEMENTOR;
  4377. return m_pointsInstant.gm_level;
  4378. }
  4379. void CHARACTER::SetGMLevel()
  4380. {
  4381. if (GetDesc())
  4382. {
  4383. m_pointsInstant.gm_level = gm_get_level(GetName(), GetDesc()->GetHostName(), GetDesc()->GetAccountTable().login);
  4384. }
  4385. else
  4386. {
  4387. m_pointsInstant.gm_level = GM_PLAYER;
  4388. }
  4389. }
  4390. BOOL CHARACTER::IsGM() const
  4391. {
  4392. if (m_pointsInstant.gm_level != GM_PLAYER)
  4393. return true;
  4394. if (test_server)
  4395. return true;
  4396. return false;
  4397. }
  4398. void CHARACTER::SetStone(LPCHARACTER pkChrStone)
  4399. {
  4400. m_pkChrStone = pkChrStone;
  4401. if (m_pkChrStone)
  4402. {
  4403. if (pkChrStone->m_set_pkChrSpawnedBy.find(this) == pkChrStone->m_set_pkChrSpawnedBy.end())
  4404. pkChrStone->m_set_pkChrSpawnedBy.insert(this);
  4405. }
  4406. }
  4407. struct FuncDeadSpawnedByStone
  4408. {
  4409. void operator () (LPCHARACTER ch)
  4410. {
  4411. ch->Dead(NULL);
  4412. ch->SetStone(NULL);
  4413. }
  4414. };
  4415. void CHARACTER::ClearStone()
  4416. {
  4417. if (!m_set_pkChrSpawnedBy.empty())
  4418. {
  4419. // ���� �����Ų ���͵�� ��� ���δ�.
  4420. FuncDeadSpawnedByStone f;
  4421. std::for_each(m_set_pkChrSpawnedBy.begin(), m_set_pkChrSpawnedBy.end(), f);
  4422. m_set_pkChrSpawnedBy.clear();
  4423. }
  4424. if (!m_pkChrStone)
  4425. return;
  4426. m_pkChrStone->m_set_pkChrSpawnedBy.erase(this);
  4427. m_pkChrStone = NULL;
  4428. }
  4429. void CHARACTER::ClearTarget()
  4430. {
  4431. if (m_pkChrTarget)
  4432. {
  4433. m_pkChrTarget->m_set_pkChrTargetedBy.erase(this);
  4434. m_pkChrTarget = NULL;
  4435. }
  4436. TPacketGCTarget p;
  4437. p.header = HEADER_GC_TARGET;
  4438. p.dwVID = 0;
  4439. p.bHPPercent = 0;
  4440. CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin();
  4441. while (it != m_set_pkChrTargetedBy.end())
  4442. {
  4443. LPCHARACTER pkChr = *(it++);
  4444. pkChr->m_pkChrTarget = NULL;
  4445. if (!pkChr->GetDesc())
  4446. {
  4447. sys_err("%s %p does not have desc", pkChr->GetName(), get_pointer(pkChr));
  4448. abort();
  4449. }
  4450. pkChr->GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  4451. }
  4452. m_set_pkChrTargetedBy.clear();
  4453. }
  4454. void CHARACTER::SetTarget(LPCHARACTER pkChrTarget)
  4455. {
  4456. if (m_pkChrTarget == pkChrTarget)
  4457. return;
  4458. // CASTLE
  4459. if (IS_CASTLE_MAP(GetMapIndex()) && !IsGM())
  4460. return;
  4461. // CASTLE
  4462. if (m_pkChrTarget)
  4463. m_pkChrTarget->m_set_pkChrTargetedBy.erase(this);
  4464. m_pkChrTarget = pkChrTarget;
  4465. TPacketGCTarget p;
  4466. p.header = HEADER_GC_TARGET;
  4467. if (m_pkChrTarget)
  4468. {
  4469. m_pkChrTarget->m_set_pkChrTargetedBy.insert(this);
  4470. p.dwVID = m_pkChrTarget->GetVID();
  4471. if (m_pkChrTarget->IsPC() && !m_pkChrTarget->IsPolymorphed() || m_pkChrTarget->GetMaxHP() <= 0)
  4472. p.bHPPercent = 0;
  4473. else
  4474. {
  4475. if (m_pkChrTarget->GetRaceNum() == 20101 ||
  4476. m_pkChrTarget->GetRaceNum() == 20102 ||
  4477. m_pkChrTarget->GetRaceNum() == 20103 ||
  4478. m_pkChrTarget->GetRaceNum() == 20104 ||
  4479. m_pkChrTarget->GetRaceNum() == 20105 ||
  4480. m_pkChrTarget->GetRaceNum() == 20106 ||
  4481. m_pkChrTarget->GetRaceNum() == 20107 ||
  4482. m_pkChrTarget->GetRaceNum() == 20108 ||
  4483. m_pkChrTarget->GetRaceNum() == 20109)
  4484. {
  4485. LPCHARACTER owner = m_pkChrTarget->GetVictim();
  4486. if (owner)
  4487. {
  4488. int iHorseHealth = owner->GetHorseHealth();
  4489. int iHorseMaxHealth = owner->GetHorseMaxHealth();
  4490. if (iHorseMaxHealth)
  4491. p.bHPPercent = MINMAX(0, iHorseHealth * 100 / iHorseMaxHealth, 100);
  4492. else
  4493. p.bHPPercent = 100;
  4494. }
  4495. else
  4496. p.bHPPercent = 100;
  4497. }
  4498. else
  4499. p.bHPPercent = MINMAX(0, (m_pkChrTarget->GetHP() * 100) / m_pkChrTarget->GetMaxHP(), 100);
  4500. }
  4501. }
  4502. else
  4503. {
  4504. p.dwVID = 0;
  4505. p.bHPPercent = 0;
  4506. }
  4507. GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  4508. }
  4509. void CHARACTER::BroadcastTargetPacket()
  4510. {
  4511. if (m_set_pkChrTargetedBy.empty())
  4512. return;
  4513. TPacketGCTarget p;
  4514. p.header = HEADER_GC_TARGET;
  4515. p.dwVID = GetVID();
  4516. if (IsPC())
  4517. p.bHPPercent = 0;
  4518. else
  4519. p.bHPPercent = MINMAX(0, (GetHP() * 100) / GetMaxHP(), 100);
  4520. CHARACTER_SET::iterator it = m_set_pkChrTargetedBy.begin();
  4521. while (it != m_set_pkChrTargetedBy.end())
  4522. {
  4523. LPCHARACTER pkChr = *it++;
  4524. if (!pkChr->GetDesc())
  4525. {
  4526. sys_err("%s %p does not have desc", pkChr->GetName(), get_pointer(pkChr));
  4527. abort();
  4528. }
  4529. pkChr->GetDesc()->Packet(&p, sizeof(TPacketGCTarget));
  4530. }
  4531. }
  4532. void CHARACTER::CheckTarget()
  4533. {
  4534. if (!m_pkChrTarget)
  4535. return;
  4536. if (DISTANCE_APPROX(GetX() - m_pkChrTarget->GetX(), GetY() - m_pkChrTarget->GetY()) >= 4800)
  4537. SetTarget(NULL);
  4538. }
  4539. void CHARACTER::SetWarpLocation(long lMapIndex, long x, long y)
  4540. {
  4541. m_posWarp.x = x * 100;
  4542. m_posWarp.y = y * 100;
  4543. m_lWarpMapIndex = lMapIndex;
  4544. }
  4545. void CHARACTER::SaveExitLocation()
  4546. {
  4547. m_posExit = GetXYZ();
  4548. m_lExitMapIndex = GetMapIndex();
  4549. }
  4550. void CHARACTER::ExitToSavedLocation()
  4551. {
  4552. sys_log (0, "ExitToSavedLocation");
  4553. WarpSet(m_posWarp.x, m_posWarp.y, m_lWarpMapIndex);
  4554. m_posExit.x = m_posExit.y = m_posExit.z = 0;
  4555. m_lExitMapIndex = 0;
  4556. }
  4557. // fixme
  4558. // ��ݱ��� privateMapIndex �� ���� �� �ε����� ����� üũ �ϴ� ��� �ܺο��� �ϰ�,
  4559. // �ٸ��� warpset� �ҷ��µ�
  4560. // �̸� warpset ����� ����.
  4561. bool CHARACTER::WarpSet(long x, long y, long lPrivateMapIndex)
  4562. {
  4563. if (!IsPC())
  4564. return false;
  4565. long lAddr;
  4566. long lMapIndex;
  4567. WORD wPort;
  4568. if (!CMapLocation::instance().Get(x, y, lMapIndex, lAddr, wPort))
  4569. {
  4570. sys_err("cannot find map location index %d x %d y %d name %s", lMapIndex, x, y, GetName());
  4571. return false;
  4572. }
  4573. //Send Supplementary Data Block if new map requires security packages in loading this map
  4574. {
  4575. long lCurAddr;
  4576. long lCurMapIndex = 0;
  4577. WORD wCurPort;
  4578. CMapLocation::instance().Get(GetX(), GetY(), lCurMapIndex, lCurAddr, wCurPort);
  4579. //do not send SDB files if char is in the same map
  4580. if( lCurMapIndex != lMapIndex )
  4581. {
  4582. const TMapRegion * rMapRgn = SECTREE_MANAGER::instance().GetMapRegion(lMapIndex);
  4583. {
  4584. DESC_MANAGER::instance().SendClientPackageSDBToLoadMap( GetDesc(), rMapRgn->strMapName.c_str() );
  4585. }
  4586. }
  4587. }
  4588. if (lPrivateMapIndex >= 10000)
  4589. {
  4590. if (lPrivateMapIndex / 10000 != lMapIndex)
  4591. {
  4592. sys_err("Invalid map inedx %d, must be child of %d", lPrivateMapIndex, lMapIndex);
  4593. return false;
  4594. }
  4595. lMapIndex = lPrivateMapIndex;
  4596. }
  4597. Stop();
  4598. Save();
  4599. if (GetSectree())
  4600. {
  4601. GetSectree()->RemoveEntity(this);
  4602. ViewCleanup();
  4603. EncodeRemovePacket(this);
  4604. }
  4605. m_lWarpMapIndex = lMapIndex;
  4606. m_posWarp.x = x;
  4607. m_posWarp.y = y;
  4608. sys_log(0, "WarpSet %s %d %d current map %d target map %d", GetName(), x, y, GetMapIndex(), lMapIndex);
  4609. TPacketGCWarp p;
  4610. p.bHeader = HEADER_GC_WARP;
  4611. p.lX = x;
  4612. p.lY = y;
  4613. p.lAddr = lAddr;
  4614. p.wPort = wPort;
  4615. GetDesc()->Packet(&p, sizeof(TPacketGCWarp));
  4616. //if (!LC_IsNewCIBN())
  4617. {
  4618. char buf[256];
  4619. snprintf(buf, sizeof(buf), "%s MapIdx %ld DestMapIdx%ld DestX%ld DestY%ld Empire%d", GetName(), GetMapIndex(), lPrivateMapIndex, x, y, GetEmpire());
  4620. LogManager::instance().CharLog(this, 0, "WARP", buf);
  4621. }
  4622. return true;
  4623. }
  4624. void CHARACTER::WarpEnd()
  4625. {
  4626. if (test_server)
  4627. sys_log(0, "WarpEnd %s", GetName());
  4628. if (m_posWarp.x == 0 && m_posWarp.y == 0)
  4629. return;
  4630. int index = m_lWarpMapIndex;
  4631. if (index > 10000)
  4632. index /= 10000;
  4633. if (!map_allow_find(index))
  4634. {
  4635. // �� ����� ������ �� ����Ƿ� �����ϱ� �� ��ǥ�� �ǵ�����.
  4636. sys_err("location %d %d not allowed to login this server", m_posWarp.x, m_posWarp.y);
  4637. GetDesc()->SetPhase(PHASE_CLOSE);
  4638. return;
  4639. }
  4640. sys_log(0, "WarpEnd %s %d %u %u", GetName(), m_lWarpMapIndex, m_posWarp.x, m_posWarp.y);
  4641. Show(m_lWarpMapIndex, m_posWarp.x, m_posWarp.y, 0);
  4642. Stop();
  4643. m_lWarpMapIndex = 0;
  4644. m_posWarp.x = m_posWarp.y = m_posWarp.z = 0;
  4645. {
  4646. // P2P Login
  4647. TPacketGGLogin p;
  4648. p.bHeader = HEADER_GG_LOGIN;
  4649. strlcpy(p.szName, GetName(), sizeof(p.szName));
  4650. p.dwPID = GetPlayerID();
  4651. p.bEmpire = GetEmpire();
  4652. p.lMapIndex = SECTREE_MANAGER::instance().GetMapIndex(GetX(), GetY());
  4653. p.bChannel = g_bChannel;
  4654. P2P_MANAGER::instance().Send(&p, sizeof(TPacketGGLogin));
  4655. }
  4656. }
  4657. bool CHARACTER::Return()
  4658. {
  4659. if (!IsNPC())
  4660. return false;
  4661. int x, y;
  4662. /*
  4663. float fDist = DISTANCE_SQRT(m_pkMobData->m_posLastAttacked.x - GetX(), m_pkMobData->m_posLastAttacked.y - GetY());
  4664. float fx, fy;
  4665. GetDeltaByDegree(GetRotation(), fDist, &fx, &fy);
  4666. x = GetX() + (int) fx;
  4667. y = GetY() + (int) fy;
  4668. */
  4669. SetVictim(NULL);
  4670. x = m_pkMobInst->m_posLastAttacked.x;
  4671. y = m_pkMobInst->m_posLastAttacked.y;
  4672. SetRotationToXY(x, y);
  4673. if (!Goto(x, y))
  4674. return false;
  4675. SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
  4676. if (test_server)
  4677. sys_log(0, "%s %p ����ϰ� ���ư���! %d %d", GetName(), this, x, y);
  4678. if (GetParty())
  4679. GetParty()->SendMessage(this, PM_RETURN, x, y);
  4680. return true;
  4681. }
  4682. bool CHARACTER::Follow(LPCHARACTER pkChr, float fMinDistance)
  4683. {
  4684. if (IsPC())
  4685. {
  4686. sys_err("CHARACTER::Follow : PC cannot use this method", GetName());
  4687. return false;
  4688. }
  4689. // TRENT_MONSTER
  4690. if (IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
  4691. {
  4692. if (pkChr->IsPC()) // �Ѿư��� ��밡 PC�� ��
  4693. {
  4694. // If i'm in a party. I must obey party leader's AI.
  4695. if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
  4696. {
  4697. if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000) // ������� ��ݹ���� 15�ʰ� ���
  4698. {
  4699. // ���� ��� ����� ���� 50���� �̻� ���̳��� ����ϰ� ���ư���.
  4700. if (m_pkMobData->m_table.wAttackRange < DISTANCE_APPROX(pkChr->GetX() - GetX(), pkChr->GetY() - GetY()))
  4701. if (Return())
  4702. return true;
  4703. }
  4704. }
  4705. }
  4706. return false;
  4707. }
  4708. // END_OF_TRENT_MONSTER
  4709. long x = pkChr->GetX();
  4710. long y = pkChr->GetY();
  4711. if (pkChr->IsPC()) // �Ѿư��� ��밡 PC�� ��
  4712. {
  4713. // If i'm in a party. I must obey party leader's AI.
  4714. if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
  4715. {
  4716. if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000) // ������� ��ݹ���� 15�ʰ� ���
  4717. {
  4718. // ���� ��� ����� ���� 50���� �̻� ���̳��� ����ϰ� ���ư���.
  4719. if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
  4720. if (Return())
  4721. return true;
  4722. }
  4723. }
  4724. }
  4725. if (IsGuardNPC())
  4726. {
  4727. if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
  4728. if (Return())
  4729. return true;
  4730. }
  4731. if (pkChr->IsState(pkChr->m_stateMove) &&
  4732. GetMobBattleType() != BATTLE_TYPE_RANGE &&
  4733. GetMobBattleType() != BATTLE_TYPE_MAGIC &&
  4734. false == IsPet())
  4735. {
  4736. // ����� �̵����̸� ���� �̵�� �Ѵ�
  4737. // ���� ������ �ӵ���� �Ÿ��κ��� ���� �ð�� ������ ��
  4738. // ������ �� �ð����� ����� �̵��Ѵٰ� ����Ͽ� �ű�� �̵��Ѵ�.
  4739. float rot = pkChr->GetRotation();
  4740. float rot_delta = GetDegreeDelta(rot, GetDegreeFromPositionXY(GetX(), GetY(), pkChr->GetX(), pkChr->GetY()));
  4741. float yourSpeed = pkChr->GetMoveSpeed();
  4742. float mySpeed = GetMoveSpeed();
  4743. float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());
  4744. float fFollowSpeed = mySpeed - yourSpeed * cos(rot_delta * M_PI / 180);
  4745. if (fFollowSpeed >= 0.1f)
  4746. {
  4747. float fMeetTime = fDist / fFollowSpeed;
  4748. float fYourMoveEstimateX, fYourMoveEstimateY;
  4749. if( fMeetTime * yourSpeed <= 100000.0f )
  4750. {
  4751. GetDeltaByDegree(pkChr->GetRotation(), fMeetTime * yourSpeed, &fYourMoveEstimateX, &fYourMoveEstimateY);
  4752. x += (long) fYourMoveEstimateX;
  4753. y += (long) fYourMoveEstimateY;
  4754. float fDistNew = sqrt(((double)x - GetX())*(x-GetX())+((double)y - GetY())*(y-GetY()));
  4755. if (fDist < fDistNew)
  4756. {
  4757. x = (long)(GetX() + (x - GetX()) * fDist / fDistNew);
  4758. y = (long)(GetY() + (y - GetY()) * fDist / fDistNew);
  4759. }
  4760. }
  4761. }
  4762. }
  4763. // ����� �ġ�� �ٶ��� �Ѵ�.
  4764. SetRotationToXY(x, y);
  4765. float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());
  4766. if (fDist <= fMinDistance)
  4767. return false;
  4768. float fx, fy;
  4769. if (IsChangeAttackPosition(pkChr) && GetMobRank() < MOB_RANK_BOSS)
  4770. {
  4771. // ���� �ֺ� ������ ����� �̵�
  4772. SetChangeAttackPositionTime();
  4773. int retry = 16;
  4774. int dx, dy;
  4775. int rot = (int) GetDegreeFromPositionXY(x, y, GetX(), GetY());
  4776. while (--retry)
  4777. {
  4778. if (fDist < 500.0f)
  4779. GetDeltaByDegree((rot + number(-90, 90) + number(-90, 90)) % 360, fMinDistance, &fx, &fy);
  4780. else
  4781. GetDeltaByDegree(number(0, 359), fMinDistance, &fx, &fy);
  4782. dx = x + (int) fx;
  4783. dy = y + (int) fy;
  4784. LPSECTREE tree = SECTREE_MANAGER::instance().Get(GetMapIndex(), dx, dy);
  4785. if (NULL == tree)
  4786. break;
  4787. if (0 == (tree->GetAttribute(dx, dy) & (ATTR_BLOCK | ATTR_OBJECT)))
  4788. break;
  4789. }
  4790. //sys_log(0, "��ó ��򰡷� �̵� %s retry %d", GetName(), retry);
  4791. if (!Goto(dx, dy))
  4792. return false;
  4793. }
  4794. else
  4795. {
  4796. // �� ��󰡱�
  4797. float fDistToGo = fDist - fMinDistance;
  4798. GetDeltaByDegree(GetRotation(), fDistToGo, &fx, &fy);
  4799. //sys_log(0, "����� �̵� %s", GetName());
  4800. if (!Goto(GetX() + (int) fx, GetY() + (int) fy))
  4801. return false;
  4802. }
  4803. SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
  4804. //MonsterLog("�Ѿư���; %s", pkChr->GetName());
  4805. return true;
  4806. }
  4807. float CHARACTER::GetDistanceFromSafeboxOpen() const
  4808. {
  4809. return DISTANCE_APPROX(GetX() - m_posSafeboxOpen.x, GetY() - m_posSafeboxOpen.y);
  4810. }
  4811. void CHARACTER::SetSafeboxOpenPosition()
  4812. {
  4813. m_posSafeboxOpen = GetXYZ();
  4814. }
  4815. CSafebox * CHARACTER::GetSafebox() const
  4816. {
  4817. return m_pkSafebox;
  4818. }
  4819. void CHARACTER::ReqSafeboxLoad(const char* pszPassword)
  4820. {
  4821. if (!*pszPassword || strlen(pszPassword) > SAFEBOX_PASSWORD_MAX_LEN)
  4822. {
  4823. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<â��> �߸�� ��ȣ�� �Է��ϼ̽�ϴ�."));
  4824. return;
  4825. }
  4826. else if (m_pkSafebox)
  4827. {
  4828. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<â��> â�� �̹� �����ֽ�ϴ�."));
  4829. return;
  4830. }
  4831. int iPulse = thecore_pulse();
  4832. if (iPulse - GetSafeboxLoadTime() < PASSES_PER_SEC(10))
  4833. {
  4834. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<â��> â�� ����� 10�� �ȿ��� �� �� ���ϴ�."));
  4835. return;
  4836. }
  4837. /*else if (GetDistanceFromSafeboxOpen() > 1000)
  4838. {
  4839. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("<â��> �Ÿ��� �־ â�� �� �� ���ϴ�."));
  4840. return;
  4841. }*/
  4842. else if (m_bOpeningSafebox)
  4843. {
  4844. sys_log(0, "Overlapped safebox load request from %s", GetName());
  4845. return;
  4846. }
  4847. SetSafeboxLoadTime();
  4848. m_bOpeningSafebox = true;
  4849. TSafeboxLoadPacket p;
  4850. p.dwID = GetDesc()->GetAccountTable().id;
  4851. strlcpy(p.szLogin, GetDesc()->GetAccountTable().login, sizeof(p.szLogin));
  4852. strlcpy(p.szPassword, pszPassword, sizeof(p.szPassword));
  4853. db_clientdesc->DBPacket(HEADER_GD_SAFEBOX_LOAD, GetDesc()->GetHandle(), &p, sizeof(p));
  4854. }
  4855. void CHARACTER::LoadSafebox(int iSize, DWORD dwGold, int iItemCount, TPlayerItem * pItems)
  4856. {
  4857. bool bLoaded = false;
  4858. //PREVENT_TRADE_WINDOW
  4859. SetOpenSafebox(true);
  4860. //END_PREVENT_TRADE_WINDOW
  4861. if (m_pkSafebox)
  4862. bLoaded = true;
  4863. if (!m_pkSafebox)
  4864. m_pkSafebox = M2_NEW CSafebox(this, iSize, dwGold);
  4865. else
  4866. m_pkSafebox->ChangeSize(iSize);
  4867. m_iSafeboxSize = iSize;
  4868. TPacketCGSafeboxSize p;
  4869. p.bHeader = HEADER_GC_SAFEBOX_SIZE;
  4870. p.bSize = iSize;
  4871. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  4872. if (!bLoaded)
  4873. {
  4874. for (int i = 0; i < iItemCount; ++i, ++pItems)
  4875. {
  4876. if (!m_pkSafebox->IsValidPosition(pItems->pos))
  4877. continue;
  4878. LPITEM item = ITEM_MANAGER::instance().CreateItem(pItems->vnum, pItems->count, pItems->id);
  4879. if (!item)
  4880. {
  4881. sys_err("cannot create item vnum %d id %u (name: %s)", pItems->vnum, pItems->id, GetName());
  4882. continue;
  4883. }
  4884. item->SetSkipSave(true);
  4885. item->SetSockets(pItems->alSockets);
  4886. item->SetAttributes(pItems->aAttr);
  4887. if (!m_pkSafebox->Add(pItems->pos, item))
  4888. {
  4889. M2_DESTROY_ITEM(item);
  4890. }
  4891. else
  4892. item->SetSkipSave(false);
  4893. }
  4894. }
  4895. }
  4896. void CHARACTER::ChangeSafeboxSize(BYTE bSize)
  4897. {
  4898. //if (!m_pkSafebox)
  4899. //return;
  4900. TPacketCGSafeboxSize p;
  4901. p.bHeader = HEADER_GC_SAFEBOX_SIZE;
  4902. p.bSize = bSize;
  4903. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  4904. if (m_pkSafebox)
  4905. m_pkSafebox->ChangeSize(bSize);
  4906. m_iSafeboxSize = bSize;
  4907. }
  4908. void CHARACTER::CloseSafebox()
  4909. {
  4910. if (!m_pkSafebox)
  4911. return;
  4912. //PREVENT_TRADE_WINDOW
  4913. SetOpenSafebox(false);
  4914. //END_PREVENT_TRADE_WINDOW
  4915. m_pkSafebox->Save();
  4916. M2_DELETE(m_pkSafebox);
  4917. m_pkSafebox = NULL;
  4918. ChatPacket(CHAT_TYPE_COMMAND, "CloseSafebox");
  4919. SetSafeboxLoadTime();
  4920. m_bOpeningSafebox = false;
  4921. Save();
  4922. }
  4923. CSafebox * CHARACTER::GetMall() const
  4924. {
  4925. return m_pkMall;
  4926. }
  4927. void CHARACTER::LoadMall(int iItemCount, TPlayerItem * pItems)
  4928. {
  4929. bool bLoaded = false;
  4930. if (m_pkMall)
  4931. bLoaded = true;
  4932. if (!m_pkMall)
  4933. m_pkMall = M2_NEW CSafebox(this, 3 * SAFEBOX_PAGE_SIZE, 0);
  4934. else
  4935. m_pkMall->ChangeSize(3 * SAFEBOX_PAGE_SIZE);
  4936. m_pkMall->SetWindowMode(MALL);
  4937. TPacketCGSafeboxSize p;
  4938. p.bHeader = HEADER_GC_MALL_OPEN;
  4939. p.bSize = 3 * SAFEBOX_PAGE_SIZE;
  4940. GetDesc()->Packet(&p, sizeof(TPacketCGSafeboxSize));
  4941. if (!bLoaded)
  4942. {
  4943. for (int i = 0; i < iItemCount; ++i, ++pItems)
  4944. {
  4945. if (!m_pkMall->IsValidPosition(pItems->pos))
  4946. continue;
  4947. LPITEM item = ITEM_MANAGER::instance().CreateItem(pItems->vnum, pItems->count, pItems->id);
  4948. if (!item)
  4949. {
  4950. sys_err("cannot create item vnum %d id %u (name: %s)", pItems->vnum, pItems->id, GetName());
  4951. continue;
  4952. }
  4953. item->SetSkipSave(true);
  4954. item->SetSockets(pItems->alSockets);
  4955. item->SetAttributes(pItems->aAttr);
  4956. if (!m_pkMall->Add(pItems->pos, item))
  4957. M2_DESTROY_ITEM(item);
  4958. else
  4959. item->SetSkipSave(false);
  4960. }
  4961. }
  4962. }
  4963. void CHARACTER::CloseMall()
  4964. {
  4965. if (!m_pkMall)
  4966. return;
  4967. m_pkMall->Save();
  4968. M2_DELETE(m_pkMall);
  4969. m_pkMall = NULL;
  4970. ChatPacket(CHAT_TYPE_COMMAND, "CloseMall");
  4971. }
  4972. bool CHARACTER::BuildUpdatePartyPacket(TPacketGCPartyUpdate & out)
  4973. {
  4974. if (!GetParty())
  4975. return false;
  4976. memset(&out, 0, sizeof(out));
  4977. out.header = HEADER_GC_PARTY_UPDATE;
  4978. out.pid = GetPlayerID();
  4979. out.percent_hp = MINMAX(0, GetHP() * 100 / GetMaxHP(), 100);
  4980. out.role = GetParty()->GetRole(GetPlayerID());
  4981. sys_log(1, "PARTY %s role is %d", GetName(), out.role);
  4982. LPCHARACTER l = GetParty()->GetLeaderCharacter();
  4983. if (l && DISTANCE_APPROX(GetX() - l->GetX(), GetY() - l->GetY()) < PARTY_DEFAULT_RANGE)
  4984. {
  4985. if (g_iUseLocale)
  4986. out.affects[0] = GetParty()->GetPartyBonusExpPercent();
  4987. else
  4988. out.affects[0] = GetParty()->GetExpBonusPercent();
  4989. out.affects[1] = GetPoint(POINT_PARTY_ATTACKER_BONUS);
  4990. out.affects[2] = GetPoint(POINT_PARTY_TANKER_BONUS);
  4991. out.affects[3] = GetPoint(POINT_PARTY_BUFFER_BONUS);
  4992. out.affects[4] = GetPoint(POINT_PARTY_SKILL_MASTER_BONUS);
  4993. out.affects[5] = GetPoint(POINT_PARTY_HASTE_BONUS);
  4994. out.affects[6] = GetPoint(POINT_PARTY_DEFENDER_BONUS);
  4995. }
  4996. return true;
  4997. }
  4998. int CHARACTER::GetLeadershipSkillLevel() const
  4999. {
  5000. return GetSkillLevel(SKILL_LEADERSHIP);
  5001. }
  5002. void CHARACTER::QuerySafeboxSize()
  5003. {
  5004. if (m_iSafeboxSize == -1)
  5005. {
  5006. DBManager::instance().ReturnQuery(QID_SAFEBOX_SIZE,
  5007. GetPlayerID(),
  5008. NULL,
  5009. "SELECT size FROM safebox%s WHERE account_id = %u",
  5010. get_table_postfix(),
  5011. GetDesc()->GetAccountTable().id);
  5012. }
  5013. }
  5014. void CHARACTER::SetSafeboxSize(int iSize)
  5015. {
  5016. sys_log(1, "SetSafeboxSize: %s %d", GetName(), iSize);
  5017. m_iSafeboxSize = iSize;
  5018. DBManager::instance().Query("UPDATE safebox%s SET size = %d WHERE account_id = %u", get_table_postfix(), iSize / SAFEBOX_PAGE_SIZE, GetDesc()->GetAccountTable().id);
  5019. }
  5020. int CHARACTER::GetSafeboxSize() const
  5021. {
  5022. return m_iSafeboxSize;
  5023. }
  5024. void CHARACTER::SetNowWalking(bool bWalkFlag)
  5025. {
  5026. //if (m_bNowWalking != bWalkFlag || IsNPC())
  5027. if (m_bNowWalking != bWalkFlag)
  5028. {
  5029. if (bWalkFlag)
  5030. {
  5031. m_bNowWalking = true;
  5032. m_dwWalkStartTime = get_dword_time();
  5033. }
  5034. else
  5035. {
  5036. m_bNowWalking = false;
  5037. }
  5038. //if (m_bNowWalking)
  5039. {
  5040. TPacketGCWalkMode p;
  5041. p.vid = GetVID();
  5042. p.header = HEADER_GC_WALK_MODE;
  5043. p.mode = m_bNowWalking ? WALKMODE_WALK : WALKMODE_RUN;
  5044. PacketView(&p, sizeof(p));
  5045. }
  5046. if (IsNPC())
  5047. {
  5048. if (m_bNowWalking)
  5049. MonsterLog("�ȴ´�");
  5050. else
  5051. MonsterLog("�ڴ�");
  5052. }
  5053. //sys_log(0, "%s is now %s", GetName(), m_bNowWalking?"walking.":"running.");
  5054. }
  5055. }
  5056. void CHARACTER::StartStaminaConsume()
  5057. {
  5058. if (m_bStaminaConsume)
  5059. return;
  5060. PointChange(POINT_STAMINA, 0);
  5061. m_bStaminaConsume = true;
  5062. //ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec, GetStamina());
  5063. if (IsStaminaHalfConsume())
  5064. ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec / 2, GetStamina());
  5065. else
  5066. ChatPacket(CHAT_TYPE_COMMAND, "StartStaminaConsume %d %d", STAMINA_PER_STEP * passes_per_sec, GetStamina());
  5067. }
  5068. void CHARACTER::StopStaminaConsume()
  5069. {
  5070. if (!m_bStaminaConsume)
  5071. return;
  5072. PointChange(POINT_STAMINA, 0);
  5073. m_bStaminaConsume = false;
  5074. ChatPacket(CHAT_TYPE_COMMAND, "StopStaminaConsume %d", GetStamina());
  5075. }
  5076. bool CHARACTER::IsStaminaConsume() const
  5077. {
  5078. return m_bStaminaConsume;
  5079. }
  5080. bool CHARACTER::IsStaminaHalfConsume() const
  5081. {
  5082. return IsEquipUniqueItem(UNIQUE_ITEM_HALF_STAMINA);
  5083. }
  5084. void CHARACTER::ResetStopTime()
  5085. {
  5086. m_dwStopTime = get_dword_time();
  5087. }
  5088. DWORD CHARACTER::GetStopTime() const
  5089. {
  5090. return m_dwStopTime;
  5091. }
  5092. void CHARACTER::ResetPoint(int iLv)
  5093. {
  5094. BYTE bJob = GetJob();
  5095. PointChange(POINT_LEVEL, iLv - GetLevel());
  5096. SetRealPoint(POINT_ST, JobInitialPoints[bJob].st);
  5097. SetPoint(POINT_ST, GetRealPoint(POINT_ST));
  5098. SetRealPoint(POINT_HT, JobInitialPoints[bJob].ht);
  5099. SetPoint(POINT_HT, GetRealPoint(POINT_HT));
  5100. SetRealPoint(POINT_DX, JobInitialPoints[bJob].dx);
  5101. SetPoint(POINT_DX, GetRealPoint(POINT_DX));
  5102. SetRealPoint(POINT_IQ, JobInitialPoints[bJob].iq);
  5103. SetPoint(POINT_IQ, GetRealPoint(POINT_IQ));
  5104. SetRandomHP((iLv - 1) * number(JobInitialPoints[GetJob()].hp_per_lv_begin, JobInitialPoints[GetJob()].hp_per_lv_end));
  5105. SetRandomSP((iLv - 1) * number(JobInitialPoints[GetJob()].sp_per_lv_begin, JobInitialPoints[GetJob()].sp_per_lv_end));
  5106. //PointChange(POINT_STAT, ((MINMAX(1, iLv, 90) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
  5107. if(iLv <= 105)
  5108. PointChange(POINT_STAT, ((MINMAX(1, iLv, 105) - 1) * 3) + GetPoint(POINT_LEVEL_STEP) - GetPoint(POINT_STAT));
  5109. else
  5110. PointChange(POINT_STAT, 315 - GetPoint(POINT_STAT));
  5111. ComputePoints();
  5112. // ȸ��
  5113. PointChange(POINT_HP, GetMaxHP() - GetHP());
  5114. PointChange(POINT_SP, GetMaxSP() - GetSP());
  5115. PointsPacket();
  5116. LogManager::instance().CharLog(this, 0, "RESET_POINT", "");
  5117. }
  5118. bool CHARACTER::IsChangeAttackPosition(LPCHARACTER target) const
  5119. {
  5120. if (!IsNPC())
  5121. return true;
  5122. DWORD dwChangeTime = AI_CHANGE_ATTACK_POISITION_TIME_NEAR;
  5123. if (DISTANCE_APPROX(GetX() - target->GetX(), GetY() - target->GetY()) >
  5124. AI_CHANGE_ATTACK_POISITION_DISTANCE + GetMobAttackRange())
  5125. dwChangeTime = AI_CHANGE_ATTACK_POISITION_TIME_FAR;
  5126. return get_dword_time() - m_dwLastChangeAttackPositionTime > dwChangeTime;
  5127. }
  5128. void CHARACTER::GiveRandomSkillBook()
  5129. {
  5130. LPITEM item = AutoGiveItem(50300);
  5131. if (NULL != item)
  5132. {
  5133. BYTE bJob = 0;
  5134. if (!number(0, 1))
  5135. bJob = GetJob() + 1;
  5136. DWORD dwSkillVnum = 0;
  5137. do
  5138. {
  5139. dwSkillVnum = number(1, 111);
  5140. const CSkillProto* pkSk = CSkillManager::instance().Get(dwSkillVnum);
  5141. if (NULL == pkSk)
  5142. continue;
  5143. if (bJob && bJob != pkSk->dwType)
  5144. continue;
  5145. break;
  5146. } while (true);
  5147. item->SetSocket(0, dwSkillVnum);
  5148. }
  5149. }
  5150. void CHARACTER::ReviveInvisible(int iDur)
  5151. {
  5152. AddAffect(AFFECT_REVIVE_INVISIBLE, POINT_NONE, 0, AFF_REVIVE_INVISIBLE, iDur, 0, true);
  5153. }
  5154. void CHARACTER::ToggleMonsterLog()
  5155. {
  5156. m_bMonsterLog = !m_bMonsterLog;
  5157. if (m_bMonsterLog)
  5158. {
  5159. CHARACTER_MANAGER::instance().RegisterForMonsterLog(this);
  5160. }
  5161. else
  5162. {
  5163. CHARACTER_MANAGER::instance().UnregisterForMonsterLog(this);
  5164. }
  5165. }
  5166. void CHARACTER::SetGuild(CGuild* pGuild)
  5167. {
  5168. if (m_pGuild != pGuild)
  5169. {
  5170. m_pGuild = pGuild;
  5171. UpdatePacket();
  5172. }
  5173. }
  5174. void CHARACTER::SendGreetMessage()
  5175. {
  5176. typeof(DBManager::instance().GetGreetMessage()) v = DBManager::instance().GetGreetMessage();
  5177. for (itertype(v) it = v.begin(); it != v.end(); ++it)
  5178. {
  5179. ChatPacket(CHAT_TYPE_NOTICE, it->c_str());
  5180. }
  5181. }
  5182. void CHARACTER::BeginStateEmpty()
  5183. {
  5184. MonsterLog("!");
  5185. }
  5186. void CHARACTER::EffectPacket(int enumEffectType)
  5187. {
  5188. TPacketGCSpecialEffect p;
  5189. p.header = HEADER_GC_SEPCIAL_EFFECT;
  5190. p.type = enumEffectType;
  5191. p.vid = GetVID();
  5192. PacketAround(&p, sizeof(TPacketGCSpecialEffect));
  5193. }
  5194. void CHARACTER::SpecificEffectPacket(const char filename[MAX_EFFECT_FILE_NAME])
  5195. {
  5196. TPacketGCSpecificEffect p;
  5197. p.header = HEADER_GC_SPECIFIC_EFFECT;
  5198. p.vid = GetVID();
  5199. memcpy (p.effect_file, filename, MAX_EFFECT_FILE_NAME);
  5200. PacketAround(&p, sizeof(TPacketGCSpecificEffect));
  5201. }
  5202. void CHARACTER::MonsterChat(BYTE bMonsterChatType)
  5203. {
  5204. if (IsPC())
  5205. return;
  5206. char sbuf[256+1];
  5207. if (IsMonster())
  5208. {
  5209. if (number(0, 60))
  5210. return;
  5211. snprintf(sbuf, sizeof(sbuf),
  5212. "(locale.monster_chat[%i] and locale.monster_chat[%i][%d] or '')",
  5213. GetRaceNum(), GetRaceNum(), bMonsterChatType*3 + number(1, 3));
  5214. }
  5215. else
  5216. {
  5217. if (bMonsterChatType != MONSTER_CHAT_WAIT)
  5218. return;
  5219. if (IsGuardNPC())
  5220. {
  5221. if (number(0, 6))
  5222. return;
  5223. }
  5224. else
  5225. {
  5226. if (number(0, 30))
  5227. return;
  5228. }
  5229. 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());
  5230. }
  5231. std::string text = quest::ScriptToString(sbuf);
  5232. if (text.empty())
  5233. return;
  5234. struct packet_chat pack_chat;
  5235. pack_chat.header = HEADER_GC_CHAT;
  5236. pack_chat.size = sizeof(struct packet_chat) + text.size() + 1;
  5237. pack_chat.type = CHAT_TYPE_TALKING;
  5238. pack_chat.id = GetVID();
  5239. pack_chat.bEmpire = 0;
  5240. TEMP_BUFFER buf;
  5241. buf.write(&pack_chat, sizeof(struct packet_chat));
  5242. buf.write(text.c_str(), text.size() + 1);
  5243. PacketAround(buf.read_peek(), buf.size());
  5244. }
  5245. void CHARACTER::SetQuestNPCID(DWORD vid)
  5246. {
  5247. m_dwQuestNPCVID = vid;
  5248. }
  5249. LPCHARACTER CHARACTER::GetQuestNPC() const
  5250. {
  5251. return CHARACTER_MANAGER::instance().Find(m_dwQuestNPCVID);
  5252. }
  5253. void CHARACTER::SetQuestItemPtr(LPITEM item)
  5254. {
  5255. m_pQuestItem = item;
  5256. }
  5257. void CHARACTER::ClearQuestItemPtr()
  5258. {
  5259. m_pQuestItem = NULL;
  5260. }
  5261. LPITEM CHARACTER::GetQuestItemPtr() const
  5262. {
  5263. return m_pQuestItem;
  5264. }
  5265. LPDUNGEON CHARACTER::GetDungeonForce() const
  5266. {
  5267. if (m_lWarpMapIndex > 10000)
  5268. return CDungeonManager::instance().FindByMapIndex(m_lWarpMapIndex);
  5269. return m_pkDungeon;
  5270. }
  5271. void CHARACTER::SetBlockMode(BYTE bFlag)
  5272. {
  5273. m_pointsInstant.bBlockMode = bFlag;
  5274. ChatPacket(CHAT_TYPE_COMMAND, "setblockmode %d", m_pointsInstant.bBlockMode);
  5275. SetQuestFlag("game_option.block_exchange", bFlag & BLOCK_EXCHANGE ? 1 : 0);
  5276. SetQuestFlag("game_option.block_party_invite", bFlag & BLOCK_PARTY_INVITE ? 1 : 0);
  5277. SetQuestFlag("game_option.block_guild_invite", bFlag & BLOCK_GUILD_INVITE ? 1 : 0);
  5278. SetQuestFlag("game_option.block_whisper", bFlag & BLOCK_WHISPER ? 1 : 0);
  5279. SetQuestFlag("game_option.block_messenger_invite", bFlag & BLOCK_MESSENGER_INVITE ? 1 : 0);
  5280. SetQuestFlag("game_option.block_party_request", bFlag & BLOCK_PARTY_REQUEST ? 1 : 0);
  5281. }
  5282. void CHARACTER::SetBlockModeForce(BYTE bFlag)
  5283. {
  5284. m_pointsInstant.bBlockMode = bFlag;
  5285. ChatPacket(CHAT_TYPE_COMMAND, "setblockmode %d", m_pointsInstant.bBlockMode);
  5286. }
  5287. bool CHARACTER::IsGuardNPC() const
  5288. {
  5289. return IsNPC() && (GetRaceNum() == 11000 || GetRaceNum() == 11002 || GetRaceNum() == 11004);
  5290. }
  5291. int CHARACTER::GetPolymorphPower() const
  5292. {
  5293. if (test_server)
  5294. {
  5295. int value = quest::CQuestManager::instance().GetEventFlag("poly");
  5296. if (value)
  5297. return value;
  5298. }
  5299. return aiPolymorphPowerByLevel[MINMAX(0, GetSkillLevel(SKILL_POLYMORPH), 40)];
  5300. }
  5301. void CHARACTER::SetPolymorph(DWORD dwRaceNum, bool bMaintainStat)
  5302. {
  5303. if (dwRaceNum < JOB_MAX_NUM)
  5304. {
  5305. dwRaceNum = 0;
  5306. bMaintainStat = false;
  5307. }
  5308. if (m_dwPolymorphRace == dwRaceNum)
  5309. return;
  5310. m_bPolyMaintainStat = bMaintainStat;
  5311. m_dwPolymorphRace = dwRaceNum;
  5312. sys_log(0, "POLYMORPH: %s race %u ", GetName(), dwRaceNum);
  5313. if (dwRaceNum != 0)
  5314. StopRiding();
  5315. SET_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  5316. m_afAffectFlag.Set(AFF_SPAWN);
  5317. ViewReencode();
  5318. REMOVE_BIT(m_bAddChrState, ADD_CHARACTER_STATE_SPAWN);
  5319. if (!bMaintainStat)
  5320. {
  5321. PointChange(POINT_ST, 0);
  5322. PointChange(POINT_DX, 0);
  5323. PointChange(POINT_IQ, 0);
  5324. PointChange(POINT_HT, 0);
  5325. }
  5326. // ����� ���¿��� �״� ���, ������ Ǯ���� �Ǵµ�
  5327. // �� ���� ���ķ� valid combo interval�� �ٸ��� ������
  5328. // Combo �� �Ǵ� Hacker�� �ν��ϴ� ��찡 �ִ�.
  5329. // ��� ������ Ǯ�ų� ����� �ϰ� �Ǹ�,
  5330. // valid combo interval� reset�Ѵ�.
  5331. SetValidComboInterval(0);
  5332. SetComboSequence(0);
  5333. ComputeBattlePoints();
  5334. }
  5335. int CHARACTER::GetQuestFlag(const std::string& flag) const
  5336. {
  5337. quest::CQuestManager& q = quest::CQuestManager::instance();
  5338. quest::PC* pPC = q.GetPC(GetPlayerID());
  5339. if(!pPC)
  5340. {
  5341. sys_err("Gecersiz GetQuestFlag CHARACTER::GetQuestFlag %lu", GetPlayerID());
  5342. return 0;
  5343. }
  5344. return pPC->GetFlag(flag);
  5345. }
  5346. void CHARACTER::SetQuestFlag(const std::string& flag, int value)
  5347. {
  5348. quest::CQuestManager& q = quest::CQuestManager::instance();
  5349. quest::PC* pPC = q.GetPC(GetPlayerID());
  5350. pPC->SetFlag(flag, value);
  5351. }
  5352. void CHARACTER::DetermineDropMetinStone()
  5353. {
  5354. const int METIN_STONE_NUM = 14;
  5355. static DWORD c_adwMetin[METIN_STONE_NUM] =
  5356. {
  5357. 28030,
  5358. 28031,
  5359. 28032,
  5360. 28033,
  5361. 28034,
  5362. 28035,
  5363. 28036,
  5364. 28037,
  5365. 28038,
  5366. 28039,
  5367. 28040,
  5368. 28041,
  5369. 28042,
  5370. 28043,
  5371. };
  5372. DWORD stone_num = GetRaceNum();
  5373. int idx = std::lower_bound(aStoneDrop, aStoneDrop+STONE_INFO_MAX_NUM, stone_num) - aStoneDrop;
  5374. if (idx >= STONE_INFO_MAX_NUM || aStoneDrop[idx].dwMobVnum != stone_num)
  5375. {
  5376. m_dwDropMetinStone = 0;
  5377. }
  5378. else
  5379. {
  5380. const SStoneDropInfo & info = aStoneDrop[idx];
  5381. m_bDropMetinStonePct = info.iDropPct;
  5382. {
  5383. m_dwDropMetinStone = c_adwMetin[number(0, METIN_STONE_NUM - 1)];
  5384. int iGradePct = number(1, 100);
  5385. for (int iStoneLevel = 0; iStoneLevel < STONE_LEVEL_MAX_NUM; iStoneLevel ++)
  5386. {
  5387. int iLevelGradePortion = info.iLevelPct[iStoneLevel];
  5388. if (iGradePct <= iLevelGradePortion)
  5389. {
  5390. break;
  5391. }
  5392. else
  5393. {
  5394. iGradePct -= iLevelGradePortion;
  5395. m_dwDropMetinStone += 100; // �� +a -> +(a+1)�� �ɶ����� 100�� ��
  5396. }
  5397. }
  5398. }
  5399. }
  5400. }
  5401. void CHARACTER::SendEquipment(LPCHARACTER ch)
  5402. {
  5403. TPacketViewEquip p;
  5404. p.header = HEADER_GC_VIEW_EQUIP;
  5405. p.vid = GetVID();
  5406. int pos[16] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 19, 20, 21, 22, 23 };
  5407. for (int i = 0; i < 16; i++)
  5408. {
  5409. LPITEM item = GetWear(pos[i]);
  5410. if (item)
  5411. {
  5412. p.equips[i].vnum = item->GetVnum();
  5413. p.equips[i].count = item->GetCount();
  5414. thecore_memcpy(p.equips[i].alSockets, item->GetSockets(), sizeof(p.equips[i].alSockets));
  5415. thecore_memcpy(p.equips[i].aAttr, item->GetAttributes(), sizeof(p.equips[i].aAttr));
  5416. }
  5417. else
  5418. {
  5419. p.equips[i].vnum = 0;
  5420. }
  5421. }
  5422. ch->GetDesc()->Packet(&p, sizeof(p));
  5423. }
  5424. bool CHARACTER::CanSummon(int iLeaderShip)
  5425. {
  5426. return (iLeaderShip >= 20 || iLeaderShip >= 12 && m_dwLastDeadTime + 180 > get_dword_time());
  5427. }
  5428. void CHARACTER::MountVnum(DWORD vnum)
  5429. {
  5430. if (m_dwMountVnum == vnum)
  5431. return;
  5432. m_dwMountVnum = vnum;
  5433. m_dwMountTime = get_dword_time();
  5434. if (m_bIsObserver)
  5435. return;
  5436. //NOTE : Mount�Ѵٰ� �ؼ� Client Side�� ��ü�� ������� �ʴ´�.
  5437. //�׸��� ����Side���� ����� �ġ �̵�� ���� �ʴ´�. �ֳ��ϸ� Client Side���� Coliision Adjust�� �Ҽ� �ִµ�
  5438. //��ü�� �Ҹ���״ٰ� �����ġ�� �̵���Ű�� �̶� collision check�� ����� ����Ƿ� ��濡 ���ų� �հ� ������ ����� ����Ѵ�.
  5439. m_posDest.x = m_posStart.x = GetX();
  5440. m_posDest.y = m_posStart.y = GetY();
  5441. //EncodeRemovePacket(this);
  5442. EncodeInsertPacket(this);
  5443. ENTITY_MAP::iterator it = m_map_view.begin();
  5444. while (it != m_map_view.end())
  5445. {
  5446. LPENTITY entity = (it++)->first;
  5447. //Mount�Ѵٰ� �ؼ� Client Side�� ��ü�� ������� �ʴ´�.
  5448. //EncodeRemovePacket(entity);
  5449. //if (!m_bIsObserver)
  5450. EncodeInsertPacket(entity);
  5451. //if (!entity->IsObserverMode())
  5452. // entity->EncodeInsertPacket(this);
  5453. }
  5454. SetValidComboInterval(0);
  5455. SetComboSequence(0);
  5456. ComputePoints();
  5457. }
  5458. namespace {
  5459. class FuncCheckWarp
  5460. {
  5461. public:
  5462. FuncCheckWarp(LPCHARACTER pkWarp)
  5463. {
  5464. m_lTargetY = 0;
  5465. m_lTargetX = 0;
  5466. m_lX = pkWarp->GetX();
  5467. m_lY = pkWarp->GetY();
  5468. m_bInvalid = false;
  5469. m_bEmpire = pkWarp->GetEmpire();
  5470. char szTmp[64];
  5471. if (3 != sscanf(pkWarp->GetName(), " %s %ld %ld ", szTmp, &m_lTargetX, &m_lTargetY))
  5472. {
  5473. if (number(1, 100) < 5)
  5474. sys_err("Warp NPC name wrong : vnum(%d) name(%s)", pkWarp->GetRaceNum(), pkWarp->GetName());
  5475. m_bInvalid = true;
  5476. return;
  5477. }
  5478. m_lTargetX *= 100;
  5479. m_lTargetY *= 100;
  5480. m_bUseWarp = true;
  5481. if (pkWarp->IsGoto())
  5482. {
  5483. LPSECTREE_MAP pkSectreeMap = SECTREE_MANAGER::instance().GetMap(pkWarp->GetMapIndex());
  5484. m_lTargetX += pkSectreeMap->m_setting.iBaseX;
  5485. m_lTargetY += pkSectreeMap->m_setting.iBaseY;
  5486. m_bUseWarp = false;
  5487. }
  5488. }
  5489. bool Valid()
  5490. {
  5491. return !m_bInvalid;
  5492. }
  5493. void operator () (LPENTITY ent)
  5494. {
  5495. if (!Valid())
  5496. return;
  5497. if (!ent->IsType(ENTITY_CHARACTER))
  5498. return;
  5499. LPCHARACTER pkChr = (LPCHARACTER) ent;
  5500. if (!pkChr->IsPC())
  5501. return;
  5502. int iDist = DISTANCE_APPROX(pkChr->GetX() - m_lX, pkChr->GetY() - m_lY);
  5503. if (iDist > 300)
  5504. return;
  5505. if (m_bEmpire && pkChr->GetEmpire() && m_bEmpire != pkChr->GetEmpire())
  5506. return;
  5507. if (pkChr->IsHack())
  5508. return;
  5509. if (!pkChr->CanHandleItem(false, true))
  5510. return;
  5511. if (m_bUseWarp)
  5512. pkChr->WarpSet(m_lTargetX, m_lTargetY);
  5513. else
  5514. {
  5515. pkChr->Show(pkChr->GetMapIndex(), m_lTargetX, m_lTargetY);
  5516. pkChr->Stop();
  5517. }
  5518. }
  5519. bool m_bInvalid;
  5520. bool m_bUseWarp;
  5521. long m_lX;
  5522. long m_lY;
  5523. long m_lTargetX;
  5524. long m_lTargetY;
  5525. BYTE m_bEmpire;
  5526. };
  5527. }
  5528. EVENTFUNC(warp_npc_event)
  5529. {
  5530. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  5531. if ( info == NULL )
  5532. {
  5533. sys_err( "warp_npc_event> <Factor> Null pointer" );
  5534. return 0;
  5535. }
  5536. LPCHARACTER ch = info->ch;
  5537. if (ch == NULL) { // <Factor>
  5538. return 0;
  5539. }
  5540. if (!ch->GetSectree())
  5541. {
  5542. ch->m_pkWarpNPCEvent = NULL;
  5543. return 0;
  5544. }
  5545. FuncCheckWarp f(ch);
  5546. if (f.Valid())
  5547. ch->GetSectree()->ForEachAround(f);
  5548. return passes_per_sec / 2;
  5549. }
  5550. void CHARACTER::ChannelSwitch(int new_ch){
  5551. long lAddr;
  5552. long lMapIndex;
  5553. WORD wPort;
  5554. long x = this->GetX();
  5555. long y = this->GetY();
  5556. if (!CMapLocation::instance().Get(x, y, lMapIndex, lAddr, wPort))
  5557. {
  5558. sys_err("cannot find map location index %d x %d y %d name %s", lMapIndex, x, y, GetName());
  5559. return;
  5560. }
  5561. if(lMapIndex >= 10000)
  5562. {
  5563. return;
  5564. }
  5565. std::map<WORD, int>micha;
  5566. for(int i = 0; i < 6; i++)
  5567. { //replace with maximum channels -1 actual 1300x - 1330x
  5568. for(int i2 = 2; i2 < 9; i2++)
  5569. { //replace with your core values actual 13x02 - 13x08
  5570. micha[13*1000 + i*100 + i2] = i+1;
  5571. }
  5572. }
  5573. //micha[13002] = 1;
  5574. int chan;
  5575. if(micha.find(wPort) != micha.end())
  5576. {
  5577. chan = micha[wPort];
  5578. }
  5579. else
  5580. {
  5581. return;
  5582. }
  5583. Stop();
  5584. Save();
  5585. if(GetSectree())
  5586. {
  5587. GetSectree()->RemoveEntity(this);
  5588. ViewCleanup();
  5589. EncodeRemovePacket(this);
  5590. }
  5591. TPacketGCWarp p;
  5592. p.bHeader = HEADER_GC_WARP;
  5593. p.lX = x;
  5594. p.lY = y;
  5595. p.lAddr = lAddr;
  5596. p.wPort = (wPort - 100*(chan-1) + 100*(new_ch-1));
  5597. GetDesc()->Packet(&p, sizeof(TPacketGCWarp));
  5598. }
  5599. void CHARACTER::StartWarpNPCEvent()
  5600. {
  5601. if (m_pkWarpNPCEvent)
  5602. return;
  5603. if (!IsWarp() && !IsGoto())
  5604. return;
  5605. char_event_info* info = AllocEventInfo<char_event_info>();
  5606. info->ch = this;
  5607. m_pkWarpNPCEvent = event_create(warp_npc_event, info, passes_per_sec / 2);
  5608. }
  5609. void CHARACTER::SyncPacket()
  5610. {
  5611. TEMP_BUFFER buf;
  5612. TPacketCGSyncPositionElement elem;
  5613. elem.dwVID = GetVID();
  5614. elem.lX = GetX();
  5615. elem.lY = GetY();
  5616. TPacketGCSyncPosition pack;
  5617. pack.bHeader = HEADER_GC_SYNC_POSITION;
  5618. pack.wSize = sizeof(TPacketGCSyncPosition) + sizeof(elem);
  5619. buf.write(&pack, sizeof(pack));
  5620. buf.write(&elem, sizeof(elem));
  5621. PacketAround(buf.read_peek(), buf.size());
  5622. }
  5623. LPCHARACTER CHARACTER::GetMarryPartner() const
  5624. {
  5625. return m_pkChrMarried;
  5626. }
  5627. void CHARACTER::SetMarryPartner(LPCHARACTER ch)
  5628. {
  5629. m_pkChrMarried = ch;
  5630. }
  5631. int CHARACTER::GetMarriageBonus(DWORD dwItemVnum, bool bSum)
  5632. {
  5633. if (IsNPC())
  5634. return 0;
  5635. marriage::TMarriage* pMarriage = marriage::CManager::instance().Get(GetPlayerID());
  5636. if (!pMarriage)
  5637. return 0;
  5638. return pMarriage->GetBonus(dwItemVnum, bSum, this);
  5639. }
  5640. void CHARACTER::ConfirmWithMsg(const char* szMsg, int iTimeout, DWORD dwRequestPID)
  5641. {
  5642. if (!IsPC())
  5643. return;
  5644. TPacketGCQuestConfirm p;
  5645. p.header = HEADER_GC_QUEST_CONFIRM;
  5646. p.requestPID = dwRequestPID;
  5647. p.timeout = iTimeout;
  5648. strlcpy(p.msg, szMsg, sizeof(p.msg));
  5649. GetDesc()->Packet(&p, sizeof(p));
  5650. }
  5651. int CHARACTER::GetPremiumRemainSeconds(BYTE bType) const
  5652. {
  5653. if (bType >= PREMIUM_MAX_NUM)
  5654. return 0;
  5655. return m_aiPremiumTimes[bType] - get_global_time();
  5656. }
  5657. bool CHARACTER::WarpToPID(DWORD dwPID)
  5658. {
  5659. LPCHARACTER victim;
  5660. if ((victim = (CHARACTER_MANAGER::instance().FindByPID(dwPID))))
  5661. {
  5662. int mapIdx = victim->GetMapIndex();
  5663. if (IS_SUMMONABLE_ZONE(mapIdx))
  5664. {
  5665. if (CAN_ENTER_ZONE(this, mapIdx))
  5666. {
  5667. WarpSet(victim->GetX(), victim->GetY());
  5668. }
  5669. else
  5670. {
  5671. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �ִ� ����� ������ �� ���ϴ�."));
  5672. return false;
  5673. }
  5674. }
  5675. else
  5676. {
  5677. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �ִ� ����� ������ �� ���ϴ�."));
  5678. return false;
  5679. }
  5680. }
  5681. else
  5682. {
  5683. // �ٸ� ���� �α��ε� ����� ��� -> �޽��� ���� ��ǥ�� �޾ƿ���
  5684. // 1. A.pid, B.pid �� �Ѹ�
  5685. // 2. B.pid�� ���� ���� �Ѹ������ A.pid, ��ǥ �� ����
  5686. // 3. ����
  5687. CCI * pcci = P2P_MANAGER::instance().FindByPID(dwPID);
  5688. if (!pcci)
  5689. {
  5690. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �¶��� ���°� �ƴմϴ�."));
  5691. return false;
  5692. }
  5693. if (pcci->bChannel != g_bChannel)
  5694. {
  5695. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ %d ä�ο� �ֽ�ϴ�. (���� ä�� %d)"), pcci->bChannel, g_bChannel);
  5696. return false;
  5697. }
  5698. else if (false == IS_SUMMONABLE_ZONE(pcci->lMapIndex))
  5699. {
  5700. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �ִ� ����� ������ �� ���ϴ�."));
  5701. return false;
  5702. }
  5703. else
  5704. {
  5705. if (!CAN_ENTER_ZONE(this, pcci->lMapIndex))
  5706. {
  5707. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ �ִ� ����� ������ �� ���ϴ�."));
  5708. return false;
  5709. }
  5710. TPacketGGFindPosition p;
  5711. p.header = HEADER_GG_FIND_POSITION;
  5712. p.dwFromPID = GetPlayerID();
  5713. p.dwTargetPID = dwPID;
  5714. pcci->pkDesc->Packet(&p, sizeof(TPacketGGFindPosition));
  5715. if (test_server)
  5716. ChatPacket(CHAT_TYPE_PARTY, "sent find position packet for teleport");
  5717. }
  5718. }
  5719. return true;
  5720. }
  5721. // ADD_REFINE_BUILDING
  5722. CGuild* CHARACTER::GetRefineGuild() const
  5723. {
  5724. LPCHARACTER chRefineNPC = CHARACTER_MANAGER::instance().Find(m_dwRefineNPCVID);
  5725. return (chRefineNPC ? chRefineNPC->GetGuild() : NULL);
  5726. }
  5727. bool CHARACTER::IsRefineThroughGuild() const
  5728. {
  5729. return GetRefineGuild() != NULL;
  5730. }
  5731. int CHARACTER::ComputeRefineFee(int iCost, int iMultiply) const
  5732. {
  5733. CGuild* pGuild = GetRefineGuild();
  5734. if (pGuild)
  5735. {
  5736. if (pGuild == GetGuild())
  5737. return iCost * iMultiply * 9 / 10;
  5738. // �ٸ� ��� ����� �õ��ϴ� ��� �߰��� 3�� ��
  5739. LPCHARACTER chRefineNPC = CHARACTER_MANAGER::instance().Find(m_dwRefineNPCVID);
  5740. if (chRefineNPC && chRefineNPC->GetEmpire() != GetEmpire())
  5741. return iCost * iMultiply * 3;
  5742. return iCost * iMultiply;
  5743. }
  5744. else
  5745. return iCost;
  5746. }
  5747. void CHARACTER::PayRefineFee(int iTotalMoney)
  5748. {
  5749. int iFee = iTotalMoney / 10;
  5750. CGuild* pGuild = GetRefineGuild();
  5751. int iRemain = iTotalMoney;
  5752. if (pGuild)
  5753. {
  5754. // �ڱ� ����̸� iTotalMoney�� �̹� 10%�� ��ܵǾ��ִ�
  5755. if (pGuild != GetGuild())
  5756. {
  5757. pGuild->RequestDepositMoney(this, iFee);
  5758. iRemain -= iFee;
  5759. }
  5760. }
  5761. PointChange(POINT_GOLD, -iRemain);
  5762. }
  5763. // END_OF_ADD_REFINE_BUILDING
  5764. //Hack ���� ��� üũ.
  5765. bool CHARACTER::IsHack(bool bSendMsg, bool bCheckShopOwner, int limittime)
  5766. {
  5767. const int iPulse = thecore_pulse();
  5768. if (test_server)
  5769. bSendMsg = true;
  5770. //â�� ���� üũ
  5771. if (iPulse - GetSafeboxLoadTime() < PASSES_PER_SEC(limittime))
  5772. {
  5773. if (bSendMsg)
  5774. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("â�� ���� %d�� �̳����� �ٸ������ �̵��Ҽ� ���ϴ�."), limittime);
  5775. if (test_server)
  5776. ChatPacket(CHAT_TYPE_INFO, "[TestOnly]Pulse %d LoadTime %d PASS %d", iPulse, GetSafeboxLoadTime(), PASSES_PER_SEC(limittime));
  5777. return true;
  5778. }
  5779. //�ŷ���� â üũ
  5780. if (bCheckShopOwner)
  5781. {
  5782. if (GetExchange() || GetMyShop() || GetShopOwner() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner())
  5783. {
  5784. if (bSendMsg)
  5785. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ŷ�â,â�� ��� �� ���¿����� �ٸ������ �̵�,��� �Ҽ� ���ϴ�"));
  5786. return true;
  5787. }
  5788. }
  5789. else
  5790. {
  5791. if (GetExchange() || GetMyShop() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen())
  5792. {
  5793. if (bSendMsg)
  5794. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ŷ�â,â�� ��� �� ���¿����� �ٸ������ �̵�,��� �Ҽ� ���ϴ�"));
  5795. return true;
  5796. }
  5797. }
  5798. //PREVENT_PORTAL_AFTER_EXCHANGE
  5799. //��ȯ �� �ð�üũ
  5800. if (iPulse - GetExchangeTime() < PASSES_PER_SEC(limittime))
  5801. {
  5802. if (bSendMsg)
  5803. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ŷ� �� %d�� �̳����� �ٸ������ �̵� �� �� ���ϴ�."), limittime );
  5804. return true;
  5805. }
  5806. //END_PREVENT_PORTAL_AFTER_EXCHANGE
  5807. //PREVENT_ITEM_COPY
  5808. if (iPulse - GetMyShopTime() < PASSES_PER_SEC(limittime))
  5809. {
  5810. if (bSendMsg)
  5811. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("�ŷ� �� %d�� �̳����� �ٸ������ �̵� �� �� ���ϴ�."), limittime);
  5812. return true;
  5813. }
  5814. if (iPulse - GetRefineTime() < PASSES_PER_SEC(limittime))
  5815. {
  5816. if (bSendMsg)
  5817. ChatPacket(CHAT_TYPE_INFO, LC_TEXT("������ ������ %d�� �̳����� ��ȯ��,��ȯ���θ� ����� �� ���ϴ�."), limittime);
  5818. return true;
  5819. }
  5820. //END_PREVENT_ITEM_COPY
  5821. return false;
  5822. }
  5823. BOOL CHARACTER::IsMonarch() const
  5824. {
  5825. //MONARCH_LIMIT
  5826. if (CMonarch::instance().IsMonarch(GetPlayerID(), GetEmpire()))
  5827. return true;
  5828. return false;
  5829. //END_MONARCH_LIMIT
  5830. }
  5831. void CHARACTER::Say(const std::string & s)
  5832. {
  5833. struct ::packet_script packet_script;
  5834. packet_script.header = HEADER_GC_SCRIPT;
  5835. packet_script.skin = 1;
  5836. packet_script.src_size = s.size();
  5837. packet_script.size = packet_script.src_size + sizeof(struct packet_script);
  5838. TEMP_BUFFER buf;
  5839. buf.write(&packet_script, sizeof(struct packet_script));
  5840. buf.write(&s[0], s.size());
  5841. if (IsPC())
  5842. {
  5843. GetDesc()->Packet(buf.read_peek(), buf.size());
  5844. }
  5845. }
  5846. //
  5847. // Monarch
  5848. //
  5849. void CHARACTER::InitMC()
  5850. {
  5851. for (int n = 0; n < MI_MAX; ++n)
  5852. {
  5853. m_dwMonarchCooltime[n] = thecore_pulse();
  5854. }
  5855. m_dwMonarchCooltimelimit[MI_HEAL] = PASSES_PER_SEC(MC_HEAL);
  5856. m_dwMonarchCooltimelimit[MI_WARP] = PASSES_PER_SEC(MC_WARP);
  5857. m_dwMonarchCooltimelimit[MI_TRANSFER] = PASSES_PER_SEC(MC_TRANSFER);
  5858. m_dwMonarchCooltimelimit[MI_TAX] = PASSES_PER_SEC(MC_TAX);
  5859. m_dwMonarchCooltimelimit[MI_SUMMON] = PASSES_PER_SEC(MC_SUMMON);
  5860. m_dwMonarchCooltime[MI_HEAL] -= PASSES_PER_SEC(GetMCL(MI_HEAL));
  5861. m_dwMonarchCooltime[MI_WARP] -= PASSES_PER_SEC(GetMCL(MI_WARP));
  5862. m_dwMonarchCooltime[MI_TRANSFER] -= PASSES_PER_SEC(GetMCL(MI_TRANSFER));
  5863. m_dwMonarchCooltime[MI_TAX] -= PASSES_PER_SEC(GetMCL(MI_TAX));
  5864. m_dwMonarchCooltime[MI_SUMMON] -= PASSES_PER_SEC(GetMCL(MI_SUMMON));
  5865. }
  5866. DWORD CHARACTER::GetMC(enum MONARCH_INDEX e) const
  5867. {
  5868. return m_dwMonarchCooltime[e];
  5869. }
  5870. void CHARACTER::SetMC(enum MONARCH_INDEX e)
  5871. {
  5872. m_dwMonarchCooltime[e] = thecore_pulse();
  5873. }
  5874. bool CHARACTER::IsMCOK(enum MONARCH_INDEX e) const
  5875. {
  5876. int iPulse = thecore_pulse();
  5877. if ((iPulse - GetMC(e)) < GetMCL(e))
  5878. {
  5879. if (test_server)
  5880. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  5881. return false;
  5882. }
  5883. if (test_server)
  5884. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  5885. return true;
  5886. }
  5887. DWORD CHARACTER::GetMCL(enum MONARCH_INDEX e) const
  5888. {
  5889. return m_dwMonarchCooltimelimit[e];
  5890. }
  5891. DWORD CHARACTER::GetMCLTime(enum MONARCH_INDEX e) const
  5892. {
  5893. int iPulse = thecore_pulse();
  5894. if (test_server)
  5895. sys_log(0, " Pulse %d cooltime %d, limit %d", iPulse, GetMC(e), GetMCL(e));
  5896. return (GetMCL(e)) / passes_per_sec - (iPulse - GetMC(e)) / passes_per_sec;
  5897. }
  5898. bool CHARACTER::IsSiegeNPC() const
  5899. {
  5900. return IsNPC() && (GetRaceNum() == 11000 || GetRaceNum() == 11002 || GetRaceNum() == 11004);
  5901. }
  5902. //------------------------------------------------
  5903. void CHARACTER::UpdateDepositPulse()
  5904. {
  5905. m_deposit_pulse = thecore_pulse() + PASSES_PER_SEC(60*5); // 5��
  5906. }
  5907. bool CHARACTER::CanDeposit() const
  5908. {
  5909. return (m_deposit_pulse == 0 || (m_deposit_pulse < thecore_pulse()));
  5910. }
  5911. //------------------------------------------------
  5912. ESex GET_SEX(LPCHARACTER ch)
  5913. {
  5914. switch (ch->GetRaceNum())
  5915. {
  5916. case MAIN_RACE_WARRIOR_M:
  5917. case MAIN_RACE_SURA_M:
  5918. case MAIN_RACE_ASSASSIN_M:
  5919. case MAIN_RACE_SHAMAN_M:
  5920. return SEX_MALE;
  5921. case MAIN_RACE_ASSASSIN_W:
  5922. case MAIN_RACE_SHAMAN_W:
  5923. case MAIN_RACE_WARRIOR_W:
  5924. case MAIN_RACE_SURA_W:
  5925. return SEX_FEMALE;
  5926. }
  5927. /* default sex = male */
  5928. return SEX_MALE;
  5929. }
  5930. int CHARACTER::GetHPPct() const
  5931. {
  5932. return (GetHP() * 100) / GetMaxHP();
  5933. }
  5934. bool CHARACTER::IsBerserk() const
  5935. {
  5936. if (m_pkMobInst != NULL)
  5937. return m_pkMobInst->m_IsBerserk;
  5938. else
  5939. return false;
  5940. }
  5941. void CHARACTER::SetBerserk(bool mode)
  5942. {
  5943. if (m_pkMobInst != NULL)
  5944. m_pkMobInst->m_IsBerserk = mode;
  5945. }
  5946. bool CHARACTER::IsGodSpeed() const
  5947. {
  5948. if (m_pkMobInst != NULL)
  5949. {
  5950. return m_pkMobInst->m_IsGodSpeed;
  5951. }
  5952. else
  5953. {
  5954. return false;
  5955. }
  5956. }
  5957. void CHARACTER::SetGodSpeed(bool mode)
  5958. {
  5959. if (m_pkMobInst != NULL)
  5960. {
  5961. m_pkMobInst->m_IsGodSpeed = mode;
  5962. if (mode == true)
  5963. {
  5964. SetPoint(POINT_ATT_SPEED, 250);
  5965. }
  5966. else
  5967. {
  5968. SetPoint(POINT_ATT_SPEED, m_pkMobData->m_table.sAttackSpeed);
  5969. }
  5970. }
  5971. }
  5972. bool CHARACTER::IsDeathBlow() const
  5973. {
  5974. if (number(1, 100) <= m_pkMobData->m_table.bDeathBlowPoint)
  5975. {
  5976. return true;
  5977. }
  5978. else
  5979. {
  5980. return false;
  5981. }
  5982. }
  5983. struct FFindReviver
  5984. {
  5985. FFindReviver()
  5986. {
  5987. pChar = NULL;
  5988. HasReviver = false;
  5989. }
  5990. void operator() (LPCHARACTER ch)
  5991. {
  5992. if (ch->IsMonster() != true)
  5993. {
  5994. return;
  5995. }
  5996. if (ch->IsReviver() == true && pChar != ch && ch->IsDead() != true)
  5997. {
  5998. if (number(1, 100) <= ch->GetMobTable().bRevivePoint)
  5999. {
  6000. HasReviver = true;
  6001. pChar = ch;
  6002. }
  6003. }
  6004. }
  6005. LPCHARACTER pChar;
  6006. bool HasReviver;
  6007. };
  6008. bool CHARACTER::HasReviverInParty() const
  6009. {
  6010. LPPARTY party = GetParty();
  6011. if (party != NULL)
  6012. {
  6013. if (party->GetMemberCount() == 1) return false;
  6014. FFindReviver f;
  6015. party->ForEachMemberPtr(f);
  6016. return f.HasReviver;
  6017. }
  6018. return false;
  6019. }
  6020. bool CHARACTER::IsRevive() const
  6021. {
  6022. if (m_pkMobInst != NULL)
  6023. {
  6024. return m_pkMobInst->m_IsRevive;
  6025. }
  6026. return false;
  6027. }
  6028. void CHARACTER::SetRevive(bool mode)
  6029. {
  6030. if (m_pkMobInst != NULL)
  6031. {
  6032. m_pkMobInst->m_IsRevive = mode;
  6033. }
  6034. }
  6035. #define IS_SPEED_HACK_PLAYER(ch) (ch->m_speed_hack_count > SPEEDHACK_LIMIT_COUNT)
  6036. EVENTFUNC(check_speedhack_event)
  6037. {
  6038. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  6039. if ( info == NULL )
  6040. {
  6041. sys_err( "check_speedhack_event> <Factor> Null pointer" );
  6042. return 0;
  6043. }
  6044. LPCHARACTER ch = info->ch;
  6045. if (NULL == ch || ch->IsNPC())
  6046. return 0;
  6047. if (IS_SPEED_HACK_PLAYER(ch))
  6048. {
  6049. // write hack log
  6050. LogManager::instance().SpeedHackLog(ch->GetPlayerID(), ch->GetX(), ch->GetY(), ch->m_speed_hack_count);
  6051. if (false == LC_IsEurope())
  6052. {
  6053. // close connection
  6054. LPDESC desc = ch->GetDesc();
  6055. if (desc)
  6056. {
  6057. DESC_MANAGER::instance().DestroyDesc(desc);
  6058. return 0;
  6059. }
  6060. }
  6061. }
  6062. ch->m_speed_hack_count = 0;
  6063. ch->ResetComboHackCount();
  6064. return PASSES_PER_SEC(60);
  6065. }
  6066. void CHARACTER::StartCheckSpeedHackEvent()
  6067. {
  6068. if (m_pkCheckSpeedHackEvent)
  6069. return;
  6070. char_event_info* info = AllocEventInfo<char_event_info>();
  6071. info->ch = this;
  6072. m_pkCheckSpeedHackEvent = event_create(check_speedhack_event, info, PASSES_PER_SEC(60)); // 1��
  6073. }
  6074. void CHARACTER::GoHome()
  6075. {
  6076. WarpSet(EMPIRE_START_X(GetEmpire()), EMPIRE_START_Y(GetEmpire()));
  6077. }
  6078. void CHARACTER::SendGuildName(CGuild* pGuild)
  6079. {
  6080. if (NULL == pGuild) return;
  6081. DESC *desc = GetDesc();
  6082. if (NULL == desc) return;
  6083. if (m_known_guild.find(pGuild->GetID()) != m_known_guild.end()) return;
  6084. m_known_guild.insert(pGuild->GetID());
  6085. TPacketGCGuildName pack;
  6086. memset(&pack, 0x00, sizeof(pack));
  6087. pack.header = HEADER_GC_GUILD;
  6088. pack.subheader = GUILD_SUBHEADER_GC_GUILD_NAME;
  6089. pack.size = sizeof(TPacketGCGuildName);
  6090. pack.guildID = pGuild->GetID();
  6091. memcpy(pack.guildName, pGuild->GetName(), GUILD_NAME_MAX_LEN);
  6092. desc->Packet(&pack, sizeof(pack));
  6093. }
  6094. void CHARACTER::SendGuildName(DWORD dwGuildID)
  6095. {
  6096. SendGuildName(CGuildManager::instance().FindGuild(dwGuildID));
  6097. }
  6098. EVENTFUNC(destroy_when_idle_event)
  6099. {
  6100. char_event_info* info = dynamic_cast<char_event_info*>( event->info );
  6101. if ( info == NULL )
  6102. {
  6103. sys_err( "destroy_when_idle_event> <Factor> Null pointer" );
  6104. return 0;
  6105. }
  6106. LPCHARACTER ch = info->ch;
  6107. if (ch == NULL) { // <Factor>
  6108. return 0;
  6109. }
  6110. if (ch->GetVictim())
  6111. {
  6112. return PASSES_PER_SEC(300);
  6113. }
  6114. sys_log(1, "DESTROY_WHEN_IDLE: %s", ch->GetName());
  6115. ch->m_pkDestroyWhenIdleEvent = NULL;
  6116. M2_DESTROY_CHARACTER(ch);
  6117. return 0;
  6118. }
  6119. void CHARACTER::StartDestroyWhenIdleEvent()
  6120. {
  6121. if (m_pkDestroyWhenIdleEvent)
  6122. return;
  6123. char_event_info* info = AllocEventInfo<char_event_info>();
  6124. info->ch = this;
  6125. m_pkDestroyWhenIdleEvent = event_create(destroy_when_idle_event, info, PASSES_PER_SEC(300));
  6126. }
  6127. void CHARACTER::SetComboSequence(BYTE seq)
  6128. {
  6129. m_bComboSequence = seq;
  6130. }
  6131. BYTE CHARACTER::GetComboSequence() const
  6132. {
  6133. return m_bComboSequence;
  6134. }
  6135. void CHARACTER::SetLastComboTime(DWORD time)
  6136. {
  6137. m_dwLastComboTime = time;
  6138. }
  6139. DWORD CHARACTER::GetLastComboTime() const
  6140. {
  6141. return m_dwLastComboTime;
  6142. }
  6143. void CHARACTER::SetValidComboInterval(int interval)
  6144. {
  6145. m_iValidComboInterval = interval;
  6146. }
  6147. int CHARACTER::GetValidComboInterval() const
  6148. {
  6149. return m_iValidComboInterval;
  6150. }
  6151. BYTE CHARACTER::GetComboIndex() const
  6152. {
  6153. return m_bComboIndex;
  6154. }
  6155. void CHARACTER::IncreaseComboHackCount(int k)
  6156. {
  6157. m_iComboHackCount += k;
  6158. if (m_iComboHackCount >= 10)
  6159. {
  6160. if (GetDesc())
  6161. if (GetDesc()->DelayedDisconnect(number(2, 7)))
  6162. {
  6163. sys_log(0, "COMBO_HACK_DISCONNECT: %s count: %d", GetName(), m_iComboHackCount);
  6164. LogManager::instance().HackLog("Combo", this);
  6165. }
  6166. }
  6167. }
  6168. void CHARACTER::ResetComboHackCount()
  6169. {
  6170. m_iComboHackCount = 0;
  6171. }
  6172. void CHARACTER::SkipComboAttackByTime(int interval)
  6173. {
  6174. m_dwSkipComboAttackByTime = get_dword_time() + interval;
  6175. }
  6176. DWORD CHARACTER::GetSkipComboAttackByTime() const
  6177. {
  6178. return m_dwSkipComboAttackByTime;
  6179. }
  6180. void CHARACTER::ResetChatCounter()
  6181. {
  6182. m_bChatCounter = 0;
  6183. }
  6184. BYTE CHARACTER::IncreaseChatCounter()
  6185. {
  6186. return ++m_bChatCounter;
  6187. }
  6188. BYTE CHARACTER::GetChatCounter() const
  6189. {
  6190. return m_bChatCounter;
  6191. }
  6192. // ���̳� �ٸ���� Ÿ�� �ֳ�?
  6193. bool CHARACTER::IsRiding() const
  6194. {
  6195. return IsHorseRiding() || GetMountVnum();
  6196. }
  6197. bool CHARACTER::CanWarp() const
  6198. {
  6199. const int iPulse = thecore_pulse();
  6200. const int limit_time = PASSES_PER_SEC(g_nPortalLimitTime);
  6201. if ((iPulse - GetSafeboxLoadTime()) < limit_time)
  6202. return false;
  6203. if ((iPulse - GetExchangeTime()) < limit_time)
  6204. return false;
  6205. if ((iPulse - GetMyShopTime()) < limit_time)
  6206. return false;
  6207. if ((iPulse - GetRefineTime()) < limit_time)
  6208. return false;
  6209. if (GetExchange() || GetMyShop() || GetShopOwner() || IsOpenSafebox() || IsCubeOpen() || IsAcceOpen() || GetOfflineShopOwner())
  6210. return false;
  6211. return true;
  6212. }
  6213. DWORD CHARACTER::GetNextExp() const
  6214. {
  6215. if (PLAYER_EXP_TABLE_MAX < GetLevel())
  6216. return 2500000000;
  6217. else
  6218. return exp_table[GetLevel()];
  6219. }
  6220. int CHARACTER::GetSkillPowerByLevel(int level, bool bMob) const
  6221. {
  6222. return CTableBySkill::instance().GetSkillPowerByLevelFromType(GetJob(), GetSkillGroup(), MINMAX(0, level, SKILL_MAX_LEVEL), bMob);
  6223. }
  6224. void CHARACTER::SetOfflineShopSign(const char * c_szSign)
  6225. {
  6226. char szSign[SHOP_SIGN_MAX_LEN + 1];
  6227. strlcpy(szSign, c_szSign, sizeof(szSign));
  6228. m_stOfflineShopSign = szSign;
  6229. }
  6230. void CHARACTER::DestroyOfflineShop()
  6231. {
  6232. DBManager::instance().DirectQuery("DELETE FROM %soffline_shop_npc WHERE owner_id = %u", get_table_postfix(), GetOfflineShopRealOwner());
  6233. LPOFFLINESHOP pkOfflineShop = GetOfflineShop();
  6234. if (pkOfflineShop)
  6235. pkOfflineShop->RemoveAllGuest();
  6236. M2_DESTROY_CHARACTER(this);
  6237. }
Comments powered by Disqus