private void OnBtnPlayClick()
    {
        List <BaseSoldier> soldiers = new List <BaseSoldier>();

        for (int i = 0; i < _hiredSoldiers.Length; i++)
        {
            if (_hiredSoldiers[i] >= 0)
            {
                soldiers.Add(new BaseSoldier(_availableSoldiers[_hiredSoldiers[i]], Global.Instance.Player.City.GetSoldierUpgradesInfo(_availableSoldiers[_hiredSoldiers[i]].Key).Level));
            }
        }
        Global.Instance.CurrentMission.SelectedSoldiers = new ArrayRO <BaseSoldier>(soldiers.ToArray());

        //setup random units and map
        EUnitKey[] availableUnits = new EUnitKey[] { EUnitKey.Scout, EUnitKey.Trooper, EUnitKey.Jawa_1 };
        string[]   availableMaps  = new string[] { "battle1_forest_1", "battle1_forest_2" };

        EUnitKey[] units = new EUnitKey[Random.Range(1, 6)];
        units[0] = EUnitKey.Hero_Sniper;
        for (int i = 1; i < units.Length; i++)
        {
            units[i] = availableUnits[Random.Range(0, availableUnits.Length)];
        }

        MissionMapData mmd = new MissionMapData(units, availableMaps[Random.Range(0, availableMaps.Length)]);
        MissionData    md  = new MissionData(EMissionKey.None, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, new MissionMapData[] { mmd });

        FightManager.Setup(EFightMode.PvP, md);

        LoadingScreen.Instance.Show();
        LoadingScreen.Instance.SetProgress(0f);
        Application.LoadLevel("Fight");
    }
Example #2
0
 public void SetSoldierLevel(EUnitKey unitKey, int level)
 {
     for (int i = GetSoldierUpgradesInfo(unitKey).Level; i < level; i++)
     {
         GetSoldierUpgradesInfo(unitKey).LevelUp();
     }
 }
    public void Setup(EUnitKey unitKey)
    {
        _unitKey = unitKey;

        Sprite enemyIconBGResource = UIResourcesManager.Instance.GetResource <Sprite>(GameConstants.Paths.GetUnitBGIconResourcePath(unitKey));

        if (enemyIconBGResource != null)
        {
            _unitBG.sprite  = enemyIconBGResource;
            _unitBG.enabled = true;
        }
        else
        {
            _unitBG.enabled = false;
        }
        Sprite enemyIconFGResource = UIResourcesManager.Instance.GetResource <Sprite>(GameConstants.Paths.GetUnitIconResourcePath(unitKey));

        if (enemyIconFGResource != null)
        {
            _unitFG.sprite  = enemyIconFGResource;
            _unitFG.enabled = true;
        }
        else
        {
            _unitFG.enabled = false;
        }
    }
Example #4
0
 public SoldierUpgradesInfo GetSoldierUpgradesInfo(EUnitKey unitKey)
 {
     if (!_unitUpgrades.ContainsKey(unitKey))
     {
         _unitUpgrades.Add(unitKey, new SoldierUpgradesInfo(unitKey));
     }
     return(_unitUpgrades[unitKey]);
 }
	private List<ESkillKey> GetHeroSkillsInternal(EUnitKey heroKey) {
		if (!_heroSkillsData.ContainsKey(heroKey)) {
			_heroSkillsData.Add(heroKey, new List<ESkillKey>());
		}
		if (_heroSkillsData[heroKey] == null) {
			_heroSkillsData[heroKey] = new List<ESkillKey>();
		}
		return _heroSkillsData[heroKey];
	}
	public SoldierUpgradesInfo(EUnitKey unitKey, int currentLevel) {
		if (currentLevel < 1 || currentLevel > GameConstants.City.MAX_UNIT_UPGRADE_LEVEL) {
			Debug.LogError("Wrong unit level: " + unitKey + " - " + currentLevel);
			currentLevel = 1;
		}

		UnitKey = unitKey;
		Level = currentLevel;
	}
	public void SetSkillIndex(EUnitKey heroKey, ESkillKey skillKey, int index) {
		List<ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);
		if (index < 0 || index >= heroSkills.Count) {
			return;
		}
		if (heroSkills.IndexOf(skillKey) != -1 && heroSkills.IndexOf(skillKey) != index) {
			heroSkills.Remove(skillKey);
			heroSkills.Insert(index, skillKey);
		}
	}
	public BaseHero GetHero(EUnitKey heroKey) {
		if (_heroes != null) {
			for (int i = 0; i < _heroes.Length; i++) {
				if (_heroes[i].Data.Key == heroKey) {
					return _heroes[i];
				}
			}
		}
		return null;
	}
	public void AddSkill(EUnitKey heroKey, ESkillKey skillKey) {
		List<ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);
		if (heroSkills.Count >= _maxSkillsAmount) {
			return;
		}
		if (heroSkills.IndexOf(skillKey) != -1) {
			return;
		}
		heroSkills.Add(skillKey);
	}
Example #10
0
 public SkillParameters HetHeroSkillParameters(EUnitKey heroKey)
 {
     for (int i = 0; i < _heroesUniqueSkills.Length; i++)
     {
         if (_heroesUniqueSkills[i].HeroKey == heroKey)
         {
             return(_heroesUniqueSkills[i].Skill);
         }
     }
     return(null);
 }
Example #11
0
 public BaseSoldierData GetSoldierData(EUnitKey unitKey)
 {
     for (int i = 0; i < _soldiersData.Length; i++)
     {
         if (_soldiersData[i].Key == unitKey)
         {
             return(_soldiersData[i]);
         }
     }
     return(null);
 }
Example #12
0
    public SoldierUpgradesInfo(EUnitKey unitKey, int currentLevel)
    {
        if (currentLevel < 1 || currentLevel > GameConstants.City.MAX_UNIT_UPGRADE_LEVEL)
        {
            Debug.LogError("Wrong unit level: " + unitKey + " - " + currentLevel);
            currentLevel = 1;
        }

        UnitKey = unitKey;
        Level   = currentLevel;
    }
	public void Setup(EUnitKey unitKey) {
		_unitData = UnitsConfig.Instance.GetSoldierData(unitKey);

		_lblLeadershipCost.text = _unitData.LeadershipCost.ToString();
		//TODO: set leved

		Sprite enemyIconResource = UIResourcesManager.Instance.GetResource<Sprite>(GameConstants.Paths.GetUnitIconResourcePath(_unitData.IconName));
		if (enemyIconResource != null) {
			_imgUnitIcon.sprite = enemyIconResource;
		}
	}
Example #14
0
 public BaseHeroData GetHeroData(EUnitKey unitKey)
 {
     for (int i = 0; i < _heroesData.Length; i++)
     {
         if (_heroesData[i].Key == unitKey)
         {
             return(_heroesData[i]);
         }
     }
     return(null);
 }
Example #15
0
    public SoldierUpgrade GetSoldierUpgrades(EUnitKey unitKey)
    {
        for (int i = 0; i < _soldierUpgrades.Length; i++)
        {
            if (_soldierUpgrades[i].SoldierKey == unitKey)
            {
                return(_soldierUpgrades[i]);
            }
        }

        return(null);
    }
	public void Clear() {
		if (_unitBG.sprite != null) {
			_unitBG.sprite = null;
			UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitBGIconResourcePath(_unitKey));
		}
		if (_unitFG.sprite != null) {
			_unitFG.sprite = null;
			UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitIconResourcePath(_unitKey));
		}

		_unitKey = EUnitKey.Idle;
	}
Example #17
0
 private List <ESkillKey> GetHeroSkillsInternal(EUnitKey heroKey)
 {
     if (!_heroSkillsData.ContainsKey(heroKey))
     {
         _heroSkillsData.Add(heroKey, new List <ESkillKey>());
     }
     if (_heroSkillsData[heroKey] == null)
     {
         _heroSkillsData[heroKey] = new List <ESkillKey>();
     }
     return(_heroSkillsData[heroKey]);
 }
Example #18
0
    public BaseUnitData GetUnitData(EUnitKey unitKey)
    {
        BaseUnitData bud = null;

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

        bud = GetSoldierData(unitKey);
        return(bud);
    }
Example #19
0
    public void Setup(EUnitKey unitKey)
    {
        _unitData = UnitsConfig.Instance.GetSoldierData(unitKey);

        _lblLeadershipCost.text = _unitData.LeadershipCost.ToString();
        //TODO: set leved

        Sprite enemyIconResource = UIResourcesManager.Instance.GetResource <Sprite>(GameConstants.Paths.GetUnitIconResourcePath(_unitData.IconName));

        if (enemyIconResource != null)
        {
            _imgUnitIcon.sprite = enemyIconResource;
        }
    }
Example #20
0
    public void AddSkill(EUnitKey heroKey, ESkillKey skillKey)
    {
        List <ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);

        if (heroSkills.Count >= _maxSkillsAmount)
        {
            return;
        }
        if (heroSkills.IndexOf(skillKey) != -1)
        {
            return;
        }
        heroSkills.Add(skillKey);
    }
Example #21
0
 public BaseHero GetHero(EUnitKey heroKey)
 {
     if (_heroes != null)
     {
         for (int i = 0; i < _heroes.Length; i++)
         {
             if (_heroes[i].Data.Key == heroKey)
             {
                 return(_heroes[i]);
             }
         }
     }
     return(null);
 }
Example #22
0
    public void SetSkillIndex(EUnitKey heroKey, ESkillKey skillKey, int index)
    {
        List <ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);

        if (index < 0 || index >= heroSkills.Count)
        {
            return;
        }
        if (heroSkills.IndexOf(skillKey) != -1 && heroSkills.IndexOf(skillKey) != index)
        {
            heroSkills.Remove(skillKey);
            heroSkills.Insert(index, skillKey);
        }
    }
    public void Clear()
    {
        if (_unitBG.sprite != null)
        {
            _unitBG.sprite = null;
            UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitBGIconResourcePath(_unitKey));
        }
        if (_unitFG.sprite != null)
        {
            _unitFG.sprite = null;
            UIResourcesManager.Instance.FreeResource(GameConstants.Paths.GetUnitIconResourcePath(_unitKey));
        }

        _unitKey = EUnitKey.Idle;
    }
	public void Setup(EUnitKey unitKey) {
		_unitKey = unitKey;

		Sprite enemyIconBGResource = UIResourcesManager.Instance.GetResource<Sprite>(GameConstants.Paths.GetUnitBGIconResourcePath(unitKey));
		if (enemyIconBGResource != null) {
			_unitBG.sprite = enemyIconBGResource;
			_unitBG.enabled = true;
		} else {
			_unitBG.enabled = false;
		}
		Sprite enemyIconFGResource = UIResourcesManager.Instance.GetResource<Sprite>(GameConstants.Paths.GetUnitIconResourcePath(unitKey));
		if (enemyIconFGResource != null) {
			_unitFG.sprite = enemyIconFGResource;
			_unitFG.enabled = true;
		} else {
			_unitFG.enabled = false;
		}
	}
    private void SetupEnemies(MissionData md)
    {
        float enemyImageWidth = _iconEnemy.UnitBG.transform.GetComponent <RectTransform>().rect.width;

        List <EUnitKey> unitKeys = new List <EUnitKey>();
        MissionMapData  mmd      = null;

        for (int i = 0; i < md.MapsCount; i++)
        {
            mmd = md.GetMap(i);
            for (int j = 0; j < mmd.Units.Length; j++)
            {
                if (unitKeys.IndexOf(mmd.Units[j]) == -1)
                {
                    unitKeys.Add(mmd.Units[j]);
                }
            }
        }
        EUnitKey   firstEnemy = unitKeys[0];
        UIHeroCard enemyCard  = _enemyCard.GetComponent <UIHeroCard>();

        enemyCard.UnitKey = firstEnemy;

        //_enemies = unitKeys.ToArray();
        //_enemyIcons = new UIBattlePreviewUnitInfo[_enemies.Length];
        //_enemyIcons[0] = _iconEnemy;
        //for (int i = 0; i < _enemies.Length; i++)
        //{
        //    if (i > 0)
        //    {
        //        _enemyIcons[i] = (GameObject.Instantiate(_iconEnemy.gameObject) as GameObject).GetComponent<UIBattlePreviewUnitInfo>();
        //        _enemyIcons[i].transform.SetParent(_iconEnemy.transform.parent, false);
        //        _enemyIcons[i].UnitBG.rectTransform.anchoredPosition = _iconEnemy.UnitBG.rectTransform.anchoredPosition + new Vector2(i * (enemyImageWidth + _offsetImageEnemy), 0f);
        //    }
        //    _enemyIcons[i].Setup(_enemies[i]);
        //}
    }
Example #26
0
 public void Setup(EUnitKey unitkey, Sprite sprIcon)
 {
     _imgUnitIcon.sprite = sprIcon;
     _unitKey            = unitkey;
     UpdateUnitInfo();
 }
Example #27
0
 public bool IsHero(EUnitKey unitKey)
 {
     return((int)unitKey > 0 && (int)unitKey < 1000000);
 }
Example #28
0
 public UnitDamageInfo(EUnitKey attacker, EUnitKey target, int damageAmount)
 {
     _attacker     = attacker;
     _target       = target;
     _damageAmount = damageAmount;
 }
	public void  RemoveSkill(EUnitKey heroKey, ESkillKey skillKey) {
		List<ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);
		heroSkills.Remove(skillKey);
	}
Example #30
0
 public bool HaveHero(EUnitKey heroKey)
 {
     return(GetHero(heroKey) != null);
 }
Example #31
0
 public void AddSkill(EUnitKey heroKey, ESkillKey skillKey, int index)
 {
     AddSkill(heroKey, skillKey);
     SetSkillIndex(heroKey, skillKey, index);
 }
Example #32
0
	public void SetSoldierLevel(EUnitKey unitKey, int level) {
		for (int i = GetSoldierUpgradesInfo(unitKey).Level; i < level; i++) {
			GetSoldierUpgradesInfo(unitKey).LevelUp();
		}
	}
Example #33
0
 public void SoldierLevelUp(EUnitKey unitKey)
 {
     GetSoldierUpgradesInfo(unitKey).LevelUp();
 }
Example #34
0
    public void  RemoveSkill(EUnitKey heroKey, ESkillKey skillKey)
    {
        List <ESkillKey> heroSkills = GetHeroSkillsInternal(heroKey);

        heroSkills.Remove(skillKey);
    }
Example #35
0
    }                                           //TODO: dispatch level up event

    public SoldierUpgradesInfo(EUnitKey unitKey)
    {
        UnitKey = unitKey;
        Level   = 1;
    }
		public static string GetUnitBGIconResourcePath(EUnitKey unitKey) {
			return GetUnitBGIconResourcePath(UnitsConfig.Instance.GetSoldierData(unitKey).IconName);
		}
	public void AddSkill(EUnitKey heroKey, ESkillKey skillKey, int index) {
		AddSkill(heroKey, skillKey);
		SetSkillIndex(heroKey, skillKey, index);
	}
Example #38
0
	public SoldierUpgradesInfo GetSoldierUpgradesInfo(EUnitKey unitKey) {
		if (!_unitUpgrades.ContainsKey(unitKey)) {
			_unitUpgrades.Add(unitKey, new SoldierUpgradesInfo(unitKey));
		}
		return _unitUpgrades[unitKey];
	}
Example #39
0
 public UnitSlot(UnitPlace place, EUnitKey unit)
 {
     _place = place;
     _unit  = unit;
 }
Example #40
0
	public void SoldierLevelUp(EUnitKey unitKey) {
		GetSoldierUpgradesInfo(unitKey).LevelUp();
	}
Example #41
0
 public static string GetUnitIconResourcePath(EUnitKey unitKey)
 {
     return(GetUnitIconResourcePath(UnitsConfig.Instance.GetSoldierData(unitKey).IconName));
 }
	public MissionMapData(EUnitKey[] units, string mapBackgroundPath) {
		_units = units;
		_mapBackgroundPath = mapBackgroundPath;
	}
	public ListRO<ESkillKey> GetHeroSkills(EUnitKey heroKey) {
		return new ListRO<ESkillKey>(GetHeroSkillsInternal(heroKey));
	}
	public int Level { get; private set; }	//TODO: dispatch level up event

	public SoldierUpgradesInfo(EUnitKey unitKey) {
		UnitKey = unitKey;
		Level = 1;
	}
	private void OnBtnPlayClick() {
		List<BaseSoldier> soldiers = new List<BaseSoldier>();
		for (int i = 0; i < _hiredSoldiers.Length; i++) {
			if (_hiredSoldiers[i] >= 0) {
				soldiers.Add(new BaseSoldier(_availableSoldiers[_hiredSoldiers[i]], Global.Instance.Player.City.GetSoldierUpgradesInfo(_availableSoldiers[_hiredSoldiers[i]].Key).Level));
			}
		}
		Global.Instance.CurrentMission.SelectedSoldiers = new ArrayRO<BaseSoldier>(soldiers.ToArray());

		//setup random units and map
		EUnitKey[] availableUnits = new EUnitKey[] { EUnitKey.Scout, EUnitKey.Trooper, EUnitKey.Jawa_1 };
		string[] availableMaps = new string[] { "battle1_forest_1", "battle1_forest_2" };

		EUnitKey[] units = new EUnitKey[Random.Range(1, 6)];
		units[0] = EUnitKey.Hero_Sniper;
		for (int i = 1; i < units.Length; i++) {
			units[i] = availableUnits[Random.Range(0, availableUnits.Length)];
		}

		MissionMapData mmd = new MissionMapData(units, availableMaps[Random.Range(0, availableMaps.Length)]);
		MissionData md = new MissionData(EMissionKey.None, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, new MissionMapData[] { mmd });
		FightManager.Setup(EFightMode.PvP, md);

		LoadingScreen.Instance.Show();
		LoadingScreen.Instance.SetProgress(0f);
		Application.LoadLevel("Fight");
	}
Example #46
0
    private void LoadItemsResources(Dictionary <EItemKey, GameObject[]> resourcesDic, EUnitKey unitKey, UnitModelView unitModelView, EItemKey weaponRKey, EItemKey weaponLKey, EItemKey armorKey)
    {
        if (unitModelView != null)
        {
            GameObject rhWeaponResource  = null;
            GameObject lhWeaponResource  = null;
            GameObject headArmorResource = null;
            GameObject bodyArmorResource = null;

            unitModelView.SetWeaponType(weaponRKey, weaponLKey);

            //right hand weapon
            if (!resourcesDic.ContainsKey(weaponRKey))
            {
                GameObject[] weaponResources = new GameObject[1];
                weaponResources[0] = Resources.Load(string.Format("{0}/{1}", GameConstants.Paths.ITEM_RESOURCES, GetItemResourcePath(weaponRKey))) as GameObject;
                resourcesDic.Add(weaponRKey, weaponResources);

                rhWeaponResource = weaponResources[0];
            }
            else if (weaponRKey != EItemKey.None)
            {
                rhWeaponResource = resourcesDic[weaponRKey][0];
            }

            //left hand weapon
            if (!resourcesDic.ContainsKey(weaponLKey))
            {
                GameObject[] weaponResources = new GameObject[1];
                weaponResources[0] = Resources.Load(string.Format("{0}/{1}", GameConstants.Paths.ITEM_RESOURCES, GetItemResourcePath(weaponLKey))) as GameObject;
                resourcesDic.Add(weaponLKey, weaponResources);

                lhWeaponResource = weaponResources[0];
            }
            else if (weaponLKey != EItemKey.None)
            {
                lhWeaponResource = resourcesDic[weaponLKey][0];
            }

            //armor
            if (armorKey == EItemKey.None)
            {
                //Debug.LogWarning(string.Format("No armor set for {0} unit", unitKey));
            }
            else if (!resourcesDic.ContainsKey(armorKey))
            {
                string armorResourcePath = GetItemResourcePath(armorKey);

                GameObject[] armorResources = new GameObject[2];
                armorResources[0] = Resources.Load(string.Format("{0}/{1}_head", GameConstants.Paths.ITEM_RESOURCES, armorResourcePath)) as GameObject;
                armorResources[1] = Resources.Load(string.Format("{0}/{1}_body", GameConstants.Paths.ITEM_RESOURCES, armorResourcePath)) as GameObject;
                resourcesDic.Add(armorKey, armorResources);

                headArmorResource = armorResources[0];
                bodyArmorResource = armorResources[1];
            }
            else
            {
                headArmorResource = resourcesDic[armorKey][0];
                bodyArmorResource = resourcesDic[armorKey][1];
            }

            unitModelView.SetupGraphics(rhWeaponResource, lhWeaponResource, headArmorResource, bodyArmorResource);
        }
    }
Example #47
0
 public UnitSlot(UnitPlace place, EUnitKey unit)
 {
     _place = place;
     _unit = unit;
 }
Example #48
0
 public ListRO <ESkillKey> GetHeroSkills(EUnitKey heroKey)
 {
     return(new ListRO <ESkillKey>(GetHeroSkillsInternal(heroKey)));
 }
	public void Setup(EUnitKey unitkey, Sprite sprIcon) {
		_imgUnitIcon.sprite = sprIcon;
		_unitKey = unitkey;
		UpdateUnitInfo();
	}
Example #50
0
		public UnitDamageInfo(EUnitKey attacker, EUnitKey target, int damageAmount) {
			_attacker = attacker;
			_target = target;
			_damageAmount = damageAmount;
		}
	public bool HaveHero(EUnitKey heroKey) {
		return GetHero(heroKey) != null;
	}