public void Complete() { Program.Game.RandomRequests.Remove(this); if (_max < _min) { Result = -1; } else { int xorResult = _values.Aggregate(0, (current, value) => current ^ (int)(value.Decrypted & 0xffffff)); double relativeValue = xorResult / (double)0xffffff; Result = (int)Math.Truncate((_max - _min + 1) * relativeValue) + _min; if (Result > _max) { Result = _max; // this handles the extremely rare case where relativeValue == 1.0 } } Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event + EventIds.PlayerFlag(_player), "{0} randomly picks {1} in [{2}, {3}]", _player, Result, _min, _max); if (Completed != null) { Completed(this, EventArgs.Empty); } }
// Set the counter's value internal void SetValue(int value, Player who, bool notifyServer) { var oldValue = _state; // Check the difference with current value int delta = value - _state; if (delta == 0) { return; } // Notify the server if needed if (notifyServer) { Program.Client.Rpc.CounterReq(this, value); } // Set the new value _state = value; OnPropertyChanged("Value"); // Display a notification in the chat string deltaString = (delta > 0 ? "+" : "") + delta.ToString(CultureInfo.InvariantCulture); if (notifyServer || who != Player.LocalPlayer) { Program.GameEngine.EventProxy.OnChangeCounter(who, this, oldValue); } Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(who), "{0} sets {1} counter to {2} ({3})", who, this, value, deltaString); }
// Pass control to player p internal void PassControlTo(Player p, Player who, bool notifyServer, bool requested) { if (notifyServer) { // Can't pass control if I don't own it if (Controller != Player.LocalPlayer) { return; } Program.Client.Rpc.PassToReq(this, p, requested); } Controller = p; if (requested) { Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(p), "{0} takes control of {1}", p, this); } else { Program.Trace.TraceEvent(TraceEventType.Information, EventIds.Event | EventIds.PlayerFlag(who), "{0} gives control of {1} to {2}", who, this, p); } }