コード例 #1
0
ファイル: TradeOffer.cs プロジェクト: AbnerSquared/Orikivo
 public TradeOffer(Discord.IUser user, Discord.IUser target)
 {
     Author    = new Author(user);
     Target    = new Author(target);
     CreatedAt = DateTime.UtcNow;
     Id        = KeyBuilder.Generate(5);
 }
コード例 #2
0
        public static OriKeyBatch Regenerate(int iterations, int size = KeyBuilder.DefaultKeyLength)
        {
            Debugger.Write("KeyBuilder.Generate...");
            Debugger.Write($"-- Now generating {iterations.ToPlaceValue()} iteration{(iterations > 1 ? "s" : "")} for a key with the length of {size}. --");
            Task <OriKeyBatch> factory = Task <OriKeyBatch> .Factory.StartNew(() =>
            {
                List <string> keys = new List <string>();

                for (int i = 0; i < iterations; i++)
                {
                    string key = KeyBuilder.Generate(size);
                    if (keys.Contains(key))
                    {
                        Debugger.Write("-- Production failed. --");
                        Debugger.Write($"-- Collision at position {keys.Count}. Key {key} has already been generated at position {(keys.IndexOf(key) + 1).ToPlaceValue()}. --");
                        return(new OriKeyBatch(key, keys.Count, keys.IndexOf(key) + 1, keys));
                    }

                    keys.Add(key);
                    continue;
                }

                Debugger.Write($"-- Successful production. No duplicate entries from {iterations.ToPlaceValue()} iteration{(iterations > 1 ? "s": "")}. --");

                return(null);
            });

            return(factory.Result);
        }
コード例 #3
0
ファイル: ItemData.cs プロジェクト: AbnerSquared/Orikivo
 internal ItemData(string id, bool locked, int?stackCount, UniqueItemData data, ItemSealData seal)
 {
     Id         = id;
     TempId     = KeyBuilder.Generate(5);
     Locked     = locked;
     StackCount = stackCount;
     Data       = data;
     Seal       = seal;
 }
コード例 #4
0
ファイル: ItemData.cs プロジェクト: AbnerSquared/Orikivo
        /// <summary>
        /// Initializes a unique <see cref="ItemData"/> stack.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Item"/> to store.</param>
        /// <param name="data">The unique data of the <see cref="Item"/> to store.</param>
        public ItemData(string id, UniqueItemData data)
        {
            if (!ItemHelper.IsUnique(id))
            {
                throw new Exception("Incorrect item data initializer used.");
            }

            Id     = id;
            TempId = KeyBuilder.Generate(5);
            Data   = data;
        }
コード例 #5
0
ファイル: ItemData.cs プロジェクト: AbnerSquared/Orikivo
        /// <summary>
        /// Initializes a non-unique <see cref="ItemData"/> stack.
        /// </summary>
        /// <param name="id">The ID of the <see cref="Item"/> to store.</param>
        /// <param name="stackCount">The stack count of the <see cref="Item"/> to store.</param>
        internal ItemData(string id, int stackCount)
        {
            if (ItemHelper.IsUnique(id))
            {
                throw new Exception("Incorrect item data initializer used.");
            }

            Id         = id;
            TempId     = KeyBuilder.Generate(5);
            StackCount = stackCount;
        }
コード例 #6
0
        /// <summary>
        /// Initializes a new <see cref="ActionQueue"/> with a generated ID.
        /// </summary>
        /// <param name="duration">The delay at which this <see cref="ActionQueue"/> will be called in.</param>
        /// <param name="actionId">The ID of the <see cref="GameAction"/> to invoke.</param>
        /// <param name="session">The <see cref="GameSession"/> to bind this <see cref="ActionQueue"/> for.</param>
        public ActionQueue(TimeSpan duration, string actionId, GameSession session)
        {
            if (session.Actions.All(x => x.Id != actionId))
            {
                throw new ValueNotFoundException("Failed to find the specified action in the current game session", actionId);
            }

            _session  = session;
            CreatedAt = StartedAt = DateTime.UtcNow;
            Id        = KeyBuilder.Generate(6);
            ActionId  = actionId;
            Delay     = duration;
            Timer     = new Timer(OnElapse, null, duration, TimeSpan.FromMilliseconds(-1));
            Logger.Debug($"[{Id}] Queued '{actionId}' (at {Format.FullTime(StartedAt)}) to invoke in {Format.Countdown(duration)}.");
        }
コード例 #7
0
 private GameServer(GameManager manager, IUser host, ServerProperties properties = null)
 {
     properties ??= ServerProperties.GetDefault(host.Username);
     _manager       = manager;
     HostId         = host.Id;
     Id             = KeyBuilder.Generate(8);
     Name           = properties.Name;
     GameId         = properties.GameId;
     Privacy        = properties.Privacy;
     Broadcasts     = DisplayBroadcast.GetReservedBroadcasts();
     Connections    = new List <ServerConnection>();
     Invites        = new List <ServerInvite>();
     AllowedActions = properties.AllowedActions;
     _players       = new List <Player>
     {
         new Player(this, host)
     };
     Destroyed   = false;
     LastUpdated = DateTime.UtcNow;
     LoadGameConfig();
 }
コード例 #8
0
 internal UniqueItemData()
 {
     Id = KeyBuilder.Generate(5);
 }