Files
OldThink/Content.Server/White/Reputation/ReputationSystem.cs

185 lines
5.7 KiB
C#
Raw Normal View History

using System.Linq;
using Content.Server.Administration;
using Content.Server.GameTicking;
2024-01-25 08:49:08 +03:00
using Content.Server.Objectives;
using Content.Server.Roles;
using Content.Server.White.AspectsSystem.Base;
2024-01-25 08:49:08 +03:00
using Content.Shared.Mind;
using Content.Shared.Mind.Components;
[Feat] Panda socket (#616) * base server side * token check & base command response * panda base command response addition & some commands * web event, rest of commands & events * fix empty api * [DRAFT] Panda HTTP server (#570) * [Sponsor] Nairsark ghost (#492) * [Sponsor] Trora ghost (#493) * [Sponsor] Trora ghost * ckey * Vtergot fluff (#494) * Твики (#491) * Economy additions * Tweak implant cooldowns * Cult stuff * Random appearance aspect nuke ops fix * Auto shuttle enable on round end * Holy water threshold * Automatic changelog update * [Sponsor] Geraldiy fluff (#496) * [Fix] Reputation respawn hotfix (#497) * Automatic changelog update * Новые аспекты (#495) * Add ReflectAspect * Add SlipperyAspect * Add TraitorRichAspect * Add WhisperAspect * Add DarknessAspect & StolenFloorAspect * Add WindowLeakAspect * Add CatEarsAspect * Add NothingAspect * Fix fast and furious clone * Add SkeletonAspect * Add cvar ceanup * Automatic changelog update * [Sponsor] Fluff knife cappy (#498) * [Sponsor] Fluff KnifeCappy * loadout * Всякое (#501) * eftpos form jurist * ebal parameda * Automatic changelog update * [Sponsor] Zilendorie ghost upgrade (#502) * Апдейт карт, станция прибытия (#503) * Automatic changelog update * Fix aspects (#500) * Automatic changelog update * Rules popup fix (#504) * Defib fix (#499) * Automatic changelog update * Фикс флаффа (#507) * Фикс прибытия (#509) * Automatic changelog update * Фиксы (#508) * Fix cult blindfold * Add stamina resistances * Energy bolt is energy * Laser shield is anti-laser * Cult blindfold welding protection * Eject id cards on deconstruct * Wires panel power fix * Add markings for species * Ebow gaming * feat: настенные консольки (#505) * Automatic changelog update * [Sponsor] Fluff Medicgaming (#510) * Привязка банковского аккаунта (#506) * Sustenance vend price fix * Account link * Automatic changelog update * antag ban fix (#511) * antag ban fix * rename some shit * Bugfixes (#512) * Bullets go through open crates * Bullets don't hit pulled dead bodies * No glued cuffs * Missed reflect aspect mark * vehicles cannot be shot (#18910) Co-authored-by: deltanedas <@deltanedas:kde.org> * Cleanup --------- Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> * Automatic changelog update * атмос гейминг indeed (#513) * fix hypernob + plasma and trit fire * add 11 new gas types * actually fix hypernob --------- Co-authored-by: halicopter <kirillhalic@gmail.com> * Automatic changelog update * [Sponsor] thechaotic fluff * Revert "[Sponsor] thechaotic fluff" This reverts commit d19c807751258f9cfb205db01b0e4617b638fe98. * [Sponsor] Fluff updates (#518) * warete update * renosan & warete size * [Sponsor] thechaotic fluff (#519) (cherry picked from commit d19c807751258f9cfb205db01b0e4617b638fe98) * fix tts sanitize (#517) * Automatic changelog update * [Fluff] ghost regari * Buffs (#515) * FIRE axe * Bow pro * Bang * Meleeeee * Disarm two-handed hard * Automatic changelog update * Игнор вайтлист требования ролей если стоит флаг TOOLS (#514) * forAmins be like * >вайтлист в девелопменте * а описание кто напишет а * Размеры попапов в чате (#525) * попытка деконить магнит пока он активен гибает интернет приколистов (#524) * Интернет прикол * попап * Prevent using cultist items & halberd (#523) * Fix skeleton aspect (#522) * Fix cult door (#521) * Fix cult door * Prevent emagging * Walls and griders * Fix * Drone fix (#520) * Drone fix * RCD * Automatic changelog update * Смешное в конце раунда с аспектом (#516) * Cats * Fix * Automatic changelog update * Fix cult win conditions (#527) * Runes stuff (#526) * Blood boil 2.0 * Attach to grid * No * Automatic changelog update * [Sponsor] thefrendlypsychopath ghost (#529) * knifeCappy (#528) Co-authored-by: Mona Hmiza <you@example.com> * [Feat] TTS 8 new voices * borg fix * Automatic changelog update * мапперы тестили * fix void prototype * [Fix] Cult chat fix (#536) * ERT tweak (#530) * tweak values * tweak spawn logic * Invisible rune (#531) * Automatic changelog update * [Sponsor] Oleg_Tinkoff fluff (#534) * [Sponsor] Oleg_Tinkoff fluff * name fix * Small fixes (#537) * No sleeping emotes * Beakers & jugs in fridge * Drone fix * Fix teleport pulling * Fix loc * More fixes * Fix ghost role * Stuff * Automatic changelog update * Nerf grilles (#541) * Nerf grilles * tweak * Bola fix (#540) * Automatic changelog update * Куча говна (#539) * No Emp resistance (#538) * No EMP resistance * Cleanup * Automatic changelog update * mappews mapped some mowe~ * anothew update UwU * [Sponsor] Geraldiy fluff 2 (#542) * fix drydock * Objective changes (#543) * Automatic changelog update * UwU spawnews are now fixed, hopefully~ * UwU tired of it alweady * Automatic changelog update * Респрайт капитанского лазера (#546) * antique lasergun resprite lol * лицуха * Automatic changelog update * Апдейт арахнидов (#544) * Web underwear * Fix layers * Change melee sound * Arachnid 2: Episode 2 (#19984) * Shield * minor sprite changes and buffs * structure buff * Crafting stuff * tweaks * 88-88 * Better web pocket sprites. * yeah it's fine now. * Fix * Sprite tweaks * This I guess * Eye sprite --------- Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * [Sponsor] Zilendorie fluff (#545) * Automatic changelog update * Fire buff (#549) * EntityStorage deletion fix? (#548) * strip fix (#21552) (#547) Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * Automatic changelog update * [Fluff] SSAO Ghost * [Fluff] svinka ghost tweak * [Fluff] Svinka Coat * Meaty-Ore Idea (#550) * qwe * yeah * Vtergot fluff fix (#552) * наяриваем на лишние пиксели * Чтобы мапперы не втыкали * fix atmos (#551) * fix atmos * fixie * Automatic changelog update * Meow hotfix (#553) * Many stuff (#555) * Drone bucket * Weird insuls * Not too strong * No cult door bolts * Emergency shuttle after round end fix * Fix spiders * Automatic changelog update * [FEAT] Всякие прикольные разности и вкусности (#554) * feat: трикодер * feat: принтер документов * fix: текст фелинидов * feat: возможность менять голос эмоутов * feat: мяукаем при аспекте мяуканья * feat: ПНВ * fix: забирай свои метадаты * fix: oopsies * fix: линтер снова * fix: пожалуйста линтер отстань * Automatic changelog update * Гарпии (#533) * harpy initial * fix and some locale * ru locale * actions refactor shit * пофиксив гавпий~~~ пойду тестить~~ * hawpies are ready UwU * cweanup OwO * hawpies fixed a bit, still cant seawch them nya~ * hawpies can be stwipped now, fixie-dixie awwived~ * emotes fixie-dixied nya~ * говно * говно говна линтер соси * Automatic changelog update * Revert "Гарпии (#533)" (#557) This reverts commit e3f2166bf7cbd775278a396a3f8d8215a2d5c506. * Doom fluff (#556) * DOOMMAX fluff * Detective meow * Сеньёр помидор офицер * RSI validator su4ka * [Fluff] MR_Regari ghost tweak * [Fluff] svinka ghost tweak * [Fluff] Antohag gasmask fluff * ГАРПИИ (#559) * harpy initial * fix and some locale * ru locale * actions refactor shit * пофиксив гавпий~~~ пойду тестить~~ * hawpies are ready UwU * cweanup OwO * hawpies fixed a bit, still cant seawch them nya~ * hawpies can be stwipped now, fixie-dixie awwived~ * emotes fixie-dixied nya~ * говно * говно говна линтер соси * Automatic changelog update * [Tweak] Бумажная работа и фикс крафта пнв. (#560) * fix: персонал станции вспомнил как делать пнв * tweak: блюспейс технологии убраны у принтера документов * feat: заказ бумаги в карго * feat: бумажная дверь * Automatic changelog update * doommaxx-fluff nothing interesting * fluff skufa (#562) * [Sponsor] Fluff Forg (#567) * [Sponsor] Fluff Forg * fix size * sound * [Feat] TTS 15 new voices (#568) * Automatic changelog update * base server side * token check & base command response * panda base command response addition & some commands * web event, rest of commands & events * fix empty api --------- Co-authored-by: Cinkafox <70429757+Cinkafox@users.noreply.github.com> Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: Kotovskiy <77529717+wCATw@users.noreply.github.com> Co-authored-by: ThereDrD0 <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: KurokoTurbo <92106367+melanoTurbo@users.noreply.github.com> Co-authored-by: halicopter <kirillhalic@gmail.com> Co-authored-by: rhailrake <49613070+rhailrake@users.noreply.github.com> Co-authored-by: Subversionary <109166122+Subversionary@users.noreply.github.com> Co-authored-by: RavMorgan <48182970+RavMorgan@users.noreply.github.com> Co-authored-by: Mona Hmiza <you@example.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: REBOLUTION228-a11 <128076300+REBOLUTION228-a11@users.noreply.github.com> Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com> * newtonsoft version change * remove semaphore * remove double dooc * fix admin stealth * cleanup * remove utka sockets --------- Co-authored-by: Cinkafox <70429757+Cinkafox@users.noreply.github.com> Co-authored-by: Aviu00 <93730715+Aviu00@users.noreply.github.com> Co-authored-by: RavmorganButOnCocaine <valtos@nextmail.ru> Co-authored-by: Kotovskiy <77529717+wCATw@users.noreply.github.com> Co-authored-by: ThereDrD0 <88589686+ThereDrD0@users.noreply.github.com> Co-authored-by: Remuchi <72476615+Remuchi@users.noreply.github.com> Co-authored-by: deltanedas <39013340+deltanedas@users.noreply.github.com> Co-authored-by: KurokoTurbo <92106367+melanoTurbo@users.noreply.github.com> Co-authored-by: halicopter <kirillhalic@gmail.com> Co-authored-by: rhailrake <49613070+rhailrake@users.noreply.github.com> Co-authored-by: Subversionary <109166122+Subversionary@users.noreply.github.com> Co-authored-by: RavMorgan <48182970+RavMorgan@users.noreply.github.com> Co-authored-by: Mona Hmiza <you@example.com> Co-authored-by: Valtos <valtos@spaces.ru> Co-authored-by: REBOLUTION228-a11 <128076300+REBOLUTION228-a11@users.noreply.github.com> Co-authored-by: PixelTK <85175107+PixelTheKermit@users.noreply.github.com>
2024-01-09 15:54:16 +03:00
using Content.Server.White.PandaSocket.Main;
using Content.Shared.Mobs;
using Content.Shared.Mobs.Components;
using Content.Shared.White;
using Robust.Server.Player;
using Robust.Shared.Configuration;
using Robust.Shared.Network;
using Robust.Shared.Utility;
namespace Content.Server.White.Reputation;
public sealed class ReputationSystem : EntitySystem
{
[Dependency] private readonly IPlayerManager _playerManager = default!;
[Dependency] private readonly ReputationManager _repManager = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly IPlayerLocator _locator = default!;
[Dependency] private readonly IConfigurationManager _cfg = default!;
2024-01-25 08:49:08 +03:00
[Dependency] private readonly RoleSystem _roles = default!;
[Dependency] private readonly ObjectivesSystem _objectives = default!;
private const int MinPlayers = 15;
private const int MinRoundLength = 25;
private const int MinTimePlayerConnected = 20;
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<UtkaBannedEvent>(ModifyReputationOnPlayerBanned);
}
/// <summary>
/// Tries to modify reputation on round end and then returns it's new value and delta value if successful.
/// </summary>
/// <param name="name">Player to get new values for.</param>
/// <param name="newValue">Modified player's reputation value.</param>
/// <param name="deltaValue"></param>
/// <returns>Success in modifying player's reputation.</returns>
public bool TryModifyReputationOnRoundEnd(string name, out float? newValue, out float? deltaValue)
{
newValue = null;
deltaValue = null;
var repEnabled = _cfg.GetCVar(WhiteCVars.ReputationEnabled);
if (!repEnabled)
return false;
if (!_playerManager.TryGetSessionByUsername(name, out var session) || session.AttachedEntity == null)
return false;
if (!TryCalculatePlayerReputation(session.AttachedEntity.Value, out var delta))
return false;
var uid = session.UserId;
_repManager.GetCachedPlayerReputation(uid, out var value);
if (value == null)
return false;
var longConnected = _repManager.GetCachedPlayerConnection(uid, out var date)
&& DateTime.UtcNow - date >= TimeSpan.FromMinutes(MinTimePlayerConnected);
var longRound = _gameTicker.RoundDuration() >= TimeSpan.FromMinutes(MinRoundLength);
var enoughPlayers = _playerManager.PlayerCount >= MinPlayers;
if (delta != 0 && longRound && longConnected && enoughPlayers)
{
_repManager.ModifyPlayerReputation(uid, delta);
}
deltaValue = longRound && longConnected && enoughPlayers ? delta : 0f;
newValue = value + deltaValue;
return true;
}
private bool TryCalculatePlayerReputation(EntityUid entity, out float deltaValue)
{
deltaValue = 0f;
var aspect = false;
if (!TryComp<MobStateComponent>(entity, out var state) || state.CurrentState is MobState.Dead or MobState.Invalid)
return true;
var ruleEnt = _gameTicker.GetActiveGameRules()
.Where(HasComp<AspectComponent>)
.FirstOrNull();
if (ruleEnt != null)
{
if (TryComp<AspectComponent>(ruleEnt, out var comp))
{
deltaValue += comp.Weight switch
{
3 => 2f,
2 => 3f,
1 => 4f,
_ => 0f
};
aspect = true;
}
}
if (!aspect)
deltaValue += 1f;
if (TryComp<MindContainerComponent>(entity, out var mind)
&& mind.Mind != null
2024-01-25 08:49:08 +03:00
&& _roles.MindIsAntagonist(mind.Mind)
&& TryComp(mind.Mind, out MindComponent? mindComp))
{
2024-01-25 08:49:08 +03:00
var objCompleted = 0;
var totalObj = 0;
foreach (var obj in mindComp.Objectives)
{
2024-01-25 08:49:08 +03:00
totalObj++;
var info = _objectives.GetInfo(obj, mind.Mind.Value, mindComp);
2024-01-25 08:49:08 +03:00
if (info is {Progress: > 0.99f})
objCompleted++;
}
if (aspect)
{
2024-01-25 08:49:08 +03:00
if (objCompleted == totalObj)
deltaValue += 1f + objCompleted;
else
2024-01-25 08:49:08 +03:00
deltaValue += 1f + objCompleted * 0.5f;
}
else
{
2024-01-25 08:49:08 +03:00
if (objCompleted == totalObj)
deltaValue += 2f + objCompleted * 0.5f;
else
2024-01-25 08:49:08 +03:00
deltaValue += objCompleted * 0.5f;
}
}
return true;
}
private async void ModifyReputationOnPlayerBanned(UtkaBannedEvent ev)
{
NetUserId uid;
float value;
if (ev.Bantype == "server")
{
value = ev.Duration switch
{
> 10080 => -10f,
> 4320 => -7f,
> 1440 => -5f,
0 => -25f,
_ => -3f
};
}
else
value = -2f;
if (_playerManager.TryGetPlayerDataByUsername(ev.Ckey!, out var data))
uid = data.UserId;
else
{
var located = await _locator.LookupIdByNameAsync(ev.Ckey!);
if (located == null)
return;
uid = located.UserId;
}
_repManager.ModifyPlayerReputation(uid, value);
}
}