protected override void InitOtherThings() { // 单人模式下,AI 属于玩家 if (!PeGameMgr.IsMulti) { if (energy > 0f) { SetOwner(MainPlayer.Instance.entity); } ResetHost(MainPlayer.Instance.entity.Id); } // 监控敌人 creationSkEntity.onHpReduce += (enemy, value) => { if (enemy is SkAliveEntity && !enemy.Equals(null)) { _attackSelfEntity = enemy as SkAliveEntity; _attackSelfView = enemy.GetComponent <ViewCmpt>(); } }; // 战斗模式 _aiMode = defaultAIMode; _cureValueList = new List <float>(); _cureValueList.Add(0f); }
void OnOwnerAttack(SkEntity enemy, float value) { if (enemy is SkAliveEntity && !enemy.Equals(null)) { _ownerAttackEntity = enemy as SkAliveEntity; _ownerAttackView = enemy.GetComponent <ViewCmpt>(); } }
void OnOwnerHpReduce(SkEntity enemy, float value) { enemy = PETools.PEUtil.GetCaster(enemy); if (enemy is SkAliveEntity && !enemy.Equals(null)) { _attackOwnerEntity = enemy as SkAliveEntity; _attackOwnerView = enemy.GetComponent <ViewCmpt>(); } }
// 更新锁定目标 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; } } }
IEnumerator DestroyEnumerator(SkEntity entity, float delayTime, float fadeoutTime = 3.0f) { yield return(new WaitForSeconds(delayTime)); if (entity != null) { ViewCmpt view = entity.GetComponent <ViewCmpt>(); if (view != null) { if (view is BiologyViewCmpt) { (view as BiologyViewCmpt).Fadeout(fadeoutTime); yield return(new WaitForSeconds(fadeoutTime)); } } if (entity != null) { GameObject.Destroy(entity.gameObject); PeEventGlobal.Instance.DestroyEvent.Invoke(entity); } } }
public void SetHandler(Motion_Move move, ViewCmpt view, Motion_Beat beat) { m_Beat = beat; }
// 在主控端 FixedUpdate 中调用 protected void UpdateAttactTarget() { CheckOwnerCarrier(); SkEntity newAimTarget = null; ViewCmpt newAimView = null; if (_aiMode != AIMode.Passive && _aiMode != AIMode.Cure) { // 优先选择攻击玩家的敌人 if (_attackOwnerEntity && _attackOwnerView && !_attackOwnerEntity.isDead && _attackOwnerView.hasView && _attackOwnerEntity.Entity != ownerEntity) { newAimTarget = _attackOwnerEntity; newAimView = _attackOwnerView; } else { _attackOwnerEntity = null; _attackOwnerView = null; // 其次选择攻击自己的敌人 if (_attackSelfEntity && _attackSelfView && !_attackSelfEntity.isDead && _attackSelfView.hasView && _attackSelfEntity.Entity != ownerEntity) { newAimTarget = _attackSelfEntity; newAimView = _attackSelfView; } else { _attackSelfEntity = null; _attackSelfView = null; // 最后选择玩家攻击的敌人 if (_ownerAttackEntity && _ownerAttackView && !_ownerAttackEntity.isDead && _ownerAttackView.hasView && _ownerAttackEntity.Entity != ownerEntity) { newAimTarget = _ownerAttackEntity; newAimView = _ownerAttackView; } else { _ownerAttackEntity = null; _ownerAttackView = null; // 攻击模式下主动寻找目标 if (_aiMode == AIMode.Attack) { // 如果当前目标有效则继续攻击 if (_aimEntity && _aimView && _aimView.hasView && _aimEntity is SkAliveEntity && !(_aimEntity as SkAliveEntity).isDead && (_aimView.Entity.position - transform.position).sqrMagnitude < PEVCConfig.instance.sqrRobotAttackRange) { newAimTarget = _aimEntity; newAimView = _aimView; } else { _timeCountForFindEnemy += Time.deltaTime; // 当前目标无效则每隔 0.77 秒搜索一次目标 if (_timeCountForFindEnemy > 0.77f) { _timeCountForFindEnemy = 0f; foreach (var pair in EntityMgr.Instance.mDicEntity) { if (pair.Value.hasView && !pair.Value.IsDeath() && (pair.Value.position - transform.position).sqrMagnitude < PEVCConfig.instance.sqrRobotAttackRange && PETools.PEUtil.CanAttack(creationPeEntity, pair.Value)) { newAimTarget = pair.Value.skEntity; newAimView = pair.Value.viewCmpt; break; } } } } } } } } } else if (_aiMode == AIMode.Cure) { OnCureModeUpdate(); } // 更新攻击目标 _isAttackMode = newAimTarget; if (_isAttackMode) { _aimPoint = newAimView.centerPosition; } _aimEntity = newAimTarget; _aimView = newAimView; // 开火 SetWeaponControlEnabled(WeaponType.AI, isAttackMode && (attackTargetPoint - transform.position).sqrMagnitude < PEVCConfig.instance.sqrRobotAttackRange); }