Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
 /// <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);
     }
 }
Beispiel #4
0
 /// <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);
     }
 }
Beispiel #5
0
 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);
     }
 }
Beispiel #6
0
 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);
     }
 }
Beispiel #7
0
        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);
        }
Beispiel #8
0
    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);
        }
    }
Beispiel #9
0
 /// <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);
     }
 }
Beispiel #10
0
 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);
 }
Beispiel #11
0
 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);
 }
Beispiel #12
0
        public GeneticAlgorithmBuilder <U> SetKiller(IKiller <U> killer)
        {
            Contract.Requires <ArgumentNullException>(killer != null, "Killer cannot be null.");

            Killer = killer;

            return(this);
        }
Beispiel #13
0
        protected override void Mob_OnDead(IKillable sender, IKiller killer)
        {
            var mob = sender as Mob;

            _guildRankingManager.AddPoints(GuildId, mob.GuildPoints);

            base.Mob_OnDead(sender, killer);
        }
Beispiel #14
0
        /// <summary>
        /// Rebirth mob, when it's dead.
        /// </summary>
        private void MobRebirth_OnDead(int senderId, IKiller killer)
        {
            if (!ShouldRebirth)
            {
                return;
            }

            _rebirthTimer.Start();
        }
Beispiel #15
0
        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();
        }
Beispiel #17
0
        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>());
        }
Beispiel #18
0
        public GeneticAlgorithmBuilder <T> SetKiller(IKiller <T> killer)
        {
            if (killer == null)
            {
                throw new System.ArgumentNullException(nameof(killer));
            }

            Killer = killer;

            return(this);
        }
Beispiel #19
0
        /// <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));
        }
Beispiel #20
0
        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);
            }
        }
Beispiel #21
0
        /// <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);
                }
            }
        }
Beispiel #22
0
        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);
                }
            }
        }
Beispiel #23
0
        /// <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);
                }
            }
        }
Beispiel #24
0
        /// <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();
            }
        }
Beispiel #25
0
        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();
        }
Beispiel #26
0
        /// <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));
                }
            }
        }
Beispiel #27
0
        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)];
Beispiel #28
0
        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);
        }
Beispiel #29
0
        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();
        }
Beispiel #30
0
 /// <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();
 }