Advertisement
AnzusWarGames

SCR_NotificationSenderComponent.c

Feb 21st, 2024
855
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 24.64 KB | None | 0 0
  1. [ComponentEditorProps(category: "GameScripted/GameMode/Components", description: "Base for gamemode scripted component.")]
  2. class SCR_NotificationSenderComponentClass: SCR_BaseGameModeComponentClass
  3. {
  4. };
  5.  
  6.  
  7. class SCR_NotificationSenderComponent : SCR_BaseGameModeComponent
  8. {      
  9.     [Attribute("1", desc: "Show player left notification if player left.")]
  10.     protected bool m_bShowPlayerLeftNotification;
  11.    
  12.     [Attribute("10", desc: "Is killfeed enabled and what info will be displayed (Full killfeed is always displayed in open unlimited Editor)", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EKillFeedType))]
  13.     protected EKillFeedType m_iKillFeedType;
  14.    
  15.     [Attribute("40", desc: "If killfeed is enabled, what is the relationship between the player that died and the local player. (Full killfeed is always displayed in open unlimited Editor)", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EKillFeedReceiveType))]
  16.     protected EKillFeedReceiveType m_iReceiveKillFeedType;
  17.    
  18.     [Attribute("0", desc: "Array of Killfeed names")]
  19.     protected ref array<ref SCR_NotificationKillfeedTypeName> m_aKillfeedTypeNames;
  20.    
  21.     [Attribute("0", desc: "Array of Killfeed receive names")]
  22.     protected ref array<ref SCR_NotificationKillfeedreceiveTypeName> m_aKillfeedReceiveTypeNames;
  23.    
  24.     [Attribute("{D3BFEE28E7D5B6A1}Configs/ServerBrowser/KickDialogs.conf", desc: "If disconnect reason has a preset set to it then it will send a kick/ban notification", params: "conf")]
  25.     protected ref SCR_ConfigurableDialogUiPresets m_PlayerKickReasonsConfig;
  26.    
  27.     protected Faction m_FactionOnSpawn;
  28.    
  29.     protected SCR_FactionManager m_FactionManager;
  30.    
  31.     //States
  32.     protected bool m_bListeningToWeatherChanged;
  33.    
  34.     override void OnControllableDestroyed(IEntity entity, IEntity killerEntity, notnull Instigator killer)
  35.     {
  36.         //~ hot fix for On Controllable Destroyed issues \/
  37.         if (Replication.IsClient())
  38.             return;
  39.        
  40.         if (!entity)
  41.             return;
  42.        
  43.         RplComponent entityRpl = RplComponent.Cast(entity.FindComponent(RplComponent));
  44.         RplComponent instigatorRpl;
  45.        
  46.         if (killerEntity)
  47.             instigatorRpl = RplComponent.Cast(killerEntity.FindComponent(RplComponent));
  48.        
  49.         RplId entityRplId = RplId.Invalid();
  50.         RplId instigatorRplId = RplId.Invalid();
  51.        
  52.         if (entityRpl)
  53.             entityRplId = entityRpl.Id();
  54.        
  55.         if (instigatorRpl)
  56.             instigatorRplId = instigatorRpl.Id();
  57.        
  58.         OnControllableDestroyedBroadCast(entityRplId, instigatorRplId);
  59.         Rpc(OnControllableDestroyedBroadCast, entityRplId,instigatorRplId);
  60.        
  61.         //~ hot fix for On Controllable Destroyed issues /\
  62.     }
  63.    
  64.    
  65.     //~ Todo: This is a hot a hotfix for On Controllable Destroyed issues \/
  66.     [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
  67.     protected void OnControllableDestroyedBroadCast(RplId entityRplId, RplId instigatorRplId)
  68.     {
  69.         IEntity entity;
  70.         IEntity instigator;
  71.        
  72.         RplComponent entityRpl = RplComponent.Cast(Replication.FindItem(entityRplId));
  73.         RplComponent instigatorRpl = RplComponent.Cast(Replication.FindItem(instigatorRplId));
  74.        
  75.         if (entityRpl)
  76.             entity = entityRpl.GetEntity();
  77.        
  78.         if (instigatorRpl)
  79.             instigator = instigatorRpl.GetEntity();
  80.        
  81.         OnControllableDestroyedHotfix(entity, instigator);
  82.     }
  83.     //~ hot fix for On Controllable Destroyed  issues /\
  84.    
  85.     //~ Todo: hot fix for On Controllable Destroyed  issues - Move logic to OnControllableDestroyed if fixed
  86.     protected void OnControllableDestroyedHotfix(IEntity entity, IEntity instigator)
  87.     {      
  88.         //~ No entity destroyed
  89.         if (!entity)
  90.             return;
  91.        
  92.         bool isUnlimitedEditorOpened = false;
  93.        
  94.         //~ Check if player has unlimited editor and if the editor is open
  95.         SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
  96.         if (editorManager)
  97.             isUnlimitedEditorOpened = !editorManager.IsLimited() && editorManager.IsOpened();
  98.        
  99.         //~ Killfeed is disabled and unlimited editor is not open
  100.         if (!isUnlimitedEditorOpened && m_iKillFeedType == EKillFeedType.DISABLED)
  101.             return;
  102.        
  103.         int playerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(entity);
  104.         if (playerId <= 0)
  105.             return;
  106.        
  107.         //~ Check if killed player message can be seen if Limited editor (or editor not open)
  108.         if (!isUnlimitedEditorOpened && m_iReceiveKillFeedType != EKillFeedReceiveType.ALL)
  109.         {
  110.             //~ No faction manager so don't show killfeed?
  111.             if (!m_FactionManager)
  112.                 return;
  113.            
  114.             Faction localPlayerFaction = m_FactionManager.GetLocalPlayerFaction();
  115.  
  116.             //~ No local faction so don't show killfeed
  117.             if (!localPlayerFaction)
  118.                 return;
  119.            
  120.             int localPlayerID = SCR_PlayerController.GetLocalPlayerId();
  121.             Faction killedPlayerFaction = m_FactionManager.GetPlayerFaction(playerId);
  122.            
  123.             switch (m_iReceiveKillFeedType)
  124.             {
  125.                 //~ check if in group
  126.                 case EKillFeedReceiveType.GROUP_ONLY :
  127.                 {
  128.                     //~ Check if local player is not the same as killed otherwise they are always in the same group
  129.                     if (localPlayerID != playerId)
  130.                     {
  131.                         //~ Factions not friendly so don't show killfeed
  132.                         if (!localPlayerFaction.IsFactionFriendly(killedPlayerFaction))
  133.                             return;
  134.                        
  135.                         //~ No group manager so don't send
  136.                         SCR_GroupsManagerComponent groupManager = SCR_GroupsManagerComponent.GetInstance();
  137.                         if (!groupManager)
  138.                             return;
  139.                        
  140.                         SCR_AIGroup localPlayerGroup = groupManager.GetPlayerGroup(localPlayerID);
  141.                        
  142.                         //~ If not in group or not in the same group do not send
  143.                         if (!localPlayerGroup || !localPlayerGroup.IsPlayerInGroup(playerId))
  144.                             return;
  145.                     }
  146.                    
  147.                     break;
  148.                 }
  149.                 //~ Check if the same faction
  150.                 case EKillFeedReceiveType.SAME_FACTION_ONLY :
  151.                 {
  152.                     //~ Check if local player is not the same as killed otherwise they are always the same faction
  153.                     if (localPlayerID != playerId)
  154.                     {
  155.                         //~ If no local faction or if not the same faction do not show killfeed
  156.                         if (!localPlayerFaction || localPlayerFaction != killedPlayerFaction)
  157.                             return;
  158.                        
  159.                         //~ If Faction is hostile towards itself still do not show killfeed (DM)
  160.                         if (!localPlayerFaction.IsFactionFriendly(localPlayerFaction))
  161.                             return;
  162.                     }
  163.                    
  164.                     break;
  165.                 }
  166.                 //~ Check if allies
  167.                 case EKillFeedReceiveType.ALLIES_ONLY :
  168.                 {
  169.                     //~ Check if local player is not the same as killed otherwise they are always allied
  170.                     if (localPlayerID != playerId)
  171.                     {
  172.                         //~ Factions not friendly so don't show killfeed
  173.                         if (!localPlayerFaction || !localPlayerFaction.IsFactionFriendly(killedPlayerFaction))
  174.                             return;
  175.                     }
  176.                    
  177.                     break;
  178.                 }
  179.                 //~ Check if enemies
  180.                 case EKillFeedReceiveType.ENEMIES_ONLY :
  181.                 {
  182.                     //~ If local player killed it is never an enemy
  183.                     if (localPlayerID == playerId)
  184.                         return;
  185.                    
  186.                     //~ Factions friendly so don't show killfeed
  187.                     if (localPlayerFaction.IsFactionFriendly(killedPlayerFaction))
  188.                         return;
  189.                    
  190.                     break;
  191.                 }
  192.             }
  193.         }
  194.        
  195.         //~ Never show killer so simply show player died if limited editor
  196.         if (!isUnlimitedEditorOpened && m_iKillFeedType == EKillFeedType.UNKNOWN_KILLER)
  197.         {
  198.             SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_DIED, playerId);
  199.             return;
  200.         }
  201.        
  202.         int killerId;
  203.         if (entity == instigator)
  204.             killerId = playerId;
  205.         else
  206.             killerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(instigator);
  207.  
  208.         SCR_EditableCharacterComponent killerEditableCharacterComponent;
  209.         //~ If there is a killer and the killer is not the player itself
  210.         if (instigator && killerId <= 0)
  211.         {
  212.             killerEditableCharacterComponent = SCR_EditableCharacterComponent.Cast(instigator.FindComponent(SCR_EditableCharacterComponent));
  213.        
  214.             //~ Killer was not character so get killer in vehicle
  215.             if (!killerEditableCharacterComponent)
  216.                 killerEditableCharacterComponent = GetKillerFromVehicle(instigator, instigator.IsInherited(Vehicle));
  217.            
  218.             if (killerEditableCharacterComponent)
  219.                 killerId = SCR_PossessingManagerComponent.GetPlayerIdFromControlledEntity(killerEditableCharacterComponent.GetOwner());
  220.         }
  221.  
  222.         bool playerIsPossessed = false;
  223.         bool killerIsPossessed = false;
  224.        
  225.         //~ Check if player or killer where possessed
  226.         SCR_PossessingManagerComponent possesionManager = SCR_PossessingManagerComponent.GetInstance();
  227.         if (possesionManager)
  228.         {
  229.             playerIsPossessed = possesionManager.IsPossessing(playerId);
  230.            
  231.             if (killerId > 0)
  232.                 killerIsPossessed = possesionManager.IsPossessing(killerId);
  233.         }
  234.            
  235.         //Death notification   
  236.         //Suicide  
  237.         if (playerId == killerId || !instigator)
  238.         {          
  239.             //Player Suicide
  240.             if (!playerIsPossessed)
  241.                 SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_DIED, playerId);
  242.             //Possessed Suicide
  243.             else
  244.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.POSSESSED_AI_DIED, playerId);
  245.         }
  246.         //If killed by other player
  247.         else if (killerId > 0)
  248.         {
  249.             //Player killed player
  250.             if (!playerIsPossessed && !killerIsPossessed)
  251.             {
  252.                 SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_KILLED_PLAYER, killerId, playerId);
  253.             }
  254.             //Possesed player killed by other player (Show player killed by NPC and for GM: possesed GM killed player)
  255.             else if (!playerIsPossessed && killerIsPossessed)
  256.             {      
  257.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.POSSESSED_AI_KILLED_PLAYER, killerId, playerId);
  258.                 SCR_NotificationsComponent.SendLocalLimitedEditor(ENotification.AI_KILLED_PLAYER, killerId, playerId);
  259.             }
  260.             //Player killed possessed player (Show to GM only)
  261.             else if (playerIsPossessed && !killerIsPossessed)
  262.             {
  263.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.PLAYER_KILLED_POSSESSED_AI, killerId, playerId);
  264.             }
  265.             //Possessed AI Killed Possessed AI (GM Only)
  266.             else
  267.             {
  268.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.POSSESSED_AI_KILLED_POSSESSED_AI, killerId, playerId);
  269.             }
  270.         }
  271.         //Killed by NPC
  272.         else if (killerEditableCharacterComponent)
  273.         {
  274.             int killerRplId = Replication.FindId(killerEditableCharacterComponent);
  275.            
  276.             if (!playerIsPossessed)
  277.                 SCR_NotificationsComponent.SendLocal(ENotification.AI_KILLED_PLAYER, killerRplId, playerId);
  278.             else
  279.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.AI_KILLED_POSSESSED_AI, killerRplId, playerId);
  280.         }
  281.         //Unknown killer
  282.         else
  283.         {
  284.             if (!playerIsPossessed)
  285.                 SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_DIED, playerId);
  286.             else
  287.                 SCR_NotificationsComponent.SendLocalUnlimitedEditor(ENotification.POSSESSED_AI_DIED, playerId);
  288.         }
  289.     }
  290.    
  291.     //------------------------------------------------------------------------------------------------
  292.     protected SCR_EditableCharacterComponent GetKillerFromVehicle(IEntity veh, bool pilot)
  293.     {
  294.         BaseCompartmentManagerComponent compartmentManager = BaseCompartmentManagerComponent.Cast(veh.FindComponent(BaseCompartmentManagerComponent));
  295.            
  296.         if (!compartmentManager)
  297.             return null;
  298.        
  299.         array<BaseCompartmentSlot> compartments = new array <BaseCompartmentSlot>();
  300.        
  301.         for (int i = 0, compart = compartmentManager.GetCompartments(compartments); i < compart; i++)
  302.         {
  303.             BaseCompartmentSlot slot = compartments[i];
  304.            
  305.             if (pilot && slot.Type() == PilotCompartmentSlot)
  306.             {
  307.                 if (slot.GetOccupant())
  308.                     return SCR_EditableCharacterComponent.Cast(slot.GetOccupant().FindComponent(SCR_EditableCharacterComponent));
  309.             }
  310.             else if (!pilot && slot.Type() == TurretCompartmentSlot)
  311.             {
  312.                 if (slot.GetOccupant())
  313.                     return SCR_EditableCharacterComponent.Cast(slot.GetOccupant().FindComponent(SCR_EditableCharacterComponent));
  314.             }
  315.         }
  316.        
  317.         return null;
  318.     }
  319.    
  320.     //------------------------------------------------------------------------------------------------
  321.     protected void OnEditorLimitedChanged(bool isLimited)
  322.     {
  323.         SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
  324.         if (!editorManager)
  325.             return;
  326.        
  327.         int playerID = editorManager.GetPlayerID();
  328.        
  329.         //Became Player
  330.         if (isLimited)
  331.             SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PLAYER_NO_LONGER_GM, playerID);
  332.         //Became GM
  333.         else
  334.             SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_PLAYER_BECAME_GM, playerID);
  335.     }
  336.    
  337.     override void OnPlayerRegistered(int playerId)
  338.     {
  339.         //Join notification
  340.         SCR_NotificationsComponent.SendLocal(ENotification.PLAYER_JOINED, playerId);
  341.     }
  342.    
  343.     //------------------------------------------------------------------------------------------------
  344.     override void OnPlayerDisconnected(int playerId, KickCauseCode cause, int timeout)
  345.     {
  346.         //~ Should never be called for clients but just in case
  347.         if (!GetGameMode().IsMaster())
  348.             return;
  349.        
  350.         SCR_EditorManagerEntity editorManager;
  351.        
  352.         //~ Get editorManager if has any
  353.         SCR_EditorManagerCore core = SCR_EditorManagerCore.Cast(SCR_EditorManagerCore.GetInstance(SCR_EditorManagerCore));
  354.         if (core)
  355.         {
  356.              editorManager = core.GetEditorManager(playerId);
  357.         }
  358.  
  359.         bool hasUnlimitedEditor = editorManager && !editorManager.IsLimited();
  360.        
  361.         //~ Is GM, Always show GM left notification even if kicked/banned to notify players that the GM has left
  362.         if (hasUnlimitedEditor)
  363.             SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_GM_LEFT, playerId);     
  364.        
  365.         bool isKickedOrBanned = false;
  366.        
  367.         //~ Check if disconnect cause has message attached to it. If true: show kick/ban reason. If false: only show gm/player left
  368.         if (m_PlayerKickReasonsConfig)
  369.         {
  370.             string groupId, reasonId;
  371.             KickCauseGroup2 groupInt;
  372.             int reasonInt;
  373.            
  374.             //~ Get disconnect message preset
  375.             GetGame().GetFullKickReason(cause, groupInt, reasonInt, groupId, reasonId);
  376.             SCR_ConfigurableDialogUiPreset preset = m_PlayerKickReasonsConfig.FindPreset(groupId + "_" + reasonId);
  377.            
  378.             //~ If has kick/Ban message it will send out a notification
  379.             isKickedOrBanned = preset != null && !preset.m_sMessage.IsEmpty();
  380.         }
  381.         //~ No config
  382.         else
  383.         {
  384.             Print("'SCR_NotificationSenderComponent' has no 'm_PlayerKickReasonsConfig'! Make sure it is added else it will never know if a player was kicked!", LogLevel.ERROR);
  385.         }
  386.        
  387.         //~ Is kicked/banned. Will also send ban notification if for some reason there is a timeout attached even if there is no specific kick message
  388.         if (isKickedOrBanned || timeout != 0)
  389.         {
  390.             SCR_DataCollectorComponent dataCollector = GetGame().GetDataCollector();
  391.             if (dataCollector)
  392.             {
  393.                 SCR_PlayerData playerData = dataCollector.GetPlayerData(playerId);
  394.                
  395.                 if (playerData)
  396.                 {
  397.                     float banTimeOut = playerData.GetTimeOut();
  398.                
  399.                     //~ If playerData has ban timeout which is greater then timeout use that instead. This is because Heavy ban kicks the player and bans it via backend. So the timeout is set somewhere else
  400.                     if (banTimeOut > 0 && banTimeOut > timeout)
  401.                         timeout = banTimeOut;
  402.                 }
  403.             }
  404.            
  405.             //~ Player kicked
  406.             if (timeout == 0)
  407.                 SCR_NotificationsComponent.SendToEveryone(ENotification.PLAYER_KICKED, playerId, cause, timeout);  
  408.             //~ Player perminent ban
  409.             else if (timeout < 0)
  410.                 SCR_NotificationsComponent.SendToEveryone(ENotification.PLAYER_BANNED_NO_DURATION, playerId, cause, timeout);
  411.             //~ Player temp ban
  412.             else
  413.                 SCR_NotificationsComponent.SendToEveryone(ENotification.PLAYER_BANNED, playerId, cause, timeout);
  414.         }      
  415.         //~ Is Not kicked/banned, is player and should send on leave notification.
  416.         else if (m_bShowPlayerLeftNotification && !hasUnlimitedEditor)
  417.         {
  418.             SCR_NotificationsComponent.SendToEveryone(ENotification.PLAYER_LEFT, playerId);
  419.         }
  420.     }
  421.    
  422.     //------------------------------------------------------------------------------------------------
  423.     override void OnPlayerSpawned(int playerId, IEntity controlledEntity)
  424.     {
  425.         //Check if faction changed and send notification if diffrent
  426.         if (m_FactionManager)
  427.         {
  428.             //Get factions using ID
  429.             Faction playerFaction = m_FactionManager.GetPlayerFaction(playerId);
  430.        
  431.             //Faction is diffrent
  432.             if (m_FactionOnSpawn != playerFaction)
  433.             {
  434.                 //Send player joined faction notification
  435.                 SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(ENotification.PLAYER_JOINED_FACTION, playerId);
  436.                 m_FactionOnSpawn = playerFaction;
  437.             }
  438.         }
  439.     }  
  440.    
  441.    
  442.  
  443.    
  444.     //======================================== WEATHER SET TO LOOPING ========================================\\
  445.     /*!
  446.     Called when weather is set to looping or when weather itself is changed (which auto sets it on looping)
  447.     This is to make sure the notification, that weather is set, is only called once
  448.     */
  449.     void OnWeatherChangedNotification(int playerID)
  450.     {
  451.         if (Replication.IsClient())
  452.             return;
  453.        
  454.         if (!m_bListeningToWeatherChanged)
  455.         {
  456.             m_bListeningToWeatherChanged = true;
  457.             GetGame().GetCallqueue().CallLater(OnWeatherChangedNotificationDelay, 0 , false, playerID);
  458.         }
  459.     }
  460.    
  461.     protected void OnWeatherChangedNotificationDelay(int playerID)
  462.     {
  463.         m_bListeningToWeatherChanged = false;
  464.        
  465.         ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
  466.         if (!world)
  467.             return;
  468.        
  469.         TimeAndWeatherManagerEntity weatherManager = world.GetTimeAndWeatherManager();
  470.         if (!weatherManager)
  471.             return;
  472.        
  473.         WeatherState currentState = weatherManager.GetCurrentWeatherState();
  474.        
  475.         if (!currentState)
  476.             return;
  477.        
  478.         SCR_NotificationsComponent.SendToUnlimitedEditorPlayers(ENotification.EDITOR_ATTRIBUTES_WEATHER_CHANGED, playerID, currentState.GetStateID());
  479.     }
  480.    
  481.    
  482.     //======================================== KILLFEED ========================================\\ 
  483.     /*!
  484.     Get an list of all killfeed types and the localized name
  485.     \param killFeedTypeNames list of killfeed type and name
  486.     \return the amount of names in the list
  487.     */
  488.     int GetKillFeedTypeNames(notnull array<ref SCR_NotificationKillfeedTypeName> killFeedTypeNames)
  489.     {
  490.         killFeedTypeNames.Clear();
  491.         foreach (SCR_NotificationKillfeedTypeName killfeedTypeName: m_aKillfeedTypeNames)
  492.             killFeedTypeNames.Insert(killfeedTypeName);
  493.        
  494.         return killFeedTypeNames.Count();
  495.     }
  496.    
  497.     /*!
  498.     Get an list of all killfeed receive types and the localized name
  499.     \param killFeedReceiveTypeNames list of killfeed receive type and name
  500.     \return the amount of names in the list
  501.     */
  502.     int GetKillFeedReceiveTypeNames(notnull array<ref SCR_NotificationKillfeedreceiveTypeName> killFeedReceiveTypeNames)
  503.     {
  504.         killFeedReceiveTypeNames.Clear();
  505.         foreach (SCR_NotificationKillfeedreceiveTypeName killfeedReceiveTypeName: m_aKillfeedReceiveTypeNames)
  506.             killFeedReceiveTypeNames.Insert(killfeedReceiveTypeName);
  507.        
  508.         return killFeedReceiveTypeNames.Count();
  509.     }
  510.    
  511.     /*!
  512.     Get the current killfeed type
  513.     \return the type of killfeed that is displayed
  514.     */
  515.     EKillFeedType GetKillFeedType()
  516.     {
  517.         return m_iKillFeedType;
  518.     }
  519.    
  520.     /*!
  521.     Server set killfeed type
  522.     \param killFeedType new killfeed type to set
  523.     \param playerNotificationId add player ID of player that changed the type to display a notification
  524.     */
  525.     void SetKillFeedType(EKillFeedType killFeedType, int playerNotificationId = -1)
  526.     {
  527.         if (!GetGameMode().IsMaster() || killFeedType == m_iKillFeedType)
  528.             return;
  529.        
  530.         SetKillFeedTypeBroadcast(killFeedType);
  531.         Rpc(SetKillFeedTypeBroadcast, killFeedType);
  532.        
  533.         if (playerNotificationId > 0)
  534.             SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_CHANGED_KILLFEED_TYPE, playerNotificationId, killFeedType, false);
  535.     }
  536.    
  537.     /*!
  538.     Get the current killfeed receive type
  539.     \return the type from whom the player receives killfeed
  540.     */
  541.     EKillFeedReceiveType GetReceiveKillFeedType()
  542.     {
  543.         return m_iReceiveKillFeedType;
  544.     }
  545.    
  546.     /*!
  547.     Server set killfeed receive type
  548.     \param receiveKillFeedType new killfeed reveive type to set
  549.     \param playerNotificationId add player ID of player that changed the type to display a notification
  550.     */
  551.     void SetReceiveKillFeedType(EKillFeedReceiveType receiveKillFeedType, int playerNotificationId = -1)
  552.     {
  553.         if (!GetGameMode().IsMaster() || receiveKillFeedType == m_iReceiveKillFeedType)
  554.             return;
  555.        
  556.         SetReceiveKillFeedTypeBroadcast(receiveKillFeedType);
  557.         Rpc(SetReceiveKillFeedTypeBroadcast, receiveKillFeedType);
  558.        
  559.         if (playerNotificationId > 0)
  560.             SCR_NotificationsComponent.SendToEveryone(ENotification.EDITOR_CHANGED_KILLFEED_RECEIVE_TYPE, playerNotificationId, receiveKillFeedType, true);
  561.     }
  562.    
  563.     [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
  564.     protected void SetKillFeedTypeBroadcast(EKillFeedType killFeedType)
  565.     {
  566.         m_iKillFeedType = killFeedType;
  567.     }
  568.    
  569.     [RplRpc(RplChannel.Reliable, RplRcver.Broadcast)]
  570.     protected void SetReceiveKillFeedTypeBroadcast(EKillFeedReceiveType receiveKillFeedType)
  571.     {
  572.         m_iReceiveKillFeedType = receiveKillFeedType;
  573.     }
  574.    
  575.     //======================================== RPL ========================================\\
  576.     override bool RplSave(ScriptBitWriter writer)
  577.     {  
  578.         writer.WriteInt(m_iKillFeedType);
  579.         writer.WriteInt(m_iReceiveKillFeedType);
  580.        
  581.         return true;
  582.     }
  583.      
  584.     override bool RplLoad(ScriptBitReader reader)
  585.     {
  586.         EKillFeedType killFeedType;
  587.         EKillFeedReceiveType receiveKillFeedType;
  588.        
  589.         reader.ReadInt(killFeedType);
  590.         reader.ReadInt(receiveKillFeedType);
  591.  
  592.         SetKillFeedTypeBroadcast(killFeedType);
  593.         SetReceiveKillFeedTypeBroadcast(receiveKillFeedType);
  594.        
  595.         return true;
  596.     }
  597.    
  598.     //======================================== INIT ========================================\\
  599.     override void EOnInit(IEntity owner)
  600.     {
  601.         SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
  602.         if (editorManager)
  603.             editorManager.GetOnLimitedChange().Insert(OnEditorLimitedChanged);
  604.        
  605.         m_FactionManager = SCR_FactionManager.Cast(GetGame().GetFactionManager());
  606.        
  607.         super.EOnInit(owner);
  608.     }
  609.    
  610.     override void OnPostInit(IEntity owner)
  611.     {
  612.         SetEventMask(owner, EntityEvent.INIT);
  613.        
  614.         super.OnPostInit(owner);
  615.     }
  616.    
  617.    
  618.     //======================================== DELETE ========================================\\
  619.     protected override void OnDelete(IEntity owner)
  620.     {
  621.         SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
  622.         if (editorManager)
  623.             editorManager.GetOnLimitedChange().Remove(OnEditorLimitedChanged);
  624.        
  625.         super.OnDelete(owner);
  626.     }
  627. };
  628.  
  629. /*!
  630. What kind of killfeed will be displayed in the gamemode.
  631. Noted that players with unlimited Editor will always see full killfeed if Editor is open
  632. */
  633. enum EKillFeedType
  634. {
  635.     //~ If changes are made in this enum make sure to change m_aKillfeedTypeNames
  636.     DISABLED = 0, ///< Killfeed is disabled
  637.     UNKNOWN_KILLER = 10, ///< Will see killfeed messages but will never know who the killer is
  638.     FULL = 20, ///< Will see every player (except possessed pawns) killed messages. Including killer
  639. };
  640.  
  641.  
  642. /*!
  643. From who will players receive kill notifications
  644. Noted that players with unlimited Editor will always see full killfeed if Editor is open
  645. */
  646. enum EKillFeedReceiveType
  647. {
  648.     //~ If changes are made in this enum make sure to change m_aKillfeedReceiveTypeNames
  649.     ALL = 0, ///< Will see killfeed from allies and enemies alike
  650.     ENEMIES_ONLY = 10, ///< Will see killfeed from enemies only
  651.     ALLIES_ONLY = 20, ///< Will see killfeed from allies only
  652.     SAME_FACTION_ONLY = 30, ///< Will see killfeed from same faction only
  653.     GROUP_ONLY = 40, ///< Will see killfeed from group members only
  654. };
  655.  
  656. /*!
  657. Class to get Killfeed type name
  658. */
  659. [BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EKillFeedType, "m_iKillfeedType")]
  660. class SCR_NotificationKillfeedTypeName
  661. {
  662.     [Attribute(desc: "Killfeed type", uiwidget : UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EKillFeedType))]
  663.     protected EKillFeedType m_iKillfeedType;
  664.    
  665.     [Attribute(desc: "Name displayed in Notification", uiwidget: UIWidgets.LocaleEditBox)]
  666.     protected LocalizedString m_sKillfeedTypeName;
  667.    
  668.     /*!
  669.     Get the killfeed type
  670.     \return the killfeed type enum
  671.     */
  672.     EKillFeedType GetKillfeedType()
  673.     {
  674.         return m_iKillfeedType;
  675.     }
  676.    
  677.     /*!
  678.     Get the killfeed Type name
  679.     \return the killfeed type name as string
  680.     */
  681.     string GetName()
  682.     {
  683.         return m_sKillfeedTypeName;
  684.     }
  685. };
  686.  
  687. /*!
  688. Class to get Killfeed receive type name
  689. */
  690. [BaseContainerProps(), SCR_BaseContainerCustomTitleEnum(EKillFeedReceiveType, "m_iKillfeedreceiveType")]
  691. class SCR_NotificationKillfeedreceiveTypeName
  692. {
  693.     [Attribute(desc: "Killfeed receive type", uiwidget : UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EKillFeedReceiveType))]
  694.     protected EKillFeedReceiveType m_iKillfeedreceiveType;
  695.    
  696.     [Attribute(desc: "Name displayed in Notification", uiwidget: UIWidgets.LocaleEditBox)]
  697.     protected LocalizedString m_sKillfeedReceiveTypeName;
  698.    
  699.     /*!
  700.     Get the killfeed receive Type
  701.     \return the killfeed receive type enum
  702.     */
  703.     EKillFeedType GetKillfeedReceiveType()
  704.     {
  705.         return m_iKillfeedreceiveType;
  706.     }
  707.    
  708.     /*!
  709.     Get the killfeed receive type name
  710.     \return the killfeed receive type name as string
  711.     */
  712.     string GetName()
  713.     {
  714.         return m_sKillfeedReceiveTypeName;
  715.     }
  716. };
  717.  
  718.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement