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

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

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

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


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

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