public override float EstimateCost(IWorldState worldState) { Merchant merchant = worldState.GetMerchant(merchantId); float salePrice = merchant.saleEntries[saleEntryIndex].price; return(salePrice); }
protected override void GenerateConditions(IWorldState worldState) { Merchant merchant = worldState.GetMerchant(merchantId); conditions = new List <Condition>(); MoneyCondition moneyCond = new MoneyCondition(buyerId, merchant.saleEntries[saleEntryIndex].price); conditions.Add(moneyCond); LocationCondition locationCond = new LocationCondition(buyerId, merchant.position); conditions.Add(locationCond); }
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 Merchant GetMerchant(int id) { if (merchantDict.TryGetValue(id, out Merchant merchant)) { return(merchant); } else { Merchant parentMerchant = parentWorldState.GetMerchant(id); if (parentMerchant != null) { Merchant m = parentMerchant.Clone(); merchantDict.Add(m.id, m); return(m); } else { return(null); } } }