ItemObject.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. using System.Drawing;
  2. using Server.MirDatabase;
  3. using Server.MirEnvir;
  4. using S = ServerPackets;
  5. namespace Server.MirObjects
  6. {
  7. public sealed class ItemObject : MapObject
  8. {
  9. public override ObjectType Race
  10. {
  11. get { return ObjectType.Item; }
  12. }
  13. public override string Name
  14. {
  15. get { return Item == null ? string.Empty : Item.Info.FriendlyName; }
  16. set { throw new NotSupportedException(); }
  17. }
  18. public override int CurrentMapIndex { get; set; }
  19. public override Point CurrentLocation { get; set; }
  20. public override MirDirection Direction
  21. {
  22. get { throw new NotSupportedException(); }
  23. set { throw new NotSupportedException(); }
  24. }
  25. public override ushort Level
  26. {
  27. get { throw new NotSupportedException(); }
  28. set { throw new NotSupportedException(); }
  29. }
  30. public override bool Blocking
  31. {
  32. get { return false; }
  33. }
  34. public uint Gold;
  35. public UserItem Item;
  36. public override int Health
  37. {
  38. get { throw new NotSupportedException(); }
  39. }
  40. public override int MaxHealth
  41. {
  42. get { throw new NotSupportedException(); }
  43. }
  44. public ItemObject(MapObject dropper, UserItem item, bool deathDrop = false)
  45. {
  46. if (deathDrop)//player dropped it when he died: allow for time to run back and pickup his drops
  47. ExpireTime = Envir.Time + Settings.PlayerDiedItemTimeOut * Settings.Minute;
  48. else
  49. ExpireTime = Envir.Time + Settings.ItemTimeOut * Settings.Minute;
  50. Item = item;
  51. if (Item.IsAdded)
  52. NameColour = Color.Cyan;
  53. else
  54. {
  55. if (item.Info.Grade == ItemGrade.None)
  56. NameColour = Color.White;
  57. if (item.Info.Grade == ItemGrade.Common)
  58. NameColour = Color.White;
  59. if (item.Info.Grade == ItemGrade.Rare)
  60. NameColour = Color.DeepSkyBlue;
  61. if (item.Info.Grade == ItemGrade.Legendary)
  62. NameColour = Color.DarkOrange;
  63. if (item.Info.Grade == ItemGrade.Mythical)
  64. NameColour = Color.Plum;
  65. if (item.Info.Grade == ItemGrade.Heroic)
  66. NameColour = Color.Red;
  67. }
  68. CurrentMap = dropper.CurrentMap;
  69. CurrentLocation = dropper.CurrentLocation;
  70. }
  71. public ItemObject(MapObject dropper, UserItem item, Point manualpoint)
  72. {
  73. ExpireTime = Envir.Time + Settings.ItemTimeOut * Settings.Minute;
  74. Item = item;
  75. if (Item.IsAdded)
  76. NameColour = Color.Cyan;
  77. else
  78. {
  79. if (item.Info.Grade == ItemGrade.None)
  80. NameColour = Color.White;
  81. if (item.Info.Grade == ItemGrade.Common)
  82. NameColour = Color.White;
  83. if (item.Info.Grade == ItemGrade.Rare)
  84. NameColour = Color.DeepSkyBlue;
  85. if (item.Info.Grade == ItemGrade.Legendary)
  86. NameColour = Color.DarkOrange;
  87. if (item.Info.Grade == ItemGrade.Mythical)
  88. NameColour = Color.Plum;
  89. if (item.Info.Grade == ItemGrade.Heroic)
  90. NameColour = Color.Red;
  91. }
  92. CurrentMap = dropper.CurrentMap;
  93. CurrentLocation = manualpoint;
  94. }
  95. public ItemObject(MapObject dropper, uint gold)
  96. {
  97. ExpireTime = Envir.Time + Settings.ItemTimeOut * Settings.Minute;
  98. Gold = gold;
  99. CurrentMap = dropper.CurrentMap;
  100. CurrentLocation = dropper.CurrentLocation;
  101. }
  102. public ItemObject(MapObject dropper, uint gold, Point manualLocation)
  103. {
  104. ExpireTime = Envir.Time + Settings.ItemTimeOut * Settings.Minute;
  105. Gold = gold;
  106. CurrentMap = dropper.CurrentMap;
  107. CurrentLocation = manualLocation;
  108. }
  109. public override void Process()
  110. {
  111. if (Envir.Time > ExpireTime)
  112. {
  113. CurrentMap.RemoveObject(this);
  114. Despawn();
  115. return;
  116. }
  117. if (Owner != null && Envir.Time > OwnerTime)
  118. Owner = null;
  119. base.Process();
  120. }
  121. public override void SetOperateTime()
  122. {
  123. long time = Envir.Time + 2000;
  124. if (OwnerTime < time && OwnerTime > Envir.Time)
  125. time = OwnerTime;
  126. if (ExpireTime < time && ExpireTime > Envir.Time)
  127. time = ExpireTime;
  128. if (PKPointTime < time && PKPointTime > Envir.Time)
  129. time = PKPointTime;
  130. if (LastHitTime < time && LastHitTime > Envir.Time)
  131. time = LastHitTime;
  132. if (EXPOwnerTime < time && EXPOwnerTime > Envir.Time)
  133. time = EXPOwnerTime;
  134. if (BrownTime < time && BrownTime > Envir.Time)
  135. time = BrownTime;
  136. for (int i = 0; i < ActionList.Count; i++)
  137. {
  138. if (ActionList[i].Time >= time && ActionList[i].Time > Envir.Time) continue;
  139. time = ActionList[i].Time;
  140. }
  141. for (int i = 0; i < PoisonList.Count; i++)
  142. {
  143. if (PoisonList[i].TickTime >= time && PoisonList[i].TickTime > Envir.Time) continue;
  144. time = PoisonList[i].TickTime;
  145. }
  146. for (int i = 0; i < Buffs.Count; i++)
  147. {
  148. if (Buffs[i].NextTime >= time && Buffs[i].NextTime > Envir.Time) continue;
  149. time = Buffs[i].NextTime;
  150. }
  151. if (OperateTime <= Envir.Time || time < OperateTime)
  152. OperateTime = time;
  153. }
  154. public bool Drop(int distance)
  155. {
  156. if (CurrentMap == null) return false;
  157. Cell best = null;
  158. int bestCount = 0;
  159. Point bestLocation = Point.Empty;
  160. for (int d = 0; d <= distance; d++)
  161. {
  162. for (int y = CurrentLocation.Y - d; y <= CurrentLocation.Y + d; y++)
  163. {
  164. if (y < 0) continue;
  165. if (y >= CurrentMap.Height) break;
  166. for (int x = CurrentLocation.X - d; x <= CurrentLocation.X + d; x += Math.Abs(y - CurrentLocation.Y) == d ? 1 : d*2)
  167. {
  168. if (x < 0) continue;
  169. if (x >= CurrentMap.Width) break;
  170. if (!CurrentMap.ValidPoint(x, y)) continue;
  171. bool movement = false;
  172. for (int i = 0; i < CurrentMap.Info.Movements.Count; i++)
  173. {
  174. MovementInfo info = CurrentMap.Info.Movements[i];
  175. if (info.Source != new Point(x,y)) continue;
  176. movement = true;
  177. break;
  178. }
  179. if (movement) continue;
  180. Cell cell = CurrentMap.GetCell(x, y);
  181. if (cell.Objects == null)
  182. {
  183. CurrentLocation = new Point(x, y);
  184. CurrentMap.AddObject(this);
  185. Spawned();
  186. return true;
  187. }
  188. int count = 0;
  189. bool blocking = false;
  190. for (int i = 0; i < cell.Objects.Count; i++)
  191. {
  192. MapObject ob = cell.Objects[i];
  193. if (ob.Blocking)
  194. {
  195. blocking = true;
  196. break;
  197. }
  198. if (ob.Race == ObjectType.Item)
  199. count++;
  200. }
  201. if (blocking || count >= Settings.DropStackSize) continue;
  202. if (count == 0)
  203. {
  204. CurrentLocation = new Point(x, y);
  205. CurrentMap.AddObject(this);
  206. Spawned();
  207. return true;
  208. }
  209. if (best == null || count < bestCount)
  210. {
  211. best = cell;
  212. bestCount = count;
  213. bestLocation = new Point(x, y);
  214. }
  215. }
  216. }
  217. }
  218. if (best == null)
  219. return false;
  220. CurrentLocation = bestLocation;
  221. CurrentMap.AddObject(this);
  222. Spawned();
  223. return true;
  224. }
  225. public bool DragonDrop(int distance)
  226. {
  227. if (CurrentMap == null) return false;
  228. Cell best = null;
  229. int bestCount = 0;
  230. Point bestLocation = Point.Empty;
  231. for (int d = 0; d <= distance; d++)
  232. {
  233. for (int y = CurrentLocation.Y + 3; y <= CurrentLocation.Y + (d * 2); y++)
  234. {
  235. if (y < 0) continue;
  236. if (y >= CurrentMap.Height) break;
  237. for (int x = CurrentLocation.X - d; x <= CurrentLocation.X + d; x += Math.Abs(y - CurrentLocation.Y) == d ? 1 : d * 2)
  238. {
  239. if (x < 0) continue;
  240. if (x >= CurrentMap.Width) break;
  241. if (!CurrentMap.ValidPoint(x, y)) continue;
  242. bool movement = false;
  243. for (int i = 0; i < CurrentMap.Info.Movements.Count; i++)
  244. {
  245. MovementInfo info = CurrentMap.Info.Movements[i];
  246. if (info.Source != new Point(x, y)) continue;
  247. movement = true;
  248. break;
  249. }
  250. if (movement) continue;
  251. Cell cell = CurrentMap.GetCell(x, y);
  252. if (cell.Objects == null)
  253. {
  254. CurrentLocation = new Point(x, y);
  255. CurrentMap.AddObject(this);
  256. Spawned();
  257. return true;
  258. }
  259. int count = 0;
  260. bool blocking = false;
  261. for (int i = 0; i < cell.Objects.Count; i++)
  262. {
  263. MapObject ob = cell.Objects[i];
  264. if (ob.Blocking)
  265. {
  266. blocking = true;
  267. break;
  268. }
  269. if (ob.Race == ObjectType.Item)
  270. count++;
  271. }
  272. if (blocking || count >= Settings.DropStackSize) continue;
  273. if (count == 0)
  274. {
  275. CurrentLocation = new Point(x, y);
  276. CurrentMap.AddObject(this);
  277. Spawned();
  278. return true;
  279. }
  280. if (best == null || count < bestCount)
  281. {
  282. best = cell;
  283. bestCount = count;
  284. bestLocation = new Point(x, y);
  285. }
  286. }
  287. }
  288. }
  289. if (best == null)
  290. return false;
  291. CurrentLocation = bestLocation;
  292. CurrentMap.AddObject(this);
  293. Spawned();
  294. return true;
  295. }
  296. public override Packet GetInfo()
  297. {
  298. if (Item != null)
  299. return new S.ObjectItem
  300. {
  301. ObjectID = ObjectID,
  302. Name = Item.Count > 1 ? string.Format("{0} ({1})", Name, Item.Count) : Name,
  303. NameColour = NameColour,
  304. Location = CurrentLocation,
  305. Image = Item.Image
  306. };
  307. return new S.ObjectGold
  308. {
  309. ObjectID = ObjectID,
  310. Gold = Gold,
  311. Location = CurrentLocation,
  312. };
  313. }
  314. public override void Process(DelayedAction action)
  315. {
  316. throw new NotSupportedException();
  317. }
  318. public override bool IsAttackTarget(HumanObject attacker)
  319. {
  320. throw new NotSupportedException();
  321. }
  322. public override bool IsAttackTarget(MonsterObject attacker)
  323. {
  324. throw new NotSupportedException();
  325. }
  326. public override int Attacked(HumanObject attacker, int damage, DefenceType type = DefenceType.ACAgility, bool damageWeapon = true)
  327. {
  328. throw new NotSupportedException();
  329. }
  330. public override int Attacked(MonsterObject attacker, int damage, DefenceType type = DefenceType.ACAgility)
  331. {
  332. throw new NotSupportedException();
  333. }
  334. public override int Struck(int damage, DefenceType type = DefenceType.ACAgility)
  335. {
  336. throw new NotSupportedException();
  337. }
  338. public override void ApplyPoison(Poison p, MapObject Caster = null, bool NoResist = false, bool ignoreDefence = true)
  339. {
  340. throw new NotSupportedException();
  341. }
  342. public override Buff AddBuff(BuffType type, MapObject owner, int duration, Stats stats, bool refreshStats = true, bool updateOnly = false, params int[] values)
  343. {
  344. throw new NotSupportedException();
  345. }
  346. public override bool IsFriendlyTarget(HumanObject ally)
  347. {
  348. throw new NotSupportedException();
  349. }
  350. public override bool IsFriendlyTarget(MonsterObject ally)
  351. {
  352. throw new NotSupportedException();
  353. }
  354. public override void Die()
  355. {
  356. throw new NotSupportedException();
  357. }
  358. public override void SendHealth(HumanObject player)
  359. {
  360. throw new NotSupportedException();
  361. }
  362. public override int Pushed(MapObject pusher, MirDirection dir, int distance)
  363. {
  364. throw new NotSupportedException();
  365. }
  366. public override void ReceiveChat(string text, ChatType type)
  367. {
  368. throw new NotSupportedException();
  369. }
  370. }
  371. }