protected async Task PlayerUpdate() { await using JsonHandler json = new JsonHandler(SaveJson); double MaxHealthCheck = await json.GetData <double>(PlayerData.MaxHealth); if (await json.GetData <double>(PlayerData.Health) > MaxHealthCheck) { await json.WriteEntry(PlayerData.Health, MaxHealthCheck); } }
protected async Task <double> XPToLevelUp() { await using JsonHandler json = new JsonHandler(SaveJson); byte PlayerLevel = await json.GetData <byte>(PlayerData.Level); return((PlayerLevel * PlayerLevel) + (PlayerLevel > 25 ? (PlayerLevel * 36.591) : (PlayerLevel * 18.2955))); }
private async Task GoldMine() { if (await HasInitialized() == false) { await ReplyAsync("Please use the `.start` command first to initialize."); return; } await using JsonHandler playerMiningGold = new JsonHandler(SaveJson); if (Globals.Rnd.NextDouble() < 0.67) { await playerMiningGold.WriteEntry(PlayerData.Gold, await playerMiningGold.GetData <double>(PlayerData.Gold) + 2); } else { await playerMiningGold.WriteEntry(PlayerData.Gold, await playerMiningGold.GetData <double>(PlayerData.Gold) + 1); } await ReplyAsync("Gold mined! (+1 gold)"); }
private async Task GiveGold(IUser toGiveTo, double goldToGive) { await using JsonHandler toGetFrom = new JsonHandler(SaveJson); double currentGold = await toGetFrom.GetData <double>(PlayerData.Gold); string toGiveToPath = $"{AppDomain.CurrentDomain.BaseDirectory}/SaveData/{toGiveTo.Id}.json"; if (!File.Exists(toGiveToPath)) { await ReplyAsync($"Error: specified user ({toGiveTo.Username}) has not initialized yet"); return; } if (await HasInitialized(toGiveToPath) == false) { await ReplyAsync($"Error: specified user ({toGiveTo.Username}) has not initialized yet"); return; } if (currentGold < goldToGive) { await ReplyAsync($"Error: you don't have enough gold ({currentGold}), compared to the amount you want to give ({goldToGive})"); return; } if (toGiveTo == null) { await ReplyAsync($"Error: specified user doesn't seem to exist"); return; } if (await HasInitialized() == false) { await ReplyAsync("Please use the `.start` command first to initialize."); return; } await ReplyAsync($"Giving {goldToGive} gold to {toGiveTo.Username}, please say `confirm` to confirm."); SocketMessage confirm; confirm = await NextMessageAsync(timeout : new TimeSpan(0, 0, 20)); if (confirm.Content.RemoveWhitespace().Contains("confirm", StringComparison.OrdinalIgnoreCase)) { await toGetFrom.WriteEntry(PlayerData.Gold, currentGold - goldToGive); await using JsonHandler toGiveToJson = new JsonHandler(toGiveToPath); await toGiveToJson.WriteEntry(PlayerData.Gold, await toGiveToJson.GetData <double>(PlayerData.Gold) + goldToGive); await ReplyAsync($"Successfully gave {goldToGive} gold to {toGiveTo.Username}!"); return; } else if (confirm.Content.RemoveWhitespace().StartsWith('.')) { await ReplyAsync("No commands allowed --- you were currently being awaited for input, please try again. (`.givegold`, input context: giving gold)"); return; } else if (confirm == null) { await ReplyAsync("You didn't reply in time, please try again. (`.givegold`)"); return; } else { await ReplyAsync("Input doesn't match `confirm`, gold giving canceled (use the `.givegold` command again to try again if that was a mistake)"); return; } }