Ejemplo n.º 1
0
    /// <summary>
    /// 试图保存目标
    /// </summary>
    /// <param name="newTarget"></param>
    private void TryToLockThisTarget(ulong newTargetId)
    {
        BaseEntity newTarget = GameplayManager.Instance.GetEntityManager().GetEntityById <BaseEntity>((uint)newTargetId);

        if (newTarget == null || !m_GameplayProxy.CanAttackToTarget(m_MainPlayer, (SpacecraftEntity)newTarget))
        {
            return;
        }

        // 新的目标有两种可能. 1. 不在当前目标列表里面 且 不为空, 2. 在目标列表里, 但是此目标已经锁定完成, 可以进行下一轮锁定
        if (!m_LockTargeMap.ContainsKey(newTargetId))
        {
            TargetLockInfo targetLockInfo = new TargetLockInfo();
            targetLockInfo.LockState         = TargetLockState.Locking;
            targetLockInfo.LockTimeRemaining = m_LockonTimeParam;
            targetLockInfo.LockTimes         = 0;
            m_LockTargeMap.Add(newTargetId, targetLockInfo);

            Leyoutech.Utility.DebugUtility.LogWarning("武器", string.Format("锁定新目标 {0}", newTarget.name));
        }
        else if (IsLockedEntity(newTargetId))
        {
            m_LockTargeMap[newTargetId].LockTimeRemaining = m_LockonTimeParam;
            m_LockTargeMap[newTargetId].LockState         = TargetLockState.Locking;

            Leyoutech.Utility.DebugUtility.LogWarning("武器", string.Format("锁定老目标,为其增加一层锁定层数. {0}", newTarget.name));
        }
        else
        {
            //SLog("目标正在锁定中, 却作为新目标被选中了. {0}", newTarget.name);
        }
    }
Ejemplo n.º 2
0
    public void TryToLockThisTarget(SpacecraftEntity newTarget)
    {
        // UNDONE. 需要添加阵营判断逻辑. 判断是不是敌人. 等待阵营功能完成
        if (newTarget == null)
        {
            return;
        }
        else
        {
            SLog("选中此目标进行锁定. {0}", newTarget.name);
        }

        // 新的目标有两种可能. 1. 不在当前目标列表里面 且 不为空, 2. 在目标列表里, 但是此目标已经锁定完成, 可以进行下一轮锁定
        if (!m_LockTargeMap.ContainsKey(newTarget))
        {
            TargetLockInfo targetLockInfo = new TargetLockInfo();
            targetLockInfo.LockState         = TargetLockState.Locking;
            targetLockInfo.LockTimeRemaining = m_LockonTimeParam;
            targetLockInfo.LockTimes         = 0;
            m_LockTargeMap.Add(newTarget, targetLockInfo);

            SLog("锁定新目标. {0}", newTarget.name);
        }
        else if (IsLockedEntity(newTarget))
        {
            m_LockTargeMap[newTarget].LockTimeRemaining = m_LockonTimeParam;
            m_LockTargeMap[newTarget].LockState         = TargetLockState.Locking;

            SLog("锁定老目标, 为其增加一层锁定层数. {0}", newTarget.name);
        }
        else
        {
            //SLog("目标正在锁定中, 却作为新目标被选中了. {0}", newTarget.name);
        }
    }
    /// <summary>
    /// 清理正在锁定但是已经不在瞄准框中的目标
    /// </summary>
    private void ClearLockingTargetWhichIsNotInLockingRect()
    {
        List <SpacecraftEntity> targetList = new List <SpacecraftEntity>();
        bool targetSelected = GetAllEntitySelectedByVirtualCamera(ref targetList);

        List <SpacecraftEntity> cancelLockList = new List <SpacecraftEntity>();

        foreach (var pair in m_LockTargeMap)
        {
            SpacecraftEntity lockTarget = pair.Key;
            TargetLockInfo   lockInfo   = pair.Value;
            // 正在锁定的目标如果已经不在框中, 就取消锁定
            if (lockInfo.LockState == TargetLockState.Locking && !targetList.Contains(lockTarget))
            {
                cancelLockList.Add(lockTarget);
            }
        }

        for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
        {
            SpacecraftEntity entity = cancelLockList[iEntity];
            if (m_LockTargeMap[entity].LockTimes == 0)
            {
                m_LockTargeMap.Remove(entity);
            }
            else
            {
                m_LockTargeMap[entity].LockState         = TargetLockState.Locked;
                m_LockTargeMap[entity].LockTimeRemaining = 0;
            }
            SLog("目标在锁定完成前出框了, 失去锁定. {0}", iEntity);
        }
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 更新锁定中,转圈单位
    /// </summary>
    private void UpdateTheLocking(float delta)
    {
        List <ulong> cancelLockList = new List <ulong>();

        foreach (var pair in m_LockTargeMap)
        {
            BaseEntity targetEntity = GameplayManager.Instance.GetEntityManager().GetEntityById <BaseEntity>((uint)pair.Key);

            // UNDONE, 检查所有目标是不是已经超出了射程或者已经死了. 如果是的话, 就解除锁定
            if (targetEntity == null || targetEntity.IsDead())
            {
                cancelLockList.Add(pair.Key);
                continue;
            }

            TargetLockInfo targetLockInfo = pair.Value;
            if (targetLockInfo.LockState == TargetLockState.Locking && IsThereSurplusMissile())
            {
                if (IsThereSurplusMissile()) //还不够
                {
                    if (targetLockInfo.LockTimeRemaining <= 0f)
                    {
                        targetLockInfo.LockState         = TargetLockState.Locked;
                        targetLockInfo.LockTimeRemaining = 0f;
                        targetLockInfo.LockTimes++;

                        Leyoutech.Utility.DebugUtility.LogWarning("武器", string.Format("目标锁定完成. EntityId = {0}", pair.Key));
                    }
                    else
                    {
                        targetLockInfo.LockTimeRemaining -= delta;
                    }
                }
                else //够了,将未完成转圈的
                {
                    if (targetLockInfo.LockTimes == 0)
                    {
                        cancelLockList.Add(pair.Key);
                    }
                    else
                    {
                        targetLockInfo.LockState         = TargetLockState.Locked;
                        targetLockInfo.LockTimeRemaining = 0;
                    }
                }
            }
        }

        // 对于那些已经不可用的目标解除锁定
        for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
        {
            m_LockTargeMap.Remove(cancelLockList[iEntity]);
            Leyoutech.Utility.DebugUtility.LogWarning("武器", string.Format("目标因为死亡或者超出视野而失去锁定. {0}", iEntity));
        }
    }
Ejemplo n.º 5
0
    /// <summary>
    /// 本此攻击流程中是否还有富余的弹药以供锁定更多的目标
    /// </summary>
    /// <returns></returns>
    private bool IsThereSurplusMissile()
    {
        int lockCount = 0;

        foreach (var pair in m_LockTargeMap)
        {
            TargetLockInfo lockInfo = pair.Value;
            lockCount += lockInfo.LockTimes;
        }

        return(m_MaxMissileCountInOneShotParam > lockCount);
    }
Ejemplo n.º 6
0
    /// <summary>
    /// 是否存在已经锁定的目标
    /// </summary>
    /// <returns></returns>
    private bool ExistingLockedTarget()
    {
        // 剔除所有正在锁定的目标. 只留下已经锁定的
        int count = 0;

        foreach (var pair in m_LockTargeMap)
        {
            TargetLockInfo lockInfo = pair.Value;
            if (lockInfo.LockState == TargetLockState.Locked || lockInfo.LockTimes >= 1)
            {
                count++;
            }
        }
        return(count > 0);
    }
Ejemplo n.º 7
0
    public override void CalculateNextTargets(ref List <SkillTarget> targetList)
    {
        targetList.Clear();
        string targetListStr = "";

        foreach (var pair in m_LockTargeMap)
        {
            SpacecraftEntity target   = pair.Key;
            TargetLockInfo   lockInfo = pair.Value;
            for (int iLockTime = 0; iLockTime < lockInfo.LockTimes; iLockTime++)
            {
                targetList.Add(new SkillTarget(target, target.GetSkinRootTransform().position));
            }
            targetListStr += target.name + ", ";
        }
        SLog("选择目标释放. {0}", targetListStr);
    }
Ejemplo n.º 8
0
    /// <summary>
    /// 设置技能需要的目标列表结构数据
    /// </summary>
    private void SetSkillTargets()
    {
        foreach (var item in m_LockTargeMap)
        {
            TargetLockInfo lockInfo = item.Value;
            BaseEntity     entity   = GameplayManager.Instance.GetEntityManager().GetEntityById <BaseEntity>((uint)item.Key);
            if (entity == null || entity.IsDead())
            {
                continue;
            }

            for (int i = 0; i < lockInfo.LockTimes; i++)
            {
                Target locktaget = new Target();
                locktaget.target_entityId = item.Key;
                locktaget.target_pos      = entity.GetRootTransform().position;
                m_LockedTargetList.Add(locktaget);
            }
        }
    }
Ejemplo n.º 9
0
    /// <summary>
    /// 清除已经不再虚拟相机里的单位
    /// </summary>
    private void ClearAlreadyNoInVirtualCameraTargets()
    {
        List <ulong> currTargetList = new List <ulong>();

        for (int i = 0; i < m_Targets.Count; i++)
        {
            Target target = m_Targets[i];
            currTargetList.Add(target.target_entityId);
        }

        List <ulong> cancelLockList = new List <ulong>();

        foreach (var pair in m_LockTargeMap)
        {
            ulong          lockTarget = pair.Key;
            TargetLockInfo lockInfo   = pair.Value;
            // 正在锁定的目标如果已经不在框中, 就取消锁定
            if (lockInfo.LockState == TargetLockState.Locking && !currTargetList.Contains(lockTarget))
            {
                cancelLockList.Add(lockTarget);
            }
        }

        for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
        {
            ulong entity = cancelLockList[iEntity];
            if (m_LockTargeMap[entity].LockTimes == 0)
            {
                m_LockTargeMap.Remove(entity);
                Leyoutech.Utility.DebugUtility.LogWarning("武器", string.Format("目标在锁定完成前出框了, 失去锁定. entityID = {0}", entity));
            }
            else
            {
                m_LockTargeMap[entity].LockState         = TargetLockState.Locked;
                m_LockTargeMap[entity].LockTimeRemaining = 0;
            }
        }
    }
    /// <summary>
    /// 释放技能攻击所有已经锁定的目标
    /// </summary>
    private void CastSkill()
    {
        SLog("释放技能. ");
        foreach (var pair in m_LockTargeMap)
        {
            TargetLockInfo targetLockInfo = pair.Value;
            targetLockInfo.LockTimeRemaining = m_LockonTimeParam;
        }

        SkillCastEvent skillCastEvent = new SkillCastEvent();

        skillCastEvent.IsWeaponSkill = true;
        skillCastEvent.KeyPressed    = true;

//#if NewSkill
//#else
        m_MainPlayer.SendEvent(ComponentEventName.CastSkill, skillCastEvent);

        // 相当于一次按键的按下和抬起. 在技能系统中技能按键的操作要成对出现
        skillCastEvent.KeyPressed = false;
        m_MainPlayer.SendEvent(ComponentEventName.CastSkill, skillCastEvent);
//#endif
    }
Ejemplo n.º 11
0
    /// <summary>
    /// 检测是否已经选中了新的目标
    /// 更新已经锁定了的目标的锁定状态
    /// </summary>
    /// <param name="deltaTime"></param>
    public override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);

        //  调试代码
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            ResetWeaponRuntimeData();
            Debug.LogError("清理武器导弹状态");
        }

        TranslateUniformParamToWeaponParam();
        // 调试代码

        List <SpacecraftEntity> targetList = new List <SpacecraftEntity>();

        // 锁定多目标, 同时让他们描红的逻辑, 还需要仔细考虑. 这里暂时先注释. 选择目标把它描红的逻辑让HUD执行
        //bool targetSelected = GetAllEntitySelectedByVirtualCamera(ref targetList);
        //NotifyHUDTargetSelected(targetSelected ? targetList[0] : null);

        // 尝试锁定新的目标
        if (m_State == State.Lock && IsThereSurplusMissile())
        {
            for (int iTarget = 0; iTarget < targetList.Count; iTarget++)
            {
                TryToLockThisTarget(targetList[iTarget]);
            }
        }

        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        // FIXME. 动态内存分配
        //targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);

        // 更新已有的目标
        // iterate all locking and locked target
        // locking:
        //		once countdown finished, set target state to Locked
        // locking and locked:
        //		if target is out of range / dead, unlock target
        List <SpacecraftEntity> cancelLockList = new List <SpacecraftEntity>();

        foreach (var pair in m_LockTargeMap)
        {
            SpacecraftEntity targetEntity   = pair.Key;
            TargetLockInfo   targetLockInfo = pair.Value;
            if (targetLockInfo.LockState == TargetLockState.Locking)
            {
                if (targetLockInfo.LockTimeRemaining <= 0f)
                {
                    targetLockInfo.LockState         = TargetLockState.Locked;
                    targetLockInfo.LockTimeRemaining = 0f;
                    targetLockInfo.LockTimes++;

                    SLog("目标锁定完成. {0}", targetEntity.name);
                }
                else
                {
                    targetLockInfo.LockTimeRemaining -= deltaTime;
                }
            }

            // UNDONE, 检查所有目标是不是已经超出了射程或者已经死了. 如果是的话, 就接触锁定
            if (targetEntity == null || targetEntity.IsDead())
            {
                cancelLockList.Add(targetEntity);
            }
        }

        // 接触已经不可用的目标的锁定
        for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
        {
            m_LockTargeMap.Remove(cancelLockList[iEntity]);
            SLog("目标因为死亡或者超出视野而失去锁定. {0}", iEntity);
        }
    }
    /// <summary>
    /// 检测是否已经选中了新的目标
    /// 更新已经锁定了的目标的锁定状态
    /// </summary>
    /// <param name="deltaTime"></param>
    public override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);

        //  调试代码
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            ResetWeaponRuntimeData();
            Debug.LogError("清理武器导弹状态");
        }
        TranslateUniformParamToWeaponParam();
        //  调试代码

        if (m_State == State.Lock)
        {
            SpacecraftEntity newTarget = GetTargetSelectedByCenterRay();

            //NotifyHUDTargetSelected(newTarget);

            // 尝试锁定新的目标
            if (IsThereSurplusMissile())
            {
                TryToLockThisTarget(newTarget);
            }

            // 清理已经出框的目标
            ClearLockingTargetWhichIsNotInLockingRect();

            // 更新已有的目标
            // iterate all locking and locked target
            // locking:
            //		once countdown finished, set target state to Locked
            // locking and locked:
            //		if target is out of range / dead, unlock target
            List <SpacecraftEntity> cancelLockList = new List <SpacecraftEntity>();
            foreach (var pair in m_LockTargeMap)
            {
                SpacecraftEntity targetEntity = pair.Key;

                // UNDONE, 检查所有目标是不是已经超出了射程或者已经死了. 如果是的话, 就接触锁定
                if (targetEntity == null || targetEntity.IsDead())
                {
                    cancelLockList.Add(targetEntity);
                    continue;
                }

                TargetLockInfo targetLockInfo = pair.Value;
                if (targetLockInfo.LockState == TargetLockState.Locking && IsThereSurplusMissile())
                {
                    if (IsThereSurplusMissile()) //还不够
                    {
                        if (targetLockInfo.LockTimeRemaining <= 0f)
                        {
                            targetLockInfo.LockState         = TargetLockState.Locked;
                            targetLockInfo.LockTimeRemaining = 0f;
                            targetLockInfo.LockTimes++;

                            SLog("目标锁定完成. {0}", targetEntity.name);
                        }
                        else
                        {
                            targetLockInfo.LockTimeRemaining -= deltaTime;
                        }
                    }
                    else //够了,将未完成转圈的
                    {
                        if (targetLockInfo.LockTimes == 0)
                        {
                            cancelLockList.Add(targetEntity);
                        }
                        else
                        {
                            targetLockInfo.LockState         = BattleWeapon_Missile.TargetLockState.Locked;
                            targetLockInfo.LockTimeRemaining = 0;
                        }
                    }
                }
            }

            // 对于那些已经不可用的目标解除锁定
            for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
            {
                m_LockTargeMap.Remove(cancelLockList[iEntity]);
                SLog("目标因为死亡或者超出视野而失去锁定. {0}", iEntity);
            }
        }

        // 通知UI当前锁定的所有目标
        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        //targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);
    }