예제 #1
0
    public void InitInMultiMode(CSEntity m_Entity, int ownerId)
    {
        m_Type             = GetMTypeFromProtoId(itemDrag.itemObj.protoId);
        this.m_Entity      = m_Entity;
        m_Entity.gameLogic = gameObject;

        _peEntity                    = gameObject.GetComponent <PeEntity>();
        _peTrans                     = gameObject.GetComponent <PeTrans>();
        _skEntity                    = gameObject.GetComponent <PESkEntity>();
        _skEntity.m_Attrs            = new PESkEntity.Attr[5];
        _skEntity.m_Attrs[0]         = new PESkEntity.Attr();
        _skEntity.m_Attrs[1]         = new PESkEntity.Attr();
        _skEntity.m_Attrs[2]         = new PESkEntity.Attr();
        _skEntity.m_Attrs[3]         = new PESkEntity.Attr();
        _skEntity.m_Attrs[4]         = new PESkEntity.Attr();
        _skEntity.m_Attrs[0].m_Type  = AttribType.HpMax;
        _skEntity.m_Attrs[1].m_Type  = AttribType.Hp;
        _skEntity.m_Attrs[2].m_Type  = AttribType.CampID;
        _skEntity.m_Attrs[3].m_Type  = AttribType.DefaultPlayerID;
        _skEntity.m_Attrs[4].m_Type  = AttribType.DamageID;
        _skEntity.m_Attrs[0].m_Value = m_Entity.MaxDurability;
        _skEntity.m_Attrs[1].m_Value = m_Entity.CurrentDurability;
        _skEntity.m_Attrs[2].m_Value = 1;
        _skEntity.m_Attrs[3].m_Value = ownerId;
        PeEntity ownerEntity = EntityMgr.Instance.Get(ownerId);

        if (ownerEntity != null)
        {
            _skEntity.m_Attrs[2].m_Value = ownerEntity.GetAttribute(AttribType.CampID);
            _skEntity.m_Attrs[4].m_Value = ownerEntity.GetAttribute(AttribType.DamageID);
        }

        _skEntity.onHpChange += OnHpChange;
        if (m_Type == CSConst.ObjectType.Assembly)
        {
            _skEntity.onHpChange += SendHpChangeMessage;
        }
        _skEntity.deathEvent += OnDeathEvent;
        _skEntity.InitEntity();
        OnHpChange(_skEntity, 0);
        EntityMgr.Instance.InitEntity(InstanceId, _peEntity.gameObject);

        //if(m_Type == CSConst.ObjectType.Processing)
        //{
        //    network.InitResultPos(m_ResultTrans);
        //}

        m_Entity.m_MgCreator.AddLogic(id, this);

        if (CSMain.s_MgCreator == m_Entity.m_MgCreator && m_Entity as CSAssembly != null)
        {
            //Vector3 travelPos = gameObject.transform.position + new Vector3(0, 2, 0);
            if (travelTrans != null)
            {
                //travelPos = travelTrans.position;
            }
        }

        StartCoroutine(SetFirstConstruct());
    }
예제 #2
0
        protected override void OnOwnerChange(PESkEntity oldOwner, PESkEntity newOwner)
        {
            base.OnOwnerChange(oldOwner, newOwner);

            if (oldOwner)
            {
                PeEntity entity = oldOwner.GetComponent <PeEntity>();

                if (PeCreature.Instance.mainPlayerId == entity.Id)
                {
                    _playerFollower = null;
                    if (onPlayerLoseRobot != null)
                    {
                        onPlayerLoseRobot();
                    }
                }
            }
            if (newOwner)
            {
                PeEntity entity = newOwner.GetComponent <PeEntity>();

                if (PeCreature.Instance.mainPlayerId == entity.Id)
                {
                    _playerFollower = this;
                    if (onPlayerGetRobot != null)
                    {
                        onPlayerGetRobot(itemObject, gameObject);
                    }
                }
            }
        }
예제 #3
0
    void Start()
    {
        if (!GameConfig.IsMultiMode)
        {
            m_Type = GetMTypeFromProtoId(itemDrag.itemObj.protoId);
            CSMgCreator creator = CSMain.s_MgCreator;
            if (creator != null)
            {
                CSEntityAttr attr = new CSEntityAttr();
                attr.m_InstanceId = InstanceId;
                attr.m_protoId    = protoId;
                attr.m_Type       = (int)m_Type;
                attr.m_Pos        = transform.position;
                attr.m_LogicObj   = gameObject;
                //attr.m_Bound = GetObjectBounds();
                //attr.m_Bound.center = transform.TransformPoint(attr.m_Bound.center);
                //attr.m_ColonyBase = _ColonyObj;
                int r = creator.CreateEntity(attr, out m_Entity);
                if (r != CSConst.rrtSucceed)
                {
                    Debug.LogError("Error with Init Entities");
                    return;
                }
                _peEntity                    = gameObject.GetComponent <PeEntity>();
                _peTrans                     = gameObject.GetComponent <PeTrans>();
                _skEntity                    = gameObject.GetComponent <PESkEntity>();
                _skEntity.m_Attrs            = new PESkEntity.Attr[5];
                _skEntity.m_Attrs[0]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[1]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[2]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[3]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[4]         = new PESkEntity.Attr();
                _skEntity.m_Attrs[0].m_Type  = AttribType.HpMax;
                _skEntity.m_Attrs[1].m_Type  = AttribType.Hp;
                _skEntity.m_Attrs[2].m_Type  = AttribType.CampID;
                _skEntity.m_Attrs[3].m_Type  = AttribType.DefaultPlayerID;
                _skEntity.m_Attrs[4].m_Type  = AttribType.DamageID;
                _skEntity.m_Attrs[0].m_Value = m_Entity.MaxDurability;
                _skEntity.m_Attrs[1].m_Value = m_Entity.CurrentDurability;
                _skEntity.m_Attrs[2].m_Value = PeCreature.Instance.mainPlayer.GetAttribute(AttribType.CampID);
                _skEntity.m_Attrs[3].m_Value = ForceConstant.PLAYER;
                _skEntity.m_Attrs[4].m_Value = PeCreature.Instance.mainPlayer.GetAttribute(AttribType.DamageID);

                _skEntity.onHpChange += OnHpChange;
                if (m_Type == CSConst.ObjectType.Assembly)
                {
                    _skEntity.onHpChange += SendHpChangeMessage;
                }
                _skEntity.deathEvent += OnDeathEvent;
                _skEntity.InitEntity();
                m_Entity.onDuraChange = SetHp;
                OnHpChange(_skEntity, 0);
                int entityId = Pathea.WorldInfoMgr.Instance.FetchNonRecordAutoId();
                EntityMgr.Instance.InitEntity(entityId, _peEntity.gameObject);
                creator.AddLogic(id, this);
            }
            StartCoroutine(SetFirstConstruct());
        }
    }
예제 #4
0
    void Awake()
    {
        FlagEntity   = gameObject.AddComponent <PeEntity>();
        FlagTrans    = gameObject.AddComponent <PeTrans>();
        FlagSkEntity = gameObject.AddComponent <PESkEntity>();

        FlagSkEntity.onHpChange += OnHpChange;
        FlagSkEntity.deathEvent += OnDeathEvent;
        FlagSkEntity.InitEntity();
    }
예제 #5
0
 void CheckCasterAlive()
 {
     if (m_DeletWhenCasterDead)
     {
         PESkEntity entity = GetSkEntityCaster() as PESkEntity;
         if (null != entity && entity.isDead)
         {
             Delete();
         }
     }
 }
예제 #6
0
    IEnumerator NpcRevive(SkEntity entity, float delayTime)
    {
        if (Pathea.PeGameMgr.IsMulti)
        {
            yield break;
        }

        PeEntity peentity = entity.GetComponent <PeEntity>();

        if (peentity == null)
        {
            yield break;
        }

        EntityInfoCmpt InfoCmpt = peentity.enityInfoCmpt;

        InfoCmpt.SetDelaytime(Time.time, delayTime);

        PESkEntity skentity = peentity.peSkEntity;

        yield return(new WaitForSeconds(delayTime));

        if (entity != null && skentity != null && skentity.isDead)
        {
            MotionMgrCmpt motion = entity.GetComponent <MotionMgrCmpt>();
            if (motion != null)
            {
                while (true)
                {
                    if (null == peentity || null == motion)
                    {
                        yield break;
                    }
                    //在复活中被任务设置成不能复活 ReviveTime = -1
                    if (peentity.NpcCmpt.ReviveTime < 0)
                    {
                        break;
                    }

                    PEActionParamB param = PEActionParamB.param;
                    param.b = false;
                    if (motion.DoAction(PEActionType.Revive, param))
                    {
                        entity.SetAttribute((int)AttribType.Hp, entity.GetAttribute((int)AttribType.HpMax) * 0.8f);
                        break;
                    }
                    else
                    {
                        yield return(new WaitForSeconds(1));
                    }
                }
            }
        }
    }
 protected override void OnOwnerChange(PESkEntity oldOwner, PESkEntity newOwner)
 {
     if (oldOwner)
     {
         oldOwner.onHpReduce  -= OnOwnerHpReduce;
         oldOwner.attackEvent -= OnOwnerAttack;
     }
     if (newOwner)
     {
         newOwner.onHpReduce  += OnOwnerHpReduce;
         newOwner.attackEvent += OnOwnerAttack;
     }
 }
예제 #8
0
    void OnDamage(int casterId, float damage)
    {
        NetworkInterface caster = Get <NetworkInterface>(casterId);
        SkEntity         entity = null != caster ? null != caster.Runner ? caster.Runner.SkEntityBase : null : null;

        if (Runner != null)
        {
            PESkEntity skEntity = Runner.SkEntityBase as PESkEntity;
            if (skEntity != null)
            {
                skEntity.DispatchHPChangeEvent(entity, damage);
            }
        }
    }
예제 #9
0
        // 更新锁定目标
        void UpdateLockTarget()
        {
            // 锁定目标
            if (PeInput.Get(PeInput.LogicFunction.MissleTarget))
            {
                _lockedTarget     = null;
                _lockedTargetView = null;
                if (_aimEntity)
                {
                    _targetToLock     = _aimEntity;
                    _targetViewToLock = _aimEntity.GetComponent <ViewCmpt>();
                    _timeToLock       = PEVCConfig.instance.lockTargetDuration;
                }
                else
                {
                    _targetToLock     = null;
                    _targetViewToLock = null;
                    _timeToLock       = -1;
                }
            }

            if (_timeToLock > 0f)
            {
                if (_targetToLock == _aimEntity && _targetToLock && (!_targetViewToLock || _targetViewToLock.hasView))
                {
                    _timeToLock -= Time.deltaTime;
                    if (_timeToLock <= 0f)
                    {
                        _lockedTarget     = _targetToLock;
                        _lockedTargetView = _targetViewToLock;
                    }
                }
                else
                {
                    _targetToLock     = null;
                    _targetViewToLock = null;
                    _timeToLock       = -1;
                }
            }
            else
            {
                if ((_lockedTarget && _lockedTarget.isDead) || (_lockedTargetView && !_lockedTargetView.hasView))
                {
                    _lockedTarget     = null;
                    _lockedTargetView = null;
                }
            }
        }
예제 #10
0
        IEnumerator GetMonster()
        {
            yield return(new WaitForSeconds(2f));

            if (GameObject.Find("lepus hare_2146483648") == null)
            {
                yield return(0);
            }
            mMonster = GameObject.Find("lepus hare_2146483648");
            mPeSE    = mMonster.GetComponent <PESkEntity>();
            if (mPeSE == null)
            {
                yield return(0);
            }
            mPeSE.SetAttribute(AttribType.CampID, 0f);
            mPeSE.SetAttribute(AttribType.DamageID, 0f);
        }
예제 #11
0
    protected void RPC_S2C_SkOnDamage(uLink.BitStream stream, uLink.NetworkMessageInfo info)
    {
        int   casterId = stream.Read <int> ();
        float damage   = stream.Read <float> ();

        NetworkInterface caster = Get <NetworkInterface> (casterId);
        SkEntity         entity = null != caster ? null != caster.Runner ? caster.Runner.SkEntityBase : null : null;

        //if (null != Runner && null != Runner.SkEntityPE && IsController)
        //	Runner.SkEntityPE.Entity.SendMsg (EMsg.Battle_HPChange, entity, damage);

        if (Runner != null)
        {
            PESkEntity skEntity = Runner.SkEntityBase as PESkEntity;
            if (skEntity != null)
            {
                skEntity.DispatchHPChangeEvent(entity, damage);
            }
        }
    }
예제 #12
0
        /// <summary> 设置归属者(攻击判定相关) </summary>
        protected void SetOwner(PeEntity owner)
        {
            _ownerEntity = owner;
            _hasOwner    = owner;

            PESkEntity oldOwner = _ownerSkEntity;

            if (_hasOwner)
            {
                _ownerSkEntity = owner.GetComponent <PESkEntity>();
                _creationSkEntity.SetAttribute(AttribType.CampID, 5);
                _creationSkEntity.SetAttribute(AttribType.DamageID, 5);
                _creationSkEntity.SetAttribute(AttribType.DefaultPlayerID, owner.GetAttribute(AttribType.DefaultPlayerID));
            }
            else
            {
                _ownerSkEntity = null;
                _creationSkEntity.SetAttribute(AttribType.CampID, 0);
                _creationSkEntity.SetAttribute(AttribType.DamageID, 0);
                _creationSkEntity.SetAttribute(AttribType.DefaultPlayerID, 99);
            }

            OnOwnerChange(oldOwner, _ownerSkEntity);
        }
예제 #13
0
 // 所属变化事件
 protected virtual void OnOwnerChange(PESkEntity oldOwner, PESkEntity newOwner)
 {
 }
예제 #14
0
        // 处理非传输输入
        void HandleNormalInput()
        {
            if (_isAttackMode)
            {
                // 获取瞄准信息

                var hit           = Physics.RaycastAll(_ray = PeCamera.mouseRay, _rayMaxDistance, PEVCConfig.instance.attackRayLayerMask);
                int selectedIndex = -1;

                if (hit.Length > 0)
                {
                    float distance = float.MaxValue;

                    for (int i = 0; i < hit.Length; i++)
                    {
                        if (!hit[i].collider.isTrigger && hit[i].distance < distance && !hit[i].transform.IsChildOf(transform))
                        {
                            selectedIndex = i;
                            distance      = hit[i].distance;
                        }
                    }
                }

                if (selectedIndex >= 0)
                {
                    _aimPoint  = hit[selectedIndex].point;
                    _aimEntity = hit[selectedIndex].collider.GetComponentInParent <PESkEntity>();
                    if (_aimEntity != null)
                    {
                        // 排除友方和死亡目标
                        if (ForceSetting.Instance.AllyPlayer(
                                (int)_aimEntity.GetAttribute(AttribType.DefaultPlayerID),
                                (int)creationSkEntity.GetAttribute(AttribType.DefaultPlayerID)
                                ) || _aimEntity.isDead)
                        {
                            _aimEntity = null;
                        }
                    }
                }
                else
                {
                    _aimPoint  = _ray.direction * _rayMaxDistance + _ray.origin;
                    _aimEntity = null;
                }

                UpdateLockTarget();

                // 导弹发射
                SetWeaponControlEnabled(WeaponType.Missile, PeInput.Get(PeInput.LogicFunction.MissleLaunch));

                // 炮发射
                if (PeInput.Get(PeInput.LogicFunction.Vehicle_BegFixedShooting))
                {
                    SetWeaponControlEnabled(WeaponType.Cannon, true);
                }
                if (PeInput.Get(PeInput.LogicFunction.Vehicle_EndFixedShooting))
                {
                    SetWeaponControlEnabled(WeaponType.Cannon, false);
                }

                // 枪发射
                if (PeInput.Get(PeInput.LogicFunction.Vehicle_BegUnfixedShooting))
                {
                    SetWeaponControlEnabled(WeaponType.Gun, true);
                }
                if (PeInput.Get(PeInput.LogicFunction.Vehicle_EndUnfixedShooting))
                {
                    SetWeaponControlEnabled(WeaponType.Gun, false);
                }

                // 武器组开关
                for (int i = 0; i < _weaponGroupKey.Length; i++)
                {
                    if (PeInput.Get(_weaponGroupKey[i]))
                    {
                        ReverseWeaponGroupEnabled(i);
                        UIDrivingCtrl.Instance.SetWweaponGroupToggles(i, IsWeaponGroupEnabled(i));
                    }
                }
            }
            else
            {
                _timeToLock   = -1f;
                _targetToLock = null;
                _lockedTarget = null;
                DisableAllWeaponControl();
            }
        }
예제 #15
0
        /// <summary> 乘客上载具 </summary>
        /// <param name="seatIndex"> 座位序号, -1 表示驾驶舱, 非负值表示普通座位序号 </param>
        public void GetOn(PeEntity entity, int seatIndex)
        {
            VCPBaseSeat seat = null;

            // 驾驶舱
            if (seatIndex < 0)
            {
                seat = _cockpit;

                ChangeOwner(entity);                      // 设置归属者(攻击判定相关)
                ResetHost(entity.Id);                     // 重置主控端

                // 玩家坐上驾驶舱
                if (isPlayerHost)
                {
                    _playerDriving = this;

                    UIDrivingCtrl.Instance.Show(
                        () => maxHp, () => hp, () => maxEnergy, () => energy,
                        () => { var v = rigidbody.velocity; return(Mathf.Sqrt(v.x * v.x + v.z * v.z) * 3.6f); },
                        () => _jetExhausts.Length > 0 ? _jetRestValue : 0);

                    seat.getOffCallback += () =>
                    {
                        _playerDriving = null;
                        UIDrivingCtrl.Instance.Hide();
                        UIDrivingCtrl.Instance.SetWweaponGroupTogglesVisible(false, this);
                        UISightingTelescope.Instance.Show(UISightingTelescope.SightingType.Null);
                    };

                    // 教程
                    TutorialData.AddActiveTutorialID(TutorialData.GetOnVehicle);
                }

                // 驾驶员离开驾驶舱
                seat.getOffCallback += () =>
                {
                    _inputState = OnDriverGetOff(_inputState);

                    _aimEntity    = null;
                    _lockedTarget = null;
                    _timeToLock   = -1f;
                    _isAttackMode = false;
                    DisableAllWeaponControl();

                    //终止撞击伤害技能
                    ActivateImpactDamage(false);
                };

                //单机模式玩家上车直接释放撞击伤害技能
                if (!GameConfig.IsMultiMode || IsController())
                {
                    ActivateImpactDamage(true);
                }
            }
            // 普通座位
            else
            {
                seat = _sideSeats[seatIndex];
            }

            _passengerCount += 1;

            seat.GetOn(entity.GetCmpt <PassengerCmpt>());

            // 当所有乘客都下车, 车的归属恢复默认
            seat.getOffCallback += () =>
            {
                _passengerCount -= 1;
                if (_passengerCount == 0)
                {
                    ChangeOwner(null);
                }
            };
        }
예제 #16
0
        void LateUpdate()
        {
            int showType = 0;             // 0 不显示, 1 可攻击, 2 锁定中, 3 已锁定

            var        carrier = CarrierController.playerDriving;
            PESkEntity target  = null;

            if (carrier)
            {
                if (carrier.lockedTarget)
                {
                    showType = 3;
                    target   = carrier.lockedTarget;
                }
                else if (carrier.timeToLock > 0f)
                {
                    showType = 2;
                    target   = carrier.targetToLock;
                }
                else if (carrier.aimEntity)
                {
                    showType = 1;
                    target   = carrier.aimEntity;
                }
            }

            if (showType != lastShowType && !hiding)
            {
                lastShowType = showType;

                _background.enabled = showType == 1 || showType == 2;
                _progress.enabled   = showType == 2 || showType == 3;
                _cross.enabled      = true;

                _crossShow.enabled    = showType == 0 || showType == 1;
                _crossLocking.enabled = showType == 2;
                _crossLocked.enabled  = showType == 3;

                if (_crossShow.enabled)
                {
                    _crossShow.speed = showType == 0 ? -1f : 1f;
                }
                else if (_crossLocking.enabled)
                {
                    Color c = _cross.color;
                    c.a          = 1f;
                    _cross.color = c;
                    _cross.transform.localScale  = Vector3.one;
                    _crossLocking.normalizedTime = 0;
                }
                else if (_crossLocked.enabled)
                {
                    Color c = _cross.color;
                    c.a          = 1f;
                    _cross.color = c;
                    _cross.transform.localEulerAngles = Vector3.zero;
                }
            }

            if (target)
            {
                if (target != lastTarget)
                {
                    lastTarget             = target;
                    lastTrans              = target.GetComponent <PeTrans>();
                    lastCreationController = target.GetComponent <CreationController>();
                }

                var     camera         = Camera.main;
                Vector3 targetPosition = this.targetPosition;

                if (visible != (Vector3.Dot(camera.transform.forward, targetPosition - camera.transform.position) > 1f))
                {
                    visible = !visible;
                    for (int i = 0; i < transform.childCount; i++)
                    {
                        transform.GetChild(i).gameObject.SetActive(visible);
                    }
                }

                if (visible)
                {
                    _progress.fillAmount       = 1f - carrier.timeToLock / PEVCConfig.instance.lockTargetDuration;
                    rectTrans.anchoredPosition = camera.WorldToScreenPoint(targetPosition) / rectTransParent.localScale.x;
                }
            }
        }