private void InitialiseEverything() { RNG.SetSeed(DateTime.Now.Millisecond); ScriptingEngine.Initialise(); ObjectIcons.Load(); NeedHandler.Initialise(); AbilityHandler.Initialise(); JobHandler.Initialise(); CultureHandler.Initialise(); MaterialHandler.Initialise(); ItemHandler.LoadItems(); NameProvider.Initialise(); EntityTemplateHandler.Initialise(); }
private void NextState(object sender, EventArgs eventArgs) { Sex m_Playersex = (Sex)m_sexIndex; Dictionary <NeedIndex, EntityNeed> needs = EntityNeed.GetFullRandomisedNeeds(); EntityTemplate humanTemplate = EntityTemplateHandler.Get("Human"); m_Player = WorldState.EntityHandler.Create(humanTemplate, needs, 1, m_Jobs[m_JobIndex], m_Playersex, Sexuality.Bisexual, new UnityEngine.Vector2Int(-1, -1), ObjectIcons.GetSprites("Jobs", m_Jobs[m_JobIndex].name).ToList(), null); m_Player.PlayerControlled = true; m_Player.AddItem(new ItemInstance(ItemHandler.GetSpecificItem("Lantern"), new UnityEngine.Vector2Int(-1, -1), true)); }
public ItemInstance(BaseItemType type, Vector2Int position, bool identified, string interactionFile = null) : base(type.UnidentifiedName, type.GetHitPoints(), position, ObjectIcons.GetSprites(type.Category, type.UnidentifiedName), type.Category, false) { this.m_Type = type; this.Move(position); this.m_HitPoints = type.GetHitPoints(); this.m_HitPointsRemaining = this.m_HitPoints; this.GUID = GUIDManager.AssignGUID(); this.Identified = identified; //chosenIcon = RNG.Roll(0, m_Icons.Length - 1); this.m_Contents = new List <long>(); m_InteractionFile = interactionFile; }
public List <JoyObject> GenerateWalls(WorldTile[,] worldTiles) { List <JoyObject> walls = new List <JoyObject>(); for (int i = 0; i < m_UntreatedTiles.GetLength(0); i++) { for (int j = 0; j < m_UntreatedTiles.GetLength(1); j++) { if (m_UntreatedTiles[i, j] == GeneratorTileType.Perimeter || m_UntreatedTiles[i, j] == GeneratorTileType.Wall || m_UntreatedTiles[i, j] == GeneratorTileType.None) { walls.Add(new JoyObject("Surround", 1, new Vector2Int(i, j), ObjectIcons.GetSprites("Walls", "Surround"), "Wall", false, true)); } } } return(walls); }
private static void AssignIcons(WorldInstance parent) { foreach (JoyObject obj in parent.Objects) { obj.SetIcons(ObjectIcons.GetIcons(obj.BaseType, obj.JoyName)); } foreach (Entity entity in parent.Entities) { if (entity.PlayerControlled) { entity.SetIcons(ObjectIcons.GetIcons("Jobs", entity.Job.name)); } else { entity.SetIcons(ObjectIcons.GetIcons(entity.Tileset, entity.CreatureType)); } } foreach (WorldInstance world in parent.Areas.Values) { AssignIcons(world); } }
protected void InstantiateWorld() { GameObject worldHolder = GameObject.Find("WorldHolder"); GameObject objectHolder = GameObject.Find("WorldObjects"); GameObject entityHolder = GameObject.Find("WorldEntities"); GameObject fogOfWarHolder = GameObject.Find("WorldFog"); GameObject wallHolder = GameObject.Find("WorldWalls"); MonoBehaviourHandler prefab = Resources.Load <MonoBehaviourHandler>("Prefabs/MonoBehaviourHandler"); GameObject sprite = Resources.Load <GameObject>("Prefabs/Sprite"); //Make the upstairs if (m_ActiveWorld.GUID != m_Overworld.GUID) { GameObject upstairs = GameObject.Instantiate(sprite); upstairs.transform.position = new Vector3(m_ActiveWorld.SpawnPoint.x, m_ActiveWorld.SpawnPoint.y, 0.0f); upstairs.GetComponent <SpriteRenderer>().sortingLayerName = "Walls"; upstairs.GetComponent <SpriteRenderer>().sprite = ObjectIcons.GetSprite("Stairs", "UpStairs0"); upstairs.transform.parent = objectHolder.transform; } //Make each downstairs foreach (Vector2Int position in m_ActiveWorld.Areas.Keys) { GameObject downstairs = GameObject.Instantiate(sprite); downstairs.transform.position = new Vector3(position.x, position.y, 0.0f); downstairs.GetComponent <SpriteRenderer>().sortingLayerName = "Walls"; downstairs.GetComponent <SpriteRenderer>().sprite = ObjectIcons.GetSprite("Stairs", "DownStairs0"); downstairs.transform.parent = objectHolder.transform; } //Make the floors and the fog of war for (int i = 0; i < m_ActiveWorld.Tiles.GetLength(0); i++) { for (int j = 0; j < m_ActiveWorld.Tiles.GetLength(1); j++) { //Make the floor GameObject gameObject = GameObject.Instantiate(sprite); gameObject.transform.position = new Vector3(i, j); gameObject.GetComponent <SpriteRenderer>().sortingLayerName = "Terrain"; switch (m_ActiveWorld.Tiles[i, j]) { case WorldTile.Paving: gameObject.GetComponent <SpriteRenderer>().sprite = ObjectIcons.GetSprite("Paving", "MiddleMiddle0"); break; case WorldTile.Plains: gameObject.GetComponent <SpriteRenderer>().sprite = ObjectIcons.GetSprite("Plains", "MiddleMiddle0"); break; } gameObject.transform.parent = objectHolder.transform; //Make the fog of war //TODO: MAKE THIS VIABLE GameObject fogOfWar = GameObject.Instantiate(sprite); fogOfWar.transform.position = new Vector3(i, j); fogOfWar.GetComponent <SpriteRenderer>().sortingLayerName = "Fog of War"; fogOfWar.GetComponent <SpriteRenderer>().sprite = ObjectIcons.GetSprite("Obscure", "Obscure0"); fogOfWar.transform.parent = fogOfWarHolder.transform; fogOfWar.name = "Fog of War"; } } //Create the objects foreach (JoyObject obj in m_ActiveWorld.Objects) { MonoBehaviourHandler newObject = GameObject.Instantiate(prefab); newObject.AttachJoyObject(obj); newObject.transform.parent = objectHolder.transform; } //Create the walls foreach (JoyObject wall in m_ActiveWorld.Walls.Values) { MonoBehaviourHandler newObject = GameObject.Instantiate(prefab); newObject.AttachJoyObject(wall); newObject.transform.parent = wallHolder.transform; } //Create the entities foreach (Entity entity in m_ActiveWorld.Entities) { MonoBehaviourHandler newEntity = GameObject.Instantiate(prefab); newEntity.AttachJoyObject(entity); newEntity.transform.parent = entityHolder.transform; } Camera camera = GameObject.Find("Main Camera").GetComponent <Camera>(); Entity player = m_ActiveWorld.Player; camera.transform.position = new Vector3(player.WorldPosition.x, player.WorldPosition.y, camera.transform.position.z); Done = true; }
public static List <Entity> PlaceEntities(WorldInstance worldRef, List <string> entityTypes) { List <Entity> entities = new List <Entity>(); List <EntityTemplate> templates = EntityTemplateHandler.Templates; templates = templates.Where(x => entityTypes.Contains(x.CreatureType)).ToList(); int numberToPlace = (worldRef.Tiles.GetLength(0) * worldRef.Tiles.GetLength(1)) / 50; 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 point = new Vector2Int(i, j); if (PhysicsManager.IsCollision(point, point, worldRef) == PhysicsResult.None && point != worldRef.SpawnPoint) { availablePoints.Add(point); } } } for (int i = 0; i < numberToPlace; i++) { int pointIndex = RNG.Roll(0, availablePoints.Count - 1); int entityIndex = RNG.Roll(0, templates.Count - 1); Entity newEntity = null; if (templates[entityIndex].Sentient) { CultureType culture = CultureHandler.Get(templates[entityIndex].CreatureType); JobType jobType = JobHandler.GetRandom(); Dictionary <string, int> jobLevels = new Dictionary <string, int>(); jobLevels.Add(jobType.name, 1); newEntity = WorldState.EntityHandler.Create(templates[entityIndex], EntityNeed.GetFullRandomisedNeeds(), 1, jobType, culture.ChooseSex(), culture.ChooseSexuality(), new Vector2Int(-1, -1), ObjectIcons.GetSprites(templates[entityIndex].Tileset, templates[entityIndex].CreatureType).ToList(), null); } else { CultureType culture = CultureHandler.Get(templates[entityIndex].CreatureType); JobType jobType = JobHandler.GetRandom(); Dictionary <string, int> jobLevels = new Dictionary <string, int>(); jobLevels.Add(jobType.name, 1); newEntity = WorldState.EntityHandler.Create(templates[entityIndex], EntityNeed.GetBasicRandomisedNeeds(), 1, jobType, culture.ChooseSex(), culture.ChooseSexuality(), new Vector2Int(-1, -1), ObjectIcons.GetSprites(templates[entityIndex].Tileset, templates[entityIndex].CreatureType).ToList(), null); } newEntity.Move(availablePoints[pointIndex]); newEntity.MyWorld = worldRef; entities.Add(newEntity); availablePoints.RemoveAt(pointIndex); } return(entities); }
// Use this for initialization void Start() { InitialiseEverything(); m_StateManager = new StateManager(); Entity thief = WorldState.EntityHandler.Create(EntityTemplateHandler.Get("Human"), EntityNeed.GetFullRandomisedNeeds(), 1, JobHandler.Get("Thief"), Sex.Neutral, Sexuality.Bisexual, Vector2Int.zero, ObjectIcons.GetSprites("Jobs", "Thief"), null); thief.PlayerControlled = true; m_StateManager.ChangeState(new WorldCreationState(thief)); GameObject.Find("NeedsText").GetComponent <GUINeedsAlert>().SetPlayer(thief); }