Advertisement
Guest User

marketplace.py

a guest
Aug 6th, 2018
2,636
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 14.44 KB | None | 0 0
  1. I saw someone asking about this in a thread so I thought I'd share what I did to make it work.
  2.  
  3.  
  4. 1. Install windows python and pymongo (I don't remember if pymongo comes with it)
  5.  
  6. 2. Run this script:
  7. [quote]
  8.  
  9. import pymongo
  10. from pymongo import MongoClient
  11. from pprint import pprint
  12. from bson.int64 import Int64
  13. import copy
  14.  
  15. class Marketplace:
  16.  
  17.     item_data = {
  18.         # weapons: index0 is used for price
  19.         "weapons" : [
  20.             [ 200000, 10413, 10613, 13313, 11213, 11363, 10213, 10013, 13213, 14413 ], # Bares
  21.             [ 200000, 10403, 10603, 13303, 11203, 11353, 10203, 10003, 13203, 14403 ], # Elsh
  22.             [ 120000, 10406, 10606, 13306, 11206, 11356, 10206, 10006, 13206, 14406 ], # Ain
  23.             [ 120000, 10405, 10605, 13305, 11205, 11355, 10205, 10005, 13205, 14405 ], # Azwell
  24.             [ 140000, 10471, 10671, 13371, 11222, 11372, 10271, 10071, 13271, 14471 ], # Styd
  25.             [ 150000, 10414, 10614, 13314, 11214, 11364, 10214, 10014, 13214, 14414 ], # Yuria
  26.             [ 150000, 10407, 10607, 13307, 11207, 11357, 10207, 10007, 13207, 14407 ], # Seleth
  27.             [ 200000, 10412, 10612, 13312, 11212, 11362, 10212, 10012, 13212, 14412 ], # Kalis
  28.             [ 250000, 10456, 10656, 13356, 11220, 11370, 10256, 10056, 13256, 14456 ], # Krea
  29.             [ 300000, 10457, 10657, 13357, 11221, 11371, 10257, 10057, 13257, 14457 ], # Rosar
  30.             [ 9000000, 10409, 10609, 13309, 11209, 11359, 10209, 10009, 13209, 14409 ], # Liverto
  31.             [ 90000000, 10410, 10610, 13310, 11210, 11360, 10210, 10010, 13210, 14410 ], # Kzarka
  32.             # Secondaries
  33.             #[ 10000, 10301, 13001, 10101, 10501, 10701, 13101, 14501, 14601, 11301 ], # t1
  34.             #[ 60000, 10302, 13002, 10104, 10502, 10702, 13102, 14502, 14602, 11302 ], # t2
  35.             [ 60000, 10303, 13003, 10102, 10503, 10705, 13104, 14503, 14603, 11303 ], # t3
  36.             [ 200000, 10304, 13004, 10103, 10504, 10704, 13103, 14504, 14604, 11304 ], # t4
  37.             [ 250000, 10305, 13005, 10105, 10505, 10703, 13105, 14505, 14605, 11305 ], # t5
  38.             [ 350000, 10324, 13024, 10124, 10724, 10524, 13124, 14524, 14624, 11324 ], # t6
  39.             [ 400000, 10325, 13025, 10125, 10525, 10725, 13125, 14525, 14625, 11325 ], # t7
  40.             [ 80000000, 10340, 13140, 14540, 10740, 10140, 14640, 10540, 13040, 11340 ], # t8 kutum
  41.             [ 90000000, 13038, 10338, 13138, 14538, 10738, 10138, 10138, 14638, 10538, 11338 ], # t9 nouver
  42.            
  43.             # Awakened
  44.             [ 90000000, 14802, 14742, 14762, 14822, 14812, 14702, 14722, 14732, 14772, 14752, 14792, 14712, 14782, 14817 ], # dandelion
  45.            
  46.             # Misusing the weapon structure here for non-stacking misc items
  47.             # because they are processed in the same way.
  48.             # Magic Crystals:
  49.             [ 5000, 15034, 15035, 15036, 15037, 15038, 15039, 15040, 15041, 15042, 15043, 15044, 15045 ], # white
  50.             [ 5000, 15001, 15002, 15003, 15004, 15005, 15006, 15007, 15008, 15009, 15010, 15011, 15012, 15013, 15014, 15015, 15016, 15017, 15018, 15019, 15020, 15027, 15028, 15029, 15030, 15031, 15033 ], # green
  51.             [ 250000, 15101, 15102, 15103, 15104, 15105, 15106, 15107, 15108, 15109, 15110, 15111, 15112, 15113, 15114, 15115, 15116, 15117, 15118, 15119, 15120, 15121, 15122, 15123, 15124, 15125, 15126, 15127, 15128, 15129, 15130, 15131, 15132, 15133, 15134, 15135, 15136, 15137, 15138, 15139, 15146, 15147, 15148, 15149, 15150, 15151, 15152, 15153, 15154 ], # blue
  52.             [ 1600000, 15021, 15022, 15023, 15024, 15025, 15026, 15032, 15201, 15202, 15203, 15204, 15205, 15206, 15207, 15208, 15209, 15210, 15211, 15212, 15213, 15214, 15215, 15216, 15217, 15218, 15219, 15220, 15221, 15222, 15223, 15224, 15606, 15607, 15608, 15609, 15610, 15611, 15612, 15613, 15614, 15615, 15616, 15617, 15618, 15619, 15620, 15621, 15622, 15623, 15624, 15625 ], # yellow
  53.             [ 15000000, 15501, 15502, 15503, 15504, 15505, 15601, 15602, 15603, 15604, 15605, 15606, 15626, 15627, 15628, 15629, 15630, 15631, 15632, 15633, 15634, 15635, 15636, 15637, 15638, 15639, 15640, 15649, 15650, 15651 ], # orange
  54.            
  55.            
  56.            
  57.             # Summon Items        15226,
  58.             [ 100000, 40220 ], # Forbidden Book
  59.             [ 200000, 40218 ], # Ancient Relic Crystal shard
  60.             [ 250000, 40228 ], # Scroll written in ancient language
  61.            
  62.             ### Useful consumables ###
  63.             # Purified Water, Star Anise Tea
  64.             [ 1000, 6656, 9306 ],
  65.  
  66.             # Dim Tree Armor, Red Nose Armor, Giath Hat, Muskan Shoe, Bheg Glove
  67.             [ 100000000, 11017, 11014, 11013, 11016, 11015 ],
  68.            
  69.             ## Crafting ##
  70.             [ 50000, 44195 ], # Memory Fragment
  71.             [ 100000, 4911, 4910 ], # grade 3 reform stones
  72.             [ 100000, 16001, 16002 ], # Black stones
  73.             [ 10000000, 16004, 16005 ], # Concentrated Black stones
  74.  
  75.             # Accessories
  76.    
  77.             # Riddell Earring
  78.             [ 900000, 11811 ],
  79.            
  80.             # Shrine Guardian Token, Outlaw's Ring
  81.             [ 1500000, 12008, 12012 ],
  82.            
  83.             # Blue Coral Ring, Blue Coral Earring, Ancient Weapon Core, Red Coral Ring, Scarla Necklace
  84.             [ 4500000, 12017, 11816, 12220, 12018, 11610 ],
  85.            
  86.             # Belt of Shultz
  87.             [ 7000000, 12211 ],
  88.    
  89.             # Necklace of Shultz, Red Coral Earring, Witch's Earring, Fugitive Khalk's Earring, Mark of Shadow
  90.             [ 12000000, 11631, 11817, 11808, 11827, 12007 ],
  91.            
  92.             # Ancient Guardian's Seal
  93.             [ 18000000, 11613 ],
  94.            
  95.             # Tree Spirit Belt
  96.             [ 35000000, 12210 ],
  97.            
  98.             # Blue Whale Molar Earring
  99.             [ 40000000, 11815 ],
  100.            
  101.             # Ring of Cadry Guardian, Ring of Crescent Guardian, Serap's Necklace
  102.             [ 45000000, 12032, 12031, 11628 ],
  103.            
  104.             # Sicil's Necklace
  105.             [ 55000000, 11625 ],
  106.    
  107.             # Basilisk's Belt
  108.             [ 70000000, 12230 ],
  109.            
  110.             # Tungrad Earring, Ogre Ring, Laytenn's Power Stone
  111.             [ 90000000, 11828, 11607, 11630 ],
  112.            
  113.             # Tungrad Necklace
  114.             [ 120000000, 11629 ],
  115.            
  116.         ],
  117.         # armor has a feature where chests are more expensive than other parts
  118.         "armor" : [ # price, hatID, chestID, gloveID, shoeID
  119.             [ 100000, 10813, 10814, 10815, 10816 ], # Taritas
  120.             [ 100000, 10821, 10822, 10823, 10824 ], # Talis
  121.             [ 250000, 10809, 10810, 10811, 10812 ], # Agerian
  122.             [ 330000, 11005, 11006, 11007, 11008 ], # Strength of Heve
  123.             [ 320000, 11001, 11002, 11003, 11004 ], # Hercules Might
  124.             [ 330000, 11009, 11010, 11011, 11012 ], # Luck Fortuna
  125.             [ 340000, 10817, 10818, 10819, 10820 ], # Zereth
  126.             [ 350000, 10933, 10934, 10935, 10936 ], # grunil
  127.             [ 200000, 10937, 10938, 10939, 10940 ], # Rocaba
  128.         ],
  129.        
  130.         # other have price as index0 and quantity as index 1
  131.         "other" : [
  132.             [ 100000, 9999, 16001, 16002 ], # Black stones
  133.             [ 10000000, 999, 16004, 16005 ], # Concentrated Black stones
  134.            
  135.         ]
  136.     }
  137.  
  138.     base_item = {
  139.         "_id":Int64(10000002000000002),
  140.         "accountId": 2,
  141.         "marketRegistredDate": 1531821851,
  142.         "marketExpirationDate": 1832426651,
  143.         "revenue":0,
  144.         "totalCount":9999999,
  145.         "price":33333,
  146.         "territoryKey":0,
  147.         "item":{
  148.             "objectId": -1,
  149.             "itemId":10813,
  150.             "regionId":1,
  151.             "enchantLevel":0,
  152.             "count":9999,
  153.             "endurance":100,
  154.             "maxEndurance":100,
  155.             "expirationPeriod":-1,
  156.             "isVested":False,
  157.             "price":33333,
  158.             "alchemyStoneExp":0,
  159.             "colorPaletteType":0,
  160.             "jewels":[],
  161.             "colorPalettes":[]
  162.         }
  163.     }
  164.  
  165.     base_master = {
  166.         "_id":Int64(10000002000000002),
  167.         "itemId":10813,
  168.         "itemEnchantLevel":0,
  169.         "itemMinPrice":100,
  170.         "itemMaxPrice":Int64(100000000000),
  171.         "marketSoldCount":0,
  172.         "marketMinPrice":100,
  173.         "marketMaxPrice":Int64(100000000000),
  174.         "marketPrice":33333
  175.     }
  176.  
  177.     def __init__(self):
  178.         # Account ID in mongo account collection of the user who is
  179.         # "selling" everything that we are putting on the market. To create
  180.         # an account for this modify the Start64.bat to change the
  181.         # credentials and the change back to launch your main account.
  182.         self.account_id = 2
  183.                
  184.         self.current_key = 0
  185.         self.market_items = []
  186.         self.master_items = []
  187.    
  188.     def collectionsAreEmpty(self, db):
  189.         gs = db["gameserver"]
  190.         if "itemMarket" in gs.collection_names():
  191.             if gs["itemMarket"].count() > 0:
  192.                 gs["itemMarket"].drop()
  193.                 gs["itemMarket"].remove()
  194.                
  195.             if gs["itemMarket"].count() > 0:
  196.                 raise EnvironmentError("Script was unable to create an empty collection. You need to manually delete itemMarket and itemMarketMaster collections to run this script.")
  197.    
  198.         if "itemMarketMaster" in gs.collection_names():
  199.             if gs["itemMarketMaster"].count() > 0:
  200.                 gs["itemMarketMaster"].drop()
  201.                 gs["itemMarketMaster"].remove()
  202.        
  203.    
  204.     def populate(self):
  205.         # if collections do not exist, create them
  206.         # if that fails, error out
  207.         # if collections exist and are empty, proceed
  208.         # if collections exist and are not empty, drop them
  209.         # if collections still exist and are not empty, error out
  210.  
  211.         try:
  212.             db = MongoClient("localhost", 27017)
  213.             gameserver = db["gameserver"]
  214.  
  215.             self.collectionsAreEmpty(db)
  216.            
  217.             self.col_item_market = gameserver.itemMarket
  218.             self.col_master_item_market = db["gameserver"].masterItemMarket
  219.  
  220.             self.buildArmor()
  221.             self.buildWeapons()
  222.             self.buildOther()
  223.             self.send_item_market()
  224.             self.send_item_master()          
  225.             print("If you don't see any error messages, it probably worked")
  226.            
  227.         except EnvironmentError as e:
  228.             print (e.args)
  229.    
  230.     def getNewId(self):
  231.         self.current_key = self.current_key + 1
  232.         return Int64(1000000200000) + self.current_key  
  233.  
  234.     def addDupes(self, item_record, num_dupes):
  235.         for c in range(0, num_dupes):
  236.             new_clone_item = copy.deepcopy(item_record)
  237.             new_clone_item["_id"] = self.getNewId()
  238.             self.market_items.append(new_clone_item)  
  239.  
  240.     def buildArmor(self):
  241.         for idx in range(len(self.item_data["armor"])):
  242.             armor_set = self.item_data["armor"][idx]
  243.             price = armor_set[0]
  244.             armor_set.pop(0)
  245.            
  246.             for idx2 in range(len(armor_set)):
  247.                 new_item = copy.deepcopy(self.base_item)
  248.                 new_item["_id"] = self.getNewId()
  249.                 new_item["price"] = price
  250.                 new_item["item"]["price"] = price
  251.                 new_item["item"]["itemId"] = armor_set[idx2]
  252.                 self.market_items.append(new_item)
  253.                 #self.addDupes(new_item, 10)
  254.                
  255.                 new_master = copy.deepcopy(self.base_master)
  256.                 new_master["_id"] = new_item["_id"]
  257.                 new_master["itemId"] = armor_set[idx2]
  258.                 new_master["marketPrice"] = price
  259.                 self.master_items.append(new_master)
  260.        
  261.     def buildWeapons(self):
  262.         for idx in range(len(self.item_data["weapons"])):
  263.             weapon_set = self.item_data["weapons"][idx]
  264.             price = weapon_set[0]
  265.             weapon_set.pop(0)
  266.            
  267.             for idx2 in range(len(weapon_set)):
  268.                 new_item = copy.deepcopy(self.base_item)
  269.                 new_item["_id"] = self.getNewId()
  270.                 new_item["price"] = price
  271.                 new_item["item"]["price"] = price
  272.                 new_item["item"]["itemId"] = weapon_set[idx2]
  273.                 self.market_items.append(new_item)
  274.                 #self.addDupes(new_item, 10)          
  275.            
  276.                 new_master = copy.deepcopy(self.base_master)
  277.                 new_master["_id"] = new_item["_id"]
  278.                 new_master["itemId"] = weapon_set[idx2]
  279.                 new_master["marketPrice"] = price
  280.                 self.master_items.append(new_master)
  281.        
  282.     def buildOther(self):
  283.         pass
  284.        
  285.     def send_item_market(self):
  286.         for idx in range(len(self.market_items)):
  287.             result = self.col_item_market.insert_one(self.market_items[idx])
  288.             if not result.acknowledged:
  289.                 pprint(market_items[idx])
  290.                 raise ConnectionError("Insert failed")
  291.  
  292.     def send_item_master(self):
  293.         for idx in range(len(self.master_items)):
  294.             result = self.col_master_item_market.insert_one(self.master_items[idx])
  295.             if not result.acknowledged:
  296.                 pprint(master_items[idx])
  297.                 raise ConnectionError("Insert failed")
  298.  
  299. if __name__ == "__main__":
  300.     mrkt = Marketplace()
  301.     mrkt.populate()
  302. [/quote]
  303.  
  304.  
  305. This will populate the market with most of the weapon, armor and accessory sets in the game. Note that even though there is code to drop the mongo collections before the script runs, it doesn't seem to work.
  306.  
  307. You should only ever need to run this once, but if you want to tweak the script to add more items or whatever, you will probably need to manually delete itemMarket and itemMarketMaster collections from mongo's gameserver database. I included code in the script to do this but it fails silently, I'm not sure why, and I'm not too interested in polishing this little one-off any further.
  308.  
  309. BTW, part of the reason I use this is because I have made some SQLite queries which remove all non-stacking items from mob loot tables. So I needed another way to make these items available. I did this because I pumped up the item drop rate on my server and non stacking items quickly became a massive inventory nuisance. By replacing things like weapons and armor with stacking things like ores and feathers, you can still build currency from grinding without a big management hassle. If anyone wants the queries I used to do this, let me know and I'll share them.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement