Переглянути джерело

Merge branch 'master' into feature/blocking_play

Aleos 6 роки тому
батько
коміт
063d8503ee
81 змінених файлів з 876 додано та 660 видалено
  1. 6 0
      conf/battle/exp.conf
  2. 8 0
      conf/battle/items.conf
  3. 10 0
      conf/login_athena.conf
  4. 19 19
      db/pre-re/skill_db.txt
  5. 14 1
      db/re/mob_db.txt
  6. 19 19
      db/re/skill_db.txt
  7. 13 0
      db/re/skill_tree.txt
  8. 40 25
      doc/script_commands.txt
  9. 1 1
      npc/custom/events/mvp_ladder.txt
  10. 3 3
      npc/custom/official/GeffenMagicTournament.txt
  11. 1 1
      npc/events/gdevent_aru.txt
  12. 1 1
      npc/events/gdevent_sch.txt
  13. 4 6
      npc/events/god_se_festival.txt
  14. 1 1
      npc/events/nguild/nguild_managers.txt
  15. 47 47
      npc/guild/agit_main.txt
  16. 1 1
      npc/guild/trs_rp.txt
  17. 60 60
      npc/guild2/agit_main_se.txt
  18. 1 1
      npc/instances/EndlessTower.txt
  19. 3 3
      npc/instances/NydhoggsNest.txt
  20. 2 2
      npc/instances/OrcsMemory.txt
  21. 8 10
      npc/instances/SealedShrine.txt
  22. 1 1
      npc/other/CashShop_Functions.txt
  23. 3 4
      npc/other/arena/arena_party.txt
  24. 4 4
      npc/other/poring_war.txt
  25. 7 8
      npc/quests/guildrelay.txt
  26. 2 2
      npc/quests/okolnir.txt
  27. 8 17
      npc/quests/partyrelay.txt
  28. 2 2
      npc/quests/quests_louyang.txt
  29. 3 3
      npc/quests/seals/god_weapon_creation.txt
  30. 1 1
      npc/re/cities/malaya.txt
  31. 3 3
      npc/re/guild/invest_main.txt
  32. 4 4
      npc/re/guild/mission_main.txt
  33. 46 46
      npc/re/guild3/agit_main_te.txt
  34. 2 2
      npc/re/instances/AirshipAssault.txt
  35. 3 3
      npc/re/instances/BakonawaLake.txt
  36. 1 1
      npc/re/instances/BangungotHospital.txt
  37. 1 1
      npc/re/instances/BuwayaCave.txt
  38. 2 2
      npc/re/instances/CentralLaboratory.txt
  39. 13 13
      npc/re/instances/DevilTower.txt
  40. 2 2
      npc/re/instances/EclageInterior.txt
  41. 4 4
      npc/re/instances/FacewormsNest.txt
  42. 2 2
      npc/re/instances/GhostPalace.txt
  43. 1 1
      npc/re/instances/HazyForest.txt
  44. 4 4
      npc/re/instances/HorrorToyFactory.txt
  45. 2 2
      npc/re/instances/IsleOfBios.txt
  46. 3 3
      npc/re/instances/LastRoom.txt
  47. 4 4
      npc/re/instances/MalangdoCulvert.txt
  48. 2 2
      npc/re/instances/MorseCave.txt
  49. 1 1
      npc/re/instances/OctopusCave.txt
  50. 5 5
      npc/re/instances/OldGlastHeim.txt
  51. 6 6
      npc/re/instances/RoomOfConsciousness.txt
  52. 6 6
      npc/re/instances/SaraMemory.txt
  53. 6 6
      npc/re/instances/SarahAndFenrir.txt
  54. 5 5
      npc/re/instances/WolfchevLaboratory.txt
  55. 9 9
      npc/re/quests/quests_16_1.txt
  56. 1 1
      npc/re/quests/woe_te/te_goditem_alde1.txt
  57. 1 1
      npc/re/quests/woe_te/te_goditem_prt01.txt
  58. 14 1
      sql-files/mob_db_re.sql
  59. 22 22
      src/char/int_guild.cpp
  60. 17 0
      src/common/mmo.hpp
  61. 111 74
      src/login/login.cpp
  62. 15 19
      src/login/login.hpp
  63. 16 21
      src/login/loginchrif.cpp
  64. 10 19
      src/login/loginclif.cpp
  65. 0 5
      src/login/logincnslif.cpp
  66. 4 2
      src/map/atcommand.cpp
  67. 4 0
      src/map/battle.cpp
  68. 4 0
      src/map/battle.hpp
  69. 1 1
      src/map/chrif.cpp
  70. 3 2
      src/map/clif.cpp
  71. 18 13
      src/map/guild.cpp
  72. 0 6
      src/map/instance.cpp
  73. 5 5
      src/map/mob.cpp
  74. 10 0
      src/map/npc.hpp
  75. 57 53
      src/map/pc.cpp
  76. 1 1
      src/map/pc.hpp
  77. 76 22
      src/map/script.cpp
  78. 32 0
      src/map/script_constants.hpp
  79. 17 8
      src/map/skill.cpp
  80. 2 2
      src/map/status.cpp
  81. 5 2
      src/map/status.hpp

+ 6 - 0
conf/battle/exp.conf

@@ -18,6 +18,12 @@ job_exp_rate: 100
 // Turn this on to allow a player to level up more than once from a kill. (Note 1)
 multi_level_up: no
 
+// Allow multi level up until a certain level?
+// This only triggers if multi_level_up is enabled.
+// Default: 0 (Unlimited)
+multi_level_up_base: 0
+multi_level_up_job: 0
+
 // Setting this can cap the max experience one can get per kill specified as a
 // % of the current exp bar. (Every 10 = 1.0%)
 // For example, set it to 500 and no matter how much exp the mob gives, 

+ 8 - 0
conf/battle/items.conf

@@ -133,3 +133,11 @@ broadcast_hide_name: 2
 
 // Enable to sell rental item to NPC shop? (Note 1)
 rental_transaction: yes
+
+// Minimum purchase price of items at a normal Shop
+// Officially items cannot be purchased for less than 1 Zeny
+min_shop_buy: 1
+
+// Minimum sell price of items at a normal shop
+// Officially items can be sold for 0 Zeny
+min_shop_sell: 0

+ 10 - 0
conf/login_athena.conf

@@ -110,6 +110,16 @@ start_limited_time: -1
 // NOTE: Will not work with clients that use <passwordencrypt>
 use_MD5_passwords: no
 
+// User count colorization on login window (requires PACKETVER >= 20170726)
+// Disable colorization and description in general?
+usercount_disable: no
+// Amount of users that will display in green
+usercount_low: 200
+// Amount of users that will display in yellow
+usercount_medium: 500
+// Amount of users that will display in red
+usercount_high: 1000
+
 // Ipban features
 ipban_enable: yes
 // Dynamic password failure ipban system

+ 19 - 19
db/pre-re/skill_db.txt

@@ -129,9 +129,9 @@
 37,0,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_DISCOUNT,Discount
 38,0,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_OVERCHARGE,Overcharge
 39,1,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_PUSHCART,Pushcart
-40,1,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,		MC_IDENTIFY,Item Appraisal
-41,1,6,4,0,0x1,0,10,1,no,0,0,0,none,0,0x0,		MC_VENDING,Vending
-42,-1,6,1,-1,0,0,10,1,no,0,0,0,weapon,0,0x0,		MC_MAMMONITE,Mammonite
+40,1,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x4000,		MC_IDENTIFY,Item Appraisal
+41,1,6,4,0,0x1,0,10,1,no,0,0,0,none,0,0x4000,		MC_VENDING,Vending
+42,-1,6,1,-1,0,0,10,1,no,0,0,0,weapon,0,0x4000,		MC_MAMMONITE,Mammonite
 
 //****
 // Archer
@@ -215,13 +215,13 @@
 105,0,0,0,0,0,0,1,0,no,0,0,0,weapon,0,0x0,		BS_HILTBINDING,Hilt Binding
 106,0,0,0,0,0,0,1,0,no,0,0,0,weapon,0,0x0,		BS_FINDINGORE,Ore Discovery
 107,0,0,0,0,0,0,10,0,no,0,0,0,weapon,0,0x0,		BS_WEAPONRESEARCH,Weaponry Research
-108,2,6,16,0,0x1,0,1,1,yes,0,0,0,weapon,0,0x0,	BS_REPAIRWEAPON,Weapon Repair
+108,2,6,16,0,0x1,0,1,1,yes,0,0,0,weapon,0,0x4000,	BS_REPAIRWEAPON,Weapon Repair
 109,0,0,0,0,0,0,5,0,no,0,0,0,weapon,0,0x0,		BS_SKINTEMPER,Skin Tempering
-110,1,6,2,0,0x3,2:2:2:2:2:12,5,1,no,0,0,0,weapon,0,0x0,	BS_HAMMERFALL,Hammer Fall
-111,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_ADRENALINE,Adrenaline Rush
-112,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_WEAPONPERFECT,Weapon Perfection
-113,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_OVERTHRUST,Power-Thrust
-114,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x0,		BS_MAXIMIZE,Maximize Power
+110,1,6,2,0,0x3,2:2:2:2:2:12,5,1,no,0,0,0,weapon,0,0x4000,	BS_HAMMERFALL,Hammer Fall
+111,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_ADRENALINE,Adrenaline Rush
+112,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_WEAPONPERFECT,Weapon Perfection
+113,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_OVERTHRUST,Power-Thrust
+114,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x4000,		BS_MAXIMIZE,Maximize Power
 
 //****
 // Hunter
@@ -269,9 +269,9 @@
 150,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,5,0x40,	TF_BACKSLIDING,Back Slide
 151,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		TF_PICKSTONE,Find Stone
 152,7,6,1,0,0x40,0,1,1,no,0,0x1,0,misc,0,0x0,	TF_THROWSTONE,Stone Fling
-153,1,6,1,-1,0x2,1,1,1,no,0,0x40001,0,weapon,2,0x0,	MC_CARTREVOLUTION,Cart Revolution
-154,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		MC_CHANGECART,Change Cart
-155,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,0,0x0,	MC_LOUD,Crazy Uproar
+153,1,6,1,-1,0x2,1,1,1,no,0,0x40001,0,weapon,2,0x4000,	MC_CARTREVOLUTION,Cart Revolution
+154,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x4000,		MC_CHANGECART,Change Cart
+155,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,0,0x4000,	MC_LOUD,Crazy Uproar
 156,9,6,1,6,0,0,1,1,yes,0,0x1,0,magic,0,0x0,		AL_HOLYLIGHT,Holy Light
 157,0,6,4,0,0x1,0,1,1,yes,0,0x1,0,magic,0,0x0,	MG_ENERGYCOAT,Energy Coat
 
@@ -563,10 +563,10 @@
 
 //****
 // Whitesmith
-384,0,0,4,0,0x1,0,10,1,yes,0,0,0,weapon,0,0x0,	WS_MELTDOWN,Shattering Strike
+384,0,0,4,0,0x1,0,10,1,yes,0,0,0,weapon,0,0x4000,	WS_MELTDOWN,Shattering Strike
 385,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,	WS_CREATECOIN,Create Coins
 386,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,	WS_CREATENUGGET,Create Nuggets
-387,0,6,4,0,0x1,0,1,1,no,0,0,0,weapon,0,0x0,		WS_CARTBOOST,Cart Boost
+387,0,6,4,0,0x1,0,1,1,no,0,0,0,weapon,0,0x4000,		WS_CARTBOOST,Cart Boost
 388,9,6,2,0,0x1,0,5,1,no,0,0,0,none,0,0x0,		WS_SYSTEMCREATE,Auto Attack System
 
 //****
@@ -680,7 +680,7 @@
 
 //****
 // Blacksmith
-459,0,6,4,0,0x3,-1,1,1,no,0,0x8,0,weapon,0 ,0x0,	BS_ADRENALINE2,Advanced Adrenaline Rush
+459,0,6,4,0,0x3,-1,1,1,no,0,0x8,0,weapon,0 ,0x4000,	BS_ADRENALINE2,Advanced Adrenaline Rush
 
 //****
 // Soul Linker
@@ -704,7 +704,7 @@
 474,0,0,4,0,0x1,0,10,1,no,0,0x2,0,none,0,0x0,	NPC_EMOTION_ON,Emotion ON
 475,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,		ST_PRESERVE,Preserve
 476,1,6,1,0,0x1,0,5,1,yes,0,0,0,weapon,0,0x0,	ST_FULLSTRIP,Divest All
-477,0,6,4,0,0x1,0,10,1,no,0,0,0,weapon,0,0x0,	WS_WEAPONREFINE,Upgrade Weapon
+477,0,6,4,0,0x1,0,10,1,no,0,0,0,weapon,0,0x4000,	WS_WEAPONREFINE,Upgrade Weapon
 478,3,6,2,0,0x3,3,10,1,no,0,0,0,none,0,0x0,		CR_SLIMPITCHER,Aid Condensed Potion
 479,1,6,16,0,0x1,0,5,1,yes,0,0,0,weapon,0,0x0,	CR_FULLPROTECTION,Full Protection
 480,4,8,1,0,0,0,5,5,no,0,0,0,weapon,0,0x20000,		PA_SHIELDCHAIN,Shield Chain
@@ -712,8 +712,8 @@
 482,0,6,4,0,0x1,0,5,1,no,0,0,0,magic,0,0x0,		PF_DOUBLECASTING,Double Casting
 483,18,6,2,0,0x1,1:2:3:4:5,1,1,no,0,0,0,none,0,0x0,	HW_GANBANTEIN,Ganbantein
 484,18,6,2,2,0xD1,0,5,1,yes,0,0x18000,0,misc,0,0x11010,		HW_GRAVITATION,Gravitation Field
-485,-2,6,1,-1,0x8,0,10,1,no,0,0,0,weapon,0,0x0,	WS_CARTTERMINATION,Cart Termination
-486,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x0,		WS_OVERTHRUSTMAX,Maximum Power Thrust
+485,-2,6,1,-1,0x8,0,10,1,no,0,0,0,weapon,0,0x4000,	WS_CARTTERMINATION,Cart Termination
+486,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x4000,		WS_OVERTHRUSTMAX,Maximum Power Thrust
 487,0,6,4,0,0x1,0,5,1,no,0,0,0,none,0,0x8,		CG_LONGINGFREEDOM,Longing for Freedom
 488,0,6,4,0,0x1,1,5,1,no,0,0x20,0,misc,0,0x1,	CG_HERMODE,Wand of Hermode
 489,9,6,1,0,0x41,0,5,1,no,0,0,0,misc,0,0x0,		CG_TAROTCARD,Tarot Card of Fate
@@ -1265,7 +1265,7 @@
 //2541,0,0,0,0,0,0,??,0,no,0,0,0,none,0,0x0,		NPC_UGLYDANCE,Ugly Dance 2
 //2542,0,0,0,0,0,0,??,0,no,0,0,0,none,0,0x0,		ALL_TETANY,Tetany
 //2543,0,0,0,0,0,0,??,0,no,0,0,0,none,0,0x0,		ALL_RAY_OF_PROTECTION,Ray of Protection
-2544,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		MC_CARTDECORATE,Decorate Cart
+2544,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x4000,		MC_CARTDECORATE,Decorate Cart
 
 //****
 // Rebellion

+ 14 - 1
db/re/mob_db.txt

@@ -3648,6 +3648,19 @@
 //20517,G_BONE_ACIDUS
 //20518,E_MD_LUDE
 //20519,E_MD_JACK_GAINT
-
+//20520,ILL_BAPHOMET
+//20521,ILL_ANDREA
+//20522,ILL_ANES
+//20523,ILL_SILVANO
+//20524,ILL_CECILIA
+//20525,ILL_BAPHOMET_J
+//20526,ILL_SIDE_WINDER
+//20527,ILL_HUNTER_FLY
+//20528,ILL_MANTIS
+//20529,ILL_GHOSTRING
+//20530,ILL_KILLER_MANTIS
+//20531,ILL_POPORING
+//20532,ILL_STEM_WORM
+//20533,G_ILL_BAPHOMET_J
 //20534,G_REGINLEIF
 //20535,G_INGRID

+ 19 - 19
db/re/skill_db.txt

@@ -129,9 +129,9 @@
 37,0,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_DISCOUNT,Discount
 38,0,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_OVERCHARGE,Overcharge
 39,1,0,0,0,0,0,10,0,no,0,0,0,none,0,0x0,		MC_PUSHCART,Pushcart
-40,1,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,		MC_IDENTIFY,Item Appraisal
-41,1,6,4,0,0x1,0,10,1,no,0,0,0,none,0,0x0,		MC_VENDING,Vending
-42,-1,6,1,-1,0,0,10,1,no,0,0,0,weapon,0,0x0,		MC_MAMMONITE,Mammonite
+40,1,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x4000,		MC_IDENTIFY,Item Appraisal
+41,1,6,4,0,0x1,0,10,1,no,0,0,0,none,0,0x4000,		MC_VENDING,Vending
+42,-1,6,1,-1,0,0,10,1,no,0,0,0,weapon,0,0x4000,		MC_MAMMONITE,Mammonite
 
 //****
 // Archer
@@ -215,13 +215,13 @@
 105,0,0,0,0,0,0,1,0,no,0,0,0,weapon,0,0x0,		BS_HILTBINDING,Hilt Binding
 106,0,0,0,0,0,0,1,0,no,0,0,0,weapon,0,0x0,		BS_FINDINGORE,Ore Discovery
 107,0,0,0,0,0,0,10,0,no,0,0,0,weapon,0,0x0,		BS_WEAPONRESEARCH,Weaponry Research
-108,2,6,16,0,0x1,0,1,1,yes,0,0,0,weapon,0,0x0,	BS_REPAIRWEAPON,Weapon Repair
+108,2,6,16,0,0x1,0,1,1,yes,0,0,0,weapon,0,0x4000,	BS_REPAIRWEAPON,Weapon Repair
 109,0,0,0,0,0,0,5,0,no,0,0,0,weapon,0,0x0,		BS_SKINTEMPER,Skin Tempering
-110,1,6,2,0,0x3,2:2:2:2:2:12,5,1,no,0,0,0,weapon,0,0x0,	BS_HAMMERFALL,Hammer Fall
-111,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_ADRENALINE,Adrenaline Rush
-112,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_WEAPONPERFECT,Weapon Perfection
-113,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x0,	BS_OVERTHRUST,Power-Thrust
-114,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x0,		BS_MAXIMIZE,Maximize Power
+110,1,6,2,0,0x3,2:2:2:2:2:12,5,1,no,0,0,0,weapon,0,0x4000,	BS_HAMMERFALL,Hammer Fall
+111,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_ADRENALINE,Adrenaline Rush
+112,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_WEAPONPERFECT,Weapon Perfection
+113,0,6,4,0,0x3,-1,5,1,no,0,0,0,weapon,0,0x4000,	BS_OVERTHRUST,Power-Thrust
+114,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x4000,		BS_MAXIMIZE,Maximize Power
 
 //****
 // Hunter
@@ -269,9 +269,9 @@
 150,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,5,0x40,	TF_BACKSLIDING,Back Slide
 151,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		TF_PICKSTONE,Find Stone
 152,7,6,1,0,0x40,0,1,1,no,0,0x1,0,misc,0,0x0,	TF_THROWSTONE,Stone Fling
-153,1,6,1,-1,0x2,1,1,1,no,0,0x40001,0,weapon,2,0x0,	MC_CARTREVOLUTION,Cart Revolution
-154,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		MC_CHANGECART,Change Cart
-155,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,0,0x0,	MC_LOUD,Crazy Uproar
+153,1,6,1,-1,0x2,1,1,1,no,0,0x40001,0,weapon,2,0x4000,	MC_CARTREVOLUTION,Cart Revolution
+154,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x4000,		MC_CHANGECART,Change Cart
+155,0,6,4,0,0x1,0,1,1,no,0,0x1,0,weapon,0,0x4000,	MC_LOUD,Crazy Uproar
 156,9,6,1,6,0,0,1,1,yes,0,0x1,0,magic,0,0x0,		AL_HOLYLIGHT,Holy Light
 157,0,6,4,0,0x1,0,1,1,yes,0,0x1,0,magic,0,0x0,	MG_ENERGYCOAT,Energy Coat
 
@@ -563,10 +563,10 @@
 
 //****
 // Whitesmith
-384,0,0,4,0,0x1,0,10,1,yes,0,0,0,weapon,0,0x0,	WS_MELTDOWN,Shattering Strike
+384,0,0,4,0,0x1,0,10,1,yes,0,0,0,weapon,0,0x4000,	WS_MELTDOWN,Shattering Strike
 385,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,	WS_CREATECOIN,Create Coins
 386,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,	WS_CREATENUGGET,Create Nuggets
-387,0,6,4,0,0x1,0,1,1,no,0,0,0,weapon,0,0x0,		WS_CARTBOOST,Cart Boost
+387,0,6,4,0,0x1,0,1,1,no,0,0,0,weapon,0,0x4000,		WS_CARTBOOST,Cart Boost
 388,9,6,2,0,0x1,0,5,1,no,0,0,0,none,0,0x0,		WS_SYSTEMCREATE,Auto Attack System
 
 //****
@@ -680,7 +680,7 @@
 
 //****
 // Blacksmith
-459,0,6,4,0,0x3,-1,1,1,no,0,0x8,0,weapon,0,0x0,		BS_ADRENALINE2,Advanced Adrenaline Rush
+459,0,6,4,0,0x3,-1,1,1,no,0,0x8,0,weapon,0,0x4000,		BS_ADRENALINE2,Advanced Adrenaline Rush
 
 //****
 // Soul Linker
@@ -704,7 +704,7 @@
 474,0,0,4,0,0x1,0,10,1,no,0,0x2,0,none,0,0x0,	NPC_EMOTION_ON,Emotion ON
 475,0,0,4,0,0x1,0,1,1,yes,0,0,0,none,0,0x0,		ST_PRESERVE,Preserve
 476,1,6,1,0,0x1,0,5,1,yes,0,0,0,weapon,0,0x0,	ST_FULLSTRIP,Divest All
-477,0,6,4,0,0x1,0,10,1,no,0,0,0,weapon,0,0x0,	WS_WEAPONREFINE,Upgrade Weapon
+477,0,6,4,0,0x1,0,10,1,no,0,0,0,weapon,0,0x4000,	WS_WEAPONREFINE,Upgrade Weapon
 478,3,6,2,0,0x3,3,10,1,no,0,0,0,none,0,0x0,		CR_SLIMPITCHER,Aid Condensed Potion
 479,1,6,16,0,0x1,0,5,1,yes,0,0,0,weapon,0,0x0,	CR_FULLPROTECTION,Full Protection
 480,4,8,1,-1,0,0,5,5,no,0,0,0,weapon,0,0x20000,		PA_SHIELDCHAIN,Shield Chain
@@ -712,8 +712,8 @@
 482,0,6,4,0,0x1,0,5,1,no,0,0,0,magic,0,0x0,		PF_DOUBLECASTING,Double Casting
 483,18,6,2,0,0x1,1:2:3:4:5,1,1,no,0,0,0,none,0,0x0,	HW_GANBANTEIN,Ganbantein
 484,18,6,2,2,0xD1,0,5,1,yes,0,0x18000,0,misc,0,0x11010,		HW_GRAVITATION,Gravitation Field
-485,-2,6,1,-1,0x0,0,10,1,no,0,0,0,weapon,0,0x0,	WS_CARTTERMINATION,Cart Termination
-486,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x0,		WS_OVERTHRUSTMAX,Maximum Power Thrust
+485,-2,6,1,-1,0x0,0,10,1,no,0,0,0,weapon,0,0x4000,	WS_CARTTERMINATION,Cart Termination
+486,0,6,4,0,0x1,0,5,1,no,0,0,0,weapon,0,0x4000,		WS_OVERTHRUSTMAX,Maximum Power Thrust
 487,0,6,4,0,0x1,0,5,1,no,0,0,0,none,0,0x8,		CG_LONGINGFREEDOM,Longing for Freedom
 488,0,6,4,0,0x1,1,5,1,no,0,0x20,0,misc,0,0x1,	CG_HERMODE,Wand of Hermode
 489,9,6,1,0,0x41,0,5,1,no,0,0,0,misc,0,0x0,		CG_TAROTCARD,Tarot Card of Fate
@@ -1271,7 +1271,7 @@
 //2541,0,6,4,0,0x1,0,5,1,no,0,0x2,0,none,0,0x0,		NPC_UGLYDANCE,Ugly Dance 2
 //2542,0,0,0,0,0,0,??,0,no,0,0,0,none,0,0x0,	ALL_TETANY,Tetany
 //2543,0,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,	ALL_RAY_OF_PROTECTION,Ray of Protection
-2544,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x0,		MC_CARTDECORATE,Decorate Cart
+2544,0,6,4,0,0x1,0,1,1,no,0,0x1,0,none,0,0x4000,		MC_CARTDECORATE,Decorate Cart
 //2545,0,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,	GM_ITEM_ATKMAX,Maximize Attack
 //2546,0,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,	GM_ITEM_ATKMIN,Minimize Attack
 //2547,0,6,4,0,0x1,0,1,1,no,0,0,0,none,0,0x0,	GM_ITEM_MATKMAX,Maximize Magic Attack

+ 13 - 0
db/re/skill_tree.txt

@@ -5774,6 +5774,19 @@
 4220,5039,5,5038,3,0,0,0,0,0,0,0,0 //SU_TUNAPARTY##
 4220,5040,5,5041,3,0,0,0,0,0,0,0,0 //SU_BUNCHOFSHRIMP##
 4220,5041,5,5024,1,0,0,0,0,0,0,0,0 //SU_FRESHSHRIMP##
+4220,5044,1,5024,1,0,0,0,0,0,0,0,0 //SU_SOULATTACK##
+4220,5045,5,100,0,5047,5,0,0,0,0,0,0,0,0 //SU_POWEROFFLOCK##
+4220,5046,5,100,0,5045,5,0,0,0,0,0,0,0,0 //SU_SVG_SPIRIT##
+4220,5047,5,100,0,5031,1,0,0,0,0,0,0,0,0 //SU_HISS##
+4220,5048,5,100,0,5053,5,0,0,0,0,0,0,0,0 //SU_NYANGGRASS##
+4220,5049,5,100,0,5037,1,0,0,0,0,0,0,0,0 //SU_GROOMING##
+4220,5050,5,100,0,5049,5,0,0,0,0,0,0,0,0 //SU_PURRING##
+4220,5051,5,100,0,5050,5,0,0,0,0,0,0,0,0 //SU_SHRIMPARTY##
+4220,5052,1,100,0,5046,5,0,0,0,0,0,0,0,0 //SU_SPIRITOFLIFE##
+4220,5053,5,100,0,5025,1,0,0,0,0,0,0,0,0 //SU_MEOWMEOW##
+4220,5054,1,100,0,5048,5,0,0,0,0,0,0,0,0 //SU_SPIRITOFLAND##
+4220,5055,5,100,0,5025,1,0,0,0,0,0,0,0,0 //SU_CHATTERING##
+4220,5056,1,100,0,5051,5,0,0,0,0,0,0,0,0 //SU_SPIRITOFSEA##
 4220,408,1,0,0,0,0,0,0,0,0,0,0 //WE_BABY#Baby#
 4220,409,1,0,0,0,0,0,0,0,0,0,0 //WE_CALLPARENT#Call Parent#
 4220,5065,1,0,0,0,0,0,0,0,0,0,0 //WE_CHEERUP#Cheer Up#

+ 40 - 25
doc/script_commands.txt

@@ -3353,6 +3353,13 @@ guild specified by the ID. 0 if the character is not a guild master of any guild
 
 ---------------------------------------
 
+*is_guild_leader({<guild ID>})
+
+This command will return true if the player attached to the script is the leader
+of his/her guild, or, if a guild ID is specified, of that guild.
+
+---------------------------------------
+
 *getcastlename("<map name>")
 
 This function returns the name of the castle when given the map name for that
@@ -3368,29 +3375,29 @@ to by its map name. Castle information is stored in `guild_castle` SQL table.
 
 Types of data correspond to `guild_castle` table columns:
 
- 1 - `guild_id`   - Guild ID.
- 2 - `economy`    - Castle Economy score.
- 3 - `defense`    - Castle Defense score.
- 4 - `triggerE`   - Number of times the economy was invested in today.
- 5 - `triggerD`   - Number of times the defense was invested in today.
- 6 - `nextTime`   - unused
- 7 - `payTime`    - unused
- 8 - `createTime` - unused
- 9 - `visibleC`   - Is 1 if a Kafra was hired for this castle, 0 otherwise.
-10 - `visibleG0`  - Is 1 if the 1st guardian is present (Soldier Guardian)
-11 - `visibleG1`  - Is 1 if the 2nd guardian is present (Soldier Guardian)
-12 - `visibleG2`  - Is 1 if the 3rd guardian is present (Soldier Guardian)
-13 - `visibleG3`  - Is 1 if the 4th guardian is present (Archer Guardian)
-14 - `visibleG4`  - Is 1 if the 5th guardian is present (Archer Guardian)
-15 - `visibleG5`  - Is 1 if the 6th guardian is present (Knight Guardian)
-16 - `visibleG6`  - Is 1 if the 7th guardian is present (Knight Guardian)
-17 - `visibleG7`  - Is 1 if the 8th guardian is present (Knight Guardian)
+CD_GUILD_ID          - Guild ID.
+CD_CURRENT_ECONOMY   - Castle Economy score.
+CD_CURRENT_DEFENSE   - Castle Defense score.
+CD_INVESTED_ECONOMY  - Number of times the economy was invested in today.
+CD_INVESTED_DEFENSE  - Number of times the defense was invested in today.
+CD_NEXT_TIME         - unused
+CD_PAY_TIME          - unused
+CD_CREATE_TIME       - unused
+CD_ENABLED_KAFRA     - Is 1 if a Kafra was hired for this castle, 0 otherwise.
+CD_ENABLED_GUARDIAN0 - Is 1 if the 1st guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN1 - Is 1 if the 2nd guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN2 - Is 1 if the 3rd guardian is present (Soldier Guardian)
+CD_ENABLED_GUARDIAN3 - Is 1 if the 4th guardian is present (Archer Guardian)
+CD_ENABLED_GUARDIAN4 - Is 1 if the 5th guardian is present (Archer Guardian)
+CD_ENABLED_GUARDIAN5 - Is 1 if the 6th guardian is present (Knight Guardian)
+CD_ENABLED_GUARDIAN6 - Is 1 if the 7th guardian is present (Knight Guardian)
+CD_ENABLED_GUARDIAN7 - Is 1 if the 8th guardian is present (Knight Guardian)
 
 All types of data have their meaning determined by War of Emperium scripts,
 with exception of:
- - `guild_id` that is always considered ID of the guild that owns the castle,
- - `defense` that is used in Guardians & Emperium HP calculations,
- - `visibleG` that is always considered to hold guardian presence bits.
+ - CD_GUILD_ID that is always considered ID of the guild that owns the castle,
+ - CD_CURRENT_DEFENSE that is used in Guardians & Emperium HP calculations,
+ - CD_ENABLED_GUARDIANX that is always considered to hold guardian presence bits.
 
 The 'setcastledata' command will behave identically, but instead of returning
 values for the specified types of accessible data, it will alter them and cause
@@ -7470,11 +7477,12 @@ This command will display a picture, usually an NPC illustration, also called
 cutin, for the currently attached client. The position parameter determines the
 placement of the illustration and takes following values:
 
-	0 - bottom left corner
-	1 - bottom middle
-	2 - bottom right corner
-	3 - middle of screen in a movable window with an empty title bar
-	4 - middle of screen without the window header, but still movable
+	0	bottom left corner
+	1	bottom middle
+	2	bottom right corner
+	3	middle of screen in a movable window with an empty title bar
+	4	middle of screen without the window header, but still movable
+	255	clear all displayed cutins
 
 The picture is read from data\texture\유저인터페이스\illust, from both the GRF archive
 and data folder, and is required to be a bitmap. The file extension .bmp can be
@@ -9776,6 +9784,13 @@ returns "null" instead of the character name, and -1 for the other types.
 
 ---------------------------------------
 
+*is_party_leader({<party ID>})
+
+This command will return true if the player attached to the script is the leader
+of his/her party, or, if a party ID is specified, of that party.
+
+---------------------------------------
+
 *party_create("<party name>"{,<character id>{,<item share>,<item share type>}});
 
 Organizes a party with the attached or specified character as leader. If

+ 1 - 1
npc/custom/events/mvp_ladder.txt

@@ -63,7 +63,7 @@ prontera,164,171,3	script	MvP Ladder Warper	56,{
 		mes "You have to form a party to play.";
 		close;
 	}
-	if ( getpartyleader( getcharid(1), 2 ) != getcharid(0) ) {
+	if ( is_party_leader() == false ) {
 		mes "[MvP Ladder Warper]";
 		mes "Only the party leader can register.";
 		close;

+ 3 - 3
npc/custom/official/GeffenMagicTournament.txt

@@ -625,7 +625,7 @@ dali,100,147,3	script	Dimensional Device#gefma	PORTAL,{
 			getpartymember(getcharid(1),0);
 			set .@GPPartySize,$@partymembercount;
 			
-			if( !getcharid(1) || getcharid(3) != getpartyleader( getcharid(1),1 ) || .@GPPartySize > 1) {
+			if( !getcharid(1) || is_party_leader() == false || .@GPPartySize > 1) {
 				mes .@n$;
 				mes "This is a solo instance. Please form a solo party before continuing.";
 				end;
@@ -737,7 +737,7 @@ dali,98,141,3	script	Emmitt White	4_M_KHKYEL,{
 		getpartymember(getcharid(1),0);
 		set .@GPPartySize,$@partymembercount;
 		
-		if( !getcharid(1) || getcharid(3) != getpartyleader( getcharid(1),1 ) || .@GPPartySize > 1) {
+		if( !getcharid(1) || is_party_leader() == false || .@GPPartySize > 1) {
 			mes .@n$;
 			mes "This is a solo instance. Please form a solo party before continuing.";
 			end;
@@ -757,7 +757,7 @@ dali,98,141,3	script	Emmitt White	4_M_KHKYEL,{
 				end;
 			}
 			
-		if (getcharid(0) == getpartyleader(.@party_id,2)){
+		if (is_party_leader() == true){
 			mes .@n$; 
 			mes "Did you know? A long time ago there was a Magic Tournament in Geffen.";
 			next;

+ 1 - 1
npc/events/gdevent_aru.txt

@@ -504,7 +504,7 @@ arug_que01,100,81,3	script	Pierrot Pier#aru_gd	715,{
 		mes "- and come back later. -";
 		close;
 	}
-	if (strcharinfo(0) == getguildmaster(getcharid(2))) {
+	if (is_guild_leader() == true) {
 		if ($@gdeventv_a2 == 0) {
 			set .@que_2143,checkquest(2143,PLAYTIME);
 			if (.@que_2143 == -1) {

+ 1 - 1
npc/events/gdevent_sch.txt

@@ -503,7 +503,7 @@ schg_que01,100,81,3	script	Pierrot Pier#sch_gd	715,{
 		mes "- and come back later. -";
 		close;
 	}
-	if (strcharinfo(0) == getguildmaster(getcharid(2))) {
+	if (is_guild_leader() == true) {
 		if ($@gdeventv_s2 == 0) {
 			set .@que_2143,checkquest(2143,PLAYTIME);
 			if (.@que_2143 == -1) {

+ 4 - 6
npc/events/god_se_festival.txt

@@ -47,13 +47,12 @@ yuno,1,1,0	script	Festival Manager#gq_fes0	891,{
 }
 
 yuno,118,192,5	script	Rmimi Ravies#gq_fes01	891,{
-	set .@GID, getcharid(2);
 	if (countitem(7840) > 0) {
 		mes "[Rmimi Ravies]";
 		mes "This is the flower.";
 		mes "This is just a formality, but let me check your qualifications.";
 		next;
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			mes "[Rmimi Ravies]";
 			mes "Your qualification is verified as a Guild master.";
 			next;
@@ -123,7 +122,7 @@ yuno,118,192,5	script	Rmimi Ravies#gq_fes01	891,{
 				mes "Have a good time.";
 				donpcevent "Rmimi Ravies#gq_fes01::OnStart";
 				
-				announce "["+ strcharinfo(0) +"] member of ["+ GetGuildName(.@GID) +"] is summoning a 'Valkyrie's Present' in 'Juno'.",bc_all,"0x70dbdb";
+				announce "["+ strcharinfo(0) +"] member of ["+ GetGuildName( getcharid(2) ) +"] is summoning a 'Valkyrie's Present' in 'Juno'.",bc_all,"0x70dbdb";
 				close;
 			}
 			else {
@@ -425,13 +424,12 @@ rachel,1,1,0	script	Festival Manager#gq_fes2	891,{
 }
 
 rachel,132,117,3	script	Rhehe Ravies#gq_fes03	891,{
-	set .@GID, getcharid(2);
 	if (countitem(7840) > 0) {
 		mes "[Rhehe Ravies]";
 		mes "A flower!!";
 		mes "Shall we proceed?";
 		next;
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			mes "[Rhehe Ravies]";
 			mes "Eeeeh, so young and yet you're a guild master? Your guildsmen must be jealous.";
 			next;
@@ -504,7 +502,7 @@ rachel,132,117,3	script	Rhehe Ravies#gq_fes03	891,{
 				mes "[Rhehe Ravies]";
 				mes "I hope you enjoy yourself!";
 				donpcevent "Rhehe Ravies#gq_fes03::OnStart";
-				announce "["+ strcharinfo(0) +"] member of ["+ GetGuildName(.@GID) +"] is summoning a 'Valkyrie's Present' in 'Rachel'.",bc_all,"0x70dbdb";
+				announce "["+ strcharinfo(0) +"] member of ["+ GetGuildName( getcharid(2) ) +"] is summoning a 'Valkyrie's Present' in 'Rachel'.",bc_all,"0x70dbdb";
 				close;
 			}
 			else {

+ 1 - 1
npc/events/nguild/nguild_managers.txt

@@ -39,7 +39,7 @@ function	script	F_GldManager	{
 		mes "Where are the guardians? Destroy these intruders!";
 		return;
 	}
-	if (strcharinfo(0) != getguildmaster(.@gid)){
+	if (is_guild_leader() == false){
 		mes "You're not ^5533FF" + getguildmaster(.@gid) + "^000000! I am here to follow ^5533FF" + getguildmaster(.@gid) + "^000000's command only";
 		return 0;
 	}

+ 47 - 47
npc/guild/agit_main.txt

@@ -63,7 +63,7 @@
 // War of Emperium has started.
 OnAgitStart:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
-	MapRespawnGuildID strnpcinfo(2),GetCastleData(strnpcinfo(2),1),6;
+	MapRespawnGuildID strnpcinfo(2),GetCastleData(strnpcinfo(2),CD_GUILD_ID),6;
 	GvgOn strnpcinfo(2);
 
 // Spawn (fall through), or respawn the Emperium once it has been broken.
@@ -109,16 +109,16 @@ OnAgitBreak:
 		end;
 	}
 	// Adjust Economy Invest Level for Castle
-	set .@Economy,GetCastleData(strnpcinfo(2),2) - 5;
+	set .@Economy,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY) - 5;
 	if (.@Economy < 0) set .@Economy, 0;
-	SetCastleData strnpcinfo(2), 2, .@Economy;
+	SetCastleData strnpcinfo(2), CD_CURRENT_ECONOMY, .@Economy;
 	// Adjust Defense Invest Level for Castle
-	set .@Defence,GetCastleData(strnpcinfo(2),3) - 5;
+	set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE) - 5;
 	if (.@Defence < 0) set .@Defence, 0;
-	SetCastleData strnpcinfo(2), 3, .@Defence;
+	SetCastleData strnpcinfo(2), CD_CURRENT_DEFENSE, .@Defence;
 
 	// Set new Castle Occupant
-	SetCastleData strnpcinfo(2),1, .@GID;
+	SetCastleData strnpcinfo(2),CD_GUILD_ID, .@GID;
 
 	// Announce that the Emperium is destroyed, and respawn all but new castle-occupants.
 	mapannounce strnpcinfo(2),"The emperium has been destroyed.",bc_map|bc_woe,"0x00CCFF",FW_NORMAL,12;
@@ -127,12 +127,12 @@ OnAgitBreak:
 	// Refresh castle data, disable Kafra and reset Invest information.
 	donpcevent strnpcinfo(0)+"::OnRecvCastle";
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
-	for( set .@i, 4; .@i <= 9; set .@i, .@i+1 ) {
+	for( set .@i, CD_INVESTED_ECONOMY; .@i <= CD_ENABLED_KAFRA; set .@i, .@i+1 ) {
 		SetCastleData strnpcinfo(2), .@i, 0;
 	}
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	if( getgdskilllv(.@GID,10002) == 0 ) {
-		for( set .@i, 10; .@i <= 17; set .@i, .@i+1 ) {
+		for( set .@i, CD_ENABLED_GUARDIAN00; .@i < CD_MAX; set .@i, .@i+1 ) {
 			SetCastleData strnpcinfo(2), .@i, 0;
 		}
 	}
@@ -149,7 +149,7 @@ OnAgitEnd:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	GvgOff strnpcinfo(2);
 	// If the castle has no owner at the end of WoE, do not kill Emperium.
-	if (GetCastleData(strnpcinfo(2),1)) {
+	if (GetCastleData(strnpcinfo(2),CD_GUILD_ID)) {
 		KillMonster strnpcinfo(2),"Agit#"+strnpcinfo(2)+"::OnAgitBreak";
 	}
 	end;
@@ -160,7 +160,7 @@ OnGuildBreak:
 	// Kill guardians, disable the Kafra, and set owner to 0.
 	killmonster strnpcinfo(2),"Guardian#"+strnpcinfo(2)+"::OnGuardianDied";
 	disablenpc "Kafra Staff#"+strnpcinfo(2);
-	SetCastleData strnpcinfo(2),1,0;
+	SetCastleData strnpcinfo(2),CD_GUILD_ID,0;
 	// Wait before refreshing guild information.
 	sleep 7000;
 	Announce "Guild Base [" + GetCastleName(strnpcinfo(2)) + "] has been abandoned.",0;
@@ -171,7 +171,7 @@ OnAgitInit:
 OnRecvCastle:
 	if (strnpcinfo(0) == "Gld_Agit_Manager") end;
 	// Spawn Monsters if the castle is empty.
-	set .@GID, GetCastleData(strnpcinfo(2),1);
+	set .@GID, GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 	if (.@GID == 0) {
 		killmonsterall strnpcinfo(2);
 		if (compare(strnpcinfo(2),"aldeg")) {
@@ -309,7 +309,7 @@ OnRecvCastle:
 		// And load purchased Guardian in castles.
 		donpcevent "Guardian#"+strnpcinfo(2)+"::OnSpawnGuardians";
 		// And display Kafra if purchased.
-		if (GetCastleData(strnpcinfo(2),9) < 1) disablenpc "Kafra Staff#"+strnpcinfo(2);
+		if (GetCastleData(strnpcinfo(2),CD_ENABLED_KAFRA) < 1) disablenpc "Kafra Staff#"+strnpcinfo(2);
 	}
 	end;
 }
@@ -318,7 +318,7 @@ OnRecvCastle:
 //============================================================
 -	script	Kafra Staff#woe::guildkafra	-1,{
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 	if (compare(strnpcinfo(2),"aldeg")) {
 		setarray .@destination$[0],"Al De Baran","aldebaran";
@@ -467,7 +467,7 @@ OnRecvCastle:
 //============================================================
 -	script	Castle Manager#cm::cm	-1,{
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 	// .@guardiantype = Defines the types of guardians per castle basis.
 	// 1 - Soldier Guardian, 2 - Archer Guardian, 3 - Knight Guardian
@@ -610,7 +610,7 @@ OnRecvCastle:
 		mes "Brave soul... fate will guide you towards your future...";
 		close;
 	}
-	if (GetGuildMaster(.@GID) != strcharinfo(0)) {
+	if (is_guild_leader(.@GID) == false) {
 		mes "["+strnpcinfo(1)+"]";
 		mes "No matter how much you pester me, I'll still follow my master ^ff0000"+GetGuildMaster(.@GID)+"^000000. Where are the Guardians?! Send these ruffians away right now!";
 		close;
@@ -624,19 +624,19 @@ OnRecvCastle:
 		mes "["+strnpcinfo(1)+"]";
 		mes "I will report the Castle briefing, Master.";
 		mes " ";
-		mes "^0000ffNow, the commercial growth level is "+GetCastleData(strnpcinfo(2),2)+".";
-		if (GetCastleData(strnpcinfo(2),4)) {
-			mes " You invested "+GetCastleData(strnpcinfo(2),4)+" times in past 1 day.";
+		mes "^0000ffNow, the commercial growth level is "+GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY)+".";
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+			mes " You invested "+GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)+" times in past 1 day.";
 		}
-		mes " Now, the Castle Defense level is "+GetCastleData(strnpcinfo(2),3)+".^000000";
-		if (GetCastleData(strnpcinfo(2),5)) {
-			mes " ^0000ff- You invested "+GetCastleData(strnpcinfo(2),5)+" times in past 1 day.^000000";
+		mes " Now, the Castle Defense level is "+GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE)+".^000000";
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+			mes " ^0000ff- You invested "+GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)+" times in past 1 day.^000000";
 		}
 		mes " ";
 		mes "That's all I have to report, Master.";
 		close;
 	case 2:
-		set .@Economy,GetCastleData(strnpcinfo(2),2);
+		set .@Economy,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY);
 		if (.@Economy < 6) { set .@eco_invest,5000; }
 		else if ((.@Economy >= 6) && (.@Economy <= 10)) { set .@eco_invest,10000; }
 		else if ((.@Economy >= 11) && (.@Economy <= 15)) { set .@eco_invest,20000; }
@@ -658,7 +658,7 @@ OnRecvCastle:
 		else if ((.@Economy >= 91) && (.@Economy <= 95)) { set .@eco_invest,860000; }
 		else if ((.@Economy >= 96) && (.@Economy <= 100)) { set .@eco_invest,955000; }
 		//Quadruple the cost of investing if you've already invested once.
-		if (GetCastleData(strnpcinfo(2),4)) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
 			set .@eco_invest,.@eco_invest*4;
 		}
 		mes "["+strnpcinfo(1)+"]";
@@ -670,12 +670,12 @@ OnRecvCastle:
 			mes "^ff0000The commercial growth level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great economist like you, Master.^000000";
 			close;
 		}
-		if (GetCastleData(strnpcinfo(2),4) >= 2) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) >= 2) {
 			mes " ";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect riches of the guild to grow at a high rate.";
 			close;
 		}
-		if (GetCastleData(strnpcinfo(2),4) == 0) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) == 0) {
 			mes " ";
 			mes "The current investment amount required is ^ff0000"+.@eco_invest+"^000000 zeny. Will you invest?";
 		}
@@ -692,7 +692,7 @@ OnRecvCastle:
 				close;
 			}
 			set Zeny, Zeny - .@eco_invest;
-			SetCastleData strnpcinfo(2),4,GetCastleData(strnpcinfo(2),4)+1;
+			SetCastleData strnpcinfo(2),CD_INVESTED_ECONOMY,GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)+1;
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "We finished the investment safely. I expect that our growth level will be increased by tomorrow.";
 			close;
@@ -702,7 +702,7 @@ OnRecvCastle:
 			close;
 		}
 	case 3:
-		set .@Defence,GetCastleData(strnpcinfo(2),3);
+		set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE);
 		if (.@Defence < 6) { set .@def_invest,10000; }
 		else if ((.@Defence >= 6) && (.@Defence <= 10)) { set .@def_invest,20000; }
 		else if ((.@Defence >= 11) && (.@Defence <= 15)) { set .@def_invest,40000; }
@@ -724,7 +724,7 @@ OnRecvCastle:
 		else if ((.@Defence >= 91) && (.@Defence <= 95)) { set .@def_invest,1720000; }
 		else if ((.@Defence >= 96) && (.@Defence <= 100)) { set .@def_invest,1910000; }
 		//Quadruple the cost of investing if you've already invested once.
-		if (GetCastleData(strnpcinfo(2),5)) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
 			set .@def_invest,.@def_invest*4;
 		}
 		mes "["+strnpcinfo(1)+"]";
@@ -736,12 +736,12 @@ OnRecvCastle:
 			mes "^ff0000But the Castle Defense level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great strategist like you, Master.^000000";
 			close;
 		}
-		if (GetCastleData(strnpcinfo(2),5) >= 2) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE) >= 2) {
 			mes " ";
 			mes "^ff0000You have already invested twice today. You cannot invest any more.^000000 I expect the Defenses of the guild to grow at a high rate.";
 			close;
 		}
-		if (GetCastleData(strnpcinfo(2),5) == 0) {
+		if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE) == 0) {
 			mes " ";
 			mes "The current investment amount required is ^ff0000"+.@def_invest+"^000000 zeny. Will you invest?";
 		}
@@ -758,7 +758,7 @@ OnRecvCastle:
 				close;
 			}
 			set Zeny, Zeny - .@def_invest;
-			SetCastleData strnpcinfo(2),5,GetCastleData(strnpcinfo(2),5)+1;
+			SetCastleData strnpcinfo(2),CD_INVESTED_DEFENSE,GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)+1;
 			mes "[ "+strnpcinfo(1)+"]";
 			mes "We finished the investment safely. I expect that our Castle Defense level will be increased by tomorrow.";
 			close;
@@ -821,7 +821,7 @@ OnRecvCastle:
 			close;
 		}
 	case 5:
-		if (GetCastleData(strnpcinfo(2),9) == 1) {
+		if (GetCastleData(strnpcinfo(2),CD_ENABLED_KAFRA) == 1) {
 			mes "["+strnpcinfo(1)+"]";
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			next;
@@ -850,7 +850,7 @@ OnRecvCastle:
 				close;
 			}
 			disablenpc "Kafra Staff#"+strnpcinfo(2);
-			SetCastleData strnpcinfo(2),9,0;
+			SetCastleData strnpcinfo(2),CD_ENABLED_KAFRA,0;
 			mes "["+strnpcinfo(1)+"]";
 			mes "....";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
@@ -874,7 +874,7 @@ OnRecvCastle:
 			}
 			set Zeny, Zeny - 10000;
 			enablenpc "Kafra Staff#"+strnpcinfo(2);
-			SetCastleData strnpcinfo(2),9,1;
+			SetCastleData strnpcinfo(2),CD_ENABLED_KAFRA,1;
 			mes "["+strnpcinfo(1)+"]";
 			mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 			next;
@@ -919,7 +919,7 @@ OnRecvCastle:
 //============================================================
 -	script	Lever#gd::gdlever	-1,{
 
-	set .@GID,GetCastleData(strnpcinfo(2),1);
+	set .@GID,GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 
 	if (.@GID == 0) {
 		mes "[Ringing Voice]";
@@ -1133,13 +1133,13 @@ OnClock0001:
 	// Do nothing if this script is the template.
 	if (strnpcinfo(1) == "Gld_Trea_Spawn") end;
 	
-	set .@GID, GetCastleData(strnpcinfo(2),1);
+	set .@GID, GetCastleData(strnpcinfo(2),CD_GUILD_ID);
 	
 	// If there is no owner, do nothing.
 	if (!.@GID) end;
 
 	// Is there Economy in this castle?
-	set .@Treasure,GetCastleData(strnpcinfo(2),2)/5+4;
+	set .@Treasure,GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY)/5+4;
 
 	// Set information
 	if (strnpcinfo(2) == "aldeg_cas01") { 
@@ -1249,19 +1249,19 @@ OnClock0001:
 
 	// Apply investment to Eco. and Def. Only happens if there were investments made.
 	// Permanent Development can only happen once per day.
-	if (GetCastleData(strnpcinfo(2),4)) {
-		set .@Economy,GetCastleData(strnpcinfo(2),2);
-		SetCastleData strnpcinfo(2),2,.@Economy + GetCastleData(strnpcinfo(2),4) + (rand(2) && getgdskilllv(.@GID,10014));
-		if (GetCastleData(strnpcinfo(2),2) > 100) SetCastleData strnpcinfo(2),2,100;
+	if (GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+		set .@Economy,GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY);
+		SetCastleData strnpcinfo(2),CD_INVESTED_ECONOMY,.@Economy + GetCastleData(strnpcinfo(2),CD_INVESTED_ECONOMY) + (rand(2) && getgdskilllv(.@GID,10014));
+		if (GetCastleData(strnpcinfo(2),CD_CURRENT_ECONOMY) > 100) SetCastleData strnpcinfo(2),CD_CURRENT_ECONOMY,100;
 	}
-	if (GetCastleData(strnpcinfo(2),5)) {
-		set .@Defence,GetCastleData(strnpcinfo(2),3);
-		SetCastleData strnpcinfo(2),3,.@Defence + GetCastleData(strnpcinfo(2),5);
-		if (GetCastleData(strnpcinfo(2),3) > 100) SetCastleData strnpcinfo(2),3,100;
+	if (GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+		set .@Defence,GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE);
+		SetCastleData strnpcinfo(2),CD_CURRENT_DEFENSE,.@Defence + GetCastleData(strnpcinfo(2),CD_INVESTED_DEFENSE);
+		if (GetCastleData(strnpcinfo(2),CD_CURRENT_DEFENSE) > 100) SetCastleData strnpcinfo(2),CD_CURRENT_DEFENSE,100;
 	}
 	// Reset daily investment limits.
-	setcastledata strnpcinfo(2),4,0;
-	setcastledata strnpcinfo(2),5,0;
+	setcastledata strnpcinfo(2),CD_INVESTED_ECONOMY,0;
+	setcastledata strnpcinfo(2),CD_INVESTED_DEFENSE,0;
 
 	// Spawn boxes in proper order.
 	for (set .@i,0; .@i < .@Treasure ; set .@i,.@i+1) {

+ 1 - 1
npc/guild/trs_rp.txt

@@ -20,7 +20,7 @@
 	end;
 OnTouch:
 	set .@GID, getcastledata(strnpcinfo(2),1);
-	if (strcharinfo(0) != getguildmaster(.@GID)) {
+	if (is_guild_leader(.@GID) == false) {
 		if (compare(strnpcinfo(2),"aldeg"))
 			warp "aldebaran",143,112;
 		else if (compare(strnpcinfo(2),"gefg"))

+ 60 - 60
npc/guild2/agit_main_se.txt

@@ -25,7 +25,7 @@
 OnAgitInit2:
 OnRecvCastle2:
 	if (strnpcinfo(2) == "template") end;
-	if (!getcastledata(strnpcinfo(2),1)) {
+	if (!getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		donpcevent strnpcinfo(0)+"::OnStart";
 		// Monster spawns are identical for all castles.
 		monster strnpcinfo(2),0,0,"Evil Druid",1117,10;
@@ -42,14 +42,14 @@ OnRecvCastle2:
 		monster strnpcinfo(2),0,0,"Dark Lord",1272,2;
 		monster strnpcinfo(2),0,0,"Tower Keeper",1270,4;
 	}
-	if (getcastledata(strnpcinfo(2),9) < 1)
+	if (getcastledata(strnpcinfo(2),CD_ENABLED_KAFRA) < 1)
 		disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 	end;
 
 OnAgitStart2:
 	if (strnpcinfo(2) == "template") end;
 	if (agitcheck2()) {
-		maprespawnguildid strnpcinfo(2),getcastledata(strnpcinfo(2),1),2;
+		maprespawnguildid strnpcinfo(2),getcastledata(strnpcinfo(2),CD_GUILD_ID),2;
 		gvgon strnpcinfo(2);
 		donpcevent strnpcinfo(0)+"::OnStart";
 	}
@@ -60,7 +60,7 @@ OnAgitStart2:
 OnAgitEnd2:
 	if (strnpcinfo(2) == "template") end;
 	gvgoff strnpcinfo(2);
-	if (getcastledata(strnpcinfo(2),1)) {
+	if (getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		set .@str$,substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
 		killmonster strnpcinfo(2),"Steward#"+.@str$+"::OnStartArena";
 		donpcevent strnpcinfo(0)+"::OnReset";
@@ -73,7 +73,7 @@ OnGuildBreak:
 	killmonster strnpcinfo(2),"gard1#"+strnpcinfo(2)+"::OnGuardianDied";
 	killmonster strnpcinfo(2),"gard2#"+strnpcinfo(2)+"::OnGuardianDied";
 	disablenpc "Kafra Employee#"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9);
-	setcastledata strnpcinfo(2),1,0;
+	setcastledata strnpcinfo(2),CD_GUILD_ID,0;
 	sleep 7000;
 	announce "Guild Base ["+getcastlename(strnpcinfo(2))+"] has been abandoned.",0;
 	donpcevent strnpcinfo(0)+"::OnRecvCastle2";
@@ -84,7 +84,7 @@ OnStart:
 	// 1st Guardian stone, 2nd Guardian stone, Barrier 1, Barrier 2, Barrier 3, Summon Guardians
 	// Settings for all but Summon Guardians: 0 = Okay | 1 = Destroyed | 2 = Repairing
 	// Summon Guardians: 0 = Do not Summon | 1 = Summon
-	if (getcastledata(strnpcinfo(2),1)) {
+	if (getcastledata(strnpcinfo(2),CD_GUILD_ID)) {
 		setarray getd("$agit_"+substr(strnpcinfo(2),0,1)+substr(strnpcinfo(2),8,9)+"[0]"),0,0,0,0,0,0;
 		donpcevent "df1#"+strnpcinfo(2)+"::OnEnable";
 		donpcevent "df2#"+strnpcinfo(2)+"::OnEnable";
@@ -136,21 +136,21 @@ OnChange:
 OnClock0001:
 	// Spawn Treasure Chests based on castle economy.
 	if (strnpcinfo(2) == "template") end;
-	if (!getcastledata(strnpcinfo(2),1)) end;
+	if (!getcastledata(strnpcinfo(2),CD_GUILD_ID)) end;
 	killmonster strnpcinfo(2),strnpcinfo(0)+"::OnTreasureDied";
-	if (getcastledata(strnpcinfo(2),4)) {
-		set .@Economy,getcastledata(strnpcinfo(2),2);
-		setcastledata strnpcinfo(2),2,.@Economy+getcastledata(strnpcinfo(2),4)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),1),10014));
-		if (getcastledata(strnpcinfo(2),2) > 100) setcastledata strnpcinfo(2),2,100;
-		setcastledata strnpcinfo(2),4,0;
+	if (getcastledata(strnpcinfo(2),CD_INVESTED_ECONOMY)) {
+		set .@Economy,getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY);
+		setcastledata strnpcinfo(2),CD_CURRENT_ECONOMY,.@Economy+getcastledata(strnpcinfo(2),CD_INVESTED_ECONOMY)+(rand(2) && getgdskilllv(getcastledata(strnpcinfo(2),CD_GUILD_ID),10014));
+		if (getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY) > 100) setcastledata strnpcinfo(2),CD_CURRENT_ECONOMY,100;
+		setcastledata strnpcinfo(2),CD_INVESTED_ECONOMY,0;
 	}
-	if (getcastledata(strnpcinfo(2),5)) {
-		set .@Defence,getcastledata(strnpcinfo(2),3);
-		setcastledata strnpcinfo(2),3,.@Defence+getcastledata(strnpcinfo(2),5);
-		if (getcastledata(strnpcinfo(2),3) > 100) setcastledata strnpcinfo(2),3,100;
-		setcastledata strnpcinfo(2),5,0;
+	if (getcastledata(strnpcinfo(2),CD_INVESTED_DEFENSE)) {
+		set .@Defence,getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE);
+		setcastledata strnpcinfo(2),CD_CURRENT_DEFENSE,.@Defence+getcastledata(strnpcinfo(2),CD_INVESTED_DEFENSE);
+		if (getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE) > 100) setcastledata strnpcinfo(2),CD_CURRENT_DEFENSE,100;
+		setcastledata strnpcinfo(2),CD_INVESTED_DEFENSE,0;
 	}
-	set .@Treasure,getcastledata(strnpcinfo(2),2)/5+4;
+	set .@Treasure,getcastledata(strnpcinfo(2),CD_CURRENT_ECONOMY)/5+4;
 	if (!.@Treasure) end;
 	freeloop(1);
 	if (compare(strnpcinfo(2),"arug")) {
@@ -205,7 +205,7 @@ OnTreasureDied:
 // Guild Manager
 //============================================================
 -	script	Steward#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (!.@GID) {
 		mes "[ Steward ]";
 		mes "I await for the master";
@@ -215,7 +215,7 @@ OnTreasureDied:
 		mes "to conquer this stronghold?";
 		close;
 	}
-	if (getcharid(2) != .@GID || strcharinfo(0) != getguildmaster(.@GID)) {
+	if (is_guild_leader(.@GID) == false) {
 		mes "[ Steward ]";
 		mes "Hmpf. Your threats don't";
 		mes "scare me! Guardians, drive";
@@ -236,24 +236,24 @@ OnTreasureDied:
 	case 1:
 		mes "[ Steward ]";
 		mes "The Commercial Growth";
-		mes "Level of the stronghold is ^0000ff"+getcastledata(strnpcinfo(4),2)+".";
-		if (getcastledata(strnpcinfo(4),4) > 0) {
+		mes "Level of the stronghold is ^0000ff"+getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY)+".";
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) > 0) {
 			mes "Last time, you invested in";
-			mes "Commercial Growth "+getcastledata(strnpcinfo(4),4)+".";
+			mes "Commercial Growth "+getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)+".";
 		}
 		next;
 		mes "[ Steward ]";
 		mes "Our stronghold's";
-		mes "safeguard level is "+getcastledata(strnpcinfo(4),3)+".";
-		if (getcastledata(strnpcinfo(4),5) > 0) {
+		mes "safeguard level is "+getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE)+".";
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) > 0) {
 			mes "Last time, you invested";
-			mes "in defense "+getcastledata(strnpcinfo(4),5)+" times.";
+			mes "in defense "+getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)+" times.";
 		}
 		mes " ";
 		mes "That is all, master.";
 		close;
 	case 2:
-		set .@Economy,getcastledata(strnpcinfo(4),2);
+		set .@Economy,getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY);
 		setarray .@cost[0],5000,10000,20000,35000,55000,80000,110000,145000,185000,230000,280000,335000,395000,460000,530000,605000,685000,770000,860000,955000;
 		set .@j,0;
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
@@ -264,7 +264,7 @@ OnTreasureDied:
 			set .@j, .@j+1;
 		}
 		// Quadruple the cost of investing if you've already invested once.
-		if (getcastledata(strnpcinfo(4),4)) set .@eco_invest,.@eco_invest*4;
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)) set .@eco_invest,.@eco_invest*4;
 		mes "[ Steward ]";
 		mes "Raising the stronghold's";
 		mes "commercial growth will";
@@ -290,7 +290,7 @@ OnTreasureDied:
 			mes "any further than that.";
 			close;
 		}
-		if (getcastledata(strnpcinfo(4),4) >= 2) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) >= 2) {
 			mes "[ Steward ]";
 			mes "You've already made two";
 			mes "investments today, so you'll";
@@ -298,7 +298,7 @@ OnTreasureDied:
 			mes "to make another investment.";
 			close;
 		}
-		if (getcastledata(strnpcinfo(4),4) == 0) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) == 0) {
 			mes "[ Steward ]";
 			mes "You must pay ^FF0000"+.@eco_invest+"^000000 Zeny";
 			mes "to make an investment";
@@ -316,7 +316,7 @@ OnTreasureDied:
 		next;
 		switch(select("Invest in Commercial Growth:Cancel")) {
 		case 1:
-			if (getcastledata(strnpcinfo(4),4) >= 2) {
+			if (getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY) >= 2) {
 				mes "[ Steward ]";
 				mes "You've already made two";
 				mes "investments today, so you'll";
@@ -333,7 +333,7 @@ OnTreasureDied:
 				close;
 			}
 			set Zeny, Zeny-.@eco_invest;
-			setcastledata strnpcinfo(4),4,getcastledata(strnpcinfo(4),4)+1;
+			setcastledata strnpcinfo(4),CD_INVESTED_ECONOMY,getcastledata(strnpcinfo(4),CD_INVESTED_ECONOMY)+1;
 			mes "[ Steward ]";
 			mes "A wise use of the guild's";
 			mes "funds, Master. We can expect";
@@ -346,7 +346,7 @@ OnTreasureDied:
 			close;
 		}
 	case 3:
-		set .@Defence,getcastledata(strnpcinfo(4),3);
+		set .@Defence,getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE);
 		setarray .@cost[0],10000,20000,40000,70000,110000,160000,220000,290000,370000,460000,560000,670000,790000,920000,1060000,1210000,1370000,1540000,1720000,1910000;
 		set .@j,0;
 		for(set .@i,6; .@i<101; set .@i,.@i+5) {
@@ -357,7 +357,7 @@ OnTreasureDied:
 			set .@j, .@j+1;
 		}
 		// Quadruple the cost of investing if you've already invested once.
-		if (getcastledata(strnpcinfo(4),5)) set .@def_invest,.@def_invest*4;
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)) set .@def_invest,.@def_invest*4;
 		mes "[ Steward ]";
 		mes "Investing in our stronghold's";
 		mes "defense will enhance the";
@@ -373,13 +373,13 @@ OnTreasureDied:
 		mes "a maximum of two times daily.";
 		next;
 		mes "[ Steward ]";
-		if (getcastledata(strnpcinfo(4),3) == 100) {
+		if (getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE) == 100) {
 			mes "The Defense Level of this";
 			mes "stronghold is 100%, and";
 			mes "cannot be increased further.";
 			close;
 		}
-		if (getcastledata(strnpcinfo(4),5) >= 2) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) >= 2) {
 			mes "Master, you've already";
 			mes "invested in Defense twice";
 			mes "today. You'll need to wait";
@@ -387,7 +387,7 @@ OnTreasureDied:
 			mes "want to increase our defenses.";
 			close;
 		}
-		if (getcastledata(strnpcinfo(4),5) == 0) {
+		if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) == 0) {
 			mes "We need ^FF0000"+.@def_invest+"^000000";
 			mes "Zeny to invest in our";
 			mes "stronghold's defenses.";
@@ -403,7 +403,7 @@ OnTreasureDied:
 		next;
 		switch(select("Invest in Defense:Cancel")) {
 		case 1:
-			if (getcastledata(strnpcinfo(4),5) >= 2) {
+			if (getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE) >= 2) {
 				mes "[ Steward ]";
 				mes "Master, you've already";
 				mes "invested in Defense twice";
@@ -421,7 +421,7 @@ OnTreasureDied:
 				close;
 			}
 			set Zeny, Zeny-.@def_invest;
-			setcastledata strnpcinfo(4),5,getcastledata(strnpcinfo(4),5)+1;
+			setcastledata strnpcinfo(4),CD_INVESTED_DEFENSE,getcastledata(strnpcinfo(4),CD_INVESTED_DEFENSE)+1;
 			mes "[ Steward ]";
 			mes "A wise use of the guild's";
 			mes "funds, Master. Increasing";
@@ -435,7 +435,7 @@ OnTreasureDied:
 			close;
 		}
 	case 4:
-		if (getcastledata(strnpcinfo(4),9) == 1) {
+		if (getcastledata(strnpcinfo(4),CD_ENABLED_KAFRA) == 1) {
 			mes "[ Steward ]";
 			mes "Do you wish to dismiss";
 			mes "the Kafra Employee that";
@@ -478,7 +478,7 @@ OnTreasureDied:
 				close;
 			}
 			disablenpc "Kafra Employee#"+strnpcinfo(2);
-			setcastledata strnpcinfo(4),9,0;
+			setcastledata strnpcinfo(4),CD_ENABLED_KAFRA,0;
 			mes "[ Steward ]";
 			mes "That Kafra Employee";
 			mes "has been dismissed.";
@@ -514,7 +514,7 @@ OnTreasureDied:
 				}
 				set Zeny, Zeny-10000;
 				enablenpc "Kafra Employee#"+strnpcinfo(2);
-				setcastledata strnpcinfo(4),9,1;
+				setcastledata strnpcinfo(4),CD_ENABLED_KAFRA,1;
 				mes "[ Steward ]";
 				mes "Very well. We have formed";
 				mes "a contract with the Kafra";
@@ -605,17 +605,17 @@ OnStartArena:
 	set .@GID,getcharid(2);
 	set .@region$, (compare(strnpcinfo(4),"arug"))?"Valfreyja":"Nithafjoll";
 	// Lower castle Economy
-	set .@Economy,getcastledata(strnpcinfo(4),2)-5;
+	set .@Economy,getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY)-5;
 	if (.@Economy < 0) set .@Economy, 0;
-	setcastledata strnpcinfo(4),2,.@Economy;
+	setcastledata strnpcinfo(4),CD_CURRENT_ECONOMY,.@Economy;
 	// Lower Castle Defence
-	set .@Defence,getcastledata(strnpcinfo(4),3)-5;
+	set .@Defence,getcastledata(strnpcinfo(4),CD_CURRENT_DEFENSE)-5;
 	if (.@Defence < 0) set .@Defence, 0;
-	setcastledata strnpcinfo(4),3,.@Defence;
+	setcastledata strnpcinfo(4),CD_CURRENT_DEFENSE,.@Defence;
 	// Set new owner
-	setcastledata strnpcinfo(4),1,.@GID;
+	setcastledata strnpcinfo(4),CD_GUILD_ID,.@GID;
 	// Clear castle's data.
-	for(set .@i,4; .@i<10; set .@i,.@i+1)
+	for(set .@i,CD_INVESTED_ECONOMY; .@i<CD_ENABLED_GUARDIAN00; set .@i,.@i+1)
 		setcastledata strnpcinfo(4),.@i,0;
 	// Disable Kafra
 	disablenpc "Kafra Employee#"+strnpcinfo(2);
@@ -623,7 +623,7 @@ OnStartArena:
 	announce "The ["+getguildname(.@GID)+"] guild conquered the ["+.@region$+" "+charat(strnpcinfo(2),3)+"] stronghold of "+getcastlename(strnpcinfo(4))+"!",bc_all|bc_woe;
 	mapannounce strnpcinfo(4),"The emperium has been shattered!",bc_map,"0x00FF00",FW_NORMAL,20,0,40;
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnReset";
-	maprespawnguildid strnpcinfo(4),getcastledata(strnpcinfo(4),1),2;
+	maprespawnguildid strnpcinfo(4),getcastledata(strnpcinfo(4),CD_GUILD_ID),2;
 	donpcevent "Manager#"+strnpcinfo(4)+"::OnRecvCastle2";
 	donpcevent "::OnRecvCastle"+strnpcinfo(2);
 	sleep 10000;
@@ -637,7 +637,7 @@ OnStartArena:
 // Castle Guardians
 //============================================================
 -	script	Guardian#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@n$, "["+strnpcinfo(1)+"]";
 	if (!.@GID) {
 		mes .@n$;
@@ -648,7 +648,7 @@ OnStartArena:
 		close;
 	}
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) != getguildmaster(.@GID)) {
+		if (is_guild_leader() == false) {
 			mes .@n$;
 			mes "As guardian of this";
 			mes "stronghold, I answer only";
@@ -838,7 +838,7 @@ OnInit:
 //============================================================
 -	script	Kafra#template	-1,{
 	cutin "kafra_01",2;
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (getcharid(2) == .@GID && getgdskilllv(.@GID,10001)) {
 		mes "[Kafra Employee]";
 		mes "Welcome, proud member";
@@ -950,7 +950,7 @@ OnInit:
 // Guardian Stones (2)
 //============================================================
 -	script	Guardian Stone#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@num, atoi(charat(strnpcinfo(1),0));
 	set .@var$,"$agit_"+strnpcinfo(2);
 	if (getcharid(2) == .@GID) {
@@ -1104,11 +1104,11 @@ OnEnable:
 // Control Devices (3)
 //============================================================
 -	script	Control#template	-1,{
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	set .@num, atoi(charat(strnpcinfo(1),15));
 	set .@var$,"$agit_"+strnpcinfo(2);
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (getd(.@var$+"["+(.@num+1)+"]") == 2) {
 				mes "^3355FFDemolished Fortress";
 				mes "Gates can be repaired,";
@@ -1386,7 +1386,7 @@ OnEnable:
 	}
 	if (charat(strnpcinfo(1),4) == "2") set .@z,11;
 	freeloop(1);
-	set .@defence,getcastledata(strnpcinfo(2),3);
+	set .@defence,getcastledata(strnpcinfo(2),CD_CURRENT_DEFENSE);
 	callsub OnSummon,.@z;
 	if (.@defence > 70) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),5;
 	else if (.@defence > 50) set getd(".MyMobCount_"+charat(strnpcinfo(1),4)+strnpcinfo(2)),4;
@@ -1710,7 +1710,7 @@ OnDisable:
 // Link Flags (function)
 //============================================================
 function	script	LinkFlag	{
-	if (!getcharid(2) || getcharid(2) != getcastledata(strnpcinfo(4),1)) end;
+	if (!getcharid(2) || getcharid(2) != getcastledata(strnpcinfo(4),CD_GUILD_ID)) end;
 	if (getarg(0) == "Convenience Facility") {
 		mes "^3355FFThis is the Stronghold";
 		mes "Teleport Service. Would";
@@ -1748,7 +1748,7 @@ function	script	LinkFlag	{
 function	script	ReturnFlag	{
 	.@map$ = getarg(0);
 	set .@str$, (compare(strnpcinfo(4),"aru"))?"Arunafeltz":"Schwaltzvalt";
-	.@GID =  getcastledata(.@map$,1);
+	.@GID =  getcastledata(.@map$,CD_GUILD_ID);
 	if (!.@GID) {
 		mes "[ "+.@str$+" Royal Edict ]";
 		mes "The Holy Kingdom of";
@@ -1765,7 +1765,7 @@ function	script	ReturnFlag	{
 		mes "do you wish to return";
 		mes "to your stronghold?";
 		next;
-		if(select("Return to the Stronghold:Cancel") == 1 && getcharid(2) == getcastledata(.@map$,1)) {
+		if(select("Return to the Stronghold:Cancel") == 1 && getcharid(2) == getcastledata(.@map$,CD_GUILD_ID)) {
 			if (compare(.@map$,"arug")) {
 				if (.@map$ == "arug_cas01") setarray .@i[0],67,193;
 				else if (.@map$ == "arug_cas02") setarray .@i[0],43,256;
@@ -1821,7 +1821,7 @@ function	script	ReturnFlag	{
 // Guild Dungeon Warps
 //============================================================
 -	script	Sunflower#template	-1,{
-	if (getcharid(2) == getcastledata(strnpcinfo(4),1)) {
+	if (getcharid(2) == getcastledata(strnpcinfo(4),CD_GUILD_ID)) {
 		mes "- It's an amazingly huge sunflower; as big as a human! ... You feel something mysterious emanating from the flower. -";
 		next;
 		switch(select("Hold the stem.:Do nothing.")) {

+ 1 - 1
npc/instances/EndlessTower.txt

@@ -216,7 +216,7 @@ e_tower,81,105,0	script	Tower Protection Stone	406,{
 	}
 	switch(.@etower_timer) {
 	case -1:
-		if (getcharid(0) == getpartyleader(.@party_id,2)) {
+		if (is_party_leader() == true) {
 			mes "Confirmed the party has been made. Would you like to reserve entrance to the Endless Tower?";
 			next;
 			switch(select("Generate dungeon "+.@md_name$+":Enter the dungeon:Return to Alberta:Cancel")) {

+ 3 - 3
npc/instances/NydhoggsNest.txt

@@ -108,7 +108,7 @@ nyd_dun02,100,201,3	script	Yggdrasil Gatekeeper	111,8,8,{
 				mes "And only 1 representative of you needs to talk to me, so don't annoy me...";
 				close;
 			}
-			if (getcharid(0) == getpartyleader(.@party_id,2)) {
+			if (is_party_leader(.@party_id) == true) {
 				mes "[Yggdrasil Gatekeeper]";
 				mes "The loyal servants of the Guardian... what can I do for you?";
 				next;
@@ -1591,7 +1591,7 @@ OnTouch_:
 		mes "I thank you deeply for your decision. I will use what is left of my powers to open up the path towards the Guardian's Nest.";
 		next;
 		mes "[World Tree Yggdrasil]";
-		if (getcharid(0) == getpartyleader(getcharid(1),2)) {
+		if (is_party_leader() == true) {
 			mes "The path to the Guardian's Nest is just past the waterfall by the large World Tree Yggdrasil to the North. The defensive mechanisms of the Sanctuary will start immediately.";
 			next;
 			mes "[World Tree Yggdrasil]";
@@ -1844,7 +1844,7 @@ OnTouch:
 
 2@nyd,199,268,0	script	nyd_2f_boss_enter	-1,8,8,{
 OnTouch_:
-	if (getcharid(0) == getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		donpcevent instance_npcname("nyd_2f_boss_enter_call")+"::OnEnable";
 		disablenpc instance_npcname("nyd_2f_boss_enter");
 		end;

+ 2 - 2
npc/instances/OrcsMemory.txt

@@ -47,7 +47,7 @@ gef_fild10,242,202,0	script	Dimensional Gorge Piece	406,{
 
 	set .@orctime,checkquest(12059,PLAYTIME);
 	if (.@orctime == -1) {
-		if (getcharid(0) == getpartyleader(.@party_id,2)) {
+		if (is_party_leader() == true) {
 			mes "Party status confirmed. Would you like to book entrance to the "+.@md_name$+"?";
 			next;
 			switch(select("Reserve the "+.@md_name$+":Enter the Dungeon:Cancel")) {
@@ -677,7 +677,7 @@ OnTimer23910:
 }
 
 2@orcs,26,164,0	script	Torch#1-1	844,{
-	if(getpartyleader(getcharid(1),2) != getcharid(0)) end;
+	if (is_party_leader() == false) end;
 	progressbar "ffff00",5;
 	setarray .@id[0], atoi(charat(strnpcinfo(2),0)), atoi(charat(strnpcinfo(2),2));
 	if (.@id[1] == 4)

+ 8 - 10
npc/instances/SealedShrine.txt

@@ -109,7 +109,7 @@ monk_test,309,146,3	script	Friar Patrick#edq	412,{
 			//set .@ins_bapho_check2,checkquest(3045,PLAYTIME);
 
 			if (.@ins_bapho_check == -1) {
-				if (getpartyleader(.@party_id,2) == getcharid(0) && instance_check_party(.@party_id,2,75)) {
+				if (is_party_leader(.@party_id) == true && instance_check_party(.@party_id,2,75)) {
 					mes "[Friar Patrick]";
 					mes "Party name is "+getpartyname(.@party_id)+"...";
 					mes "Name of the leader is "+strcharinfo(0)+"...";
@@ -540,7 +540,7 @@ OnMyMobDead:
 		mes "If your ^0000FFparty leader^000000 brings me the pendant, my soul can be substantialized. So, hurry up.";
 		close;
 	}
-	else if (('ins_baphomet == 2) && (getpartyleader(.@party_id,2) == getcharid(0))) {
+	else if (('ins_baphomet == 2) && is_party_leader(.@party_id) == true) {
 		mes "[Voice of the Gravestone]";
 		mes "Did you find the pendant?";
 		next;
@@ -652,7 +652,7 @@ OnInstanceInit: // Temporary fix for @reloadscript.
 				break;
 			case 3:
 				set .@ins_baphomet_1f_3,.@ins_baphomet_1f_3+1;
-				if (getpartyleader(.@party_id,2) == getcharid(0)) {
+				if (is_party_leader(.@party_id) == true) {
 					mes "[Ancient Hero's Soul]";
 					mes "You look like the leader of this party. You need to go and get ^0000FF10 Essence of Fire^000000 from the torches.";
 					next;
@@ -704,7 +704,7 @@ OnInstanceInit: // Temporary fix for @reloadscript.
 			}
 			if (.@exitloop) break;
 		}
-		if (getpartyleader(.@party_id,2) == getcharid(0)) {
+		if (is_party_leader(.@party_id) == true) {
 			mes "[Ancient Hero's Soul]";
 			mes "To remind you again, I must be substantialized within the next hour. So everyone, finish your work within that time!";
 			set 'ins_baphomet,3;
@@ -721,7 +721,7 @@ OnInstanceInit: // Temporary fix for @reloadscript.
 		cutin "",255;
 		end;
 	}
-	else if (('ins_baphomet == 3) && (getpartyleader(.@party_id,2) == getcharid(0))) {
+	else if (('ins_baphomet == 3) && is_party_leader(.@party_id) == true) {
 		cutin "ins_cata_champ_n",2;
 		mes "[Ancient Hero's Soul]";
 		mes "Did you get 10 ^0000FFEssence of Fire^000000 and ^0000FFToken of Apostle^000000?";
@@ -758,7 +758,7 @@ OnInstanceInit: // Temporary fix for @reloadscript.
 		cutin "",255;
 		end;
 	}
-	else if (('ins_baphomet == 4) && (getpartyleader(.@party_id,2) == getcharid(0))) {
+	else if (('ins_baphomet == 4) && is_party_leader(.@party_id) == true) {
 		cutin "ins_cata_champ_n",2;
 		mes "[Ancient Hero's Soul]";
 		mes "Are you ready? I opened the sealed gate. To pass the gate, you should carry a ^0000FFToken of Apostle^000000.";
@@ -881,8 +881,7 @@ OnInstanceInit:
 // Bobbing Torches
 //============================================================
 -	script	Bobbing Torch#SS	-1,{
-	set .@party_id,getcharid(1);
-	if (getpartyleader(.@party_id,2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		if (('ins_baphomet == 3) && (countitem(6001) < 11)) {
 			mes "A huge torch appearing as if it can burn everything is bobbing up and down in front of me.";
 			next;
@@ -1120,8 +1119,7 @@ OnInstanceInit:
 2@cata,35,109,0	duplicate(Magical Seal#SS)	Magical Seal#10	844
 
 2@cata,79,65,0	script	The Main Altar#ss	844,{
-	set .@party_id,getcharid(1);
-	if (('ins_baphomet == 5) && (getpartyleader(.@party_id,2) == getcharid(0))) {
+	if (('ins_baphomet == 5) && is_party_leader() == true) {
 		mes "An evil power, too terrible to describe, lies under the great altar radiating a violet color.";
 		next;
 		mes "Complicated Magical Rune letters blink rapidly, attempting to suppress the dreadful power within.";

+ 1 - 1
npc/other/CashShop_Functions.txt

@@ -52,7 +52,7 @@ function	script	F_CashStore	{
 // - No arguments.
 function	script	F_CashPartyCall	{
 	warp "Random",0,0;
-	if(getpartyleader(getcharid(1),2) == getcharid(0))
+	if (is_party_leader() == true)
 		warpparty "Leader", 0, 0, getcharid(1), strcharinfo(3), 3, 3;
 	return;
 }

+ 3 - 4
npc/other/arena/arena_party.txt

@@ -1006,7 +1006,6 @@ prt_are_in,77,135,3	script	Staff#party-2	67,{
 	mes "[Staff]";
 	mes "^3131FF"+$arena_pttopn$+"^000000's running time was ^3131FF"+$top_ptmin+"^000000minutes ^3131FF"+$top_ptsec+"^000000seconds.";
 	next;
-	set .arn_party,getcharid(1);
 	if (@gappt < 0) {
 		mes "[Staff]";
 		mes "Although you failed to make a new record, I hope you will succeed next time.";
@@ -1034,7 +1033,7 @@ prt_are_in,77,135,3	script	Staff#party-2	67,{
 			mes "See you later~";
 			close2;
 		}
-		if(getpartyleader(.arn_party,2) == getcharid(0)) {
+		if (is_party_leader() == true) {
 			donpcevent "#arn_timer_pt::OnStop";
 			donpcevent "alloff#pt::OnEnable";
 			donpcevent "Ponox::OnStart";
@@ -1049,7 +1048,7 @@ prt_are_in,77,135,3	script	Staff#party-2	67,{
 		mes "Wow! You have renewed the record!";
 		mes "What a great job!";
 		next;
-		if(getpartyleader(.arn_party,2) == getcharid(0)) {
+		if (is_party_leader() == true) {
 			mes "[Staff]";
 			mes "You can record you and your party members on ^FF0000the hall of Arena Time Force Battle party ^000000.";
 			mes "When you enter a name, the name will be remained on the top unless someone make a new record.";
@@ -1112,7 +1111,7 @@ prt_are_in,77,135,3	script	Staff#party-2	67,{
 			mes "See you later~";
 			close2;
 		}
-		if(getpartyleader(.arn_party,2) == getcharid(0)) {
+		if (is_party_leader() == true) {
 			donpcevent "#arn_timer_pt::OnStop";
 			donpcevent "alloff#pt::OnEnable";
 			donpcevent "Ponox::OnStart";

+ 4 - 4
npc/other/poring_war.txt

@@ -648,7 +648,7 @@ poring_w02,26,181,3	script	Mr. Doppel#wop_team_a	739,{
 			mes "If you don't get there in time, you won't make it to the battle.";
 			close;
 		case 2:
-			if ((getpartyleader(getcharid(1),2) == getcharid(0))) {
+			if (is_party_leader() == true) {
 				mes "[Mr. Doppel]";
 				mes "So, you are the leader. Before going to the battlefield, you should check all your members.";
 				next;
@@ -680,7 +680,7 @@ poring_w02,26,181,3	script	Mr. Doppel#wop_team_a	739,{
 		}
 	}
 	else {
-		if ((getpartyleader(getcharid(1),2) == getcharid(0))) {
+		if (is_party_leader() == true) {
 			if ($@wop_team_a == 0) {
 				mes "[Mr. Doppel]";
 				mes "So, you are the party leader of Angeling Team.";
@@ -779,7 +779,7 @@ poring_w02,170,181,3	script	Mr. Doppel#wop_team_d	739,{
 			mes "If you don't get there in time, you won't make it to the battle.";
 			close;
 		case 2:
-			if ((getpartyleader(getcharid(1),2) == getcharid(0))) {
+			if (is_party_leader() == true) {
 				mes "[Mr. Doppel]";
 				mes "So, you are the leader. Before going to the battlefield, you should check all your members.";
 				next;
@@ -809,7 +809,7 @@ poring_w02,170,181,3	script	Mr. Doppel#wop_team_d	739,{
 			}
 		}
 	} else {
-		if ((getpartyleader(getcharid(1),2) == getcharid(0))) {
+		if (is_party_leader() == true) {
 			if ($@wop_team_d == 0) {
 				mes "[Mr. Doppel]";
 				mes "So, you are the party leader of Deviling Team.";

+ 7 - 8
npc/quests/guildrelay.txt

@@ -69,7 +69,7 @@
 		close;
 	}
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (guildrelay_q == 100) {
 				if (guildtime > 22) {
 					if ((gettime(DT_HOUR) > 1) && (gettime(DT_HOUR) < guildtime)) {
@@ -1247,7 +1247,7 @@
 		close;
 	}
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (countitem(7234) > 0) {
 				mes "[" + .@name$ + "]";
 				mes "Hm. You can't just keep";
@@ -1710,7 +1710,7 @@
 		}
 	}
 	else {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader(.@GID) == true) {
 			mes "[" + .@name$ + "]";
 			mes "Hm? What brings you";
 			mes "here? Feel free to take";
@@ -1751,7 +1751,7 @@
 		close;
 	}
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (countitem(7240) > 0) {
 				mes "[" + .@name$ + "]";
 				mes "Hm? What are you doing?";
@@ -2266,7 +2266,7 @@
 		}
 	}
 	else {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader(.@GID) == true) {
 			mes "[" + .@name$ + "]";
 			mes "Hm. You're the master";
 			mes "of another guild, aren't";
@@ -2436,7 +2436,7 @@
 		close;
 	}
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (countitem(7246) > 0) {
 				mes "[" + .@name$ + "]";
 				mes "Hm? That spirit that";
@@ -2512,7 +2512,6 @@
 			}
 			getpartymember(getcharid(1));
 			set .@partymembercount,$@partymembercount;
-			set .@partyleader,getpartyleader(getcharid(1),2);
 			if (guildrelay_q == 91) {
 				if (.@partymembercount == 6) {
 					mes "[" + .@name$ + "]";
@@ -3059,7 +3058,7 @@
 		}
 	}
 	else {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader(.@GID) == true) {
 			mes "[" + .@name$ + "]";
 			mes "You might be the master";
 			mes "of a guild, but you and I";

+ 2 - 2
npc/quests/okolnir.txt

@@ -174,7 +174,7 @@ que_qsch05,345,23,0	warp	Gate02#gq_sch05	1,1,schg_cas05,369,306
 	set .@GID, GetCastleData(.@t$,1);
 	if (getcharid(2) == .@GID) {
 		cutin "wish_maiden31",1;
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			mes "[Wish Maiden]";
 			mes "I am... Wish maiden.";
 			mes "Mourning in this virtual realm, Okolnir.";
@@ -2146,7 +2146,7 @@ que_qsch05,251,255,3	duplicate(Wish Maiden#main_boss)	Wish Maiden#sch05_boss	193
 	set .@t$, ((compare(strnpcinfo(4),"aru"))?"arug_cas0":"schg_cas0")+(charat(strnpcinfo(4),getstrlen(strnpcinfo(4))-1));
 	set .@GID, GetCastleData(.@t$,1);
 	if (getcharid(2) == .@GID) {
-		if (strcharinfo(0) == getguildmaster(.@GID)) {
+		if (is_guild_leader() == true) {
 			if (compare(.@sub$,"aru")) {
 				setarray .@n, 7835,1,7836,1,7837,1,7838,1,2513,1,7291,10,7293,10,7063,100,985,20;
 				set .@rwd, 2541; //Asprika

+ 8 - 17
npc/quests/partyrelay.txt

@@ -18,7 +18,7 @@
 payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 	getpartymember(getcharid(1));
 	set .@partymembercount,$@partymembercount;
-	set .@partyleader,getpartyleader(getcharid(1),2);
+	set .@partyleader, is_party_leader();
 	if (checkweight(907,300) == 0) {
 		mes "^3355FFWait a minute! You're";
 		mes "carrying too many items";
@@ -36,7 +36,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "of your group members with you.";
 		close;
 	}
-	if ((countitem(7741) > 0) && (.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5)) {
+	if ((countitem(7741) > 0) && .@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5)) {
 		mes "[Ledrion]";
 		mes "Ah, you've brought the";
 		mes "last ticket from Rospii.";
@@ -111,7 +111,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "over to Gatan right now?";
 		close;
 	}
-	if ((countitem(7737) > 0) && (.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5)) {
+	if ((countitem(7737) > 0) && .@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5)) {
 		mes "[Ledrion]";
 		mes "Great, you've brought";
 		mes "me the eighth ticket from";
@@ -160,7 +160,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "a ticket to Gatan?";
 		close;
 	}
-	if ((countitem(7733) > 0) && (.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5)) {
+	if ((countitem(7733) > 0) && .@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5)) {
 		mes "[Ledrion]";
 		mes "I see that you've brought";
 		mes "me the fourth ticket from";
@@ -201,7 +201,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "come to me, not yet.";
 		close;
 	}
-	if ((BaseLevel > 39) && (.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5) && (party_relay == 1)) {
+	if ((BaseLevel > 39) && .@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5) && (party_relay == 1)) {
 		mes "[Ledrion]";
 		mes "As I mentioned earlier,";
 		mes "I'm challenging guild";
@@ -253,7 +253,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "once the time is right.";
 		close;
 	}
-	if ((.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5) && (party_relay > 0)) {
+	if (.@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5) && (party_relay > 0)) {
 		mes "[Ledrion]";
 		mes "As leader of your";
 		mes "Party, you should";
@@ -262,7 +262,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 		mes "of your partners.";
 		close;
 	}
-	if ((.@partyleader != getcharid(0)) && (getcharid(2) > 0)) {
+	if (.@partyleader == false && (getcharid(2) > 0)) {
 		mes "[Ledrion]";
 		mes "I'm sorry, but there's";
 		mes "nothing I can really offer";
@@ -345,7 +345,7 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 	next;
 	switch(select("Sure!:No.")) {
 	case 1:
-		if ((BaseLevel > 39) && (.@partyleader == getcharid(0)) && (getcharid(2) > 0) && (.@partymembercount > 5)) {
+		if ((BaseLevel > 39) && .@partyleader == true && (getcharid(2) > 0) && (.@partymembercount > 5)) {
 			mes "[Ledrion]";
 			mes "Great! Let's see...";
 			mes "Well, you meet all the";
@@ -384,9 +384,6 @@ payon,103,113,3	script	Ledrion#payon::RelayLedrion	109,{
 }
 
 payon,83,327,3	script	Gatan#payon::RelayGatan	86,{
-	getpartymember(getcharid(1));
-	set .@partymembercount,$@partymembercount;
-	set .@partyleader,getpartyleader(getcharid(1),2);
 	if (checkweight(907,300) == 0) {
 		mes "^3355FFWait a minute! You're";
 		mes "carrying too many items";
@@ -1819,9 +1816,6 @@ payon,83,327,3	script	Gatan#payon::RelayGatan	86,{
 }
 
 payon,204,221,3	script	Bafhail#payon::RelayBafhail	731,{
-	getpartymember(getcharid(1));
-	set .@partymembercount,$@partymembercount;
-	set .@partyleader,getpartyleader(getcharid(1),2);
 	if (checkweight(907,300) == 0) {
 		mes "^3355FFWait a minute! You're";
 		mes "carrying too many items";
@@ -2452,9 +2446,6 @@ payon,204,221,3	script	Bafhail#payon::RelayBafhail	731,{
 }
 
 payon,168,314,3	script	Lospii#payon::RelayLospii	706,{
-	getpartymember(getcharid(1));
-	set .@partymembercount,$@partymembercount;
-	set .@partyleader,getpartyleader(getcharid(1),2);
 	if (checkweight(907,300) == 0) {
 		mes "^3355FFWait a minute! You're";
 		mes "carrying too many items";

+ 2 - 2
npc/quests/quests_louyang.txt

@@ -4643,7 +4643,7 @@ lou_in02,77,37,7	script	Hermit	824,{
 				next;
 				getpartymember(getcharid(1));
 				set @partymember,$@partymembercount;
-				if (getpartyleader(getcharid(1),1) == getcharid(0) || !@partymember) {
+				if (is_party_leader() == true || !@partymember) {
 					mes "[Sun Mao]";
 					mes "Now, the most important thing for our cause is to gather more recruits and increase our numbers. Please find others who will join us in our fight.";
 					next;
@@ -4666,7 +4666,7 @@ lou_in02,77,37,7	script	Hermit	824,{
 			mes "If you're a real tourist, you do not want to get involved in our business, one way or another.";
 			close;
 		}
-	} else if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	} else if (is_party_leader() == true) {
 		if (QL_REVOL == 9) {
 			mes "[Sun Mao]";
 			mes "Once again,";

+ 3 - 3
npc/quests/seals/god_weapon_creation.txt

@@ -72,7 +72,7 @@ gld_dun01,28,85,0	script	Grunburti#1::GodDwarf	826,{
 	case 3:
 		set .@GID,getcharid(2);
 		if (($God1 < $@god_check2) || ($God2 < $@god_check2) || ($God3 < $@god_check2) || ($God4 < $@god_check2)){
-			if (($God1 >= $@god_check1) && ($God2 >= $@god_check1) && ($God3 >= $@god_check1) && ($God4 >= $@god_check1) && (strcharinfo(0) == getguildmaster(.@GID))) {
+			if (($God1 >= $@god_check1) && ($God2 >= $@god_check1) && ($God3 >= $@god_check1) && ($God4 >= $@god_check1) && (is_guild_leader() == true)) {
 				mes "[Dwarf Grunburti]";
 				mes "Hmm...";
 				mes "I'll need some things to make a weapon for you. What exactly were you interested in having?";
@@ -148,7 +148,7 @@ gld_dun01,28,85,0	script	Grunburti#1::GodDwarf	826,{
 			mes "Stop bothering me and get out of here! Go play with some monsters, you simple minded fool!";
 			close;
 		}
-		if (strcharinfo(0) != getguildmaster(.@GID)) {
+		if (is_guild_leader() == false) {
 			mes "[Dwarf Grunburti]";
 			mes "I'll only present";
 			mes "my magnificent skills";
@@ -394,7 +394,7 @@ que_god01,154,112,4	script	Grunburti#god	826,{
 		close;
 	}
 	set .@GID,getcharid(2);
-	if (strcharinfo(0) != getguildmaster(.@GID)) {
+	if (is_guild_leader() == false) {
 		mes "[Dwarf Grunburti]";
 		mes "How in the...";
 		mes "Get out of here!";

+ 1 - 1
npc/re/cities/malaya.txt

@@ -221,7 +221,7 @@ OnBingx2:
 OnTouch_:
 	set .@i, atoi(strnpcinfo(2));
 	if (.@i%4 == 2) {
-		if (getcharid(0) == getpartyleader(getcharid(1),2))
+		if (is_party_leader() == true)
 			set .@pass,1;
 	} else if (.@i%4 == 3) {
 		if (checkquest(4229,PLAYTIME) > -1 && checkquest(9223,PLAYTIME) > -1 && checkquest(12278,PLAYTIME) > -1)

+ 3 - 3
npc/re/guild/invest_main.txt

@@ -896,7 +896,7 @@ OnAgitInvest:
 		set .@guild, getcharid(2);
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 			set .@castle_name$[.@i], getcastlename(.@npc$+"g_cas0"+.@i);
-			set .@owner_id[.@i], getcastledata(.@npc$+"g_cas0"+.@i,1);
+			set .@owner_id[.@i], getcastledata(.@npc$+"g_cas0"+.@i,CD_GUILD_ID);
 			set .@owner_name$[.@i], getguildname(.@owner_id[.@i]);
 			if (.@guild == .@owner_id[.@i]) {
 				set .@menu$, .@menu$+.@castle_name$[.@i]+" ["+.@owner_name$[.@i]+"] Guild:";
@@ -1044,7 +1044,7 @@ OnAgitInvest:
 		for(set .@i,1; .@i<=5; set .@i,.@i+1) {
 			set .@map$, .@npc$+"g_cas0"+.@i;
 			set .@fund[.@i], getd("$@vfund_"+.@npc$+"0"+.@i);
-			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,1))+" Guild: "+.@fund[.@i];
+			mes getcastlename(.@map$)+" "+getguildname(getcastledata(.@map$,CD_GUILD_ID))+" Guild: "+.@fund[.@i];
 		}
 		set .@fund[0], getd("$@vfund_"+.@npc$+"_extra");
 		mes .@realm$+" normal: "+.@fund[0];
@@ -1098,7 +1098,7 @@ OnAgitInvest:
 		set .@realm$,"Valkyrie Realm";
 	}
 
-	set .@GID, getcastledata(strnpcinfo(4),1);
+	set .@GID, getcastledata(strnpcinfo(4),CD_GUILD_ID);
 	if (getcharid(2) != .@GID) {
 		mes "[Gate Manager]";
 		mes "You don't seem to be the member of guild owning this castle.";

+ 4 - 4
npc/re/guild/mission_main.txt

@@ -59,7 +59,7 @@ function calcjobexp;
 	switch(select("Conquering " + .region$[.@zoneid], "Guild Dungeon Daily Quests", "About quests", "I don't need it.")){
 		case 1: // Conquering.
 			.@gid = getcharid(2);
-			if(.@gid && getguildmaster(.@gid) == strcharinfo(0)){
+			if(.@gid && is_guild_leader() == true){
 				.@time_check1 = checkquest(.conquer_delay_questid[.@zoneid], PLAYTIME);
 				if(.@time_check1 == 0){
 					mes .@npcname$;
@@ -93,7 +93,7 @@ function calcjobexp;
 						} else {
 							.@total = 0;
 							for(.@i = 0; .@i < 5; ++.@i){
-								.@total += (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],1));
+								.@total += (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],CD_GUILD_ID));
 							}
 
 							if(!.@total){
@@ -108,7 +108,7 @@ function calcjobexp;
 								else
 									mes "Currently, the total number of fortresses that your guild has conquered";
 								for(.@i = 0; .@i < 5; ++.@i){
-									mes getcastlename(.castle$[.@i+.@zoneid*5]) + (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],1) ? ": ^4d4dffOccupied^000000" : "");
+									mes getcastlename(.castle$[.@i+.@zoneid*5]) + (.@gid == getcastledata(.castle$[.@i+.@zoneid*5],CD_GUILD_ID) ? ": ^4d4dffOccupied^000000" : "");
 								}
 								if(.@total == 5)
 									mes "Your guild has conquered " + .region$[.@zoneid] + "!";
@@ -175,7 +175,7 @@ function calcjobexp;
 					getitem 6615,1;
 				} else {
 					mes .@npcname$;
-					mes "Hmm? It seems like you haven't completed the mission yet";
+					mes "Hmm? It seems like you haven't completed the mission yet..";
 					mes "Is there any problem?";
 					next;
 					if(select("No.","Give up the quest.") == 1){

+ 46 - 46
npc/re/guild3/agit_main_te.txt

@@ -19,7 +19,7 @@ OnAgitInit3:
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	.@npc_name$ = strnpcinfo(0);
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	if (.@guild_id == 0) {
 		killmonster .@map$, .@npc_name$ +"::OnMyMobDead";
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
@@ -75,7 +75,7 @@ OnAgitInit3:
 	else {
 		requestguildinfo .@guild_id;
 		donpcevent "::OnFlagTE" + strnpcinfo(2);// Guild emblem on flags.
-		if (getcastledata(.@map$,9)  == 0)
+		if (getcastledata(.@map$,CD_ENABLED_KAFRA)  == 0)
 			disablenpc "Kafra Employee#"+ replacestr(.@map$, "cas", "");
 
 		// Load purchased Guardian in castles.
@@ -113,7 +113,7 @@ OnAgitStart3:
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	if (agitcheck3()) {
-		maprespawnguildid .@map$, getcastledata(.@map$,1),2;// warp all non-guild members
+		maprespawnguildid .@map$, getcastledata(.@map$,CD_GUILD_ID),2;// warp all non-guild members
 		gvgon3 .@map$;
 		donpcevent strnpcinfo(0)+"::OnEmpSpawn";
 		callsub S_Message,"OnCommandOn";
@@ -124,7 +124,7 @@ OnAgitEnd3:
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
 	gvgoff3 .@map$;
-	if (getcastledata(.@map$,1))
+	if (getcastledata(.@map$,CD_GUILD_ID))
 		killmonster .@map$, strnpcinfo(0) +"::OnAgitBreak";
 	callsub S_Message,"OnReset";
 	end;
@@ -133,26 +133,26 @@ OnAgitBreak:
 	.@guild_id = getcharid(2);
 	.@map$ = strnpcinfo(4);
 
-	.@economy = getcastledata(.@map$,2) - 5;// Adjust economy Invest Level for Castle
+	.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY) - 5;// Adjust economy Invest Level for Castle
 	if (.@economy < 1)
-		setcastledata .@map$, 2,1;
+		setcastledata .@map$, CD_CURRENT_ECONOMY,1;
 	else
-		setcastledata .@map$, 2,.@economy;
-	.@defense = getcastledata(.@map$,3) - 5;// Adjust Defense Invest Level for Castle
+		setcastledata .@map$, CD_CURRENT_ECONOMY,.@economy;
+	.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE) - 5;// Adjust Defense Invest Level for Castle
 	if (.@defense < 1)
-		setcastledata .@map$, 3,1;
+		setcastledata .@map$, CD_CURRENT_DEFENSE,1;
 	else
-		setcastledata .@map$, 3,.@defense;
-	setcastledata .@map$,1,.@guild_id;
+		setcastledata .@map$, CD_CURRENT_DEFENSE,.@defense;
+	setcastledata .@map$,CD_GUILD_ID,.@guild_id;
 
 	// Reset Invest information and refresh castle data
-	for ( .@i = 4; .@i <= 9; .@i++ )
+	for ( .@i = CD_INVESTED_ECONOMY; .@i < CD_ENABLED_GUARDIAN00; .@i++ )
 		setcastledata .@map$,.@i,0;
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";// spawn guardians / monsters
 
 	// Erase Guardian Database information if the new owners do not have Guardian Research.
 	if (getgdskilllv(.@guild_id,10002) == 0) {
-		for ( .@i = 10; .@i <= 17; .@i++ )
+		for ( .@i = CD_ENABLED_GUARDIAN00; .@i < CD_MAX; .@i++ )
 			setcastledata .@map$,.@i,0;
 	}
 
@@ -172,7 +172,7 @@ OnGuildBreak:
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	disablenpc "Kafra Employee#"+ .@tmp$;
-	setcastledata .@map$,1,0;
+	setcastledata .@map$,CD_GUILD_ID,0;
 	sleep 7000;
 	announce "Guild Base [" + getcastlename(.@map$) + "] has been abandoned.",bc_all;
 	donpcevent strnpcinfo(0) +"::OnAgitInit3";
@@ -180,7 +180,7 @@ OnGuildBreak:
 
 S_Message:
 	.@map$ = strnpcinfo(4);
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	
 	if (.@guild_id)
 		announce "The [" + getcastlename(.@map$) + "] castle is occupied by the [" + getguildname(.@guild_id) + "] guild.",bc_all,"0xFF0000",FW_NORMAL,10;
@@ -211,7 +211,7 @@ OnMyMobDead:
 // Guild Kafras
 //============================================================
 -	script	Kafra_Staff_TE	-1,{
-	.@guild_id = getcastledata( strnpcinfo(4),1 );
+	.@guild_id = getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	.@guildname$ = getguildname(.@guild_id);
 
 	cutin "kafra_01",2;
@@ -335,7 +335,7 @@ function GuardianData;
 
 	.@map$ = strnpcinfo(4);
 	.@npc_name$ = "[ Butler "+ strnpcinfo(1) +"]";
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	.@guildmaster$ = getguildmaster(.@guild_id);
 
 	mes .@npc_name$;
@@ -353,15 +353,15 @@ function GuardianData;
 	next;
 	switch( select( "Castle briefing", "Invest in commercial growth", "Invest in Castle Defenses", "Summon Guardian", "Hire / Fire a Kafra Employee", "Go into Master's room" ) ) {
 	case 1:
-		.@economy_today = getcastledata(.@map$,4);
-		.@defense_today = getcastledata(.@map$,5);
+		.@economy_today = getcastledata(.@map$,CD_INVESTED_ECONOMY);
+		.@defense_today = getcastledata(.@map$,CD_INVESTED_DEFENSE);
 		mes .@npc_name$;
 		mes "I will report the Castle briefing, Master.";
 		mes " ";
-		mes "^0000ffNow, the commercial growth level is "+GetCastleData(.@map$,2)+".";
+		mes "^0000ffNow, the commercial growth level is "+GetCastleData(.@map$,CD_CURRENT_ECONOMY)+".";
 		if (.@economy_today > 0)
 			mes " You invested "+.@economy_today+" times in past 1 day.";
-		mes " Now, the Castle Defense level is "+GetCastleData(.@map$,3)+".^000000";
+		mes " Now, the Castle Defense level is "+GetCastleData(.@map$,CD_CURRENT_DEFENSE)+".^000000";
 		if (.@defense_today > 0)
 			mes " ^0000ff- You invested "+.@defense_today+" times in past 1 day.^000000";
 		mes " ";
@@ -369,20 +369,20 @@ function GuardianData;
 		close;
 
 	case 2:
-		.@economy = getcastledata(.@map$,2);
+		.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY);
 		setarray .@eco_invest[0], 5,5000, 10,10000, 15,20000, 20,35000, 25,55000, 30,80000, 35,110000, 40,145000, 45,185000, 50,230000,
 			55,280000, 60,335000, 65,395000, 70,460000, 75,530000, 80,605000, 85,685000, 90,770000, 95,860000, 100,955000;
 		for ( .@i = 0; .@i < getarraysize(.@eco_invest); .@i += 2 )
 			if (.@economy <= .@eco_invest[.@i]) break;
-		callsub( S_Invest, 4, .@eco_invest[.@i+1], getcastledata(.@map$,4), "commercial growth", "quantity of goods made by the guild will increase", "future", "economist", "riches" );
+		callsub( S_Invest, 4, .@eco_invest[.@i+1], getcastledata(.@map$,CD_INVESTED_ECONOMY), "commercial growth", "quantity of goods made by the guild will increase", "future", "economist", "riches" );
 
 	case 3:
-		.@defense = getcastledata(.@map$,3);
+		.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE);
 		setarray .@def_invest[0], 5,10000, 10,20000, 15,40000, 20,70000, 25,110000, 30,160000, 35,220000, 40,290000, 45,370000, 50,460000,
 			55,560000, 60,670000, 65,790000, 70,920000, 75,1060000, 80,1210000, 85,1370000, 90,1540000, 95,1720000, 100,1910000;
 		for ( .@i = 0; .@i < getarraysize(.@def_invest); .@i += 2 )
 			if (.@defense <= .@def_invest[.@i]) break;
-		callsub( S_Invest, 5, .@def_invest[.@i+1], getcastledata(.@map$,5), "Castle Defenses", "durability of Guardians and the Emperium will increase", "coming battles", "strategist", "Defenses" );
+		callsub( S_Invest, 5, .@def_invest[.@i+1], getcastledata(.@map$,CD_INVESTED_DEFENSE), "Castle Defenses", "durability of Guardians and the Emperium will increase", "coming battles", "strategist", "Defenses" );
 
 	case 4:
 		mes .@npc_name$;
@@ -409,13 +409,13 @@ function GuardianData;
 		if (getgdskilllv(.@guild_id,10002) == 0) {
 			mes "Master, we have not the resources to Summon the Guardian. If you want to accumulate them, you have to learn the Guild skill. We failed to summon the Guardian.";
 		}
-		else if (getcastledata( .@map$,(.@s+10) ) == 1)
+		else if (getcastledata( .@map$,(.@s + CD_ENABLED_GUARDIAN00) ) == 1)
 			mes "Master, you already have summoned that Guardian. We cannot summon another.";
 		else if (Zeny <  10000)
 			mes "Well... I'm sorry but we don't have funds to summon the Guardian. We failed to summon the Guardian.";
 		else {
 			Zeny = Zeny - 10000;
-			setcastledata .@map$,(.@s+10),1;
+			setcastledata .@map$,(.@s + CD_ENABLED_GUARDIAN00),1;
 			guardian .@map$, .@x[.@s], .@y[.@s], .@name$[.@s], .@mob_id[.@s], "Kafra Employee#"+ replacestr(.@map$, "cas", "") +"::OnGuardianDied", .@s;
 			mes "We completed the summoning of the Guardian. Our defenses are now increased with it in place.";
 		}
@@ -423,7 +423,7 @@ function GuardianData;
 
 	case 5:
 		mes .@npc_name$;
-		if (getcastledata(.@map$,9) == 1) {
+		if (getcastledata(.@map$,CD_ENABLED_KAFRA) == 1) {
 			mes "We are currently hiring a Kafra Employee... Do you want to fire the Kafra Employee?";
 			next;
 			if (select( "Fire","Cancel" ) == 2) {
@@ -445,7 +445,7 @@ function GuardianData;
 			next;
 			cutin "",255;
 			disablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
-			setcastledata .@map$,9,0;
+			setcastledata .@map$,CD_ENABLED_KAFRA,0;
 			mes .@npc_name$;
 			mes "....";
 			mes "I have discharged the Kafra Employee... But... are you unsatisfied with something?";
@@ -470,7 +470,7 @@ function GuardianData;
 		}
 		Zeny = Zeny - 10000;
 		enablenpc "Kafra Employee#" + replacestr(.@map$, "cas", "");
-		setcastledata .@map$,9,1;
+		setcastledata .@map$,CD_ENABLED_KAFRA,1;
 
 		mes "We obtained a contract with the kafra Main Office, and hired a Kafra Employee.";
 		next;
@@ -532,7 +532,7 @@ S_Invest:
 	mes " ";
 	mes "Initially, you are able to invest just once but if you pay more money, you will be able to invest twice.";
 	mes " ";
-	if (getcastledata(strnpcinfo(4),2) >= 100) {
+	if (getcastledata(strnpcinfo(4),CD_CURRENT_ECONOMY) >= 100) {
 		mes "^ff0000The "+ getarg(3) +" level of our Castle is at it's highest, 100%. No more investments are needed. Just as I have expected from a great "+ getarg(6) +" like you, Master.^000000";
 		close;
 	}
@@ -689,7 +689,7 @@ OnSpawnGuardians:
 	.@tmp$ = replacestr(.@map$, "cas", "");
 	killmonster .@map$, "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied";
 	for ( .@i = 0; .@i < MAX_GUARDIANS; .@i++ ) {
-		if (getcastledata( .@map$,(.@i+10) ))
+		if (getcastledata( .@map$,(.@i + CD_ENABLED_GUARDIAN00) ))
 			guardian .@map$, .@x[.@i], .@y[.@i], .@name$[.@i], .@mob_id[.@i], "Kafra Employee#"+ .@tmp$ +"::OnGuardianDied",.@i;
 	}
 }
@@ -697,7 +697,7 @@ OnSpawnGuardians:
 // Guild Dungeon Entrances
 //============================================================
 -	script	lever2_TE	-1,{
-	.@guild_id = getcastledata( strnpcinfo(4),1 );
+	.@guild_id = getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	if (.@guild_id == 0) {
 		mes "[Ringing Voice]";
 		mes "'Those who overcome an ordeal shows a great deal of bravery... and will find their way to another ordeal.'";
@@ -768,26 +768,26 @@ OnSpawnGuardians:
 OnClock0001:// Spawn Treasure Chests based on castle economy.
 	.@map$ = strnpcinfo(4);
 	if (.@map$ == "") end;
-	.@guild_id = getcastledata(.@map$,1);
+	.@guild_id = getcastledata(.@map$,CD_GUILD_ID);
 	if (.@guild_id == 0) end;
 
-	.@economy = getcastledata(.@map$,2);
-	.@defense = getcastledata(.@map$,3);
-	.@economy_today = getcastledata(.@map$,4);
-	.@defense_today = getcastledata(.@map$,5);
+	.@economy = getcastledata(.@map$,CD_CURRENT_ECONOMY);
+	.@defense = getcastledata(.@map$,CD_CURRENT_DEFENSE);
+	.@economy_today = getcastledata(.@map$,CD_INVESTED_ECONOMY);
+	.@defense_today = getcastledata(.@map$,CD_INVESTED_DEFENSE);
 
 	killmonster .@map$, strnpcinfo(0)+"::OnTreasureDied";
 	if (.@economy_today) {
 		.@economy = .@economy + .@economy_today + (rand(2) && getgdskilllv(.@guild_id,10014));
 		.@economy = ( .@economy > 100 ) ? 100 : .@economy;
-		setcastledata .@map$,2,.@economy;
-		setcastledata .@map$,4,0;
+		setcastledata .@map$,CD_CURRENT_ECONOMY,.@economy;
+		setcastledata .@map$,CD_INVESTED_ECONOMY,0;
 	}
 	if (.@defense_today) {
 		.@defense = .@defense + .@defense_today;
 		.@defense = ( .@defense > 100 ) ? 100 : .@defense;
-		setcastledata .@map$,3,.@defense;
-		setcastledata .@map$,5,0;
+		setcastledata .@map$,CD_CURRENT_DEFENSE,.@defense;
+		setcastledata .@map$,CD_INVESTED_DEFENSE,0;
 	}
 
 	if (.@map$ == "te_aldecas1") {
@@ -1071,7 +1071,7 @@ OnTreasureDied:
 //============================================================
 function	script	F_flag_woe_TE	{
 	.@castle$ = getarg(1);
-	.@guild_id = getcastledata( .@castle$,1 );
+	.@guild_id = getcastledata( .@castle$,CD_GUILD_ID );
 	if (.@guild_id == 0) {
 		mes "[ Edict of the Divine Rune-Midgarts Kingdom ]";
 		mes " ";
@@ -1096,7 +1096,7 @@ function	script	F_flag_woe_TE	{
 				mes "Tertiary job class and users with expanded levels are not allowed to participate in Training Siege Battles.";
 				close;
 			}
-			if (getcastledata( getarg(1),1 ) == getcharid(2))
+			if (getcastledata( getarg(1),CD_GUILD_ID ) == getcharid(2))
 				warp getarg(1),getarg(2),getarg(3);
 			end;
 		}
@@ -1120,7 +1120,7 @@ function	script	F_flag_woe_TE	{
 	callfunc( "F_flag_woe_TE",0,strnpcinfo(4) );
 OnInit:
 	if (strnpcinfo(4) != "")
-		flagemblem getcastledata( strnpcinfo(4),1 );
+		flagemblem getcastledata( strnpcinfo(4),CD_GUILD_ID );
 	end;
 }
 
@@ -1128,7 +1128,7 @@ OnInit:
 	end;
 OnInit:
 	if (strnpcinfo(2) != "")
-		flagemblem getcastledata( strnpcinfo(2),1 );
+		flagemblem getcastledata( strnpcinfo(2),CD_GUILD_ID );
 	end;
 }
 

+ 2 - 2
npc/re/instances/AirshipAssault.txt

@@ -42,12 +42,12 @@ dali02,142,81,3	script	Dimensional Device#air1	PORTAL,{
 		mes "^ff0000To enter, you must create or join a party of 1 or more members.^000000";
 		close;
 	}
-	if (getcharid(0) != getpartyleader(.@party_id,2)) {
+	if (is_party_leader() == false) {
 		mes "^ff0000This Memorial Dungeon is only for 1 person. Only the party leader can enter.^000000";
 		close;
 	}
 	.@s = select( "Power Up the Device", "Use the Device", "Cancel" );
-	if (getcharid(0) != getpartyleader(.@party_id,2)) {
+	if (is_party_leader(.@party_id) == false) {
 		mes "^ff0000This Memorial Dungeon is only for 1 person. Only the party leader can enter.^000000";
 		close;
 	}

+ 3 - 3
npc/re/instances/BakonawaLake.txt

@@ -52,7 +52,7 @@ ma_scene01,174,179,4	script	Taho	541,{
 		close;
 	}
 	if (.@baku_time == -1) {
-		if (getcharid(0) == getpartyleader(.@party_id,2)) {
+		if (is_party_leader() == true) {
 			mes "[Taho]";
 			mes "Are you the leader of the Bakonawa slayers? The road is not well so we have to go down the cliff with a rope, is that OK?";
 			next;
@@ -130,7 +130,7 @@ sec_in02,26,26,4	script	Bakonawa's Rage	541,{
 	mes "[Taho]";
 	mes "Bakonawa becomes invincible at some point. When that time comes, listen to my guides carefully. Just trust me and all will be good.";
 	next;
-	if (getcharid(0) == getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		mes "[Taho]";
 		mes "Now I will make Bakonawa spring out from the lake.";
 		next;
@@ -514,7 +514,7 @@ OnTimer10000:
 	mes "[Taho]";
 	mes "HMM. We almost got him but he is one fast creature...";
 	next;
-	if (getcharid(0) == getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		mes "[Taho]";
 		mes "Are we going to try again?";
 		next;

+ 1 - 1
npc/re/instances/BangungotHospital.txt

@@ -241,7 +241,7 @@ S_NoParty:
 S_Enter:
 	.@md_name$ = "Bangungot Hospital 2F";
 	if (getarg(1,1) == true) {
-		if (getcharid(0) == getpartyleader(getcharid(1),2))
+		if (is_party_leader() == true)
 			.@menu$ = "Prepare to enter the second floor.";
 		mes "[Nurse Maenne]";
 		if (getarg(0) == false) {

+ 1 - 1
npc/re/instances/BuwayaCave.txt

@@ -35,7 +35,7 @@ ma_fild02,312,317,5	script	Guard#buwaya_cave	570,{
 		mes "team with other people.";
 		close;
 	}
-	if (getcharid(0) == getpartyleader(.@party_id,2)) {
+	if (is_party_leader() == true) {
 		mes "[Guard]";
 		mes "This place is dangerous. Please go back.";
 		mes "If you dont have any business here, please go back.";

+ 2 - 2
npc/re/instances/CentralLaboratory.txt

@@ -103,7 +103,7 @@ verus01,149,155,5	script	Civilization Explorer#p	4_LGTSCIENCE,{
 		mes "Please talk to me after composing a party of 1 or more, or after joining a party.";
 		close;
 	}
-	if (getpartyleader(.@party_id,2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Civilization Explorer]";
 		mes "Ah. You aren't the party leader. Take me to your leader! Or perhaps take your leader to me.";
 		close;
@@ -136,7 +136,7 @@ verus01,149,155,5	script	Civilization Explorer#p	4_LGTSCIENCE,{
 		mes "The entrance door is already open.";
 		close;
 	}
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Probationary researcher]";
 		mes "Please hold. I am speaking with the guide about whether or not you have been authorized.";
 		close;

+ 13 - 13
npc/re/instances/DevilTower.txt

@@ -226,7 +226,7 @@ dali02,137,121,3	script	Magic Scholar Artie#tnm	4_M_FAIRYKID6,{
 		mes "Don't take any unncessary risks, okay?";
 		close;
 	}
-	if (getpartyleader(.@party_id,2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Artie]";
 		mes "Bring the Expedition Chief.";
 		mes "Devil's Tower is not a place to visit alone.";
@@ -441,7 +441,7 @@ OnTimer26000:
 1@tnm1,57,112,5	script	Officer Heim#heim0	4_TOWER_05,{ end; }
 
 1@tnm1,56,110,3	script	Officer Heim#heim	4_TOWER_05,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Officer Heim]";
 		mes "Who brought you all here?";
 		mes "I will talk to a representative.";
@@ -454,7 +454,7 @@ OnTimer26000:
 		npctalk "Officer Heim: Back up soldiers? So why are you just standing there?";
 		next;
 		select("Right now?");
-		if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 0) {
+		if (is_party_leader() == true && 'devil_tower == 0) {
 			enablenpc instance_npcname("Healer Fama#feima");
 			'devil_tower = 1;
 		}
@@ -638,7 +638,7 @@ OnTouch:
 }
 
 1@tnm1,46,105,5	script	Lucile#tnm01	4_F_LUCILE,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		cutin "tnm_lucile01.bmp",2;
 		mes "[Lucile]";
 		mes "Who is in charge of the back-up team?";
@@ -831,7 +831,7 @@ OnMobDead:
 1@tnm1,138,96,3	script	Lucile#tnm02	4_F_LUCILE,{
 	if (isbegin_quest(7571) == 0)
 		end;
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "You wave your hand in front of her but she doesn't react.";
 		close;
 	}
@@ -857,7 +857,7 @@ OnMobDead:
 			next;
 			sleep2 750;
 			npctalk "Lucile: Please hold tight.";
-			if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 4) {
+			if (is_party_leader() == true && 'devil_tower == 4) {
 				donpcevent instance_npcname("Huey#hui02") + "::OnEnable";
 				'devil_tower = 5;
 			}
@@ -868,7 +868,7 @@ OnMobDead:
 		mes "I can hear mechanical sounds all of a sudden.";
 		specialeffect EF_LEVEL99_3;
 		// progressbar "000000",40;	// fix me: progressbar doesn't display close button on cancel
-		if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 5) {
+		if (is_party_leader() == true && 'devil_tower == 5) {
 			if (isbegin_quest(7572) == 0)
 				setquest 7572;// Lucile...?
 			'devil_tower = 6;
@@ -996,7 +996,7 @@ OnMobDead:
 1@tnm2,133,139,5	duplicate(Officer Heim#heim0)	Demon Morocc#tnm01	1916
 
 1@tnm2,144,137,3	script	Lucile#tnm03	4_F_LUCILE,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Lucile]";
 		mes "I am talking to your party leader now so please step back for a while.";
 		cutin "tnm_lucile01.bmp",2;
@@ -1012,7 +1012,7 @@ OnMobDead:
 		mes "We need to stop the demon...";
 		mes "Can you do that?";
 		npctalk "Lucile: We need to stop the demon... Can you do that?";
-		if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 7) {
+		if (is_party_leader() == true && 'devil_tower == 7) {
 			if (isbegin_quest(7573) == 0)
 				setquest 7573;// Magic Swordman Thanatos
 			'demon$ = instance_npcname("Demon Morocc#tnm01");
@@ -1464,7 +1464,7 @@ OnTimer9000:
 		close;
 	}
 	if ('devil_tower == 10) {
-		if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (is_party_leader() == false) {
 			mes "[Young Girl]";
 			mes "*weeping* The demons are so scary.";
 			close;
@@ -1493,7 +1493,7 @@ OnTimer9000:
 		mes "Please come with me through the passage behind that shelf!";
 		npctalk "Young Girl: Please come with me through the passage behind that shelf!";
 		close2;
-		if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 10) {
+		if (is_party_leader() == true && 'devil_tower == 10) {
 			enablenpc instance_npcname("#tnm3gate01");
 			enablenpc instance_npcname("#tnm3event02ect");
 			'devil_tower = 11;
@@ -1825,7 +1825,7 @@ OnTimer55500:
 1@tnm3,137,65,3	script	Loki#tnmloki02	4_M_ROKI2,{
 	if ('devil_tower != 13)
 		end;
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Loki]";
 		mes "I am talking to your boss.";
 		close;
@@ -1853,7 +1853,7 @@ OnTimer55500:
 	mes "You will be in charge of activating Mind Blaster.";
 	npctalk "Loki: You will be in charge of activating Mind Blaster.", instance_npcname("Loki#tnmloki02");
 	next;
-	if (getpartyleader(getcharid(1),2) == getcharid(0) && 'devil_tower == 13) {
+	if (is_party_leader() == true && 'devil_tower == 13) {
 		disablenpc instance_npcname("Loki#tnmloki02");
 		mes "^4d4dffLoki, Guillotine Cross of the Assassin Guild, has joined your party.";
 		mes "We have to get rid of the demonic Lord Knight by Mind Blasting him with Loki's skill.^000000";

+ 2 - 2
npc/re/instances/EclageInterior.txt

@@ -18,7 +18,7 @@ ecl_hub01,132,12,3	script	Chief of Staff#tl02	435,{
 	.@party_id = getcharid(1);
 	.@md_name$ = "Eclage Interior";
 
-	if (.@party_id == 0 || getpartyleader(.@party_id,2) != getcharid(0)){
+	if (.@party_id == 0 || is_party_leader() == false){
 		mes "-! Warning !-";
 		mes "This current quest will be held at Memorial dungeon.";
 		mes "Only the party leader will enter. Please create your party.";
@@ -62,7 +62,7 @@ ecl_hub01,130,15,0	script	It is closed shut.	844,{
 		if (select("Enter it.:Forget it.") == 1) {
 			.@party_id = getcharid(1);
 			.@md_name$ = "Eclage Interior";
-			if (.@party_id == 0 || getpartyleader(.@party_id,2) != getcharid(0)) {
+			if (.@party_id == 0 || is_party_leader() == false) {
 				mes "-! Warning !-";
 				mes "This current quest will be held at Memorial dungeon.";
 				mes "Only the party leader will enter. Please create your party.";

+ 4 - 4
npc/re/instances/FacewormsNest.txt

@@ -333,7 +333,7 @@ dali,80,60,4	script	Magic Scholar	4_M_SAGE_C,{
 	}
 	switch( checkquest(12325,PLAYTIME) ) {
 	case -1:
-		if (getcharid(0) == getpartyleader(.@party_id,2)) {
+		if (is_party_leader() == true) {
 			mes "[Magic Scholar]";
 			mes "What can I do for you?";
 			next;
@@ -440,7 +440,7 @@ dali,72,55,4	script	Interdimensional Device	CLEAR_NPC,{
 //============================================================
 1@face,110,348,6	script	Chaos#0	4_M_CHAOS,{
 	cutin "h_chaos01",2;
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Chaos]";
 		mes "I do not know what this is about, but I'm talking to your leader so please wait for a while ok?";
 		close2;
@@ -680,7 +680,7 @@ OnInstanceInit:
 //============================================================
 1@face,120,97,6	script	Chaos#1	4_M_CHAOS,{
 	cutin "h_chaos01",2;
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Chaos]";
 		mes "I do not know what this is about, but I'm talking to your leader so please wait for a while ok?";
 		close2;
@@ -896,7 +896,7 @@ OnInstanceInit:
 //============================================================
 1@face,153,113,7	script	Chaos#2	4_M_CHAOS,{
 	cutin "h_chaos01",2;
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Chaos]";
 		mes "I do not know what this is about, but I'm talking to your leader so please wait for a while ok?";
 		close2;

+ 2 - 2
npc/re/instances/GhostPalace.txt

@@ -17,7 +17,7 @@ dali02,43,129,5	script	Unpleasant Royal Guard#	4_M_SAKRAYROYAL,{
 		close;
 	}
 	.@party_id = getcharid(1);
-	if (getcharid(0) != getpartyleader(.@party_id,2) || .@party_id < 1) {
+	if (is_party_leader() == false || .@party_id < 1) {
 		mes "[Unpleasant Royal Guard]";
 		mes "I can only open the secret passage for party leaders. Please have your party leader talk to me.";
 		close;
@@ -98,7 +98,7 @@ dali02,40,134,5	script	Interdimensional Device#dk	PORTAL,{
 		close;
 	}
 	.@party_id = getcharid(1);
-	if (getcharid(0) != getpartyleader(.@party_id,2) || .@party_id < 1) {
+	if (is_party_leader() == false || .@party_id < 1) {
 		mes "[Unpleasant Royal Guard]";
 		mes "I can only open the secret passage for party leaders. Please have your party leader talk to me.";
 		close;

+ 1 - 1
npc/re/instances/HazyForest.txt

@@ -32,7 +32,7 @@ bif_fild01,158,340,5	script	Laphine Soldier#mist	447,{
 		close;
 	}
 	set .@playtime, checkquest(7211,PLAYTIME);
-	if (getcharid(0) == getpartyleader(.@party_id,2)) {
+	if (is_party_leader() == true) {
 		if (.@playtime == 0 || .@playtime == 1) {
 			mes "[Laphine Soldier]";
 			mes "...Are you sure you're not doing too much?";

+ 4 - 4
npc/re/instances/HorrorToyFactory.txt

@@ -146,7 +146,7 @@ xmas,237,303,3	script	Catherine Jet Johnson	4_F_SKULL06GIRL,{
 	}
 	switch( checkquest(12331,PLAYTIME) ) {
 	case -1:
-		if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (is_party_leader() == false) {
 			mes "[Catherine Jet Johnson]";
 			mes "Eh.. Give me a second. I am talking to the person in charge. Please wait a little bit.";
 			close;
@@ -226,7 +226,7 @@ xmas,233,305,4	script	Factory Dimension Telep	PORTAL,{
 		mes "Please wait until the transformation is finished. You cannot move to another area until you become normal.";
 		close;
 	}
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		mes "[Catherine Jet Johnson]";
 		mes "Eh.. Give me a second. I am talking to the person in charge. Please wait.";
 		close;
@@ -367,7 +367,7 @@ OnTimer1000:
 }
 
 1@xm_d,71,129,3	script	#fac1bs	4_M_COOKIE,{
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		.@mob_id_transform = getstatus(SC_MONSTER_TRANSFORM,1);
 		mes "[Coordinator]";
 		if (.@mob_id_transform == 1246) {
@@ -565,7 +565,7 @@ OnMyMobDead:
 
 
 1@xm_d,185,100,6	script	Catherine Jet Johnson#2	4_F_SKULL06GIRL,{
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		mes "[Catherine Jet Johnson]";
 		mes "Lucky you got here safely.";
 		next;

+ 2 - 2
npc/re/instances/IsleOfBios.txt

@@ -48,7 +48,7 @@ moro_cav,50,64,5	script	Yellow Seed#bios	CLEAR_NPC,{
 			erasequest 15008;// Memorial Dungeon: Isle of Bios
 		break;
 	}
-	if (getpartyleader(.@party_id,2) == getcharid(0))
+	if (is_party_leader() == true)
 		.@create$ = "Create Memorial dungeon.";
 	switch( select( .@create$, "Enter Isle of Bios.", "Cancel." ) ) {
 	case 1:
@@ -61,7 +61,7 @@ moro_cav,50,64,5	script	Yellow Seed#bios	CLEAR_NPC,{
 		case IE_NOMEMBER:
 		case IE_NOINSTANCE:
 		case IE_OTHER:
-			if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+			if (is_party_leader(.@party_id) == false) {
 				mes "^ff0000Please note that This Memorial Dungeon cannot be accessed for 23 hours after your last visit.^000000";
 				next;
 			}

+ 3 - 3
npc/re/instances/LastRoom.txt

@@ -29,7 +29,7 @@ un_myst,163,38,5	script	Mark	4_M_BLUEMAN,{
 	switch( checkquest(11379,PLAYTIME) ) {
 	case -1:
 		.@party_id = getcharid(1);
-		if (getpartyleader(.@party_id,2) == getcharid(0))
+		if (is_party_leader() == true)
 			.@string$ = "Open door.";
 		.@s = select( .@string$, "Go in.", "Quit." );
 		if (.@s == 1) {
@@ -114,7 +114,7 @@ un_myst,163,38,5	script	Mark	4_M_BLUEMAN,{
 		mes "[Verity]";
 		mes "Umph...I suddenly have a feeling that's not good.";
 		cutin "EP15_2_brt_6.bmp",2;
-		if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (is_party_leader() == false) {
 			mes "I wish to talk with the leader.";
 			close3;
 		}
@@ -238,7 +238,7 @@ OnMyMobDead2:
 	mes "[Tamarin]";
 	mes "Huff huff... Verity suddenly huff huff couldn't even stand straight before huff huff...";
 	cutin "ep143_tahuk.bmp",2;
-	if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+	if (is_party_leader() == false) {
 		next;
 		mes "[Tamarin]";
 		mes "I don't think this is a problem we can solve by talking amongst ourselves.";

+ 4 - 4
npc/re/instances/MalangdoCulvert.txt

@@ -392,7 +392,7 @@ mal_in01,160,34,4	script	Missing, the Cleaner	545,{
 	}
 	set .@playtime, checkquest(12254,PLAYTIME);
 	if (.@playtime == -1) {
-		if (getcharid(0) == getpartyleader(.@party_id,2)) {
+		if (is_party_leader() == true) {
 			mes "[Missing, the Cleaner]";
 			mes "Ummm? What's up? Tell me the password if you're the leader!";
 			next;
@@ -455,7 +455,7 @@ L_Enter:
 // Instance: Common Scripts
 //============================================================
 1@pump,63,100,4	script	Missing, the Cleaner#0	545,{
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Missing, the Cleaner]";
 		mes "I am trying to have a conversation with your leader now. Please don't disturb and wait!";
 		close;
@@ -546,7 +546,7 @@ function	script	F_mal_missing	{
 	mes "[Missing, the Cleaner]";
 	mes "I don't care if you get help from your friends or not. I want you to clean up all culverts! Don't forget! I will watch you and give you instructions. Just do what I said!!";
 	next;
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Missing, the Cleaner]";
 		mes "Once your leader finishes preparing, it will begin, so get your hearts ready for it!!";
 		close;
@@ -575,7 +575,7 @@ function	script	F_mal_missing	{
 	mes "[Missing, the Cleaner]";
 	mes "I see seaweed everywhere because you're wiggling! All the culverts will be blocked with seaweed!";
 	next;
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Missing, the Cleaner]";
 		mes "Once your leader finishes preparing, settlement will be decided so get your hearts ready for it!!";
 		close;

+ 2 - 2
npc/re/instances/MorseCave.txt

@@ -75,7 +75,7 @@ moro_cav,61,69,3	script	Senior Tracker#a1	4_M_JOB_ASSASSIN,{
 		mes "and become the hero";
 		mes "who saved the world from evil?";
 		next;
-		if (getcharid(1) < 1 || getcharid(0) != getpartyleader(getcharid(1),2)) {
+		if (getcharid(1) < 1 || is_party_leader() == false) {
 			mes "[Senior Tracker]";
 			mes "If you're interested in my proposition,";
 			mes "let me talk to your party leader.";
@@ -136,7 +136,7 @@ moro_cav,61,69,3	script	Senior Tracker#a1	4_M_JOB_ASSASSIN,{
 	mes "as many comrades as you can find.";
 	mes "Are you ready to enter the Red Flower";
 	mes "where Morroc is believed to be hiding?";
-	if (getcharid(1) > 0 && getcharid(0) == getpartyleader(getcharid(1),2)) {
+	if (getcharid(1) > 0 && is_party_leader() == true) {
 		next;
 		if (select( "No.", "Yes." ) == 1) {
 			mes "[Senior Tracker]";

+ 1 - 1
npc/re/instances/OctopusCave.txt

@@ -28,7 +28,7 @@ mal_dun01,151,235,5	script	Starfish	551,{
 		mes "Make a party, and come back later.";
 		close;
 	}
-	if (getcharid(0) != getpartyleader(.@party_id,2)) {
+	if (is_party_leader() == false) {
 		mes "[Starfish]";
 		mes "Where is your leader, hehe.";
 		mes "I don't talk to some random people.";

+ 5 - 5
npc/re/instances/OldGlastHeim.txt

@@ -88,7 +88,7 @@ glast_01,204,273,5	script	Hugin	4_M_SAGE_C,{
 			mes "Why don't you make a party with more than 1 person and talk to me again?";
 			close;
 		}
-		if (getcharid(0) == getpartyleader(.@party_id,2))
+		if (is_party_leader() == true)
 			.@menu$ = "Generate Time Gap";
 		else {
 			mes "[Hugin]";
@@ -174,7 +174,7 @@ glast_01,204,273,5	script	Hugin	4_M_SAGE_C,{
 // Floor 1
 //============================================================
 1@gl_k,149,41,5	script	Varmundt#0	4_M_BARMUND,{
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Varmundt]";
 		mes "Where's your leader? I need his help.";
 		cutin "gl_barmund2",2;
@@ -312,7 +312,7 @@ glast_01,204,273,5	script	Hugin	4_M_SAGE_C,{
 1@gl_k,154,54,3	duplicate(Khalitzburg Knightage#21)	Khalitzburg Knightage#22	4_F_KHALITZBURG
 
 1@gl_k,149,100,6	script	Heinrich#1	4_M_HEINRICH,{
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Heinrich]";
 		mes "Where is your leader? I must talk to him.";
 		cutin "gl_heinrich2",2;
@@ -642,7 +642,7 @@ OnMyMobDead:
 }
 
 1@gl_k,17,51,3	script	Altar boy Domun#1	4_M_KID1,{
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Altar boy Domun]";
 		mes "Save me, save me, please...";
 		close;
@@ -720,7 +720,7 @@ OnMyMobDead:
 }
 
 1@gl_k,291,145,3	script	Holgren the Destroyer#1	4_F_JOB_BLACKSMITH,{
-	if (getcharid(0) != getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == false) {
 		mes "[Holgren the Destroyer]";
 		mes "You human?";
 		close;

+ 6 - 6
npc/re/instances/RoomOfConsciousness.txt

@@ -8,7 +8,7 @@
 //============================================================
 
 1@mir,103,40,3	script	Fenrir#1mir	4_F_FENRIR,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	cutin "fenrir_a",2;
 	mes "[Fenrir]";
@@ -79,7 +79,7 @@ OnInstanceInit:
 }
 
 1@mir,100,94,7	script	Iris#2mir	4_F_IRIS,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	mes "[Iris]";
 	mes "This...this must be...";
@@ -200,7 +200,7 @@ OnMobDead2:
 }
 
 1@mir,103,85,1	script	Iris#3mir	4_F_IRIS,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	mes "[Bijou]";
 	mes "~Chuckles~ I think you're not that bad for a human.";
@@ -392,7 +392,7 @@ OnStop:
 }
 
 1@mir,100,90,7	script	Iris#4mir	4_F_IRIS,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	mes "[Iris]";
 	mes "Was that it...? Has it gone now?";
@@ -461,7 +461,7 @@ OnMobDead:
 }
 
 1@mir,103,90,1	script	Fenrir#5mir	4_F_FENRIR,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	mes "[Fenrir]";
 	mes "~Groans~ I can't believe nothing seems to work!";
@@ -727,7 +727,7 @@ OnStop:
 }
 
 1@mir,100,95,5	script	Iris#6mir	4_F_IRIS,{
-	if (getpartyleader(getcharid(1),2) != getcharid(0))	// it shouldn't happen
+	if (is_party_leader() == false)	// it shouldn't happen
 		end;
 	mes "[Iris]";
 	mes "~Grunts~";

+ 6 - 6
npc/re/instances/SaraMemory.txt

@@ -179,7 +179,7 @@ dali,139,118,4	script	Dimensional Device#sara	10007,{
 			close;
 		}
 
-		if (getcharid(0) == getpartyleader(.@party_id,2))
+		if (is_party_leader() == true)
 			set .@menu$, "Boot up the dimensional device.:Use the dimensional device.:Cancel.";
 		else
 			set .@menu$, ":Use the dimensional device.:Cancel.";
@@ -228,7 +228,7 @@ dali,139,118,4	script	Dimensional Device#sara	10007,{
 }
 
 1@sara,260,156,6	script	A Girl#01	668,{
-	if(getcharid(0)==getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		unittalk getcharid(3),"Where am I?";
 		mes "["+strcharinfo(0)+"]";
 		mes "Where am I?";
@@ -419,7 +419,7 @@ OnEnable:
 }
 
 1@sara,107,325,6	script	Sara Irene#01	668,{
-	if(getcharid(0)==getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		cutin "sara_9sara1",2;
 		npctalk "Oh! Hello again! I remember you, what's up?";
 		mes "[Sara Irene]";
@@ -546,7 +546,7 @@ OnEnable:
 }
 
 1@sara,152,233,6	script	Sara Irene#02	668,{
-	if(getcharid(0)==getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		cutin "sara_9sara2",2;
 		npctalk "Mommy!";
 		mes "[Sara Irene]";
@@ -617,7 +617,7 @@ OnEnable:
 }
 
 1@sara,156,236,4	script	Doyen Irene#04	684,{
-	if(getcharid(0)==getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		cutin "sara_elder_irine4",2;
 		npctalk "You... were too strong for me.";
 		mes "[Doyen Irene]";
@@ -697,7 +697,7 @@ OnEnable:
 }
 
 1@sara,39,142,4	script	Sara Irene#03	668,{
-	if(getcharid(0)==getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		mapannounce instance_mapname("1@sara"), "As you are about to call out to Sara, a sudden blow knocks you down from behind.",bc_area,"0xffffff";
 		mes "^FF0000As you are about to call out to Sara, a sudden blow knocks you down from behind.^000000";
 		next;

+ 6 - 6
npc/re/instances/SarahAndFenrir.txt

@@ -28,7 +28,7 @@ dali02,97,142,3	script	Professor Bernhard#a1	4_LGTSCIENCE,{
 			mes "That is why..I need you..";
 			next;
 			mes "[Professor Bernhard]";
-			if (getpartyleader(getcharid(1),2) != getcharid(0)) {
+			if (is_party_leader() == false) {
 				mes "A longing for accomplishing a powerful weapon as a genuine professor!";
 				mes "In order to accomplish that, we need shards of Gigantes that once appeared in the past battle of Fenrir and Sarah.";
 				next;
@@ -124,7 +124,7 @@ dali02,97,142,3	script	Professor Bernhard#a1	4_LGTSCIENCE,{
 		mes "There, all the preparations are finished.";
 		mes "Can you go back in time again and bring me the shards of Gigantes?";
 		mes "I will make sure to compensate you sufficiently.";
-		if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+		if (is_party_leader() == true) {
 			next;
 			if (select( "No", "Yes" ) == 1) {
 				mes "[Professor Bernhard]";
@@ -664,7 +664,7 @@ OnTimer15500:
 1@glast,199,237,0	script	#glast_move_03	WARPNPC,2,2,{
 	end;
 OnTouch:
-	if (getcharid(0) == getpartyleader(getcharid(1),2))
+	if (is_party_leader() == true)
 		warpparty 'map_glast$,197,263, getcharid(1), 'map_glast$,1,1;
 	end;
 }
@@ -673,7 +673,7 @@ OnTouch:
 1@glast,199,294,0	script	#glast_move_03a	WARPNPC,3,3,{
 	end;
 OnTouch:
-	if (getcharid(0) == getpartyleader(getcharid(1),2))
+	if (is_party_leader() == true)
 		warpparty 'map_glast$,188,334, getcharid(1), 'map_glast$,1,1;
 	end;
 }
@@ -690,7 +690,7 @@ OnTouch:
 1@glast,351,269,0	script	#glast_move_04	WARPNPC,3,3,{
 	end;
 OnTouch:
-	if (getcharid(0) == getpartyleader(getcharid(1),2)) {
+	if (is_party_leader() == true) {
 		donpcevent instance_npcname("#sarah_wrath") + "::OnStop";
 		warpparty 'map_glast$,349,282, getcharid(1), 'map_glast$,1,1;
 	}
@@ -750,7 +750,7 @@ OnTouch:
 1@glast,47,270,0	script	#glast_event_7	HIDDEN_WARP_NPC,5,5,{
 	end;
 OnTouch:
-	if (getcharid(0) != getpartyleader(getcharid(1),2))
+	if (is_party_leader() == false)
 		npctalk "Fenrith Fenrir: I would like your party leader to come and help me!", 'fenrir_3$;
 	else {
 		mes "";

+ 5 - 5
npc/re/instances/WolfchevLaboratory.txt

@@ -818,7 +818,7 @@ lhz_dun04,151,276,3	script	Researcher#memo	4_LGTSCIENCE,{
 						}
 					}
 				}
-				if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+				if (is_party_leader() == true) {
 					if (instance_create("Wolfchev's Laboratory") < 0) {
 						mes "[Wolfchev]";
 						mes "Hmm.. Lab entering system is a bit weird. Would wait for me to check the system?";
@@ -990,7 +990,7 @@ OnMyMobDead:
 1@lhz,39,168,0	script	Manual Sheet#1_1	CLEAR_NPC,{
 	mes "There are valve manual sheets littered on the floor.";
 	next;
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		mes "You the party leader, started to read the manual.";
 		next;
 		mes "[Emergency Access Valve Manual]";
@@ -1068,7 +1068,7 @@ OnEnable:
 1@lhz,41,172,0	script	Valve#1_2	CLEAR_NPC,{
 	.@open_portal = 0;
 	mes "This is the left valve for the emergency access.";
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		next;
 		mes "To which direction do you wish to turn?";
 		next;
@@ -1131,7 +1131,7 @@ OnEnable:
 1@lhz,52,172,0	script	Valve#1_3	CLEAR_NPC,{
 	.@open_portal = 0;
 	mes "This is the left valve for the emergency access.";
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		next;
 		mes "To which direction do you wish to turn?";
 		next;
@@ -1526,7 +1526,7 @@ OnMyMobDead:
 // The Lab No.2 Valves
 //============================================================
 -	script	bio4FLab2Valve	-1,{
-	if (getpartyleader(getcharid(1),2) == getcharid(0)) {
+	if (is_party_leader() == true) {
 		progressbar "0xffff00", 20;
 		stopnpctimer;
 		donpcevent instance_npcname("Lab2#2_2")+"::OnDisableValve1";

+ 9 - 9
npc/re/quests/quests_16_1.txt

@@ -1572,7 +1572,7 @@ prt_lib,76,80,3	script	Lindt the Librarian#ep1	1_M_01,{
 prt_lib,91,85,3	script	Mage Nillem#ep16_warp	4_M_JOB_WIZARD,{
 	switch( banquet_main_quest ) {
 	case 8:
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {// solo instance
+		if (getcharid(1) == 0 || is_party_leader() == false) {// solo instance
 			mes "^4d4dffIt is an event which proceeds as a memorial.";
 			mes "Only the party leader can proceed with a memorial event. Try again after forming a party.^000000";
 			close;
@@ -1760,7 +1760,7 @@ prt_lib,91,85,3	script	Mage Nillem#ep16_warp	4_M_JOB_WIZARD,{
 
 prt_lib,88,90,1	script	Room of Consciousness#e	HIDDEN_WARP_NPC,{
 	if (banquet_main_quest == 8) {
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (getcharid(1) == 0 || is_party_leader() == false) {
 			mes "^4d4dffOnly the party leader can enter MD [Ritual of Blessing].^000000";
 			close;
 		}
@@ -1771,7 +1771,7 @@ prt_lib,88,90,1	script	Room of Consciousness#e	HIDDEN_WARP_NPC,{
 			mes "Hum... This gate is only activated temporarily so that it doesn't last long.";
 			close;
 		}
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (getcharid(1) == 0 || is_party_leader() == false) {
 			mes "^4d4dffOnly the party leader can enter MD [Ritual of Blessing].^000000";
 			close;
 		}
@@ -2257,7 +2257,7 @@ prt_lib_q,91,85,3	script	Nillem#ep16_lib_q	4_M_JOB_WIZARD,{
 		close;
 	}
 	if (banquet_main_quest == 21) {
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (getcharid(1) == 0 || is_party_leader() == false) {
 			mes "^4d4dffIt is an event which proceeds as a memorial.";
 			mes "Only the party leader can proceed with a memorial event. Try again after forming a party.^000000";
 			close;
@@ -2449,7 +2449,7 @@ prt_lib_q,91,85,3	script	Nillem#ep16_lib_q	4_M_JOB_WIZARD,{
 				close;
 			case 0:
 			case 1:
-				if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+				if (getcharid(1) == 0 || is_party_leader() == false) {
 					mes "^4d4dffIt is an event which proceeds as a memorial.";
 					mes "Only the party leader can proceed with a memorial event. Try again after forming a party.^000000";
 					close;
@@ -2518,14 +2518,14 @@ prt_lib_q,91,85,3	script	Nillem#ep16_lib_q	4_M_JOB_WIZARD,{
 
 prt_lib_q,88,90,1	script	Swaying Space#evt_gate0	HIDDEN_WARP_NPC,{
 	if (banquet_main_quest == 21) {
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {// solo instance
+		if (getcharid(1) == 0 || is_party_leader() == false) {// solo instance
 			mes "^4d4dffOnly the party leader can enter MD [Room of Consciousness].^000000";
 			close;
 		}
 		mes "You can move to the place where the piece of Imir Heart was in the past.";
 		next;
 		if (select( "Enter.", "Do not enter." ) == 1) {
-			if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+			if (getcharid(1) == 0 || is_party_leader() == false) {
 				mes "^4d4dffOnly the party leader can enter MD [Room of Consciousness].^000000";
 				close;
 			}
@@ -2557,7 +2557,7 @@ prt_lib_q,88,90,1	script	Swaying Space#evt_gate0	HIDDEN_WARP_NPC,{
 		close;
 	}
 	if (banquet_main_quest == 26) {
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {// solo instance
+		if (getcharid(1) == 0 || is_party_leader() == false) {// solo instance
 			mes "^4d4dffOnly the party leader can enter MD [Room of Consciousness].^000000";
 			close;
 		}
@@ -2569,7 +2569,7 @@ prt_lib_q,88,90,1	script	Swaying Space#evt_gate0	HIDDEN_WARP_NPC,{
 			mes "Such thing is possible since I am a genius!";
 			close;
 		}
-		if (getcharid(1) == 0 || getpartyleader(getcharid(1),2) != getcharid(0)) {
+		if (getcharid(1) == 0 || is_party_leader() == false) {
 			mes "^4d4dffOnly the party leader can enter MD [Room of Consciousness].^000000";
 			close;
 		}

+ 1 - 1
npc/re/quests/woe_te/te_goditem_alde1.txt

@@ -33,7 +33,7 @@ te_aldecas1,226,34,3	script	Blacksmith Cano#tegod01	4_M_RACHMAN1,{
 		mes "Don't worry about me.";
 		close;
 	}
-	if (getguildmaster(.@guild_id) != strcharinfo(0)) {
+	if (is_guild_leader() == false) {
 		mes "I feel so grateful all the time about you letting me stay here.";
 		mes "It's nothing special... but if you want, I'll make you tools that could be of use.";
 		next;

+ 1 - 1
npc/re/quests/woe_te/te_goditem_prt01.txt

@@ -33,7 +33,7 @@ te_prtcas01,204,204,3	script	Blacksmith Kai#tegod01	4_M_RACHMAN2,{
 		mes "Don't worry about me.";
 		close;
 	}
-	if (getguildmaster(.@guild_id) != strcharinfo(0)) {
+	if (is_guild_leader() == false) {
 		mes "I feel so grateful all the time about you letting me stay here.";
 		mes "It's nothing special... but if you want, I'll make you tools that could be of use.";
 		next;

+ 14 - 1
sql-files/mob_db_re.sql

@@ -3714,7 +3714,20 @@ REPLACE INTO `mob_db_re` VALUES (3788,'RR_CRAMP','Rr Cramp','Brown Rat',101,988,
 #20517,G_BONE_ACIDUS
 #20518,E_MD_LUDE
 #20519,E_MD_JACK_GAINT
-
+#20520,ILL_BAPHOMET
+#20521,ILL_ANDREA
+#20522,ILL_ANES
+#20523,ILL_SILVANO
+#20524,ILL_CECILIA
+#20525,ILL_BAPHOMET_J
+#20526,ILL_SIDE_WINDER
+#20527,ILL_HUNTER_FLY
+#20528,ILL_MANTIS
+#20529,ILL_GHOSTRING
+#20530,ILL_KILLER_MANTIS
+#20531,ILL_POPORING
+#20532,ILL_STEM_WORM
+#20533,G_ILL_BAPHOMET_J
 #20534,G_REGINLEIF
 #20535,G_INGRID
 

+ 22 - 22
src/char/int_guild.cpp

@@ -603,17 +603,17 @@ struct guild_castle* inter_guildcastle_fromsql(int castle_id)
 	gc->castle_id = castle_id;
 
 	if (SQL_SUCCESS == Sql_NextRow(sql_handle)) {
-		Sql_GetData(sql_handle, 1, &data, NULL); gc->guild_id =  atoi(data);
-		Sql_GetData(sql_handle, 2, &data, NULL); gc->economy = atoi(data);
-		Sql_GetData(sql_handle, 3, &data, NULL); gc->defense = atoi(data);
-		Sql_GetData(sql_handle, 4, &data, NULL); gc->triggerE = atoi(data);
-		Sql_GetData(sql_handle, 5, &data, NULL); gc->triggerD = atoi(data);
-		Sql_GetData(sql_handle, 6, &data, NULL); gc->nextTime = atoi(data);
-		Sql_GetData(sql_handle, 7, &data, NULL); gc->payTime = atoi(data);
-		Sql_GetData(sql_handle, 8, &data, NULL); gc->createTime = atoi(data);
-		Sql_GetData(sql_handle, 9, &data, NULL); gc->visibleC = atoi(data);
-		for (i = 10; i < 10+MAX_GUARDIANS; i++) {
-			Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i-10].visible = atoi(data);
+		Sql_GetData(sql_handle, CD_GUILD_ID, &data, NULL); gc->guild_id =  atoi(data);
+		Sql_GetData(sql_handle, CD_CURRENT_ECONOMY, &data, NULL); gc->economy = atoi(data);
+		Sql_GetData(sql_handle, CD_CURRENT_DEFENSE, &data, NULL); gc->defense = atoi(data);
+		Sql_GetData(sql_handle, CD_INVESTED_ECONOMY, &data, NULL); gc->triggerE = atoi(data);
+		Sql_GetData(sql_handle, CD_INVESTED_DEFENSE, &data, NULL); gc->triggerD = atoi(data);
+		Sql_GetData(sql_handle, CD_NEXT_TIME, &data, NULL); gc->nextTime = atoi(data);
+		Sql_GetData(sql_handle, CD_PAY_TIME, &data, NULL); gc->payTime = atoi(data);
+		Sql_GetData(sql_handle, CD_CREATE_TIME, &data, NULL); gc->createTime = atoi(data);
+		Sql_GetData(sql_handle, CD_ENABLED_KAFRA, &data, NULL); gc->visibleC = atoi(data);
+		for (i = CD_ENABLED_GUARDIAN00; i < CD_MAX; i++) {
+			Sql_GetData(sql_handle, i, &data, NULL); gc->guardian[i - CD_ENABLED_GUARDIAN00].visible = atoi(data);
 		}
 	}
 	Sql_FreeResult(sql_handle);
@@ -1805,7 +1805,7 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
 	}
 
 	switch (index) {
-		case 1:
+		case CD_GUILD_ID:
 			if (charserv_config.log_inter && gc->guild_id != value) {
 				int gid = (value) ? value : gc->guild_id;
 				struct guild *g = (struct guild*)idb_get(guild_db_, gid);
@@ -1814,17 +1814,17 @@ int mapif_parse_GuildCastleDataSave(int fd, int castle_id, int index, int value)
 			}
 			gc->guild_id = value;
 			break;
-		case 2: gc->economy = value; break;
-		case 3: gc->defense = value; break;
-		case 4: gc->triggerE = value; break;
-		case 5: gc->triggerD = value; break;
-		case 6: gc->nextTime = value; break;
-		case 7: gc->payTime = value; break;
-		case 8: gc->createTime = value; break;
-		case 9: gc->visibleC = value; break;
+		case CD_CURRENT_ECONOMY: gc->economy = value; break;
+		case CD_CURRENT_DEFENSE: gc->defense = value; break;
+		case CD_INVESTED_ECONOMY: gc->triggerE = value; break;
+		case CD_INVESTED_DEFENSE: gc->triggerD = value; break;
+		case CD_NEXT_TIME: gc->nextTime = value; break;
+		case CD_PAY_TIME: gc->payTime = value; break;
+		case CD_CREATE_TIME: gc->createTime = value; break;
+		case CD_ENABLED_KAFRA: gc->visibleC = value; break;
 		default:
-			if (index > 9 && index <= 9+MAX_GUARDIANS) {
-				gc->guardian[index-10].visible = value;
+			if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+				gc->guardian[index - CD_ENABLED_GUARDIAN00].visible = value;
 				break;
 			}
 			ShowError("mapif_parse_GuildCastleDataSave: not found index=%d\n", index);

+ 17 - 0
src/common/mmo.hpp

@@ -701,6 +701,23 @@ struct guild_castle {
 	int temp_guardians_max;
 };
 
+/// Enum for guild castle data script commands
+enum e_castle_data : uint8 {
+	CD_NONE = 0,
+	CD_GUILD_ID, ///< Guild ID
+	CD_CURRENT_ECONOMY, ///< Castle Economy score
+	CD_CURRENT_DEFENSE, ///< Castle Defense score
+	CD_INVESTED_ECONOMY, ///< Number of times the economy was invested in today
+	CD_INVESTED_DEFENSE, ///< Number of times the defense was invested in today
+	CD_NEXT_TIME, ///< unused
+	CD_PAY_TIME, ///< unused
+	CD_CREATE_TIME, ///< unused
+	CD_ENABLED_KAFRA, ///< Is 1 if a Kafra was hired for this castle, 0 otherwise
+	CD_ENABLED_GUARDIAN00, ///< Is 1 if the 1st guardian is present (Soldier Guardian)
+	// The others in between are not needed in src, but are exported for the script engine
+	CD_MAX = CD_ENABLED_GUARDIAN00 + MAX_GUARDIANS
+};
+
 /// Guild Permissions
 enum e_guild_permission {
 	GUILD_PERM_INVITE	= 0x001,

+ 111 - 74
src/login/login.cpp

@@ -7,10 +7,10 @@
 #include <stdlib.h>
 #include <string.h>
 #include <string>
+#include <unordered_map>
 
 #include "../common/cli.hpp"
 #include "../common/core.hpp"
-#include "../common/db.hpp"
 #include "../common/malloc.hpp"
 #include "../common/md5calc.hpp"
 #include "../common/mmo.hpp"
@@ -20,6 +20,7 @@
 #include "../common/socket.hpp" //ip2str
 #include "../common/strlib.hpp"
 #include "../common/timer.hpp"
+#include "../common/utilities.hpp"
 #include "../common/utils.hpp"
 #include "../config/core.hpp"
 
@@ -30,14 +31,16 @@
 #include "logincnslif.hpp"
 #include "loginlog.hpp"
 
+using namespace rathena;
+
 #define LOGIN_MAX_MSG 30				/// Max number predefined in msg_conf
 static char* msg_table[LOGIN_MAX_MSG];	/// Login Server messages_conf
 
 //definition of exported var declared in .h
 struct mmo_char_server ch_server[MAX_SERVERS];	/// char server data
 struct Login_Config login_config;				/// Configuration of login-serv
-DBMap* online_db;
-DBMap* auth_db;
+std::unordered_map<uint32,struct online_login_data> online_db;
+std::unordered_map<uint32,struct auth_node> auth_db;
 
 // account database
 AccountDB* accounts = NULL;
@@ -65,20 +68,8 @@ int parse_console(const char* buf){
 	return cnslif_parse(buf);
 }
 
-/**
- * Sub function to create an online_login_data and save it to db.
- * @param key: Key of the database entry
- * @param ap: args
- * @return : Data identified by the key to be put in the database
- * @see DBCreateData
- */
-DBData login_create_online_user(DBKey key, va_list args) {
-	struct online_login_data* p;
-	CREATE(p, struct online_login_data, 1);
-	p->account_id = key.i;
-	p->char_server = -1;
-	p->waiting_disconnect = INVALID_TIMER;
-	return db_ptr2data(p);
+struct online_login_data* login_get_online_user( uint32 account_id ){
+	return util::umap_find( online_db, account_id );
 }
 
 /**
@@ -89,13 +80,24 @@ DBData login_create_online_user(DBKey key, va_list args) {
  * @return the new online_login_data for that user
  */
 struct online_login_data* login_add_online_user(int char_server, uint32 account_id){
-	struct online_login_data* p;
-	p = (struct online_login_data*)idb_ensure(online_db, account_id, login_create_online_user);
-	p->char_server = char_server;
-	if( p->waiting_disconnect != INVALID_TIMER ) {
-		delete_timer(p->waiting_disconnect, login_waiting_disconnect_timer);
+	struct online_login_data* p = login_get_online_user( account_id );
+
+	if( p == nullptr ){
+		// Allocate the player
+		p = &online_db[account_id];
+
+		p->account_id = account_id;
+		p->char_server = char_server;
 		p->waiting_disconnect = INVALID_TIMER;
+	}else{
+		p->char_server = char_server;
+
+		if( p->waiting_disconnect != INVALID_TIMER ){
+			delete_timer( p->waiting_disconnect, login_waiting_disconnect_timer );
+			p->waiting_disconnect = INVALID_TIMER;
+		}
 	}
+
 	return p;
 }
 
@@ -106,14 +108,38 @@ struct online_login_data* login_add_online_user(int char_server, uint32 account_
  * @param account_id : aid to remove from db
  */
 void login_remove_online_user(uint32 account_id) {
-	struct online_login_data* p;
-	p = (struct online_login_data*)idb_get(online_db, account_id);
-	if( p == NULL )
+	struct online_login_data* p = login_get_online_user( account_id );
+
+	if( p == nullptr ){
 		return;
-	if( p->waiting_disconnect != INVALID_TIMER )
-		delete_timer(p->waiting_disconnect, login_waiting_disconnect_timer);
+	}
+
+	if( p->waiting_disconnect != INVALID_TIMER ){
+		delete_timer( p->waiting_disconnect, login_waiting_disconnect_timer );
+	}
+
+	online_db.erase( account_id );
+}
+
+struct auth_node* login_get_auth_node( uint32 account_id ){
+	return util::umap_find( auth_db, account_id );
+}
+
+struct auth_node* login_add_auth_node( struct login_session_data* sd, uint32 ip ){
+	struct auth_node* node = &auth_db[sd->account_id];
+
+	node->account_id = sd->account_id;
+	node->login_id1 = sd->login_id1;
+	node->login_id2 = sd->login_id2;
+	node->sex = sd->sex;
+	node->ip = ip;
+	node->clienttype = sd->clienttype;
+
+	return node;
+}
 
-	idb_remove(online_db, account_id);
+void login_remove_auth_node( uint32 account_id ){
+	auth_db.erase( account_id );
 }
 
 /**
@@ -128,51 +154,31 @@ void login_remove_online_user(uint32 account_id) {
  * @return :0
  */
 TIMER_FUNC(login_waiting_disconnect_timer){
-	struct online_login_data* p = (struct online_login_data*)idb_get(online_db, id);
-	if( p != NULL && p->waiting_disconnect == tid && p->account_id == id ){
+	struct online_login_data* p = login_get_online_user( id );
+
+	if( p != nullptr && p->waiting_disconnect == tid && p->account_id == id ){
 		p->waiting_disconnect = INVALID_TIMER;
 		login_remove_online_user(id);
-		idb_remove(auth_db, id);
+		login_remove_auth_node(id);
 	}
+
 	return 0;
 }
 
-/**
- * Sub function to apply on online_db.
- * Mark a character as offline.
- * @param data: 1 entry in the db
- * @param ap: args
- * @return : Value to be added up by the function that is applying this
- * @see DBApply
- */
-int login_online_db_setoffline(DBKey key, DBData *data, va_list ap) {
-	struct online_login_data* p = (struct online_login_data*)db_data2ptr(data);
-	int server = va_arg(ap, int);
-	if( server == -1 ) {
-		p->char_server = -1;
-		if( p->waiting_disconnect != INVALID_TIMER ) {
-			delete_timer(p->waiting_disconnect, login_waiting_disconnect_timer);
-			p->waiting_disconnect = INVALID_TIMER;
+void login_online_db_setoffline( int char_server ){
+	for( std::pair<uint32,struct online_login_data> pair : online_db ){
+		if( char_server == -1 ){
+			pair.second.char_server = -1;
+
+			if( pair.second.waiting_disconnect != INVALID_TIMER ){
+				delete_timer( pair.second.waiting_disconnect, login_waiting_disconnect_timer );
+				pair.second.waiting_disconnect = INVALID_TIMER;
+			}
+		}else if( pair.second.char_server == char_server ){
+			// Char server disconnected.
+			pair.second.char_server = -2;
 		}
 	}
-	else if( p->char_server == server )
-		p->char_server = -2; //Char server disconnected.
-	return 0;
-}
-
-/**
- * Sub function of login_online_data_cleanup.
- *  Checking if all users in db are still connected to a char-server, and remove them if they aren't.
- * @param data: 1 entry in the db
- * @param ap: args
- * @return: Value to be added up by the function that is applying this
- * @see DBApply
- */
-static int login_online_data_cleanup_sub(DBKey key, DBData *data, va_list ap) {
-	struct online_login_data *character= (struct online_login_data*)db_data2ptr(data);
-	if (character->char_server == -2) //Unknown server.. set them offline
-		login_remove_online_user(character->account_id);
-	return 0;
 }
 
 /**
@@ -185,7 +191,13 @@ static int login_online_data_cleanup_sub(DBKey key, DBData *data, va_list ap) {
  * @return : 0
  */
 static TIMER_FUNC(login_online_data_cleanup){
-	online_db->foreach(online_db, login_online_data_cleanup_sub);
+	for( std::pair<uint32,struct online_login_data> pair : online_db  ){
+		// Unknown server.. set them offline
+		if( pair.second.char_server == -2 ){
+			login_remove_online_user( pair.first );
+		}
+	}
+
 	return 0;
 }
 
@@ -439,6 +451,24 @@ bool login_check_password(const char* md5key, int passwdenc, const char* passwd,
 	}
 }
 
+int login_get_usercount( int users ){
+#if PACKETVER >= 20170726
+	if( login_config.usercount_disable ){
+		return 4; // Removes count and colorization completely
+	}else if( users <= login_config.usercount_low ){
+		return 0; // Green => Smooth
+	}else if( users <= login_config.usercount_medium ){
+		return 1; // Yellow => Normal
+	}else if( users <= login_config.usercount_high ){
+		return 2; // Red => Busy
+	}else{
+		return 3; // Purple => Crowded
+	}
+#else
+	return users;
+#endif
+}
+
 /**
  * Test to determine if an IP come from LAN or WAN.
  * @param ip: ip to check if in auth network
@@ -628,7 +658,15 @@ bool login_config_read(const char* cfgName, bool normal) {
 				nnode->next = login_config.client_hash_nodes;
 				login_config.client_hash_nodes = nnode;
 			}
-		} else if(strcmpi(w1, "chars_per_account") == 0) { //maxchars per account [Sirius]
+		} else if (!strcmpi(w1, "usercount_disable"))
+			login_config.usercount_disable = config_switch(w2);
+		else if (!strcmpi(w1, "usercount_low"))
+			login_config.usercount_low = atoi(w2);
+		else if (!strcmpi(w1, "usercount_medium"))
+			login_config.usercount_medium = atoi(w2);
+		else if (!strcmpi(w1, "usercount_high"))
+			login_config.usercount_high = atoi(w2);
+		else if(strcmpi(w1, "chars_per_account") == 0) { //maxchars per account [Sirius]
 			login_config.char_per_account = atoi(w2);
 			if( login_config.char_per_account <= 0 || login_config.char_per_account > MAX_CHARS ) {
 				if( login_config.char_per_account > MAX_CHARS ) {
@@ -699,6 +737,10 @@ void login_set_defaults() {
 
 	login_config.client_hash_check = 0;
 	login_config.client_hash_nodes = NULL;
+	login_config.usercount_disable = false;
+	login_config.usercount_low = 200;
+	login_config.usercount_medium = 500;
+	login_config.usercount_high = 1000;
 	login_config.char_per_account = MAX_CHARS - MAX_CHAR_VIP - MAX_CHAR_BILLING;
 #ifdef VIP_ENABLE
 	login_config.vip_sys.char_increase = MAX_CHAR_VIP;
@@ -748,8 +790,8 @@ void do_final(void) {
 	}
 
 	accounts = NULL; // destroyed in account_engine
-	online_db->destroy(online_db, NULL);
-	auth_db->destroy(auth_db, NULL);
+	online_db.clear();
+	auth_db.clear();
 
 	do_final_loginchrif();
 
@@ -828,13 +870,8 @@ int do_init(int argc, char** argv) {
 	// initialize static and dynamic ipban system
 	ipban_init();
 
-	// Online user database init
-	online_db = idb_alloc(DB_OPT_RELEASE_DATA);
 	add_timer_func_list(login_waiting_disconnect_timer, "waiting_disconnect_timer");
 
-	// Interserver auth init
-	auth_db = idb_alloc(DB_OPT_RELEASE_DATA);
-
 	// set default parser as parse_login function
 	set_defaultparse(logclif_parse);
 

+ 15 - 19
src/login/login.hpp

@@ -97,6 +97,11 @@ struct Login_Config {
 	char msgconf_name[256];							/// name of msg_conf config file
 	char lanconf_name[256];							/// name of lan config file
 
+	bool usercount_disable;							/// Disable colorization and description in general?
+	int usercount_low;								/// Amount of users that will display in green
+	int usercount_medium;							/// Amount of users that will display in yellow
+	int usercount_high;								/// Amount of users that will display in red
+
 	int char_per_account;							/// number of characters an account can have
 #ifdef VIP_ENABLE
 	struct {
@@ -124,7 +129,6 @@ struct online_login_data {
 	int waiting_disconnect;
 	int char_server;
 };
-extern DBMap* online_db; // uint32 account_id -> struct online_login_data*
 
 /// Auth database
 #define AUTH_TIMEOUT 30000
@@ -136,19 +140,11 @@ struct auth_node {
 	char sex;
 	uint8 clienttype;
 };
-extern DBMap* auth_db; // uint32 account_id -> struct auth_node*
 
 ///Accessors
 AccountDB* login_get_accounts_db(void);
 
-/**
- * Sub function to create an online_login_data and save it to db.
- * @param key: Key of the database entry
- * @param ap: args
- * @return : Data identified by the key to be put in the database
- * @see DBCreateData
- */
-DBData login_create_online_user(DBKey key, va_list args);
+struct online_login_data* login_get_online_user( uint32 account_id );
 
 /**
  * Function to add a user in online_db.
@@ -167,6 +163,12 @@ struct online_login_data* login_add_online_user(int char_server, uint32 account_
  */
 void login_remove_online_user(uint32 account_id);
 
+struct auth_node* login_get_auth_node( uint32 account_id );
+
+struct auth_node* login_add_auth_node( struct login_session_data* sd, uint32 ip );
+
+void login_remove_auth_node( uint32 account_id );
+
 /**
  * Timered function to disconnect a user from login.
  *  This is done either after auth_ok or kicked by char-server.
@@ -180,15 +182,7 @@ void login_remove_online_user(uint32 account_id);
  */
 TIMER_FUNC(login_waiting_disconnect_timer);
 
-/**
- * Sub function to apply on online_db.
- * Mark a character as offline.
- * @param data: 1 entry in the db
- * @param ap: args
- * @return : Value to be added up by the function that is applying this
- * @see DBApply
- */
-int login_online_db_setoffline(DBKey key, DBData *data, va_list ap);
+void login_online_db_setoffline( int char_server );
 
 /**
  * Test to determine if an IP come from LAN or WAN.
@@ -228,4 +222,6 @@ int login_mmo_auth_new(const char* userid, const char* pass, const char sex, con
  */
 int login_mmo_auth(struct login_session_data* sd, bool isServer);
 
+int login_get_usercount( int users );
+
 #endif /* LOGIN_HPP */

+ 16 - 21
src/login/loginchrif.cpp

@@ -73,7 +73,6 @@ int logchrif_parse_reqauth(int fd, int id,char* ip){
 	if( RFIFOREST(fd) < 23 )
 		return 0;
 	else{
-		struct auth_node* node;
 		uint32 account_id = RFIFOL(fd,2);
 		uint32 login_id1 = RFIFOL(fd,6);
 		uint32 login_id2 = RFIFOL(fd,10);
@@ -82,9 +81,10 @@ int logchrif_parse_reqauth(int fd, int id,char* ip){
 		int request_id = RFIFOL(fd,19);
 		RFIFOSKIP(fd,23);
 
-		node = (struct auth_node*)idb_get(auth_db, account_id);
+		struct auth_node* node = login_get_auth_node( account_id );
+
 		if( runflag == LOGINSERVER_ST_RUNNING &&
-			node != NULL &&
+			node != nullptr &&
 			node->account_id == account_id &&
 			node->login_id1  == login_id1 &&
 			node->login_id2  == login_id2 &&
@@ -105,7 +105,7 @@ int logchrif_parse_reqauth(int fd, int id,char* ip){
 			WFIFOSET(fd,21);
 
 			// each auth entry can only be used once
-			idb_remove(auth_db, account_id);
+			login_remove_auth_node( account_id );
 		}else{// authentication not found
 			ShowStatus("Char-server '%s': authentication of the account %d REFUSED (ip: %s).\n", ch_server[id].name, account_id, ip);
 			WFIFOHEAD(fd,21);
@@ -529,17 +529,13 @@ int logchrif_parse_updonlinedb(int fd, int id){
 	if (RFIFOREST(fd) < 4 || RFIFOREST(fd) < RFIFOW(fd,2))
 		return 0;
 	else{
-		uint32 i, users;
-		online_db->foreach(online_db, login_online_db_setoffline, id); //Set all chars from this char-server offline first
-		users = RFIFOW(fd,4);
-		for (i = 0; i < users; i++) {
-			int aid = RFIFOL(fd,6+i*4);
-			struct online_login_data *p = (struct online_login_data*)idb_ensure(online_db, aid, login_create_online_user);
-			p->char_server = id;
-			if (p->waiting_disconnect != INVALID_TIMER){
-				delete_timer(p->waiting_disconnect, login_waiting_disconnect_timer);
-				p->waiting_disconnect = INVALID_TIMER;
-			}
+		//Set all chars from this char-server offline first
+		login_online_db_setoffline( id );
+
+		for( uint32 i = 0, users = RFIFOW(fd, 4); i < users; i++) {
+			uint32 aid = RFIFOL(fd,6+i*4);
+
+			login_add_online_user( id, aid );
 		}
 		RFIFOSKIP(fd,RFIFOW(fd,2));
 	}
@@ -588,7 +584,7 @@ int logchrif_parse_updcharip(int fd, int id){
  */
 int logchrif_parse_setalloffline(int fd, int id){
 	ShowInfo("Setting accounts from char-server %d offline.\n", id);
-	online_db->foreach(online_db, login_online_db_setoffline, id);
+	login_online_db_setoffline( id );
 	RFIFOSKIP(fd,2);
 	return 1;
 }
@@ -628,12 +624,11 @@ int logchrif_parse_pincode_authfail(int fd){
 		struct mmo_account acc;
 		AccountDB* accounts = login_get_accounts_db();
 		if( accounts->load_num(accounts, &acc, RFIFOL(fd,2) ) ){
-			struct online_login_data* ld;
-
-			ld = (struct online_login_data*)idb_get(online_db,acc.account_id);
+			struct online_login_data* ld = login_get_online_user( acc.account_id );
 
-			if( ld == NULL )
+			if( ld == nullptr ){
 				return 0;
+			}
 
 			login_log( host2ip(acc.last_ip), acc.userid, 100, "PIN Code check failed" );
 		}
@@ -850,7 +845,7 @@ void logchrif_server_destroy(int id){
  * @param id: id of char-serv (should be >0, FIXME)
  */
 void logchrif_server_reset(int id) {
-	online_db->foreach(online_db, login_online_db_setoffline, id); //Set all chars from this char server to offline.
+	login_online_db_setoffline(id); //Set all chars from this char server to offline.
 	logchrif_server_destroy(id);
 	logchrif_server_init(id);
 }

+ 10 - 19
src/login/loginclif.cpp

@@ -47,7 +47,6 @@ static void logclif_auth_ok(struct login_session_data* sd) {
 
 	uint8 server_num, n;
 	uint32 subnet_char_ip;
-	struct auth_node* node;
 	int i;
 
 #if PACKETVER < 20170315
@@ -89,7 +88,8 @@ static void logclif_auth_ok(struct login_session_data* sd) {
 	}
 
 	{
-		struct online_login_data* data = (struct online_login_data*)idb_get(online_db, sd->account_id);
+		struct online_login_data* data = login_get_online_user( sd->account_id );
+
 		if( data )
 		{// account is already marked as online!
 			if( data->char_server > -1 )
@@ -108,7 +108,7 @@ static void logclif_auth_ok(struct login_session_data* sd) {
 			if( data->char_server == -1 )
 			{// client has authed but did not access char-server yet
 				// wipe previous session
-				idb_remove(auth_db, sd->account_id);
+				login_remove_auth_node(sd->account_id);
 				login_remove_online_user(sd->account_id);
 				data = NULL;
 			}
@@ -139,7 +139,7 @@ static void logclif_auth_ok(struct login_session_data* sd) {
 		WFIFOL(fd,header+n*size) = htonl((subnet_char_ip) ? subnet_char_ip : ch_server[i].ip);
 		WFIFOW(fd,header+n*size+4) = ntows(htons(ch_server[i].port)); // [!] LE byte order here [!]
 		memcpy(WFIFOP(fd,header+n*size+6), ch_server[i].name, 20);
-		WFIFOW(fd,header+n*size+26) = ch_server[i].users;
+		WFIFOW(fd,header+n*size+26) = login_get_usercount( ch_server[i].users );
 		WFIFOW(fd,header+n*size+28) = ch_server[i].type;
 		WFIFOW(fd,header+n*size+30) = ch_server[i].new_;
 #if PACKETVER >= 20170315
@@ -150,21 +150,12 @@ static void logclif_auth_ok(struct login_session_data* sd) {
 	WFIFOSET(fd,header+size*server_num);
 
 	// create temporary auth entry
-	CREATE(node, struct auth_node, 1);
-	node->account_id = sd->account_id;
-	node->login_id1 = sd->login_id1;
-	node->login_id2 = sd->login_id2;
-	node->sex = sd->sex;
-	node->ip = ip;
-	node->clienttype = sd->clienttype;
-	idb_put(auth_db, sd->account_id, node);
-	{
-		struct online_login_data* data;
-		// mark client as 'online'
-		data = login_add_online_user(-1, sd->account_id);
-		// schedule deletion of this node
-		data->waiting_disconnect = add_timer(gettick()+AUTH_TIMEOUT, login_waiting_disconnect_timer, sd->account_id, 0);
-	}
+	login_add_auth_node( sd, ip );
+
+	// mark client as 'online'
+	struct online_login_data* data = login_add_online_user(-1, sd->account_id);
+	// schedule deletion of this node
+	data->waiting_disconnect = add_timer(gettick()+AUTH_TIMEOUT, login_waiting_disconnect_timer, sd->account_id, 0);
 }
 
 /**

+ 0 - 5
src/login/logincnslif.cpp

@@ -7,7 +7,6 @@
 #include <string.h>
 
 #include "../common/cli.hpp"
-#include "../common/ers.hpp"
 #include "../common/md5calc.hpp"
 #include "../common/mmo.hpp" //cbasetype + NAME_LENGTH
 #include "../common/showmsg.hpp" //show notice
@@ -143,15 +142,11 @@ int cnslif_parse(const char* buf){
 			ShowStatus("Console: Account '%s' created successfully.\n", username);
 		}
 	}
-	else if( strcmpi("ers_report", type) == 0 ){
-		ers_report();
-	}
 	else if( strcmpi("help", type) == 0 ){
 		ShowInfo("Available commands:\n");
 		ShowInfo("\t server:shutdown => Stops the server.\n");
 		ShowInfo("\t server:alive => Checks if the server is running.\n");
 		ShowInfo("\t server:reloadconf => Reload config file: \"%s\"\n", login_config.loginconf_name);
-		ShowInfo("\t ers_report => Displays database usage.\n");
 		ShowInfo("\t create:<username> <password> <sex:M|F> => Creates a new account.\n");
 	}
 	return 1;

+ 4 - 2
src/map/atcommand.cpp

@@ -3910,8 +3910,10 @@ ACMD_FUNC(reload) {
 		//atcommand_broadcast( fd, sd, "@broadcast", "You will feel a bit of lag at this point !" );
 
 		iter = mapit_getallusers();
-		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) )
-			pc_close_npc(pl_sd,2);
+		for( pl_sd = (TBL_PC*)mapit_first(iter); mapit_exists(iter); pl_sd = (TBL_PC*)mapit_next(iter) ){
+			pc_close_npc(pl_sd,1);
+			clif_cutin(pl_sd, "", 255);
+		}
 		mapit_free(iter);
 
 		flush_fifos();

+ 4 - 0
src/map/battle.cpp

@@ -8256,6 +8256,8 @@ static const struct _battle_data {
 	{ "manner_system",                      &battle_config.manner_system,                   0xFFF,  0,      0xFFF,          },
 	{ "pet_equip_required",                 &battle_config.pet_equip_required,              0,      0,      1,              },
 	{ "multi_level_up",                     &battle_config.multi_level_up,                  0,      0,      1,              },
+	{ "multi_level_up_base",                &battle_config.multi_level_up_base,             0,      0,      MAX_LEVEL,      },
+	{ "multi_level_up_job",                 &battle_config.multi_level_up_job,              0,      0,      MAX_LEVEL,      },
 	{ "max_exp_gain_rate",                  &battle_config.max_exp_gain_rate,               0,      0,      INT_MAX,        },
 	{ "backstab_bow_penalty",               &battle_config.backstab_bow_penalty,            0,      0,      1,              },
 	{ "night_at_start",                     &battle_config.night_at_start,                  0,      0,      1,              },
@@ -8509,6 +8511,8 @@ static const struct _battle_data {
 	{ "feature.attendance",                 &battle_config.feature_attendance,              1,      0,      1,              },
 	{ "feature.privateairship",             &battle_config.feature_privateairship,          1,      0,      1,              },
 	{ "rental_transaction",                 &battle_config.rental_transaction,              1,      0,      1,              },
+	{ "min_shop_buy",                       &battle_config.min_shop_buy,                    1,      0,      INT_MAX,        },
+	{ "min_shop_sell",                      &battle_config.min_shop_sell,                   0,      0,      INT_MAX,        },
 	{ "blocking_play_delay",                &battle_config.blocking_play_delay,             20000,  0,      INT_MAX,        },
 
 #include "../custom/battle_config_init.inc"

+ 4 - 0
src/map/battle.hpp

@@ -352,6 +352,8 @@ struct Battle_Config
 	int equip_self_break_rate; //Natural & Penalty skills break rate
 	int equip_skill_break_rate; //Offensive skills break rate
 	int multi_level_up;
+	int multi_level_up_base;
+	int multi_level_up_job;
 	int max_exp_gain_rate; //Max amount of exp bar % you can get in one go.
 	int pk_mode;
 	int pk_mode_mes;
@@ -649,6 +651,8 @@ struct Battle_Config
 	int feature_attendance;
 	int feature_privateairship;
 	int rental_transaction;
+	int min_shop_buy;
+	int min_shop_sell;
 	int blocking_play_delay;
 
 #include "../custom/battle_config_struct.inc"

+ 1 - 1
src/map/chrif.cpp

@@ -583,7 +583,7 @@ void chrif_on_ready(void) {
 	do_reconnect_storage();
 
 	//Re-save any guild castles that were modified in the disconnection time.
-	guild_castle_reconnect(-1, 0, 0);
+	guild_castle_reconnect(-1, CD_NONE, 0);
 	
 	// Charserver is ready for loading autotrader
 	if (!char_init_done)

+ 3 - 2
src/map/clif.cpp

@@ -2388,6 +2388,7 @@ void clif_viewpoint(struct map_session_data *sd, int npc_id, int type, int x, in
 ///     2 = bottom right corner
 ///     3 = middle of screen, inside a movable window
 ///     4 = middle of screen, movable with a close button, chrome-less
+///   255 = clear all displayed cutins
 void clif_cutin(struct map_session_data* sd, const char* image, int type)
 {
 	int fd;
@@ -10272,7 +10273,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 
 	// Autotraders should ignore this entirely, clif_parse_LoadEndAck is always invoked manually for them
 	if (!sd->state.active || (!sd->state.autotrade && !sd->state.pc_loaded)) { //Character loading is not complete yet!
-		//Let pc_reg_received or intif_parse_StorageReceived reinvoke this when ready.
+		//Let pc_reg_received or pc_scdata_received reinvoke this when ready.
 		sd->state.connect_new = 0;
 		return;
 	}
@@ -10588,7 +10589,7 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd)
 	mail_clear(sd);
 
 	/* Guild Aura Init */
-	if( sd->state.gmaster_flag ) {
+	if( sd->guild && sd->state.gmaster_flag ) {
 		guild_guildaura_refresh(sd,GD_LEADERSHIP,guild_checkskill(sd->guild,GD_LEADERSHIP));
 		guild_guildaura_refresh(sd,GD_GLORYWOUNDS,guild_checkskill(sd->guild,GD_GLORYWOUNDS));
 		guild_guildaura_refresh(sd,GD_SOULCOLD,guild_checkskill(sd->guild,GD_SOULCOLD));

+ 18 - 13
src/map/guild.cpp

@@ -108,7 +108,7 @@ int guild_skill_get_max (int id) {
 
 // Retrieve skill_lv learned by guild
 int guild_checkskill(struct guild *g, int id) {
-	if ((id = guild_skill_get_index(id)) < 0)
+	if ( g == nullptr || (id = guild_skill_get_index(id)) < 0)
 		return 0;
 	return g->skill[id].lv;
 }
@@ -535,6 +535,11 @@ int guild_recv_info(struct guild *sg) {
 			bm++;
 	}
 
+	// Restore the instance id
+	if( !guild_new && before.instance_id ){
+		g->instance_id = before.instance_id;
+	}
+
 	for (i = 0; i < g->max_member; i++) { //Transmission of information at all members
 		sd = g->member[i].sd;
 		if( sd==NULL )
@@ -1725,7 +1730,7 @@ int castle_guild_broken_sub(DBKey key, DBData *data, va_list ap)
 		npc_event_do(name);
 
 		//Save the new 'owner', this should invoke guardian clean up and other such things.
-		guild_castledatasave(gc->castle_id, 1, 0);
+		guild_castledatasave(gc->castle_id, CD_GUILD_ID, 0);
 	}
 	return 0;
 }
@@ -1965,7 +1970,7 @@ int guild_castledatasave(int castle_id, int index, int value) {
 	}
 
 	switch (index) {
-	case 1: // The castle's owner has changed? Update or remove Guardians too. [Skotlex]
+	case CD_GUILD_ID: // The castle's owner has changed? Update or remove Guardians too. [Skotlex]
 	{
 		int i;
 		gc->guild_id = value;
@@ -1976,9 +1981,9 @@ int guild_castledatasave(int castle_id, int index, int value) {
 		}
 		break;
 	}
-	case 2:
+	case CD_CURRENT_ECONOMY:
 		gc->economy = value; break;
-	case 3: // defense invest change -> recalculate guardian hp
+	case CD_CURRENT_DEFENSE: // defense invest change -> recalculate guardian hp
 	{
 		int i;
 		gc->defense = value;
@@ -1989,21 +1994,21 @@ int guild_castledatasave(int castle_id, int index, int value) {
 		}
 		break;
 	}
-	case 4:
+	case CD_INVESTED_ECONOMY:
 		gc->triggerE = value; break;
-	case 5:
+	case CD_INVESTED_DEFENSE:
 		gc->triggerD = value; break;
-	case 6:
+	case CD_NEXT_TIME:
 		gc->nextTime = value; break;
-	case 7:
+	case CD_PAY_TIME:
 		gc->payTime = value; break;
-	case 8:
+	case CD_CREATE_TIME:
 		gc->createTime = value; break;
-	case 9:
+	case CD_ENABLED_KAFRA:
 		gc->visibleC = value; break;
 	default:
-		if (index > 9 && index <= 9+MAX_GUARDIANS) {
-			gc->guardian[index-10].visible = value;
+		if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+			gc->guardian[index - CD_ENABLED_GUARDIAN00].visible = value;
 			break;
 		}
 		ShowWarning("guild_castledatasave: index = '%d' is out of allowed range\n", index);

+ 0 - 6
src/map/instance.cpp

@@ -806,12 +806,6 @@ enum e_instance_enter instance_enter(struct map_session_data *sd, unsigned short
 	if (pc_setpos(sd, map_id2index(m), x, y, CLR_OUTSIGHT))
 		return IE_OTHER;
 
-	// If there was an idle timer, let's stop it
-	instance_stopidletimer(im, instance_id);
-
-	// Now we start the instance timer
-	instance_startkeeptimer(im, instance_id);
-
 	return IE_OK;
 }
 

+ 5 - 5
src/map/mob.cpp

@@ -793,11 +793,11 @@ static TIMER_FUNC(mob_spawn_guardian_sub){
 			if (md->guardian_data->castle->guild_id) //Free castle up.
 			{
 				ShowNotice("Clearing ownership of castle %d (%s)\n", md->guardian_data->castle->castle_id, md->guardian_data->castle->castle_name);
-				guild_castledatasave(md->guardian_data->castle->castle_id, 1, 0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_GUILD_ID, 0);
 			}
 		} else {
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
-				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number,0);
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 		}
 		return 0;
@@ -2446,7 +2446,7 @@ int mob_dead(struct mob_data *md, struct block_list *src, int type)
 	}
 
 	if( md->guardian_data && md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS )
-		guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number,0);
+		guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number,0);
 
 	if( src ) { // Use Dead skill only if not killed by Script or Command
 		md->status.hp = 1;
@@ -3090,7 +3090,7 @@ int mob_guardian_guildchange(struct mob_data *md)
 			md->guardian_data->guild_name[0] = '\0';
 		} else {
 			if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS && md->guardian_data->castle->guardian[md->guardian_data->number].visible)
-				guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
+				guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number, 0);
 			unit_free(&md->bl,CLR_OUTSIGHT); //Remove guardian.
 		}
 		return 0;
@@ -3101,7 +3101,7 @@ int mob_guardian_guildchange(struct mob_data *md)
 	{	//Properly remove guardian info from Castle data.
 		ShowError("mob_guardian_guildchange: New Guild (id %d) does not exists!\n", md->guardian_data->guild_id);
 		if (md->guardian_data->number >= 0 && md->guardian_data->number < MAX_GUARDIANS)
-			guild_castledatasave(md->guardian_data->castle->castle_id, 10+md->guardian_data->number, 0);
+			guild_castledatasave(md->guardian_data->castle->castle_id, CD_ENABLED_GUARDIAN00 + md->guardian_data->number, 0);
 		unit_free(&md->bl,CLR_OUTSIGHT);
 		return 0;
 	}

+ 10 - 0
src/map/npc.hpp

@@ -1109,6 +1109,16 @@ enum e_job_types
 	JT_4_ED_OSCAR,
 	JT_4_ED_ORB,
 	JT_4_ED_FENCE,
+	JT_4_M_ANDREA,
+	JT_4_M_ANDREA_D,
+	JT_4_F_ANES,
+	JT_4_F_ANES_D,
+	JT_4_M_SILVANO,
+	JT_4_M_SILVANO_D,
+	JT_4_F_CECILIA,
+	JT_4_F_CECILIA_D,
+
+	JT_4_F_ERENE = 10337,
 	NPC_RANGE3_END, // Official: JT_NEW_NPC_3RD_END=19999
 
 	// Unofficial

+ 57 - 53
src/map/pc.cpp

@@ -4294,8 +4294,8 @@ int pc_modifybuyvalue(struct map_session_data *sd,int orig_value)
 	if(rate1 < rate2) rate1 = rate2;
 	if(rate1)
 		val = (int)((double)orig_value*(double)(100-rate1)/100.);
-	if(val < 0) val = 0;
-	if(orig_value > 0 && val < 1) val = 1;
+	if(val < battle_config.min_shop_buy)
+		val = battle_config.min_shop_buy;
 
 	return val;
 }
@@ -4310,8 +4310,8 @@ int pc_modifysellvalue(struct map_session_data *sd,int orig_value)
 		rate = 5+skill*2-((skill==10)? 1:0);
 	if(rate)
 		val = (int)((double)orig_value*(double)(100+rate)/100.);
-	if(val < 0) val = 0;
-	if(orig_value > 0 && val < 1) val = 1;
+	if (val < battle_config.min_shop_sell)
+		val = battle_config.min_shop_sell;
 
 	return val;
 }
@@ -5338,13 +5338,15 @@ int pc_show_steal(struct block_list *bl,va_list ap)
 
 	return 0;
 }
-/*==========================================
+
+/**
  * Steal an item from bl (mob).
- * Return:
- *	0 = fail
- *	1 = succes
- *------------------------------------------*/
-int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
+ * @param sd: Player data
+ * @param bl: Object to steal from
+ * @param skill_lv: Level of skill used
+ * @return True on success or false otherwise
+ */
+bool pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv)
 {
 	int i,itemid;
 	double rate;
@@ -5354,12 +5356,12 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
 	struct item tmp_item;
 
 	if(!sd || !bl || bl->type!=BL_MOB)
-		return 0;
+		return false;
 
 	md = (TBL_MOB *)bl;
 
 	if(md->state.steal_flag == UCHAR_MAX || ( md->sc.opt1 && md->sc.opt1 != OPT1_BURNING ) ) //already stolen from / status change check
-		return 0;
+		return false;
 
 	sd_status= status_get_status_data(&sd->bl);
 	md_status= status_get_status_data(bl);
@@ -5370,23 +5372,31 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
 			md->state.steal_flag++ >= battle_config.skill_steal_max_tries)
   	) { //Can't steal from
 		md->state.steal_flag = UCHAR_MAX;
-		return 0;
+		return false;
 	}
 
 	// base skill success chance (percentual)
 	rate = (sd_status->dex - md_status->dex)/2 + skill_lv*6 + 4;
 	rate += sd->bonus.add_steal_rate;
 
-	if( rate < 1 )
-		return 0;
+	if( rate < 1
+#ifdef RENEWAL
+		|| rnd()%100 >= rate
+#endif
+	)
+		return false;
 
 	// Try dropping one item, in the order from first to last possible slot.
 	// Droprate is affected by the skill success rate.
 	for( i = 0; i < MAX_STEAL_DROP; i++ )
-		if( md->db->dropitem[i].nameid > 0 && !md->db->dropitem[i].steal_protected && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p * rate/100. )
+		if( md->db->dropitem[i].nameid > 0 && !md->db->dropitem[i].steal_protected && itemdb_exists(md->db->dropitem[i].nameid) && rnd() % 10000 < md->db->dropitem[i].p
+#ifndef RENEWAL
+		* rate/100.
+#endif
+		)
 			break;
 	if( i == MAX_STEAL_DROP )
-		return 0;
+		return false;
 
 	itemid = md->db->dropitem[i].nameid;
 	memset(&tmp_item,0,sizeof(tmp_item));
@@ -5401,7 +5411,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
 
 	if(flag) { //Failed to steal due to overweight
 		clif_additem(sd,0,0,flag);
-		return 0;
+		return false;
 	}
 
 	if(battle_config.show_steal_in_same_party)
@@ -5419,7 +5429,7 @@ int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skil
 		//MSG: "'%s' stole %s's %s (chance: %0.02f%%)"
 		intif_broadcast(message, strlen(message) + 1, BC_DEFAULT);
 	}
-	return 1;
+	return true;
 }
 
 /*==========================================
@@ -5492,24 +5502,14 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
 	sd->state.workinprogress = WIP_DISABLE_NONE;
 
 	if( sd->state.changemap ) { // Misc map-changing settings
-		int i;
-		unsigned short instance_id = map_getmapdata(sd->bl.m)->instance_id;
-
-		if (instance_id && instance_id != mapdata->instance_id) {
-			struct party_data *p = NULL;
-			struct guild *g = NULL;
-			struct clan *cd = NULL;
-
-			if (sd->instance_id)
-				instance_delusers(sd->instance_id);
-			else if (sd->status.party_id && (p = party_search(sd->status.party_id)) != NULL && p->instance_id)
-				instance_delusers(p->instance_id);
-			else if (sd->status.guild_id && (g = guild_search(sd->status.guild_id)) != NULL && g->instance_id)
-				instance_delusers(g->instance_id);
-			else if (sd->status.clan_id && (cd = clan_search(sd->status.clan_id)) != NULL && cd->instance_id)
-				instance_delusers(cd->instance_id);
-			else
-				instance_delusers(instance_id);
+		unsigned short curr_map_instance_id = map_getmapdata(sd->bl.m)->instance_id, new_map_instance_id = mapdata->instance_id;
+
+		if (curr_map_instance_id != new_map_instance_id) {
+			if (curr_map_instance_id) // Update instance timer for the map on leave
+				instance_delusers(curr_map_instance_id);
+
+			if (new_map_instance_id) // Update instance timer for the map on enter
+				instance_addusers(new_map_instance_id);
 		}
 
 		sd->state.pmap = sd->bl.m;
@@ -5536,7 +5536,7 @@ enum e_setpos pc_setpos(struct map_session_data* sd, unsigned short mapindex, in
 			status_change_end(&sd->bl, SC_CLOAKING, INVALID_TIMER);
 			status_change_end(&sd->bl, SC_CLOAKINGEXCEED, INVALID_TIMER);
 		}
-		for( i = 0; i < EQI_MAX; i++ ) {
+		for(int i = 0; i < EQI_MAX; i++ ) {
 			if( sd->equip_index[i] >= 0 )
 				if( pc_isequip(sd,sd->equip_index[i]) )
 					pc_unequipitem(sd,sd->equip_index[i],2);
@@ -6569,7 +6569,7 @@ int pc_checkbaselevelup(struct map_session_data *sd) {
 	do {
 		sd->status.base_exp -= next;
 		//Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
-		if(!battle_config.multi_level_up && sd->status.base_exp > next-1)
+		if( ( !battle_config.multi_level_up || ( battle_config.multi_level_up_base > 0 && sd->status.base_level >= battle_config.multi_level_up_base ) ) && sd->status.base_exp > next-1 )
 			sd->status.base_exp = next-1;
 
 		next = pc_gets_status_point(sd->status.base_level);
@@ -6638,7 +6638,7 @@ int pc_checkjoblevelup(struct map_session_data *sd)
 	do {
 		sd->status.job_exp -= next;
 		//Kyoki pointed out that the max overcarry exp is the exp needed for the previous level -1. [Skotlex]
-		if(!battle_config.multi_level_up && sd->status.job_exp > next-1)
+		if( ( !battle_config.multi_level_up || ( battle_config.multi_level_up_job > 0 && sd->status.job_level >= battle_config.multi_level_up_job ) ) && sd->status.job_exp > next-1 )
 			sd->status.job_exp = next-1;
 
 		sd->status.job_level ++;
@@ -7688,10 +7688,12 @@ TIMER_FUNC(pc_close_npc_timer){
 	if(sd) pc_close_npc(sd,data);
 	return 0;
 }
-/*
- *  Method to properly close npc for player and clear anything related
- * @flag == 1 : produce close button
- * @flag == 2 : directly close it
+/**
+ * Method to properly close a NPC for player and clear anything related.
+ * @param sd: Player attached
+ * @param flag: Method of closure
+ *   1: Produce a close button and end the NPC
+ *   2: End the NPC (best for no dialog windows)
  */
 void pc_close_npc(struct map_session_data *sd,int flag)
 {
@@ -7717,15 +7719,17 @@ void pc_close_npc(struct map_session_data *sd,int flag)
 #ifdef SECURE_NPCTIMEOUT
 		sd->npc_idle_timer = INVALID_TIMER;
 #endif
-		if (sd->st && sd->st->state == CLOSE) {
-			clif_scriptclose(sd, sd->npc_id);
-			clif_scriptclear(sd, sd->npc_id); // [Ind/Hercules]
-			sd->st->state = END; // Force to end now
-		}
-		if(sd->st && sd->st->state == END ) {// free attached scripts that are waiting
-			script_free_state(sd->st);
-			sd->st = NULL;
-			sd->npc_id = 0;
+		if (sd->st) {
+			if (sd->st->state == CLOSE) {
+				clif_scriptclose(sd, sd->npc_id);
+				clif_scriptclear(sd, sd->npc_id); // [Ind/Hercules]
+				sd->st->state = END; // Force to end now
+			}
+			if (sd->st->state == END) { // free attached scripts that are waiting
+				script_free_state(sd->st);
+				sd->st = NULL;
+				sd->npc_id = 0;
+			}
 		}
 	}
 }

+ 1 - 1
src/map/pc.hpp

@@ -1108,7 +1108,7 @@ int pc_insert_card(struct map_session_data *sd,int idx_card,int idx_equip);
 
 int pc_identifyall(struct map_session_data *sd, bool identify_item);
 
-int pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv);
+bool pc_steal_item(struct map_session_data *sd,struct block_list *bl, uint16 skill_lv);
 int pc_steal_coin(struct map_session_data *sd,struct block_list *bl);
 
 int pc_modifybuyvalue(struct map_session_data*,int);

+ 76 - 22
src/map/script.cpp

@@ -12849,27 +12849,27 @@ BUILDIN_FUNC(getcastledata)
 	}
 
 	switch (index) {
-		case 1:
+		case CD_GUILD_ID:
 			script_pushint(st,gc->guild_id); break;
-		case 2:
+		case CD_CURRENT_ECONOMY:
 			script_pushint(st,gc->economy); break;
-		case 3:
+		case CD_CURRENT_DEFENSE:
 			script_pushint(st,gc->defense); break;
-		case 4:
+		case CD_INVESTED_ECONOMY:
 			script_pushint(st,gc->triggerE); break;
-		case 5:
+		case CD_INVESTED_DEFENSE:
 			script_pushint(st,gc->triggerD); break;
-		case 6:
+		case CD_NEXT_TIME:
 			script_pushint(st,gc->nextTime); break;
-		case 7:
+		case CD_PAY_TIME:
 			script_pushint(st,gc->payTime); break;
-		case 8:
+		case CD_CREATE_TIME:
 			script_pushint(st,gc->createTime); break;
-		case 9:
+		case CD_ENABLED_KAFRA:
 			script_pushint(st,gc->visibleC); break;
 		default:
-			if (index > 9 && index <= 9+MAX_GUARDIANS) {
-				script_pushint(st,gc->guardian[index-10].visible);
+			if (index >= CD_ENABLED_GUARDIAN00 && index < CD_MAX) {
+				script_pushint(st,gc->guardian[index - CD_ENABLED_GUARDIAN00].visible);
 				break;
 			}
 			script_pushint(st,0);
@@ -12891,7 +12891,7 @@ BUILDIN_FUNC(setcastledata)
 		return SCRIPT_CMD_FAILURE;
 	}
 
-	if (index <= 0 || index > 9+MAX_GUARDIANS) {
+	if (index <= CD_NONE || index >= CD_MAX) {
 		ShowWarning("buildin_setcastledata: index = '%d' is out of allowed range\n", index);
 		return SCRIPT_CMD_FAILURE;
 	}
@@ -17771,8 +17771,8 @@ BUILDIN_FUNC(setunitdata)
 		switch (type) {
 			case UMOB_SIZE: md->base_status->size = (unsigned char)value; calc_status = true; break;
 			case UMOB_LEVEL: md->level = (unsigned short)value; break;
-			case UMOB_HP: md->base_status->hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
-			case UMOB_MAXHP: md->base_status->max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
+			case UMOB_HP: status_set_hp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
+			case UMOB_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); clif_name_area(&md->bl); break;
 			case UMOB_MASTERAID: md->master_id = value; break;
 			case UMOB_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break;
 			case UMOB_X: if (!unit_walktoxy(bl, (short)value, md->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break;
@@ -17855,8 +17855,8 @@ BUILDIN_FUNC(setunitdata)
 		switch (type) {
 			case UHOM_SIZE: hd->base_status.size = (unsigned char)value; calc_status = true; break;
 			case UHOM_LEVEL: hd->homunculus.level = (unsigned short)value; break;
-			case UHOM_HP: hd->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break;
-			case UHOM_MAXHP: hd->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break;
+			case UHOM_HP: status_set_hp(bl, (unsigned int)value, 0); break;
+			case UHOM_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break;
 			case UHOM_SP: hd->base_status.sp = (unsigned int)value; status_set_sp(bl, (unsigned int)value, 0); break;
 			case UHOM_MAXSP: hd->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break;
 			case UHOM_MASTERCID: hd->homunculus.char_id = (uint32)value; break;
@@ -17918,7 +17918,7 @@ BUILDIN_FUNC(setunitdata)
 			case UPET_SIZE: pd->status.size = (unsigned char)value; break;
 			case UPET_LEVEL: pd->pet.level = (unsigned short)value; break;
 			case UPET_HP: status_set_hp(bl, (unsigned int)value, 0); break;
-			case UPET_MAXHP: status_set_maxhp(bl, (unsigned int)value, 0); break;
+			case UPET_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break;
 			case UPET_MASTERAID: pd->pet.account_id = (unsigned int)value; break;
 			case UPET_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break;
 			case UPET_X: if (!unit_walktoxy(bl, (short)value, pd->bl.y, 2)) unit_movepos(bl, (short)value, md->bl.y, 0, 0); break;
@@ -17965,8 +17965,8 @@ BUILDIN_FUNC(setunitdata)
 		}
 		switch (type) {
 			case UMER_SIZE: mc->base_status.size = (unsigned char)value; calc_status = true; break;
-			case UMER_HP: mc->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break;
-			case UMER_MAXHP: mc->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break;
+			case UMER_HP: status_set_hp(bl, (unsigned int)value, 0); break;
+			case UMER_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break;
 			case UMER_MASTERCID: mc->mercenary.char_id = (uint32)value; break;
 			case UMER_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break;
 			case UMER_X: if (!unit_walktoxy(bl, (short)value, mc->bl.y, 2)) unit_movepos(bl, (short)value, mc->bl.y, 0, 0); break;
@@ -18024,8 +18024,8 @@ BUILDIN_FUNC(setunitdata)
 		}
 		switch (type) {
 			case UELE_SIZE: ed->base_status.size = (unsigned char)value; calc_status = true; break;
-			case UELE_HP: ed->base_status.hp = (unsigned int)value; status_set_hp(bl, (unsigned int)value, 0); break;
-			case UELE_MAXHP: ed->base_status.max_hp = (unsigned int)value; status_set_maxhp(bl, (unsigned int)value, 0); break;
+			case UELE_HP: status_set_hp(bl, (unsigned int)value, 0); break;
+			case UELE_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break;
 			case UELE_SP: ed->base_status.sp = (unsigned int)value; status_set_sp(bl, (unsigned int)value, 0); break;
 			case UELE_MAXSP: ed->base_status.max_sp = (unsigned int)value; status_set_maxsp(bl, (unsigned int)value, 0); break;
 			case UELE_MASTERCID: ed->elemental.char_id = (uint32)value; break;
@@ -18088,7 +18088,7 @@ BUILDIN_FUNC(setunitdata)
 			case UNPC_DISPLAY: status_set_viewdata(bl, (unsigned short)value); break;
 			case UNPC_LEVEL: nd->level = (unsigned int)value; break;
 			case UNPC_HP: status_set_hp(bl, (unsigned int)value, 0); break;
-			case UNPC_MAXHP: status_set_maxhp(bl, (unsigned int)value, 0); break;
+			case UNPC_MAXHP: status_set_hp(bl, (unsigned int)value, 0); status_set_maxhp(bl, (unsigned int)value, 0); break;
 			case UNPC_MAPID: if (mapname) value = map_mapname2mapid(mapname); unit_warp(bl, (short)value, 0, 0, CLR_TELEPORT); break;
 			case UNPC_X: if (!unit_walktoxy(bl, (short)value, nd->bl.y, 2)) unit_movepos(bl, (short)value, nd->bl.x, 0, 0); break;
 			case UNPC_Y: if (!unit_walktoxy(bl, nd->bl.x, (short)value, 2)) unit_movepos(bl, nd->bl.x, (short)value, 0, 0); break;
@@ -23991,6 +23991,58 @@ BUILDIN_FUNC(identifyall) {
 	return SCRIPT_CMD_SUCCESS;
 }
 
+BUILDIN_FUNC(is_guild_leader)
+{
+	struct map_session_data* sd;
+	struct guild* guild_data;
+	int guild_id;
+
+	if (!script_rid2sd(sd)) {
+		script_pushint(st, false);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	if (script_hasdata(st, 2))
+		guild_id = script_getnum(st, 2);
+	else
+		guild_id = sd->status.guild_id;
+
+	guild_data = guild_search(guild_id);
+	if (guild_data)
+		script_pushint(st, (guild_data->member[0].char_id == sd->status.char_id));
+	else
+		script_pushint(st, false);
+	return SCRIPT_CMD_SUCCESS;
+}
+
+BUILDIN_FUNC(is_party_leader)
+{
+	struct map_session_data* sd;
+	struct party_data* p_data;
+	int p_id, i = 0;
+
+	if (!script_rid2sd(sd)) {
+		script_pushint(st, false);
+		return SCRIPT_CMD_FAILURE;
+	}
+
+	if (script_hasdata(st, 2))
+		p_id = script_getnum(st, 2);
+	else
+		p_id = sd->status.party_id;
+
+	p_data = party_search(p_id);
+	if (p_data) {
+		ARR_FIND( 0, MAX_PARTY, i, p_data->data[i].sd == sd );
+		if (i < MAX_PARTY){
+			script_pushint(st, p_data->party.member[i].leader);
+			return SCRIPT_CMD_SUCCESS;
+		}
+	}
+	script_pushint(st, false);
+	return SCRIPT_CMD_SUCCESS;
+}
+
 #include "../custom/script.inc"
 
 // declarations that were supposed to be exported from npc_chat.c
@@ -24651,6 +24703,8 @@ struct script_function buildin_func[] = {
 	BUILDIN_DEF(mail, "isss*"),
 	BUILDIN_DEF(open_roulette,"?"),
 	BUILDIN_DEF(identifyall,"??"),
+	BUILDIN_DEF(is_guild_leader,"?"),
+	BUILDIN_DEF(is_party_leader,"?"),
 #include "../custom/script_def.inc"
 
 	{NULL,NULL,NULL},

+ 32 - 0
src/map/script_constants.hpp

@@ -3608,8 +3608,11 @@
 	export_constant(EFST_BOW_ATK_POWER);
 	export_constant(EFST_RED_ORG_POTION);
 	export_constant(EFST_CAST_TIME);
+	export_constant(EFST_LEAPIMPAIRED);
 	export_constant(EFST_EXCLUSIVE_RECEIVEITEM);
 	export_constant(EFST_EXCLUSIVE_PLUSEXP);
+	export_constant(EFST_ASSUMPTIO_BUFF);
+	export_constant(EFST_BASILICA_BUFF);
 	export_constant(EFST_OVERLAPEXPUP2);
 /// @APIHOOK_END
 /// Do not modify code above this, since it will be automatically generated by the API again
@@ -6068,6 +6071,15 @@
 	export_constant_npc(JT_4_ED_OSCAR);
 	export_constant_npc(JT_4_ED_ORB);
 	export_constant_npc(JT_4_ED_FENCE);
+	export_constant_npc(JT_4_M_ANDREA);
+	export_constant_npc(JT_4_M_ANDREA_D);
+	export_constant_npc(JT_4_F_ANES);
+	export_constant_npc(JT_4_F_ANES_D);
+	export_constant_npc(JT_4_M_SILVANO);
+	export_constant_npc(JT_4_M_SILVANO_D);
+	export_constant_npc(JT_4_F_CECILIA);
+	export_constant_npc(JT_4_F_CECILIA_D);
+	export_constant_npc(JT_4_F_ERENE);
 	#undef export_constant_npc
 
 	/* special effects */
@@ -7327,6 +7339,26 @@
 	export_constant(GUILDSTORAGE_LOG_EMPTY);
 	export_constant(GUILDSTORAGE_LOG_FAILED);
 
+	/* castle data flags */
+	export_constant(CD_NONE);
+	export_constant(CD_GUILD_ID);
+	export_constant(CD_CURRENT_ECONOMY);
+	export_constant(CD_CURRENT_DEFENSE);
+	export_constant(CD_INVESTED_ECONOMY);
+	export_constant(CD_INVESTED_DEFENSE);
+	export_constant(CD_NEXT_TIME);
+	export_constant(CD_PAY_TIME);
+	export_constant(CD_CREATE_TIME);
+	export_constant(CD_ENABLED_KAFRA);
+	for( int i = CD_ENABLED_GUARDIAN00, j = 0; i < CD_MAX; i++, j++ ){
+		char constant[32];
+
+		sprintf( constant, "CD_ENABLED_GUARDIAN%02d", j );
+
+		script_set_constant( constant, i, false, false );
+	}
+	export_constant(CD_MAX);
+
 	#undef export_constant
 	#undef export_constant2
 	#undef export_parameter

+ 17 - 8
src/map/skill.cpp

@@ -7153,6 +7153,16 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 	}
 		break;
 
+	case RK_IGNITIONBREAK:
+		skill_area_temp[1] = 0;
+#if PACKETVER >= 20180207
+		clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
+#else
+		clif_skill_damage(src, src, tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, DMG_SKILL);
+#endif
+		map_foreachinrange(skill_area_sub, bl, skill_get_splash(skill_id, skill_lv), BL_CHAR|BL_SKILL, src, skill_id, skill_lv, tick, flag|BCT_ENEMY|SD_SPLASH|1, skill_castend_damage_id);
+		break;
+
 	case SR_WINDMILL:
 	case GN_CART_TORNADO:
 		clif_skill_nodamage(src,bl,skill_id,skill_lv,1);
@@ -9082,16 +9092,15 @@ int skill_castend_nodamage_id (struct block_list *src, struct block_list *bl, ui
 				skill_castend_nodamage_id);
 		}
 		break;
-	case RK_IGNITIONBREAK:
-	case LG_EARTHDRIVE:
+
+	case LG_EARTHDRIVE: {
+			int dummy = 1;
+
 			clif_skill_damage(src,bl,tick, status_get_amotion(src), 0, -30000, 1, skill_id, skill_lv, DMG_SKILL);
 			i = skill_get_splash(skill_id,skill_lv);
-			if( skill_id == LG_EARTHDRIVE ) {
-				int dummy = 1;
-				map_foreachinallarea(skill_cell_overlap, src->m, src->x-i, src->y-i, src->x+i, src->y+i, BL_SKILL, LG_EARTHDRIVE, &dummy, src);
-			}
-			map_foreachinrange(skill_area_sub, bl,i,BL_CHAR,
-				src,skill_id,skill_lv,tick,flag|BCT_ENEMY|1,skill_castend_damage_id);
+			map_foreachinallarea(skill_cell_overlap, src->m, src->x-i, src->y-i, src->x+i, src->y+i, BL_SKILL, LG_EARTHDRIVE, &dummy, src);
+			map_foreachinrange(skill_area_sub, bl,i,BL_CHAR,src,skill_id,skill_lv,tick,flag|BCT_ENEMY|1,skill_castend_damage_id);
+		}
 		break;
 	case RK_GIANTGROWTH:
 	case RK_STONEHARDSKIN:

+ 2 - 2
src/map/status.cpp

@@ -416,7 +416,7 @@ void initChangeTables(void)
 	add_sc( NPC_INVISIBLE		, SC_CLOAKING		);
 	set_sc( LK_AURABLADE		, SC_AURABLADE		, EFST_AURABLADE		, SCB_NONE );
 	set_sc( LK_PARRYING		, SC_PARRYING		, EFST_PARRYING		, SCB_NONE );
-	set_sc( LK_CONCENTRATION	, SC_CONCENTRATION	, EFST_CONCENTRATION	,
+	set_sc( LK_CONCENTRATION	, SC_CONCENTRATION	, EFST_LKCONCENTRATION	,
 #ifndef RENEWAL
 		SCB_BATK|SCB_WATK|SCB_HIT|SCB_DEF|SCB_DEF2 );
 #else
@@ -12811,7 +12811,7 @@ int status_change_end_(struct block_list* bl, enum sc_type type, int tid, const
 	if(opt_flag&4) // Out of hiding, invoke on place.
 		skill_unit_move(bl,gettick(),1);
 
-	if(opt_flag&2 && sd && map_getcell(bl->m,bl->x,bl->y,CELL_CHKNPC))
+	if(opt_flag&2 && sd && !sd->state.warping && map_getcell(bl->m,bl->x,bl->y,CELL_CHKNPC))
 		npc_touch_areanpc(sd,bl->m,bl->x,bl->y); // Trigger on-touch event.
 
 	ers_free(sc_data_ers, sce);

+ 5 - 2
src/map/status.hpp

@@ -2895,10 +2895,13 @@ enum efst_types : short{
 	EFST_RED_ORG_POTION,
 	EFST_CAST_TIME,
 
+	EFST_LEAPIMPAIRED = 1117,
+
 	EFST_EXCLUSIVE_RECEIVEITEM = 1119,
 	EFST_EXCLUSIVE_PLUSEXP,
-
-	EFST_OVERLAPEXPUP2 = 1123,
+	EFST_ASSUMPTIO_BUFF,
+	EFST_BASILICA_BUFF,
+	EFST_OVERLAPEXPUP2,
 /// @APIHOOK_END
 /// Do not modify code above this, since it will be automatically generated by the API again
 	EFST_MAX,