Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        if (Instance != null)
        {
            Debug.Log("There should never be more than one GameManager.");
            Destroy(this.gameObject);
            return;
        }
        Instance = this;
        GameObject.DontDestroyOnLoad(this.gameObject);

        // Set up MonsterData config file for use
        MonsterDataReader.SetUp();
        MonsterDataReader.ReadData();
        ConsumableDataReader.SetUp();
        ConsumableDataReader.ReadData();

        // Game loads Hero Data from save file,
        // IF NewGame - this save file is set to default in Launch-Menu Scene
        LoadGameData();
        AssignPlayerMonsterParty();


        //if (BSP_MapDictionary.Count < 1)
        //{
        //    SetBSPMapForFloor(playerStartFloor, new BSP_MapGen(dungeonMapWidth, dungeonMapHeight, baseFloorDifficulty));
        //    BSP_MapDictionary[playerStartFloor].GenerateBSPDungeon();
        //    playerDungeonPosition = BSP_MapDictionary[playerStartFloor].GetMapUpStairs;
        //}
    }
    private List <MonsterInfo> PopulateGuardList(int CacheDifficulty)
    {
        List <MonsterInfo> guardList           = new List <MonsterInfo>();
        int pointsToSpend                      = CacheDifficulty;
        List <MonsterInfo> availableCombatants = MonsterDataReader.GetAvailableMonstersForDifficulty(pointsToSpend);

        while (guardList.Count <= 6 && availableCombatants.Count > 0)
        {
            int randIndex = Random.Range(0, availableCombatants.Count);
            guardList.Add(availableCombatants[randIndex]);
            pointsToSpend -= availableCombatants[randIndex].DifficultyLevel;

            availableCombatants = MonsterDataReader.GetAvailableMonstersForDifficulty(pointsToSpend);
        }

        if (guardList.Count < 1)
        {
            Debug.LogError("no guards available for cache with difficulty: " + CacheDifficulty);
        }

        return(guardList);
    }
        public GameObject SpawnMonster(int index, MonsterInfo mi, TeamName team, GameObject teamGroup, GameObject unitSlot)
        {
            // TODO... the index will not be needed once all monster spawns are driven by player and map driven teams
            MonsterInfo monsterInfo;

            if (index == 0)
            {
                monsterInfo = mi;
            }
            else
            {
                // Get monster data from index
                monsterInfo = MonsterDataReader.GetMonsterFromIndex(index);
            }
            // Keep track of count of each monster type in this fight
            TrackCharacterCount(monsterInfo, team);

            GameObject monsterGO = GameObject.Instantiate(monsterTemplateGO, unitSlot.transform.position, Quaternion.identity, teamGroup.transform) as GameObject;

            monsterGO.name = monsterInfo.MonsterName;// + " " + monsterCounts[team + monsterInfo.MonsterName];
            if (team == TeamName.Friendly)
            {
                monsterGO.GetComponent <Monster>().SetMonsterSprite(monsterSprites[monsterInfo.FriendlySpriteName]);
                monsterGO.GetComponent <Animator>().runtimeAnimatorController = Resources.Load($"BattleResources\\Animations\\Default_Animations\\{monsterInfo.AnnimationController}") as RuntimeAnimatorController;
            }
            else if (team == TeamName.Enemy)
            {
                monsterGO.GetComponent <Monster>().SetMonsterSprite(monsterSprites[monsterInfo.EnemySpriteName]);
                monsterGO.GetComponent <Animator>().runtimeAnimatorController = Resources.Load($"BattleResources\\Animations\\Default_Animations\\Enemy\\Enemy{monsterInfo.AnnimationController}") as RuntimeAnimatorController;
            }
            else
            {
                Debug.Log("TEAM name not correct!!!!");
            }
            monsterGO.GetComponent <Monster>().SetTeam(team);
            monsterGO.GetComponent <Monster>().SetUnitSlot(unitSlot);

            // Set Monster's ability
            List <Ability> abilities = new List <Ability>();

            if (!string.IsNullOrEmpty(monsterInfo.Ability1))
            {
                abilities.Add(CreateAbilityFromData(monsterInfo.Ability1));
            }
            if (!string.IsNullOrEmpty(monsterInfo.Ability2))
            {
                abilities.Add(CreateAbilityFromData(monsterInfo.Ability2));
            }
            if (!string.IsNullOrEmpty(monsterInfo.Ability3))
            {
                abilities.Add(CreateAbilityFromData(monsterInfo.Ability3));
            }
            if (!string.IsNullOrEmpty(monsterInfo.Ability4))
            {
                abilities.Add(CreateAbilityFromData(monsterInfo.Ability4));
            }
            // TODO... what if no abilities?!?
            monsterGO.GetComponent <Monster>().SetMonsterAbilities(abilities);

            // Set monster HP, MP and stats
            // HP and Mana specifically Must be set here or the UI at start doesn't update with correct HP/MP
            monsterGO.GetComponent <Monster>().SetupMonster(monsterInfo);
            // Set Character Unique ID
            monsterGO.GetComponent <Monster>().SetUniqueID(AssignUniqueID(monsterInfo, team));

            // Trigger Unit Spawn Event Callback
            EventCallbacks.UnitSpawnEventInfo usei = new EventCallbacks.UnitSpawnEventInfo();
            usei.EventDescription = "Unit " + monsterGO.name + " has spawned.";
            usei.UnitGO           = monsterGO;
            usei.UnitSlotGO       = unitSlot;
            usei.FireEvent();

            return(monsterGO);
        }