protected virtual bool AttackTargetDamagable(IDamagable damagable) { bool hitDamagable = false; SetAttackInfo(damagable); _onDamagableDestructedAction = delegate(IDamagable targetDamagable) { OnDamagableDestructed(targetDamagable); }; damagable.RegisterToDamagableDestructedEvent(_onDamagableDestructedAction, true); _onDamageReflectedAction = delegate(AttackInfo attackInfo) { OnDamageReflected(attackInfo); }; damagable.RegisterToDamageReflectedEvent(_onDamageReflectedAction, true); _registeredDamagableList.Add(damagable); if (damagable.TakeDamage(_attackInfo)) { hitDamagable = true; } return(hitDamagable); }
void Awake() { playerLight = GetComponent <PlayerLight>(); attacker = GetComponentInChildren <IAttackable>(); damageControl = GetComponentInChildren <IDamagable>(); updateUI = GetComponent <UpdatePlayerUI>(); }
private void OnTriggerEnter2D(Collider2D col) { if (col.tag == "Player" && isPlayer) { return; } if (col.tag == "Enemy" && !isPlayer) { return; } ExplosionManager exp = ObjectPool.Get <ExplosionManager>(); exp.Initialize(transform.position, 4); if (damage == null) { return; } IDamagable target = col.GetComponent <IDamagable>(); if (target != null) { target.Damage(damage); } Disable(); }
protected virtual void OnDamagableDestructed(IDamagable damagable) { _targetDamagableList.Remove(damagable); damagable.RegisterToDamagableDestructedEvent(_onDamagableDestructedAction, false); damagable.RegisterToDamageReflectedEvent(_onDamageReflectedAction, false); }
protected override void HitTarget(IDamagable targetHit, string layerName) { if (layerName == "Player" || layerName == "Asteroid") { targetHit.TakeDamage(laserDamage); } }
public void DoDamage(IDamagable damagable) { Random r = new Random(); var roll = r.Next(1, 21); var percent = 21 - (ArmorClass - HitModifier) / 20; Console.WriteLine(Name + " is doing damage"); var status = Combat.GetStatus(percent * 100); switch (status) { case Combat.HitStatus.CRITICAL_HIT: break; case Combat.HitStatus.CRITICAL_MISS: break; case Combat.HitStatus.HIT: break; case Combat.HitStatus.MISS: break; default: break; } }
public void DealDamageInRadius(float damage, float radius) { List <IDamagable> damnagables = new List <IDamagable>(); Collider[] colliders = Physics.OverlapSphere(transform.position, radius, thisDamages); foreach (Collider collider in colliders) { IDamagable damagable = collider.GetComponent <IDamagable>(); if (damagable != null && damagable.Damagable) { bool duplicate = false; //prevents dealing damage multiple times to ame damagable if it has more than one collider foreach (var d in damnagables) { if (d == damagable) { duplicate = true; } } if (!duplicate) { damnagables.Add(damagable); } } } foreach (IDamagable damagable in damnagables) { float distance = Vector3.Distance(transform.position, damagable.Transform.position); float damageByDistance = damage * damageFalloff.Evaluate(distance / radius); damagable.TakeDamage(damageByDistance); } }
public static void Effect(GameObject target, SpellData _spell = null, int _strength = -1) { SpellData spell = _spell == null ? currentSpell : _spell; int strength = _strength == -1 ? _currentStrength : _strength; switch (spell.action) { case SpellData.ActionType.Grow: Plant plant = target.GetComponent <Plant> (); if (plant != null) { plant.AccelerateGrow(.01f * spell.attributeLevel * (spell.strengthenEffect ? _currentStrength : 1)); } break; case SpellData.ActionType.Hurt: IDamagable damagable = target.GetComponent <IDamagable> (); damagable.hit(spell.attributeLevel + spell.attributeLevel * (spell.strengthenEffect ? _currentStrength / 10 : 0), spell.attribute); break; case SpellData.ActionType.Heal: IDamagable toHeal = target.GetComponent <IDamagable> (); toHeal.heal(spell.attributeLevel + spell.attributeLevel * (spell.strengthenEffect ? _currentStrength / 10 : 0)); break; default: break; } }
protected virtual void DealDamage(int damage, GameObject[] targets) { foreach (GameObject target in targets) { //if there's a damageable component in the object, find it IDamagable targetDamagable = target.GetComponent <IDamagable>(); if (targetDamagable == null) { targetDamagable = target.GetComponentInParent <IDamagable>(); } if (targetDamagable == null) { targetDamagable = target.GetComponentInChildren <IDamagable>(); } //only apply accuracy if target is an enemy if (card.target != TargetingOption.Player) { targetDamagable.TakeDamage(damage + PlayerStats.instance.playerClass.accuracy); } else { targetDamagable.TakeDamage(damage); } } }
// Use this for initialization void Start() { grad = new Gradient(); GradientColorKey[] colorKeys = new GradientColorKey[4]; colorKeys[0].color = Color.white; colorKeys[0].time = 0.0f; colorKeys[1].color = Color.green; colorKeys[1].time = 0.33f; colorKeys[2].color = Color.yellow; colorKeys[2].time = 0.67f; colorKeys[3].color = Color.red; colorKeys[3].time = 1.0F; GradientAlphaKey[] alphaKeys = new GradientAlphaKey[4]; alphaKeys[0].alpha = 1.0f; alphaKeys[0].time = 0.0f; alphaKeys[1].alpha = 1.0f; alphaKeys[1].time = 0.33f; alphaKeys[2].alpha = 1.0f; alphaKeys[2].time = 0.67f; alphaKeys[3].alpha = 1.0f; alphaKeys[3].time = 1.0f; grad.SetKeys(colorKeys, alphaKeys); text = statueText.GetComponent <Text>(); statueDamagable = statue.GetComponent <IDamagable>(); }
public void PlayAttackSound(AttackType attack, IDamagable toDamage) { if (GetComponentInParent <Player>() != null) { switch (attack) { case AttackType.Attack1: AudioController.controller.PlaySound(SoundType.Attack1); break; case AttackType.Attack2: AudioController.controller.PlaySound(SoundType.Attack2); break; case AttackType.Attack3: AudioController.controller.PlaySound(SoundType.Attack3); break; default: break; } } else { AudioController.controller.PlaySound(SoundType.EnemyAttack); } }
private void AttackInteractable(IInteractable interactable) { // if the attack was blocked, it can't hit anymore // TODO: we probably should do this on a per-source basis // and probably should track per-source if it hit / was blocked // so we never re-hit and re-block or whatever if (_brawler.CurrentAction.WasBlocked) { return; } IDamagable damagable = interactable.gameObject.GetComponent <IDamagable>(); if (null == damagable) { return; } Actors.DamageData damageData = new Actors.DamageData { Source = Owner, SourceBrawlerActionHandler = Owner.Behavior as IBrawlerBehaviorActions, AttackData = _attackData, Bounds = _collider.bounds, Direction = _direction, }; if (damagable.Damage(damageData)) { AttackHitEvent?.Invoke(this, new AttackVolumeEventArgs { HitTarget = damagable, }); } }
void Shot() { // Пускаем лучь Ray ray = new Ray(fierPoint.position, fierPoint.forward * 10f); RaycastHit hit; if (Physics.Raycast(ray, out hit, 500f, 13, QueryTriggerInteraction.Ignore)) { // Если попали во врага, наносим урон IDamagable enemy = hit.transform.gameObject.GetComponent <IDamagable>(); if (enemy != null) { enemy.GetDamage(damage); } // Устанавливаем декаль GameObject g = Instantiate <GameObject>(Dec); g.transform.position = hit.point + hit.normal * 0.01f; g.transform.rotation = Quaternion.LookRotation(-hit.normal); g.transform.SetParent(hit.transform); Rigidbody r = hit.transform.gameObject.GetComponent <Rigidbody>(); if (r != null) { r.AddForceAtPosition(-hit.normal * 500, hit.point); } } Partial.Play(); }
private void OnCollisionEnter(Collision collision) { //CheckCollision collisionCheck = new CheckCollision(collision, damage); //Instantiate(bombExplosion, transform.position, transform.rotation); Collider[] colliders = Physics.OverlapSphere(collision.transform.position, 0.1f); controller.DestroyBulletView(); foreach (Collider hit in colliders) { IDamagable damagable = hit.gameObject.GetComponent <IDamagable>(); if (damagable != null) { damagable.TakeDamage(damage); } //if (hit.GetComponent<EnemyView>()) //{ // EnemyView enemy = hit.GetComponent<EnemyView>(); // if (enemy != null) // { // controller.ApplyEnemyDamage(damage, enemy); // } //} } }
public ZombieAttackState(GameObject followTarget, ZombieComponent zombie, StateMachine stateMachine) : base(zombie, stateMachine) { FollowTarget = followTarget; UpdateInterval = 2.0f; DamagableObject = followTarget.GetComponent <IDamagable>(); }
public void Init(Projectile parent) { _parent = parent; Ray2D ray = new Ray2D(transform.position, transform.right); RaycastHit2D[] hits = Physics2D.RaycastAll(ray.origin, ray.direction, parent.Range, parent.Layer); foreach (RaycastHit2D hit in hits) { IDamagable damagable = parent.CheckHit(hit.collider); if (damagable != null) { DamageInfo damageInfo = parent.Hit(damagable, hit.collider, hit.point, hit.normal); _parent.Damage -= damageInfo.DamageDealt; if (parent.Damage <= 0f) { _renderer.SetPositions(transform.position, hit.point); break; } } } if (parent.Damage > 0f) { _renderer.SetPositions(transform.position, ray.GetPoint(parent.Range)); } Invoke("FuckingDie", Life); }
void OnTriggerEnter(Collider c) { if (playerDamageable == null) { playerDamageable = GameManager.instance.Player.GetComponent <IDamagable>(); } var o = Physics.OverlapSphere(transform.position, radiusOfOverlap, damageToLayer); if (o.Length > 0) { posOverlap = transform.position; if (_strategy != null) { _strategy.playerHitted(playerDamageable); } } //if (c.gameObject.layer == 10) { //Squirrel // if(_strategy != null) // _strategy.playerHitted(playerDamageable); //comentado hasta que se implemente idamageable en squirrel // //Debug.Log("bla"); //} if (c.gameObject.layer != 15 && c.gameObject.layer != 16 && c.gameObject.layer != 19) //spider //spiderBullet //checkpoint { SpiderBulletManager.instance.ReturnBulletToPool(this); } }
private void Attack() { // should be able to hit whatever - for now plants int layerMask = LayerMask.GetMask(GetFoodType()); Vector3 attackPos = (transform.position); if (spOrient.getFacingRight()) { attackPos.x += attackDistance; } else { attackPos.x -= attackDistance; } attackPos.y = attackDistance * .5f; Collider[] hitColliders = Physics.OverlapSphere(attackPos, attackDistance, layerMask); gizmoPos = attackPos; gizmoRad = attackDistance; foreach (Collider c in hitColliders) { IDamagable damagableObject = c.GetComponent <IDamagable>(); if (damagableObject != null) { damagableObject.TakeHit(damage, this.GetComponent <IEats>()); } } }
private void OnDamageTaken(IDamagable source, DamageArgs args) { HitboxID hitboxId = ((HitReceiver)source).HitboxID; float totalDamage = args.Damage * hitboxMapper[hitboxId].DamageMultiplier; Health.TakeDamage(new DamageArgs(args.Origin, args.Dealer, totalDamage)); }
void ShootRay() { if (hitObject) { return; } if (Physics.Raycast(raySpawn, transform.forward, out hit, rayDistance + 1)) { hitObject = true; //----------------------- SurfaceData surfData = hit.transform.root.GetComponent <SurfaceData>(); if (surfData != null) { GameObject impactFX = (GameObject)Instantiate(particalEffects[surfData.surfaceMaterial], hit.point, Quaternion.identity); impactFX.transform.up = hit.normal; impactFX.transform.SetParent(hit.transform); } IDamagable damagable = hit.transform.root.GetComponent <IDamagable>(); if (damagable != null) { damagable.ITakeDamage(25); } Debug.Log("Hit: " + hit.transform.name); } currentRaySpawn += rayMultiplier; Debug.DrawLine(raySpawn, raySpawn + transform.forward * rayMultiplier, Color.green, 2f * Time.deltaTime); raySpawn = raySpawn + (-transform.up * bulletDrop); raySpawn = raySpawn + (transform.forward * rayMultiplier); //rayMultiplier was originally currentRaySpawn }
private void FixedUpdate() { // Update rotation this.rigidbody.rotation = Quaternion.LookRotation(velocity); // Try to hit something RaycastHit hit; if (Physics.Raycast(this.rigidbody.position, velocity, out hit, velocity.magnitude * Time.fixedDeltaTime)) { IDamagable damagable = hit.collider.GetComponentInParent <IDamagable>(); if (damagable != null) { damagable.Damage(damage); } ImpactEffect impact = hit.collider.GetComponentInParent <ImpactEffect>(); if (impact) { impact.Impact(this, hit); } Destroy(this.gameObject); } // Move and update velocity rigidbody.MovePosition(rigidbody.position + (velocity * Time.fixedDeltaTime)); velocity.y += (gravity * Time.fixedDeltaTime); velocity *= (1f - (airResistance * Time.fixedDeltaTime)); }
private void Explode() { audioSource.Play(); particle.Play(); barrelIntact.SetActive(false); foreach (GameObject g in barrelPieces) { g.GetComponent <MeshCollider>().enabled = true; g.GetComponent <Renderer>().enabled = true; g.GetComponent <Rigidbody>().isKinematic = false; g.GetComponent <Rigidbody>().AddExplosionForce(force, transform.position + new Vector3(0, 0.2f, 0), radius, 0, ForceMode.Force); } Collider[] hitColliders = Physics.OverlapSphere(transform.position, radius); for (int i = 0; i < hitColliders.Length; i++) { GameObject hit = hitColliders[i].gameObject; IDamagable damageableObject = (IDamagable)hit.GetComponent(typeof(IDamagable)); if (damageableObject != null) { damageableObject.TakeDamage(damage); } Rigidbody rBody = hit.GetComponent <Rigidbody>(); if (rBody != null) { hit.GetComponent <Rigidbody>().AddExplosionForce(force * 2, transform.position, radius); } } }
void OnHitObject(Collider c, Vector3 hitPoint) { AudioManager.instance.PlaySound("ImpactSFX", c.transform.position); if (c.CompareTag("Enemy")) { IDamagable target = c.GetComponent <IDamagable>(); if (target != null) { target.TakeHit(damage, hitPoint, transform.forward); } if (!piercing || hasPierced) { Destroy(gameObject); } else { hasPierced = true; } } else if (c.CompareTag("Obsticle")) { Destroy(Instantiate(bulletImpactObsticleEffect.gameObject, transform.position + (hitPoint - transform.position) / 2, Quaternion.FromToRotation(Vector3.forward, -transform.forward)) as GameObject, bulletImpactObsticleEffect.main.startLifetime.constant); Destroy(gameObject); } else { Destroy(gameObject); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.gameObject.tag.Equals("bullet")) { return; } m_isMoving = false; IDamagable damagable = collision.GetComponent <IDamagable>(); if (damagable != null) { Creature creature = damagable as Creature; if (creature != null && creature == m_owner) { m_isMoving = true; return; } damagable.DoDamage(Damage); } DoDestroy(); }
/// <summary> /// check if we have hit something (animation event) /// </summary> public void CheckForHit() { //Vector3 boxPosition = transform.position + (Vector3.up * lastAttack.collHeight) + Vector3.right * ((int)lastAttackDirection * lastAttack.collDistance); //Vector3 boxSize = new Vector3(lastAttack.collSize / 2, lastAttack.collSize / 2, hitZRange / 2); //Collider[] hitColliders = Physics.OverlapBox(boxPosition, boxSize, Quaternion.identity, hitLayerMask); Vector3 boxPosition = swordHandPos.position + swordHandPos.forward * 0.5f; float radius = lastAttack.collDistance; Collider[] hitColliders = Physics.OverlapSphere(boxPosition, radius, hitLayerMask); int i = 0; while (i < hitColliders.Length) { IDamagable <DamageObject> damageObject = hitColliders[i].GetComponent(typeof(IDamagable <DamageObject>)) as IDamagable <DamageObject>; if (damageObject != null) { damageObject.Hit(lastAttack); targetHit = true; } i++; } if (hitColliders.Length == 0) { targetHit = false; } }
public void Initialize(List <SpellBehaviour> modifiers, StatsBehaviour stats, Transform transform, IDamagable avoidTarget) { _transform.position = transform.position; _transform.rotation = transform.rotation; _transform.rotation *= Quaternion.Euler(0f, Random.Range(-_recoil, _recoil), 0f); _damage = stats.GetStatValue(StatType.ProjectileDamage); _speed = stats.GetStatValue(StatType.ProjectileSpeed); _range = stats.GetStatValue(StatType.AttackRange); _size = stats.GetStatValue(StatType.ProjectileSize); _recoil = stats.GetStatValue(StatType.AttackRecoil); _targetToAvoid = avoidTarget; _timeToRemove = _range / _speed; _modifiers = modifiers; }
void OnCollisionEnter(Collision collision) { if (collision.gameObject == owner) { return; } IDamagable applyDamage = collision.gameObject.GetComponent <IDamagable>(); if (applyDamage != null) { applyDamage.Damage(damage); if (debuffs != null) { //applyDamage.AddDebuff(debuffs()); foreach (AttackDebuffs debuff in debuffs.GetInvocationList()) { Debuff d = debuff(); applyDamage.AddDebuff(d); Debug.Log($"Added Debuff {d}"); } } } ContactPoint hit = collision.GetContact(0); Instantiate(ImpactEffect, hit.point, Quaternion.LookRotation(hit.normal)); if (maxBounces > 0) { maxBounces--; Vector3 newDirection = Vector3.Reflect(currentVelocity, hit.normal); rbody.AddForce(newDirection, ForceMode.Impulse); } }
private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag == "StartGate") { //Enemy is inside the player view //enable killable methods; isReadyToDie = true; } if (collision.tag == "Destroyer") { //Remove enemy from the active list GameManager.instance.ResetEnemyOnDefaultDeath(this); gameObject.SetActive(false); } IDamagable playerTarget = (IDamagable)collision.gameObject.GetComponent(typeof(IDamagable)); if (collision.gameObject.tag == "Player" && playerTarget != null) { //Deal damage to the player playerTarget.TakeDamage(damage); //Remove enemy from the active list GameManager.instance.ResetEnemyOnDefaultDeath(this); //Destroy itself Kill(); } }
public Vector2 HandleBullet(Vector2 EndPoint, RaycastHit2D[] RCH, Collider2D[] IgnoreColliders) { foreach (RaycastHit2D Hit in RCH) { if (Hit.collider != null) { if (IgnoreColliders.Contains(Hit.collider)) { continue; } IDamagable Char = Hit.collider.GetComponent <IDamagable>(); if (Char != null) { bool stop = Char.StopsBullet; Char.ApplyDamage(WeaponConfiguration.Damage); if (stop) { return(Hit.point); } } } } return(EndPoint); }
protected override void DealDamage(int damage, GameObject[] targets) { for (int i = 0; i < 3; i++) { foreach (GameObject target in targets) { //need to check so the game doesn't crash when your first shot kills the enemy if (target != null) { //if there's a damageable component in the object, find it IDamagable targetDamagable = target.GetComponent <IDamagable>(); if (targetDamagable == null) { targetDamagable = target.GetComponentInParent <IDamagable>(); } if (targetDamagable == null) { targetDamagable = target.GetComponentInChildren <IDamagable>(); } //only apply accuracy if target is an enemy if (card.target != TargetingOption.Player) { if (targetDamagable != null) { targetDamagable.TakeDamage(damage + PlayerStats.instance.playerClass.accuracy); } } else { targetDamagable.TakeDamage(damage); } } } } }
protected void OnEnable() { _damagableObject = GetComponent(typeof (IDamagable)) as IDamagable; if (Particles == null || Particles.Length == 0 || _damagableObject == null) { //Debug.LogError("Particles manager couldn't get required components!"); return; } foreach (ParticleSystem particle in Particles) { particle.enableEmission = false; } _thresholdLevelJump = (float) ((_damagableObject.MaxHitPoints*0.9f)/Particles.Length); _thresholdMin = _damagableObject.MaxHitPoints - _thresholdLevelJump; _thresholdMax = _damagableObject.MaxHitPoints + 0.1f; //just in case }
void Start() { unitType = player; }
//--------------------------------------------------------------- //ON OBJECT DESTROY //--------------------------------------------------------------- private void OnDestroy(IDamagable sender) { try { IDraw system = FindSolarOrBlackHoleSystemWithObject(sender.ToIDraw()); if (system == null) { throw new SystemNotFoundException(); } else if (system is SolarSystem) { system.ToSolarSystem().Objects.Remove( system.ToSolarSystem().Objects.Find(x => Object.ReferenceEquals(sender, x))); if (sender is Asteroid) { Asteroid temp = CreateAsteroid(); temp.OnDestroy += new OnDestroyHandler(OnDestroy); system.ToSolarSystem().Objects.Add(temp); } } else if (system is BlackHoleSystem) { system.ToBlackHoleSystem().Objects.Remove( system.ToBlackHoleSystem().Objects.Find(x => Object.ReferenceEquals(sender, x))); if (sender is Asteroid) { Asteroid temp = CreateAsteroid(); temp.OnDestroy += new OnDestroyHandler(OnDestroy); system.ToBlackHoleSystem().Objects.Add(temp); } } else { throw new UnknownException(); } } //TODO: Запилить тут обработку исключений нормальную. catch { return; } }