Ejemplo n.º 1
0
 void OnBulletCollision(ProjectileData other)
 {
     if (player != null)
     {
         player.Graze();
     }
 }
Ejemplo n.º 2
0
 public override void Init(ProjectileData data, Vector3 objective, float damageMultiplier)
 {
     m_initialPoint     = transform.position;
     m_objective        = objective;
     m_data             = (ArtilleryData)data;
     m_damageMultiplier = damageMultiplier;
 }
Ejemplo n.º 3
0
        public static void SendProjectile(ProjectileData payload) //.PROJECTILE
        {
            NetDataWriter writer = new NetDataWriter();

            writer.Put(".PROJECTILE " + JsonConvert.SerializeObject(payload));
            Engine.networkClient.send(writer, DeliveryMethod.ReliableUnordered);
        }
Ejemplo n.º 4
0
    protected override bool Shoot(ProjectileData _projData, Vector2 _direction, GameObject[] _shootTransform, bool b = false)
    {
        if (!bossDefeated)
        {
            if (shootCooldown >= shootRate)
            {
                for (int i = 0; i < _shootTransform.Length; i++)
                {
                    Vector3 shootDir = new Vector3(Player.instance.transform.position.x, Player.instance.transform.position.y) - _shootTransform[i].transform.position;
                    if (shootDir.x > 0)
                    {
                        shootDir.x = Mathf.Clamp(shootDir.x, 0, 7.5f);
                    }
                    else
                    {
                        shootDir.x = Mathf.Clamp(shootDir.x, -7.5f, 0);
                    }

                    Projectile p = ProjectileManager.instance.PoolingProjectile(_shootTransform[i].transform);
                    p.SetProjectile(_projData, shootDir);
                    p.transform.position = _shootTransform[i].transform.position;
                    p.gameObject.SetActive(true);
                    shootCooldown = 0;
                    p.GetComponentInChildren <ParticleSystem>().startLifetime = .1f;
                }
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 5
0
        /// <summary>
        /// Fires the weapon. Used for weapons which are fired by this client. Sends fire request to server. Generates a list of projectileIDs to be sent to the server.
        /// </summary>
        /// <param name="projectileIDs"></param>
        /// <param name="rotation"></param>
        /// <param name="charge"></param>
        public virtual bool Fire_LocalOrigin(float rotation, byte charge, bool changeEnergy)
        {
            if (!Fire(changeEnergy))
            {
                return(false);
            }


            var projectileIDs = new List <int>(Stats.NumProjectiles);

            for (int i = 0; i < Stats.NumProjectiles; i++)
            {
                projectileIDs.Add(Utilities.NextUnique());//Ensures that all IDs are unique
            }

            List <Vector2> projectilePositions  = GeneratePositions(rotation);
            List <float>   projectileRotations  = GenerateRotations(rotation);
            List <Vector2> projectileVelocities = GenerateVelocityOffsets(rotation);

            ProjectileRequest pr = new ProjectileRequest(HoldingObj, rotation, Slot, charge, true, Stats.ProjectileType);

            for (int i = 0; i < projectileIDs.Count; i++)
            {
                ProjectileData d = new ProjectileData(projectilePositions[i], projectileVelocities[i], projectileRotations[i], projectileIDs[i]);
                pr.AddProjectile(d);
            }



            _projectileManager.CreateProjectiles(pr);

            return(true);
        }
Ejemplo n.º 6
0
 void Start()
 {
     shootingCooldown         = new Cooldown();
     projectileData           = new ProjectileData();
     projectileData.position  = new Position();
     projectileData.direction = new Position();
 }
Ejemplo n.º 7
0
    public ProjectileType(int type, int subTypeCount)
    {
        modifierType         = type;
        modifierSubTypeCount = subTypeCount;

        projectileDatas = new ProjectileData[subTypeCount];
    }
Ejemplo n.º 8
0
    void BaseInit(IWeapon shooter, float shotTime, ProjectileData data, EffectData effect)
    {
        enabled = true;

        _data      = data;
        _effect    = effect;
        _parent    = shooter;
        _id        = _currentID++;
        _exploded  = false;
        _deathTime = shotTime + data.lifetime + Random.Range(0, data.lifetimeVariation);
        _bounces   = 0;

        _activeSubweaponCount = 0;
        _subweaponCreated     = new bool[data.subweapons.Count];

        if (_deathTime <= shotTime)
        {
            Kill(DeathCause.Timeout, shotTime);
            return;
        }

        //TODO: add subweapons after pos is set?
        for (int i = 0; i < data.subweapons.Count; i++)
        {
            SubweaponData subweapon = data.subweapons[i];
            if (subweapon.activation.onStartup)
            {
                AddSubweapon(subweapon, shotTime, i);
            }
        }

        _rigidbody.detectCollisions = true;
        _trailRenderer.enabled      = true;
        _renderer.enabled           = true;
    }
Ejemplo n.º 9
0
 public void shootProjectile(ProjectileData projData)
 {
     try {
         PlayerGameState ownGameState = getOwnGameState();
         Monster         target       = ownGameState.monsterRef[projData.targetSerializeId];
         Vector2         source       = ownGameState.viewMapRef.getTile(projData.startCoord.row, projData.startCoord.col).transform.position;
         Projectile      proj         = projectilePool.GetProjectile();
         proj.projData       = projData;
         proj.target         = target;
         proj.source         = source;
         proj.spriteR.sprite = TowerR.getById(projData.towerId).projectileSprite;
         proj.splashR.color  = TowerR.getById(projData.towerId).splashColor;
         if (!getOpponentGameState().sendMapData)
         {
             SoundManager.instance.PlayShoot(TowerR.getById(projData.towerId).shootingSound);
         }
         proj.Initialize();
         if (getOwnGameState().sendMapData&& PhotonNetwork.connected)
         {
             photonView.RPC("shootViewProjectile", PhotonTargets.Others, projData.serialize());
         }
     } catch (KeyNotFoundException e) {
         Debug.LogWarning(e.StackTrace);
     }
 }
Ejemplo n.º 10
0
    /// <summary>
    ///
    /// </summary>
    /// <param name="penData"></param>
    /// <returns>bool willPenetrate, float penetrationDepth</returns>
    protected virtual Tuple <bool, float> WillPen(TerminalBallisticsData penData)
    {
        ProjectileData          projData         = penData.projectile.projectileData;
        VirtualPhysicsTransform physicsTransform = penData.projectile.physicsTransform;

        //(assuming 0 degrees is hitting straight on)
        //If angleWeHitTarget >= 80 degrees, then richochet
        if (Vector3.Angle(physicsTransform.Velocity.normalized, -penData.hitInfo.normal) >= 80)
        {
            return(new Tuple <bool, float>(false, 0.0f));           //When Unity supports C#7, switch this to the new syntax
        }
        //Otherwise, do some more testing

        float targetDensity = 1000.0f;         //{TODO} Hook this up

        //tex:
        //$$stoppingDist=\sqrt[3]{\frac{projMass * initVel^2}{targetDensity*projCrossArea * projDragCoefficient}} $$
        //Heavily simplified model

        float stoppingDist =
            Mathf.Pow(                                                                                                                    //3rd root
                (projData.bulletMass * physicsTransform.VelocityMagnitude * physicsTransform.VelocityMagnitude)                           //{TODO} Make velocity relative to target
                /
                (targetDensity * projData.CrossSectionalArea * projData.GetDragCoefficient(physicsTransform.Velocity.magnitude / 343.0f)) //{TODO} Rewrite correctly!
                , (1.0f / 3.0f)
                );

        return(new Tuple <bool, float>(stoppingDist >= projData.noseLength, stoppingDist));
    }
Ejemplo n.º 11
0
    protected virtual bool Shoot(ProjectileData _projData, Vector2 _direction, GameObject[] _shootTransform, bool special = false)
    {
        if (shootCooldown >= shootRate)
        {
            for (int i = 0; i < _shootTransform.Length; i++)
            {
                Projectile p;
                if (special)
                {
                    p = ProjectileManager.instance.PoolingEnemyProjectile(_shootTransform[i].transform);
                }
                else
                {
                    p = ProjectileManager.instance.PoolingProjectile(_shootTransform[i].transform);
                }

                p.SetProjectile(_projData, _direction);
                p.transform.position = _shootTransform[i].transform.position;
                p.gameObject.SetActive(true);
                shootCooldown = 0;
                if (tag == "Enemy")
                {
                    p.GetComponentInChildren <ParticleSystem>().startLifetime = .15f;
                }
                else
                {
                    p.GetComponentInChildren <ParticleSystem>().startLifetime = .2f;
                }
            }
            return(true);
        }
        return(false);
    }
Ejemplo n.º 12
0
    private void SpawnNewProjectiles(BattleMoveOutputSingle[] results)
    {
        foreach (var result in results)
        {
            if (result.ProjVelosity != null)
            {
                UnitData unit = this.units.Single(x => x.ID == result.ID);

                SpellCooldown spellCD = unit.SpellCooldowns.FirstOrDefault(x => x.Spell == "fireball");

                if (spellCD.CurrentIteration <= 0)
                {
                    spellCD.CurrentIteration = spellCD.MaxIteration;

                    ProjectileData proj = new ProjectileData()
                    {
                        Demage           = 20,
                        Direction        = result.ProjVelosity.Value,
                        Position         = unit.Position,
                        Radious          = (Fix64)1f,
                        Team             = unit.Team,
                        Type             = result.ProjType,
                        CurrentIteration = 0,
                        MaxIteration     = this.projDuration,
                    };

                    this.projectiles.Add(proj);
                }
            }
        }
    }
    new protected void Start()
    {
        _transform = GetComponent <Transform>();
        _projData  = GetComponent <ProjectileData>();

        base.Start();
    }
 protected virtual void ProjDataInit(ref ProjectileData data)
 {
     Data.Clone(data);
     Data.TypeProjectile = (int)ProjectileType;
     m_LifeTime          = Data.LifeTime;
     //m_LifeTime = data.LifeTime;
 }
Ejemplo n.º 15
0
    /// <summary>
    /// Checks the collision.
    /// </summary>
    /// <returns>The collision.</returns>
    /// <param name="projectile">Projectile.</param>
    /// <param name="movementVector">Movement vector.</param>
    public override RaycastHit2D[] CheckCollision(ProjectileData projectile, Vector3 movementVector)
    {
        Vector2 origin = Util.To2D(projectile.Position) + Util.ComponentProduct2(projectile.Scale, boxOffset);
        Vector2 size   = Util.ComponentProduct2(projectile.Scale, boxSize);

        return(Physics2D.BoxCastAll(origin, size, projectile.Rotation.eulerAngles.z, movementVector, movementVector.magnitude));
    }
Ejemplo n.º 16
0
    /// <summary>
    /// Checks the collision.
    /// </summary>
    /// <returns>The collision.</returns>
    /// <param name="projectile">Projectile.</param>
    /// <param name="movementVector">Movement vector.</param>
    public override RaycastHit2D[] CheckCollision(ProjectileData projectile, Vector3 movementVector)
    {
        Vector2 origin = Util.To2D(projectile.Position) + Util.ComponentProduct2(projectile.Scale, circleOffset);
        float   size   = circleRadius * MinAbsScale(projectile.Scale.x, projectile.Scale.y, projectile.Scale.z);

        return(Physics2D.CircleCastAll(origin, size, movementVector, movementVector.magnitude, projectile.Group.Layer));
    }
Ejemplo n.º 17
0
    public void Shoot(Entity owner, Vector2 startingFacing)
    {
        if (readyToFire)
        {
            audio.Play();
            GameObject bullet = new GameObject("Bullet");
            Destroy(bullet, 10.0f);

            bullet.transform.position = weaponFirePoint.transform.position;
            float angle = Mathf.Atan2(startingFacing.y, startingFacing.x) * Mathf.Rad2Deg;
            currentSpread             = Random.Range(minSpread, maxSpread);
            angle                    += Random.Range(-currentSpread, currentSpread);
            bullet.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);

            SpriteRenderer renderer = bullet.AddComponent <SpriteRenderer>();
            renderer.sprite           = Resources.Load <Sprite>("Sprites/Entity/sci-fi-bullet");
            renderer.sortingLayerName = "Bullets";

            BoxCollider2D collider = bullet.AddComponent <BoxCollider2D>();
            collider.isTrigger = true;

            Rigidbody2D rb2d = bullet.AddComponent <Rigidbody2D>();
            rb2d.gravityScale = 0;
            rb2d.velocity     = bullet.transform.right * 20.0f;

            ProjectileData projectileData = bullet.AddComponent <ProjectileData>();
            projectileData.SetProjectileData(owner);
            projectileData.SetDamage(damage);
            projectileData.SetBulletDrop(bulletDrop);

            currentAmmo--;
            readyToFire = false;
        }
    }
Ejemplo n.º 18
0
        private static ProjectileData ParseProjectileData(Dictionary <string, object> data)
        {
            ProjectileData projectile = new ProjectileData();

            projectile.LifeTime = int.Parse(data["lifeTime"].ToString());

            projectile.AreaBoxSizeX = int.Parse(data["areaBoxSizeX"].ToString());

            projectile.AreaBoxSizeY = int.Parse(data["areaBoxSizeY"].ToString());

            projectile.AreaBoxSizeZ = int.Parse(data["areaBoxSizeZ"].ToString());

            projectile.TargetingList = new List <Targeting>();

            if (data.ContainsKey("TargetingList"))
            {
                foreach (var targetingListData in (List <Dictionary <string, object> >)data["TargetingList"])
                {
                    if (!targetingListData.ContainsKey("Targeting"))
                    {
                        continue;
                    }

                    foreach (var targetingData in (List <Dictionary <string, object> >)targetingListData["Targeting"])
                    {
                        projectile.TargetingList.Add(ParseTargeting(targetingData));
                    }
                }
            }

            return(projectile);
        }
Ejemplo n.º 19
0
    public static AnimationCurve GenerateDragCurve(
        ProjectileData projData,
        int iterations        = 100,
        float upperSpeedRange = 4f         //In mach
        )
    {
        AnimationCurve graph      = new AnimationCurve();
        MCDRAG         dragCalcor = new MCDRAG(); //{TODO} Should I make this a static field instead of recreating it?

        dragCalcor.SetIterations(iterations, upperSpeedRange, 0.0, true);

        dragCalcor.InputValues(
            projData.bulletDiameter,
            projData.bulletLength / projData.bulletDiameter,
            projData.noseLength / projData.bulletDiameter,
            projData.ogiveTangentRadius / projData.ogiveRadius,
            projData.boatTailLength / projData.bulletDiameter,
            projData.baseDiameter / projData.bulletDiameter,
            projData.meplatDiameter / projData.bulletDiameter,
            projData.hasDriveBand ? projData.driveBandDiameter / projData.bulletDiameter : 1,
            projData.centerOfMass / projData.bulletDiameter,
            projData.boundaryLayerCode,
            ""
            );

        dragCalcor.GenerateCoefficients();

        for (int i = 0; i < dragCalcor.M.Length; i++)
        {
            graph.AddKey((float)dragCalcor.M[i], (float)dragCalcor.C1[i]);
        }

        return(graph);
    }
Ejemplo n.º 20
0
 public Beam(GameObject target, Vector2 beamOrigin, ProjectileData projectileData) :
     base(target, beamOrigin, projectileData)
 {
     Opacity       = 0;
     Size          = new Vector2(5, (target.WorldPosition - beamOrigin).Length());
     LocalPosition = (target.WorldPosition + beamOrigin) * 0.5f;
 }
Ejemplo n.º 21
0
    public override void InitStats()
    {
        AttackData = new AttackData(15);

        // Main: Cooldown
        Main_CD.EndTime = new FloatStat(0.7f, min: 0.01f);
        // Main: Mana Usage
        Main_ManaUsage = new FloatStat(4f, min: 0);
        // Main: Ice Bolt
        Main_IceBoltData = new ProjectileData()
        {
            moveSpeed  = new FloatStat(25f, min: 0f),
            travelDist = new FloatStat(0f, min: 0f, max: 10f)
        };

        // Sub: Cast Time
        Sub_CastTime.EndTime = new FloatStat(0.2f, min: 0f);
        // Sub: Damage
        Sub_DamageTick.EndTime = new FloatStat(0.5f, min: 0f);
        Sub_DamagePerTick      = new AttackData(2f, gameObject);
        // Sub: Mana Usage
        Sub_ManaUsageTick.EndTime = new FloatStat(0.25f, min: 0f);
        Sub_ManaUsagePerTick      = new FloatStat(0.5f, min: 0f);

        // Special: Cast Time
        Spec_CastTime.EndTime = new FloatStat(0.15f, min: 0f);
        // Special: Frozen Soul Usage
        Spec_FrozenSoulUsage = new IntStat(5, min: 0);
        // Special: Ice Block
        Spec_IceBlockDur.EndTime = new FloatStat(5f, min: 0f);
    }
Ejemplo n.º 22
0
    public override void InitStats()
    {
        AttackData = new AttackData(8);

        // Main
        Main_Shoot_CD.EndTime         = new FloatStat(0.15f, min: 0.01f);
        Main_Reload_Dur.EndTime       = new FloatStat(0.5f, min: 0.01f);
        Main_SwapMagazine_Dur.EndTime = new FloatStat(0.8f, min: 0.01f);
        Main_MagazineSize             = new IntStat(6, min: 0);
        Main_BulletData = new ProjectileData()
        {
            moveSpeed  = new FloatStat(45f, min: 0f),
            travelDist = new FloatStat(0f, min: 0f, max: 10f)
        };

        // Upgrade
        switch (ItemLevel)
        {
        case 1: break;

        case 2:
            AttackData = new AttackData(10);
            break;

        default:
            AttackData = new AttackData(12);
            break;
        }
    }
Ejemplo n.º 23
0
    public override void Load(GameData gameData, int id)
    {
        ProjectileData projectileData = gameData.projectileData.First(x => x.id == id);

        transform.position    = projectileData.position.ConvertedToVector3;
        transform.eulerAngles = projectileData.rotation.ConvertedToVector3;
    }
Ejemplo n.º 24
0
 public void shootViewProjectile(byte[] ProjectileBytes)
 {
     try {
         ProjectileData projData = ProjectileData.deserialize(ProjectileBytes);
         projData.startTime = getTime();
         if (projData.hitTime < projData.startTime + 100)   // Min take 100ms to hit.
         {
             projData.hitTime = projData.startTime + 100;
         }
         projData.isView = true;
         PlayerGameState oppGameState = getOpponentGameState();
         Monster         target       = oppGameState.monsterRef[projData.targetSerializeId];
         Vector2         source       = oppGameState.viewMapRef.getTile(projData.startCoord.row, projData.startCoord.col).transform.position;
         Projectile      proj         = projectilePool.GetProjectile();
         proj.projData       = projData;
         proj.target         = target;
         proj.source         = source;
         proj.spriteR.sprite = TowerR.getById(projData.towerId).projectileSprite;
         proj.splashR.color  = TowerR.getById(projData.towerId).splashColor;
         if (oppGameState.sendMapData)
         {
             SoundManager.instance.PlayShoot(TowerR.getById(projData.towerId).shootingSound);
         }
         proj.Initialize();
     } catch (KeyNotFoundException e) {
         Debug.LogWarning(e.StackTrace);
     }
 }
Ejemplo n.º 25
0
 private IEnumerator FireProjectileCoroutine(ProjectileData data, GameObject prefab, Transform[] spawnPoints, Transform target)
 {
     for (var i = 0; i < data.salvos; i++)
     {
         FireProjectile(data, prefab, spawnPoints, target);
         yield return(new WaitForSeconds(data.timeBetweenSalvos));
     }
 }
        /// <summary>
        /// Spawns a missile (not parented under a turret, but just as effect) which fires at the inputted target ship
        /// </summary>
        /// <param name="targetShip"></param>
        private void SpawnMissileAtTarget(Ship targetShip)
        {
            ProjectileData missileData = AssetManager.GetData <ProjectileData>(Missile.defaultMissileDataAsset);

            DebugUtils.AssertNotNull(missileData);

            ScreenManager.Instance.CurrentScreen.AddInGameUIObject(new Missile(targetShip, WorldPosition, missileData), true, true);
        }
Ejemplo n.º 27
0
 public void Initialize(Transform transform, Animator anim, ProjectileData data, float fireRate, float shootingAnimationTime)
 {
     this.transform             = transform;
     animator                   = anim;
     projectileData             = data;
     this.fireRate              = fireRate;
     this.shootingAnimationTime = shootingAnimationTime;
     OnInitialize();
 }
Ejemplo n.º 28
0
        public void Init(ProjectileData projectileData, Vector2 direction)
        {
            _projectileData = projectileData;
            _direction      = direction;

            _rigidbody.bodyType    = RigidbodyType2D.Dynamic;
            _spriteRenderer.sprite = _projectileData.ProjectileSprite;
            _circleCollider.radius = _spriteRenderer.sprite.bounds.extents.x * 1.5f;
        }
Ejemplo n.º 29
0
    // Use this for initialization
    private void Start()
    {
        rb   = GetComponent <Rigidbody>();
        data = GetComponent <ProjectileData>();

        // Destroy this projectile after a amount of time
        Destroy(this.gameObject, data.projectileLifespan);
        pushForward();
    }
Ejemplo n.º 30
0
        /// <summary>
        ///  Initializes parameters of the script.
        /// </summary>
        /// <param name="projectileData"></param> The projectile's data (Scriptable object instance)
        /// <param name="spawnDirection">The direction of the projectile (right or left)</param>
        /// <param name="shouldDamagePlayer">If the projectile was shot by player's weapon, this should be false</param>
        public void Init(ProjectileData projectileData, Vector2 spawnDirection, bool shouldDamagePlayer)
        {
            _projectileData     = projectileData;
            _direction          = spawnDirection;
            _shouldDamagePlayer = shouldDamagePlayer;

            _rigidbody.isKinematic = true;
            _spriteRenderer.sprite = _projectileData.ProjectileSprite;
        }
Ejemplo n.º 31
0
        public static List<ProjectileData> initializeProjectileData()
        {
            List<ProjectileData> data = new List<ProjectileData>();

            ProjectileData alliedBullet = new ProjectileData();
            alliedBullet.damage = 10;
            alliedBullet.speed = 300;
            alliedBullet.texture = ResourceID.Bullet;
            data.Insert((int)Projectile.Type.AlliedBullet, alliedBullet);

            ProjectileData enemyBullet = new ProjectileData();
            enemyBullet.damage = 10;
            enemyBullet.speed = 300;
            enemyBullet.texture = ResourceID.Bullet;
            data.Insert((int)Projectile.Type.EnemyBullet, enemyBullet);

            ProjectileData missile = new ProjectileData();
            missile.damage = 200;
            missile.speed = 150;
            missile.texture = ResourceID.Missile;


            return data;
        }
Ejemplo n.º 32
0
	public ProjectileType(int type, int subTypeCount) {
		modifierType = type;
		modifierSubTypeCount = subTypeCount;

		projectileDatas = new ProjectileData[subTypeCount];
	}