public static void InstantiateShot(WeaponController weaponOrigin, ShotController shotPrefab, Transform origin, float power) { GameObject newObject = Instantiate(shotPrefab.gameObject, origin); ShotController newShotController = newObject.GetComponent <ShotController>(); Assert.IsNotNull(newShotController, "Missing asset"); newShotController.WeaponOrigin = weaponOrigin; newShotController.EffectivePowerInPercent = power; }
public override void Apply(ShotController controller, GameObject target) { DestructibleController destructible = target.GetComponent <DestructibleController>(); if (destructible) { if (destructible.GetDestructibleData().IsAffectedByDamageType(controller.GetDamageType())) { float damages = this.UsesPowerModificator ? controller.CalculatedValueAfterPowerModification(this.amountOfDamage) : this.amountOfDamage; destructible.TakeDamage(damages); GameObject.Destroy(controller.gameObject); } } }
public override void Apply(ShotController controller, Rigidbody2D rg) { Assert.IsNotNull(controller, "Invalid parameter"); Assert.IsNotNull(rg, "Invalid parameter"); if (controller && rg) { // TODO Movement to fix, currently, it increase constantly (+ apply modificator) Transform transform = rg.gameObject.transform; Vector2 forwardForce = new Vector2(transform.up.x, transform.up.y); forwardForce *= this.SpeedInUnityForce * Time.deltaTime; rg.AddForce(forwardForce); Debug.DrawRay(transform.position, rg.velocity, Color.blue, 0.1f); } }
// TODO Add on trigger collisions private void OnCollisionEnter2D(Collision2D collision) { // Check for special case with collision is actually the one who did the shot. // TODO Update with a better implementation (I don't know it the cost of the GetComponentsInChildren is that expensive) // This requires that collision is in the parent (or same gameobject) WeaponController[] weaponControllers = collision.gameObject.GetComponentsInChildren <WeaponController>(); foreach (WeaponController weapon in weaponControllers) { Assert.IsNotNull(this.WeaponOrigin, "Invalid asset"); if (weapon.gameObject == this.WeaponOrigin.gameObject) { if (this.shotData.DamagedByTheShooter) { this.shotData.Damage.Apply(this, collision.gameObject); } else { // Don't do anything else return; } } } // Special case of collision with another shot ShotController collisionShotController = collision.gameObject.GetComponent <ShotController>(); if (collisionShotController) { bool isFriendlyShot = collisionShotController.WeaponOrigin == this.WeaponOrigin; bool isEnemyShot = !isFriendlyShot; if (isFriendlyShot && this.shotData.DamagedByFriendlyShots) { this.shotData.Damage.Apply(this, collision.gameObject); } else if (isEnemyShot && this.shotData.DamagedByEnemyShots) { this.shotData.Damage.Apply(this, collision.gameObject); } } else { this.shotData.Damage.Apply(this, collision.gameObject); } }
public override void Apply(ShotController controller, GameObject target) { float damages = this.UsesPowerModificator ? controller.CalculatedValueAfterPowerModification(this.ExplosionDamageAmount) : this.ExplosionDamageAmount; Instantiate(this.ExplosionPrefab, controller.gameObject.transform.position, controller.gameObject.transform.rotation); // TODO Add damages to the explosion (atm, does nothing more than prefab instantiation and impact damage) DestructibleController destructible = target.GetComponent <DestructibleController>(); if (destructible) { if (destructible.GetDestructibleData().IsAffectedByDamageType(controller.GetDamageType())) { destructible.TakeDamage(damages); } } GameObject.Destroy(controller.gameObject); }
public override void Apply(ShotController controller, Rigidbody2D rg) { // TODO To re-integrate (movement is buggy) Assert.IsNotNull(controller, "Invalid parameter"); Assert.IsNotNull(rg, "Invalid parameter"); if (controller && rg) { // This is a hacky why to recreate a pseudo gravity float elapsedtime = Mathf.Exp(controller.GetLifetimeDuration()); Vector2 slowForceDirection = -(rg.velocity.normalized); float modif = this.SpeedModificator * Time.deltaTime * elapsedtime; modif = Mathf.Clamp(modif, 0, rg.velocity.magnitude); Vector2 slowForce = slowForceDirection * modif; rg.AddForce(slowForce); } }
public override void Apply(ShotController controller, Rigidbody2D rg) { Assert.IsNotNull(controller, "Invalid parameter"); Assert.IsNotNull(rg, "Invalid parameter"); if (controller && rg) { Transform target = controller.GetTarget(); if (target) { // TODO fix movement (and add power modificator) Vector3 direction = target.position - rg.transform.position; rg.velocity = direction.normalized * this.SpeedInUnitsPerSec; Debug.DrawRay(rg.transform.position, rg.velocity, Color.blue, 0.1f); } else { // TODO To implement } } }
public void DoFire() { ShotController.InstantiateShot(this, this.weaponData.ShotControllerPrefab, this.weaponEndPoint.transform, this.GetCurrentPower()); this.lastFireTime = Time.time; }
public abstract void Init(ShotController controller, Rigidbody2D rg);
public abstract void Apply(ShotController controller, Rigidbody2D rg);
public abstract void Apply(ShotController controller, GameObject target);
public override void Apply(ShotController controller, GameObject target) { // TODO add shock GameObject.Destroy(controller.gameObject); }