/// <summary> /// Construct with the container to set as the location /// </summary> /// <param name="currentContainer">the container</param> public GlobalPosition(IContains currentContainer) { CurrentContainer = currentContainer; CurrentZone = currentContainer.CurrentLocation?.CurrentZone; CurrentLocale = currentContainer.CurrentLocation?.CurrentLocale; CurrentRoom = currentContainer.CurrentLocation?.CurrentRoom; }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { //We can't even try this until we know if the data is there if (DataTemplate == null) { throw new InvalidOperationException("Missing backing data store on object spawn event."); } var backingStore = (IInanimateData)DataTemplate; BirthMark = Birthmarker.GetBirthmark(backingStore); Keywords = new string[] { backingStore.Name.ToLower() }; Birthdate = DateTime.Now; if (spawnTo == null) { throw new NotImplementedException("Objects can't spawn to nothing"); } CurrentLocation = spawnTo; spawnTo.MoveInto <IInanimate>(this); Contents = new EntityContainer <IInanimate>(); LiveCache.Add(this); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { var ch = (ICharacter)DataTemplate; BirthMark = Birthmarker.GetBirthmark(ch); Keywords = new string[] { ch.Name.ToLower(), ch.SurName.ToLower() }; Birthdate = DateTime.Now; if (spawnTo == null) { spawnTo = GetBaseSpawn(); } CurrentLocation = spawnTo; //Set the data context's stuff too so we don't have to do this over again ch.LastKnownLocation = spawnTo.DataTemplate.ID.ToString(); ch.LastKnownLocationType = spawnTo.GetType().Name; ch.Save(); spawnTo.MoveInto <IPlayer>(this); Inventory = new EntityContainer <IInanimate>(); LiveCache.Add(this); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { var roomTemplate = (IRoomData)DataTemplate; BirthMark = Birthmarker.GetBirthmark(roomTemplate); Keywords = new string[] { roomTemplate.Name.ToLower() }; Birthdate = DateTime.Now; CurrentLocation = spawnTo; }
/// <summary> /// News up an entity with its backing data and where to spawn it into /// </summary> /// <param name="backingStore">the backing data</param> /// <param name="spawnTo">where to spawn this into</param> public Inanimate(IInanimateData backingStore, IContains spawnTo) { Contents = new EntityContainer<IInanimate>(backingStore.InanimateContainers); Pathways = new EntityContainer<IPathway>(); MobilesInside = new EntityContainer<IMobile>(backingStore.MobileContainers); DataTemplateId = backingStore.ID; SpawnNewInWorld(spawnTo); }
/// <summary> /// News up an entity with its backing data and where to spawn it into /// </summary> /// <param name="backingStore">the backing data</param> /// <param name="spawnTo">where to spawn this into</param> public Inanimate(IInanimateData backingStore, IContains spawnTo) { Contents = new EntityContainer <IInanimate>(backingStore.InanimateContainers); Pathways = new EntityContainer <IPathway>(); MobilesInside = new EntityContainer <IMobile>(backingStore.MobileContainers); DataTemplate = backingStore; SpawnNewInWorld(spawnTo); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { var bS = (IPathwayData)DataTemplate; var locationAssembly = Assembly.GetAssembly(typeof(Room)); MovementDirection = MessagingUtility.TranslateDegreesToDirection(bS.DegreesFromNorth); BirthMark = Birthmarker.GetBirthmark(bS); Keywords = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() }; Birthdate = DateTime.Now; //paths need two locations ILocation fromLocation = null; var fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType)); if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID)) { if (fromLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton))) { long fromLocationID = long.Parse(bS.FromLocationID); fromLocation = LiveCache.Get <ILocation>(fromLocationID, fromLocationType); } else { var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID); fromLocation = LiveCache.Get <ILocation>(cacheKey); } } ILocation toLocation = null; var toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType)); if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID)) { if (toLocationType.GetInterfaces().Contains(typeof(ISpawnAsSingleton))) { long toLocationID = long.Parse(bS.ToLocationID); toLocation = LiveCache.Get <ILocation>(toLocationID, toLocationType); } else { var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID); toLocation = LiveCache.Get <ILocation>(cacheKey); } } FromLocation = fromLocation; ToLocation = toLocation; CurrentLocation = fromLocation; Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination }); Enter.ToSurrounding.Add(bS.VisibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.VisibleToSurroundings })); Enter.ToSurrounding.Add(bS.AudibleStrength, new Tuple <MessagingType, IEnumerable <string> >(MessagingType.Visible, new string[] { bS.AudibleToSurroundings })); fromLocation.MoveInto <IPathway>(this); }
/// <summary> /// Executes this command /// </summary> public override void Execute() { var sb = new List <string>(); var thing = (IEntity)Subject; var actor = (IContains)Actor; IContains place = (IContains)OriginLocation; actor.MoveFrom(thing); place.MoveInto(thing); sb.Add("You drop $S$."); var messagingObject = new MessageCluster(sb, new string[] { }, new string[] { }, new string[] { "$A$ drops $S$." }, new string[] { }); messagingObject.ExecuteMessaging(Actor, thing, null, OriginLocation, null); }
/// <summary> /// Executes this command /// </summary> public override void Execute() { IEntity thing = (IEntity)Subject; IContains actor = (IContains)Actor; IContains place = (IContains)OriginLocation; actor.MoveFrom(thing); place.MoveInto(thing); ILexicalParagraph toActor = new LexicalParagraph("You drop $S$."); ILexicalParagraph toOrigin = new LexicalParagraph("$A$ drops $S$."); IMessage messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toOrigin } }; messagingObject.ExecuteMessaging(Actor, thing, null, OriginLocation.CurrentRoom, null); }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { List <string> sb = new List <string>(); IEntity thing = (IEntity)Subject; IContains actor = (IContains)Actor; IContains place; string toRoomMessage = "$A$ gets $S$."; if (Target != null) { place = (IContains)Target; toRoomMessage = "$A$ gets $S$ from $T$."; sb.Add("You get $S$ from $T$."); } else { place = (IContains)OriginLocation; sb.Add("You get $S$."); } place.MoveFrom(thing); actor.MoveInto(thing); ILexicalParagraph toActor = new LexicalParagraph(sb.ToString()); ILexicalParagraph toOrigin = new LexicalParagraph(toRoomMessage); Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toOrigin } }; messagingObject.ExecuteMessaging(Actor, thing, (IEntity)Target, OriginLocation.CurrentRoom, null); return(true); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { var bS = DataTemplate<IPathwayData>(); ; var locationAssembly = Assembly.GetAssembly(typeof(Room)); MovementDirection = Utilities.TranslateToDirection(bS.DegreesFromNorth, bS.InclineGrade); BirthMark = LiveCache.GetUniqueIdentifier(bS); Keywords = new string[] { bS.Name.ToLower(), MovementDirection.ToString().ToLower() }; Birthdate = DateTime.Now; //paths need two locations ILocation fromLocation = null; var fromLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.FromLocationType)); if (fromLocationType != null && !string.IsNullOrWhiteSpace(bS.FromLocationID)) { if (fromLocationType.GetInterfaces().Contains(typeof(ISingleton))) { long fromLocationID = long.Parse(bS.FromLocationID); fromLocation = LiveCache.Get<ILocation>(fromLocationID, fromLocationType); } else { var cacheKey = new LiveCacheKey(fromLocationType, bS.FromLocationID); fromLocation = LiveCache.Get<ILocation>(cacheKey); } } ILocation toLocation = null; var toLocationType = locationAssembly.DefinedTypes.FirstOrDefault(tp => tp.Name.Equals(bS.ToLocationType)); if (toLocationType != null && !string.IsNullOrWhiteSpace(bS.ToLocationID)) { if (toLocationType.GetInterfaces().Contains(typeof(ISingleton))) { long toLocationID = long.Parse(bS.ToLocationID); toLocation = LiveCache.Get<ILocation>(toLocationID, toLocationType); } else { var cacheKey = new LiveCacheKey(toLocationType, bS.ToLocationID); toLocation = LiveCache.Get<ILocation>(cacheKey); } } FromLocation = fromLocation; ToLocation = toLocation; CurrentLocation = fromLocation; if (String.IsNullOrWhiteSpace(bS.MessageToActor)) bS.MessageToActor = String.Empty; if (String.IsNullOrWhiteSpace(bS.MessageToDestination)) bS.MessageToDestination = String.Empty; if (String.IsNullOrWhiteSpace(bS.MessageToOrigin)) bS.MessageToOrigin = String.Empty; if (String.IsNullOrWhiteSpace(bS.MessageToOrigin)) bS.MessageToOrigin = String.Empty; if (String.IsNullOrWhiteSpace(bS.VisibleToSurroundings)) bS.VisibleToSurroundings = String.Empty; if (String.IsNullOrWhiteSpace(bS.AudibleToSurroundings)) bS.AudibleToSurroundings = String.Empty; Enter = new MessageCluster(new string[] { bS.MessageToActor }, new string[] { "$A$ enters you" }, new string[] { }, new string[] { bS.MessageToOrigin }, new string[] { bS.MessageToDestination }); Enter.ToSurrounding.Add(MessagingType.Visible, new Tuple<int, IEnumerable<string>>(bS.VisibleStrength, new string[] { bS.VisibleToSurroundings })); Enter.ToSurrounding.Add(MessagingType.Audible, new Tuple<int, IEnumerable<string>>(bS.AudibleStrength, new string[] { bS.AudibleToSurroundings })); fromLocation.MoveInto<IPathway>(this); }
public override void SpawnNewInWorld(IContains spawnTo) { //Places are containers, they don't spawn to anything UpsertToLiveWorldCache(); }
/// <summary> /// Move this inside of something /// </summary> /// <param name="container">The container to move into</param> /// <returns>was this thing moved?</returns> public virtual string TryMoveTo(IContains container) { return(TryMoveTo(new GlobalPosition(container))); }
public static bool IsIntersection(IContains inter, int move) { if (inter.GetSize() <= 2) { return(false); } int lWidth = inter.GetWidth(); int ActiveMice = 0; int[] lMousePosition = new int[4]; int[] lMouseDirection = new int[4]; int[] lMouseNextDirection = new int[4]; int[] lMouseByDirection = new int[4]; CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(lWidth); for (int i = 0; i < 4; i++) { int lNeightbor = lCoord.GetNeighbor(move, i); if (lCoord.OnBoard(lNeightbor) && inter.Contains(lNeightbor)) { lMousePosition[ActiveMice] = lNeightbor; lMouseDirection[ActiveMice] = i; lMouseByDirection[i] = ActiveMice; if (ActiveMice > 0) { lMouseNextDirection[ActiveMice - 1] = i; } ActiveMice++; } else { lMouseByDirection[i] = -1; // no mouse } } if (ActiveMice == 1) { return(false); } lMouseNextDirection[ActiveMice - 1] = 0; // it's never used! for (int CurrentMouse = 0; CurrentMouse < ActiveMice - 1; CurrentMouse++) { int CurrentMousePosition = lMousePosition[CurrentMouse]; int CurrentMouseDirection = lMouseDirection[CurrentMouse]; int CurrentMouseOriginalDirection = CurrentMouseDirection; while (CurrentMousePosition != move) { int lRightDirection = CoordinateSystem.TurnClockWise(CurrentMouseDirection); int lRightPosition = lCoord.GetNeighbor(CurrentMousePosition, lRightDirection); // if (can turn right & move) if (CoordinateSystem.OnBoard(lRightPosition, lWidth) && inter.Contains(lRightPosition)) { // yes, turn turn and move CurrentMousePosition = lRightPosition; CurrentMouseDirection = lRightDirection; } else { while (true) { int lStraightPosition = lCoord.GetNeighbor(CurrentMousePosition, CurrentMouseDirection); // if (can go straight) ( if (CoordinateSystem.OnBoard(lStraightPosition, lWidth) && inter.Contains(lStraightPosition)) { // yes, go straight CurrentMousePosition = lStraightPosition; break; } else { // else, change direction clockwise and try-again (loop) CurrentMouseDirection = CoordinateSystem.TurnCounterClockWise(CurrentMouseDirection); } } } } // right back where we started int FromDirection = CoordinateSystem.TurnAround(CurrentMouseDirection); // if mice returned from a direction other than the next direction, then there is a split if (lMouseNextDirection[CurrentMouse] != FromDirection) { return(true); } // if mouse came back from original direction then there is a split if (CurrentMouseOriginalDirection == FromDirection) { return(true); // should never reach here } // by now we know that the next mouse must merge, so no split if (CurrentMouse == ActiveMice - 1) { return(false); } } return(false); }
/// <summary> /// Executes the messaging, sending messages using WriteTo on all relevant entities /// </summary> /// <param name="Actor">The acting entity</param> /// <param name="Subject">The command's subject entity</param> /// <param name="Target">The command's target entity</param> /// <param name="OriginLocation">The location the acting entity acted in</param> /// <param name="DestinationLocation">The location the command is targetting</param> public void ExecuteMessaging(IEntity Actor, IEntity Subject, IEntity Target, IEntity OriginLocation, IEntity DestinationLocation) { Dictionary <MessagingTargetType, IEntity[]> entities = new Dictionary <MessagingTargetType, IEntity[]> { { MessagingTargetType.Actor, new IEntity[] { Actor } }, { MessagingTargetType.Subject, new IEntity[] { Subject } }, { MessagingTargetType.Target, new IEntity[] { Target } }, { MessagingTargetType.OriginLocation, new IEntity[] { OriginLocation } }, { MessagingTargetType.DestinationLocation, new IEntity[] { DestinationLocation } } }; if (Actor != null && ToActor.Any()) { if (ToActor.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str))) { Actor.WriteTo(TranslateOutput(ToActor.Select(msg => msg.Override), entities)); } else { Actor.WriteTo(TranslateOutput(ToActor.Select(msg => msg.Describe()), entities)); } } if (Subject != null && ToSubject.Any()) { if (ToSubject.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str))) { Subject.WriteTo(TranslateOutput(ToSubject.Select(msg => msg.Override), entities)); } else { Subject.WriteTo(TranslateOutput(ToSubject.Select(msg => msg.Describe()), entities)); } } if (Target != null && ToTarget.Any()) { ILanguage language = Target.IsPlayer() ? ((IPlayer)Target).Template <IPlayerTemplate>().Account.Config.UILanguage : null; if (ToTarget.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str))) { Target.WriteTo(TranslateOutput(ToTarget.Select(msg => msg.Override), entities)); } else { Target.WriteTo(TranslateOutput(ToTarget.Select(msg => msg.Describe()), entities)); } } //TODO: origin and destination are areas of effect on their surrounding areas if (OriginLocation != null && ToOrigin.Any()) { IContains oLoc = (IContains)OriginLocation; IEnumerable <IEntity> validContents = oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target)); //Message dudes in the location, including non-person entities since they might have triggers foreach (IEntity dude in validContents) { if (ToOrigin.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str))) { dude.WriteTo(TranslateOutput(ToOrigin.Select(msg => msg.Override), entities)); } else { dude.WriteTo(TranslateOutput(ToOrigin.Select(msg => msg.Describe()), entities)); } } } if (DestinationLocation != null && ToDestination.Any()) { IContains oLoc = (IContains)DestinationLocation; //Message dudes in the location, including non-person entities since they might have triggers foreach (IEntity dude in oLoc.GetContents <IEntity>().Where(dud => !dud.Equals(Actor) && !dud.Equals(Subject) && !dud.Equals(Target))) { if (ToDestination.Select(msg => msg.Override).Any(str => !string.IsNullOrEmpty(str))) { dude.WriteTo(TranslateOutput(ToDestination.Select(msg => msg.Override), entities)); } else { dude.WriteTo(TranslateOutput(ToDestination.Select(msg => msg.Describe()), entities)); } } } }
public static bool IsIntersection(IContains inter, int move) { if (inter.GetSize() <= 2) return false; int lWidth = inter.GetWidth(); int ActiveMice = 0; int[] lMousePosition = new int[4]; int[] lMouseDirection = new int[4]; int[] lMouseNextDirection = new int[4]; int[] lMouseByDirection = new int[4]; CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(lWidth); for (int i = 0; i < 4; i++) { int lNeightbor = lCoord.GetNeighbor(move, i); if (lCoord.OnBoard(lNeightbor) && inter.Contains(lNeightbor)) { lMousePosition[ActiveMice] = lNeightbor; lMouseDirection[ActiveMice] = i; lMouseByDirection[i] = ActiveMice; if (ActiveMice > 0) lMouseNextDirection[ActiveMice - 1] = i; ActiveMice++; } else lMouseByDirection[i] = -1; // no mouse } if (ActiveMice == 1) return false; lMouseNextDirection[ActiveMice - 1] = 0; // it's never used! for (int CurrentMouse = 0; CurrentMouse < ActiveMice - 1; CurrentMouse++) { int CurrentMousePosition = lMousePosition[CurrentMouse]; int CurrentMouseDirection = lMouseDirection[CurrentMouse]; int CurrentMouseOriginalDirection = CurrentMouseDirection; while (CurrentMousePosition != move) { int lRightDirection = CoordinateSystem.TurnClockWise(CurrentMouseDirection); int lRightPosition = lCoord.GetNeighbor(CurrentMousePosition, lRightDirection); // if (can turn right & move) if (CoordinateSystem.OnBoard(lRightPosition, lWidth) && inter.Contains(lRightPosition)) { // yes, turn turn and move CurrentMousePosition = lRightPosition; CurrentMouseDirection = lRightDirection; } else { while (true) { int lStraightPosition = lCoord.GetNeighbor(CurrentMousePosition, CurrentMouseDirection); // if (can go straight) ( if (CoordinateSystem.OnBoard(lStraightPosition, lWidth) && inter.Contains(lStraightPosition)) { // yes, go straight CurrentMousePosition = lStraightPosition; break; } else { // else, change direction clockwise and try-again (loop) CurrentMouseDirection = CoordinateSystem.TurnCounterClockWise(CurrentMouseDirection); } } } } // right back where we started int FromDirection = CoordinateSystem.TurnAround(CurrentMouseDirection); // if mice returned from a direction other than the next direction, then there is a split if (lMouseNextDirection[CurrentMouse] != FromDirection) return true; // if mouse came back from original direction then there is a split if (CurrentMouseOriginalDirection == FromDirection) return true; // should never reach here // by now we know that the next mouse must merge, so no split if (CurrentMouse == ActiveMice - 1) return false; } return false; }
/// <summary> /// News up an entity with its backing data and where to spawn it into /// </summary> /// <param name="backingStore">the backing data</param> /// <param name="spawnTo">where to spawn this into</param> public Intelligence(INonPlayerCharacter backingStore, IContains spawnTo) { Inventory = new EntityContainer <IInanimate>(); DataTemplate = backingStore; SpawnNewInWorld(spawnTo); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public virtual void SpawnNewInWorld(IContains spawnTo) { UpsertToLiveWorldCache(); }
/// <summary> /// Move this inside of something /// </summary> /// <param name="container">The container to move into</param> /// <returns>was this thing moved?</returns> public virtual bool TryMoveInto(IContains container) { return(false); }
/// <summary> /// Wraps sending messages to the connected descriptor /// </summary> /// <param name="strings">the output</param> /// <returns>success status</returns> public bool SendOutput(IEnumerable <string> strings) { //TODO: Stop hardcoding this but we have literally no sense of injury/self status yet SelfStatus self = new SelfStatus { Body = new BodyStatus { Health = _currentPlayer.CurrentHealth == 0 ? 100 : 100 / (2M * _currentPlayer.CurrentHealth), Stamina = _currentPlayer.CurrentStamina, Overall = OverallStatus.Excellent, Anatomy = new AnatomicalPart[] { new AnatomicalPart { Name = "Arm", Overall = OverallStatus.Good, Wounds = new string[] { "Light scrape" } }, new AnatomicalPart { Name = "Leg", Overall = OverallStatus.Excellent, Wounds = new string[] { } } } }, CurrentActivity = _currentPlayer.CurrentAction, Balance = _currentPlayer.Balance.ToString(), CurrentArt = _currentPlayer.LastAttack?.Name ?? "", CurrentCombo = _currentPlayer.LastCombo?.Name ?? "", CurrentTarget = _currentPlayer.GetTarget() == null ? "" : _currentPlayer.GetTarget() == _currentPlayer ? "Your shadow" : _currentPlayer.GetTarget().GetDescribableName(_currentPlayer), CurrentTargetHealth = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? double.PositiveInfinity : _currentPlayer.GetTarget().CurrentHealth == 0 ? 100 : 100 / (2 * _currentPlayer.CurrentHealth), Position = _currentPlayer.StancePosition.ToString(), Stance = _currentPlayer.Stance, Stagger = _currentPlayer.Stagger.ToString(), Qualities = string.Join("", _currentPlayer.Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))), CurrentTargetQualities = _currentPlayer.GetTarget() == null || _currentPlayer.GetTarget() == _currentPlayer ? "" : string.Join("", _currentPlayer.GetTarget().Qualities.Where(quality => quality.Visible).Select(quality => string.Format("<div class='qualityRow'><span>{0}</span><span>{1}</span></div>", quality.Name, quality.Value))), Mind = new MindStatus { Overall = OverallStatus.Excellent, States = new string[] { "Fearful" } } }; IGlobalPosition currentLocation = _currentPlayer.CurrentLocation; IContains currentContainer = currentLocation.CurrentLocation(); IZone currentZone = currentContainer.CurrentLocation.CurrentZone; ILocale currentLocale = currentLocation.CurrentLocale; IRoom currentRoom = currentLocation.CurrentRoom; IGaia currentWorld = currentZone.GetWorld(); IEnumerable <string> pathways = Enumerable.Empty <string>(); IEnumerable <string> inventory = Enumerable.Empty <string>(); IEnumerable <string> populace = Enumerable.Empty <string>(); string locationDescription = string.Empty; LexicalContext lexicalContext = new LexicalContext(_currentPlayer) { Language = _currentPlayer.Template <IPlayerTemplate>().Account.Config.UILanguage, Perspective = NarrativePerspective.SecondPerson, Position = LexicalPosition.Near }; Message toCluster = new Message(currentContainer.RenderToVisible(_currentPlayer)); if (currentContainer != null) { pathways = ((ILocation)currentContainer).GetPathways().Select(data => data.GetDescribableName(_currentPlayer)); inventory = currentContainer.GetContents <IInanimate>().Select(data => data.GetDescribableName(_currentPlayer)); populace = currentContainer.GetContents <IMobile>().Where(player => !player.Equals(_currentPlayer)).Select(data => data.GetDescribableName(_currentPlayer)); locationDescription = toCluster.Unpack(TargetEntity.Actor, lexicalContext); } LocalStatus local = new LocalStatus { ZoneName = currentZone?.TemplateName, LocaleName = currentLocale?.TemplateName, RoomName = currentRoom?.TemplateName, Inventory = inventory.ToArray(), Populace = populace.ToArray(), Exits = pathways.ToArray(), LocationDescriptive = locationDescription }; //The next two are mostly hard coded, TODO, also fix how we get the map as that's an admin thing ExtendedStatus extended = new ExtendedStatus { Horizon = new string[] { "A hillside", "A dense forest" }, VisibleMap = currentLocation.CurrentRoom == null ? string.Empty : currentLocation.CurrentRoom.RenderCenteredMap(3, true) }; string timeOfDayString = string.Format("The hour of {0} in the day of {1} in {2} in the year of {3}", currentWorld.CurrentTimeOfDay.Hour , currentWorld.CurrentTimeOfDay.Day , currentWorld.CurrentTimeOfDay.MonthName() , currentWorld.CurrentTimeOfDay.Year); string sun = "0"; string moon = "0"; string visibilityString = "5"; Tuple <string, string, string[]> weatherTuple = new Tuple <string, string, string[]>("", "", new string[] { }); if (currentZone != null) { Tuple <PrecipitationAmount, PrecipitationType, HashSet <WeatherType> > forecast = currentZone.CurrentForecast(); weatherTuple = new Tuple <string, string, string[]>(forecast.Item1.ToString(), forecast.Item2.ToString(), forecast.Item3.Select(wt => wt.ToString()).ToArray()); visibilityString = currentZone.GetCurrentLuminosity().ToString(); if (currentWorld != null) { IEnumerable <ICelestial> bodies = currentZone.GetVisibileCelestials(_currentPlayer); ICelestial theSun = bodies.FirstOrDefault(cest => cest.Name.Equals("sun", StringComparison.InvariantCultureIgnoreCase)); ICelestial theMoon = bodies.FirstOrDefault(cest => cest.Name.Equals("moon", StringComparison.InvariantCultureIgnoreCase)); if (theSun != null) { ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theSun); sun = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString(); } if (theMoon != null) { ICelestialPosition celestialPosition = currentWorld.CelestialPositions.FirstOrDefault(celest => celest.CelestialObject == theMoon); moon = AstronomicalUtilities.GetCelestialLuminosityModifier(celestialPosition.CelestialObject, celestialPosition.Position, currentWorld.PlanetaryRotation , currentWorld.OrbitalPosition, currentZone.Template <IZoneTemplate>().Hemisphere, currentWorld.Template <IGaiaTemplate>().RotationalAngle).ToString(); } } } EnvironmentStatus environment = new EnvironmentStatus { Sun = sun, Moon = moon, Visibility = visibilityString, Weather = weatherTuple, Temperature = currentZone.EffectiveTemperature().ToString(), Humidity = currentZone.EffectiveHumidity().ToString(), TimeOfDay = timeOfDayString }; OutputStatus outputFormat = new OutputStatus { Occurrence = EncapsulateOutput(strings), Self = self, Local = local, Extended = extended, Environment = environment }; Send(Utility.SerializationUtility.Serialize(outputFormat)); return(true); }
public void Exclude(IContains exclude) => exclusions.Add(exclude);
/// <summary> /// Move this inside of something /// </summary> /// <param name="container">The container to move into</param> /// <returns>was this thing moved?</returns> public override bool TryMoveInto(IContains container) { return(container.MoveInto(this)); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { spawnTo.MoveInto(this); UpsertToLiveWorldCache(); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public override void SpawnNewInWorld(IContains spawnTo) { //We can't even try this until we know if the data is there if (DataTemplate<IInanimateData>() == null) throw new InvalidOperationException("Missing backing data store on object spawn event."); var bS = DataTemplate<IInanimateData>(); BirthMark = LiveCache.GetUniqueIdentifier(bS); Keywords = new string[] { bS.Name.ToLower() }; Birthdate = DateTime.Now; if (spawnTo == null) { throw new NotImplementedException("Objects can't spawn to nothing"); } InsideOf = spawnTo; spawnTo.MoveInto<IInanimate>(this); Contents = new EntityContainer<IInanimate>(); LiveCache.Add(this); }
/// <summary> /// Spawn this new into the live world into a specified container /// </summary> /// <param name="spawnTo">the location/container this should spawn into</param> public abstract void SpawnNewInWorld(IContains spawnTo);
public void Include(IContains include) => inclusions.Add(include);