Exemplo n.º 1
0
        private void AutoFeedSlave(PlayerStoneFactoryAccountInfo factory)
        {
            if (factory.EnableSlavesGroupCount > 0)
            {
                if (factory.SlaveLiveDiscountms <= 0)
                {
                    //每三次累计翻倍
                    int countTimes = 1;
                    if (factory.AutoFeedSumTimes != 0)
                    {
                        countTimes = (int)((factory.AutoFeedSumTimes - 1) / 3f) + 1;
                    }

                    int autofeedNeedFoods = countTimes * StoneFactoryConfig.AutoFeedNeedFoods;

                    if (factory.Food < autofeedNeedFoods)
                    {
                        LogHelper.Instance.AddInfoLog("矿石工厂自动投喂处理,玩家[" + factory.UserName + "] 由于玩家没有及时投喂," + factory.EnableSlavesGroupCount.ToString() + "苦力被饿死。");

                        factory.EnableSlavesGroupCount = 0;
                        factory.SlaveLiveDiscountms    = 0;
                    }
                    else
                    {
                        factory.Food -= autofeedNeedFoods;
                        factory.LastFeedSlaveTime = new MyDateTime(DateTime.Now);
                        factory.AutoFeedSumTimes++;
                        LogHelper.Instance.AddInfoLog("矿石工厂自动投喂处理,系统自动为玩家[" + factory.UserName + "]苦力投喂食物,消耗玩家" + autofeedNeedFoods.ToString() + "食物。还剩" + factory.Food.ToString() + "食物。");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public bool SavePlayerStoneFactoryAccountInfo(PlayerStoneFactoryAccountInfo account, CustomerMySqlTransaction myTrans)
        {
            MySqlCommand mycmd = null;

            try
            {
                mycmd = myTrans.CreateCommand();

                string sqlText = "update playerstonefactoryaccountinfo set `FactoryIsOpening`=@FactoryIsOpening,`FactoryLiveDays`=@FactoryLiveDays,`Food`=@Food,`LastFeedSlaveTime`=@LastFeedSlaveTime,`LastDayValidStoneStack`=@LastDayValidStoneStack,`FreezingSlaveGroupCount`=@FreezingSlaveGroupCount,`EnableSlavesGroupCount`=@EnableSlavesGroupCount,`AutoFeedSumTimes`=@AutoFeedSumTimes where `ID`=@ID ";
                mycmd.CommandText = sqlText;
                mycmd.Parameters.AddWithValue("@ID", account.ID);
                mycmd.Parameters.AddWithValue("@FactoryIsOpening", account.FactoryIsOpening);
                mycmd.Parameters.AddWithValue("@FactoryLiveDays", account.FactoryLiveDays);
                mycmd.Parameters.AddWithValue("@Food", account.Food);
                mycmd.Parameters.AddWithValue("@LastFeedSlaveTime", account.LastFeedSlaveTime == null? DBNull.Value: (object)account.LastFeedSlaveTime.ToDateTime());
                mycmd.Parameters.AddWithValue("@LastDayValidStoneStack", account.LastDayValidStoneStack);
                mycmd.Parameters.AddWithValue("@FreezingSlaveGroupCount", account.FreezingSlaveGroupCount);
                mycmd.Parameters.AddWithValue("@EnableSlavesGroupCount", account.EnableSlavesGroupCount);
                mycmd.Parameters.AddWithValue("@AutoFeedSumTimes", account.AutoFeedSumTimes);
                mycmd.ExecuteNonQuery();
            }
            finally
            {
                if (mycmd != null)
                {
                    mycmd.Dispose();
                }
            }
            return(true);
        }
Exemplo n.º 3
0
        private void SumUserAccountProfitRMBCount(PlayerStoneFactoryAccountInfo account, MySqlCommand mycmd)
        {
            string sqlText = "select * from stonefactoryprofitrmbchangedrecord where `UserID`=@UserID ";

            mycmd.CommandText = sqlText;
            mycmd.Parameters.Clear();
            mycmd.Parameters.AddWithValue("@UserID", account.UserID);
            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);

            adapter.Fill(table);

            StoneFactoryProfitRMBChangedRecord[] items = MetaDBAdapter <StoneFactoryProfitRMBChangedRecord> .GetStoneFactoryProfitRMBChangedRecordItemFromDataTable(table);

            table.Dispose();
            adapter.Dispose();

            decimal sumProfitRMB             = 0;
            decimal sumWithdrawableProfitRMB = 0;

            //已经提现的收益灵币(该值为负数)
            decimal sumWithdrawedProfitRMB = 0;

            decimal sumYesterdayProfitRMB = 0;

            //按时间顺序
            if (items != null && items.Length != 0)
            {
                DateTime timeNow = DateTime.Now;
                foreach (var item in items)
                {
                    if (item.ProfitType == FactoryProfitOperType.WithdrawRMB)
                    {
                        sumWithdrawedProfitRMB += item.OperRMB;
                    }
                    else
                    {
                        sumProfitRMB += item.OperRMB;
                        DateTime itemOperTime = item.OperTime.ToDateTime();
                        if ((timeNow.Date - itemOperTime.Date).Days >= StoneFactoryConfig.ProfitRMBWithdrawLimitDays)
                        {
                            sumWithdrawableProfitRMB += item.OperRMB;
                        }
                        else
                        {
                            if ((timeNow - itemOperTime).TotalHours <= 24)
                            {
                                sumYesterdayProfitRMB += item.OperRMB;
                            }
                        }
                    }
                }
            }

            account.YesterdayTotalProfitRMB = sumYesterdayProfitRMB;
            account.TotalProfitRMB          = sumProfitRMB;
            account.WithdrawableProfitRMB   = sumWithdrawableProfitRMB + sumWithdrawedProfitRMB;
        }
Exemplo n.º 4
0
        /// <summary>
        /// 100个矿工为一组奴隶
        /// </summary>
        /// <param name="userID"></param>
        /// <param name="userName"></param>
        /// <param name="minersGroupCount">100个矿工为一组奴隶</param>
        /// <returns></returns>
        public int AddMinersToFactory(int userID, string userName, int minersGroupCount)
        {
            int result = CheckTime();

            if (result != OperResult.RESULTCODE_TRUE)
            {
                return(result);
            }

            if (minersGroupCount < 1)
            {
                return(OperResult.RESULTCODE_PARAM_INVALID);
            }
            PlayerRunnable playerrunner = PlayerController.Instance.GetRunnable(userName);

            if (playerrunner == null)
            {
                return(OperResult.RESULTCODE_USER_NOT_EXIST);
            }
            if (playerrunner.BasePlayer.FortuneInfo.MinersCount < minersGroupCount * StoneFactoryConfig.OneGroupSlaveHasMiners)
            {
                return(OperResult.RESULTCODE_MINERS_LACK_OF_BALANCE);
            }

            PlayerStoneFactoryAccountInfo factoryAccount = DBProvider.PlayerStoneFactoryDBProvider.GetPlayerStoneFactoryAccountInfo(userID);

            if (factoryAccount == null || !factoryAccount.FactoryIsOpening || factoryAccount.FactoryLiveDays <= 0)
            {
                return(OperResult.RESULTCODE_STONEFACTORYISCLOSED);
            }

            result = MyDBHelper.Instance.TransactionDataBaseOper(myTrans =>
            {
                result = playerrunner.TransferMinersToFactory(minersGroupCount * StoneFactoryConfig.OneGroupSlaveHasMiners, myTrans);
                if (result == OperResult.RESULTCODE_TRUE)
                {
                    factoryAccount.FreezingSlaveGroupCount += minersGroupCount;
                    //factoryAccount.LastFeedSlaveTime = new MyDateTime(DateTime.Now);

                    bool isOK = DBProvider.PlayerStoneFactoryDBProvider.SavePlayerStoneFactoryAccountInfo(factoryAccount, myTrans);
                    return(isOK ? OperResult.RESULTCODE_TRUE : OperResult.RESULTCODE_FALSE);
                }

                return(result);
            },
                                                                 exc =>
            {
                PlayerController.Instance.RollbackUserFromDB(userName);
            });

            if (result == OperResult.RESULTCODE_TRUE)
            {
                LogHelper.Instance.AddInfoLog("矿石工厂,玩家ID[" + userName + "] 增加" + minersGroupCount + "00苦力");
            }
            return(result);
        }
Exemplo n.º 5
0
        private void SumUserAccountStoneStackCount(PlayerStoneFactoryAccountInfo account, MySqlCommand mycmd)
        {
            string sqlText = "select * from stonefactorystackchangerecord where `UserID`=@UserID ";

            mycmd.CommandText = sqlText;
            mycmd.Parameters.Clear();
            mycmd.Parameters.AddWithValue("@UserID", account.UserID);
            DataTable        table   = new DataTable();
            MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);

            adapter.Fill(table);

            StoneFactoryStackChangeRecord[] items = MetaDBAdapter <StoneFactoryStackChangeRecord> .GetStoneFactoryStackChangeRecordItemFromDataTable(table);

            table.Dispose();
            adapter.Dispose();

            int sumEnableStoneStack       = 0;
            int sumFreezingStoneStack     = 0;
            int sumWithdrawableStoneStack = 0;
            int sumWithdrawedStoneStack   = 0;

            if (items != null && items.Length != 0)
            {
                DateTime timeNow = DateTime.Now;
                foreach (var item in items)
                {
                    if ((timeNow.Date - item.Time.ToDateTime().Date).Days >= StoneFactoryConfig.StoneFactoryStoneFreezingDays)
                    {
                        //可用矿石
                        sumEnableStoneStack += item.JoinStoneStackCount;
                    }
                    else
                    {
                        sumFreezingStoneStack += item.JoinStoneStackCount;
                    }
                    if (item.JoinStoneStackCount > 0 && (timeNow.Date - item.Time.ToDateTime().Date).Days >= StoneFactoryConfig.StoneStackWithdrawLimitDays)
                    {
                        //可提现的矿石(没有减去已经提走的灵币)
                        sumWithdrawableStoneStack += item.JoinStoneStackCount;
                    }
                    if (item.JoinStoneStackCount < 0)
                    {
                        //已提取的灵币
                        sumWithdrawedStoneStack += item.JoinStoneStackCount;
                    }
                }
            }

            account.TotalStackCount        = sumEnableStoneStack;
            account.WithdrawableStackCount = sumWithdrawableStoneStack + sumWithdrawedStoneStack;
            account.FreezingStackCount     = sumFreezingStoneStack;
        }
Exemplo n.º 6
0
        public int FeedSlave(int userID)
        {
            int result = CheckTime();

            if (result != OperResult.RESULTCODE_TRUE)
            {
                return(result);
            }

            PlayerStoneFactoryAccountInfo factoryAccount = DBProvider.PlayerStoneFactoryDBProvider.GetPlayerStoneFactoryAccountInfo(userID);

            if (factoryAccount == null || !factoryAccount.FactoryIsOpening || factoryAccount.FactoryLiveDays <= 0)
            {
                return(OperResult.RESULTCODE_STONEFACTORYISCLOSED);
            }

            if (factoryAccount.Food < StoneFactoryConfig.SlaveDefaultLiveDays)
            {
                return(OperResult.RESULTCODE_FACTORY_FOOD_LACKOFBALANCE);
            }

            factoryAccount.Food -= StoneFactoryConfig.SlaveDefaultLiveDays;
            factoryAccount.LastFeedSlaveTime = new MyDateTime(DateTime.Now);
            factoryAccount.AutoFeedSumTimes  = 0;

            result = MyDBHelper.Instance.TransactionDataBaseOper(myTrans =>
            {
                bool isOK = DBProvider.PlayerStoneFactoryDBProvider.SavePlayerStoneFactoryAccountInfo(factoryAccount, myTrans);
                return(isOK ? OperResult.RESULTCODE_TRUE : OperResult.RESULTCODE_FALSE);
            }
                                                                 , exc =>
            {
                if (exc != null)
                {
                    LogHelper.Instance.AddErrorLog("矿石工厂,玩家ID[" + userID + "] 投喂苦力异常", exc);
                }
            });

            if (result == OperResult.RESULTCODE_TRUE)
            {
                LogHelper.Instance.AddInfoLog("矿石工厂,玩家ID[" + userID + "] 投喂苦力");
            }
            return(result);
        }
Exemplo n.º 7
0
        public int AddFoods(int userID, int foodsCount, CustomerMySqlTransaction myTrans)
        {
            int result = CheckTime();

            if (result != OperResult.RESULTCODE_TRUE)
            {
                return(result);
            }

            PlayerStoneFactoryAccountInfo factoryAccount = DBProvider.PlayerStoneFactoryDBProvider.GetPlayerStoneFactoryAccountInfo(userID);

            if (factoryAccount == null || !factoryAccount.FactoryIsOpening || factoryAccount.FactoryLiveDays <= 0)
            {
                return(OperResult.RESULTCODE_STONEFACTORYISCLOSED);
            }

            factoryAccount.Food += foodsCount;

            bool isOK = DBProvider.PlayerStoneFactoryDBProvider.SavePlayerStoneFactoryAccountInfo(factoryAccount, myTrans);

            return(isOK ? OperResult.RESULTCODE_TRUE : OperResult.RESULTCODE_FALSE);
        }
Exemplo n.º 8
0
        public PlayerStoneFactoryAccountInfo GetPlayerStoneFactoryAccountInfo(int userID)
        {
            PlayerStoneFactoryAccountInfo account = null;

            MyDBHelper.Instance.ConnectionCommandSelect(mycmd =>
            {
                string sqlText = "select ttt.*, s.UserName from " +
                                 " (select f.* from playerstonefactoryaccountinfo f where f.`UserID`=@UserID ) ttt " +
                                 " left join playersimpleinfo s on ttt.UserID = s.id  ";
                mycmd.Parameters.AddWithValue("@UserID", userID);
                mycmd.CommandText        = sqlText;
                DataTable table          = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter(mycmd);
                adapter.Fill(table);

                var items = MetaDBAdapter <PlayerStoneFactoryAccountInfo> .GetPlayerStoneFactoryAccountInfoItemFromDataTable(table);
                table.Dispose();
                adapter.Dispose();

                if (items == null || items.Length == 0)
                {
                    return;
                }
                account = items[0];

                if (account.LastFeedSlaveTime != null)
                {
                    account.SlaveLiveDiscountms = StoneFactoryConfig.OnceFeedFoodSlaveCanLivems - (int)(DateTime.Now - account.LastFeedSlaveTime.ToDateTime()).TotalSeconds;
                }
                else
                {
                    account.SlaveLiveDiscountms = 0;
                }
                SumUserAccountStoneStackCount(account, mycmd);
                SumUserAccountProfitRMBCount(account, mycmd);
            });

            return(account);
        }
Exemplo n.º 9
0
        //凝练按天计算,每天0点计算前一天数值,为了简化计算,当前投入的矿石,矿工,食物,都是以第二天0时开始计算。
        //每天23:50分到次到1点禁止充值矿石、矿工、食物。

        public PlayerStoneFactoryAccountInfo GetPlayerStoneFactoryAccountInfo(int userID)
        {
            PlayerStoneFactoryAccountInfo account = DBProvider.PlayerStoneFactoryDBProvider.GetPlayerStoneFactoryAccountInfo(userID);

            if (account != null && account.SlaveLiveDiscountms <= 0 && account.EnableSlavesGroupCount > 0)
            {
                AutoFeedSlave(account);

                int result = MyDBHelper.Instance.TransactionDataBaseOper(myTrans =>
                {
                    DBProvider.PlayerStoneFactoryDBProvider.SavePlayerStoneFactoryAccountInfo(account, myTrans);
                    return(OperResult.RESULTCODE_TRUE);
                },
                                                                         exc =>
                {
                    if (exc != null)
                    {
                        LogHelper.Instance.AddErrorLog("矿石工厂加载处理保存玩家信息异常:玩家:[" + account.UserName + "] ", exc);
                    }
                });
            }

            return(account);
        }
Exemplo n.º 10
0
 public PlayerStoneFactoryAccountInfoUIModel(PlayerStoneFactoryAccountInfo parent)
 {
     this.ParentObject = parent;
 }