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);
        }
    }
Beispiel #2
0
    IEnumerator spawn()
    {
        Transform spawn = GameSetup.instance.spawnPoint;

        myAvatar = PhotonNetwork.Instantiate(
            Path.Combine("PhotonPrefabs", "PlayerAvatar"),
            spawn.position,
            Quaternion.identity
            );
        TeamToken teamToken = TeamToken.getTeamToken(myAvatar);

        teamToken.assignTeam();
        while (teamToken.teamCaptain == null)
        {
            yield return(null);
        }
        spawn = teamToken.teamCaptain.getNextSpawnPoint();
        Rigidbody2D rb2d = myAvatar.GetComponent <Rigidbody2D>();

        rb2d.isKinematic = true;
        while (myAvatar.transform.position != spawn.position)
        {
            myAvatar.transform.position = spawn.position;
            yield return(null);
        }
        rb2d.isKinematic = false;
        myAvatar.GetComponent <AvatarSetup>().setTeamIndicator();
        yield return(null);
    }
 public void Display(bool display)
 {
     //Destroy all current icons
     glg.transform.DetachChildren();
     playerIcons.ForEach(pi => Destroy(pi));
     playerIcons.Clear();
     //Create new icons
     if (display)
     {
         List <TeamTokenCaptain> ttcList = FindObjectsOfType <TeamTokenCaptain>().ToList();
         List <PlayerController> pcList  = FindObjectsOfType <PlayerController>().ToList();
         //Red team
         TeamTokenCaptain ttcRed = ttcList.Find(
             ttc => ttc.colorGroupIndex == redColorGroupIndex
             );
         pcList.FindAll(
             pc => ttcRed.onSameTeam(TeamToken.getTeamToken(pc.gameObject))
             )
         .ForEach(pc => playerIcons.Add(CreatePlayerIcon(pc)));
         //Separator
         playerIcons.Add(Instantiate(separatorPrefab));
         //Blue team
         TeamTokenCaptain ttcBlue = ttcList.Find(
             ttc => ttc.colorGroupIndex == blueColorGroupIndex
             );
         pcList.FindAll(
             pc => ttcBlue.onSameTeam(TeamToken.getTeamToken(pc.gameObject))
             )
         .ForEach(pc => playerIcons.Add(CreatePlayerIcon(pc)));
         //Layout icons
         playerIcons.ForEach(pi => pi.transform.parent = glg.transform);
     }
 }
 private void recruitOwnedObject(TeamToken tt)
 {
     recruit(tt);
     tt.owner      = this;
     tt.controller = this;
     tt.onControllerGainedControl?.Invoke(this);
 }
Beispiel #5
0
    void Update()
    {
        if (PV.IsMine)
        {
            if (teamToken.teamCaptain != null || !waitForTeamToken)
            {
                foreach (string objectName in objectNames)
                {
                    GameObject go = PhotonNetwork.Instantiate(
                        Path.Combine("PhotonPrefabs", folderName, objectName),
                        transform.position,
                        transform.rotation
                        );
                    //Color
                    ColorInitializer colorInit = go.FindComponent <ColorInitializer>();
                    if (colorInit)
                    {
                        colorInit.setColor(PlayerColor);
                    }
                    //Delegate
                    if (onObjectSpawned != null)
                    {
                        onObjectSpawned(go);
                    }

                    TeamToken.seeRecruiter(go, teamToken.owner, true);
                }
                PhotonNetwork.Destroy(this.gameObject);
            }
        }
    }
Beispiel #6
0
 protected List <T> FindObjectsToEffect <T>(TeamTokenCaptain teamCaptain) where T : Component
 {
     return(FindObjectsOfType <T>().ToList()
            .FindAll(t => t &&
                     (TeamToken.getTeamToken(t.gameObject)?.onSameTeam(teamCaptain) ?? false)
                     ));
 }
    public static bool controlledBySamePlayer(GameObject go1, GameObject go2)
    {//2022-02-10: copied from ownedBySamePlayer()
        //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 controllers
            return(tt1.controlledBySamePlayer(tt2));
        }
        //If neither has a team token
        else if (!tt1 && !tt2)
        {
            //not controlled at all
            return(false);
        }
        //If one or either has a team token, but not both
        else
        {
            //one's not controlled at all,
            //therefore not controlled by same player
            return(false);
        }
    }
    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 updatePushingPlayers(bool pvMine)
    {
        teamCaptains.Clear();
        int count = detectionColl.Cast(Vector2.zero, rch2ds, 0, true);

        for (int i = 0; i < count; i++)
        {
            RaycastHit2D rch2d = rch2ds[i];
            GameObject   rchGO = rch2d.collider.gameObject;
            if (rchGO.CompareTag("Player"))
            {
                TeamToken  tt         = TeamToken.getTeamToken(rchGO);
                HealthPool healthPool = rchGO.GetComponentInChildren <HealthPool>();
                if (healthPool)
                {
                    if (!teamCaptains.ContainsKey(tt.teamCaptain))
                    {
                        teamCaptains.Add(tt.teamCaptain, 0);
                    }
                    float amount = healthPool.Health;
                    //Add in distance to caravan
                    float distance           = (rchGO.transform.position - transform.position).magnitude;
                    float distanceMultiplier = 1 + ((maxAllowedDistance - distance) / maxAllowedDistance);
                    //Update team captains dict
                    teamCaptains[tt.teamCaptain] += amount * distanceMultiplier;
                }
            }
        }
        updateDirection(pvMine);
    }
Beispiel #10
0
    private MapMarker CreateMapMarkerPos(PhotonView placer, Vector2 pos, MapMarkerInfo markerInfo)
    {
        MapMarker marker = GetOrCreateMapMarker(placer.ViewID);

        marker.Init(markerInfo, TeamToken.getTeamToken(placer.gameObject)); //placer.teamCaptain.teamColor, Color.white);
        marker.Mark(pos);
        return(marker);
    }
Beispiel #11
0
    private MapMarker CreateMapMarkerFollow(PhotonView placer, Transform follow, MapMarkerInfo markerInfo)
    {
        MapMarker marker = GetOrCreateMapMarker(placer.ViewID);

        marker.Init(markerInfo, TeamToken.getTeamToken(placer.gameObject)); //placer.teamCaptain.teamColor, Color.white);
        marker.Mark(follow);
        return(marker);
    }
 public void Init(MapMarkerInfo info, TeamToken placer, Color iconColor, Color markerColor)
 {
     this.info      = info;
     this.placer    = placer;
     iconSR.sprite  = info.icon;
     iconSR.color   = iconColor;
     markerSR.color = markerColor;
 }
 public void Init(MapMarkerInfo info, TeamToken placer)
 {
     Init(
         info,
         placer,
         placer?.teamCaptain.teamColor ?? Color.white,
         Color.white //placer?.teamCaptain.teamColor ?? Color.white
         );
 }
    public static TeamToken getTeamToken(GameObject go, bool addIfNone = false)
    {
        TeamToken tt = go.FindComponent <TeamToken>();

        if (!tt && addIfNone)
        {
            tt = go.AddComponent <TeamToken>();
        }
        return(tt);
    }
 void checkCollision(GameObject go)
 {
     if (friendlyHit || !TeamToken.onSameTeam(gameObject, go))
     {
         HealthPool hp = go.FindComponent <HealthPool>();
         if (hp && entityTypes.Contains(hp.entityType))
         {
             takeDamage();
         }
     }
 }
    private TeamToken recruit(GameObject go)
    {
        TeamToken tt = go.GetComponent <TeamToken>();

        if (!tt)
        {
            tt = go.AddComponent <TeamToken>();
        }
        recruit(tt);
        return(tt);
    }
    void RPC_SeeRecruiter(int recruiterID, bool ownedObject)
    {
        TeamToken tt = TeamToken.FindTeamToken(recruiterID);

        if (ownedObject)
        {
            tt?.recruitOwnedObject(this);
        }
        else
        {
            tt?.recruit(this);
        }
    }
    void registerDelegates(TeamToken controller, bool register)
    {
        StatusKeeper statusKeeper = controller.gameObject.FindComponent <StatusKeeper>();

        if (statusKeeper)
        {
            statusKeeper.onStatusChanged -= checkReleaseFromOwner;
            if (register)
            {
                statusKeeper.onStatusChanged += checkReleaseFromOwner;
            }
        }
    }
    public void switchController(TeamToken controller)
    {
        int controllerID = controller?.PV.ViewID ?? this.owner.PV.ViewID;

        if (controller)
        {
            PV.TransferOwnership(controller.PV.Owner);
        }
        else
        {
            PV.TransferOwnership(this.owner.PV.Owner);
        }
        PV.RPC("RPC_SwitchController", RpcTarget.AllBuffered, controllerID);
    }
 protected virtual void Start()
 {
     //If there's no owner,
     if (!owner)
     {
         //it owns itself
         owner = this;
     }
     //If there's no controller,
     if (!controller)
     {
         //it controls itself
         controller = this;
         onControllerGainedControl?.Invoke(this);
     }
 }
 private void Awake()
 {
     teamToken = TeamToken.getTeamToken(gameObject);
     PV        = gameObject.FindComponent <PhotonView>();
     if (PV.IsMine)
     {
         //Subfoldername
         if (string.IsNullOrEmpty(folderName))
         {
             throw new UnityException(
                       $"folderName is null! foldername: {folderName}, " +
                       $"gameObject: {gameObject.name}"
                       );
         }
     }
 }
 public GameObject spawnObject(ObjectSpawnInfo osi, Vector2 pos, Vector2 dir, float addSpawnBuffer = 0)
 {
     if (PV.IsMine)
     {
         //Make sure dir is a unit vector
         if (!Mathf.Approximately(dir.sqrMagnitude, 1))
         {
             throw new System.ArgumentException(
                       $"dir needs to be a unit vector! dir: {dir}, " +
                       $"sqrMagnitude: {dir.sqrMagnitude}"
                       );
         }
         //Initialize arguments
         string  pathName = Path.Combine("PhotonPrefabs", folderName, osi.objectName);
         Vector2 position = pos + (dir * (osi.spawnBuffer + addSpawnBuffer));
         position += osi.spawnOffset;
         Quaternion rotation = (osi.rotateShot)
             ? Quaternion.Euler(0, 0, Vector2.SignedAngle(Vector2.up, dir))
             : Quaternion.Euler(0, 0, 0);
         //Instantiate
         GameObject go = (SpawnMaster)
                         //Spawn as scene object (doesn't disappear when player disconnects)
             ? PhotonNetwork.InstantiateRoomObject(pathName, position, rotation)
                         //Spawn as player object (disappears when player disconnects)
             : PhotonNetwork.Instantiate(pathName, position, rotation)
         ;
         //Team Token
         if (osi.inheritTeamToken)
         {
             TeamToken.seeRecruiter(go, teamToken.owner, true);
         }
         //Color
         if (osi.inheritColor)
         {
             ColorInitializer colorInit = go.FindComponent <ColorInitializer>();
             if (colorInit)
             {
                 colorInit.setColor(PlayerColor);
             }
         }
         //Delegate
         onObjectSpawned?.Invoke(go, position, dir);
         //Return
         return(go);
     }
     return(null);
 }
Beispiel #23
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}");
    }
    void RPC_SwitchController(int controllerID)
    {
        //Old TT is the current controller
        TeamToken oldTT = this.controller;
        //New TT is the given controller,or if it's null,
        //New TT is this teamToken (it controls itself)
        TeamToken newTT = TeamToken.FindTeamToken(controllerID)
                          ?? this;

        //If the controller has changed
        if (oldTT != newTT)
        {
            //Switch the controller
            onControllerLostControl?.Invoke(oldTT);
            this.controller = newTT;
            onControllerGainedControl?.Invoke(newTT);
        }
    }
Beispiel #25
0
 // Start is called before the first frame update
 void Start()
 {
     PV = GetComponent <PhotonView>();
     if (PV.IsMine)
     {
         PV.RPC(
             "RPC_AddCharacter",
             RpcTarget.AllBuffered,
             PlayerInfo.instance.characterSelection.Index
             );
         Camera.main.GetComponent <CameraController>().FocusObject = gameObject;
     }
     teamToken = TeamToken.getTeamToken(gameObject);
     if (teamToken.teamCaptain)
     {
         setTeamIndicator();
     }
 }
 void RPC_ShowResultScreen(int winnerID)
 {
     foreach (TeamTokenCaptain ttc in FindObjectsOfType <TeamTokenCaptain>())
     {
         if (ttc.PV.ViewID == winnerID)
         {
             if (ttc.onSameTeam(TeamToken.getTeamToken(PhotonPlayer.localPlayer.myAvatar)))
             {
                 showResultsScreen(true);
             }
             else
             {
                 showResultsScreen(false);
             }
             break;
         }
     }
 }
    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 #28
0
 public void setTeamIndicator()
 {
     if (!teamToken)
     {
         teamToken = TeamToken.getTeamToken(gameObject);
     }
     //Team Color
     shadowSR.color = shadowSR.color.setRGB(
         teamToken.teamCaptain.teamColor
         );
     //Player Color
     myCharacter.FindComponent <PlayerController>().playerColor =
         PlayerInfo.instance.colorGroups[teamToken.teamCaptain.colorGroupIndex]
         .SelectedItem;
     //RPC
     if (PV && PV.IsMine || this.isPhotonViewMine())
     {
         PV.RPC("RPC_SetTeamIndicator", RpcTarget.OthersBuffered);
     }
 }
Beispiel #29
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);
                }
            }
        }
    }
Beispiel #30
0
 private void Start()
 {
     teamToken = TeamToken.getTeamToken(gameObject);
     PV        = GetComponent <PhotonView>();
 }