private void OnUseHand(EntityUid uid, UplinkComponent component, UseInHandEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            // check if uplinks activates directly or use some proxy, like a PDA
            if (!component.ActivatesInHands)
            {
                return;
            }
            if (component.UplinkAccount == null)
            {
                return;
            }

            if (!EntityManager.TryGetComponent(args.User.Uid, out ActorComponent? actor))
            {
                return;
            }

            ToggleUplinkUI(component, actor.PlayerSession);
            args.Handled = true;
        }
        private void UpdateUserInterface(UplinkComponent component)
        {
            var ui = component.Owner.GetUIOrNull(UplinkUiKey.Key);

            if (ui == null)
            {
                return;
            }

            var listings = _listing.GetListings().Values.ToArray();
            var acc      = component.UplinkAccount;

            UplinkAccountData accData;

            if (acc != null)
            {
                accData = new UplinkAccountData(acc.AccountHolder, acc.Balance);
            }
            else
            {
                accData = new UplinkAccountData(null, 0);
            }

            ui.SetState(new UplinkUpdateState(accData, listings));
        }
        private void OnBuy(EntityUid uid, UplinkComponent uplink, UplinkBuyListingMessage message)
        {
            var player = message.Session.AttachedEntity;

            if (player == null)
            {
                return;
            }
            if (uplink.UplinkAccount == null)
            {
                return;
            }

            if (!_accounts.TryPurchaseItem(uplink.UplinkAccount, message.ItemId,
                                           player.Transform.Coordinates, out var entity))
            {
                SoundSystem.Play(Filter.SinglePlayer(message.Session), uplink.InsufficientFundsSound.GetSound(),
                                 uplink.Owner, AudioParams.Default);
                RaiseNetworkEvent(new UplinkInsufficientFundsMessage(), message.Session.ConnectedClient);
                return;
            }

            if (player.TryGetComponent(out HandsComponent? hands) &&
                entity.TryGetComponent(out ItemComponent? item))
            {
                hands.PutInHandOrDrop(item);
            }

            SoundSystem.Play(Filter.SinglePlayer(message.Session), uplink.BuySuccessSound.GetSound(),
                             uplink.Owner, AudioParams.Default.WithVolume(-2f));

            RaiseNetworkEvent(new UplinkBuySuccessMessage(), message.Session.ConnectedClient);
        }
예제 #4
0
        private void OnWithdrawTC(EntityUid uid, UplinkComponent uplink, UplinkTryWithdrawTC args)
        {
            var acc = uplink.UplinkAccount;

            if (acc == null)
            {
                return;
            }

            if (args.Session.AttachedEntity is not {
                Valid : true
            } player)
            {
                return;
            }
            var cords = EntityManager.GetComponent <TransformComponent>(player).Coordinates;

            // try to withdraw TCs from account
            if (!_accounts.TryWithdrawTC(acc, args.TC, cords, out var tcUid))
            {
                return;
            }

            // try to put it into players hands
            _handsSystem.PickupOrDrop(player, tcUid.Value);

            // play buying sound
            SoundSystem.Play(uplink.BuySuccessSound.GetSound(),
                             Filter.SinglePlayer(args.Session), uplink.Owner, AudioParams.Default.WithVolume(-8f));

            UpdateUserInterface(uplink);
        }
예제 #5
0
        private void OnBuy(EntityUid uid, UplinkComponent uplink, UplinkBuyListingMessage message)
        {
            if (message.Session.AttachedEntity is not {
                Valid: true
            } player)
            {
                return;
            }
            if (uplink.UplinkAccount == null)
            {
                return;
            }

            if (!_accounts.TryPurchaseItem(uplink.UplinkAccount, message.ItemId,
                                           EntityManager.GetComponent <TransformComponent>(player).Coordinates, out var entity))
            {
                SoundSystem.Play(uplink.InsufficientFundsSound.GetSound(),
                                 Filter.SinglePlayer(message.Session), uplink.Owner, AudioParams.Default);
                RaiseNetworkEvent(new UplinkInsufficientFundsMessage(), message.Session.ConnectedClient);
                return;
            }

            _handsSystem.PickupOrDrop(player, entity.Value);

            SoundSystem.Play(uplink.BuySuccessSound.GetSound(),
                             Filter.SinglePlayer(message.Session), uplink.Owner, AudioParams.Default.WithVolume(-8f));

            RaiseNetworkEvent(new UplinkBuySuccessMessage(), message.Session.ConnectedClient);
        }
예제 #6
0
        private void OnUseHand(EntityUid uid, UplinkComponent component, UseInHandEvent args)
        {
            if (args.Handled)
            {
                return;
            }

            // check if uplinks activates directly or use some proxy, like a PDA
            if (!component.ActivatesInHands)
            {
                return;
            }
            if (component.UplinkAccount == null)
            {
                return;
            }

            if (!EntityManager.TryGetComponent(args.User, out ActorComponent? actor))
            {
                return;
            }

            var actionBlocker = EntitySystem.Get <ActionBlockerSystem>();

            if (!actionBlocker.CanInteract(uid) || !actionBlocker.CanUse(uid))
            {
                return;
            }

            ToggleUplinkUI(component, actor.PlayerSession);
            args.Handled = true;
        }
        public void ToggleUplinkUI(UplinkComponent component, IPlayerSession session)
        {
            var ui = component.Owner.GetUIOrNull(UplinkUiKey.Key);

            ui?.Toggle(session);

            UpdateUserInterface(component);
        }
        public void SetAccount(UplinkComponent component, UplinkAccount account)
        {
            if (component.UplinkAccount != null)
            {
                Logger.Error("Can't init one uplink with different account!");
                return;
            }

            component.UplinkAccount = account;
        }
        private void OnInit(EntityUid uid, UplinkComponent component, ComponentInit args)
        {
            RaiseLocalEvent(uid, new UplinkInitEvent(component));

            // if component has a preset info (probably spawn by admin)
            // create a new account and register it for this uplink
            if (component.PresetInfo != null)
            {
                var account = new UplinkAccount(component.PresetInfo.StartingBalance);
                _accounts.AddNewAccount(account);
                SetAccount(component, account);
            }
        }
예제 #10
0
 public UplinkInitEvent(UplinkComponent uplink)
 {
     Uplink = uplink;
 }
 private void OnRemove(EntityUid uid, UplinkComponent component, ComponentRemove args)
 {
     RaiseLocalEvent(uid, new UplinkRemovedEvent());
 }
 private void OnRequestUpdateUI(EntityUid uid, UplinkComponent uplink, UplinkRequestUpdateInterfaceMessage args)
 {
     UpdateUserInterface(uplink);
 }
예제 #13
0
        private void UpdateUserInterface(UplinkComponent component)
        {
            var ui = component.Owner.GetUIOrNull(UplinkUiKey.Key);

            if (ui == null)
            {
                return;
            }

            var listings = _listing.GetListings().Values.ToList();
            var acc      = component.UplinkAccount;

            UplinkAccountData accData;

            if (acc != null)
            {
                // if we don't have a jobwhitelist stored, get a new one
                if (component.JobWhitelist == null &&
                    acc.AccountHolder != null &&
                    TryComp <MindComponent>(acc.AccountHolder, out var mind) &&
                    mind.Mind != null)
                {
                    HashSet <string>?jobList = new();
                    foreach (var role in mind.Mind.AllRoles.ToList())
                    {
                        if (role.GetType() == typeof(Job))
                        {
                            var job = (Job)role;
                            jobList.Add(job.Prototype.ID);
                        }
                    }
                    component.JobWhitelist = jobList;
                }

                // filter out items not on the whitelist
                for (var i = 0; i < listings.Count; i++)
                {
                    var entry = listings[i];
                    if (entry.JobWhitelist != null)
                    {
                        var found = false;
                        if (component.JobWhitelist != null)
                        {
                            foreach (var job in component.JobWhitelist)
                            {
                                if (entry.JobWhitelist.Contains(job))
                                {
                                    found = true;
                                    break;
                                }
                            }
                        }
                        if (!found)
                        {
                            listings.Remove(entry);
                            i--;
                        }
                    }
                }
                accData = new UplinkAccountData(acc.AccountHolder, acc.Balance);
            }
            else
            {
                accData = new UplinkAccountData(null, 0);
            }

            ui.SetState(new UplinkUpdateState(accData, listings.ToArray()));
        }