public bool UnlockAward(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(false); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); bool new_unlock = false; if (award == null) { PlayerAwardDict[player.handle].Add(new PlayerAward(ID, AwardDict[ID].RequiredProgress, true, DateTime.Now)); new_unlock = true; } else { if (!award.Unlocked) { new_unlock = true; award.Unlocked = true; award.UnlockDate = DateTime.Now; } } SavePlayer(player); if (new_unlock) { player.triggerEvent("Award_Unlocked", API.toJson(AwardDict[ID])); OnPlayerUnlockAward(player, ID, AwardDict[ID].Name); } return(true); }
public bool SetAwardProgress(Client player, string ID, int progress) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(false); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { PlayerAward new_award = null; bool unlocked = false; if (progress >= AwardDict[ID].RequiredProgress) { new_award = new PlayerAward(ID, progress, true, DateTime.Now); unlocked = true; } else { new_award = new PlayerAward(ID, progress, false, null); } PlayerAwardDict[player.handle].Add(new_award); if (unlocked) { UnlockAward(player, ID); } else { SavePlayer(player); } } else { award.Progress = progress; if (award.Progress >= AwardDict[ID].RequiredProgress) { UnlockAward(player, ID); } else { SavePlayer(player); } } return(true); }
public DateTime?GetAwardUnlockDate(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(null); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { return(null); } return(award.UnlockDate); }
public bool IsAwardUnlocked(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(false); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { return(false); } return(award.Unlocked); }
public int GetAwardProgress(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(0); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { return(0); } return(award.Progress); }
public bool RemoveAward(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(false); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { return(false); } PlayerAwardDict[player.handle].Remove(award); SavePlayer(player); return(true); }
public bool LockAward(Client player, string ID) { if (!AwardDict.ContainsKey(ID) || !PlayerAwardDict.ContainsKey(player.handle)) { return(false); } PlayerAward award = PlayerAwardDict[player.handle].FirstOrDefault(a => a.ID == ID); if (award == null) { return(false); } award.Unlocked = false; award.UnlockDate = null; SavePlayer(player); return(true); }