feat: sync time with dailylogin server
This commit is contained in:
+61
-56
@@ -1,23 +1,26 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://dqsocial001"]
|
||||
[gd_scene format=3 uid="uid://dqsocial001"]
|
||||
|
||||
[ext_resource type="Script" path="res://scripts/ui/social_panel.gd" id="1_social"]
|
||||
[ext_resource type="Script" uid="uid://dyr5tlvds11ib" path="res://scripts/ui/social_panel.gd" id="1_social"]
|
||||
|
||||
[node name="SocialPanel" type="Control"]
|
||||
[node name="SocialPanel" type="Control" unique_id=1931784939]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_social")
|
||||
|
||||
[node name="BgOverlay" type="ColorRect" parent="."]
|
||||
[node name="BgOverlay" type="ColorRect" parent="." unique_id=680051647]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
color = Color(0, 0, 0, 0.6)
|
||||
mouse_filter = 0
|
||||
|
||||
[node name="Panel" type="PanelContainer" parent="."]
|
||||
[node name="Panel" type="PanelContainer" parent="." unique_id=49835309]
|
||||
layout_mode = 1
|
||||
anchors_preset = 8
|
||||
anchor_left = 0.5
|
||||
@@ -28,201 +31,203 @@ offset_left = -250.0
|
||||
offset_top = -310.0
|
||||
offset_right = 250.0
|
||||
offset_bottom = 310.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="VBox" type="VBoxContainer" parent="Panel"]
|
||||
[node name="VBox" type="VBoxContainer" parent="Panel" unique_id=1778361359]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Header" type="HBoxContainer" parent="Panel/VBox"]
|
||||
[node name="Header" type="HBoxContainer" parent="Panel/VBox" unique_id=760715334]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TitleLabel" type="Label" parent="Panel/VBox/Header"]
|
||||
[node name="TitleLabel" type="Label" parent="Panel/VBox/Header" unique_id=207941011]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Social"
|
||||
|
||||
[node name="CloseBtn" type="Button" parent="Panel/VBox/Header"]
|
||||
[node name="CloseBtn" type="Button" parent="Panel/VBox/Header" unique_id=1052436789]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "X"
|
||||
|
||||
[node name="HSep0" type="HSeparator" parent="Panel/VBox"]
|
||||
[node name="HSep0" type="HSeparator" parent="Panel/VBox" unique_id=2043117827]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="TabBar" type="HBoxContainer" parent="Panel/VBox"]
|
||||
[node name="TabBar" type="HBoxContainer" parent="Panel/VBox" unique_id=687086642]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SearchTabBtn" type="Button" parent="Panel/VBox/TabBar"]
|
||||
[node name="SearchTabBtn" type="Button" parent="Panel/VBox/TabBar" unique_id=827932127]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Search"
|
||||
|
||||
[node name="RequestsTabBtn" type="Button" parent="Panel/VBox/TabBar"]
|
||||
[node name="RequestsTabBtn" type="Button" parent="Panel/VBox/TabBar" unique_id=243883852]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Requests"
|
||||
|
||||
[node name="FriendsTabBtn" type="Button" parent="Panel/VBox/TabBar"]
|
||||
[node name="FriendsTabBtn" type="Button" parent="Panel/VBox/TabBar" unique_id=1723617099]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Friends"
|
||||
|
||||
[node name="DMTabBtn" type="Button" parent="Panel/VBox/TabBar"]
|
||||
[node name="DMTabBtn" type="Button" parent="Panel/VBox/TabBar" unique_id=439566194]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "DM"
|
||||
visible = false
|
||||
|
||||
[node name="HSep1" type="HSeparator" parent="Panel/VBox"]
|
||||
[node name="HSep1" type="HSeparator" parent="Panel/VBox" unique_id=549111536]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SearchView" type="VBoxContainer" parent="Panel/VBox"]
|
||||
[node name="SearchView" type="VBoxContainer" parent="Panel/VBox" unique_id=1208859643]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="SearchRow" type="HBoxContainer" parent="Panel/VBox/SearchView"]
|
||||
[node name="SearchRow" type="HBoxContainer" parent="Panel/VBox/SearchView" unique_id=773262308]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SearchInput" type="LineEdit" parent="Panel/VBox/SearchView/SearchRow"]
|
||||
[node name="SearchInput" type="LineEdit" parent="Panel/VBox/SearchView/SearchRow" unique_id=1000924330]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Search by username..."
|
||||
|
||||
[node name="SearchBtn" type="Button" parent="Panel/VBox/SearchView/SearchRow"]
|
||||
[node name="SearchBtn" type="Button" parent="Panel/VBox/SearchView/SearchRow" unique_id=93688269]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Search"
|
||||
|
||||
[node name="NoSearchResultsLabel" type="Label" parent="Panel/VBox/SearchView"]
|
||||
[node name="NoSearchResultsLabel" type="Label" parent="Panel/VBox/SearchView" unique_id=788091908]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "No users found."
|
||||
visible = false
|
||||
|
||||
[node name="SearchScroll" type="ScrollContainer" parent="Panel/VBox/SearchView"]
|
||||
[node name="SearchScroll" type="ScrollContainer" parent="Panel/VBox/SearchView" unique_id=209134848]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="SearchResultsList" type="VBoxContainer" parent="Panel/VBox/SearchView/SearchScroll"]
|
||||
[node name="SearchResultsList" type="VBoxContainer" parent="Panel/VBox/SearchView/SearchScroll" unique_id=339880904]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="SearchResultTemplate" type="HBoxContainer" parent="Panel/VBox/SearchView"]
|
||||
[node name="SearchResultTemplate" type="HBoxContainer" parent="Panel/VBox/SearchView" unique_id=1331976559]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="SRNameLabel" type="Label" parent="Panel/VBox/SearchView/SearchResultTemplate"]
|
||||
[node name="SRNameLabel" type="Label" parent="Panel/VBox/SearchView/SearchResultTemplate" unique_id=1704878305]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
|
||||
[node name="SRAddBtn" type="Button" parent="Panel/VBox/SearchView/SearchResultTemplate"]
|
||||
[node name="SRAddBtn" type="Button" parent="Panel/VBox/SearchView/SearchResultTemplate" unique_id=1934694377]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Add Friend"
|
||||
|
||||
[node name="RequestsView" type="VBoxContainer" parent="Panel/VBox"]
|
||||
[node name="RequestsView" type="VBoxContainer" parent="Panel/VBox" unique_id=1296365230]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
visible = false
|
||||
|
||||
[node name="NoRequestsLabel" type="Label" parent="Panel/VBox/RequestsView"]
|
||||
[node name="NoRequestsLabel" type="Label" parent="Panel/VBox/RequestsView" unique_id=1128340712]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "No incoming friend requests."
|
||||
visible = false
|
||||
|
||||
[node name="RequestsScroll" type="ScrollContainer" parent="Panel/VBox/RequestsView"]
|
||||
[node name="RequestsScroll" type="ScrollContainer" parent="Panel/VBox/RequestsView" unique_id=964968029]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="RequestsList" type="VBoxContainer" parent="Panel/VBox/RequestsView/RequestsScroll"]
|
||||
[node name="RequestsList" type="VBoxContainer" parent="Panel/VBox/RequestsView/RequestsScroll" unique_id=1332648515]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="RequestRowTemplate" type="HBoxContainer" parent="Panel/VBox/RequestsView"]
|
||||
[node name="RequestRowTemplate" type="HBoxContainer" parent="Panel/VBox/RequestsView" unique_id=619262910]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
[node name="RRNameLabel" type="Label" parent="Panel/VBox/RequestsView/RequestRowTemplate"]
|
||||
[node name="RRNameLabel" type="Label" parent="Panel/VBox/RequestsView/RequestRowTemplate" unique_id=1650836202]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
|
||||
[node name="RRAcceptBtn" type="Button" parent="Panel/VBox/RequestsView/RequestRowTemplate"]
|
||||
[node name="RRAcceptBtn" type="Button" parent="Panel/VBox/RequestsView/RequestRowTemplate" unique_id=1452984145]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Accept"
|
||||
|
||||
[node name="RRDeclineBtn" type="Button" parent="Panel/VBox/RequestsView/RequestRowTemplate"]
|
||||
[node name="RRDeclineBtn" type="Button" parent="Panel/VBox/RequestsView/RequestRowTemplate" unique_id=942241768]
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "Decline"
|
||||
|
||||
[node name="FriendsView" type="VBoxContainer" parent="Panel/VBox"]
|
||||
[node name="FriendsView" type="VBoxContainer" parent="Panel/VBox" unique_id=696809922]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
visible = false
|
||||
|
||||
[node name="NoFriendsLabel" type="Label" parent="Panel/VBox/FriendsView"]
|
||||
[node name="NoFriendsLabel" type="Label" parent="Panel/VBox/FriendsView" unique_id=1420717854]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "No friends yet!"
|
||||
visible = false
|
||||
|
||||
[node name="FriendScroll" type="ScrollContainer" parent="Panel/VBox/FriendsView"]
|
||||
[node name="FriendScroll" type="ScrollContainer" parent="Panel/VBox/FriendsView" unique_id=1428917844]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="FriendList" type="VBoxContainer" parent="Panel/VBox/FriendsView/FriendScroll"]
|
||||
[node name="FriendList" type="VBoxContainer" parent="Panel/VBox/FriendsView/FriendScroll" unique_id=1152435338]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="DMView" type="VBoxContainer" parent="Panel/VBox"]
|
||||
[node name="DMView" type="VBoxContainer" parent="Panel/VBox" unique_id=828807744]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
visible = false
|
||||
|
||||
[node name="DMHeader" type="HBoxContainer" parent="Panel/VBox/DMView"]
|
||||
[node name="DMHeader" type="HBoxContainer" parent="Panel/VBox/DMView" unique_id=1689887837]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="DMBackBtn" type="Button" parent="Panel/VBox/DMView/DMHeader"]
|
||||
[node name="DMBackBtn" type="Button" parent="Panel/VBox/DMView/DMHeader" unique_id=1721956547]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
text = "<- Back"
|
||||
|
||||
[node name="DMUsernameLabel" type="Label" parent="Panel/VBox/DMView/DMHeader"]
|
||||
[node name="DMUsernameLabel" type="Label" parent="Panel/VBox/DMView/DMHeader" unique_id=632301252]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
|
||||
[node name="DMLog" type="RichTextLabel" parent="Panel/VBox/DMView"]
|
||||
[node name="DMLog" type="RichTextLabel" parent="Panel/VBox/DMView" unique_id=1090451527]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
@@ -230,16 +235,16 @@ theme_override_colors/default_color = Color(0.3, 0.18, 0.1, 1)
|
||||
bbcode_enabled = true
|
||||
scroll_following = true
|
||||
|
||||
[node name="DMInputRow" type="HBoxContainer" parent="Panel/VBox/DMView"]
|
||||
[node name="DMInputRow" type="HBoxContainer" parent="Panel/VBox/DMView" unique_id=433115787]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="DMInput" type="LineEdit" parent="Panel/VBox/DMView/DMInputRow"]
|
||||
[node name="DMInput" type="LineEdit" parent="Panel/VBox/DMView/DMInputRow" unique_id=533043662]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
placeholder_text = "Type a message..."
|
||||
|
||||
[node name="DMSendBtn" type="Button" parent="Panel/VBox/DMView/DMInputRow"]
|
||||
[node name="DMSendBtn" type="Button" parent="Panel/VBox/DMView/DMInputRow" unique_id=695010640]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.3, 0.18, 0.1, 1)
|
||||
|
||||
@@ -29,7 +29,7 @@ signal closed
|
||||
# Tab: Daily Rewards
|
||||
@onready var month_option_btn := %MonthOptionBtn as OptionButton
|
||||
@onready var days_grid := %DaysGrid as GridContainer
|
||||
@onready var day_config_template := %DayConfigTemplate as VBoxContainer
|
||||
@onready var day_config_template := %DayConfigTemplate as PanelContainer
|
||||
@onready var load_dr_btn := %LoadDRConfigBtn as Button
|
||||
@onready var save_dr_btn := %SaveDRConfigBtn as Button
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ signal closed
|
||||
@onready var reward_name_label = $MainWindow/HBox/RightCol/MiddleDetails/VBox/RewardName
|
||||
|
||||
var _month_rewards: Array = []
|
||||
var _claimed_days: int = 0
|
||||
var _claimed_days: Array = []
|
||||
var _today_index: int = 0
|
||||
var _server_month: int = 1
|
||||
var _can_claim: bool = false
|
||||
var _today: String = ""
|
||||
|
||||
@@ -25,10 +27,6 @@ func _ready():
|
||||
)
|
||||
claim_btn.pressed.connect(_on_claim_pressed)
|
||||
|
||||
var time_dict = Time.get_datetime_dict_from_system()
|
||||
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
||||
month_label.text = months[time_dict.month - 1] + " Sign-in"
|
||||
|
||||
func show_panel():
|
||||
show()
|
||||
status_label.text = "Loading rewards..."
|
||||
@@ -51,9 +49,20 @@ func _fetch_state():
|
||||
var data = json.get_data()
|
||||
_month_rewards = data.get("month_rewards", [])
|
||||
var state = data.get("state", {})
|
||||
_claimed_days = state.get("claimed_days", 0)
|
||||
|
||||
var claimed_list = state.get("claimed_days", [])
|
||||
_claimed_days.clear()
|
||||
for item in claimed_list:
|
||||
_claimed_days.append(int(item))
|
||||
|
||||
_can_claim = data.get("can_claim_today", false)
|
||||
_today = data.get("today_date", "")
|
||||
_today_index = data.get("today_index", 0)
|
||||
_server_month = data.get("server_month", 1)
|
||||
|
||||
var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
|
||||
if _server_month >= 1 and _server_month <= 12:
|
||||
month_label.text = months[_server_month - 1] + " Sign-in"
|
||||
|
||||
_update_ui()
|
||||
else:
|
||||
@@ -73,8 +82,8 @@ func _update_ui():
|
||||
|
||||
var today_reward_amount = 0
|
||||
var today_reward_type = "star"
|
||||
if _claimed_days < _month_rewards.size():
|
||||
var r = _month_rewards[_claimed_days]
|
||||
if _today_index < _month_rewards.size():
|
||||
var r = _month_rewards[_today_index]
|
||||
if typeof(r) == TYPE_DICTIONARY:
|
||||
today_reward_amount = r.get("amount", 0)
|
||||
today_reward_type = r.get("type", "star")
|
||||
@@ -99,8 +108,8 @@ func _update_ui():
|
||||
|
||||
var r_slot_data = _get_reward_display_data(reward_type)
|
||||
|
||||
var is_claimed = i < _claimed_days
|
||||
var is_today = i == _claimed_days
|
||||
var is_claimed = _claimed_days.has(i)
|
||||
var is_today = i == _today_index
|
||||
|
||||
var slot = slot_template.duplicate()
|
||||
slot.visible = true
|
||||
|
||||
@@ -608,15 +608,27 @@ function rpcClaimDailyReward(ctx, logger, nk, payload) {
|
||||
var now = new Date();
|
||||
var currentMonth = now.toISOString().substring(5, 7); // e.g. "05"
|
||||
var todayStr = now.toISOString().substring(0, 10);
|
||||
var todayIndex = now.getUTCDate() - 1; // 0 to 30
|
||||
|
||||
var stateObjs = nk.storageRead([{ collection: "daily_rewards", key: "state", userId: ctx.userId }]);
|
||||
var state = { claimed_days: 0, last_claim_date: "", month: "" };
|
||||
var state = { claimed_days: [], last_claim_date: "", month: "" };
|
||||
if (stateObjs && stateObjs.length > 0) {
|
||||
state = stateObjs[0].value;
|
||||
var val = stateObjs[0].value;
|
||||
state.last_claim_date = val.last_claim_date || "";
|
||||
state.month = val.month || "";
|
||||
if (typeof val.claimed_days === 'number') {
|
||||
var arr = [];
|
||||
for (var i=0; i<val.claimed_days; i++) arr.push(i);
|
||||
state.claimed_days = arr;
|
||||
} else if (Array.isArray(val.claimed_days)) {
|
||||
state.claimed_days = val.claimed_days;
|
||||
} else {
|
||||
state.claimed_days = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (state.month !== currentMonth) {
|
||||
state.claimed_days = 0;
|
||||
state.claimed_days = [];
|
||||
state.month = currentMonth;
|
||||
}
|
||||
|
||||
@@ -638,10 +650,13 @@ function rpcClaimDailyReward(ctx, logger, nk, payload) {
|
||||
}
|
||||
}
|
||||
|
||||
var dayIndex = state.claimed_days;
|
||||
var dayIndex = todayIndex;
|
||||
if (dayIndex >= monthRewards.length) {
|
||||
throw new Error("Already claimed all rewards for this month");
|
||||
}
|
||||
if (state.claimed_days.indexOf(dayIndex) !== -1) {
|
||||
throw new Error("Already claimed today's reward");
|
||||
}
|
||||
|
||||
var rewardData = monthRewards[dayIndex];
|
||||
if (typeof rewardData === "number") {
|
||||
@@ -672,7 +687,7 @@ function rpcClaimDailyReward(ctx, logger, nk, payload) {
|
||||
}]);
|
||||
}
|
||||
|
||||
state.claimed_days++;
|
||||
state.claimed_days.push(dayIndex);
|
||||
state.last_claim_date = todayStr;
|
||||
|
||||
nk.storageWrite([{
|
||||
@@ -684,7 +699,7 @@ function rpcClaimDailyReward(ctx, logger, nk, payload) {
|
||||
permissionWrite: 0
|
||||
}]);
|
||||
|
||||
return JSON.stringify({ success: true, reward_type: rewardType, reward_amount: rewardAmount, day: state.claimed_days });
|
||||
return JSON.stringify({ success: true, reward_type: rewardType, reward_amount: rewardAmount, day: dayIndex + 1 });
|
||||
}
|
||||
|
||||
function rpcGetDailyRewardState(ctx, logger, nk, payload) {
|
||||
@@ -692,14 +707,26 @@ function rpcGetDailyRewardState(ctx, logger, nk, payload) {
|
||||
var now = new Date();
|
||||
var currentMonth = now.toISOString().substring(5, 7); // e.g. "05"
|
||||
var todayStr = now.toISOString().substring(0, 10);
|
||||
var todayIndex = now.getUTCDate() - 1;
|
||||
|
||||
var stateObjs = nk.storageRead([{ collection: "daily_rewards", key: "state", userId: ctx.userId }]);
|
||||
var state = { claimed_days: 0, last_claim_date: "", month: "" };
|
||||
var state = { claimed_days: [], last_claim_date: "", month: "" };
|
||||
if (stateObjs && stateObjs.length > 0) {
|
||||
state = stateObjs[0].value;
|
||||
var val = stateObjs[0].value;
|
||||
state.last_claim_date = val.last_claim_date || "";
|
||||
state.month = val.month || "";
|
||||
if (typeof val.claimed_days === 'number') {
|
||||
var arr = [];
|
||||
for (var i=0; i<val.claimed_days; i++) arr.push(i);
|
||||
state.claimed_days = arr;
|
||||
} else if (Array.isArray(val.claimed_days)) {
|
||||
state.claimed_days = val.claimed_days;
|
||||
} else {
|
||||
state.claimed_days = [];
|
||||
}
|
||||
}
|
||||
if (state.month !== currentMonth) {
|
||||
state.claimed_days = 0;
|
||||
state.claimed_days = [];
|
||||
state.month = currentMonth;
|
||||
}
|
||||
|
||||
@@ -719,8 +746,10 @@ function rpcGetDailyRewardState(ctx, logger, nk, payload) {
|
||||
return JSON.stringify({
|
||||
state: state,
|
||||
month_rewards: monthRewards,
|
||||
can_claim_today: state.last_claim_date !== todayStr && state.claimed_days < monthRewards.length,
|
||||
today_date: todayStr
|
||||
can_claim_today: state.last_claim_date !== todayStr && state.claimed_days.indexOf(todayIndex) === -1 && todayIndex < monthRewards.length,
|
||||
today_date: todayStr,
|
||||
today_index: todayIndex,
|
||||
server_month: now.getUTCMonth() + 1
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user