private void UI_UpdateHandDisplays() { for (uint i = 0; i < (uint)EPlayerHand.MAX; ++i) { EPlayerHand hand = (EPlayerHand)i; bool displayAmmo = false; if (m_player.m_playerWeaponHolder.IsHoldingWeaponInHand(hand)) { Item item = m_player.m_playerWeaponHolder.GetWeaponInHand(hand); if (item) { if (item.GetItemSprite()) { m_handDisplays[i].sprite = item.GetItemSprite(); } Weapon_Base baseWeapon = item as Weapon_Base; if (baseWeapon.GetWeaponType() == EWeaponType.RANGED) { Weapon_Ranged rangedWeapon = baseWeapon as Weapon_Ranged; if (rangedWeapon) { //set the fill amount to ration of ammo float ammoRatio = rangedWeapon.GetCurrentAmmo() / rangedWeapon.AccessWeaponStat(EWeaponStat.RANGED_CLIP_SIZE).GetCurrent(); m_handDisplaysAmmo[i].fillAmount = ammoRatio; //set ammo text m_handDisplaysAmmoText[i].text = rangedWeapon.GetCurrentAmmo().ToString(); //reload effect if (rangedWeapon.IsReloading()) { m_handDisplaysAmmo[i].color = Color.green; m_handDisplaysAmmo[i].fillAmount = 1 - (rangedWeapon.GetCurrentReloadTime() / rangedWeapon.AccessWeaponStat(EWeaponStat.RANGED_RELOAD_TIME).GetCurrent()); m_handDisplaysAmmoText[i].text = "R"; } else { m_handDisplaysAmmo[i].color = Color.white; } } displayAmmo = true; } } } else { m_handDisplays[i].sprite = m_defaultHandSprite; } m_handDisplaysAmmo[i].transform.parent.gameObject.SetActive(displayAmmo); } }
private Item LootCrossbow(int currentItemLevel) { Item testItem = new Weapon_Ranged(); int rarity = Rarity(); int nIL = NewItemLevel(rarity, currentItemLevel); int degreesSecun = Degrees(); int degreesPri = Degrees(); int amountSecun = 1; int amountPrim = 1; if (degreesSecun != 0) { amountSecun = AmountSecun(); } if (degreesPri != 0) { amountPrim = AmountPrimary(); } bool rOL = false; if (rarity >= 2) { rOL = true; } string secun = Database.hostInstance.GetRangedSecundary(rOL); //Item Creation XD testItem.StartUp(Database.hostInstance.GetCrossbowName(), rarity, Database.hostInstance.GetCrossbowSprite(), NewStats(nIL), Database.hostInstance.GetCrossbowObject(), nIL); testItem.StartWeapon(BaseDamage(nIL), FireRate(), secun, SecundaryFR(), ChargeTime(), Force(), amountSecun, degreesSecun, Buff(secun), Single(secun)); testItem.StartRanged(Force(), amountPrim, degreesPri); //end item creation test.Add((Weapon_Ranged)testItem); return(testItem); }
private void WeaponSlot_OnUsePrimary() { if (isDropped || isDecoy) { return; } // Ranged Attack. if (WeaponSlot.currentWeapon is Weapon_Ranged) { Weapon_Ranged weapon = WeaponSlot.currentWeapon as Weapon_Ranged; ProjectileManager.ProjectileData data = new ProjectileManager.ProjectileData { spawnPosition = ProjectileManager.instance.GetProjectileSpawn(this, weapon.primaryProjectile), spawnRotation = projectileSpawn.rotation, projectilePool = weapon.primaryProjectile, speed = ProjectileManager.instance.GetProjectileSpeed(weapon.force, weapon.primaryProjectile), damage = weapon.baseDamage + Player.localPlayer.entity.CalculateDamage(Stats.DamageType.Ranged), amount = weapon.amountOfProjectiles, coneOfFireInDegrees = weapon.coneOfFireInDegrees, mousePos = PlayerController.mouseInWorldPos, projectileOwnerID = Player.localPlayer.photonView.ViewID }; ProjectileManager.instance.FireProjectile(data); } // Melee Attack. else { Weapon_Melee weapon = WeaponSlot.currentWeapon as Weapon_Melee; int collidersFound = Physics.OverlapSphereNonAlloc(transform.position, weapon.attackRange, meleeHits, hitLayerMask); bool pvp = false; for (int i = 0; i < collidersFound; i++) { if (meleeHits[i].transform.tag == "PvPZone") { pvp = true; } } for (int i = 0; i < collidersFound; i++) { Vector3 toHit = meleeHits[i].transform.position - Player.localPlayer.playerController.body.position; if (Vector3.Dot(Player.localPlayer.playerController.body.forward, toHit) > 0) { Entity entity = meleeHits[i].GetComponent <Entity>(); if (entity) { if (pvp ? meleeHits[i].transform.tag == "Player" : meleeHits[i].transform.tag != "Player") { entity.Hit(-(weapon.baseDamage + Player.localPlayer.entity.CalculateDamage(Stats.DamageType.Melee)), Stats.DamageType.Melee, WeaponSlot.weaponBuffs); // TODO: Change this to an event or a parameter in Entity.Hit() UIManager.instance.playerStatusCanvas.Hit(); if (weapon.knockBack > 0 && !pvp) { entity.KnockBack(toHit, weapon.knockBack); } } } if (!string.IsNullOrEmpty(prefabToSpawnOnHit)) { GameObject newSpawn = ObjectPooler.instance.GrabFromPool(prefabToSpawnOnHit, meleeHits[i].ClosestPoint(transform.position), Quaternion.identity); } } } } }