Example #1
0
    private IEnumerator respawnTimer(ParticipantID hit)
    {
        respawnWait = new WaitForSecondsRealtime(respawnTime);
        yield return(respawnWait);

        respawnParticipant(hit);
    }
Example #2
0
 public void ReportArrowHit(ParticipantID Shooter, ParticipantID Hit, int damageAmount)
 {
     if (ParticipantManager.GrabbingAndShootingAllowed)
     {
         if (Hit.HealthStats.takeDamage(damageAmount)) //damage has been accepted (participant was alive before arrow hit)
         {
             if (Hit.HealthStats.Lives <= 0)
             {
                 pm.ReportKill(Shooter, Hit);
                 if (Hit.IsPlayer)
                 {
                     Hit.MainObject.GetComponent <Player>().RpcDie();
                 }
                 else
                 {
                     Hit.MainObject.GetComponent <Bot>().RpcDie();
                 }
                 if (ParticipantManager.SelfRespawnAllowed)
                 {
                     StartCoroutine("respawnTimer", Hit);
                 }
             }
             else if (Hit.MainObject.GetComponent <Bot>() && Shooter.Team != Hit.Team) //if the one that got shot is a bot, WARN HIM
             {
                 Hit.MainObject.GetComponent <Bot>().Attack(Shooter);
             }
         }
     }
 }
Example #3
0
 public Message(ParticipantID sender, ParticipantID receiver, MessageType type, params string[] contents)
 {
     this.Sender = sender;
     this.Receiver = receiver;
     this.MessageType = type;
     this.Contents = contents;
 }
Example #4
0
    private ParticipantID reportHit(GameObject hit, bool instantKill)
    {
        if (shooter != null)
        {
            int           damage = 0;
            ParticipantID hitID  = null;

            if (hit.name.Contains("Head")) //headshot
            {
                damage = 2;
            }
            else if (hit.name.Contains("Body")) //bodyshot
            {
                damage = 1;
                if (instantKill)
                {
                    damage = 2;
                }
            }
            if (damage > 0)
            {
                hitID = ParticipantHelper.PH.getIDByBodyPart(hit);
                if (hitID != null && !(hitID == shooter && !arrowIsShot))
                {
                    ParticipantHelper.PH.ReportArrowHit(shooter, hitID, damage);
                    return(hitID);
                }
                return(null); //if hitID == shooter && !arrowIsShot change hitID back to null!
            }
            return(null);
        }
        return(null);
    }
Example #5
0
 public void SetShooter(ParticipantID id)
 {
     if (this.shooter == null)
     {
         this.shooter = id;
     }
 }
Example #6
0
    public void CmdRegisterPlayer(NetworkInstanceId NetID, string Name)
    {
        GameObject    me   = NetworkServer.FindLocalObject(NetID);
        ParticipantID myID = pm.RegisterPlayer(me, Name, true);

        if (myID != null)
        {
            SpawnPlayerWithMaterials(myID);
        }
    }
Example #7
0
        /// <summary>
        /// Removes a server with key nick
        /// </summary>
        /// <param name="nick"> The nickname of the server to be removed </param>
        public void removeServer(string url)
        {
            UInt64 serverID = ParticipantID.get(url, BINARY_KEY_LENGTH);
            string retURL   = "";

            if (mServers.TryRemove(serverID, out retURL))
            {
                System.Console.WriteLine("Server removed: " + url);
                return;
            }

            System.Console.WriteLine("Server not found for url " + url);
        }
Example #8
0
        /// <summary>
        /// Removes a client with key nick
        /// </summary>
        /// <param name="nick"></param>
        /// <param name="url"></param>
        public void removeClient(string url)
        {
            UInt64 clientID = ParticipantID.get(url, BINARY_KEY_LENGTH);
            string retURL   = "";

            if (mClients.TryRemove(clientID, out retURL))
            {
                System.Console.WriteLine("Client removed: " + url);
                return;
            }

            System.Console.WriteLine("Client not found for url " + url);
        }
Example #9
0
 /// <summary>
 /// Checks if the server is responsible for some key which it was not supposed to be
 /// </summary>
 /// <param name="key"></param>
 /// <returns></returns>
 public string needUpdate(string key)
 {
     if (mServers.Count > 1)
     {
         //System.Console.WriteLine("INSIDE NEED UPDATE");
         UInt64 serverKey   = ParticipantID.get(key, BINARY_KEY_LENGTH); //CHANGED LINE
         int    serverCount = mServers.Count;
         for (int i = 0; i < mServers.Count; i++)
         {
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR");
             //The third element before this one
             int serverIndex = ((i - 3) > 0) ? ((i - 3) % serverCount) : (((i - 3) % serverCount) + serverCount);
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 1");
             //The second element before this one
             int serverIndex1 = ((i - 2) > 0) ? ((i - 2) % serverCount) : (((i - 2) % serverCount) + serverCount);
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 2");
             //The first element before this one
             int serverIndex2 = ((i - 1) > 0) ? ((i - 1) % serverCount) : (((i - 1) % serverCount) + serverCount);
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 3");
             //Check if it has some key which belongs to the server before the one this replicates
             if (serverCount == 2 && (mServers.ElementAt(i).Key == mID) && (serverKey > mID))
             {
                 return(mServers[mThisIsReplicaOf]);
             }                                                                                                                       //CHANGED LINE
             if ((i == 1) && (mServers.ElementAt(i).Key == mID) && (serverKey > mServers.ElementAt(serverIndex1).Key))
             {
                 //System.Console.WriteLine("S INSIDE NEED UPDATE");
                 return(mServers.ElementAt(serverIndex2).Value);
             }
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 5");
             //Check if it has some key which is to be replicated now to the server just before him
             if ((mServers.ElementAt(i).Key == mID) && (serverKey > mServers.ElementAt(serverIndex).Key) &&
                 (serverKey <= mServers.ElementAt(serverIndex1).Key))
             {
                 //System.Console.WriteLine("S INSIDE NEED UPDATE");
                 return(mServers.ElementAt(serverIndex1).Value);
             }
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 6");
             if ((mServers.ElementAt(i).Key == mID) && (serverKey > mServers.ElementAt(serverIndex1).Key) &&
                 (serverKey <= mServers.ElementAt(serverIndex2).Key))
             {
                 //System.Console.WriteLine("S INSIDE NEED UPDATE");
                 return(mServers.ElementAt(serverIndex2).Value);
             }
             //System.Console.WriteLine("INSIDE NEED UPDATE FOR 4");
         }
         //System.Console.WriteLine("S INSIDE NEED UPDATE");
         return(null);
     }
     return(null);
 }
Example #10
0
        public NodeRouter(string url, KeyManager kManager, Server server)
        {
            mClients            = new Dictionary <UInt64, string>();
            mServers            = new Dictionary <UInt64, string>();
            mURL                = url;
            mServer             = server;
            thisReplicaObject   = new Object();
            thisIsReplicaObject = new Object();

            mID = ParticipantID.get(url, BINARY_KEY_LENGTH);
            System.Console.WriteLine("MID ------- " + mID);

            mKeyManager = kManager;
        }
    public ParticipantID RegisterPlayer(GameObject me, string Name, bool firstTrial) //player can register here!
    {
        if (getIDByBodyPart(me) == null)                                             //this player has not been registered yet
        {
            if (ss.TotalParticipants < ScoreboardSystem.TeamSize * 2)                //there is place for another player
            {
                int           id;
                int           spawnNumber;
                Team          team;
                ParticipantID newID;
                ss.GetNextParticipantStats(out id, out team, out spawnNumber);

                if (id != -1) //player succesful registered!
                {
                    newID = new ParticipantID(id, Name, team, spawnNumber, me, new Health());
                }
                else //player register failed
                {
                    Debug.LogWarning("ParticipantManager: player " + Name + " failed to register (id was -1)");
                    return(null);
                }

                players.Add(newID);
                ss.AddID(newID);
                Debug.Log("ParticipantManager: player " + newID.Name + " registered on " + team + " with id: " + id);
                return(newID);
            }
            else //check if bot can be removed
            {
                if (firstTrial)
                {
                    if (bots.Count > 0) //remove bot
                    {
                        ParticipantID bot = bots[bots.Count - 1];
                        bot.MainObject.GetComponent <Bot>().BotIsActive = false;
                        Disconnect(bot);
                        bots.Remove(bot);
                        NetworkServer.Destroy(bot.MainObject);
                        Debug.Log("ParticipantManager: bot (id: " + bot.ID + ") has been removed");
                        return(RegisterPlayer(me, Name, false)); //try again
                    }
                }
                Debug.LogWarning("ParticipantManager: player " + Name + " failed to register (no slots available)");
                return(null);
            }
        }
        Debug.LogWarning("ParticipantManager: player " + Name + " failed to register (already registered)");
        return(null);
    }
Example #12
0
 public bool AddID(ParticipantID newID)
 {
     if (newID.ID <= ids.Length && newID.ID > 0)
     {
         kills[newID.ID - 1] = 0;
         deads[newID.ID - 1] = 0;
         ids[newID.ID - 1]   = newID;
         names[newID.ID - 1] = newID.Name;
         namesChanged        = true;
         killsChanged        = true;
         deadsChanged        = true;
         return(true);
     }
     return(false);
 }
Example #13
0
 private void respawnParticipant(ParticipantID participant)
 {
     if (participant.MainObject != null)
     {
         participant.HealthStats.Revive();
         if (participant.IsPlayer)
         {
             participant.MainObject.GetComponent <Player>().RpcRespawn(GetSpawnPoint());
         }
         else
         {
             participant.MainObject.GetComponent <Bot>().Respawn(GetSpawnPoint());
         }
     }
 }
Example #14
0
        /// <summary>
        /// Returns the server to which we send the message
        /// </summary>
        /// <param name="key">The key we want to execute a put or get operation</param>
        /// <returns></returns>
        public string getServerToSend(string key)
        {
            lock (mServers)
            {
                if ((mServers != null) && mServers.Count > 0)
                {
                    UInt64 serverKey = ParticipantID.get(key, BINARY_KEY_LENGTH);
                    System.Console.WriteLine("SERVERKEY " + key + " " + serverKey);
                    foreach (UInt64 skey in mServers.Keys)
                    {
                        System.Console.WriteLine("SERVER KEY - " + skey + " " + mServers[skey]);
                    }
                    //Retornar server consoante valor achado
                    string serverURL;

                    if (mServers.TryGetValue(serverKey, out serverURL))
                    {
                        return(serverURL);
                    }

                    System.Console.WriteLine("No server found with key equals to key computed using the key for the operation: " + serverKey);

                    for (int i = 0; i < mServers.Count; i++)
                    {
                        if ((i == 0) && ((serverKey > mServers.ElementAt(mServers.Count - 1).Key) ||
                                         (serverKey <= mServers.ElementAt(i).Key)))
                        {
                            System.Console.WriteLine("RETURNING  " + mServers.ElementAt(i).Value); return(mServers.ElementAt(i).Value);
                        }
                        else if ((i != 0) && (serverKey > mServers.ElementAt(i - 1).Key) && (serverKey <= mServers.ElementAt(i).Key))
                        {
                            System.Console.WriteLine("RETURNING  " + mServers.ElementAt(i).Value); return(mServers.ElementAt(i).Value);
                        }
                    }

                    System.Console.WriteLine("RETURNING LAST " + mServers.ElementAt(mServers.Count - 1).Value);
                    return(mServers.ElementAt(mServers.Count - 1).Value);
                }
                else
                {
                    System.Console.WriteLine("RegisterManager: getServerToSend, empty list of servers");
                    throw new RemoteException("Empty list of servers");
                }
            }
        }
    } //FINISHED

    private bool enemyCheck(ParticipantID participant1, ParticipantID participant2)
    {
        if (!ScoreboardSystem.EnemiesAreTeamBased)
        {
            return(true);
        }                                          //everyone is your enemy
        else                                       //only the other team is your enemy
        {
            if (participant1.Team == participant2.Team)
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
    }
Example #16
0
        /// <summary>
        /// Checks if the server has some key which it should not be responsible for at a moment
        /// </summary>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool keyBelongsToServer(string key)
        {
            UInt64 serverKey = ParticipantID.get(key, BINARY_KEY_LENGTH);

            System.Console.WriteLine("serverKey " + key + " " + serverKey);
            if (mServers.Count == 1)
            {
                return(true);
            }
            if ((mServers.ElementAt(0).Key == mID) && ((serverKey > mThisIsReplicaOf) ||
                                                       (serverKey <= mID)))
            {
                return(true);
            }
            else if ((serverKey > mThisIsReplicaOf) && (serverKey <= mID))
            {
                return(true);
            }
            return(false);
        }
Example #17
0
        /// <summary>
        /// Add a server to the list of servers which the central directory knows
        /// </summary>
        /// <param name="nick"></param>
        /// <param name="url"></param>
        public void addServer(string url)
        {
            UInt64 serverID = ParticipantID.get(url, BINARY_KEY_LENGTH);

            if (mServers.TryAdd(serverID, url))
            {
                System.Console.WriteLine("Server added " + url + " " + serverID);
            }
            else
            {
                while (true)
                {
                    serverID = (serverID + 1) % ((UInt64)Math.Pow(2.0, BINARY_KEY_LENGTH));
                    if (mServers.TryAdd(serverID, url))
                    {
                        System.Console.WriteLine("Server added " + url + " " + serverID);
                        break;
                    }
                }
            }
        }
Example #18
0
 public void ReportKill(ParticipantID killer, ParticipantID destroyed)
 {
     if (ParticipantManager.GrabbingAndShootingAllowed)
     {
         if (killer == destroyed)
         {
             deads[killer.ID - 1]++;
         }                                                    //suicide
         else if (killer.Team == destroyed.Team)
         {
             kills[killer.ID - 1]--; deads[destroyed.ID - 1]++;
         }                                                      //team kill
         else //normal kill
         {
             kills[killer.ID - 1]++;
             deads[destroyed.ID - 1]++;
         }
         killsChanged = true;
         deadsChanged = true;
     }
 }
Example #19
0
        /// <summary>
        /// Adds a client to the list of clients which the central directory knows.
        /// </summary>
        /// <param name="nick"> nickname of the client </param>
        /// <param name="url"> url to get the client </param>
        public void addClient(string url)
        {
            UInt64 clientID = ParticipantID.get(url, BINARY_KEY_LENGTH);

            if (mClients.TryAdd(clientID, url))
            {
                System.Console.WriteLine("Client added " + url + " " + clientID);
                return;
            }
            else
            {
                while (true)
                {
                    clientID++;
                    if (mClients.TryAdd(clientID, url))
                    {
                        System.Console.WriteLine("Client added " + url + " " + clientID);
                        break;
                    }
                }
            }
        }
    private void CreateBot()
    {
        GameObject newBot = Instantiate(BotPrefab);

        ParticipantHelper.PH.GivePMSpawnPoint();

        if (ss.TotalBlueParticipants <= ss.TotalRedParticipants) //new blue team bot
        {
            newBot.GetComponent <Bot>().CheckMaterials(Team.Blue);
        }
        else //new red team bot
        {
            newBot.GetComponent <Bot>().CheckMaterials(Team.Red);
        }

        ParticipantID newID = null;
        int           id;
        int           spawnNumber;
        Team          team;

        ss.GetNextParticipantStats(out id, out team, out spawnNumber);

        if (id != -1) //bot succesful registered!
        {
            newID = new ParticipantID(id, (BotName)bots.Count, team, spawnNumber, newBot, new Health());
            NetworkServer.Spawn(newBot);
            Debug.Log("Bot has been added to " + team + " with id: " + id);
        }
        else
        {
            Debug.LogWarning("ParticipantManager: bot failed to register");
            Destroy(newBot);
            return;
        }

        ss.AddID(newID);
        bots.Add(newID);
        newBot.GetComponent <Bot>().SetBot(newSpawnPoint, newID);
    }
Example #21
0
 public void SetOwner(ParticipantID id)
 {
     owner = id;
 }
Example #22
0
 private static void OnOffgasCollectedEvent(ParticipantID sender)
 {
     if (OffgasCollected != null)
         OffgasCollected(sender);
 }
 public ReactorAssociationInfo(ParticipantID id, bool value)
 {
     this.ReactorID = id;
     this.IsAssociated = value;
 }
Example #24
0
 public void SpawnPlayerWithMaterials(ParticipantID myID)
 {
     myID.MainObject.GetComponent <Player>().RpcCheckMaterials(myID.Team);
     myID.MainObject.GetComponent <Player>().RpcSpawn(GetSpawnPoint());
 }
 public ParticipantQuery(string tournamentID, ParticipantID id)
 {
     this.tournamentID  = tournamentID;
     this.ParticipantID = id;
 }
 public void Disconnect(ParticipantID myID) //can be used for both players and bots (removes participant from scoreboard)
 {
     ss.RemoveID(myID.ID);
 }
 public Cultivation FindRunningCultivation(ParticipantID reactor, out Experiment conflictingExperiment)
 {
     foreach (Experiment exp in Experiments)
     {
         foreach (Cultivation culti in exp.Cultivations)
         {
             if (culti.IsRunning && culti.Reactor.ParticipantID == reactor)
             {
                 conflictingExperiment = exp;
                 return culti;
             }
         }
     }
     conflictingExperiment = null;
     return null;
 }
 public void ReportKill(ParticipantID attacker, ParticipantID destroyed)
 {
     ss.ReportKill(attacker, destroyed);
 } //checking is done by PH