public Unit SetParams(int unitType, string name) { _myType = unitType; _myID = UnitCount; UnitsStats theStats = UnitsStats.CreateUnitsStats(); _myName = name; if (_myName == "") { _myName = theStats.AllStats[_myType + 1][(int)StatsOrder.UnitName]; } Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.MaxHP], out _maxHP); _currentHP = _maxHP; _XP = 0; Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.MinDmg], out _minDmg); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.MaxDmg], out _maxDmg); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.HitsPerTurn], out _hitsPerTurn); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.Initiative], out _initiative); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.Block], out _block); _currentBlock = _block; float.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.Accuracy], out _accuracy); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.UnitCombat], out _unitRange); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.Regen], out _regen); Int32.TryParse(theStats.AllStats[_myType + 1][(int)StatsOrder.Level], out _level); _lvlUps = new int[(int)LevelUpOptions.LENGTH]; _lvlUpChoice = new int[2] { -1, -1 }; return(this); }
private void LevelUpUnit(int whichSkill) { UnitsStats theStats = UnitsStats.CreateUnitsStats(); switch (whichSkill) { case 0: case 1: case 2: _maxHP = _maxHP + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; _currentHP = _currentHP + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new max hp: " + _maxHP); break; case 3: _minDmg = _minDmg + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; _maxDmg = _maxDmg + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new min-max dmg: " + _minDmg + "-" + _maxDmg); break; case 4: case 5: _initiative = _initiative + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new initiative: " + _initiative); break; case 6: _block = _block + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new block: " + _block); break; case 7: _regen = _regen + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new regen: " + _regen); break; case 8: _hitsPerTurn = _hitsPerTurn + theStats.AllLvlUps[whichSkill * 4 + 0, _myType]; print("LEVEL UP - new APT: " + _hitsPerTurn); break; default: break; } _lvlUps[whichSkill]++; _level++; }
void Start() { UnitsStats setUpStats = UnitsStats.CreateUnitsStats(); Army attackingArmy = Army.CreateMyArmy(); attackingArmy.Start(); attackingArmy.addUnitToArmy(Unit.CreateMyUnit().SetParams((int)UnitType.Swordsman, "")); attackingArmy.addUnitToArmy(Unit.CreateMyUnit().SetParams((int)UnitType.Swordsman, "")); Army defendingArmy = Army.CreateMyArmy(); defendingArmy.Start(); defendingArmy.addUnitToArmy(Unit.CreateMyUnit().SetParams((int)UnitType.Swordsman, "")); defendingArmy.addUnitToArmy(Unit.CreateMyUnit().SetParams((int)UnitType.Archer, "")); _cm = CombatManager.CreateMyCM(attackingArmy, defendingArmy); _cm.ConductBattle(); GenerateMap(); }
/* Let's randomly select 2 options for level up for the player to choose from */ public void LevelUpCheck() { UnitsStats theStats = UnitsStats.CreateUnitsStats(); if (_level == 15 || (_lvlUpChoice[0] != -1 || _lvlUpChoice[1] != -1)) { return; } if (_XP >= theStats.XPTable[_level]) { int[] lvlOptions = new int[(int)LevelUpOptions.LENGTH]; int totalOptions = 0; int i; for (i = 0; i < (int)LevelUpOptions.LENGTH; i++) { if (theStats.AllLvlUps[i * 4 + 2, _myType] <= _level && (theStats.AllLvlUps[i * 4 + 3, _myType] > _level || theStats.AllLvlUps[i * 4 + 3, _myType] == 0)) { lvlOptions[i] = Math.Max(theStats.AllLvlUps[i * 4 + 1, _myType] - _lvlUps[i], 0); totalOptions = totalOptions + lvlOptions[i]; } } int randomLvlOption = UnityEngine.Random.Range(1, totalOptions + 1); int runningTotal = 0; for (i = 0; i < (int)LevelUpOptions.LENGTH; i++) { runningTotal = runningTotal + lvlOptions[i]; if (randomLvlOption <= runningTotal) { break; } } totalOptions = totalOptions - lvlOptions[i]; lvlOptions[i] = 0; int j = i; int counter = 0; while (j == i && counter < 100) { randomLvlOption = UnityEngine.Random.Range(1, totalOptions + 1); runningTotal = 0; for (j = 0; j < (int)LevelUpOptions.LENGTH; j++) { runningTotal = runningTotal + lvlOptions[j]; if (randomLvlOption <= runningTotal) { break; } } } if (counter == 100) { j = -1; } /*print("Level Up Randomly Chosen between: " + i + " and " + j);*/ int randomLvl = UnityEngine.Random.Range(1, 3); if (randomLvl == 1) { LevelUpUnit(i); } else { LevelUpUnit(j); } } }