Example #1
0
      /// <summary>
      ///  修改密码
      /// </summary>
      /// <param name="context"></param>
      public static void ChangePassword(HttpContext context)
      {
         if (context.Request.IsAuthenticated)
         {
            string op = context.Request.Form["op"];
            string np = context.Request.Form["np"];

            if (string.IsNullOrEmpty(op) || string.IsNullOrEmpty(np)) { context.Response.Write(JU.Build(false, "输入不完整,请完整输入当前密码和新密码后再试")); return; }
            
            UserEntity user = UserAccount.Current;
            if (user != null && user.password == MU.MD5(op))
            {
               string passwd = MU.MD5(np);
               if (UserData.ChangePassword(user.id, passwd) > 0)
               {
                  user.password = passwd;
                  //TODO:notify other server change
                  context.Response.Write(JU.AJAX_SUCCESS);
                  return;
               }
            }
            else { context.Response.Write(JU.Build(false, "当前密码错误,请重新输入当前使用的密码!")); return; }
         }

         context.Response.Write(JU.Build(false,"对不起,无法修改密码,请重新登录后再试!"));
      }
Example #2
0
        }                                  // 最大移动距离

        public bool InAttackRange(int tx, int ty)
        {
            GetPosInMap(out int x, out int y);
            var dist = MU.ManhattanDist(x, y, tx, ty);

            return(FC.IndexOf(AttackRange, dist) >= 0);
        }
Example #3
0
        // 寻找最近目标
        public Warrior FindNearestTarget(Warrior warrior)
        {
            Warrior nearestTarget = null;
            int     tx            = 0;
            int     ty            = 0;

            warrior.GetPosInMap(out int fx, out int fy);
            warrior.Map.ForeachObjs <Warrior>((x, y, target) =>
            {
                // 过滤队友和已经死亡的敌人
                if (target.IsDead || target.Team == warrior.Team)
                {
                    return;
                }

                if (nearestTarget == null || MU.ManhattanDist(fx, fy, x, y) < MU.ManhattanDist(fx, fy, tx, ty))
                {
                    tx            = x;
                    ty            = y;
                    nearestTarget = target;
                }
            });

            return(nearestTarget);
        }
Example #4
0
        static void Main(string[] args)
        {
            University mu = new MU();

            mu.StartProcess();
            Console.WriteLine();
            mu = new GTU();
            mu.StartProcess();
        }
Example #5
0
 public static int Create(string name, string pwd, string email, string www)
 {
     return(UserData.Create(new UserEntity()
     {
         name = name,
         password = MU.MD5(pwd),
         email = email,
         www = www
     }));
 }
Example #6
0
        // 计算给定角色移动后,可以攻击到哪些目标
        static Dictionary <Warrior, KeyValuePair <int, int> > FindTargetsReachable(Warrior warrior)
        {
            var targets = new Dictionary <Warrior, KeyValuePair <int, int> >(); // 潜在可以攻击到的目标,及对应的站位
            var map     = warrior.Map;

            warrior.GetPosInMap(out int fx, out int fy);
            map.ForeachObjs <Warrior>((tx, ty, target) =>
            {
                if (warrior.Team == target.Team) // 过滤掉队友
                {
                    return;
                }

                var dstX = fx;
                var dstY = fy;

                // 如果寻路结果的终点,可以攻击到目标,则加入候选列表
                if (warrior.AttackRange.IndexOf(MU.ManhattanDist(dstX, dstY, tx, ty)) >= 0)
                {
                    targets[target] = new KeyValuePair <int, int>(dstX, dstY);
                }
                else if (warrior.MoveRange > 0)
                {
                    // 向目标寻路,如果无法达到,返回的路径表示朝向目标最近的方向的移动路径
                    var path2Target = map.FindPath(fx, fy, tx, ty, warrior.MoveRange, warrior.StandableTiles);
                    for (var i = 0; i < path2Target.Count; i += 2)
                    {
                        dstX = path2Target[path2Target.Count - i - 2];
                        dstY = path2Target[path2Target.Count - i - 1];

                        // 如果寻路结果的终点,可以攻击到目标,则加入候选列表
                        if (warrior.AttackRange.IndexOf(MU.ManhattanDist(dstX, dstY, tx, ty)) >= 0)
                        {
                            targets[target] = new KeyValuePair <int, int>(dstX, dstY);
                            break;
                        }
                    }
                }
            });

            return(targets);
        }
Example #7
0
        public event Action <Warrior, int, int, List <int>, bool> OnWarriorMovingOnPath = null; // 角色沿路径移动
        public List <int> MoveOnPath(Warrior warrior, bool forceMove = false /* 忽略限制强制移动 */)
        {
            Debug.Assert(forceMove || (!warrior.Moved && !warrior.ActionDone), "attacker has already moved or acted in this round");

            warrior.GetPosInMap(out int x, out int y);
            Debug.Assert(MU.ManhattanDist(x, y, warrior.MovingPath[0], warrior.MovingPath[1]) == 1, "the warrior has not been right on the start position: " + x + ", " + y);

            if (!forceMove && warrior.MovingPath.Count > warrior.MoveRange * 2) // 超出移动能力
            {
                return(null);
            }

            BeforeMoveOnPath?.Invoke(warrior, forceMove);

            List <int> movedPath = new List <int>(); // 实际落实了的移动路径
            var        lstPathXY = warrior.MovingPath;
            var        fx        = x;
            var        fy        = y;

            while (lstPathXY.Count >= 2)
            {
                var tx = lstPathXY[0];
                var ty = lstPathXY[1];

                lstPathXY.RemoveRange(0, 2);
                movedPath.Add(tx);
                movedPath.Add(ty);

                Debug.Assert(!map.BlockedAt(tx, ty, warrior.StandableTiles), "target position has been blocked: " + tx + ", " + ty);

                MoveWarroirs(warrior, tx, ty);

                fx = tx;
                fy = ty;
            }

            warrior.Moved = true;

            OnWarriorMovingOnPath?.Invoke(warrior, x, y, movedPath, forceMove);
            AfterMoveOnPath?.Invoke(warrior, x, y, movedPath, forceMove);
            return(movedPath);
        }
Example #8
0
        // 检查指定范围内有多少队友
        public static Warrior[] CheckTeammateInDistance(Warrior warrior, int dist)
        {
            var map = warrior.Map;

            warrior.GetPosInMap(out int cx, out int cy);
            var teammates = new List <Warrior>();

            FC.RectForCenterAt(cx, cy, dist, dist, (x, y) =>
            {
                if (!MU.InRect(x, y, 0, 0, map.Width, map.Height))
                {
                    return;
                }

                var t = map.GetAt <Warrior>(x, y);
                if (t != null && t.Team == warrior.Team)
                {
                    teammates.Add(t);
                }
            });

            return(teammates.ToArray());
        }
Example #9
0
File: Room.cs Project: radtek/SCM2
        // 扇形攻击
        public virtual Unit[] DoAOEAttackFan(Unit attacker, Unit target)
        {
            var ps      = target.cfg.IsAirUnit ? attacker.cfg.AOEParams[1] : attacker.cfg.AOEParams[0];
            var dir     = MU.v2Degree(target.Pos.x - attacker.Pos.x, target.Pos.y - attacker.Pos.y);
            var targets = new List <Unit>();

            targets.Add(target); // place main target as first one
            var ts = GetUnitInFanArea(attacker.Pos,
                                      ps[0], dir, ps[1], (u) => attacker.CanAttack(u) && u.Hp > 0 && u.cfg.IsAirUnit == target.cfg.IsAirUnit);

            foreach (Unit t in ts)
            {
                if (!targets.Contains(t))
                {
                    targets.Add(t);
                }
            }

            var tars = targets.ToArray();

            MakeDamage(attacker, targets.ToArray());
            return(tars);
        }
Example #10
0
        public string ToString(CultureInfo culture, bool includePQ = false, int?digits = null)
        {
            var res = "";

            var mustr = "";

            if (MU != MUCollection.Adimensional.adim)
            {
                mustr = MU.ToString();
            }

            if (!ExpPref.HasValue || ExpPref.Value == 0)
            {
                var v = Value;
                if (digits.HasValue)
                {
                    v = Round(v, digits.Value);
                }
                res = Invariant($"{v} {(mustr.Length > 0 ? mustr : "")}");
            }
            else
            {
                var v = Value / Pow(10, ExpPref.Value);
                if (digits.HasValue)
                {
                    v = Round(v, digits.Value);
                }
                res = Invariant($"{v}e{ExpPref.Value} {(mustr.Length > 0 ? mustr : "")}");
            }

            if (includePQ)
            {
                res += $" [{MU.PhysicalQuantity}]";
            }

            return(res);
        }
Example #11
0
        // 寻找最近的队友
        public static Warrior FindTheNearestTeammate(Warrior warrior)
        {
            Warrior nearestTeammate = null;
            var     map             = warrior.Map;

            warrior.GetPosInMap(out int fx, out int fy);
            var nearestX = 0;
            var nearestY = 0;

            map.ForeachObjs <Warrior>((tx, ty, target) =>
            {
                if (warrior.Team != target.Team || warrior == target) // 过滤掉敌人和自己
                {
                    return;
                }

                if (// 选距离最近的
                    (nearestTeammate == null || MU.ManhattanDist(fx, fy, tx, ty) < MU.ManhattanDist(fx, fy, nearestX, nearestY))
                    // 距离相同选 HP 高的
                    || (MU.ManhattanDist(fx, fy, tx, ty) == MU.ManhattanDist(fx, fy, nearestX, nearestY) && nearestTeammate.HP < target.HP)
                    // 距离,HP 相同选防御高的
                    || (MU.ManhattanDist(fx, fy, tx, ty) == MU.ManhattanDist(fx, fy, nearestX, nearestY) &&
                        nearestTeammate.HP == target.HP && nearestTeammate.GetEstimatedDefence() < target.GetEstimatedDefence())
                    // 距离,HP,防御相同选攻击高的
                    || (MU.ManhattanDist(fx, fy, tx, ty) == MU.ManhattanDist(fx, fy, nearestX, nearestY) &&
                        nearestTeammate.HP == target.HP && nearestTeammate.GetEstimatedDefence() == target.GetEstimatedDefence() &&
                        (nearestTeammate.BasicAttackValue < target.BasicAttackValue)))
                {
                    nearestX        = tx;
                    nearestY        = ty;
                    nearestTeammate = target;
                }
            });

            return(nearestTeammate);
        }
Example #12
0
 // 显示攻击范围
 public void ShowAttackRange(float x, float y, Warrior worrior)
 {
     Debug.Assert(pathATKRange.Count == 0, "path range is not empty now.");
     FC.For(worrior.AttackRange.Length, (i) =>
     {
         int minX = (x - worrior.AttackRange[i]) < 0 ? 0 : (int)(x - worrior.AttackRange[i]);
         int maxX = (x + worrior.AttackRange[i]) >= BattleStage.Map.Width ? BattleStage.Map.Width : (int)(x + worrior.AttackRange[i] + 1);
         int minY = (y - worrior.AttackRange[i]) < 0 ? 0 : (int)(y - worrior.AttackRange[i]);
         int maxY = (y + worrior.AttackRange[i]) >= BattleStage.Map.Height ? BattleStage.Map.Height : (int)(y + worrior.AttackRange[i] + 1);
         FC.For2(minX, maxX, minY, maxY, (tx, ty) =>
         {
             if (MU.ManhattanDist((int)x, (int)y, tx, ty) == worrior.AttackRange[i])
             {
                 var tile = BattleStage.CreateMapTile(tx, ty);
                 pathATKRange.Add(tile);
                 var avatar = BattleStage.GetAvatarAt(tx, ty);
                 if (avatar != null && avatar.Warrior.Team != worrior.Team)
                 {
                     avatar.AttackHint.SetActive(true);
                 }
             }
         });
     });
 }
Example #13
0
        /// <summary>
        ///  用户登录
        /// </summary>
        /// <param name="name"></param>
        /// <param name="pwd"></param>
        /// <returns></returns>
        public static bool Login(string name, string pwd)
        {
            UserEntity entity = null;

            pwd = MU.MD5(pwd);
            try
            {
                if (name.Contains("@"))
                {
                    entity = UserData.LoginByEmail(name, pwd);
                }
                else
                {
                    entity = UserData.LoginByName(name, pwd);
                }

                //write cookie
                if (entity != null)
                {
                    CacheService.Add(CNC.ACCOUNT_ENTITY_ID + entity.id, entity);
                    string id = entity.id.ToString(); // id 仅作内部使用,不对外公开
                    QA.SetCookie(FormsAuthentication.FormsCookieName,
                                 FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, id, DateTime.Now, DateTime.MaxValue, true, id, FormsAuthentication.FormsCookiePath))
                                 , DateTime.MaxValue); //设置永久保留登录信息,之后版本可考虑进行配置

                    QA.SetCookie(SC.CN.A_NAME, HttpUtility.UrlEncode(entity.name), DateTime.MaxValue);
                    string cookie = QA.GetCookie(SC.CN.FROM);

                    //TODO: write log,add to task.
                    Log.Login(entity);
                }
            }
            catch { }

            return(entity != null);
        }
Example #14
0
File: Room.cs Project: radtek/SCM2
 // 获取指定矩形范围内满足条件的单位
 public Unit[] GetUnitInFanArea(Vec2 fanCenter, Fix64 fanR, Fix64 fanDir, Fix64 fanAngle, Func <Unit, bool> filter)
 {
     return(FC.Select(AllUnits,
                      (u) => (filter == null || filter(u)) &&
                      MU.IsFunOverlappedCircle(u.Pos, u.cfg.SizeRadius, fanCenter, fanR, fanDir, fanAngle)).ToArray());
 }
Example #15
0
    // 显示范围
    public void ShowRange(int cx, int cy, ActiveSkill skill, Action <int, int> onSelPos)
    {
        Debug.Assert(Range.Count == 0, "path asasrange is not empty now.");
        this.onSelPos = onSelPos;
        var map = BattleStage.Map;

        // 如果无释放范围的技能
        if (!(skill is ISkillWithRange))
        {
            // 需要过滤目标
            if (skill is ISkillWithTargetFilter)
            {
                var targetList = (skill as ISkillWithTargetFilter).AllAvaliableTargets();
                FC.For(targetList.Count, (i) =>
                {
                    var warrior = targetList[i] as Warrior;
                    if (warrior != null)
                    {
                        // 建立用于显示技能范围的地块
                        var avatar  = BattleStage.GetAvatarByWarrior(warrior);
                        var mapTile = BattleStage.CreateMapTile(avatar.X, avatar.Y);
                        mapTile.gameObject.SetActive(false);
                        Range.Add(mapTile);

                        // 显示人物身上的技能标识
                        if (warrior.Team == skill.Owner.Team)
                        {
                            avatar.FriendSkillDec.SetActive(true);
                        }
                        else
                        {
                            avatar.EnemySkillDec.SetActive(true);
                        }
                    }
                    else
                    {
                        Debug.Assert(warrior != null, "the target is not warrior");
                    }
                });
            }
        }
        else // 有释放范围的技能
        {
            var range = (skill as ISkillWithRange).Range;
            FC.SquareFor(cx, cy, range, (x, y) =>
            {
                if (x < 0 || x >= map.Width || y < 0 || y >= map.Height)
                {
                    return;
                }
                var obj = map.GetAt <BattleMapObj>(x, y);
                if (MU.ManhattanDist(x, y, cx, cy) == range)
                {
                    if (obj == null || (obj != null && obj is Hero))
                    {
                        var tile = BattleStage.CreateMapTile(x, y);
                        Range.Add(tile);
                    }
                }
            });
        }
    }
Example #16
0
        // 根据优先级重新排序 ai 执行顺序
        public static void Resort(this WarriorAI[] ais)
        {
            // 最近敌人的距离
            var dist2Target = new Dictionary <WarriorAI, int>();

            foreach (var ai in ais)
            {
                ai.Owner.GetPosInMap(out int fx, out int fy);
                var target = ai.Owner.Map.FindNearestTarget(ai.Owner);
                if (target != null)
                {
                    target.GetPosInMap(out int tx, out int ty);
                    dist2Target[ai] = MU.ManhattanDist(fx, fy, tx, ty);
                }
            }

            // 排序权重:距离敌人距离小,攻击力高,HP 高,防御高
            ais.SwiftSort((a, b) =>
            {
                if (dist2Target[a] < dist2Target[b])
                {
                    return(-1);
                }
                else if (dist2Target[a] > dist2Target[b])
                {
                    return(1);
                }
                else if (a.Owner.BasicAttackValue > b.Owner.BasicAttackValue)
                {
                    return(-1);
                }
                else if (a.Owner.BasicAttackValue < b.Owner.BasicAttackValue)
                {
                    return(1);
                }
                else if (a.Owner.HP < b.Owner.HP)
                {
                    return(1);
                }
                else if (a.Owner.HP > b.Owner.HP)
                {
                    return(-1);
                }
                else if (a.Owner.HP < b.Owner.HP)
                {
                    return(1);
                }
                else if (a.Owner.GetEstimatedDefence() > b.Owner.GetEstimatedDefence())
                {
                    return(-1);
                }
                else if (a.Owner.GetEstimatedDefence() < b.Owner.GetEstimatedDefence())
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            });
        }
Example #17
0
 protected virtual void Awake()
 {
     MU.AddBehaviour(this);
 }
Example #18
0
 protected virtual void OnDestroy()
 {
     MU.RemoveBehaviour(this);
 }