public static StatPack Min(StatPack a, StatPack b) { StatPack c = new StatPack(); foreach (StatType type in System.Enum.GetValues(typeof(StatType))) { if (a.GetAdd(type) < b.GetAdd(type)) { c.SetAdd(type, a.GetAdd(type)); } else { c.SetAdd(type, b.GetAdd(type)); } if (a.GetMult(type) < b.GetMult(type)) { c.SetMult(type, a.GetMult(type)); } else { c.SetMult(type, b.GetMult(type)); } } return(c); }
public void ShowPotentialItem(GameObject item) { PowerupMain main = item.GetComponent <PowerupMain>(); PowerupAttachable attach = item.GetComponent <PowerupAttachable>(); StatPack pack = item.GetComponent <PowerupStats>().GetPack(); PowerupAttachable otherItem; StatPack otherPack; if (main.IsEquipped()) { return; } if (attach.isWeapon) { otherItem = controller.GetCar().GetComponent <PowerupManager>().GetWeapon(attach.weaponLocation); damageSliders.ShowPotentialWeapon(attach); } else { otherItem = controller.GetCar().GetComponent <PowerupManager>().GetMod(attach.modLocation); } if (otherItem == null) { otherPack = new StatPack(); } else { otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); } ShowStatBars(pack, otherPack); }
public static StatPack Instead(StatPack basePack, StatPack currentPack, StatPack newPack) { StatPack x = new StatPack(); foreach (StatType type in System.Enum.GetValues(typeof(StatType))) { x.SetAdd(type, (basePack.GetAdd(type) / (1 + currentPack.GetMult(type)) - currentPack.GetAdd(type) + newPack.GetAdd(type)) * (1 + newPack.GetMult(type))); } return(x); }
public static StatPack ApplyToBase(StatPack baseStats, StatPack powerups) { StatPack result = new StatPack(); foreach (StatType type in System.Enum.GetValues(typeof(StatType))) { result.SetAdd(type, (baseStats.GetAdd(type) + powerups.GetAdd(type)) * (1 + powerups.GetMult(type))); } return(result); }
private void SendStats(StatPack stats, PowerupAttachable attachable) { if (attachable.isWeapon) { GarageStats.TryUpdate(stats, attachable.weaponLocation, attachable.baseDamage); } else { GarageStats.TryUpdate(stats, attachable.modLocation); } }
public void SetupPlayer() { baseStats = new StatPack(); baseStats.SetAdd(StatPack.StatType.Health, 100); baseStats.SetAdd(StatPack.StatType.Nitro, 100); baseStats.SetAdd(StatPack.StatType.Weight, controller.GetCar().GetComponent <Rigidbody2D>().mass); baseStats.SetAdd(StatPack.StatType.TopSpeed, controller.GetCar().GetComponent <Driving>().topSpeed); baseStats.SetAdd(StatPack.StatType.Grip, controller.GetCar().GetComponent <Driving>().staticCoefficientOfFriction); baseStats.SetAdd(StatPack.StatType.Acceleration, controller.GetCar().GetComponent <Driving>().acceleration); GarageStats.SetBaseStats(baseStats); GarageStats.SetCurrentStats(baseStats); }
public void ShowUnequippedItem(ModMount mount) { StatPack pack = new StatPack(); PowerupAttachable otherItem = controller.GetCar().GetComponent <PowerupManager>().GetMod(mount); if (otherItem == null) { return; } StatPack otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); ShowStatBars(pack, otherPack); }
public void ReApplyStats(StatPack powerups) { StatPack newStats = StatPack.ApplyToBase(baseStats, powerups); maxHealth = newStats.GetAdd(StatPack.StatType.Health); maxNO2 = newStats.GetAdd(StatPack.StatType.Nitro); currentArmor = newStats.GetAdd(StatPack.StatType.Armor); controller.GetCar().GetComponent <Rigidbody2D>().mass = newStats.GetAdd(StatPack.StatType.Weight); controller.GetCar().GetComponent <Driving>().topSpeed = newStats.GetAdd(StatPack.StatType.TopSpeed); controller.GetCar().GetComponent <Driving>().staticCoefficientOfFriction = newStats.GetAdd(StatPack.StatType.Grip); controller.GetCar().GetComponent <Driving>().acceleration = newStats.GetAdd(StatPack.StatType.Acceleration); GarageStats.SetCurrentStats(newStats); }
public void ShowUnequippedItem(WeaponMount mount) { StatPack pack = new StatPack(); PowerupAttachable otherItem = controller.GetCar().GetComponent <PowerupManager>().GetWeapon(mount); if (otherItem == null) { return; } StatPack otherPack = otherItem.GetComponent <PowerupStats>().GetPack(); ShowStatBars(pack, otherPack); damageSliders.ShowPotentialWeapon(mount, controller.GetCar().GetComponent <PowerupManager>().baseDamage); }
public static void TryUpdate(StatPack pack, ModMount mod) { if (ModMin.ContainsKey(mod)) { ModMin[mod] = StatPack.Min(ModMin[mod], pack); ModMax[mod] = StatPack.Max(ModMax[mod], pack); } else { ModMin[mod] = StatPack.Min(new StatPack(), pack); ModMax[mod] = StatPack.Max(new StatPack(), pack); } UpdateMinMax(); }
public static void TryUpdate(StatPack pack, WeaponMount weapon, float damage) { if (damage > maxDamage) { maxDamage = damage; } if (WeaponMin.ContainsKey(weapon)) { WeaponMin[weapon] = StatPack.Min(WeaponMin[weapon], pack); WeaponMax[weapon] = StatPack.Max(WeaponMax[weapon], pack); } else { WeaponMin[weapon] = StatPack.Min(new StatPack(), pack); WeaponMax[weapon] = StatPack.Max(new StatPack(), pack); } UpdateMinMax(); }
private static void UpdateMinMax() { minStats = new StatPack(); maxStats = new StatPack(); foreach (StatPack pack in ModMin.Values) { minStats += pack; } foreach (StatPack pack in ModMax.Values) { maxStats += pack; } foreach (StatPack pack in WeaponMin.Values) { minStats += pack; } foreach (StatPack pack in WeaponMax.Values) { maxStats += pack; } }
public void ReCalcStats() { StatPack powerupStats = new StatPack(); foreach (PowerupAttachable attachment in equippedWeapons.Values) { PowerupStats newStats = attachment.GetComponent <PowerupStats>(); if (newStats != null) { powerupStats += newStats.GetPack(); } } foreach (PowerupAttachable attachment in equippedMods.Values) { PowerupStats newStats = attachment.GetComponent <PowerupStats>(); if (newStats != null) { powerupStats += newStats.GetPack(); } } controller.GetPlayer().ReApplyStats(powerupStats); }
public void ShowStatBars(StatPack pack, StatPack otherPack) { Slider slider; StatPack newStats; StatPack.StatType type; StatPack currentStats = GarageStats.currentStats; newStats = StatPack.Instead(GarageStats.currentStats, otherPack, pack); type = StatPack.StatType.Acceleration; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.Armor; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.Grip; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.Health; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.Nitro; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.TopSpeed; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); type = StatPack.StatType.Weight; slider = PickSlider(type); if (newStats.GetAdd(type) > currentStats.GetAdd(type) + 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(0, 1, 0, 0.3f); } if (newStats.GetAdd(type) < currentStats.GetAdd(type) - 0.00001f) { slider.transform.Find("Fill Area").Find("Fill").GetComponent <Image>().color = new Color(1, 0, 0, 0.3f); } slider.value = SliderPosition(GarageStats.MinStatValue(type), GarageStats.MaxStatValue(type), newStats.GetAdd(type)); }
public void UpdateButtons(List <GameObject> items) { int index = 1; Transform element = transform.Find("Slot0"); Select(element.gameObject); PowerupMain main; GarageItemButton gIB = element.gameObject.AddComponent <GarageItemButton>(); ButtonScripts scripts = element.gameObject.GetComponent <ButtonScripts>(); GarageSlider slider = GameObject.Find("GarageUI").transform.Find("StatSliders").GetComponent <GarageSlider>(); gIB.slider = slider; gIB.Unequipper(gameObject.name); element.GetComponent <Button>().onClick.AddListener(scripts.UnequipItem); foreach (GameObject item in items) { main = item.GetComponent <PowerupMain>(); element = gameObject.transform.Find("Slot" + index); element.Find("Text").GetComponent <Text>().text = item.gameObject.name; element.Find("Image").GetComponent <Image>().sprite = item.GetComponent <SpriteRenderer>().sprite; if (main.IsOwned()) { element.Find("Image").GetComponent <Image>().color = Color.white; element.Find("Text").GetComponent <Text>().color = Color.white; } else { element.Find("Image").GetComponent <Image>().color = Color.black; element.Find("Text").GetComponent <Text>().color = Color.black; } if (!main.IsChecked()) { main.Check(); StatPack stats = item.GetComponent <PowerupStats>().GetPack(); if (stats != null) { SendStats(stats, item.GetComponent <PowerupAttachable>()); } } if (main.IsEquipped()) { Select(element.gameObject); } scripts = element.gameObject.GetComponent <ButtonScripts>(); gIB = element.gameObject.AddComponent <GarageItemButton>(); scripts.SetItem(item); element.GetComponent <Button>().onClick.AddListener(scripts.EquipItem); slider = GameObject.Find("GarageUI").transform.Find("StatSliders").GetComponent <GarageSlider>(); gIB.slider = slider; gIB.item = item; element.GetComponent <Button>().onClick.AddListener(slider.SetSlidersOnNewEquip); index++; } for (; index < 5; index++) { element = gameObject.transform.Find("Slot" + index); element.gameObject.SetActive(false); } }
public static void SetCurrentStats(StatPack pack) { currentStats = pack; }
public static void SetBaseStats(StatPack pack) { baseStats = pack; }