Пример #1
0
        /// <summary>
        /// 组织数据
        /// </summary>
        /// <param name="vo"></param>
        /// <returns></returns>
        private ASObject BuildData(WarFightVo vo)
        {
            var dic = new Dictionary <string, object>()
            {
                { "result", (int)ResultType.SUCCESS },
                { "fight", vo },
            };

            return(new ASObject(dic));
        }
Пример #2
0
        /// <summary>
        /// 战斗结束
        /// </summary>
        /// <param name="player"></param>
        /// <param name="cityinfo"></param>
        /// <param name="defenseuserid"></param>
        /// <param name="fightvo"></param>
        /// <param name="bq"></param>
        /// <returns></returns>
        private bool GetFightEnd(Player player, tg_war_city cityinfo, Int64 defenseuserid, WarFightVo fightvo, tg_war_battle_queue bq)
        {
            var defenseuser = tg_user.FindByid(defenseuserid);
            var own         = Variable.BASE_OFFICE.FirstOrDefault(q => q.id == player.User.office); //占有度查询

            if (own == null)
            {
                return(false);
            }
            var left     = own.total_own - player.UserExtend.war_total_own;
            var basesize = Variable.BASE_WARCITYSIZE.FirstOrDefault(q => q.id == cityinfo.size);

            if (basesize == null)
            {
                return(false);
            }
            var defenseextend = tg_user_extend.GetByUserId(defenseuserid);

            if (fightvo.result.isWin == 1) //出征成功,攻防胜利且占有度足够
            {
                //游戏战报
                WarReportInsert(player.User.id, 100042, cityinfo.base_id, defenseuserid, player.User.player_name);
                if (left >= basesize.own) //占有度足够
                {
                    var rivalUserId = cityinfo.user_id;
                    var planlist    = GetCityPlanIds(cityinfo);
                    tg_war_city_plan.GetListDelete(planlist);        //删除所有的防守方案
                    player.UserExtend.war_total_own += basesize.own; //进攻玩家占有度使用增加

                    if (defenseextend.war_total_own >= basesize.own) //防守玩家占有度使用减少
                    {
                        defenseextend.war_total_own -= basesize.own;
                    }
                    //城市资源结算,城市改为进攻方
                    CityWarResourse(cityinfo, player.User.id);
                    player.UserExtend.Update();
                    player.User.merit += (int)Math.Floor(fightvo.result.rivalDieCount * 0.5);
                    GetCityChange(defenseuserid, cityinfo, player.User.id);

                    #region  除内政策略

                    var flag = Variable.WarCityAll.Values.Count(m => m.user_id == rivalUserId) > 0;
                    if (!flag)
                    {
                        var temp = tg_war_home_tactics.GetEntityByUserid(rivalUserId);
                        if (temp != null)
                        {
                            (new Share.War()).RemoveCD((new Share.War()).GetKey(temp.end_time, rivalUserId));
                            temp.Delete();
                        }
                    }

                    #endregion
                }
                else
                {
                    CityWarResourse(cityinfo);
                    player.User.merit += (int)Math.Floor(fightvo.result.rivalDieCount * 0.5) + basesize.addMerit;
                }
                defenseuser.merit += (int)Math.Floor(fightvo.result.rivalDieCount * 0.1);

                fightvo.result.reward.Add(new RewardVo()
                {
                    goodsType = (int)GoodsType.TYPE_MERIT,
                    value     = player.User.merit,
                });
            }
            else
            {
                //游戏战报
                WarReportInsert(player.User.id, 100043, cityinfo.base_id, defenseuserid, player.User.player_name);
                player.User.merit += (int)Math.Floor(fightvo.result.rivalDieCount * 0.1);
                defenseuser.merit += (int)Math.Floor(fightvo.result.rivalDieCount * 0.5);
                fightvo.result.reward.Add(new RewardVo()
                {
                    goodsType = (int)GoodsType.TYPE_MERIT,
                    value     = player.User.merit,
                });
                //  new Share.War().QueueResultCity(bq);
            }
            //进攻玩家发送协议
            if (Variable.OnlinePlayer.ContainsKey(player.User.id))
            {
                player.User.Update();
                player.UserExtend.Update();
                var session = Variable.OnlinePlayer[player.User.id] as TGGSession;
                session.Player = player;
                (new Share.User()).REWARDS_API(player.User.id, fightvo.result.reward);
            }
            //防守玩家发送协议
            if (Variable.OnlinePlayer.ContainsKey(defenseuserid))
            {
                defenseuser.Update();
                var session = Variable.OnlinePlayer[defenseuserid] as TGGSession;
                session.Player.User       = defenseuser;
                session.Player.UserExtend = defenseextend;
                (new Share.User()).REWARDS_API(defenseuserid, fightvo.result.reward);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// 初始合战武将值
        /// </summary>
        /// <param name="fight">战斗实体</param>
        /// <param name="vo">战斗vo</param>
        private void GetFightRoles(WarFight fight, WarFightVo vo)
        {
            vo.roles = new List <WarFightRoleVo>();
            vo.roles.AddRange(fight.AttackRoles.Select(q => new WarFightRoleVo()
            {
                roleId   = q.RoleId,
                type     = 0,
                campType = 0,
                lines    = null,
                effects  = null,
                baseId   = q.Role.role_id,
                blood    = q.SoldierCount,
                roleName = q.roleName,
                point    = new PointVo()
                {
                    x = q.X, y = q.Y
                },
                armyBaseId = q.SoldierId,
            }));
            vo.roles.AddRange(fight.DefenseRoles.Select(q => new WarFightRoleVo()
            {
                baseId   = q.Role.role_id,
                roleId   = q.RoleId,
                campType = 1,
                type     = q.type,
                lines    = null,
                effects  = null,
                isNpc    = q.isNpc,
                blood    = q.SoldierCount,
                point    = new PointVo()
                {
                    x = q.X, y = q.Y
                },
                armyBaseId = q.SoldierId,
                roleName   = q.roleName
            }));
            vo.roles.Add(new WarFightRoleVo()
            {
                roleId   = fight.Door.RoleId,
                campType = 1,
                type     = fight.Door.type,
                blood    = fight.Door.SoldierCount,
                lines    = null,
                effects  = null,

                point = new PointVo()
                {
                    x = 2, y = 2
                }
            });
            vo.roles.Add(new WarFightRoleVo()
            {
                campType = 1,
                roleId   = fight.City.RoleId,
                type     = fight.City.type,
                blood    = fight.City.SoldierCount,
                lines    = null,
                effects  = null,

                point = new PointVo()
                {
                    x = 0, y = 4
                }
            });
        }
Пример #4
0
        /// <summary>
        ///  通过战斗模型得到战斗过程
        /// </summary>
        /// <returns></returns>
        public Tuple <int, WarFightVo> GetFightProcess(WarFight fight)
        {
            WarFightVo vo = new WarFightVo();

            vo.moves  = new List <WarMovesVo>();
            vo.result = new WarFightResultVo();
            //初始武将
            GetFightRoles(fight, vo);
            //回合开始
            for (int i = 1; i < 51; i++)
            {
#if DEBUG
                XTrace.WriteLine("--------- 回合数:{0}", i);
#endif
                var times = new WarMovesVo();
                times.roles = new List <WarFightRoleVo>();
                GetRoleBuff(fight, times);
                //天气和五常生成
                GetWeatherAndFive(fight, times, i);

                GetDarkRoleShow(fight.DefenseRoles);
                //循环武将
                for (var j = 0; j < fight.AttackSort.Count; j++)
                {
#if DEBUG
                    var t = vo.roles.Where(m => m.roleId == fight.AttackSort[j].RoleId).FirstOrDefault();
                    XTrace.WriteLine("武将id:{0} name:{4} 攻击值:{1} x:{2} y:{3}",
                                     t.baseId, t.blood, t.point.x, t.point.y, t.roleName
                                     );
#endif
                    if (fight.AttackSort[j].isDie)
                    {
                        continue;
                    }
                    if (fight.AttackSort[j].type == 2) //防守武将
                    {
                        var tuple = CheckDefenseRole(fight, fight.AttackSort[j].RoleId, times);
                        if (tuple.Item1 < 0)
                        {
                            return(null);
                        }
                        if (tuple.Item2)
                        {
                            vo.moves.Add(times);
                            var defensedie = fight.DefenseSoldierCount - fight.DefenseRoles.Sum(q => q.SoldierCount);
                            var attackdie  = fight.AttackSoldierCount - fight.AttackRoles.Sum(q => q.SoldierCount);
                            RolesCountUpdate(fight.DefenseRoles, fight.AttackRoles);
                            vo.result.myDieCount    = attackdie;
                            vo.result.rivalDieCount = defensedie;
                            if (fight.City.SoldierCount <= 0)
                            {
                                vo.result.isWin = 1;
                            }
                            return(Tuple.Create((int)ResultType.SUCCESS, vo));
                        }
                    }
                    else
                    {
                        var tuple = CheckAttackRole(fight, fight.AttackSort[j].RoleId, times);
                        if (tuple.Item1 < 0)
                        {
                            return(null);
                        }
                        if (tuple.Item2)
                        {
                            vo.moves.Add(times);
                            var defensedie1 = fight.DefenseSoldierCount - fight.DefenseRoles.Sum(q => q.SoldierCount);
                            var attackdie1  = fight.AttackSoldierCount - fight.AttackRoles.Sum(q => q.SoldierCount);
                            RolesCountUpdate(fight.DefenseRoles, fight.AttackRoles);
                            if (fight.City.SoldierCount <= 0)
                            {
                                vo.result.isWin = 1;
                            }
                            vo.result.myDieCount    = attackdie1;
                            vo.result.rivalDieCount = defensedie1;
                            return(Tuple.Create((int)ResultType.SUCCESS, vo));
                        }
                    }
                }
                vo.moves.Add(times);
            }
            vo.result.isWin = 0;
            var defensedie2 = fight.DefenseSoldierCount - fight.DefenseRoles.Sum(q => q.SoldierCount);
            var attackdie2  = fight.AttackSoldierCount - fight.AttackRoles.Sum(q => q.SoldierCount);
            RolesCountUpdate(fight.DefenseRoles, fight.AttackRoles);
            vo.result.myDieCount    = defensedie2;
            vo.result.rivalDieCount = attackdie2;
            return(Tuple.Create((int)ResultType.SUCCESS, vo));
        }