public override bool Start(IReadOnlyList <IPlayerSession> readyPlayers, bool force = false) { 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); } var list = new List <IPlayerSession>(readyPlayers); var prefList = new List <IPlayerSession>(); foreach (var player in list) { if (!readyProfiles.ContainsKey(player.Name)) { continue; } var profile = readyProfiles[player.Name]; if (profile.AntagPreferences.Contains(_prototypeManager.Index <AntagPrototype>(TraitorID).Name)) { prefList.Add(player); } } var numTraitors = FloatMath.Clamp(readyPlayers.Count % PlayersPerTraitor, MinTraitors, readyPlayers.Count); for (var i = 0; i < numTraitors; i++) { IPlayerSession traitor; if (prefList.Count() == 0) { 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); mind.AddRole(new SuspicionTraitorRole(mind, antagPrototype)); } foreach (var player in list) { var mind = player.Data.ContentData().Mind; var antagPrototype = _prototypeManager.Index <AntagPrototype>(InnocentID); mind.AddRole(new SuspicionInnocentRole(mind, antagPrototype)); } _gameTicker.AddGameRule <RuleSuspicion>(); return(true); }
private void AddCargoContents(CargoShuttleComponent component, StationCargoOrderDatabaseComponent orderDatabase) { var xformQuery = GetEntityQuery <TransformComponent>(); var orders = GetProjectedOrders(orderDatabase, component); var pads = GetCargoPallets(component); DebugTools.Assert(orders.Sum(o => o.Amount) <= pads.Count); for (var i = 0; i < orders.Count; i++) { var order = orders[i]; Spawn(_protoMan.Index <CargoProductPrototype>(order.ProductId).Product, new EntityCoordinates(component.Owner, xformQuery.GetComponent(_random.PickAndTake(pads).Owner).LocalPosition)); order.Amount--; if (order.Amount == 0) { orders.RemoveSwap(i); orderDatabase.Orders.Remove(order.OrderNumber); i--; } else { orderDatabase.Orders[order.OrderNumber] = order; } } }
public override bool Start(IReadOnlyList <IPlayerSession> readyPlayers) { if (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); } var list = new List <IPlayerSession>(readyPlayers); var numTraitors = Math.Max(readyPlayers.Count() % PlayersPerTraitor, MinTraitors); for (var i = 0; i < numTraitors; i++) { var traitor = _random.PickAndTake(list); var mind = traitor.Data.ContentData().Mind; mind.AddRole(new SuspicionTraitorRole(mind)); } foreach (var player in list) { var mind = player.Data.ContentData().Mind; mind.AddRole(new SuspicionInnocentRole(mind)); } _gameTicker.AddGameRule <RuleSuspicion>(); return(true); }
private bool TryGetPiece(EntityUid uid, EntityUid user, EntityUid used, KitchenSpikeComponent?component = null, UtensilComponent?utensil = null) { if (!Resolve(uid, ref component) || component.PrototypesToSpawn == null || component.PrototypesToSpawn.Count == 0) { return(false); } // Is using knife if (!Resolve(used, ref utensil, false) || (utensil.Types & UtensilType.Knife) == 0) { return(false); } var item = _random.PickAndTake(component.PrototypesToSpawn); var ent = Spawn(item, Transform(uid).Coordinates); MetaData(ent).EntityName = Loc.GetString("comp-kitchen-spike-meat-name", ("name", Name(ent)), ("victim", component.Victim)); if (component.PrototypesToSpawn.Count != 0) { _popupSystem.PopupEntity(component.MeatSource1p, uid, Filter.Entities(user)); } else { UpdateAppearance(uid, null, component); _popupSystem.PopupEntity(component.MeatSource0, uid, Filter.Entities(user)); } return(true); }
public override void Startup() { base.Startup(); var stationSystem = EntitySystem.Get <StationSystem>(); var stationJobsSystem = EntitySystem.Get <StationJobsSystem>(); if (stationSystem.Stations.Count == 0) { return; // No stations } var chosenStation = _random.Pick(stationSystem.Stations.ToList()); var jobList = stationJobsSystem.GetJobs(chosenStation).Keys.ToList(); // Low chance to completely change up the late-join landscape by closing all positions except infinite slots. // Lower chance than the /tg/ equivalent of this event. if (_random.Prob(0.25f)) { var chosenJob = _random.PickAndTake(jobList); stationJobsSystem.MakeJobUnlimited(chosenStation, chosenJob); // INFINITE chaos. foreach (var job in jobList) { if (stationJobsSystem.IsJobUnlimited(chosenStation, job)) { continue; } stationJobsSystem.TrySetJobSlot(chosenStation, job, 0); } } else { // Changing every role is maybe a bit too chaotic so instead change 20-30% of them. for (var i = 0; i < _random.Next((int)(jobList.Count * 0.20), (int)(jobList.Count * 0.30)); i++) { var chosenJob = _random.PickAndTake(jobList); if (stationJobsSystem.IsJobUnlimited(chosenStation, chosenJob)) { continue; } stationJobsSystem.TryAdjustJobSlot(chosenStation, chosenJob, _random.Next(-3, 6)); } } }
public override void Startup() { base.Startup(); var chosenStation = _random.Pick(EntitySystem.Get <StationSystem>().StationInfo.Values.ToList()); var jobList = chosenStation.JobList.Keys.Where(x => !_prototypeManager.Index <JobPrototype>(x).IsHead).ToList(); // Low chance to completely change up the late-join landscape by closing all positions except infinite slots. // Lower chance than the /tg/ equivalent of this event. if (_random.Prob(0.25f)) { var chosenJob = _random.PickAndTake(jobList); chosenStation.AdjustJobAmount(chosenJob, -1); // INFINITE chaos. foreach (var job in jobList) { if (chosenStation.JobList[job] == -1) { continue; } chosenStation.AdjustJobAmount(job, 0); } } else { // Changing every role is maybe a bit too chaotic so instead change 20-30% of them. for (var i = 0; i < _random.Next((int)(jobList.Count * 0.20), (int)(jobList.Count * 0.30)); i++) { var chosenJob = _random.PickAndTake(jobList); if (chosenStation.JobList[chosenJob] == -1) { continue; } var adj = Math.Max(chosenStation.JobList[chosenJob] + _random.Next(-3, 6), 0); chosenStation.AdjustJobAmount(chosenJob, adj); } } }
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 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; } 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); DebugTools.AssertNotNull(mind?.OwnedEntity); 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(TraitorStartingBalance, mind.OwnedEntity !.Uid); var accounts = EntityManager.EntitySysManager.GetEntitySystem <UplinkAccountsSystem>(); accounts.AddNewAccount(uplinkAccount); // try to place uplink if (!EntityManager.EntitySysManager.GetEntitySystem <UplinkSystem>() .AddUplink(mind.OwnedEntity, uplinkAccount)) { continue; } } foreach (var player in list) { var mind = player.Data.ContentData()?.Mind; var antagPrototype = _prototypeManager.Index <AntagPrototype>(InnocentID); DebugTools.AssertNotNull(mind); mind !.AddRole(new SuspicionInnocentRole(mind, antagPrototype)); } foreach (var traitor in traitors) { traitor.GreetSuspicion(traitors, _chatManager); } EntitySystem.Get <GameTicker>().AddGameRule <RuleSuspicion>(); return(true); }
public override bool Start(IReadOnlyList <IPlayerSession> readyPlayers, bool force = false) { MinPlayers = _cfg.GetCVar <int>("game.suspicion_min_players"); MinTraitors = _cfg.GetCVar <int>("game.suspicion_min_traitors"); PlayersPerTraitor = _cfg.GetCVar <int>("game.suspicion_players_per_traitor"); 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.Name)) { continue; } var profile = readyProfiles[player.Name]; 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); } 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); }