void InitWorld( Room[] room_db ) { /* zero out the world */ room_db = null; return; }
int RoomEnter( Room[] rb, int key, Room rm ) { Room temp = null; temp = room_find( rb, key ); if( temp ) return ( 0 ); rb[ key ] = rm; return ( 1 ); }
/// <summary> /// Scanning function. /// </summary> /// <param name="ch"></param> /// <param name="room"></param> /// <param name="text"></param> /// <param name="distance"></param> /// <param name="dir"></param> /// <returns></returns> public static int ScanRoom( CharData ch, Room room, ref string text, int distance, int dir ) { int numberFound = 0; string distanceMsg; if( dir < 0 || dir >= Limits.MAX_DIRECTION ) { Log.Error( "ScanRoom: direction {0} out of bounds!", dir ); ch.SendText( "Bug while scanning, direction out of bounds!\r\n" ); return 0; } // Not going to find anything in a room that is unscannable - Xangis if (room.HasFlag(RoomTemplate.ROOM_NO_SCAN)) { return 0; } switch( distance ) { case 1: distanceMsg = String.Format( "&n who is close by to the " ); break; case 2: distanceMsg = String.Format( "&n who is not far off to the " ); break; case 3: distanceMsg = String.Format( "&n who is a brief walk away to the " ); break; default: distanceMsg = String.Format( "&n who is an unknown distance to the " ); break; } foreach( CharData target in room.People ) { if( ch.FlightLevel == target.FlightLevel ) { Visibility visibility = Look.HowSee(ch, target); switch( visibility ) { case Visibility.sense_hidden: case Visibility.invisible: case Visibility.too_dark: default: break; case Visibility.visible: text += ( target.ShowNameTo( ch, true )); text += distanceMsg; text += dir.ToString(); text += ".&n\r\n"; numberFound++; break; case Visibility.sense_infravision: text += "&+rYou sense a being within the darkness"; text += distanceMsg; text += dir.ToString(); text += ".&n\r\n"; numberFound++; break; } } } return numberFound; }
/// <summary> /// Gets the scan info for the provided room. /// </summary> /// <param name="ch"></param> /// <param name="room"></param> /// <param name="buffer"></param> /// <param name="flyLevel"></param> /// <returns></returns> public static int ScanThisRoom( CharData ch, Room room, string buffer, CharData.FlyLevel flyLevel ) { int numberFound = 0; string levelMsg; int diff = flyLevel - ch.FlightLevel; switch( diff ) { case -3: levelMsg = String.Format( "&n who is very far beneath you." ); break; case -2: levelMsg = String.Format( "&n who is not far beneath you." ); break; case -1: levelMsg = String.Format( "&n who is close by beneath you." ); break; case 1: levelMsg = String.Format( "&n who is flying close by above you." ); break; case 2: levelMsg = String.Format( "&n who is flying not far above you." ); break; case 3: levelMsg = String.Format( "&n who is flying very far above you." ); break; default: levelMsg = String.Format( "&n who is an unknown distance away from you." ); break; } foreach( CharData target in room.People ) { if( target.FlightLevel == flyLevel ) { Visibility visibility = Look.HowSee(ch, target); switch( visibility ) { case Visibility.sense_hidden: case Visibility.invisible: case Visibility.too_dark: default: break; case Visibility.visible: buffer += ( target.ShowNameTo( ch, true )); buffer += levelMsg; buffer += "&n\r\n"; numberFound++; break; case Visibility.sense_infravision: buffer += "&+rYou sense a being within the darkness"; buffer += levelMsg; buffer += "&n\r\n"; numberFound++; break; } } } return numberFound; }
/// <summary> /// Shows text for affects on a room. /// </summary> /// <param name="ch"></param> /// <param name="room"></param> public static void ShowRoomAffects(CharData ch, Room room) { if (room.HasFlag(RoomTemplate.ROOM_EARTHEN_STARSHELL)) ch.SendText("&+yEarth moves about this room.&n\r\n"); if (room.HasFlag(RoomTemplate.ROOM_FIERY_STARSHELL)) ch.SendText("&+rFire burns in the air here.&n\r\n"); if (room.HasFlag(RoomTemplate.ROOM_AIRY_STARSHELL)) ch.SendText("&+cAir blows around viciously here.&n\r\n"); if (room.HasFlag(RoomTemplate.ROOM_WATERY_STARSHELL)) ch.SendText("&+bWater floats about in this room.&n\r\n"); if (room.HasFlag(RoomTemplate.ROOM_HYPNOTIC_PATTERN)) ch.SendText("&+mA &+bbe&+mau&+bt&+mifu&+bl pa&+mtter&+bn floa&+mts her&+be..&n\r\n"); if (room.HasFlag(RoomTemplate.ROOM_MAGICDARK)) ch.SendText("It is unnaturally &+Ldark&n here.\r\n"); if (room.HasFlag(RoomTemplate.ROOM_MAGICLIGHT)) ch.SendText("It is unnaturally &+Wbright&n here.\r\n"); }
/// <summary> /// Sends a string of text to everyone in the specified room. /// </summary> /// <param name="txt"></param> /// <param name="room"></param> private void SendToRoom( string txt, Room room ) { foreach( SocketConnection socket in Database.SocketList ) { if (socket.Character != null) { if (socket.Character.InRoom == room) { Act(txt, socket.Character, null, null, MessageTarget.character); } } } }
/// <summary> /// Finds a character in an arbitrary room. /// </summary> /// <param name="room"></param> /// <param name="ch"></param> /// <param name="argument"></param> /// <returns></returns> public static CharData GetCharAtRoom( Room room, CharData ch, string argument ) { string arg = String.Empty; int number = MUDString.NumberArgument( argument, ref arg ); int count = 0; foreach( CharData roomChar in ch.InRoom.People ) { if( ch.FlightLevel != roomChar.FlightLevel ) continue; if( !roomChar.IsNPC() && ( ch.IsRacewar( roomChar ) ) && !ch.IsImmortal() ) { if( !MUDString.NameContainedIn( arg, Race.RaceList[ roomChar.GetRace() ].Name ) ) continue; } else { if( !MUDString.NameContainedIn( arg, roomChar.Name ) ) continue; } if (++count == number) { return roomChar; } } return null; }
Room room_find( Room[] room_db, int key ) { return ( ( key < WORLD_SIZE && key > -1 ) ? room_db[ key ] : null ); }
/// <summary> /// Places an object into a room. /// </summary> /// <param name="room"></param> /// <returns></returns> public bool AddToRoom( Room room ) { if( room == null ) { Log.Error( "Object.AddToRoom(): null room.", 0 ); return false; } if( _objIndexData == null ) { Log.Error( "Object.AddToRoom(): Object has null pIndexData.", 0 ); return false; } if( _objIndexData.IndexNumber == StaticObjects.OBJECT_NUMBER_MONEY_ONE || _objIndexData.IndexNumber == StaticObjects.OBJECT_NUMBER_MONEY_SOME ) { for( int i = (room.Contents.Count-1); i >= 0; i-- ) { Object obj2 = room.Contents[i]; switch( obj2._objIndexData.IndexNumber ) { case StaticObjects.OBJECT_NUMBER_MONEY_ONE: case StaticObjects.OBJECT_NUMBER_MONEY_SOME: _objIndexData = Database.GetObjTemplate( StaticObjects.OBJECT_NUMBER_MONEY_SOME ); _name = _objIndexData.Name; _shortDescription = _objIndexData.ShortDescription; _fullDescription = _objIndexData.FullDescription; _values[ 0 ] += obj2._values[ 0 ]; _values[ 1 ] += obj2._values[ 1 ]; _values[ 2 ] += obj2._values[ 2 ]; _values[ 3 ] += obj2._values[ 3 ]; obj2.RemoveFromWorld(); break; } } } room.Contents.Insert(0, this ); _inRoom = room; if( HasFlag( ObjTemplate.ITEM_LIT ) ) { _inRoom.Light++; } return true; }
/// <summary> /// Takes an object out of the room it's currently in. /// </summary> public void RemoveFromRoom() { if( _inRoom == null ) { Log.Error( "Object.RemoveFromRoom(): Object " + _shortDescription + " not in any room."); return; } if( !_inRoom.Contents.Remove( this ) ) { Log.Error( "Object.RemoveFromRoom(): obj " + _shortDescription + " not found in room " + _inRoom.IndexNumber + "." ); // If the room doesn't recognize this object as being present we might as well reciprocate. _inRoom = null; return; } _inRoom = null; if( HasFlag( ObjTemplate.ITEM_LIT ) ) { _inRoom.Light--; } return; }
/// <summary> /// Check for falling. Called from room update and movement. /// </summary> /// <param name="room"></param> /// <param name="target"></param> /// <param name="ch"></param> public static void CheckFall( Room room, Room target, CharData ch ) { int chance; if( !room || !target || !ch ) return; if( room.TerrainType != TerrainType.air && room.TerrainType != TerrainType.plane_of_air && room.TerrainType != TerrainType.underground_no_ground ) { if( MUDMath.NumberPercent() > room.FallChance ) return; } if( ch.CanFly() || ch.IsAffected( Affect.AFFECT_LEVITATE ) ) return; if( ch.InRoom.People != null ) { SocketConnection.Act( "You are falling down!", ch, null, null, SocketConnection.MessageTarget.character ); SocketConnection.Act( "$n&n falls away.", ch, null, null, SocketConnection.MessageTarget.room ); } ch.RemoveFromRoom(); ch.AddToRoom( target ); if( !ch.HasSkill( "safe_fall" ) ) chance = 0; else if( ch.IsNPC() ) chance = ( ( ch.Level * 3 ) / 2 ) + 15; else chance = ( (PC)ch ).SkillAptitude[ "safe fall" ]; // People with high agility have a small chance to safe fall, and those with // the skill already get a bonus. chance += ( ch.GetCurrAgi() / 20 ); // Minimum 1% chance of a bad fall. if( chance > 99 ) { chance = 99; } // Safe fall added by Xangis if( target.FallChance == 0 || !target.ExitData[ 5 ] || !target.ExitData[ 5 ].TargetRoom ) { if( MUDMath.NumberPercent() < chance ) { // Decent chance of skill increase - people don't fall very often. ch.PracticeSkill( "safe fall" ); ch.PracticeSkill( "safe fall" ); ch.PracticeSkill( "safe fall" ); ch.PracticeSkill( "safe fall" ); ch.SendText( "You fall to the ground!\r\n" ); if( MUDMath.NumberPercent() < chance ) { SocketConnection.Act( "$n&n falls from above and lands gracefully.", ch, null, null, SocketConnection.MessageTarget.room ); ch.SendText( "You land gracefully, avoiding any injury.\r\n" ); } else { SocketConnection.Act( "$n&n falls from above and lands on $s arse.", ch, null, null, SocketConnection.MessageTarget.room ); if( Race.MAX_SIZE > 0 && !ch.IsNPC() ) { Combat.InflictDamage(ch, ch, MUDMath.NumberRange(2, 4), String.Empty, ObjTemplate.WearLocation.none, AttackType.DamageType.none); ch.CurrentPosition = Position.sitting; ch.WaitState( 3 ); } } } else { ch.SendText( "You slam into the ground!\r\n" ); ch.CurrentPosition = Position.sitting; ch.WaitState( 8 ); SocketConnection.Act( "$n&n comes crashing in from above.", ch, null, null, SocketConnection.MessageTarget.room ); if( Race.MAX_SIZE > 0 && !ch.IsNPC() ) { Combat.InflictDamage( ch, ch, ( ( MUDMath.NumberPercent() * (int)ch.CurrentSize ) / Race.MAX_SIZE ), String.Empty, ObjTemplate.WearLocation.none, AttackType.DamageType.none); } } } else if( ch && ch.InRoom ) { if( ch.InRoom.People.Count > 0 ) { SocketConnection.Act( "$n&n falls by.", ch, null, null, SocketConnection.MessageTarget.room ); } } return; }
/// <summary> /// Camping timer ticking away. /// /// Uses a single event for each person that is actively camping. /// </summary> /// <param name="ch"></param> /// <param name="room"></param> /// <returns></returns> static bool CampUpdate( CharData ch, Room room ) { if( !ch || !room || ch.CurrentPosition <= Position.incapacitated ) return false; if( !ch.HasActionBit(PC.PLAYER_CAMPING ) ) return false; if( ch.CurrentPosition == Position.fighting || ch.Fighting || ch.InRoom != room ) { ch.SendText( "So much for that camping effort.\r\n" ); ch.RemoveActionBit(PC.PLAYER_CAMPING); return false; } return true; }
/// <summary> /// Enhanced exit display. /// </summary> /// <param name="ch"></param> /// <param name="room"></param> public static void ShowRoomInfo(CharData ch, Room room) { if (ch == null || room == null || !ch.HasActionBit(PC.PLAYER_GODMODE)) { return; } String roomOpen = String.Empty; String roomClose = String.Empty; if( !ch.IsNPC() && ch.Socket.Terminal == SocketConnection.TerminalType.TERMINAL_ENHANCED) { roomOpen = "<room>"; roomClose = "</room>"; } string text = String.Format("{1}[{0}] {2} ({4}){3}\r\n", room.IndexNumber, roomOpen, room.Title, roomClose, room.TerrainType ); ch.SendText(text); return; }
Room RoomFindOrCreate( Room[] rb, int key ) { Room rv = null; rv = room_find( rb, key ); if( rv ) return rv; rv = new Room(); rb[ key ] = rv; return rv; }
/// <summary> /// Move a char into a room. /// </summary> /// <param name="targetRoom"></param> public void AddToRoom( Room targetRoom ) { if( targetRoom == null ) { Log.Error( "AddToRoom(): null target room.", 0 ); return; } InRoom = targetRoom; targetRoom.People.Insert(0,this); if( targetRoom.Area == null ) { Log.Error( "AddToRoom(): Room " + targetRoom.IndexNumber + " not in any area!", 0 ); return; } if( !IsNPC() ) { ++targetRoom.Area.NumPlayers; } MoveLight( true ); if( Riding ) { Riding.AddToRoom( targetRoom ); } return; }
int RoomRemove( Room[] rb, int key ) { Room tmp = null; tmp = room_find( rb, key ); if( tmp ) { rb[ key ] = null; tmp = null; } return ( 0 ); }
/// <summary> /// Display the room flags as a string. /// </summary> /// <param name="room"></param> /// <returns></returns> public static string RoomString(Room room) { string text = String.Empty; foreach(BitvectorFlagType bvf in BitvectorFlagType.RoomFlags) { if (room.HasFlag(bvf.BitvectorData)) { text += " "; text += bvf.Name; } } return (!String.IsNullOrEmpty(text)) ? text.Substring(1) : "none"; }
static void MoveXorn( System.Object mob, Room toRoom, int type ) { Room room = toRoom; CharData ch = (CharData)mob; if( room == null ) { int min = ch.InRoom.Area.LowRoomIndexNumber; int max = ch.InRoom.Area.HighRoomIndexNumber; while( !room ) { room = Room.GetRoom( MUDMath.NumberRange( min, max ) ); } } if( type == XORN_MOVE_EARTH ) SocketConnection.Act( "$n&n&+L sinks into the ground and dissappears from sight!&n", ch, null, null, SocketConnection.MessageTarget.room ); else SocketConnection.Act( "$n&n phases out of existence.", ch, null, null, SocketConnection.MessageTarget.room ); ch.RemoveFromRoom(); ch.AddToRoom( room ); if( type == XORN_MOVE_EARTH ) SocketConnection.Act( "$n&n&+L rises out of the earth right beside you.&n", ch, null, null, SocketConnection.MessageTarget.room ); else SocketConnection.Act( "$n&n phases into existence.", ch, null, null, SocketConnection.MessageTarget.room ); return; }
public Target( Room rm ) { _room = rm; _type = TargetType.room; }