} // NPCÉ̵ê public NpcShop Lookup(int id) { NpcShop vShop = null; NpcShopList.TryGetValue(id, out vShop); return(vShop); }
internal void SendClosedMessage(NpcShop shop) { var msg = !string.IsNullOrWhiteSpace(shop.ClosedMessage) ? shop.ClosedMessage : $"This shop is closed. Come back at {shop.OpeningTime}."; player.SendErrorMessage(msg); }
private void sendOpenMessage(NpcShop shop) { if (shop.Message != null) { player.SendInfoMessage(shop.Message); } }
private void TryLoad() { var shops = new List <NpcShop>(); if (BankingPlugin.Instance == null) { this.LogPrint("BankingPlugin is not available. Banking is required for NpcShopsPlugin to operate.", TraceLevel.Error); return; } var files = Directory.EnumerateFiles("npcshops", "*.shop", SearchOption.AllDirectories); foreach (var file in files) { var definition = NpcShopDefinition.TryLoadFromFile(file); if (definition != null) { var errors = 0; var warnings = 0; var validationResult = definition.Validate(); validationResult.Source = $"NpcShop {file}."; validationResult.GetTotals(ref errors, ref warnings); if (errors > 0 || warnings > 0) { this.LogPrint(validationResult); } if (errors == 0) { try { var shop = new NpcShop(definition); shops.Add(shop); } catch (Exception ex) { this.LogPrint($"An error occured while trying to create NpcShop {file}.", TraceLevel.Error); this.LogPrint(ex.Message, TraceLevel.Error); } } else { this.LogPrint($"Disabling NpcShop {file} due to errors.", TraceLevel.Error); } } } NpcShops = shops; }
public void Load(byte[] bytes) { BinaryHelper helper = new BinaryHelper(bytes); int length = helper.ReadInt(); NpcShopList = new Dictionary <int, NpcShop>(); for (int index = 0; index < length; ++index) { NpcShop info = new NpcShop(); info.Load(helper); NpcShopList.Add(info.ShopId, info); } }
void Start() { //canvas에 접근 canvasTag = FindTag.getInstance().canvas; canvasTr = Find.getInstance().FindTagTransform(canvasTag); //shopNpc에 접근 shopNpcTag = FindTag.getInstance().shopNpc; shopNpcTr = Find.getInstance().FindTagTransform(shopNpcTag); npcShopSc = shopNpcTr.GetComponent <NpcShop>(); //칸마다의 image에 접근 for (int i = 0; i < slotEffects.Length; i++) { slotEffects[i] = canvasTr.GetChild(17).transform.GetChild(1).transform.GetChild(i).gameObject.GetComponent <Image>(); } }
private static string GetPostPurchaseRenderString(NpcShop shop, ShopProduct product, decimal totalCost, int quantity) { var sb = new StringBuilder(); if (totalCost > 0) { var totalCostString = product.Currency.GetCurrencyConverter().ToString(totalCost); sb.Append($"[c/{ Color.OrangeRed.Hex3()}:{totalCostString}]"); } if (product.RequiredItems.Count > 0) { var fragment = NpcShop.GetMaterialsCostRenderString(product, quantity);; sb.Append(totalCost > 0 ? $" and {fragment}" : fragment); } return(sb.ToString()); }
void Awake() { //currentJob = SelectSceneCtrl.selectJob; //test 한직업으로 고정 currentJob = "Magician"; dataBaseTag = FindTag.getInstance().dataBase; dataBaseTr = Find.getInstance().FindTagTransform(dataBaseTag); itemManagerSc = dataBaseTr.GetComponent <ItemManager>(); saveLoadDataSc = dataBaseTr.GetComponent <SaveLoadData>(); npcShopTag = FindTag.getInstance().shopNpc; npcShopTr = Find.getInstance().FindTagTransform(npcShopTag); npcShopSc = npcShopTr.GetComponent <NpcShop>(); for (int i = 0; i < inventorySlots.Length; i++) { inventorySlots[i] = content.transform.GetChild(i + 1).gameObject; } }
private void Awake() { //오브젝트 지정 for (int i = 0; i < inventorySlots.Length; i++) { inventorySlots[i] = content.transform.GetChild(i + 1).gameObject; } npcShopTag = FindTag.getInstance().shopNpc; npcShopTr = Find.getInstance().FindTagTransform(npcShopTag); npcShopSc = npcShopTr.GetComponent <NpcShop>(); for (int i = 0; i < randomSlotBools.Length; i++) { randomImageNames[i] = randomImageName + i; randomSlotBools[i] = randomSlotBool + i; } for (int i = 0; i < randomSlots.Length; i++) { randomSlots[i] = randomContents.transform.GetChild(i).gameObject; } }
private NpcShop getCurrentShop() { NpcShop newShop = null; if (HasShopkeeper && IsShopkeeperInRange()) { //npc shop var shopKeeper = GetShopkeeper(); string npcType = null; //Determine if this is a custom npc, and if so try to get its id/internal name. if (shopKeeper != null) { var customNpc = NpcManager.Instance?.GetCustomNpc(shopKeeper); if (customNpc != null) { npcType = customNpc.Definition.Name; } } if (npcType == null) { npcType = shopKeeper.type.ToString(); } NpcShop.NpcToShopMap.TryGetValue(npcType, out newShop); } if (newShop == null) { //region shop newShop = NpcShopsPlugin.Instance.NpcShops.FirstOrDefault(ns => ns.Rectangle.Contains(player.TileX, player.TileY)); } return(newShop); }
public static void NpcBuy(CommandArgs args) { var parameters = args.Parameters; var player = args.Player; if (parameters.Count != 1 && parameters.Count != 2) { player.SendErrorMessage($"Syntax: {Commands.Specifier}npcbuy <index> [amount]"); return; } var session = GetOrCreateSession(player); var shop = session.CurrentShop; if (shop == null) { player.SendErrorMessage("You aren't currently in a shop."); return; } if (!shop.IsOpen) { session.SendClosedMessage(shop); return; } var inputIndex = parameters[0]; if (!int.TryParse(inputIndex, out var index) || index < 1 || index > shop.ShopItems.Count + shop.ShopCommands.Count) { player.SendErrorMessage($"Invalid index '{inputIndex}'."); return; } index -= 1; var inputAmount = parameters.Count == 2 ? parameters[1] : "1"; if (!int.TryParse(inputAmount, out var amount) || amount < 1) { player.SendErrorMessage($"Invalid amount '{inputAmount}'."); return; } if (index < shop.ShopItems.Count) { var shopItem = shop.ShopItems[index]; var currencyConverter = shopItem.Currency.GetCurrencyConverter(); if (shopItem.StackSize == 0 || shopItem.PermissionRequired != null && !player.HasPermission(shopItem.PermissionRequired)) { player.SendErrorMessage($"Invalid index '{inputIndex}'."); return; } if (amount > shopItem.StackSize && shopItem.StackSize > 0 || amount > shopItem.MaxStackSize) { player.SendErrorMessage($"Invalid amount '{inputAmount}'."); return; } var purchaseCost = amount * shopItem.UnitPrice; var salesTax = Math.Round(purchaseCost * (decimal)shop.SalesTaxRate); var itemText = $"[i/s{amount},p{shopItem.PrefixId}:{shopItem.ItemId}]"; if (purchaseCost > 0) { var purchaseCostString = currencyConverter.ToString(purchaseCost); var salesTaxString = currencyConverter.ToString(salesTax); player.SendInfoMessage($"Purchasing {itemText} will cost [c/{Color.OrangeRed.Hex3()}:{purchaseCostString}], " + $"with a sales tax of [c/{Color.OrangeRed.Hex3()}:{salesTaxString}]."); } if (shopItem.RequiredItems.Count > 0) { player.SendInfoMessage(purchaseCost > 0 ? $"{itemText} will also require materials: " : $"{itemText} requires materials: "); player.SendInfoMessage(NpcShop.GetMaterialsCostRenderString(shopItem, amount)); } player.SendInfoMessage("Do you wish to proceed? Use /yes or /no."); player.AddResponse("yes", args2 => { player.AwaitingResponse.Remove("no"); //var account = SEconomyPlugin.Instance?.GetBankAccount(player); var account = BankingPlugin.Instance.GetBankAccount(player, shopItem.Currency.InternalName); var totalCost = purchaseCost + salesTax; if (account == null || account.Balance < totalCost) { player.SendErrorMessage($"You do not have enough of a balance to purchase {itemText}."); return; } if (amount > shopItem.StackSize && shopItem.StackSize > 0) { player.SendErrorMessage("While waiting, the stock changed."); return; } if (!player.HasSufficientMaterials(shopItem, amount)) { player.SendErrorMessage($"You do not have sufficient materials to purchase {itemText}."); return; } var item = new Item(); item.SetDefaults(shopItem.ItemId); var worldAccount = BankingPlugin.Instance.GetBankAccount("Server", shopItem.Currency.InternalName); if (account.TryTransferTo(worldAccount, totalCost)) { //deduct materials from player player.TransferMaterials(shopItem, amount); if (shopItem.StackSize > 0) { shopItem.StackSize -= amount; } player.GiveItem(shopItem.ItemId, "", Player.defaultWidth, Player.defaultHeight, amount, shopItem.PrefixId); player.SendSuccessMessage($"Purchased {itemText} for { GetPostPurchaseRenderString(shop, shopItem, totalCost, amount) }."); } else { player.SendErrorMessage($"Transfer of funds failed for {itemText}."); } //refresh the shop dispay for player, after some time so they can the transaction messages. shop.ShowTo(player, 2000); }); player.AddResponse("no", args2 => { player.AwaitingResponse.Remove("yes"); player.SendInfoMessage("Canceled purchase."); }); } else { index -= shop.ShopItems.Count; var shopCommand = shop.ShopCommands[index]; var currencyConverter = shopCommand.Currency.GetCurrencyConverter(); if (shopCommand.StackSize == 0) //|| //shopCommand.PermissionRequired != null && !player.HasPermission(shopCommand.PermissionRequired)) { player.SendErrorMessage($"Invalid index '{inputIndex}'."); return; } if (amount > shopCommand.StackSize && shopCommand.StackSize > 0) { player.SendErrorMessage($"Invalid amount '{inputAmount}'."); return; } var purchaseCost = amount * shopCommand.UnitPrice; var salesTax = Math.Round(purchaseCost * (decimal)shop.SalesTaxRate); var commandText = $"{shopCommand.Name} x[c/{Color.OrangeRed.Hex3()}:{amount}]"; if (purchaseCost > 0) { var purchaseCostString = currencyConverter.ToString(purchaseCost); var salesTaxString = currencyConverter.ToString(salesTax); player.SendInfoMessage($"Purchasing {commandText} will cost [c/{Color.OrangeRed.Hex3()}:{purchaseCostString}], " + $"with a sales tax of [c/{Color.OrangeRed.Hex3()}:{salesTaxString}]."); } if (shopCommand.RequiredItems.Count > 0) { player.SendInfoMessage(purchaseCost > 0 ? $"{commandText} will also require materials: " : $"{commandText} requires materials: "); player.SendInfoMessage(NpcShop.GetMaterialsCostRenderString(shopCommand, amount)); } player.SendInfoMessage("Do you wish to proceed? Use /yes or /no."); player.AddResponse("yes", args2 => { player.AwaitingResponse.Remove("no"); // var account = SEconomyPlugin.Instance?.GetBankAccount(player); var account = BankingPlugin.Instance.GetBankAccount(player, shopCommand.Currency.InternalName); var totalCost = purchaseCost + salesTax; if (account == null || account.Balance < totalCost) { player.SendErrorMessage($"You do not have enough of a balance to purchase {commandText}."); return; } if (amount > shopCommand.StackSize && shopCommand.StackSize > 0) { player.SendErrorMessage("While waiting, the stock changed."); return; } if (!player.HasSufficientMaterials(shopCommand, amount)) { player.SendErrorMessage($"You do not have sufficient materials to purchase {commandText}."); return; } var worldAccount = BankingPlugin.Instance.GetBankAccount("Server", shopCommand.Currency.InternalName); if (account.TryTransferTo(worldAccount, totalCost)) { //deduct materials from player player.TransferMaterials(shopCommand, amount); if (shopCommand.StackSize > 0) { shopCommand.StackSize -= amount; } //run purchased commands for (var i = 0; i < amount; ++i) { Console.WriteLine(shopCommand.Command.Replace("$name", player.GetEscapedName())); shopCommand.ForceHandleCommand(player); } player.SendSuccessMessage($"Purchased {commandText} for { GetPostPurchaseRenderString(shop, shopCommand, totalCost, amount) }."); } else { player.SendErrorMessage($"Transfer of funds failed for {commandText}."); } //refresh the shop dispay for player, after some time so they can the transaction messages. shop.ShowTo(player, 2000); }); player.AddResponse("no", args2 => { player.AwaitingResponse.Remove("yes"); player.SendInfoMessage("Canceled purchase."); }); } }
public void Update() { NpcShop newShop = getCurrentShop(); if (newShop != CurrentShop) { //we've changed shops somehow, someway CurrentShop = newShop; lastShopState = null; // CurrentShop?.IsOpen; Debug.Print("Changed shop."); } else { //HACK - to ensure shopkeeper tells you hes closed on each click/talk/interaction if (HasShopkeeper && shopKeeperClickedHack) { if (CurrentShop?.IsOpen == false) { SendClosedMessage(CurrentShop); } else { CurrentShop?.ShowTo(player); } shopKeeperClickedHack = false; lastShopState = CurrentShop?.IsOpen; return; } if (CurrentShop == null) { //reset the npc shop if we're out of range if (HasShopkeeper) // && CurrentShop == null ) { CurrentShopkeeperNpcIndex = InvalidNpcIndex; } lastShopState = null; return; } //still in same old shop if (CurrentShop.IsOpen != lastShopState) { if (CurrentShop.IsOpen) { sendOpenMessage(CurrentShop); CurrentShop.ShowTo(player); } else { SendClosedMessage(CurrentShop); } lastShopState = CurrentShop.IsOpen; } } }