Rocket upgrades done

This commit is contained in:
Sewmina
2022-10-22 00:29:09 +05:30
parent e6a3c8f705
commit 9175e6740b
67 changed files with 7501 additions and 291 deletions

View File

@@ -14,7 +14,7 @@ public class KillfeedMgr : MonoBehaviour
instance=this;
}
void Start(){
AddNewEntry("Welcome to UPF Minigame 1.2");
// AddNewEntry("Welcome to UPF Minigame 1.2");
}
public void AddNewEntry(string message){

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5779a57dc9f6c27aa8eaa3dbc76a8227
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,11 @@
using UnityEngine;
[CreateAssetMenu(fileName = "RocketSkin1", menuName = "Game/RocketSkinData", order = 1)]
public class RocketSkinStats : ScriptableObject
{
public RocketLevel[] baseLevels;
public RocketLevel[] commonLevels;
public RocketLevel[] rareLevels;
public RocketLevel[] legendaryLevels;
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: ec4b2a2c9c885ac4089eed59b7239880
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
using UnityEngine.UI;
public class RocketUpgradePanel : MonoBehaviour
{
public TMP_Text txtEnergyGain;
public TMP_Text txtSpeed;
public TMP_Text txtBoostConsumption;
public TMP_Text txtLevel;
public TMP_Text txtCostGold;
public TMP_Text txtCostMetal;
public Button btn_upgrade;
RocketLevel CurrentLevel,NextLevel;
SkinShopItemData selectedRocket;
public bool Affordable => DBmanager.Metal >= NextLevel.metalCost && DBmanager.Coins >= NextLevel.goldCost;
void Awake(){
btn_upgrade.onClick.AddListener(OnUpgrade);
}
public void Show(RocketLevel currentLevel, RocketLevel nextLevel, SkinShopItemData rocketData){
CurrentLevel = currentLevel;
NextLevel = nextLevel;
selectedRocket = rocketData;
txtLevel.text = "Level " +currentLevel.Level;
txtEnergyGain.text = $"{currentLevel.moonMultiplier} Per moon";
txtSpeed.text = $"{currentLevel.speedMultiplier*100}%";
txtBoostConsumption.text = $"{currentLevel.boostConsumption*100}%";
if(nextLevel != null){
txtLevel.text += $" -> <color=green> Level {nextLevel.Level}</color>";
txtEnergyGain.text += $" -> <color=green> {nextLevel.moonMultiplier}</color>";
txtSpeed.text += $" -> <color=green> {nextLevel.speedMultiplier*100}%</color>";
txtBoostConsumption.text += $" -> <color=green> {nextLevel.boostConsumption*100}%</color>";
}
btn_upgrade.interactable = Affordable;
txtCostGold.text = nextLevel.goldCost.ToString();
txtCostMetal.text = nextLevel.metalCost.ToString();
txtCostGold.transform.parent.gameObject.SetActive(nextLevel.goldCost > 0);
txtCostMetal.transform.parent.gameObject.SetActive(nextLevel.metalCost > 0);
gameObject.SetActive(true);
}
void OnUpgrade(){
if(!Affordable){
MessageDialog.instance.ShowMessage("Error","Not enough resources to upgrade.");
return;
}
DBmanager.UpgradeRocket(selectedRocket.name, NextLevel);
SkinShopManager.instance.Populate();
MessageDialog.instance.ShowMessage("Success","Rocket Upgraded Successfully!");
AudioManager.instnace.ChestOpen();
Hide();
}
public void Hide(){
gameObject.SetActive(false);
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8059e8e629278b13a8fb8109b44906d2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -10,8 +10,13 @@ public class SkinShopItem : MonoBehaviour
public GameObject[] banners;
public Image frame;
public bool Available;
public GameObject notPurchasedIndicator;
// public GameObject notPurchasedIndicator;
public SkinShopItemData skinData;
[Header("Stats")]
public TMP_Text txtLevel;
public TMP_Text txtEnergyGain;
public TMP_Text txtSpeed;
public TMP_Text txtBoostConsumption;
public void Set(SkinShopItemData data, bool available){
skinData = data;
@@ -20,8 +25,8 @@ public class SkinShopItem : MonoBehaviour
spaceshipImg.color = available ? Color.white : Color.black;
Available = available;
UpdateFrame();
if(data.price <=0){
if(data.price_metal <=0 && data.price_gold <=0){
banners[0].SetActive(true);
banners[1].SetActive(false);
}else{
@@ -31,7 +36,22 @@ public class SkinShopItem : MonoBehaviour
banners[2].SetActive(data.skinType== SkinType.Rare);
banners[3].SetActive(data.skinType== SkinType.Legendary);
//Level
txtLevel.text = "";
txtEnergyGain.transform.parent.gameObject.SetActive(available);
txtSpeed.transform.parent.gameObject.SetActive(available);
txtBoostConsumption.transform.parent.gameObject.SetActive(available);
if(available){
int curLevel = DBmanager.SkinsPurchased[data.name];
RocketLevel level = SkinShopManager.GetStatsForRarity(data)[curLevel];
txtLevel.text = "Level " +(curLevel+1);
txtEnergyGain.text = level.moonMultiplier.ToString();
txtSpeed.text = (level.speedMultiplier * 100).ToString("n0") + "%";
txtBoostConsumption.text = (level.boostConsumption * 100).ToString("n0") + "%";
}
}
public void UpdateFrame(){
@@ -42,15 +62,15 @@ public class SkinShopItem : MonoBehaviour
frame.enabled=false;
}
if(!DBmanager.SkinsPurchased.Contains(skinData.name)){
if(!DBmanager.SkinsPurchased.ContainsKey(skinData.name)){
frame.color = Color.red;
notPurchasedIndicator.SetActive(true);
notPurchasedIndicator.GetComponentInChildren<TMP_Text>().text = skinData.price.ToString();
// notPurchasedIndicator.SetActive(true);
// notPurchasedIndicator.GetComponentInChildren<TMP_Text>().text = skinData.price.ToString();
}else{
notPurchasedIndicator.SetActive(false);
// notPurchasedIndicator.SetActive(false);
}
if(!Available){
notPurchasedIndicator.SetActive(false);
// notPurchasedIndicator.SetActive(false);
}
}

View File

@@ -8,16 +8,23 @@ using UnityEngine.UI;
public class SkinShopManager : MonoBehaviour
{
public static SkinShopManager instance;
public RocketSkinStats rocketStats;
public static RocketSkinStats RocketStats;
public static bool availableToUpgrade;
public NewSkinDisplay newSkinDisplay;
public Building skinShopBuilding;
public SkinsData skinsData;
public static SkinsData SkinsData;
public GameObject popup;
public GameObject listItemPrefab;
public Transform listItemsParent;
public Button btn_Equip;
public Button btn_Buy;
public TMP_Text txt_buy_gold,txt_buy_metal;
public Button btn_Upgrade;
public RocketUpgradePanel upgradePanel;
public static SkinShopItemData selectedSkin;
public int[] prices;
public static int[] Prices => instance.prices;
@@ -25,6 +32,8 @@ public class SkinShopManager : MonoBehaviour
void Awake() {
instance = this;
RocketStats = rocketStats;
SkinsData = skinsData;
}
void Start()
{
@@ -32,6 +41,7 @@ public class SkinShopManager : MonoBehaviour
btn_Equip.onClick.AddListener(onEquip);
btn_Buy.onClick.AddListener(onBuy);
btn_Upgrade.onClick.AddListener(onUpgrade);
}
public void Show(){
@@ -46,7 +56,7 @@ public class SkinShopManager : MonoBehaviour
//Validate skins list
if(DBmanager.SkinsPurchased.Count <=0){
foreach(SkinShopItemData skin in skinsData.skins){
if(skin.price==0){ //Defaults
if(skin.price_metal==0 && skin.price_gold==0){ //Defaults
DBmanager.PurchaseSkin(skin);
if(GetEquipedSkin().Length <=0){
EquipSkin(skin.name);
@@ -66,7 +76,7 @@ public class SkinShopManager : MonoBehaviour
bool isAvailable = skinShopBuilding.curLevel >= rarity;
if(!isAvailable){continue;}
bool isOwned = DBmanager.SkinsPurchased.Contains(skinsData.skins[i].name);
bool isOwned = DBmanager.SkinsPurchased.ContainsKey(skinsData.skins[i].name);
if(skinShopBuilding.curLevel == rarity){
@@ -119,16 +129,21 @@ public class SkinShopManager : MonoBehaviour
btn_Equip.gameObject.SetActive(false); btn_Buy.gameObject.SetActive(false);
return;
}
if(DBmanager.SkinsPurchased.Contains(data.name)){ // <-- purchased
if(DBmanager.SkinsPurchased.ContainsKey(data.name)){ // <-- purchased
btn_Equip.gameObject.SetActive(true);
btn_Upgrade.gameObject.SetActive(true);
btn_Buy.gameObject.SetActive(false);
btn_Equip.interactable = GetEquipedSkin() != data.name; // <-- disable equip button if already equipped
}else{
btn_Buy.gameObject.SetActive(true);
btn_Equip.gameObject.SetActive(false);
btn_Buy.interactable = DBmanager.Metal >= data.price;
btn_Buy.GetComponentInChildren<TMP_Text>().text = data.price.ToString();
btn_Upgrade.gameObject.SetActive(false);
bool affordable = DBmanager.Metal >= data.price_metal && DBmanager.Coins >= data.price_gold;
btn_Buy.interactable = affordable;
txt_buy_gold.text = data.price_gold.ToString();
txt_buy_metal.text = data.price_metal.ToString();
txt_buy_gold.gameObject.SetActive(data.price_gold > 0);
txt_buy_metal.gameObject.SetActive(data.price_metal > 0);
}
foreach(SkinShopItem item in skinShopItems){
@@ -147,6 +162,12 @@ public class SkinShopManager : MonoBehaviour
Populate();
}
void onUpgrade(){
RocketLevel[] levels = GetStatsForRarity(selectedSkin);
int curLevel = DBmanager.SkinsPurchased[selectedSkin.name];
upgradePanel.Show(levels[curLevel], levels[curLevel+1],selectedSkin);
}
public void onBuy(){
List<SkinShopItemData> skinsInSameRarity = new List<SkinShopItemData>();
foreach(SkinShopItemData skin in skinsAvailableToPurchase){
@@ -167,6 +188,8 @@ public class SkinShopManager : MonoBehaviour
PlayerPrefs.Save();
}
//Helpers
public static string GetEquipedSkin(){
if(PlayerPrefs.HasKey("shipSkin")){
return PlayerPrefs.GetString("shipSkin");
@@ -175,6 +198,46 @@ public class SkinShopManager : MonoBehaviour
return "Default";
}
public static int GetRarityIndexFromName(string name){
int rarityIndex = 0;
foreach(SkinShopItemData item in SkinsData.skins){
if(item.name == name){
//this is it
if(item.price_gold <= 0 && item.price_metal <=0){
rarityIndex=0;
}else if(item.skinType == SkinType.Base){
rarityIndex=1;
}else if(item.skinType == SkinType.Rare){
rarityIndex = 2;
}else{
rarityIndex=3;
}
break;
}
}
return rarityIndex;
}
public static SkinType GetRarityFromName(string name){
return GetRarityFromIndex(GetRarityIndexFromName(name));
}
public static SkinType GetRarityFromIndex(int id){
if(id==0){
return SkinType.Default;
}else if(id==1){
return SkinType.Base;
}else if(id==2){
return SkinType.Rare;
}else{
return SkinType.Legendary;
}
}
public static Color getRarityColor(SkinShopItemData skin){
Color color = new Color(0,1,0);
if(skin.skinType == SkinType.Rare){
@@ -185,19 +248,54 @@ public class SkinShopManager : MonoBehaviour
return color;
}
public static RocketLevel[] GetStatsForRarity(SkinShopItemData data){
if(data.price_gold == 0 && data.price_metal ==0){
return RocketStats.baseLevels;
}else if(data.skinType == SkinType.Base){
return RocketStats.commonLevels;
}else if(data.skinType == SkinType.Rare){
return RocketStats.rareLevels;
}else{
return RocketStats.legendaryLevels;
}
}
public static RocketLevel[] GetStatsForRarity(SkinType data){
if(data == SkinType.Default){
return RocketStats.baseLevels;
}else if(data == SkinType.Base){
return RocketStats.commonLevels;
}else if(data == SkinType.Rare){
return RocketStats.rareLevels;
}else{
return RocketStats.legendaryLevels;
}
}
}
[Serializable]
public class SkinShopItemData{
public string name;
public Sprite image;
public int price;
public int price_gold,price_metal;
public SkinType skinType;
}
public enum SkinType{
Default,
Base,
Rare,
Legendary
}
[Serializable]
public class RocketLevel{
public int Level;
public int goldCost;
public int metalCost;
public float moonMultiplier;
public float speedMultiplier;
public float boostConsumption;
}

View File

@@ -30,6 +30,13 @@ public class SpaceshipController : NetworkBehaviour
public bool dead;
[SyncVar]
public float speed;
[SyncVar]
public float speedMultiplier;
[SyncVar]
public float boostConsumption;
[SyncVar]
public float energyGain;
public float _scaleMultiplier = 1;
public Text pnameTxt;
public Transform body;
@@ -51,6 +58,7 @@ public class SpaceshipController : NetworkBehaviour
public bool showDebugHUD = false;
public float distanceFromCenter = 0;
RocketLevel rocketStats;
public void SetReady(bool value){
if(isServer){
@@ -82,6 +90,13 @@ public class SpaceshipController : NetworkBehaviour
skinName = newSkin;
}
[Command]
void CmdSetStats(float _speed, float _energy, float _boost){
speedMultiplier = _speed;
energyGain = _energy;
boostConsumption = _boost;
}
void OnSkinChanged(string oldSkin, string newSkin)
{
ChangeSkin(newSkin);
@@ -175,19 +190,30 @@ public class SpaceshipController : NetworkBehaviour
}
//Set Skin
if (!DBmanager.SkinsPurchased.Contains(SkinShopManager.GetEquipedSkin()))
if (!DBmanager.SkinsPurchased.ContainsKey(SkinShopManager.GetEquipedSkin()))
{
//False skin purchase
}
else
{
string skin = SkinShopManager.GetEquipedSkin();
SkinType rarity = SkinShopManager.GetRarityFromName(skin);
int level = DBmanager.SkinsPurchased[skin];
RocketLevel stats = SkinShopManager.GetStatsForRarity(rarity)[level];
if (isServer)
{
skinName = SkinShopManager.GetEquipedSkin();
skinName = skin;
speedMultiplier = stats.speedMultiplier;
energyGain = stats.moonMultiplier;
boostConsumption = stats.boostConsumption;
}
else
{
CmdSetSkin(SkinShopManager.GetEquipedSkin());
CmdSetSkin(skin);
CmdSetStats(stats.speedMultiplier, stats.moonMultiplier,stats.boostConsumption);
}
}
@@ -253,14 +279,14 @@ public class SpaceshipController : NetworkBehaviour
//boost check
if (boosting && scale > 1)
{
speed = movingSpeed * 2;
DecreaseTrail(Time.deltaTime * 1);
speed = movingSpeed * 2 * speedMultiplier;
DecreaseTrail(Time.deltaTime * boostConsumption);
// scaleMultiplier -= Time.deltaTime;
// if (scaleMultiplier < 1) { scaleMultiplier = 1; } //Clamp in case gets lower
}
else
{
speed = movingSpeed;
speed = movingSpeed* speedMultiplier;
}
}
///Diff = rot1 . rot2
@@ -595,7 +621,12 @@ public class SpaceshipController : NetworkBehaviour
{
if (isLocalPlayer)
{
MinigameManager.instance.GainMetals((type == PickupItem.PickupType.Star) ? 2 : 5);
int gainedEnergy = (int)energyGain;
if(type == PickupItem.PickupType.Star){
gainedEnergy = Mathf.RoundToInt((float)gainedEnergy/2f);
}
MinigameManager.instance.GainMetals(gainedEnergy);
AudioManager.instnace.CollectPickup();
}
}