Files
OpenFUT-Core/src/models/objective.rs
T
2026-08-07 12:03:21 -07:00

79 lines
1.9 KiB
Rust

use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ObjectiveType {
Daily,
Weekly,
Lifetime,
Milestone,
Season,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ObjectiveMetric {
MatchesWon,
MatchesPlayed,
GoalsScored,
PacksOpened,
SbcsCompleted,
CoinsEarned,
}
impl ObjectiveMetric {
pub fn as_str(&self) -> &'static str {
match self {
ObjectiveMetric::MatchesWon => "matcheswon",
ObjectiveMetric::MatchesPlayed => "matchesplayed",
ObjectiveMetric::GoalsScored => "goalsscored",
ObjectiveMetric::PacksOpened => "packsopened",
ObjectiveMetric::SbcsCompleted => "sbcscompleted",
ObjectiveMetric::CoinsEarned => "coinsearned",
}
}
}
/// Objective definition from data/objectives/*.json
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ObjectiveDefinition {
pub id: String,
pub title: String,
pub description: String,
pub objective_type: ObjectiveType,
pub metric: ObjectiveMetric,
pub target: i64,
pub reward_coins: i64,
pub reward_pack_id: Option<String>,
pub reward_xp: i64,
}
/// Progress row in DB
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct ObjectiveProgress {
pub id: String,
pub profile_id: String,
pub objective_id: String,
pub current: i64,
pub completed: bool,
pub claimed: bool,
pub updated_at: String,
}
#[derive(Debug, Serialize)]
pub struct ObjectiveWithProgress {
#[serde(flatten)]
pub definition: ObjectiveDefinition,
pub current: i64,
pub completed: bool,
pub claimed: bool,
}
#[derive(Debug, Serialize)]
pub struct ClaimRewardResult {
pub objective_id: String,
pub coins_granted: i64,
pub xp_granted: i64,
pub pack_granted: Option<String>,
}