示例#1
0
        public override void OnStart(OnStartProperties onStartProperties)
        {
            base.OnStart(onStartProperties);

            /*
             * if (!File.Exists(@"C:\Users\1080622\Documents\code\deenee\campaigns\test.campaign")) {
             *  Main.campaign = Campaign.New(@"C:\Users\1080622\Documents\code\deenee\campaigns", "test");
             * }
             * else {
             *  Main.campaign = Campaign.Load(@"C:\Users\1080622\Documents\code\deenee\campaigns\test.campaign");
             * }
             * Map map = new Map();
             * map.Name = "idk";
             * map.Campaign = Main.campaign;
             * Main.campaign.Maps.Add(map);
             * Console.WriteLine(Main.campaign.Maps.Count);
             * Map = Main.campaign.Maps[0];
             */
        }
示例#2
0
        public override void OnStart(OnStartProperties onStartProperties)
        {
            base.OnStart(onStartProperties);

            /*
             * ChatInput.onEndEdit.AddListener(new UnityEngine.Events.UnityAction<string>(str => {
             *  if (str.StartsWith("/")) {
             *      str += str.Substring(1);
             *  }
             *  else {
             *      return;
             *  }
             *  var args = str.splitNotBetween(' ', '"', '"').ToList();
             *  var func = args[0];
             *  args.RemoveAt(0);
             *  var inter = interactives.Where(x => x.Comamnds.Contains(func));
             *  inter.ToList().ForEach(x => {
             *
             *  });
             * }));
             */
        }
示例#3
0
 /// <summary>
 /// overwrite this for a method that is run when the object starts existing
 /// </summary>
 /// <param name="onStartProperties">properties for stating</param>
 public virtual void OnStart(OnStartProperties onStartProperties)
 {
 }
示例#4
0
 public override void OnStart(OnStartProperties onStartProperties)
 {
     base.OnStart(onStartProperties);
 }
示例#5
0
        public override void OnStart(OnStartProperties onStartProperties)
        {
            base.OnStart(onStartProperties);
            discord = new Discord.Discord(DISCORD_CLIENT_ID, (UInt64)Discord.CreateFlags.Default);
            discord.SetLogHook(Discord.LogLevel.Debug, (level, message) => {
                // Console.WriteLine("Log[{0}] {1}", level, message);
            });
            DontDestroyOnLoad(this);
            applicationManager = discord.GetApplicationManager();
            //Console.WriteLine("Current Locale: {0}", applicationManager.GetCurrentLocale());
            // Get the current branch. For example alpha or beta.
            //Console.WriteLine("Current Branch: {0}", applicationManager.GetCurrentBranch());
            var activityManager = discord.GetActivityManager();

            LobbyManager = discord.GetLobbyManager();
            activityManager.OnActivityJoin += secret => {
                //Console.WriteLine("OnJoin {0}", secret);
                LobbyManager.ConnectLobbyWithActivitySecret(secret, (Discord.Result result, ref Discord.Lobby lobby) => {
                    //Console.WriteLine("Connected to lobby: {0}", lobby.Id);
                    LobbyManager.ConnectNetwork(lobby.Id);
                    LobbyManager.OpenNetworkChannel(lobby.Id, 0, true);
                    foreach (var user in LobbyManager.GetMemberUsers(lobby.Id))
                    {
                        LobbyManager.SendNetworkMessage(lobby.Id, user.Id, 0,
                                                        Encoding.UTF8.GetBytes(string.Format("Hello, {0}!", user.Username)));
                    }
                    UpdateActivity(discord, lobby);
                });
            };
            // Received when someone accepts a request to spectate
            activityManager.OnActivitySpectate += secret => {
                //Console.WriteLine("OnSpectate {0}", secret);
            };
            // A join request has been received. Render the request on the UI.
            activityManager.OnActivityJoinRequest += (ref Discord.User user) => {
                //Console.WriteLine("OnJoinRequest {0} {1}", user.Id, user.Username);
            };
            // An invite has been received. Consider rendering the user / activity on the UI.
            activityManager.OnActivityInvite += (Discord.ActivityActionType Type, ref Discord.User user, ref Discord.Activity activity2) => {
                //Console.WriteLine("OnInvite {0} {1} {2}", Type, user.Username, activity2.Name);
                // activityManager.AcceptInvite(user.Id, result =>
                // {
                //     Console.WriteLine("AcceptInvite {0}", result);
                // });
            };
            // This is used to register the game in the registry such that Discord can find it.
            // This is only needed by games acquired from other platforms, like Steam.
            // activityManager.RegisterCommand();

            var imageManager = discord.GetImageManager();

            var userManager = discord.GetUserManager();

            // The auth manager fires events as information about the current user changes.
            // This event will fire once on init.
            //
            // GetCurrentUser will error until this fires once.
            userManager.OnCurrentUserUpdate += () => {
                var currentUser = userManager.GetCurrentUser();
                //Console.WriteLine(currentUser.Username);
                //Console.WriteLine(currentUser.Id);
            };
            // If you store Discord user ids in a central place like a leaderboard and want to render them.
            // The users manager can be used to fetch arbitrary Discord users. This only provides basic
            // information and does not automatically update like relationships.
            userManager.GetUser(450795363658366976, (Discord.Result result, ref Discord.User user) => {
                if (result == Discord.Result.Ok)
                {
                    //Console.WriteLine("user fetched: {0}", user.Username);

                    // Request users's avatar data.
                    // This can only be done after a user is successfully fetched.
                    FetchAvatar(imageManager, user.Id);
                }
                else
                {
                    //Console.WriteLine("user fetch error: {0}", result);
                }
            });

            var relationshipManager = discord.GetRelationshipManager();

            // It is important to assign this handle right away to get the initial relationships refresh.
            // This callback will only be fired when the whole list is initially loaded or was reset
            relationshipManager.OnRefresh += () => {
                // Filter a user's relationship list to be just friends
                relationshipManager.Filter((ref Discord.Relationship relationship) => { return(relationship.Type == Discord.RelationshipType.Friend); });
                // Loop over all friends a user has.
                //Console.WriteLine("relationships updated: {0}", relationshipManager.Count());
                for (uint i = 0; i < Math.Min(relationshipManager.Count(), 10); i++)
                {
                    // Get an individual relationship from the list
                    var r = relationshipManager.GetAt(i);
                    //Console.WriteLine("relationships: {0} {1} {2} {3}", r.Type, r.User.Username, r.Presence.Status, r.Presence.Activity.Name);

                    // Request relationship's avatar data.
                    FetchAvatar(imageManager, r.User.Id);
                }
            };
            // All following relationship updates are delivered individually.
            // These are fired when a user gets a new friend, removes a friend, or a relationship's presence changes.

            /*
             * relationshipManager.OnRelationshipUpdate += (ref Discord.Relationship r) => {
             *  Console.WriteLine("relationship updated: {0} {1} {2} {3}", r.Type, r.User.Username, r.Presence.Status, r.Presence.Activity.Name);
             * };
             */

            LobbyManager.OnLobbyMessage += (lobbyID, userID, data) => {
                Console.WriteLine("lobby message: ", lobbyID, data.Length);
            };

            LobbyManager.OnNetworkMessage += (long lobbyId, long userId, byte channelId, byte[] data) => {
            };

            /*
             * lobbyManager.OnSpeaking += (lobbyID, userID, speaking) => {
             *  Console.WriteLine("lobby speaking: {0} {1} {2}", lobbyID, userID, speaking);
             * };
             */
            // Create a lobby.
            var transaction = LobbyManager.GetLobbyCreateTransaction();

            transaction.SetCapacity(20);
            transaction.SetType(Discord.LobbyType.Public);
            transaction.SetMetadata("a", "123");
            transaction.SetMetadata("a", "456");
            transaction.SetMetadata("b", "111");
            transaction.SetMetadata("c", "222");

            LobbyManager.CreateLobby(transaction, (Discord.Result result, ref Discord.Lobby lobby) => {
                if (result != Discord.Result.Ok)
                {
                    return;
                }
                var _lobby = lobby;
                newLobbyListener.ForEach(x => x(_lobby));

                // Print all the members of the lobby.
                foreach (var user in LobbyManager.GetMemberUsers(lobby.Id))
                {
                    //Console.WriteLine("lobby member: {0}", user.Username);
                }

                // Update lobby.
                var lobbyTransaction = LobbyManager.GetLobbyUpdateTransaction(lobby.Id);
                lobbyTransaction.SetMetadata("d", "e");
                lobbyTransaction.SetCapacity(16);
                LobbyManager.UpdateLobby(lobby.Id, lobbyTransaction, (_) => {
                    //Console.WriteLine("lobby has been updated");
                });

                // Update a member.
                var lobbyID           = lobby.Id;
                var userID            = lobby.OwnerId;
                var memberTransaction = LobbyManager.GetMemberUpdateTransaction(lobbyID, userID);
                memberTransaction.SetMetadata("hello", "there");
                LobbyManager.UpdateMember(lobbyID, userID, memberTransaction, (_) => {
                    //Console.WriteLine("lobby member has been updated: {0}", lobbyManager.GetMemberMetadataValue(lobbyID, userID, "hello"));
                });

                // Search lobbies.
                var query = LobbyManager.GetSearchQuery();
                // Filter by a metadata value.
                query.Filter("metadata.a", Discord.LobbySearchComparison.GreaterThan, Discord.LobbySearchCast.Number, "455");
                query.Sort("metadata.a", Discord.LobbySearchCast.Number, "0");
                // Only return 1 result max.
                query.Limit(1);
                LobbyManager.Search(query, (_) => {
                    //Console.WriteLine("search returned {0} lobbies", lobbyManager.LobbyCount());
                    if (LobbyManager.LobbyCount() == 1)
                    {
                        //Console.WriteLine("first lobby secret: {0}", lobbyManager.GetLobby(lobbyManager.GetLobbyId(0)).Secret);
                    }
                });

                // Connect to voice chat.
                LobbyManager.ConnectVoice(lobby.Id, (_) => {
                    //Console.WriteLine("Connected to voice chat!");
                });

                // Setup networking.
                LobbyManager.ConnectNetwork(lobby.Id);
                LobbyManager.OpenNetworkChannel(lobby.Id, 0, true);

                // Update activity.
                UpdateActivity(discord, lobby);
            });

            /*
             * var overlayManager = discord.GetOverlayManager();
             * overlayManager.OnOverlayLocked += locked =>
             * {
             *  Console.WriteLine("Overlay Locked: {0}", locked);
             * };
             * overlayManager.SetLocked(false);
             */

            /*
             * var storageManager = discord.GetStorageManager();
             * var contents = new byte[20000];
             * var random = new Random();
             * random.NextBytes(contents);
             * Console.WriteLine("storage path: {0}", storageManager.GetPath());
             * storageManager.WriteAsync("foo", contents, res => {
             *  var files = storageManager.Files();
             *  foreach (var file in files) {
             *      Console.WriteLine("file: {0} size: {1} last_modified: {2}", file.Filename, file.Size, file.LastModified);
             *  }
             *  storageManager.ReadAsyncPartial("foo", 400, 50, (result, data) => {
             *      Console.WriteLine("partial contents of foo match {0}", Enumerable.SequenceEqual(data, new ArraySegment<byte>(contents, 400, 50)));
             *  });
             *  storageManager.ReadAsync("foo", (result, data) => {
             *      Console.WriteLine("length of contents {0} data {1}", contents.Length, data.Length);
             *      Console.WriteLine("contents of foo match {0}", Enumerable.SequenceEqual(data, contents));
             *      Console.WriteLine("foo exists? {0}", storageManager.Exists("foo"));
             *      storageManager.Delete("foo");
             *      Console.WriteLine("post-delete foo exists? {0}", storageManager.Exists("foo"));
             *  });
             * });
             *
             */
            var storeManager = discord.GetStoreManager();

            storeManager.OnEntitlementCreate += (ref Discord.Entitlement entitlement) => {
                Console.WriteLine("Entitlement Create1: {0}", entitlement.Id);
            };

            // Start a purchase flow.
            // storeManager.StartPurchase(487507201519255552, result =>
            // {
            //     if (result == Discord.Result.Ok)
            //     {
            //         Console.WriteLine("Purchase Complete");
            //     }
            //     else
            //     {
            //         Console.WriteLine("Purchase Canceled");
            //     }
            // });

            // Get all entitlements.
            storeManager.FetchEntitlements(result => {
                if (result == Discord.Result.Ok)
                {
                    foreach (var entitlement in storeManager.GetEntitlements())
                    {
                        //Console.WriteLine("entitlement: {0} - {1} {2}", entitlement.Id, entitlement.Type, entitlement.SkuId);
                    }
                }
            });

            // Get all SKUs.
            storeManager.FetchSkus(result => {
                if (result == Discord.Result.Ok)
                {
                    foreach (var sku in storeManager.GetSkus())
                    {
                        //Console.WriteLine("sku: {0} - {1} {2}", sku.Name, sku.Price.Amount, sku.Price.Currency);
                    }
                }
            });
        }