Example #1
0
        public void AddMember(WorldCharacter Character, GuildAcademyRank Rank)
        {
            if (Character.Character.CharLevel < 10
                || Character.Character.CharLevel > 60)
                return;

            if (Character.IsInGuild
                || Character.IsInGuildAcademy)
            {
               Handlers.Handler38.SendAcademyResponse(Character.Client, Guild.Name, GuildAcademyResponse.AlreadyInAcademy);
                return;
            }

            lock (Guild.ThreadLocker)
            {
                if (Members.Count >= MaxMembers)
                {
                    Handlers.Handler38.SendAcademyResponse(Character.Client, Guild.Name, GuildAcademyResponse.AcademyFull);
                    return;
                }

                var registerDate = Program.CurrentTime;

                //add to sql
                using (var con = Program.DatabaseManager.GetClient().GetConnection())
                {
                    using (var cmd = con.CreateCommand())
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.CommandText = "GuildAcademyMember_Create";

                        cmd.Parameters.Add(new MySqlParameter("@pGuildID", Guild.ID));
                        cmd.Parameters.Add(new MySqlParameter("@pCharacterID", Character.ID));
                        cmd.Parameters.Add(new MySqlParameter("@pRegisterDate", registerDate));
                        cmd.Parameters.Add(new MySqlParameter("@pRank", (byte)Rank));

                        switch (Convert.ToInt32(cmd.ExecuteScalar()))
                        {
                            case 0:

                                var member = new GuildAcademyMember(this, Character, registerDate, Rank);

                                //Add to list
                                Members.Add(member);

                                //Update character
                                Character.Guild = Guild;
                                Character.GuildAcademy = this;
                                Character.GuildAcademyMember = member;

                                //send packets to client
                                Handlers.Handler38.SendAcademyResponse(Character.Client, Guild.Name, GuildAcademyResponse.JoinSuccess);
                                using (var packet = new Packet(SH4Type.CharacterGuildacademyinfo))
                                {
                                    WriteInfo(packet);

                                    Character.Client.SendPacket(packet);
                                }

                                member.BroadcastGuildName();
                                using (var packet = new Packet(SH38Type.AcademyMemberJoined))
                                {
                                    member.WriteInfo(packet);

                                    Broadcast(packet);
                                    Guild.Broadcast(packet);
                                }

                                //send packet to zones
                                using (var packet = new InterPacket(InterHeader.ZONE_AcademyMemberJoined))
                                {
                                    packet.WriteInt(Guild.ID);
                                    packet.WriteInt(Character.ID);
                                    packet.WriteDateTime(registerDate);

                                    ZoneManager.Instance.Broadcast(packet);
                                }

                                break;

                            case -1:
                                Handlers.Handler38.SendAcademyResponse(Character.Client, Guild.Name, GuildAcademyResponse.AlreadyInAcademy);
                                return;
                            case -2:
                            default:
                                Handlers.Handler38.SendAcademyResponse(Character.Client, Guild.Name, GuildAcademyResponse.DatabaseError);
                                return;
                        }
                    }
                }
            }
        }
Example #2
0
        public static void On_GameClient_UpdateGuildMessage(WorldClient Client, Packet Packet)
        {
            ushort length;
            string message;
            if (Client.Character.Guild == null
                || !Packet.TryReadUShort(out length)
                || !Packet.TryReadString(out message, length))
            {
                return;
            }

            //response packets
            using (var packet = new Packet(SH29Type.UnkMessageChange))
            {
                packet.WriteHexAsBytes("68 1B 00 92 AD F8 4F 2E 00 00 00 2B 00 00 00 17 00 00 00 07 00 00 00 06 00 00 00 70 00 00 00 06 00 00 00 BC 00 00 00 01 00 00 00 00 00");

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.ClearGuildDetailsMessage))
            {
                packet.WriteUShort(3137);
                packet.WriteLong(0);

                Client.SendPacket(packet);
            }
            using (var packet = new Packet(SH29Type.UpdateGuildMessageResponse))
            {
                packet.WriteUShort(3137);
                Client.SendPacket(packet);
            }

            //update guild
            lock (Client.Character.Guild.ThreadLocker)
            {
                Client.Character.Guild.Message = message;
                Client.Character.Guild.MessageCreater = Client.Character;
                Client.Character.Guild.MessageCreateTime = Program.CurrentTime;

                Client.Character.Guild.Save();

                //broadcast packet to all guild members
                using (var packet = new Packet(SH29Type.SendUpdateGuildDetails))
                {
                    packet.Fill(4, 0x00);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Second);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Minute);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Hour);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Day);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Month - 1);
                    packet.WriteInt(Client.Character.Guild.MessageCreateTime.Year - 1900);
                    packet.WriteInt(0);
                    packet.WriteLong(0);
                    packet.WriteString(Client.Character.Character.Name, 16);
                    packet.WriteUShort(length);
                    packet.WriteString(message, length);

                    Client.Character.Guild.Broadcast(packet);
                }

                //send packet to zone that guild message changed
                using (var packet = new InterPacket(InterHeader.ZONE_GuildMessageUpdate))
                {
                    packet.WriteInt(Client.Character.Guild.ID);
                    packet.WriteInt(Client.Character.ID);
                    packet.WriteDateTime(Client.Character.Guild.MessageCreateTime);

                    packet.WriteUShort(length);
                    packet.WriteString(message, length);
                    ZoneManager.Instance.Broadcast(packet);
                }
            }
        }
Example #3
0
        private static void On_CharacterManager_CharacterLevelUp(WorldCharacter Character)
        {
            //fix later
            if (Character.IsInGuildAcademy)
            {
                using (var packet = new Packet(SH38Type.AcademyMemberLevelUp))
                {
                    packet.WriteString(Character.Character.Name, 16);
                    packet.WriteByte(Character.Character.CharLevel);

                    Character.Guild.Broadcast(packet);
                    Character.GuildAcademy.Broadcast(packet);
                }

                lock (Character.Guild.ThreadLocker)
                {
                    uint points;
                    if (GuildDataProvider.Instance.AcademyLevelUpPoints.TryGetValue(Character.Character.CharLevel, out points))
                    {
                        Character.GuildAcademy.Points += (ushort)points;
                    }

                    //add time to guild buff
                    var time = Program.CurrentTime;
                    //var newTime = Math.Min(CharacterDataProvider.ChrCommon.GuildBuffMaxTime.TotalSeconds, (CharacterDataProvider.ChrCommon.GuildBuffAddTime.TotalSeconds + Character.GuildAcademy.GuildBuffKeepTime.TotalSeconds));
                    //Character.GuildAcademy.GuildBuffKeepTime = TimeSpan.FromSeconds(newTime);

                    //update guild buff to all guild/aka members
                    var toUpdate = new List<WorldCharacter>();
                    foreach (var member in Character.GuildAcademy.Members)
                    {
                        if (member.Character.IsOnline)
                        {
                            toUpdate.Add(member.Character);
                        }
                    }
                    foreach (var member in Character.Guild.Members)
                    {
                        if (member.Character.IsOnline
                            && !toUpdate.Contains(member.Character))
                        {
                            toUpdate.Add(member.Character);
                        }
                    }

                   //BuffManager.SetBuff(GuildDataProvider.AcademyBuff, GuildDataProvider.AcademyBuffStrength, (uint)(newTime * 1000), toUpdate.ToArray());

                    toUpdate.Clear();
                    toUpdate = null;

                    //update guild buff to zones
                    using (var packet = new InterPacket(InterHeader.ZONE_AcademyBuffUpdate))
                    {
                        packet.WriteInt(Character.Guild.ID);
                        packet.WriteDateTime(time);
                        packet.WriteDouble(900);//fix later

                        ZoneManager.Instance.Broadcast(packet);
                    }

                    //broadcast info and save guild
                    Character.GuildAcademy.BroadcastInfo();
                    Character.GuildAcademy.Save();
               }
            }
        }