@quenty/deathreport 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [1.4.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/deathreport@1.3.0...@quenty/deathreport@1.4.0) (2022-07-31)
7
+
8
+
9
+ ### Features
10
+
11
+ * Add DeathReport support for weapon data ([010d5bd](https://github.com/Quenty/NevermoreEngine/commit/010d5bd760b456f52d1c50a5f6302e512ed57677))
12
+
13
+
14
+
15
+
16
+
6
17
  # [1.3.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/deathreport@1.2.0...@quenty/deathreport@1.3.0) (2022-07-02)
7
18
 
8
19
  **Note:** Version bump only for package @quenty/deathreport
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@quenty/deathreport",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "Death report service which will track the deaths of players",
5
5
  "keywords": [
6
6
  "Roblox",
@@ -29,19 +29,19 @@
29
29
  "access": "public"
30
30
  },
31
31
  "dependencies": {
32
- "@quenty/baseobject": "^5.0.0",
33
- "@quenty/binder": "^6.2.0",
34
- "@quenty/characterutils": "^5.1.0",
32
+ "@quenty/baseobject": "^5.1.0",
33
+ "@quenty/binder": "^6.3.0",
34
+ "@quenty/characterutils": "^5.2.0",
35
35
  "@quenty/humanoidkillerutils": "^2.2.0",
36
36
  "@quenty/loader": "^5.0.0",
37
- "@quenty/maid": "^2.3.0",
38
- "@quenty/playerhumanoidbinder": "^6.2.0",
39
- "@quenty/remoting": "^5.1.0",
40
- "@quenty/rx": "^5.1.0",
41
- "@quenty/rxbinderutils": "^6.2.0",
42
- "@quenty/servicebag": "^5.0.0",
37
+ "@quenty/maid": "^2.4.0",
38
+ "@quenty/playerhumanoidbinder": "^6.3.0",
39
+ "@quenty/remoting": "^5.2.0",
40
+ "@quenty/rx": "^5.2.0",
41
+ "@quenty/rxbinderutils": "^6.3.0",
42
+ "@quenty/servicebag": "^5.1.0",
43
43
  "@quenty/signal": "^2.2.0",
44
44
  "@quenty/table": "^3.1.0"
45
45
  },
46
- "gitHead": "de33c83e7f897e2b0887c77aeb1fc7963756f234"
46
+ "gitHead": "e31b3a35aa475bb5699a24898a8639e107165b36"
47
47
  }
@@ -72,6 +72,26 @@ function DeathReportServiceClient:ObservePlayerDeathReports(player)
72
72
  return self._reportProcessor:ObservePlayerDeathReports(player)
73
73
  end
74
74
 
75
+ --[=[
76
+ Observes killer reports for the given humanoid
77
+
78
+ @param humanoid Humanoid
79
+ @return Observable<DeathReport>
80
+ ]=]
81
+ function DeathReportServiceClient:ObserveHumanoidKillerReports(humanoid)
82
+ return self._reportProcessor:ObserveHumanoidKillerReports(humanoid)
83
+ end
84
+
85
+ --[=[
86
+ Observes death reports for the given humanoid
87
+
88
+ @param humanoid Humanoid
89
+ @return Observable<DeathReport>
90
+ ]=]
91
+ function DeathReportServiceClient:ObserveHumanoidDeathReports(humanoid)
92
+ return self._reportProcessor:ObserveHumanoidDeathReports(humanoid)
93
+ end
94
+
75
95
  --[=[
76
96
  Gets the last recorded death reports
77
97
  @return { DeathReport }
@@ -39,6 +39,32 @@ function DeathReportService:Init(serviceBag)
39
39
 
40
40
  self._reportProcessor = DeathReportProcessor.new()
41
41
  self._maid:GiveTask(self._reportProcessor)
42
+
43
+ self._weaponDataRetrievers = {}
44
+ end
45
+
46
+ function DeathReportService:AddWeaponDataRetriever(getWeaponData)
47
+ table.insert(self._weaponDataRetrievers, getWeaponData)
48
+
49
+ return function()
50
+ local index = table.find(self._weaponDataRetrievers, getWeaponData)
51
+ if index then
52
+ table.remove(self._weaponDataRetrievers, index)
53
+ end
54
+ end
55
+ end
56
+
57
+ function DeathReportService:FindWeaponData(humanoid)
58
+ for _, item in pairs(self._weaponDataRetrievers) do
59
+ local result = item(humanoid)
60
+ if result then
61
+ assert(DeathReportUtils.isWeaponData(result), "Failed to return valid weaponData")
62
+
63
+ return result
64
+ end
65
+ end
66
+
67
+ return nil
42
68
  end
43
69
 
44
70
  --[=[
@@ -61,14 +87,35 @@ function DeathReportService:ObservePlayerDeathReports(player)
61
87
  return self._reportProcessor:ObservePlayerDeathReports(player)
62
88
  end
63
89
 
90
+ --[=[
91
+ Observes killer reports for the given humanoid
92
+
93
+ @param humanoid Humanoid
94
+ @return Observable<DeathReport>
95
+ ]=]
96
+ function DeathReportService:ObserveHumanoidKillerReports(humanoid)
97
+ return self._reportProcessor:ObserveHumanoidKillerReports(humanoid)
98
+ end
99
+
100
+ --[=[
101
+ Observes death reports for the given humanoid
102
+
103
+ @param humanoid Humanoid
104
+ @return Observable<DeathReport>
105
+ ]=]
106
+ function DeathReportService:ObserveHumanoidDeathReports(humanoid)
107
+ return self._reportProcessor:ObserveHumanoidDeathReports(humanoid)
108
+ end
109
+
64
110
  --[=[
65
111
  Reports the death of a humanoid. This is called automatically
66
112
  by [DeathTrackedHumanoid].
67
113
 
68
114
  @param humanoid Humanoid -- Humanoid that died
115
+ @param weaponData WeaponData? -- Weapon data to report
69
116
  ]=]
70
- function DeathReportService:ReportDeath(humanoid)
71
- local report = DeathReportUtils.fromDeceasedHumanoid(humanoid)
117
+ function DeathReportService:ReportDeath(humanoid, weaponData)
118
+ local report = DeathReportUtils.fromDeceasedHumanoid(humanoid, weaponData or self:FindWeaponData(humanoid))
72
119
 
73
120
  -- Notify services
74
121
  self.NewDeathReport:Fire(report)
@@ -21,6 +21,8 @@ function PlayerKillTrackerAssigner.new(serviceBag)
21
21
  self._serviceBag = assert(serviceBag, "No serviceBag")
22
22
  self._deathReportBindersServer = self._serviceBag:GetService(DeathReportBindersServer)
23
23
 
24
+ self._killTrackers = {}
25
+
24
26
  self._maid:GiveTask(Players.PlayerAdded:Connect(function(player)
25
27
  self:_handlePlayerAdded(player)
26
28
  end))
@@ -35,6 +37,24 @@ function PlayerKillTrackerAssigner.new(serviceBag)
35
37
  return self
36
38
  end
37
39
 
40
+ function PlayerKillTrackerAssigner:GetPlayerKills(player)
41
+ local tracker = self:GetPlayerKillTracker(player)
42
+ if tracker then
43
+ return tracker:GetKills()
44
+ else
45
+ return nil
46
+ end
47
+ end
48
+
49
+ function PlayerKillTrackerAssigner:GetPlayerKillTracker(player)
50
+ local trackerInstance = self._killTrackers[player]
51
+ if trackerInstance then
52
+ return self._deathReportBindersServer.PlayerKillTracker:Get(trackerInstance)
53
+ else
54
+ return nil
55
+ end
56
+ end
57
+
38
58
  function PlayerKillTrackerAssigner:_handlePlayerRemoving(player)
39
59
  self._maid[player] = nil
40
60
  end
@@ -45,6 +65,12 @@ function PlayerKillTrackerAssigner:_handlePlayerAdded(player)
45
65
  local killTracker = PlayerKillTrackerUtils.create(self._deathReportBindersServer.PlayerKillTracker, player)
46
66
  maid:GiveTask(killTracker)
47
67
 
68
+ self._killTrackers[player] = killTracker
69
+
70
+ maid:GiveTask(function()
71
+ self._killTrackers[player] = nil
72
+ end)
73
+
48
74
  local deathTracker = PlayerKillTrackerUtils.create(self._deathReportBindersServer.PlayerDeathTracker, player)
49
75
  maid:GiveTask(deathTracker)
50
76
 
@@ -23,6 +23,12 @@ function DeathReportProcessor.new()
23
23
  self._playerDeathSubTable = ObservableSubscriptionTable.new()
24
24
  self._maid:GiveTask(self._playerDeathSubTable)
25
25
 
26
+ self._humanoidKillerSubTable = ObservableSubscriptionTable.new()
27
+ self._maid:GiveTask(self._humanoidKillerSubTable)
28
+
29
+ self._humanoidDeathSubTable = ObservableSubscriptionTable.new()
30
+ self._maid:GiveTask(self._humanoidDeathSubTable)
31
+
26
32
  self._maid:GiveTask(Players.PlayerRemoving:Connect(function(player)
27
33
  self._playerKillerSubTable:Complete(player)
28
34
  self._playerDeathSubTable:Complete(player)
@@ -55,6 +61,30 @@ function DeathReportProcessor:ObservePlayerDeathReports(player)
55
61
  return self._playerDeathSubTable:Observe(player)
56
62
  end
57
63
 
64
+ --[=[
65
+ Observes death reports for the given humanoid
66
+
67
+ @param humanoid Humanoid
68
+ @return Observable<DeathReport>
69
+ ]=]
70
+ function DeathReportProcessor:ObserveHumanoidDeathReports(humanoid)
71
+ assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "Bad humanoid")
72
+
73
+ return self._humanoidDeathSubTable:Observe(humanoid)
74
+ end
75
+
76
+ --[=[
77
+ Observes killer reports for the given humanoid
78
+
79
+ @param humanoid Humanoid
80
+ @return Observable<DeathReport>
81
+ ]=]
82
+ function DeathReportProcessor:ObserveHumanoidKillerReports(humanoid)
83
+ assert(typeof(humanoid) == "Instance" and humanoid:IsA("Humanoid"), "Bad humanoid")
84
+
85
+ return self._humanoidKillerSubTable:Observe(humanoid)
86
+ end
87
+
58
88
  --[=[
59
89
  Handles the death report
60
90
 
@@ -67,9 +97,17 @@ function DeathReportProcessor:HandleDeathReport(deathReport)
67
97
  self._playerKillerSubTable:Fire(deathReport.killerPlayer, deathReport)
68
98
  end
69
99
 
100
+ if deathReport.killerHumanoid then
101
+ self._humanoidKillerSubTable:Fire(deathReport.killerHumanoid, deathReport)
102
+ end
103
+
70
104
  if deathReport.player then
71
105
  self._playerDeathSubTable:Fire(deathReport.player, deathReport)
72
106
  end
107
+
108
+ if deathReport.humanoid then
109
+ self._humanoidDeathSubTable:Fire(deathReport.humanoid, deathReport)
110
+ end
73
111
  end
74
112
 
75
113
  return DeathReportProcessor
@@ -15,33 +15,54 @@ local DeathReportUtils = {}
15
15
  Constructs a new DeathReport from a humanoid
16
16
 
17
17
  @param humanoid Humanomid
18
+ @param weaponData WeaponData
18
19
  @return DeathReport
19
20
  ]=]
20
- function DeathReportUtils.fromDeceasedHumanoid(humanoid)
21
+ function DeathReportUtils.fromDeceasedHumanoid(humanoid, weaponData)
22
+ assert(DeathReportUtils.isWeaponData(weaponData) or weaponData == nil, "Bad weaponData")
23
+
21
24
  return {
22
25
  adornee = humanoid.Parent;
23
26
  humanoid = humanoid;
24
27
  player = CharacterUtils.getPlayerFromCharacter(humanoid);
25
28
  killerHumanoid = HumanoidKillerUtils.getKillerHumanoidOfHumanoid(humanoid);
26
29
  killerPlayer = HumanoidKillerUtils.getPlayerKillerOfHumanoid(humanoid);
27
- weaponData = DeathReportUtils.createWeaponData();
30
+ weaponData = weaponData or DeathReportUtils.createWeaponData(nil);
28
31
  }
29
32
  end
30
33
 
34
+ --[=[
35
+ Returns true if a DeathReport
36
+
37
+ @param deathReport any
38
+ @return boolean
39
+ ]=]
31
40
  function DeathReportUtils.isDeathReport(deathReport)
32
41
  return type(deathReport) == "table"
33
42
  and typeof(deathReport.humanoid) == "Instance"
34
43
  end
35
44
 
45
+ --[=[
46
+ Returns true if a WeaponData
47
+
48
+ @param weaponData any
49
+ @return boolean
50
+ ]=]
51
+ function DeathReportUtils.isWeaponData(weaponData)
52
+ return type(weaponData) == "table" and (typeof(weaponData.weaponInstance) == "Instance" or weaponData.weaponInstance == nil)
53
+ end
54
+
36
55
  --[=[
37
56
  Creates weapon data information
38
57
 
58
+ @param weaponInstance Instance?
39
59
  @return WeaponData
40
60
  ]=]
41
- function DeathReportUtils.createWeaponData()
61
+ function DeathReportUtils.createWeaponData(weaponInstance)
62
+ assert(typeof(weaponInstance) == "Instance" or weaponInstance == nil, "Bad weaponInstance")
63
+
42
64
  return {
43
- weaponKey = "test";
44
- weaponInstance = nil;
65
+ weaponInstance = weaponInstance;
45
66
  }
46
67
  end
47
68
 
@@ -137,6 +158,10 @@ function DeathReportUtils.getKillerColor(deathReport)
137
158
  return nil
138
159
  end
139
160
 
161
+ --[=[
162
+ Gets the default color of a death report to use.
163
+ @return Color3
164
+ ]=]
140
165
  function DeathReportUtils.getDefaultColor()
141
166
  return DEFAULT_COLOR
142
167
  end