public async Task <ApiError> InsertAsync(BeanModel model) { var checkresult = await ValidateModelAsync(model); if (!checkresult.Successful) { return(checkresult); } BeanEntity entity = model !; try { var result = await _beanRepository.InsertAsync(entity); if (result.Successful) { model.Id = entity.Id; } return(ApiError.FromDalResult(result)); } catch (Exception ex) { return(ApiError.FromException(ex)); } }
public async Task <ApiError> UpdateAsync(BeanModel model) { var checkresult = await ValidateModelAsync(model, true, true); if (!checkresult.Successful) { return(checkresult); } BeanEntity entity = model !; try { return(ApiError.FromDalResult(await _beanRepository.UpdateAsync(entity))); } catch (Exception ex) { return(ApiError.FromException(ex)); } }
//决策,生成该战术的细节,出牌位置和移动方案 public override void thinkTactic() { BeanEntity bean = (BeanEntity)this.target; double priority = this.important; this.cardPriority = priority * 0.1; this.movePriority = priority * 0.8; this.life = 0; this.move = 2000 * priority + 500; this.damage = 0; this.control = 0; this.push = 0; this.setMoveAim(bean.position); this.floatMoveAim(50); this.cardAimPosition = this.moveAimPosition.clone(); // this.cardAimPosition.copy(this.moveAimPosition); }
public async Task <DalResult> InsertAsync(MovementEntity movement, BeanEntity bean) { if (movement is null) { throw new ArgumentNullException(nameof(movement)); } if (bean is null) { throw new ArgumentNullException(nameof(bean)); } using var conn = new SqlConnection(ConnectionString); await conn.OpenAsync(); using var transaction = await conn.BeginTransactionAsync(); try { var result = await conn.InsertAsync(movement, transaction : transaction); movement.Id = result; var beanresult = await conn.UpdateAsync(bean, transaction : transaction); await transaction.CommitAsync(); return(beanresult ? DalResult.Success : DalResult.NotFound); } catch (Exception ex) { await transaction.RollbackAsync(); return(DalResult.FromException(ex)); } finally { await conn.CloseAsync(); } }
public async Task <ApiError> InsertAsync(MovementModel movement, BeanModel bean) { var checkresult = await ValidateModelAsync(movement); if (!checkresult.Successful) { return(checkresult); } if (bean is null) { return(new(string.Format(Strings.Invalid, "bean model"))); } MovementEntity movementEntity = movement !; BeanEntity beanEntity = bean !; try { return(ApiError.FromDalResult(await _movementRepository.InsertAsync(movementEntity, beanEntity))); } catch (Exception ex) { return(ApiError.FromException(ex)); } }
///判断条件,满足条件的战术,都压进去 public void addTactics() { //判断条件,满足条件的战术,都压进去 double important; int i, len; double distance; //自身中了控制 //ai级别 double IQ = this._aiPlayer.IQ; //对自己的评估 AssessPlayer selfAssess = this._aiPlayer.selfAssess; FindController findController = this._aiPlayer.findController; //自身血量低,回复生命类 // important = (AIConstant.HP_PER_MIDDLE - this._aiPlayer.selfAssess.hpPer)/AIConstant.HP_PER_MIDDLE * IQ; // if (important>0) { // CheckAddTactic (new DyingTactic (ai, null, important)); // } //自身短暂未来会出现在的位置,子弹、玩家、道具与之判断距离和重要性时都依照此位置判断 Vector2D ownerForecastPosition = selfAssess.getForecastPosition(AIConstant.FORECAST_TIME * (0.5 + IQ)); if (this._map.mapData.isTeam) { //如果抢萝卜模式,之后再实现AI } //应对附近有子弹,只考虑最近4个,中低级AI几乎不用 // if (this.getRandom() < IQ*0.8) { // len = findController.findBulletList.Count; // for (i = 0; i < len; i++) { // BulletEntity bullet = findController.findBulletList [i]; // if (bullet.alived) { // distance = Collision.realPosition(ownerForecastPosition,bullet.position,this._map.mapData).deltaPos.length; //// important = Math.Min (Math.Min ((AIConfig.AI_FIND_RADIUS - distance) / 1500, 1), 1) * AIValue; // important = Math.Min (Math.Min ((2500- distance) / 1500, 1) * (0.9 + bullet.atk / this._aiPlayer.player.hp), 1) * (IQ+0.2); // // checkAddTactic (new BulletTactic (this._aiPlayer, bullet, important)); // } // } // } //应对附近有敌人玩家 if (this.getRandom() < IQ * 2) { len = findController.findEnemyPlayerList.Count; for (i = 0; i < len; i++) { PlayerEntity player = findController.findEnemyPlayerList [i]; if (player.alived) { distance = Collision.realPosition(ownerForecastPosition, player.position, this._map.mapData).deltaPos.length; important = Math.Min((2500 - distance) / 1500, 1) * (IQ * 0.5 + 0.5); if (this._map.mapData.isChaos) { //如果是乱斗前3名玩家,有更高可能性被针对 int scoreIndex = this._map.getSortPlayer(1).IndexOf(player); if (scoreIndex < 3) { important += (3 - scoreIndex) * 0.25 * IQ; } } //如果血很少,很容易被针对 double hpPer = selfAssess.hpPer; if (hpPer < AIConstant.HP_PER_NEAR_MAX) { important += (AIConstant.HP_PER_NEAR_MAX - hpPer) * 0.8 * IQ; } //仇恨列表中的玩家,针对性大大提升 AssessPlayer assessPlayer = this._aiPlayer.assessController.getAssessPlayer(player.uid); important += assessPlayer.anger * 0.6 * (IQ + 0.5); this.checkAddTactic(new PlayerTactic(this._aiPlayer, player, important)); } } } //应对附近有多个道具,低级AI几乎不用 if (this.getRandom() < IQ * 1.4) { len = findController.findBeanList.Count; if (len > 0) { //确定玩家对于能量和生命的需求 double powerImportant = selfAssess.needPowerCardCount * 0.34; double scoreImportant = 1; double hpImportant = 0.05 + (1 - selfAssess.hpPer); //每种类型的道具只考虑最近的一个 Dictionary <int, BeanEntity> beans = new Dictionary <int, BeanEntity> (); //如果数量特别庞大,以格子内的总价值集中地作为特殊目标策略进行思考 for (i = 0; i < len; i++) { BeanEntity bean = findController.findBeanList [i]; if (bean.canUse) { if (beans.ContainsKey(bean.itemType)) { continue; } beans.Add(bean.itemType, bean); distance = Collision.realPosition(ownerForecastPosition, bean.position, this._map.mapData).deltaPos.length; // Debug.Log ("distance "+distance); //该道具吻合玩家需求的程度 important = bean.beanVO.power * 0.001 * powerImportant * (IQ + 0.5); important += bean.beanVO.score * 0.0001 * scoreImportant * (IQ + 1); important += bean.beanVO.cure * hpImportant * 30 * (IQ + 1); //根据距离修正,但如果没有需求,就基本不重要 important *= Math.Min((2500 - distance) / 1500, 1); if (important > AIConstant.MESS_IMPORTANT) { this.checkAddTactic(new BeanTactic(this._aiPlayer, bean, important)); } } } } } //如果有装备冷却完毕,立即使用,低级AI几乎不用 if (this.getRandom() < IQ * 1) { important = IQ + 0.1; this.checkAddTactic(new PartTactic(this._aiPlayer, null, important)); } //无条件的乱走乱扔牌战术 important = AIConstant.MESS_IMPORTANT; addTactic(new MessTactic(this._aiPlayer, null, important)); //遗忘上一次考虑过的战术 this.lastTacticTargetList.Clear(); }