BattleMgr_Update.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using CommonAI.Zone;
  2. using CommonAI.ZoneClient;
  3. using CommonLang.Geometry;
  4. using ET.Client;
  5. using ET.EventType;
  6. using System;
  7. namespace ET
  8. {
  9. //战斗中,每一帧要干的活
  10. public partial class BattleMgr
  11. {
  12. public void doUpdate()
  13. {
  14. SyncUnitPos();
  15. }
  16. private Vector3 VecTmp = new Vector3();
  17. private void SyncUnitPos()
  18. {
  19. if (UnitMgr.Instance != null)
  20. {
  21. foreach (var obj in UnitMgr.Instance.AllUnits)
  22. {
  23. if (obj is BattleUnit)
  24. {
  25. var zo = obj.ZoneObject;
  26. VecTmp.Set(zo.X, zo.Y, zo.Z);
  27. if (!VecTmp.Equal(obj.LastPos, 0.01f) || MathF.Abs(obj.LastRotation - zo.Direction) > 0.01f)
  28. {
  29. EventSystem.Instance.Publish<SyncUnitPosEvent>(SyncUnitPosEvent.Static.Clone(zo.ObjectID, VecTmp, zo.Direction));
  30. obj.LastPos.Set(VecTmp);
  31. obj.LastRotation = zo.Direction;
  32. }
  33. }
  34. else if(obj is BattleSpell)
  35. {
  36. var zs = obj.ZoneObject as ZoneSpell;
  37. /*
  38. if (zs.Info.MType == CommonAI.Zone.SpellTemplate.MotionType.Foxfire)
  39. {
  40. if (zs.Target.ObjectID == 0 || zs.PassTimeMS > zs.Info.LifeTimeMS + 5000)
  41. {
  42. PostMsg2Layer(new RemoveObjectEvent(zs.ObjectID));
  43. return;
  44. }
  45. }
  46. else if (zs.PassTimeMS > zs.Info.LifeTimeMS + 150)
  47. {
  48. PostMsg2Layer(new RemoveObjectEvent(zs.ObjectID));
  49. return;
  50. }*/
  51. VecTmp.Set(zs.X, zs.Y, zs.Z);
  52. if (!VecTmp.Equal(obj.LastPos, 0.01f) || MathF.Abs(obj.LastRotation - zs.Direction) > 0.01f)
  53. {
  54. EventSystem.Instance.Publish<SyncUnitPosEvent>(SyncUnitPosEvent.Static.Clone(zs.ObjectID, VecTmp, zs.Direction, zs.RotationX));
  55. obj.LastPos.Set(VecTmp);
  56. obj.LastRotation = zs.Direction;
  57. }
  58. }
  59. }
  60. }
  61. }
  62. }
  63. }