Beispiel #1
0
        public static void AddGuildStone(MabiGuild guild)
        {
            var extra = string.Format("<xml guildid=\"{0}\"{1}/>", guild.Id, guild.HasOption(GuildOptionFlags.Warp) ? " gh_warp=\"true\"" : "");
            var prop = new MabiProp("", guild.Name, extra, (uint)guild.StoneClass, guild.Region, guild.X, guild.Y, guild.Rotation);

            WorldManager.Instance.AddProp(prop);
            WorldManager.Instance.SetPropBehavior(new MabiPropBehavior(prop, GuildstoneTouch));
        }
Beispiel #2
0
 /// <summary>
 /// Sends info on guild membership status changed. Pass null for guild to remove.
 /// </summary>
 /// <param name="guild"></param>
 /// <param name="creature"></param>
 /// <returns></returns>
 public static MabiPacket GuildMembershipChanged(MabiGuild guild, MabiCreature creature, GuildMemberRank rank = GuildMemberRank.Member)
 {
     var p = new MabiPacket(Op.GuildMembershipChanged, creature.Id);
     if (guild == null)
     {
         p.PutInt(0);
     }
     else
     {
         p.PutInt(1);
         p.PutString(guild.Name);
         p.PutLong(guild.Id);
         p.PutInt((uint)rank); // (5) Member Rank?
         p.PutByte(0);
     }
     return p;
 }
Beispiel #3
0
        /// <summary>
        /// Sends GuildMessage to creature's client.
        /// </summary>
        public static void GuildMessage(MabiCreature creature, MabiGuild guild, string format, params object[] args)
        {
            var character = creature as MabiPC;

            var packet = new MabiPacket(Op.GuildMessage, creature.Id);
            packet.PutLong(guild.Id);
            packet.PutString(character == null ? "Aura" : character.Server);
            packet.PutLong(creature.Id);
            packet.PutString(guild.Name);
            packet.PutString(string.Format(format, args));
            packet.PutByte(1);
            packet.PutByte(1);

            creature.Client.Send(packet);
        }
Beispiel #4
0
        public static bool CreateGuild(string name, GuildType type, MabiCreature leader, IEnumerable<MabiCreature> otherMembers)
        {
            if (WorldDb.Instance.GetGuildForChar(leader.Id) != null)
            {
                Send.MsgBox(leader.Client, leader, Localization.Get("guild.already_you")); // You are already a member of a guild
                return false;
            }

            foreach (var member in otherMembers)
            {
                if (WorldDb.Instance.GetGuildForChar(member.Id) != null)
                {
                    Send.MsgBox(leader.Client, leader, Localization.Get("guild.already"), member.Name); // {0} is already a member of a guild
                    return false;
                }
            }

            if (!WorldDb.Instance.GuildNameOkay(name))
            {
                Send.MsgBox(leader.Client, leader, Localization.Get("guild.name_used")); // That name is not valid or is already in use.
                return false;
            }

            // TODO: checks in here...

            var pos = leader.GetPosition();

            var guild = new MabiGuild();
            guild.IntroMessage = string.Format(Localization.Get("guild.intro"), name);         // Guild stone for the {0} guild
            guild.LeavingMessage = string.Format(Localization.Get("guild.leaving"), name);	   // You have left the {0} guild
            guild.RejectionMessage = string.Format(Localization.Get("guild.rejection"), name); // You have been denied admission to the {0} guild.
            guild.WelcomeMessage = string.Format(Localization.Get("guild.welcome"), name);	   // Welcome to the {0} guild!
            guild.Name = name;
            guild.Region = leader.Region;
            guild.X = pos.X;
            guild.Y = pos.Y;
            guild.Rotation = leader.Direction;
            guild.StoneClass = GuildStoneType.Normal;
            guild.Type = type;

            var guildId = guild.Save();

            leader.GuildMember = new MabiGuildMember(leader.Id, guildId, GuildMemberRank.Leader);
            leader.GuildMember.Save();
            foreach (var member in otherMembers)
            {
                member.GuildMember = new MabiGuildMember(member.Id, guildId, GuildMemberRank.SeniorMember);
                member.GuildMember.Save();
            }

            // Reload guild to make sure it gets initialized and gets an id
            guild = WorldDb.Instance.GetGuild(guildId);

            leader.Guild = guild;

            WorldManager.Instance.Broadcast(PacketCreator.GuildMembershipChanged(guild, leader, GuildMemberRank.Leader), SendTargets.Range, leader);

            foreach (var member in otherMembers)
            {
                member.Guild = guild;
                WorldManager.Instance.Broadcast(PacketCreator.GuildMembershipChanged(guild, member, GuildMemberRank.SeniorMember), SendTargets.Range, member);
            }

            AddGuildStone(guild);

            Send.ChannelNotice(NoticeType.Top, 20000, Localization.Get("guild.created"), name, leader.Name); // {0} Guild has been created. Guild leader: {1}

            return true;
        }