void UpdateAttackBehavior() { if (actionEffect == null) { return; } UnitStatistic statisic = GetStatisticsInfo(); if (Time.frameCount % 15 == 0) { if (behaviorType == BehaviorType.Aggressive) { AttackNearEnemies(transform.position, statisic.agrRange, -1, randomRange: 8.0f); } } if (target != null && interactType == InteractigType.None) { Vector3 offset = new Vector3(0, 0.5f, 0); RaycastHit hit; if (Physics.Raycast(actionEffect.transform.position + offset, (target.transform.position + offset - (actionEffect.transform.position + offset)).normalized, out hit, statisic.rangeAttack)) { if (hit.transform.gameObject.GetHashCode() == target.GetHashCode()) { interactType = InteractigType.Attacking; Attack(target); } } else { ActionIsDone(); } } }
public void LoadUnitTypes(string downloadedData) { using (StringReader reader = new StringReader(downloadedData)) { string line; while ((line = reader.ReadLine()) != null) { string[] fields = line.Split(','); if (fields[0].Equals("Name")) { continue; } UnitStatistic stats = new UnitStatistic(); stats.unitName = fields[0].Trim(' '); stats.unitType = fields[1].Trim(' '); stats.unitVariant = fields[2].Trim(' '); stats.armor = float.Parse(fields[3].Trim(' ')); stats.energy = float.Parse(fields[4].Trim(' ')); stats.visualRange = float.Parse(fields[5].Trim(' ')); stats.meleeRange = float.Parse(fields[6].Trim(' ')); stats.chargeRange = float.Parse(fields[7].Trim(' ')); string[] missileRangeParts = fields[8].Trim(' ').Split('/'); stats.missileRange = new Vector2(float.Parse(missileRangeParts[0]), float.Parse(missileRangeParts[1])); stats.missileType = fields[9].Trim(' '); stats.disciplined = bool.Parse(fields[10].Trim(' ')); stats.holdTheLine = bool.Parse(fields[11].Trim(' ')); stats.worksTogether = bool.Parse(fields[12].Trim(' ')); stats.reachOut = bool.Parse(fields[13].Trim(' ')); unitStats.Add(stats.unitName, stats); Debug.Log("Adding " + stats.unitName); } } }
public void ApplyStatisticOffset(UnitStatistic statistic, ulong offset) { if (!UnitStatisticChanges.ContainsKey(statistic)) { UnitStatisticChanges.Add(statistic, offset); return; } UnitStatisticChanges[statistic] += offset; }
public ulong GetStatistic(UnitStatistic statistic) { // If the statistic isn't set then assume it is zero if (!_statistics.ContainsKey(statistic)) { return(0); } // Otherwise just return the value return(_statistics[statistic]); }
public ulong IncrementStatistic(UnitStatistic statistic, ulong value) { if (!Statistics.ContainsKey(statistic)) { _statistics.Add(statistic, value); return(value); } var newValue = _statistics[statistic] + value; _statistics[statistic] = newValue; return(newValue); }
public ulong SetStatistic(UnitStatistic statistic, ulong value) { if (!Statistics.ContainsKey(statistic)) { _statistics.Add(statistic, value); } else { _statistics[statistic] = value; } return(value); }
public GameObject CreateUnit(string unitName, Vector3 pos, Quaternion rot) { if (!unitStats.ContainsKey(unitName)) { Debug.Log("There is no entry for " + unitName); return(null); } UnitStatistic stats = unitStats[unitName]; GameObject prefab = gameManager.unitInventory.GetUnitPrefab(stats.unitType); GameObject newUnit = GameObject.Instantiate(prefab, pos, rot); Renderer[] renderers = newUnit.GetComponentsInChildren <Renderer>(); Material variantMat = gameManager.unitInventory.GetUnitVariant(stats.unitType, stats.unitVariant); foreach (Renderer item in renderers) { item.material = variantMat; } newUnit.GetComponent <UnitControl>().Init(stats); return(newUnit); }
public ulong DecrementStatistic(UnitStatistic statistic, ulong value) { // Check if we have a value for this statistic already. If we don't we can't decrement it so just assign it to zero and return it if (!Statistics.ContainsKey(statistic)) { _statistics.Add(statistic, 0); return(0); } // Underflow check if (value > _statistics[statistic]) { _statistics[statistic] = 0; return(0); } // Update value of the statistic but subtracting it from the given value var newValue = _statistics[statistic] - value; _statistics[statistic] = newValue; return(newValue); }