public float GetUnitPosition(BaseUnit unit) { return unitPositions[unit]; }
public void AddUnit(BaseUnit unit, float initialPosition) { unitPositions.Add(unit, initialPosition); }
public void ChangeUnitPosition(BaseUnit unit, float newPosition) { unitPositions[unit] = newPosition; }
public void RemoveUnit(BaseUnit baseUnit) { unitPositions.Remove(baseUnit); }
public void AddUnit(BaseUnit unit) { var initialPosition = unit.GetInitialPosition(); AddUnit(unit, initialPosition); }
public BaseUnit[] GetUnitsWithinCircularRange(float radius, Vector3 position) { BaseUnit[] units; int numCollidersInRange = Physics.OverlapSphereNonAlloc(position, radius, collidersForPhysicsTest); var testVar = collidersForPhysicsTest; DebugExtension.DebugWireSphere(position, Color.red, radius, Time.deltaTime, true); if (numCollidersInRange > 0) FilterAllUnits(ref collidersForPhysicsTest, out units, numCollidersInRange, this); else units = new BaseUnit[0]; return units; }
public static void FilterAllUnits(ref Collider[] colliders, out BaseUnit[] units, int colliderCount = -1, BaseUnit unitToIgnore = null) { UnitBuffer.Clear(); if (colliderCount == -1) { colliderCount = colliders.Length; } for (int i = 0; i < colliderCount; i++) { if (colliders[i].CompareTag(UNIT_COLLIDER_TAG)) { var unit = colliders[i].GetComponent<UnitCollider>().unit; if (unit != unitToIgnore) UnitBuffer.Add(unit); } } units = UnitBuffer.ToArray(); }
public void ReceiveAttack(BaseUnit attacker) { _currentHealth -= 50; if (IsAlive() == false) { Log.Steb("Blergh unit died"); OnDeath(); } }
public ResourceContainer ReceiveLootStrike(BaseUnit attacker) { var takenLoot = new ResourceContainer(); Log.Steb("Getting a lootstrike " + _buildInstructions.unitName); foreach (ResourceType lootType in Enum.GetValues(typeof(ResourceType))) { var takenAmount = resourceContainer.Subtract(lootType, 30d); Log.Steb("Took " + takenAmount + " of type " + lootType.ToString()); takenLoot.Add(lootType, takenAmount); } return takenLoot; }
public bool IsInRange(BaseUnit targetUnit) { if (Mathf.Abs(targetUnit.GetUnitPositionX() - GetUnitPositionX()) < 3f) return true; return false; }
public void AttackUnit(BaseUnit target) { if (target.IsAlive()) target.ReceiveAttack(this); else resourceContainer += target.ReceiveLootStrike(this); _timeSincePreviousAttack = 0f; }
public bool CanTarget(BaseUnit potentialTarget) { return potentialTarget.gameObject != null && (potentialTarget.IsAlive() || potentialTarget.ContainsLoot()); }
public bool ShouldTarget(BaseUnit potentialTarget) { if (faction == potentialTarget.faction) return false; // TODO calculate faction logic here return true; }
// Update is called once per frame private void Update() { var dt = Time.deltaTime; _timeSincePreviousAttack += dt; _transform.localPosition = _currentPosition; Globals.playfield.unitPositions[this] = _currentPosition.x; _behaviorContext.timeLeft = dt; behaviourTree.Update(_behaviorContext); if (true) return; switch (state) { case UnitStates.Moving: _currentTarget = GetNearTarget(); if (_currentTarget != null) { state = UnitStates.Targetting; goto case UnitStates.Targetting; } UpdateMovement(dt); break; case UnitStates.Targetting: if (CanTarget(_currentTarget) == false && ShouldTarget(_currentTarget)) { _currentTarget = null; state = UnitStates.Moving; goto default; } if (IsInRange(_currentTarget)) { state = UnitStates.Attacking; goto case UnitStates.Attacking; } UpdateTargetting(dt); break; case UnitStates.Attacking: if (CanTarget(_currentTarget) == false || IsInRange(_currentTarget) == false) { _currentTarget = null; state = UnitStates.Moving; goto default; } if (IsReadyForAttack()) { DebugExtension.DebugArrow(_currentPosition, new Vector3(_currentTarget._currentPosition.x - _currentPosition.x, 0f), Color.red, 1f, false); AttackUnit(_currentTarget); } UpdateAttack(dt); break; case UnitStates.Dead: break; default: break; } }
public CombatData(BaseUnit attacker, BaseUnit[] targets) { this.attacker = attacker; this.targets = targets; }
public CombatData(BaseUnit attacker, BaseUnit target) { this.attacker = attacker; this.targets = new BaseUnit[] { target }; }