Example #1
0
        //为玩家增加Buff
        void OnTriggerEnter(Collider other)
        {
            if (NetworkUtil.IsNetMaster())
            {
                if (other.tag == GameTag.Player)
                {
                    //击退技能
                    var pos     = other.transform.position;
                    var otherGo = other.gameObject;

                    var skill     = Util.GetSkillData(140, 1);
                    var skillInfo = SkillLogic.GetSkillInfo(skill);
                    var evt       = skillInfo.eventList[0];
                    var ret       = gameObject.GetComponent <BuffComponent>().AddBuff(evt.affix, pos);
                    if (ret)
                    {
                        NetDateInterface.FastAddBuff(evt.affix, otherGo, gameObject, skill.Id, evt.EvtId);
                    }
                }
            }
        }
Example #2
0
 public override IEnumerator RunLogic()
 {
     //等网络属性同步上去了再删除对象 Hp = 0 接着等一会删除对象
     if (NetworkUtil.IsNetMaster())
     {
         //yield return new WaitForSeconds(5);
         var cg = CGPlayerCmd.CreateBuilder();
         cg.Cmd = "RemoveEntity";
         var ety = EntityInfo.CreateBuilder();
         ety.Id        = GetAttr().GetNetView().GetServerID();
         cg.EntityInfo = ety.Build();
         var world = WorldManager.worldManager.GetActive();
         world.BroadcastMsg(cg);
         ObjectManager.objectManager.DestroyByLocalId(GetAttr().GetComponent <KBEngine.KBNetworkView>().GetLocalId());
     }
     else
     {
         ObjectManager.objectManager.DestroyByLocalId(GetAttr().GetComponent <KBEngine.KBNetworkView>().GetLocalId());
     }
     yield return(null);
 }
Example #3
0
        /// <summary>
        ///相同的技能 Skill Configure来触发Buff 但是不要触发 Buff修改非表现属性
        /// </summary>
        /// <param name="affix">Affix.</param>
        /// <param name="attacker">Attacker.</param>
        /// <param name="target">Target.</param>
        public static void FastAddBuff(Affix affix, GameObject attacker, GameObject target, int skillId, int evtId)
        {
            var cg    = CGPlayerCmd.CreateBuilder();
            var binfo = BuffInfo.CreateBuilder();

            binfo.BuffType = (int)affix.effectType;
            binfo.Attacker = attacker.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.Target   = target.GetComponent <KBEngine.KBNetworkView>().GetServerID();
            binfo.SkillId  = skillId;
            binfo.EventId  = evtId;
            var pos = attacker.transform.position;

            binfo.AddAttackerPos((int)(pos.x * 100));
            binfo.AddAttackerPos((int)(pos.y * 100));
            binfo.AddAttackerPos((int)(pos.z * 100));

            var pos1 = NetworkUtil.ConvertPos(target.transform.position);

            binfo.X   = pos1[0];
            binfo.Y   = pos1[1];
            binfo.Z   = pos1[2];
            binfo.Dir = (int)target.transform.eulerAngles.y;

            var eft  = BuffManager.buffManager.GetBuffInstance(affix.effectType);
            var buff = (IEffect)Activator.CreateInstance(eft);

            buff.attacker = attacker;
            buff.target   = target;
            var param = buff.GetExtraParams();

            binfo.Params = param;

            cg.BuffInfo = binfo.Build();
            cg.Cmd      = "Buff";
            var sc = WorldManager.worldManager.GetActive();

            sc.BroadcastMsg(cg);
        }
Example #4
0
        public void SyncToServer()
        {
            var me     = gameObject;
            var pos    = me.transform.position;
            var dir    = (int)me.transform.localRotation.eulerAngles.y;
            var meAttr = me.GetComponent <NpcAttribute>();
            var intPos = NetworkUtil.ConvertPos(pos);
            var ainfo  = EntityInfo.CreateBuilder();

            ainfo.Id = meAttr.GetNetView().GetServerID();
            var change = false;

            if (intPos [0] != lastInfo.X || intPos [1] != lastInfo.Y || intPos [2] != lastInfo.Z)
            {
                change  = true;
                ainfo.X = intPos [0];
                ainfo.Y = intPos [1];
                ainfo.Z = intPos [2];

                lastInfo.X = intPos [0];
                lastInfo.Y = intPos [1];
                lastInfo.Z = intPos [2];
            }
            if (meAttr.HP != lastInfo.HP)
            {
                change      = true;
                ainfo.HP    = meAttr.HP;
                lastInfo.HP = meAttr.HP;
            }
            if (change)
            {
                var etyInfo = ainfo.Build();
                var cg      = CGPlayerCmd.CreateBuilder();
                cg.Cmd        = "UpdateEntityData";
                cg.EntityInfo = etyInfo;
                NetworkUtil.Broadcast(cg);
            }
        }
Example #5
0
 /// <summary>
 /// Master 退出场景所有的Entities都销毁掉简单处理
 /// </summary>
 /// <param name="unitData">Unit data.</param>
 /// <param name="spawn">Spawn.</param>
 public void CreateChest(UnitData unitData, SpawnChest spawn)
 {
     if (NetworkUtil.IsNetMaster())
     {
         var cg = CGPlayerCmd.CreateBuilder();
         cg.Cmd = "AddEntity";
         var entityInfo = EntityInfo.CreateBuilder();
         entityInfo.UnitId = unitData.ID;
         var ip = NetworkUtil.ConvertPos(spawn.transform.position);
         entityInfo.X       = ip [0];
         entityInfo.Y       = ip [1];
         entityInfo.Z       = ip [2];
         entityInfo.SpawnId = spawn.SpawnId;
         entityInfo.HP      = unitData.HP;
         cg.EntityInfo      = entityInfo.Build();
         var scene = WorldManager.worldManager.GetActive();
         scene.BroadcastMsg(cg);
     }
     else
     {
         CreateChestFromNetwork(unitData, spawn);
     }
 }
Example #6
0
        void OnTriggerEnter(Collider other)
        {
            Log.Sys("MoveBlock Enter : " + other.gameObject);
            if (NetworkUtil.IsNetMaster())
            {
                if (other.tag == GameTag.Player)
                {
                    //击退技能
                    var pos     = other.transform.position;
                    var otherGo = other.gameObject;
                    //dy dx 比较 那个大 保留那个 同时另外一个修正为 自己的pos
                    var par   = transform.parent.gameObject;
                    var myPos = par.transform.position;

                    //假设箱子都是 正方体
                    var dx = myPos.x - pos.x;
                    var dz = myPos.z - pos.z;
                    if (Mathf.Abs(dx) < Mathf.Abs(dz))
                    {
                        pos.x = myPos.x;
                    }
                    else
                    {
                        pos.z = myPos.z;
                    }

                    var skill     = Util.GetSkillData((int)SkillData.SkillConstId.KnockBack, 1);
                    var skillInfo = SkillLogic.GetSkillInfo(skill);
                    var evt       = skillInfo.eventList [0];
                    var ret       = par.GetComponent <BuffComponent>().AddBuff(evt.affix, pos);
                    if (ret)
                    {
                        NetDateInterface.FastAddBuff(evt.affix, otherGo, par, skill.Id, evt.EvtId, pos);
                    }
                }
            }
        }
Example #7
0
 public static Vector3 FloatPos(AvatarInfo curInfo)
 {
     return(NetworkUtil.FloatPos(curInfo.X, curInfo.Y, curInfo.Z));
 }
Example #8
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());
                }
            }
        }
Example #9
0
        /*
         * public void CreateNpc(UnitData unitData, GameObject spawn)
         * {
         *  if (WorldManager.worldManager.station == WorldManager.WorldStation.Enter)
         *  {
         *      var Resource = Resources.Load<GameObject>(unitData.ModelName);
         *      GameObject g = Instantiate(Resource) as GameObject;
         *      if (g.GetComponent<CharacterController>() == null)
         *      {
         *          var c = g.AddComponent<CharacterController>();
         *          c.center = new Vector3(0, 0.7f, 0);
         *          c.height = 1.6f;
         *      }
         *
         *      NpcAttribute npc = NGUITools.AddMissingComponent<NpcAttribute>(g);
         *
         *      var type = Type.GetType("MyLib." + unitData.AITemplate);
         *      var t = typeof(NGUITools);
         *      var m = t.GetMethod("AddMissingComponent");
         *      Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
         *      var geMethod = m.MakeGenericMethod(type);
         *      geMethod.Invoke(null, new object[]{ g });// as AIBase;
         *
         *      g.transform.parent = transform;
         *      g.tag = GameTag.Npc; //Player Or Npc
         *      g.layer = (int)GameLayer.IgnoreCollision;
         *
         *      //Register Unique Id To Npc
         *      var netView = g.GetComponent<KBEngine.KBNetworkView>();
         *      netView.SetServerID(Util.NotInitServerID);
         *      netView.IsPlayer = false;
         *
         *      npc.SetObjUnitData(unitData);
         *      AddObject(netView.GetServerID(), netView);
         *
         *      npc.transform.position = spawn.transform.position;
         *      var rotY = spawn.transform.localRotation.eulerAngles.y;
         *      npc.transform.localRotation = Quaternion.Euler(new Vector3(0, rotY, 0));
         *
         *      NpcManager.Instance.RegNpc(unitData.name, g);
         *  } else
         *  {
         *      cacheNpc.Add(new MonsterInit(unitData, spawn));
         *  }
         * }
         */

        /// <summary>
        /// 伤害区域
        /// Moba中的移动小兵
        /// </summary>
        /// <param name="unitData"></param>
        /// <param name="spawn"></param>
        /// <param name="info"></param>
        public void CreateSpawnZoneEntity(UnitData unitData, SpawnZone spawn, EntityInfo info)
        {
            Log.Sys("CreateSpawnZoneEntity: " + unitData + spawn + " info " + info);
            //TODO: 这里可能有BUG
            if (info != null)
            {
                var oldMon = ObjectManager.objectManager.GetPlayer(info.Id);
                if (oldMon != null)
                {
                    var nv = oldMon.GetComponent <KBEngine.KBNetworkView>();
                    if (nv != null)
                    {
                        ObjectManager.objectManager.DestroyByLocalId(nv.GetLocalId());
                    }
                }
            }

            var          Resource = Resources.Load <GameObject>(unitData.ModelName);
            GameObject   g        = Instantiate(Resource) as GameObject;
            NpcAttribute npc      = NGUITools.AddMissingComponent <NpcAttribute>(g);

            //npc.spawnTrigger = spawn.gameObject;

            g.transform.parent = transform;
            g.tag   = GameTag.Enemy;
            g.layer = (int)GameLayer.Npc;
            if (info != null)
            {
                g.name += "_" + info.Id;
            }

            var type = Type.GetType("MyLib." + unitData.AITemplate);
            var t    = typeof(NGUITools);
            var m    = t.GetMethod("AddMissingComponent");

            Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
            var geMethod = m.MakeGenericMethod(type);

            geMethod.Invoke(null, new object[] { g });// as AIBase;


            var netView = g.GetComponent <KBEngine.KBNetworkView>();

            //服务器返回的ViewId
            //Owner 客户端怪物 服务器怪物
            //Id ViewId
            if (info != null)
            {
                netView.SetServerID(info.Id);
            }
            else
            {
                netView.SetServerID(Util.NotInitServerID);
            }

            netView.IsPlayer = false;

            npc.SetObjUnitData(unitData);
            AddObject(netView.GetServerID(), netView);

            //不算怪物允许不去打
            if (info != null)
            {
                npc.transform.position = NetworkUtil.FloatPos(info.X, info.Y, info.Z);
            }
            else
            {
                //npc.transform.position = spawn.transform.position;
            }

            //BattleManager.battleManager.AddEnemy(npc.gameObject);
            //npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;

            var sync = npc.GetComponent <MonsterSync>();

            if (sync != null)
            {
                sync.SyncAttribute(info);
            }
        }
Example #10
0
        public void PickItemFromNetwork(GameObject who)
        {
            pickYet = true;
            var whoAttr = NetworkUtil.GetAttr(who);

            BackgroundSound.Instance.PlayEffect("pickup");
            GameObject.Destroy(gameObject);
            var me = ObjectManager.objectManager.GetMyPlayer();

            Log.Sys("PickItemFromNetwork: " + whoAttr + " itemType: " + itemData.UnitType);

            var gen = Resources.Load <GameObject>("particles/drops/generic_item");
            var par = ParticlePool.Instance.GetGameObject(gen, ParticlePool.InitParticle);

            //var par = Instantiate() as GameObject;

            //par.transform.parent = g.transform;
            par.transform.position = gameObject.transform.position;
            var rm = par.AddMissingComponent <RemoveSelf>();

            rm.StartCoroutine(rm.WaitReturn(3));

            if (whoAttr != null && whoAttr.gameObject == me)
            {
                if (itemData.UnitType == ItemData.UnitTypeEnum.POWER_DRUG)
                {
                    WindowMng.windowMng.ShowNotifyLog("炸弹威力上升");
                    GameInterface_Backpack.LearnSkill((int)SkillData.SkillConstId.Bomb);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.QIPAO_DRUG)
                {
                    var attr = ObjectManager.objectManager.GetMyAttr();
                    attr.AddMpMax(20);
                    attr.AddThrowSpeed(0.1f);
                    WindowMng.windowMng.ShowNotifyLog("MP上限增加");
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.XieZi_DRUG)
                {
                    ObjectManager.objectManager.GetMyAttr().AddNetSpeed(0.1f);
                    WindowMng.windowMng.ShowNotifyLog("速度提升");
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.LIAN_FA)
                {
                    GameInterface_Skill.AddSkillBuff(me, (int)GameBuff.LianFa, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("连发弹");
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.POTION)
                {
                    GameInterface_Skill.AddSkillBuff(me, (int)GameBuff.AddHP, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("恢复生命");
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.FASHI)
                {
                    var attr = ObjectManager.objectManager.GetMyAttr();
                    attr.SetNetSpeed(0);
                    attr.SetJob(Job.ALCHEMIST);
                    WindowMng.windowMng.ShowNotifyLog("攻击提升", 2, null, true);
                    WindowMng.windowMng.ShowNotifyLog("生命值变化", 2, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.CIKE)
                {
                    var attr = ObjectManager.objectManager.GetMyAttr();
                    attr.SetJob(Job.ARMOURER);
                    attr.SetNetSpeed(0.5f);
                    WindowMng.windowMng.ShowNotifyLog("移动速度加快", 2, null, true);
                    WindowMng.windowMng.ShowNotifyLog("生命值变化", 2, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.SUPER)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.SuperShoot, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("拾获超能子弹", 2, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.HIDE)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.Hide, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("拾获隐身药水", 2, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.NUCLEAR)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.NuclearBuff, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("拾获核弹,使用后立即逃离区域", 4, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.KNOCK)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.KnockBuff, Vector3.zero);
                    WindowMng.windowMng.ShowNotifyLog("获得击退能力", 4, null, true);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.WUDI)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.WuDi, Vector3.zero);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.DaoDan)
                {
                    GameInterface_Skill.AddBuffWithNet(me, (int)GameBuff.DaoDan, Vector3.zero);
                }
                else if (itemData.UnitType == ItemData.UnitTypeEnum.DefaultSkill)
                {
                    GameInterface_Skill.AddBuffWithNet(me, itemData.triggerBuffId, Vector3.zero);
                    Util.ShowMsg("获得" + itemData.ItemName);
                }
                else
                {
                    GameInterface_Backpack.PickItem(itemData, num);
                }
            }
        }
Example #11
0
        /*
         *客户端表现粒子和服务器计算伤害的数值分离开来
         */

        private void HitSomething(Collider other)
        {
            Log.AI("Bullet collider enemy " + other.name + " " + other.tag);
            var otherAttr = NetworkUtil.GetAttr(other.gameObject);

            if (otherAttr != null && otherAttr.gameObject == attacker)
            {
                return;
            }

            if (SkillLogic.IsEnemyForBullet(attacker, other.gameObject))
            {
                var oattr = NetworkUtil.GetAttr(other.gameObject);
                if (oattr != null)
                {
                    var buff   = oattr.GetComponent <BuffComponent>();
                    var fanTan = buff.CheckHasSuchBuff(Affix.EffectType.FanTanBullet);
                    Log.Sys("CheckHasSuchBuff: " + fanTan);
                    if (fanTan && fanTanNum == 0)
                    {
                        fanTanNum++;
                        var dirY = transform.localRotation.eulerAngles.y;
                        transform.localRotation           = Quaternion.Euler(new Vector3(0, dirY + 180, 0));
                        this.runner.stateMachine.attacker = oattr.gameObject;
                        var l2 = Util.FindChildRecursive(this.transform, "blue");
                        if (l2 != null)
                        {
                            l2.gameObject.SetActive(false);
                            var l3 = Util.FindChildRecursive(this.transform, "red");
                            l3.gameObject.SetActive(true);
                        }
                        return;
                    }
                }

                //攻击多个目标只释放一次 DieParticle
                CreateHitParticle();
                //计算随机的弹射 反射方向
                if (LeftRicochets > 0)
                {
                    Log.AI("Generate new bullet " + LeftRicochets);
                    LeftRicochets--;
                    initPos = transform.position;
                    //子弹应该冲入怪物群中
                    transform.localRotation =
                        Quaternion.Euler(new Vector3(0,
                                                     transform.localRotation.eulerAngles.y +
                                                     Random.Range(-missileData.RandomAngle, missileData.RandomAngle), 0));
                }
                else
                {
                    //地震是穿透的因此只会等待粒子自然死亡
                    //非穿透性子弹
                    if (!missileData.piercing)
                    {
                        GameObject.Destroy(gameObject);
                    }
                }

                //伤害多个目标
                if (missileData.IsAOE)
                {
                    AOEDamage();
                }
                else
                {
                    DoDamage(other);
                }

                //非穿透性子弹
                if (!missileData.piercing)
                {
                    var evt = new MyEvent(MyEvent.EventType.EventMissileDie);
                    evt.missile = transform;
                    MyEventSystem.myEventSystem.PushLocalEvent(
                        attacker.GetComponent <KBEngine.KBNetworkView>().GetLocalId(), evt);
                }
                //TODO::撞击其它玩家如何处理
            }
            else
            {
//装到墙体 或者建筑物 等对象身上 则 反射  Not used
                Log.AI("Bullet colldier with Wall " + other.name);
                CreateHitParticle();


                if (LeftRicochets > 0)
                {
                    Log.AI("Generate new bullet " + LeftRicochets);
                    LeftRicochets--;
                    initPos = transform.position;
                    transform.localRotation =
                        Quaternion.Euler(new Vector3(0,
                                                     transform.localRotation.eulerAngles.y + 180 +
                                                     Random.Range(-missileData.RandomAngle, missileData.RandomAngle), 0));
                    //sleepTime = IgnoreTime;
                }
                else
                {
                    if (!missileData.piercing)
                    {
                        GameObject.Destroy(gameObject);
                    }
                }
                if (!missileData.piercing)
                {
                    var evt = new MyEvent(MyEvent.EventType.EventMissileDie);
                    evt.missile = transform;
                    if (attacker != null)
                    {
                        MyEventSystem.myEventSystem.PushLocalEvent(
                            attacker.GetComponent <KBEngine.KBNetworkView>().GetLocalId(), evt);
                    }
                }
            }
        }
Example #12
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);
            }
        }
Example #13
0
        /// <summary>
        /// 等待世界初始化结束 再初始化坦克网络
        /// </summary>
        /// <returns></returns>
        private IEnumerator WaitInitMap()
        {
            yield return(StartCoroutine(NetworkUtil.WaitForWorldInit()));

            netScene.InitMap();
        }
Example #14
0
        public void SyncAttribute()
        {
            var me     = gameObject;
            var pos    = me.transform.position;
            var dir    = (int)me.transform.localRotation.eulerAngles.y;
            var meAttr = me.GetComponent <NpcAttribute>();
            var intPos = NetworkUtil.ConvertPos(pos);

            var ainfo  = AvatarInfo.CreateBuilder();
            var change = false;

            //Pos 和 Dir 同时同步
            if (intPos [0] != lastInfo.X || intPos [1] != lastInfo.Y || intPos [2] != lastInfo.Z || dir != lastInfo.Dir)
            {
                ainfo.X = intPos [0];
                ainfo.Y = intPos [1];
                ainfo.Z = intPos [2];

                curInfo.X = ainfo.X;
                curInfo.Y = ainfo.Y;
                curInfo.Z = ainfo.Z;

                ainfo.Dir   = dir;
                curInfo.Dir = dir;
                change      = true;
            }

            if (meAttr.HP != lastInfo.HP)
            {
                ainfo.HP   = meAttr.HP;
                curInfo.HP = meAttr.HP;
                change     = true;
            }
            var intNetSpeed = (int)(meAttr.NetSpeed * 100);

            if (intNetSpeed != lastInfo.NetSpeed)
            {
                ainfo.NetSpeed   = intNetSpeed;
                curInfo.NetSpeed = intNetSpeed;
                change           = true;
            }
            var intThrowSpeed = (int)(meAttr.ThrowSpeed * 100);

            if (intThrowSpeed != lastInfo.ThrowSpeed)
            {
                ainfo.ThrowSpeed   = intThrowSpeed;
                curInfo.ThrowSpeed = intThrowSpeed;
                change             = true;
            }
            var intJumpSpeed = (int)(meAttr.JumpForwardSpeed * 100);

            if (intJumpSpeed != lastInfo.JumpForwardSpeed)
            {
                ainfo.JumpForwardSpeed   = intJumpSpeed;
                curInfo.JumpForwardSpeed = intJumpSpeed;
                change = true;
            }

            if (meAttr.userName != lastInfo.Name)
            {
                ainfo.Name   = meAttr.userName;
                curInfo.Name = meAttr.userName;
                change       = true;
            }

            if (lastInfo.Job != ServerData.Instance.playerInfo.Roles.Job)
            {
                ainfo.Job   = ServerData.Instance.playerInfo.Roles.Job;
                curInfo.Job = ainfo.Job;
                change      = true;
            }

            if (change)
            {
                lastInfo = AvatarInfo.CreateBuilder(curInfo).Build();

                var cg = CGPlayerCmd.CreateBuilder();
                cg.Cmd        = "UpdateData";
                cg.AvatarInfo = ainfo.Build();
                NetworkUtil.Broadcast(cg);
            }
        }
Example #15
0
        public void CreateChestFromNetwork(UnitData unitData, SpawnChest spawn, EntityInfo info = null)
        {
            Log.Sys("Create Chest Unit " + unitData.name);
            var          Resource = Resources.Load <GameObject>(unitData.ModelName);
            GameObject   g        = Instantiate(Resource) as GameObject;
            NpcAttribute npc      = NGUITools.AddMissingComponent <NpcAttribute>(g);

            npc.spawnTrigger = spawn.gameObject;

            g.transform.parent = transform;
            g.tag   = GameTag.Enemy;
            g.layer = (int)GameLayer.Npc;

            var type = Type.GetType("MyLib." + unitData.AITemplate);
            var t    = typeof(NGUITools);
            var m    = t.GetMethod("AddMissingComponent");

            Log.AI("Monster Create Certain AI  " + unitData.AITemplate + " " + type);
            var geMethod = m.MakeGenericMethod(type);

            geMethod.Invoke(null, new object[] { g });// as AIBase;


            var netView = g.GetComponent <KBEngine.KBNetworkView>();

            //服务器返回的ViewId
            //Owner 客户端怪物 服务器怪物
            //Id ViewId
            if (info != null)
            {
                netView.SetID(new KBEngine.KBViewID(info.Id, myPlayer));
            }
            else
            {
                netView.SetID(new KBEngine.KBViewID(-1, myPlayer));
            }

            netView.IsPlayer = false;

            npc.SetObjUnitData(unitData);
            AddObject(netView.GetServerID(), netView);

            //不算怪物允许不去打
            if (info != null)
            {
                npc.transform.position = NetworkUtil.FloatPos(info.X, info.Y, info.Z);
            }
            else
            {
                npc.transform.position = spawn.transform.position;
            }


            BattleManager.battleManager.AddEnemy(npc.gameObject);
            npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;


            var sync = npc.GetComponent <MonsterSync>();

            if (sync != null)
            {
                sync.SyncAttribute(info);
            }
        }