// RB   5/21/2016   Damage Resistance for siege
        /// <summary>Inflicts damage upon this unit.</summary>
        public override bool ReceiveDamage(Unit caster, uint damage, float hatredScale = 1f, uint mitigation = 0)
        {
            bool   wasKilled      = false;
            Player creditedPlayer = null;

            if (IsDead || PendingDisposal || IsInvulnerable)
            {
                return(false);
            }

            if (caster.Realm != Realm)
            {
                creditedPlayer = caster.CbtInterface.CreditedPlayer;
            }

            lock (DamageApplicationLock)
            {
                if (IsDead)
                {
                    return(false);
                }
                if (damage >= Health)
                {
                    wasKilled = true;

                    damage  = Health;
                    _health = 0;

                    if (creditedPlayer != null)
                    {
                        PendingTotalDamageTaken += damage;
                        AddTrackedDamage(creditedPlayer, damage);
                    }

                    TotalDamageTaken        = PendingTotalDamageTaken;
                    PendingTotalDamageTaken = 0;
                }
                else
                {
                    _health = Math.Max(0, _health - damage);

                    if (creditedPlayer != null)
                    {
                        PendingTotalDamageTaken += damage;
                        AddTrackedDamage(creditedPlayer, damage);
                    }
                }
            }

            CbtInterface.OnTakeDamage(caster, damage, 1f);
            Siege siege = caster as Siege;

            if (siege != null)
            {
                Siege s = siege;
                foreach (KeyValuePair <Player, byte> p in s.SiegeInterface.Players)
                {
                    p.Key.CbtInterface.OnDealDamage(this, damage);
                }
            }
            else
            {
                caster.CbtInterface.OnDealDamage(this, damage);
            }

            LastHitOid = caster.Oid;

            if (wasKilled)
            {
                SetDeath(caster);
            }

            return(wasKilled);
        }
Beispiel #2
0
        public void Fire(Player player, ushort targetID, ushort targetX, ushort targetY, ushort targetZ, ushort zoneId, ushort power)
        {
            if (!HasPlayer(player) || !_weapon.AbtInterface.CanCastCooldown(_abilityId))
            {
                return;
            }

            // RB   6/25/2016   Reset timer before death every time the siege is fired
            _deathTime = TCPManager.GetTimeStampMS() + 300 * 1000;


            switch (Type)
            {
            case SiegeType.GTAOE:
                Point3D targetPos = ZoneService.GetWorldPosition(_weapon.Zone.Info, targetX, targetY, targetZ);

                if (!ArcHit(zoneId, new Point3D(targetX, targetY, targetZ), targetPos))
                {
                    player.SendClientMessage("Can't hit that position from here", ChatLogFilters.CHATLOGFILTERS_C_ABILITY_ERROR);
                    return;
                }

                Siege artillery = _weapon as Siege;
                if (artillery != null && !artillery.CanFire(player))
                {
                    return;
                }

                _weapon.AbtInterface.StartCastAtPos(player, _abilityId, ZoneService.GetWorldPosition(_weapon.Zone.Info, targetX, targetY, targetZ), _weapon.Zone.ZoneId, 0);
                break;

            case SiegeType.OIL:
                _weapon.AbtInterface.StartCastAtPos(player, _abilityId, ZoneService.GetWorldPosition(_weapon.Zone.Info, targetX, targetY, targetZ), _weapon.Zone.ZoneId, 0);
                break;

            case SiegeType.SNIPER:
                Unit target = _weapon.Region.GetObject(targetID) as Unit;

                if (target == null || !CombatInterface.CanAttack(player, target))
                {
                    return;
                }

                Siege cannon = _weapon as Siege;
                if (cannon != null && !cannon.CanFire(player))
                {
                    return;
                }

                _weapon.CbtInterface.SetTarget(targetID, TargetTypes.TARGETTYPES_TARGET_ENEMY);
                _weapon.AbtInterface.StartCast(player, _abilityId, 0, 0, Math.Max((byte)1, (byte)(_weapon.Level * power * 0.01f)));
                break;

            case SiegeType.RAM:
                Unit ramTarget = null;
                foreach (Object obj in _Owner.ObjectsInRange)
                {
                    KeepDoor.KeepGameObject door = obj as KeepDoor.KeepGameObject;

                    if (door == null)
                    {
                        continue;
                    }

                    if (!CombatInterface.CanAttack(player, door))
                    {
                        continue;
                    }

                    if (!_Owner.IsObjectInFront(door, 90) || !door.IsWithinRadiusFeet(_Owner, 20))
                    {
                        continue;
                    }

                    ramTarget = door;
                    break;
                }
                //Unit target = _weapon.Region.GetObject(targetID) as Unit;

                if (ramTarget != null)
                {
                    _weapon.CbtInterface.SetTarget(ramTarget.Oid, TargetTypes.TARGETTYPES_TARGET_ENEMY);
                    _weapon.AbtInterface.StartCast(player, _abilityId, 0, 0, Math.Max((byte)1, (byte)(_weapon.Level * power * 0.01f)));
                }

                else
                {
                    foreach (var plrInfo in Players)
                    {
                        plrInfo.Key.SendClientMessage("No target", ChatLogFilters.CHATLOGFILTERS_C_ABILITY_ERROR);
                    }
                }
                break;
            }

            SendSiegeCooldown();


            // Disable Firing?

            /*
             * Out = new PacketOut((byte)Opcodes.F_UPDATE_STATE);
             * Out.WriteUInt16(_Owner.Oid);
             * Out.WriteByte(0x1C);
             * Out.WriteByte(2);
             * Out.Fill(0, 6);
             * player.SendPacket(Out);
             */

            SendSiegeUserUpdate();

            /*
             * Out = new PacketOut((byte)Opcodes.F_UPDATE_STATE);
             * Out.WriteUInt16(_Owner.Oid);
             * Out.WriteByte(0x1E);
             * Out.WriteUInt16(0);
             * Out.WriteByte((byte)_Owner.Name.Length);
             * Out.WriteUInt16(0);
             * Out.WriteCString(_Owner.Name);
             * Out.WriteByte(0);
             * player.SendPacket(Out);
             */

            SendSiegeIdleTimer(player);
        }