Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fan
- {
- public ushort UserX, UserY = 0;
- public ushort SourceX, SourceY = 0;
- public int Range = 0;
- public int Width = 0;
- public Fan(ushort x,ushort y, ushort x2, ushort y2, int nRange, int nWidth)
- {
- UserX = x;
- UserY = y;
- SourceX = x2;
- SourceY = y2;
- Range = nRange;
- Width = nWidth;
- }
- public bool IsInFan(ushort TargetX, ushort TargetY)
- {
- if (UserX == SourceX && UserY == SourceY)
- return false;
- if (GetDistance(UserX, UserY, TargetX, TargetY) > Range)
- return false;
- double PI = Math.PI;
- double fRadianDelta = (PI * Width / 180) / 2;
- float fCenterLine = GetRadian(UserX, UserY, TargetX, TargetY);
- float fTargetLine = GetRadian(SourceX, SourceY, UserX, UserY);
- float fDelta = Math.Abs(fCenterLine - fTargetLine);
- if (fDelta <= fRadianDelta || fDelta >= 2 * PI - fRadianDelta)
- return false;
- return true;
- }
- public static float GetRadian(float posSourX, float posSourY, float posTargetX, float posTargetY)
- {
- float PI = 3.1415926535f;
- float fDeltaX = posTargetX - posSourX;
- float fDeltaY = posTargetY - posSourY;
- float fDistance = SquareRootFloat(fDeltaX * fDeltaX + fDeltaY * fDeltaY);
- double fRadian = (float)Math.Asin(fDeltaX / fDistance);
- return (float)(fDeltaY > 0 ? (PI / 2 - fRadian) : (PI + fRadian + PI / 2));
- }
- unsafe static float SquareRootFloat(float number)
- {
- long i;
- float x, y;
- const float f = 1.5F;
- x = number * 0.5F;
- y = number;
- i = *(long*)&y;
- i = 0x5f3759df - (i >> 1);
- y = *(float*)&i;
- y = y * (f - (x * y * y));
- y = y * (f - (x * y * y));
- return number * y;
- }
- public static short GetDistance(ushort X, ushort Y, ushort X2, ushort Y2)
- {
- short x = 0;
- short y = 0;
- if (X >= X2)
- {
- x = (short)(X - X2);
- }
- else if (X2 >= X)
- {
- x = (short)(X2 - X);
- }
- if (Y >= Y2)
- {
- y = (short)(Y - Y2);
- }
- else if (Y2 >= Y)
- {
- y = (short)(Y2 - Y);
- }
- if (x > y)
- return x;
- else
- return y;
- }
- }
- how use the code:
- case (ushort)Role.Flags.SpellID.CrackingSwipe:
- {
- MsgSpellAnimation MsgSpell = new MsgSpellAnimation(obj.client.Player.UID
- , 0, obj.Attack->X, obj.Attack->Y, ClientSpell.ID
- , ClientSpell.Level, ClientSpell.UseSpellSoul);
- Algoritms.Fan fan = new Algoritms.Fan(obj.client.Player.X, obj.client.Player.Y, obj.Attack->X, obj.Attack->Y, 7, 160);
- uint Experience = 0;
- foreach (Role.IMapObj target in obj.client.Player.View.Roles(Role.MapObjectType.Monster))
- {
- MsgMonster.MonsterRole attacked = target as MsgMonster.MonsterRole;
- if (fan.IsInFan(target.X,target.Y))
- {
- if (CheckAttack.CanAttackMonster.Verified(obj.client, attacked, DBSpell))
- {
- MsgSpellAnimation.SpellObj AnimationObj;
- Calculate.Physical.OnMonster(obj.client.Player, attacked, DBSpell, out AnimationObj);
- AnimationObj.Damage = Calculate.Base.CalculateSoul(AnimationObj.Damage, ClientSpell.UseSpellSoul);
- Experience += ReceiveAttack.Monster.Execute(AnimationObj, obj.client, attacked);
- MsgSpell.Targets.Enqueue(AnimationObj);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement