コード例 #1
0
        private void OnMeleeInteract(EntityUid uid, FlashComponent comp, MeleeInteractEvent args)
        {
            if (!UseFlash(comp, args.User))
            {
                return;
            }

            if (args.Entity.HasComponent <FlashableComponent>())
            {
                args.CanInteract = true;
                FlashEntity(args.Entity, args.User, comp.FlashDuration, comp.SlowTo);
            }
        }
コード例 #2
0
        private void OnMeleeInteract(EntityUid uid, StunbatonComponent comp, MeleeInteractEvent args)
        {
            if (!comp.Activated)
            {
                return;
            }

            if (!ComponentManager.TryGetComponent <PowerCellSlotComponent>(uid, out var slot) || slot.Cell == null || !slot.Cell.TryUseCharge(comp.EnergyPerUse))
            {
                return;
            }

            if (args.Entity.HasComponent <StunnableComponent>())
            {
                args.CanInteract = true;
                StunEntity(args.Entity, comp);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Used for melee weapons that want some behavior on AfterInteract,
        ///     but also want the cooldown (stun batons, flashes)
        /// </summary>
        private void OnAfterInteract(EntityUid uid, MeleeWeaponComponent comp, AfterInteractEvent args)
        {
            if (!args.CanReach)
            {
                return;
            }

            var curTime = _gameTiming.CurTime;

            if (curTime < comp.CooldownEnd)
            {
                return;
            }

            var owner = EntityManager.GetEntity(uid);

            if (args.Target == null)
            {
                return;
            }

            var location = args.User.Transform.Coordinates;
            var diff     = args.ClickLocation.ToMapPos(owner.EntityManager) - location.ToMapPos(owner.EntityManager);
            var angle    = Angle.FromWorldVec(diff);

            var hitEvent = new MeleeInteractEvent(args.Target, args.User);

            RaiseLocalEvent(uid, hitEvent, false);

            if (!hitEvent.CanInteract)
            {
                return;
            }
            SendAnimation(comp.ClickArc, angle, args.User, owner, new List <IEntity>()
            {
                args.Target
            }, comp.ClickAttackEffect, false);

            comp.LastAttackTime = curTime;
            comp.CooldownEnd    = comp.LastAttackTime + TimeSpan.FromSeconds(comp.CooldownTime);

            RaiseLocalEvent(uid, new RefreshItemCooldownEvent(comp.LastAttackTime, comp.CooldownEnd), false);
        }