/// <summary> /// Demote: Decrease the rank of a guild member. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Demote(CharData ch, string[] str) { if( ch == null ) return; SocketConnection victimSocket; int count; bool loggedIn = false; if (str.Length == 0) { ch.SendText("Demote whom?\r\n"); return; } if (!ch.IsGuild() || ((PC)ch).GuildRank != Guild.Rank.leader) { ch.SendText("You don't have the power to do this.\r\n"); return; } Guild guild = ((PC)ch).GuildMembership; CharData victim = null; foreach (CharData worldChar in Database.CharList) { if (worldChar.IsNPC()) { continue; } if (MUDString.NameContainedIn(str[0], worldChar.Name)) { victim = worldChar; loggedIn = true; break; } } if (victim == null) { if (!(CharData.LoadPlayer((victimSocket = new SocketConnection()), str[0]))) { ch.SendText("Who's that?!\r\n"); return; } victim = victimSocket.Original ? victimSocket.Original : victimSocket.Character; loggedIn = false; } if (victim.IsNPC()) { ch.SendText("NPCs are not guildable!\r\n"); return; } if (!ch.IsSameGuild(victim)) { SocketConnection.Act("$N&n isn't even from $t.", ch, guild.WhoName, victim, SocketConnection.MessageTarget.character); return; } switch (((PC)victim).GuildRank) { default: ch.SendText("You can't demote this person.\r\n"); return; case Guild.Rank.normal: ch.SendText("You can't demote them any further.\r\n"); return; case Guild.Rank.senior: case Guild.Rank.officer: case Guild.Rank.deputy: break; case Guild.Rank.leader: if (str.Length > 1 && MUDString.StringsNotEqual(str[1], "confirm")) { ch.SendText("Try 'demote leadername confirm' to demote a leader.\r\n"); return; } break; } ((PC)victim).GuildRank--; Guild.Rank newrank = ((PC)victim).GuildRank; SetTitle(victim, guild.RankNames[(int)((PC)victim).GuildRank]); string text = String.Format("Log {0}: demoting {1} to {2}", ch.Name, victim.Name, ((PC)ch).GuildMembership.Name); Database.LogGuild(text); text = String.Format( "The grand Overlord {0} says:\r\n\r\n" + "'I hereby demote you {1} to {2}!!!'\r\n" + "You should make more efforts to improve!", ch.Name, victim.Name, newrank); if (loggedIn) { victim.SendText(text); } SocketConnection.Act("You have demoted $N to $t.", ch, newrank.ToString(), victim, SocketConnection.MessageTarget.character); for (count = 0; count < Limits.MAX_GUILD_MEMBERS; ++count) { if (!MUDString.StringsNotEqual(guild.Members[count].Name, victim.Name)) { guild.Members[count].Rank = ((PC)victim).GuildRank; } } CharData.SavePlayer(victim); guild.Save(); /* Close rented chars pfile. */ if (!loggedIn) { victimSocket = null; } return; }
/// <summary> /// Exile a player from a guild. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Exile(CharData ch, string[] str) { if( ch == null ) return; if (str.Length == 0) { ch.SendText("Exile whom?\r\n"); return; } if (!ch.IsGuild() || ((PC)ch).GuildRank != Guild.Rank.leader) { ch.SendText("You don't have the power to do this.\r\n"); return; } Guild guild = ((PC)ch).GuildMembership; CharData victim = ch.GetCharWorld(str[0]); if (!victim) { ch.SendText("They aren't here.\r\n"); return; } if (victim.IsNPC() || victim == ch || victim.Level > ch.Level) return; if (!ch.IsSameGuild(victim)) { SocketConnection.Act("$N isn't even from $t.", ch, guild.WhoName, victim, SocketConnection.MessageTarget.character); return; } string text = String.Format("Log {0}: exiling {1} from {2}", ch.Name, victim.Name, ((PC)ch).GuildMembership.Name); Database.LogGuild(text); // This function handles resetting member data victim.RemoveFromGuild(); ((PC)victim).GuildRank = Guild.Rank.exiled; text = String.Format( "The grand Overlord of {0} {1} says:\r\n\r\n" + "'Then so be done, you {2} shall be exiled from {3}!'\r\n" + "You hear a thundering sound...\r\n\r\n" + "A booming voice says: 'You have been exiled. Only the gods can allow you\r\n" + "to join another clan, order or guild!'\r\n", guild.WhoName, guild.Overlord, victim.Name, guild.WhoName); victim.SendText(text); SocketConnection.Act("You have exiled $N&n from $t!", ch, guild.WhoName, victim, SocketConnection.MessageTarget.character); CharData.SavePlayer(victim); guild.Save(); return; }
/// <summary> /// Sets a character's title, cropped to a maximum length to avoid word wrap. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Title(CharData ch, string[] str) { if( ch == null ) return; int point; if (!ch || ch.IsNPC()) return; if (str.Length < 2) { ch.SendText("&nChange whose title to what?\r\n"); return; } CharData victim = ch.GetCharWorld(str[0]); if (!victim) { ch.SendText("&nThat person isn't here.\r\n"); return; } if (ch.IsSameGuild(victim) && !ch.IsImmortal()) { /* Officers and deputies can title themselves. */ if (ch == victim && ((PC)ch).GuildRank < Guild.Rank.officer) { ch.SendText("&nThey might not appreciate that.\r\n"); return; } /* Leaders can title others. */ if (ch != victim && ((PC)ch).GuildRank < Guild.Rank.leader) { ch.SendText("You can't do that to another at your rank.\r\n"); return; } } else if (!ch.IsImmortal() || (ch.Level <= victim.Level && ch != victim) || ch.IsNPC() || victim.IsNPC()) { SocketConnection.Act("$N&n might not appreciate that.", ch, null, victim, SocketConnection.MessageTarget.character); return; } string text = String.Join(" ", str, 1, (str.Length - 1)); int length = 0; for (point = 0; point < text.Length; ++point) { if (text[point] == '&') { /* Don't count color codes. */ point++; /* Skip the &n's. */ if (!(text[point] == 'N' || text[point] == 'n')) { /* Skip the &+'s and &-'s. */ if (text[point] == '+' || text[point] == '-') { point++; } else { // Cap title at max length if (++length >= Limits.MAX_TITLE_LENGTH) { text = text.Substring(0, point); break; } } } } else { // Cap title at max length. if (++length >= Limits.MAX_TITLE_LENGTH) { text = text.Substring(0, Limits.MAX_TITLE_LENGTH); break; } } } SetTitle(victim, text); ch.SendText("&nOk.\r\n"); }
/// <summary> /// Promote target to another rank in the guild. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void Promote(CharData ch, string[] str) { if( ch == null ) return; SocketConnection victimSocket; int count; bool loggedIn = false; if (ch.IsNPC()) { return; } if (str.Length == 0) { ch.SendText("Promote whom?\r\n"); return; } if (!ch.IsGuild() || ((PC)ch).GuildRank != Guild.Rank.leader) { ch.SendText("You don't have the power to do this. Only a leader may promote someone.\r\n"); return; } Guild guild = ((PC)ch).GuildMembership; CharData victim = null; foreach (CharData worldChar in Database.CharList) { if (worldChar.IsNPC()) { continue; } if (MUDString.NameContainedIn(str[0], worldChar.Name)) { victim = worldChar; loggedIn = true; break; } } if (victim == null) { if (!(CharData.LoadPlayer((victimSocket = new SocketConnection()), str[0]))) { ch.SendText("Who's that?!\r\n"); return; } victim = victimSocket.Original ? victimSocket.Original : victimSocket.Character; loggedIn = false; } if (victim.IsNPC() || victim == ch) { return; } if (!ch.IsSameGuild(victim)) { SocketConnection.Act("$N&n isn't even from $t.", ch, guild.WhoName, victim, SocketConnection.MessageTarget.character); return; } // This is technically where we would give them their guild badges. switch (((PC)victim).GuildRank) { default: return; case Guild.Rank.normal: case Guild.Rank.officer: case Guild.Rank.senior: case Guild.Rank.deputy: break; case Guild.Rank.leader: ch.SendText("You may not promote that person any further.\r\n"); return; } ((PC)victim).GuildRank++; Guild.Rank newrank = ((PC)victim).GuildRank; SetTitle(victim, guild.RankNames[(int)((PC)victim).GuildRank]); string text = String.Format("Log {0}: promoting {1} to {2} in guild {3}", ch.Name, victim.Name, newrank, ((PC)ch).GuildMembership.Name); Database.LogGuild(text); text = String.Format( "The grand Overlord {0} says:\r\n\r\nI hereby promote you {1} to {2}!'\r\n", ch.Name, victim.Name, newrank); if (loggedIn) { victim.SendText(text); } SocketConnection.Act("You have promoted $N&n to $t.", ch, newrank.ToString(), victim, SocketConnection.MessageTarget.character); for (count = 0; count < Limits.MAX_GUILD_MEMBERS; ++count) { if (!MUDString.StringsNotEqual(guild.Members[count].Name, victim.Name)) { guild.Members[count].Rank = ((PC)victim).GuildRank; } } CharData.SavePlayer(victim); guild.Save(); /* Close rented chars pfile. */ if (!loggedIn) { victimSocket = null; } return; }
/// <summary> /// Kick a character out of a guild. /// </summary> /// <param name="ch"></param> /// <param name="str"></param> public static void KickOut(CharData ch, string[] str) { if( ch == null ) return; SocketConnection victimSocket; bool loggedIn = false; if (str.Length == 0) { ch.SendText("Kick out whom?\r\n"); return; } if (!ch.IsGuild() || ((PC)ch).GuildRank < Guild.Rank.officer) { ch.SendText("You don't have the power to do this.\r\n"); return; } Guild guild = ((PC)ch).GuildMembership; CharData victim = null; foreach (CharData worldChar in Database.CharList) { if (worldChar.IsNPC()) { continue; } if (MUDString.NameContainedIn(str[0], worldChar.Name)) { victim = worldChar; loggedIn = true; break; } } if (victim == null) { if (!(CharData.LoadPlayer((victimSocket = new SocketConnection()), str[0]))) { ch.SendText("Who's that?!\r\n"); return; } victim = victimSocket.Original ? victimSocket.Original : victimSocket.Character; loggedIn = false; } if (victim.IsNPC()) { return; } if (victim == ch) { ch.SendText("Try &+rsociety secede&n!\r\n"); return; } if (!ch.IsSameGuild(victim)) { SocketConnection.Act("$N&n isn't even from $t.", ch, guild.WhoName, victim, SocketConnection.MessageTarget.character); return; } if (((PC)ch).GuildRank <= ((PC)victim).GuildRank) { ch.SendText("You don't have the power to do this.\r\n"); return; } string text = String.Format("Log {0}: kicking {1} from {2}", ch.Name, victim.Name, ((PC)ch).GuildMembership.Name); Database.LogGuild(text); // this _function _resets member data victim.RemoveFromGuild(); ((PC)victim).GuildRank = Guild.Rank.normal; if (loggedIn) { victim.SendText("&+RYou have been booted from your guild!&n\r\n"); } ch.SendText("You have kicked them out of the guild.\r\n"); CharData.SavePlayer(victim); guild.Save(); /* Close rented chars pfile. */ if (!loggedIn) { victimSocket = null; } return; }
/// <summary> /// Channel function - sends text to a specific output channel. /// </summary> /// <param name="ch"></param> /// <param name="argument"></param> /// <param name="channel"></param> /// <param name="verb"></param> public static void SendToChannel( CharData ch, string argument, TalkChannel channel, string verb ) { if (ch == null || String.IsNullOrEmpty(argument)) { return; } string text; int position; if( String.IsNullOrEmpty(argument) ) { text = String.Format( "{0} what?\r\n", verb ); ch.SendText( text ); return; } if( !ch.IsNPC() && ch.HasActionBit(PC.PLAYER_SILENCE ) ) { text = String.Format( "You can't {0}.\r\n", verb ); ch.SendText( text ); return; } if( !ch.CanSpeak() ) { ch.SendText( "Your lips move but no sound comes out.\r\n" ); return; } ch.SetListening(channel, true); // Make the words look drunk if needed... argument = DrunkSpeech.MakeDrunk( argument, ch ); switch( channel ) { default: text = String.Format( "You {0} '{1}'\r\n", verb, argument ); ch.SendText( text ); text = String.Format( "$n&n {0}s '$t'", verb ); break; case TalkChannel.shout: text = String.Format( "You {0} '{1}'\r\n", verb, argument ); ch.SendText( text ); text = String.Format( "$n&n {0}s '$t'", verb ); break; case TalkChannel.yell: text = String.Format( "You {0} '{1}'\r\n", verb, argument ); ch.SendText( text ); text = String.Format( "$n&n {0}s '$t'", verb ); break; case TalkChannel.guild: text = String.Format( "&+L[&+C$n&+L]&n&+c $t&n" ); Act( text, ch, argument, null, MessageTarget.character ); break; case TalkChannel.immortal: text = String.Format( "&+L[&+r$n&+L]&n $t" ); position = ch.CurrentPosition; ch.CurrentPosition = Position.standing; Act( text, ch, argument, null, MessageTarget.character ); ch.CurrentPosition = position; break; } foreach( SocketConnection socket in Database.SocketList ) { CharData originalChar = socket.Original ? socket.Original : socket.Character; CharData targetChar = socket.Character; if( socket.ConnectionStatus == ConnectionState.playing && targetChar != ch && !originalChar.IsListening( channel ) && !originalChar.InRoom.HasFlag( RoomTemplate.ROOM_SILENT ) ) { if( channel == TalkChannel.immortal && !originalChar.IsImmortal() ) continue; if( channel == TalkChannel.guild && ( !originalChar.IsGuild() || !ch.IsSameGuild( originalChar ) ) ) continue; if( channel == TalkChannel.shout && targetChar.InRoom.Area != ch.InRoom.Area && !targetChar.IsImmortal() ) continue; position = targetChar.CurrentPosition; if( channel != TalkChannel.shout && channel != TalkChannel.yell ) targetChar.CurrentPosition = Position.standing; if( channel == TalkChannel.shout || channel == TalkChannel.yell ) { // TODO: BUG: FIXME: Get rid of this hard-coded mob index number crap! if( ( ch.IsNPC() && ( ch.MobileTemplate.IndexNumber == 9316 || ch.MobileTemplate.IndexNumber == 9748 ) ) || (!targetChar.IsNPC() && targetChar.HasActionBit(PC.PLAYER_SHOUT))) { // Add foreign language filter if( !ch.IsNPC() ) { Act( text, ch, TranslateText( argument, ch, originalChar ), targetChar, MessageTarget.victim ); } else { Act( text, ch, argument, targetChar, MessageTarget.victim ); } } } else { Act( text, ch, argument, targetChar, MessageTarget.victim ); } targetChar.CurrentPosition = position; } } return; }
/// <summary> /// Function for use with portal spells. Can be reused for other spells if applicable. /// </summary> /// <param name="ch"></param> /// <param name="victim"></param> /// <returns></returns> public static bool HasSpellConsent( CharData ch, CharData victim ) { if( victim.IsNPC() || ch.IsNPC() ) return true; if( ch.IsSameGuild( victim ) ) return true; if( ch.IsSameGroup( victim ) ) return true; if( ch.IsImmortal() ) return true; if( !victim.IsConsenting(ch) ) { ch.SendText( "You do not have their consent.\r\n" ); return false; } return true; }