public void newThreadDo(commandWithTime.baseC dObj)
 {
     if (dObj.c == "diamondOwner")
     {
         commandWithTime.diamondOwner dOwner = (commandWithTime.diamondOwner)dObj;
         this.setDiamondOwner(dOwner);
     }
     //throw new NotImplementedException();
 }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="startT"></param>
        /// <param name="dor"></param>
        private async void setDiamondOwner(int startT, commandWithTime.diamondOwner dor)
        {
            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}开始执行setDiamondOwner");
            Thread.Sleep(startT + 1);
            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}开始执行setDiamondOwner正文");
            List <string> notifyMsg = new List <string>();
            bool          needUpdatePromoteState = false;

            lock (this.PlayerLock)
            {
                var player = this._Players[dor.key];
                var car    = this._Players[dor.key].getCar(dor.car);
                {
                    if ((dor.changeType == "mile" || dor.changeType == "business" || dor.changeType == "volume" || dor.changeType == "speed") &&
                        car.state == CarState.buying)
                    {
                        if (car.targetFpIndex == -1)
                        {
                            throw new Exception("居然来了一个没有目标的车!!!");
                        }
                        if (car.ability.diamondInCar != "")
                        {
                            throw new Exception("怎么能让满载车出来购买?");
                        }
                        if (!(car.purpose == Purpose.collect || car.purpose == Purpose.@null || car.purpose == Purpose.tax))
                        {
                            //在执行抢能力提升宝石是,有可能之前是在基地等待 car.purpose == Purpose.@null
                            //在执行抢能力提升宝石时,也有可能之前是在完成收集任务之后 car.purpose == Purpose.collect
                            //在执行抢能力提升宝石时,也有可能之前是在完成收集保护费之后 car.purpose == Purpose.tax
                            throw new Exception($"错误的purpose:{car.purpose}");
                        }
                        if (dor.target == this.getPromoteState(dor.changeType))
                        {
                            /*
                             * 这里,整个流程,保证玩家在开始任务的时候,钱是够的。如果不够,要爆异常的。
                             */
                            var needMoney = this.promotePrice[dor.changeType];
                            if (car.ability.SumMoneyCanForPromote < needMoney)
                            {
                                /*
                                 * 这里,在逻辑上保证了car.ability.SumMoneyCanForPromote >=needMoney
                                 * 首先在出发的时候就进行判断
                                 * 其次,在promote地点选择的时候,会避免使用玩家的target.
                                 * 最后保证了dor.target == this.getPromoteState(dor.changeType) 条件下,
                                 * 肯定car.ability.SumMoneyCanForPromote >= needMoney
                                 */
                                throw new Exception("钱不够,还让执行setDiamondOwner");
                            }
                            Console.WriteLine($"需要用钱支付");
                            printState(player, car, $"支付前:costBusiness:{car.ability.costBusiness},costVolume:{car.ability.costVolume},needMoney:{needMoney}");

                            //var costBusiness1 = car.ability.costBusiness;
                            // bool needToUpdateCostBussiness;
                            car.ability.payForPromote(needMoney, player, car, ref notifyMsg);//用汽车上的钱支付
                            //if (needToUpdateCostBussiness)
                            //    AbilityChanged(player, car, ref notifyMsg, "business");

                            printState(player, car, $"支付后:costBusiness:{car.ability.costBusiness},costVolume:{car.ability.costVolume},needMoney:{needMoney}");

                            setPromtePosition(dor.changeType);
                            //this.promoteMilePosition = GetRandomPosition();
                            needUpdatePromoteState = true;
                            car.ability.setDiamondInCar(dor.changeType, player, car, ref notifyMsg);
                            // car.ability.diamondInCar = dor.changeType;
                            printState(player, car, "执行购买过程!需要立即执行返回!");
                            Thread th = new Thread(() => setReturn(0, new commandWithTime.returnning()
                            {
                                c          = "returnning",
                                key        = dor.key,
                                car        = dor.car,
                                returnPath = dor.returnPath,//returnPath_Record,
                                target     = dor.target,
                                changeType = dor.changeType,
                            }));
                            th.Start();
                            ;
                        }
                        else
                        {
                            Console.WriteLine("由于迟到没有执行购买过程!");

                            car.ability.setCostMiles(car.ability.costMiles + dor.costMile, player, car, ref notifyMsg);
                            //   car.ability.costMiles += dor.costMile;


                            //   AbilityChanged(player, car, ref notifyMsg, "mile");

                            Console.WriteLine($"{player.PlayerName}的{dor.car}执行完购买宝石过程,由于没有抢到,停在路上,待命中...!");
                            carParkOnRoad(dor.target, ref car, player, ref notifyMsg);

                            if (this.debug)
                            {
                            }

                            if (car.purpose == Purpose.@null && car.state == CarState.buying)
                            {
                                car.setState(player, ref notifyMsg, CarState.waitOnRoad);
                                //car.state = CarState.waitOnRoad;

                                this._Players[dor.key].returningRecord[dor.car] = dor.returnPath;
                            }
                            else
                            {
                                throw new Exception($"错误的目标{car.purpose } 和 状态{car.state}");
                            }
                            // car.state = CarState.waitOnRoad;
                        }
                    }
                    else
                    {
                        throw new Exception("car.state == CarState.buying!或者 dor.changeType不是四种类型");
                    }
                }
            }
            for (var i = 0; i < notifyMsg.Count; i += 2)
            {
                var url     = notifyMsg[i];
                var sendMsg = notifyMsg[i + 1];
                Console.WriteLine($"url:{url}");

                await Startup.sendMsg(url, sendMsg);
            }
            Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}执行setReturn结束");
            if (needUpdatePromoteState)
            {
                await CheckAllPlayersPromoteState(dor.changeType);
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="startT"></param>
        /// <param name="dor"></param>
        private void setDiamondOwner(commandWithTime.diamondOwner dor)
        {
            List <string> notifyMsg = new List <string>();
            bool          needUpdatePromoteState = false;

            lock (that.PlayerLock)
            {
                var player = that._Players[dor.key];
                var car    = that._Players[dor.key].getCar();
                {
                    if (car.state == CarState.working)
                    {
                        if (car.targetFpIndex == -1)
                        {
                            throw new Exception("居然来了一个没有目标的车!!!");
                        }
                        if (car.ability.diamondInCar != "")
                        {
                            /*
                             * 重复收集,立即返回!
                             */
                            car.setState(player, ref notifyMsg, CarState.returning);
                            that.retutnE.SetReturnT(0, new commandWithTime.returnning()
                            {
                                c            = "returnning",
                                changeType   = commandWithTime.returnning.ChangeType.BeforeTax,
                                key          = dor.key,
                                returningOjb = dor.returningOjb,
                                target       = dor.target
                            });
                        }
                        else if (dor.target == that.getPromoteState(dor.diamondType))
                        {
                            /*
                             * 这里,整个流程,保证玩家在开始任务的时候,钱是够的。如果不够,要爆异常的。
                             */
                            // var needMoney = that.promotePrice[dor.diamondType];
                            //if (car.ability.SumMoneyCanForPromote < needMoney)
                            //{
                            //    /*
                            //     * 这里,在逻辑上保证了car.ability.SumMoneyCanForPromote >=needMoney
                            //     * 首先在出发的时候就进行判断
                            //     * 其次,在promote地点选择的时候,会避免使用玩家的target.
                            //     * 最后保证了dor.target == this.getPromoteState(dor.changeType) 条件下,
                            //     * 肯定car.ability.SumMoneyCanForPromote >= needMoney
                            //     */
                            //    throw new Exception("钱不够,还让执行setDiamondOwner");
                            //}
                            //  Console.WriteLine($"需要用钱支付");
                            // car.ability.payForPromote(needMoney, player, car, ref notifyMsg);//用汽车上的钱支付

                            that.setPromtePosition(dor.diamondType);
                            //this.promoteMilePosition = GetRandomPosition();
                            needUpdatePromoteState = true;
                            car.ability.setDiamondInCar(dor.diamondType, player, car, ref notifyMsg);
                            // car.ability.diamondInCar = dor.changeType;
                            //car.setState(player, ref notifyMsg, CarState.waitOnRoad);
                            //car.ability.setCostMiles(car.ability.costMiles + dor.costMile, player, car, ref notifyMsg);
                            car.ability.setCostMiles(car.ability.costMiles + dor.costMile, player, car, ref notifyMsg);
                            // carParkOnRoad(dor.target, ref car, player, ref notifyMsg);
                            car.setState(player, ref notifyMsg, CarState.returning);
                            that.retutnE.SetReturnT(0, new commandWithTime.returnning()
                            {
                                c            = "returnning",
                                changeType   = commandWithTime.returnning.ChangeType.BeforeTax,
                                key          = dor.key,
                                returningOjb = dor.returningOjb,
                                target       = dor.target
                            });
                            that._Players[dor.key].returningOjb = dor.returningOjb;
                        }
                        else
                        {
                            WebNotify(player, "车来迟了,宝石被别人买走啦!");
                            carParkOnRoad(dor.target, ref car, player, ref notifyMsg);
                            car.setState(player, ref notifyMsg, CarState.waitOnRoad);
                            that._Players[dor.key].returningOjb = dor.returningOjb;

                            //player.
                        }
                    }
                    else
                    {
                        throw new Exception("car.state == CarState.buying!或者 dor.changeType不是四种类型");
                    }
                }
            }
            for (var i = 0; i < notifyMsg.Count; i += 2)
            {
                var url     = notifyMsg[i];
                var sendMsg = notifyMsg[i + 1];
                Startup.sendMsg(url, sendMsg);
            }
            //  Console.WriteLine($"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}执行setReturn结束");
            if (needUpdatePromoteState)
            {
                that.CheckAllPlayersPromoteState(dor.diamondType);
            }
        }