void Awake() { if (instance != null) { Destroy(gameObject); } else { instance = this; } }
//Passes the projectile object by reference (I hope) public ProjectileAdapter(ProjectileParent projectile) { this.projectile = projectile; }
public void dealDamageToShip(int amountDamage, GameObject damagingObject) { int amountBeingDamaged = Mathf.RoundToInt(amountDamage * defenseModifier); if (damagingObject != null) { if (damagingObject.GetComponent <DisplayItem>()) { dealTrueDamageToShip(amountDamage); return; } if (itemsGrantingDamageImmunity.Count > 0) { amountBeingDamaged = 0; } if (damageAbsorb == true) { healPlayer(Mathf.RoundToInt(amountBeingDamaged)); amountBeingDamaged = 0; } // need to correct here if (hitBufferPeriod == false) { float angle = Mathf.Atan2(damagingObject.transform.position.y - transform.position.y, damagingObject.transform.position.x - transform.position.x); if (Vector2.Distance(transform.position, damagingObject.transform.position) < 1f) { damageNumbers.showDamage((int)(amountBeingDamaged), shipHealthMAX, damagingObject.transform.position); } else { damageNumbers.showDamage((int)(amountBeingDamaged), shipHealthMAX, transform.position + new Vector3(Mathf.Cos(angle), Mathf.Sin(angle))); } cameraShake.shakeCamFunction(0.2f, 0.1f + ((float)amountBeingDamaged / shipHealthMAX) * 0.2f); } else { return; } } StartCoroutine(SleepHit(0.07f)); if (amountBeingDamaged == 0) { return; } StartCoroutine(bufferHit(0.5f)); shipHealth -= amountBeingDamaged; if (damagingObject != null) { foreach (ArtifactSlot slot in PlayerProperties.playerArtifacts.artifactSlots) { if (slot.displayInfo != null && slot.displayInfo.GetComponent <ArtifactEffect>()) { if (damagingObject.GetComponent <ProjectileParent>()) { ProjectileParent projectileParent = damagingObject.GetComponent <ProjectileParent>(); if (projectileParent.instantiater != null) { slot.displayInfo.GetComponent <ArtifactEffect>().tookDamage(amountBeingDamaged, damagingObject.GetComponent <ProjectileParent>().instantiater?.GetComponent <Enemy>()); } } else if (damagingObject.transform.parent != null) { slot.displayInfo.GetComponent <ArtifactEffect>().tookDamage(amountBeingDamaged, damagingObject.transform.parent.GetComponent <Enemy>()); } else { slot.displayInfo.GetComponent <ArtifactEffect>().tookDamage(amountBeingDamaged, damagingObject.GetComponent <Enemy>()); } } } foreach (ShipWeaponScript script in allShipWeaponScripts) { if (damagingObject.GetComponent <ProjectileParent>()) { ProjectileParent projectileParent = damagingObject.GetComponent <ProjectileParent>(); if (projectileParent.instantiater != null) { script.shipWeaponTemplate.GetComponent <WeaponFireTemplate>().TookDamage(amountBeingDamaged, projectileParent.instantiater.GetComponent <Enemy>()); } } else if (damagingObject.transform.parent != null) { script.shipWeaponTemplate.GetComponent <WeaponFireTemplate>().TookDamage(amountBeingDamaged, damagingObject.transform.parent.GetComponent <Enemy>()); } else { script.shipWeaponTemplate.GetComponent <WeaponFireTemplate>().TookDamage(amountBeingDamaged, damagingObject.GetComponent <Enemy>()); } } } damagingObject = null; CheckPlayerDeath(); updateHealthBar(); }