/// <summary> /// Spawn this into the world and live cache /// </summary> public override void SpawnNewInWorld(IGlobalPosition spawnTo) { //We can't even try this until we know if the data is there ILocaleTemplate bS = Template <ILocaleTemplate>() ?? throw new InvalidOperationException("Missing backing data store on locale spawn event."); Keywords = new string[] { bS.Name.ToLower() }; AlwaysDiscovered = bS.AlwaysDiscovered; Descriptives = bS.Descriptives; if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } UpsertToLiveWorldCache(true); ParentLocation = LiveCache.Get <IZone>(bS.ParentLocation.Id); if (spawnTo?.CurrentZone == null) { spawnTo = new GlobalPosition(ParentLocation, this); } CurrentLocation = spawnTo; UpsertToLiveWorldCache(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(IGlobalPosition spawnTo) { //We can't even try this until we know if the data is there IInanimateTemplate bS = Template <IInanimateTemplate>() ?? throw new InvalidOperationException("Missing backing data store on object spawn event."); Keywords = bS.Keywords; if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } Qualities = bS.Qualities; AccumulationCap = bS.AccumulationCap; TryMoveTo(spawnTo); if (CurrentLocation == null) { throw new NotImplementedException("Objects can't spawn to nothing"); } UpsertToLiveWorldCache(true); KickoffProcesses(); }
/// <summary> /// Spawn this into the world and live cache /// </summary> /// <param name="spawnTo">Where this will go</param> public override void SpawnNewInWorld(IGlobalPosition spawnTo) { //We can't even try this until we know if the data is there IZoneTemplate bS = Template <IZoneTemplate>() ?? throw new InvalidOperationException("Missing backing data store on zone spawn event."); Keywords = bS.Keywords; if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } Qualities = bS.Qualities; Descriptives = bS.Descriptives; WeatherEvents = Enumerable.Empty <IWeatherEvent>(); FloraNaturalResources = new HashSet <INaturalResourceSpawn <IFlora> >(); FaunaNaturalResources = new HashSet <INaturalResourceSpawn <IFauna> >(); MineralNaturalResources = new HashSet <INaturalResourceSpawn <IMineral> >(); PopulateMap(); UpsertToLiveWorldCache(true); KickoffProcesses(); CurrentLocation = new GlobalPosition(this, null, null); UpsertToLiveWorldCache(true); Save(); }
public override string TryMoveTo(IGlobalPosition newPosition) { string error = string.Empty; if (CurrentLocation?.CurrentLocation() != null) { error = CurrentLocation.CurrentLocation().MoveFrom(this); } //validate position if (newPosition != null && string.IsNullOrEmpty(error)) { if (newPosition.CurrentLocation() != null) { error = newPosition.CurrentLocation().MoveInto(this); } if (string.IsNullOrEmpty(error)) { CurrentLocation = newPosition; UpsertToLiveWorldCache(); error = string.Empty; } } else { error = "Cannot move to an invalid location"; } return(error); }
/// <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(IInanimateTemplate backingStore, IGlobalPosition spawnTo) { Contents = new EntityContainer <IInanimate>(); Qualities = new HashSet <IQuality>(); TemplateId = backingStore.Id; 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(IGlobalPosition position) { //We can't even try this until we know if the data is there IPathwayTemplate bS = Template <IPathwayTemplate>() ?? throw new InvalidOperationException("Missing backing data store on pathway spawn event."); Keywords = new string[] { bS.Name.ToLower(), DirectionType.ToString().ToLower() }; if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } DegreesFromNorth = bS.DegreesFromNorth; InclineGrade = bS.InclineGrade; DirectionType = Utilities.TranslateToDirection(DegreesFromNorth, InclineGrade); Descriptives = bS.Descriptives; //paths need two locations if (bS.Origin.GetType() == typeof(RoomTemplate)) { Origin = ((IRoomTemplate)bS.Origin).GetLiveInstance(); } else { Origin = ((IZoneTemplate)bS.Origin).GetLiveInstance(); } if (bS.Destination.GetType() == typeof(RoomTemplate)) { Destination = ((IRoomTemplate)bS.Destination).GetLiveInstance(); } else { Destination = ((IZoneTemplate)bS.Destination).GetLiveInstance(); } CurrentLocation = (IGlobalPosition)Origin.CurrentLocation.Clone(); Model = bS.Model; //Enter = new Message(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 })); UpsertToLiveWorldCache(true); Save(); }
/// <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 NonPlayerCharacter(INonPlayerCharacterTemplate backingStore, IGlobalPosition spawnTo) { Inventory = new EntityContainer <IInanimate>(); Qualities = new HashSet <IQuality>(); WillPurchase = new HashSet <IMerchandise>(); WillSell = new HashSet <IMerchandise>(); InventoryRestock = new HashSet <MerchandiseStock>(); TemplateId = backingStore.Id; TeachableProficencies = new HashSet <IQuality>(); Hypothalamus = new Brain(); Race = new Race(); 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(IGlobalPosition spawnTo) { //We can't even try this until we know if the data is there IRoomTemplate bS = Template <IRoomTemplate>() ?? throw new InvalidOperationException("Missing backing data store on room spawn event."); Keywords = new string[] { bS.Name.ToLower() }; Model = bS.Model; Descriptives = bS.Descriptives; Qualities = bS.Qualities; if (FloraNaturalResources == null) { FloraNaturalResources = new HashSet <INaturalResourceSpawn <IFlora> >(); } if (FaunaNaturalResources == null) { FaunaNaturalResources = new HashSet <INaturalResourceSpawn <IFauna> >(); } if (MineralNaturalResources == null) { MineralNaturalResources = new HashSet <INaturalResourceSpawn <IMineral> >(); } if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } UpsertToLiveWorldCache(true); ParentLocation = LiveCache.Get <ILocale>(bS.ParentLocation.Id); spawnTo.CurrentLocale = ParentLocation; spawnTo.CurrentZone = ParentLocation.ParentLocation; if (spawnTo?.CurrentLocale == null || spawnTo?.CurrentZone == null) { spawnTo = new GlobalPosition(this); } CurrentLocation = spawnTo; UpsertToLiveWorldCache(true); Save(); }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { IInanimateTemplate newObject = (IInanimateTemplate)Subject; IMobile initator = (IMobile)Actor; List <string> sb = new List <string>(); IInanimate entityObject; //No target = spawn to inventory if (Target != null) { IGlobalPosition spawnTo = (IGlobalPosition)Target; entityObject = Activator.CreateInstance(newObject.EntityClass, new object[] { newObject }) as IInanimate; sb.Add(string.Format("{0} spawned to {1}.", entityObject.TemplateName, spawnTo.CurrentZone.Keywords[0])); } else { entityObject = Activator.CreateInstance(newObject.EntityClass, new object[] { newObject, initator.GetContainerAsLocation() }) as IInanimate; sb.Add(string.Format("{0} spawned to your inventory.", entityObject.TemplateName)); } //TODO: keywords is janky, location should have its own identifier name somehow for output purposes - DISPLAY short/long NAME ILexicalParagraph toActor = new LexicalParagraph(sb.ToString()); ILexicalParagraph toOrigin = new LexicalParagraph("$S$ appears in the $T$."); ILexicalParagraph toSubject = new LexicalParagraph("You are ALIVE"); ILexicalParagraph toTarget = new LexicalParagraph("You have been given $S$"); Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toOrigin }, ToSubject = new List <ILexicalParagraph> { toSubject }, ToTarget = new List <ILexicalParagraph> { toTarget } }; messagingObject.ExecuteMessaging(Actor, entityObject, OriginLocation.CurrentZone, OriginLocation.CurrentZone, null); return(true); }
public override void SpawnNewInWorld(IGlobalPosition spawnTo) { //We can't even try this until we know if the data is there IGaiaTemplate bS = Template <IGaiaTemplate>() ?? throw new InvalidOperationException("Missing backing data store on gaia spawn event."); Keywords = bS.Keywords; if (CelestialPositions == null || CelestialPositions.Count() == 0) { HashSet <ICelestialPosition> celestials = new HashSet <ICelestialPosition>(); foreach (ICelestial body in bS.CelestialBodies) { celestials.Add(new CelestialPosition(body, 0)); } CelestialPositions = celestials; } RotationalAngle = bS.RotationalAngle; Qualities = bS.Qualities; //gotta spawn 2 per hemisphere if (MeterologicalFronts == null || MeterologicalFronts.Count() == 0) { MeterologicalFronts = AddFronts(); } CurrentTimeOfDay = new TimeOfDay(bS.ChronologicalSystem); if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } Macroeconomy = new Economy(bS); UpsertToLiveWorldCache(true); CurrentLocation = new GlobalPosition(null, null, null); KickoffProcesses(); UpsertToLiveWorldCache(true); Save(); }
/// <summary> /// Executes this command /// </summary> internal override bool ExecutionBody() { IEntity moveToPerson = (IEntity)Subject; if (moveToPerson.CurrentLocation == null) { throw new Exception("Invalid goto target."); } IGlobalPosition moveTo = (IGlobalPosition)moveToPerson.CurrentLocation.Clone(); LexicalParagraph toActor = new LexicalParagraph() { Override = "You teleport." }; LexicalParagraph toOrigin = new LexicalParagraph() { Override = "$A$ disappears in a puff of smoke." }; LexicalParagraph toDest = new LexicalParagraph() { Override = "$A$ appears out of nowhere." }; Message messagingObject = new Message(toActor) { ToOrigin = new List <ILexicalParagraph> { toOrigin }, ToDestination = new List <ILexicalParagraph> { toDest } }; messagingObject.ExecuteMessaging(Actor, null, null, OriginLocation.CurrentZone, null); Actor.TryTeleport(moveTo); 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(IGlobalPosition position) { INonPlayerCharacterTemplate bS = Template <INonPlayerCharacterTemplate>() ?? throw new InvalidOperationException("Missing backing data store on NPC spawn event."); Keywords = bS.Keywords; if (string.IsNullOrWhiteSpace(BirthMark)) { BirthMark = LiveCache.GetUniqueIdentifier(bS); Birthdate = DateTime.Now; } CurrentHealth = bS.TotalHealth; CurrentStamina = bS.TotalStamina; Qualities = bS.Qualities; TotalHealth = bS.TotalHealth; TotalStamina = bS.TotalStamina; Race = bS.Race; Personality = bS.Personality; SurName = bS.SurName; Gender = bS.Gender; WillPurchase = bS.WillPurchase; WillSell = bS.WillSell; InventoryRestock = bS.InventoryRestock; TeachableProficencies = bS.TeachableProficencies; TryMoveTo(position); if (CurrentLocation == null) { throw new NotImplementedException("Objects can't spawn to nothing"); } UpsertToLiveWorldCache(true); KickoffProcesses(); }
public override string TryMoveTo(IGlobalPosition newPosition) { throw new NotImplementedException(); }
/// <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(IGlobalPosition spawnTo);
public abstract string TryMoveTo(IGlobalPosition newPosition);
/// <summary> /// Change the position of this without physical movement /// </summary> /// <param name="newPosition">The new position the thing is in, will return with the original one if nothing moved</param> /// <returns>was this thing moved?</returns> public virtual string TryTeleport(IGlobalPosition newPosition) { return(TryMoveTo(newPosition)); }
public bool TryMoveDirection(MovementDirectionType direction, IGlobalPosition newPosition) { return(true); }
public override bool ShouldSpawnIn(IGlobalPosition location) { bool returnValue = true; return base.ShouldSpawnIn(location) && returnValue; }
/// <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); }
/// <summary> /// Should this resource spawn in this room. Combines the "can" logic with checks against total local population /// </summary> /// <param name="room">The room to spawn in</param> /// <returns>if this should spawn there</returns> public virtual bool ShouldSpawnIn(IGlobalPosition room) { return(true); }
/// <summary> /// Can this resource potentially spawn in this room /// </summary> /// <param name="room">The room to spawn in</param> /// <returns>if this can spawn there</returns> public virtual bool CanSpawnIn(IGlobalPosition position) { return(true); }