コード例 #1
0
        private void Start()
        {
            var runner = transform.parent.GetComponent <SkillLayoutRunner>();
            var isMe   = runner.stateMachine.attacker.GetComponent <NpcAttribute>().GetNetView().IsMe;

            if (isMe)
            {
                var unitData = Util.GetUnitData(false, MonsterID, 0);
                var cg       = CGPlayerCmd.CreateBuilder();
                cg.Cmd = "AddEntity";

                var entityInfo = EntityInfo.CreateBuilder();
                entityInfo.UnitId = MonsterID;
                var ip = NetworkUtil.ConvertPos(this.transform.position);
                entityInfo.X        = ip[0];
                entityInfo.Y        = ip[1] + 50;
                entityInfo.Z        = ip[2];
                entityInfo.SpawnId  = 0;
                entityInfo.EType    = EntityType.CHEST;
                entityInfo.HP       = unitData.HP;
                entityInfo.LifeLeft = GameConst.Instance.NuclearWaitTime + GameConst.Instance.NuclearWorkTime;
                entityInfo.PlayerID =
                    runner.stateMachine.attacker.GetComponent <NpcAttribute>().GetNetView().GetServerID();
                cg.EntityInfo = entityInfo.Build();
                var scene = WorldManager.worldManager.GetActive();
                scene.BroadcastMsg(cg);
            }
        }
コード例 #2
0
ファイル: ObjectManager.cs プロジェクト: lumieru/MobaKeHuDuan
        GameObject CreateMyPlayerInternal()
        {
            var job   = MyLib.Job.WARRIOR;
            var udata = Util.GetUnitData(true, (int)job, GetMyLevel());

            //var player = Instantiate(Resources.Load<GameObject>(udata.ModelName)) as GameObject;
            var player = new GameObject("Player_Me");

            NetDebug.netDebug.AddConsole("Init Player tag layer transform");
            NGUITools.AddMissingComponent <NpcAttribute>(player);
            NGUITools.AddMissingComponent <MobaMePlayerAI>(player);
            player.tag              = "Player";
            player.layer            = (int)GameLayer.Npc;
            player.transform.parent = transform;


            //设置自己玩家的View属性
            var view = player.GetComponent <KBEngine.KBNetworkView>();

            view.SetServerID(myPlayerServerId);

            var npcAttr = player.GetComponent <NpcAttribute>();

            player.GetComponent <NpcAttribute>().SetObjUnitData(udata);
            player.GetComponent <NpcEquipment>().InitDefaultEquip();
            player.GetComponent <NpcEquipment>().InitPlayerEquipmentFromBackPack();
            npcAttr.InitName();

            player.name = "player_me_" + myPlayerServerId;

            ObjectManager.objectManager.AddObject(SaveGame.saveGame.selectChar.PlayerId, view);

            myPlayerGameObj = player;
            return(player);
        }
コード例 #3
0
        /*
         * 4 Job Start From 0
         */
        public static GameObject ConstructChar(RolesInfo roleInfo)
        {
            Log.Sys("SelectChar::ConstructChar " + roleInfo);
            GameObject player = null;

            if (fakeObj.TryGetValue(roleInfo.PlayerId, out player))
            {
                return(player);
            }

            var udata = Util.GetUnitData(true, (int)roleInfo.Job, 0);

            Log.Sys("udata " + udata + " " + udata.name + " " + udata.ModelName);
            player = Instantiate(Resources.Load <GameObject> (udata.ModelName)) as GameObject;
            NGUITools.AddMissingComponent <NpcAttribute> (player);
            var selChar = NGUITools.AddMissingComponent <SelectChar> (player);

            player.GetComponent <NpcAttribute> ().SetObjUnitData(udata);
            player.GetComponent <NpcEquipment> ().InitDefaultEquip();


            selChar.name     = roleInfo.Name;
            selChar.playerId = roleInfo.PlayerId;
            selChar.level    = roleInfo.Level;
            selChar.roleInfo = roleInfo;

            return(player);
        }
コード例 #4
0
ファイル: NetworkScene.cs プロジェクト: lumieru/MobaKeHuDuan
        void WaitZoneInit(EntityInfo ety)
        {
            var zone      = BattleManager.battleManager.GetZone().GetComponent <ZoneEntityManager>();
            var unitData  = Util.GetUnitData(false, ety.UnitId, 0);
            var spawnZone = zone.GetSpawnZone(ety.SpawnId);

            ObjectManager.objectManager.CreateSpawnZoneEntity(unitData, spawnZone, ety);
        }
コード例 #5
0
ファイル: NpcAttribute.cs プロジェクト: Xnovae/MobaClient
        public void SetJob(Job j)
        {
            Log.Sys("SetJob: " + j);
            job = j;
            var udata = Util.GetUnitData(true, (int)job, Level);

            SetObjUnitData(udata);
            StartCoroutine(WaitSetColor());
        }
コード例 #6
0
 //玩家升级后设置等级 调整对应UnitData
 //TODO: 单人副本中调整属性  多人副本中网络同步属性 城市中网络同步属性  属性调整都是通过 CharacterInfo 来做的
 void SetLevel()
 {
     _ObjUnitData = Util.GetUnitData(_ObjUnitData.GetIsPlayer(), _ObjUnitData.ID, Level);
     charInfo.SetProp(CharAttribute.CharAttributeEnum.EXP_MAX, (int)_ObjUnitData.MaxExp);
     charInfo.SetProp(CharAttribute.CharAttributeEnum.HP, _ObjUnitData.HP);
     charInfo.SetProp(CharAttribute.CharAttributeEnum.HP_MAX, _ObjUnitData.HP);
     charInfo.SetProp(CharAttribute.CharAttributeEnum.MP, _ObjUnitData.MP);
     charInfo.SetProp(CharAttribute.CharAttributeEnum.MP_MAX, _ObjUnitData.MP);
     ChangeHP(0);
 }
コード例 #7
0
        /// <summary>
        /// 创建其它玩家
        /// 玩家所在场景
        /// </summary>
        /// <param name="ainfo">Ainfo.</param>
        public void CreateOtherPlayer(AvatarInfo ainfo)
        {
            if (WorldManager.worldManager.station == WorldManager.WorldStation.Enter)
            {
                Log.Sys("CreateOtherPlayer: " + ainfo);
                var oldPlayer = GetPlayer(ainfo.Id);
                if (oldPlayer != null)
                {
                    Debug.LogError("PlayerExists: " + ainfo);
                    return;
                }

                if (myPlayer != null && myPlayer.ID == ainfo.Id)
                {
                    Debug.LogError("CreateMeAgain");
                    return;
                }

                var kbplayer = new KBEngine.KBPlayer();
                kbplayer.ID = ainfo.Id;

                var udata  = Util.GetUnitData(true, (int)ainfo.Job, 1);
                var player = GameObject.Instantiate(Resources.Load <GameObject>(udata.ModelName)) as GameObject;

                var attr = NGUITools.AddMissingComponent <NpcAttribute>(player);
                //状态机类似 之后可能需要修改为其它玩家状态机
                NGUITools.AddMissingComponent <OtherPlayerAI>(player);

                player.tag   = "Player";
                player.layer = (int)GameLayer.Npc;

                NGUITools.AddMissingComponent <SkillInfoComponent>(player);
                player.GetComponent <NpcAttribute>().SetObjUnitData(udata);
                player.GetComponent <NpcEquipment>().InitDefaultEquip();

                player.name             = "player_" + ainfo.Id;
                player.transform.parent = gameObject.transform;

                var netview = player.GetComponent <KBEngine.KBNetworkView>();
                netview.SetID(new KBEngine.KBViewID(-1, kbplayer));


                AddPlayer(kbplayer.ID, kbplayer);
                AddObject(netview.GetServerID(), netview);
                attr.Init();
                var sync = player.GetComponent <MyLib.PlayerSync>();
                sync.SetPositionAndDir(ainfo);
                sync.SetLevel(ainfo);
            }
            else
            {
            }
        }
コード例 #8
0
        //ui界面构建玩家模型
        public static GameObject ConstructChar(Job job)
        {
            var        udata  = Util.GetUnitData(true, (int)job, 0);
            GameObject player = null;

            player = Instantiate(Resources.Load <GameObject> (udata.ModelName)) as GameObject;
            NGUITools.AddMissingComponent <NpcAttribute> (player);
            var selChar = NGUITools.AddMissingComponent <SelectChar> (player);

            selChar.GetComponent <NpcAttribute> ().SetObjUnitData(udata);
            selChar.GetComponent <NpcEquipment> ().InitDefaultEquip();
            return(player);
        }
コード例 #9
0
        IEnumerator WaitZoneInit(EntityInfo ety)
        {
            var zone       = BattleManager.battleManager.GetZone().GetComponent <ZoneEntityManager>();
            var unitData   = Util.GetUnitData(false, ety.UnitId, 0);
            var spawnChest = zone.GetSpawnChest(ety.SpawnId);

            while (spawnChest == null)
            {
                yield return(null);

                spawnChest = zone.GetSpawnChest(ety.SpawnId);
            }
            ObjectManager.objectManager.CreateChestFromNetwork(unitData, spawnChest, ety);
        }
コード例 #10
0
        GameObject CreateMyPlayerInternal()
        {
            var kbplayer = new KBEngine.KBPlayer();

            kbplayer.ID = (int)-2;
            if (myPlayer != null)
            {
                throw new System.Exception("myPlayer not null");
            }

            myPlayer = kbplayer;

            var job    = (MyLib.Job)GetMyJob();
            var udata  = Util.GetUnitData(true, (int)job, GetMyLevel());
            var player = Instantiate(Resources.Load <GameObject>(udata.ModelName)) as GameObject;

            NetDebug.netDebug.AddConsole("Init Player tag layer transform");
            NGUITools.AddMissingComponent <NpcAttribute>(player);
            NGUITools.AddMissingComponent <PlayerAIController>(player);
            player.tag              = "Player";
            player.layer            = (int)GameLayer.Npc;
            player.transform.parent = transform;


            //设置自己玩家的View属性
            var view = player.GetComponent <KBEngine.KBNetworkView>();

            NetDebug.netDebug.AddConsole("SelectCharID " + SaveGame.saveGame.selectChar.PlayerId);
            view.SetID(new KBEngine.KBViewID(-1, kbplayer));

            var npcAttr = player.GetComponent <NpcAttribute>();

            NetDebug.netDebug.AddConsole("Set UnitData of Certain Job " + udata);
            player.GetComponent <NpcAttribute>().SetObjUnitData(udata);
            player.GetComponent <NpcEquipment>().InitDefaultEquip();
            player.GetComponent <NpcEquipment>().InitPlayerEquipmentFromBackPack();
            npcAttr.InitName();

            player.name = "player_me";

            ObjectManager.objectManager.AddObject(SaveGame.saveGame.selectChar.PlayerId, view);

            var light = GameObject.Instantiate(Resources.Load <GameObject>("light/playerLight")) as GameObject;

            light.transform.parent        = player.transform;
            light.transform.localPosition = Vector3.zero;

            NetDebug.netDebug.AddConsole("LevelInit::Awake Initial kbplayer Initial KbNetowrkView " + kbplayer + " " + view);
            return(player);
        }
コード例 #11
0
        /// <summary>
        /// 通过ObjectManager来生成新的怪物对象
        /// </summary>
        /// <returns>The monster.</returns>
        IEnumerator GenerateMonster()
        {
            Log.Sys("GenerateMonsters " + GroupNum);
            for (int i = 0; i < GroupNum; i++)
            {
                var rd       = UnityEngine.Random.Range(0, 100);
                var unitData = Util.GetUnitData(false, MonsterID, 0);
                if (rd < EliteRate || BattleManager.allElite)
                {
                    var elites = unitData.EliteIds;
                    if (elites.Count > 0)
                    {
                        var rd2 = UnityEngine.Random.Range(0, elites.Count);
                        var id2 = elites [rd2];
                        unitData = Util.GetUnitData(false, id2, 0);
                        Log.Sys("CreateEliteMonster " + id2);
                    }
                }

                ObjectManager.objectManager.CreateMonster(unitData, this);
                yield return(new WaitForSeconds(1));
            }

            if (multiSpawner.Count > 0)
            {
                multiSpawner [0].SpawnChild(this);
            }

            curWaveNum++;
            if (Forever && curWaveNum < TotalWave)
            {
                waveNum++;
                isSpawnYet = false;
                if (AddLevel)
                {
                    Level++;
                }
            }
            yield return(null);
        }
コード例 #12
0
ファイル: SpawnChest.cs プロジェクト: Xnovae/MobaClient
 private void DoSpawn()
 {
     var unitData = Util.GetUnitData(false, ChestId, 0);
     //ObjectManager.objectManager.CreateChest(unitData, this);
 }
コード例 #13
0
ファイル: NpcAttribute.cs プロジェクト: Xnovae/MobaClient
        //玩家升级后设置等级 调整对应UnitData
        void SetLevel()
        {
            var udata = Util.GetUnitData(_ObjUnitData.GetIsPlayer(), _ObjUnitData.ID, Level);

            SetObjUnitData(udata);
        }
コード例 #14
0
ファイル: MobaOtherSync.cs プロジェクト: Xnovae/MobaClient
        public override void NetworkAttribute(GCPlayerCmd cmd)
        {
            var info = cmd.AvatarInfo;

            if (attr == null)
            {
                attr = GetComponent <NpcAttribute>();
            }

            Log.Net("OtherSync: " + info);
            if (info == null)
            {
                Debug.LogError("NetMatchInfo is Null ");
                return;
            }
            NetworkMove(info);

            //服务器通知瞬间传送位置
            if (info.ResetPos)
            {
                if (aiBase != null)
                {
                    aiBase.GetAI().ChangeState(AIStateEnum.IDLE);
                }

                var netPos = MobaUtil.FloatPos(info);
                transform.position = netPos;
                positions.Clear();
            }


            if (info.HasTeamColor)
            {
                attr.SetTeamColorNet(info.TeamColor);
                curInfo.TeamColor = info.TeamColor;
            }
            if (info.HasIsMaster)
            {
                attr.SetIsMasterNet(info.IsMaster);
                curInfo.IsMaster = info.IsMaster;
            }

            var dataChanged = false;
            var skillCount  = curInfo.KillCount;

            if (info.HasKillCount)
            {
                skillCount        = info.KillCount;
                curInfo.KillCount = info.KillCount;
                dataChanged       = true;
            }

            var deadCount = curInfo.DeadCount;

            if (info.HasDeadCount)
            {
                deadCount         = info.DeadCount;
                curInfo.DeadCount = info.DeadCount;
                dataChanged       = true;
            }

            var secondaryAttackCount = curInfo.SecondaryAttackCount;

            if (info.HasSecondaryAttackCount)
            {
                secondaryAttackCount         = info.SecondaryAttackCount;
                curInfo.SecondaryAttackCount = info.SecondaryAttackCount;
                dataChanged = true;
            }

            if (info.HasScore)
            {
                curInfo.Score = info.Score;
                dataChanged   = true;
            }

            if (dataChanged)
            {
                var sid = attr.GetNetView().GetServerID();
                ScoreManager.Instance.NetSyncScore(sid, curInfo.Score, sid, skillCount, deadCount, secondaryAttackCount);
            }

            if (info.HasContinueKilled)
            {
                curInfo.ContinueKilled = info.ContinueKilled;
                if (curInfo.ContinueKilled > 0)
                {
                }
            }
            if (info.HasPlayerModelInGame && curInfo.PlayerModelInGame != info.PlayerModelInGame)
            {
                curInfo.PlayerModelInGame = info.PlayerModelInGame;
                GetComponent <MobaModelLoader>().LoadModel(curInfo.PlayerModelInGame);
                var unitData = Util.GetUnitData(true, curInfo.PlayerModelInGame, 0);
                attr.SetObjUnitData(unitData);

                //SkillDataController.skillDataController.InitSkillShotAfterSelectSkill(curInfo.PlayerModelInGame);
            }
            if (info.HasHP)
            {
                curInfo.HP = info.HP;
                attr.SetHPNet(info.HP);
            }
            if (info.HasLevel)
            {
                curInfo.Level = info.Level;
                attr.ChangeLevel(info.Level);
            }
            if (info.HasState)
            {
                curInfo.State = info.State;
            }
        }
コード例 #15
0
ファイル: NetworkScene.cs プロジェクト: Xnovae/MobaClient
        void WaitZoneInit(EntityInfo ety)
        {
            var unitData = Util.GetUnitData(false, ety.UnitId, 0);

            ObjectManager.objectManager.CreateSpawnZoneEntity(unitData, ety);
        }
コード例 #16
0
        public void CreatePet(int monsterId, GameObject owner, Affix affix, Vector3 pos)
        {
            Log.Sys("Create Pet " + monsterId + " " + owner + " " + pos);
            if (owner == null)
            {
                Debug.LogError("Own NotExist Pet Not Born");
                return;
            }
            var unitData = Util.GetUnitData(false, monsterId, 1);

            var Resource = Resources.Load <GameObject>(unitData.ModelName);

            GameObject   g    = Instantiate(Resource) as GameObject;
            NpcAttribute npc  = NGUITools.AddMissingComponent <NpcAttribute>(g);
            var          type = Type.GetType("MyLib." + unitData.AITemplate);
            var          t    = typeof(NGUITools);
            var          m    = t.GetMethod("AddMissingComponent");

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

            //var petAI =
            geMethod.Invoke(null, new object[] { g });// as AIBase;
            //var petAI =
            //NGUITools.AddMissingComponent<type> (g);

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


            npc.SetOwnerId(owner.GetComponent <KBEngine.KBNetworkView>().GetLocalId());
            npc.spawnTrigger = owner.GetComponent <NpcAttribute>().spawnTrigger;

            //不可移动Buff
            //持续时间Buff
            //无敌不可被攻击Buff
            //火焰陷阱的特点 特点组合
            g.GetComponent <BuffComponent>().AddBuff(affix);

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

            netView.SetID(new KBEngine.KBViewID(-1, myPlayer));
            netView.IsPlayer = false;
            //owner.GetComponent<NpcAttribute>().AddSummon(netView.gameObject);

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

            npc.transform.position = pos;

            if (unitData.IsElite)
            {
                npc.transform.localScale = new Vector3(2, 2, 2);
            }

            if (npc.tag == GameTag.Enemy)
            {
                BattleManager.battleManager.AddEnemy(npc.gameObject);
                npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;
            }
        }