Example #1
0
    void CloneParentMerchants()
    {
        merchantDict = new Dictionary <int, Merchant>();
        ICollection <Merchant> parentMerchants = parentWorldState.GetMerchants();

        foreach (Merchant m in parentMerchants)
        {
            if (!merchantDict.ContainsKey(m.id))
            {
                merchantDict.Add(m.id, m.Clone());
            }
        }
    }
Example #2
0
    public override List <Action> GenerateSatisfyingActions(IWorldState worldState, int maxActions)
    {
        List <BuyOption> options = new List <BuyOption>();
        IEntity          owner   = worldState.GetEntity(ownerId);

        foreach (Merchant m in worldState.GetMerchants())
        {
            int bestIndex = -1;
            for (int i = 0; i < m.saleEntries.Count; i++)
            {
                if (itemFilter.Satisfied(m.saleEntries[i].itemTemplate.Expected()))
                {
                    if (bestIndex == -1 || m.saleEntries[bestIndex].price < m.saleEntries[i].price)
                    {
                        bestIndex = i;
                    }
                }
            }
            if (bestIndex != -1)
            {
                float dist = PathFinder.EstimateDistance(owner.Position, m.position);
                options.Add(new BuyOption(m, dist, bestIndex));
            }
        }
        //Debug.Log($"Found {options.Count} options");

        options.Sort((x, y) => x.dist.CompareTo(y.dist));
        List <Action> actions = new List <Action>();

        for (int i = 0; i < Mathf.Min(maxActions, options.Count); i++)
        {
            BuyAction buyAction = new BuyAction(worldState, ownerId, options[i].saleEntryIndex, options[i].merchant.id);
            actions.Add(buyAction);
        }
        return(actions);
    }