Advertisement
SphinxGames

DyeTub Dont Edit

Dec 16th, 2017
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.79 KB | None | 0 0
  1. // ------------------- //
  2. // --- SphinxGames --- //
  3. // --- Dont Edit --- //
  4. // ------------------- //
  5. using Server.Mobiles;
  6. using Server.Multis;
  7. using Server.Targeting;
  8. using System;
  9.  
  10. namespace Server.Items
  11. {
  12. public class AwesomeDyeTub : DyeTub
  13. {
  14. [CommandProperty(AccessLevel.GameMaster)]
  15. public new virtual bool AllowRunebooks
  16. {
  17. get; set;
  18. }
  19. [CommandProperty(AccessLevel.GameMaster)]
  20. public virtual int CostRunebookDye
  21. {
  22. get; set;
  23. }
  24. [CommandProperty(AccessLevel.GameMaster)]
  25. public new virtual bool AllowFurniture
  26. {
  27. get; set;
  28. }
  29. [CommandProperty(AccessLevel.GameMaster)]
  30. public virtual int CostFurnitureDye
  31. {
  32. get; set;
  33. }
  34. [CommandProperty(AccessLevel.GameMaster)]
  35. public new virtual bool AllowStatuettes
  36. {
  37. get; set;
  38. }
  39. [CommandProperty(AccessLevel.GameMaster)]
  40. public virtual int CostStatuettesDye
  41. {
  42. get; set;
  43. }
  44. [CommandProperty(AccessLevel.GameMaster)]
  45. public new virtual bool AllowLeather
  46. {
  47. get; set;
  48. }
  49. [CommandProperty(AccessLevel.GameMaster)]
  50. public virtual int CostLeatherDye
  51. {
  52. get; set;
  53. }
  54. [CommandProperty(AccessLevel.GameMaster)]
  55. public virtual bool AllowMetal
  56. {
  57. get; set;
  58. }
  59. [CommandProperty(AccessLevel.GameMaster)]
  60. public virtual int CostMetalDye
  61. {
  62. get; set;
  63. }
  64. [CommandProperty(AccessLevel.GameMaster)]
  65. public virtual bool AllowBackpack
  66. {
  67. get; set;
  68. }
  69. [CommandProperty(AccessLevel.GameMaster)]
  70. public virtual int CostBackpackDye
  71. {
  72. get; set;
  73. }
  74. [CommandProperty(AccessLevel.GameMaster)]
  75. public virtual bool AllowContainer
  76. {
  77. get; set;
  78. }
  79. [CommandProperty(AccessLevel.GameMaster)]
  80. public virtual int CostContainerDye
  81. {
  82. get; set;
  83. }
  84. [CommandProperty(AccessLevel.GameMaster)]
  85. public virtual bool AllowEverything
  86. {
  87. get; set;
  88. }
  89. [CommandProperty(AccessLevel.GameMaster)]
  90. public virtual int CostMiscDye
  91. {
  92. get; set;
  93. }
  94. [CommandProperty(AccessLevel.GameMaster)]
  95. public new virtual bool AllowDyables
  96. {
  97. get; set;
  98. }
  99. [CommandProperty(AccessLevel.GameMaster)]
  100. public virtual int CostDyablesDye
  101. {
  102. get; set;
  103. }
  104. [CommandProperty(AccessLevel.GameMaster)]
  105. public override int Hue
  106. {
  107. get
  108. { return base.Hue; }
  109. set
  110. {
  111. if (DyedHue != value)
  112. DyedHue = value;
  113. base.Hue = value;
  114. }
  115. }
  116. [Constructable]
  117. public AwesomeDyeTub()
  118. {
  119. Name = "Awesome Dyeing Tub";
  120. }
  121.  
  122. public AwesomeDyeTub(Serial serial)
  123. : base(serial)
  124. {
  125. }
  126.  
  127. public override void Serialize(GenericWriter writer)
  128. {
  129. base.Serialize(writer);
  130.  
  131. writer.Write((int)0); // version
  132. writer.Write(AllowBackpack);
  133. writer.Write(AllowContainer);
  134. writer.Write(AllowDyables);
  135. writer.Write(AllowEverything);
  136. writer.Write(AllowFurniture);
  137. writer.Write(AllowLeather);
  138. writer.Write(AllowMetal);
  139. writer.Write(AllowRunebooks);
  140. writer.Write(AllowStatuettes);
  141.  
  142. writer.Write(CostBackpackDye);
  143. writer.Write(CostContainerDye);
  144. writer.Write(CostDyablesDye);
  145. writer.Write(CostFurnitureDye);
  146. writer.Write(CostLeatherDye);
  147. writer.Write(CostMetalDye);
  148. writer.Write(CostMiscDye);
  149. writer.Write(CostRunebookDye);
  150. writer.Write(CostStatuettesDye);
  151. }
  152.  
  153. public override void Deserialize(GenericReader reader)
  154. {
  155. base.Deserialize(reader);
  156.  
  157. int version = reader.ReadInt();
  158. AllowBackpack = reader.ReadBool();
  159. AllowContainer = reader.ReadBool();
  160. AllowDyables = reader.ReadBool();
  161. AllowEverything = reader.ReadBool();
  162. AllowFurniture = reader.ReadBool();
  163. AllowLeather = reader.ReadBool();
  164. AllowMetal = reader.ReadBool();
  165. AllowRunebooks = reader.ReadBool();
  166. AllowStatuettes = reader.ReadBool();
  167.  
  168. CostBackpackDye = reader.ReadInt();
  169. CostContainerDye = reader.ReadInt();
  170. CostDyablesDye = reader.ReadInt();
  171. CostFurnitureDye = reader.ReadInt();
  172. CostLeatherDye = reader.ReadInt();
  173. CostMetalDye = reader.ReadInt();
  174. CostMiscDye = reader.ReadInt();
  175. CostRunebookDye = reader.ReadInt();
  176. CostStatuettesDye = reader.ReadInt();
  177. }
  178.  
  179. public override void OnDoubleClick(Mobile from)
  180. {
  181. if (from.InRange(GetWorldLocation(), 1))
  182. {
  183. from.SendLocalizedMessage(TargetMessage);
  184. from.Target = new InternalTarget(this);
  185. }
  186. else
  187. {
  188. from.SendLocalizedMessage(500446); // That is too far away.
  189. }
  190. }
  191.  
  192. private class InternalTarget : Target
  193. {
  194. private readonly AwesomeDyeTub m_Tub;
  195. public InternalTarget(AwesomeDyeTub tub)
  196. : base(1, false, TargetFlags.None)
  197. {
  198. m_Tub = tub;
  199. }
  200. private void Dye(Mobile from, Item item, int cost)
  201. {
  202. if(from.TotalGold + Banker.GetBalance(from) < cost)
  203. {
  204. from.SendLocalizedMessage(1019022); // You do not have enough gold.
  205. from.SendMessage("To dye this item you need to pay " + cost + " pieces of gold");
  206. return;
  207. }
  208. item.Hue = m_Tub.DyedHue;
  209. from.PlaySound(0x23E);
  210. if (cost <= 0)
  211. return;
  212. //take gold
  213. int min = Math.Min(from.TotalGold, cost);
  214. if (min < cost)
  215. {
  216. Banker.Withdraw(from, cost - min);
  217. }
  218. from.Backpack.ConsumeTotal(typeof(Gold), min);
  219. from.SendMessage("You paid " + cost + " pieces of gold");
  220. }
  221. protected override void OnTarget(Mobile from, object targeted)
  222. {
  223. if (targeted is Item)
  224. {
  225. Item item = (Item)targeted;
  226.  
  227. if (item is IDyable && !(item is Container) && (m_Tub.AllowDyables || m_Tub.AllowEverything))
  228. {
  229. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  230. from.SendLocalizedMessage(500446); // That is too far away.
  231. else if (item.Parent is Mobile)
  232. from.SendLocalizedMessage(500861); // Can't Dye clothing that is being worn.
  233. else if (((IDyable)item).Dye(from, m_Tub))
  234. {
  235. Dye(from, item, m_Tub.CostDyablesDye);
  236. }
  237. }
  238. else if ((FurnitureAttribute.Check(item) || (item is PotionKeg)) && (m_Tub.AllowFurniture || m_Tub.AllowEverything))
  239. {
  240. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  241. {
  242. from.SendLocalizedMessage(500446); // That is too far away.
  243. }
  244. else
  245. {
  246. bool okay = (item.IsChildOf(from.Backpack));
  247.  
  248. if (!okay)
  249. {
  250. if (item.Parent == null)
  251. {
  252. BaseHouse house = BaseHouse.FindHouseAt(item);
  253.  
  254. if (house == null || (!house.IsLockedDown(item) && !house.IsSecure(item)))
  255. from.SendLocalizedMessage(501022); // Furniture must be locked down to paint it.
  256. else if (!house.IsCoOwner(from))
  257. from.SendLocalizedMessage(501023); // You must be the owner to use this item.
  258. else
  259. okay = true;
  260. }
  261. else
  262. {
  263. from.SendLocalizedMessage(1048135); // The furniture must be in your backpack to be painted.
  264. }
  265. }
  266. if (okay)
  267. {
  268. Dye(from, item, m_Tub.CostFurnitureDye);
  269. }
  270. }
  271. }
  272. else if ((item is Runebook || item is RecallRune) && (m_Tub.AllowRunebooks || m_Tub.AllowEverything))
  273. {
  274. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  275. {
  276. from.SendLocalizedMessage(500446); // That is too far away.
  277. }
  278. else if (!item.Movable)
  279. {
  280. from.SendLocalizedMessage(1049776); // You cannot dye runes or runebooks that are locked down.
  281. }
  282. else
  283. {
  284. Dye(from, item, m_Tub.CostRunebookDye);
  285. }
  286. }
  287. else if (item is MonsterStatuette && (m_Tub.AllowStatuettes || m_Tub.AllowEverything))
  288. {
  289. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  290. {
  291. from.SendLocalizedMessage(500446); // That is too far away.
  292. }
  293. else if (!item.Movable)
  294. {
  295. from.SendLocalizedMessage(1049779); // You cannot dye statuettes that are locked down.
  296. }
  297. else
  298. {
  299. Dye(from, item, m_Tub.CostStatuettesDye);
  300. }
  301. }
  302. else if (item is BaseArmor)
  303. {
  304. BaseArmor ba = item as BaseArmor;
  305. if (((ba.MaterialType == ArmorMaterialType.Leather || ba.MaterialType == ArmorMaterialType.Studded) || item is ElvenBoots || item is WoodlandBelt) && (m_Tub.AllowLeather || m_Tub.AllowEverything))
  306. {
  307. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  308. {
  309. from.SendLocalizedMessage(500446); // That is too far away.
  310. }
  311. else if (!item.Movable)
  312. {
  313. from.SendLocalizedMessage(1042419); // You may not dye leather items which are locked down.
  314. }
  315. else if (item.Parent is Mobile)
  316. {
  317. from.SendLocalizedMessage(500861); // Can't Dye clothing that is being worn.
  318. }
  319. else
  320. {
  321. Dye(from, item, m_Tub.CostLeatherDye);
  322. }
  323. }
  324. else if ((ba.MaterialType == ArmorMaterialType.Ringmail || ba.MaterialType == ArmorMaterialType.Chainmail || ba.MaterialType == ArmorMaterialType.Plate) && (m_Tub.AllowMetal || m_Tub.AllowEverything))
  325. {
  326. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  327. {
  328. from.SendLocalizedMessage(500446); // That is too far away.
  329. }
  330. else if (!item.Movable)
  331. {
  332. from.SendLocalizedMessage(1010093); // You may not dye items which are locked down.
  333. }
  334. else if (item.Parent is Mobile)
  335. {
  336. from.SendLocalizedMessage(500861); // Can't Dye clothing that is being worn.
  337. }
  338. else
  339. {
  340. Dye(from, item, m_Tub.CostMetalDye);
  341. }
  342. }
  343. }
  344. else if (item is Container)
  345. {
  346. Container c = item as Container;
  347. if (c is Backpack && c.Parent == from && (m_Tub.AllowBackpack || m_Tub.AllowEverything))
  348. {
  349. Dye(from, item, m_Tub.CostBackpackDye);
  350. }
  351. else if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(c.GetWorldLocation(), 1))
  352. {
  353. from.SendLocalizedMessage(500446); // That is too far away.
  354. }
  355. else if (!c.Movable)
  356. {
  357. from.SendLocalizedMessage(1010093); // You may not dye items which are locked down.
  358. }
  359. else if(m_Tub.AllowContainer || m_Tub.AllowEverything)
  360. {
  361. Dye(from, item, m_Tub.CostContainerDye);
  362. }
  363. }
  364. else if (m_Tub.AllowEverything)
  365. {
  366. if (!from.InRange(m_Tub.GetWorldLocation(), 1) || !from.InRange(item.GetWorldLocation(), 1))
  367. {
  368. from.SendLocalizedMessage(500446); // That is too far away.
  369. }
  370. else if (!item.Movable)
  371. {
  372. from.SendLocalizedMessage(1010093); // You may not dye items which are locked down.
  373. }
  374. else if (item.Parent is Mobile)
  375. {
  376. from.SendLocalizedMessage(500861); // Can't Dye clothing that is being worn.
  377. }
  378. else
  379. {
  380. Dye(from, item, m_Tub.CostMiscDye);
  381. }
  382. }
  383. else
  384. {
  385. from.SendLocalizedMessage(m_Tub.FailMessage);
  386. }
  387. }
  388. else
  389. {
  390. from.SendLocalizedMessage(m_Tub.FailMessage);
  391. }
  392. }
  393. }
  394. }
  395. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement