Ejemplo n.º 1
0
        public bool TryPurchaseItem(UplinkAccount acc, string itemId)
        {
            if (acc == null)
            {
                return(false);
            }

            if (!_listings.TryGetValue(itemId, out var listing))
            {
                return(false);
            }

            if (acc.Balance < listing.Price)
            {
                return(false);
            }

            if (!ChangeBalance(acc, -listing.Price))
            {
                return(false);
            }

            var player = _entityManager.GetEntity(acc.AccountHolder);
            var hands  = player.GetComponent <HandsComponent>();

            hands.PutInHandOrDrop(_entityManager.SpawnEntity(listing.ItemId,
                                                             player.Transform.Coordinates).GetComponent <ItemComponent>());
            return(true);
        }
Ejemplo n.º 2
0
        public bool AddNewAccount(UplinkAccount acc)
        {
            var entity = _entityManager.GetEntity(acc.AccountHolder);

            if (entity.TryGetComponent(out MindComponent mindComponent))
            {
                if (!mindComponent.HasMind)
                {
                    return(false);
                }

                if (mindComponent.Mind !.AllRoles.Any(role => !role.Antagonist))
                {
                    return(false);
                }
            }

            if (_accounts.Contains(acc))
            {
                return(false);
            }

            _accounts.Add(acc);
            return(true);
        }
Ejemplo n.º 3
0
        public bool AddUplink(EntityUid user, UplinkAccount account, EntityUid?uplinkEntity = null)
        {
            // Try to find target item
            if (uplinkEntity == null)
            {
                uplinkEntity = FindUplinkTarget(user);
                if (uplinkEntity == null)
                {
                    return(false);
                }
            }

            var uplink = uplinkEntity.Value.EnsureComponent <UplinkComponent>();

            SetAccount(uplink, account);

            if (!HasComp <PDAComponent>(uplinkEntity.Value))
            {
                uplink.ActivatesInHands = true;
            }

            // TODO add BUI. Currently can't be done outside of yaml -_-

            return(true);
        }
        public UplinkAccountBalanceChanged(UplinkAccount account, int difference)
        {
            Account    = account;
            Difference = difference;

            NewBalance = account.Balance;
            OldBalance = account.Balance - difference;
        }
        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;
        }
Ejemplo n.º 6
0
        public bool ChangeBalance(UplinkAccount acc, int amt)
        {
            var account = _accounts.Find(uplinkAccount => uplinkAccount.AccountHolder == acc.AccountHolder);

            if (account != null && account.Balance + amt < 0)
            {
                return(false);
            }
            account.ModifyAccountBalance(account.Balance + amt);
            return(true);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initialize the PDA's syndicate uplink account.
        /// </summary>
        /// <param name="acc"></param>
        public void InitUplinkAccount(UplinkAccount acc)
        {
            _syndicateUplinkAccount = acc;
            _uplinkManager.AddNewAccount(_syndicateUplinkAccount);

            _syndicateUplinkAccount.BalanceChanged += account =>
            {
                UpdatePDAUserInterface();
            };

            UpdatePDAUserInterface();
        }
        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);
            }
        }
Ejemplo n.º 9
0
        public bool AddNewAccount(UplinkAccount acc)
        {
            var entity = _entityManager.GetEntity(acc.AccountHolder);

            if (entity.TryGetComponent(out MindComponent mindComponent) && !mindComponent.HasMind)
            {
                return(false);
            }

            if (_accounts.Contains(acc))
            {
                return(false);
            }

            _accounts.Add(acc);
            return(true);
        }
Ejemplo n.º 10
0
        public bool TryPurchaseItem(UplinkAccount acc, UplinkListingData listing)
        {
            if (acc == null || listing == null)
            {
                return(false);
            }
            if (!ContainsListing(listing) || acc.Balance < listing.Price)
            {
                return(false);
            }

            var player = _entityManager.GetEntity(acc.AccountHolder);
            var hands  = player.GetComponent <HandsComponent>();

            hands.PutInHandOrDrop(_entityManager.SpawnEntity(listing.ItemId,
                                                             player.Transform.GridPosition).GetComponent <ItemComponent>());
            return(ChangeBalance(acc, -listing.Price));
        }
Ejemplo n.º 11
0
        public bool AddUplink(IEntity user, UplinkAccount account, IEntity?uplinkEntity = null)
        {
            // Try to find target item
            if (uplinkEntity == null)
            {
                uplinkEntity = FindUplinkTarget(user);
                if (uplinkEntity == null)
                {
                    return(false);
                }
            }

            var uplink = uplinkEntity.EnsureComponent <UplinkComponent>();

            SetAccount(uplink, account);

            return(true);
        }
Ejemplo n.º 12
0
        public override bool Start(IReadOnlyList <IPlayerSession> readyPlayers, bool force = false)
        {
            MinPlayers             = _cfg.GetCVar(CCVars.SuspicionMinPlayers);
            MinTraitors            = _cfg.GetCVar(CCVars.SuspicionMinTraitors);
            PlayersPerTraitor      = _cfg.GetCVar(CCVars.SuspicionPlayersPerTraitor);
            TraitorStartingBalance = _cfg.GetCVar(CCVars.SuspicionStartingBalance);

            if (!force && readyPlayers.Count < MinPlayers)
            {
                _chatManager.DispatchServerAnnouncement($"Not enough players readied up for the game! There were {readyPlayers.Count} players readied up out of {MinPlayers} needed.");
                return(false);
            }

            if (readyPlayers.Count == 0)
            {
                _chatManager.DispatchServerAnnouncement("No players readied up! Can't start Suspicion.");
                return(false);
            }

            var list     = new List <IPlayerSession>(readyPlayers);
            var prefList = new List <IPlayerSession>();

            foreach (var player in list)
            {
                if (!ReadyProfiles.ContainsKey(player.UserId))
                {
                    continue;
                }
                var profile = ReadyProfiles[player.UserId];
                if (profile.AntagPreferences.Contains(_prototypeManager.Index <AntagPrototype>(TraitorID).Name))
                {
                    prefList.Add(player);
                }

                player.AttachedEntity?.EnsureComponent <SuspicionRoleComponent>();
            }

            var numTraitors = MathHelper.Clamp(readyPlayers.Count / PlayersPerTraitor,
                                               MinTraitors, readyPlayers.Count);

            var traitors = new List <SuspicionTraitorRole>();

            for (var i = 0; i < numTraitors; i++)
            {
                IPlayerSession traitor;
                if (prefList.Count == 0)
                {
                    if (list.Count == 0)
                    {
                        Logger.InfoS("preset", "Insufficient ready players to fill up with traitors, stopping the selection.");
                        break;
                    }
                    traitor = _random.PickAndTake(list);
                    Logger.InfoS("preset", "Insufficient preferred traitors, picking at random.");
                }
                else
                {
                    traitor = _random.PickAndTake(prefList);
                    list.Remove(traitor);
                    Logger.InfoS("preset", "Selected a preferred traitor.");
                }
                var mind           = traitor.Data.ContentData().Mind;
                var antagPrototype = _prototypeManager.Index <AntagPrototype>(TraitorID);
                var traitorRole    = new SuspicionTraitorRole(mind, antagPrototype);
                mind.AddRole(traitorRole);
                traitors.Add(traitorRole);
                // creadth: we need to create uplink for the antag.
                // PDA should be in place already, so we just need to
                // initiate uplink account.
                var uplinkAccount =
                    new UplinkAccount(mind.OwnedEntity.Uid,
                                      TraitorStartingBalance);
                var inventory = mind.OwnedEntity.GetComponent <InventoryComponent>();
                if (!inventory.TryGetSlotItem(EquipmentSlotDefines.Slots.IDCARD, out ItemComponent pdaItem))
                {
                    continue;
                }

                var pda = pdaItem.Owner;

                var pdaComponent = pda.GetComponent <PDAComponent>();
                if (pdaComponent.IdSlotEmpty)
                {
                    continue;
                }

                pdaComponent.InitUplinkAccount(uplinkAccount);
            }

            foreach (var player in list)
            {
                var mind           = player.Data.ContentData().Mind;
                var antagPrototype = _prototypeManager.Index <AntagPrototype>(InnocentID);
                mind.AddRole(new SuspicionInnocentRole(mind, antagPrototype));
            }

            foreach (var traitor in traitors)
            {
                traitor.GreetSuspicion(traitors, _chatManager);
            }

            _gameTicker.AddGameRule <RuleSuspicion>();
            return(true);
        }
        public void Execute(IConsoleShell shell, string argStr, string[] args)
        {
            if (args.Length < 1)
            {
                shell.WriteError(Loc.GetString("shell-wrong-arguments-number"));
                return;
            }

            // Get player entity
            if (!IoCManager.Resolve <IPlayerManager>().TryGetSessionByUsername(args[0], out var session))
            {
                shell.WriteLine(Loc.GetString("shell-target-player-does-not-exist"));
                return;
            }
            if (session.AttachedEntity is not {
            } user)
            {
                shell.WriteLine(Loc.GetString("Selected player doesn't controll any entity"));
                return;
            }

            // Get target item
            EntityUid?uplinkEntity  = null;
            var       entityManager = IoCManager.Resolve <IEntityManager>();

            if (args.Length >= 2)
            {
                if (!int.TryParse(args[1], out var itemID))
                {
                    shell.WriteLine(Loc.GetString("shell-entity-uid-must-be-number"));
                    return;
                }

                var eUid = new EntityUid(itemID);
                if (!eUid.IsValid() || !entityManager.EntityExists(eUid))
                {
                    shell.WriteLine(Loc.GetString("shell-invalid-entity-id"));
                    return;
                }

                uplinkEntity = eUid;
            }

            // Get TC count
            var configManager = IoCManager.Resolve <IConfigurationManager>();
            var tcCount       = configManager.GetCVar(CCVars.TraitorStartingBalance);

            // Get account
            var uplinkAccount = new UplinkAccount(tcCount, user);
            var accounts      = entityManager.EntitySysManager.GetEntitySystem <UplinkAccountsSystem>();

            accounts.AddNewAccount(uplinkAccount);

            // Finally add uplink
            if (!entityManager.EntitySysManager.GetEntitySystem <UplinkSystem>()
                .AddUplink(user, uplinkAccount, uplinkEntity))
            {
                shell.WriteLine(Loc.GetString("Failed to add uplink to the player"));
                return;
            }
        }