private void UpdateTurnablePart(IAttackableEntity targetEntity) { if (targetEntity is BaseEntity entity) { turnablePart.right = (entity.transform.position - turnablePart.position).normalized; } }
/// <summary> /// Gets the damage between two entities using ranged attack calculations. /// </summary> /// <param name="attacker">The attacker.</param> /// <param name="attacked">The attacked.</param> /// <returns>The amount of damage dealt.</returns> public static uint GetDamage(IAttackableEntity attacker, IAttackableEntity attacked) { double damage = 0; var attackerPlayer = attacker as Player; if (attackerPlayer != null) { var attackedPlayer = attacked as Player; var attackedMonster = attacked as Monster; damage = Drivers.Repositories.Safe.Random.Next(attackerPlayer.MinAttack, attackerPlayer.MaxAttack); if (attackedPlayer != null) { Player_Player(attackerPlayer, attackedPlayer, ref damage); } else if (attackedMonster != null) { Player_Monster(attackerPlayer, attackedMonster, ref damage); } } SharedDamageCalculations.CalculateLevelExtraDamage(attacker.Level, attacked.Level, ref damage); SharedDamageCalculations.CalculateRebornExtraDamage(attacker.Reborns, ref damage); return((uint)Math.Max((int)damage, (int)1)); }
public AttackResults AttackWithProjectileSingleTarget(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y]) { if (attackableEntity.AttackWithDamage(DamageType.Projectile, damage)) { return(AttackResults.Kill); } else { return(AttackResults.Damage); } } } } } } return(AttackResults.None); }
public static IAttackableEntity[] AttackableEntitiesWithinAttackersBounds(Rectangle attackersBounds, IAttackableEntity[] attackableEntites) { List<IAttackableEntity> attackableEntitieWithinBounds = new List<IAttackableEntity>(); foreach (IAttackableEntity attackableEntity in attackableEntites) { if (attackersBounds.Intersects(attackableEntity.AttackBounds)) { attackableEntitieWithinBounds.Add(attackableEntity); } } return attackableEntitieWithinBounds.ToArray(); }
public void Initialise(ProjectileConfiguration configuration, IAttackableEntity targetEntity) { //Set base values TargetEntity = targetEntity; Configuration = configuration; AliveTime = 0; //Update sprite spriteRenderer = spriteRenderer == null?gameObject.AddComponent <SpriteRenderer>() : spriteRenderer; spriteRenderer.sprite = configuration.ProjectileSprite; //Start Projectile Configuration.ProjectileStart(this); }
private IEnumerable <IAttackableEntity> GetRelevantEntities(IAttackableEntity mainTarget) { bool targetsEnemies = mainTarget is EnemyUnit; foreach (BaseEntity entity in BaseEntity.AllEntities) { if (entity is IAttackableEntity attackableEntity) { if (targetsEnemies == entity.IsEnemyEntity) { yield return(attackableEntity); } } } }
/// <summary> /// Gets the damage between two entities using magic attack calculations. /// </summary> /// <param name="attacker">The attacker.</param> /// <param name="attacked">The attacked.</param> /// <param name="spellInfo">The spell info.</param> /// <returns>The amount of damage dealt.</returns> public static uint GetDamage(IAttackableEntity attacker, IAttackableEntity attacked, SpellInfo spellInfo) { double damage = 0; var attackerPlayer = attacker as Player; var attackerMonster = attacker as Monster; var attackedPlayer = attacked as Player; var attackedMonster = attacked as Monster; if (attackerPlayer != null) { damage = (double)attackerPlayer.MagicAttack; if (attackedPlayer != null) { Player_Player(attackerPlayer, attackedPlayer, spellInfo, ref damage); } else if (attackedMonster != null) { Player_Monster(attackerPlayer, attackedMonster, spellInfo, ref damage); } } else if (attackerMonster != null) { damage = Drivers.Repositories.Safe.Random.Next(attackerMonster.MinAttack, attackerMonster.MaxAttack); if (attackedPlayer != null) { Monster_Player(attackerMonster, attackedPlayer, spellInfo, ref damage); } else if (attackedMonster != null) { Monster_Monster(attackerMonster, attackedMonster, spellInfo, ref damage); } } if (attackerMonster == null || attackerMonster != null && attackerMonster.Behaviour != Enums.MonsterBehaviour.DeathGuard) { SharedDamageCalculations.CalculateLevelExtraDamage(attacker.Level, attacked.Level, ref damage); SharedDamageCalculations.CalculateRebornExtraDamage(attacker.Reborns, ref damage); } return((uint)Math.Max((int)damage, (int)1)); }
public MultiAttackResults AttackWithProjectile(IAttackerEntity attackerEntity, float damage) { IAttackableEntity[] attackableEntitiesWithinAttackersBounds = AttackHelper.AttackableEntitiesWithinAttackersBounds(attackerEntity.AttackerBounds, this.AttackableEntities.ToArray()); float[] damageValuesArray = new float[attackableEntitiesWithinAttackersBounds.Length]; MultiAttackResults multiAttackResults = new MultiAttackResults(); foreach (Point attackersPixel in attackerEntity.AttackerPixels) { Point attackersPixelInScreenCoordinates = CollisionHelper.ConvertTexturePixelToScreenPixel(attackersPixel, attackerEntity.AttackerTransformMatrix); for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { IAttackableEntity attackableEntity = attackableEntitiesWithinAttackersBounds[index]; Point attackersPixelInAttackableEntitysTextureCoordinates = CollisionHelper.ConvertScreenPixelToTexturePixel(attackersPixelInScreenCoordinates, attackableEntity.AttackTransformMatrix); if (attackersPixelInAttackableEntitysTextureCoordinates.X >= 0 && attackersPixelInAttackableEntitysTextureCoordinates.Y >= 0) { if (attackersPixelInAttackableEntitysTextureCoordinates.X < attackableEntity.AttackBooleans.GetLength(0) && attackersPixelInAttackableEntitysTextureCoordinates.Y < attackableEntity.AttackBooleans.GetLength(1)) { if (attackableEntity.AttackBooleans[attackersPixelInAttackableEntitysTextureCoordinates.X, attackersPixelInAttackableEntitysTextureCoordinates.Y]) { damageValuesArray[index] += damage; } } } } } for (int index = 0; index < attackableEntitiesWithinAttackersBounds.Length; index++) { if (damageValuesArray[index] > 0.0f) { if (attackableEntitiesWithinAttackersBounds[index].AttackWithDamage(DamageType.Projectile, damageValuesArray[index])) { multiAttackResults.Kills++; } else { multiAttackResults.Damages++; } } } return(multiAttackResults); }
protected bool Attack(IAttackableEntity target) { if (target == null) { return(false); } StartedAttack?.Invoke(target); ProjectileFactory.CreateProjectile(Configuration.Projectile, target); remainingAttacks--; if (remainingAttacks == 0) { Reload(); } else { nextAttackDelay += Configuration.AttackSpeed; } return(true); }
public static void CreateProjectile(ProjectileConfiguration projectileConfiguration, IAttackableEntity projectileTarget) { Projectile projectile = ProjectilePool.GetPoolObject(); projectile.Initialise(projectileConfiguration, projectileTarget); }