Exemplo n.º 1
0
        /// <summary> 组装合战武将实体 </summary>
        /// <param name="list"></param>
        /// <param name="userid"></param>
        /// <param name="lsvo"></param>
        /// <param name="rs"></param>
        /// <returns></returns>
        private ResultType BuildWarRole(IEnumerable <object> list, Int64 userid, ref List <WarRolesLinesVo> lsvo, ref List <tg_war_role> rs)
        {
            var ls  = list.OfType <ASObject>();
            var ids = (from item in ls where item.ContainsKey("roleId") select Convert.ToInt64(item["roleId"])).ToList();

            if (!ids.Any())
            {
                return(ResultType.FRONT_DATA_ERROR);
            }
            var roles = tg_role.GetFindAllByIds(ids);

            foreach (var item in ls)
            {
                var _roleid    = item.ContainsKey("roleId") ? item["roleId"] : null;
                var _arms      = item.ContainsKey("arms") ? item["arms"] : null;
                var _armsCount = item.ContainsKey("armsCount") ? item["armsCount"] : null;
                if (_roleid == null || _arms == null || _armsCount == null)
                {
                    return(ResultType.FRONT_DATA_ERROR);
                }

                var roleid    = Convert.ToInt32(_roleid);
                var arms      = Convert.ToInt32(_arms);
                var armsCount = Convert.ToInt32(_armsCount);

                var role = roles.FirstOrDefault(m => m.id == roleid);
                if (role == null)
                {
                    return(ResultType.ROLE_NOT_EXIST);
                }
                var baseIdenity = Variable.BASE_IDENTITY.FirstOrDefault(m => m.id == role.role_identity);
                if (baseIdenity == null)
                {
                    return(ResultType.BASE_TABLE_ERROR);
                }
                if (armsCount > baseIdenity.soldier)
                {
                    return(ResultType.WAR_COPY_ARMSCOUNT_MAX);
                }

                var key   = String.Format("{0}_{1}_{2}", userid, 2, roleid);
                var model = Variable.WarLines.ContainsKey(key) ? Variable.WarLines[key] : null;
                if (armsCount <= 0)
                {
                    return(ResultType.WAR_COPY_SOLDIER_NULL);
                }
                if (model == null || model.lines == null)
                {
                    return(ResultType.WAR_COPY_ROLE_LINE_ERROR);
                }
                lsvo.Add(model.lines);

                var temp = new tg_war_role {
                    rid = roleid, army_id = arms, army_soldier = armsCount, user_id = userid
                };
                rs.Add(temp);
            }
            return(ResultType.SUCCESS);
        }
Exemplo n.º 2
0
        public void SendWarRole(tg_war_role role, List <Int32> otherinfo, params string[] name)
        {
            if (!Variable.OnlinePlayer.ContainsKey(role.user_id))
            {
                return;
            }
            var session = Variable.OnlinePlayer[role.user_id] as TGGSession;
            var dic     = new Dictionary <string, object>();

            #region 要推送的属性

            foreach (var item in name)
            {
                switch (item)
                {
                case "state":
                {
                    dic.Add("state", role.state);
                    break;
                }

                case "station":
                {
                    dic.Add("station", role.station);
                    break;
                }

                case "armyBaseId":
                {
                    dic.Add("armyBaseId", role.army_id);
                    break;
                }

                case "armyCount":
                {
                    dic.Add("armyCount", role.army_soldier);
                    break;
                }

                case "ArmyTypes":
                {
                    dic.Add("ArmyTypes", otherinfo);
                    break;
                }

                case "ArmyFormation":
                {
                    dic.Add("ArmyFormation", otherinfo);
                    break;
                }
                }
            }
            #endregion

            var data = BulidData(role.id, role.type, new ASObject(dic));
            var pv   = session.InitProtocol((int)ModuleNumber.WAR, (int)WarCommand.WAR_ROLE_UPDATE, (int)ResponseType.TYPE_SUCCESS, data);
            session.SendData(pv);
        }
Exemplo n.º 3
0
        public Dictionary <string, object> StartData(int result, tg_war_role role)
        {
            var dic = new Dictionary <string, object>
            {
                { "result", result },
                { "skyCity", role == null ? null : EntityToVo.ToSkyCityVo(role) }
            };

            return(dic);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 组装数据
        /// </summary>
        /// <param name="role">合战武将实体</param>
        /// <returns></returns>
        private ASObject BuildData(tg_war_role role)
        {
            var dic = new Dictionary <string, object>()
            {
                { "result", ResultType.SUCCESS },
                { "role", EntityToVo.ToWarRoleInfoVo(role) }
            };

            return(new ASObject(dic));
        }
Exemplo n.º 5
0
 /// <summary>
 /// 验证该武将是否在该城市中
 /// </summary>
 /// <param name="role">合战武将实体</param>
 /// <returns></returns>
 private bool CheckRoleState(tg_war_role role)
 {
     if (role == null)
     {
         return(false);
     }
     if (!tg_war_role.RoleIsIdle(role))
     {
         return(false);
     }
     role.state = (int)WarRoleStateType.DEFENSE;
     role.Update();
     new Share.War().SendWarRole(role, "state");
     return(true);
 }
Exemplo n.º 6
0
        /// <summary>验证据点信息并根据对应方案处理</summary>
        private void CheckCity(tg_war_role role)
        {
            //查询玩家据点信息
            var city = (new Share.War()).GetWarCity(role.station, role.user_id);

            //var city = tg_war_city.GetCityByBidUserId(role.station, role.user_id);
            if (city == null) //据点信息不存在或被占领,整理正在训练的武将信息
            {
                RoleUpdate(role);
                RemoveTask(role.user_id, role.id); //移除CD时间
            }
            else
            {
                CheckData(city, role);
            }
        }
Exemplo n.º 7
0
        /// <summary> 保存武将合战状态并推送 </summary>
        /// <param name="role">要保存的武将实体</param>
        /// <param name="state">要更改的状态</param>
        /// <param name="id">固定规则id</param>
        public void SaveRoleStateAndSend(tg_war_role role, int state, string id)
        {
            var rv = Variable.BASE_RULE.FirstOrDefault(m => m.id == id);

            if (rv == null)
            {
                return;
            }
            var count = 0;

            #region 外交冷却时间减少

            if (state == (int)WarRoleStateType.DIPLOMATIC_RELATIONS)
            {
                count = Convert.ToInt32((new Share.War()).GetTactics(role.user_id, (int)WarTacticsType.FOREIGN_TIME)); //内政策略外交冷却时间减少
            }

            #endregion

            var value = Convert.ToInt32(rv.value) - count;
            value               = value < 0 ? 0 : value;
            role.state          = state;
            role.state_end_time = (DateTime.Now.AddMinutes(value).Ticks - 621355968000000000) / 10000;

#if DEBUG
            role.state_end_time = (DateTime.Now.AddMinutes(1).Ticks - 621355968000000000) / 10000;
#endif
            role.Update();
            (new Share.War()).TaskRoleState(role);

            var str = new string[] { "state" };
            if (Convert.ToInt32(WarRoleStateType.PRISONERS) == state)
            {
                str = new string[] { "state", "stateEndTime" }
            }
            ;

            (new Share.War()).SendWarRole(role, str); //推送武将合战状态更变
        }
Exemplo n.º 8
0
        private bool SavaData(List <Common.Resourse> resourses, tg_war_role role, Int32 baseid, Int32 count, tg_war_city city)
        {
            role.army_id      = baseid;
            role.army_soldier = count;
            //更新城市资源和武将资源
            foreach (var resourse in resourses)
            {
                switch (resourse.type)
                {
                case (int)WarResourseType.兵粮: { city.res_foods -= resourse.value * count; } break;

                case (int)WarResourseType.军资金: { city.res_funds -= resourse.value * count; } break;

                case (int)WarResourseType.苦无: { city.res_use_kuwu += resourse.value * count; role.army_kuwu = resourse.value * count; } break;

                case (int)WarResourseType.薙刀: { city.res_use_razor += resourse.value * count; role.army_razor = resourse.value * count; } break;

                case (int)WarResourseType.足轻: { city.res_use_soldier += resourse.value * count; role.army_soldier = resourse.value * count; } break;

                case (int)WarResourseType.铁炮: { city.res_use_gun += resourse.value * count; role.army_gun = resourse.value * count; } break;

                case (int)WarResourseType.马匹: { city.res_use_horse += resourse.value * count; role.army_horse = resourse.value * count; } break;
                }
            }
            //保存数据
            role.Update();
            city.Update();
            Variable.WarCityAll.TryUpdate(city.base_id, city, city);
            //推送数据
            var list = new[] { "armyBaseId", "armyCount" };

            new Share.War().SendWarRole(role, list);
            new Share.War().SendCity(city.base_id, role.user_id);
            //tg_war_city.Update(string.Format("res_use_foods={0},res_use_funds={1},res_use_kuwu={2},res_use_razor={3}," +
            //                                 "res_use_soldier={4},res_use_gun={5},res_use_horse={6}"city.res_use_foods, city.res_use_funds))
            return(true);
        }
Exemplo n.º 9
0
        /// <summary>验证数据信息</summary>
        private void CheckData(tg_war_city city, tg_war_role role)
        {
            var basesize = GetBase();

            if (basesize == null)
            {
                return;
            }
            switch (role.state)
            {
            case (int)WarRoleStateType.ASSART: city.res_foods += role.resource; break;

            case (int)WarRoleStateType.BUILDING:
            {
                city.boom += role.resource;
                if (city.boom > basesize.boom)
                {
                    city.boom = basesize.boom;
                }
                break;
            }

            case (int)WarRoleStateType.BUILD_ADD:
            {
                city.strong += role.resource;
                if (city.strong > basesize.strong)
                {
                    city.strong = basesize.strong;
                }
                break;
            }

            case (int)WarRoleStateType.MINING: city.res_funds += role.resource; break;

            case (int)WarRoleStateType.PEACE:
            {
                city.peace += role.resource;
                if (city.peace > basesize.peace)
                {
                    city.peace = basesize.peace;
                }
                break;
            }

            case (int)WarRoleStateType.LEVY:
            {
                city.res_soldier += role.resource;
                var res = city.res_morale - ReduceMorale(role.resource);          //徵兵扣除士气
                city.res_morale = res <= 0 ? 0 : res;
            }
            break;

            case (int)WarRoleStateType.TRAIN:
            {
                city.res_morale = city.res_morale + role.resource + GetCharacterMorale(city.user_id);
                var basecity = Variable.BASE_WARCITYSIZE.FirstOrDefault(m => m.id == city.size);
                if (basecity == null)                    //基表判断
                {
                    return;
                }
                if (city.res_morale > basecity.morale)
                {
                    city.res_morale = basecity.morale;
                }
            }
            break;
            }
            new Share.War().ReduceAdd(role, 0);
            city.Update();
            if (role.count == 0)
            {
                new Share.War().ReduceRes(role);
                role.state          = (int)WarRoleStateType.IDLE;
                role.resource       = 0;
                role.total_count    = 0;
                role.state_end_time = 0;
                RemoveTask(role.user_id, role.id); //移除CD时间
                (new Share.War()).SendWarRole(role, "state");
            }
            else
            {
                //更新武将下一个半小时到达时间
                role.count -= 1;
                Int64 time = 30 * 60 * 1000;
# if DEBUG
                time = 1 * 60 * 1000;
#endif
                role.state_end_time = CurrentTime() + time;
                RemoveTask(role.user_id, role.id);      //移除CD时间
                SpinWait.SpinUntil(() => false, 500);
                TaskBegin(role.user_id, role.id, time); //重新开启线程
            }
Exemplo n.º 10
0
        /// <summary> 内政 军事完成推送资源更新</summary>
        public void ResourcePush(int baseid, tg_war_role role)
        {
# if DEBUG
Exemplo n.º 11
0
        /// <summary> 武将配置的兵扣除对应城市的资源 </summary>
        /// <param name="temp">武将信息</param>
        /// <param name="city">据点信息</param>
        private tg_war_city ReduceWarCityRes(tg_war_role temp, tg_war_city city)
        {
            city.res_foods     -= temp.army_foods;
            city.res_use_foods -= temp.army_foods;
            if (city.res_foods < 0)
            {
                city.res_foods = 0;
            }
            if (city.res_use_foods < 0)
            {
                city.res_use_foods = 0;
            }

            city.res_funds     -= temp.army_funds;
            city.res_use_funds -= temp.army_funds;
            if (city.res_funds < 0)
            {
                city.res_funds = 0;
            }
            if (city.res_use_funds < 0)
            {
                city.res_use_funds = 0;
            }

            city.res_gun     -= temp.army_gun;
            city.res_use_gun -= temp.army_gun;
            if (city.res_gun < 0)
            {
                city.res_gun = 0;
            }
            if (city.res_use_gun < 0)
            {
                city.res_use_gun = 0;
            }

            city.res_horse     -= temp.army_horse;
            city.res_use_horse -= temp.army_horse;
            if (city.res_horse < 0)
            {
                city.res_horse = 0;
            }
            if (city.res_use_horse < 0)
            {
                city.res_use_horse = 0;
            }

            city.res_kuwu     -= temp.army_kuwu;
            city.res_use_kuwu -= temp.army_kuwu;
            if (city.res_kuwu < 0)
            {
                city.res_kuwu = 0;
            }
            if (city.res_use_kuwu < 0)
            {
                city.res_use_kuwu = 0;
            }

            city.res_razor     -= temp.army_razor;
            city.res_use_razor -= temp.army_razor;
            if (city.res_razor < 0)
            {
                city.res_razor = 0;
            }
            if (city.res_use_razor < 0)
            {
                city.res_use_razor = 0;
            }

            city.res_soldier     -= temp.army_soldier;
            city.res_use_soldier -= temp.army_soldier;
            if (city.res_soldier < 0)
            {
                city.res_soldier = 0;
            }
            if (city.res_use_soldier < 0)
            {
                city.res_use_soldier = 0;
            }
            return(city);
        }
Exemplo n.º 12
0
 private Int32 GetRoleBaseId(tg_war_role role)
 {
     return(role.type == (int)WarRoleType.NPC ?
            Convert.ToInt32(role.rid)
        : tg_role.FindByid(role.rid).role_id);
 }
Exemplo n.º 13
0
        /// <summary>检测资源 </summary>
        private Tuple <bool, List <Common.Resourse> > CheckResourse(Int32 baseid, int count, tg_war_city city, tg_war_role role)
        {
            var listentity = new List <Common.Resourse>();
            var add        = Common.GetInstance().GetResourseString(role.army_id, 1);

            if (add == null)
            {
                return(Tuple.Create(false, listentity));
            }
            var oldcount = role.army_soldier;

            if (oldcount > 0)
            {
                foreach (var resourse in add)
                {
                    switch (resourse.type)
                    {
                    //兵粮和军资金回归城市,不用锁定
                    case (int)WarResourseType.兵粮: { city.res_foods += resourse.value * oldcount; } break;

                    case (int)WarResourseType.军资金: { city.res_funds += resourse.value * oldcount; } break;

                    case (int)WarResourseType.苦无: { if (city.res_use_kuwu >= resourse.value * oldcount)
                                                    {
                                                        city.res_use_kuwu -= resourse.value * oldcount;
                                                    }
                    } break;

                    case (int)WarResourseType.薙刀: { if (city.res_use_razor >= resourse.value * oldcount)
                                                    {
                                                        city.res_use_razor -= resourse.value * oldcount;
                                                    }
                    } break;

                    case (int)WarResourseType.足轻: { if (city.res_use_soldier >= resourse.value * oldcount)
                                                    {
                                                        city.res_use_soldier -= resourse.value * oldcount;
                                                    }
                    } break;

                    case (int)WarResourseType.铁炮: { if (city.res_use_gun >= resourse.value * oldcount)
                                                    {
                                                        city.res_use_gun -= resourse.value * oldcount;
                                                    }
                    } break;

                    case (int)WarResourseType.马匹: { if (city.res_use_horse >= resourse.value * oldcount)
                                                    {
                                                        city.res_use_horse -= resourse.value * oldcount;
                                                    }
                    } break;
                    }
                }
            }

            // listentity.AddRange(add);
            var reduce = Common.GetInstance().GetResourseString(baseid, 1);

            if (reduce == null)
            {
                return(Tuple.Create(false, listentity));
            }
            foreach (var resourse in reduce)
            {
                switch (resourse.type)
                {
                case (int)WarResourseType.兵粮: { if (resourse.value * count > city.res_foods)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;

                case (int)WarResourseType.军资金: { if (resourse.value * count > city.res_funds)
                                                 {
                                                     return(Tuple.Create(false, listentity));
                                                 }
                } break;

                case (int)WarResourseType.苦无: { if (resourse.value * count > city.res_kuwu - city.res_use_kuwu)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;

                case (int)WarResourseType.薙刀: { if (resourse.value * count > city.res_razor - city.res_use_razor)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;

                case (int)WarResourseType.足轻: { if (resourse.value * count > city.res_soldier - city.res_use_soldier)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;

                case (int)WarResourseType.铁炮: { if (resourse.value * count > city.res_gun - city.res_use_gun)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;

                case (int)WarResourseType.马匹: { if (resourse.value * count > city.res_horse - city.res_use_horse)
                                                {
                                                    return(Tuple.Create(false, listentity));
                                                }
                } break;
                }
            }
            listentity.AddRange(reduce);
            return(Tuple.Create(true, listentity));
        }