public static EventObject makeBuy()
    {
        ItemCostTuple item = getRandomItem();

        EventObject BuyEvent = ScriptableObject.CreateInstance <EventObject>();
        EventObject Agree    = ScriptableObject.CreateInstance <EventObject>();
        EventObject NoThanks = ScriptableObject.CreateInstance <EventObject>();

        Agree.textEvents    = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They smile as they hand you the gold. They take the {0} and leave.", item.item.name), new ResourceAmount[0], null, null) };
        Agree.prerequisites = item.item.cost.ToArray();
        List <ResourceAmount> resourceEffect = new List <ResourceAmount>();

        for (int i = 0; i < item.item.cost.Count; i++)
        {
            resourceEffect.Add(new ResourceAmount(item.item.cost[i].resourceName, item.item.cost[i].amount * -1));
        }
        List <ResourceAmount> totalEffect = new List <ResourceAmount>(resourceEffect);

        totalEffect.Add(new ResourceAmount("Gold", item.priceUpper));
        Agree.effects = totalEffect.ToArray();
        Agree.title   = "Sell to Customer";

        NoThanks.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They frown as they take their gold and leave."), new ResourceAmount[0], null, null) };
        NoThanks.title      = "Sell to Customer";
        NoThanks.effects    = new ResourceAmount[0];

        BuyEvent.textEvents       = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("A customer walks in asking if they can buy one {0}.", item.item.name), resourceEffect.ToArray(), new ResourceAmount("Gold", item.priceUpper), null) };
        BuyEvent.connectedOptions = new EventObject.EventGroup[] { new EventObject.EventGroup(Agree, "Sure, I\'ll sell."), new EventObject.EventGroup(NoThanks, "I can\'t sell you that.") };
        BuyEvent.title            = "Sell to Customer";
        BuyEvent.effects          = new ResourceAmount[0];

        return(BuyEvent);
    }
    public static EventObject makeSell()
    {
        ItemCostTuple item = getRandomItem();

        EventObject SellEvent = ScriptableObject.CreateInstance <EventObject>();
        EventObject Agree     = ScriptableObject.CreateInstance <EventObject>();
        EventObject NoThanks  = ScriptableObject.CreateInstance <EventObject>();

        Agree.textEvents    = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They smile as they hand you the {0}. They take the gold and leave.", item.item.name), new ResourceAmount[0], null, null) };
        Agree.prerequisites = new ResourceAmount[] { new ResourceAmount("Gold", item.priceLower) };
        List <ResourceAmount> totalEffect = new List <ResourceAmount>(item.item.cost);

        totalEffect.Add(new ResourceAmount("Gold", item.priceLower * -1));
        Agree.effects = totalEffect.ToArray();
        Agree.title   = "Buy from Customer";

        NoThanks.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They frown as they take the {0} and leave.", item.item.name), new ResourceAmount[0], null, null) };
        NoThanks.title      = "Buy from Customer";
        NoThanks.effects    = new ResourceAmount[0];

        SellEvent.textEvents       = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("A customer walks in asking if they can sell their {0}.", item.item.name), item.item.cost.ToArray(), new ResourceAmount("Gold", item.priceLower * -1), null) };
        SellEvent.connectedOptions = new EventObject.EventGroup[] { new EventObject.EventGroup(Agree, "Sure, I\'ll buy."), new EventObject.EventGroup(NoThanks, "I can\'t buy that from you.") };
        SellEvent.title            = "Buy from Customer";
        SellEvent.effects          = new ResourceAmount[0];

        return(SellEvent);
    }
    private static ItemCostTuple getRandomItem()
    {
        ItemTuple     item     = ResourceItems[UnityEngine.Random.Range(0, ResourceItems.Count)];
        ItemCostTuple itemCost = new ItemCostTuple();

        itemCost.item = item;

        float flatPrice = 0;

        foreach (ResourceAmount amount in item.cost)
        {
            flatPrice += CostManager.Instance.getPrice(amount.resourceName) * amount.amount;
        }

        itemCost.priceUpper = Mathf.FloorToInt(flatPrice * (UnityEngine.Random.Range(1f, 1.4f) + (ResourceStorage.Instance.checkResource("Reputation") / 10f)));
        itemCost.priceLower = Mathf.FloorToInt(flatPrice * (UnityEngine.Random.Range(0.8f, 1f) - (ResourceStorage.Instance.checkResource("Reputation") / 20f)));
        return(itemCost);
    }
    public static EventObject makeQuest()
    {
        ItemCostTuple item  = getRandomItem();
        ItemCostTuple item2 = getRandomItem();

        EventObject QuestEvent    = ScriptableObject.CreateInstance <EventObject>();
        EventObject Agree         = ScriptableObject.CreateInstance <EventObject>();
        EventObject NoThanks      = ScriptableObject.CreateInstance <EventObject>();
        EventObject OnEnd         = ScriptableObject.CreateInstance <EventObject>();
        EventObject QuestSucess   = ScriptableObject.CreateInstance <EventObject>();
        EventObject QuestFailed   = ScriptableObject.CreateInstance <EventObject>();
        EventObject TooManyQuests = ScriptableObject.CreateInstance <EventObject>();
        QuestObject quest         = ScriptableObject.CreateInstance <QuestObject>();



        List <ResourceAmount> effects = new List <ResourceAmount>();

        for (int i = 0; i < item.item.cost.Count; i++)
        {
            effects.Add(item.item.cost[i]);
        }

        for (int i = 0; i < item2.item.cost.Count; i++)
        {
            if (effects.Exists(ra => ra.resourceName == item2.item.cost[i].resourceName))
            {
                effects.Find(ra => ra.resourceName == item2.item.cost[i].resourceName).amount += item2.item.cost[i].amount;
            }
            else
            {
                effects.Add(item2.item.cost[i]);
            }
        }

        quest.maxTurns = 2;
        quest.cost     = effects.ToArray();

        List <ResourceAmount> copyEffects = new List <ResourceAmount>(effects);

        for (int i = 0; i < copyEffects.Count; i++)
        {
            copyEffects[i] = new ResourceAmount(copyEffects[i].resourceName, copyEffects[i].amount * -1);
        }
        quest.reward     = new ResourceAmount("Gold", item.priceUpper + item2.priceUpper);
        quest.OnQuestEnd = OnEnd;

        QuestEvent.title = "Customer Quest";
        if (item.item.name == item2.item.name)
        {
            QuestEvent.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("A customer walks in asking for two {0}s in two days", item.item.name), copyEffects.ToArray(), new ResourceAmount("Turn", 2), new ResourceAmount("Gold", item.priceUpper + item2.priceUpper)) };
            quest.description     = string.Format("Get two {0}s", item.item.name);
            OnEnd.textEvents      = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("The customer from two days ago returns asking for their two {0}s", item.item.name), copyEffects.ToArray(), null, new ResourceAmount("Gold", item.priceUpper + item2.priceUpper)) };
        }
        else
        {
            QuestEvent.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("A customer walks in asking for one {0} and one {1} in two days.", item.item.name, item2.item.name), copyEffects.ToArray(), new ResourceAmount("Turn", 2), new ResourceAmount("Gold", item.priceUpper + item2.priceUpper)) };
            quest.description     = string.Format("Get one {0} and one {1}", item.item.name, item2.item.name);
            OnEnd.textEvents      = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("The customer from two days ago returns asking for their {0} and {1}", item.item.name, item2.item.name), copyEffects.ToArray(), null, new ResourceAmount("Gold", item.priceUpper + item2.priceUpper)) };
        }
        QuestEvent.effects          = new ResourceAmount[0];
        QuestEvent.connectedOptions = new EventObject.EventGroup[] { new EventObject.EventGroup(Agree, "Sure, I can make that order"), new EventObject.EventGroup(NoThanks, "I can\'t make that order") };

        Agree.textEvents      = new EventObject.TextEvent[] { new EventObject.TextEvent("\"Fantastic! I'll be back in two days.\" They leave the store.", new ResourceAmount[0], null, null) };
        Agree.assignedQuest   = quest;
        Agree.title           = "Customer Quest";
        Agree.onTooManyQuests = TooManyQuests;
        Agree.effects         = new ResourceAmount[0];

        NoThanks.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They frown and leave.", item.item.name), new ResourceAmount[0], null, null) };
        NoThanks.title      = "Customer Quest";
        NoThanks.effects    = new ResourceAmount[0];

        TooManyQuests.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("Unfortunately, you have too much on your plate (too many active quests)! You tell the customer you cannot accept their request. They leave looking disappointed."), new ResourceAmount[0], null, null) };
        TooManyQuests.title      = "Customer Quest";
        TooManyQuests.effects    = new ResourceAmount[0];

        OnEnd.title            = "!!End Customer Quest!!";
        OnEnd.effects          = new ResourceAmount[0];
        OnEnd.connectedOptions = new EventObject.EventGroup[] { new EventObject.EventGroup(QuestSucess, "Here are your items!"), new EventObject.EventGroup(QuestFailed, "I\'m sorry I can\'t give you those items.") };

        QuestSucess.title         = "!!End Customer Quest!!";
        QuestSucess.prerequisites = effects.ToArray();

        copyEffects.Add(new ResourceAmount("Gold", item.priceUpper + item2.priceUpper));
        copyEffects.Add(new ResourceAmount("Reputation", 1));
        QuestSucess.effects    = copyEffects.ToArray();
        QuestSucess.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("They smile as they take their items. They put the gold on your desk, thank you, and leave."), new ResourceAmount[0], null, null) };

        QuestFailed.title      = "!!End Customer Quest!!";
        QuestFailed.textEvents = new EventObject.TextEvent[] { new EventObject.TextEvent(string.Format("The customer leaves your store fuming with rage."), new ResourceAmount[0], null, null) };
        QuestFailed.effects    = new ResourceAmount[] { new ResourceAmount("Reputation", -1) };

        return(QuestEvent);
    }