Exemple #1
0
        internal bool RemoveBotFromGroup(Bot bot, BotGroup botGroup)
        {
            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var removeQuery = string.Format("delete from bot_group_members where bot_id = {0} and groups_index={1};", bot.Id, botGroup.GroupIndex);
                var cmd         = new MySqlCommand(removeQuery, _connection);
                var result      = cmd.ExecuteNonQuery();

                if (result == 0)
                {
                    return(false);
                }
                if (result != -1)
                {
                    var botToRemove = botGroup.Members.Single(b => b.Id == bot.Id);
                    botToRemove.IsMember = false;
                    botGroup.Members.Remove(botToRemove);

                    if (botGroup.Members.Count == 0) // this was the last bot and should be the leader, empty bot groups cannot exist, so we delete those as well.
                    {
                        botToRemove.IsLeader = false;
                        var deleteGroup = DeleteBotGroup(botGroup, true);
                        if (deleteGroup)
                        {
                            return(true);
                        }
                    }

                    return(true);
                }
            }
            return(false);
        }
Exemple #2
0
 public RenameBotGroupForm(BotGroup botGroup, DatabaseConnector connector)
 {
     this._botGroup  = botGroup;
     this._connector = connector;
     InitializeComponent();
     this.Text = string.Format("Rename Bot Group [{0}]", _botGroup.GroupName);
 }
Exemple #3
0
 internal bool DeleteBotGroup(BotGroup botGroup, bool lastMember = false)
 {
     if (_connection.State == System.Data.ConnectionState.Open)
     {
         if (lastMember)
         {
             var queryLeader  = string.Format("delete from bot_groups where group_leader_id = {0};", botGroup.GroupLeaderId);
             var cmdRemove    = new MySqlCommand(queryLeader, _connection);
             var removeResult = cmdRemove.ExecuteNonQuery();
             if (removeResult != -1)
             {
                 return(true);
             }
         }
         var memberQuery = string.Format("delete from bot_group_members where groups_index={0};", botGroup.GroupIndex);
         var cmd         = new MySqlCommand(memberQuery, _connection);
         var result      = cmd.ExecuteNonQuery();
         if (result != -1)
         {
             var queryLeader = string.Format("delete from bot_groups where group_leader_id = {0};", botGroup.GroupLeaderId);
             cmd    = new MySqlCommand(queryLeader, _connection);
             result = cmd.ExecuteNonQuery();
             if (result != -1)
             {
                 return(true);
             }
         }
         else
         {
             return(false);
         }
     }
     return(false);
 }
Exemple #4
0
    /// <summary>
    /// 根据类型,生成一组怪物
    /// </summary>
    /// <param name="type"></param>
    private void SpawnBotGroup(BotGroup.Type type)
    {
        float   speed = spawnNextSpeed;
        Vector3 spawnPos;

        spawnPos    = character.transform.position;
        spawnPos.z += spawnPosOffect;
        switch (spawnGroupTypeCurrent)
        {
        case BotGroup.Type.Slow:
        {
            speed = 1.0f;
        }
        break;

        case BotGroup.Type.Normal:
        {
            speed = spawnNextSpeed;
        }
        break;
        }

        BotGroup botGroup = GameObject.Instantiate <BotGroup>(botGroupPrefab);
        //怪物组生成的Y轴位置处于自身碰撞盒范围的一半
        var extents = botGroup.GetComponent <Collider>().bounds.extents;

        spawnPos.y = extents.y / 2;
        botGroup.transform.position = spawnPos;
        //怪物组生成内部怪物
        botGroup.SpawnBot(spawnBotNum);
        botGroup.runSpeed = speed;
    }
Exemple #5
0
        internal BotGroup CreateBotGroup(Bot bot, string groupName)
        {
            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var nameCheckQuery = string.Format("select * from bot_groups where group_name = '{0}';", groupName);
                var cmd            = new MySqlCommand(nameCheckQuery, _connection);
                using (var dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.HasRows)
                    {
                        return(null);
                    }
                }

                var insertQuery = string.Format("insert into bot_groups (group_leader_id, group_name) values ('{0}', '{1}');", bot.Id, groupName);
                cmd = new MySqlCommand(insertQuery, _connection);
                var result = cmd.ExecuteNonQuery();
                if (result == -1)
                {
                    return(null);
                }


                var botGroup = new BotGroup();

                var groupCheckQuery = string.Format("select * from bot_groups where group_leader_id = '{0}';", bot.Id);
                cmd = new MySqlCommand(groupCheckQuery, _connection);
                using (var dataReader = cmd.ExecuteReader())
                {
                    while (dataReader.Read())
                    {
                        botGroup = new BotGroup();
                        botGroup.GroupLeaderId = Convert.ToInt32(dataReader["group_leader_id"]);
                        botGroup.GroupName     = Convert.ToString(dataReader["group_name"]);
                        botGroup.GroupIndex    = Convert.ToInt32(dataReader["groups_index"]);
                        botGroup.LeaderName    = bot.Name;
                    }
                }

                insertQuery = string.Format("insert into bot_group_members (groups_index, bot_id) values ('{0}', '{1}');", botGroup.GroupIndex, bot.Id);
                cmd         = new MySqlCommand(insertQuery, _connection);
                result      = cmd.ExecuteNonQuery();
                if (result == -1)
                {
                    return(null);
                }

                return(botGroup);
            }

            return(null);
        }
Exemple #6
0
 private void LoadBotGroupMembers(BotGroup botGroup)
 {
     if (botGroup != null)
     {
         botGroup.Members = _connector.LoadBotGroupMembers(botGroup);
         if (botGroup.Members != null && botGroup.Members.Count > 0)
         {
             foreach (var bot in botGroup.Members)
             {
                 var botToModify = (from b in _user.SelectedCharacter.Bots where bot.Id == b.Id select b).FirstOrDefault();
                 if (botToModify != null)
                 {
                     botToModify.GroupId = botGroup.GroupIndex;
                 }
             }
         }
     }
 }
Exemple #7
0
        internal List <Bot> LoadBotGroupMembers(BotGroup botGroup)
        {
            var botGroupMembers = new List <Bot>();

            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var query = string.Format("select * from bot_group_members where groups_index = {0};", botGroup.GroupIndex);
                var cmd   = new MySqlCommand(query, _connection);
                using (var dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            var bot = new Bot();
                            bot.Id      = Convert.ToInt32(dataReader["bot_id"]);
                            bot.GroupId = Convert.ToInt32(dataReader["groups_index"]);
                            //bot.IsMember = true;
                            botGroupMembers.Add(bot);
                        }
                    }
                }

                foreach (var bot in botGroupMembers)
                {
                    query = string.Format("select * from bot_data where bot_id = {0};", bot.Id);
                    cmd   = new MySqlCommand(query, _connection);
                    using (var dataReader = cmd.ExecuteReader())
                    {
                        if (dataReader.HasRows)
                        {
                            while (dataReader.Read())
                            {
                                bot.Name    = Convert.ToString(dataReader["name"]);
                                bot.ClassId = Convert.ToInt32(dataReader["class"]);
                            }
                        }
                    }
                }
            }

            return(botGroupMembers);
        }
Exemple #8
0
        internal bool AddBotToGroup(Bot bot, BotGroup botGroup)
        {
            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var addQuery = string.Format("insert into bot_group_members (groups_index, bot_id) values ('{0}', '{1}');", botGroup.GroupIndex, bot.Id);
                var cmd      = new MySqlCommand(addQuery, _connection);
                var result   = cmd.ExecuteNonQuery();
                if (result != -1)
                {
                    if (botGroup.Members == null)
                    {
                        botGroup.Members = new List <Bot>();
                    }
                    bot.GroupId  = botGroup.GroupIndex;
                    bot.IsMember = true;
                    botGroup.Members.Add(bot);

                    return(true);
                }
            }
            return(false);
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            var botGroup = _connector.CreateBotGroup(_bot, botNameTextBox.Text);

            if (botGroup != null)
            {
                if (_character.BotGroups == null)
                {
                    _character.BotGroups = new List <BotGroup>();
                }
                if (botGroup.Members == null)
                {
                    botGroup.Members = new List <Bot>();
                }

                var botToModify = (from b in _character.Bots where _bot.Id == b.Id select b).FirstOrDefault();
                botToModify.IsLeader = true;
                botToModify.GroupId  = botGroup.GroupIndex;
                botGroup.Members.Add(botToModify);
                _character.BotGroups.Add(botGroup);
                this.NewGroup = botGroup;
            }
        }
Exemple #10
0
        internal bool RenameBotGroup(BotGroup botGroup, string newName)
        {
            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var nameCheckQuery = string.Format("select * from bot_groups where group_name = '{0}';", newName);
                var cmd            = new MySqlCommand(nameCheckQuery, _connection);
                using (var dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.HasRows)
                    {
                        return(false);
                    }
                }

                var updateQuery = string.Format("update bot_groups set group_name = '{0}' where groups_index = {1};", newName, botGroup.GroupIndex);
                cmd = new MySqlCommand(updateQuery, _connection);
                var result = cmd.ExecuteNonQuery();
                if (result != -1)
                {
                    return(true);
                }
            }
            return(false);
        }
Exemple #11
0
        internal BotGroup LoadBotGroup(Character bot)
        {
            if (_connection.State == System.Data.ConnectionState.Open)
            {
                var query = string.Format("select * from bot_groups where group_leader_id = {0};", bot.Id);
                var cmd   = new MySqlCommand(query, _connection);
                using (var dataReader = cmd.ExecuteReader())
                {
                    if (dataReader.HasRows)
                    {
                        while (dataReader.Read())
                        {
                            var botGroup = new BotGroup();
                            botGroup.GroupName     = Convert.ToString(dataReader["group_name"]);
                            botGroup.GroupIndex    = Convert.ToInt32(dataReader["groups_index"]);
                            botGroup.GroupLeaderId = Convert.ToInt32(dataReader["group_leader_id"]);
                            return(botGroup);
                        }
                    }
                }
            }

            return(null);
        }
Exemple #12
0
        public JsonResponse onNewGroup(Dictionary <string, object> parameters)
        {
            JsonError error = null;

            string    group = (string)parameters["group"];
            IxiNumber cost  = new IxiNumber((string)parameters["cost"]);
            bool      admin = false;

            if ((string)parameters["admin"] == "1")
            {
                admin = true;
            }

            if (Node.groups.hasGroup(group))
            {
                return(new JsonResponse {
                    result = "", error = new JsonError()
                    {
                        code = (int)RPCErrorCode.RPC_INVALID_PARAMETER, message = "Group already exists."
                    }
                });
            }

            BotGroup new_group = new BotGroup(Node.groups.getNextIndex(), group, cost, admin);

            Node.groups.setGroup(group, new_group);
            if ((string)parameters["default"] == "1")
            {
                Node.settings.setOption("defaultGroup", new_group.index.ToString());
            }
            Node.settings.saveSettings();

            return(new JsonResponse {
                result = "", error = error
            });
        }