Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- using System.Threading.Tasks;
- using PlayerIO.GameLibrary;
- namespace UPIO.Server
- {
- internal class RecourcesEngine : Player
- {
- private BigDB bigDb;
- private async Task CalculateRecources(string tableName, string clientName, string clientId, Player client,
- CancellationToken cancellationToken)
- {
- var delay = TimeSpan.FromSeconds(30);
- cancellationToken.ThrowIfCancellationRequested();
- int aluminium = 0, uranium = 0;
- await bigDb.LoadAsync(tableName,clientId,(databaseobject) =>
- {
- var recources = databaseobject.GetObject("Recources");
- var aluminium = recources.GetInt("Aluminium");
- var uranium = recources.GetInt("Uranium");
- aluminium += 30;
- uranium += 40;
- recources.Set("Aluminium", aluminium);
- recources.Set("Uranium", uranium);
- }, cancellationToken).ConfigureAwait(false);
- cancellationToken.ThrowIfCancellationRequested();
- await client.SendAsync("Recources", aluminium, uranium);
- cancellationToken.ThrowIfCancellationRequested();
- await Task.Delay(delay, cancellationToken).ConfigureAwait(false);
- }
- }
- }
- namespace UPIO.DB
- {
- class BigDB
- {
- private void Load(string tableName, string clientId, Action<DatabaseObject> process, CancellationToken ctx)
- {
- // ...
- }
- private TaskScheduler scheduler;
- public Task LoadAsync(
- string tableName,
- string clientId,
- Action<DatabaseObject> process,
- CancellationToken ctx)
- {
- return Task.Factory.StartNew(
- () => Load(tableName, clientId, process, ctx),
- ctx,
- TaskCreationOptions.None,
- scheduler);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement