Beispiel #1
0
        public void HandleAttack(Player player, Pbmsg.AttackReq reqMsg)
        {
            Role roleTarget = RoleMgr.Instance().GetRoleBySessionID(reqMsg.Targetid);

            if (roleTarget == null)
            {
                return;
            }
            Pbmsg.AttackRet retMsg = new Pbmsg.AttackRet()
            {
                Id       = player.GetID(),
                Targetid = reqMsg.Targetid,
                Magicid  = reqMsg.Magicid,
            };
            FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SAttack, retMsg);
            Random rd         = new Random();
            int    hpChaneged = rd.Next(1, roleTarget.maxhp / 10);

            //hpChaneged = 1;

            if (roleTarget.hp >= hpChaneged)
            {
                roleTarget.hp -= hpChaneged;
            }
            else
            {
                roleTarget.hp = 0;
            }
            Pbmsg.HPChangedRet retMsg2 = new Pbmsg.HPChangedRet()
            {
                Id         = roleTarget.GetID(),
                Magicid    = reqMsg.Magicid,
                ValCur     = roleTarget.hp,
                ValChanged = hpChaneged,
            };
            FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SHpChanged, retMsg2);
            roleTarget.nLastAttackedTime = Util.GetNowTimeMs();

            if (roleTarget is Monster)
            {
                Monster monster = roleTarget as Monster;
                monster.direction           = (player.direction + 4) % 8;
                monster.nLastAttackedRoleID = player.GetID();
                if (monster.hp == 0)
                {
                    Pbmsg.LeaveMapRet leaveMsg = new Pbmsg.LeaveMapRet()
                    {
                        Id = roleTarget.GetID(),
                    };
                    FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SLeaveMap, leaveMsg);
                }
            }
        }
Beispiel #2
0
        public void HandleAttack(Player player, Pbmsg.AttackReq reqMsg)
        {
            Role roleTarget = getRoleBySessionID(reqMsg.Targetid);

            if (roleTarget == null)
            {
                return;
            }
            Pbmsg.AttackRet retMsg = new Pbmsg.AttackRet()
            {
                Id       = player.getID(),
                Targetid = reqMsg.Targetid,
                Magicid  = reqMsg.Magicid,
            };
            BroadcastPlayerMsg <Pbmsg.AttackRet>(Pbmsg.ServerCmdDef.SAttack, retMsg);
            Random rd         = new Random();
            int    hpChaneged = 1 + rd.Next() % 5;

            if (roleTarget.hp >= hpChaneged)
            {
                roleTarget.hp -= hpChaneged;
            }
            else
            {
                roleTarget.hp = 0;
            }
            int hpNow = roleTarget.hp;

            Pbmsg.HPChangedRet retMsg2 = new Pbmsg.HPChangedRet()
            {
                Id         = roleTarget.getID(),
                Magicid    = reqMsg.Magicid,
                ValCur     = hpNow,
                ValChanged = hpChaneged,
            };
            BroadcastPlayerMsg <Pbmsg.HPChangedRet>(Pbmsg.ServerCmdDef.SHpChanged, retMsg2);

            if (roleTarget is Monster && hpChaneged <= 3)
            {
                Monster monster = roleTarget as Monster;
                monster.direction = (player.direction + 4) % 8;
                Pbmsg.AttackRet monsterAttackMsg = new Pbmsg.AttackRet()
                {
                    Id       = monster.getID(),
                    Targetid = player.getID(),
                };
                BroadcastPlayerMsg <Pbmsg.AttackRet>(Pbmsg.ServerCmdDef.SAttack, monsterAttackMsg);

                roleTarget = player;
                if (roleTarget.hp >= hpChaneged)
                {
                    roleTarget.hp -= hpChaneged;
                }
                else
                {
                    roleTarget.hp = 0;
                }
                hpNow = roleTarget.hp;
                Pbmsg.HPChangedRet retMsg3 = new Pbmsg.HPChangedRet()
                {
                    Id         = roleTarget.getID(),
                    ValCur     = hpNow,
                    ValChanged = hpChaneged,
                };
                BroadcastPlayerMsg <Pbmsg.HPChangedRet>(Pbmsg.ServerCmdDef.SHpChanged, retMsg3);
            }
        }
Beispiel #3
0
        public void HandleRobotAI(Player player)
        {
            long nowtm = Util.GetNowTimeMs();

            if (nowtm - player.nLastRobotAITm < 1000)
            {
                return;
            }
            player.nLastRobotAITm = nowtm;
            Role targetRole = GetTargetRobot(player);

            if (targetRole == null)//!没有目标找一个离自己最近的目标
            {
                RoleMgr.Instance().ForeachRole((Role roleOther) => {
                    if (roleOther == player || roleOther.hp == 0 || roleOther is Monster)
                    {
                        return;
                    }
                    if (targetRole != null && Util.Distance(player.x, player.y, targetRole.x, targetRole.y) <= Util.Distance(player.x, player.y, roleOther.x, roleOther.y))
                    {
                        return;
                    }
                    targetRole        = roleOther;
                    player.nCurTarget = targetRole.GetID();
                });
            }
            int nDistance = Util.Distance(player.x, player.y, targetRole.x, targetRole.y);

            if (nDistance <= 1)
            {
                Pbmsg.AttackRet monsterAttackMsg = new Pbmsg.AttackRet()
                {
                    Magicid  = 2,
                    Id       = player.GetID(),
                    Targetid = targetRole.GetID(),
                };
                FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SAttack, monsterAttackMsg);

                int hpChaneged = 200;

                //if (targetRole.hp >= hpChaneged)
                //{
                //    targetRole.hp -= hpChaneged;
                //}
                //else
                //{
                //    targetRole.hp = 0;
                //    targetRole.nLastAttackedTime = Util.GetNowTimeMs();
                //}
                Pbmsg.HPChangedRet retMsg2 = new Pbmsg.HPChangedRet()
                {
                    Id         = targetRole.GetID(),
                    Magicid    = 2,
                    ValCur     = targetRole.hp,
                    ValChanged = hpChaneged,
                };
                FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SHpChanged, retMsg2);
                return;
            }
            //!追击
            int       nDir      = GameUtil.CalDirection(player.x, player.y, targetRole.x, targetRole.y);
            GamePoint offsetPos = GameUtil.CalPointByDirLen(nDir, 1);

            player.x = player.x + offsetPos.x;
            player.y = player.y + offsetPos.y;
            Pbmsg.RunRet runRet = new Pbmsg.RunRet()
            {
                Id = player.GetID(),
                X  = player.x,
                Y  = player.y,
            };
            FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SRun, runRet);
            return;
        }
Beispiel #4
0
        public void HandleMonsterAI()
        {
            long now = Util.GetNowTimeMs();

            if (now - this.nLastAITick < 800)
            {
                return;
            }
            this.nLastAITick = Util.GetNowTimeMs();
            RoleMgr.Instance().ForeachRole((Role role) => {
                //if (gCount++ % 10 == 0)
                //{
                //    FFLog.Trace(string.Format("HandleMonsterAI! {0},hp:{1}", gCount, role.hp));
                //}
                if (role.hp <= 0)
                {
                    if (Util.GetNowTimeMs() - role.nLastAttackedTime < 5000 && gCount++ % 10 != 0)
                    {
                        return;
                    }
                    role.hp = role.maxhp;
                    Pbmsg.EnterMapRet enterMapRet = role.BuildEnterMsg();
                    FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                    return;
                }
                if (!(role is Monster))
                {
                    if (role is Player)
                    {
                        Player playerTmp = role as Player;
                        if (playerTmp.bIsRobot)
                        {
                            HandleRobotAI(playerTmp);
                        }
                    }
                    return;
                }

                Monster monster = role as Monster;
                if (monster.nLastAttackedRoleID == 0)
                {
                    return;
                }
                Player player = RoleMgr.Instance().GetPlayerBySessionID(monster.nLastAttackedRoleID);
                if (player == null || player.hp == 0)
                {
                    monster.nLastAttackedRoleID = 0;
                    return;
                }
                int nDistance = Util.Distance(monster.x, monster.y, player.x, player.y);
                if (nDistance <= 1)
                {
                    if (Util.GetNowTimeMs() - monster.nLastAttackTime < 1000)
                    {
                        return;
                    }
                    monster.nLastAttackTime          = Util.GetNowTimeMs();
                    Pbmsg.AttackRet monsterAttackMsg = new Pbmsg.AttackRet()
                    {
                        Id       = monster.GetID(),
                        Targetid = player.GetID(),
                    };
                    FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SAttack, monsterAttackMsg);

                    Random rd = new Random();

                    Role roleTarget = player;
                    int hpChaneged  = rd.Next(1, roleTarget.maxhp / 10);
                    if (roleTarget.hp >= hpChaneged)
                    {
                        roleTarget.hp -= hpChaneged;
                    }
                    else
                    {
                        roleTarget.hp = 0;
                    }
                    roleTarget.nLastAttackedTime = Util.GetNowTimeMs();
                    Pbmsg.HPChangedRet retMsg3   = new Pbmsg.HPChangedRet()
                    {
                        Id         = roleTarget.GetID(),
                        ValCur     = roleTarget.hp,
                        ValChanged = hpChaneged,
                    };
                    FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SHpChanged, retMsg3);
                }
                else//!怪物寻路追打角色
                {
                    GamePoint nextPos = GameUtil.FindPath(new GamePoint(monster.x, monster.y), new GamePoint(player.x, player.y));
                    if (RoleMgr.Instance().GetRoleByPos(nextPos.x, nextPos.y) != null)
                    {
                        return;
                    }
                    monster.x           = nextPos.x;
                    monster.y           = nextPos.y;
                    Pbmsg.RunRet runRet = new Pbmsg.RunRet()
                    {
                        Id = monster.GetID(),
                        X  = monster.x,
                        Y  = monster.y,
                    };
                    FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SRun, runRet);
                }
            });
        }
Beispiel #5
0
        public void HandleMonsterAI()
        {
            foreach (Role role in m_dictRoles.Values)
            {
                if (role.hp == 0)
                {
                    if (Util.GetNowTimeMs() - role.nLastAttackedTime < 5000)
                    {
                        continue;
                    }
                    role.hp = role.maxhp;
                    Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(role);
                    BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                    continue;
                }
                if (!(role is Monster))
                {
                    continue;
                }

                Monster monster = role as Monster;
                if (monster.nLastAttackedRoleID == 0)
                {
                    continue;
                }
                Player player = GetPlayerBySessionID(monster.nLastAttackedRoleID);
                if (player == null || player.hp == 0)
                {
                    monster.nLastAttackedRoleID = 0;
                    continue;
                }
                int nDistance = Util.Distance(monster.x, monster.y, player.x, player.y);
                if (nDistance <= 1)
                {
                    if (Util.GetNowTimeMs() - monster.nLastAttackTime < 1000)
                    {
                        continue;
                    }
                    monster.nLastAttackTime = Util.GetNowTimeMs();
                    Pbmsg.AttackRet monsterAttackMsg = new Pbmsg.AttackRet()
                    {
                        Id       = monster.GetID(),
                        Targetid = player.GetID(),
                    };
                    BroadcastPlayerMsg <Pbmsg.AttackRet>(Pbmsg.ServerCmdDef.SAttack, monsterAttackMsg);

                    Random rd = new Random();

                    Role roleTarget = player;
                    int  hpChaneged = rd.Next(1, roleTarget.maxhp / 10);
                    if (roleTarget.hp >= hpChaneged)
                    {
                        roleTarget.hp -= hpChaneged;
                    }
                    else
                    {
                        roleTarget.hp = 0;
                    }
                    roleTarget.nLastAttackedTime = Util.GetNowTimeMs();
                    Pbmsg.HPChangedRet retMsg3 = new Pbmsg.HPChangedRet()
                    {
                        Id         = roleTarget.GetID(),
                        ValCur     = roleTarget.hp,
                        ValChanged = hpChaneged,
                    };
                    BroadcastPlayerMsg <Pbmsg.HPChangedRet>(Pbmsg.ServerCmdDef.SHpChanged, retMsg3);
                }
                else//!怪物寻路追打角色
                {
                    GamePoint nextPos = FindPath(new GamePoint(monster.x, monster.y), new GamePoint(player.x, player.y));
                    if (GetRoleByPos(nextPos.x, nextPos.y) != null)
                    {
                        continue;
                    }
                    monster.x = nextPos.x;
                    monster.y = nextPos.y;
                    Pbmsg.RunRet runRet = new Pbmsg.RunRet()
                    {
                        Id = monster.GetID(),
                        X  = monster.x,
                        Y  = monster.y,
                    };
                    BroadcastPlayerMsg <Pbmsg.RunRet>(Pbmsg.ServerCmdDef.SRun, runRet);
                }
            }
            FFNet.Timerout(800, this.HandleMonsterAI);
        }
Beispiel #6
0
        public void HandleMonsterAI()
        {
            foreach (Role role in m_dictRoles.Values)
            {
                if (role.hp == 0)
                {
                    if (Util.GetNowTimeMs() - role.nLastAttackedTime < 5000)
                    {
                        continue;
                    }
                    role.hp = 100;
                    Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(role);
                    BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                    continue;
                }
                if (!(role is Monster))
                {
                    continue;
                }

                Monster monster = role as Monster;
                if (monster.nLastAttackedRoleID == 0)
                {
                    continue;
                }
                Player player = GetPlayerBySessionID(monster.nLastAttackedRoleID);
                if (player == null || player.hp == 0)
                {
                    monster.nLastAttackedRoleID = 0;
                    continue;
                }
                int nDistance = Util.Distance(monster.x, monster.y, player.x, player.y);
                if (nDistance <= 1)
                {
                    Pbmsg.AttackRet monsterAttackMsg = new Pbmsg.AttackRet()
                    {
                        Id       = monster.GetID(),
                        Targetid = player.GetID(),
                    };
                    BroadcastPlayerMsg <Pbmsg.AttackRet>(Pbmsg.ServerCmdDef.SAttack, monsterAttackMsg);

                    Random rd         = new Random();
                    int    hpChaneged = 5 + rd.Next() % 5;

                    Role roleTarget = player;
                    if (roleTarget.hp >= hpChaneged)
                    {
                        roleTarget.hp -= hpChaneged;
                    }
                    else
                    {
                        roleTarget.hp = 0;
                    }
                    roleTarget.nLastAttackedTime = Util.GetNowTimeMs();
                    Pbmsg.HPChangedRet retMsg3 = new Pbmsg.HPChangedRet()
                    {
                        Id         = roleTarget.GetID(),
                        ValCur     = roleTarget.hp,
                        ValChanged = hpChaneged,
                    };
                    BroadcastPlayerMsg <Pbmsg.HPChangedRet>(Pbmsg.ServerCmdDef.SHpChanged, retMsg3);
                }
            }
            FFNet.Timerout(2000, this.HandleMonsterAI);
        }