commit c8613dc51941c482f72cf2ec7f1afd3df5821326 Author: Anton Tarasenko Date: Mon Jun 14 03:49:19 2021 +0700 first commit diff --git a/KFZedsReportMut.uc b/KFZedsReportMut.uc new file mode 100644 index 0000000..b736ab8 --- /dev/null +++ b/KFZedsReportMut.uc @@ -0,0 +1,101 @@ +/** + * Mutator that replicates and diplayes on clients information about how many + * zeds are spawned and with what recent spawn rate. + */ +class KFZedsReportMut extends Mutator; + +// How often should we update our information? +var config float updateInterval; +// Over what interval do we count average spawn rate? +var config float smoothingInterval; + +var bool interactionAdded; + +var array zedSpawnTimes; + +var int repCurrentTotalZeds, repGameInfo_MaxMonsters; +var float repCurrentSpawnRate; + +replication +{ + reliable if(Role == ROLE_Authority) + repCurrentTotalZeds, repGameInfo_MaxMonsters, repCurrentSpawnRate; +} + +function PostBeginPlay() +{ + if (updateInterval <= 0) { + updateInterval = 0.25; + } + if (smoothingInterval <= 0) { + smoothingInterval = 10.0; + } + SetTimer(updateInterval, true); +} + +function bool CheckReplacement(Actor other, out byte bSuperRelevant) +{ + if (Monster(other) != none) { + zedSpawnTimes[zedSpawnTimes.length] = level.timeSeconds; + } + return true; +} + +simulated function Tick(float delta) +{ + local ReportInteraction myInteraction; + local Player localPlayer; + if (role == Role_AUTHORITY) return; + if (interactionAdded) return; + localPlayer = level.GetLocalPlayerController().player; + if (localPlayer == none) return; + + myInteraction = ReportInteraction(localPlayer.interactionMaster + .AddInteraction("KFZedsReport.ReportInteraction", localPlayer)); + if (myInteraction != none) + { + myInteraction.reportMutator = self; + interactionAdded = true; + } +} + +function Timer() +{ + local int i; + local float cutOffTime; + local Monster nextMonster; + cutOffTime = level.timeSeconds - smoothingInterval; + while (i < zedSpawnTimes.length) + { + if (zedSpawnTimes[i] < cutOffTime) { + zedSpawnTimes.Remove(i, 1); + } + else { + i += 1; + } + } + // Update replicated values + repGameInfo_MaxMonsters = KFGameType(level.game).maxMonsters; + repCurrentSpawnRate = zedSpawnTimes.length / smoothingInterval; + repCurrentTotalZeds = 0; + foreach level.DynamicActors(class'Monster', nextMonster) + { + if (nextMonster.health > 0) { + repCurrentTotalZeds += 1; + } + } +} + +defaultproperties +{ + // Mutator description + GroupName = "Test mutatros" + FriendlyName = "Zed report mutator" + Description = "Mutator that provides clients with information about how many zeds (and their spawn rate) are present on the map." + bAddToServerPackages = true + bAlwaysRelevant = true + RemoteRole = ROLE_SimulatedProxy + // Default config values + updateInterval = 0.25 + smoothingInterval = 10.0 +} \ No newline at end of file diff --git a/ReportInteraction.uc b/ReportInteraction.uc new file mode 100644 index 0000000..02bfeca --- /dev/null +++ b/ReportInteraction.uc @@ -0,0 +1,38 @@ +class ReportInteraction extends Interaction; + +var KFZedsReportMut reportMutator; + +event NotifyLevelChange() +{ + if (master != none) { + master.RemoveInteraction(self); + } +} + +function PostRender(Canvas canvas) +{ + local float textWidth, textHeight; + local string maxZedsReport, spawnRateReport; + local string tagWhite, tagGreen; + if (canvas == none) return; + if (reportMutator == none) return; + + tagWhite = Chr(27) $ Chr(250) $ Chr(250) $ Chr(250); + tagGreen = Chr(27) $ Chr(1) $ Chr(200) $ Chr(1); + maxZedsReport = tagWhite $ "Current total zeds" + @ tagGreen $ reportMutator.repCurrentTotalZeds + @ tagWhite $ "out of server's total" + @ tagGreen $ reportMutator.repGameInfo_MaxMonsters; + spawnRateReport = tagWhite $ "Current spawn rate is" + @ tagGreen $ reportMutator.repCurrentSpawnRate; + canvas.TextSize(maxZedsReport, textWidth, textHeight); + canvas.SetPos(0, 0); + canvas.DrawText(maxZedsReport); + canvas.SetPos(0, textHeight + 10); + canvas.DrawText(spawnRateReport); +} + +defaultproperties +{ + bVisible = true +} \ No newline at end of file