Пример #1
0
        public void AddMemberToGuild(Player player, Guild guild, Player inviter = null)
        {
            if (guild == null || player == null)
                return;

            if(guild.GuildMembers != null && guild.GuildMembers.Count > 30)
                return;

            lock (guild.MembersLock)
            {
                if (guild.GuildMembers == null || guild.GuildMembers.Count == 0)
                    guild.GuildMembers = new Dictionary<Player, int> {{player, 1}};
                else
                    guild.GuildMembers.Add(player, 2);
            }

            AddHistoryEvent(guild,
                            new HistoryEvent
                                {
                                    Args = GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                        /* TODO: 
                                         * inviter != null
                                            ? GuildHistoryStrings.UserXInvitedUserY(player.PlayerData.Name)
                                            : GuildHistoryStrings.GuildCreate(player.PlayerData.Name)*/
                                });

            player.Guild = guild;

            Communication.Global.VisibleService.Send(player,
                                                     new SpCharacterGuildInfo(player, guild.GuildName, "Recruit"));

            Communication.Global.RelationService.ResendRelation(player);
        }
Пример #2
0
 public void AddCharacterToGuild(Player player, Guild guild)
 {
     string SQL = "UPDATE guilds SET guildmembers = ?player WHERE guildname = ?gname";
     MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
     cmd.Parameters.AddWithValue("?player", player);
     cmd.Parameters.AddWithValue("?gname", guild.GuildName);
 }
Пример #3
0
        public void AddNewGuild(List<Player> players, string guildName)
        {
            Guild g = new Guild
                          {
                              GuildLogo = "",
                              GuildName = guildName,
                              CreationDate = RandomUtilities.GetRoundedUtc(),
                              GuildHistory = new List<HistoryEvent>(),
                              GuildRanks = new List<GuildMemberRank>()
                          };

            AddNewRank(g, new GuildMemberRank {RankId = 1, RankName = "Guildmaster"});
            AddNewRank(g, new GuildMemberRank {RankId = 2, RankName = "Recruit"});

            foreach (Player player in players)
            {
                AddMemberToGuild(player, g);
                SystemMessages.GuildHasBeenCreated(guildName).Send(player.Connection);
            }

            lock (GuildsLock)
                 //DAOManager.guildDAO.SaveGuild(gu)

            Global.UsedGuildNames.Add(g.GuildName.ToLower());
        }
Пример #4
0
 private Player GetPlayerById(Guild guild, int playerId)
 {
     return guild.GuildMembers.FirstOrDefault(pl => pl.Key.PlayerId == playerId).Key;
 }
Пример #5
0
        public Player GetLeader(Guild guild)
        {
            if (guild == null)
                return null;

            return guild.GuildMembers.FirstOrDefault(player => player.Value == 1).Key;
        }
Пример #6
0
 public void SendPacketToGuildMembers(ISendPacket packet, Guild guild, Player sender = null)
 {
     lock (guild.MembersLock)
         foreach (
             KeyValuePair<Player, int> guildMember in
                 guild.GuildMembers.Where(
                     guildMember => Communication.Global.PlayerService.IsPlayerOnline(guildMember.Key) && !guildMember.Key.Equals(sender)))
             packet.Send(guildMember.Key.Connection);
 }
Пример #7
0
        public void DisbandGuild(Player initiator, Guild guild)
        {
            if(!GetLeader(guild).Equals(initiator))
                return;

            SendPacketToGuildMembers(SystemMessages.TheGuildHasBeenDisbanded(guild.GuildName), guild);

            lock (guild.MembersLock)
            {
                foreach (KeyValuePair<Player, int> guildMember in guild.GuildMembers)
                {
                    guildMember.Key.Guild = null;
                    SendGuildToPlayer(guildMember.Key);
                }
            }

            guild.GuildMembers = null;

            lock (GuildsLock)
                //Cache.Guilds.Remove(guild.GuildId);

            if (Global.UsedGuildNames.Contains(guild.GuildName.ToLower()))
                Global.UsedGuildNames.Remove(guild.GuildName.ToLower());
        }
Пример #8
0
 public SpGuildHistory(Guild guild)
 {
     Guild = guild;
 }
Пример #9
0
        private void SendGuildInformationToOnlineMembers(Guild guild)
        {
            if(guild == null)
                return;

            lock (guild.MembersLock)
                foreach (KeyValuePair<Player, int> member in guild.GuildMembers)
                    if (Communication.Global.PlayerService.IsPlayerOnline(member.Key))
                        new SpGuildRanking(member.Key).Send(member.Key);
        }
Пример #10
0
        private void AddNewRank(Guild guild, GuildMemberRank rank)
        {
            if(guild == null)
                return;

            if (rank.RankName == "Guildmaster")
                rank.RankPrivileges = 7;

            guild.GuildRanks.Add(rank);

            AddHistoryEvent(guild, new HistoryEvent {Args = GuildHistoryStrings.AddNewRank(rank.RankName)});

            UpdateGuild(guild);
        }
Пример #11
0
        public void CreateNewRank(Guild guild, string rankName)
        {
            if(guild == null)
                return;

            if(guild.GuildRanks.Count >= 10)
                return;

            if(guild.GuildRanks.FirstOrDefault(rank => rank.RankName.ToLower() == rankName.ToLower()) != null)
                return;

            AddNewRank(guild,
                       new GuildMemberRank
                           {
                               RankId = guild.GuildRanks.Last().RankId + 1,
                               RankName = rankName,
                               RankPrivileges = 0
                           });

            UpdateGuild(guild);
        }
Пример #12
0
        public void AddHistoryEvent(Guild guild, HistoryEvent hEvent, Player initiator = null)
        {
            if(guild == null)
                return;

            hEvent.Date = RandomUtilities.GetRoundedUtc();

            guild.GuildHistory.Add(hEvent);

            //TODO update
        }
Пример #13
0
        public Dictionary<int, Guild> LoadGuilds()
        {
            string SQL = "SELECT * FROM `guilds`";
            MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
            MySqlDataReader LoadGuildsReader = cmd.ExecuteReader();

            Dictionary<int, Guild> guildlist = new Dictionary<int, Guild>();
            if (LoadGuildsReader.HasRows)
            {
                while (LoadGuildsReader.Read())
                {
                    Guild tmpGuild = new Guild();
                    {
                        //TODO: 
                    };
                    guildlist.Add(tmpGuild.GuildId, tmpGuild);
                }
            }
            LoadGuildsReader.Close();

            return guildlist;
        }
Пример #14
0
        /*
        public List<Player> LoadPlayerGuild(string accName)
        {
            string cmdString = "SELECT * FROM `guilds` WHERE AccountName=?username AND deleted = ?delete";
            MySqlCommand command = new MySqlCommand(cmdString, GuildDAOConnection);
            command.Parameters.AddWithValue("?username", accName);
            command.Parameters.AddWithValue("?delete", 0);
            MySqlDataReader reader = command.ExecuteReader();

            List<Player> players = new List<Player>();
            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    Player player = new Player()
                    {
                        Id = reader.GetInt32(0),
                        AccountName = reader.GetString(1),
                        Level = reader.GetInt32(2),
                        Exp = reader.GetInt64(3),
                        ExpRecoverable = reader.GetInt64(4),
                        Mount = reader.GetInt32(5),
                        UiSettings = (reader.GetString(6) != null) ? HexToBytes(reader.GetString(6)) : new byte[0],
                        GuildAccepted = (byte)reader.GetInt16(7),
                        PraiseGiven = (byte)reader.GetInt16(8),
                        LastPraise = reader.GetInt32(9),
                        CurrentBankSection = reader.GetInt32(10),
                        CreationDate = reader.GetInt32(11),
                        LastOnline = reader.GetInt32(12)
                    };
                    players.Add(player);
                }
            }
            reader.Close();

            foreach (var player in players)
            {
                cmdString = "SELECT * FROM character_data WHERE PlayerId=?id";
                command = new MySqlCommand(cmdString, PlayerDAOConnection);
                command.Parameters.AddWithValue("?id", player.Id);
                reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {

                        player.PlayerData = new PlayerData()
                        {
                            Name = reader.GetString(1),
                            Gender = (Gender)Enum.Parse(typeof(Gender), reader.GetString(2)),
                            Race = (Race)Enum.Parse(typeof(Race), reader.GetString(3)),
                            Class = (PlayerClass)Enum.Parse(typeof(PlayerClass), reader.GetString(4)),
                            Data = HexToBytes(reader.GetString(5)),
                            Details = HexToBytes(reader.GetString(6)),
                        };

                        player.Position = new Structures.World.WorldPosition()
                        {
                            MapId = reader.GetInt32(7),
                            X = reader.GetFloat(8),
                            Y = reader.GetFloat(9),
                            Z = reader.GetFloat(10),
                            Heading = reader.GetInt16(11)
                        };
                    }
                }
                reader.Close();
            }

            
            return players;
        }
         */

        public bool AddGuildRank(Guild g, GuildMemberRank gmr)
        {
            string SQL = "INSERT INTO guild_ranks "
            + "(gid, rankprivileges, rankname) "
            + "VALUES(?gid, ?rankpriv, ?rankname);";

            // Are we GM
            if (gmr.RankName == "GuildMaster")
                gmr.RankPrivileges = 7;
            else
                gmr.RankPrivileges = 0;

            MySqlCommand cmd = new MySqlCommand(SQL, GuildDAOConnection);
            cmd.Parameters.AddWithValue("?gid", g.GuildId);
            cmd.Parameters.AddWithValue("?rankpriv", gmr.RankPrivileges);
            cmd.Parameters.AddWithValue("?rankname", gmr.RankName);

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                Logger.WriteLine(LogState.Exception ,"DAO: Guild Rank Add Error!" + ex.Message);
                return false;
            }
            return true;
        }
Пример #15
0
 private Player GetPlayerByName(Guild guild, string name)
 {
     return guild.GuildMembers.FirstOrDefault(pl => pl.Key.PlayerData.Name == name).Key;
 }
Пример #16
0
        public void UpdateGuild(Guild guild)
        {
            if(guild == null)
                return;

            if(guild.GuildMembers == null)
                return;

            lock (guild.MembersLock)
            {
                foreach (var member in guild.GuildMembers)
                {
                    if(Communication.Global.PlayerService.IsPlayerOnline(member.Key))
                    {
                        new SpGuildRanking(member.Key).Send(member.Key);
                        new SpGuildMemberList(guild).Send(member.Key);
                    }
                }
            }
        }
Пример #17
0
 public void LeaveGuild(Player player, Guild guild)
 {
     RemoveMember(player, guild);
 }
Пример #18
0
        public void RemoveMember(Player player, Guild guild)
        {
            if(guild == null)
                return;

            lock (guild.MembersLock)
            {
                guild.GuildMembers.Remove(player);
                player.Guild = null;
            }

            if(Communication.Global.PlayerService.IsPlayerOnline(player))
                new SpGuildMemberList().Send(player);

            SystemMessages.YouLeftTheGuild(guild.GuildName).Send(player.Connection);

            if (GetLeader(guild).Equals(player) || guild.GuildMembers.Count <= 1)
            {
                DisbandGuild(GetLeader(guild), guild);
                return;
            }

            SendPacketToGuildMembers(SystemMessages.PlayerHasBeenRemovedFromTheGuild(player.PlayerData.Name), guild);

            UpdateGuild(guild);

            Communication.Global.RelationService.ResendRelation(player);
        }
Пример #19
0
 public void ChangeGuildIcon(Player initiator, Guild guild, byte[] newIcon)
 {
     throw new NotImplementedException();
 }
Пример #20
0
 public SpGuildRanking(Player player)
 {
     Guild = player.Guild;
     Player = player;
 }
Пример #21
0
 public SpGuildMemberList(Guild guild)
 {
     Guild = guild;
 }