Added support for savemaxpower
This commit is contained in:
@@ -35,8 +35,8 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
return Ok(e.response);
|
return Ok(e.response);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Task<IActionResult> InvokeEndpointHandlerForMethod<T>(object _this, string method, string body)
|
private Task<IActionResult> InvokeEndpointHandlerForMethod<T>(object _this, string method, string body)
|
||||||
{
|
{
|
||||||
MethodMap registeredEndpointHandlers = GetMethodMapForType<T>();
|
MethodMap registeredEndpointHandlers = GetMethodMapForType<T>();
|
||||||
if (registeredEndpointHandlers.ContainsKey(method))
|
if (registeredEndpointHandlers.ContainsKey(method))
|
||||||
|
|||||||
@@ -31,10 +31,6 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
public async Task<IActionResult> Get(string id)
|
public async Task<IActionResult> Get(string id)
|
||||||
{
|
{
|
||||||
User user = await _userRepository.GetUser(id);
|
User user = await _userRepository.GetUser(id);
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
return BadRequest("Invalid user id specified");
|
|
||||||
}
|
|
||||||
|
|
||||||
return Ok(_mapper.Map<PlayerBaseDataResponse>(user));
|
return Ok(_mapper.Map<PlayerBaseDataResponse>(user));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,6 +39,14 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
_storeService = storeService;
|
_storeService = storeService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async Task<IActionResult> SavePowerMax(string body)
|
||||||
|
{
|
||||||
|
PlayerDataSavePowerMaxTotalRequest request =
|
||||||
|
JsonConvert.DeserializeObject<PlayerDataSavePowerMaxTotalRequest>(body);
|
||||||
|
await _storeService.ChangePowerMaxTotal(request.SteamId, request.Op == "add" ? 1 : -1);
|
||||||
|
return Ok(new OkResponse());
|
||||||
|
}
|
||||||
|
|
||||||
[EndpointHandler("save_card_level")]
|
[EndpointHandler("save_card_level")]
|
||||||
private async Task<IActionResult> SaveCardLevel(string body)
|
private async Task<IActionResult> SaveCardLevel(string body)
|
||||||
{
|
{
|
||||||
@@ -97,10 +105,6 @@ namespace TOOHUCardAPI.Controllers
|
|||||||
PlayerDataSaveCardGroupRequest request =
|
PlayerDataSaveCardGroupRequest request =
|
||||||
JsonConvert.DeserializeObject<PlayerDataSaveCardGroupRequest>(body);
|
JsonConvert.DeserializeObject<PlayerDataSaveCardGroupRequest>(body);
|
||||||
User user = await _userRepository.GetUser(request.SteamId);
|
User user = await _userRepository.GetUser(request.SteamId);
|
||||||
if (user == null)
|
|
||||||
{
|
|
||||||
throw new InvalidUserException();
|
|
||||||
}
|
|
||||||
|
|
||||||
EncodedCardGroup group = user.EncodedCardGroups.FirstOrDefault(group => group.GroupKey == request.GroupKey) ?? new EncodedCardGroup()
|
EncodedCardGroup group = user.EncodedCardGroups.FirstOrDefault(group => group.GroupKey == request.GroupKey) ?? new EncodedCardGroup()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -10,6 +11,10 @@ namespace TOOHUCardAPI.DTO
|
|||||||
{
|
{
|
||||||
public static string EncodeLevelList(this IEnumerable<CardLevel> cardLevels)
|
public static string EncodeLevelList(this IEnumerable<CardLevel> cardLevels)
|
||||||
{
|
{
|
||||||
|
if (cardLevels == null)
|
||||||
|
{
|
||||||
|
return string.Empty;
|
||||||
|
}
|
||||||
return cardLevels.Select(cl => $"{cl.CardItemCode.Substring(6)}{cl.Level}").Aggregate(new StringBuilder(),
|
return cardLevels.Select(cl => $"{cl.CardItemCode.Substring(6)}{cl.Level}").Aggregate(new StringBuilder(),
|
||||||
(ret, current) =>
|
(ret, current) =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ namespace TOOHUCardAPI.DTO
|
|||||||
[JsonProperty("luck_crit")] public float LuckCrit { get; set; }
|
[JsonProperty("luck_crit")] public float LuckCrit { get; set; }
|
||||||
[JsonProperty("new_card_list")] public string NewCardList { get; set; } = string.Empty;
|
[JsonProperty("new_card_list")] public string NewCardList { get; set; } = string.Empty;
|
||||||
[JsonProperty("open_day_list")] public string OpenDayList { get; set; } = string.Empty;
|
[JsonProperty("open_day_list")] public string OpenDayList { get; set; } = string.Empty;
|
||||||
[JsonProperty("is_open_day")] public int IsOpenDay { get; set; }
|
[JsonProperty("is_open_day")] public int IsOpenDay { get; set; } = 1;
|
||||||
[JsonProperty("server_time")] public string ServerTime { get; set; } = string.Empty;
|
[JsonProperty("server_time")] public string ServerTime { get; set; } = string.Empty;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ namespace TOOHUCardAPI.DTO.PlayerData
|
|||||||
[JsonProperty("level_list")] public string LevelList { get; set; } = string.Empty;
|
[JsonProperty("level_list")] public string LevelList { get; set; } = string.Empty;
|
||||||
[JsonProperty("is_first_win")]public int IsFirstWin { get; set; }
|
[JsonProperty("is_first_win")]public int IsFirstWin { get; set; }
|
||||||
[JsonProperty("key_use_count")] public int KeyUseCount { get; set; }
|
[JsonProperty("key_use_count")] public int KeyUseCount { get; set; }
|
||||||
|
[JsonProperty("power_max_total")] public int PowerMaxTotal { get; set; }
|
||||||
|
|
||||||
public Dictionary<string, object> ToDynamicProperties()
|
public Dictionary<string, object> ToDynamicProperties()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
namespace TOOHUCardAPI.DTO.PlayerData
|
||||||
|
{
|
||||||
|
public class PlayerDataSavePowerMaxTotalRequest : AbstractPlayerTargetedRequest
|
||||||
|
{
|
||||||
|
public string Op { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,6 +19,7 @@ namespace TOOHUCardAPI.Data.Models
|
|||||||
public bool Ban { get; set; }
|
public bool Ban { get; set; }
|
||||||
public int Point { get; set; }
|
public int Point { get; set; }
|
||||||
public DateTime LastFirstWin { get; set; }
|
public DateTime LastFirstWin { get; set; }
|
||||||
|
public int PowerMaxTotal { get; set; }
|
||||||
public List<EncodedCardGroup> EncodedCardGroups { get; set; }
|
public List<EncodedCardGroup> EncodedCardGroups { get; set; }
|
||||||
public List<CardLevel> CardLevels { get; set; }
|
public List<CardLevel> CardLevels { get; set; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,14 @@ namespace TOOHUCardAPI.Data.Services
|
|||||||
_logger.LogInformation($"User with steamid {user.SteamId} was given {points} points. New total: {user.Point}");
|
_logger.LogInformation($"User with steamid {user.SteamId} was given {points} points. New total: {user.Point}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task<int> ChangePowerMaxTotal(string steamId, int amt)
|
||||||
|
{
|
||||||
|
User user = await _userRepository.GetUser(steamId);
|
||||||
|
user.PowerMaxTotal = Math.Clamp(user.PowerMaxTotal + amt, 0, int.MaxValue);
|
||||||
|
await _userRepository.UpdateUser(user);
|
||||||
|
return user.PowerMaxTotal;
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<int> LevelUpCard(string steamId, string itemName, int levelIncrease)
|
public async Task<int> LevelUpCard(string steamId, string itemName, int levelIncrease)
|
||||||
{
|
{
|
||||||
User user = await _userRepository.GetUser(steamId);
|
User user = await _userRepository.GetUser(steamId);
|
||||||
|
|||||||
1020
TOOHUCardAPI/Migrations/20211031065641_maxpower stuff.Designer.cs
generated
Normal file
1020
TOOHUCardAPI/Migrations/20211031065641_maxpower stuff.Designer.cs
generated
Normal file
File diff suppressed because it is too large
Load Diff
24
TOOHUCardAPI/Migrations/20211031065641_maxpower stuff.cs
Normal file
24
TOOHUCardAPI/Migrations/20211031065641_maxpower stuff.cs
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
namespace TOOHUCardAPI.Migrations
|
||||||
|
{
|
||||||
|
public partial class maxpowerstuff : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "PowerMaxTotal",
|
||||||
|
table: "Users",
|
||||||
|
type: "INTEGER",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "PowerMaxTotal",
|
||||||
|
table: "Users");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -971,6 +971,9 @@ namespace TOOHUCardAPI.Migrations
|
|||||||
b.Property<int>("Point")
|
b.Property<int>("Point")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
b.Property<int>("PowerMaxTotal")
|
||||||
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
b.Property<bool>("Vip")
|
b.Property<bool>("Vip")
|
||||||
.HasColumnType("INTEGER");
|
.HasColumnType("INTEGER");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user