天气系统

This commit is contained in:
2025-07-14 11:58:33 +08:00
parent 98de447cb9
commit 106a69c89e
27 changed files with 842 additions and 217 deletions

View File

@@ -849,7 +849,9 @@ class TCPGameServer(TCPServer):
# 检查并更新体力值
stamina_updated = self._check_and_update_stamina(player_data)
if stamina_updated:
self.log('INFO', f"玩家 {username} 体力值已更新:{player_data.get('体力值', 20)}", 'SERVER')
stamina_system = player_data.get("体力系统", {})
current_stamina = stamina_system.get("当前体力值", 20)
self.log('INFO', f"玩家 {username} 体力值已更新:{current_stamina}", 'SERVER')
# 检查并更新每日点赞次数
likes_updated = self._check_and_update_daily_likes(player_data)
@@ -864,6 +866,9 @@ class TCPGameServer(TCPServer):
# 检查并清理新手礼包历史数据
self._cleanup_new_player_gift_history(player_data)
# 检查并清理体力系统历史数据
self._cleanup_stamina_system_history(player_data)
# 检查并更新已存在玩家的注册时间
self._check_and_update_register_time(player_data, username)
@@ -5103,6 +5108,62 @@ class TCPGameServer(TCPServer):
self.log('INFO', f"已清理玩家数据中的旧英文新手礼包格式", 'SERVER')
def _cleanup_stamina_system_history(self, player_data):
"""清理旧的体力系统数据,迁移到新的"体力系统"对象"""
if "体力值" in player_data or "体力上次刷新时间" in player_data or "体力上次恢复时间" in player_data:
# 加载体力系统配置
stamina_config = self._load_stamina_config()
max_stamina = stamina_config.get("最大体力值", 20)
# 保存旧的体力数据
old_stamina = player_data.get("体力值", 20)
old_refresh_time = player_data.get("体力上次刷新时间", "")
old_recovery_time = player_data.get("体力上次恢复时间", 0)
# 创建新的体力系统对象
if "体力系统" not in player_data:
player_data["体力系统"] = {}
stamina_system = player_data["体力系统"]
# 迁移数据到新格式
stamina_system["当前体力值"] = old_stamina
stamina_system["最大体力值"] = max_stamina
stamina_system["上次刷新时间"] = old_refresh_time
stamina_system["上次恢复时间"] = old_recovery_time
# 移除旧的体力数据
if "体力值" in player_data:
del player_data["体力值"]
if "体力上次刷新时间" in player_data:
del player_data["体力上次刷新时间"]
if "体力上次恢复时间" in player_data:
del player_data["体力上次恢复时间"]
self.log('INFO', f"已清理玩家数据中的旧体力系统格式,迁移到新的体力系统对象", 'SERVER')
def _load_stamina_config(self):
"""加载体力系统配置"""
try:
config_path = os.path.join(os.path.dirname(__file__), "config", "stamina_config.json")
with open(config_path, 'r', encoding='utf-8') as file:
config_data = json.load(file)
return config_data.get("体力系统配置", {})
except FileNotFoundError:
self.log('WARNING', f"体力系统配置文件未找到,使用默认配置", 'SERVER')
return {
"最大体力值": 20,
"每小时恢复体力": 1,
"恢复间隔秒数": 3600,
"新玩家初始体力": 20
}
except json.JSONDecodeError as e:
self.log('ERROR', f"体力系统配置文件格式错误: {e}", 'SERVER')
return {}
except Exception as e:
self.log('ERROR', f"加载体力系统配置时发生错误: {e}", 'SERVER')
return {}
#==========================点赞玩家处理==========================
@@ -5131,37 +5192,50 @@ class TCPGameServer(TCPServer):
current_time = time.time()
current_date = datetime.datetime.now().strftime("%Y-%m-%d")
# 初始化体力值相关字段
if "体力值" not in player_data:
player_data["体力值"] = 20
if "体力上次刷新时间" not in player_data:
player_data["体力上次刷新时间"] = current_date
if "体力上次恢复时间" not in player_data:
player_data["体力上次恢复时间"] = current_time
# 加载体力系统配置
stamina_config = self._load_stamina_config()
max_stamina = stamina_config.get("最大体力值", 20)
recovery_amount = stamina_config.get("每小时恢复体力", 1)
recovery_interval = stamina_config.get("恢复间隔秒数", 3600)
initial_stamina = stamina_config.get("新玩家初始体力", 20)
# 获取或创建体力系统对象
if "体力系统" not in player_data:
player_data["体力系统"] = {
"当前体力值": initial_stamina,
"最大体力值": max_stamina,
"上次刷新时间": current_date,
"上次恢复时间": current_time
}
stamina_system = player_data["体力系统"]
# 确保最大体力值与配置同步
stamina_system["最大体力值"] = max_stamina
# 检查是否需要每日重置
last_refresh_date = player_data.get("体力上次刷新时间", "")
last_refresh_date = stamina_system.get("上次刷新时间", "")
if last_refresh_date != current_date:
# 新的一天,重置体力值
player_data["体力值"] = 20
player_data["体力上次刷新时间"] = current_date
player_data["体力上次恢复时间"] = current_time
stamina_system["当前体力值"] = max_stamina
stamina_system["上次刷新时间"] = current_date
stamina_system["上次恢复时间"] = current_time
return True # 发生了重置
# 检查每小时恢复
last_recovery_time = player_data.get("体力上次恢复时间", current_time)
last_recovery_time = stamina_system.get("上次恢复时间", current_time)
time_diff = current_time - last_recovery_time
# 如果超过1小时3600秒,恢复体力值
if time_diff >= 3600:
hours_passed = int(time_diff // 3600)
current_stamina = player_data.get("体力值", 0)
# 如果超过恢复间隔时间,恢复体力值
if time_diff >= recovery_interval:
recovery_cycles = int(time_diff // recovery_interval)
current_stamina = stamina_system.get("当前体力值", 0)
# 体力值恢复,但不能超过20
new_stamina = min(20, current_stamina + hours_passed)
# 体力值恢复,但不能超过最大值
new_stamina = min(max_stamina, current_stamina + (recovery_cycles * recovery_amount))
if new_stamina > current_stamina:
player_data["体力值"] = new_stamina
player_data["体力上次恢复时间"] = current_time
stamina_system["当前体力值"] = new_stamina
stamina_system["上次恢复时间"] = current_time
return True # 发生了恢复
return False # 没有变化
@@ -5169,18 +5243,20 @@ class TCPGameServer(TCPServer):
#消耗体力值
def _consume_stamina(self, player_data, amount, action_name):
"""消耗体力值"""
current_stamina = player_data.get("体力", 20)
stamina_system = player_data.get("体力系统", {})
current_stamina = stamina_system.get("当前体力值", 20)
if current_stamina < amount:
return False, f"体力值不足!{action_name}需要 {amount} 点体力,当前体力:{current_stamina}"
player_data["体力值"] = current_stamina - amount
return True, f"消耗 {amount} 点体力,剩余体力:{player_data['体力值']}"
stamina_system["当前体力值"] = current_stamina - amount
return True, f"消耗 {amount} 点体力,剩余体力:{stamina_system['当前体力值']}"
#检查体力值是否足够
def _check_stamina_sufficient(self, player_data, amount):
"""检查体力值是否足够"""
current_stamina = player_data.get("体力", 20)
stamina_system = player_data.get("体力系统", {})
current_stamina = stamina_system.get("当前体力值", 20)
return current_stamina >= amount
def _check_and_update_register_time(self, player_data, username):
@@ -5437,6 +5513,9 @@ class TCPGameServer(TCPServer):
last_login_timestamp = self._parse_login_time_to_timestamp(last_login_str)
# 获取所需的玩家信息
stamina_system = player_data.get("体力系统", {})
current_stamina = stamina_system.get("当前体力值", 20)
player_info = {
"user_name": player_data.get("user_name", account_id),
"player_name": player_data.get("player_name", player_data.get("user_name", account_id)),
@@ -5444,7 +5523,7 @@ class TCPGameServer(TCPServer):
"level": player_data.get("level", 1),
"money": player_data.get("money", 0),
"experience": player_data.get("experience", 0),
"体力值": player_data.get("体力值", 20),
"体力值": current_stamina,
"seed_count": seed_count,
"last_login_time": last_login_str,
"last_login_timestamp": last_login_timestamp,
@@ -5591,6 +5670,9 @@ class TCPGameServer(TCPServer):
self._check_and_fix_wisdom_tree_config(target_player_data, target_username)
# 返回目标玩家的农场数据(只返回可见的数据,不包含敏感信息如密码)
target_stamina_system = target_player_data.get("体力系统", {})
target_current_stamina = target_stamina_system.get("当前体力值", 20)
safe_player_data = {
"user_name": target_player_data.get("user_name", target_username),
"player_name": target_player_data.get("player_name", target_username),
@@ -5598,7 +5680,7 @@ class TCPGameServer(TCPServer):
"level": target_player_data.get("level", 1),
"money": target_player_data.get("money", 0),
"experience": target_player_data.get("experience", 0),
"体力值": target_player_data.get("体力值", 20),
"体力值": target_current_stamina,
"farm_lots": target_player_data.get("farm_lots", []),
"player_bag": target_player_data.get("player_bag", []),
"作物仓库": target_player_data.get("作物仓库", []),
@@ -5653,6 +5735,9 @@ class TCPGameServer(TCPServer):
self.log('INFO', f"玩家 {username} 返回了自己的农场", 'SERVER')
# 返回玩家自己的农场数据
my_stamina_system = player_data.get("体力系统", {})
my_current_stamina = my_stamina_system.get("当前体力值", 20)
return self.send_data(client_id, {
"type": "return_my_farm_response",
"success": True,
@@ -5664,7 +5749,7 @@ class TCPGameServer(TCPServer):
"level": player_data.get("level", 1),
"money": player_data.get("money", 0),
"experience": player_data.get("experience", 0),
"体力值": player_data.get("体力值", 20),
"体力值": my_current_stamina,
"farm_lots": player_data.get("farm_lots", []),
"player_bag": player_data.get("player_bag", []),
"宠物背包": player_data.get("宠物背包", []),

View File

@@ -0,0 +1,23 @@
{
"体力系统配置": {
"最大体力值": 20,
"每小时恢复体力": 1,
"恢复间隔秒数": 3600,
"新玩家初始体力": 20,
"体力消耗": {
"浇水": 1,
"施肥": 1,
"挖地": 2,
"收获": 1,
"种植": 1,
"除草": 1,
"偷菜": 2
},
"提示消息": {
"体力不足": "体力值不足!当前体力:{current_stamina},需要:{required_stamina}",
"体力恢复": "体力已恢复到:{current_stamina}",
"体力重置": "新的一天,体力已重置为:{current_stamina}",
"体力消耗": "消耗 {amount} 点体力,剩余体力:{remaining_stamina}"
}
}
}

View File

@@ -1,32 +1,32 @@
{
"experience": 2926,
"experience": 3039,
"level": 32,
"money": 1250116,
"money": 1224518,
"farm_name": "柚大青の小农场",
"player_name": "柚大青",
"user_name": "2143323382",
"user_password": "tyh@19900420",
"last_login_time": "2025年07月12日23时02分19秒",
"total_login_time": "5时14分13秒",
"last_login_time": "2025年07月14日08时03分08秒",
"total_login_time": "5时36分14秒",
"farm_lots": [
{
"crop_type": "",
"grow_time": 0,
"crop_type": "番茄",
"grow_time": 724,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 650,
"is_planted": true,
"max_grow_time": 720,
"已浇水": false,
"已施肥": false,
"土地等级": 2
"土地等级": 4
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "小麦",
"grow_time": 300,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 720,
"is_planted": true,
"max_grow_time": 300,
"已浇水": false,
"已施肥": false,
"土地等级": 2
@@ -43,45 +43,45 @@
"土地等级": 3
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "龙果",
"grow_time": 14492,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"is_planted": true,
"max_grow_time": 14400,
"已浇水": false,
"已施肥": false,
"土地等级": 4
},
{
"crop_type": "小麦",
"grow_time": 318,
"is_dead": false,
"is_diged": true,
"is_planted": true,
"max_grow_time": 300,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "玉米",
"grow_time": 918,
"is_dead": false,
"is_diged": true,
"is_planted": true,
"max_grow_time": 900,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "小麦",
"grow_time": 316,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 3000,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 7800,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 900,
"is_planted": true,
"max_grow_time": 300,
"已浇水": false,
"已施肥": false,
"土地等级": 1
@@ -120,78 +120,78 @@
"土地等级": 0
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "小麦",
"grow_time": 300,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 240,
"已浇水": false,
"已施肥": false,
"土地等级": 2
},
{
"crop_type": "",
"grow_time": 0,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"is_planted": true,
"max_grow_time": 300,
"已浇水": false,
"已施肥": false,
"土地等级": 2
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "玉米",
"grow_time": 912,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 600,
"is_planted": true,
"max_grow_time": 900,
"已浇水": false,
"已施肥": false,
"土地等级": 2
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "杂交树1",
"grow_time": 21632,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 720,
"is_planted": true,
"max_grow_time": 21600,
"已浇水": false,
"已施肥": false,
"土地等级": 2
},
{
"crop_type": "小麦",
"grow_time": 314,
"is_dead": false,
"is_diged": true,
"is_planted": true,
"max_grow_time": 300,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "稻谷",
"grow_time": 614,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 7000,
"is_planted": true,
"max_grow_time": 600,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "胡萝卜",
"grow_time": 240,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"is_planted": true,
"max_grow_time": 240,
"已浇水": false,
"已施肥": false,
"土地等级": 1
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "花椰菜",
"grow_time": 1334,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 650,
"is_planted": true,
"max_grow_time": 1320,
"已浇水": false,
"已施肥": false,
"土地等级": 1
@@ -230,38 +230,38 @@
"土地等级": 0
},
{
"crop_type": "",
"grow_time": 0,
"crop_type": "番茄",
"grow_time": 726,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 650,
"已浇水": false,
"已施肥": false,
"土地等级": 0
},
{
"crop_type": "",
"grow_time": 0,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"max_grow_time": 240,
"已浇水": false,
"已施肥": false,
"土地等级": 0
},
{
"crop_type": "",
"grow_time": 0,
"is_dead": false,
"is_diged": true,
"is_planted": false,
"is_planted": true,
"max_grow_time": 720,
"已浇水": false,
"已施肥": false,
"土地等级": 0
},
{
"crop_type": "土豆",
"grow_time": 486,
"is_dead": false,
"is_diged": true,
"is_planted": true,
"max_grow_time": 480,
"已浇水": false,
"已施肥": false,
"土地等级": 0
},
{
"crop_type": "土豆",
"grow_time": 486,
"is_dead": false,
"is_diged": true,
"is_planted": true,
"max_grow_time": 480,
"已浇水": false,
"已施肥": false,
"土地等级": 0
},
{
"crop_type": "",
"grow_time": 0,
@@ -564,32 +564,32 @@
{
"name": "稻谷",
"quality": "普通",
"count": 2
"count": 1
},
{
"name": "土豆",
"quality": "普通",
"count": 3
"count": 6
},
{
"name": "小麦",
"quality": "普通",
"count": 5
"count": 8
},
{
"name": "胡萝卜",
"quality": "普通",
"count": 5
"count": 7
},
{
"name": "玉米",
"quality": "优良",
"count": 6
"count": 4
},
{
"name": "番茄",
"quality": "普通",
"count": 5
"count": 3
},
{
"name": "辣椒",
@@ -604,7 +604,7 @@
{
"name": "花椰菜",
"quality": "优良",
"count": 2
"count": 1
},
{
"name": "葡萄",
@@ -634,7 +634,7 @@
{
"name": "龙果",
"quality": "稀有",
"count": 2
"count": 1
},
{
"name": "松露",
@@ -646,11 +646,6 @@
"quality": "传奇",
"count": 1
},
{
"name": "杂交树1",
"quality": "传奇",
"count": 1
},
{
"name": "杂交树2",
"quality": "传奇",
@@ -658,9 +653,6 @@
}
],
"last_water_reset_date": "2025-06-05",
"体力值": 20,
"体力上次刷新时间": "2025-07-12",
"体力上次恢复时间": 1752323298.9468062,
"注册时间": "2025年05月21日15时00分00秒",
"个人简介": "其实我是一个梨子,真的,不骗你",
"作物仓库": [],
@@ -816,29 +808,27 @@
"当前生命值": 106
},
"签到历史": {
"2025年07月12日21时05分47秒": "金币249 经验75 土豆x3"
"2025年07月12日21时05分47秒": "金币249 经验75 土豆x3",
"2025年07月13日07时26分04秒": "金币302 经验63 土豆x5 小麦x3"
},
"在线礼包": {
"当前日期": "2025-07-12",
"今日在线时长": 100008.91207242012,
"已领取礼包": [
"1分钟",
"3分钟",
"5分钟",
"10分钟",
"30分钟",
"1小时",
"3小时",
"5小时"
],
"登录时间": 1752329209.0102558
"当前日期": "2025-07-14",
"今日在线时长": 0.0,
"已领取礼包": [],
"登录时间": 1752451388.1583223
},
"点赞系统": {
"今日剩余点赞次数": 0,
"点赞上次刷新时间": "2025-07-12"
"今日剩余点赞次数": 10,
"点赞上次刷新时间": "2025-07-14"
},
"新手礼包": {
"已领取": true,
"领取时间": "2025-07-12 23:02:25"
},
"体力系统": {
"当前体力值": 20,
"最大体力值": 20,
"上次刷新时间": "2025-07-14",
"上次恢复时间": 1752451388.157905
}
}