Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using BattleCore;
- using BattleCore.Events;
- namespace Drone
- {
- class WeaponTracker
- {
- //begins at cos 90 degrees and goes counterclockwise - light
- private double[] xChange = new[] { 0, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
- -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
- 0, 0.156, 0.309, 0.454, 0.588, 0.707, 0.848, 0.891, 0.951, 0.988,
- 1, 0.988, 0.951, 0.891, 0.809, 0.707, 0.588, 0.454, 0.309, 0.156 };
- //begins at sin 90 degrees and goes counterclockwise - light
- private double[] yChange = new[] { 1, 0.988, 0.951, 0.891, 0.809, 0.707, 0.588, 0.454, 0.309, 0.156,
- 0, -0.156, -0.309, -0.454, -0.588, -0.707, -0.809, -0.891, -0.951, -0.988,
- -1, -0.988, -0.951, -0.891, -0.809, -0.707, -0.588, -0.454, -0.309, -0.156,
- 0, 0.156, 0.309, 0.454, 0.588, 0.707, 0.809, 0.891, 0.951, 0.988 };
- ushort _Rate;
- public ushort Rate
- { set { _Rate = value; } }
- private ushort _BombAliveTime;
- private ushort _BombSpeed;
- private ushort _BombThrust;
- private ushort _BulletAliveTime;
- private ushort _BulletSpeed;
- private WeaponFired _LastFired;
- public WeaponFired LastFired
- {
- get { return _LastFired; }
- set { _LastFired = value; }
- }
- private List<WeaponFired> _ShotsFired = new List<WeaponFired>();
- private Queue<WeaponFired> _ExpiredShots = new Queue<WeaponFired>();
- public Queue<WeaponFired> ExpiredShots
- {
- get { return _ExpiredShots; }
- set { _ExpiredShots = value; }
- }
- public class WeaponFired
- {
- private string _PlayerName;
- public string PlayerName
- { get { return _PlayerName; } }
- private ushort _MapPositionX;
- public ushort MapPositionX
- {
- get { return _MapPositionX; }
- set { _MapPositionX = value ;}
- }
- private ushort _MapPositionY;
- public ushort MapPositionY
- {
- get { return _MapPositionY; }
- set { _MapPositionY = value; }
- }
- private short _VelocityX;
- public short VelocityX
- {
- get { return _VelocityX; }
- }
- private short _VelocityY;
- public short VelocityY
- {
- get { return _VelocityY; }
- }
- private WeaponTypes _Type;
- public WeaponTypes Type
- { get { return _Type; } }
- private byte _Lvl;
- private ushort _LifeTimer;
- public ushort LifeTimer
- {
- get { return _LifeTimer; }
- set { _LifeTimer = value; }
- }
- public void ConfigWeapon(string name, ushort mapX, ushort mapY, short velX, short velY, WeaponTypes weapon,byte lvl, ushort timer)
- {
- _PlayerName = name;
- _MapPositionX = mapX;
- _MapPositionY = mapY;
- _VelocityX = velX;
- _VelocityY = velY;
- _Type = weapon;
- _LifeTimer = timer;
- _Lvl = lvl;
- }
- }
- public void NewShot(PlayerPositionEvent p)
- {
- bool addY = true;
- bool addX = true;
- if (p.VelocityX > 50000)
- {
- addX = false;
- p.VelocityX = (ushort)(65536 - p.VelocityX);
- }
- if (p.VelocityY > 50000)
- {
- addY = false;
- p.VelocityY = (ushort)(65536 - p.VelocityY);
- }
- WeaponFired newshot = new WeaponFired();
- ushort velX = (ushort)(p.VelocityX + (WeaponSpeed(p.Weapon.Type) - WeaponThrust(p.Weapon.Type)) * xChange[p.ShipRotation]);
- ushort velY = (ushort)(p.VelocityY + (WeaponSpeed(p.Weapon.Type) - WeaponThrust(p.Weapon.Type)) * yChange[p.ShipRotation]);
- velX = (ushort)(velX / 10000.0 * _Rate);
- velY = (ushort)(velY / 10000.0 * _Rate);
- short vX;
- short vY;
- if (!addX)
- vX = (short)(velX * -1);
- else
- vX = (short)velX;
- if (!addY)
- vY = (short)(velY * -1);
- else
- vY = (short)velY;
- newshot.ConfigWeapon
- (p.PlayerName,
- p.MapPositionX,
- p.MapPositionY,
- vX,
- vY,
- p.Weapon.Type,
- p.Weapon.Level,
- GetAliveTime(p.Weapon.Type));
- _ShotsFired.Add(newshot);
- }
- public void SetVariables(ushort BombAliveTime, ushort BulletAliveTime, ushort BombSpeed,ushort BombThrust, ushort BulletSpeed )
- {
- _BombAliveTime = BombAliveTime;
- _BulletAliveTime = BulletAliveTime;
- _BombSpeed = BombSpeed;
- _BulletSpeed = BulletSpeed;
- _BombThrust = BombThrust;
- }
- public void UpdateWeaponTracker()
- {
- for (int i = 0; i < _ShotsFired.Count; i++)
- {
- _ShotsFired[i].LifeTimer -= _Rate;
- if (_ShotsFired[i].LifeTimer <= 0)
- {
- _ExpiredShots.Enqueue(_ShotsFired[i]);
- _ShotsFired.Remove(_ShotsFired[i]);
- }
- else
- {
- _ShotsFired[i].MapPositionX = (ushort)(_ShotsFired[i].MapPositionX + _ShotsFired[i].VelocityX);
- _ShotsFired[i].MapPositionY = (ushort)(_ShotsFired[i].MapPositionY + _ShotsFired[i].VelocityY);
- }
- LastFired = _ShotsFired[i];
- }
- }
- private ushort GetAliveTime(WeaponTypes weapon)
- {
- if (weapon.ToString().ToLower().Contains("bullet"))
- return _BulletAliveTime;
- else
- return _BombAliveTime;
- }
- private ushort WeaponThrust(WeaponTypes weapon)
- {
- if (weapon.ToString().ToLower().Contains("bomb"))
- return _BombThrust;
- else
- return 0;
- }
- private ushort WeaponSpeed(WeaponTypes weapon)
- {
- string wep = weapon.ToString().ToLower();
- if (wep.Contains("bomb") || wep.Contains("thor"))
- return _BombSpeed;
- else
- return _BulletSpeed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment