/// <summary> /// Renders a single weapon box at the top of the screen /// </summary> /// <param name='playerWeapon'> /// Player weapon. /// </param> void RenderWeaponBox(WeaponDirector.PlayerWeapon playerWeapon) { // Render the box GUI.color = Color.white; GUI.DrawTexture(new Rect(0,0,guiWeaponBoxWidth,guiWeaponBoxHeight), weaponBoxTexture); // Render the icon GUI.color = PlayerDirector.ActiveSession.HasWeapon(playerWeapon) ? Color.black : new Color(0,0,0,0.3f); if (PlayerDirector.ActiveSession.CurrentWeapon == playerWeapon) { GUI.color = PlayerDirector.PlayerColor; } GUI.DrawTexture(new Rect(3,3,guiWeaponBoxWidth-6,guiWeaponBoxHeight-6), weaponBoxIconTextures[(int)playerWeapon]); // Render the hotkey GUI.Label(new Rect(2,2,guiWeaponBoxWidth,18),((int)playerWeapon+1).ToString(), weaponHotkeyGUIStyle); // Render the player ammo if (WeaponDirector.PlayerWeapon.Pistol != playerWeapon) { weaponAmmoGUIStyle.normal.textColor = PlayerDirector.ActiveSession.HasWeapon(playerWeapon) ? Color.black : Color.gray; GUI.Label(new Rect(0,0,guiWeaponBoxWidth-4,guiWeaponBoxHeight-1), PlayerDirector.ActiveSession.GetAmmo(playerWeapon).ToString(), weaponAmmoGUIStyle); } else { // Pistols have infinite ammo } }
/// <summary> /// Gives or takes a weapon from the player /// </summary> /// <param name='weapon'> /// Weapon. /// </param> /// <param name='hasWeapon'> /// Has weapon. /// </param> public static void SetHasWeapon(WeaponDirector.PlayerWeapon weapon, bool hasWeapon) { if (WeaponDirector.PlayerWeapon.Pistol != weapon) { _availableWeapons[(int)weapon] = hasWeapon; } }
/// <summary> /// Sets the player's active ammo. /// </summary> /// <param name='weapon'> /// Weapon. /// </param> /// <param name='ammoValue'> /// Ammo value. /// </param> public static void SetAmmo(WeaponDirector.PlayerWeapon weapon, int ammoAmount) { if (WeaponDirector.PlayerWeapon.Pistol != weapon) { _ammo[(int)weapon] = ammoAmount; } }
/// <summary> /// Determines if this player has a weapon in this active sesson /// </summary> /// <returns> /// True if the player has the weapon /// </returns> /// <param name='weapon'> /// If set to <c>true</c> weapon. /// </param> public static bool HasWeapon(WeaponDirector.PlayerWeapon weapon) { if (WeaponDirector.PlayerWeapon.Pistol == weapon) { return true; } else { return _availableWeapons[(int)weapon]; } }
/// <summary> /// Gets the player's active ammo. /// </summary> /// <returns> /// The ammo. /// </returns> /// <param name='weapon'> /// Weapon. /// </param> public static int GetAmmo(WeaponDirector.PlayerWeapon weapon) { if (WeaponDirector.PlayerWeapon.Pistol == weapon) { return 1; // Infinite ammo; will never be zero } return _ammo[(int)weapon]; }
/// <summary> /// Called by GiveDropToPlayer to give a weapon to the player /// </summary> /// <param name='weapon'> /// Weapon. /// </param> /// <param name='defaultAmmo'> /// Default ammo. /// </param> void GiveWeaponDropToPlayer(WeaponDirector.PlayerWeapon weapon, int defaultAmmo) { if (!PlayerDirector.ActiveSession.HasWeapon(weapon)) { // Flag ourselves as now having this weapon PlayerDirector.ActiveSession.SetHasWeapon(weapon, true); // Now set the active weapon PlayerDirector.ActiveSession.CurrentWeapon = weapon; playerCharacter.SendMessage("SetActiveWeapon", "Player" + weapon.ToString()); PlayerDirector.ActiveSession.SetAmmo(weapon, defaultAmmo); } else { PlayerDirector.ActiveSession.IncreaseAmmo(weapon, defaultAmmo); } }