Beispiel #1
0
        internal static async Task <string> setPromote(State s, Promote promote)
        {
            if (promote.pType == "mile" || promote.pType == "business" || promote.pType == "volume" || promote.pType == "speed")
            {
                // string A = "carA_bb6a1ef1cb8c5193bec80b7752c6d54c";
                // A = Console.ReadLine();
                //Regex r = new Regex("^car_(?<key>[a-f0-9]{32})$");

                //var m = r.Match(promote.car);
                //if (m.Success)
                {
                    // Console.WriteLine($"正则匹配成功:{m.Groups["car"] }+{m.Groups["key"] }");
                    // if (m.Groups["key"].Value == s.Key)
                    {
                        var getPosition = new SetPromote()
                        {
                            c     = "SetPromote",
                            Key   = s.Key,
                            pType = promote.pType
                        };
                        var msg = Newtonsoft.Json.JsonConvert.SerializeObject(getPosition);
                        await Startup.sendInmationToUrlAndGetRes(Room.roomUrls[s.roomIndex], msg);
                    }
                }

                //var "carA_bb6a1ef1cb8c5193bec80b7752c6d54c"
            }
            return("");
        }
Beispiel #2
0
        private void StartDiamondOwnerThread(int startT, Car car, SetPromote sp, List <Model.MapGo.nyrqPosition> returnPath, int goMile)
        {
            Thread th = new Thread(() => setDiamondOwner(startT, new commandWithTime.diamondOwner()
            {
                c          = "diamondOwner",
                key        = sp.Key,
                returnPath = returnPath,
                target     = car.targetFpIndex,//新的起点
                changeType = sp.pType,
                costMile   = goMile
            }));

            th.Name = "DiamondOwner";
            th.Start();
        }
Beispiel #3
0
        private void setReturnWhenPromoteFailed(SetPromote sp, Car car)
        {
            // var carKey = $"{sp.car}_{sp.Key}";
            var    returnPath = this._Players[sp.Key].returningRecord[sp.car];//  this.returningRecord[carKey];
            Thread th         = new Thread(() => setReturn(0, new commandWithTime.returnning()
            {
                c          = "returnning",
                key        = sp.Key,
                car        = sp.car,
                returnPath = returnPath,        //returnPath_Record,
                target     = car.targetFpIndex, //这里的target 实际上是returnning 的起点,是汽车的上一个目标
                changeType = sp.pType,
            }));

            th.Start();
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="player"></param>
        /// <param name="car"></param>
        /// <param name="sp"></param>
        /// <param name="notifyMsg"></param>
        /// <returns>true:表示已执行;false,表示各种原因(去不了、去了回不来)未执行。</returns>
        bool promote(Player player, Car car, SetPromote sp, ref List <string> notifyMsg, out MileResultReason reason)
        {
            var from = this.getFromWhenUpdatePromote(player, car);
            var to   = GetPromotePositionTo(sp.pType);//  this.promoteMilePosition;

            var fp1    = Program.dt.GetFpByIndex(from);
            var fp2    = Program.dt.GetFpByIndex(to);
            var baseFp = Program.dt.GetFpByIndex(player.StartFPIndex);

            //var goPath = Program.dt.GetAFromB(fp1, fp2.FastenPositionID);
            //var returnPath = Program.dt.GetAFromB(fp2, baseFp.FastenPositionID);
            // var goPath = Program.dt.GetAFromB(from, to);
            var goPath = this.GetAFromB(from, to, player, ref notifyMsg);
            // var returnPath = Program.dt.GetAFromB(to, player.StartFPIndex);
            var returnPath = this.GetAFromB(to, player.StartFPIndex, player, ref notifyMsg);

            var goMile     = GetMile(goPath);
            var returnMile = GetMile(returnPath);


            //第一步,计算去程和回程。
            if (car.ability.leftMile >= goMile + returnMile)
            {
                int startT;
                EditCarStateWhenPromoteStartOK(player, ref car, to, fp1, to, sp, goPath, ref notifyMsg, out startT);
                StartDiamondOwnerThread(startT, car, sp, returnPath, goMile);
                //  getAllCarInfomations(sp.Key, ref notifyMsg);
                reason = MileResultReason.Abundant;
                return(true);
            }

            else if (car.ability.leftMile >= goMile)
            {
                printState(player, car, $"去程{goMile},回程{returnMile},去了回不来");
                reason = MileResultReason.CanNotReturn;
                return(false);
            }
            else
            {
                printState(player, car, $"去程{goMile},回程{returnMile},去不了");
                reason = MileResultReason.CanNotReach;
                return(false);
            }
        }
Beispiel #5
0
 public string updatePromote(SetPromote sp)
 {
     return(this.promoteE.updatePromote(sp));
 }
Beispiel #6
0
        private void EditCarStateWhenPromoteStartOK(Player player, ref Car car, int to, Model.FastonPosition fp1, int to2, SetPromote sp, List <Model.MapGo.nyrqPosition> goPath, ref List <string> nofityMsgs, out int startT)
        {
            car.targetFpIndex = to; //A.更改小车目标,在其他地方引用。
                                    //  car.changeState++;//B.更改状态用去前台更新动画

            /*
             * C.更新小车动画参数
             */
            var speed = car.ability.Speed;

            startT = 0;
            List <Data.PathResult> result;

            if (car.state == CarState.waitOnRoad)
            {
                result = new List <Data.PathResult>();
            }
            else if (car.state == CarState.waitAtBaseStation)
            {
                result = getStartPositon(fp1, sp.car, ref startT);
            }
            else if (car.state == CarState.waitForCollectOrAttack)
            {
                result = new List <Data.PathResult>();
            }
            else if (car.state == CarState.waitForTaxOrAttack)
            {
                result = new List <Data.PathResult>();
            }
            else
            {
                Console.WriteLine($"{Newtonsoft.Json.JsonConvert.SerializeObject(car)}");
                throw new Exception("错误的汽车类型!!!");
            }
            Program.dt.GetAFromBPoint(goPath, fp1, speed, ref result, ref startT);
            result.RemoveAll(item => item.t0 == item.t1);

            var animateData = new AnimateData()
            {
                animateData = result,
                recordTime  = DateTime.Now
            };

            car.setAnimateData(player, ref nofityMsgs, animateData);
            //car.animateData = new AnimateData()
            //{
            //    animateData = result,
            //    recordTime = DateTime.Now
            //};
            car.setState(player, ref nofityMsgs, CarState.buying);
            //  car.state = CarState.buying;//更改汽车状态

            //Thread th = new Thread(() => setDiamondOwner(startT, new commandWithTime.diamondOwner()
            //{
            //    c = "diamondOwner",
            //    key = sp.Key,
            //    car = sp.car,
            //    returnPath = returnPath,
            //    target = to,//新的起点
            //    changeType = sp.pType,
            //    costMile = goMile
            //}));
            //th.Start();
            //car.changeState++;//更改状态

            //getAllCarInfomations(sp.Key, ref notifyMsg);
        }
Beispiel #7
0
        internal async Task <string> updatePromote(SetPromote sp)
        {
            throw new Exception("作废!");
            //{"Key":"1faff8e98891e33f6defc9597354c08b","pType":"mile","car":"carE","c":"SetPromote"}
            //  Console.WriteLine($"{Newtonsoft.Json.JsonConvert.SerializeObject(sp)}");
            //return "";
            if (string.IsNullOrEmpty(sp.car))
            {
                return("wrong car");
            }
            else if (!(sp.car == "carA" || sp.car == "carB" || sp.car == "carC" || sp.car == "carD" || sp.car == "carE"))
            {
                return($"wrong car:{sp.car}");
            }
            else if (string.IsNullOrEmpty(sp.pType))
            {
                return($"wrong pType:{sp.pType}");
            }
            else if (!(sp.pType == "mile" || sp.pType == "business" || sp.pType == "volume" || sp.pType == "speed"))
            {
                return($"wrong pType:{sp.pType}");;
            }
            else
            {
                var           carIndex  = getCarIndex(sp.car);
                List <string> notifyMsg = new List <string>();
                var           player    = this._Players[sp.Key];
                var           car       = player.getCar(carIndex);
                if (player.Bust)
                {
                    WebNotify(player, "您已破产");
                    return($"{player.Key} go bust!");

#warning 这里要提示前台,已经进行破产清算了。
                }
                else
                {
                    lock (this.PlayerLock)
                    {
                        if (this._Players.ContainsKey(sp.Key))
                        {
                            //if(sp.pType=="mi")
                            switch (sp.pType)
                            {
                            case "mile":
                            case "business":
                            case "volume":
                            case "speed":
                            {
                                switch (car.purpose)
                                {
                                case Purpose.@null:
                                {
                                    switch (car.state)
                                    {
                                    case CarState.waitAtBaseStation:
                                    {
                                        // if(player.Money<)
                                        var moneyIsEnoughToStart = giveMoneyFromPlayerToCarForPromoting(player, car, sp.pType, ref notifyMsg);
                                        if (moneyIsEnoughToStart)
                                        {
                                            MileResultReason reason;
                                            var hasBeginToPromote = promote(player, car, sp, ref notifyMsg, out reason);
                                            if (hasBeginToPromote)
                                            {
                                                WebNotify(player, $"{car.name}在路上寻找能力宝石的路上了!!!");
                                                printState(player, car, "开始在路上寻找能力宝石的路上了!!!");
                                            }
                                            else
                                            {
                                                if (reason == MileResultReason.CanNotReach)
                                                {
                                                    WebNotify(player, $"{car.name}的剩余里程不足以支持到达目的地!");
                                                    //WebNotify(player, $"资金不够,{car.name}未能上路!!!");
                                                }
                                                else if (reason == MileResultReason.CanNotReturn)
                                                {
                                                    WebNotify(player, $"到达目的地后,{car.name}的剩余里程不足以支持返回!");
                                                }
                                                printState(player, car, "各种原因,不能开始!");
                                                giveMoneyFromCarToPlayer(player, car, ref notifyMsg);
                                            }
                                        }
                                        else
                                        {
                                            WebNotify(player, $"钱不够了,由于本身待在基地,不用返回");
                                            printState(player, car, "钱不够了,由于本身待在基地,不用返回。");
                                        }
                                    }; break;

                                    case CarState.waitOnRoad:
                                    {
                                        if (car.ability.diamondInCar == "")
                                        {
                                            if (car.ability.SumMoneyCanForPromote >= this.promotePrice[sp.pType])
                                            {
                                                MileResultReason reason;
                                                var hasBeginToPromote = promote(player, car, sp, ref notifyMsg, out reason);
                                                if (hasBeginToPromote)
                                                {
                                                    WebNotify(player, $"{car.name}在路上寻找能力宝石的路上了!!!");
                                                    printState(player, car, $"已经在收集{sp.pType}宝石的路上了!");
                                                }
                                                else
                                                {
                                                    if (reason == MileResultReason.CanNotReach)
                                                    {
                                                        WebNotify(player, $"{car.name}的剩余里程不足以支持到达目的地!");
                                                        //WebNotify(player, $"资金不够,{car.name}未能上路!!!");
                                                    }
                                                    else if (reason == MileResultReason.CanNotReturn)
                                                    {
                                                        WebNotify(player, $"到达目的地后,{car.name}的剩余里程不足以支持返回!");
                                                    }
                                                    printState(player, car, "收集宝石剩余里程不足,必须立即返回!");
                                                    setReturnWhenPromoteFailed(sp, car);
                                                }
                                            }
                                            else
                                            {
                                                WebNotify(player, $"资金不够,{car.name}被安排返航!!!");
                                                printState(player, car, "在路上走的车,想找宝石,钱不够啊,必须立即返回!");
                                                Console.WriteLine($"宝石的价格{this.promotePrice[sp.pType]},钱不够啊,{car.ability.costBusiness},{car.ability.costVolume}!");
#warning 在路上,由于资金不够,这里没有能测到。
                                                setReturnWhenPromoteFailed(sp, car);
                                            }
                                        }
                                        else
                                        {
                                            Console.WriteLine("在路上走的车,有了宝石,居然没返回!");
                                            //throw new Exception();
                                        }
                                    }; break;

                                    default:
                                    {
                                        var msg = $"{car.state.ToString()}状态下不能提升能力!";
                                        Console.WriteLine(msg);
                                    }; break;
                                    }
                                }; break;

                                default:
                                {
                                    Console.WriteLine($"{car.purpose}状态下不能获取提升能力宝石了!");
                                    return($"{car.purpose}-state can not do action !");
                                }; break;
                                }
                            }; break;
                            }
                        }
                        else
                        {
                            return($"not has player-{sp.Key}!");
                        }
                    }
                }
                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);
                }
                return("ok");
            }
        }
        internal void StartDiamondOwnerThread(int startT, int step, RoleInGame player, Car car, SetPromote sp, RoomMainF.RoomMain.commandWithTime.ReturningOjb ro, int goMile, Node goPath)
        {
            System.Threading.Thread th = new System.Threading.Thread(() =>
            {
                if (step >= goPath.path.Count - 1)
                {
                    this.startNewThread(startT + 100, new commandWithTime.diamondOwner()
                    {
                        c            = "diamondOwner",
                        key          = sp.Key,
                        target       = car.targetFpIndex,//新的起点
                        changeType   = commandWithTime.returnning.ChangeType.BeforeTax,
                        costMile     = goMile,
                        returningOjb = ro,
                        diamondType  = sp.pType
                    }, this);
                }
                //that.debtE.setDebtT(startT, car, sa, goMile, ro);
                //this.startNewThread(startT, new commandWithTime.defenseSet()
                //{
                //    c = command,
                //    changeType = commandWithTime.returnning.ChangeType.BeforeTax,
                //    costMile = goMile,
                //    key = ms.Key,
                //    returningOjb = ro,
                //    target = car.targetFpIndex,
                //    beneficiary = ms.targetOwner
                //}, this);
                else
                {
                    if (step == 0)
                    {
                        this.ThreadSleep(startT);
                        if (player.playerType == RoleInGame.PlayerType.NPC || player.Bust)
                        {
                        }
                        else
                        {
                            StartSelectThread(goPath.path[step].selections, goPath.path[step].selectionCenter, (Player)player);
                        }

                        List <string> notifyMsg = new List <string>();
                        int newStartT;
                        step++;
                        if (step < goPath.path.Count)
                        {
                            EditCarStateAfterSelect(step, player, ref car, goPath, ref notifyMsg, out newStartT);
                        }
                        else
                        {
                            newStartT = 0;
                        }

                        car.setState(player, ref notifyMsg, CarState.working);
                        this.sendMsg(notifyMsg);
                        //string command, int startT, int step, RoleInGame player, Car car, MagicSkill ms, int goMile, Node goPath, commandWithTime.ReturningOjb ro
                        StartDiamondOwnerThread(newStartT, step, player, car, sp, ro, goMile, goPath);
                    }
                    else
                    {
                        this.ThreadSleep(startT);
                        if (player.playerType == RoleInGame.PlayerType.NPC || player.Bust)
                        {
                        }
                        else if (startT != 0)
                        {
                            StartSelectThread(goPath.path[step].selections, goPath.path[step].selectionCenter, (Player)player);
                        }
                        step++;
                        List <string> notifyMsg = new List <string>();
                        int newStartT;
                        if (step < goPath.path.Count)
                        {
                            EditCarStateAfterSelect(step, player, ref car, goPath, ref notifyMsg, out newStartT);
                        }
                        // else if(step==goPath.path.Count-1)
                        //EditCarStateAfterSelect(step,player,ref car,)
                        else
                        {
                            throw new Exception("这种情况不会出现");
                        }
                        //newStartT = 0;
                        car.setState(player, ref notifyMsg, CarState.working);
                        this.sendMsg(notifyMsg);
                        StartDiamondOwnerThread(newStartT, step, player, car, sp, ro, goMile, goPath);
                    }
                }
            });
            th.Start();
            //throw new NotImplementedException();

            //Thread th = new Thread(() => setDiamondOwner(startT, ));
            //th.Name = $"{sp.Key}-DiamondOwner";
            //th.Start();
        }
Beispiel #9
0
 internal string updatePromote(SetPromote sp)
 {
     return(this.updateAction(this, sp, sp.Key));
 }
Beispiel #10
0
        private commandWithTime.ReturningOjb promotePassBossAddress(RoleInGame player, RoleInGame boss, Car car, SetPromote sp, ref List <string> notifyMsg, out MileResultReason mrr)
        {
            switch (sp.pType)
            {
            case "mile":
            case "business":
            case "volume":
            case "speed":
            {
                switch (car.state)
                {
                case CarState.waitAtBaseStation:
                {
                    // if(player.Money<)
                    //int collectIndex;
                    OssModel.FastonPosition fpResult;
                    var distanceIsEnoughToStart = that.theNearestToDiamondIsCarNotMoney(player, car, sp.pType, out fpResult);
                    if (distanceIsEnoughToStart)
                    {
                        var from = this.getFromWhenAction(player, car);
                        var to   = that.GetPromotePositionTo(sp.pType);              //  this.promoteMilePosition;

                        var fp1    = Program.dt.GetFpByIndex(from);
                        var fp2    = Program.dt.GetFpByIndex(to);
                        var baseFp = Program.dt.GetFpByIndex(player.StartFPIndex);
                        var goPath = that.GetAFromB_v2(from, to, player, ref notifyMsg);
                        // var returnPath = Program.dt.GetAFromB(to, player.StartFPIndex);
                        var returnToBossPath = that.GetAFromB_v2(to, boss.StartFPIndex, player, ref notifyMsg);
                        var returnToSelfPath = that.GetAFromB_v2(boss.StartFPIndex, player.StartFPIndex, player, ref notifyMsg);

                        var goMile           = that.GetMile(goPath);
                        var returnToBossMile = that.GetMile(returnToBossPath);
                        var returnToSelfMile = that.GetMile(returnToSelfPath);

                        //第一步,计算去程和回程。
                        if (car.ability.leftMile >= goMile + returnToBossMile + returnToSelfMile)
                        {
                            int startT;
                            this.EditCarStateWhenActionStartOK(player, ref car, to, fp1, goPath, ref notifyMsg, out startT);
                            RoomMainF.RoomMain.commandWithTime.ReturningOjb ro = commandWithTime.ReturningOjb.ojbWithBoss(returnToBossPath, returnToSelfPath, boss);
                            that.diamondOwnerE.StartDiamondOwnerThread(startT, 0, player, car, sp, ro, goMile, goPath);
                            //  getAllCarInfomations(sp.Key, ref notifyMsg);
                            mrr = MileResultReason.Abundant;
                            return(ro);
                        }

                        else if (car.ability.leftMile >= goMile)
                        {
                            WebNotify(player, $"去程{goMile}km,回程{returnToBossMile + returnToSelfMile}km,去了回不来");
                            mrr = MileResultReason.CanNotReturn;
                            return(player.returningOjb);
                        }
                        else
                        {
                            WebNotify(player, $"去程{goMile}km,回程{returnToBossMile + returnToSelfMile}km,去不了");
                            // printState(player, car, $"去程{goMile},回程{returnMile},去不了");
                            mrr = MileResultReason.CanNotReach;
                            return(player.returningOjb);
                        }
                    }
                    else
                    {
                        mrr = MileResultReason.NearestIsMoneyWhenPromote;
                        this.WebNotify(player, $"离宝石最近的是[{fpResult.FastenPositionName}]处的钱,不是你的车。请离宝石再近点儿!");
                        return(player.returningOjb);
                        //printState(player, car, "钱不够了,由于本身待在基地,不用返回。");
                    }
                };

                case CarState.waitOnRoad:
                {
                    OssModel.FastonPosition fpResult;
                    var distanceIsEnoughToStart = that.theNearestToDiamondIsCarNotMoney(player, car, sp.pType, out fpResult);
                    if (distanceIsEnoughToStart)
                    {
                        var from = this.getFromWhenAction(player, car);
                        var to   = that.GetPromotePositionTo(sp.pType);              //  this.promoteMilePosition;

                        var fp1    = Program.dt.GetFpByIndex(from);
                        var fp2    = Program.dt.GetFpByIndex(to);
                        var baseFp = Program.dt.GetFpByIndex(player.StartFPIndex);
                        var goPath = that.GetAFromB_v2(from, to, player, ref notifyMsg);

                        var returnToBossPath = that.GetAFromB_v2(to, boss.StartFPIndex, player, ref notifyMsg);
                        var returnToSelfPath = that.GetAFromB_v2(boss.StartFPIndex, player.StartFPIndex, player, ref notifyMsg);

                        var goMile           = that.GetMile(goPath);
                        var returnToBossMile = that.GetMile(returnToBossPath);
                        var returnToSelfMile = that.GetMile(returnToSelfPath);


                        //第一步,计算去程和回程。
                        if (car.ability.leftMile >= goMile + returnToBossMile + returnToSelfMile)
                        {
                            int startT;
                            this.EditCarStateWhenActionStartOK(player, ref car, to, fp1, goPath, ref notifyMsg, out startT);

                            RoomMainF.RoomMain.commandWithTime.ReturningOjb ro = commandWithTime.ReturningOjb.ojbWithBoss(returnToBossPath, returnToSelfPath, boss);
                            that.diamondOwnerE.StartDiamondOwnerThread(startT, 0, player, car, sp, ro, goMile, goPath);
                            mrr = MileResultReason.Abundant;
                            return(ro);
                        }

                        else if (car.ability.leftMile >= goMile)
                        {
                            WebNotify(player, $"去程{goMile}km,回程{returnToBossMile + returnToSelfMile}km,去了回不来");
                            mrr = MileResultReason.CanNotReturn;
                            return(player.returningOjb);
                        }
                        else
                        {
                            WebNotify(player, $"去程{goMile}km,回程{returnToBossMile + returnToSelfMile}km,去不了");
                            mrr = MileResultReason.CanNotReach;
                            return(player.returningOjb);
                        }
                    }
                    else
                    {
                        mrr = MileResultReason.NearestIsMoneyWhenPromote;
                        this.WebNotify(player, $"离宝石最近的是[{fpResult.FastenPositionName}]处的钱,不是你的车。请离宝石再近点儿!");
                        return(player.returningOjb);
                    }
                };

                default:
                {
                    throw new Exception($"{Enum.GetName(typeof(CarState), car.state)}不是注册的类型!");
                }
                }
            };

            default:
            {
                throw new Exception($"{sp.pType}-不是规定的输入!");
            };
            }
        }