From 50e0dde7de3173b688df27ea0c8af99e6a1ffcf1 Mon Sep 17 00:00:00 2001 From: EmmyHeart Date: Mon, 13 May 2024 08:45:19 +0000 Subject: [PATCH 1/2] Added team user points --- titles/chuni/schema/profile.py | 35 ++++++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/titles/chuni/schema/profile.py b/titles/chuni/schema/profile.py index 2f8bce3..9b4d645 100644 --- a/titles/chuni/schema/profile.py +++ b/titles/chuni/schema/profile.py @@ -1,3 +1,4 @@ +import json from typing import Dict, List, Optional from sqlalchemy import Table, Column, UniqueConstraint, and_ from sqlalchemy.types import Integer, String, Boolean, JSON, BigInteger @@ -389,6 +390,7 @@ team = Table( Column("id", Integer, primary_key=True, nullable=False), Column("teamName", String(255)), Column("teamPoint", Integer), + Column("userTeamPoint", JSON), mysql_charset="utf8mb4", ) @@ -693,12 +695,36 @@ class ChuniProfileData(BaseData): # Return the rank if found, or a default rank otherwise return rank if rank is not None else 0 - # RIP scaled team ranking. Gone, but forgotten - # def get_team_rank_scaled(self, team_id: int) -> int: - - async def update_team(self, team_id: int, team_data: Dict) -> bool: + async def update_team(self, team_id: int, team_data: Dict, user_id: str, user_point_delta: int) -> bool: + # Update the team data team_data["id"] = team_id + existing_team = self.get_team_by_id(team_id) + if existing_team is None or "userTeamPoint" not in existing_team: + self.logger.warn( + f"update_team: Failed to update team! team id: {team_id}. Existing team data not found." + ) + return False + user_team_point_data = [] + if existing_team["userTeamPoint"] is not None and existing_team["userTeamPoint"] is not "": + user_team_point_data = json.loads(existing_team["userTeamPoint"]) + updated = False + + # Try to find the user in the existing data and update their points + for user_point_data in user_team_point_data: + if user_point_data["user"] == user_id: + user_point_data["userPoint"] = str(int(user_point_delta)) + updated = True + break + + # If the user was not found, add them to the data with the new points + if not updated: + user_team_point_data.append({"user": user_id, "userPoint": str(user_point_delta)}) + + # Update the team's userTeamPoint field in the team data + team_data["userTeamPoint"] = json.dumps(user_team_point_data) + + # Update the team in the database sql = insert(team).values(**team_data) conflict = sql.on_duplicate_key_update(**team_data) @@ -710,6 +736,7 @@ class ChuniProfileData(BaseData): ) return False return True + async def get_rival(self, rival_id: int) -> Optional[Row]: sql = select(profile).where(profile.c.user == rival_id) result = await self.execute(sql) -- 2.39.2 From b3c1dceec9755ac73423f3136c36081fe6409ac6 Mon Sep 17 00:00:00 2001 From: EmmyHeart Date: Mon, 13 May 2024 08:48:01 +0000 Subject: [PATCH 2/2] Add team user points --- titles/chuni/base.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/titles/chuni/base.py b/titles/chuni/base.py index 9e8a634..e53c2d2 100644 --- a/titles/chuni/base.py +++ b/titles/chuni/base.py @@ -720,9 +720,14 @@ class ChuniBase: team_id = 65535 team_name = self.game_cfg.team.team_name team_rank = 0 + team_user_point = 0 # Get user profile profile = await self.data.profile.get_profile_data(data["userId"], self.version) + + if profile is None: + return {"userId": data["userId"], "teamId": 0} + if profile and profile["teamId"]: # Get team by id team = await self.data.profile.get_team_by_id(profile["teamId"]) @@ -731,7 +736,12 @@ class ChuniBase: team_id = team["id"] team_name = team["teamName"] team_rank = await self.data.profile.get_team_rank(team["id"]) - + team_point = team["teamPoint"] + if team["userTeamPoint"] is not None and team["userTeamPoint"] is not "": + user_team_point_data = json.loads(team["userTeamPoint"]) + for user_point_data in user_team_point_data: + if user_point_data["user"] == data["userId"]: + team_user_point = int(user_point_data["userPoint"]) # Don't return anything if no team name has been defined for defaults and there is no team set for the player if not profile["teamId"] and team_name == "": return {"userId": data["userId"], "teamId": 0} @@ -741,11 +751,12 @@ class ChuniBase: "teamId": team_id, "teamRank": team_rank, "teamName": team_name, + "assaultTimeRate": 1, # TODO: Figure out assaultTime, which might be team point boost? "userTeamPoint": { "userId": data["userId"], "teamId": team_id, - "orderId": 1, - "teamPoint": 1, + "orderId": 0, + "teamPoint": team_user_point, "aggrDate": data["playDate"], }, } -- 2.39.2