Beispiel #1
0
        private void AttackAction()
        {
            var targetEntity = mBattleSys.FindEntityByID(m_attackCom.TargetID);

            if (!CheckTargetValid(targetEntity))
            {
                StateTransite((int)E_RoleState.Idle);
                return;
            }
            CLog.Log(SysLogType.Battle_Role_State, "{0} 播放攻击行为", m_attriCom.ID);
            m_animCom.ForcePlayAnim(E_AnimatorState.attack);
            var targetAttackCom = targetEntity.GetComponent <CAttackCom>();

            targetAttackCom.OnHpChange(-(int)m_attriCom.GetAttr(E_AttributeType.Attack));

            var targetAttricom = targetEntity.GetComponent <CAttributeCom>();

            //refresh blood of ui

            if (!targetAttricom.IsAlive())
            {
                //change to dead
                var targetFsm = targetEntity.GetComponent <CFsmCom>();
                targetFsm.FsmMgr.SetCurrentState((int)E_RoleState.Dead);
            }
        }
Beispiel #2
0
        public override void OnEnterState()
        {
            base.OnEnterState();
            m_attirCom  = Entity.GetComponent <CAttributeCom>();
            m_moveSpeed = m_attirCom.GetAttr(E_AttributeType.MoveSpeed) / 10f;
            m_moveGobj  = Entity.GetComponent <CRenderCom>().GameObject;
            var attackCom = Entity.GetComponent <CAttackCom>();
            var battleSys = CBattleEntityMgr.Instance.GetSystem <CBattleEntitySys>();

            m_targetEntity = battleSys.FindEntityByID(attackCom.TargetID);
            if (null == m_targetEntity)
            {
                //back to idle
                StateTransite((int)E_RoleState.Idle);
                return;
            }
            //look at target
            var targetRenderer = m_targetEntity.GetComponent <CRenderCom>();

            //m_moveGobj.transform.LookAt(targetRenderer.GameObject.transform);
            SetLookAt(m_moveGobj.transform, targetRenderer.GameObject.transform);

            var animCom = this.Entity.GetComponent <CAnimCom>();

            animCom.ForcePlayAnim(E_AnimatorState.walk);
        }
Beispiel #3
0
        public void CreateATestEntity(E_BattleGroupType battleGroup)
        {
            var attrCom = new CAttributeCom()
            {
                Config = new RoleConfig()
                {
                    Name = "soldier01", AssetName = "black01"
                }
            };

            attrCom.BattleGroupType = battleGroup;
            attrCom.ID          = ++s_EntityID;
            attrCom.Config.Name = string.Format("{0}_{1}", attrCom.Config.Name, s_EntityID);
            var t = typeof(E_AttributeType);

            foreach (E_AttributeType key in System.Enum.GetValues(t))
            {
                attrCom.SetAttr(key, (uint)UnityEngine.Random.Range(5, 20));
            }
            uint hp = attrCom.GetAttr(E_AttributeType.MaxHp);

            attrCom.SetAttr(E_AttributeType.CurrentHp, hp);
            attrCom.SetAttr(E_AttributeType.MoveSpeed, 20);
            attrCom.Hp = (int)hp;

            var fsmCom = new CFsmCom();

            new CRoleBorn(fsmCom.FsmMgr);
            new CIdleState(fsmCom.FsmMgr);
            new CWalkState(fsmCom.FsmMgr);
            new CAttackState(fsmCom.FsmMgr);
            new CDeadState(fsmCom.FsmMgr);

            var attackCom = new CAttackCom();
            var transCom  = new CTransCom();
            var animCom   = new CAnimCom();
            var entity    = CEngine.Instance.CreateEntity(new System.Collections.Generic.List <AComponent>
            {
                attrCom,
                transCom,
                new CRenderCom(),
                new CEntityTypeCom()
                {
                    EntityType = E_EntityType.Role
                },
                fsmCom,
                attackCom,
                animCom
            });

            CLog.Log(SysLogType.Battle, "创建角色:{0}, hp = {1}", attrCom.ID, hp);
            CEngine.Instance.AddEntity(entity);
            fsmCom.FsmMgr.SetCurrentState((int)E_RoleState.Born);
        }