Skip to content

Commit 80052cb

Browse files
authored
feat: pvp auto-match (#6)
* feat: pvp auto-match * fix: add tiers for pvp leaderboard * update: add pvp shedulers
1 parent 06adde8 commit 80052cb

File tree

23 files changed

+469
-102
lines changed

23 files changed

+469
-102
lines changed

docs/spec/CodeCharacter-API.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ paths:
446446
in: query
447447
name: size
448448
description: Size of the page
449+
- schema:
450+
$ref: '#/components/schemas/TierType'
451+
in: query
452+
name: tier
453+
description: Leaderboard Tier
449454
description: Get PvP leaderboard
450455
parameters: []
451456

@@ -1661,23 +1666,31 @@ paths:
16611666
components:
16621667
schemas:
16631668
UserMatchStats:
1664-
title: UserMatchStats
1669+
title: UserMatchStat
1670+
type: array
1671+
description: User Match Stats array model
1672+
items:
1673+
anyOf:
1674+
- $ref: '#/components/schemas/UserMatchStat'
1675+
required:
1676+
- stat
1677+
1678+
UserMatchStat:
1679+
title: UserMatchStat
16651680
type: object
1666-
description: User Match Stats model
1681+
description: User Match Stat model
16671682
properties:
16681683
avgAtk:
16691684
type: number
1670-
default: 0
16711685
dc_wins:
16721686
type: number
1673-
default: 0
16741687
coins:
16751688
type: number
1676-
default: 0
16771689
required:
16781690
- avgAtk
16791691
- dc_wins
16801692
- coins
1693+
16811694
PasswordLoginRequest:
16821695
title: PasswordLoginRequest
16831696
type: object
@@ -2599,6 +2612,7 @@ components:
25992612
- DAILYCHALLENGE
26002613
- PVP
26012614
- SELFPVP
2615+
- AUTOPVP
26022616
description: Match Mode
26032617
Verdict:
26042618
type: string

library/src/main/kotlin/delta/codecharacter/core/LeaderboardApi.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ interface LeaderboardApi {
7373
value = ["/pvpleaderboard"],
7474
produces = ["application/json"]
7575
)
76-
fun getPvPLeaderboard(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?): ResponseEntity<List<PvPLeaderBoardResponseDto>> {
76+
fun getPvPLeaderboard(@Parameter(description = "Index of the page") @Valid @RequestParam(value = "page", required = false) page: kotlin.Int?,@Parameter(description = "Size of the page") @Valid @RequestParam(value = "size", required = false) size: kotlin.Int?,@Parameter(description = "Leaderboard Tier", schema = Schema(allowableValues = ["TIER_PRACTICE", "TIER1", "TIER2", "TIER3", "TIER4"])) @Valid @RequestParam(value = "tier", required = false) tier: TierTypeDto?): ResponseEntity<List<PvPLeaderBoardResponseDto>> {
7777
return ResponseEntity(HttpStatus.NOT_IMPLEMENTED)
7878
}
7979
}

library/src/main/kotlin/delta/codecharacter/dtos/MatchModeDto.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import io.swagger.v3.oas.annotations.media.Schema
1616

1717
/**
1818
* Match Mode
19-
* Values: SELF,MANUAL,AUTO,DAILYCHALLENGE,PVP,SELFPVP
19+
* Values: SELF,MANUAL,AUTO,DAILYCHALLENGE,PVP,SELFPVP,AUTOPVP
2020
*/
2121
enum class MatchModeDto(val value: kotlin.String) {
2222

@@ -25,6 +25,7 @@ enum class MatchModeDto(val value: kotlin.String) {
2525
@JsonProperty("AUTO") AUTO("AUTO"),
2626
@JsonProperty("DAILYCHALLENGE") DAILYCHALLENGE("DAILYCHALLENGE"),
2727
@JsonProperty("PVP") PVP("PVP"),
28-
@JsonProperty("SELFPVP") SELFPVP("SELFPVP")
28+
@JsonProperty("SELFPVP") SELFPVP("SELFPVP"),
29+
@JsonProperty("AUTOPVP") AUTOPVP("AUTOPVP")
2930
}
3031

library/src/main/kotlin/delta/codecharacter/dtos/UserMatchStatDto.kt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,23 @@ import jakarta.validation.constraints.Pattern
1212
import jakarta.validation.constraints.Size
1313
import jakarta.validation.Valid
1414
import io.swagger.v3.oas.annotations.media.Schema
15-
import java.math.BigDecimal
1615

1716
/**
1817
* User Match Stat model
19-
* @param avgAtk
20-
* @param dcWins
21-
* @param coins
18+
* @param avgAtk
19+
* @param dcWins
20+
* @param coins
2221
*/
2322
data class UserMatchStatDto(
2423

2524
@Schema(example = "null", required = true, description = "")
26-
@get:JsonProperty("avgAtk", required = true) val avgAtk: java.math.BigDecimal = BigDecimal.ZERO,
25+
@get:JsonProperty("avgAtk", required = true) val avgAtk: java.math.BigDecimal,
2726

2827
@Schema(example = "null", required = true, description = "")
29-
@get:JsonProperty("dc_wins", required = true) val dcWins: java.math.BigDecimal = BigDecimal.ZERO,
28+
@get:JsonProperty("dc_wins", required = true) val dcWins: java.math.BigDecimal,
3029

3130
@Schema(example = "null", required = true, description = "")
32-
@get:JsonProperty("coins", required = true) val coins: java.math.BigDecimal = BigDecimal.ZERO
31+
@get:JsonProperty("coins", required = true) val coins: java.math.BigDecimal
3332
) {
3433

3534
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package delta.codecharacter.dtos
2+
3+
import java.util.Objects
4+
import com.fasterxml.jackson.annotation.JsonProperty
5+
import jakarta.validation.constraints.DecimalMax
6+
import jakarta.validation.constraints.DecimalMin
7+
import jakarta.validation.constraints.Email
8+
import jakarta.validation.constraints.Max
9+
import jakarta.validation.constraints.Min
10+
import jakarta.validation.constraints.NotNull
11+
import jakarta.validation.constraints.Pattern
12+
import jakarta.validation.constraints.Size
13+
import jakarta.validation.Valid
14+
import io.swagger.v3.oas.annotations.media.Schema
15+
16+
/**
17+
* User Match Stats model
18+
* @param avgAtk
19+
* @param dcWins
20+
* @param coins
21+
*/
22+
data class UserMatchStatsDto(
23+
24+
@Schema(example = "null", required = true, description = "")
25+
@get:JsonProperty("avgAtk", required = true) val avgAtk: java.math.BigDecimal,
26+
27+
@Schema(example = "null", required = true, description = "")
28+
@get:JsonProperty("dc_wins", required = true) val dcWins: java.math.BigDecimal,
29+
30+
@Schema(example = "null", required = true, description = "")
31+
@get:JsonProperty("coins", required = true) val coins: java.math.BigDecimal
32+
) {
33+
34+
}
35+

library/src/main/kotlin/delta/codecharacter/dtos/UserMatchStatsInnerDto.kt

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,23 @@ import jakarta.validation.constraints.Pattern
1313
import jakarta.validation.constraints.Size
1414
import jakarta.validation.Valid
1515
import io.swagger.v3.oas.annotations.media.Schema
16-
import java.math.BigDecimal
1716

1817
/**
19-
*
20-
* @param avgAtk
21-
* @param dcWins
22-
* @param coins
18+
*
19+
* @param avgAtk
20+
* @param dcWins
21+
* @param coins
2322
*/
2423
data class UserMatchStatsInnerDto(
2524

2625
@Schema(example = "null", required = true, description = "")
27-
@get:JsonProperty("avgAtk", required = true) val avgAtk: java.math.BigDecimal = BigDecimal.ZERO,
26+
@get:JsonProperty("avgAtk", required = true) val avgAtk: java.math.BigDecimal,
2827

2928
@Schema(example = "null", required = true, description = "")
30-
@get:JsonProperty("dc_wins", required = true) val dcWins: java.math.BigDecimal = BigDecimal.ZERO,
29+
@get:JsonProperty("dc_wins", required = true) val dcWins: java.math.BigDecimal,
3130

3231
@Schema(example = "null", required = true, description = "")
33-
@get:JsonProperty("coins", required = true) val coins: java.math.BigDecimal = BigDecimal.ZERO
32+
@get:JsonProperty("coins", required = true) val coins: java.math.BigDecimal
3433
) {
3534

3635
}

server/src/main/kotlin/delta/codecharacter/server/code/code_revision/CodeRevisionService.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import java.util.UUID
1515
class CodeRevisionService(@Autowired private val codeRevisionRepository: CodeRevisionRepository) {
1616

1717
fun createCodeRevision(userId: UUID, createCodeRevisionRequestDto: CreateCodeRevisionRequestDto) {
18-
println(createCodeRevisionRequestDto)
1918
val (code, message, language) = createCodeRevisionRequestDto
2019
val parentCodeRevision =
2120
codeRevisionRepository

server/src/main/kotlin/delta/codecharacter/server/game/GameService.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ class GameService(
8080
destruction = destructionPercentage, coinsUsed = coinsUsed, status = gameStatus
8181
)
8282
val game = gameRepository.save(newGameEntity)
83-
if(!codeTutorialMatchRepository.findById(game.matchId).isPresent) {
84-
gameLogService.saveGameLog(game.id, gameResult.log)
85-
}
86-
else{
83+
84+
if(codeTutorialMatchRepository.findById(game.matchId).isPresent) {
8785
gameRepository.deleteById(game.id)
86+
return game
8887
}
88+
89+
gameLogService.saveGameLog(game.id, gameResult.log)
8990
return game
9091
}
9192
}

server/src/main/kotlin/delta/codecharacter/server/leaderboard/LeaderboardController.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class LeaderboardController(@Autowired private val publicUserService: PublicUser
2323
override fun getPvPLeaderboard(
2424
page: Int?,
2525
size: Int?,
26+
tier: TierTypeDto?,
2627
): ResponseEntity<List<PvPLeaderBoardResponseDto>> {
27-
return ResponseEntity.ok(publicUserService.getPvPLeaderboard(page, size))
28+
return ResponseEntity.ok(publicUserService.getPvPLeaderboard(page, size, tier))
2829
}
2930
}

server/src/main/kotlin/delta/codecharacter/server/match/MatchModeEnum.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ enum class MatchModeEnum {
55
SELFPVP,
66
MANUAL,
77
AUTO,
8+
AUTOPVP,
89
PVP
910
}

0 commit comments

Comments
 (0)