Ejemplo n.º 1
0
 public virtual Vector2Int[] GetVisibleWalls(IEntity viewer, IWorldInstance world)
 {
     Vector2Int[] visibleWalls = viewer.MyWorld.Walls.Where(
         wall => viewer.VisionProvider.CanSee(viewer, world, wall))
                                 .ToArray();
     return(visibleWalls);
 }
Ejemplo n.º 2
0
        public IQuest MakeRandomQuest(IEntity questor, IEntity provider, IWorldInstance overworldRef)
        {
            GlobalConstants.GameManager.ItemHandler.CleanUpRewards();

            List <IQuestAction> actions = new List <IQuestAction>();

            //int numberOfSteps = RNG.instance.Roll(1, 4);
            int numberOfSteps = 1;

            for (int i = 0; i < numberOfSteps; i++)
            {
                int          result = this.Roller.Roll(0, this.Actions.Count);
                IQuestAction action = this.Actions[result].Create(questor, provider, overworldRef, new string[0]);
                actions.Add(action);
            }

            IEnumerable <string> tagsForAllSteps = actions.SelectMany(step => step.Tags);
            var   rewards = this.GetRewards(questor, provider, actions);
            Quest quest   = new Quest(
                actions,
                QuestMorality.Neutral,
                rewards,
                provider.Guid,
                questor.Guid,
                tagsForAllSteps);

            return(quest);
        }
Ejemplo n.º 3
0
        public override bool ExecutedSuccessfully(IJoyAction action)
        {
            if (action.Name.Equals("enterworldaction", StringComparison.OrdinalIgnoreCase) == false)
            {
                return(false);
            }

            foreach (object obj in action.LastArgs)
            {
                if (obj is IWorldInstance world)
                {
                    if (this.Areas.Contains(world.Guid) == false)
                    {
                        return(false);
                    }
                }
            }

            IWorldInstance        overworld = GlobalConstants.GameManager.Player.MyWorld.GetOverworld();
            List <IWorldInstance> worlds    = overworld.GetWorlds(overworld)
                                              .Where(instance => this.Areas.Contains(instance.Guid))
                                              .ToList();

            return(worlds.All(world => action.LastParticipants.First().HasDataKey(world.Name)) && action.Successful);
        }
Ejemplo n.º 4
0
        public IEntity CreateFromTemplate(IEntityTemplate template,
                                          Vector2Int position,
                                          string name = null,
                                          IDictionary <string, IEntityStatistic> statistics = null,
                                          IDictionary <string, IDerivedValue> derivedValues = null,
                                          IDictionary <string, IEntitySkill> skills         = null,
                                          IEnumerable <IAbility> abilities = null,
                                          IEnumerable <ICulture> cultures  = null,
                                          IGender gender       = null,
                                          IBioSex sex          = null,
                                          ISexuality sexuality = null,
                                          IRomance romance     = null,
                                          IJob job             = null,
                                          IEnumerable <ISpriteState> sprites = null,
                                          IWorldInstance world = null,
                                          IDriver driver       = null)
        {
            string     selectedName      = name;
            IJob       selectedJob       = job;
            IGender    selectedGender    = gender;
            IBioSex    selectedSex       = sex;
            ISexuality selectedSexuality = sexuality;
            IRomance   selectedRomance   = romance;
            IEnumerable <ISpriteState> selectedSprites  = sprites;
            List <ICulture>            creatureCultures = new List <ICulture>();
            IDriver selectedDriver = driver;
            IDictionary <string, IEntityStatistic> selectedStatistics = statistics;
            IDictionary <string, IDerivedValue>    selectedDVs        = derivedValues;
            IDictionary <string, IEntitySkill>     selectedSkills     = skills;
            IEnumerable <IAbility> selectedAbilities = abilities;

            if (!(cultures is null))
            {
                creatureCultures.AddRange(cultures);
            }
Ejemplo n.º 5
0
        public override IQuestAction Create(
            IEntity questor,
            IEntity provider,
            IWorldInstance overworld,
            IEnumerable <string> tags)
        {
            List <IWorldInstance> worlds = overworld.GetWorlds(overworld);

            List <string> myTags = new List <string>(tags);

            worlds = worlds.Where(instance => questor.HasDataKey(instance.Name) == false).ToList();
            if (worlds.Any() == false)
            {
                GlobalConstants.ActionLog.Log(questor + " has explored the whole world!", LogLevel.Warning);
                worlds = overworld.GetWorlds(overworld);
            }

            int result = this.Roller.Roll(0, worlds.Count);

            return(new ExploreQuestAction(
                       new List <Guid>(),
                       new List <Guid>(),
                       new List <Guid> {
                worlds[result].Guid
            },
                       myTags));
        }
        public override string Get(IWorldInstance worldInstance, IEntity origin = null)
        {
            var entityGrouping = worldInstance.Entities
                                 .SelectMany(entity => entity.Cultures)
                                 .Distinct()
                                 .Select(culture => new Tuple <ICulture, int>(
                                             culture,
                                             worldInstance.Entities.Count(entity => entity.Cultures.Contains(culture))));

            List <string> stringData = new List <string>();

            foreach (var group in entityGrouping)
            {
                int count = group.Item2;
                if (count > 10)
                {
                    int remainder = count % 10;
                    count -= remainder;
                }

                bool plural = count > 1;

                string temp = "There " +
                              (plural ? "are " : "is ") +
                              (plural ? "roughly " : "") +
                              count +
                              (plural ? " people " : " person ") +
                              "who " +
                              (plural ? "belong" : "belongs") +
                              " to the " + group.Item1.CultureName.ToTitleCase() + " here.";
                stringData.Add(temp);
            }

            return(string.Join(" ", stringData));
        }
Ejemplo n.º 7
0
        public override IQuestAction Create(
            IEntity questor,
            IEntity provider,
            IWorldInstance overworld,
            IEnumerable <string> tags)
        {
            this.ItemFactory ??= GlobalConstants.GameManager.ItemFactory;

            IItemInstance        deliveryItem = null;
            List <IItemInstance> backpack     = provider.Contents.ToList();

            if (backpack.Count > 0)
            {
                int result = this.Roller.Roll(0, backpack.Count);

                deliveryItem = backpack[result];
            }
            IEntity endPoint = overworld.GetRandomSentientWorldWide();

            deliveryItem ??= this.ItemFactory.CreateRandomWeightedItem();
            deliveryItem.SetOwner(endPoint.Guid);

            List <string> myTags = new List <string>(tags);

            return(new DeliverQuestAction(
                       new List <Guid> {
                deliveryItem.Guid
            },
                       new List <Guid> {
                endPoint.Guid
            },
                       new List <Guid>(),
                       myTags));
        }
Ejemplo n.º 8
0
        public PhysicsResult IsCollision(Vector2Int @from, Vector2Int to, IWorldInstance worldRef)
        {
            IEntity tempEntity = worldRef.GetEntity(to);

            if (tempEntity != null && from != to)
            {
                if (tempEntity.WorldPosition != from)
                {
                    return(PhysicsResult.EntityCollision);
                }
            }

            if (worldRef.Walls.Contains(to))
            {
                return(PhysicsResult.WallCollision);
            }

            IJoyObject obj = worldRef.GetObject(to);

            if (obj != null)
            {
                return(PhysicsResult.ObjectCollision);
            }
            else
            {
                return(PhysicsResult.None);
            }
        }
Ejemplo n.º 9
0
        public Queue <Vector2Int> FindPath(Vector2Int from, Vector2Int to, IWorldInstance worldRef)
        {
            IWorldInstance world = worldRef;

            HashSet <Vector2Int> walls = world.Walls;

            AStar pathfinder = new AStar();

            AStarNode.sizes = new Vector2Int(world.Tiles.GetLength(0), world.Tiles.GetLength(1));
            AStarNode.walls = walls;
            AStarNode goalNode  = new AStarNode2D(null, null, 0, to.x, to.y);
            AStarNode startNode = new AStarNode2D(null, goalNode, 0, from.x, from.y);

            pathfinder.FindPath(startNode, goalNode);

            Queue <Vector2Int> path = new Queue <Vector2Int>();

            for (int i = 0; i < pathfinder.solution.Count; i++)
            {
                AStarNode2D node = (AStarNode2D)pathfinder.solution[i];
                path.Enqueue(new Vector2Int(node.x, node.y));
            }

            return(path);
        }
Ejemplo n.º 10
0
        public string GetSpecificLocalAreaInfo(IWorldInstance world, IEnumerable <string> tags)
        {
            ILocalAreaProcessor processor = this.Processors.Where(
                p => p.HasTags(tags))
                                            .ToArray()
                                            .GetRandom();

            return(processor.Get(world));
        }
Ejemplo n.º 11
0
        public void ContinueGame()
        {
            IWorldInstance overworld = this.m_WorldSerialiser.Deserialise("Everse");

            this.Done = true;

            IWorldInstance playerWorld = GlobalConstants.GameManager.EntityHandler.GetPlayer().MyWorld;

            this.m_NextState = new WorldInitialisationState(overworld, playerWorld);
        }
Ejemplo n.º 12
0
        public IFOVBoard Do(IEntity viewer, IWorldInstance world, Vector2Int dimensions, IEnumerable <Vector2Int> walls)
        {
            this.Viewer    = viewer;
            this.VisionMod = viewer.VisionMod;
            this.Board     = new FOVArrayBoard(dimensions.x, dimensions.y, walls);
            this.Board.Visible(this.Viewer.WorldPosition.x, this.Viewer.WorldPosition.y);

            this.DoAdjacent(viewer.WorldPosition, 0);

            return(this.Board);
        }
Ejemplo n.º 13
0
        protected void SetEntityWorld(IWorldInstance world)
        {
            foreach (IEntity entity in world.Entities)
            {
                entity.MyWorld = world;
            }

            foreach (IWorldInstance nextWorld in world.Areas.Values)
            {
                this.SetEntityWorld(nextWorld);
            }
        }
Ejemplo n.º 14
0
        public virtual void Update(IEntity viewer, IWorldInstance world)
        {
            this.Vision = new HashSet <Vector2Int>();

            this.Board = this.Algorithm.Do(
                viewer,
                world,
                world.Dimensions,
                world.Walls);

            this.Vision = this.Board.GetVision();
        }
Ejemplo n.º 15
0
        public static int GetNumberOfFloors(int floorsSoFar, IWorldInstance worldToCheck)
        {
            if (worldToCheck.Areas.Count > 0)
            {
                foreach (IWorldInstance world in worldToCheck.Areas.Values)
                {
                    return(GetNumberOfFloors(floorsSoFar + 1, world));
                }
            }

            return(floorsSoFar);
        }
Ejemplo n.º 16
0
        public void LoadGame()
        {
            WorldSerialiser worldSerialiser = new WorldSerialiser(GlobalConstants.GameManager.ObjectIconHandler);
            IWorldInstance  overworld       = worldSerialiser.Deserialise("Everse");
            ICulture        playerCulture   = GlobalConstants.GameManager.EntityHandler.GetPlayer().Cultures.First();

            GlobalConstants.GameManager.GUIManager.CloseAllGUIs();
            GlobalConstants.GameManager.GUIManager.SetUIColours(
                playerCulture.BackgroundColours,
                playerCulture.CursorColours,
                playerCulture.FontColours);
            GlobalConstants.GameManager.SetNextState(new WorldInitialisationState(overworld, overworld.GetPlayerWorld(overworld)));
        }
Ejemplo n.º 17
0
        public LightBoard Do(IEnumerable <IItemInstance> items, IWorldInstance world, Vector2Int dimensions,
                             IEnumerable <Vector2Int> walls)
        {
            this.m_Board = new LightBoard(dimensions.x, dimensions.y, walls);
            foreach (IItemInstance item in items)
            {
                this.m_Board.ClearVisited();
                this.Light.DiffuseLight(item.WorldPosition, item.ItemType.LightLevel);
                this.DoAdjacent(item.WorldPosition);
            }

            return(this.m_Board);
        }
Ejemplo n.º 18
0
        public Vector2Int PlaceTransitionPoint(IWorldInstance worldRef)
        {
            int breakout = (worldRef.Tiles.GetLength(0) * worldRef.Tiles.GetLength(1)) / 4;
            int x, y;

            x = this.Roller.Roll(1, worldRef.Tiles.GetLength(0));
            y = this.Roller.Roll(1, worldRef.Tiles.GetLength(1));

            Vector2Int point = new Vector2Int(x, y);

            int count = 0;

            while (worldRef.Walls.Contains(point) &&
                   (point.Equals(worldRef.SpawnPoint) || count < breakout))
            {
                x      = this.Roller.Roll(1, worldRef.Tiles.GetLength(0));
                y      = this.Roller.Roll(1, worldRef.Tiles.GetLength(1));
                point  = new Vector2Int(x, y);
                count += 1;
            }

            Pathfinder         pathfinder = new Pathfinder();
            Queue <Vector2Int> points     = pathfinder.FindPath(point, worldRef.SpawnPoint, worldRef);

            if (points.Count > 0)
            {
                return(point);
            }
            else
            {
                count = 0;
                while (worldRef.Walls.Contains(point) &&
                       (point.Equals(worldRef.SpawnPoint) || count < breakout) &&
                       pathfinder.FindPath(point, worldRef.SpawnPoint, worldRef).Count == 0)
                {
                    x      = this.Roller.Roll(1, worldRef.Tiles.GetLength(0));
                    y      = this.Roller.Roll(1, worldRef.Tiles.GetLength(1));
                    point  = new Vector2Int(x, y);
                    count += 1;
                }

                if (count < breakout)
                {
                    return(point);
                }
            }

            return(new Vector2Int(-1, -1));
        }
Ejemplo n.º 19
0
        public IFOVBoard Do(IEntity viewer, IWorldInstance world, Vector2Int dimensions,
                            IEnumerable <Vector2Int> walls)
        {
            Vector2Int viewerPos = viewer.WorldPosition;

            this.m_Board = new FOVArrayBoard(dimensions.x, dimensions.y, walls);
            this.m_Board.Visible(viewerPos.x, viewerPos.y);
            foreach (Vector2Int direction in DIAGONALS)
            {
                this.CastLight(viewer, world, viewerPos, viewer.VisionMod, 1, 1, 0, 0, direction.x, direction.y, 0);
                this.CastLight(viewer, world, viewerPos, viewer.VisionMod, 1, 1, 0, direction.x, 0, 0, direction.y);
            }

            return(this.m_Board);
        }
Ejemplo n.º 20
0
        public bool Add(IWorldInstance value)
        {
            if (this.Worlds.ContainsKey(value.Guid))
            {
                return(false);
            }

            this.Worlds.Add(value.Guid, value);
            foreach (IWorldInstance child in value.Areas.Values)
            {
                this.Add(child);
            }

            return(true);
        }
Ejemplo n.º 21
0
        public void SetUp()
        {
            ActionLog actionLog = new ActionLog();

            GlobalConstants.ActionLog = actionLog;
            this.scriptingEngine      = new ScriptingEngine();

            this.target = new ConcreteRumourMill();

            IWorldInstance world = Mock.Of <IWorldInstance>();

            IGameManager gameManager = Mock.Of <IGameManager>(
                manager => manager.NeedHandler == Mock.Of <INeedHandler>(
                    handler => handler.GetManyRandomised(It.IsAny <IEnumerable <string> >())
                    == new List <INeed>()) &&
                manager.SkillHandler == Mock.Of <IEntitySkillHandler>(
                    handler => handler.GetDefaultSkillBlock()
                    == new Dictionary <string, IEntitySkill>
            {
                {
                    "light blades",
                    new EntitySkill(
                        "light blades",
                        5,
                        7)
                }
            }) &&
                manager.RelationshipHandler == Mock.Of <IEntityRelationshipHandler>() &&
                manager.ObjectIconHandler == Mock.Of <IObjectIconHandler>());

            GlobalConstants.GameManager = gameManager;

            IGender gender = Mock.Of <IGender>(
                g => g.PersonalSubject == "her");

            IDictionary <string, IEntitySkill> skills = gameManager.SkillHandler.GetDefaultSkillBlock();

            this.left = Mock.Of <IEntity>(
                entity => entity.PlayerControlled == true &&
                entity.JoyName == "TEST1" &&
                entity.Skills == skills);

            this.right = Mock.Of <IEntity>(
                entity => entity.JoyName == "TEST2" &&
                entity.Skills == skills);
        }
Ejemplo n.º 22
0
        public WorldState(IWorldInstance overworldRef, IWorldInstance activeWorldRef) : base()
        {
            this.m_ActiveWorld = activeWorldRef;
            this.m_Overworld   = overworldRef;

            this.GameManager         = GlobalConstants.GameManager;
            this.PhysicsManager      = this.GameManager.PhysicsManager;
            this.RelationshipHandler = this.GameManager.RelationshipHandler;
            this.ConversationEngine  = this.GameManager.ConversationEngine;
            this.GUIManager          = this.GameManager.GUIManager;

            this.m_Camera = new Camera2D
            {
                AnchorMode  = Camera2D.AnchorModeEnum.DragCenter,
                ProcessMode = Camera2D.Camera2DProcessMode.Physics,
                Current     = true,
                ZIndex      = 100,
                ZAsRelative = false
            };

            this.FogHolder = this.GameManager.FogHolder;

            GlobalConstants.GameManager?.Player.MyNode?.AddChild(this.m_Camera);

            GlobalConstants.GameManager.Player.AliveChange         -= this.OnPlayerDeath;
            GlobalConstants.GameManager.Player.AliveChange         += this.OnPlayerDeath;
            GlobalConstants.GameManager.Player.ConsciousnessChange -= this.OnPlayerConsciousChange;
            GlobalConstants.GameManager.Player.ConsciousnessChange += this.OnPlayerConsciousChange;

            var player = GlobalConstants.GameManager.Player;

            for (int i = 0; i < this.FogHolder.GetChildCount(); i++)
            {
                PositionableSprite fog            = this.FogHolder.GetChild(i) as PositionableSprite;
                ShaderMaterial     shaderMaterial = fog?.Material as ShaderMaterial;
                shaderMaterial?.SetShaderParam("darkColour", player.VisionProvider.DarkColour);
                shaderMaterial?.SetShaderParam("lightColour", player.VisionProvider.LightColour);
                shaderMaterial?.SetShaderParam("minimumLight", player.VisionProvider.MinimumLightLevel);
                shaderMaterial?.SetShaderParam("minimumComfort", player.VisionProvider.MinimumComfortLevel);
                shaderMaterial?.SetShaderParam("maximumComfort", player.VisionProvider.MaximumComfortLevel);
                shaderMaterial?.SetShaderParam("maximumLight", player.VisionProvider.MaximumLightLevel);
            }

            this.Tick();
        }
Ejemplo n.º 23
0
        public Vector2Int PlaceSpawnPoint(IWorldInstance worldRef)
        {
            int x, y;

            x = this.Roller.Roll(1, worldRef.Tiles.GetLength(0));
            y = this.Roller.Roll(1, worldRef.Tiles.GetLength(1));

            Vector2Int point = new Vector2Int(x, y);

            while (worldRef.Walls.Any(l => l.Equals(point)))
            {
                x     = this.Roller.Roll(1, worldRef.Tiles.GetLength(0));
                y     = this.Roller.Roll(1, worldRef.Tiles.GetLength(1));
                point = new Vector2Int(x, y);
            }

            return(point);
        }
Ejemplo n.º 24
0
        public override string Get(IWorldInstance worldInstance, IEntity origin = null)
        {
            var entities = worldInstance.Entities;

            int count = entities.Count;

            if (count > 10)
            {
                int remainder = count % 5;
                count -= remainder;
            }

            bool plural = count > 1;

            return("There" +
                   (plural ? " are " : " is ") +
                   (plural ? "around " : "") +
                   count +
                   (plural ? " people " : " person ") +
                   "here.");
        }
Ejemplo n.º 25
0
        protected void ChangeWorld(IWorldInstance newWorld, Vector2Int spawnPoint)
        {
            this.Done = true;

            IEntity player = GlobalConstants.GameManager.Player;

            newWorld.Initialise();
            player.FetchAction("enterworldaction")
            .Execute(
                new IJoyObject[] { player },
                new[] { "exploration", "world change" },
                new Dictionary <string, object>
            {
                { "world", newWorld }
            });
            this.m_ActiveWorld = newWorld;

            player.Move(spawnPoint);
            player.Tick();

            this.Tick();
        }
Ejemplo n.º 26
0
        public void Serialise(IWorldInstance world)
        {
            string directory = Directory.GetCurrentDirectory() + "/save/" + world.Name;

            try
            {
                if (!Directory.Exists(directory))
                {
                    Directory.CreateDirectory(directory);
                }
            }
            catch (Exception e)
            {
                GlobalConstants.ActionLog.Log("Cannot open save directory.", LogLevel.Error);
                GlobalConstants.ActionLog.StackTrace(e);
            }
            try
            {
                string json = JSON.Print(world.Save(), "\t");
                File.WriteAllText(directory + "/world.dat", json);

                json = JSON.Print(GlobalConstants.GameManager.QuestTracker.Save(), "\t");
                File.WriteAllText(directory + "/quests.dat", json);

                json = JSON.Print(GlobalConstants.GameManager.ItemHandler.Save(), "\t");
                File.WriteAllText(directory + "/items.dat", json);

                json = JSON.Print(GlobalConstants.GameManager.EntityHandler.Save(), "\t");
                File.WriteAllText(directory + "/entities.dat", json);

                json = JSON.Print(GlobalConstants.GameManager.RelationshipHandler.Save(), "\t");
                File.WriteAllText(directory + "/relationships.dat", json);
            }
            catch (Exception e)
            {
                GlobalConstants.ActionLog.Log("Cannot serialise and/or write world to file.", LogLevel.Error);
                GlobalConstants.ActionLog.StackTrace(e);
            }
        }
Ejemplo n.º 27
0
        public override string AssembleDescription()
        {
            StringBuilder builder = new StringBuilder();

            IWorldInstance        overworld = GlobalConstants.GameManager.Player.MyWorld.GetOverworld();
            List <IWorldInstance> worlds    = overworld.GetWorlds(overworld)
                                              .Where(instance => this.Areas.Contains(instance.Guid))
                                              .ToList();

            for (int i = 0; i < this.Areas.Count; i++)
            {
                if (i > 0 && i < this.Items.Count - 1)
                {
                    builder.Append(", ");
                }
                if (this.Items.Count > 1 && i == this.Items.Count - 1)
                {
                    builder.Append("and ");
                }
                builder.Append(worlds[i].Name);
            }

            return("Go to " + builder + ".");
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Places items in the dungeon
        /// </summary>
        /// <param name="worldRef">The world in which to place the items</param>
        /// <param name="prosperity">The prosperity of the world, the lower the better</param>
        /// <returns>The items placed</returns>
        public List <IItemInstance> PlaceItems(IWorldInstance worldRef, int prosperity = 50)
        {
            List <IItemInstance> placedItems = new List <IItemInstance>();

            int dungeonArea  = worldRef.Tiles.GetLength(0) * worldRef.Tiles.GetLength(1);
            int itemsToPlace = dungeonArea / prosperity;

            List <Vector2Int> availablePoints = new List <Vector2Int>();

            for (int i = 0; i < worldRef.Tiles.GetLength(0); i++)
            {
                for (int j = 0; j < worldRef.Tiles.GetLength(1); j++)
                {
                    Vector2Int position = new Vector2Int(i, j);
                    if (worldRef.Walls.Contains(position) == false &&
                        position != worldRef.SpawnPoint &&
                        worldRef.Areas.ContainsKey(position) == false)
                    {
                        availablePoints.Add(position);
                    }
                }
            }


            for (int i = 0; i < itemsToPlace; i++)
            {
                Vector2Int point = availablePoints[this.Roller.Roll(0, availablePoints.Count)];

                IItemInstance item = this.ItemFactory.CreateRandomWeightedItem();
                worldRef.AddItem(item);
                item.Move(point);
                placedItems.Add(item);
            }

            return(placedItems);
        }
Ejemplo n.º 29
0
        public virtual bool HasVisibility(IEntity viewer, IWorldInstance world, Vector2Int point)
        {
            int lightLevel = world.LightCalculator?.Light?.GetLight(point) ?? 0;

            return(this.CanSee(viewer, world, point) && lightLevel >= this.MinimumLightLevel && lightLevel <= this.MaximumLightLevel);
        }
Ejemplo n.º 30
0
 public virtual bool HasVisibility(IEntity viewer, IWorldInstance world, int x, int y)
 {
     return(this.HasVisibility(viewer, world, new Vector2Int(x, y)));
 }