Ejemplo n.º 1
0
        /// <summary>
        /// Get the current luminosity rating of the place you're in
        /// </summary>
        /// <returns>The current Luminosity</returns>
        public override float GetCurrentLuminosity()
        {
            float lumins = 0;

            IZone zone = CurrentLocation.CurrentZone;

            if (zone != null)
            {
                zone.GetCurrentLuminosity();
            }

            foreach (IMobile dude in MobilesInside.EntitiesContained())
            {
                lumins += dude.GetCurrentLuminosity();
            }

            foreach (IInanimate thing in Contents.EntitiesContained())
            {
                lumins += thing.GetCurrentLuminosity();
            }

            return(lumins);
        }
Ejemplo n.º 2
0
        /// <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);
        }