Exemplo n.º 1
0
 public Area(AreaType areaType, Vector2Int Position)
 {
     discovered   = false;
     position     = new Vector2IntS(Position);
     pathToSaveTo = AreaManager.CurrentSaveFolder + position.x + "_" + position.y + ".xml";
     type         = areaType;
     entities     = new List <Entity>();
 }
Exemplo n.º 2
0
 public Area()
 {
     discovered   = false;
     position     = Vector2IntS.zero;
     pathToSaveTo = AreaManager.CurrentSaveFolder + position.x + "_" + position.y + ".xml";
     type         = areaTypes[0];
     entities     = new List <Entity>();
 }
Exemplo n.º 3
0
 public void AssignType(int typeID)
 {
     if (typeID >= 0 && typeID < areaTypes.Count)
     {
         if (areaTypes != null)
         {
             type = areaTypes[typeID];
         }
     }
 }
Exemplo n.º 4
0
 public void AssignType(AreaType atype)
 {
     if (atype != null)
     {
         type = atype;
     }
     else
     {
         type = areaTypes[0];
     }
 }
Exemplo n.º 5
0
 public void AssignType(string areaName)
 {
     for (int i = 0; i < areaTypes.Count; i++)   //search through list
     {
         if (areaTypes[i].name.Equals(areaName)) //if name matches
         {
             type = areaTypes[i];                //return the type
             return;                             //leave method
         }
     }                                           //if loop completes, area name was not found
     type = areaTypes[0];                        //assign default type
 }
Exemplo n.º 6
0
 public override bool Equals(object obj)
 {
     if (obj.GetType().Equals(typeof(AreaType)))
     {
         AreaType cast = (AreaType)obj;
         if (cast.name.Equals(name))
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 7
0
        /// <summary>
        /// Populates the area with entities (Characters, Scenery, Structures).
        /// </summary>
        /// <param name="charactersOnly">To be used when repopulating dead characters</param>
        /// <returns></returns>
        public IEnumerator Populate(bool charactersOnly)
        {
            if (type == null)
            {
                if (areaTypes != null && areaTypes[0] != null)
                {
                    type = areaTypes[0];
                }
            }

            string entityAreaPrefix = type.name + "_";
            string currEntityFilename;

            if (entities == null)               //shouldn't be null, but just in case
            {
                entities = new List <Entity>();
            }
            else
            {
                entities.Clear();
            }

            Entity tempEntity;                                               //current entity to add
            int    i;                                                        //iteration index for all 3 loops
            int    numEntities    = 0;                                       //num of entites for this area
            int    currAssetCount = 0;                                       // num of assets available for areatype
            int    assetTypeLimit = charactersOnly ? 1 : 3;                  //limits the loop to only do characters if true

            for (int assetType = 0; assetType < assetTypeLimit; assetType++) //loop through each asset type and do (mostly) the same thing
            {
                switch (assetType)                                           //establish the only differences
                {
                case 1:
                    currAssetCount     = type.sceneryAssetCount;                         //set the count
                    currEntityFilename = "Scenery/" + entityAreaPrefix;                  //set folder path
                    numEntities        = Random.Range(10, type.sceneryMaxSpawnCount);    //set random quantity for scenery objs in this area
                    break;

                case 2:
                    currAssetCount     = type.structureAssetCount;                         //set the count
                    currEntityFilename = "Structures/" + entityAreaPrefix;                 //set folder path
                    numEntities        = Random.Range(1, type.structureMaxSpawnCount);     //set random quantity for scenery objs in this area
                    break;

                default:
                    currAssetCount     = type.characterAssetCount;                         //set the count
                    currEntityFilename = "Characters/" + entityAreaPrefix;                 //set folder path
                    numEntities        = Random.Range(5, type.characterMaxSpawnCount);     //set random quantity for character objs in this area
                    break;
                }

                if (currAssetCount > 0)                   //if asset type has assets to offer
                {
                    for (i = 0; i < numEntities; i++)
                    {
                        tempEntity             = new Entity();                                           //instantiate new entity
                        tempEntity.name        = currEntityFilename + (Random.Range(0, currAssetCount)); //i.e. "Structures/Plains_0" -- So, it will be prepped for Resources.Load<GameObject>(path)
                        tempEntity.positionX   = Random.Range(-boundaryRadius, boundaryRadius);          //generate random position
                        tempEntity.positionY   = Random.Range(-boundaryRadius, boundaryRadius);
                        tempEntity.lastUpdated = (int)WorldManager.ElapsedGameTime;
                        entities.Add(tempEntity);
                    }
                }
                yield return(new WaitForEndOfFrame());                //add time between iterations
            }

            Save();
        }