Exemplo n.º 1
0
        public static void AddComponents(EntityFactory factory)
        {
            // Apply these one after the other.
            // This will only initialize the inject variables of the behavior / component.
            // So, apply will be autogenerated for the different behaviors based on their injects.
            // Or do it even smarter?
            // So, since I'd like to make components structs in the future and store them somewhere
            // central (optionally), these can actually reference a global storage for them.

            // So this just adds the behavior
            Acting.AddTo(factory, null, Algos.SimpleAlgo, Order.Player);
            Moving.AddTo(factory);
            Digging.AddTo(factory);
            Pushable.AddTo(factory);
            Attacking.AddTo(factory, Attacking.GetTargetProviderFromInventory, Layers.REAL, Faction.Enemy | Faction.Environment);
            Attackable.AddTo(factory, Attackness.ALWAYS);
            Damageable.AddTo(factory, new Health(5));
            Displaceable.AddTo(factory, Layers.BLOCK);
            Ticking.AddTo(factory);

            FactionComponent.AddTo(factory, Faction.Player);
            Transform.AddTo(factory, Layers.REAL, TransformFlags.Default);
            Inventory.AddTo(factory);
            Inventory.AddInitTo(factory);

            // TODO: pass this an action
            Controllable.AddTo(factory,
                               // The default action is the AttackDigMove action.
                               Action.Compose(Attacking.Action, Digging.Action, Moving.Action));

            // TODO: rename the namespaces
            Stats.AddTo(factory, Registry.Global.Stats._map);
        }
    void UpdatePushableObjects()
    {
        if (closestPushable != null)
        {
            if (characterMovement.IsMoving() == false)
            {
                StopPushingClosestPushable();
            }

            return;
        }

        if (IsPushing() == false)
        {
            return;
        }

        closestPushable = FindClosestPushable();

        if (closestPushable == null)
        {
            return;
        }

        StartPushingClosestPushable();
    }
Exemplo n.º 3
0
    public bool TryPush(Vector2Int dir, float speed = Single.NaN)
    {
        Vector3Int from = Pushable.ServerPosition;

        if (!CanPushServer(from, dir, speed))
        {
            return(false);
        }

        bool       success = Pushable.Push(dir, speed);
        Vector3Int target  = from + dir.To3Int();

        if (success)
        {
            if (IsBeingPulled &&              //Break pull only if pushable will end up far enough
                (pushRequestQueue.Count > 0 || !PlayerScript.IsInReach(PulledBy.registerTile.WorldPositionServer, target)))
            {
                StopFollowing();
            }
            if (IsPullingSomethingServer &&              //Break pull only if pushable will end up far enough
                (pushRequestQueue.Count > 0 || !PlayerScript.IsInReach(PulledObjectServer.registerTile.WorldPositionServer, target)))
            {
                ReleaseControl();
            }
            isBeingPushed = true;
            pushTarget    = target;
            Logger.LogTraceFormat("{2}: Started push {0}->{1}", Category.PushPull, from, target, gameObject.name);
            this.RestartCoroutine(NoMoveSafeguard(from), ref revertIsBeingPushedHandle);
        }

        return(success);
    }
Exemplo n.º 4
0
    public bool TryPredictivePush(Vector3Int from, Vector2Int dir, float speed = Single.NaN)
    {
        if (isNotPushable || !CanPredictPush || Pushable == null || !isAllowedDir(dir))
        {
            return(false);
        }
        lastReliablePos = registerTile.WorldPositionClient;
        if (from != lastReliablePos)
        {
            return(false);
        }
        Vector3Int target = from + Vector3Int.RoundToInt(( Vector2 )dir);

        if (!MatrixManager.IsPassableAt(from, target, isServer: false) ||
            MatrixManager.IsNoGravityAt(target, isServer: false))               //not allowing predictive push into space
        {
            return(false);
        }

        bool success = Pushable.PredictivePush(target.To2Int(), speed);

        if (success)
        {
            pushPrediction       = PushState.InProgress;
            pushApproval         = ApprovalState.None;
            predictivePushTarget = target;
            Logger.LogTraceFormat("Started predictive push {0}->{1}", Category.PushPull, from, target);
        }

        return(success);
    }
Exemplo n.º 5
0
    public bool TryPush(Vector3Int from, Vector2Int dir, float speed = Single.NaN)
    {
        if (!CanPush(from, dir, speed))
        {
            return(false);
        }


        bool       success = Pushable.Push(dir, speed);
        Vector3Int target  = from + dir.To3Int();

        if (success)
        {
            if (IsBeingPulled &&              //Break pull only if pushable will end up far enough
                (pushRequestQueue.Count > 0 || !PlayerScript.IsInReach(PulledBy.registerTile.WorldPosition, target)))
            {
                StopFollowing();
            }
            if (IsPullingSomethingServer &&              //Break pull only if pushable will end up far enough
                (pushRequestQueue.Count > 0 || !PlayerScript.IsInReach(PulledObjectServer.registerTile.WorldPosition, target)))
            {
                ReleaseControl();
            }
            isPushing  = true;
            pushTarget = target;
            Logger.LogTraceFormat("Started push {0}->{1}", Category.PushPull, from, target);
        }

        return(success);
    }
Exemplo n.º 6
0
    //Find the closest object that which we may push (similar to closest interactable)
    private Pushable FindClosestPushable()
    {
        Collider2D[] closeColliders = m_InteractionModel.GetCloseColliders();

        Pushable closestPushable        = null;
        float    angleToClosestPushable = Mathf.Infinity;

        for (int i = 0; i < closeColliders.Length; ++i)
        {
            Pushable colliderPushable = closeColliders[i].GetComponent <Pushable>();

            if (colliderPushable == null)
            {
                continue;
            }

            Vector3 directionToPushable = closeColliders[i].transform.position - transform.position;

            float angleToPushable = Vector3.Angle(m_MovementModel.GetFacingDirection(), directionToPushable);

            Debug.Log(i + ": " + angleToPushable);
            if (angleToPushable < 40)
            {
                if (angleToPushable < angleToClosestPushable)
                {
                    closestPushable        = colliderPushable;
                    angleToClosestPushable = angleToPushable;
                }
            }
        }

        return(closestPushable);
    }
Exemplo n.º 7
0
    public IEnumerator CheckForBlockOnTop()
    {
        yield return(new WaitForSeconds(2.5f));

        if (blocks.Length == 0)
        {
            blocks = GameObject.FindGameObjectsWithTag("Pushable");
        }

        if (!set)
        {
            foreach (var b in blocks)
            {
                Pushable p = b.GetComponent <Pushable>();
                if (!p.grabbed && !p.pushed && Vector2.Distance(b.transform.position, this.transform.position) < 0.25f)
                {
                    b.transform.position = this.transform.position;
                    set_block            = b;
                    set = true;
                }
            }
        }
        else if (Vector2.Distance(set_block.transform.position, this.transform.position) > 0.25f)
        {
            set       = false;
            set_block = null;
        }
        StartCoroutine(CheckForBlockOnTop());
    }
Exemplo n.º 8
0
    //Update the object being pushed
    private void UpdatePushableObjects()
    {
        if (m_ClosestPushable != null)
        {
            if (m_MovementModel.IsMoving() == false)
            {
                StopPushingClosestPushable();
            }

            return;
        }

        if (IsPushing() == false)
        {
            return;
        }

        m_ClosestPushable = FindClosestPushable();

        if (m_ClosestPushable == null)
        {
            return;
        }

        StartPushingClosestPushable();
    }
Exemplo n.º 9
0
    private bool TryFollow(Vector3Int from, Vector2Int dir, float speed = Single.NaN)
    {
        if (!IsBeingPulled || isNotPushable || isBeingPushed || Pushable == null)
        {
            return(false);
        }

        if (Mathf.Abs(dir.x) > 1 || Mathf.Abs(dir.y) > 1)
        {
            Logger.LogTrace("oops=" + dir, Category.PushPull);
            return(false);
        }

        Vector3Int target = from + Vector3Int.RoundToInt(( Vector2 )dir);

        if (!MatrixManager.IsPassableAt(from, target, isServer: true, includingPlayers: false))            //non-solid things can be pushed to player tile
        {
            return(false);
        }

        bool success = Pushable.Push(dir, speed, true);

        if (success)
        {
            pushTarget = target;
//			Logger.LogTraceFormat( "Following {0}->{1}", Category.PushPull, from, target );
        }

        return(success);
    }
Exemplo n.º 10
0
    void huboColision()
    {
        RaycastHit hit;
        Vector3    aux = new Vector3(x, y, z);

        if (!Physics.Raycast(transform.position, aux, out hit, 1) || hit.collider.isTrigger)
        {
            transform.Translate(aux);
            GameManager.instance.UpdatePasos();
        }


        else
        {
            hit.collider.GetComponent <Pushable>();

            Pushable pushable = hit.collider.GetComponent <Pushable>();
            if (pushable != null)
            {
                if (pushable.push(x, z))
                {
                    transform.Translate(aux);
                    GameManager.instance.UpdatePasos();
                }
            }
        }
    }
    void UpdatePushableObjects()
    {
        if( m_ClosestPushable != null )
        {
            if( m_MovementModel.IsMoving() == false )
            {
                StopPushingClosestPushable();
            }

            return;
        }

        if( IsPushing() == false )
        {
            return;
        }

        m_ClosestPushable = FindClosestPushable();

        if( m_ClosestPushable == null )
        {
            return;
        }

        StartPushingClosestPushable();
    }
Exemplo n.º 12
0
    // Use this for initialization
    void Start()
    {
        mNextShotTimeSeconds = Time.time + 5; // Wait 5 seconds before firing next shot

        // The droid will rise directly above its spawn location to a random height.
        Vector3 firstTargetLocation = new Vector3(transform.position.x, BASE_TARGET_LOCATION_HEIGHT + (Random.value * TARGET_LOCATION_HEIGHT_OFFSET), transform.position.z);

        SetTargetLocation(firstTargetLocation);

        mIsMovementActive = true;

        mPushable         = GetComponent <Pushable>();
        mPushable.Pushed += OnPushed;

        mLiftable         = GetComponent <Liftable>();
        mLiftable.Lifted += OnLifted;

        mLightningable              = GetComponent <Lightningable>();
        mLightningable.Lightninged += OnLightninged;

        mDestroyable            = GetComponent <Destroyable>();
        mDestroyable.Destroyed += Explode;

        mAudioSource      = GetComponent <AudioSource>();
        mAudioSource.clip = HoverLoopClip;
        mAudioSource.Play();
    }
Exemplo n.º 13
0
 // Start is called before the first frame update
 void Start()
 {
     pushable                = GetComponent <Pushable>();
     combatController        = FindObjectOfType <CombatController>();
     currentCell             = CurrentCell();
     currentCell.hasObstacle = true;
 }
Exemplo n.º 14
0
 void Awake()
 {
     baby     = GetComponentInChildren <Baby>();
     menuItem = GetComponentInChildren <Pushable>();
     SetSelected(false);
     priceText.text        = "" + Price;
     priceText_shadow.text = "" + Price;
 }
Exemplo n.º 15
0
 void Awake()
 {
     baby = GetComponentInChildren<Baby>();
     menuItem = GetComponentInChildren<Pushable>();
     SetSelected(false);
     priceText.text = "" + Price;
     priceText_shadow.text = "" + Price;
 }
Exemplo n.º 16
0
    private void Update()
    {
        Transform t = transform;

        Vector2 center = t.position + t.up * distance / 2f;

        Debug.DrawLine(t.position, t.position + (t.up * distance));
        Debug.DrawLine(center, center + (Vector2)(t.right * spread / 2f));
        Collider2D[] hitColliders = Physics2D.OverlapCapsuleAll(center, new Vector2(spread, distance), CapsuleDirection2D.Vertical, 0); //OverlapCircleAll(transform.position, targetingRadius);

        Vector2 dir = ((t.position + (t.up * distance)) - t.position).normalized;

        //Debug.Log("pos = " + t.position.ToString() + " up *dist = " + (t.up * distance).ToString() + " normalized dir = " + dir.ToString());

        int i = 0;

        while (i < hitColliders.Length)
        {
            //don't extinguish past wall
            bool           hitWall = false;
            RaycastHit2D[] hit     = Physics2D.LinecastAll(t.position, hitColliders[i].transform.position);
            for (int j = 0; j < hit.Length; j++)
            {
                if (hit[j].transform.tag == "Wall" || hit[j].transform.tag == "Debris")
                {
                    hitWall = true;
                    break;
                }
            }

            if (!hitWall)
            {
                if (hitColliders[i].tag == "Player")
                {
                    InteriorPlayer p = hitColliders[i].GetComponent <InteriorPlayer>();

                    float pDist = ((Vector2)hitColliders[i].transform.position - (Vector2)t.position).magnitude;
                    if (pDist < distance / 0.6f)
                    {
                        p.DropItem();
                    }
                    // TODO: Scale push with how close they're to the vent
                    p.PushInDir(dir, push);
                }
                else
                {
                    Pushable p = hitColliders[i].GetComponent <Pushable>();
                    if (p != null)
                    {
                        float pDist = ((Vector2)hitColliders[i].transform.position - (Vector2)t.position).magnitude;
                        // TODO: Scale push with how close they're to the vent
                        p.PushInDir(dir, push);
                    }
                }
            }
            i++;
        }
    }
Exemplo n.º 17
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        Pushable pushable = other.GetComponent <Pushable>();

        if (pushable != null)
        {
            currentPushables.Add(pushable);
        }
    }
Exemplo n.º 18
0
    void Start()
    {
        mIsMovementActive = true;

        mPushable         = GetComponent <Pushable>();
        mPushable.Pushed += OnPushed;

        mLightningable              = GetComponent <Lightningable>();
        mLightningable.Lightninged += OnLightninged;
    }
Exemplo n.º 19
0
        public Bouncing_Test()
        {
            InitScript.Init();

            entityFactory = new EntityFactory();
            Transform.AddTo(entityFactory, Layers.REAL, TransformFlags.Default);
            Stats.AddTo(entityFactory, Registry.Global.Stats._map);
            Displaceable.AddTo(entityFactory, Layers.BLOCK).DefaultPreset();
            Pushable.AddTo(entityFactory).DefaultPreset();
        }
Exemplo n.º 20
0
 private void OnCollisionEnter2D(Collision2D collision)
 {
     if (collision.gameObject.layer == LayerMask.NameToLayer("MoveableObject"))
     {
         if (xInput * (collision.transform.position.x - transform.position.x) > 0)
         {
             pushTGT = collision.gameObject.GetComponent <Pushable>();
         }
     }
 }
Exemplo n.º 21
0
    /**
     * Changes player state so that the player is no longer ready to pull an object (e.g. a Sokoban box).
     */
    public void DisablePulling()
    {
        _playerState = PlayerState.walking;
        Animator.SetBool(PullingState, false);
        // `Pushable` objects have a timeout before a player can push them.
        // Since a player is in constant contact with the `Pushable` during pulling, this timeout has likely run out by
        // now. Resetting the timeout when stopping to pull leads to a better experience:
        _pushableToPull?.ResetContactTimeout();

        _pushableToPull = null;
    }
    void StopPushingClosestPushable()
    {
        Collider2D closestCollider = m_ClosestPushable.GetComponent<Collider2D>();
        Physics2D.IgnoreCollision( m_Collider, closestCollider, false );

        m_ClosestPushable.transform.parent = m_ClosestPushableParent;
        m_ClosestPushable = null;

        m_MovementModel.SetFrozen( false, false, false );
        m_MovementModel.SetOverrideSpeedEnabled( false );
    }
Exemplo n.º 23
0
    private void OnTriggerExit2D(Collider2D other) // For when the player exits a trigger collider, follow the same procedure as the enter, and remove it from the list if it was a pushable
    {
        Pushable pushable = other.GetComponent <Pushable>();

        if (pushable != null)
        {
            if (currentPushables.Contains(pushable))
            {
                currentPushables.Remove(pushable);
            }
        }
    }
    void StopPushingClosestPushable()
    {
        Collider2D closestCollider = closestPushable.GetComponent <Collider2D>();

        Physics2D.IgnoreCollision(col, closestCollider, false);

        closestPushable.transform.parent = null;
        closestPushable = null;

        characterMovement.SetFrozen(false, false, false);
        characterMovement.SetOverrideSpeed(false);
    }
Exemplo n.º 25
0
    //Done being pushed, stop the updating for this object
    private void StopPushingClosestPushable()
    {
        Collider2D closestCollider = m_ClosestPushable.GetComponent <Collider2D>();

        Physics2D.IgnoreCollision(m_Collider, closestCollider, false); //allow collision to work again

        m_ClosestPushable.transform.parent = m_ClosestPushableParent;
        m_ClosestPushable = null;

        m_MovementModel.SetFrozen(false, false, false); //Freeze object again
        m_MovementModel.SetOverrideSpeedEnabled(false);
    }
    void OnTriggerStay(Collider c)
    {
        Pushable check = c.GetComponent <Pushable>();

        if (check)
        {
            //Debug.Log("pushing");
            Vector3 diff = c.transform.position - transform.position;
            diff.y = 0;
            c.transform.position = transform.position + diff * pushRate;
        }
    }
Exemplo n.º 27
0
    private void OnTriggerExit2D(Collider2D other)
    {
        Pushable pushable = other.GetComponent <Pushable>();

        if (pushable != null)
        {
            if (currentPushables.Contains(pushable))
            {
                currentPushables.Remove(pushable);
            }
        }
    }
Exemplo n.º 28
0
    void Awake()
    {
        menuItem         = GetComponent <Pushable>();
        living           = GetComponent <Living>();
        enabled          = false;
        menuItem.enabled = false;
        if (living)
        {
            living.enabled = false;
        }

        SetState(eState.OUT);
    }
Exemplo n.º 29
0
    public void SetSecured(ToolStation station)
    {
        securingStation = station;

        Pushable p = GetComponent <Pushable>();

        if (p == null && transform.parent != null)
        {
            p = transform.parent.gameObject.GetComponent <Pushable>();
        }

        p.enabled = station == null;
    }
Exemplo n.º 30
0
 public static void AddComponents(Entity subject)
 {
     FactionComponent.AddTo(subject, Faction.Environment);
     Displaceable.AddTo(subject, Layers.BLOCK);
     Attackable.AddTo(subject, Attackness.ALWAYS);
     // TODO: Be able to manipulate stats in a simple way.
     Stats.AddTo(subject, Registry.Global.Stats._map);
     Pushable.AddTo(subject);
     Damageable.AddTo(subject, new Health(1));
     Transform.AddTo(subject, Layers.REAL, TransformFlags.Default);
     Ticking.AddTo(subject);
     MoreChains.AddTo(subject, Registry.Global.MoreChains._map);
 }
Exemplo n.º 31
0
 public void SetPushable(Pushable setPushable)
 {
     if (!hasTrap)
     {
         isOccupied = true;
         myPushable = Instantiate(setPushable);
         if (myPushable != null)
         {
             myPushable.transform.position = transform.position;
             myPushable.transform.rotation = transform.rotation;
         }
     }
 }
Exemplo n.º 32
0
        public Slide_Tests()
        {
            InitScript.Init();
            entityFactory = new EntityFactory();
            Transform.AddTo(entityFactory, Layers.REAL, TransformFlags.Default);
            Stats.AddTo(entityFactory, Registry.Global.Stats._map);

            Ticking.AddTo(entityFactory).DefaultPreset();
            Displaceable.AddTo(entityFactory, Layers.BLOCK).DefaultPreset();
            Moving.AddTo(entityFactory).DefaultPreset();
            Pushable.AddTo(entityFactory).DefaultPreset();
            Acting.AddTo(entityFactory, null, Algos.SimpleAlgo, Order.Entity).DefaultPreset(entityFactory);
        }
Exemplo n.º 33
0
    private IEnumerator RevertPushTimer()
    {
        yield return(WaitFor.Seconds(2));

        if (Pushable.ClientPosition != Pushable.TrustedPosition)
        {
            Logger.LogFormat("{0}: Reverted push position", Category.PushPull, gameObject.name);
            Pushable.RollbackPrediction();
        }
        else
        {
            Logger.LogTraceFormat("{0}: No need to revert push position", Category.PushPull, gameObject.name);
        }
    }
Exemplo n.º 34
0
    void Awake()
    {
        menuItem = GetComponent<Pushable>();
        living = GetComponent<Living>();
        enabled = false;
        menuItem.enabled = false;
        if(living)
        {
            living.enabled = false;
        }

        SetState(eState.OUT);
    }