Skip to content

Commit 6f24d31

Browse files
committed
add deaths goal type
1 parent 4f8629a commit 6f24d31

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

src-tauri/src/database.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn get_db_dir() -> Option<&'static PathBuf> {
4343
pub enum GoalMetric {
4444
Networth,
4545
Kills,
46+
Deaths,
4647
LastHits,
4748
Denies,
4849
Level,
@@ -55,6 +56,7 @@ impl GoalMetric {
5556
match self {
5657
GoalMetric::Networth => "networth",
5758
GoalMetric::Kills => "kills",
59+
GoalMetric::Deaths => "deaths",
5860
GoalMetric::LastHits => "last_hits",
5961
GoalMetric::Denies => "denies",
6062
GoalMetric::Level => "level",
@@ -67,6 +69,7 @@ impl GoalMetric {
6769
match s {
6870
"networth" => Some(GoalMetric::Networth),
6971
"kills" => Some(GoalMetric::Kills),
72+
"deaths" => Some(GoalMetric::Deaths),
7073
"last_hits" => Some(GoalMetric::LastHits),
7174
"denies" => Some(GoalMetric::Denies),
7275
"level" => Some(GoalMetric::Level),
@@ -1034,6 +1037,15 @@ pub fn evaluate_goal(conn: &Connection, goal: &Goal, match_data: &Match) -> Opti
10341037
((match_data.kills as f32 / duration_minutes as f32) * target_minutes as f32) as i32
10351038
}
10361039
}
1040+
GoalMetric::Deaths => {
1041+
// For deaths, assume linear progression (same as kills)
1042+
if duration_minutes <= target_minutes {
1043+
match_data.deaths
1044+
} else {
1045+
// Estimate deaths at target time
1046+
((match_data.deaths as f32 / duration_minutes as f32) * target_minutes as f32) as i32
1047+
}
1048+
}
10371049
GoalMetric::LastHits => {
10381050
// ONLY use exact per-minute CS data from OpenDota - never estimate
10391051
// Linear estimation (total_cs / game_time * target_time) is completely inaccurate
@@ -1101,10 +1113,8 @@ pub fn evaluate_goal(conn: &Connection, goal: &Goal, match_data: &Match) -> Opti
11011113
};
11021114

11031115
let achieved = match &goal.metric {
1104-
GoalMetric::ItemTiming => {
1105-
// For item timing, actual_value is purchase time in seconds
1106-
// target_value is target time in seconds
1107-
// Achieved if purchased before or at target time
1116+
GoalMetric::ItemTiming | GoalMetric::Deaths => {
1117+
// Lower is better: achieved if actual <= target
11081118
actual_value <= goal.target_value
11091119
}
11101120
_ => {
@@ -1573,6 +1583,13 @@ pub fn get_goal_match_data(conn: &Connection, goal_id: i64) -> Result<Vec<MatchD
15731583
((match_data.kills as f32 / duration_minutes as f32) * target_minutes as f32) as i32
15741584
}
15751585
}
1586+
GoalMetric::Deaths => {
1587+
if duration_minutes <= target_minutes {
1588+
match_data.deaths
1589+
} else {
1590+
((match_data.deaths as f32 / duration_minutes as f32) * target_minutes as f32) as i32
1591+
}
1592+
}
15761593
GoalMetric::LastHits => {
15771594
match cs_map.get(&match_data.match_id) {
15781595
Some(&(lh, _)) => lh,
@@ -1611,7 +1628,7 @@ pub fn get_goal_match_data(conn: &Connection, goal_id: i64) -> Result<Vec<MatchD
16111628
};
16121629

16131630
let achieved = match &goal.metric {
1614-
GoalMetric::ItemTiming => actual_value <= goal.target_value,
1631+
GoalMetric::ItemTiming | GoalMetric::Deaths => actual_value <= goal.target_value,
16151632
_ => actual_value >= goal.target_value,
16161633
};
16171634

src/lib/locales/en.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"metric_partner_nw": "Partner Networth",
204204
"metric_networth": "Net Worth",
205205
"metric_kills": "Kills",
206+
"metric_deaths": "Deaths",
206207
"metric_level": "Level",
207208
"metric_item_timing": "Item Timing",
208209
"item": "Item",
@@ -232,6 +233,7 @@
232233
"tag_deny": "Deny Goal",
233234
"tag_item": "Item Goal",
234235
"tag_kill": "Kill Goal",
236+
"tag_death": "Death Goal",
235237
"tag_nw": "NW Goal",
236238
"tag_support": "Support Goal",
237239
"any_hero": "Any Hero",

src/lib/locales/ru.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
"metric_partner_nw": "Золото партнёра",
204204
"metric_networth": "Нетфорс",
205205
"metric_kills": "Убийства",
206+
"metric_deaths": "Смерти",
206207
"metric_level": "Уровень",
207208
"metric_item_timing": "Тайминг предмета",
208209
"item": "Предмет",
@@ -232,6 +233,7 @@
232233
"tag_deny": "Цель: денаи",
233234
"tag_item": "Цель: предмет",
234235
"tag_kill": "Цель: убийства",
236+
"tag_death": "Цель: смерти",
235237
"tag_nw": "Цель: золото",
236238
"tag_support": "Цель: саппорт",
237239
"any_hero": "Любой герой",

src/routes/goals/+page.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@
254254
switch (metric) {
255255
case "Networth": return "Net Worth";
256256
case "Kills": return "Kills";
257+
case "Deaths": return "Deaths";
257258
case "LastHits": return "Last Hits";
258259
case "Denies": return "Denies";
259260
case "Level": return "Level";
@@ -268,6 +269,7 @@
268269
switch (metric) {
269270
case "Networth": return "gold";
270271
case "Kills": return "kills";
272+
case "Deaths": return "deaths";
271273
case "LastHits": return "CS";
272274
case "Denies": return "denies";
273275
case "PartnerNetworth": return "gold";
@@ -299,6 +301,8 @@
299301
const seconds = goal.target_value % 60;
300302
const timeStr = seconds > 0 ? `${minutes}:${seconds.toString().padStart(2, '0')}` : `${minutes}:00`;
301303
return `${heroName}${itemName} by ${timeStr}`;
304+
} else if (goal.metric === "Deaths") {
305+
return `${heroName} — at most ${goal.target_value} deaths by ${goal.target_time_minutes} min`;
302306
} else if (goal.metric === "PartnerNetworth") {
303307
return `${heroName} — Partner: ${goal.target_value}g by ${goal.target_time_minutes} min`;
304308
} else {
@@ -328,6 +332,7 @@
328332
case "Denies": return { tkey: 'goals.tag_deny', cls: 'tag-cs' };
329333
case "ItemTiming": return { tkey: 'goals.tag_item', cls: 'tag-item' };
330334
case "Kills": return { tkey: 'goals.tag_kill', cls: 'tag-kill' };
335+
case "Deaths": return { tkey: 'goals.tag_death', cls: 'tag-kill' };
331336
case "Networth": return { tkey: 'goals.tag_nw', cls: 'tag-nw' };
332337
case "PartnerNetworth": return { tkey: 'goals.tag_support', cls: 'tag-nw' };
333338
default: return { tkey: null, cls: '' };
@@ -368,6 +373,7 @@
368373
<option value="PartnerNetworth">{$_('goals.metric_partner_nw')}</option>
369374
<option value="Networth">{$_('goals.metric_networth')}</option>
370375
<option value="Kills">{$_('goals.metric_kills')}</option>
376+
<option value="Deaths">{$_('goals.metric_deaths')}</option>
371377
<option value="Level">{$_('goals.metric_level')}</option>
372378
<option value="ItemTiming">{$_('goals.metric_item_timing')}</option>
373379
</select>
@@ -395,7 +401,7 @@
395401
<div class="fg">
396402
<div class="form-label">{$_('goals.target', { values: { metric: getMetricLabel(formMetric) } })}</div>
397403
<input class="form-input" type="number" min="1"
398-
placeholder={formMetric === "Level" ? "e.g. 6" : "e.g. 50"}
404+
placeholder={formMetric === "Level" ? "e.g. 6" : formMetric === "Deaths" ? "e.g. <4" : "e.g. 50"}
399405
bind:value={formTargetValue} />
400406
</div>
401407
<div class="fg fg-narrow">

0 commit comments

Comments
 (0)