public static bool ownedBySamePlayer(GameObject go1, GameObject go2)
    {//2019-03-20: copied from onSameTeam()
        //Get go1's team token
        TeamToken tt1 = go1.FindComponent <TeamToken>();
        //Get go2's team token
        TeamToken tt2 = go2.FindComponent <TeamToken>();

        //If both have a team token
        if (tt1 && tt2)
        {
            //easy, just compare their owners
            return(tt1.ownedBySamePlayer(tt2));
        }
        //If neither has a team token
        else if (!tt1 && !tt2)
        {
            //not owned at all
            return(false);
        }
        //If one or either has a team token, but not both
        else
        {
            //one's not owned at all,
            //therefore not owned by same player
            return(false);
        }
    }
Exemplo n.º 2
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}");
    }
Exemplo n.º 3
0
    private PreviewDisplayer.PreviewState getPreviewState(Vector2 position)
    {
        preview.transform.position = position + ChargedShotSpawnInfo.spawnOffset;
        preview.transform.up       = Vector2.up;
        previewDisplayer.updatePreviewSprite();
        GameObject conflictingObject = null;
        bool       coHasSC           = false;

        if (previewCollider)
        {
            RaycastHit2D[] rch2ds = new RaycastHit2D[10];
            int            count  = previewCollider.Cast(Vector2.zero, rch2ds, 0, false);
            for (int i = 0; i < count; i++)
            {
                RaycastHit2D rch2d  = rch2ds[i];
                Collider2D   coll2d = rch2d.collider;
                GameObject   rchGO  = coll2d.gameObject;
                HealthPool   hp     = rchGO.FindComponent <HealthPool>();
                //If the conflicting object is a regular moving shot,
                if (hp && hp.entityType == EntityType.SHOT)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is not solid,
                else if (coll2d.isTrigger)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is non-moving or is not a shot,
                else
                {
                    //Double-check to make sure the sprites overlap
                    SpriteRenderer coSR    = rchGO.FindComponent <SpriteRenderer>();
                    bool           overlap = previewDisplayer.boundsIntersects(coSR.bounds);
                    if (overlap)
                    {
                        //it's conflicting
                        conflictingObject = rchGO;
                        coHasSC           = rchGO.FindComponent <ShotController>();
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
        if (!conflictingObject && upgradeRange > 0)
        {
            RaycastHit2D[] rch2ds = Physics2D.CircleCastAll(
                position,
                upgradeRange,
                Vector2.zero
                );
            for (int i = 0; i < rch2ds.Length; i++)
            {
                RaycastHit2D rch2d  = rch2ds[i];
                Collider2D   coll2d = rch2d.collider;
                GameObject   rchGO  = coll2d.gameObject;
                HealthPool   hp     = rchGO.FindComponent <HealthPool>();
                //If the conflicting object is a regular moving shot,
                if (hp && hp.entityType == EntityType.SHOT)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is not solid,
                else if (coll2d.isTrigger)
                {
                    //You can build here anyway
                    continue;
                }
                //If the conflicting object is non-moving or is not a shot,
                else
                {
                    //If the object is upgradable
                    if (rchGO.name.Contains(ChargedShotSpawnInfo.objectName))
                    {
                        //it's conflicting
                        conflictingObject = rchGO;
                        coHasSC           = rchGO.FindComponent <ShotController>();
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
        }
        if (conflictingObject)
        {
            //If this player owns the conflicting object,
            if (TeamToken.ownedBySamePlayer(gameObject, conflictingObject))
            {
                //if they're the same type,
                if (conflictingObject.name.Contains(ChargedShotSpawnInfo.objectName))
                {
                    //upgrade the one there
                    targetObject = conflictingObject;
                    preview.transform.position = conflictingObject.transform.position;
                    preview.transform.up       = conflictingObject.transform.up;
                    return(PreviewDisplayer.PreviewState.UPGRADE);
                }
                //else if they're not the same type,
                //but still both constructs
                else if (coHasSC)
                {
                    ChargedShotController csc = conflictingObject.FindComponent <ChargedShotController>();
                    Sprite conflictingSprite  = csc.previewSprite;
                    //delete the object already there
                    targetObject = conflictingObject;
                    preview.transform.position = conflictingObject.transform.position;
                    preview.transform.up       = conflictingObject.transform.up;
                    previewDisplayer.updatePreviewSprite(conflictingSprite);
                    return(PreviewDisplayer.PreviewState.DESTROY);
                }
            }
            return(PreviewDisplayer.PreviewState.NONE);
        }
        else
        {
            targetObject = null;
        }
        if (aminaPool.ReservedAmina < minAminaReserved)
        {
            return(PreviewDisplayer.PreviewState.NONE);
        }
        return(PreviewDisplayer.PreviewState.BUILD);
    }