Exemplo n.º 1
0
    public BaseUnit(BaseUnitData data)
    {
        _data     = data;
        Inventory = new UnitInventory(CreateSlotsData(), _data.BaseEquipment, OnEquipmentUpdate);

        RecalculateParamsInternal();
    }
Exemplo n.º 2
0
    private void LoadEnemyUnitsResources(MissionMapData mapData)
    {
        BaseUnitData      bud = null;
        BaseUnitBehaviour bub = null;

        //load unique units
        for (int i = 0; i < mapData.Units.Length; i++)
        {
            if (_enemyUnitsGraphicsResources.ContainsKey(mapData.Units[i]))
            {
                continue;
            }

            bud = UnitsConfig.Instance.GetUnitData(mapData.Units[i]);
            if (bud != null && !bud.PrefabName.Equals(string.Empty))
            {
                bub = LoadUnitResource <BaseUnitBehaviour>(string.Format("{0}/{1}", GameConstants.Paths.UNIT_RESOURCES, bud.PrefabName));
                _enemyUnitsGraphicsResources.Add(mapData.Units[i], bub);
            }
            else
            {
                Debug.LogError("Can't load unit graphics: " + mapData.Units[i]);
            }
        }
    }
Exemplo n.º 3
0
    public Unit SpawnUnit(BaseUnitData unitData)
    {
        Unit unit = new Unit(unitData);

        units.Add(unit);
        return(unit);
    }
Exemplo n.º 4
0
    private Dictionary <string, BaseUnitData> ParseUnitData(TextAsset textFile)
    {
        Dictionary <string, BaseUnitData> unitDataDict = new Dictionary <string, BaseUnitData>();

        string textFileString = textFile.text;

        string[] rowStrings = textFileString.Split('\n');
        for (int i = 1; i < rowStrings.Length; i++)
        {
            string   rowString   = rowStrings[i];
            string[] cellStrings = rowString.Split('\t');

            string name = cellStrings[(int)UnitDataColumns.Name];
            string description = cellStrings[(int)UnitDataColumns.Description];
            int    sizeX, sizeY;
            int.TryParse(cellStrings[(int)UnitDataColumns.SizeX], out sizeX);
            Debug.Assert(sizeX != 0, "Improper size X value for " + name);
            int.TryParse(cellStrings[(int)UnitDataColumns.SizeY], out sizeY);
            Debug.Assert(sizeY != 0, "Improper size Y value for " + name);
            Vector2Int     size           = new Vector2Int(sizeX, sizeY);
            UnitSpriteData unitSpriteData = null;
            if (spriteDataDict.ContainsKey(name.ToUpper()))
            {
                unitSpriteData = spriteDataDict[name.ToUpper()];
            }
            else
            {
                Debug.Assert(false, "Unit sprite data for " + name + " not found");
            }
            Sprite   sprite           = unitSpriteData.Sprite;
            string[] componentStrings = cellStrings[(int)UnitDataColumns.Components].Split(';');
            List <UnitComponentFactory> unitComponentFactories = new List <UnitComponentFactory>();
            foreach (string componentString in componentStrings)
            {
                if (componentString == "")
                {
                    continue;
                }
                string[] componentStringParts = componentString.Split(',');
                string   componentName        = componentStringParts[0];
                string[] componentParams      = new string[componentStringParts.Length - 1];
                componentStringParts.CopyTo(componentParams, 1);
                UnitComponentFactory unitComponentFactory = new UnitComponentFactory(componentName,
                                                                                     componentParams);
                unitComponentFactories.Add(unitComponentFactory);
            }
            BaseUnitData baseUnitData = new BaseUnitData(name, description, size, sprite,
                                                         unitComponentFactories);
            unitDataDict.Add(name, baseUnitData);
        }

        return(unitDataDict);
    }
Exemplo n.º 5
0
    public BaseUnitData GetUnitData(EUnitKey unitKey)
    {
        BaseUnitData bud = null;

        bud = GetHeroData(unitKey);
        if (bud != null)
        {
            return(bud);
        }

        bud = GetSoldierData(unitKey);
        return(bud);
    }
Exemplo n.º 6
0
    private void LoadAllyUnitsResources()
    {
        //check if this is first map
        if (_allyUnitsGraphicsResources.Count > 0)
        {
            return;
        }

        ArrayRO <BaseSoldier> playerSoldiersList = Global.Instance.CurrentMission.SelectedSoldiers;

        BaseUnitData      bud = null;
        BaseUnitBehaviour bub = null;

        //load unique soldiers
        for (int i = 0; i < playerSoldiersList.Length; i++)
        {
            if (_allyUnitsGraphicsResources.ContainsKey(playerSoldiersList[i].Data.Key))
            {
                continue;
            }

            bud = UnitsConfig.Instance.GetSoldierData(playerSoldiersList[i].Data.Key);
            if (bud != null && !bud.PrefabName.Equals(string.Empty))
            {
                bub = LoadUnitResource <BaseUnitBehaviour>(string.Format("{0}/{1}", GameConstants.Paths.UNIT_RESOURCES, bud.PrefabName));
                _allyUnitsGraphicsResources.Add(playerSoldiersList[i].Data.Key, bub);
            }
            else
            {
                Debug.LogError("Can't load unit graphics: " + playerSoldiersList[i].Data.Key);
            }
        }

        //load hero
        BaseHero playerHero = Global.Instance.Player.Heroes.Current;

        if (playerHero == null || playerHero.Data.PrefabName.Equals(string.Empty))
        {
            Debug.LogError("Can't load unit graphics for player hero");
        }

        bub = LoadUnitResource <BaseUnitBehaviour>(string.Format("{0}/{1}", GameConstants.Paths.UNIT_RESOURCES, playerHero.Data.PrefabName));
        _allyUnitsGraphicsResources.Add(playerHero.Data.Key, bub);
    }
Exemplo n.º 7
0
    private void InstantiateEnemyUnits(MissionMapData mapData)
    {
        //TODO: setup inventory

        BaseUnitBehaviour[] unitsList = new BaseUnitBehaviour[mapData.Units.Length];

        BaseUnitData      bud = null;
        BaseUnitBehaviour bub = null;

        //instantiate soldiers
        for (int i = 0; i < mapData.Units.Length; i++)
        {
            bub = (GameObject.Instantiate(_enemyUnitsGraphicsResources[mapData.Units[i]].gameObject) as GameObject).GetComponent <BaseUnitBehaviour>();
            bub.gameObject.name = "Enemy_" + mapData.Units[i] + " (" + i + ")";
            unitsList[i]        = bub;

            bud = UnitsConfig.Instance.GetUnitData(mapData.Units[i]);
            //LoadItemsResources(_enemyItemsGraphicsResources, mapData.Units[i], bub.ModelView, bud.GetBaseItemInSlot(EUnitEqupmentSlot.Weapon_RHand), bud.GetBaseItemInSlot(EUnitEqupmentSlot.Weapon_LHand), bud.GetBaseItemInSlot(EUnitEqupmentSlot.Armor));
        }

        //save
        _enemyUnits = new ArrayRO <BaseUnitBehaviour>(unitsList);
    }
Exemplo n.º 8
0
	public BaseUnit(BaseUnitData data) {
		_data = data;
		Inventory = new UnitInventory(CreateSlotsData(), _data.BaseEquipment, OnEquipmentUpdate);

		RecalculateParamsInternal();
	}
Exemplo n.º 9
0
    private IEnumerator InitializeUnitsData(MissionMapData mapData)
    {
        _fightPreparationStep = EFightPreparationStep.InitializeUnitsGraphics;

        float unitInitializationStep = (0.9f - 0.25f) / (_alliesCount + _enemiesCount);
        float currentLoadPercentage  = 0.25f;

        //get player hero skills
        Dictionary <ESkillKey, BaseUnitSkill> playerHeroSkills = new Dictionary <ESkillKey, BaseUnitSkill>();
        SkillParameters skillParams = SkillsConfig.Instance.HetHeroSkillParameters(Global.Instance.Player.Heroes.Current.Data.Key);

        if (skillParams != null)
        {
            playerHeroSkills.Add(skillParams.Key, SkillsConfig.Instance.GetSkillInstance(skillParams));
        }
        ListRO <ESkillKey> playerHeroSkillKeys = Global.Instance.Player.HeroSkills.GetHeroSkills(Global.Instance.Player.Heroes.Current.Data.Key);

        for (int i = 0; i < playerHeroSkillKeys.Count; i++)
        {
            skillParams = SkillsConfig.Instance.GetSkillParameters(playerHeroSkillKeys[i]);
            if (skillParams != null)
            {
                playerHeroSkills.Add(skillParams.Key, SkillsConfig.Instance.GetSkillInstance(skillParams));
            }
        }

        _graphics.AllyUnits[_graphics.AllyUnits.Length - 1].Setup(Global.Instance.Player.Heroes.Current, playerHeroSkills,
                                                                  GameConstants.Tags.UNIT_ALLY, _graphics.UnitUIResource, Global.Instance.CurrentMission.SelectedSoldiers.Length);
        for (int i = 0; i < Global.Instance.CurrentMission.SelectedSoldiers.Length; i++)
        {
            if (!Global.Instance.CurrentMission.SelectedSoldiers[i].IsDead)
            {
                _graphics.AllyUnits[i].Setup(Global.Instance.CurrentMission.SelectedSoldiers[i], null, GameConstants.Tags.UNIT_ALLY, _graphics.UnitUIResource, i);                      //TODO: setup units skills

                currentLoadPercentage += unitInitializationStep;
                LoadingScreen.Instance.SetProgress(currentLoadPercentage);

                yield return(null);
            }
        }

        BaseUnitData bud = null;

        for (int i = 0; i < mapData.Units.Length; i++)
        {
            bud = UnitsConfig.Instance.GetUnitData(mapData.Units[i]);
            if (bud is BaseHeroData)
            {
                _graphics.EnemyUnits[i].Setup(new BaseHero(bud as BaseHeroData, 0), null, GameConstants.Tags.UNIT_ENEMY, _graphics.UnitUIResource, i);                  //TODO: setup enemy hero inventory, hero skills
            }
            else
            {
                _graphics.EnemyUnits[i].Setup(new BaseSoldier(bud as BaseSoldierData, 1), null, GameConstants.Tags.UNIT_ENEMY, _graphics.UnitUIResource, i);                    //TODO: setup enemy soldier upgrades, unit skills
            }

            currentLoadPercentage += unitInitializationStep;
            LoadingScreen.Instance.SetProgress(currentLoadPercentage);

            yield return(null);
        }

        _fightPreparationStep = EFightPreparationStep.UnitsGraphicsInitialized;
    }
Exemplo n.º 10
0
 public Unit(BaseUnitData baseUnitData)
 {
     this.baseUnitData = baseUnitData;
     unitComponents    = baseUnitData.GetUnitComponents(this);
 }