/// <summary> /// 弹夹信息,只有主角才有 /// </summary> /// <param name="result"></param> private static void DisposeSyncClipInfo(SyncClipInfo result) { //Leyoutech.Utility.DebugUtility.LogWarning("广播", string.Format("弹夹信息, 武器ID = {0}", result.CurWeaponUid)); GameplayProxy m_GameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID()); if (entity == null) { return; } PlayerSkillProxy m_PlayerSkillProxy = GameFacade.Instance.RetrieveProxy(ProxyName.PlayerSkillProxy) as PlayerSkillProxy; m_PlayerSkillProxy.ChangeCurrentWeaponByServer(result.CurWeaponUid); foreach (WeaponValue info in result.Infos) { ulong weaponUID = info.WeaponUid; WeaponPowerVO power = entity.GetWeaponPower(weaponUID); if (power == null) { entity.SetWeaponPower(weaponUID, new WeaponPowerVO()); power = entity.GetWeaponPower(weaponUID); } power.WeaponUID = info.WeaponUid; power.CurrentValue = info.CurValue; power.MaxValue = info.MaxValue; power.SafeValue = info.SaftyValue; IWeapon weapon = m_PlayerSkillProxy.GetWeaponByUID(power.WeaponUID); if (weapon != null && weapon.GetConfig().ClipType != (int)WeaponL1.Treasure) { if (power.CurrentValue <= 0) { power.ForceCooldown = true; } else if (power.CurrentValue >= power.SafeValue) { power.ForceCooldown = false; } } else { if (power.CurrentValue >= power.MaxValue) { power.ForceCooldown = true; } else if (power.CurrentValue <= power.SafeValue) { power.ForceCooldown = false; } } } GameFacade.Instance.SendNotification(NotificationName.MSG_CHARACTER_WEAPON_POWER_CHANGED); entity.SendEvent(ComponentEventName.WeaponPowerChanged, null); }
private void OnWeaponPowerChanged(KProtoBuf buffer) { S2C_WEAPON_VALUE msg = buffer as S2C_WEAPON_VALUE; SpacecraftEntity entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID()); if (entity == null) { return; } m_PlayerSkillProxy.ChangeCurrentWeaponByServer(msg.cur_weapon_uid); foreach (WEAPONVALUE info in msg.infos) { ulong weaponUID = info.weapon_oid; WeaponPowerVO power = entity.GetWeaponPower(weaponUID); if (power == null) { entity.SetWeaponPower(weaponUID, new WeaponPowerVO()); power = entity.GetWeaponPower(weaponUID); } power.WeaponUID = info.weapon_oid; power.CurrentValue = info.cur_value; power.MaxValue = info.max_value; power.SafeValue = info.safty_valve; IWeapon weapon = m_PlayerSkillProxy.GetWeaponByUID(power.WeaponUID); if (weapon != null && weapon.GetConfig().ClipType != (int)WeaponL1.Treasure) { if (power.CurrentValue <= 0) { power.ForceCooldown = true; } else if (power.CurrentValue >= power.SafeValue) { power.ForceCooldown = false; } } else { if (power.CurrentValue >= power.MaxValue) { power.ForceCooldown = true; } else if (power.CurrentValue <= power.SafeValue) { power.ForceCooldown = false; } } } GameFacade.Instance.SendNotification(NotificationName.MSG_CHARACTER_WEAPON_POWER_CHANGED); entity.SendEvent(ComponentEventName.WeaponPowerChanged, null); }
public bool CanWeaponRelease(ulong UID) { SpacecraftEntity mainEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID()); WeaponPowerVO powerVO = mainEntity.GetWeaponPower(UID); int weaponType = ItemTypeUtil.GetWeaponType(GetWeaponByUID(UID)); // 武器是否有弹药或者是否已经冷却 if (weaponType < 0 || (powerVO != null && powerVO.ForceCooldown)) { Debug.LogFormat("power.current: {0}. ForceCooldown: {1}", powerVO.CurrentValue, powerVO.ForceCooldown); return(false); } return(true); }
/// <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; } } }