private void Mob_OnDead(IKillable sender, IKiller killer) { var mob = (Mob)sender; RemoveListeners(mob); Mobs.TryRemove(mob.Id, out var removedMob); foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendMobDead(player.Client, sender, killer); } // Add experience to killer character/party if (killer is Character killerCharacter) { if (killerCharacter.HasParty) { killerCharacter.AddPartyMobExperience(mob.Level, (ushort)mob.Exp); } else { killerCharacter.AddMobExperience(mob.Level, (ushort)mob.Exp); } } }
public void Character_TestKillerCalculation() { var characterToKill = CreateCharacter(); characterToKill.IncreaseHP(characterToKill.MaxHP); var killer1 = CreateCharacter(); var killer2 = CreateCharacter(); IKiller finalKiller = null; characterToKill.OnDead += (IKillable sender, IKiller killer) => { finalKiller = killer; }; var littleHP = characterToKill.CurrentHP / 5; var allHP = characterToKill.MaxHP; characterToKill.DecreaseHP(littleHP, killer1); Assert.Equal(characterToKill.MaxHP - littleHP, characterToKill.CurrentHP); characterToKill.DecreaseHP(characterToKill.MaxHP, killer2); Assert.Equal(0, characterToKill.CurrentHP); Assert.True(characterToKill.IsDead); Assert.Equal(killer2, finalKiller); }
/// <summary> /// Notifies other players, that player is dead. /// </summary> private void Character_OnDead(IKillable sender, IKiller killer) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendCharacterKilled(player.Client, (Character)sender, killer); } }
/// <summary> /// Notifies other players, that player is dead. /// </summary> private void Character_OnDead(IKillable sender, IKiller killer) { foreach (var player in Players) { _packetHelper.SendCharacterKilled(player.Value.Client, (Character)sender, killer); } }
private void Character_OnUsedRangeSkill(IKiller sender, IKillable target, Skill skill, AttackResult attackResult) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendUsedRangeSkill(player.Client, (Character)sender, target, skill, attackResult); } }
private void Mob_OnUsedSkill(IKiller sender, IKillable target, Skill skill, AttackResult attackResult) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendMobUsedSkill(player.Client, (Mob)sender, target.Id, skill, attackResult); } }
public void Character_TestKillerCalculation() { var characterToKill = new Character(loggerMock.Object, gameWorldMock.Object, config.Object, taskQueuMock.Object, databasePreloader.Object, chatMock.Object, linkingMock.Object, dyeingMock.Object) { Class = CharacterProfession.Archer }; characterToKill.IncreaseHP(characterToKill.MaxHP); var killer1 = new Character(loggerMock.Object, gameWorldMock.Object, config.Object, taskQueuMock.Object, databasePreloader.Object, chatMock.Object, linkingMock.Object, dyeingMock.Object); var killer2 = new Character(loggerMock.Object, gameWorldMock.Object, config.Object, taskQueuMock.Object, databasePreloader.Object, chatMock.Object, linkingMock.Object, dyeingMock.Object); IKiller finalKiller = null; characterToKill.OnDead += (IKillable sender, IKiller killer) => { finalKiller = killer; }; var littleHP = characterToKill.CurrentHP / 5; var allHP = characterToKill.MaxHP; characterToKill.DecreaseHP(littleHP, killer1); Assert.Equal(characterToKill.MaxHP - littleHP, characterToKill.CurrentHP); characterToKill.DecreaseHP(characterToKill.MaxHP, killer2); Assert.Equal(0, characterToKill.CurrentHP); Assert.True(characterToKill.IsDead); Assert.Equal(killer2, finalKiller); }
public void ReceiveDamage(int amount, IKiller killer = null) { lastDamage = Time.time; CurrentHealth -= amount; NotifiyHit?.Invoke(gameObject); if (CurrentHealth <= 0) { if (explosion != null) { var obj = Instantiate(explosion, transform.position, transform.rotation); Destroy(obj, 2); } NotifiyOnZeroHealth?.Invoke(gameObject); if (DestroyAfterZeroHealth) { Destroy(gameObject); } killer?.NotifyKill(gameObject); playerController?.NotifyDeath(this, killer); } }
/// <summary> /// Notifies other players, that player used auto attack. /// </summary> private void Character_OnAttack(IKiller sender, IKillable target, AttackResult attackResult) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendCharacterUsualAttack(player.Client, sender, target, attackResult); } }
internal void SendCharacterKilled(IWorldClient client, Character character, IKiller killer) { using var packet = new Packet(PacketType.CHARACTER_DEATH); packet.Write(character.Id); packet.WriteByte(1); // killer type. 1 - another player. packet.Write(killer.Id); client.SendPacket(packet); }
internal void SendMobDead(IWorldClient client, IKillable sender, IKiller killer) { using var packet = new Packet(PacketType.MOB_DEATH); packet.Write(sender.Id); packet.WriteByte(1); // killer type. Always 1, since only player can kill the mob. packet.Write(killer.Id); client.SendPacket(packet); }
public GeneticAlgorithmBuilder <U> SetKiller(IKiller <U> killer) { Contract.Requires <ArgumentNullException>(killer != null, "Killer cannot be null."); Killer = killer; return(this); }
protected override void Mob_OnDead(IKillable sender, IKiller killer) { var mob = sender as Mob; _guildRankingManager.AddPoints(GuildId, mob.GuildPoints); base.Mob_OnDead(sender, killer); }
/// <summary> /// Rebirth mob, when it's dead. /// </summary> private void MobRebirth_OnDead(int senderId, IKiller killer) { if (!ShouldRebirth) { return; } _rebirthTimer.Start(); }
static void ExplictInterfaceTest() { var item = new WarmKiller(); IKiller killer = item; IGentleman gentleman = item; killer.Kill(); gentleman.Love(); }
private void HealthManager_OnGotDamage(int senderId, IKiller gamageMaker) { if (_castProtectionManager.IsCastProtected) { return; } CancelCasting(); }
public override IList <Item> GenerateDrop(IKiller killer) { if (killer is Mob || killer is Npc) { return(new List <Item>()); } // TODO: generate drop, if character was killed by another character. return(new List <Item>()); }
public GeneticAlgorithmBuilder <T> SetKiller(IKiller <T> killer) { if (killer == null) { throw new System.ArgumentNullException(nameof(killer)); } Killer = killer; return(this); }
/// <summary> /// Gets enemies near target. /// </summary> public IEnumerable <IKillable> GetEnemies(IKiller sender, float x, float z, byte range) { IEnumerable <IKillable> mobs = sender is Mob ? new List <IKillable>() : GetAllMobs(true).Where(m => !m.HealthManager.IsDead && m.HealthManager.IsAttackable && m.CountryProvider.Country != sender.CountryProvider.Country && MathExtensions.Distance(x, m.PosX, z, m.PosZ) <= range); IEnumerable <IKillable> chars = GetAllPlayers(true) .Where(p => !p.HealthManager.IsDead && p.HealthManager.IsAttackable && (p.CountryProvider.Country != sender.CountryProvider.Country || (sender is Character senderPlayer && senderPlayer.DuelManager.IsStarted && p.Id == senderPlayer.DuelManager.OpponentId)) && MathExtensions.Distance(x, p.PosX, z, p.PosZ) <= range); return(mobs.Concat(chars)); }
private void Mob_OnDead(IKillable sender, IKiller killer) { var mob = (Mob)sender; RemoveListeners(mob); Mobs.TryRemove(mob.Id, out var removedMob); foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendMobDead(player.Client, sender, killer); } }
/// <summary> /// Notifies other players, that player used skill. /// </summary> private void Character_OnUsedSkill(IKiller sender, IKillable target, Skill skill, AttackResult attackResult) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendCharacterUsedSkill(player.Client, (Character)sender, target, skill, attackResult); if (attackResult.Absorb != 0 && player == target) { _packetsHelper.SendAbsorbValue(player.Client, attackResult.Absorb); } } }
private void Mob_OnAttack(IKiller sender, IKillable target, AttackResult attackResult) { foreach (var player in GetAllPlayers(true)) { _packetsHelper.SendMobAttack(player.Client, (Mob)sender, target.Id, attackResult); if (attackResult.Absorb != 0 && player == target) { _packetsHelper.SendAbsorbValue(player.Client, attackResult.Absorb); } } }
/// <summary> /// When user hits mob, it automatically turns on ai. /// </summary> protected override void DecreaseHP(IKiller damageMaker) { if (!IsDead) { SelectActionBasedOnAI(); // TODO: calculate not only max damage, but also amount or rec and argo skills. if (MaxDamageMaker is IKillable) { Target = (MaxDamageMaker as IKillable); } } }
/// <summary> /// When user hits mob, it automatically turns on ai. /// </summary> private void OnDecreaseHP(int senderId, IKiller damageMaker) { if (!HealthManager.IsDead) { // TODO: calculate not only max damage, but also amount or rec and argo skills. if (HealthManager.MaxDamageMaker is IKillable) { AttackManager.Target = (HealthManager.MaxDamageMaker as IKillable); } AIManager.SelectActionBasedOnAI(); } }
static void Main() { //way1: var wk = new WarmKiller(); wk.Love(); IKiller killer = wk; killer.Kill(); // way2: //IKiller killer = new WarmKiller(); //killer.Kill(); //var wk = (IGentlemen)killer; //wk.Love(); }
/// <summary> /// Notifies other players, that player is dead. /// </summary> private void Character_OnDead(int senderId, IKiller killer) { foreach (var player in GetAllPlayers(true)) { Map.PacketFactory.SendCharacterKilled(player.GameSession.Client, senderId, killer); } if (killer is Character killerCharacter) { var killed = Players[senderId]; var items = killed.GenerateDrop(killerCharacter); foreach (var item in items) { Map.AddItem(new MapItem(item, killerCharacter, killed.PosX, 0, killed.PosZ)); } } }
protected override IList <Item> GenerateDrop(IKiller killer) { if (killer is Npc) { return(new List <Item>()); } var items = new List <Item>(); for (byte i = 1; i <= 9; i++) { if (!_databasePreloader.MobItems.ContainsKey((MobId, i))) { _logger.LogWarning($"Mob {MobId} doesn't contain drop. Is it expected?"); continue; } var dropItem = _databasePreloader.MobItems[(MobId, i)];
internal void SendCharacterUsualAttack(IWorldClient client, IKiller sender, IKillable target, AttackResult attackResult) { PacketType attackType; if (target is Character) { attackType = PacketType.CHARACTER_CHARACTER_AUTO_ATTACK; } else if (target is Mob) { attackType = PacketType.CHARACTER_MOB_AUTO_ATTACK; } else { attackType = PacketType.CHARACTER_CHARACTER_AUTO_ATTACK; } using var packet = new Packet(attackType); packet.Write(new UsualAttack(sender.Id, target.Id, attackResult).Serialize()); client.SendPacket(packet); }
private void ObeliskAI_OnDead(IKillable sender, IKiller killer) { ObeliskAI.OnDead -= ObeliskAI_OnDead; ObeliskCountry = killer.Country == Fraction.Light ? ObeliskCountry.Light : ObeliskCountry.Dark; OnObeliskBroken?.Invoke(this); if (ObeliskCountry == ObeliskCountry.Light) { Bless.Instance.LightAmount += 1000; // TODO: maybe different value for different obelisks? Bless.Instance.DarkAmount -= 500; } else { Bless.Instance.DarkAmount += 1000; Bless.Instance.LightAmount -= 500; } ClearGuards(); _rebirthTimer.Start(); }
/// <summary> /// When target is dead, mob returns to its' original place. /// </summary> /// <param name="sender">player, that is dead</param> /// <param name="killer">player's killer</param> private void Target_OnDead(IKillable sender, IKiller killer) { ClearTarget(); }