public override float EstimateCost(IWorldState worldState) { IEntity entity = worldState.GetEntity(entityID); float dist = PathFinder.EstimateDistance(entity.Position, targetPos); return(dist); }
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); }
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); }
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; } } }
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; } }
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); } } }
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); }
public override void ExecuteImmediate(IWorldState worldState) { IEntity entity = worldState.GetEntity(entityID); entity.Position = targetPos; }
override public bool Satisfied(IWorldState worldState) { IEntity owner = worldState.GetEntity(entityId); return(owner.GetPower() >= minPower); }
public override bool Satisfied(IWorldState worldState) { IEntity entity = worldState.GetEntity(entityId); return(entity.Money > money); }
public override bool Satisfied(IWorldState worldState) { IEntity entity = worldState.GetEntity(entityID); return(entity.Position == position); }