private static void processArmorPurchase(Player pl, string itemKey) { int armorCount = 0; if (itemKey == ShopItemsInfo.ARMOR_3X) armorCount = 3; else if (itemKey == ShopItemsInfo.ARMOR_5X) armorCount = 5; else if (itemKey == ShopItemsInfo.ARMOR_10X) armorCount = 10; var item = new BuyItemInfo(itemKey); pl.PayVault.Buy(false, new BuyItemInfo[1] {item}, delegate { var items = new BuyItemInfo[armorCount]; for (int i = 0; i < armorCount; i++) { items[i] = new BuyItemInfo(ShopItemsInfo.ARMOR_ITEM); } pl.PayVault.Give(items, delegate { }, delegate(PlayerIOError err) { pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item (2nd step)"); pl.roomLink.handleError(err); }); }, delegate(PlayerIOError err) { pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item (1st step)"); pl.roomLink.handleError(err); }); }
/// <summary> /// SELL ITEM PRICE FOR PLAIN ITEMS IS ITEM.PRICE / 2.5 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void c_ClientBuyItemInfo(object sender, ClientBuyItemEventArgs e) { Client c = (Client)sender; BuyItemInfo i = e.Info; BaseItem buyitem = null; BaseItem npcitem = null; Npc npc = null; try { npc = mapEngine.GetNpcByID(i.NpcID, c.MyCharacter.MapId); npcitem = npc.Bags[i.Bag].Items.Single(x => (x.ReferenceID == i.ReferenceID)); if (c.MyCharacter.Money >= npcitem.Price) { c.MyCharacter.Money -= npcitem.Price; c.Send(PacketManager.SendMoneyLeft(c.MyCharacter.Money)); c.Send(PacketManager.SendBuyItemState(BuyItemState.Success)); BagSlot bagSlot = new BagSlot(); if (!c.MyCharacter.FindFreeSlotInBags(npcitem, bagSlot)) { //Throw exception here } MemoryStream stream = new MemoryStream(); BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, npcitem); stream.Position = 0; buyitem = (BaseItem)formatter.Deserialize(stream); stream.Close(); buyitem.Bag = bagSlot.Bag; buyitem.Slot = bagSlot.Slot; buyitem.OwnerID = c.MyCharacter.CharacterId; buyitem.Amount = i.Amount; buyitem.ItemID = itemDataManager.InsertItem(buyitem); c.MyCharacter.Bags[buyitem.Bag - 1].AddItem(buyitem); c.Send(PacketManager.SendAddItem(buyitem)); } else { c.Send(PacketManager.SendBuyItemState(BuyItemState.NoMoney)); } } catch { } }
private void HandleRecvBuyItem(Packet parsed) { BuyItemInfo i = PacketManager.RecvBuyItem(parsed); if (ClientBuyItemInfo != null) { ClientBuyItemInfo(this, new ClientBuyItemEventArgs(i)); } }
private void AwardWorldRewards(CommonPlayer player, CampaignWorld world, Shop shop) { foreach (var reward in world.Rewards) { switch (reward.Key) { case "maxEnergy": player.MaxEnergy += (int)reward.Value; Console.WriteLine("Rewarded {0} with +{1} maximum energy.", player.Name, reward.Value); break; case "energy": player.AddEnergy((int)reward.Value); Console.WriteLine("Rewarded {0} with +{1} energy.", player.Name, reward.Value); break; case "energyRefill": player.RefillEnergy(); Console.WriteLine("Rewarded {0} with energy refill.", player.Name); break; case "gems": var amount = reward.Value; player.PayVault.Credit(amount, "Completing " + this.Data.Title + " campaign", delegate { Console.WriteLine("Rewarded {0} with {1} gems.", player.Name, amount); }); break; default: var item = shop.GetShopItem(reward.Key); if (item != null && item.Key == reward.Key && (!player.PayVault.Has(item.Key) || item.Reusable)) { var count = item.Reusable ? reward.Value : 1; var items = new BuyItemInfo[count]; for (var i = 0; i < items.Length; i++) { items[i] = new BuyItemInfo(item.Key); } player.PayVault.Give(items, delegate { Console.WriteLine("Rewarded {0} with {1} x{2}.", player.Name, item.Key, count); }); } break; } } }
public void checkIfNewbie(Player player) { if (!player.PlayerObject.Contains(DBProperties.SPELL_OBJECT)) //new guy { double expiresDate = Utils.unixSecs() + GameConfig.SPELL_ACTIVATION_TIME * 60 * 60; if (player.isGuest) expiresDate = Utils.unixSecs() + (60 * 60 * 24 * 365 * 500L); //for 500 years, should be enough; Adding L solves "The operation overflows at compile time in checked mode" problem DatabaseObject spells = new DatabaseObject(); //fill slots DatabaseObject freezeSpell = new DatabaseObject(); freezeSpell.Set(DBProperties.SPELL_SLOT, 1).Set(DBProperties.SPELL_EXPIRES, expiresDate); DatabaseObject splitSpell = new DatabaseObject(); splitSpell.Set(DBProperties.SPELL_SLOT, 2).Set(DBProperties.SPELL_EXPIRES, expiresDate); DatabaseObject lightningSpell = new DatabaseObject(); lightningSpell.Set(DBProperties.SPELL_SLOT, 3).Set(DBProperties.SPELL_EXPIRES, expiresDate); DatabaseObject charmSpell = new DatabaseObject(); charmSpell.Set(DBProperties.SPELL_SLOT, 4).Set(DBProperties.SPELL_EXPIRES, expiresDate); DatabaseObject bouncyShield = new DatabaseObject(); bouncyShield.Set(DBProperties.SPELL_SLOT, 5).Set(DBProperties.SPELL_EXPIRES, expiresDate); spells.Set(Spells.FREEZE, freezeSpell); spells.Set(Spells.SPLIT_IN_TWO, splitSpell); spells.Set(Spells.LIGHTNING_ONE, lightningSpell); spells.Set(Spells.LASER_SHOTS, charmSpell); spells.Set(Spells.BOUNCY_SHIELD, bouncyShield); player.PlayerObject.Set(DBProperties.SPELL_OBJECT, spells); player.PlayerObject.Set(DBProperties.ENERGY, GameConfig.ENERGY_MAX); player.PlayerObject.Set(DBProperties.ENERGY_LAST_UPDATE, Utils.unixSecs()); player.PlayerObject.Set(DBProperties.ENERGY_EXPIRES, (double)0); player.PlayerObject.Set(DBProperties.RANK_NUMBER, 1); player.PlayerObject.Set(DBProperties.RANK_PROGRESS, GameConfig.RANK_PROGRESS_START); player.PlayerObject.Set(DBProperties.BOUNCER_ID, ShopItemsInfo.BOUNCER_STANDART_BLUE); player.PlayerObject.Set(DBProperties.SOUNDS_ON, true); player.PlayerObject.Set(DBProperties.MUSIC_ON, true); player.PlayerObject.Save(); BuyItemInfo bluePanel = new BuyItemInfo(ShopItemsInfo.BOUNCER_STANDART_BLUE); player.PayVault.Give(new BuyItemInfo[1] { bluePanel }, delegate() { }, _roomLink.handleError); player.PayVault.Credit(GameConfig.COINS_START_AMOUNT, "Started playing", delegate() { Console.WriteLine("Player got start coins"); }, handleError); } }
private static void processBouncerPurchase(Player pl, string itemKey) { var item = new BuyItemInfo(itemKey); pl.PayVault.Buy(true, new BuyItemInfo[1] {item}, delegate { Console.WriteLine("Successfully bought " + itemKey); pl.PlayerObject.Set(DBProperties.BOUNCER_ID, itemKey); pl.PlayerObject.Save(); }, delegate(PlayerIOError err) { pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item"); pl.roomLink.handleError(err); }); }
private static void purchaseEnergyTicket(string itemKey, Player pl) { var item = new BuyItemInfo(itemKey); pl.PayVault.Buy(false, new BuyItemInfo[1] {item}, delegate { int days = 1; if (itemKey == ShopItemsInfo.ENERGY_TICKET_3_DAYS) days = 3; else if (itemKey == ShopItemsInfo.ENERGY_TICKET_7_DAYS) days = 7; int ticketLengthInSeconds = days*24*60*1000; pl.PlayerObject.Set(DBProperties.ENERGY, GameConfig.ENERGY_MAX); //set current energy to max (so when ticket experies energy is full) pl.PlayerObject.Set(DBProperties.ENERGY_EXPIRES, Utils.unixSecs() + ticketLengthInSeconds); pl.PlayerObject.Save(); }, delegate(PlayerIOError err) { pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item (1st step)"); pl.roomLink.handleError(err); }); }
private static void processSpellActivation(Player pl, string spellName) { var item = new BuyItemInfo(spellName); bool needActivationBuffer = pl.roomLink.game != null; //user might be activating not during the game if (needActivationBuffer) //user might be activating not during the game pl.roomLink.game.spellChecker.putSpellInActivationBuffer(spellName); //so it is not blocked from usage while transaction is processed pl.PayVault.Buy(false, new BuyItemInfo[1] {item}, //immediately consume items. Instead PlayerObject is updated (for storage convenience) delegate { Console.WriteLine("PayVault ok..."); DatabaseObject spells = pl.getSpellsConfig(); double expiresDate = Utils.unixSecs() + GameConfig.SPELL_ACTIVATION_TIME*60*60; var newSpell = new DatabaseObject(); int prevSlotID = spells.Contains(spellName) ? spells.GetObject(spellName).GetInt(DBProperties.SPELL_SLOT) : -1; //dont lose spell newSpell.Set(DBProperties.SPELL_SLOT, prevSlotID); newSpell.Set(DBProperties.SPELL_EXPIRES, expiresDate); spells.Set(spellName, newSpell); pl.PlayerObject.Save(); pl.sendMessage(MessageTypes.ACTIVATE_SPELL_OK, spellName); //send "ok" back pl.roomLink.statisticsManager.onSpellActivated(spellName); if (needActivationBuffer) //user might be activating not during the game pl.roomLink.game.spellChecker.removeSpellFromActivationBuffer(spellName); //now checks are made as usual foreach (Player play in pl.roomLink.playingUsers) { if (!(play is NPCPlayer)) { play.sendMessage(MessageTypes.ACTIVATE_SPELL_OPPONENT, pl.realID, spellName); } } }, delegate(PlayerIOError err) { if (needActivationBuffer) //user might be activating not during the game pl.roomLink.game.spellChecker.removeSpellFromActivationBuffer(spellName); //now checks are made as usual pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item"); pl.roomLink.handleError(err); }); }
private static void processEnergyPurchase(Player pl, string itemKey) { if (itemKey == ShopItemsInfo.ENERGY_REFILL) { var item = new BuyItemInfo(itemKey); pl.PayVault.Buy(false, new BuyItemInfo[1] {item}, delegate { pl.PlayerObject.Set(DBProperties.ENERGY, GameConfig.ENERGY_MAX); pl.roomLink.playerEnergyTimer.resetLastUpdateTime(); pl.PlayerObject.Save(); }, delegate(PlayerIOError err) { pl.sendMessage(MessageTypes.PURCHASE_FAILED, "Service error at buying item (1st step)"); pl.roomLink.handleError(err); }); } else if (itemKey == ShopItemsInfo.ENERGY_TICKET_1_DAY || itemKey == ShopItemsInfo.ENERGY_TICKET_3_DAYS || itemKey == ShopItemsInfo.ENERGY_TICKET_7_DAYS) { purchaseEnergyTicket(itemKey, pl); } }
public ClientBuyItemEventArgs(BuyItemInfo i) { buyinfo = i; }
public override void Pulse() { if (!_pulseTimer.IsFinished) return; _pulseTimer.Reset(); if (LogoutAtCap && WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints).Amount > 3750 && WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints).Amount > 3750) { Slog("HonorPoints and Justice Points are Capped! Logging out!"); InactivityDetector.ForceLogout(true); } // We should avoid overriding any poi set by the core if (BotPoi.Current.Type != PoiType.None) return; // There are no vendors in battlegrounds or dungeons ! if (Styx.Logic.Battlegrounds.IsInsideBattleground || Me.IsInInstance) return; // First item in the list. We should check item by item so we don't end up buying the last item in the list with lower cost. var firstItem = BuyItemList.FirstOrDefault(); // BuyItemList looks to be empty. Wait for user to populate the list if (firstItem == null) return; // Should check if we have enough currency. var currencyType = Enum.Parse(typeof (WoWCurrencyType), firstItem.ItemCostType); // Something went wrong with parsing. We should avoid buying that item. if (!(currencyType is WoWCurrencyType)) { Slog("Couldn't parse item's cost type ({0}). Please consult to the plugin writer", firstItem.ItemCostType); BuyItemList.Remove(firstItem); return; } // Actually checking if we have enough of that currency now. var currency = WoWCurrency.GetCurrencyByType((WoWCurrencyType)currencyType); var currencyJp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints); var currencyHp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints); if (currency == null) return; if (currency.Amount < firstItem.ItemCost) { // Don't ever buy justice points to buy honor points and vice versa. Otherwise we will enter in an endless loop which will drop // the total of our points. if (firstItem.ItemId != 392 && firstItem.ItemId != 395 && BuyOppositePointToBuildUp) { if (currency.CurrencyType == WoWCurrencyType.JusticePoints && currencyHp.Amount >= 375) { // We set this to true here. So we don't end up spending all our honor points if the Only remove hp/jp points when capped is true _forceAddedPoints = true; if (Me.IsAlliance) { var buyJusticePoint = new BuyItemInfo { ItemCost = 375, ItemName = "Justice Points", ItemSupplierId = 52029, ItemId = 395, ItemCostType = WoWCurrencyType.HonorPoints.ToString() }; Slog( "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyJusticePoint); } if (Me.IsHorde) { var buyJusticePoint = new BuyItemInfo { ItemCost = 375, ItemName = "Justice Points", ItemSupplierId = 52033, ItemId = 395, ItemCostType = WoWCurrencyType.HonorPoints.ToString() }; Slog( "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyJusticePoint); } } if (currency.CurrencyType == WoWCurrencyType.HonorPoints && currencyJp.Amount >= 375) { // We set this to true here. So we don't end up spending all our justice points if the Only remove hp/jp points when capped is true _forceAddedPoints = true; if (Me.IsAlliance) { var buyHonorPoint = new BuyItemInfo { ItemCost = 375, ItemName = "Honor Points", ItemSupplierId = 52028, ItemId = 392, ItemCostType = WoWCurrencyType.JusticePoints.ToString() }; Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyHonorPoint); } if (Me.IsHorde) { var buyHonorPoint = new BuyItemInfo { ItemCost = 375, ItemName = "Honor Points", ItemSupplierId = 52034, ItemId = 392, ItemCostType = WoWCurrencyType.JusticePoints.ToString() }; Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyHonorPoint); } } } return; } // We need to find the vendor var vendorAsUnit = ObjectManager.GetObjectsOfType<WoWUnit>(false, false).FirstOrDefault( u => u.Entry == firstItem.ItemSupplierId); Vendor vendor; // Vendor is not around. This won't work if (vendorAsUnit == null) { // Check the database for the vendor as a second hope NpcResult npc = NpcQueries.GetNpcById(firstItem.ItemSupplierId); if (npc != null) { vendor = new Vendor(npc.Entry, npc.Name, Vendor.VendorType.Unknown, npc.Location); } else { Slog("Please move your toon close to the vendor. Otherwise HonorCap won't be able to buy items."); return; } } else { vendor = new Vendor(vendorAsUnit, Vendor.VendorType.Unknown); } // Setting ItemToBuy here so VendorBehavior knows which item we want. ItemToBuy = firstItem; //We need to make sure vender is usable, so removing blacklist. if (Blacklist.Contains(vendorAsUnit)) { Slog("For whatever reason vender is blacklisted, Clearing Blacklist."); Blacklist.Flush(); } // Finally setting the poi BotPoi.Current = new BotPoi(vendor, PoiType.Buy); }
public override void Pulse() { if (!_pulseTimer.IsFinished) { return; } _pulseTimer.Reset(); if (LogoutAtCap && WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints).Amount > 3750 && WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints).Amount > 3750) { Slog("HonorPoints and Justice Points are Capped! Logging out!"); InactivityDetector.ForceLogout(true); } // We should avoid overriding any poi set by the core if (BotPoi.Current.Type != PoiType.None) { return; } // There are no vendors in battlegrounds or dungeons ! if (Styx.Logic.Battlegrounds.IsInsideBattleground || Me.IsInInstance) { return; } // First item in the list. We should check item by item so we don't end up buying the last item in the list with lower cost. var firstItem = BuyItemList.FirstOrDefault(); // BuyItemList looks to be empty. Wait for user to populate the list if (firstItem == null) { return; } // Should check if we have enough currency. var currencyType = Enum.Parse(typeof(WoWCurrencyType), firstItem.ItemCostType); // Something went wrong with parsing. We should avoid buying that item. if (!(currencyType is WoWCurrencyType)) { Slog("Couldn't parse item's cost type ({0}). Please consult to the plugin writer", firstItem.ItemCostType); BuyItemList.Remove(firstItem); return; } // Actually checking if we have enough of that currency now. var currency = WoWCurrency.GetCurrencyByType((WoWCurrencyType)currencyType); var currencyJp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.JusticePoints); var currencyHp = WoWCurrency.GetCurrencyByType(WoWCurrencyType.HonorPoints); if (currency == null) { return; } if (currency.Amount < firstItem.ItemCost) { // Don't ever buy justice points to buy honor points and vice versa. Otherwise we will enter in an endless loop which will drop // the total of our points. if (firstItem.ItemId != 392 && firstItem.ItemId != 395 && BuyOppositePointToBuildUp) { if (currency.CurrencyType == WoWCurrencyType.JusticePoints && currencyHp.Amount >= 375) { // We set this to true here. So we don't end up spending all our honor points if the Only remove hp/jp points when capped is true _forceAddedPoints = true; if (Me.IsAlliance) { var buyJusticePoint = new BuyItemInfo { ItemCost = 375, ItemName = "Justice Points", ItemSupplierId = 52029, ItemId = 395, ItemCostType = WoWCurrencyType.HonorPoints.ToString() }; Slog( "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyJusticePoint); } if (Me.IsHorde) { var buyJusticePoint = new BuyItemInfo { ItemCost = 375, ItemName = "Justice Points", ItemSupplierId = 52033, ItemId = 395, ItemCostType = WoWCurrencyType.HonorPoints.ToString() }; Slog( "Adding Justice Point to the Buy List so we can build up Justice Points to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyJusticePoint); } } if (currency.CurrencyType == WoWCurrencyType.HonorPoints && currencyJp.Amount >= 375) { // We set this to true here. So we don't end up spending all our justice points if the Only remove hp/jp points when capped is true _forceAddedPoints = true; if (Me.IsAlliance) { var buyHonorPoint = new BuyItemInfo { ItemCost = 375, ItemName = "Honor Points", ItemSupplierId = 52028, ItemId = 392, ItemCostType = WoWCurrencyType.JusticePoints.ToString() }; Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyHonorPoint); } if (Me.IsHorde) { var buyHonorPoint = new BuyItemInfo { ItemCost = 375, ItemName = "Honor Points", ItemSupplierId = 52034, ItemId = 392, ItemCostType = WoWCurrencyType.JusticePoints.ToString() }; Slog("Adding HonorPoint to the Buy List so we can build up HonorPoints to buy {0}.", firstItem.ItemName); BuyItemList.Insert(0, buyHonorPoint); } } } return; } // We need to find the vendor var vendorAsUnit = ObjectManager.GetObjectsOfType <WoWUnit>(false, false).FirstOrDefault( u => u.Entry == firstItem.ItemSupplierId); Vendor vendor; // Vendor is not around. This won't work if (vendorAsUnit == null) { // Check the database for the vendor as a second hope NpcResult npc = NpcQueries.GetNpcById(firstItem.ItemSupplierId); if (npc != null) { vendor = new Vendor(npc.Entry, npc.Name, Vendor.VendorType.Unknown, npc.Location); } else { Slog("Please move your toon close to the vendor. Otherwise HonorCap won't be able to buy items."); return; } } else { vendor = new Vendor(vendorAsUnit, Vendor.VendorType.Unknown); } // Setting ItemToBuy here so VendorBehavior knows which item we want. ItemToBuy = firstItem; //We need to make sure vender is usable, so removing blacklist. if (Blacklist.Contains(vendorAsUnit)) { Slog("For whatever reason vender is blacklisted, Clearing Blacklist."); Blacklist.Flush(); } // Finally setting the poi BotPoi.Current = new BotPoi(vendor, PoiType.Buy); }