ZoneObject.Item.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using CommonAI.Zone;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. namespace CommonAI.ZoneClient
  7. {
  8. public class ZoneItem : ZoneObject
  9. {
  10. public readonly ItemTemplate Info;
  11. public readonly SyncItemInfo SyncInfo;
  12. public int Force { get; private set; }
  13. public string Alias { get; private set; }
  14. public int ExpireTimeMS { get; private set; }
  15. public int TotalTimeMS { get; private set; }
  16. public int PassTimeMS { get { return TotalTimeMS - ExpireTimeMS; } }
  17. public override string Name { get { return null; } }
  18. public override string DisplayName { get { return Info.Name; } }
  19. public override float RadiusSize { get { return Info.BodySize; } }
  20. public ZoneItem(ItemTemplate info, SyncItemInfo syn, ZoneLayer parent, AddItemEvent add)
  21. : base(syn.ObjectID, parent)
  22. {
  23. this.SyncInfo = syn;
  24. this.mPos.SetX(syn.x);
  25. this.mPos.SetY(syn.y);
  26. this.Direction = syn.direction;
  27. this.Info = info;
  28. this.Force = syn.Force;
  29. this.Alias = syn.Alias;
  30. this.ExpireTimeMS = syn.ItemExpireTimeMS;
  31. this.TotalTimeMS = syn.ItemTotalTimeMS;
  32. }
  33. protected internal override void OnAdded()
  34. {
  35. base.OnAdded();
  36. if (Info.DropEffect != null)
  37. {
  38. Parent.PreQueueEvent(new AddEffectEvent(0, X, Y, Direction, Info.DropEffect));
  39. }
  40. }
  41. internal protected override void DoEvent(ObjectEvent e)
  42. {
  43. if (e is ObjectForceSyncPosEvent)
  44. {
  45. var oe = e as ObjectForceSyncPosEvent;
  46. this.ForceSyncPos(oe.X, oe.Y);
  47. this.Direction = oe.Direction;
  48. }
  49. }
  50. internal protected override void Update()
  51. {
  52. if (ExpireTimeMS > 0)
  53. {
  54. ExpireTimeMS -= Parent.CurrentIntervalMS;
  55. if (ExpireTimeMS < 0)
  56. {
  57. ExpireTimeMS = 0;
  58. }
  59. }
  60. }
  61. }
  62. }