Example #1
0
    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);
    }
Example #2
0
    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);
    }
Example #3
0
    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);
    }
Example #4
0
    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);
    }
Example #5
0
 private void SendStats(StatPack stats, PowerupAttachable attachable)
 {
     if (attachable.isWeapon)
     {
         GarageStats.TryUpdate(stats, attachable.weaponLocation, attachable.baseDamage);
     }
     else
     {
         GarageStats.TryUpdate(stats, attachable.modLocation);
     }
 }
Example #6
0
    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);
    }
Example #7
0
    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);
    }
Example #8
0
    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);
    }
Example #9
0
    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);
    }
Example #10
0
 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();
 }
Example #11
0
 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();
 }
Example #12
0
    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;
        }
    }
Example #13
0
    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);
    }
Example #14
0
    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));
    }
Example #15
0
    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);
        }
    }
Example #16
0
 public static void SetCurrentStats(StatPack pack)
 {
     currentStats = pack;
 }
Example #17
0
 public static void SetBaseStats(StatPack pack)
 {
     baseStats = pack;
 }