Пример #1
0
        /// <summary>
        /// 掉落网络物品
        /// </summary>
        /// <param name="mon">Mon.</param>
        public static void DropStaticGoods(NpcAttribute mon)
        {
            var treasure = mon.GetDropTreasure();

            foreach (var d in treasure)
            {
                Log.Sys("DropTreasure " + d.Count);
                var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)d[0]);
                int num      = 1;
                if (d.Count >= 3)
                {
                    num = (int)d[2];
                }

                DropItemStatic.MakeDropItem(itemData, mon.transform.position + new Vector3(0, 0.4f, 0), num, mon.GetNetView().GetServerID());
            }
        }
Пример #2
0
        void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("Map4Receive: " + proto);
            var cmds = proto.Result.Split(' ');

            if (cmds [0] == "Login")
            {
                myId = Convert.ToInt32(cmds [1]);
                ObjectManager.objectManager.RefreshMyServerId(myId);
            }
            else if (cmds [0] == "Add")
            {
                ObjectManager.objectManager.CreateOtherPlayer(proto.AvatarInfo);
                PlayerDataInterface.DressEquip(proto.AvatarInfo);
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkMove(proto.AvatarInfo);
                    }
                    else
                    {
                        var sync2 = player.GetComponent <MySelfAttributeSync>();
                        sync2.NetworkAttribute(proto.AvatarInfo);
                    }
                }
            }
            else if (cmds [0] == "Remove")
            {
                ObjectManager.objectManager.DestroyPlayer(proto.AvatarInfo.Id);
            }
            else if (cmds [0] == "Update")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkMove(proto.AvatarInfo);
                    }
                    else
                    {
                        var myselfAttr = player.GetComponent <MySelfAttributeSync>();
                        if (myselfAttr != null)
                        {
                            myselfAttr.NetworkAttribute(proto.AvatarInfo);
                        }
                    }
                }
            }
            else if (cmds [0] == "Damage")
            {
                var dinfo = proto.DamageInfo;
                var enemy = ObjectManager.objectManager.GetPlayer(dinfo.Enemy);
                if (enemy != null)
                {
                    var sync = enemy.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
                if (!NetworkUtil.IsMaster() && enemy != null)
                {
                    var sync = enemy.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
            }
            else if (cmds [0] == "Skill")
            {
                var sk     = proto.SkillAction;
                var player = ObjectManager.objectManager.GetPlayer(sk.Who);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.NetworkAttack(sk);
                    }
                }
            }
            else if (cmds [0] == "Buff")
            {
                var target = proto.BuffInfo.Target;
                var sync   = NetDateInterface.GetPlayer(target);
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (sync != null)
                {
                    sync.NetworkBuff(proto);
                }
                if (player != null && !NetworkUtil.IsNetMaster())
                {
                    var monSync = player.GetComponent <MonsterSync>();
                    if (monSync != null)
                    {
                        monSync.NetworkBuff(proto);
                    }
                }
            }
            else if (cmds [0] == "AddEntity")
            {
                var ety = proto.EntityInfo;
                if (ety.EType == EntityType.CHEST)
                {
                    StartCoroutine(WaitZoneInit(ety));
                }
                else if (ety.EType == EntityType.DROP)
                {
                    var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)ety.ItemId);
                    var itemNum  = ety.ItemNum;
                    var pos      = NetworkUtil.FloatPos(ety.X, ety.Y, ety.Z);
                    DropItemStatic.MakeDropItemFromNet(itemData, pos, itemNum, ety);
                }
            }
            else if (cmds [0] == "UpdateEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                Log.Net("UpdateEntityHP: " + ety.Id + " hp " + ety.HasHP + " h " + ety.HP);
                if (!NetworkUtil.IsMaster() && mon != null)
                {
                    var sync = mon.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.SyncAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "RemoveEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                if (!NetworkUtil.IsMaster() && mon != null)
                {
                    var netView = mon.GetComponent <KBEngine.KBNetworkView>();
                    if (netView != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(netView.GetLocalId());
                    }
                }
            }
            else if (cmds [0] == "Pick")
            {
                if (!NetworkUtil.IsMaster())
                {
                    var action = proto.PickAction;
                    var ety    = ObjectManager.objectManager.GetPlayer(action.Id);
                    var who    = ObjectManager.objectManager.GetPlayer(action.Who);
                    if (ety != null)
                    {
                        var item = ety.GetComponent <DropItemStatic>();
                        if (item != null)
                        {
                            item.PickItemFromNetwork(who);
                        }
                    }
                }
            }
            else if (cmds [0] == "Revive")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <PlayerSync>();
                    if (sync != null)
                    {
                        sync.Revive();
                    }
                }
            }
            else if (cmds [0] == "Dead")
            {
                var dinfo = proto.DamageInfo;
                ScoreManager.Instance.NetAddScore(dinfo.Attacker, dinfo.Enemy);
            }
            else if (cmds [0] == "SyncTime")
            {
                if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetSyncTime(proto.LeftTime);
                }
            }
            else if (cmds [0] == "GameOver")
            {
                if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetworkGameOver();
                }
            }
            else if (cmds [0] == "AllReady")
            {
                Util.ShowMsg("所有客户端准备完成");
                //当所有客户端准备好之后 服务器推送Entity给所有客户端
                NetMatchScene.Instance.SetAllReady();

                //更新IsMaster 这样才能生成Entity
                var player     = ObjectManager.objectManager.GetMyPlayer();
                var myselfAttr = player.GetComponent <MySelfAttributeSync>();
                var matchRoom  = NetMatchScene.Instance.GetComponent <MatchRoom>();
                if (myselfAttr != null)
                {
                    myselfAttr.NetworkAttribute(matchRoom.GetMyInfo());
                }
            }
        }
Пример #3
0
        public void MsgHandler(KBEngine.Packet packet)
        {
            var proto = packet.protoBody as GCPlayerCmd;

            Log.Net("Map4Receive: " + proto);
            var cmds = proto.Result.Split(' ');
            var cmd0 = cmds[0];

            if (cmds [0] == "Add")
            {
                ObjectManager.objectManager.CreateOtherPlayer(proto.AvatarInfo);
                //PlayerDataInterface.DressEquip(proto.AvatarInfo);
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();

                    if (!proto.AvatarInfo.HasScore)
                    {
                        proto.AvatarInfo.Score = 0;
                    }
                    if (sync != null)
                    {
                        var ainfo = NetMatchScene.Instance.matchRoom.GetPlayerInfo(proto.AvatarInfo.Id);
                        sync.InitSync(ainfo);
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Remove")
            {
                ObjectManager.objectManager.DestroyPlayer(proto.AvatarInfo.Id);
            }
            else if (cmds [0] == "Update")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "Damage")
            {
                var dinfo = proto.DamageInfo;
                var enemy = ObjectManager.objectManager.GetPlayer(dinfo.Enemy);
                if (enemy != null)
                {
                    var sync = enemy.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.DoNetworkDamage(proto);
                    }
                }
            }
            else if (cmds [0] == "Skill")
            {
                var sk     = proto.SkillAction;
                var player = ObjectManager.objectManager.GetPlayer(sk.Who);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkAttack(proto);
                    }
                }
            }
            else if (cmds [0] == "Buff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkBuff(proto);
                    }
                }

                /*
                 * var target = proto.BuffInfo.Target;
                 * var sync = NetDateInterface.GetPlayer(target);
                 * var player = ObjectManager.objectManager.GetPlayer(target);
                 * if (sync != null)
                 * {
                 *  sync.NetworkBuff(proto);
                 * }
                 * else if(player != null)
                 * {
                 *  var sync2 = player.GetComponent<MySelfAttributeSync>();
                 *  if (sync2 != null)
                 *  {
                 *      sync2.NetworkBuff(proto);
                 *  }
                 * }
                 * if (player != null && !NetworkUtil.IsNetMaster())
                 * {
                 *  var monSync = player.GetComponent<MonsterSync>();
                 *  if (monSync != null)
                 *  {
                 *      monSync.NetworkBuff(proto);
                 *  }
                 * }
                 */
            }
            else if (cmds[0] == "RemoveBuff")
            {
                var target = proto.BuffInfo.Target;
                var player = ObjectManager.objectManager.GetPlayer(target);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.NetworkRemoveBuff(proto);
                    }
                }
            }
            else if (cmds [0] == "AddEntity")
            {
                var ety = proto.EntityInfo;
                if (ety.EType == EntityType.CHEST)
                {
                    WaitZoneInit(ety);
                }
                else if (ety.EType == EntityType.DROP)
                {
                    var itemData = Util.GetItemData((int)ItemData.GoodsType.Props, (int)ety.ItemId);
                    var itemNum  = ety.ItemNum;
                    var pos      = NetworkUtil.FloatPos(ety.X, ety.Y, ety.Z);
                    DropItemStatic.MakeDropItemFromNet(itemData, pos, itemNum, ety);
                }
            }
            else if (cmds [0] == "UpdateEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                Log.Net("UpdateEntityHP: " + ety.Id + " hp " + ety.HasHP + " h " + ety.HP + ":" + ety + ":" + mon);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var sync = mon.GetComponent <MonsterSync>();
                    if (sync != null)
                    {
                        sync.NetworkAttribute(proto);
                    }
                }
            }
            else if (cmds [0] == "RemoveEntity")
            {
                var ety = proto.EntityInfo;
                var mon = ObjectManager.objectManager.GetPlayer(ety.Id);
                //if (!NetworkUtil.IsMaster() && mon != null)
                if (mon != null)
                {
                    var netView = mon.GetComponent <KBEngine.KBNetworkView>();
                    if (netView != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(netView.GetLocalId());
                    }
                }
            }
            else if (cmds [0] == "Pick")
            {
                //if (!NetworkUtil.IsMaster())
                {
                    var action = proto.PickAction;
                    var ety    = ObjectManager.objectManager.GetPlayer(action.Id);
                    var who    = ObjectManager.objectManager.GetPlayer(action.Who);
                    if (ety != null)
                    {
                        var item = ety.GetComponent <DropItemStatic>();
                        if (item != null)
                        {
                            item.PickItemFromNetwork(who);
                        }
                    }
                }
            }
            else if (cmds [0] == "Revive")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.AvatarInfo.Id);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Revive(proto);
                    }
                }
            }
            else if (cmd0 == "DeadActor")
            {
                var player = ObjectManager.objectManager.GetPlayer(proto.ActorId);
                if (player != null)
                {
                    var sync = player.GetComponent <ISyncInterface>();
                    if (sync != null)
                    {
                        sync.Dead(proto);
                    }
                }
            }
            else if (cmds [0] == "Dead")
            {
                //ScoreManager.Instance.NetAddScore(dinfo.Attacker, dinfo.Enemy);
                ScoreManager.Instance.Dead(proto);
            }
            else if (cmds [0] == "SyncTime")
            {
                //if (!NetworkUtil.IsNetMaster())
                ScoreManager.Instance.NetSyncTime(proto.LeftTime);
            }
            else if (cmds [0] == "GameOver")
            {
                //if (!NetworkUtil.IsNetMaster())
                {
                    ScoreManager.Instance.NetworkGameOver();
                }
            }
            else if (cmds [0] == "AllReady")
            {
                Util.ShowMsg("所有客户端准备完成");
                //当所有客户端准备好之后 服务器推送Entity给所有客户端
                NetMatchScene.Instance.SetAllReady();
            }
            else if (cmds[0] == "News")
            {
                var con = proto.News;
                Util.ShowMsg(con);
            }
            else if (cmds[0] == "UDPLost")
            {
                Util.ShowMsg("Server Side UDPLost!");
                UDPLost();
            }
            else if (cmd0 == "SyncFrame")
            {
                SyncFrame(proto);
            }
        }