示例#1
0
    public void ReturnShipButton(bool FromGUI)
    {
        ShipTracking  ShipTracker = GameObject.Find("DockingFunctions").GetComponent <ShipTracking>();
        Player        Player      = GameObject.Find("Player").GetComponent <Player>();
        ServerPretend Server      = GameObject.Find("Server").GetComponent <ServerPretend>();

        if (Player.GetRentedStatus())
        {
            //Problem: Server needs to GET immediately before POST is called
            //         BUT, That just resets any changes made to the server.
            //Solution:Enforce GET calls to be made immediately, put post in server methods.
            Server.ReturnShip(ref Player);
            if (Player.GetWaitListStatus())
            {
                //Server will automatically handle renting a waitlisted ship.
                //So all we have to do is tell the player it's going from waitlist to
                //Rental . . . probably.
            }
            //Update the GUI
            Debug.Log("Telling ShipTracker to Return");
            ShipTracker.ShipReturned(Player.GetRentedShipName()); //just visuals happen here.
            //Updating the GUI Timestamp.
            GameObject.Find("Rental Time Remaining")
            .GetComponentInChildren <GetRentalTimeRemaining>().NewTime();
        }
        else if (FromGUI == false)
        {
            //In case user can't rent a ship, because someone else did first,
            // we call this method in order to remove it's icon from rented space.
            // Icon gets added before we actually know if we can rent.
            ShipTracker.ShipReturned(Player.GetRentedShipName());
        }
    }
示例#2
0
        /*
         * public bool DropFromWaitList(string Username)
         * {
         *  //test to make sure we were given a proper UserName
         *  bool UsernameFound = false;
         *  int MatchingUserNum = 0;
         *  for (int i = 0; i < UserList.Count; i++)
         *  {
         *      if (UserList[i].Username == Username)
         *      {
         *          UsernameFound = true;
         *          MatchingUserNum = i;
         *      }
         *  }
         *  if (UsernameFound == false) return UsernameFound;
         *
         *  DateTime OldestWaitEntry = DateTime.MinValue;
         *  //Search through users and find the user waitlisting this ship that is highest
         *  for (int i = 0; i < UserList.Count; i++)
         *  {
         *      if (UserList[i].WaitListShipName == ShipName)
         *      {
         *          //
         *          if (UserList[i].WaitExpireTime.CompareTo(OldestWaitEntry) == 1)
         *          {
         *              OldestWaitEntry = UserList[i].WaitExpireTime.AddHours(TOTAL_RENT_TIME);
         *          }
         *      }
         *  }
         *  //if the renter is wait list #1, check to see if the ship is rented.
         *  //if the ship isn' rented and our user hasn't rented a ship, rent the ship
         *  bool ShipNotRented = true;
         *  for (int i = 0; i < UserList.Count; i++)
         *  {
         *      if (UserList[i].RentedShipName == ShipName)
         *      {
         *          ShipNotRented = false;
         *      }
         *  }
         *  if (ShipNotRented && UserList[MatchingUserNum].RentedShipName == "")
         *  {
         *      RentingShip(Username, ShipName);
         *      Debug.Log("WaitList attempted, Rented instead");
         *      return false;
         *  }
         *  //If the user can't auto-rent the ship, it gets waitlisted:
         *
         *  //reassign all stuff to insert into userlists. Structs can't be modified,
         *  // only reassigned.
         *  UserProfile tempProf;
         *  tempProf.Username = UserList[MatchingUserNum].Username;
         *  tempProf.Password = UserList[MatchingUserNum].Password;
         *  tempProf.Credits = UserList[MatchingUserNum].Credits;
         *  tempProf.TimeToReturnBy = UserList[MatchingUserNum].TimeToReturnBy;
         *  tempProf.RentedShipName = UserList[MatchingUserNum].RentedShipName;
         *  tempProf.WaitExpireTime = OldestWaitEntry;
         *  tempProf.WaitListShipName = ShipName;
         *  UserList[MatchingUserNum] = tempProf;
         *  Debug.Log("WaitList attempted, Waitlisting Success");
         *  return true;
         * }*/

        public bool UpdateWaitLists(string CurrentUsername)
        {
            //if ship IS rented, check to see if time is up
            //if NOT rented, check to see if

            string ShipTestingName     = "Ship ";
            int    TotalShipsToCheck   = 12;
            int    TotalPlayersToCheck = UserList.Count;

            for (int x = 0; x < TotalShipsToCheck; x++)
            {
                ShipTestingName = ShipTestingName.Substring(0, 5) + (x + 1);
                int ShipRentedBy = 0;
                //Check to see if the ship is rented
                bool ShipIsRented = false;
                for (int y = 0; y < TotalPlayersToCheck; y++)
                {
                    if (UserList[y].RentedShipName == ShipTestingName)
                    {
                        ShipIsRented = true;
                        ShipRentedBy = y;
                    }
                    //Debug.Log("Ship Not Rented: " + ShipTestingName + ", No Match: "
                    //  + UserList[y].RentedShipName);
                }

                //if the ship is rented
                if (ShipIsRented)
                {
                    bool RentExpired;
                    //is the ship's rent expired?
                    //TimeSpan span = DateTime.Now.Subtract(UserList[ShipRentedBy].TimeToReturnBy);
                    if (DateTime.Now.CompareTo(UserList[ShipRentedBy].TimeToReturnBy) > 0)
                    {
                        //if yes, forcibly de-rent ship.
                        ShipIsRented = false;
                        Debug.Log(UserList[ShipRentedBy].Username + "'s rental has expired!! At: " +
                                  UserList[ShipRentedBy].TimeToReturnBy.ToString());
                        if (CurrentUsername == UserList[ShipRentedBy].Username)
                        {
                            Debug.Log("Returning Ship In Server Script.");
                            GameObject.Find("DockingFunctions").GetComponent <ReturnShipClass>().ReturnShipButton(true);
                        }
                        UserProfile tempProf;
                        tempProf.Username         = UserList[ShipRentedBy].Username;
                        tempProf.Password         = UserList[ShipRentedBy].Password;
                        tempProf.Credits          = 0;
                        tempProf.WaitListShipName = UserList[ShipRentedBy].WaitListShipName;
                        tempProf.WaitExpireTime   = UserList[ShipRentedBy].WaitExpireTime;
                        tempProf.TimeToReturnBy   = DateTime.MinValue;
                        tempProf.RentedShipName   = "";
                        UserList[ShipRentedBy]    = tempProf;
                    }
                }
                if (ShipIsRented == false)
                {
                    //ship is no longer rented or was never rented.
                    //is the ship waitlisted?
                    List <int> TempWaitList  = new List <int>();
                    int        WaitUserIndex = -1; //Index of first user in waitlist.
                    DateTime   MinWaitList   = DateTime.MaxValue;
                    for (int y = 0; y < TotalPlayersToCheck; y++)
                    {
                        if (UserList[y].WaitListShipName == ShipTestingName)
                        {
                            //if yes, is this person earliest in waitlist?
                            if (UserList[y].WaitExpireTime.CompareTo(MinWaitList) < 0)
                            {
                                //finding the earliest (#1 spot) member in the waitlist
                                WaitUserIndex = y;
                                MinWaitList   = UserList[y].WaitExpireTime;
                                TempWaitList.Add(WaitUserIndex);
                            }
                        }
                    }
                    //check if we found a waitlist spot #1
                    if (WaitUserIndex != -1 && MinWaitList.CompareTo(DateTime.MaxValue) != 0)
                    {
                        //check to see if they are renting a ship
                        if (UserList[WaitUserIndex].RentedShipName != "")
                        {
                            //if this player's rent HAS expired
                            //TimeSpan span = DateTime.Now.Subtract(UserList[WaitUserIndex].TimeToReturnBy);
                            if (DateTime.Now.CompareTo(UserList[ShipRentedBy].TimeToReturnBy) > 0)
                            {
                                //forcibly return their ship and . . .
                                Debug.Log(UserList[WaitUserIndex].Username + "'s rental has expired!! At: " +
                                          UserList[WaitUserIndex].TimeToReturnBy.ToString());
                                UserProfile tempProf;
                                tempProf.Username = UserList[WaitUserIndex].Username;
                                tempProf.Password = UserList[WaitUserIndex].Password;
                                tempProf.Credits  = 0;
                                //forcibly make them rent their #1 spot on waitlist
                                tempProf.WaitListShipName = "";
                                if (CurrentUsername == UserList[WaitUserIndex].Username)
                                {
                                    tempProf.TimeToReturnBy = DateTime.Now.AddHours(TOTAL_RENT_TIME);
                                }
                                else
                                {
                                    tempProf.TimeToReturnBy = UserList[WaitUserIndex].WaitExpireTime;
                                }
                                tempProf.WaitExpireTime = DateTime.MaxValue;
                                tempProf.RentedShipName = UserList[WaitUserIndex].WaitListShipName;
                                UserList[WaitUserIndex] = tempProf;
                            }
                            //if NOT expired, do nothing.
                        }
                        else
                        {
                            //player hasn't rented a ship, make them auto-rent their waitlist ship
                            Debug.Log("Making user " + UserList[WaitUserIndex].Username + " Rent wait ship: " +
                                      UserList[WaitUserIndex].WaitListShipName);
                            string ShipToRent = UserList[WaitUserIndex].WaitListShipName;

                            if (CurrentUsername == UserList[ShipRentedBy].Username)
                            {
                                Player       CurrentPlayer = GameObject.Find("Player").GetComponent <Player>();
                                ShipTracking Station       = GameObject.Find("DockingFunctions").GetComponent <ShipTracking>();

                                //client returns their ship.
                                CurrentPlayer.SetShipReturned();
                                //docking station GUI returns the ship.
                                GameObject.Find("DockingFunctions").GetComponent <ReturnShipClass>().ReturnShipButton(true);
                                //station clears it's waitlist.
                                Station.RemoveShipFromWaitList(); //Also calls client's remove from waitlist

                                Station.ShipRented(ShipToRent, true);
                                CurrentPlayer.SetShipRented(ShipToRent, Station.GetSelectedShip(), false);
                            }

                            UserProfile tempProf;
                            tempProf.Username = UserList[WaitUserIndex].Username;
                            tempProf.Password = UserList[WaitUserIndex].Password;
                            tempProf.Credits  = UserList[WaitUserIndex].Credits;
                            //forcibly make them rent their #1 spot on waitlist
                            tempProf.WaitListShipName = "";
                            if (CurrentUsername == UserList[WaitUserIndex].Username)
                            {
                                tempProf.TimeToReturnBy = DateTime.Now.AddHours(TOTAL_RENT_TIME);
                            }
                            else
                            {
                                tempProf.TimeToReturnBy = UserList[WaitUserIndex].WaitExpireTime;
                            }
                            tempProf.WaitExpireTime = DateTime.MaxValue;
                            tempProf.RentedShipName = UserList[WaitUserIndex].WaitListShipName;
                            UserList[WaitUserIndex] = tempProf;
                        }
                    }
                }
            }
            GameObject.Find("DockingFunctions").GetComponent <ShipTracking>().UpdateDockingStation(true);
            return(true);
        }