bool CanAttackTarget( Attackable target ) { if( target == null ) return false; return IsEffectiveAgainst( rawAttack, target.GetWord() ); }
// Use this for initialization void Start () { if(attack == null) { attack = GetComponent<Attackable>(); } // SetTarget(new Vector3(-1f, -1f, -1f)); }
public void SetTarget(Attackable target, Attacker owner) { Owner = owner; Target = target; rigid.AddForce(Direction.normalized * StartForce, ForceMode2D.Impulse); float rot_z = Mathf.Atan2(Direction.normalized.y, Direction.normalized.x) * Mathf.Rad2Deg; transform.rotation = Quaternion.Euler(0f, 0f, rot_z - 90); }
public float TargetStrengthDifference(Attackable other) { if (other == null) return 0f; if (other.Owner == null) return RelativeStrength - other.RelativeStrength; return RelativeStrength - other.Owner.RelativeStrength; }
protected override void Attack(GameObject go, Attackable a) { if (ready) { StartCoroutine(Wait(a)); } }
protected virtual void Shoot(Attackable target) { if (target == null) return; Projectile projectile = Projectile.Spawn(BodyCenter).GetComponent<Projectile>(); projectile.SetSize(ProjectileSize); projectile.SetTarget(target, this); projectile.Damage = Power; }
IEnumerator Wait(Attackable a) { Attacking = true; ready = false; yield return new WaitForSeconds(timePerAttack / 2); AudioPlay. PlaySound(attackSound); if (a != null) a.Damage(this); Attacking = false; yield return new WaitForSeconds(timePerAttack / 2); ready = true; }
public virtual bool DoDamageToTarget(Attackable target) { if (CanAttack(target)) { float damageDone = target.Damage(Power, this); Experience += GameManager.Instance.CalculateDamageDoneExp(damageDone, RelativeStrength, target.RelativeStrength); if (target.IsDead) { Experience += GameManager.Instance.CalculateEnemyKilledExp(RelativeStrength, target.RelativeStrength); } return true; } return false; }
protected virtual void UpdateAttacking() { if (Vector3.Distance(CurrentTargetPosition, MinionCenter) > ForgetDistance) { Target = null; State = States.IDLE; return; } CurrentTargetPosition = Target.transform.position; if (Target.Health == 0f) { if (Target.Owner != null) { if (Target.Owner.Minions.Count > 0) { Target = Target.Owner.Minions[0]; } else { Target = null; } } else { Target = null; } if (Target == null) { State = States.IDLE; IdleTimer.Reset(); return; } else { State = States.ATTACKING; } } //If i am weaker or same strength run away if (TargetStrengthDifference(Target) <= 0) { State = States.RUNNING; } Debug.DrawLine(MinionCenter, CurrentTargetPosition, Color.red); }
public void RetroactiveAttack(Attackable attackable) { attackable.GetAttacked(_power); }
public void SetAttacker(Attackable attacker) { this.attacker = attacker; }
protected virtual void Explode() { if (!isAlive) return; rigid.velocity = Vector2.zero; isAlive = false; if (Owner == null) { Despawn(); return; } if (ExplosionRange > 0) { attackables.Clear(); Collider2D[] targets = Physics2D.OverlapCircleAll(rigid.position, ExplosionRange); for (int i = 0; i < targets.Length; i++) { attackable = targets[i].GetComponent<Attackable>(); attackableCollider = targets[i].GetComponent<AttackableCollider>(); if (attackable == null && attackableCollider != null) attackable = attackableCollider.Target; if (attackable == null) continue; if (attackable.Owner == Owner.Owner) continue; attackables.Add(attackable); } for (int i = 0; i < attackables.Count; i++) { ExplodeTarget(attackables[i]); } } else { ExplodeTarget(Target); } if (Animator != null) Animator.SetTrigger("Explode"); else Despawn(); }
public override void ApplyOnTarget(Attackable target) { target.AddEffect(this); }
protected virtual bool ShouldAttack(Attackable other) { if (other == null) return false; if (other.IsDead) return false; if (other.Owner != null && other.Owner == Owner) return false; return true; }
public virtual void SetCurrentAttacker(Attacker attacker) { Target = attacker; }
private void AttackEnemies() { if (this.attackTargetUnits.Count > 0) { GameObject enemy = this.attackTargetUnits[0]; if (enemy == null) { this.attackTargetUnits.RemoveAt(0); return; } Selectable enemySelect = enemy.GetComponent <Selectable>(); if (enemySelect == null) { this.attackTargetUnits.RemoveAt(0); return; } if (enemySelect.UUID.Equals(this.selectable.UUID)) { this.attackTargetUnits.RemoveAt(0); return; } DeathCheck check = enemy.GetComponent <DeathCheck>(); if (check != null && !check.isDead) { if (Vector3.Distance(enemy.transform.position, this.gameObject.transform.position) <= 2.5f) { if (this.gameObject != null && enemy.gameObject != null) { BattlePair p = new BattlePair(this.gameObject, enemy); if (!DeathCheck.pairs.Contains(p)) { //TODO: Swap this to another script that keeps track of strength and HP. Attackable attack = enemy.GetComponent <Attackable>(); if (attack != null) { if (attack.attackCooldown <= 0f) { NetworkViewID viewID = enemy.GetComponent <NetworkView>().viewID; this.attackableNetworkView.RPC("RPC_DecreaseHealth", RPCMode.AllBuffered, viewID); HealthBar bar = enemy.GetComponent <HealthBar>(); Divisible div = enemy.GetComponent <Divisible>(); if (bar.currentHealth <= 0f || bar.healthPercentage <= 0f || !div.IsDivisibleStateReady()) { check.Kill(); DeathCheck.pairs.Add(p); } attack.attackCooldown = 1.414f; } else { attack.attackCooldown -= Time.deltaTime; } } } } } else { Vector3 unitVector = (enemy.transform.position - this.gameObject.transform.position).normalized; if (this.attackableNetworkView != null && !this.receivedAttackCommand) { this.receivedAttackCommand = true; this.attackableNetworkView.RPC("RPC_Attack", RPCMode.AllBuffered, this.gameObject.transform.position + unitVector); } } } } }
public override bool OnTick(Attackable target) { target.ModHp(-tickDmg); return(true); }
public override void OnTick(Targetable target) { Attackable attackable = target as Attackable; attackable.AddHp(heal); }
//private float regenCooldownMax; void Start() { myAttackable = GetComponent <Attackable>(); defaultRate = regenRate; //regenCooldownMax = regenCooldown; }
public void DirectPosition(Vector2 pos) { m_target = null; m_Destination = pos; }
public void Target(GameObject other) { m_target = other.GetComponent <Attackable>(); }
public override bool OnApply(Attackable target) { return(true); }
public virtual void IHaveBeenAttacked(Attackable other) { }
protected override void Move(Attackable target) { Vector3 direction = new Vector3(target.transform.position.x - this.transform.position.x, 0f, target.transform.position.z - this.transform.position.z).normalized; this.transform.position += direction * DefaultSpeed; }
public override void IHaveBeenAttacked(Attackable other) { base.IHaveBeenAttacked(other); if (Type == Types.NEUTRAL) return; if (other.Owner != null) { if (TargetStrengthDifference(other) <= 0) { //Run away Target = other; State = States.RUNNING; } else { //Fight Target = other; State = States.ATTACKING; } } else { //Destroy if we are not attacking something yet if (Target == null) { Target = other; State = States.ATTACKING; } } }
// Abstract Methods protected abstract void Move(Attackable target);
public void rollDamage(int damage, int damageRolls, Attackable a) { //assume melee attack damage for(int i = 0; i < damageRolls; i++) { TdamageRoll += TdamageRoll + Random.Range(1,damage+1); } TdamageRoll += e.strengthModifier(); a.modCurrentHealth(-TdamageRoll); Debug.Log(e.getName()+" deals "+TdamageRoll+" damage (roll = "+(TdamageRoll-e.strengthModifier())+", Strength Modifier = "+e.strengthModifier()+")"); TdamageRoll = 0; }
//Public methods //Find root cause and change public void AdjustStart() { this.allegiance = this.Creator.allegiance; this.EnemyCastle = this.allegiance == false?GameObject.FindGameObjectWithTag("Castle1").GetComponent <Attackable>() : GameObject.FindGameObjectWithTag("Castle0").GetComponent <Attackable>(); }
private void Awake() { attackable = transform.parent.parent.GetComponentInChildren <Attackable>(); width = transform.localScale.x; }
private void MovePlayer() { if (Vector3.Distance(this.transform.position, lastValidMoveTarget) > allowedDelta && isMouseDown) { //Old Solution //Vector3 offset = transform.forward * (Time.deltaTime * moveSpeed); //transform.position += offset; Vector3 desiredPosition = this.transform.position + this.transform.forward * (Time.deltaTime * moveSpeed); Vector3 bottomSphere = desiredPosition + transform.forward * forwardOffset + bottomOffset; Vector3 topSphere = desiredPosition + transform.forward * forwardOffset + heightOffset; int count = Physics.OverlapCapsuleNonAlloc(bottomSphere, topSphere, overlapRadius, overlapResults); bool canMove = true; for (int i = 0; i < count; i++) { //Debug.Log(overlapResults[i].name); if (overlapResults[i].gameObject.tag == "NoPass") { //This shouldn't break anything but is just expensive. You can use it, if you feel like the code's broken //currentCornerIndex += 1; //if (currentCornerIndex < path.corners.Length) //{ // targetCorner = path.corners[currentCornerIndex]; // Vector3 lookPoint = targetCorner; // lookPoint.y = transform.position.y; // transform.LookAt(lookPoint); //} //canMove = false; //This line just sucks } } if (canMove) { transform.position = desiredPosition; } } else if (Vector3.Distance(this.transform.position, lastValidMoveTarget) > allowedDelta && !isMouseDown) { if (Vector3.Distance(transform.position, targetCorner) > allowedDelta) { Vector3 offset = transform.forward * (Time.deltaTime * moveSpeed); transform.position += offset; } else { currentCornerIndex += 1; if (currentCornerIndex < path.corners.Length) { targetCorner = path.corners[currentCornerIndex]; Vector3 lookPoint = targetCorner; lookPoint.y = transform.position.y; transform.LookAt(lookPoint); } else if (attackTarget != null) { //Additional Attack code needed!!!!!! Vector3 lookPoint = attackTarget.transform.position; lookPoint.y = this.transform.position.y; this.transform.LookAt(lookPoint); //HAAAAACK attackTarget = null; currentMode = IDLE; } } } }
public override bool OnRemove(Attackable target) { target.ModHp(-removeDmg); return(true); }
public bool IsUsable(Attackable attacker, Attackable target) { return((IsMelee(attacker, target) || TargetingFunction.IsInRangeorMelee(attacker, target, Range)) && IsValidTarget(target)); }
protected bool canAttack(Attackable atkObj) { return(!(!atkObj || (atkObj.gameObject == Creator) || m_collidedObjs.Contains(atkObj) || !atkObj.CanAttack(Faction))); }
public virtual void Cast(Attackable from, Attackable onto) { from.RemoveMana(Cost); }
//public AudioClip dmgHit; protected override void Attack(GameObject go, Attackable a) { }
public virtual void Cast(Character caster, Attackable target) { caster.RemoveMana(caster.calculateCost(this)); }
/// <summary> /// Checks this alliance can attack the given alliance. /// </summary> /// <param name="allianceID">Alliance ID to check against.</param> /// <returns>True if can attack the given alliance, else false.</returns> public bool CanAttack(AllianceID allianceID) { return(Attackable.Contains(allianceID)); }
public override void ApplyOnTarget(Attackable target) { appliedTime = 0f; target.AddEffect(this); }
public virtual void IHaveSeenAttackable(Attackable other) { }
public abstract bool OnApply(Attackable target);
protected virtual void UpdateRunning() { if (Target.Owner != null) { CurrentTargetPosition = MinionCenter - (Target.Owner.MinionCenter - CurrentTargetPosition).normalized * RunDistance; Debug.DrawLine(MinionCenter, CurrentTargetPosition, Color.blue); if (TargetStrengthDifference(Target) > 0) State = States.ATTACKING; if (Vector3.Distance(Target.Owner.CurrentTargetPosition, CurrentTargetPosition) > SaveDistance) { Target = null; State = States.IDLE; } } else { Target = null; } }
public abstract bool OnTick(Attackable target);
public override void IHaveSeenAttackable(Attackable other) { base.IHaveSeenAttackable(other); if (Type == Types.NEUTRAL) return; IHaveBeenAttacked(other); }
public abstract bool OnRemove(Attackable target);
public override bool OnApply(Attackable target) { tickTime = 1; target.ModHp(-initialDmg); return(true); }
protected virtual bool CanAttack(Attackable other) { if (!ShouldAttack(other)) return false; return GameManager.Instance.CanAttack(this, other); }
/* public void attackOfOpportunity(GameObject g) { //may have been scrapped try { Attackable aooA = g.GetComponent<Attackable>(); if(attackRoll() > aooA.getArmorClass()) { try { hitee = hit.transform.gameObject.GetComponent<Animator>(); if(hit.transform.gameObject.tag == "Player") { hitee.SetTrigger("playerHit"); } } catch (Exception e) { //nothing so far } if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } aooA.modCurrentHealth(-damageRoll()); } } catch (Exception e) { //nothing so far } } */ private int getArmorClass(bool flatFooted, bool touch, Attackable a) { try { Entity e = a.transform.gameObject.GetComponent<Entity>(); if(flatFooted && touch) { if(e.dexterityModifier() > e.armorArmorClass()) { return e.getArmorClass() + e.armorArmorClass() + 10; } else { return e.getArmorClass() + e.dexterityModifier() + 10; } } else if(flatFooted) { return e.getArmorClass() + e.armorArmorClass() + 10; } else if(touch) { return e.getArmorClass() + e.dexterityModifier() + 10; } else { Debug.Log("AC = "+e.getArmorClass()+" + "+e.dexterityModifier()+" + "+e.armorArmorClass()+" + 10"); return (e.getArmorClass() + e.dexterityModifier() + e.armorArmorClass() + 10); } } catch (Exception ex) { return a.getArmorClass() + 10; } }
public void setTarget(Attackable target) { Debug.Log("New target: " + target.ToString()); // Store data regarding our new target attackTarget = target; attackTargetLastKnowTileLocation = mapManager.getTileAtPosition(target.transform.position); }
public void attack(Weapon w, Attackable a, bool flatFooted, bool touch) { //function actually attacks AC = getArmorClass(flatFooted, touch, a); rollAttack(); Debug.Log(e.getName()+" attack roll = "+TattackRoll); if(TattackRoll == 1) { //critical miss, add some sort of fumble later Debug.Log(e.getName()+"'s attack critically misses :("); if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } } else if(TattackRoll >= 21 - w.getCriticalRange()) { //critical hit rollAttack(); Debug.Log(e.getName()+" critical roll = "+TattackRoll); if(TattackRoll == 20 || TattackRoll+attackBonus(w) > AC) { Debug.Log(e.getName()+" lands a critical hit!"); for(int i = 0; i < w.getCriticalRolls(); i++) { rollDamage(w.getDamage(), w.getDamageRolls(), a); } } try { hitee = hit.transform.gameObject.GetComponent<Animator>(); if(hit.transform.gameObject.tag == "Player") { hitee.SetTrigger("playerHit"); } } catch (Exception ex) { Debug.Log(ex); } if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } rollDamage(w.getDamage(), w.getDamageRolls(), a); } else if(TattackRoll == 20 || TattackRoll+attackBonus(w) > AC) { //hit try { hitee = hit.transform.gameObject.GetComponent<Animator>(); if(hit.transform.gameObject.tag == "Player") { hitee.SetTrigger("playerHit"); } } catch (Exception ex) { Debug.Log(ex); } if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } rollDamage(w.getDamage(), w.getDamageRolls(), a); } else { if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } } if(w.getTwoAttackRolls()) { rollAttack(); Debug.Log(e.getName()+" attack roll = "+TattackRoll); if(TattackRoll == 1) { Debug.Log(e.getName()+"'s attack critically misses :("); if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } } else if(TattackRoll < 21 - w.getCriticalRange()) { rollAttack(); Debug.Log(e.getName()+" critical roll = "+TattackRoll); if(TattackRoll == 20 || TattackRoll+attackBonus(w) > AC) { Debug.Log(e.getName()+" lands a critical hit!"); if(w.getTwoCriticalRolls()) { for(int i = 0; i < w.getSecondAttackCritical(); i++) { rollDamage(w.getSecondAttackDamage(), w.getDamageRolls(), a); } } else { for(int i = 0; i < w.getCriticalRolls(); i++) { rollDamage(w.getSecondAttackDamage(), w.getDamageRolls(), a); } } } try { hitee = hit.transform.gameObject.GetComponent<Animator>(); if(hit.transform.gameObject.tag == "Player") { hitee.SetTrigger("playerHit"); } } catch (Exception ex) { Debug.Log(ex); } if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } rollDamage(w.getSecondAttackDamage(), w.getDamageRolls(), a); } else if(TattackRoll == 20 || TattackRoll+attackBonus(w) > AC) { try { hitee = hit.transform.gameObject.GetComponent<Animator>(); if(hit.transform.gameObject.tag == "Player") { hitee.SetTrigger("playerHit"); } } catch (Exception ex) { Debug.Log(ex); } if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } rollDamage(w.getSecondAttackDamage(), w.getDamageRolls(), a); } else { if(transform.gameObject.tag == "Player") { hitter.SetTrigger("playerAttack"); } else if(transform.gameObject.tag == "Fightable") { hitter.SetTrigger("fightableAttack"); } } } }
public IEnumerator commenceBattle(Attackable opponent) { // If we are already in a battle, we should abort the current commenceBattle request Debug.Log(isInBattle); if (isInBattle) yield break; Debug.Log("Commencing attack!"); eventManager.addEvent(opponent.gameObject.transform.position); // If we are attacking an anthill, the battle will behave somewhat differently Anthill anthill = opponent.GetComponent<Anthill>(); hasSetNewPath = false; // Set both units to be in 'attack mode' and generate a 'combat cloud' GameObject cloud = null; opponent.startBattle(); if (!anthill) { isInBattle = true; Vector3 pos = mapManager.getTileAtPosition(transform.position).transform.position; if (Network.isClient || Network.isServer) { cloud = Network.Instantiate(combatCloud, new Vector3(pos.x, pos.y, transform.position.z - 1), Quaternion.identity, 0) as GameObject; networkView.RPC("fixCombatCloud", RPCMode.All, cloud.networkView.viewID); } else { cloud = GameObject.Instantiate(combatCloud, new Vector3(pos.x, pos.y, transform.position.z - 1), Quaternion.identity) as GameObject; } if (getPlayerId() == 1) { cloud.transform.Find("RedHead").gameObject.GetComponent<SpriteRenderer>().sprite = this.getFightSprite(); cloud.transform.Find("BlueHead").gameObject.GetComponent<SpriteRenderer>().sprite = opponent.getFightSprite(); } else { cloud.transform.Find("RedHead").gameObject.GetComponent<SpriteRenderer>().sprite = opponent.getFightSprite(); cloud.transform.Find("BlueHead").gameObject.GetComponent<SpriteRenderer>().sprite = this.getFightSprite(); } cloud.transform.parent = GameObject.Find("Objects").transform; gameObject.renderer.enabled = false; opponent.gameObject.renderer.enabled = false; } else { // If we are attacking an anthill, make sure to 'face' it if (transform.position.x < opponent.transform.position.x) transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y); } // Every second, battle calculations should take place only if we haven't started moving again while (true) { // Do one round of battle calculations exchangeBlows(this, opponent); // Wait for 1 seconds Debug.Log("AttackableOne: " + this.currentHp + ", AttackableTwo: " + opponent.currentHp); yield return new WaitForSeconds(1); // If we are fighting an anthill, we can be interrupted by another battle during our yield if (anthill && isInBattle) { Debug.Log("Interrupted by another battle!"); break; } // If we are fighting an anthill, can interrupt our own battle by leaving if (anthill && hasSetNewPath) { Debug.Log("Cancelled attack on anthill due to moving away!"); break; } // Check if one of the units has died if (this.currentHp <= 0 || opponent.currentHp <= 0) { Debug.Log("Cancelled attack since at least one of us is dead!"); break; } } hasSetNewPath = false; // After the battle, 'cleanup' the unit(s) and the combat cloud if (cloud) { if (Network.isClient || Network.isServer) { Network.Destroy(cloud); } else { GameObject.Destroy(cloud); } } if (transform.localScale.x < 0) transform.localScale = new Vector2(transform.localScale.x * -1, transform.localScale.y); gameObject.renderer.enabled = true; opponent.gameObject.renderer.enabled = true; this.removeFromBattle(); opponent.removeFromBattle(); if (opponent.currentHp <= 0) opponent.kill(); // Note: if this unit dies, make sure to delete it at the end! if (this.currentHp <= 0) this.kill(); }
protected abstract void Attack(GameObject go, Attackable a);
void Start() { player = FindObjectOfType <PlayerInputBody>().GetComponent <Attackable>(); }
private void exchangeBlows(Attackable antOne, Attackable antTwo) { // Calculate each ant's attack based on their remaining health and base attack stat Debug.Log(antOne.currentHp / antOne.maxHp); float antOneAttack = antOne.attack * (antOne.currentHp / antOne.maxHp); //TODO: dynamic attack calculations float antTwoAttack = antTwo.attack * (antTwo.currentHp / antTwo.maxHp); //TODO: dynamic attack calculations // Calculate damage dealt by factoring in eachothers defenses and apply to current hp float hpOne = Mathf.Max(Random.Range(antTwoAttack*0.5f, antTwoAttack*1.5f) - antOne.defense, 0); float hpTwo = Mathf.Max(Random.Range(antOneAttack*0.5f, antOneAttack*1.5f) - antTwo.defense, 0); if (Network.isClient || Network.isServer) { NetworkView networkAntOne = antOne.networkView; NetworkView networkAntTwo = antTwo.networkView; networkView.RPC("setHPNetwork", RPCMode.All, hpOne, hpTwo, networkAntOne.viewID, networkAntTwo.viewID); } else { antOne.currentHp -= hpOne; antTwo.currentHp -= hpTwo; } }
public void Attack(Attackable target, double shieldPenetration = 0) { var missProbability = Type == StationModuleModule.LASER_LOW_RANGE ? 0.1 : Type == StationModuleModule.LASER_MID_RANGE ? 0.3 : Type == StationModuleModule.LASER_HIGH_RANGE ? 0.4 : Type == StationModuleModule.ROCKET_LOW_ACCURACY ? 0.5 : Type == StationModuleModule.ROCKET_MID_ACCURACY ? 0.3 : 1.00; var damage = AttackManager.RandomizeDamage((Type == StationModuleModule.LASER_LOW_RANGE ? 59850 : Type == StationModuleModule.LASER_MID_RANGE ? 48450 : Type == StationModuleModule.LASER_HIGH_RANGE ? 28500 : Type == StationModuleModule.ROCKET_LOW_ACCURACY ? 85500 : Type == StationModuleModule.ROCKET_MID_ACCURACY ? 71250 : 0), missProbability); damage = 1000; //for test var damageType = (Type == StationModuleModule.LASER_LOW_RANGE || Type == StationModuleModule.LASER_MID_RANGE || Type == StationModuleModule.LASER_HIGH_RANGE) ? DamageType.LASER : (Type == StationModuleModule.ROCKET_LOW_ACCURACY || Type == StationModuleModule.ROCKET_MID_ACCURACY) ? DamageType.ROCKET : DamageType.LASER; var cooldown = (Type == StationModuleModule.ROCKET_LOW_ACCURACY || Type == StationModuleModule.ROCKET_MID_ACCURACY) ? 2 : 1; if (target.Position.DistanceTo(Position) < GetRange()) { if (!TargetDefinition(target)) { return; } if (lastAttackTime.AddSeconds(cooldown) < DateTime.Now) { int damageShd = 0, damageHp = 0; double shieldAbsorb = System.Math.Abs(target.ShieldAbsorption - shieldPenetration); if (shieldAbsorb > 1) { shieldAbsorb = 1; } if ((target.CurrentShieldPoints - damage) >= 0) { damageShd = (int)(damage * shieldAbsorb); damageHp = damage - damageShd; } else { int newDamage = damage - target.CurrentShieldPoints; damageShd = target.CurrentShieldPoints; damageHp = (int)(newDamage + (damageShd * shieldAbsorb)); } if ((target.CurrentHitPoints - damageHp) < 0) { damageHp = target.CurrentHitPoints; } if (target is Player && !(target as Player).Attackable()) { damage = 0; damageShd = 0; damageHp = 0; } if (damageType == DamageType.LASER) { if (target is Player && (target as Player).Storage.Sentinel) { damageShd -= Maths.GetPercentage(damageShd, 30); } if (target is Player && (target as Player).Storage.Diminisher) { if ((target as Player).Storage.UnderDiminisherEntity == this) { damageShd += Maths.GetPercentage(damage, 30); } } var laserRunCommand = AttackLaserRunCommand.write(Id, target.Id, 0, false, false); SendCommandToInRangeCharacters(laserRunCommand); } else if (damageType == DamageType.ROCKET) { var rocketRunPacket = $"0|v|{Id}|{target.Id}|H|" + 1 + "|0|1"; SendPacketToInRangeCharacters(rocketRunPacket); } if (damage == 0) { SendCommandToInRangeCharacters(AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 1), target); if (target is Player) { (target as Player).SendCommand(AttackMissedCommand.write(new AttackTypeModule((short)damageType), target.Id, 0)); } } else { var attackHitCommand = AttackHitCommand.write(new AttackTypeModule((short)damageType), Id, target.Id, target.CurrentHitPoints, target.CurrentShieldPoints, target.CurrentNanoHull, damage > damageShd ? damage : damageShd, false); SendCommandToInRangeCharacters(attackHitCommand); } if (damageHp >= target.CurrentHitPoints || target.CurrentHitPoints <= 0) { target.Destroy(this, DestructionType.MISC); } else { if (target.CurrentNanoHull > 0) { if (target.CurrentNanoHull - damageHp < 0) { var nanoDamage = damageHp - target.CurrentNanoHull; target.CurrentNanoHull = 0; target.CurrentHitPoints -= nanoDamage; } else { target.CurrentNanoHull -= damageHp; } } else { target.CurrentHitPoints -= damageHp; } } target.CurrentShieldPoints -= damageShd; target.LastCombatTime = DateTime.Now; target.UpdateStatus(); lastAttackTime = DateTime.Now; } } }
private void clearAttackTarget() { attackTarget = null; attackTargetLastKnowTileLocation = null; }
void ShowLine(Attackable target) { }
public void Attack(int x, int y, Attackable source) { throw new NotImplementedException(); }
public abstract void OnContact(Attackable target);
protected bool CanSeeEnemy(out Attackable a, out GameObject go) { a = null; go = null; RaycastHit2D h = Physics2D.Raycast(transform.position, (DirectionIsToLeft) ? transform.up : -transform.up, sight, enemyMask); if (h.collider == null) return false; a = h.collider.GetComponent<Attackable>(); go = h.collider.gameObject; return a != null; }
protected virtual void ExplodeTarget(Attackable target) { if (target == null) return; Owner.DoDamageToTarget(target); Vector2 force = (target.Position - rigid.position); force *= (ExplosionRange - force.magnitude); //Reverse force magnitude (closer = bigger force) force *= ExplosionForce; if (force.magnitude < 0) //don't suck things in force *= 0; target.AddForce(force, ForceMode2D.Impulse); }