public void Attack(IAttackable otherCharacter) { if (!this.IsAlive()) { throw new InvalidOperationException(ErrorMessages.DeadBlobAttackError); } this.attack.Attack(otherCharacter); }
/// <summary> /// Damage is applied here, hit animation /// </summary> /// <param name="attacker">Entity doing the damage</param> /// <returns>Damage done</returns> public int Defend(IAttackable attacker) { int damage = attacker.Damage; // should be multidimensional - type, direction, level, effect this.HP = this.HP - damage; // should be more complicated, use equipment and effects //this.color = defend_color; // should be animation return damage; // should graphically pop up }
public void MobCanAttackWithWeapon() { var weapon = Substitute.For<IWeapon> (); _mob.Equip (weapon); _attackable = Substitute.For<IAttackable> (); _mob.Attack (_attackable); weapon.Received ().Attack (_attackable, _mob.AttackSkill); }
public override void Attack(IAttackable otherCharacter) { int selfDamage = this.Owner.Health / 2; if (this.Owner.Health - selfDamage <= 0) { selfDamage++; } this.Owner.TakeDamage(selfDamage); this.SetDamage(); base.Attack(otherCharacter); }
public void TestWeaponAttacksTarget() { var meleeWeapon = new Weapon (); meleeWeapon.Range = 1f; _mob.Equip (meleeWeapon); _attackable = Substitute.For<IAttackable> (); _mob.Attack (_attackable); _attackable.Received ().Defend (meleeWeapon.Power, _mob.AttackSkill); }
public virtual void Attack(IAttackable otherCharacter) { if (this.Owner == default(IBlob)) { throw new InvalidOperationException(ErrorMessages.OwnerNotSet); } if (!otherCharacter.IsAlive()) { throw new InvalidOperationException(ErrorMessages.DeadBlobAttackedError); } otherCharacter.TakeDamage(this.Damage); }
private IEnumerator Attack_Sequence(IAttackable attackable) { // Stop other coroutine exectution Is_Enabled = false; // Check used only to prevent crash when coroutine called frome Launch death animation if (attackable != null) { attackable.Be_Attacked(); } // Launch animation Mini_Slime_An.Launch_Death_Animation(); // Stop the mob from moving Mini_Slime_Mo.Set_Life(false); // Wait for the animation to finish yield return(new WaitForSeconds(0.5f)); // Destroy entire game object by calling the finction in a parent script Mini_Slime_He.Destroy(); }
public override void AddKill(IAttackable attackable) { if (attackable is Character deadCharacter && deadCharacter.FactionId != Player.FactionId && (deadCharacter.Hangar.Ship.RootId == 8 || deadCharacter.Hangar.Ship.RootId == 10)) { Stats.Kills += 1; if (Stats.Kills == 10) { //todo: fix Stats.Complete = true; //Packet.Builder.QuestCompletedCommand(Player.GetGameSession(), this); Player.AcceptedQuests.Remove(this); Player.CompletedQuests.Add(this); //Packet.Builder.QuestListCommand(Player.GetGameSession()); Reward.ParseRewards(Player); } //Packet.Builder.QuestConditionUpdateCommand(Player.GetGameSession(), Root.Elements[0].Condition); } base.AddKill(attackable); }
public bool execute() { GameObject raw = logic.master.entityMap[logic.player.ahead]; if (raw != null) { MonoBehaviour[] scripts = raw.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour mb in scripts) { IAttackable target = mb as IAttackable; if (target != null) { interaction.attack(logic.player, target); return(true); } } } return(false); }
public static bool IsValidTarget(this IAttackable t, bool mustBeEnemy = true) { if (t == null || t.Name == "WardCorpse") { return(false); } if (!t.IsVisible || t.IsDead || !t.IsTargetable || t.IsInvulnerable || mustBeEnemy && !t.IsEnemy()) { return(false); } if (t is IUnit unit && !unit.IsHPBarRendered) { return(false); } return(true); }
/// <inheritdoc/> public void ShowSkillAnimation(Player attackingPlayer, IAttackable target, Skill skill) { var playerId = attackingPlayer.GetId(this.player); var targetId = target.GetId(this.player); var skillId = NumberConversionExtensions.ToUnsigned(skill.SkillID); using (var writer = this.connection.StartSafeWrite(0xC3, 0x09)) { var packet = writer.Span; packet[2] = 0x19; packet[3] = skillId.GetHighByte(); packet[4] = skillId.GetLowByte(); packet[5] = playerId.GetHighByte(); packet[6] = playerId.GetLowByte(); packet[7] = targetId.GetHighByte(); packet[8] = targetId.GetLowByte(); writer.Commit(); } }
private static float CalculateCastDamage(IAttackable attacker, IAttackable defender, int level, double power) { var rangeLvl = level; var armour = defender.GetEquipmentStats().ArmorPower; var rangeEquip = 15f; int armourRatio = (int)(60D + ((double)((rangeEquip * 3D) - armour) / 300D) * 40D); if (UnityEngine.Random.value * 100f > armourRatio && UnityEngine.Random.value <= 0.5) { return(0); } int max = (int)(((double)rangeLvl * 0.15D) + 0.85D + power); int peak = (int)(((double)max / 100D) * (double)armourRatio); int dip = (int)(((double)peak / 3D) * 2D); return(RandomWeighted(0, dip, peak, max)); }
public override IEnumerator Start() { List <Vector3Int> tiles = playerManager.TilesInBasic(); List <RaycastHit2D> hits = GridHelper.RaycastTiles(tiles); for (int i = 0; i < tiles.Count; ++i) { GridHelper.groundTilemap.SetColor(tiles[i], playerManager.atkRangeColor); if (hits[i]) { IAttackable target = hits[i].collider.gameObject.transform.parent.GetComponent <IAttackable>(); if (target != null) { target.SetAttackableOutline(!playerManager.playerInfo.attacked); } } } yield break; }
public static float GetAutoAttackRange(IUnit source, IAttackable target) { if (target is IUnit unit) { var champ = source.CharName; if (champ == "Caitlyn" && unit.HasBuff("caitlynyordletrapinternal")) { return(1300f); } if (champ == "Aphelios" && source.HasBuff("aphelioscalibrumbonusrangebuff") && unit.HasBuff("aphelioscalibrumbonusrangedebuff")) { return(1800f); } } return(GetAutoAttackRange(source) + target.BoundingRadius); }
public HealthBar Add(IAttackable enemy) { if (!healthBarPrefab) { return(null); } if (enemy == null) { return(null); } var enemyName = ((MonoBehaviour)enemy).name; lock (mutex) { if (healthBars.Any(x => x.Target == enemy)) { Debug.LogWarning($"{enemyName} already have an assigned health bar."); return(null); } } var healthBar = Instantiate(healthBarPrefab, transform); if (!healthBar) { Debug.LogError($"Failed to add health bar for {enemyName}"); return(null); } var barComponent = healthBar.GetComponent <HealthBar>(); barComponent.Manager = this; barComponent.SetTarget(enemy); lock (mutex) { healthBars.Add(barComponent); } return(barComponent); }
void Update() { timerAlive += Time.deltaTime; if (timerAlive >= 10) { Destroy(gameObject); } transform.Translate(Vector3.up * Time.deltaTime * 4, Space.Self); Ray ray = new Ray(transform.position - transform.up, transform.up); RaycastHit hit; if (Physics.Raycast(ray, out hit, 1.2f, hitMask)) { GameObject go = Instantiate(audioPrefab); go.transform.position = transform.position; AudioSource source = go.GetComponent <AudioSource>(); bool remove = true; if (hit.collider.GetComponent <IAttackable>() != null) { IAttackable att = hit.collider.GetComponent <IAttackable>(); Debug.Log(hit.collider.name); att.Damage(1); source.clip = att.GetHitClip(); } else { source.clip = hitSound; } source.pitch = Random.Range(0.95f, 1.05f); source.volume = Random.Range(0.1f, 0.2f); if (remove) { source.Play(); Destroy(gameObject); } } }
static void Main() { GameManager gm = new GameManager(); RegisterUnits(gm); gm.KingAttacked += gm.King.OnAttack; foreach (var guard in gm.RoyalGuards) { gm.KingAttacked += guard.OnAttack; } foreach (var footman in gm.Footmans) { gm.KingAttacked += footman.OnAttack; } string input = ""; while ((input = Console.ReadLine()) != "End") { string[] args = input.Split(); string command = args[0]; string name = args[1]; switch (command) { case "Attack": gm.AttackKing(); break; case "Kill": IAttackable result = gm.KillUnit(name); if (result != null) { gm.KingAttacked -= result.OnAttack; } break; } } }
/// <summary> /// Gets the hit information, calculates which part of the damage damages the shield and which the health. /// </summary> /// <param name="defender">The defender.</param> /// <param name="damage">The damage.</param> /// <param name="attributes">The attributes.</param> /// <param name="attacker">The attacker.</param> /// <returns>The calculated hit info.</returns> public static HitInfo GetHitInfo(this IAttackable defender, uint damage, DamageAttributes attributes, IAttackable attacker) { var shieldBypass = Rand.NextRandomBool(attacker.Attributes[Stats.ShieldBypassChance]); if (shieldBypass || defender.Attributes[Stats.CurrentShield] < 1) { hi = new HitInfo((uint)dmg, 0, 0); } else { var shieldRatio = 0.90; shieldRatio -= attacker.Attributes[Stats.ShieldDecreaseRateIncrease]; shieldRatio += defender.Attributes[Stats.ShieldRateIncrease]; shieldRatio = Math.Max(0, shieldRatio); shieldRatio = Math.Min(1, shieldRatio); hi = new HitInfo((uint)(dmg * (1 - shieldRatio)), (uint)(dmg * shieldRatio), attributes); } return(hi); }
private bool ChestEncounter(IAttackable monster) { var encounterResult = false; Console.WriteLine("\n\n\nIt's just a chest . . ."); TextUtils.AnimateText($". . . . . . . . . .{Environment.NewLine}", 100); Console.ForegroundColor = ConsoleColor.Red; TextUtils.AnimateText($"or is it a Mimic?!", 500); player.Attack(monster); monster.Attack(player); Console.ResetColor(); Console.ReadKey(true); if (monster.Health <= 0) { encounterResult = true; } return(encounterResult); }
public void OnTriggerEnter2D(Collider2D col) { if (col.transform == player) { Debug.Log("Self Hit"); return; } IAttackable attack = col.GetComponent <IAttackable>(); if (attack != null) { OnHit.Invoke(); Vector2 finalKb = kb; finalKb.x *= Mathf.Sign(transform.lossyScale.x); attack.Attack(finalKb, damage, force); } }
private static GameSession[] AssembleSelectedSessions(IAttackable target) { var hits = target.Spacemap.Entities.Where(x => x.Value is Player && x.Value.Selected == target).ToArray(); var l = hits.Length; if (target is Player) { l += 1; } GameSession[] sessions = new GameSession[l]; for (var i = 0; i < hits.Length; i++) { sessions[i] = ((Player)hits[i].Value).GetGameSession(); } if (l > hits.Length) { sessions[l - 1] = ((Player)target).GetGameSession(); } return(sessions); }
public void Attack(IAttackable target) { string targetName = target.Name; int baseAttack = UnityEngine.Random.Range(0, 100); int totalAttack = baseAttack + Accuracy; int damage = UnityEngine.Random.Range(MinDamage, MaxDamage); string attackFormat; if (baseAttack >= 95) // 5% chance to crit. Hardcoded for now, maybe turn it into a stat later. { totalAttack *= 10; // Extremely high chance to land a hit when delivering a critical. damage *= CritMultiplier; attackFormat = CRITICAL_ATTACK_FORMAT; } else { attackFormat = NORMAL_ATTACK_FORMAT; } target.Attack(totalAttack, damage, string.Format(attackFormat, targetName)); }
private void SendMagicEffectStatus(MagicEffect effect, IAttackable affectedPlayer, bool isActive, uint duration) { if (effect.Definition.Number <= 0) { return; } // TODO: Duration var playerId = affectedPlayer.GetId(this.player); using (var writer = this.connection.StartSafeWrite(0xC1, 0x07)) { var packet = writer.Span; packet[2] = 0x07; packet[3] = isActive ? (byte)1 : (byte)0; packet.Slice(4).SetShortSmallEndian(playerId); packet[6] = (byte)effect.Id; writer.Commit(); } }
/// <summary> /// Applies the regeneration of the players skill to the target. /// </summary> /// <param name="target">The target.</param> /// <param name="player">The player.</param> /// <param name="skillEntry">The skill entry.</param> public static void ApplyRegeneration(this IAttackable target, Player player, SkillEntry skillEntry) { var skill = skillEntry.Skill; var regenerationValue = player.Attributes.CreateElement(skill.MagicEffectDef.PowerUpDefinition.Boost); var regeneration = Stats.IntervalRegenerationAttributes.FirstOrDefault(r => r.CurrentAttribute == skill.MagicEffectDef.PowerUpDefinition.TargetAttribute); if (regeneration != null) { var value = skillEntry.Level == 0 ? regenerationValue.Value : regenerationValue.Value + skillEntry.CalculateValue(); target.Attributes[regeneration.CurrentAttribute] = Math.Min( target.Attributes[regeneration.CurrentAttribute] + value, target.Attributes[regeneration.MaximumAttribute]); } else { Log.Warn( $"Regeneration skill {skill.Name} is configured to regenerate a non-regeneration-able target attribute {skill.MagicEffectDef.PowerUpDefinition.TargetAttribute}."); } }
public override AttackLog DealDamage(IAttackable target) { if (!this.CanAttack()) { return(AttackLog.AttackFailed); } else if (target.IsAlive) { SkillDamage attackPower; AttackLog result; if (RandomGenerator.GetRandomValue(0, 101) % 2 == 0) { var specialSkills = this.AvailableSkills.Where(x => !(x is BasicAttack)).ToList(); var skillToUse = specialSkills[RandomGenerator.GetRandomValue(0, specialSkills.Count)]; var appliesStatusEffect = skillToUse as IAppliesStatusEffect; if (appliesStatusEffect != null) { target.AddStatusEffect(appliesStatusEffect.ApplyEffect()); } attackPower = skillToUse.DealDamage(this.AttackDamage); result = target.TakeDamage(attackPower); result.AttackDetails = string.Format("{0} applies {1} on {2}", this.Name, skillToUse.Name, result.AttackDetails); this.OnAbilityUsed(); return(result); } else { this.OnAbilityUsed(); return(base.DealDamage(target)); } } return(AttackLog.AttackFailed); }
public string Attack(string[] args) { string attackerName = args[0]; string receiverName = args[1]; Character character = this.party.FirstOrDefault(x => x.Name == attackerName); if (character == null) { throw new ArgumentException($"Character {attackerName} not found!"); } Character receiver = this.party.FirstOrDefault(x => x.Name == receiverName); if (receiver == null) { throw new ArgumentException($"Character {receiverName} not found!"); } if (!(character is IAttackable)) { throw new ArgumentException($"{attackerName} cannot attack!"); } IAttackable attacker = character; if (receiver.IsAlive && character.IsAlive) { attacker.Attack(receiver); } string result = $"{attackerName} attacks {receiverName} for {character.AbilityPoints} hit points! {receiverName} has " + $"{receiver.Health}/{receiver.BaseHealth} HP and {receiver.Armor}/{receiver.BaseArmor} AP left!"; if (receiver.IsAlive == false) { result += $"\n{receiverName} is dead!"; } return(result); }
void TryMoveTo(Coord coord) { if (Map.IsWalkable(coord)) { Collider2D collision = CustomRaycast.GetMapEntityColliderAt(coord); if (collision != null) // something is in the way { IAttackable target = collision.GetComponent <IAttackable>(); if (target != null) // that something can be attacked { attack.Attack(target); time.Increase(AttackSpeed); } } else { transform.position = (Vector2)coord; time.Increase(MoveSpeed); } } }
/// <summary> /// Is called when an <see cref="IAttackable" /> object got killed by another. /// </summary> /// <param name="killed">The killed <see cref="IAttackable" />.</param> /// <param name="killer">The killer.</param> public void AttackableGotKilled(IAttackable killed, IAttacker killer) { if (killer is Player { GuildWarContext : not null } killerPlayer && killed is Player { GuildWarContext : not null } killedPlayer && killerPlayer.GuildWarContext !.Team != killedPlayer.GuildWarContext !.Team) { var score = killedPlayer.GuildStatus?.Position == GuildPosition.GuildMaster ? (byte)2 : (byte)1; if (killerPlayer.GuildWarContext.Team == GuildWarTeam.First) { killerPlayer.GuildWarContext.Score.IncreaseFirstGuildScore(score); } else { killerPlayer.GuildWarContext.Score.IncreaseSecondGuildScore(score); } } }
public void OnAttack() { Bounds bounds = attackTrigger.bounds; int barrels = LayerMask.NameToLayer("Barrels"); int crates = LayerMask.NameToLayer("Crates"); int enemies = LayerMask.NameToLayer("Enemies"); int mask = 1 << barrels; mask |= 1 << crates; mask |= 1 << enemies; Collider2D collider = Physics2D.OverlapBox(bounds.center, bounds.size, 0, mask); if (collider != null) { IAttackable attackable = collider.gameObject.GetComponent <IAttackable>(); if (attackable != null) { attackable.Attack(); } } }
/// <inheritdoc/> public void ObjectGotKilled(IAttackable killed, IAttackable killer) { var killedId = killed.GetId(this.player); var killerId = killer.GetId(this.player); using (var writer = this.connection.StartSafeWrite(0xC1, 9)) { var packet = writer.Span; packet[2] = 0x17; packet[3] = killedId.GetHighByte(); packet[4] = killedId.GetLowByte(); packet[7] = killerId.GetHighByte(); packet[8] = killerId.GetLowByte(); writer.Commit(); } if (this.player == killed && killer is Player killerPlayer) { this.player.PlayerView.ShowMessage($"You got killed by {killerPlayer.Name}", MessageType.BlueNormal); } }
void TriggerEffect(Effect effect) { Ray ray = LevelController.Instance.MainCamera.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (!Physics.Raycast(ray, out hit, Mathf.Infinity, clickableLayer)) { return; } if (effect == Effect.Lightining) { IAttackable attackable = hit.collider.GetComponent <IAttackable>(); attackable?.StruckedByLightning(); } else { IDousable dousable = hit.collider.GetComponent <IDousable>(); dousable?.RainedOn(); } }
public override IEnumerator HideAttack() { List <Vector3Int> tiles = playerManager.TilesInBasic(); List <RaycastHit2D> hits = GridHelper.RaycastTiles(tiles); for (int i = 0; i < tiles.Count; ++i) { GridHelper.groundTilemap.SetColor(tiles[i], Color.white); if (hits[i]) { IAttackable target = hits[i].transform.parent.GetComponent <IAttackable>(); if (target != null) { target.SetAttackableOutline(false); } } } playerManager.SetState(new MyTurn(playerManager)); yield break; }
public void Attack(float deltaTime, IAttackable target) { if (target == null || !AttackReady(deltaTime)) { return; } float damage = tower.AttackDamage; target.ApplyDamage(damage); attackAbility.Apply(target); int count = UnitScanner.ScanFor(target.Position, tower.CurrentLevel.aoeRadius, buffer); for (int i = 0; i < count; ++i) { float distance = Vector3.Distance(target.Position, buffer[i].Position); buffer[i].ApplyDamage(damage / (distance + 1.0f)); attackAbility.Apply(buffer[i]); } }
public override void StopActive() { hero.animator.runtimeAnimatorController = hero.defaultAnimator; foreach (GameObject col in collidedList) { if (col != null) { IAttackable obj = col.GetComponent <IAttackable>(); if (obj != null) { obj.ReceiveDragChange(0); } } } if (callback != null) { callback(); } gameObject.SetActive(false); }
private void OnTriggerEnter(Collider a_Collision) { IAttackable attackableObject = a_Collision.transform.gameObject.GetComponent<IAttackable>(); if (attackableObject != null && !m_HitUnits.Contains(attackableObject) && attackableObject.faction != m_Parent.faction) { m_HitUnits.Add(attackableObject); attackableObject.damageFSM.Transition(DamageState.TakingDamge); attackableObject.health -= m_SkillData.damage; UIAnnouncer.self.FloatingText( m_SkillData.damage, a_Collision.transform.position, FloatingTextType.PhysicalDamage); if (a_Collision.transform.GetComponent<IStats>() != null && attackableObject.health <= 0) m_Parent.experience += a_Collision.transform.GetComponent<IStats>().experience; } }
/// <summary> /// Returns the base damage if the attacker, using a specific skill. /// </summary> /// <param name="attacker">The attacker.</param> /// <param name="skill">Skill which is used.</param> /// <param name="minimumBaseDamage">Minimum base damage.</param> /// <param name="maximumBaseDamage">Maximum base damage.</param> private static void GetBaseDmg(this IAttackable attacker, SkillEntry skill, out int minimumBaseDamage, out int maximumBaseDamage) { var attackerStats = attacker.Attributes; minimumBaseDamage = (int)attackerStats[Stats.BaseDamageBonus]; maximumBaseDamage = (int)attackerStats[Stats.BaseDamageBonus]; DamageType damageType = DamageType.Physical; if (skill != null) { damageType = skill.Skill.DamageType; var skillDamage = skill.GetDamage(); minimumBaseDamage += skillDamage; maximumBaseDamage += skillDamage; } switch (damageType) { case DamageType.Wizardry: minimumBaseDamage += (int)attackerStats[Stats.MinimumWizBaseDmg]; maximumBaseDamage += (int)(attackerStats[Stats.MaximumWizBaseDmg] + (attackerStats[Stats.MaximumWizBaseDmgPer20LevelItemCount] * attackerStats[Stats.Level] / 20)); break; case DamageType.Curse: minimumBaseDamage += (int)attackerStats[Stats.MinimumCurseBaseDmg]; maximumBaseDamage += (int)(attackerStats[Stats.MaximumCurseBaseDmg] + (attackerStats[Stats.MaximumCurseBaseDmgPer20LevelItemCount] * attackerStats[Stats.Level] / 20)); break; case DamageType.Physical: minimumBaseDamage += (int)attackerStats[Stats.MinimumPhysBaseDmg]; maximumBaseDamage += (int)(attackerStats[Stats.MaximumPhysBaseDmg] + (attackerStats[Stats.MaximumPhysBaseDmgPer20LevelItemCount] * attackerStats[Stats.Level] / 20)); break; default: // the skill has some other damage type defined which is not applicable to this calculation break; } }
public int Defend(IAttackable attacker) { int damage = attacker.Damage; this.HP = this.HP - damage; this.color = Color.BlueViolet; return damage; }
protected virtual bool FindTarget() { timerCD = 3; IAttackable possibleTarget = null; IAttackable target = null; bool miss = true; foreach (var hit in Physics.OverlapSphere(Transform.position, Range)) { target = attack.CanAttack(hit.transform); if (target != null) { if (currTarget == null) { currTarget = target; miss = false; break; } else { if (currTarget == target) { miss = false; break; } else if (possibleTarget == null) possibleTarget = target; } } } if (miss) currTarget = possibleTarget; return currTarget != null; //bool miss = true; //foreach (var hit in Physics.OverlapSphere(transform.position, Range)) //{ // if (currTarget == null) // { // currTarget = attack.CanAttack(hit.transform); // miss = false; // } // else // if (currTarget == attack.CanAttack(hit.transform)) // miss = false; //} //if (miss) // currTarget = null; //return !miss; }
public SimpleTargetable(Vector3 position, IAttackable attackable) { Position = position; Attackable = attackable; IsValid = true; }
public void SpawnProjectile(Vector2 position, float time, IAttackable target) { vfx.Add(new ProjectileEffect(position, time, target)); }
public void Attack(IAttackable mob, int attackDice) { }
void attack(IAttackable i) { if (i != null) { if (Time.time - lastAttack > attackCoolDown) i.decrease(damage); } }
public static float Distance(IAttackable a, IAttackable b) { return Vector2.Distance(a.Position, b.Position) - a.Radius - b.Radius; }
public virtual void Attack(IAttackable target) { if (attackTimer <= 0) { target.DealDamage(attackDamage, attackSpeed); attackTimer = attackDelay; gm.VFX.SpawnProjectile(Position, attackSpeed, target); } }
public void Attack(IAttackable target) { Weapon.Attack (target, AttackSkill); }
public virtual void Deselect(IAttackable s) { selection.Remove(s); }
public ProjectileEffect(Vector2 position, float time, IAttackable target) { timeLeft = time; this.target = target; emitter = ParticleEmitter.SpawnGenericProjectileEmitter(position); }