public override ComponentState GetComponentState(ICommonSession player)
        {
            (int, int)? count = (ShotsLeft, Capacity);
            var chamberedExists = _chamberContainer.ContainedEntity != null;
            // (Is one chambered?, is the bullet spend)
            var chamber = (chamberedExists, false);

            if (chamberedExists && _chamberContainer.ContainedEntity.TryGetComponent <AmmoComponent>(out var ammo))
            {
                chamber.Item2 = ammo.Spent;
            }
            return(new PumpBarrelComponentState(
                       chamber,
                       FireRateSelector,
                       count,
                       SoundGunshot));
        }
示例#2
0
        private void HandleUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            // client sanitization
            if (!coords.IsValidLocation())
            {
                Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
                return;
            }

            if (uid.IsClientSide())
            {
                Logger.WarningS("system.interaction", $"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
                return;
            }

            UserInteraction(((IPlayerSession)session).AttachedEntity, coords, uid);
        }
        private bool HandleExamine(ICommonSession session, EntityCoordinates coords, EntityUid uid)
        {
            if (!uid.IsValid() || !EntityManager.TryGetEntity(uid, out var examined))
            {
                return(false);
            }

            var playerEntity = _playerManager.LocalPlayer.ControlledEntity;

            if (playerEntity == null || !CanExamine(playerEntity, examined))
            {
                return(false);
            }

            DoExamine(examined);
            return(true);
        }
示例#4
0
        /// <summary>
        ///     Inserts an Input Command into the simulation.
        /// </summary>
        /// <param name="session">Player session that raised the command. On client, this is always the LocalPlayer session.</param>
        /// <param name="function">Function that is being changed.</param>
        /// <param name="message">Arguments for this event.</param>
        public void HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message)
        {
            // set state, state change is updated regardless if it is locally bound
            _cmdStates.SetState(function, message.State);

            // handle local binds before sending off
            if (_bindMap.TryGetHandler(function, out var handler))
            {
                // local handlers can block sending over the network.
                if (handler.HandleCmdMessage(session, message))
                {
                    return;
                }
            }

            RaiseNetworkEvent(message);
        }
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.GetActiveHand == null)
            {
                return(false);
            }

            var dir        = (coords.Position - ent.Transform.GridPosition.Position);
            var ray        = new CollisionRay(ent.Transform.GridPosition.Position, dir.Normalized, (int)CollisionGroup.Impassable);
            var rayResults = IoCManager.Resolve <IPhysicsManager>().IntersectRay(ent.Transform.MapID, ray, dir.Length, ent);

            if (!rayResults.DidHitObject)
            {
                if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
                {
                    handsComp.Drop(handsComp.ActiveIndex, coords);
                }
                else
                {
                    var entCoords = ent.Transform.GridPosition.Position;
                    var entToDesiredDropCoords = coords.Position - entCoords;
                    var clampedDropCoords      = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords);

                    handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID));
                }
            }
            else
            {
                handsComp.Drop(handsComp.ActiveIndex, ent.Transform.GridPosition);
            }

            return(true);
        }
        private static OrganizationRelationship ProvisionOrganizationRelationship(ICommonSession session, OrganizationRelationship existingOrgRel, IFederationInformation federationInfo, IEnumerable <SmtpDomain> domains, string relationshipName)
        {
            if (existingOrgRel != null)
            {
                session.RemoveOrganizationRelationship(existingOrgRel.Identity.ToString());
            }
            string targetApplicationUri  = (federationInfo != null) ? federationInfo.TargetApplicationUri : null;
            string targetAutodiscoverEpr = (federationInfo != null) ? federationInfo.TargetAutodiscoverEpr : null;

            session.NewOrganizationRelationship(relationshipName, targetApplicationUri, targetAutodiscoverEpr, domains);
            existingOrgRel = TaskCommon.GetOrganizationRelationship(session, relationshipName, from d in domains
                                                                    select d.Domain);
            if (existingOrgRel == null)
            {
                throw new LocalizedException(HybridStrings.ErrorOrgRelProvisionFailed(domains.First <SmtpDomain>().ToString()));
            }
            return(existingOrgRel);
        }
 private void Enabled(ICommonSession session)
 {
     if (_escapeMenu.IsOpen)
     {
         if (_escapeMenu.IsAtFront())
         {
             _setOpenValue(false);
         }
         else
         {
             _escapeMenu.MoveToFront();
         }
     }
     else
     {
         _setOpenValue(true);
     }
 }
示例#8
0
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.GetActiveHand == null)
            {
                return(false);
            }

            var interactionSystem = _entitySystemManager.GetEntitySystem <InteractionSystem>();

            if (interactionSystem.InRangeUnobstructed(coords, ent.Transform.GridPosition, 0f, ignoredEnt: ent))
            {
                if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
                {
                    handsComp.Drop(handsComp.ActiveIndex, coords);
                }
                else
                {
                    var entCoords = ent.Transform.GridPosition.Position;
                    var entToDesiredDropCoords = coords.Position - entCoords;
                    var clampedDropCoords      = ((entToDesiredDropCoords.Normalized * InteractionSystem.InteractionRange) + entCoords);

                    handsComp.Drop(handsComp.ActiveIndex, new GridCoordinates(clampedDropCoords, coords.GridID));
                }
            }
            else
            {
                handsComp.Drop(handsComp.ActiveIndex, ent.Transform.GridPosition);
            }

            return(true);
        }
示例#9
0
        public override ComponentState GetComponentState(ICommonSession player)
        {
            var slotsSpent = new bool?[Capacity];

            for (var i = 0; i < Capacity; i++)
            {
                slotsSpent[i] = null;
                if (_ammoSlots[i] != null && _ammoSlots[i].TryGetComponent(out AmmoComponent ammo))
                {
                    slotsSpent[i] = ammo.Spent;
                }
            }

            //TODO: make yaml var to not sent currentSlot/UI? (for russian roulette)
            return(new RevolverBarrelComponentState(
                       _currentSlot,
                       FireRateSelector,
                       slotsSpent,
                       SoundGunshot));
        }
        public void HandleActivateItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            if (!EntityManager.TryGetEntity(uid, out var used))
            {
                return;
            }

            var playerEnt = ((IPlayerSession)session).AttachedEntity;

            if (playerEnt == null || !playerEnt.IsValid())
            {
                return;
            }

            if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, InteractionRange))
            {
                return;
            }

            InteractionActivate(playerEnt, used);
        }
示例#11
0
            public override bool HandleCmdMessage(ICommonSession session, InputCmdMessage message)
            {
                if (!(message is FullInputCmdMessage msg))
                {
                    return(false);
                }

                switch (msg.State)
                {
                case BoundKeyState.Up:
                    Disabled(session);
                    return(true);

                case BoundKeyState.Down:
                    Enabled(session);
                    return(true);
                }

                //Client Sanitization: unknown key state, just ignore
                return(false);
            }
示例#12
0
        private void HandleExamine(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            if (!uid.IsValid() || !_entityManager.TryGetEntity(uid, out var entity))
            {
                return;
            }

            var playerEntity = _playerManager.LocalPlayer.ControlledEntity;

            if (playerEntity == null)
            {
                return;
            }

            if ((entity.Transform.WorldPosition - playerEntity.Transform.WorldPosition).LengthSquared > ExamineRangeSquared)
            {
                return;
            }

            DoExamine(entity);
        }
示例#13
0
        private bool HandleDrop(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.GetActiveHand == null)
            {
                return(false);
            }

            if (!_entitySystemManager.GetEntitySystem <InteractionSystem>().TryDroppedInteraction(ent, handsComp.GetActiveHand.Owner))
            {
                return(false);
            }

            if (handsComp.GetActiveHand != null && !_entitySystemManager.GetEntitySystem <InteractionSystem>().TryDroppedInteraction(ent, handsComp.GetActiveHand.Owner))
            {
                return(false);
            }

            if (coords.InRange(_mapManager, ent.Transform.GridPosition, InteractionSystem.InteractionRange))
            {
                handsComp.Drop(handsComp.ActiveIndex, coords);
            }
            else
            {
                handsComp.Drop(handsComp.ActiveIndex);
            }

            return(true);
        }
示例#14
0
        private bool HandleActivateItemInWorld(ICommonSession session, EntityCoordinates coords, EntityUid uid)
        {
            if (!EntityManager.TryGetEntity(uid, out var used))
            {
                return(false);
            }

            var playerEnt = ((IPlayerSession)session).AttachedEntity;

            if (playerEnt == null || !playerEnt.IsValid())
            {
                return(false);
            }

            if (!playerEnt.Transform.Coordinates.InRange(EntityManager, used.Transform.Coordinates, InteractionRange))
            {
                return(false);
            }

            InteractionActivate(playerEnt, used);
            return(true);
        }
示例#15
0
        public static OrganizationRelationship GetOrganizationRelationship(ICommonSession session, string identity, IEnumerable <string> domains)
        {
            OrganizationRelationship organizationRelationship = null;
            IEnumerable <OrganizationRelationship> organizationRelationship2 = session.GetOrganizationRelationship();
            bool flag = false;

            foreach (OrganizationRelationship organizationRelationship3 in organizationRelationship2)
            {
                if (organizationRelationship3.Identity.ToString().Equals(identity, StringComparison.InvariantCultureIgnoreCase))
                {
                    if (flag)
                    {
                        throw new LocalizedException(HybridStrings.ErrorMultipleMatchingOrgRelationships);
                    }
                    organizationRelationship = organizationRelationship3;
                }
                foreach (string domain in domains)
                {
                    SmtpDomain smtpDomain = new SmtpDomain(domain);
                    foreach (SmtpDomain smtpDomain2 in organizationRelationship3.DomainNames)
                    {
                        if (smtpDomain2.Domain.Equals(smtpDomain.Domain, StringComparison.InvariantCultureIgnoreCase))
                        {
                            if (flag)
                            {
                                throw new LocalizedException(HybridStrings.ErrorMultipleMatchingOrgRelationships);
                            }
                            organizationRelationship = organizationRelationship3;
                            break;
                        }
                    }
                }
                if (organizationRelationship != null)
                {
                    flag = true;
                }
            }
            return(organizationRelationship);
        }
示例#16
0
        /// <summary>
        ///     Inserts an Input Command into the simulation.
        /// </summary>
        /// <param name="session">Player session that raised the command. On client, this is always the LocalPlayer session.</param>
        /// <param name="function">Function that is being changed.</param>
        /// <param name="message">Arguments for this event.</param>
        public void HandleInputCommand(ICommonSession session, BoundKeyFunction function, FullInputCmdMessage message)
        {
            #if DEBUG
            var funcId = _inputManager.NetworkBindMap.KeyFunctionID(function);
            DebugTools.Assert(funcId == message.InputFunctionId, "Function ID in message does not match function.");
            #endif

            // set state, state change is updated regardless if it is locally bound
            _cmdStates.SetState(function, message.State);

            // handle local binds before sending off
            if (_bindMap.TryGetHandler(function, out var handler))
            {
                // local handlers can block sending over the network.
                if (handler.HandleCmdMessage(session, message))
                {
                    return;
                }
            }

            RaiseNetworkEvent(message);
        }
        private void HandleUseItemInHand(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            // client sanitization
            if (!_mapManager.GridExists(coords.GridID))
            {
                Logger.InfoS("system.interaction", $"Invalid Coordinates: client={session}, coords={coords}");
                return;
            }

            if (uid.IsClientSide())
            {
                Logger.WarningS("system.interaction",
                                $"Client sent interaction with client-side entity. Session={session}, Uid={uid}");
                return;
            }

            var userEntity = ((IPlayerSession)session).AttachedEntity;

            if (userEntity.TryGetComponent(out CombatModeComponent combatMode) && combatMode.IsInCombatMode)
            {
                DoAttack(userEntity, coords, uid);
            }
示例#18
0
        public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel,
                                                  ICommonSession session = null)
        {
            base.HandleNetworkMessage(message, netChannel, session);

            switch (message)
            {
            case BoundInterfaceMessageWrapMessage wrapped:
                if (session == null)
                {
                    throw new ArgumentNullException(nameof(session));
                }

                if (!_interfaces.TryGetValue(wrapped.UiKey, out var @interface))
                {
                    Logger.DebugS("go.comp.ui", "Got BoundInterfaceMessageWrapMessage for unknown UI key: {0}",
                                  wrapped.UiKey);
                    return;
                }

                @interface.ReceiveMessage(wrapped.Message, session as IPlayerSession);
                break;
            }
        }
        private bool HandleDrop(ICommonSession session, EntityCoordinates coords, EntityUid uid)
        {
            var ent = ((IPlayerSession)session).AttachedEntity;

            if (ent == null || !ent.IsValid())
            {
                return(false);
            }

            if (!ent.TryGetComponent(out HandsComponent handsComp))
            {
                return(false);
            }

            if (handsComp.ActiveHand == null || handsComp.GetActiveHand == null)
            {
                return(false);
            }

            var entMap       = ent.Transform.MapPosition;
            var targetPos    = coords.ToMapPos(EntityManager);
            var dropVector   = targetPos - entMap.Position;
            var targetVector = Vector2.Zero;

            if (dropVector != Vector2.Zero)
            {
                var targetLength = MathF.Min(dropVector.Length, SharedInteractionSystem.InteractionRange - 0.001f); // InteractionRange is reduced due to InRange not dealing with floating point error
                var newCoords    = coords.WithPosition(dropVector.Normalized * targetLength + entMap.Position).ToMap(EntityManager);
                var rayLength    = Get <SharedInteractionSystem>().UnobstructedDistance(entMap, newCoords, ignoredEnt: ent);
                targetVector = dropVector.Normalized * rayLength;
            }

            handsComp.Drop(handsComp.ActiveHand, coords.WithPosition(entMap.Position + targetVector));

            return(true);
        }
示例#20
0
        private void HandleUseItemInWorld(ICommonSession session, GridCoordinates coords, EntityUid uid)
        {
            if (!EntityManager.TryGetEntity(uid, out var used))
            {
                return;
            }

            var playerEnt = ((IPlayerSession)session).AttachedEntity;

            if (playerEnt == null || !playerEnt.IsValid())
            {
                return;
            }

            if (!playerEnt.Transform.GridPosition.InRange(_mapManager, used.Transform.GridPosition, INTERACTION_RANGE))
            {
                return;
            }

            var activateMsg = new ActivateInWorldMessage(playerEnt, used);

            RaiseEvent(activateMsg);
            if (activateMsg.Handled)
            {
                return;
            }

            if (!used.TryGetComponent(out IActivate activateComp))
            {
                return;
            }

            activateComp.Activate(new ActivateEventArgs {
                User = playerEnt
            });
        }
示例#21
0
        /// <inheritdoc />
        public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null)
        {
            base.HandleNetworkMessage(message, netChannel, session);

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            switch (message)
            {
            case ClientInventoryMessage msg:
                var playerentity = session.AttachedEntity;

                if (playerentity == Owner)
                {
                    HandleInventoryMessage(msg);
                }
                break;

            case OpenSlotStorageUIMessage msg:
                if (!HasSlot(msg.Slot))     // client input sanitization
                {
                    return;
                }
                var item = GetSlotItem(msg.Slot);
                if (item != null && item.Owner.TryGetComponent(out ServerStorageComponent storage))
                {
                    storage.OpenStorageUI(Owner);
                }
                break;
            }
        }
示例#22
0
 public override ComponentState GetComponentState(ICommonSession player)
 {
     return(new CrayonComponentState(_color, SelectedState, Charges, Capacity));
 }
 public override ComponentState GetComponentState(ICommonSession player)
 {
     return(new HandheldLightComponentState(GetLevel()));
 }
示例#24
0
 public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
 {
     base.HandleNetworkMessage(message, channel, session);
     // If the client that sent the message isn't the client playing this instrument, we ignore it.
     if (channel != _instrumentPlayer)
     {
         return;
     }
     switch (message)
     {
     case InstrumentMidiEventMessage midiEventMsg:
         SendNetworkMessage(midiEventMsg);
         break;
     }
 }
        public override void HandleNetworkMessage(ComponentMessage message, INetChannel channel, ICommonSession session = null)
        {
            base.HandleNetworkMessage(message, channel, session);

            switch (message)
            {
            case AckStructureConstructionMessage ackMsg:
                ClearGhost(ackMsg.Ack);
                break;

            default:
                break;
            }
        }
示例#26
0
        public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null)
        {
            base.HandleNetworkMessage(message, netChannel, session);

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            switch (message)
            {
            case ClickStatusMessage msg:
            {
                var player = session.AttachedEntity;

                if (player != Owner)
                {
                    break;
                }

                // TODO: Implement clicking other status effects in the HUD
                switch (msg.Effect)
                {
                case StatusEffect.Buckled:
                    if (!player.TryGetComponent(out BuckleComponent buckle))
                    {
                        break;
                    }

                    buckle.TryUnbuckle(player);
                    break;

                case StatusEffect.Piloting:
                    if (!player.TryGetComponent(out ShuttleControllerComponent controller))
                    {
                        break;
                    }

                    controller.RemoveController();
                    break;

                case StatusEffect.Pulling:
                    if (!player.TryGetComponent(out HandsComponent hands))
                    {
                        break;
                    }

                    hands.StopPull();
                    break;

                case StatusEffect.Fire:
                    if (!player.TryGetComponent(out FlammableComponent flammable))
                    {
                        break;
                    }

                    flammable.Resist();
                    break;

                default:
                    player.PopupMessage(msg.Effect.ToString());
                    break;
                }

                break;
            }
            }
        }
 public override ComponentState GetComponentState(ICommonSession player)
 {
     return(new PullableComponentState(Puller?.Uid));
 }
示例#28
0
 public override ComponentState GetComponentState(ICommonSession player)
 {
     return(new StandingComponentState(Standing));
 }
示例#29
0
        public override void HandleNetworkMessage(ComponentMessage message, INetChannel netChannel, ICommonSession session = null)
        {
            base.HandleNetworkMessage(message, netChannel, session);

            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            switch (message)
            {
            case ClickAlertMessage msg:
            {
                var player = session.AttachedEntity;

                if (player != Owner)
                {
                    break;
                }

                if (!IsShowingAlert(msg.AlertType))
                {
                    Logger.DebugS("alert", "user {0} attempted to" +
                                  " click alert {1} which is not currently showing for them",
                                  player.Name, msg.AlertType);
                    break;
                }

                if (AlertManager.TryGet(msg.AlertType, out var alert) && alert.OnClick != null)
                {
                    alert.OnClick.AlertClicked(new ClickAlertEventArgs(player, alert));
                }
                else
                {
                    Logger.WarningS("alert", "unrecognized encoded alert {0}", msg.AlertType);
                }

                break;
            }
            }
        }
示例#30
0
 public override void Disabled(ICommonSession session)
 {
     DisabledDelegate?.Invoke(session);
 }