Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        bool ITrapElement.Trigger()
        {
            if (GetComponent <ConstructionValidator>() != null)
            {
                return(false);
            }

            var colliders = new List <Collider2D>();

            _boxCollider.GetContacts(new ContactFilter2D
            {
                useTriggers = true,
            }, colliders);

            var constructionRequest = new ConstructionSpaceRequest(null, colliders);

            foreach (var collider in colliders)
            {
                collider.gameObject.SendMessage(ConstructionSpace.OnConstructionValidationMethodName, constructionRequest, SendMessageOptions.DontRequireReceiver);
                if (!constructionRequest.accepted)
                {
                    return(false);
                }
            }

            Instantiate(_wallPrefab, transform.position, transform.rotation).GetComponent <Construct>().supplyCost = GetComponent <Construct>().supplyCost;
            Destroy(gameObject);
            return(true);
        }
Ejemplo n.º 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 private void OnConstructionSpaceRequested(ConstructionSpaceRequest request)
 {
     if (request.constructionSpace == null || request.constructionSpace.transform.position == transform.position)
     {
         request.Decline();
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 private void OnConstructionValidation(ConstructionSpaceRequest request)
 {
     if (request.contactingColliders.Contains(_capsuleCollider))
     {
         request.Decline();
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="request"></param>
 private void OnConstructionSpaceRequested(ConstructionSpaceRequest request)
 {
     if (!_acceptConstruction)
     {
         request.Decline();
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        public override void Update()
        {
            base.Update();

            if (_elapsedSinceBuildDeniedSound > 0f)
            {
                _elapsedSinceBuildDeniedSound -= GameplayStatics.gameFixedDeltaTime;
            }

            _cooldownBeforeAutoChange = Mathf.Max(0.0f, _cooldownBeforeAutoChange - GameplayStatics.gameDeltaTime);

            var characterPosition = character.transform.position;

            float x = (GameConstants.TileSize * (Mathf.Ceil(characterPosition.x / GameConstants.TileSize) - 1.0f)) + GameConstants.HalfTileSize;
            float y = (GameConstants.TileSize * (Mathf.Ceil((characterPosition.y - GameConstants.HalfTileSize) / GameConstants.TileSize) - 1.0f)) + GameConstants.HalfTileSize;

            _currentConstructionSpace.transform.position = new Vector3(x, y, 0.0f);

            var collisions = new List <Collider2D>();

            _currentConstructionSpace.boxCollider.GetContacts(new ContactFilter2D
            {
                useTriggers = true,
            }, collisions);

            if (character.constructs.Length == 0)
            {
                return;
            }

            var constructionRequest = new ConstructionSpaceRequest(_currentConstructionSpace, collisions);
            var constructItem       = character.constructs[_currentConstructIndex];

            var accepted = character.resources.supply >= constructItem.supplyCost;

            if (accepted)
            {
                foreach (var collision in collisions)
                {
                    collision.gameObject.SendMessage(ConstructionSpace.OnConstructionSpaceRequestedMethodName, constructionRequest, SendMessageOptions.DontRequireReceiver);
                    if (!constructionRequest.accepted)
                    {
                        break;
                    }
                }
                accepted = constructionRequest.accepted;
            }

            _currentConstructionSpace.canBePlaced = accepted;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="collision"></param>
        private void OnTriggerExit2D(Collider2D collision)
        {
            var constructionSpace = GetComponentInParent <ConstructionSpace>();

            if (constructionSpace == null || !constructionSpace.isPlaced)
            {
                return;
            }

            var contactingColliders = new List <Collider2D>();

            foreach (var contactingCollider in _colliders)
            {
                var currentContactingColliders = new List <Collider2D>();
                contactingCollider.GetContacts(new ContactFilter2D
                {
                    useTriggers = true,
                }, currentContactingColliders);
                contactingColliders.AddRange(currentContactingColliders);
            }

            var constructionRequest = new ConstructionSpaceRequest(constructionSpace, contactingColliders);

            foreach (var contactingCollider in contactingColliders)
            {
                contactingCollider.gameObject.SendMessage(ConstructionSpace.OnConstructionValidationMethodName, constructionRequest, SendMessageOptions.DontRequireReceiver);
                if (!constructionRequest.accepted)
                {
                    return;
                }
            }

            transform.SetParent(constructionSpace.transform.parent);

            var spriteRenderers = new List <SpriteRenderer>();

            spriteRenderers.Add(GetComponent <SpriteRenderer>());
            spriteRenderers.AddRange(GetComponentsInChildren <SpriteRenderer>());

            foreach (var spriteRenderer in spriteRenderers)
            {
                spriteRenderer.color = Color.white;
            }

            foreach (var contactingCollider in _colliders)
            {
                contactingCollider.isTrigger = false;
            }

            var objectRenderer = GetComponent <TileObjectRenderer>();

            if (objectRenderer != null)
            {
                objectRenderer.isChild  = false;
                objectRenderer.additive = 0;
            }

            Destroy(constructionSpace.gameObject);
            Destroy(this);

            var bulletReaction = GetComponent <BulletReaction>();

            if (bulletReaction != null)
            {
                bulletReaction.acceptBullets = _acceptBullets;
            }

            SendMessage(Construct.OnConstructedMethodName, construct, SendMessageOptions.DontRequireReceiver);
        }