Jump to content

[PY]Bulk Update buy/sell prices for items in item_proto.txt


Recommended Posts

M2 Download Center

This is the hidden content, please
( Internal )

The script updates item prices (buy/sell) for an item vnum:

Considering item vnum is 110, it can update till 119 (or starting vnum 112 can go till 115, or 117, or w/e you desire)
It can update for a single vnum (upgrade items, aswell), more in comments below 

Combined with can be pretty efficient

from halo import Halo
import bcolors

class Append_new_prices:
    def __init__(self, value_dict, proto_location):
        self.proto_location = proto_location
        self.protoLst = []
        self.value_dict = value_dict

    def get_proto_asList(self):
        with open(self.proto_location, 'r', encoding="utf8") as file:
            for line in file.readlines():
                lineLst = line.split('\t')
                self.protoLst.append(lineLst)
                self.modified_protoLst = []

    def update_protoLst(self):
        count = 0
        for vnum, prices in self.value_dict.items():
            try:
                upp_range = prices['uppLimit']
            except KeyError:
                upp_range = 1

            vnum_lst = self.get_item_VnumRange(vnum, upp_range)

            # while upp_range >= 0:
            for lineLst in self.protoLst:

                if "buy" not in prices.keys():
                    prices['buy'] = 0

                if "sell" not in prices.keys():
                    prices['sell'] = 0

                # print((lineLst[0]), "  ==  ", vnum_lst)
                try:
                    line_vnum = int(lineLst[0])
                except ValueError:
                    line_vnum = "VNUM NOT INT PFFFFF"

                if line_vnum in vnum_lst:
                    lineLst[9] = prices['buy']
                    lineLst[10] = prices['sell']
                    self.protoLst[self.protoLst.index(lineLst)] = lineLst


    @staticmethod
    def get_item_VnumRange(vnum, range_lim):
        vnum_lst = []
        plus_val = 0
        # if range_lim == 0:
        #     range_lim = 1

        vnum = int(vnum)
        for i in range(0, range_lim + 1):
            vnum += plus_val
            vnum_lst.append(vnum)
            plus_val = 1
        return vnum_lst


    def write_new_proto_fromList(self):
        with open(self.proto_location, 'w', encoding="utf8") as file:
            for line in self.protoLst:
                file.write('\t'.join(self.str_list(line)))

    def str_list(self, lst):
        new_lst = []
        for i in lst:
            new_lst.append(str(i))
        return new_lst


if __name__ == "__main__":

    #First number (110) is the starting vnum, uppLimit is till when to stop adding prices, upplimit 9 means => 110, 111, 112, 113, 114...119
    #It can have h/e many "item" objects as dictionary elements
    #!!!!!Count starts from 0!
    items = \
{
   "110": {
      "buy": 55,
      "sell": 43,
      "uppLimit": 1
   },
   # "120":{
   #    "buy":4000,
   #    "sell":400000,
   #    "uppLimit":9
   # }
}

    setPrices = Append_new_prices(value_dict=items,
                                  proto_location=r'C:\Users\itsas\Desktop\M2\versionControl\DumpProto\Release\item_proto.txt')

    with Halo(text='Loading', spinner='dots'):
        setPrices.get_proto_asList()
        setPrices.update_protoLst()
        setPrices.write_new_proto_fromList()
    print(f'{bcolors.OKMSG}{bcolors.OK} Done!')



Prereq:
Libs: Halo, bcoloros
Python 3.9

  • Metin2 Dev 9
  • Good 6
  • Love 1
  • Love 7
Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.