Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.39 KB | None | 0 0
  1. public class Fan
  2. {
  3. public ushort UserX, UserY = 0;
  4. public ushort SourceX, SourceY = 0;
  5.  
  6. public int Range = 0;
  7. public int Width = 0;
  8.  
  9. public Fan(ushort x,ushort y, ushort x2, ushort y2, int nRange, int nWidth)
  10. {
  11. UserX = x;
  12. UserY = y;
  13.  
  14. SourceX = x2;
  15. SourceY = y2;
  16.  
  17. Range = nRange;
  18. Width = nWidth;
  19. }
  20.  
  21. public bool IsInFan(ushort TargetX, ushort TargetY)
  22. {
  23. if (UserX == SourceX && UserY == SourceY)
  24. return false;
  25.  
  26. if (GetDistance(UserX, UserY, TargetX, TargetY) > Range)
  27. return false;
  28.  
  29. double PI = Math.PI;
  30. double fRadianDelta = (PI * Width / 180) / 2;
  31. float fCenterLine = GetRadian(UserX, UserY, TargetX, TargetY);
  32. float fTargetLine = GetRadian(SourceX, SourceY, UserX, UserY);
  33. float fDelta = Math.Abs(fCenterLine - fTargetLine);
  34. if (fDelta <= fRadianDelta || fDelta >= 2 * PI - fRadianDelta)
  35. return false;
  36.  
  37. return true;
  38. }
  39. public static float GetRadian(float posSourX, float posSourY, float posTargetX, float posTargetY)
  40. {
  41. float PI = 3.1415926535f;
  42. float fDeltaX = posTargetX - posSourX;
  43. float fDeltaY = posTargetY - posSourY;
  44. float fDistance = SquareRootFloat(fDeltaX * fDeltaX + fDeltaY * fDeltaY);
  45.  
  46. double fRadian = (float)Math.Asin(fDeltaX / fDistance);
  47.  
  48. return (float)(fDeltaY > 0 ? (PI / 2 - fRadian) : (PI + fRadian + PI / 2));
  49. }
  50. unsafe static float SquareRootFloat(float number)
  51. {
  52. long i;
  53. float x, y;
  54. const float f = 1.5F;
  55.  
  56. x = number * 0.5F;
  57. y = number;
  58. i = *(long*)&y;
  59. i = 0x5f3759df - (i >> 1);
  60. y = *(float*)&i;
  61. y = y * (f - (x * y * y));
  62. y = y * (f - (x * y * y));
  63. return number * y;
  64. }
  65. public static short GetDistance(ushort X, ushort Y, ushort X2, ushort Y2)
  66. {
  67. short x = 0;
  68. short y = 0;
  69. if (X >= X2)
  70. {
  71. x = (short)(X - X2);
  72. }
  73. else if (X2 >= X)
  74. {
  75. x = (short)(X2 - X);
  76. }
  77. if (Y >= Y2)
  78. {
  79. y = (short)(Y - Y2);
  80. }
  81. else if (Y2 >= Y)
  82. {
  83. y = (short)(Y2 - Y);
  84. }
  85. if (x > y)
  86. return x;
  87. else
  88. return y;
  89. }
  90. }
  91.  
  92. how use the code:
  93.  
  94. case (ushort)Role.Flags.SpellID.CrackingSwipe:
  95. {
  96. MsgSpellAnimation MsgSpell = new MsgSpellAnimation(obj.client.Player.UID
  97. , 0, obj.Attack->X, obj.Attack->Y, ClientSpell.ID
  98. , ClientSpell.Level, ClientSpell.UseSpellSoul);
  99.  
  100. Algoritms.Fan fan = new Algoritms.Fan(obj.client.Player.X, obj.client.Player.Y, obj.Attack->X, obj.Attack->Y, 7, 160);
  101. uint Experience = 0;
  102. foreach (Role.IMapObj target in obj.client.Player.View.Roles(Role.MapObjectType.Monster))
  103. {
  104. MsgMonster.MonsterRole attacked = target as MsgMonster.MonsterRole;
  105. if (fan.IsInFan(target.X,target.Y))
  106. {
  107. if (CheckAttack.CanAttackMonster.Verified(obj.client, attacked, DBSpell))
  108. {
  109. MsgSpellAnimation.SpellObj AnimationObj;
  110. Calculate.Physical.OnMonster(obj.client.Player, attacked, DBSpell, out AnimationObj);
  111. AnimationObj.Damage = Calculate.Base.CalculateSoul(AnimationObj.Damage, ClientSpell.UseSpellSoul);
  112. Experience += ReceiveAttack.Monster.Execute(AnimationObj, obj.client, attacked);
  113. MsgSpell.Targets.Enqueue(AnimationObj);
  114.  
  115. }
  116. }
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement