internal async void ClearPlayers() { // return; List <string> notifyMsg = new List <string>(); lock (this.PlayerLock) { List <string> keysOfAll = new List <string>(); List <string> keysNeedToClear = new List <string>(); foreach (var item in this._Players) { if (item.Value.Bust) { List <int> indexAll = new List <int>() { 0, 1, 2, 3, 4 }; var countAtBaseStation = (from indexItem in indexAll where item.Value.getCar(indexItem).state == CarState.waitAtBaseStation select indexItem).Count(); if (countAtBaseStation == 5) { keysNeedToClear.Add(item.Key); // this._Players.Remove(keysNeedToClear[i]); //for (var j = 0; j < keysOfAll.Count; j++) //{ // if (this._Players[keysOfAll[j]].others.ContainsKey(keysNeedToClear[i])) // { // this._Players[keysOfAll[j]].others.Remove(keysNeedToClear[i]); // } // if (this._Players[keysOfAll[j]].DebtsContainsKey(keysNeedToClear[i])) // { // this._Players[keysOfAll[j]].DebtsRemove(keysNeedToClear[i]); // } //} //continue; } else { keysOfAll.Add(item.Key); } } else { keysOfAll.Add(item.Key); } } for (var i = 0; i < keysNeedToClear.Count; i++) { this._Players.Remove(keysNeedToClear[i]); for (var j = 0; j < keysOfAll.Count; j++) { if (this._Players[keysOfAll[j]].othersContainsKey(keysNeedToClear[i])) { this._Players[keysOfAll[j]].othersRemove(keysNeedToClear[i], ref notifyMsg); } if (this._Players[keysOfAll[j]].DebtsContainsKey(keysNeedToClear[i])) { this._Players[keysOfAll[j]].DebtsRemove(keysNeedToClear[i], ref notifyMsg); } // if (this._Players[keysOfAll[j]].(keysNeedToClear[i])). } continue; } } 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); } }
internal async Task <string> SetAbility(SetAbility sa) { if (string.IsNullOrEmpty(sa.car)) { return("wrong car"); } else if (!(sa.car == "carA" || sa.car == "carB" || sa.car == "carC" || sa.car == "carD" || sa.car == "carE")) { return($"wrong car:{sa.car}"); } else if (string.IsNullOrEmpty(sa.pType)) { return($"wrong pType:{sa.pType}"); } else if (!(sa.pType == "mile" || sa.pType == "business" || sa.pType == "volume" || sa.pType == "speed")) { return($"wrong pType:{sa.pType}");; } else { List <string> notifyMsg = new List <string>(); lock (this.PlayerLock) { if (this._Players.ContainsKey(sa.Key)) { var carIndex = getCarIndex(sa.car); var player = this._Players[sa.Key]; var car = player.getCar(carIndex); if (player.Bust) { WebNotify(player, "您已破产"); return($"{player.Key} go bust!"); #warning 这里要提示前台,已经进行破产清算了。 } else { switch (sa.pType) { case "mile": case "business": case "volume": case "speed": { if (player.PromoteDiamondCount[sa.pType] > 0) { car.ability.AbilityAdd(sa.pType, player, car, ref notifyMsg); player.PromoteDiamondCount[sa.pType]--; SendPromoteCountOfPlayer(sa.pType, player, ref notifyMsg); } }; break; } } } else { return($"not has player-{sa.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"); } }