コード例 #1
0
    private void ClientOnWhisperCommandReceived(object sender, OnWhisperCommandReceivedArgs e)
    {
        Debug.Log(e.Command + " has been received.");

        List <string> splitWhisper = e.ArgumentsAsList;

        string id       = e.WhisperMessage.UserId;
        string username = e.WhisperMessage.DisplayName;

        // Check they have been added as a developer
        if (!developers.ContainsKey(id))
        {
            client.SendWhisper(username, "You are not a developer yet. Please send a message to chat first.");
            return;
        }

        Debug.Log("Do I make it here?");

        if (string.Compare(e.Command, "money", true) == 0)
        {
            Debug.Log("Can I fix it?");
            client.SendWhisper(username, "You have £" + developers[id].developerMoney + ".");
            Debug.Log("Yes I can.");
        }

        else if (string.Compare(e.Command, "skills", true) == 0)
        {
            Debug.Log("Beep. Boop.");
            client.SendWhisper(username, "Lead: " + developers[id].GetSkillLevel(SkillTypes.LeaderSkills.Leadership) + " | Design: " + developers[id].GetSkillLevel(SkillTypes.DeveloperSkills.Design) + " | Develop: " + developers[id].GetSkillLevel(SkillTypes.DeveloperSkills.Development) + " | Art: " + developers[id].GetSkillLevel(SkillTypes.DeveloperSkills.Art) + " | Marketing: " + developers[id].GetSkillLevel(SkillTypes.DeveloperSkills.Marketing) + ".");
        }

        else if (string.Compare(e.Command, "company", true) == 0)
        {
            //Get the company from the developer data
            string companyName = developers[id].companyName;
            Debug.Log("Got the company name.");

            //Mark as true/false by default to avoid issues
            bool companyFounder = true;
            bool companyOwner   = false;

            //Check if they are part of a company
            if (companyName == string.Empty)
            {
                companyFounder = false;
            }

            else
            {
                //If they are part of company, check if they are the owner
                if (companies[companyName].IsOwner(id))
                {
                    Debug.Log(username + " is the Owner of " + companyName);
                    companyOwner = true;
                }
            }

            Debug.Log($"Length of whisper is: {splitWhisper.Count}");

            //Start a company
            if (string.Compare(splitWhisper[0], "start", true) == 0)
            {
                Debug.Log("Creating a company.");

                //Check if player is already part of a company
                if (!companyFounder)
                {
                    companyName = splitWhisper[1];

                    //Check if a company exists
                    if (!companies.ContainsKey(companyName))
                    {
                        company = new CompanyClass(companyName);
                        company.AddFounder(id);
                        developers[id].JoinCompany(companyName);

                        client.SendWhisper(username, "You are now the proud owner of " + companyName + ".");

                        companies.Add(companyName, company);

                        Debug.Log("Company created.");
                    }

                    else
                    {
                        client.SendWhisper(username, "A company already exists with that name. Please choose another.");
                    }
                }

                else
                {
                    client.SendWhisper(username, "You are already part of a company called " + companyName + ".");
                }
            }

            //Invite upto two more people to join the company
            else if (string.Compare(splitWhisper[0], "invite", true) == 0)
            {
                Debug.Log("Inviting someone to join a company.");

                string invitedUsername = splitWhisper[1];

                //Check they are the owner of a company
                if (companyOwner)
                {
                    Debug.Log(username + " is the owner of a company.");

                    company = companies[companyName];

                    //Check the company has less than 3 founders
                    if (company.FounderCount < 3)
                    {
                        Debug.Log("The company has less than 3 founders.");

                        //Check the player is in the system
                        if (DoesUsernameExist(invitedUsername))
                        {
                            Debug.Log(invitedUsername + " is a developer.");

                            string invitedID = GetID(invitedUsername);

                            //Check the player is not already part of a company
                            if (!developers[invitedID].IsFounder)
                            {
                                Debug.Log(invitedUsername + " is not already part of a company.");

                                //Add the invited user to a list
                                company.AddInvite(invitedID);
                                Debug.Log("Invited user has been added to list.");

                                //Give them 5 minutes to respond
                                EnsureMainThread.executeOnMainThread.Enqueue(() => { StartCoroutine(ClearInvite(companyName)); });
                                Debug.Log("ClearInvite has been started.");

                                //Send the invite via whisper. Keep SendMessage just in case it doesn't work for others.
                                client.SendWhisper(invitedUsername, "You have been invited by " + username + " to join their company, " + companyName + ". Type !company accept " + companyName + " in the next 5 minutes to join.");
                                //client.SendMessage(invitedUsername + ", you have been invited to join " + companyName + ". Type !company accept " + companyName + " in the next 5 minutes to join.");
                                Debug.Log("Invite sent.");

                                //Let the founder know an invite was sent
                                client.SendWhisper(username, "An invite has been sent to " + invitedUsername + ".");
                            }

                            else
                            {
                                client.SendWhisper(username, invitedUsername + " is already part of another company.");
                            }
                        }

                        else
                        {
                            client.SendWhisper(username, invitedUsername + " is not a developer. Wait for them to send a message in chat.");
                        }
                    }

                    else
                    {
                        client.SendWhisper(username, "You are not allowed more than 3 founders in a company.");
                    }
                }

                else
                {
                    client.SendWhisper(username, "You have to be the owner of the company to invite founders.");
                }
            }

            else if (string.Compare(splitWhisper[0], "accept", true) == 0)
            {
                Debug.Log("Accepting invite.");

                if (String.IsNullOrEmpty(companyName))
                {
                    Debug.Log(username + " is not part of a company.");

                    companyName = splitWhisper[1];

                    //Check the company exists
                    if (companies.ContainsKey(companyName))
                    {
                        Debug.Log("Company exists.");

                        //Check the company has less than 3 founders
                        if (companies[companyName].FounderCount < 3)
                        {
                            Debug.Log("Company has less than three founders.");

                            company = companies[companyName];

                            //Add them to the company
                            company.AddFounder(id);

                            //Add company to their details
                            developers[id].JoinCompany(companyName);

                            //Let them now they've joined a company
                            client.SendWhisper(username, "You are now a founder of " + companyName + ". You can add funds with !company deposit 1000, etc. to fund projects, and !project start [NAME] to start projects.");
                            //Doesn't send

                            //Get the company founder
                            string founder = GetUsername(company.GetOwner);

                            //Let the founder know the player has joined the company
                            client.SendWhisper(founder, username + " has become a founder of your company, " + companyName + ".");
                        }

                        else
                        {
                            //There are already 3 people
                            client.SendWhisper(username, companyName + " already has three founders.");
                        }
                    }

                    else
                    {
                        //Company doesn't exist
                        client.SendWhisper(username, companyName + " doesn't exist. Check you typed the name correctly.");
                    }
                }

                else
                {
                    client.SendWhisper(username, "You are already part of another company, " + companyName + ".");
                }
            }

            //Add funds to company from player
            else if (string.Compare(splitWhisper[0], "deposit", true) == 0)
            {
                //Check the player is part of a company
                if (companyFounder)
                {
                    int money;

                    if (int.TryParse(splitWhisper[1], out money))
                    {
                        //Check the player has enough funds
                        if (developers[id].HasEnoughMoney(money))
                        {
                            //Transfer funds - Can probably be a function
                            developers[id].SpendMoney(money);
                            companies[companyName].AddMoney(money);

                            client.SendWhisper(username, "You have deposited " + money + ". Now " + companyName + " has " + companies[companyName].money + ", and you have " + developers[id].developerMoney + " left."); //Can probably write this better, but yeah
                        }

                        else
                        {
                            client.SendWhisper(username, "You only have " + developers[id].developerMoney + ".");
                        }
                    }

                    else
                    {
                        client.SendWhisper(username, "To deposit money, you need to use !command deposit 1000, etc.");
                    }
                }

                else
                {
                    client.SendWhisper(username, "You need to be part of a company to deposit money.");
                }
            }

            //Withdraw funds from a company to player
            else if (string.Compare(splitWhisper[0], "withdraw", true) == 0)
            {
                //Check the player is founder of a company
                if (companyFounder)
                {
                    int money;

                    if (int.TryParse(splitWhisper[1], out money))
                    {
                        //Check the company has enough funds
                        if (companies[companyName].HasEnoughMoney(money))
                        {
                            //Transfer funds
                            companies[companyName].SpendMoney(money);
                            developers[id].AddMoney(money);
                        }

                        else
                        {
                            client.SendWhisper(username, "The company only has " + companies[companyName].money + ".");
                        }
                    }

                    else
                    {
                        client.SendWhisper(username, "To withdraw money, you need to use !command withdraw 1000, etc.");
                    }
                }

                else
                {
                    client.SendWhisper(username, "You need to be part of a company to withdraw money.");
                }
            }

            //Edit company data
            else if (string.Compare(splitWhisper[0], "edit", true) == 0)
            {
                //Check they are the owner of the company
                if (companyOwner)
                {
                    string newName = splitWhisper[1];

                    //Change the company name
                    companies[companyName].ChangeName(newName);

                    //Get all the founders
                    //Change the company name in their developer profiles
                    foreach (string developer in companies[companyName].GetFounders)
                    {
                        developers[developer].UpdateCompany(newName); //Make a function
                    }

                    client.SendWhisper(username, "You have changed the name of the company to " + newName);
                }

                else
                {
                    client.SendWhisper(username, "You have to be the company owner to change the name.");
                }
            }

            //Leave company
            else if (string.Compare(splitWhisper[0], "leave", true) == 0)
            {
                //Check they are in a company
                if (companyFounder)
                {
                    companies[companyName].RemoveFounder(id);
                    developers[id].LeaveCompany();

                    client.SendWhisper(username, "You have left " + companyName + ".");
                }

                else
                {
                    client.SendWhisper(username, "You cannot leave a company if you are not part of a company. FailFish");
                }
            }

            else
            {
                Debug.Log("I can't do my damn job!");
            }
        }

        else
        {
            Debug.Log("Boop!");
        }

        //if (string.Compare(e.Command, "project", true) == 0)
        //{
        //    //List<string> splitWhisper = e.ArgumentsAsList;

        //    if (!startProject)
        //    {
        //        if (string.Compare(splitWhisper[0], "start", true) == 0)
        //        {
        //            //Is the player part of a company?
        //            //If yes continue
        //            //If not, tell them they need to be part of a company

        //            uint projectID = (uint)(projects.Count + 1);
        //            project = new ProjectClass(projectID, splitWhisper[1]);

        //            //Add the player to the project team
        //            //Find the company the player is part of ???
        //            //Add the projectID to the player
        //            //Add the projectID to the company

        //            startProject = true;
        //            applyOpen = true;
        //            Invoke("ApplyClose", 120);
        //        }
        //    }

        //    if (applyOpen)
        //    {
        //        if (string.Compare(splitWhisper[0], "apply", true) == 0)
        //        {

        //        }

        //        if (string.Compare(splitWhisper[0], "accept", true) == 0)
        //        {

        //        }
        //    }
        //}
    }