Exemplo n.º 1
0
        /*
         * Equipment PartName:
         *   head ---> face  helmet
         *   body ---> chest
         *   gloves ---> gloves
         *   shoes ---> boots
         *   trousers ---> NULL
         */
        void Awake()
        {
            attribute = GetComponent <NpcAttribute>();
            //myAnimationEvent = GetComponent<MyAnimationEvent> ();

            rightHand = Util.FindChildRecursive(transform, "Armature|tag_righthand");
            if (rightHand == null)
            {
                rightHand = Util.FindChildRecursive(transform, "Point001");
            }

            back = Util.FindChildRecursive(transform, "Point002");



            /*
             * first set body shadow then set equipment shadow
             */

            regEvt = new List <MyEvent.EventType>()
            {
                MyEvent.EventType.CharEquipChanged,
                MyEvent.EventType.TryEquip,
            };

            regLocalEvt = new List <MyEvent.EventType>()
            {
                MyEvent.EventType.ShowWeaponTrail,
                MyEvent.EventType.HideWeaponTrail,
            };
            RegEvent();
        }
Exemplo n.º 2
0
        //直接使用技能不切换状态
        public static SkillStateMachine UseSkill(NpcAttribute attacker)
        {
            var activeSkill       = attacker.GetComponent <SkillInfoComponent>().GetActiveSkill();
            var skillStateMachine = SkillLogic.CreateSkillStateMachine(attacker.gameObject, activeSkill.skillData, attacker.transform.position);

            return(skillStateMachine);
        }
Exemplo n.º 3
0
        IEnumerator KillNpc(MyAnimationEvent.Message msg)
        {
            GetComponent <PlayerAIController> ().enabled = false;

            NpcAttribute attribute = GetComponent <NpcAttribute> ();

            attribute._characterState = CharacterState.Story;


            DialogRender.KillNpcMessage m = (DialogRender.KillNpcMessage)msg;
            var targetName = m.dialog.dialog;
            var target     = GameObject.Find(targetName);

            Debug.Log("start kill Npc");
            yield return(StartCoroutine(commonAI.MoveToPos(target.transform.position)));

            //Rotation And Move To Target Position

            yield return(StartCoroutine(commonAI.KillNpc(target)));

            attribute._characterState = CharacterState.Idle;
            GetComponent <Animation>().CrossFade("idle");

            GetComponent <PlayerAIController> ().enabled = false;
        }
Exemplo n.º 4
0
        ///<summary>
        /// 副本内怪物构建流程
        /// 单人副本通过Scene配置来产生怪物
        /// 多人副本通过服务器推送消息产生怪物
        /// </summary>
        //TODO: 多人副本怪物产生机制
        public void CreateMonster(UnitData unitData, SpawnTrigger spawn)
        {
            if (WorldManager.worldManager.station == WorldManager.WorldStation.Enter)
            {
                Log.Sys("UnityDataIs " + unitData.ID);
                if (unitData.Config == null)
                {
                    Debug.LogError("NotFoundMonster " + unitData.ID);
                    return;
                }

                Log.Sys("Create Monster Unit " + unitData.name);
                var Resource = Resources.Load <GameObject>(unitData.ModelName);
                //本地怪兽不需要Player信息
                GameObject   g   = Instantiate(Resource) as GameObject;
                NpcAttribute npc = NGUITools.AddMissingComponent <NpcAttribute>(g);
                npc.spawnTrigger = spawn.gameObject;

                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);
                //var petAI =
                geMethod.Invoke(null, new object[] { g });// as AIBase;


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

                var netView = g.GetComponent <KBEngine.KBNetworkView>();
                netView.SetID(new KBEngine.KBViewID(-1, myPlayer));
                netView.IsPlayer = false;

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


                float   angle = UnityEngine.Random.Range(0, 360);
                Vector3 v     = Vector3.forward;
                v = Quaternion.Euler(new Vector3(0, angle, 0)) * v;
                float rg = UnityEngine.Random.Range(0, spawn.Radius);

                npc.transform.position = spawn.transform.position + v * rg;
                if (unitData.IsElite)
                {
                    npc.transform.localScale = new Vector3(2, 2, 2);
                }

                BattleManager.battleManager.AddEnemy(npc.gameObject);
                npc.SetDeadDelegate = BattleManager.battleManager.EnemyDead;
                //npc.Level = spawn.Level;
            }
            else
            {
                cacheMonster.Add(new MonsterInit(unitData, spawn));
            }
        }
Exemplo n.º 5
0
 void Awake()
 {
     attribute = GetComponent <NpcAttribute> ();
     //controller = GetComponent<CharacterController> ();
     myAnimationEvent = GetComponent <MyAnimationEvent> ();
     targetPlayer     = null;
 }
Exemplo n.º 6
0
 protected NpcAttribute GetAttr()
 {
     if (attr == null)
     {
         attr = aiCharacter.GetAttr();
     }
     return(attr);
 }
Exemplo n.º 7
0
        private void Start()
        {
            attr        = GetComponent <NpcAttribute>();
            aiBase      = GetComponent <AIBase>();
            vcontroller = GetComponent <MoveController>().vcontroller;

            gameObject.AddComponent <DebugServerPos>();
        }
Exemplo n.º 8
0
        void Start()
        {
            attribute    = GetComponent <NpcAttribute>();
            mvController = GetComponent <MoveController>();
            //mvController.vcontroller = new VirtualController();

            StartCoroutine(CommandHandle());
        }
Exemplo n.º 9
0
 private void OnDestroy()
 {
     if (me != null)
     {
         GameInterface_Skill.RemoveSkillBuff(me.gameObject, (int)GameBuff.NuclearDamageHP);
         me = null;
     }
 }
Exemplo n.º 10
0
 public override void Init(Affix af, GameObject o)
 {
     base.Init(af, o);
     type = Affix.EffectType.HideBuff;
     attr = obj.GetComponent <NpcAttribute>();
     attr.HideMe();
     obj.GetComponent <MyAnimationEvent>().AddCallBackLocalEvent(MyEvent.EventType.UseSkill, Over);
     obj.GetComponent <MyAnimationEvent>().AddCallBackLocalEvent(MyEvent.EventType.BeHit, Over);
 }
Exemplo n.º 11
0
 private void OnDestroy()
 {
     if (me != null)
     {
         GameInterface_Skill.RemoveSkillBuff(me.gameObject, (int)GameBuff.LaserDamageHP);
         GameInterface_Skill.RemoveSkillBuff(me.gameObject, Affix.EffectType.SlowDown2);
         me = null;
     }
 }
Exemplo n.º 12
0
        void OnEnable()
        {
            first = true;

            var player = ObjectManager.objectManager.GetMyPlayer();

            if (player != null)
            {
                nat = player.GetComponent <NpcAttribute>();
            }
        }
Exemplo n.º 13
0
 // Use this for initialization
 IEnumerator Start()
 {
     while (KBEngine.KBEngineApp.app == null)
     {
         yield return(null);
     }
     attribute = GetComponent <NpcAttribute> ();
     if (photonView.IsMe)
     {
         //StartCoroutine(InitProperty());
     }
 }
Exemplo n.º 14
0
        void OnDisable()
        {
            var player = ObjectManager.objectManager.GetMyPlayer();

            if (player != null)
            {
                nat = player.GetComponent <NpcAttribute>();
            }
            if (nat != null)
            {
                nat.SetNormalLayer();
            }
        }
Exemplo n.º 15
0
        private void OnTriggerExit(Collider other)
        {
            var attr = NetworkUtil.GetAttr(other.gameObject);

            if (attr != null)
            {
                if (attr.IsMine())
                {
                    GameInterface_Skill.RemoveSkillBuff(attr.gameObject, (int)GameBuff.LaserDamageHP);
                    GameInterface_Skill.RemoveSkillBuff(attr.gameObject, Affix.EffectType.SlowDown2);
                    me = null;
                }
            }
        }
Exemplo n.º 16
0
        private void OnTriggerEnter(Collider other)
        {
            var attr = NetworkUtil.GetAttr(other.gameObject);

            if (attr != null)
            {
                if (attr.IsMine())
                {
                    Util.ShowMsg("警告:进入核弹区域");
                    me = attr;
                    GameInterface_Skill.AddSkillBuff(me.gameObject, (int)GameBuff.NuclearDamageHP, Vector3.zero, PlayerId);
                }
            }
        }
Exemplo n.º 17
0
        void Start()
        {
            //var box = Util.FindChildRecursive(transform, "boxColldier").gameObject;
            //rigid =  box.GetComponent<Rigidbody>();
            //暂时忽略坦克碰撞 允许坦克互相穿透
            Physics.IgnoreLayerCollision((int)GameLayer.Npc, (int)GameLayer.Npc);
            rigid = this.GetComponent <Rigidbody>();

            rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            rigid.useGravity  = true;
            attribute         = GetComponent <NpcAttribute>();
            tower             = Util.FindChildRecursive(transform, "tower").gameObject;
            maxRotateChange   = attribute.ObjUnitData.jobConfig.rotateSpeed;
        }
Exemplo n.º 18
0
        private void OnTriggerExit(Collider other)
        {
            var attr = NetworkUtil.GetAttr(other.gameObject);

            if (attr != null)
            {
                if (attr == me)
                {
                    Util.ShowMsg("退出核弹区域");
                    me = null;
                    GameInterface_Skill.RemoveSkillBuff(attr.gameObject, (int)GameBuff.NuclearDamageHP);
                }
            }
        }
Exemplo n.º 19
0
        private void OnTriggerEnter(Collider other)
        {
            //Debug.LogError("OnTriggerEnter: "+other);
            var attr = NetworkUtil.GetAttr(other.gameObject);

            if (attr != null)
            {
                if (attr.IsMine())
                {
                    Util.ShowMsg("警告:进入辐射区域");
                    me = attr;
                    GameInterface_Skill.AddSkillBuff(me.gameObject, (int)GameBuff.DamageHP, Vector3.zero);
                }
            }
        }
Exemplo n.º 20
0
        void Start()
        {
            //var box = Util.FindChildRecursive(transform, "boxColldier").gameObject;
            //rigid =  box.GetComponent<Rigidbody>();
            rigid = this.GetComponent <Rigidbody>();

            rigid.constraints = RigidbodyConstraints.FreezeRotationX | RigidbodyConstraints.FreezeRotationZ;
            rigid.isKinematic = true;
            //rigid.constraints = RigidbodyConstraints.FreezeAll & ~RigidbodyConstraints.FreezePositionY;

            rigid.useGravity = true;
            attribute        = GetComponent <NpcAttribute>();
            tower            = Util.FindChildRecursive(transform, "tower").gameObject;
            maxRotateChange  = attribute.ObjUnitData.jobConfig.rotateSpeed;
        }
Exemplo n.º 21
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());
            }
        }
Exemplo n.º 22
0
        public static void Drop(NpcAttribute mon)
        {
            var treasure = mon.GetDropTreasure();

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

                ItemDataRef.MakeDropItem(itemData, mon.transform.position + new Vector3(0, 0.4f, 0), num);
            }
        }
Exemplo n.º 23
0
        IEnumerator AdjustTower(NpcAttribute attr)
        {
            var passTime = 0.0f;
            var trans    = attr.transform;

            while (true)
            {
                var curDir = transform.forward;
                curDir.y = 0;
                var forwardDir = trans.forward;
                var diffDir    = Quaternion.FromToRotation(curDir, forwardDir);
                var diffY      = diffDir.eulerAngles.y;

                if (diffY > 180)
                {
                    diffY = diffY - 360;
                }
                if (diffY < -180)
                {
                    diffY = 360 + diffY;
                }

                var dy     = Mathf.Clamp(diffY, -maxRotateChange, maxRotateChange);
                var curRot = transform.rotation.eulerAngles.y;
                var tarDir = Quaternion.Euler(new Vector3(0, curRot + dy, 0));
                transform.rotation = tarDir;
                //yield return null;
                yield return(new WaitForFixedUpdate());

                if (Mathf.Abs(diffY) <= 0.1f)
                {
                    break;
                }

                passTime += Time.deltaTime;
                if (passTime >= 1)
                {
                    var tempEnemy = SkillLogic.FindNearestEnemy(trans.gameObject);
                    if (tempEnemy != null)
                    {
                        break;
                    }
                    passTime = 0;
                }
            }
        }
Exemplo n.º 24
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.SetID(new KBEngine.KBViewID(-1, myPlayer));
                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));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// 初始化Buff
        /// </summary>
        /// <param name="af">Af.</param>
        /// <param name="o">O.</param>
        public virtual void Init(Affix af, GameObject o)
        {
            affix = af;
            obj   = o;
            attri = obj.GetComponent <NpcAttribute>();
            if (affix.UnitTheme != null)
            {
                var par = GameObject.Instantiate(affix.UnitTheme) as GameObject;
                //par.transform.parent = obj.transform;
                var sync = par.AddComponent <SyncPosWithTarget>();
                sync.target = obj;

                par.transform.localPosition = affix.ThemePos;
                par.transform.localRotation = Quaternion.identity;
                par.transform.localScale    = Vector3.one;

                unitTheme = par;
            }
        }
Exemplo n.º 26
0
        //0.1s 开启关闭
        private void OnTriggerEnter(Collider other)
        {
            var meId = ObjectManager.objectManager.GetMyServerID();

            if (meId == PlayerId)
            {
                return;
            }
            var attr = NetworkUtil.GetAttr(other.gameObject);

            if (attr != null)
            {
                Log.Sys("LaserEnter: " + other.gameObject);
                if (attr.IsMine())
                {
                    me = attr;
                    GameInterface_Skill.AddSkillBuff(me.gameObject, (int)GameBuff.LaserDamageHP, Vector3.zero, PlayerId);
                    GameInterface_Skill.AddSkillBuff(me.gameObject, "SlowDown2", Vector3.zero, PlayerId);
                }
            }
        }
Exemplo n.º 27
0
        // Use this for initialization
        void Start()
        {
            attribute = GetComponent <NpcAttribute>();
            Log.GUI("BloodBar Start Event");
            regLocalEvt = new System.Collections.Generic.List <MyEvent.EventType>()
            {
                MyEvent.EventType.UnitHP,
                MyEvent.EventType.TeamColor,
                MyEvent.EventType.IsMaster,
                MyEvent.EventType.BuffChange,
            };
            this.regEvt = new List <MyEvent.EventType>()
            {
                MyEvent.EventType.IAmFirst,
            };
            RegEvent(true);

            GetComponent <NpcAttribute>().NotifyHP();
            SetTeamColor();
            SetMaster();
        }
Exemplo n.º 28
0
        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;
            }
        }
Exemplo n.º 29
0
 void Start()
 {
     attribute   = GetComponent <NpcAttribute>();
     CacheDamage = new List <DamageData>();
 }
Exemplo n.º 30
0
        public void CalRunTime(Vector3 curPos, NpcAttribute attr)
        {
            var runTime = (targetPos - curPos).magnitude / attr.GetSpeed();

            runFrame = Util.FloatToFrame(runTime);
        }