Example #1
0
		public float GetUnitPosition(BaseUnit unit)
		{
			return unitPositions[unit];
		}
Example #2
0
		public void AddUnit(BaseUnit unit, float initialPosition)
		{
			unitPositions.Add(unit, initialPosition);
		}
Example #3
0
		public void ChangeUnitPosition(BaseUnit unit, float newPosition)
		{
			unitPositions[unit] = newPosition;
		}
Example #4
0
		public void RemoveUnit(BaseUnit baseUnit)
		{
			unitPositions.Remove(baseUnit);
		}
Example #5
0
		public void AddUnit(BaseUnit unit)
		{
			var initialPosition = unit.GetInitialPosition();

			AddUnit(unit, initialPosition);
		}
Example #6
0
		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;
		}
Example #7
0
		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();
		}
Example #8
0
		public void ReceiveAttack(BaseUnit attacker)
		{
			_currentHealth -= 50;

			if (IsAlive() == false)
			{
				Log.Steb("Blergh unit died");
				OnDeath();
			}
		}
Example #9
0
		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;
		}
Example #10
0
		public bool IsInRange(BaseUnit targetUnit)
		{
			if (Mathf.Abs(targetUnit.GetUnitPositionX() - GetUnitPositionX()) < 3f)
				return true;

			return false;
		}
Example #11
0
		public void AttackUnit(BaseUnit target)
		{
			if (target.IsAlive())
				target.ReceiveAttack(this);
			else
				resourceContainer += target.ReceiveLootStrike(this);


			_timeSincePreviousAttack = 0f;
		}
Example #12
0
		public bool CanTarget(BaseUnit potentialTarget)
		{
			return potentialTarget.gameObject != null && (potentialTarget.IsAlive() || potentialTarget.ContainsLoot());
		}
Example #13
0
		public bool ShouldTarget(BaseUnit potentialTarget)
		{
			if (faction == potentialTarget.faction)
				return false;

			// TODO calculate faction logic here
			return true;
		}
Example #14
0
		// 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;
			}
		}
Example #15
0
		public CombatData(BaseUnit attacker, BaseUnit[] targets)
		{
			this.attacker = attacker;
			this.targets = targets;
		}
Example #16
0
		public CombatData(BaseUnit attacker, BaseUnit target)
		{
			this.attacker = attacker;
			this.targets = new BaseUnit[] { target };
		}