-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Added Traveler's birthday gift system #2549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sitxovski
wants to merge
1
commit into
Grasscutters:development
Choose a base branch
from
sitxovski:feature/traveler-birthday-gift-system
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+141
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
137 changes: 137 additions & 0 deletions
137
src/main/java/emu/grasscutter/game/mail/BirthdayMailSystem.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package emu.grasscutter.game.mail; | ||
|
|
||
| import emu.grasscutter.Grasscutter; | ||
| import emu.grasscutter.game.player.Player; | ||
| import emu.grasscutter.game.props.ActionReason; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.time.ZoneId; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * System for handling birthday gifts for players. | ||
| * Checks if today is a player's birthday and sends a gift if it is. | ||
| */ | ||
| public class BirthdayMailSystem { | ||
| // Mail content constants | ||
| private static final String MAIL_TITLE = "Best Wishes on Your Birthday"; | ||
| private static final String MAIL_CONTENT = "Happy Birthday, Traveler! Please find your gift attached to this message. Thank you for all your support. We wish you a brighter future, no matter what you are going through."; | ||
| private static final String MAIL_SENDER = "Server"; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider using the configured server bot nickname instead of hardcoding the value |
||
|
|
||
| // Gift item ID - Cake for Traveler | ||
| private static final int BIRTHDAY_GIFT_ID = 118008; | ||
| private static final int BIRTHDAY_GIFT_COUNT = 1; | ||
|
|
||
| /** | ||
| * Checks if today is the player's birthday and sends a gift if it is. | ||
| * Should be called when a player logs in. | ||
| * | ||
| * @param player The player to check | ||
| */ | ||
| public static void checkBirthdayAndSendGift(Player player) { | ||
| if (player == null || !player.hasBirthday()) { | ||
| return; | ||
| } | ||
|
|
||
| // Get current date | ||
| LocalDate currentDate = LocalDate.now(ZoneId.systemDefault()); | ||
| int currentDay = currentDate.getDayOfMonth(); | ||
| int currentMonth = currentDate.getMonthValue(); | ||
|
|
||
| // Get player's birthday | ||
| int birthdayDay = player.getBirthday().getDay(); | ||
| int birthdayMonth = player.getBirthday().getMonth(); | ||
|
|
||
| // Check if today is the player's birthday | ||
| if (currentDay == birthdayDay && currentMonth == birthdayMonth) { | ||
| // Check if player already received birthday gift today | ||
| if (!hasReceivedBirthdayGiftToday(player)) { | ||
| sendBirthdayGift(player); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Sends a birthday gift to the player. | ||
| * | ||
| * @param player The player to send the gift to | ||
| */ | ||
| private static void sendBirthdayGift(Player player) { | ||
| // Create mail content | ||
| Mail.MailContent mailContent = new Mail.MailContent(MAIL_TITLE, MAIL_CONTENT, MAIL_SENDER); | ||
|
|
||
| // Create mail item list with birthday cake | ||
| List<Mail.MailItem> mailItems = new ArrayList<>(); | ||
| mailItems.add(new Mail.MailItem(BIRTHDAY_GIFT_ID, BIRTHDAY_GIFT_COUNT)); | ||
|
|
||
| // Calculate expiration time (7 days from now) | ||
| long expireTime = System.currentTimeMillis() / 1000 + (7 * 24 * 60 * 60); | ||
|
|
||
| // Create mail | ||
| Mail birthdayMail = new Mail(mailContent, mailItems, expireTime); | ||
|
|
||
| // Send mail to player | ||
| player.getMailHandler().sendMail(birthdayMail); | ||
|
|
||
| // Log the action | ||
| Grasscutter.getLogger().info("Birthday gift sent to " + player.getNickname() + " (UID: " + player.getUid() + ")"); | ||
|
|
||
| // Mark that player received birthday gift today | ||
| markBirthdayGiftReceived(player); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the player has already received a birthday gift today. | ||
| * Uses player properties to store this information. | ||
| * | ||
| * @param player The player to check | ||
| * @return True if the player has received a birthday gift today, false otherwise | ||
| */ | ||
| private static boolean hasReceivedBirthdayGiftToday(Player player) { | ||
| // Get current date as a string in format YYYYMMDD | ||
| LocalDate currentDate = LocalDate.now(ZoneId.systemDefault()); | ||
| String dateString = String.format("%04d%02d%02d", | ||
| currentDate.getYear(), | ||
| currentDate.getMonthValue(), | ||
| currentDate.getDayOfMonth()); | ||
|
|
||
| // Convert to integer for storage in player properties | ||
| int dateValue = Integer.parseInt(dateString); | ||
|
|
||
| // Check if player has a property for the last birthday gift date | ||
| Integer lastGiftDate = player.getProperties().get(PlayerProperties.LAST_BIRTHDAY_GIFT_DATE); | ||
|
|
||
| return lastGiftDate != null && lastGiftDate == dateValue; | ||
| } | ||
|
|
||
| /** | ||
| * Marks that the player has received a birthday gift today. | ||
| * | ||
| * @param player The player to mark | ||
| */ | ||
| private static void markBirthdayGiftReceived(Player player) { | ||
| // Get current date as a string in format YYYYMMDD | ||
| LocalDate currentDate = LocalDate.now(ZoneId.systemDefault()); | ||
| String dateString = String.format("%04d%02d%02d", | ||
| currentDate.getYear(), | ||
| currentDate.getMonthValue(), | ||
| currentDate.getDayOfMonth()); | ||
|
|
||
| // Convert to integer for storage in player properties | ||
| int dateValue = Integer.parseInt(dateString); | ||
|
|
||
| // Store the date in player properties | ||
| player.getProperties().put(PlayerProperties.LAST_BIRTHDAY_GIFT_DATE, dateValue); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not the thing to store in player properties |
||
|
|
||
| // Save player data | ||
| player.save(); | ||
| } | ||
|
|
||
| /** | ||
| * Constants for player properties related to birthday gifts. | ||
| */ | ||
| private static class PlayerProperties { | ||
| public static final int LAST_BIRTHDAY_GIFT_DATE = 10001; // Custom property ID | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part should be localized using the language system; not all players speak English