示例#1
0
    public override float EstimateCost(IWorldState worldState)
    {
        IEntity entity = worldState.GetEntity(entityID);
        float   dist   = PathFinder.EstimateDistance(entity.Position, targetPos);

        return(dist);
    }
示例#2
0
    public override List <Action> GenerateSatisfyingActions(IWorldState worldState, int maxActions)
    {
        List <Action> actions = new List <Action>();

        IEntity entity = worldState.GetEntity(entityId);


        float powerDiff = minPower - entity.GetPower();

        if (powerDiff <= 0)
        {
            return(actions);
        }

        ItemFilter filter = new ItemFilter();

        filter.requireEquippable = true;
        for (int i = 0; i < Item.numItemSlots; i++)
        {
            if (entity.TryGetEquippedItem((ItemSlot)i, out Item item))
            {
                filter.minPower[i] = powerDiff + item.power;
            }
            else
            {
                filter.minPower[i] = powerDiff;
            }
        }
        EquipAction equipAction = new EquipAction(worldState, entityId, filter);

        actions.Add(equipAction);
        return(actions);
    }
示例#3
0
    override public bool Satisfied(IWorldState worldState)
    {
        IEntity owner = worldState.GetEntity(ownerId);

        foreach (Item i in owner.GetInventory())
        {
            if (itemFilter.Satisfied(i))
            {
                return(true);
            }
        }
        return(false);
    }
示例#4
0
    public override void ExecuteImmediate(IWorldState worldState)
    {
        IEntity entity = worldState.GetEntity(entityId);

        foreach (Item item in entity.GetInventory())
        {
            if (itemFilter.Satisfied(item) && item.equippable)
            {
                entity.EquipItem(item, item.slot);
                return;
            }
        }
    }
示例#5
0
    public override void ExecuteImmediate(IWorldState worldState)
    {
        IEntity  buyer     = worldState.GetEntity(buyerId);
        Merchant merchant  = worldState.GetMerchant(merchantId);
        float    salePrice = merchant.saleEntries[saleEntryIndex].price;

        if (buyer.Money > salePrice)
        {
            Item item = merchant.saleEntries[saleEntryIndex].itemTemplate.Generate();
            buyer.AddInventoryItem(item);
            buyer.Money -= salePrice;
        }
    }
示例#6
0
 public IEntity GetEntity(int id)
 {
     if (entityDict.TryGetValue(id, out IEntity entity))
     {
         return(entity);
     }
     else
     {
         IEntity parentEntity = parentWorldState.GetEntity(id);
         if (parentEntity != null)
         {
             AbstractEntity e = new AbstractEntity(parentEntity);
             entityDict.Add(parentEntity.Id, e);
             return(e);
         }
         else
         {
             return(null);
         }
     }
 }
示例#7
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);
    }
示例#8
0
    public override void ExecuteImmediate(IWorldState worldState)
    {
        IEntity entity = worldState.GetEntity(entityID);

        entity.Position = targetPos;
    }
示例#9
0
    override public bool Satisfied(IWorldState worldState)
    {
        IEntity owner = worldState.GetEntity(entityId);

        return(owner.GetPower() >= minPower);
    }
示例#10
0
    public override bool Satisfied(IWorldState worldState)
    {
        IEntity entity = worldState.GetEntity(entityId);

        return(entity.Money > money);
    }
示例#11
0
    public override bool Satisfied(IWorldState worldState)
    {
        IEntity entity = worldState.GetEntity(entityID);

        return(entity.Position == position);
    }