private GainExpModel CalculateExpForAccount(uint level) { uint expAmount = ExpirienceCalculator.GetOnlineRewardForLevel(level); var expModel = new GainExpModel { Amount = expAmount, GainReason = GainExpReason.Online, TimeStamp = DateTime.Now }; return(expModel); }
public void NotifyUserOfExpAddition(ComplexAccountState userState, GainExpModel expModel) { using (IHttpActor actor = new HttpActor()) { //TODO добавить начисление экспы string address = $"{userState.Address}{Subroutes.NotifyClient.SyncExp}"; actor.SetRequestAddress(address); actor.AddHeader(FreengyHeaders.Server.ServerSessionTokenHeaderName, userState.ClientAuth.ServerToken); $"Giving { expModel.Amount } exp to { userState.ComplexAccount.Name } for { expModel.GainReason }" .WriteToConsole(ConsoleColor.Yellow); var result = actor.PostAsync <GainExpModel, GainExpModel>(expModel).Result; } }
private void OnDelayedEvent() { IEnumerable <ComplexAccountState> onlineStates = stateService.GetAllOnline(); Parallel.ForEach(onlineStates, state => { uint userPreviousLevel = state.ComplexAccount.Level; GainExpModel model = CalculateExpForAccount(state.ComplexAccount.Level); state.ComplexAccount.AddExp(model.Amount); informerService.NotifyUserOfExpAddition(state, model); uint userNewLevel = ExpirienceCalculator.GetLevelForExp((uint)state.ComplexAccount.Expirience); if (userNewLevel > userPreviousLevel) { Task.Run(() => informerService.NotifyAllFriendsAboutUser(state)); } }); stateService.FlushStates(); delayedInvoker.RequestDelayedEvent(); }