/// <summary> /// 武器技能发射, 对武器造成影响. 计算新的弹道散布和后坐力 /// </summary> private void PostWeaponFire(IComponentEvent entityEvent) { // 临时代码. 只有准星类型是1的武器, 才扩散弹道 IWeapon weapon = m_SkillProxy.GetCurrentWeapon(); BattleWeaponBase currentBattleWeapon = m_SkillProxy.GetCurrentBattleWeapon(); currentBattleWeapon?.PostWeaponFire(); }
private void RequestReload() { IWeapon weapon = m_PlayerSkillProxy.GetCurrentWeapon(); if (weapon != null) { // C2S_CHANGE_MAGAZINE msg = SingleInstanceCache.GetInstanceByType<C2S_CHANGE_MAGAZINE>(); // msg.protocolID = (ushort)KC2S_Protocol.c2s_change_magazine; // msg.weapon_tid = weapon.GetUID(); // SendToGameServer(msg); c2s_WeaponReload msg = new c2s_WeaponReload(); msg.WeaponUid = weapon.GetUID(); RequestWeaponReloadRPC.RequestWeaponReload(msg); } }
/// <summary> /// 武器热键响应 /// </summary> private void WeaponHotKeyOperation(IComponentEvent entityEvent) { SkillHotkey skillHotkey = entityEvent as SkillHotkey; IWeapon weapon = m_SkillProxy.GetCurrentWeapon(); if (weapon == null) { return; } //武器&准星循环 WeaponAndCrossSight weaponCS = m_SkillProxy.GetCurrentWeaponAndCrossSight(); if (weaponCS != null) { weaponCS.OnHotKey(skillHotkey); } }
/// <summary> /// 主武器改变时 /// </summary> private void OnMainWeaponChanged() { m_lastFireFail = false; m_CurrentTargetList.Clear(); m_Crosshair = null; m_Point = null; m_Frame = null; m_FrameBox = null; m_TargetBox = null; for (int i = 0; i < m_Root.childCount; i++) { m_Root.GetChild(i).gameObject.SetActive(false); } PlayerSkillProxy skillProxy = Facade.RetrieveProxy(ProxyName.PlayerSkillProxy) as PlayerSkillProxy; IWeapon currentWeapon = skillProxy.GetCurrentWeapon(); m_WeaponStyle = (int)WeaponAndCrossSight.WeaponAndCrossSightTypes.Null; m_AutoLockEnabled = currentWeapon != null && currentWeapon.GetConfig().AssistKey != 0; SpacecraftEntity main = GetMainEntity(); if (main && IsBattling()) { IReformer reformer = skillProxy.UsingReformer() ? skillProxy.GetReformer() : null; if (reformer != null) m_WeaponStyle = (WeaponAndCrossSight.WeaponAndCrossSightTypes)reformer.GetConfig().Reticle; else if (currentWeapon != null) m_WeaponStyle = (WeaponAndCrossSight.WeaponAndCrossSightTypes)currentWeapon.GetConfig().Reticle; } m_Crosshair = m_Root.GetChild((int)m_WeaponStyle).GetComponent<RectTransform>(); // m_Crosshair.gameObject.SetActive(true); m_Point = m_Crosshair.Find("point") != null ? m_Crosshair.Find("point").GetComponent<RectTransform>() : null; m_Frame = m_Crosshair.Find("frame") != null ? m_Crosshair.Find("frame").GetComponent<RectTransform>() : null; m_FrameBox = m_Crosshair.Find("FrameBox") != null ? m_Crosshair.Find("FrameBox").GetComponent<RectTransform>() : null; m_TargetBox = m_Crosshair.Find("Targets") != null ? m_Crosshair.Find("Targets").GetComponent<RectTransform>() : null; }
/// <summary> /// 武器切换时 /// </summary> /// <param name="hiddenRoot">是否隐藏根节点</param> private void OnWeaponToggleEnd(bool hiddenRoot) { m_Root.alpha = hiddenRoot ? 0 : 1; PlayerSkillProxy skillProxy = Facade.RetrieveProxy(ProxyName.PlayerSkillProxy) as PlayerSkillProxy; IWeapon currWeapon = skillProxy.GetCurrentWeapon(); if (currWeapon != null) { IWeapon mainWeapon = skillProxy.GetWeaponByIndex(0); IWeapon secondaryWeapon = skillProxy.GetWeaponByIndex(1); m_MainWeapon.gameObject.SetActive(true); m_SecondaryWeapon.gameObject.SetActive(true); m_MainWeapon.ResetTrigger("Big"); m_MainWeapon.ResetTrigger("Small"); m_SecondaryWeapon.ResetTrigger("Big"); m_SecondaryWeapon.ResetTrigger("Small"); m_RootAnimator.ResetTrigger("Show"); m_RootAnimator.SetTrigger("Show"); if (skillProxy.UsingReformer()) { if (currWeapon.GetPos() == 0) { m_MainWeapon.SetTrigger("Big"); m_SecondaryWeapon.SetTrigger("Small"); m_SecondaryWeapon.gameObject.SetActive(secondaryWeapon != null); } else if (currWeapon.GetPos() == 1) { m_MainWeapon.SetTrigger("Small"); m_SecondaryWeapon.SetTrigger("Big"); m_MainWeapon.gameObject.SetActive(mainWeapon != null); } } else { if (currWeapon.GetPos() == 0) { m_MainWeapon.SetTrigger("Big"); m_SecondaryWeapon.SetTrigger("Small"); m_SecondaryWeapon.gameObject.SetActive(secondaryWeapon != null); } else if (currWeapon.GetPos() == 1) { m_MainWeapon.SetTrigger("Small"); m_SecondaryWeapon.SetTrigger("Big"); m_MainWeapon.gameObject.SetActive(mainWeapon != null); } } m_MainWeapon.gameObject.SetActive(mainWeapon != null); if (mainWeapon != null) { UIUtil.SetIconImage(m_MainWeaponIcon, mainWeapon.GetBaseConfig().Icon); } m_SecondaryWeaponIcon.gameObject.SetActive(secondaryWeapon != null); if (secondaryWeapon != null) { UIUtil.SetIconImage(m_SecondaryWeaponIcon, secondaryWeapon.GetBaseConfig().Icon); } } else { m_MainWeapon.gameObject.SetActive(false); m_SecondaryWeapon.gameObject.SetActive(false); } }
/// <summary> /// 更新武器的子弹信息 /// </summary> private void UpdateWeaponBullets() { if (m_Crosshair != null && m_WeaponStyle != WeaponAndCrossSight.WeaponAndCrossSightTypes.Null) { Transform powerSlider = FindComponent<Transform>(m_Crosshair, "Slider"); Animator powerSliderAnimator = FindComponent<Animator>(m_Crosshair, "Slider"); if (powerSlider == null) return; PlayerSkillProxy skillProxy = Facade.RetrieveProxy(ProxyName.PlayerSkillProxy) as PlayerSkillProxy; if (skillProxy.UsingReformer()) { powerSlider.gameObject.SetActive(false); return; } IWeapon currentWeapon = skillProxy.GetCurrentWeapon(); if (currentWeapon == null) { powerSlider.gameObject.SetActive(false); return; } WeaponPowerVO weaponVO1 = skillProxy.GetWeaponPowerOfMainPlayer(0); WeaponPowerVO weaponVO2 = skillProxy.GetWeaponPowerOfMainPlayer(1); WeaponPowerVO power = weaponVO1 != null && skillProxy.GetWeaponByUID(weaponVO1.WeaponUID) == currentWeapon ? weaponVO1 : weaponVO2; float curr = 0; float total = 0; if (power != null) { if (m_WeaponStyle == WeaponAndCrossSight.WeaponAndCrossSightTypes.MachineGun ) { curr = power.CurrentValue; total = power.MaxValue; } else if (m_WeaponStyle == WeaponAndCrossSight.WeaponAndCrossSightTypes.Missile) { foreach (var entity in m_CurrentTargetList.Values) { curr += entity.LockTimes; } total = MaxMissileCount;// skillProxy.GetCurrentBattleWeapon().GetRelativeHeightOfReticle().MissileCountInOneShot; } else if ((int)m_WeaponStyle ==(int)WeaponAndCrossSight.WeaponAndCrossSightTypes.ShotGun) { curr = power.CurrentValue; total = power.MaxValue; } } float weaponPowerRatio = total != 0 ? curr / total : 0; if (powerSliderAnimator) { if (power.ForceCooldown) powerSliderAnimator.SetInteger("State", 2); else if (weaponPowerRatio <= 0.7f) powerSliderAnimator.SetInteger("State", 0); else if (weaponPowerRatio > 0.7f) powerSliderAnimator.SetInteger("State", 1); if (m_lastFireFail) powerSliderAnimator.SetTrigger("FireFail"); } m_lastFireFail = false; RadialSlider radialSlider = powerSlider.GetComponent<RadialSlider>(); if(radialSlider) { radialSlider.FillAmount = weaponPowerRatio; return; } BulletSlider bulletSlider = powerSlider.GetComponent<BulletSlider>(); if(bulletSlider) { bulletSlider.BulletCount = (int)total; bulletSlider.FillAmount = weaponPowerRatio; return; } Slider commonSlider = powerSlider.GetComponent<Slider>(); if(commonSlider) { commonSlider.minValue = 0; commonSlider.maxValue = 1; commonSlider.value = weaponPowerRatio; return; } } }