Ejemplo n.º 1
0
    // Start is called before the first frame update
    void Awake()
    {
        if (!Team)
        {
            Team = FindObjectOfType <PlayerTeam>();
        }

        if (!Instance)
        {
            Instance = this;
        }

        EntryObject.gameObject.SetActive(false);
    }
Ejemplo n.º 2
0
    internal static void BuyGoblin(Goblin goblin, int price, GoblinWarrens oldVillage)
    {
        Instance.Team.OnTreasureFound.Invoke(-price);

        goblin.Team = Instance.Team;

        //TODO: use method for these
        Instance.Team.AddMember(goblin);
        goblin.transform.parent = Instance.Team.transform;
        goblin.tag = "Player";

        GoblinUIList.UpdateGoblinList();

        oldVillage.Members.Remove(goblin);
    }
Ejemplo n.º 3
0
    internal static void SellGoblin(Goblin goblin, int price, GoblinWarrens newVillage)
    {
        Instance.Team.Members.Remove(goblin);
        Instance.Team.OnTreasureFound.Invoke(price);

        GoblinUIList.UpdateGoblinList();

        goblin.Team = null;

        goblin.transform.parent = newVillage.transform;

        goblin.tag = "NPC";

        newVillage.Members.Add(goblin);
    }
Ejemplo n.º 4
0
    private void NextLevel()
    {
        //a sound
        SoundController.PlayLevelup();

        PopUpText.ShowText(name + " has gained a new level!");

        //TODO: health should be handled differently than other stuff
        HEA.LevelUp();

        if (CurrentLevel == 2)
        {
            WaitingOnClassSelection = true;
        }

        GoblinUIList.UpdateGoblinList();
    }
Ejemplo n.º 5
0
    public void ConfirmChoice()
    {
        Debug.Log("Selection confirmed: " + SelectedChoice.Attribute);


        switch (SelectedChoice.Type)
        {
        case LevelController.ChoiceType.Attribute:
            LevelUp(character, character.Stats[SelectedChoice.Attribute]);
            break;

        case LevelController.ChoiceType.Class:
            SelectClass(character, SelectedChoice.Class);
            break;

        case LevelController.ChoiceType.Skill:
            break;

        default:
            throw new ArgumentOutOfRangeException();
        }

        Close();

        character.LevelUps++;

        //TODO: use goblin change event
        GoblinUIList.UpdateGoblinList();

        //TODO: use a character stat change event instead.
        CharacterView.ShowCharacter(character);


        Debug.Log("Closing level view");
        ViewHolder.SetActive(false);
    }
Ejemplo n.º 6
0
    // Use this for initialization
    public IEnumerator GenerateMap(Action <int, string> callback, Action endCallback)
    {
        Debug.Log("Setting max threads to number of cores: " + SystemInfo.processorCount);

        MaximumThreads = SystemInfo.processorCount;

        progressCallback = callback;

        startTime = Time.time;

        progress = 0;
        charFact = 25;
        areaFact = 2500;
        poiFact  = 1000;
        //could use factors on the two last to make them more important than each tiles
        progressPct = 0;

        callback(progressPct, "");

        yield return(null);

        totalAreaSize = AreaSize + AreaBufferSize;

        var areasToCreate = (SizeX / totalAreaSize) * (SizeZ / totalAreaSize);

        if (areasToCreate < 2)
        {
            Debug.LogError("Map size too small for area gen");
            yield break;
        }

        Debug.Log("Creating " + areasToCreate + " areas");

        NpcsToGenerate = areasToCreate;

        amountOfLoot = areasToCreate;//noOfAreasX * noOfAreasZ;

        totalProgress = SizeX * SizeZ +
                        areasToCreate * areaFact * 2
                        + VillagesToGenerate * poiFact
                        + PointOfInterests * poiFact
                        + amountOfLoot
                        + NpcsToGenerate * charFact
                        + GoblinsToGenerate * charFact;

        totalProgress = (int)(totalProgress * 0.83f);

        //Setting up mesh builder
        MeshBuilder.transform.localScale = new Vector3(SizeX / 8f, 1, SizeZ / 8f);
        MeshBuilder.m_Size             = new Vector3(SizeX, 10, SizeZ);
        MeshBuilder.transform.position = new Vector3(SizeX / 2f, 0, SizeZ / 2f);

        yield return(null);

        //Forest gen

        // using a tile array to generate the map before initializing it
        //GENERATING
        movableTiles = new List <Tile>();
        map          = new Tile[SizeX, SizeZ];
        for (int i = 0; i < SizeX; i++)
        {
            for (int j = 0; j < SizeZ; j++)
            {
                map[i, j] = new Tile(i, j);
                immovableTiles.Add(map[i, j]);
            }
        }

        //Instantiating Area Tiles

        Areas = new List <Area>();
        //AreaMap = new Area[noOfAreasX, noOfAreasZ];

        //TODO: could simply test for when variables are ready, when they are needed
        StartCoroutine(AreaGenRoutine());

        yield return(new WaitUntil(() => areaGenDone));

        PathGenRoutine();

        //Probably need dependency

        StartCoroutine(POIGenRoutine());

        StartCoroutine(LootGenRoutine());

        yield return(new WaitUntil(() => pathGenDone && roadsBeingBuilt <= 0));

        StartCoroutine(GroundGenRoutine());

        yield return(new WaitUntil(() => poiGenDone && areasExpanding <= 0));

        StartCoroutine(ForestGenRoutine());

        //HACK CHECK FOR AREA ACCESSIBILITY
        //select a middle point
        //ground points at random a bunch of times and check that they are reachable
        //if not make a forest road

        for (int i = 0; i < NpcsToGenerate; i++)
        {
            //TODO: create a number of spawn positions and check their connectivity.
            CreateEnemyCharacter(Npcs[Random.Range(0, Npcs.Length)], NpcHolder.Instance.transform, goblinStartArea);

            progress += charFact;

            int loc = (progress * 100) / totalProgress;
            if (loc != progressPct)
            {
                progressPct = loc;
                yield return(null);

                callback(progressPct, "Warming up enemies...");
            }
        }


        Debug.Log("Finished NPC gen : " + (Time.time - startTime) + " seconds");

        foreach (var ar in Areas)
        {
            ar.SetUpUI();
        }

        List <Goblin> members = new List <Goblin>();

        yield return(new WaitUntil(() => goblinStartArea != null));

        var pos = goblinStartArea.transform.position;

        Debug.Log("Initializing Goblin team in " + goblinStartArea);

        //Find suitable start position
        GoblinTeam.transform.position = new Vector3(pos.x, 0, pos.z);

        var b = PlayerTeam.TribeBlessing;

        if (b == LegacySystem.Blessing.SoloGoblin)
        {
            GoblinsToGenerate = 1;
        }
        if (b == LegacySystem.Blessing.ExtraGoblin)
        {
            GoblinsToGenerate++;
        }
        if (b == LegacySystem.Blessing.ExtraSlaves)
        {
            GoblinsToGenerate += 2;
        }

        //TODO: check that we are not initializinig in a too small area. could be done with connectivity check
        //TODO: Use create character
        for (int i = 0; i < GoblinsToGenerate; i++)
        {
            var next = Instantiate(DefaultCharacter, GoblinTeam.transform);

            pos = pos + Random.insideUnitSphere * GroupDistance;

            //Debug.Log("Creating gbolin at "+ pos.X +","+pos.Y);

            next.transform.position = new Vector3(pos.x, 0, pos.z);

            var g = next.GetComponent <Goblin>();

            g.name = NameGenerator.GetName();

            members.Add(g);

            g.InArea = goblinStartArea;


            if (b == LegacySystem.Blessing.ExtraSlaves && i >= GoblinsToGenerate - 2)
            {
                g.SelectClass(Goblin.Class.Slave);
            }

            progress += charFact;

            int loc = (progress * 100) / totalProgress;
            if (loc != progressPct)
            {
                progressPct = loc;
                yield return(null);

                callback(progressPct, "Giving birth to beatiful goblins...");
            }
        }

        Debug.Log("Finished Goblin gen : " + (Time.time - startTime) + " seconds");

        yield return(new WaitUntil((() => forestGenDone && groundGenDone)));

        CreateTreeBorder(20);

        yield return(null);

        GoblinTeam.Initialize(members);

        GameManager.StartGame();

        GoblinUIList.UpdateGoblinList();

        PlayerController.UpdateFog();

        Debug.Log("Finishing generation in : " + (Time.time - startTime) + " seconds");

        endCallback();
    }