Im searching a way to add daily rewards.
Or you can use GeneralLog to check if we've already had the Daily rewardQuote:
how val already wrote , write a new function for the daily reward , which works like this :
-check last given reward (use a new table on db for this)
-if LastRewardDate != DateOfToday then -> give out the reward to player and set the dateoftoday as LastRewardDate (in db)
and put this function to the OnPlayerConnect event ...
this is maybe not the best solution but it works :)
if (Session.Character.LastLogin.Date != DateTime.Now.Date)
{
Session.Character.SpAdditionPoint += Session.Character.SpPoint;
Session.Character.SpPoint = 10000;
short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 };
byte[] rewardCount = { 1, 2, 3, 4, 5 };
int rnd = new Random().Next(rewardItems.Length - 1);
Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]);
Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14);
}
Session.Character.LastLogin = DateTime.Now;
var LastDaily = Session.Character.GeneralLogs.LastOrDefault(s => s.LogData == "World" && s.LogType == "Daily" && s.CharacterId == Session.Character.CharacterId && s.Timestamp.Day == DateTime.Now.Day);
if(LastDaily == null)
{
//Give your item
var GeneralLogAdd = new GeneralLogDTO
{
LogData = "World",
LogType = "Daily",
CharacterId = Session.Character.CharacterId,
AccountId = Session.Account.AccountId,
Timestamp = DateTime.Now
};
DAOFactory.GeneralLogDAO.InsertOrUpdate(GeneralLogAdd);
}
nice °-° , can u maybe explain the first line a lil bit more there are some strange things i cant understand there ...Quote:
Code:var LastDaily = Session.Character.GeneralLogs.LastOrDefault(s => s.LogData == "World" && s.LogType == "Daily" && s.CharacterId == Session.Character.CharacterId && s.Timestamp.Day == DateTime.Now.Day); if(LastDaily == null) { //Give your item var GeneralLogAdd = new GeneralLogDTO { LogData = "World", LogType = "Daily", CharacterId = Session.Character.CharacterId, AccountId = Session.Account.AccountId, Timestamp = DateTime.Now }; DAOFactory.GeneralLogDAO.InsertOrUpdate(GeneralLogAdd); }
Quote:
:kappa:Code:if (Session.Character.LastLogin.Date != DateTime.Now.Date) { Session.Character.SpAdditionPoint += Session.Character.SpPoint; Session.Character.SpPoint = 10000; short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 }; byte[] rewardCount = { 1, 2, 3, 4, 5 }; int rnd = new Random().Next(rewardItems.Length); Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]); Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14); } Session.Character.LastLogin = DateTime.Now;
Btw fix ur crash ;) (IndexOutOfRangeException)Quote:
:kappa:Code:if (Session.Character.LastLogin.Date != DateTime.Now.Date) { Session.Character.SpAdditionPoint += Session.Character.SpPoint; Session.Character.SpPoint = 10000; short[] rewardItems = { 1011, 1011, 1011, 1011, 1011 }; byte[] rewardCount = { 1, 2, 3, 4, 5 }; int rnd = new Random().Next(rewardItems.Length); Session.Character.GiftAdd(rewardItems[rnd], rewardCount[rnd]); Session.Character.GenerateSay($"You received your daily reward: {ServerManager.GetItem(rewardItems[rnd]).Name} x {rewardCount[rnd]}", 14); } Session.Character.LastLogin = DateTime.Now;
int rnd = new Random().Next(rewardItems.Length - 1);