Example #1
0
    //given an index and the type of summon, summons that entity with the next available name
    public void BuildBuilding(int cellindex, string buildingname, string playerid)
    {
        Vector3 buildindex = hexGrid.GetCellPos(cellindex);

        buildindex.y = 0.2f;

        //Instantiate the prefab from the resources folder
        GameObject building   = (GameObject)Instantiate(Resources.Load(buildingname), buildindex, Quaternion.identity);
        Guid       buildingID = Guid.NewGuid();

        building.name = buildingID.ToString();
        char playerChar = playerid[0];

        buildingStorage.PlayerBuildingList(playerChar).Add(building);
        hexGrid.SetBuildingObject(cellindex, building);

        //sets stats for building
        buildingStats.SetPlayerID(building, playerid);
        buildingStats.SetType(building, buildingname);
        buildingStats.SetUniqueID(building, buildingID);
        buildingStats.SetCellIndex(building, cellindex);

        int health = buildingStats.GetMaxHealth(buildingname);

        buildingStats.SetMaxHealth(building, health);
        buildingStats.SetCurrHealth(building, health);
        int range = buildingStats.GetRange(buildingname);

        buildingStats.SetRange(building, range);
        int rangedattdmg = buildingStats.GetRangedAttackDmg(buildingname);

        buildingStats.SetRangedAttackDmg(building, rangedattdmg);
        int defense = buildingStats.GetDefense(buildingname);

        buildingStats.SetDefense(building, defense);
        int vision = buildingStats.GetVision(buildingname);

        buildingStats.SetVision(building, vision);

        loadMap.CreateHealthLabel(cellindex, health, building.name);
    }
    void HandleInput()
    {
        if (editmode == true)
        {
            currindex = select.ChangeTerrain(colors, activeColor);
        }
        else
        {
            currindex = select.GetCurrIndex();
        }

        //TODO lock ability for user to save while attack in progress because battle object is not saved

        //-----Selector--------------
        Debug.Log(currindex);
        //string currEntityName = hexGrid.GetEntityName (currindex);
        GameObject currEntityObj   = hexGrid.GetEntityObject(currindex);
        GameObject currBuildingObj = hexGrid.GetBuildingObject(currindex);
        //string cleanCurrEntity = Regex.Replace(currEntityName.Substring(2), @"[\d-]", string.Empty);
        //string cleanCurrBuilding = Regex.Replace(currBuildingName.Substring(2), @"[\d-]", string.Empty);

        char playerChar = playerManager.currPlayer[0];

        if (entityStorage.PlayerEntityList(playerChar).Contains(currEntityObj))
        {
            selectedindex = currindex;
            //TODO list info for curr entity, display it
            lockbattle = false;
        }
        if (buildingStorage.PlayerBuildingList(playerChar).Contains(currBuildingObj))
        {
            buildingManager.DisplayBuilding(currindex);
            //TODO GUI for buildings
        }
        //ensures attacks only happen once per update
        if (lockbattle == false)
        {
            bool checkAttHappen = battle.Attack(selectedindex, currindex);
            if (checkAttHappen == true)
            {
                lockbattle = true;
            }
        }
    }
Example #3
0
    //check each player entity in entitystorage to determine their vision range and remove the fog for that range
    public void EntityCurrPlayerVision()
    {
        if (playerManager.currPlayer != string.Empty)
        {
            char playerChar = playerManager.currPlayer[0];
            //Debug.Log(entityStorage.PlayerEntityList(playerChar)[0].name.Substring(2));
            foreach (GameObject playerEntity in entityStorage.PlayerEntityList(playerChar))
            {
                int    visionDistance = entityStats.GetCurrVision(playerEntity);
                int    index          = entityStats.GetCellIndex(playerEntity);
                string height         = hexGrid.GetTerrain(index);

                Dictionary <int, int> vision = PlayerVisionHelper(index, visionDistance, height);
                foreach (var tile in vision)
                {
                    hexGrid.SetFog(tile.Key, false);
                    Fog fog = fogs[tile.Key];
                    fog.GetComponent <Renderer>().enabled = false;
                }
            }
            foreach (GameObject buildingEntity in buildingStorage.PlayerBuildingList(playerChar))
            {
                int    visionDistance = buildingStats.GetCurrVision(buildingEntity);
                int    index          = buildingStats.GetCellIndex(buildingEntity);
                string height         = hexGrid.GetTerrain(index);

                Dictionary <int, int> vision = PlayerVisionHelper(index, visionDistance, height);
                foreach (var tile in vision)
                {
                    if (tile.Value >= -2)
                    {
                        hexGrid.SetFog(tile.Key, false);
                        Fog fog = fogs[tile.Key];
                        fog.GetComponent <Renderer>().enabled = false;
                    }
                }
            }
        }
    }
    public void TickProduction()
    {
        //if (!buildingStorage.activePlayerBuildings.Any())
        //{
        //    return;
        //}
        string currPlayerid = playerManager.currPlayer;
        char   playerChar   = currPlayerid[0];

        foreach (GameObject currBuildings in buildingStorage.PlayerBuildingList(playerChar))
        {
            currBuildings.GetComponent <Building>().TickProductionTimer();
            currBuildings.GetComponent <Building>().TickRecruitmentTimer();
            if (currBuildings.GetComponent <Building>().currConstructionTimer <= 0)
            {
                currBuildings.GetComponent <Building>().CompleteConstruction();
            }
            if (currBuildings.GetComponent <Building>().currRecruitmentTimer <= 0)
            {
                currBuildings.GetComponent <Building>().CompleteRecruitment();
            }
        }
    }