mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Add basic currency support and plumb multiplayer rewards screen #70
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#![allow(unused)]
|
||||
use polariton::operation::Typed;
|
||||
|
||||
pub struct ClanInviteInfo {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton::operation::{ParameterTable, Typed, Arr};
|
||||
|
||||
use crate::data::clan_invite::*;
|
||||
//use crate::data::clan_invite::*;
|
||||
|
||||
const PARAM_KEY: u8 = 42;
|
||||
|
||||
@@ -10,7 +10,7 @@ pub(super) fn clan_invites_provider<C: Send + Sync>() -> SimpleFunc<39, crate::U
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, Typed::<C>::Arr(Arr {
|
||||
ty: polariton::serdes::TypePrefix::HashMap, // hashmap
|
||||
items: vec![
|
||||
/*items: vec![
|
||||
ClanInviteInfo {
|
||||
username: "RE_user1".to_owned(),
|
||||
display_name: "RE_user1".to_owned(),
|
||||
@@ -19,7 +19,8 @@ pub(super) fn clan_invites_provider<C: Send + Sync>() -> SimpleFunc<39, crate::U
|
||||
use_custom_avatar: false,
|
||||
avatar_id: 0,
|
||||
}.as_transmissible()
|
||||
],
|
||||
],*/
|
||||
items: vec![],
|
||||
}));
|
||||
Ok(params.into())
|
||||
})
|
||||
|
||||
@@ -8,6 +8,8 @@ mod season_rewards;
|
||||
mod previous_battle_rewards;
|
||||
mod platoon_data;
|
||||
mod calculate_mmr;
|
||||
mod previous_battle_rewards_get;
|
||||
mod previous_battle_rewards_claim;
|
||||
|
||||
use polariton_server::operations::OperationsHandler;
|
||||
|
||||
@@ -31,4 +33,6 @@ pub fn handler() -> OperationsHandler<crate::UserTy, crate::data::custom::Custom
|
||||
.add(calculate_mmr::mmr_provider())
|
||||
.add(polariton_server::operations::Ack::<25, _>::default()) // save social settings, sent on escape menu settings save (should probably be saved someday...)
|
||||
.add(polariton_server::operations::Ack::<0, _>::default()) // send friend request, can be sent from match leaderboard
|
||||
.add(previous_battle_rewards_get::get_battle_rewards_provider())
|
||||
.add(previous_battle_rewards_claim::claim_battle_rewards_provider())
|
||||
}
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
use polariton_server::operations::SimpleFunc;
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const PARAM_KEY: u8 = 60;
|
||||
//const USER_PARAM_KEY: u8 = 1; // str (username)
|
||||
const CODE: u8 = 54;
|
||||
|
||||
pub(super) fn pending_battle_rewards_provider<C: Send + Sync>() -> SimpleFunc<54, crate::UserTy, impl (Fn(ParameterTable<C>, &crate::UserTy) -> Result<ParameterTable<C>, i16>) + Sync + Sync, C> {
|
||||
SimpleFunc::new(|params, _| {
|
||||
let mut params = params.to_dict();
|
||||
params.insert(PARAM_KEY, Typed::Bool(false));
|
||||
Ok(params.into())
|
||||
})
|
||||
// const USERNAME_PARAM_KEY: u8 = 1; // in; string
|
||||
const PARAM_KEY: u8 = 60;
|
||||
|
||||
pub(super) struct PreviousBattleRewarder;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for PreviousBattleRewarder {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut table = ParameterTable::with_capacity(2);
|
||||
let user_info = user.user()?;
|
||||
table.insert(PARAM_KEY, Typed::Bool(user_info.has_unclaimed_match_rewards().await?));
|
||||
Ok(table)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn pending_battle_rewards_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, PreviousBattleRewarder> {
|
||||
SimpleOpImpl::new(PreviousBattleRewarder)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 55;
|
||||
|
||||
// const USERNAME_PARAM_KEY: u8 = 1; // in; string
|
||||
const PARAM_KEY: u8 = 60;
|
||||
|
||||
pub(super) struct ClaimPreviousBattleRewards;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for ClaimPreviousBattleRewards {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut table = ParameterTable::with_capacity(2);
|
||||
let user_info = user.user()?;
|
||||
let is_success = user_info.claim_match_rewards().await?;
|
||||
table.insert(PARAM_KEY, Typed::Bool(!is_success || user_info.has_unclaimed_match_rewards().await?));
|
||||
Ok(table)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn claim_battle_rewards_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, ClaimPreviousBattleRewards> {
|
||||
SimpleOpImpl::new(ClaimPreviousBattleRewards)
|
||||
}
|
||||
|
||||
49
rc_social_room/src/operations/previous_battle_rewards_get.rs
Normal file
49
rc_social_room/src/operations/previous_battle_rewards_get.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use polariton_server::operations::{SimpleOpError, SimpleOperation, SimpleOpImpl};
|
||||
use polariton::operation::{ParameterTable, Typed};
|
||||
|
||||
const CODE: u8 = 53;
|
||||
|
||||
// const USERNAME_PARAM_KEY: u8 = 1; // in; string
|
||||
//const PARAM_KEY: u8 = 60;
|
||||
const NEW_SEASON_XP_PARAM_KEY: u8 = 57; // int; out
|
||||
const XP_AWARD_BASE_PARAM_KEY: u8 = 58; // int; out
|
||||
const XP_AWARD_PREMIUM_PARAM_KEY: u8 = 59; // int; out
|
||||
const XP_AWARD_PARTY_PARAM_KEY: u8 = 61; // int; out
|
||||
const XP_AWARD_TIER_PARAM_KEY: u8 = 52; // int; out
|
||||
const ROBITS_TOTAL_PARAM_KEY: u8 = 50; // int; out
|
||||
const AVERAGE_XP_PARAM_KEY: u8 = 54; // int; out
|
||||
const CLAN_TOTAL_XP_PARAM_KEY: u8 = 55; // int; out
|
||||
const ROBITS_PARAM_KEY: u8 = 68; // int; out
|
||||
const PREMIUM_ROBITS_PARAM_KEY: u8 = 69; // int; out
|
||||
const LONG_PLAY_MULTIPLIER_PARAM_KEY: u8 = 72; // float; out
|
||||
|
||||
pub(super) struct GetPreviousBattleRewards;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl <C: Send + 'static> SimpleOperation<C> for GetPreviousBattleRewards {
|
||||
type User = crate::UserTy;
|
||||
const CODE: u8 = CODE;
|
||||
|
||||
async fn handle(&self, _params: ParameterTable<C>, user: &Self::User) -> Result<ParameterTable<C>, SimpleOpError> {
|
||||
let mut table = ParameterTable::with_capacity(12);
|
||||
let user_info = user.user()?;
|
||||
let next_rewards = user_info.get_unclaimed_match_rewards().await?;
|
||||
table.insert(NEW_SEASON_XP_PARAM_KEY, Typed::Int(next_rewards.season_experience));
|
||||
table.insert(XP_AWARD_BASE_PARAM_KEY, Typed::Int(next_rewards.experience_award_base));
|
||||
table.insert(XP_AWARD_PREMIUM_PARAM_KEY, Typed::Int(next_rewards.experience_award_premium));
|
||||
table.insert(XP_AWARD_PARTY_PARAM_KEY, Typed::Int(next_rewards.experience_award_party));
|
||||
table.insert(XP_AWARD_TIER_PARAM_KEY, Typed::Int(next_rewards.experience_award_tier));
|
||||
table.insert(ROBITS_TOTAL_PARAM_KEY, Typed::Int(next_rewards.robits_total));
|
||||
table.insert(AVERAGE_XP_PARAM_KEY, Typed::Int(next_rewards.average_experience));
|
||||
table.insert(CLAN_TOTAL_XP_PARAM_KEY, Typed::Int(next_rewards.clan_experience));
|
||||
table.insert(ROBITS_PARAM_KEY, Typed::Int(next_rewards.robits_earned));
|
||||
table.insert(PREMIUM_ROBITS_PARAM_KEY, Typed::Int(next_rewards.premium_robits_earned));
|
||||
table.insert(LONG_PLAY_MULTIPLIER_PARAM_KEY, Typed::Float(1.0));
|
||||
Ok(table)
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn get_battle_rewards_provider<C: Send + 'static>() -> SimpleOpImpl<C, crate::UserTy, GetPreviousBattleRewards> {
|
||||
SimpleOpImpl::new(GetPreviousBattleRewards)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user