private void OnTriggerEnter2D(Collider2D collision)
    {
        bool onSameTeam = TeamToken.onSameTeam(gameObject, collision.gameObject);

        if (onSameTeam)
        {
            if (Controller == null)
            {
                bool targetIsPlayer = collision.gameObject.CompareTag("Player");
                if (targetIsPlayer)
                {
                    PlayerController pc = collision.gameObject.GetComponent <PlayerController>();
                    if (!pc.Stunned)
                    {
                        rb2d.velocity = Vector2.zero;
                        //Photon Take Over
                        if (PV.IsMine)
                        {
                            Controller = pc;
                        }
                    }
                }
            }
        }
        else
        {
            rb2d.velocity = Vector2.zero;
            processCollision(collision, true);
        }
    }
    public static bool onSameTeam(GameObject go1, GameObject go2)
    {
        TeamToken tt1 = getTeamToken(go1);
        TeamToken tt2 = getTeamToken(go2);

        //If both have a team token
        if (tt1 && tt2)
        {
            //easy, just compare their team captains
            return(tt1.onSameTeam(tt2));
        }
        //If neither has a team token
        else if (!tt1 && !tt2)
        {
            //basically on the same team
            //(neutral won't destroy neutral)
            return(true);
        }
        //If one or either has a team token, but not both
        else
        {
            //they're basically on opposite teams
            //(players can destroy neutral objects, and vice versa)
            return(false);
        }
    }
 void checkCollision(GameObject go)
 {
     if (friendlyHit || !TeamToken.onSameTeam(gameObject, go))
     {
         HealthPool hp = go.FindComponent <HealthPool>();
         if (hp && entityTypes.Contains(hp.entityType))
         {
             takeDamage();
         }
     }
 }
Beispiel #4
0
    private bool CanCreateMapMarker(PhotonView placerPV, MapMarkerPermission permission)
    {
        TeamToken placer = TeamToken.getTeamToken(placerPV.gameObject);

        switch (permission)
        {
        case MapMarkerPermission.EVERYONE:
            return(true);

        case MapMarkerPermission.ALLIES_ONLY:
            return(placer.onSameTeam(localPlayerTeamToken));

        case MapMarkerPermission.SELF_ONLY:
            return(placer.ownedBySamePlayer(localPlayerTeamToken));
        }
        throw new System.InvalidOperationException($"No such permission handled: {permission}");
    }
    protected override void processCollision(Collider2D collision, bool useInitialDamage)
    {
        base.processCollision(collision, useInitialDamage);
        if (TeamToken.onSameTeam(gameObject, collision.gameObject))
        {
            //don't trap teammates
            return;
        }
        HealthPool hp = collision.gameObject.FindComponent <HealthPool>();

        if (hp)
        {
            if (trapTypes.Contains(hp.entityType))
            {
                //TODO: enable trapping other types
                trapPlayer(hp.gameObject.FindComponent <PlayerController>());
            }
        }
    }
Beispiel #6
0
    //private void OnCollisionStay2D(Collision2D collision)
    //{
    //    processCollision(collision.collider, false);
    //}

    public void processCollision(Collider2D collision, bool useInitialDamage)
    {
        if (!damageFriendlies && TeamToken.onSameTeam(gameObject, collision.gameObject))
        {
            //don't damage teammates
            return;
        }
        HealthPool hp = collision.gameObject.GetComponent <HealthPool>();

        if (hp)
        {
            if (damagableTypes.Contains(hp.entityType))
            {
                if (useInitialDamage)
                {
                    hp.Health += -damage;
                    onDealtDamage?.Invoke(damage, hp);
                }
            }
        }
    }