MVC shop project for software architecture, in Unity.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

39 lines
1.4 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
/// <summary>
/// This item factory literally just takes a handcrafted list of items and populates the model with that!
/// </summary>
[CreateAssetMenu]//Allows creating ViewConfig objects in Assets -> Create menu in the Unity Editor
public class ProceduralWeaponFactory : ItemFactory
{
public ItemRarity Rarity;
public int DamageMin;
public int DamageMax;
public int PriceMin;
public int PriceMax;
public ItemPrototype[] Items;
public int Amount;
public override void PopulateModel(ShopModel model)
{
for (int i = 0; i < Amount; i++)
{
var item = Items[Random.Range(0, Items.Length)];
model.inventory.AddItem(new ItemWeapon(item.Name,item.Sprite.name,Random.Range(PriceMin,PriceMax),Random.Range(DamageMin,DamageMax) + item.AttackBonus,Random.Range(DamageMin,DamageMax) + item.AttackBonus + 3,item.Description, Rarity));
}
}
}
// This has the sole purpose of associating a sprite with a name for the factory. Not making it a scriptable object because doing this in the factory editor view is faster
[System.Serializable]
public struct ItemPrototype
{
public Sprite Sprite;
public string Name;
public string Description;
public int AttackBonus;
}