Пример #1
0
        private TimeSpan(System.TimeSpan baseValue, int microseconds, int nanoseconds)
        {
//			const string method = ".ctor";

            // If microsecond value is too large update the milliseconds (same with nanoseconds).
            // This is the behaviour of System.TimeSpan. Store microseconds as Int64 in
            // case the addition of nanoseconds pushes it over Int32.MaxValue.

            long carry             = System.Math.DivRem(nanoseconds, DateTimeHelper.Microseconds2Nanoseconds, out nanoseconds);
            long totalMicroseconds = microseconds + carry;

            carry = System.Math.DivRem(totalMicroseconds, (long)DateTimeHelper.Milliseconds2Microseconds,
                                       out totalMicroseconds);
            microseconds = (int)totalMicroseconds;             // We're back in Int32 range

            // Add carried over milliseconds to the base TimeSpan value
//			try
//			{
            baseValue = (carry == 0 ? baseValue : baseValue.Add(
                             new System.TimeSpan(0, 0, 0, 0, (int)carry)));
//			}
//			catch (OverflowException)
//			{
//				throw new ParameterOutOfRangeException(typeof(TimeSpan), method,
//					"value", baseValue.ToString() + " + " + carry.ToString() + " ms");
//			}

            // Make sure all parts (base TimeSpan, microseconds, nanoseconds) have the same sign

            int sign = System.Math.Sign(baseValue.TotalMilliseconds);

            if (sign == 0)
            {
                sign = System.Math.Sign(microseconds);
            }

            if (sign != 0)
            {
                if (nanoseconds != 0 && System.Math.Sign(nanoseconds) != sign)
                {
                    nanoseconds  += DateTimeHelper.Microseconds2Nanoseconds * sign;
                    microseconds -= sign;
                }

                if (microseconds != 0 && System.Math.Sign(microseconds) != sign)
                {
                    microseconds += DateTimeHelper.Milliseconds2Microseconds * sign;
                    baseValue     = baseValue.Subtract(new System.TimeSpan(0, 0, 0, 0, sign));
                }
            }

            m_base         = baseValue;
            m_microseconds = microseconds;
            m_nanoseconds  = nanoseconds;
        }
Пример #2
0
        } // End Function Insert_Unicode

        // http://stackoverflow.com/questions/7412944/convert-datetime-to-hex-equivalent-in-vb-net
        public string DateTimeAsHexString(System.DateTime dt)
        {
            //dt = System.DateTime.Parse("2012-04-27 14:32:13.510");
            //dt = New DateTime(2012, 4, 27, 14, 32, 13, 510)
            System.DateTime zero = new System.DateTime(1900, 1, 1);

            System.TimeSpan ts = dt - zero;
            System.TimeSpan ms = ts.Subtract(new System.TimeSpan(ts.Days, 0, 0, 0));

            //resolution for datetime: 3.33 ms ...
            //BUG @ New DateTime(2012, 12, 31, 23, 59, 59, 999)
            //string hex = "0x" + ts.Days.ToString("X8") + ((int)(ms.TotalMilliseconds / 3.3333333333)).ToString("X8");
            string hex = "0x" + ts.Days.ToString("X8") + System.Convert.ToInt32(
                System.Math.Floor(ms.TotalMilliseconds / 3.3333333333)).ToString("X8");

            return(hex);
        } // End Function DateTimeAsHexString
Пример #3
0
        /// <summary>
        /// 获取登录游戏的玩家是否可以免费试玩游戏.
        /// </summary>
        bool GetLoginPlayerIsCanFreePlayGame(int userId)
        {
            bool isCanFreePlayGame          = false;
            FreePlayGamePlayerData playerDt = m_FreePlayGamePlayerDataList.Find((dt) => { return(dt.UserId.Equals(userId)); });

            if (playerDt == null)
            {
                //可以免费试玩游戏.
                isCanFreePlayGame = true;
            }
            else
            {
                //数据列表里有玩家的记录信息.
                System.DateTime timeNow    = System.DateTime.Now;
                System.DateTime timeRecord = playerDt.TimeVal;

                System.TimeSpan ts1 = new System.TimeSpan(timeNow.Ticks);
                System.TimeSpan ts2 = new System.TimeSpan(timeRecord.Ticks);
                System.TimeSpan ts  = ts2.Subtract(ts1).Duration();

                //int dTime = ts.Hours * 3600 + ts.Minutes * 60 + ts.Seconds;
                int dTime   = (int)ts.TotalSeconds;
                int minTime = XKGlobalData.GetInstance().m_TimeMianFeiNum * 60; //秒.
                if (dTime > minTime)
                {
                    //playerDt.TimeVal = System.DateTime.Now;
                    //时间差值大于免费间隔时间后,可以被激活.
                    //可以免费试玩游戏.
                    isCanFreePlayGame = true;
                }
                //SSDebug.LogWarning("GetLoginPlayerIsCanFreePlayGame -> dTime =============== " + dTime + "s");
            }

            //yyyy - MM - dd hh: mm: ss
            //System.DateTime t1 = System.DateTime.Now;
            //System.DateTime t2 = System.Convert.ToDateTime("2019-01-07 13:45:10");
            //System.TimeSpan ts11 = new System.TimeSpan(t1.Ticks);
            //System.TimeSpan ts21 = new System.TimeSpan(t2.Ticks);
            //System.TimeSpan ts00 = ts21.Subtract(ts11).Duration();
            //int dTime11 = ts00.Hours * 3600 + ts00.Minutes * 60 + ts00.Seconds;
            //SSDebug.Log("GetLoginPlayerIsCanFreePlayGame -> dTime =============== " + dTime11 + "s");
            return(isCanFreePlayGame);
        }
Пример #4
0
        private void FixedUpdate()
        {
            HandleClock();
            HandleResetGame();
            if (Win || !IsAlive)
            {
                HandleResetGameOver();
            }
            if (Win)
            {
                HandleWin();
                return;
            }
            if (!IsAlive)
            {
                HandleGameOverMessage();
            }
            if (health < 0 && IsAlive)
            {
                DestroyStation();
            }

            winTime = winTime.Subtract(System.TimeSpan.FromSeconds(Time.fixedDeltaTime));

            if (winTime.TotalSeconds <= 0)
            {
                Win = true;
            }

            float current = healthSlider.value;
            float target  = health / maxHealth;

            healthSlider.value += (target - current) * 2f * Time.fixedDeltaTime;

            float healthRate  = health / maxHealth;
            float deathRate   = 1 - healthRate;
            Color healthState = new Color(deathRate, healthRate, 0);

            sliderImage.color = healthState;
        }
Пример #5
0
        /// <summary>
        /// 获取玩家是否可以免费试玩游戏.
        /// </summary>
        bool GetPlayerIsCanFreePlayGame(int userId)
        {
            bool isCanFreePlayGame          = false;
            FreePlayGamePlayerData playerDt = m_FreePlayGamePlayerDataList.Find((dt) => { return(dt.UserId.Equals(userId)); });

            if (playerDt == null)
            {
                playerDt         = new FreePlayGamePlayerData();
                playerDt.UserId  = userId;
                playerDt.TimeVal = System.DateTime.Now;
                m_FreePlayGamePlayerDataList.Add(playerDt);

                //免费试玩游戏玩家信息记录m_MaxPlayerNum个,超过m_MaxPlayerNum个后之前被挤出的玩家可以再次免费试玩游戏!
                if (m_FreePlayGamePlayerDataList.Count > m_MaxPlayerNum)
                {
                    //删除试玩游戏玩家列表信息的第一个元素.
                    m_FreePlayGamePlayerDataList.RemoveAt(0);
                }
                //将玩家信息存入配置信息文件中.
                WriteGamePlayerData();
                //可以免费试玩游戏.
                isCanFreePlayGame = true;
            }
            else
            {
                //数据列表里有玩家的记录信息.
                System.DateTime timeNow    = System.DateTime.Now;
                System.DateTime timeRecord = playerDt.TimeVal;

                System.TimeSpan ts1 = new System.TimeSpan(timeNow.Ticks);
                System.TimeSpan ts2 = new System.TimeSpan(timeRecord.Ticks);
                System.TimeSpan ts  = ts2.Subtract(ts1).Duration();

                //int dTime = ts.Hours * 3600 + ts.Minutes * 60 + ts.Seconds;
                int dTime = (int)ts.TotalSeconds; //时间差的秒数信息.
                if (ts.TotalMinutes > XKGlobalData.GetInstance().m_TimeMianFeiNum)
                {
                    dTime = (XKGlobalData.GetInstance().m_TimeMianFeiNum + 1) * 60; //时间间隔已经足够.
                }
                else
                {
                    dTime = (int)ts.TotalSeconds; //时间间隔秒数.
                }

                int minTime = XKGlobalData.GetInstance().m_TimeMianFeiNum * 60; //秒.
                if (dTime > minTime)
                {
                    playerDt.TimeVal = System.DateTime.Now;
                    //时间差值大于免费间隔时间后,可以被激活.
                    //可以免费试玩游戏.
                    isCanFreePlayGame = true;

                    //将玩家信息存入配置信息文件中.
                    WriteGamePlayerData();
                }
                //SSDebug.Log("GetPlayerIsCanFreePlayGame -> dTime =============== " + dTime + "s");
            }

            //yyyy - MM - dd hh: mm: ss
            //System.DateTime t1 = System.DateTime.Now;
            //System.DateTime t2 = System.Convert.ToDateTime("2019-01-07 13:45:10");
            //System.TimeSpan ts11 = new System.TimeSpan(t1.Ticks);
            //System.TimeSpan ts21 = new System.TimeSpan(t2.Ticks);
            //System.TimeSpan ts00 = ts21.Subtract(ts11).Duration();
            //int dTime11 = ts00.Hours * 3600 + ts00.Minutes * 60 + ts00.Seconds;
            //SSDebug.Log("AddFreePlayGamePlayerInfo -> dTime =============== " + dTime11 + "s");
            return(isCanFreePlayGame);
        }