コード例 #1
0
        public void HandleLogin(Player player, Pbmsg.LoginReq reqMsg)
        {
            player.strName = reqMsg.Name;
            player.nLevel  = 1;
            Pbmsg.LoginRet retMsg = new Pbmsg.LoginRet()
            {
                Id    = player.getID(),
                Name  = reqMsg.Name,
                Level = player.nLevel,
            };
            SendPlayerMsg <Pbmsg.LoginRet>(player, Pbmsg.ServerCmdDef.SLogin, retMsg);

            {
                Pbmsg.EnterMapRet enterMapRet = new Pbmsg.EnterMapRet()
                {
                    Id        = player.getID(),
                    Name      = player.strName,
                    Level     = player.nLevel,
                    X         = player.x,
                    Y         = player.y,
                    Hp        = player.hp,
                    Direction = player.direction,
                    ObjType   = 0,
                };

                BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            }


            foreach (Role roleOther in m_dictRoles.Values)
            {
                if (roleOther.getID() == player.getID())
                {
                    continue;
                }
                Pbmsg.EnterMapRet enterMapRet = new Pbmsg.EnterMapRet()
                {
                    Id        = roleOther.getID(),
                    Name      = roleOther.strName,
                    Level     = roleOther.nLevel,
                    X         = roleOther.x,
                    Y         = roleOther.y,
                    Hp        = roleOther.hp,
                    ObjType   = 0,
                    Direction = roleOther.direction
                };
                if (roleOther is Monster)
                {
                    enterMapRet.ObjType = 1;
                }

                if (roleOther.hp == 0)
                {
                    roleOther.hp   = 100;
                    enterMapRet.Hp = roleOther.hp;
                    BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                }
                SendPlayerMsg <Pbmsg.EnterMapRet>(player, Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            }
        }
コード例 #2
0
 public Pbmsg.EnterMapRet BuildEnterMsg(Role role)
 {
     Pbmsg.EnterMapRet enterMapRet = new Pbmsg.EnterMapRet()
     {
         Id        = role.GetID(),
         Name      = role.strName,
         Level     = role.nLevel,
         X         = role.x,
         Y         = role.y,
         Hp        = role.hp,
         Direction = role.direction,
         ObjType   = role is Player ? 0 : 1,
         ApprID    = role.apprID,
     };
     return(enterMapRet);
 }
コード例 #3
0
        public void HandleLogin(Player player, Pbmsg.LoginReq reqMsg)
        {
            player.strName = reqMsg.Name;
            player.nLevel  = 1;
            Pbmsg.LoginRet retMsg = new Pbmsg.LoginRet()
            {
                Id    = player.GetID(),
                Name  = reqMsg.Name,
                Level = player.nLevel,
            };
            SendPlayerMsg <Pbmsg.LoginRet>(player, Pbmsg.ServerCmdDef.SLogin, retMsg);
            //for (int i = 0; i < 100; ++i)
            //{
            //    SendPlayerMsg<Pbmsg.LoginRet>(player, Pbmsg.ServerCmdDef.SLogin, retMsg);
            //}

            {
                Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(player);
                BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);

                player.playerYS = new Player()
                {
                    nSessionID = player.nSessionID + 100000, strName = player.strName + "的元神", idZhuTi = player.GetID()
                };
                player.playerYS.x = player.x - 1;
                player.playerYS.y = player.y - 1;
                m_dictRoles[player.playerYS.nSessionID] = player.playerYS;

                enterMapRet = BuildEnterMsg(player.playerYS);
                BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            }

            foreach (Role roleOther in m_dictRoles.Values)
            {
                if (roleOther.GetID() == player.GetID())
                {
                    continue;
                }
                if (roleOther.hp == 0)
                {
                    continue;
                }
                Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(roleOther);
                SendPlayerMsg <Pbmsg.EnterMapRet>(player, Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                //System.Threading.Thread.Sleep(100);
            }
        }
コード例 #4
0
 public Pbmsg.EnterMapRet BuildEnterMsg(Role role)
 {
     Pbmsg.EnterMapRet enterMapRet = new Pbmsg.EnterMapRet()
     {
         Id        = role.GetID(),
         Name      = role.strName,
         Level     = role.nLevel,
         X         = role.x,
         Y         = role.y,
         Hp        = role.hp,
         Direction = role.direction,
         ObjType   = role is Player ? 0 : 1,
         ApprID    = role.apprID,
         OwnerID   = 0,
     };
     if (role is Player)
     {
         Player player = role as Player;
         enterMapRet.OwnerID = player.idZhuTi;
     }
     return(enterMapRet);
 }
コード例 #5
0
        public void HandleLogin(Player player, Pbmsg.LoginReq reqMsg)
        {
            player.strName = reqMsg.Name;
            player.nLevel  = 1;
            Pbmsg.LoginRet retMsg = new Pbmsg.LoginRet()
            {
                Id    = player.GetID(),
                Name  = reqMsg.Name,
                Level = player.nLevel,
            };
            SendPlayerMsg <Pbmsg.LoginRet>(player, Pbmsg.ServerCmdDef.SLogin, retMsg);
            for (int i = 0; i < 100; ++i)
            {
                SendPlayerMsg <Pbmsg.LoginRet>(player, Pbmsg.ServerCmdDef.SLogin, retMsg);
            }

            {
                Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(player);
                BroadcastPlayerMsg <Pbmsg.EnterMapRet>(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            }


            foreach (Role roleOther in m_dictRoles.Values)
            {
                if (roleOther.GetID() == player.GetID())
                {
                    continue;
                }
                if (roleOther.hp == 0)
                {
                    continue;
                }
                Pbmsg.EnterMapRet enterMapRet = BuildEnterMsg(roleOther);
                SendPlayerMsg <Pbmsg.EnterMapRet>(player, Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
                //System.Threading.Thread.Sleep(100);
            }
        }
コード例 #6
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);
                }
            });
        }
コード例 #7
0
        public void HandleLogin(Int64 nSessionID, Pbmsg.LoginReq reqMsg)
        {
            Player playerOld = RoleMgr.Instance().GetPlayerBySessionID(nSessionID);

            if (playerOld != null)
            {
                if (playerOld.nSessionID == nSessionID)
                {
                    FFLog.Error(string.Format("worker cmd invalid! {0} login twice", nSessionID));
                }
                return;
            }

            Player player = new Player()
            {
                nSessionID = nSessionID
            };

            RoleMgr.Instance().AddRole(player);

            player.strName = reqMsg.Name;
            player.nLevel  = 1;

            Pbmsg.LoginRet retMsg = new Pbmsg.LoginRet()
            {
                Id    = player.GetID(),
                Name  = reqMsg.Name,
                Level = player.nLevel,
            };

            player.SendPlayerMsg(Pbmsg.ServerCmdDef.SLogin, retMsg);

            {
                Pbmsg.EnterMapRet enterMapRet = player.BuildEnterMsg();
                FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);

                player.playerYS = new Player()
                {
                    nSessionID = player.nSessionID + 100000, strName = player.strName + "的元神", idZhuTi = player.GetID()
                };
                player.playerYS.x      = player.x - 1;
                player.playerYS.y      = player.y - 1;
                player.playerYS.apprID = player.apprID;
                RoleMgr.Instance().AddRole(player.playerYS);

                enterMapRet = player.playerYS.BuildEnterMsg();
                FFWorker.Instance().GateBroadcastMsg((int)Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            }

            RoleMgr.Instance().ForeachRole((Role roleOther) => {
                if (roleOther.GetID() == player.GetID())
                {
                    return;
                }
                if (roleOther.hp == 0)
                {
                    return;
                }
                Pbmsg.EnterMapRet enterMapRet = roleOther.BuildEnterMsg();
                player.SendPlayerMsg(Pbmsg.ServerCmdDef.SEnterMap, enterMapRet);
            });
        }
コード例 #8
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);
        }
コード例 #9
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);
        }