コード例 #1
0
ファイル: Mob.cs プロジェクト: natedahl32/EqEmulator-net
        protected void OnDamaged(DamageEventArgs de)
        {
            EventHandler<DamageEventArgs> handler = Damaged;

            if (handler != null)
                handler(this, de);
        }
コード例 #2
0
        void Mob_Damaged(object sender, DamageEventArgs de)
        {
            Mob sourceMob = this[de.SourceId];  // This safely gets a null if sourceId == 0
            Mob targetMob = sender as Mob;

            if (targetMob.Dead) {
                if (targetMob is NpcMob)    // TODO: will want to handle pets here as well
                    NpcDeath(targetMob as NpcMob, sourceMob, de.SpellId, de.Type, de.Damage);
                else if (targetMob is ZonePlayer)
                    PlayerDeath(targetMob as ZonePlayer, sourceMob, de.SpellId, de.Type, de.Damage);

                return;
            }

            CombatDamage cd = new CombatDamage()
            {
                TargetId = (ushort)targetMob.ID,
                SourceId = de.SourceId,
                DamageType = de.Type,
                Damage = de.Damage,
                SpellId = de.SpellId
            };

            EQApplicationPacket<CombatDamage> cdPack = new EQApplicationPacket<CombatDamage>(AppOpCode.Damage, cd);

            // TODO: choose right filter and then add to packet queue methods

            // Send to attacker if it's a player    TODO: verify this sends spell dmg
            if (de.SourceId != 0 && sourceMob is ZonePlayer)
                _zoneSvr.QueuePacketToClient(((ZonePlayer)sourceMob).Client, cdPack, true, ZoneConnectionState.Connected);

            // Send to nearby players
            _zoneSvr.QueuePacketToNearbyClients(targetMob, cdPack, 200.0f, true, true, new int[] { de.SourceId });

            // Send to defender if it's a player
            if (targetMob is ZonePlayer) {
                //_log.DebugFormat("Telling {0} they were damaged for {1} points.", targetMob.Name, de.Damage);
                _zoneSvr.QueuePacketToClient(((ZonePlayer)targetMob).Client, cdPack, true, ZoneConnectionState.Connected);
            }
        }