PsyOps

Drone.WeaponTracker

Jun 25th, 2012
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.91 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. using BattleCore;
  7. using BattleCore.Events;
  8.  
  9. namespace Drone
  10. {
  11.     class WeaponTracker
  12.     {
  13.         //begins at cos 90 degrees and goes counterclockwise - light
  14.         private double[] xChange = new[] {  0, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
  15.                         -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
  16.                          0,  0.156,  0.309,  0.454,  0.588,  0.707,  0.848,  0.891,  0.951,  0.988,
  17.                          1,  0.988,  0.951,  0.891,  0.809,  0.707,  0.588,  0.454,  0.309,  0.156 };
  18.         //begins at sin 90 degrees and goes counterclockwise - light
  19.         private double[] yChange = new[] {  1,  0.988,  0.951,  0.891,  0.809,  0.707,  0.588,  0.454,  0.309,  0.156,
  20.                          0, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
  21.                         -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
  22.                          0,  0.156,  0.309,  0.454,  0.588,  0.707,  0.809,  0.891,  0.951,  0.988 };
  23.  
  24.         ushort _Rate;
  25.         public ushort Rate
  26.         { set { _Rate = value; } }
  27.         private ushort _BombAliveTime;
  28.         private ushort _BombSpeed;
  29.         private ushort _BombThrust;
  30.         private ushort _BulletAliveTime;
  31.         private ushort _BulletSpeed;
  32.  
  33.         private WeaponFired _LastFired;
  34.         public WeaponFired LastFired
  35.         {
  36.             get { return _LastFired; }
  37.             set { _LastFired = value; }
  38.         }
  39.         private List<WeaponFired> _ShotsFired = new List<WeaponFired>();
  40.         private Queue<WeaponFired> _ExpiredShots = new Queue<WeaponFired>();
  41.         public Queue<WeaponFired> ExpiredShots
  42.         {
  43.             get { return _ExpiredShots; }
  44.             set { _ExpiredShots = value; }
  45.         }
  46.  
  47.         public class WeaponFired
  48.         {
  49.             private string _PlayerName;
  50.             public string PlayerName
  51.             { get { return _PlayerName; } }
  52.             private ushort _MapPositionX;
  53.             public ushort MapPositionX
  54.             {
  55.                 get { return _MapPositionX; }
  56.                 set { _MapPositionX = value ;}
  57.             }
  58.             private ushort _MapPositionY;
  59.             public ushort MapPositionY
  60.             {
  61.                 get { return _MapPositionY; }
  62.                 set { _MapPositionY = value; }
  63.             }
  64.             private short _VelocityX;
  65.             public short VelocityX
  66.             {
  67.                 get { return _VelocityX; }
  68.             }
  69.             private short _VelocityY;
  70.             public short VelocityY
  71.             {
  72.                 get { return _VelocityY; }
  73.             }
  74.             private WeaponTypes _Type;
  75.             public WeaponTypes Type
  76.             { get { return _Type; } }
  77.             private byte _Lvl;
  78.             private ushort _LifeTimer;
  79.             public ushort LifeTimer
  80.             {
  81.                 get { return _LifeTimer; }
  82.                 set { _LifeTimer = value; }
  83.             }
  84.  
  85.             public void ConfigWeapon(string name, ushort mapX, ushort mapY, short velX, short velY, WeaponTypes weapon,byte lvl, ushort timer)
  86.             {
  87.                 _PlayerName = name;
  88.                 _MapPositionX = mapX;
  89.                 _MapPositionY = mapY;
  90.                 _VelocityX = velX;
  91.                 _VelocityY = velY;
  92.                 _Type = weapon;
  93.                 _LifeTimer = timer;
  94.                 _Lvl = lvl;
  95.             }
  96.         }
  97.  
  98.         public void NewShot(PlayerPositionEvent p)
  99.         {
  100.             bool addY = true;
  101.             bool addX = true;
  102.  
  103.             if (p.VelocityX > 50000)
  104.             {
  105.                 addX = false;
  106.                 p.VelocityX = (ushort)(65536 - p.VelocityX);
  107.             }
  108.             if (p.VelocityY > 50000)
  109.             {
  110.                 addY = false;
  111.                 p.VelocityY = (ushort)(65536 - p.VelocityY);
  112.             }
  113.  
  114.             WeaponFired newshot = new WeaponFired();
  115.             ushort velX = (ushort)(p.VelocityX + (WeaponSpeed(p.Weapon.Type) - WeaponThrust(p.Weapon.Type)) * xChange[p.ShipRotation]);
  116.             ushort velY = (ushort)(p.VelocityY + (WeaponSpeed(p.Weapon.Type) - WeaponThrust(p.Weapon.Type)) * yChange[p.ShipRotation]);
  117.             velX = (ushort)(velX / 10000.0 * _Rate);
  118.             velY = (ushort)(velY / 10000.0 * _Rate);
  119.  
  120.             short vX;
  121.             short vY;
  122.  
  123.             if (!addX)
  124.                 vX = (short)(velX * -1);
  125.             else
  126.                 vX = (short)velX;
  127.             if (!addY)
  128.                 vY = (short)(velY * -1);
  129.             else
  130.                 vY = (short)velY;
  131.        
  132.             newshot.ConfigWeapon
  133.                 (p.PlayerName,
  134.                 p.MapPositionX,
  135.                 p.MapPositionY,
  136.                 vX,
  137.                 vY,
  138.                 p.Weapon.Type,
  139.                 p.Weapon.Level,
  140.                 GetAliveTime(p.Weapon.Type));
  141.  
  142.             _ShotsFired.Add(newshot);
  143.         }
  144.  
  145.         public void SetVariables(ushort BombAliveTime, ushort BulletAliveTime, ushort BombSpeed,ushort BombThrust, ushort BulletSpeed )
  146.         {
  147.             _BombAliveTime = BombAliveTime;
  148.             _BulletAliveTime = BulletAliveTime;
  149.             _BombSpeed = BombSpeed;
  150.             _BulletSpeed = BulletSpeed;
  151.             _BombThrust = BombThrust;
  152.         }
  153.         public void UpdateWeaponTracker()
  154.         {
  155.             for (int i = 0; i < _ShotsFired.Count; i++)
  156.             {
  157.                 _ShotsFired[i].LifeTimer -= _Rate;
  158.  
  159.                 if (_ShotsFired[i].LifeTimer <= 0)
  160.                 {
  161.                     _ExpiredShots.Enqueue(_ShotsFired[i]);
  162.                     _ShotsFired.Remove(_ShotsFired[i]);
  163.                 }
  164.                 else
  165.                 {
  166.                     _ShotsFired[i].MapPositionX = (ushort)(_ShotsFired[i].MapPositionX + _ShotsFired[i].VelocityX);
  167.                     _ShotsFired[i].MapPositionY = (ushort)(_ShotsFired[i].MapPositionY + _ShotsFired[i].VelocityY);
  168.                 }
  169.                 LastFired = _ShotsFired[i];
  170.             }
  171.         }
  172.         private ushort GetAliveTime(WeaponTypes weapon)
  173.         {
  174.             if (weapon.ToString().ToLower().Contains("bullet"))
  175.                 return _BulletAliveTime;
  176.             else
  177.                 return _BombAliveTime;
  178.         }
  179.         private ushort WeaponThrust(WeaponTypes weapon)
  180.         {
  181.             if (weapon.ToString().ToLower().Contains("bomb"))
  182.                 return _BombThrust;
  183.             else
  184.                 return 0;
  185.         }
  186.         private ushort WeaponSpeed(WeaponTypes weapon)
  187.         {
  188.             string wep = weapon.ToString().ToLower();
  189.             if (wep.Contains("bomb") || wep.Contains("thor"))
  190.                 return _BombSpeed;
  191.             else
  192.                 return _BulletSpeed;
  193.         }
  194.     }
  195. }
Advertisement
Add Comment
Please, Sign In to add comment