| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487 |
- using ClientPackets;
- using Server.Library.MirDatabase;
- using Server.Library.Utils;
- using Server.MirDatabase;
- using Server.MirNetwork;
- using Server.MirObjects;
- using Server.MirObjects.Monsters;
- using System.Collections.Concurrent;
- using System.Diagnostics;
- using System.Net;
- using System.Net.Sockets;
- using System.Numerics;
- using System.Text.RegularExpressions;
- using S = ServerPackets;
- namespace Server.MirEnvir
- {
- public class MobThread
- {
- public int Id = 0;
- public long LastRunTime = 0;
- public long StartTime = 0;
- public long EndTime = 0;
- public LinkedList<MapObject> ObjectsList = new LinkedList<MapObject>();
- public LinkedListNode<MapObject> _current = null;
- public bool Stop = false;
- }
- public class RandomProvider
- {
- private static int seed = Environment.TickCount;
- private static readonly ThreadLocal<Random> RandomWrapper = new ThreadLocal<Random>(() => new Random(Interlocked.Increment(ref seed)));
- public static Random GetThreadRandom() =>
- RandomWrapper.Value;
- public int Next() =>
- RandomWrapper.Value.Next();
- public int Next(int maxValue) =>
- RandomWrapper.Value.Next(maxValue);
- public int Next(int minValue, int maxValue) =>
- RandomWrapper.Value.Next(minValue, maxValue);
- }
- public class Envir
- {
- public static Envir Main { get; } = new Envir();
- public static Envir Edit { get; } = new Envir();
- protected static MessageQueue MessageQueue => MessageQueue.Instance;
- public static object AccountLock = new object();
- public static object LoadLock = new object();
- public const int MinVersion = 60;
- public const int Version = 117;
- public const int CustomVersion = 0;
- public static readonly string DatabasePath = Path.Combine(".", "Server.MirDB");
- public static readonly string AccountPath = Path.Combine(".", "Server.MirADB");
- public static readonly string BackUpPath = Path.Combine(".", "Back Up");
- public static readonly string AccountsBackUpPath = Path.Combine(".", "Back Up", "Accounts");
- public static readonly string DatabaseBackUpPath = Path.Combine(".", "Back Up", "Database");
- public static readonly string ArchivePath = Path.Combine(".", "Archive");
- public bool ResetGS = false;
- public bool GuildRefreshNeeded;
- private static readonly Regex AccountIDReg, PasswordReg, EMailReg, CharacterReg;
- public static int LoadVersion;
- public static int LoadCustomVersion;
- private readonly DateTime _startTime = DateTime.UtcNow;
- public readonly Stopwatch Stopwatch = Stopwatch.StartNew();
- public long Time { get; private set; }
- public RespawnTimer RespawnTick = new RespawnTimer();
- private static List<string> DisabledCharNames = new List<string>();
- private static List<string> LineMessages = new List<string>();
- public static ConcurrentDictionary<string, DateTime> IPBlocks = new ConcurrentDictionary<string, DateTime>();
- public static ConcurrentDictionary<string, MirConnectionLog> ConnectionLogs = new ConcurrentDictionary<string, MirConnectionLog>();
- public DateTime Now =>
- _startTime.AddMilliseconds(Time);
- public bool Running { get; private set; }
- private static uint _objectID;
- public uint ObjectID => ++_objectID;
- public static int _playerCount;
- public int PlayerCount => Players.Count;
- public int[] OnlineRankingCount = new int[6];
- public int HeroCount => Heroes.Count;
- public RandomProvider Random = new RandomProvider();
- private Thread _thread;
- private TcpListener _listener;
- private bool StatusPortEnabled = true;
- public List<MirStatusConnection> StatusConnections = new List<MirStatusConnection>();
- private TcpListener _StatusPort;
- private int _sessionID;
- public List<MirConnection> Connections = new List<MirConnection>();
- //Server DB
- public int MapIndex, ItemIndex, MonsterIndex, NPCIndex, QuestIndex, GameshopIndex, ConquestIndex, RespawnIndex, ScriptIndex;
- public List<MapInfo> MapInfoList = new List<MapInfo>();
- public List<ItemInfo> ItemInfoList = new List<ItemInfo>();
- public List<MonsterInfo> MonsterInfoList = new List<MonsterInfo>();
- public List<MagicInfo> MagicInfoList = new List<MagicInfo>();
- public List<NPCInfo> NPCInfoList = new List<NPCInfo>();
- public DragonInfo DragonInfo = new DragonInfo();
- public List<QuestInfo> QuestInfoList = new List<QuestInfo>();
- public List<GameShopItem> GameShopList = new List<GameShopItem>();
- public List<RecipeInfo> RecipeInfoList = new List<RecipeInfo>();
- public List<BuffInfo> BuffInfoList = new List<BuffInfo>();
- public List<ConquestInfo> ConquestInfoList = new List<ConquestInfo>();
- public List<GTMap> GTMapList = new List<GTMap>();
- //User DB
- public int NextAccountID, NextCharacterID, NextGuildID, NextHeroID;
- public ulong NextUserItemID, NextAuctionID, NextMailID, NextRecipeID;
- public List<AccountInfo> AccountList = new List<AccountInfo>();
- public List<CharacterInfo> CharacterList = new List<CharacterInfo>();
- public List<GuildInfo> GuildList = new List<GuildInfo>();
- public LinkedList<AuctionInfo> Auctions = new LinkedList<AuctionInfo>();
- public List<ConquestGuildInfo> ConquestList = new List<ConquestGuildInfo>();
- public Dictionary<int, int> GameshopLog = new Dictionary<int, int>();
- public List<HeroInfo> HeroList = new List<HeroInfo>();
- public int GuildCount; //This shouldn't be needed?? -> remove in the future
- //Live Info
- public bool Saving = false;
- public List<Map> MapList = new List<Map>();
- public List<SafeZoneInfo> StartPoints = new List<SafeZoneInfo>();
- public List<ItemInfo> StartItems = new List<ItemInfo>();
- public List<PlayerObject> Players = new List<PlayerObject>();
- public List<SpellObject> Spells = new List<SpellObject>();
- public List<NPCObject> NPCs = new List<NPCObject>();
- public List<GuildObject> Guilds = new List<GuildObject>();
- public List<ConquestObject> Conquests = new List<ConquestObject>();
- public List<HeroObject> Heroes = new List<HeroObject>();
- public LightSetting Lights;
- public LinkedList<MapObject> Objects = new LinkedList<MapObject>();
- public Dictionary<int, NPCScript> Scripts = new Dictionary<int, NPCScript>();
- public Dictionary<string, Timer> Timers = new Dictionary<string, Timer>();
- //multithread vars
- readonly object _locker = new object();
- public MobThread[] MobThreads = new MobThread[Settings.ThreadLimit];
- private readonly Thread[] MobThreading = new Thread[Settings.ThreadLimit];
- public int SpawnMultiplier = 1;//set this to 2 if you want double spawns (warning this can easily lag your server far beyond what you imagine)
- public List<string> CustomCommands = new List<string>();
- public Dragon DragonSystem;
- public NPCScript DefaultNPC, MonsterNPC, RobotNPC;
- public List<DropInfo> FishingDrops = new List<DropInfo>();
- public List<DropInfo> AwakeningDrops = new List<DropInfo>();
- public List<DropInfo> StrongboxDrops = new List<DropInfo>();
- public List<DropInfo> BlackstoneDrops = new List<DropInfo>();
- public List<GuildAtWar> GuildsAtWar = new List<GuildAtWar>();
- public List<MapRespawn> SavedSpawns = new List<MapRespawn>();
- public List<RankCharacterInfo> RankTop = new List<RankCharacterInfo>();
- public List<RankCharacterInfo>[] RankClass = new List<RankCharacterInfo>[5];
- static HttpServer http;
- static Envir()
- {
- AccountIDReg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinAccountIDLength + "," + Globals.MaxAccountIDLength + "}$");
- PasswordReg = new Regex(@"^[A-Za-z0-9]{" + Globals.MinPasswordLength + "," + Globals.MaxPasswordLength + "}$");
- EMailReg = new Regex(@"\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
- CharacterReg = new Regex(@"^[\u4e00-\u9fa5_A-Za-z0-9]{" + Globals.MinCharacterNameLength + "," + Globals.MaxCharacterNameLength + "}$");
- }
- public static bool IsPasswordValid(string password)
- {
- if (string.IsNullOrEmpty(password)) return false;
- return PasswordReg.IsMatch(password);
- }
- public static int LastCount = 0, LastRealCount = 0;
- public static long LastRunTime = 0;
- public int MonsterCount;
- private long warTime, guildTime, conquestTime, rentalItemsTime, auctionTime, spawnTime, robotTime, timerTime;
- private int dailyTime = DateTime.UtcNow.Day;
- private bool MagicExists(Spell spell)
- {
- for (var i = 0; i < MagicInfoList.Count; i++)
- {
- if (MagicInfoList[i].Spell == spell) return true;
- }
- return false;
- }
- private void UpdateMagicInfo()
- {
- for (var i = 0; i < MagicInfoList.Count; i++)
- {
- switch (MagicInfoList[i].Spell)
- {
- //warrior
- case Spell.Thrusting:
- MagicInfoList[i].MultiplierBase = 0.25f;
- MagicInfoList[i].MultiplierBonus = 0.25f;
- break;
- case Spell.HalfMoon:
- MagicInfoList[i].MultiplierBase = 0.3f;
- MagicInfoList[i].MultiplierBonus = 0.1f;
- break;
- case Spell.ShoulderDash:
- MagicInfoList[i].MPowerBase = 4;
- break;
- case Spell.TwinDrakeBlade:
- MagicInfoList[i].MultiplierBase = 0.8f;
- MagicInfoList[i].MultiplierBonus = 0.1f;
- break;
- case Spell.FlamingSword:
- MagicInfoList[i].MultiplierBase = 1.4f;
- MagicInfoList[i].MultiplierBonus = 0.4f;
- break;
- case Spell.CrossHalfMoon:
- MagicInfoList[i].MultiplierBase = 0.4f;
- MagicInfoList[i].MultiplierBonus = 0.1f;
- break;
- case Spell.BladeAvalanche:
- MagicInfoList[i].MultiplierBase = 1f;
- MagicInfoList[i].MultiplierBonus = 0.4f;
- break;
- case Spell.SlashingBurst:
- MagicInfoList[i].MultiplierBase = 3.25f;
- MagicInfoList[i].MultiplierBonus = 0.25f;
- break;
- //wiz
- case Spell.Repulsion:
- MagicInfoList[i].MPowerBase = 4;
- break;
- //tao
- case Spell.Poisoning:
- MagicInfoList[i].MPowerBase = 0;
- break;
- case Spell.Curse:
- MagicInfoList[i].MPowerBase = 20;
- break;
- case Spell.Plague:
- MagicInfoList[i].MPowerBase = 0;
- MagicInfoList[i].PowerBase = 0;
- break;
- //sin
- case Spell.FatalSword:
- MagicInfoList[i].MPowerBase = 20;
- break;
- case Spell.DoubleSlash:
- MagicInfoList[i].MultiplierBase = 0.8f;
- MagicInfoList[i].MultiplierBonus = 0.1f;
- break;
- case Spell.FireBurst:
- MagicInfoList[i].MPowerBase = 4;
- break;
- case Spell.MoonLight:
- MagicInfoList[i].MPowerBase = 20;
- break;
- case Spell.DarkBody:
- MagicInfoList[i].MPowerBase = 20;
- break;
- case Spell.Hemorrhage:
- MagicInfoList[i].MultiplierBase = 0.2f;
- MagicInfoList[i].MultiplierBonus = 0.05f;
- break;
- case Spell.CrescentSlash:
- MagicInfoList[i].MultiplierBase = 1f;
- MagicInfoList[i].MultiplierBonus = 0.4f;
- break;
- }
- }
- }
- private void FillMagicInfoList()
- {
- //Warrior
- if (!MagicExists(Spell.Fencing))
- MagicInfoList.Add(new MagicInfo { Name = "Fencing", Spell = Spell.Fencing, Icon = 2, Level1 = 7, Level2 = 9, Level3 = 12, Need1 = 270, Need2 = 600, Need3 = 1300, Range = 0 });
- if (!MagicExists(Spell.Slaying))
- MagicInfoList.Add(new MagicInfo { Name = "Slaying", Spell = Spell.Slaying, Icon = 6, Level1 = 15, Level2 = 17, Level3 = 20, Need1 = 500, Need2 = 1100, Need3 = 1800, Range = 0 });
- if (!MagicExists(Spell.Thrusting))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Thrusting",
- Spell = Spell.Thrusting,
- Icon = 11,
- Level1 = 22,
- Level2 = 24,
- Level3 = 27,
- Need1 = 2000,
- Need2 = 3500,
- Need3 = 6000,
- Range = 0,
- MultiplierBase = 0.25f,
- MultiplierBonus = 0.25f
- });
- if (!MagicExists(Spell.HalfMoon))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "HalfMoon",
- Spell = Spell.HalfMoon,
- Icon = 24,
- Level1 = 26,
- Level2 = 28,
- Level3 = 31,
- Need1 = 5000,
- Need2 = 8000,
- Need3 = 14000,
- BaseCost = 3,
- Range = 0,
- MultiplierBase = 0.3f,
- MultiplierBonus = 0.1f
- });
- if (!MagicExists(Spell.ShoulderDash))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ShoulderDash",
- Spell = Spell.ShoulderDash,
- Icon = 26,
- Level1 = 30,
- Level2 = 32,
- Level3 = 34,
- Need1 = 3000,
- Need2 = 4000,
- Need3 = 6000,
- BaseCost = 4,
- LevelCost = 4,
- DelayBase = 2500,
- Range = 0,
- MPowerBase = 4
- });
- if (!MagicExists(Spell.TwinDrakeBlade))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "TwinDrakeBlade",
- Spell = Spell.TwinDrakeBlade,
- Icon = 37,
- Level1 = 32,
- Level2 = 34,
- Level3 = 37,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 10000,
- BaseCost = 10,
- Range = 0,
- MultiplierBase = 0.8f,
- MultiplierBonus = 0.1f
- });
- if (!MagicExists(Spell.Entrapment))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Entrapment",
- Spell = Spell.Entrapment,
- Icon = 46,
- Level1 = 32,
- Level2 = 35,
- Level3 = 37,
- Need1 = 2000,
- Need2 = 3500,
- Need3 = 5500,
- BaseCost = 15,
- LevelCost = 3,
- Range = 9
- });
- if (!MagicExists(Spell.FlamingSword))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FlamingSword",
- Spell = Spell.FlamingSword,
- Icon = 25,
- Level1 = 35,
- Level2 = 37,
- Level3 = 40,
- Need1 = 2000,
- Need2 = 4000,
- Need3 = 6000,
- BaseCost = 7,
- Range = 0,
- MultiplierBase = 1.4f,
- MultiplierBonus = 0.4f
- });
- if (!MagicExists(Spell.LionRoar))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "LionRoar",
- Spell = Spell.LionRoar,
- Icon = 42,
- Level1 = 36,
- Level2 = 39,
- Level3 = 41,
- Need1 = 5000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 14,
- LevelCost = 4,
- Range = 0
- });
- if (!MagicExists(Spell.CrossHalfMoon))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "CrossHalfMoon",
- Spell = Spell.CrossHalfMoon,
- Icon = 33,
- Level1 = 38,
- Level2 = 40,
- Level3 = 42,
- Need1 = 7000,
- Need2 = 11000,
- Need3 = 16000,
- BaseCost = 6,
- Range = 0,
- MultiplierBase = 0.4f,
- MultiplierBonus = 0.1f
- });
- if (!MagicExists(Spell.BladeAvalanche))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "BladeAvalanche",
- Spell = Spell.BladeAvalanche,
- Icon = 43,
- Level1 = 38,
- Level2 = 41,
- Level3 = 43,
- Need1 = 5000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 14,
- LevelCost = 4,
- Range = 0,
- MultiplierBonus = 0.3f
- });
- if (!MagicExists(Spell.ProtectionField))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ProtectionField",
- Spell = Spell.ProtectionField,
- Icon = 50,
- Level1 = 39,
- Level2 = 42,
- Level3 = 45,
- Need1 = 6000,
- Need2 = 12000,
- Need3 = 18000,
- BaseCost = 23,
- LevelCost = 6,
- Range = 0
- });
- if (!MagicExists(Spell.Rage))
- MagicInfoList.Add(new MagicInfo
- { Name = "Rage", Spell = Spell.Rage, Icon = 49, Level1 = 44, Level2 = 47, Level3 = 50, Need1 = 8000, Need2 = 14000, Need3 = 20000, BaseCost = 20, LevelCost = 5, Range = 0 });
- if (!MagicExists(Spell.CounterAttack))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "CounterAttack",
- Spell = Spell.CounterAttack,
- Icon = 72,
- Level1 = 47,
- Level2 = 51,
- Level3 = 55,
- Need1 = 7000,
- Need2 = 11000,
- Need3 = 15000,
- BaseCost = 12,
- LevelCost = 4,
- DelayBase = 24000,
- Range = 0,
- MultiplierBonus = 0.4f
- });
- if (!MagicExists(Spell.SlashingBurst))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SlashingBurst",
- Spell = Spell.SlashingBurst,
- Icon = 55,
- Level1 = 50,
- Level2 = 53,
- Level3 = 56,
- Need1 = 10000,
- Need2 = 16000,
- Need3 = 24000,
- BaseCost = 25,
- LevelCost = 4,
- MPowerBase = 1,
- PowerBase = 3,
- DelayBase = 14000,
- DelayReduction = 4000,
- Range = 0,
- MultiplierBase = 3.25f,
- MultiplierBonus = 0.25f
- });
- if (!MagicExists(Spell.Fury))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Fury",
- Spell = Spell.Fury,
- Icon = 76,
- Level1 = 45,
- Level2 = 48,
- Level3 = 51,
- Need1 = 8000,
- Need2 = 14000,
- Need3 = 20000,
- BaseCost = 10,
- LevelCost = 4,
- DelayBase = 600000,
- DelayReduction = 120000,
- Range = 0
- });
- if (!MagicExists(Spell.ImmortalSkin))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ImmortalSkin",
- Spell = Spell.ImmortalSkin,
- Icon = 80,
- Level1 = 60,
- Level2 = 61,
- Level3 = 62,
- Need1 = 1560,
- Need2 = 2200,
- Need3 = 3000,
- BaseCost = 10,
- LevelCost = 4,
- DelayBase = 600000,
- DelayReduction = 120000,
- Range = 0
- });
- //Wizard
- if (!MagicExists(Spell.FireBall))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FireBall",
- Spell = Spell.FireBall,
- Icon = 0,
- Level1 = 7,
- Level2 = 9,
- Level3 = 11,
- Need1 = 200,
- Need2 = 350,
- Need3 = 700,
- BaseCost = 3,
- LevelCost = 2,
- MPowerBase = 8,
- PowerBase = 2,
- Range = 9
- });
- if (!MagicExists(Spell.Repulsion))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Repulsion",
- Spell = Spell.Repulsion,
- Icon = 7,
- Level1 = 12,
- Level2 = 15,
- Level3 = 19,
- Need1 = 500,
- Need2 = 1300,
- Need3 = 2200,
- BaseCost = 2,
- LevelCost = 2,
- Range = 0,
- MPowerBase = 4
- });
- if (!MagicExists(Spell.ElectricShock))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ElectricShock",
- Spell = Spell.ElectricShock,
- Icon = 19,
- Level1 = 13,
- Level2 = 18,
- Level3 = 24,
- Need1 = 530,
- Need2 = 1100,
- Need3 = 2200,
- BaseCost = 3,
- LevelCost = 1,
- Range = 9
- });
- if (!MagicExists(Spell.GreatFireBall))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "GreatFireBall",
- Spell = Spell.GreatFireBall,
- Icon = 4,
- Level1 = 15,
- Level2 = 18,
- Level3 = 21,
- Need1 = 2000,
- Need2 = 2700,
- Need3 = 3500,
- BaseCost = 5,
- LevelCost = 1,
- MPowerBase = 6,
- PowerBase = 10,
- Range = 9
- });
- if (!MagicExists(Spell.HellFire))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "HellFire",
- Spell = Spell.HellFire,
- Icon = 8,
- Level1 = 16,
- Level2 = 20,
- Level3 = 24,
- Need1 = 700,
- Need2 = 2700,
- Need3 = 3500,
- BaseCost = 10,
- LevelCost = 3,
- MPowerBase = 14,
- PowerBase = 6,
- Range = 0
- });
- if (!MagicExists(Spell.ThunderBolt))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ThunderBolt",
- Spell = Spell.ThunderBolt,
- Icon = 10,
- Level1 = 17,
- Level2 = 20,
- Level3 = 23,
- Need1 = 500,
- Need2 = 2000,
- Need3 = 3500,
- BaseCost = 9,
- LevelCost = 2,
- MPowerBase = 8,
- MPowerBonus = 20,
- PowerBase = 9,
- Range = 9
- });
- if (!MagicExists(Spell.Teleport))
- MagicInfoList.Add(new MagicInfo
- { Name = "Teleport", Spell = Spell.Teleport, Icon = 20, Level1 = 19, Level2 = 22, Level3 = 25, Need1 = 350, Need2 = 1000, Need3 = 2000, BaseCost = 10, LevelCost = 3, Range = 0 });
- if (!MagicExists(Spell.FireBang))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FireBang",
- Spell = Spell.FireBang,
- Icon = 22,
- Level1 = 22,
- Level2 = 25,
- Level3 = 28,
- Need1 = 3000,
- Need2 = 5000,
- Need3 = 10000,
- BaseCost = 14,
- LevelCost = 4,
- MPowerBase = 8,
- PowerBase = 8,
- Range = 9
- });
- if (!MagicExists(Spell.FireWall))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FireWall",
- Spell = Spell.FireWall,
- Icon = 21,
- Level1 = 24,
- Level2 = 28,
- Level3 = 33,
- Need1 = 4000,
- Need2 = 10000,
- Need3 = 20000,
- BaseCost = 30,
- LevelCost = 5,
- MPowerBase = 3,
- PowerBase = 3,
- Range = 9
- });
- if (!MagicExists(Spell.Lightning))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Lightning",
- Spell = Spell.Lightning,
- Icon = 9,
- Level1 = 26,
- Level2 = 29,
- Level3 = 32,
- Need1 = 3000,
- Need2 = 6000,
- Need3 = 12000,
- BaseCost = 38,
- LevelCost = 7,
- MPowerBase = 12,
- PowerBase = 12,
- Range = 0
- });
- if (!MagicExists(Spell.FrostCrunch))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FrostCrunch",
- Spell = Spell.FrostCrunch,
- Icon = 38,
- Level1 = 28,
- Level2 = 30,
- Level3 = 33,
- Need1 = 3000,
- Need2 = 5000,
- Need3 = 8000,
- BaseCost = 15,
- LevelCost = 3,
- MPowerBase = 12,
- PowerBase = 12,
- Range = 9
- });
- if (!MagicExists(Spell.ThunderStorm))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ThunderStorm",
- Spell = Spell.ThunderStorm,
- Icon = 23,
- Level1 = 30,
- Level2 = 32,
- Level3 = 34,
- Need1 = 4000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 29,
- LevelCost = 9,
- MPowerBase = 10,
- MPowerBonus = 20,
- PowerBase = 10,
- PowerBonus = 20,
- Range = 0
- });
- if (!MagicExists(Spell.MagicShield))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MagicShield",
- Spell = Spell.MagicShield,
- Icon = 30,
- Level1 = 31,
- Level2 = 34,
- Level3 = 38,
- Need1 = 3000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 35,
- LevelCost = 5,
- Range = 0
- });
- if (!MagicExists(Spell.TurnUndead))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "TurnUndead",
- Spell = Spell.TurnUndead,
- Icon = 31,
- Level1 = 32,
- Level2 = 35,
- Level3 = 39,
- Need1 = 3000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 52,
- LevelCost = 13,
- Range = 9
- });
- if (!MagicExists(Spell.Vampirism))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Vampirism",
- Spell = Spell.Vampirism,
- Icon = 47,
- Level1 = 33,
- Level2 = 36,
- Level3 = 40,
- Need1 = 3000,
- Need2 = 5000,
- Need3 = 8000,
- BaseCost = 26,
- LevelCost = 13,
- MPowerBase = 12,
- PowerBase = 12,
- Range = 9
- });
- if (!MagicExists(Spell.IceStorm))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "IceStorm",
- Spell = Spell.IceStorm,
- Icon = 32,
- Level1 = 35,
- Level2 = 37,
- Level3 = 40,
- Need1 = 4000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 33,
- LevelCost = 3,
- MPowerBase = 12,
- PowerBase = 14,
- Range = 9
- });
- if (!MagicExists(Spell.FlameDisruptor))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FlameDisruptor",
- Spell = Spell.FlameDisruptor,
- Icon = 34,
- Level1 = 38,
- Level2 = 40,
- Level3 = 42,
- Need1 = 5000,
- Need2 = 9000,
- Need3 = 14000,
- BaseCost = 28,
- LevelCost = 3,
- MPowerBase = 15,
- MPowerBonus = 20,
- PowerBase = 9,
- Range = 9
- });
- if (!MagicExists(Spell.Mirroring))
- MagicInfoList.Add(new MagicInfo
- { Name = "Mirroring", Spell = Spell.Mirroring, Icon = 41, Level1 = 41, Level2 = 43, Level3 = 45, Need1 = 6000, Need2 = 11000, Need3 = 16000, BaseCost = 21, Range = 0 });
- if (!MagicExists(Spell.FlameField))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FlameField",
- Spell = Spell.FlameField,
- Icon = 44,
- Level1 = 42,
- Level2 = 43,
- Level3 = 45,
- Need1 = 6000,
- Need2 = 11000,
- Need3 = 16000,
- BaseCost = 45,
- LevelCost = 8,
- MPowerBase = 100,
- PowerBase = 25,
- Range = 9
- });
- if (!MagicExists(Spell.Blizzard))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Blizzard",
- Spell = Spell.Blizzard,
- Icon = 51,
- Level1 = 44,
- Level2 = 47,
- Level3 = 50,
- Need1 = 8000,
- Need2 = 16000,
- Need3 = 24000,
- BaseCost = 65,
- LevelCost = 10,
- MPowerBase = 30,
- MPowerBonus = 10,
- PowerBase = 20,
- PowerBonus = 5,
- Range = 9
- });
- if (!MagicExists(Spell.MagicBooster))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MagicBooster",
- Spell = Spell.MagicBooster,
- Icon = 73,
- Level1 = 47,
- Level2 = 49,
- Level3 = 52,
- Need1 = 12000,
- Need2 = 18000,
- Need3 = 24000,
- BaseCost = 150,
- LevelCost = 15,
- Range = 0
- });
- if (!MagicExists(Spell.MeteorStrike))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MeteorStrike",
- Spell = Spell.MeteorStrike,
- Icon = 52,
- Level1 = 49,
- Level2 = 52,
- Level3 = 55,
- Need1 = 15000,
- Need2 = 20000,
- Need3 = 25000,
- BaseCost = 115,
- LevelCost = 17,
- MPowerBase = 40,
- MPowerBonus = 10,
- PowerBase = 20,
- PowerBonus = 15,
- Range = 9
- });
- if (!MagicExists(Spell.IceThrust))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "IceThrust",
- Spell = Spell.IceThrust,
- Icon = 56,
- Level1 = 53,
- Level2 = 56,
- Level3 = 59,
- Need1 = 17000,
- Need2 = 22000,
- Need3 = 27000,
- BaseCost = 100,
- LevelCost = 20,
- MPowerBase = 100,
- PowerBase = 50,
- Range = 0
- });
- if (!MagicExists(Spell.Blink))
- MagicInfoList.Add(new MagicInfo
- { Name = "Blink", Spell = Spell.Blink, Icon = 20, Level1 = 19, Level2 = 22, Level3 = 25, Need1 = 350, Need2 = 1000, Need3 = 2000, BaseCost = 10, LevelCost = 3, Range = 9 });
- //if (!MagicExists(Spell.FastMove)) MagicInfoList.Add(new MagicInfo { Name = "FastMove", Spell = Spell.ImmortalSkin, Icon = ?, Level1 = ?, Level2 = ?, Level3 = ?, Need1 = ?, Need2 = ?, Need3 = ?, BaseCost = ?, LevelCost = ?, DelayBase = ?, DelayReduction = ? });
- if (!MagicExists(Spell.StormEscape))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "StormEscape",
- Spell = Spell.StormEscape,
- Icon = 23,
- Level1 = 60,
- Level2 = 61,
- Level3 = 62,
- Need1 = 2200,
- Need2 = 3300,
- Need3 = 4400,
- BaseCost = 65,
- LevelCost = 8,
- MPowerBase = 12,
- PowerBase = 4,
- Range = 9
- });
- //Taoist
- if (!MagicExists(Spell.Healing))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Healing",
- Spell = Spell.Healing,
- Icon = 1,
- Level1 = 7,
- Level2 = 11,
- Level3 = 14,
- Need1 = 150,
- Need2 = 350,
- Need3 = 700,
- BaseCost = 3,
- LevelCost = 2,
- MPowerBase = 14,
- Range = 9
- });
- if (!MagicExists(Spell.SpiritSword))
- MagicInfoList.Add(new MagicInfo
- { Name = "SpiritSword", Spell = Spell.SpiritSword, Icon = 3, Level1 = 9, Level2 = 12, Level3 = 15, Need1 = 350, Need2 = 1300, Need3 = 2700, Range = 0 });
- if (!MagicExists(Spell.Poisoning))
- MagicInfoList.Add(new MagicInfo
- { Name = "Poisoning", Spell = Spell.Poisoning, Icon = 5, Level1 = 14, Level2 = 17, Level3 = 20, Need1 = 700, Need2 = 1300, Need3 = 2700, BaseCost = 2, LevelCost = 1, Range = 9 });
- if (!MagicExists(Spell.SoulFireBall))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SoulFireBall",
- Spell = Spell.SoulFireBall,
- Icon = 12,
- Level1 = 18,
- Level2 = 21,
- Level3 = 24,
- Need1 = 1300,
- Need2 = 2700,
- Need3 = 4000,
- BaseCost = 3,
- LevelCost = 1,
- MPowerBase = 8,
- PowerBase = 3,
- Range = 9
- });
- if (!MagicExists(Spell.SummonSkeleton))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonSkeleton",
- Spell = Spell.SummonSkeleton,
- Icon = 16,
- Level1 = 19,
- Level2 = 22,
- Level3 = 26,
- Need1 = 1000,
- Need2 = 2000,
- Need3 = 3500,
- BaseCost = 12,
- LevelCost = 4,
- Range = 0
- });
- if (!MagicExists(Spell.Hiding))
- MagicInfoList.Add(new MagicInfo
- { Name = "Hiding", Spell = Spell.Hiding, Icon = 17, Level1 = 20, Level2 = 23, Level3 = 26, Need1 = 1300, Need2 = 2700, Need3 = 5300, BaseCost = 1, LevelCost = 1, Range = 0 });
- if (!MagicExists(Spell.MassHiding))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MassHiding",
- Spell = Spell.MassHiding,
- Icon = 18,
- Level1 = 21,
- Level2 = 25,
- Level3 = 29,
- Need1 = 1300,
- Need2 = 2700,
- Need3 = 5300,
- BaseCost = 2,
- LevelCost = 2,
- Range = 9
- });
- if (!MagicExists(Spell.SoulShield))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SoulShield",
- Spell = Spell.SoulShield,
- Icon = 13,
- Level1 = 22,
- Level2 = 24,
- Level3 = 26,
- Need1 = 2000,
- Need2 = 3500,
- Need3 = 7000,
- BaseCost = 2,
- LevelCost = 2,
- Range = 9
- });
- if (!MagicExists(Spell.Revelation))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Revelation",
- Spell = Spell.Revelation,
- Icon = 27,
- Level1 = 23,
- Level2 = 25,
- Level3 = 28,
- Need1 = 1500,
- Need2 = 2500,
- Need3 = 4000,
- BaseCost = 4,
- LevelCost = 4,
- Range = 9
- });
- if (!MagicExists(Spell.BlessedArmour))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "BlessedArmour",
- Spell = Spell.BlessedArmour,
- Icon = 14,
- Level1 = 25,
- Level2 = 27,
- Level3 = 29,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 10000,
- BaseCost = 2,
- LevelCost = 2,
- Range = 9
- });
- if (!MagicExists(Spell.EnergyRepulsor))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "EnergyRepulsor",
- Spell = Spell.EnergyRepulsor,
- Icon = 36,
- Level1 = 27,
- Level2 = 29,
- Level3 = 31,
- Need1 = 1800,
- Need2 = 2400,
- Need3 = 3200,
- BaseCost = 2,
- LevelCost = 2,
- Range = 0,
- MPowerBase = 4
- });
- if (!MagicExists(Spell.TrapHexagon))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "TrapHexagon",
- Spell = Spell.TrapHexagon,
- Icon = 15,
- Level1 = 28,
- Level2 = 30,
- Level3 = 32,
- Need1 = 2500,
- Need2 = 5000,
- Need3 = 10000,
- BaseCost = 7,
- LevelCost = 3,
- Range = 9
- });
- if (!MagicExists(Spell.Purification))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Purification",
- Spell = Spell.Purification,
- Icon = 39,
- Level1 = 30,
- Level2 = 32,
- Level3 = 35,
- Need1 = 3000,
- Need2 = 5000,
- Need3 = 8000,
- BaseCost = 14,
- LevelCost = 2,
- Range = 9
- });
- if (!MagicExists(Spell.MassHealing))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MassHealing",
- Spell = Spell.MassHealing,
- Icon = 28,
- Level1 = 31,
- Level2 = 33,
- Level3 = 36,
- Need1 = 2000,
- Need2 = 4000,
- Need3 = 8000,
- BaseCost = 28,
- LevelCost = 3,
- MPowerBase = 10,
- PowerBase = 4,
- Range = 9
- });
- if (!MagicExists(Spell.Hallucination))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Hallucination",
- Spell = Spell.Hallucination,
- Icon = 48,
- Level1 = 31,
- Level2 = 34,
- Level3 = 36,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 9000,
- BaseCost = 22,
- LevelCost = 10,
- Range = 9
- });
- if (!MagicExists(Spell.UltimateEnhancer))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "UltimateEnchancer",
- Spell = Spell.UltimateEnhancer,
- Icon = 35,
- Level1 = 33,
- Level2 = 35,
- Level3 = 38,
- Need1 = 5000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 28,
- LevelCost = 4,
- Range = 9
- });
- if (!MagicExists(Spell.SummonShinsu))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonShinsu",
- Spell = Spell.SummonShinsu,
- Icon = 29,
- Level1 = 35,
- Level2 = 37,
- Level3 = 40,
- Need1 = 2000,
- Need2 = 4000,
- Need3 = 6000,
- BaseCost = 28,
- LevelCost = 4,
- Range = 0
- });
- if (!MagicExists(Spell.Reincarnation))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Reincarnation",
- Spell = Spell.Reincarnation,
- Icon = 53,
- Level1 = 37,
- Level2 = 39,
- Level3 = 41,
- Need1 = 2000,
- Need2 = 6000,
- Need3 = 10000,
- BaseCost = 125,
- LevelCost = 17,
- Range = 9
- });
- if (!MagicExists(Spell.SummonHolyDeva))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonHolyDeva",
- Spell = Spell.SummonHolyDeva,
- Icon = 40,
- Level1 = 38,
- Level2 = 41,
- Level3 = 43,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 9000,
- BaseCost = 28,
- LevelCost = 4,
- Range = 0
- });
- if (!MagicExists(Spell.Curse))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Curse",
- Spell = Spell.Curse,
- Icon = 45,
- Level1 = 40,
- Level2 = 42,
- Level3 = 44,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 9000,
- BaseCost = 17,
- LevelCost = 3,
- Range = 9,
- MPowerBase = 20
- });
- if (!MagicExists(Spell.Plague))
- MagicInfoList.Add(new MagicInfo
- { Name = "Plague", Spell = Spell.Plague, Icon = 74, Level1 = 42, Level2 = 44, Level3 = 47, Need1 = 5000, Need2 = 9000, Need3 = 13000, BaseCost = 20, LevelCost = 5, Range = 9 });
- if (!MagicExists(Spell.PoisonCloud))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "PoisonCloud",
- Spell = Spell.PoisonCloud,
- Icon = 54,
- Level1 = 43,
- Level2 = 45,
- Level3 = 48,
- Need1 = 4000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 30,
- LevelCost = 5,
- MPowerBase = 40,
- PowerBase = 20,
- DelayBase = 18000,
- DelayReduction = 2000,
- Range = 9
- });
- if (!MagicExists(Spell.EnergyShield))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "EnergyShield",
- Spell = Spell.EnergyShield,
- Icon = 57,
- Level1 = 48,
- Level2 = 51,
- Level3 = 54,
- Need1 = 5000,
- Need2 = 9000,
- Need3 = 13000,
- BaseCost = 50,
- LevelCost = 20,
- Range = 9
- });
- if (!MagicExists(Spell.PetEnhancer))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "PetEnhancer",
- Spell = Spell.PetEnhancer,
- Icon = 78,
- Level1 = 45,
- Level2 = 48,
- Level3 = 51,
- Need1 = 4000,
- Need2 = 8000,
- Need3 = 12000,
- BaseCost = 30,
- LevelCost = 40,
- Range = 0
- });
- if (!MagicExists(Spell.HealingCircle))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "HealingCircle",
- Spell = Spell.HealingCircle,
- Icon = 82,
- Level1 = 39,
- Level2 = 41,
- Level3 = 43,
- Need1 = 7000,
- Need2 = 12000,
- Need3 = 15000,
- BaseCost = 10,
- LevelCost = 100
- });
- //Assassin
- if (!MagicExists(Spell.FatalSword))
- MagicInfoList.Add(new MagicInfo { Name = "FatalSword", Spell = Spell.FatalSword, Icon = 58, Level1 = 7, Level2 = 9, Level3 = 12, Need1 = 500, Need2 = 1000, Need3 = 2300, Range = 0 });
- if (!MagicExists(Spell.DoubleSlash))
- MagicInfoList.Add(new MagicInfo
- { Name = "DoubleSlash", Spell = Spell.DoubleSlash, Icon = 59, Level1 = 15, Level2 = 17, Level3 = 19, Need1 = 700, Need2 = 1500, Need3 = 2200, BaseCost = 2, LevelCost = 1 });
- if (!MagicExists(Spell.Haste))
- MagicInfoList.Add(new MagicInfo
- { Name = "Haste", Spell = Spell.Haste, Icon = 60, Level1 = 20, Level2 = 22, Level3 = 25, Need1 = 2000, Need2 = 3000, Need3 = 6000, BaseCost = 3, LevelCost = 2, Range = 0 });
- if (!MagicExists(Spell.FlashDash))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FlashDash",
- Spell = Spell.FlashDash,
- Icon = 61,
- Level1 = 25,
- Level2 = 27,
- Level3 = 30,
- Need1 = 4000,
- Need2 = 7000,
- Need3 = 9000,
- BaseCost = 12,
- LevelCost = 2,
- DelayBase = 200,
- Range = 0
- });
- if (!MagicExists(Spell.LightBody))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "LightBody",
- Spell = Spell.LightBody,
- Icon = 68,
- Level1 = 27,
- Level2 = 29,
- Level3 = 32,
- Need1 = 5000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 11,
- LevelCost = 2,
- Range = 0
- });
- if (!MagicExists(Spell.HeavenlySword))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "HeavenlySword",
- Spell = Spell.HeavenlySword,
- Icon = 62,
- Level1 = 30,
- Level2 = 32,
- Level3 = 35,
- Need1 = 4000,
- Need2 = 8000,
- Need3 = 10000,
- BaseCost = 13,
- LevelCost = 2,
- MPowerBase = 8,
- Range = 0
- });
- if (!MagicExists(Spell.FireBurst))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FireBurst",
- Spell = Spell.FireBurst,
- Icon = 63,
- Level1 = 33,
- Level2 = 35,
- Level3 = 38,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 8000,
- BaseCost = 10,
- LevelCost = 1,
- Range = 0
- });
- if (!MagicExists(Spell.Trap))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Trap",
- Spell = Spell.Trap,
- Icon = 64,
- Level1 = 33,
- Level2 = 35,
- Level3 = 38,
- Need1 = 2000,
- Need2 = 4000,
- Need3 = 6000,
- BaseCost = 14,
- LevelCost = 2,
- DelayBase = 60000,
- DelayReduction = 15000,
- Range = 9
- });
- if (!MagicExists(Spell.PoisonSword))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "PoisonSword",
- Spell = Spell.PoisonSword,
- Icon = 69,
- Level1 = 34,
- Level2 = 36,
- Level3 = 39,
- Need1 = 5000,
- Need2 = 8000,
- Need3 = 11000,
- BaseCost = 14,
- LevelCost = 3,
- Range = 0
- });
- if (!MagicExists(Spell.MoonLight))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MoonLight",
- Spell = Spell.MoonLight,
- Icon = 65,
- Level1 = 36,
- Level2 = 39,
- Level3 = 42,
- Need1 = 3000,
- Need2 = 5000,
- Need3 = 8000,
- BaseCost = 36,
- LevelCost = 3,
- Range = 0
- });
- if (!MagicExists(Spell.MPEater))
- MagicInfoList.Add(new MagicInfo { Name = "MPEater", Spell = Spell.MPEater, Icon = 66, Level1 = 38, Level2 = 41, Level3 = 44, Need1 = 5000, Need2 = 8000, Need3 = 11000, Range = 0 });
- if (!MagicExists(Spell.SwiftFeet))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SwiftFeet",
- Spell = Spell.SwiftFeet,
- Icon = 67,
- Level1 = 40,
- Level2 = 43,
- Level3 = 46,
- Need1 = 4000,
- Need2 = 6000,
- Need3 = 9000,
- BaseCost = 17,
- LevelCost = 5,
- DelayBase = 210000,
- DelayReduction = 40000,
- Range = 0
- });
- if (!MagicExists(Spell.DarkBody))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "DarkBody",
- Spell = Spell.DarkBody,
- Icon = 70,
- Level1 = 46,
- Level2 = 49,
- Level3 = 52,
- Need1 = 6000,
- Need2 = 10000,
- Need3 = 14000,
- BaseCost = 40,
- LevelCost = 7,
- Range = 0
- });
- if (!MagicExists(Spell.Hemorrhage))
- MagicInfoList.Add(new MagicInfo
- { Name = "Hemorrhage", Spell = Spell.Hemorrhage, Icon = 75, Level1 = 47, Level2 = 51, Level3 = 55, Need1 = 9000, Need2 = 15000, Need3 = 21000, Range = 0 });
- if (!MagicExists(Spell.CrescentSlash))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "CresentSlash",
- Spell = Spell.CrescentSlash,
- Icon = 71,
- Level1 = 50,
- Level2 = 53,
- Level3 = 56,
- Need1 = 12000,
- Need2 = 16000,
- Need3 = 24000,
- BaseCost = 19,
- LevelCost = 5,
- Range = 0
- });
- if (!MagicExists(Spell.MoonMist))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MoonMist",
- Spell = Spell.MoonMist,
- Icon = 83,
- Level1 = 48,
- Level2 = 51,
- Level3 = 56,
- Need1 = 10,
- Need2 = 20,
- Need3 = 30,
- BaseCost = 30,
- LevelCost = 5,
- DelayBase = 20000,
- DelayReduction = 2000
- });
- if (!MagicExists(Spell.CatTongue))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "CatTongue",
- Spell = Spell.CatTongue,
- Icon = 79,
- Level1 = 48,
- Level2 = 51,
- Level3 = 56,
- Need1 = 10,
- Need2 = 20,
- Need3 = 30,
- BaseCost = 30,
- LevelCost = 5,
- DelayBase = 20000,
- DelayReduction = 2000
- });
- //Archer
- if (!MagicExists(Spell.Focus))
- MagicInfoList.Add(new MagicInfo { Name = "Focus", Spell = Spell.Focus, Icon = 88, Level1 = 7, Level2 = 13, Level3 = 17, Need1 = 270, Need2 = 600, Need3 = 1300, Range = 0 });
- if (!MagicExists(Spell.StraightShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "StraightShot",
- Spell = Spell.StraightShot,
- Icon = 89,
- Level1 = 9,
- Level2 = 12,
- Level3 = 16,
- Need1 = 350,
- Need2 = 750,
- Need3 = 1400,
- BaseCost = 3,
- LevelCost = 2,
- MPowerBase = 8,
- PowerBase = 3,
- Range = 9
- });
- if (!MagicExists(Spell.DoubleShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "DoubleShot",
- Spell = Spell.DoubleShot,
- Icon = 90,
- Level1 = 14,
- Level2 = 18,
- Level3 = 21,
- Need1 = 700,
- Need2 = 1500,
- Need3 = 2100,
- BaseCost = 3,
- LevelCost = 2,
- MPowerBase = 6,
- PowerBase = 2,
- Range = 9
- });
- if (!MagicExists(Spell.ExplosiveTrap))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ExplosiveTrap",
- Spell = Spell.ExplosiveTrap,
- Icon = 91,
- Level1 = 22,
- Level2 = 25,
- Level3 = 30,
- Need1 = 2000,
- Need2 = 3500,
- Need3 = 5000,
- BaseCost = 10,
- LevelCost = 3,
- MPowerBase = 15,
- PowerBase = 15,
- Range = 0
- });
- if (!MagicExists(Spell.DelayedExplosion))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "DelayedExplosion",
- Spell = Spell.DelayedExplosion,
- Icon = 92,
- Level1 = 31,
- Level2 = 34,
- Level3 = 39,
- Need1 = 3000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 8,
- LevelCost = 2,
- MPowerBase = 30,
- PowerBase = 15,
- Range = 9
- });
- if (!MagicExists(Spell.Meditation))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Meditation",
- Spell = Spell.Meditation,
- Icon = 93,
- Level1 = 19,
- Level2 = 24,
- Level3 = 29,
- Need1 = 1800,
- Need2 = 2600,
- Need3 = 5600,
- BaseCost = 8,
- LevelCost = 2,
- Range = 0
- });
- if (!MagicExists(Spell.ElementalShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ElementalShot",
- Spell = Spell.ElementalShot,
- Icon = 94,
- Level1 = 20,
- Level2 = 25,
- Level3 = 31,
- Need1 = 1800,
- Need2 = 2700,
- Need3 = 6000,
- BaseCost = 8,
- LevelCost = 2,
- MPowerBase = 6,
- PowerBase = 3,
- Range = 9
- });
- if (!MagicExists(Spell.Concentration))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "Concentration",
- Spell = Spell.Concentration,
- Icon = 96,
- Level1 = 23,
- Level2 = 27,
- Level3 = 32,
- Need1 = 2100,
- Need2 = 3800,
- Need3 = 6500,
- BaseCost = 8,
- LevelCost = 2,
- Range = 0
- });
- if (!MagicExists(Spell.ElementalBarrier))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "ElementalBarrier",
- Spell = Spell.ElementalBarrier,
- Icon = 98,
- Level1 = 33,
- Level2 = 38,
- Level3 = 44,
- Need1 = 3000,
- Need2 = 7000,
- Need3 = 10000,
- BaseCost = 10,
- LevelCost = 2,
- MPowerBase = 15,
- PowerBase = 5,
- Range = 0
- });
- if (!MagicExists(Spell.BackStep))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "BackStep",
- Spell = Spell.BackStep,
- Icon = 95,
- Level1 = 30,
- Level2 = 34,
- Level3 = 38,
- Need1 = 2400,
- Need2 = 3000,
- Need3 = 6000,
- BaseCost = 12,
- LevelCost = 2,
- DelayBase = 2500,
- Range = 0
- });
- if (!MagicExists(Spell.BindingShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "BindingShot",
- Spell = Spell.BindingShot,
- Icon = 97,
- Level1 = 35,
- Level2 = 39,
- Level3 = 42,
- Need1 = 400,
- Need2 = 7000,
- Need3 = 9500,
- BaseCost = 7,
- LevelCost = 3,
- Range = 9
- });
- if (!MagicExists(Spell.Stonetrap))
- MagicInfoList.Add(new MagicInfo
- { Name = "Stonetrap", Spell = Spell.Stonetrap, Icon = 97, Level1 = 40, Level2 = 43, Level3 = 46, Need1 = 4900, Need2 = 9800, Need3 = 141, BaseCost = 7, LevelCost = 3, Range = 9 });
- if (!MagicExists(Spell.SummonVampire))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonVampire",
- Spell = Spell.SummonVampire,
- Icon = 99,
- Level1 = 28,
- Level2 = 33,
- Level3 = 41,
- Need1 = 2000,
- Need2 = 2700,
- Need3 = 7500,
- BaseCost = 10,
- LevelCost = 5,
- Range = 9
- });
- if (!MagicExists(Spell.VampireShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "VampireShot",
- Spell = Spell.VampireShot,
- Icon = 100,
- Level1 = 26,
- Level2 = 32,
- Level3 = 36,
- Need1 = 3000,
- Need2 = 6000,
- Need3 = 12000,
- BaseCost = 12,
- LevelCost = 3,
- MPowerBase = 10,
- PowerBase = 7,
- Range = 9
- });
- if (!MagicExists(Spell.SummonToad))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonToad",
- Spell = Spell.SummonToad,
- Icon = 101,
- Level1 = 37,
- Level2 = 43,
- Level3 = 47,
- Need1 = 5800,
- Need2 = 10000,
- Need3 = 13000,
- BaseCost = 10,
- LevelCost = 5,
- Range = 9
- });
- if (!MagicExists(Spell.PoisonShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "PoisonShot",
- Spell = Spell.PoisonShot,
- Icon = 102,
- Level1 = 40,
- Level2 = 45,
- Level3 = 49,
- Need1 = 6000,
- Need2 = 14000,
- Need3 = 16000,
- BaseCost = 10,
- LevelCost = 4,
- MPowerBase = 10,
- PowerBase = 10,
- Range = 9
- });
- if (!MagicExists(Spell.CrippleShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "CrippleShot",
- Spell = Spell.CrippleShot,
- Icon = 103,
- Level1 = 43,
- Level2 = 47,
- Level3 = 50,
- Need1 = 12000,
- Need2 = 15000,
- Need3 = 18000,
- BaseCost = 15,
- LevelCost = 3,
- MPowerBase = 10,
- MPowerBonus = 20,
- PowerBase = 10,
- Range = 9
- });
- if (!MagicExists(Spell.SummonSnakes))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "SummonSnakes",
- Spell = Spell.SummonSnakes,
- Icon = 104,
- Level1 = 46,
- Level2 = 51,
- Level3 = 54,
- Need1 = 14000,
- Need2 = 17000,
- Need3 = 20000,
- BaseCost = 10,
- LevelCost = 5,
- Range = 9
- });
- if (!MagicExists(Spell.NapalmShot))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "NapalmShot",
- Spell = Spell.NapalmShot,
- Icon = 105,
- Level1 = 48,
- Level2 = 52,
- Level3 = 55,
- Need1 = 15000,
- Need2 = 18000,
- Need3 = 21000,
- BaseCost = 40,
- LevelCost = 10,
- MPowerBase = 25,
- MPowerBonus = 25,
- PowerBase = 25,
- Range = 9
- });
- if (!MagicExists(Spell.OneWithNature))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "OneWithNature",
- Spell = Spell.OneWithNature,
- Icon = 106,
- Level1 = 50,
- Level2 = 53,
- Level3 = 56,
- Need1 = 17000,
- Need2 = 19000,
- Need3 = 24000,
- BaseCost = 80,
- LevelCost = 15,
- MPowerBase = 75,
- MPowerBonus = 35,
- PowerBase = 30,
- PowerBonus = 20,
- Range = 9
- });
- if (!MagicExists(Spell.MentalState))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MentalState",
- Spell = Spell.MentalState,
- Icon = 81,
- Level1 = 11,
- Level2 = 15,
- Level3 = 22,
- Need1 = 500,
- Need2 = 900,
- Need3 = 1800,
- BaseCost = 1,
- LevelCost = 1,
- Range = 0
- });
- //Custom
- if (!MagicExists(Spell.Portal))
- MagicInfoList.Add(new MagicInfo
- { Name = "Portal", Spell = Spell.Portal, Icon = 1, Level1 = 7, Level2 = 11, Level3 = 14, Need1 = 150, Need2 = 350, Need3 = 700, BaseCost = 3, LevelCost = 2, Range = 9 });
- if (!MagicExists(Spell.BattleCry))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "BattleCry",
- Spell = Spell.BattleCry,
- Icon = 42,
- Level1 = 48,
- Level2 = 51,
- Level3 = 55,
- Need1 = 8000,
- Need2 = 11000,
- Need3 = 15000,
- BaseCost = 22,
- LevelCost = 10,
- Range = 0
- });
- if (!MagicExists(Spell.FireBounce))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "FireBounce",
- Spell = Spell.FireBounce,
- Icon = 4,
- Level1 = 15,
- Level2 = 18,
- Level3 = 21,
- Need1 = 2000,
- Need2 = 2700,
- Need3 = 3500,
- BaseCost = 5,
- LevelCost = 1,
- MPowerBase = 6,
- PowerBase = 10,
- Range = 9
- });
- if (!MagicExists(Spell.MeteorShower))
- MagicInfoList.Add(new MagicInfo
- {
- Name = "MeteorShower",
- Spell = Spell.MeteorShower,
- Icon = 4,
- Level1 = 15,
- Level2 = 18,
- Level3 = 21,
- Need1 = 2000,
- Need2 = 2700,
- Need3 = 3500,
- BaseCost = 5,
- LevelCost = 1,
- MPowerBase = 6,
- PowerBase = 10,
- Range = 9
- });
- }
- private string CanStartEnvir()
- {
- if (StartPoints.Count == 0) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMapAndStartPoint);
- if (Settings.EnforceDBChecks)
- {
- if (GetMonsterInfo(Settings.SkeletonName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.SkeletonName;
- if (GetMonsterInfo(Settings.ShinsuName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ShinsuName;
- if (GetMonsterInfo(Settings.BugBatName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BugBatName;
- if (GetMonsterInfo(Settings.Zuma1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma1;
- if (GetMonsterInfo(Settings.Zuma2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma2;
- if (GetMonsterInfo(Settings.Zuma3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma3;
- if (GetMonsterInfo(Settings.Zuma4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma4;
- if (GetMonsterInfo(Settings.Zuma5, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma5;
- if (GetMonsterInfo(Settings.Zuma6, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma6;
- if (GetMonsterInfo(Settings.Zuma7, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Zuma7;
- if (GetMonsterInfo(Settings.Turtle1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Turtle1;
- if (GetMonsterInfo(Settings.Turtle2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Turtle2;
- if (GetMonsterInfo(Settings.Turtle3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Turtle3;
- if (GetMonsterInfo(Settings.Turtle4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Turtle4;
- if (GetMonsterInfo(Settings.Turtle5, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.Turtle5;
- if (GetMonsterInfo(Settings.BoneMonster1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BoneMonster1;
- if (GetMonsterInfo(Settings.BoneMonster2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BoneMonster2;
- if (GetMonsterInfo(Settings.BoneMonster3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BoneMonster3;
- if (GetMonsterInfo(Settings.BoneMonster4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BoneMonster4;
- if (GetMonsterInfo(Settings.BehemothMonster1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BehemothMonster1;
- if (GetMonsterInfo(Settings.BehemothMonster2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BehemothMonster2;
- if (GetMonsterInfo(Settings.BehemothMonster3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BehemothMonster3;
- if (GetMonsterInfo(Settings.HellKnight1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellKnight1;
- if (GetMonsterInfo(Settings.HellKnight2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellKnight2;
- if (GetMonsterInfo(Settings.HellKnight3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellKnight3;
- if (GetMonsterInfo(Settings.HellKnight4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellKnight4;
- if (GetMonsterInfo(Settings.HellBomb1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellBomb1;
- if (GetMonsterInfo(Settings.HellBomb2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellBomb2;
- if (GetMonsterInfo(Settings.HellBomb3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HellBomb3;
- if (GetMonsterInfo(Settings.WhiteSnake, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.WhiteSnake;
- if (GetMonsterInfo(Settings.AngelName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.AngelName;
- if (GetMonsterInfo(Settings.BombSpiderName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.BombSpiderName;
- if (GetMonsterInfo(Settings.CloneName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.CloneName;
- if (GetMonsterInfo(Settings.AssassinCloneName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.AssassinCloneName;
- if (GetMonsterInfo(Settings.VampireName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.VampireName;
- if (GetMonsterInfo(Settings.ToadName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ToadName;
- if (GetMonsterInfo(Settings.SnakeTotemName, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.SnakeTotemName;
- if (GetMonsterInfo(Settings.FishingMonster, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.FishingMonster;
- if (GetMonsterInfo(Settings.GeneralMeowMeowMob1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.GeneralMeowMeowMob1;
- if (GetMonsterInfo(Settings.GeneralMeowMeowMob2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.GeneralMeowMeowMob2;
- if (GetMonsterInfo(Settings.GeneralMeowMeowMob3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.GeneralMeowMeowMob3;
- if (GetMonsterInfo(Settings.GeneralMeowMeowMob4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.GeneralMeowMeowMob4;
- if (GetMonsterInfo(Settings.KingHydraxMob, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.KingHydraxMob;
- if (GetMonsterInfo(Settings.HornedCommanderMob, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HornedCommanderMob;
- if (GetMonsterInfo(Settings.HornedCommanderBombMob, true) == null)
- return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.HornedCommanderBombMob;
- if (GetMonsterInfo(Settings.SnowWolfKingMob, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.SnowWolfKingMob;
- if (GetMonsterInfo(Settings.ScrollMob1, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ScrollMob1;
- if (GetMonsterInfo(Settings.ScrollMob2, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ScrollMob2;
- if (GetMonsterInfo(Settings.ScrollMob3, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ScrollMob3;
- if (GetMonsterInfo(Settings.ScrollMob4, true) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutMob) + Settings.ScrollMob4;
- if (GetItemInfo(Settings.RefineOreName) == null) return GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.CannotStartServerWithoutItem) + Settings.RefineOreName;
- }
- WorldMapIcon wmi = ValidateWorldMap();
- if (wmi != null)
- return GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.InvalidWorldmapIndex), wmi.MapIndex, wmi.Title);
- //add intelligent creature checks?
- return "true";
- }
- private void WorkLoop()
- {
- try
- {
- Time = Stopwatch.ElapsedMilliseconds;
- var conTime = Time;
- var saveTime = Time + Settings.SaveDelay * Settings.Minute;
- var userTime = Time + Settings.Minute * 5;
- var lineMessageTime = Time + Settings.Minute * Settings.LineMessageTimer;
- var processTime = Time + 1000;
- var startTime = Time;
- var processCount = 0;
- var processRealCount = 0;
- LinkedListNode<MapObject> current = null;
- if (Settings.Multithreaded)
- {
- for (var j = 0; j < MobThreads.Length; j++)
- {
- MobThreads[j] = new MobThread();
- MobThreads[j].Id = j;
- }
- }
- StartEnvir();
- var canstartserver = CanStartEnvir();
- if (canstartserver != "true")
- {
- MessageQueue.Enqueue(canstartserver);
- StopEnvir();
- _thread = null;
- Stop();
- return;
- }
- if (Settings.Multithreaded)
- {
- for (var j = 0; j < MobThreads.Length; j++)
- {
- var Info = MobThreads[j];
- if (j <= 0) continue;
- MobThreading[j] = new Thread(() => ThreadLoop(Info)) { IsBackground = true };
- MobThreading[j].Start();
- }
- }
- StartNetwork();
- if (Settings.StartHTTPService)
- {
- http = new HttpServer();
- http.Start();
- }
- try
- {
- while (Running)
- {
- Time = Stopwatch.ElapsedMilliseconds;
- if (Time >= processTime)
- {
- LastCount = processCount;
- LastRealCount = processRealCount;
- processCount = 0;
- processRealCount = 0;
- processTime = Time + 1000;
- }
- if (conTime != Time)
- {
- conTime = Time;
- AdjustLights();
- lock (Connections)
- {
- for (var i = Connections.Count - 1; i >= 0; i--)
- {
- Connections[i].Process();
- }
- }
- lock (StatusConnections)
- {
- for (var i = StatusConnections.Count - 1; i >= 0; i--)
- {
- StatusConnections[i].Process();
- }
- }
- }
- if (current == null)
- current = Objects.First;
- if (current == Objects.First)
- {
- LastRunTime = Time - startTime;
- startTime = Time;
- }
- if (Settings.Multithreaded)
- {
- for (var j = 1; j < MobThreads.Length; j++)
- {
- var Info = MobThreads[j];
- if (!Info.Stop) continue;
- Info.EndTime = Time + 10;
- Info.Stop = false;
- }
- lock (_locker)
- {
- Monitor.PulseAll(_locker); //changing a blocking condition. (this makes the threads wake up!)
- }
- //run the first loop in the main thread so the main thread automaticaly 'halts' until the other threads are finished
- ThreadLoop(MobThreads[0]);
- }
- var TheEnd = false;
- var Start = Stopwatch.ElapsedMilliseconds;
- while (!TheEnd && Stopwatch.ElapsedMilliseconds - Start < 20)
- {
- if (current == null)
- {
- TheEnd = true;
- break;
- }
- var next = current.Next;
- if (!Settings.Multithreaded || current.Value.Race != ObjectType.Monster || current.Value.Master != null)
- {
- if (Time > current.Value.OperateTime)
- {
- current.Value.Process();
- current.Value.SetOperateTime();
- }
- processCount++;
- }
- current = next;
- }
- for (var i = 0; i < MapList.Count; i++)
- MapList[i].Process();
- DragonSystem?.Process();
- Process();
- if (Time >= saveTime)
- {
- saveTime = Time + Settings.SaveDelay * Settings.Minute;
- BeginSaveAccounts();
- SaveDB();
- SaveGuilds();
- SaveGoods();
- SaveConquests();
- }
- if (Time >= userTime)
- {
- userTime = Time + Settings.Minute * 5;
- Broadcast(new S.Chat
- {
- Message = GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.OnlinePlayers), Players.Count),
- Type = ChatType.Hint
- });
- }
- if (LineMessages.Count > 0 && Time >= lineMessageTime)
- {
- lineMessageTime = Time + Settings.Minute * Settings.LineMessageTimer;
- Broadcast(new S.Chat
- {
- Message = LineMessages[Random.Next(LineMessages.Count)],
- Type = ChatType.LineMessage
- });
- }
- // if (Players.Count == 0) Thread.Sleep(1);
- // GC.Collect();
- }
- }
- catch (Exception ex)
- {
- lock (Connections)
- {
- for (var i = Connections.Count - 1; i >= 0; i--)
- Connections[i].SendDisconnect(3);
- }
- // Get stack trace for the exception with source file information
- var st = new StackTrace(ex, true);
- // Get the top stack frame
- var frame = st.GetFrame(0);
- // Get the line number from the stack frame
- var line = frame.GetFileLineNumber();
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.InnerWorkloopErrorLine), line, ex));
- }
- StopNetwork();
- StopEnvir();
- SaveAccounts();
- SaveGuilds(true);
- SaveConquests(true);
- }
- catch (Exception ex)
- {
- // Get stack trace for the exception with source file information
- var st = new StackTrace(ex, true);
- // Get the top stack frame
- var frame = st.GetFrame(0);
- // Get the line number from the stack frame
- var line = frame.GetFileLineNumber();
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.OuterWorkloopErrorLine), line, ex));
- }
- _thread = null;
- }
- private void ThreadLoop(MobThread Info)
- {
- Info.Stop = false;
- try
- {
- var stopping = false;
- if (Info._current == null)
- Info._current = Info.ObjectsList.First;
- stopping = Info._current == null;
- while (Running)
- {
- if (Info._current == null)
- Info._current = Info.ObjectsList.First;
- else
- {
- var next = Info._current.Next;
- //if we reach the end of our list > go back to the top (since we are running threaded, we dont want the system to sit there for xxms doing nothing)
- if (Info._current == Info.ObjectsList.Last)
- {
- next = Info.ObjectsList.First;
- Info.LastRunTime = (Info.LastRunTime + (Time - Info.StartTime)) / 2;
- //Info.LastRunTime = (Time - Info.StartTime) /*> 0 ? (Time - Info.StartTime) : Info.LastRunTime */;
- Info.StartTime = Time;
- }
- if (Time > Info._current.Value.OperateTime)
- {
- if (Info._current.Value.Master == null) //since we are running multithreaded, dont allow pets to be processed (unless you constantly move pets into their map appropriate thead)
- {
- Info._current.Value.Process();
- Info._current.Value.SetOperateTime();
- }
- }
- Info._current = next;
- }
- //if it's the main thread > make it loop till the subthreads are done, else make it stop after 'endtime'
- if (Info.Id == 0)
- {
- stopping = true;
- for (var x = 1; x < MobThreads.Length; x++)
- {
- if (MobThreads[x].Stop == false)
- {
- stopping = false;
- }
- }
- if (!stopping) continue;
- Info.Stop = stopping;
- return;
- }
- if (Stopwatch.ElapsedMilliseconds <= Info.EndTime || !Running) continue;
- Info.Stop = true;
- lock (_locker)
- {
- while (Info.Stop) Monitor.Wait(_locker);
- }
- }
- }
- catch (Exception ex)
- {
- if (ex is ThreadInterruptedException) return;
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.ThreadLoopError), ex));
- }
- }
- private void AdjustLights()
- {
- var oldLights = Lights;
- var hours = Now.Hour * 2 % 24;
- if (hours == 6 || hours == 7)
- Lights = LightSetting.Dawn;
- else if (hours >= 8 && hours <= 15)
- Lights = LightSetting.Day;
- else if (hours == 16 || hours == 17)
- Lights = LightSetting.Evening;
- else
- Lights = LightSetting.Night;
- if (oldLights == Lights) return;
- Broadcast(new S.TimeOfDay { Lights = Lights });
- }
- public void Process()
- {
- if (Now.Day != dailyTime)
- {
- dailyTime = Now.Day;
- ProcessNewDay();
- }
- if (Time >= warTime)
- {
- warTime = Time + Settings.Minute;
- for (var i = GuildsAtWar.Count - 1; i >= 0; i--)
- {
- GuildsAtWar[i].TimeRemaining -= Settings.Minute;
- if (GuildsAtWar[i].TimeRemaining >= 0) continue;
- GuildsAtWar[i].EndWar();
- GuildsAtWar.RemoveAt(i);
- }
- }
- if (Time >= guildTime)
- {
- guildTime = Time + Settings.Minute;
- for (var i = 0; i < Guilds.Count; i++)
- {
- Guilds[i].Process();
- }
- }
- if (Time >= conquestTime)
- {
- conquestTime = Time + Settings.Second * 10;
- for (var i = 0; i < Conquests.Count; i++)
- {
- Conquests[i].Process();
- }
- }
- if (Time >= rentalItemsTime)
- {
- rentalItemsTime = Time + Settings.Minute * 5;
- ProcessRentedItems();
- }
- if (Time >= auctionTime)
- {
- auctionTime = Time + Settings.Minute * 10;
- ProcessAuction();
- }
- if (Time >= spawnTime)
- {
- spawnTime = Time + Settings.Second * 10;
- Main.RespawnTick.Process();
- }
- if (Time >= robotTime)
- {
- robotTime = Time + Settings.Minute;
- Robot.Process(RobotNPC);
- }
- if (Time >= timerTime)
- {
- timerTime = Time + Settings.Second;
- string[] keys = Timers.Keys.ToArray();
- foreach (var key in keys)
- {
- if (Timers[key].RelativeTime <= Time)
- {
- Timers.Remove(key);
- }
- }
- }
- }
- private void ProcessAuction()
- {
- LinkedListNode<AuctionInfo> current = Auctions.First;
- while (current != null)
- {
- AuctionInfo info = current.Value;
- if (!info.Expired && !info.Sold && Now >= info.ConsignmentDate.AddDays(Globals.ConsignmentLength))
- {
- if (info.ItemType == MarketItemType.Auction && info.CurrentBid > info.Price)
- {
- string message = GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.YouWonForGold), info.Item.FriendlyName, info.CurrentBid);
- info.Sold = true;
- MailCharacter(info.CurrentBuyerInfo, item: info.Item, customMessage: message);
- MessageAccount(info.CurrentBuyerInfo.AccountInfo, GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.YouBoughtForGold), info.Item.FriendlyName, info.CurrentBid),
- ChatType.Hint);
- MessageAccount(info.SellerInfo.AccountInfo, GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.YouSoldForGold), info.Item.FriendlyName, info.CurrentBid),
- ChatType.Hint);
- }
- else
- {
- info.Expired = true;
- }
- }
- current = current.Next;
- }
- }
- public void Broadcast(Packet p)
- {
- for (var i = 0; i < Players.Count; i++) Players[i].Enqueue(p);
- }
- public void RequiresBaseStatUpdate()
- {
- for (var i = 0; i < Players.Count; i++) Players[i].HasUpdatedBaseStats = false;
- }
- public void RequiresHeroBaseStatUpdate()
- {
- for (var i = 0; i < Heroes.Count; i++)
- {
- Heroes[i].HasUpdatedBaseStats = false;
- Heroes[i].RefreshStats();
- }
- }
- public void SaveDB()
- {
- if (File.Exists(DatabasePath))
- {
- if (!Directory.Exists(DatabaseBackUpPath)) Directory.CreateDirectory(DatabaseBackUpPath);
- var fileName =
- $"Database {Now.Year:0000}-{Now.Month:00}-{Now.Day:00} {Now.Hour:00}-{Now.Minute:00}-{Now.Second:00}.bak";
- var backupFile = Path.Combine(DatabaseBackUpPath, fileName);
- if (File.Exists(backupFile)) File.Delete(backupFile);
- File.Copy(DatabasePath, backupFile);
- }
- using (var stream = File.Create(DatabasePath))
- using (var writer = new BinaryWriter(stream))
- {
- writer.Write(Version);
- writer.Write(CustomVersion);
- writer.Write(MapIndex);
- writer.Write(ItemIndex);
- writer.Write(MonsterIndex);
- writer.Write(NPCIndex);
- writer.Write(QuestIndex);
- writer.Write(GameshopIndex);
- writer.Write(ConquestIndex);
- writer.Write(RespawnIndex);
- writer.Write(MapInfoList.Count);
- for (var i = 0; i < MapInfoList.Count; i++)
- MapInfoList[i].Save(writer);
- writer.Write(ItemInfoList.Count);
- for (var i = 0; i < ItemInfoList.Count; i++)
- ItemInfoList[i].Save(writer);
- writer.Write(MonsterInfoList.Count);
- for (var i = 0; i < MonsterInfoList.Count; i++)
- MonsterInfoList[i].Save(writer);
- writer.Write(NPCInfoList.Count);
- for (var i = 0; i < NPCInfoList.Count; i++)
- NPCInfoList[i].Save(writer);
- writer.Write(QuestInfoList.Count);
- for (var i = 0; i < QuestInfoList.Count; i++)
- QuestInfoList[i].Save(writer);
- DragonInfo.Save(writer);
- writer.Write(MagicInfoList.Count);
- for (var i = 0; i < MagicInfoList.Count; i++)
- MagicInfoList[i].Save(writer);
- writer.Write(GameShopList.Count);
- for (var i = 0; i < GameShopList.Count; i++)
- GameShopList[i].Save(writer);
- writer.Write(ConquestInfoList.Count);
- for (var i = 0; i < ConquestInfoList.Count; i++)
- ConquestInfoList[i].Save(writer);
- RespawnTick.Save(writer);
- writer.Write(GTMapList.Count);
- for (var i = 0; i < GTMapList.Count; i++)
- GTMapList[i].Save(writer);
- }
- }
- public CharacterInfo GetArchivedCharacter(string name)
- {
- DirectoryInfo dir = new DirectoryInfo(ArchivePath);
- FileInfo[] files = dir.GetFiles($"{name}*.MirCA");
- if (files.Length != 1)
- {
- return null;
- }
- var fileInfo = files[0];
- CharacterInfo info = null;
- using (var stream = fileInfo.OpenRead())
- {
- using var reader = new BinaryReader(stream);
- var version = reader.ReadInt32();
- var customVersion = reader.ReadInt32();
- info = new CharacterInfo(reader, version, customVersion);
- }
- return info;
- }
- public void SaveArchivedCharacter(CharacterInfo info)
- {
- if (!Directory.Exists(ArchivePath)) Directory.CreateDirectory(ArchivePath);
- using var stream = File.Create(Path.Combine(ArchivePath, @$"{info.Name}{Now:_MMddyyyy_HHmmss}.MirCA"));
- using var writer = new BinaryWriter(stream);
- writer.Write(Version);
- writer.Write(CustomVersion);
- info.Save(writer);
- }
- public void SaveAccounts()
- {
- while (Saving)
- Thread.Sleep(1);
- try
- {
- using (var stream = File.Create(AccountPath + "n"))
- SaveAccounts(stream);
- if (File.Exists(AccountPath))
- File.Move(AccountPath, AccountPath + "o");
- File.Move(AccountPath + "n", AccountPath);
- if (File.Exists(AccountPath + "o"))
- File.Delete(AccountPath + "o");
- }
- catch (Exception ex)
- {
- MessageQueue.Enqueue(ex);
- }
- }
- private void SaveAccounts(Stream stream)
- {
- using (var writer = new BinaryWriter(stream))
- {
- writer.Write(Version);
- writer.Write(CustomVersion);
- writer.Write(NextAccountID);
- writer.Write(NextCharacterID);
- writer.Write(NextUserItemID);
- writer.Write(NextHeroID);
- writer.Write(GuildList.Count);
- writer.Write(NextGuildID);
- writer.Write(HeroList.Count);
- for (var i = 0; i < HeroList.Count; i++)
- HeroList[i].Save(writer);
- writer.Write(AccountList.Count);
- for (var i = 0; i < AccountList.Count; i++)
- AccountList[i].Save(writer);
- writer.Write(NextAuctionID);
- writer.Write(Auctions.Count);
- foreach (var auction in Auctions)
- auction.Save(writer);
- writer.Write(NextMailID);
- writer.Write(GameshopLog.Count);
- foreach (var item in GameshopLog)
- {
- writer.Write(item.Key);
- writer.Write(item.Value);
- }
- writer.Write(SavedSpawns.Count);
- foreach (var Spawn in SavedSpawns)
- {
- var Save = new RespawnSave { RespawnIndex = Spawn.Info.RespawnIndex, NextSpawnTick = Spawn.NextSpawnTick, Spawned = Spawn.Count >= Spawn.Info.Count * SpawnMultiplier };
- Save.Save(writer);
- }
- }
- }
- private void SaveGuilds(bool forced = false)
- {
- if (!Directory.Exists(Settings.GuildPath)) Directory.CreateDirectory(Settings.GuildPath);
- if (GuildRefreshNeeded == true) //deletes guild files and resaves with new indexing if a guild is deleted.
- {
- foreach (var guildfile in Directory.GetFiles(Settings.GuildPath, "*.mgd"))
- {
- File.Delete(guildfile);
- }
- GuildRefreshNeeded = false;
- forced = true; //triggers a full resave of all guilds
- }
- for (var i = 0; i < GuildList.Count; i++)
- {
- if (GuildList[i].NeedSave || forced)
- {
- GuildList[i].NeedSave = false;
- GuildObject liveGuild = Guilds.Find(g => g.Guildindex == GuildList[i].GuildIndex);
- if (liveGuild != null)
- {
- GuildList[i] = liveGuild.Info;
- }
- var mStream = new MemoryStream();
- var writer = new BinaryWriter(mStream);
- GuildList[i].Save(writer);
- var fStream = new FileStream(Path.Combine(Settings.GuildPath, i + ".mgdn"), FileMode.Create);
- var data = mStream.ToArray();
- fStream.BeginWrite(data, 0, data.Length, EndSaveGuildsAsync, fStream);
- }
- }
- }
- private void EndSaveGuildsAsync(IAsyncResult result)
- {
- var fStream = result.AsyncState as FileStream;
- try
- {
- if (fStream == null) return;
- var oldfilename = fStream.Name.Substring(0, fStream.Name.Length - 1);
- var newfilename = fStream.Name;
- fStream.EndWrite(result);
- fStream.Dispose();
- if (File.Exists(oldfilename))
- File.Move(oldfilename, oldfilename + "o");
- File.Move(newfilename, oldfilename);
- if (File.Exists(oldfilename + "o"))
- File.Delete(oldfilename + "o");
- }
- catch (Exception)
- {
- }
- }
- private void SaveGoods(bool forced = false)
- {
- if (!Directory.Exists(Settings.GoodsPath)) Directory.CreateDirectory(Settings.GoodsPath);
- for (var i = 0; i < MapList.Count; i++)
- {
- var map = MapList[i];
- if (map.NPCs.Count == 0) continue;
- for (var j = 0; j < map.NPCs.Count; j++)
- {
- var npc = map.NPCs[j];
- if (forced)
- {
- npc.ProcessGoods(forced);
- }
- if (!npc.NeedSave) continue;
- var path = Path.Combine(Settings.GoodsPath, npc.Info.Index + ".msdn");
- var mStream = new MemoryStream();
- var writer = new BinaryWriter(mStream);
- var Temp = 9999;
- writer.Write(Temp);
- writer.Write(Version);
- writer.Write(CustomVersion);
- writer.Write(npc.UsedGoods.Count);
- for (var k = 0; k < npc.UsedGoods.Count; k++)
- {
- npc.UsedGoods[k].Save(writer);
- }
- var fStream = new FileStream(path, FileMode.Create);
- var data = mStream.ToArray();
- fStream.BeginWrite(data, 0, data.Length, EndSaveGoodsAsync, fStream);
- }
- }
- }
- private void EndSaveGoodsAsync(IAsyncResult result)
- {
- try
- {
- var fStream = result.AsyncState as FileStream;
- if (fStream == null) return;
- var oldfilename = fStream.Name.Substring(0, fStream.Name.Length - 1);
- var newfilename = fStream.Name;
- fStream.EndWrite(result);
- fStream.Dispose();
- if (File.Exists(oldfilename))
- File.Move(oldfilename, oldfilename + "o");
- File.Move(newfilename, oldfilename);
- if (File.Exists(oldfilename + "o"))
- File.Delete(oldfilename + "o");
- }
- catch (Exception)
- {
- }
- }
- private void SaveConquests(bool forced = false)
- {
- if (!Directory.Exists(Settings.ConquestsPath)) Directory.CreateDirectory(Settings.ConquestsPath);
- for (var i = 0; i < ConquestList.Count; i++)
- {
- if (!ConquestList[i].NeedSave && !forced) continue;
- ConquestList[i].NeedSave = false;
- var mStream = new MemoryStream();
- var writer = new BinaryWriter(mStream);
- ConquestList[i].Save(writer);
- var fStream = new FileStream(Path.Combine(Settings.ConquestsPath, ConquestList[i].Info.Index + ".mcdn"), FileMode.Create);
- var data = mStream.ToArray();
- fStream.BeginWrite(data, 0, data.Length, EndSaveConquestsAsync, fStream);
- }
- }
- private void EndSaveConquestsAsync(IAsyncResult result)
- {
- var fStream = result.AsyncState as FileStream;
- try
- {
- if (fStream == null) return;
- var oldfilename = fStream.Name.Substring(0, fStream.Name.Length - 1);
- var newfilename = fStream.Name;
- fStream.EndWrite(result);
- fStream.Dispose();
- if (File.Exists(oldfilename))
- File.Move(oldfilename, oldfilename + "o");
- File.Move(newfilename, oldfilename);
- if (File.Exists(oldfilename + "o"))
- File.Delete(oldfilename + "o");
- }
- catch (Exception)
- {
- }
- }
- public void BeginSaveAccounts()
- {
- if (Saving) return;
- Saving = true;
- using (var mStream = new MemoryStream())
- {
- if (File.Exists(AccountPath))
- {
- if (!Directory.Exists(AccountsBackUpPath)) Directory.CreateDirectory(AccountsBackUpPath);
- var fileName =
- $"Accounts {Now.Year:0000}-{Now.Month:00}-{Now.Day:00} {Now.Hour:00}-{Now.Minute:00}-{Now.Second:00}.bak";
- if (File.Exists(Path.Combine(AccountsBackUpPath, fileName))) File.Delete(Path.Combine(AccountsBackUpPath, fileName));
- File.Move(AccountPath, Path.Combine(AccountsBackUpPath, fileName));
- }
- SaveAccounts(mStream);
- var fStream = new FileStream(AccountPath + "n", FileMode.Create);
- var data = mStream.ToArray();
- fStream.BeginWrite(data, 0, data.Length, EndSaveAccounts, fStream);
- }
- }
- private void EndSaveAccounts(IAsyncResult result)
- {
- var fStream = result.AsyncState as FileStream;
- try
- {
- if (fStream != null)
- {
- var oldfilename = fStream.Name.Substring(0, fStream.Name.Length - 1);
- var newfilename = fStream.Name;
- fStream.EndWrite(result);
- fStream.Dispose();
- if (File.Exists(oldfilename))
- File.Move(oldfilename, oldfilename + "o");
- File.Move(newfilename, oldfilename);
- if (File.Exists(oldfilename + "o"))
- File.Delete(oldfilename + "o");
- }
- }
- catch (Exception)
- {
- }
- Saving = false;
- }
- public bool LoadDB()
- {
- lock (LoadLock)
- {
- if (!File.Exists(DatabasePath))
- {
- SaveDB();
- }
- using (var stream = File.OpenRead(DatabasePath))
- using (var reader = new BinaryReader(stream))
- {
- LoadVersion = reader.ReadInt32();
- LoadCustomVersion = reader.ReadInt32();
- if (LoadVersion < MinVersion)
- {
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.CannotLoadDatabaseMinSupported), LoadVersion, MinVersion));
- return false;
- }
- else if (LoadVersion > Version)
- {
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.CannotLoadDatabaseMaxSupported), LoadVersion, Version));
- return false;
- }
- MapIndex = reader.ReadInt32();
- ItemIndex = reader.ReadInt32();
- MonsterIndex = reader.ReadInt32();
- NPCIndex = reader.ReadInt32();
- QuestIndex = reader.ReadInt32();
- if (LoadVersion >= 63)
- {
- GameshopIndex = reader.ReadInt32();
- }
- if (LoadVersion >= 66)
- {
- ConquestIndex = reader.ReadInt32();
- }
- if (LoadVersion >= 68)
- RespawnIndex = reader.ReadInt32();
- var count = reader.ReadInt32();
- MapInfoList.Clear();
- for (var i = 0; i < count; i++)
- MapInfoList.Add(new MapInfo(reader));
- count = reader.ReadInt32();
- ItemInfoList.Clear();
- for (var i = 0; i < count; i++)
- {
- ItemInfoList.Add(new ItemInfo(reader, LoadVersion, LoadCustomVersion));
- if (ItemInfoList[i] != null && ItemInfoList[i].RandomStatsId < Settings.RandomItemStatsList.Count)
- {
- ItemInfoList[i].RandomStats = Settings.RandomItemStatsList[ItemInfoList[i].RandomStatsId];
- }
- }
- count = reader.ReadInt32();
- MonsterInfoList.Clear();
- for (var i = 0; i < count; i++)
- MonsterInfoList.Add(new MonsterInfo(reader));
- count = reader.ReadInt32();
- NPCInfoList.Clear();
- for (var i = 0; i < count; i++)
- NPCInfoList.Add(new NPCInfo(reader));
- count = reader.ReadInt32();
- QuestInfoList.Clear();
- for (var i = 0; i < count; i++)
- QuestInfoList.Add(new QuestInfo(reader));
- DragonInfo = new DragonInfo(reader);
- count = reader.ReadInt32();
- for (var i = 0; i < count; i++)
- {
- var m = new MagicInfo(reader, LoadVersion, LoadCustomVersion);
- if (!MagicExists(m.Spell))
- MagicInfoList.Add(m);
- }
- FillMagicInfoList();
- if (LoadVersion <= 70)
- UpdateMagicInfo();
- if (LoadVersion >= 63)
- {
- count = reader.ReadInt32();
- GameShopList.Clear();
- for (var i = 0; i < count; i++)
- {
- var item = new GameShopItem(reader, LoadVersion, LoadCustomVersion);
- if (Main.BindGameShop(item))
- {
- GameShopList.Add(item);
- }
- }
- }
- if (LoadVersion >= 66)
- {
- ConquestInfoList.Clear();
- count = reader.ReadInt32();
- for (var i = 0; i < count; i++)
- {
- ConquestInfoList.Add(new ConquestInfo(reader));
- }
- }
- if (LoadVersion > 67)
- RespawnTick = new RespawnTimer(reader);
- }
- Settings.LinkGuildCreationItems(ItemInfoList);
- }
- return true;
- }
- public void LoadAccounts()
- {
- //reset ranking
- for (var i = 0; i < RankClass.Count(); i++)
- {
- if (RankClass[i] != null)
- {
- RankClass[i].Clear();
- }
- else
- {
- RankClass[i] = new List<RankCharacterInfo>();
- }
- }
- RankTop.Clear();
- lock (LoadLock)
- {
- if (!File.Exists(AccountPath))
- {
- SaveAccounts();
- }
- using (var stream = File.OpenRead(AccountPath))
- using (var reader = new BinaryReader(stream))
- {
- LoadVersion = reader.ReadInt32();
- LoadCustomVersion = reader.ReadInt32();
- NextAccountID = reader.ReadInt32();
- NextCharacterID = reader.ReadInt32();
- NextUserItemID = reader.ReadUInt64();
- if (LoadVersion > 98)
- NextHeroID = reader.ReadInt32();
- GuildCount = reader.ReadInt32();
- NextGuildID = reader.ReadInt32();
- int count;
- if (LoadVersion > 102)
- {
- count = reader.ReadInt32();
- HeroList.Clear();
- for (var i = 0; i < count; i++)
- HeroList.Add(new HeroInfo(reader, LoadVersion, LoadCustomVersion));
- }
- count = reader.ReadInt32();
- AccountList.Clear();
- CharacterList.Clear();
- int TrueAccount = 0;
- for (var i = 0; i < count; i++)
- {
- AccountInfo NextAccount = new AccountInfo(reader);
- if (i > 0 && NextAccount.Characters.Count == 0)
- continue;
- AccountList.Add(NextAccount);
- CharacterList.AddRange(AccountList[TrueAccount].Characters);
- if (LoadVersion > 98 && LoadVersion < 103)
- AccountList[TrueAccount].Characters.ForEach(character => HeroList.AddRange(character.Heroes));
- TrueAccount++;
- }
- foreach (var auction in Auctions)
- {
- auction.SellerInfo.AccountInfo.Auctions.Remove(auction);
- }
- Auctions.Clear();
- NextAuctionID = reader.ReadUInt64();
- count = reader.ReadInt32();
- for (var i = 0; i < count; i++)
- {
- var auction = new AuctionInfo(reader, LoadVersion, LoadCustomVersion);
- if (!BindItem(auction.Item) || !BindCharacter(auction)) continue;
- Auctions.AddLast(auction);
- auction.SellerInfo.AccountInfo.Auctions.AddLast(auction);
- }
- NextMailID = reader.ReadUInt64();
- if (LoadVersion <= 80)
- {
- count = reader.ReadInt32();
- for (var i = 0; i < count; i++)
- {
- var mail = new MailInfo(reader, LoadVersion, LoadCustomVersion);
- mail.RecipientInfo = GetCharacterInfo(mail.RecipientIndex);
- if (mail.RecipientInfo != null)
- {
- mail.RecipientInfo.Mail.Add(mail); //add to players inbox
- }
- }
- }
- if (LoadVersion >= 63)
- {
- var logCount = reader.ReadInt32();
- for (var i = 0; i < logCount; i++)
- {
- GameshopLog.Add(reader.ReadInt32(), reader.ReadInt32());
- }
- if (ResetGS) ClearGameshopLog();
- }
- if (LoadVersion >= 68)
- {
- var saveCount = reader.ReadInt32();
- for (var i = 0; i < saveCount; i++)
- {
- var saved = new RespawnSave(reader);
- foreach (var respawn in SavedSpawns)
- {
- if (respawn.Info.RespawnIndex != saved.RespawnIndex) continue;
- respawn.NextSpawnTick = saved.NextSpawnTick;
- if (!saved.Spawned || respawn.Info.Count * SpawnMultiplier <= respawn.Count)
- {
- continue;
- }
- var mobcount = respawn.Info.Count * SpawnMultiplier - respawn.Count;
- for (var j = 0; j < mobcount; j++)
- {
- respawn.Spawn();
- }
- }
- }
- }
- }
- }
- }
- public void LoadGuilds()
- {
- lock (LoadLock)
- {
- var count = 0;
- GuildList.Clear();
- for (var i = 0; i < GuildCount; i++)
- {
- GuildInfo guildInfo;
- if (!File.Exists(Path.Combine(Settings.GuildPath, i + ".mgd"))) continue;
- using (var stream = File.OpenRead(Path.Combine(Settings.GuildPath, i + ".mgd")))
- {
- using var reader = new BinaryReader(stream);
- guildInfo = new GuildInfo(reader);
- }
- GuildList.Add(guildInfo);
- new GuildObject(guildInfo);
- count++;
- }
- if (count != GuildCount) GuildCount = count;
- }
- }
- public void LoadConquests()
- {
- lock (LoadLock)
- {
- Conquests.Clear();
- ConquestList.Clear();
- for (var i = 0; i < ConquestInfoList.Count; i++)
- {
- ConquestObject newConquest;
- ConquestGuildInfo conquestGuildInfo;
- var tempMap = GetMap(ConquestInfoList[i].MapIndex);
- if (tempMap == null) continue;
- if (File.Exists(Path.Combine(Settings.ConquestsPath, ConquestInfoList[i].Index + ".mcd")))
- {
- using (var stream = File.OpenRead(Path.Combine(Settings.ConquestsPath, ConquestInfoList[i].Index + ".mcd")))
- {
- using var reader = new BinaryReader(stream);
- conquestGuildInfo = new ConquestGuildInfo(reader) { Info = ConquestInfoList[i] };
- }
- newConquest = new ConquestObject(conquestGuildInfo)
- {
- ConquestMap = tempMap
- };
- for (var k = 0; k < Guilds.Count; k++)
- {
- if (conquestGuildInfo.Owner != Guilds[k].Guildindex) continue;
- newConquest.Guild = Guilds[k];
- Guilds[k].Conquest = newConquest;
- }
- }
- else
- {
- conquestGuildInfo = new ConquestGuildInfo { Info = ConquestInfoList[i], NeedSave = true };
- newConquest = new ConquestObject(conquestGuildInfo)
- {
- ConquestMap = tempMap
- };
- }
- ConquestList.Add(conquestGuildInfo);
- Conquests.Add(newConquest);
- tempMap.Conquest.Add(newConquest);
- newConquest.Bind();
- }
- }
- }
- private void LoadGTInfo()
- {
- foreach (var gt in GTMapList)
- {
- var Guild = GuildList.FirstOrDefault(x => x.GTIndex == gt.Index);
- if (Guild != null)
- {
- gt.Owner = Guild.Name;
- if (Guild.Ranks.Count > 0 && Guild.Ranks[0] != null && Guild.Ranks[0].Members.Count > 0 && Guild.Ranks[0].Members[0] != null)
- gt.Leader = Guild.Ranks[0].Members[0].Name;
- gt.Price = 0;
- gt.Days = (Now - Guild.GTRent).Days;
- }
- }
- }
- public void LoadDisabledChars()
- {
- DisabledCharNames.Clear();
- var path = Path.Combine(Settings.EnvirPath, "DisabledChars.txt");
- if (!File.Exists(path))
- {
- File.WriteAllText(path, "");
- }
- else
- {
- var lines = File.ReadAllLines(path);
- for (var i = 0; i < lines.Length; i++)
- {
- if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i])) continue;
- DisabledCharNames.Add(lines[i].ToUpper());
- }
- }
- }
- public void LoadLineMessages()
- {
- LineMessages.Clear();
- var path = Path.Combine(Settings.EnvirPath, "LineMessage.txt");
- if (!File.Exists(path))
- {
- File.WriteAllText(path, "");
- }
- else
- {
- var lines = File.ReadAllLines(path);
- for (var i = 0; i < lines.Length; i++)
- {
- if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i])) continue;
- LineMessages.Add(lines[i]);
- }
- }
- }
- private bool BindCharacter(AuctionInfo auction)
- {
- bool bound = false;
- for (int i = 0; i < CharacterList.Count; i++)
- {
- if (CharacterList[i].Index == auction.SellerIndex)
- {
- auction.SellerInfo = CharacterList[i];
- bound = true;
- }
- else if (CharacterList[i].Index == auction.CurrentBuyerIndex)
- {
- auction.CurrentBuyerInfo = CharacterList[i];
- bound = true;
- }
- }
- return bound;
- }
- public void Start()
- {
- if (Running || _thread != null) return;
- Running = true;
- _thread = new Thread(WorkLoop) { IsBackground = true };
- _thread.Start();
- }
- public void Stop()
- {
- Running = false;
- lock (_locker)
- {
- // changing a blocking condition. (this makes the threads wake up!)
- Monitor.PulseAll(_locker);
- }
- //simply intterupt all the mob threads if they are running (will give an invisible error on them but fastest way of getting rid of them on shutdowns)
- for (var i = 1; i < MobThreading.Length; i++)
- {
- if (MobThreads[i] != null)
- {
- MobThreads[i].EndTime = Time + 9999;
- }
- if (MobThreading[i] != null &&
- MobThreading[i].ThreadState != System.Threading.ThreadState.Stopped && MobThreading[i].ThreadState != System.Threading.ThreadState.Unstarted)
- {
- MobThreading[i].Interrupt();
- }
- }
- http?.Stop();
- while (_thread != null)
- Thread.Sleep(1);
- }
- public void Reboot()
- {
- new Thread(() =>
- {
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.ServerRebooting));
- Stop();
- Start();
- }).Start();
- }
- public void UpdateIPBlock(string ipAddress, TimeSpan value)
- {
- IPBlocks[ipAddress] = Now.Add(value);
- }
- private void StartEnvir()
- {
- Players.Clear();
- StartPoints.Clear();
- StartItems.Clear();
- MapList.Clear();
- GTMapList.Clear();
- GameshopLog.Clear();
- CustomCommands.Clear();
- Heroes.Clear();
- MonsterCount = 0;
- LoadDB();
- BuffInfoList.Clear();
- foreach (var buff in BuffInfo.Load())
- {
- BuffInfoList.Add(buff);
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.BuffsLoaded), BuffInfoList.Count));
- RecipeInfoList.Clear();
- foreach (var recipe in Directory.GetFiles(Settings.RecipePath, "*.txt")
- .Select(path => Path.GetFileNameWithoutExtension(path))
- .ToArray())
- {
- RecipeInfoList.Add(new RecipeInfo(recipe));
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.RecipesLoaded), RecipeInfoList.Count));
- for (var i = 0; i < MapInfoList.Count; i++)
- {
- // Call CreateMap(), which adds the map to Envir.MapList
- MapInfoList[i].CreateMap();
- // Fetch the created map from Envir.MapList
- Map map = MapList.FirstOrDefault(m => m.Info == MapInfoList[i]);
- if (map != null)
- {
- if (MapInfoList[i].GT)
- {
- GTMap gt = GTMapList.FirstOrDefault(x => x.Index == MapInfoList[i].GTIndex);
- if (gt != null)
- {
- gt.Maps.Add(map);
- }
- else
- {
- var GT = new GTMap()
- {
- Index = MapInfoList[i].GTIndex,
- Name = MapInfoList[i].Title,
- Price = Settings.BuyGTGold,
- Days = 0,
- Begin = 0,
- Leader = "None",
- Owner = "None",
- };
- GT.Maps.Add(map);
- GTMapList.Add(GT);
- }
- }
- }
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.MapsLoaded), MapInfoList.Count));
- for (var i = 0; i < ItemInfoList.Count; i++)
- {
- if (ItemInfoList[i].StartItem)
- {
- StartItems.Add(ItemInfoList[i]);
- }
- }
- ReloadDrops();
- LoadDisabledChars();
- LoadLineMessages();
- if (DragonInfo.Enabled)
- {
- DragonSystem = new Dragon(DragonInfo);
- if (DragonSystem != null)
- {
- if (DragonSystem.Load()) DragonSystem.Info.LoadDrops();
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.DragonLoaded));
- }
- DefaultNPC = NPCScript.GetOrAdd((uint)Random.Next(1000000, 1999999), Settings.DefaultNPCFilename, NPCScriptType.AutoPlayer);
- MonsterNPC = NPCScript.GetOrAdd((uint)Random.Next(2000000, 2999999), Settings.MonsterNPCFilename, NPCScriptType.AutoMonster);
- RobotNPC = NPCScript.GetOrAdd((uint)Random.Next(3000000, 3999999), Settings.RobotNPCFilename, NPCScriptType.Robot);
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.EnvirStarted));
- }
-
- private void StartNetwork()
- {
- Connections.Clear();
- LoadAccounts();
- LoadGuilds();
- LoadConquests();
- LoadGTInfo();
- _listener = new TcpListener(IPAddress.Parse(Settings.IPAddress), Settings.Port);
- _listener.Start();
- _listener.BeginAcceptTcpClient(Connection, null);
- if (StatusPortEnabled)
- {
- _StatusPort = new TcpListener(IPAddress.Parse(Settings.IPAddress), 3000);
- _StatusPort.Start();
- _StatusPort.BeginAcceptTcpClient(StatusConnection, null);
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.NetworkStarted));
- }
- private void StopEnvir()
- {
- SaveGoods(true);
- MapList.Clear();
- StartPoints.Clear();
- StartItems.Clear();
- Objects.Clear();
- Players.Clear();
- Heroes.Clear();
- GTMapList.Clear();
- CleanUp();
- GC.Collect();
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.EnvirStopped));
- }
- private void StopNetwork()
- {
- _listener.Stop();
- lock (Connections)
- {
- for (var i = Connections.Count - 1; i >= 0; i--)
- Connections[i].SendDisconnect(0);
- }
- if (StatusPortEnabled)
- {
- _StatusPort.Stop();
- for (var i = StatusConnections.Count - 1; i >= 0; i--)
- StatusConnections[i].SendDisconnect();
- }
- var expire = Time + 5000;
- while (Connections.Count != 0 && Stopwatch.ElapsedMilliseconds < expire)
- {
- Time = Stopwatch.ElapsedMilliseconds;
- for (var i = Connections.Count - 1; i >= 0; i--)
- Connections[i].Process();
- Thread.Sleep(1);
- }
- Connections.Clear();
- expire = Time + 10000;
- while (StatusConnections.Count != 0 && Stopwatch.ElapsedMilliseconds < expire)
- {
- Time = Stopwatch.ElapsedMilliseconds;
- for (var i = StatusConnections.Count - 1; i >= 0; i--)
- StatusConnections[i].Process();
- Thread.Sleep(1);
- }
- StatusConnections.Clear();
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.NetworkStopped));
- }
- private void CleanUp()
- {
- for (var i = 0; i < CharacterList.Count; i++)
- {
- var info = CharacterList[i];
- if (info.Deleted)
- {
- #region Mentor Cleanup
- if (info.Mentor > 0)
- {
- var mentor = GetCharacterInfo(info.Mentor);
- if (mentor != null)
- {
- mentor.Mentor = 0;
- mentor.MentorExp = 0;
- mentor.IsMentor = false;
- }
- info.Mentor = 0;
- info.MentorExp = 0;
- info.IsMentor = false;
- }
- #endregion
- #region Marriage Cleanup
- if (info.Married > 0)
- {
- var Lover = GetCharacterInfo(info.Married);
- info.Married = 0;
- info.MarriedDate = Now;
- Lover.Married = 0;
- Lover.MarriedDate = Now;
- if (Lover.Equipment[(int)EquipmentSlot.RingL] != null)
- Lover.Equipment[(int)EquipmentSlot.RingL].WeddingRing = -1;
- }
- #endregion
- }
- if (info.Mail.Count > Settings.MailCapacity)
- {
- for (var j = info.Mail.Count - 1 - (int)Settings.MailCapacity; j >= 0; j--)
- {
- if (info.Mail[j].DateOpened > Now && info.Mail[j].Collected && info.Mail[j].Items.Count == 0 && info.Mail[j].Gold == 0)
- {
- info.Mail.Remove(info.Mail[j]);
- }
- }
- }
- }
- }
- private void Connection(IAsyncResult result)
- {
- try
- {
- if (!Running || !_listener.Server.IsBound) return;
- }
- catch (Exception e)
- {
- MessageQueue.Enqueue(e.ToString());
- }
- try
- {
- var tempTcpClient = _listener.EndAcceptTcpClient(result);
- bool connected = false;
- var ipAddress = tempTcpClient.Client.RemoteEndPoint.ToString().Split(':')[0];
- if (!IPBlocks.TryGetValue(ipAddress, out DateTime banDate) || banDate < Now)
- {
- int count = 0;
- for (int i = 0; i < Connections.Count; i++)
- {
- var connection = Connections[i];
- if (!connection.Connected || connection.IPAddress != ipAddress)
- continue;
- count++;
- }
- if (count >= Settings.MaxIP)
- {
- UpdateIPBlock(ipAddress, TimeSpan.FromSeconds(Settings.IPBlockSeconds));
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.IpAddressDisconnectedTooManyConnections), ipAddress));
- }
- else
- {
- var tempConnection = new MirConnection(++_sessionID, tempTcpClient);
- if (tempConnection.Connected)
- {
- connected = true;
- lock (Connections)
- Connections.Add(tempConnection);
- }
- }
- }
- if (!connected)
- tempTcpClient.Close();
- }
- catch (Exception ex)
- {
- MessageQueue.Enqueue(ex);
- }
- finally
- {
- while (Connections.Count >= Settings.MaxUser)
- Thread.Sleep(1);
- if (Running && _listener.Server.IsBound)
- _listener.BeginAcceptTcpClient(Connection, null);
- }
- }
- private void StatusConnection(IAsyncResult result)
- {
- if (!Running || !_StatusPort.Server.IsBound) return;
- try
- {
- var tempTcpClient = _StatusPort.EndAcceptTcpClient(result);
- lock (StatusConnections)
- StatusConnections.Add(new MirStatusConnection(tempTcpClient));
- }
- catch (Exception ex)
- {
- MessageQueue.Enqueue(ex);
- }
- finally
- {
- while (StatusConnections.Count >= 5) //dont allow to many status port connections it's just an abuse thing
- Thread.Sleep(1);
- if (Running && _StatusPort.Server.IsBound)
- _StatusPort.BeginAcceptTcpClient(StatusConnection, null);
- }
- }
- public void NewAccount(ClientPackets.NewAccount p, MirConnection c)
- {
- if (!Settings.AllowNewAccount)
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 0 });
- return;
- }
- if (ConnectionLogs.TryGetValue(c.IPAddress, out MirConnectionLog currentlog))
- {
- if (currentlog.AccountsMade.Count > 2)
- {
- IPBlocks[c.IPAddress] = Now.AddHours(24);
- c.Enqueue(new ServerPackets.NewAccount { Result = 0 });
- return;
- }
- currentlog.AccountsMade.Add(Time);
- for (int i = 0; i < currentlog.AccountsMade.Count; i++)
- {
- if ((currentlog.AccountsMade[i] + 60 * 60 * 1000) < Time)
- {
- currentlog.AccountsMade.RemoveAt(i);
- break;
- }
- }
- }
- else
- {
- ConnectionLogs[c.IPAddress] = new MirConnectionLog() { IPAddress = c.IPAddress };
- }
- if (!AccountIDReg.IsMatch(p.AccountID))
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 1 });
- return;
- }
- if (!PasswordReg.IsMatch(p.Password))
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 2 });
- return;
- }
- if (!string.IsNullOrWhiteSpace(p.EMailAddress) && !EMailReg.IsMatch(p.EMailAddress) ||
- p.EMailAddress.Length > 50)
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 3 });
- return;
- }
- if (!string.IsNullOrWhiteSpace(p.UserName) && p.UserName.Length > 20)
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 4 });
- return;
- }
- if (!string.IsNullOrWhiteSpace(p.SecretQuestion) && p.SecretQuestion.Length > 30)
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 5 });
- return;
- }
- if (!string.IsNullOrWhiteSpace(p.SecretAnswer) && p.SecretAnswer.Length > 30)
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 6 });
- return;
- }
- lock (AccountLock)
- {
- if (AccountExists(p.AccountID))
- {
- c.Enqueue(new ServerPackets.NewAccount { Result = 7 });
- return;
- }
- AccountList.Add(new AccountInfo(p) { Index = ++NextAccountID, CreationIP = c.IPAddress });
- c.Enqueue(new ServerPackets.NewAccount { Result = 8 });
- }
- }
- public int HTTPNewAccount(ClientPackets.NewAccount p, string ip)
- {
- if (!Settings.AllowNewAccount)
- {
- return 0;
- }
- if (!AccountIDReg.IsMatch(p.AccountID))
- {
- return 1;
- }
- if (!PasswordReg.IsMatch(p.Password))
- {
- return 2;
- }
- if (!string.IsNullOrWhiteSpace(p.EMailAddress) && !EMailReg.IsMatch(p.EMailAddress) ||
- p.EMailAddress.Length > 50)
- {
- return 3;
- }
- if (!string.IsNullOrWhiteSpace(p.UserName) && p.UserName.Length > 20)
- {
- return 4;
- }
- if (!string.IsNullOrWhiteSpace(p.SecretQuestion) && p.SecretQuestion.Length > 30)
- {
- return 5;
- }
- if (!string.IsNullOrWhiteSpace(p.SecretAnswer) && p.SecretAnswer.Length > 30)
- {
- return 6;
- }
- lock (AccountLock)
- {
- if (AccountExists(p.AccountID))
- {
- return 7;
- }
- AccountList.Add(new AccountInfo(p) { Index = ++NextAccountID, CreationIP = ip });
- return 8;
- }
- }
- public void ChangePassword(ClientPackets.ChangePassword p, MirConnection c)
- {
- if (!Settings.AllowChangePassword)
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 0 });
- return;
- }
- if (!AccountIDReg.IsMatch(p.AccountID))
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 1 });
- return;
- }
- if (!PasswordReg.IsMatch(p.CurrentPassword))
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 2 });
- return;
- }
- if (!PasswordReg.IsMatch(p.NewPassword))
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 3 });
- return;
- }
- var account = GetAccount(p.AccountID);
- if (account == null)
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 4 });
- return;
- }
- if (account.Banned)
- {
- if (account.ExpiryDate > Now)
- {
- c.Enqueue(new ServerPackets.ChangePasswordBanned { Reason = account.BanReason, ExpiryDate = account.ExpiryDate });
- return;
- }
- account.Banned = false;
- }
- account.BanReason = string.Empty;
- account.ExpiryDate = DateTime.MinValue;
- p.CurrentPassword = Utils.Crypto.HashPassword(p.CurrentPassword, account.Salt);
- if (string.CompareOrdinal(account.Password, p.CurrentPassword) != 0)
- {
- c.Enqueue(new ServerPackets.ChangePassword { Result = 5 });
- return;
- }
- account.Password = p.NewPassword;
- account.RequirePasswordChange = false;
- c.Enqueue(new ServerPackets.ChangePassword { Result = 6 });
- }
- public void Login(ClientPackets.Login p, MirConnection c)
- {
- if (!Settings.AllowLogin)
- {
- c.Enqueue(new ServerPackets.Login { Result = 0 });
- return;
- }
- if (!AccountIDReg.IsMatch(p.AccountID))
- {
- c.Enqueue(new ServerPackets.Login { Result = 1 });
- return;
- }
- if (!PasswordReg.IsMatch(p.Password))
- {
- c.Enqueue(new ServerPackets.Login { Result = 2 });
- return;
- }
- var account = GetAccount(p.AccountID);
- if (account == null)
- {
- c.Enqueue(new ServerPackets.Login { Result = 3 });
- return;
- }
- if (account.Banned)
- {
- if (account.ExpiryDate > Now)
- {
- c.Enqueue(new ServerPackets.LoginBanned
- {
- Reason = account.BanReason,
- ExpiryDate = account.ExpiryDate
- });
- return;
- }
- account.Banned = false;
- }
- account.BanReason = string.Empty;
- account.ExpiryDate = DateTime.MinValue;
- p.Password = Utils.Crypto.HashPassword(p.Password, account.Salt);
- if (string.CompareOrdinal(account.Password, p.Password) != 0)
- {
- if (account.WrongPasswordCount++ >= 5)
- {
- account.Banned = true;
- account.BanReason = GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.TooManyWrongLoginAttempts);
- account.ExpiryDate = Now.AddMinutes(2);
- c.Enqueue(new ServerPackets.LoginBanned
- {
- Reason = account.BanReason,
- ExpiryDate = account.ExpiryDate
- });
- return;
- }
- c.Enqueue(new ServerPackets.Login { Result = 4 });
- return;
- }
- account.WrongPasswordCount = 0;
- if (account.RequirePasswordChange)
- {
- c.Enqueue(new ServerPackets.Login { Result = 5 });
- return;
- }
- lock (AccountLock)
- {
- account.Connection?.SendDisconnect(1);
- account.Connection = c;
- }
- c.Account = account;
- c.Stage = GameStage.Select;
- account.LastDate = Now;
- account.LastIP = c.IPAddress;
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.UserLoggedIn), account.Connection.SessionID, account.Connection.IPAddress));
- c.Enqueue(new ServerPackets.LoginSuccess { Characters = account.GetSelectInfo() });
- }
- public int HTTPLogin(string AccountID, string Password)
- {
- if (!Settings.AllowLogin)
- {
- return 0;
- }
- if (!AccountIDReg.IsMatch(AccountID))
- {
- return 1;
- }
- if (!PasswordReg.IsMatch(Password))
- {
- return 2;
- }
- var account = GetAccount(AccountID);
- if (account == null)
- {
- return 3;
- }
- if (account.Banned)
- {
- if (account.ExpiryDate > Now)
- {
- return 4;
- }
- account.Banned = false;
- }
- account.BanReason = string.Empty;
- account.ExpiryDate = DateTime.MinValue;
- if (string.CompareOrdinal(account.Password, Password) != 0)
- {
- if (account.WrongPasswordCount++ >= 5)
- {
- account.Banned = true;
- account.BanReason = GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.TooManyWrongLoginAttempts);
- account.ExpiryDate = Now.AddMinutes(2);
- return 5;
- }
- return 6;
- }
- account.WrongPasswordCount = 0;
- return 7;
- }
- public void NewCharacter(ClientPackets.NewCharacter p, MirConnection c, bool IsGm)
- {
- if (!Settings.AllowNewCharacter)
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 0 });
- return;
- }
- if (ConnectionLogs.TryGetValue(c.IPAddress, out MirConnectionLog currentlog))
- {
- if (currentlog.CharactersMade.Count > 4)
- {
- IPBlocks[c.IPAddress] = Now.AddHours(24);
- c.Enqueue(new ServerPackets.NewCharacter { Result = 0 });
- return;
- }
- currentlog.CharactersMade.Add(Time);
- for (int i = 0; i < currentlog.CharactersMade.Count; i++)
- {
- if ((currentlog.CharactersMade[i] + 60 * 60 * 1000) < Time)
- {
- currentlog.CharactersMade.RemoveAt(i);
- break;
- }
- }
- }
- else
- {
- ConnectionLogs[c.IPAddress] = new MirConnectionLog() { IPAddress = c.IPAddress };
- }
- if (!CharacterReg.IsMatch(p.Name))
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 1 });
- return;
- }
- if (!IsGm && DisabledCharNames.Contains(p.Name.ToUpper()))
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 1 });
- return;
- }
- if (p.Gender != MirGender.Male && p.Gender != MirGender.Female)
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 2 });
- return;
- }
- if (p.Class != MirClass.Warrior && p.Class != MirClass.Wizard && p.Class != MirClass.Taoist &&
- p.Class != MirClass.Assassin && p.Class != MirClass.Archer)
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 3 });
- return;
- }
- if (p.Class == MirClass.Assassin && !Settings.AllowCreateAssassin ||
- p.Class == MirClass.Archer && !Settings.AllowCreateArcher)
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 3 });
- return;
- }
- var count = 0;
- for (var i = 0; i < c.Account.Characters.Count; i++)
- {
- if (c.Account.Characters[i].Deleted) continue;
- if (++count >= Globals.MaxCharacterCount)
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 4 });
- return;
- }
- }
- lock (AccountLock)
- {
- if (CharacterExists(p.Name))
- {
- c.Enqueue(new ServerPackets.NewCharacter { Result = 5 });
- return;
- }
- var info = new CharacterInfo(p, c) { Index = ++NextCharacterID, AccountInfo = c.Account };
- c.Account.Characters.Add(info);
- CharacterList.Add(info);
- c.Enqueue(new ServerPackets.NewCharacterSuccess { CharInfo = info.ToSelectInfo() });
- }
- }
- public bool CanCreateHero(ClientPackets.NewHero p, MirConnection c, bool IsGm)
- {
- if (!Settings.AllowNewHero)
- {
- c.Enqueue(new S.NewHero { Result = 0 });
- return false;
- }
- if (!CharacterReg.IsMatch(p.Name))
- {
- c.Enqueue(new S.NewHero { Result = 1 });
- return false;
- }
- if (!IsGm && DisabledCharNames.Contains(p.Name.ToUpper()))
- {
- c.Enqueue(new S.NewHero { Result = 1 });
- return false;
- }
- if (p.Gender != MirGender.Male && p.Gender != MirGender.Female)
- {
- c.Enqueue(new S.NewHero { Result = 2 });
- return false;
- }
- if (p.Class != MirClass.Warrior && p.Class != MirClass.Wizard && p.Class != MirClass.Taoist && p.Class != MirClass.Assassin && p.Class != MirClass.Archer)
- {
- c.Enqueue(new S.NewHero { Result = 3 });
- return false;
- }
- if (p.Class == MirClass.Warrior && !Settings.Hero_CanCreateClass[0] || p.Class == MirClass.Wizard && !Settings.Hero_CanCreateClass[1] || p.Class == MirClass.Taoist && !Settings.Hero_CanCreateClass[2] || p.Class == MirClass.Assassin && !Settings.Hero_CanCreateClass[3] || p.Class == MirClass.Archer && !Settings.Hero_CanCreateClass[4])
- {
- c.Enqueue(new S.NewHero { Result = 3 });
- return false;
- }
- lock (AccountLock)
- {
- if (CharacterExists(p.Name))
- {
- c.Enqueue(new S.NewHero { Result = 5 });
- return false;
- }
- }
- return true;
- }
- public bool AccountExists(string accountID)
- {
- for (var i = 0; i < AccountList.Count; i++)
- if (string.Compare(AccountList[i].AccountID, accountID, StringComparison.OrdinalIgnoreCase) == 0)
- return true;
- return false;
- }
- public bool CharacterExists(string name)
- {
- for (var i = 0; i < CharacterList.Count; i++)
- if (string.Compare(CharacterList[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
- return true;
- return false;
- }
- public List<CharacterInfo> MatchPlayer(string PlayerID, bool match = false)
- {
- if (string.IsNullOrEmpty(PlayerID)) return new List<CharacterInfo>(CharacterList);
- List<CharacterInfo> list = new List<CharacterInfo>();
- for (int i = 0; i < CharacterList.Count; i++)
- {
- if (match)
- {
- if (CharacterList[i].Name.Equals(PlayerID, StringComparison.OrdinalIgnoreCase))
- list.Add(CharacterList[i]);
- }
- else
- {
- if (CharacterList[i].Name.IndexOf(PlayerID, StringComparison.OrdinalIgnoreCase) >= 0)
- list.Add(CharacterList[i]);
- }
- }
- return list;
- }
- public List<CharacterInfo> MatchPlayerbyItem(string itemIdentifier, bool match = false)
- {
- List<CharacterInfo> list = new List<CharacterInfo>();
- bool isNumeric = ulong.TryParse(itemIdentifier, out ulong itemId);
- for (int i = 0; i < CharacterList.Count; i++)
- {
- if (match)
- {
- foreach (var item in CharacterList[i].Inventory)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.Equals(itemIdentifier, StringComparison.OrdinalIgnoreCase))) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].AccountInfo.Storage)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.Equals(itemIdentifier, StringComparison.OrdinalIgnoreCase))) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].QuestInventory)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.Equals(itemIdentifier, StringComparison.OrdinalIgnoreCase))) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].Equipment)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.Equals(itemIdentifier, StringComparison.OrdinalIgnoreCase))) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var mail in CharacterList[i].Mail)
- foreach (var item in mail.Items)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.Equals(itemIdentifier, StringComparison.OrdinalIgnoreCase))) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- }
- else
- {
- foreach (var item in CharacterList[i].Inventory)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.IndexOf(itemIdentifier, StringComparison.OrdinalIgnoreCase) >= 0)) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].QuestInventory)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.IndexOf(itemIdentifier, StringComparison.OrdinalIgnoreCase) >= 0)) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].Equipment)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.IndexOf(itemIdentifier, StringComparison.OrdinalIgnoreCase) >= 0)) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- foreach (var item in CharacterList[i].AccountInfo.Storage)
- if (item != null && ((isNumeric && item.UniqueID == itemId) || (!isNumeric && item.FriendlyName.IndexOf(itemIdentifier, StringComparison.OrdinalIgnoreCase) >= 0)) && !list.Contains(CharacterList[i]))
- list.Add(CharacterList[i]);
- }
- }
- return list;
- }
- public AccountInfo GetAccount(string accountID)
- {
- for (var i = 0; i < AccountList.Count; i++)
- if (string.Compare(AccountList[i].AccountID, accountID, StringComparison.OrdinalIgnoreCase) == 0)
- return AccountList[i];
- return null;
- }
- public AccountInfo GetAccountByCharacter(string name)
- {
- for (var i = 0; i < AccountList.Count; i++)
- {
- for (int j = 0; j < AccountList[i].Characters.Count; j++)
- {
- if (string.Compare(AccountList[i].Characters[j].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
- return AccountList[i];
- }
- }
- return null;
- }
- public List<AccountInfo> MatchAccounts(string accountID, bool match = false)
- {
- if (string.IsNullOrEmpty(accountID)) return new List<AccountInfo>(AccountList);
- var list = new List<AccountInfo>();
- for (var i = 0; i < AccountList.Count; i++)
- {
- if (match)
- {
- if (AccountList[i].AccountID.Equals(accountID, StringComparison.OrdinalIgnoreCase))
- list.Add(AccountList[i]);
- }
- else
- {
- if (AccountList[i].AccountID.IndexOf(accountID, StringComparison.OrdinalIgnoreCase) >= 0)
- list.Add(AccountList[i]);
- }
- }
- return list;
- }
- public List<AccountInfo> MatchAccountsByPlayer(string playerName, bool match = false)
- {
- if (string.IsNullOrEmpty(playerName)) return new List<AccountInfo>(AccountList);
- var list = new List<AccountInfo>();
- for (var i = 0; i < AccountList.Count; i++)
- {
- for (var j = 0; j < AccountList[i].Characters.Count; j++)
- {
- if (match)
- {
- if (AccountList[i].Characters[j].Name.Equals(playerName, StringComparison.OrdinalIgnoreCase))
- list.Add(AccountList[i]);
- }
- else
- {
- if (AccountList[i].Characters[j].Name.IndexOf(playerName, StringComparison.OrdinalIgnoreCase) >= 0)
- list.Add(AccountList[i]);
- }
- }
- }
- return list;
- }
- public List<AccountInfo> MatchAccountsByIP(string ipAddress, bool matchLastIP = false, bool match = false)
- {
- if (string.IsNullOrEmpty(ipAddress)) return new List<AccountInfo>(AccountList);
- var list = new List<AccountInfo>();
- for (var i = 0; i < AccountList.Count; i++)
- {
- string ipToMatch = matchLastIP ? AccountList[i].LastIP : AccountList[i].CreationIP;
- if (match)
- {
- if (ipToMatch.Equals(ipAddress, StringComparison.OrdinalIgnoreCase))
- list.Add(AccountList[i]);
- }
- else
- {
- if (ipToMatch.IndexOf(ipAddress, StringComparison.OrdinalIgnoreCase) >= 0)
- list.Add(AccountList[i]);
- }
- }
- return list;
- }
- public void CreateAccountInfo()
- {
- AccountList.Add(new AccountInfo { Index = ++NextAccountID });
- }
- public void CreateMapInfo()
- {
- MapInfoList.Add(new MapInfo { Index = ++MapIndex });
- }
- public void CreateItemInfo(ItemType type = ItemType.Nothing)
- {
- ItemInfoList.Add(new ItemInfo { Index = ++ItemIndex, Type = type, RandomStatsId = 255 });
- }
- public void CreateMonsterInfo()
- {
- MonsterInfoList.Add(new MonsterInfo { Index = ++MonsterIndex });
- }
- public void CreateNPCInfo()
- {
- NPCInfoList.Add(new NPCInfo { Index = ++NPCIndex });
- }
- public void CreateQuestInfo()
- {
- QuestInfoList.Add(new QuestInfo { Index = ++QuestIndex });
- }
- public void AddToGameShop(ItemInfo Info)
- {
- GameShopList.Add(new GameShopItem
- {
- GIndex = ++GameshopIndex,
- GoldPrice = (uint)(1000 * Settings.CredxGold),
- CreditPrice = 1000,
- ItemIndex = Info.Index,
- Info = Info,
- Date = Now,
- Class = "All",
- Category = Info.Type.ToString()
- });
- }
- public void Remove(MapInfo info)
- {
- MapInfoList.Remove(info);
- //Desync all objects\
- }
- public void Remove(ItemInfo info)
- {
- ItemInfoList.Remove(info);
- }
- public void Remove(MonsterInfo info)
- {
- MonsterInfoList.Remove(info);
- //Desync all objects\
- }
- public void Remove(NPCInfo info)
- {
- NPCInfoList.Remove(info);
- //Desync all objects\
- }
- public void Remove(QuestInfo info)
- {
- QuestInfoList.Remove(info);
- //Desync all objects\
- }
- public void Remove(GameShopItem info)
- {
- GameShopList.Remove(info);
- if (GameShopList.Count == 0)
- {
- GameshopIndex = 0;
- }
- //Desync all objects\
- }
- public UserItem CreateFreshItem(ItemInfo info)
- {
- var item = new UserItem(info)
- {
- UniqueID = ++NextUserItemID,
- CurrentDura = info.Durability,
- MaxDura = info.Durability
- };
- UpdateItemExpiry(item);
- return item;
- }
- public UserItem CreateDropItem(int index)
- {
- return CreateDropItem(GetItemInfo(index));
- }
- public UserItem CreateDropItem(ItemInfo info)
- {
- if (info == null) return null;
- var item = new UserItem(info)
- {
- UniqueID = ++NextUserItemID,
- MaxDura = info.Durability,
- CurrentDura = (ushort)Math.Min(info.Durability, Random.Next(info.Durability) + 1000)
- };
- UpgradeItem(item);
- UpdateItemExpiry(item);
- if (!info.NeedIdentify) item.Identified = true;
- return item;
- }
- public UserItem CreateShopItem(ItemInfo info, ulong id)
- {
- if (info == null) return null;
- var item = new UserItem(info)
- {
- UniqueID = id,
- CurrentDura = info.Durability,
- MaxDura = info.Durability,
- IsShopItem = true,
- };
- return item;
- }
- public void UpdateItemExpiry(UserItem item)
- {
- var expiryInfo = new ExpireInfo();
- var r = new Regex(@"\[(.*?)\]");
- var expiryMatch = r.Match(item.Info.Name);
- if (expiryMatch.Success)
- {
- var parameter = expiryMatch.Groups[1].Captures[0].Value;
- var numAlpha = new Regex("(?<Numeric>[0-9]*)(?<Alpha>[a-zA-Z]*)");
- var match = numAlpha.Match(parameter);
- var alpha = match.Groups["Alpha"].Value;
- var num = 0;
- int.TryParse(match.Groups["Numeric"].Value, out num);
- switch (alpha)
- {
- case "m":
- expiryInfo.ExpiryDate = Now.AddMinutes(num);
- break;
- case "h":
- expiryInfo.ExpiryDate = Now.AddHours(num);
- break;
- case "d":
- expiryInfo.ExpiryDate = Now.AddDays(num);
- break;
- case "M":
- expiryInfo.ExpiryDate = Now.AddMonths(num);
- break;
- case "y":
- expiryInfo.ExpiryDate = Now.AddYears(num);
- break;
- default:
- expiryInfo.ExpiryDate = DateTime.MaxValue;
- break;
- }
- item.ExpireInfo = expiryInfo;
- }
- }
- public void UpgradeItem(UserItem item)
- {
- if (item.Info.RandomStats == null) return;
- var stat = item.Info.RandomStats;
- if (stat.MaxDuraChance > 0 && Random.Next(stat.MaxDuraChance) == 0)
- {
- var dura = RandomomRange(stat.MaxDuraMaxStat, stat.MaxDuraStatChance);
- item.MaxDura = (ushort)Math.Min(ushort.MaxValue, item.MaxDura + dura * 1000);
- item.CurrentDura = (ushort)Math.Min(ushort.MaxValue, item.CurrentDura + dura * 1000);
- }
- if (stat.MaxAcChance > 0 && Random.Next(stat.MaxAcChance) == 0) item.AddedStats[Stat.MaxAC] = (byte)(RandomomRange(stat.MaxAcMaxStat - 1, stat.MaxAcStatChance) + 1);
- if (stat.MaxMacChance > 0 && Random.Next(stat.MaxMacChance) == 0) item.AddedStats[Stat.MaxMAC] = (byte)(RandomomRange(stat.MaxMacMaxStat - 1, stat.MaxMacStatChance) + 1);
- if (stat.MaxDcChance > 0 && Random.Next(stat.MaxDcChance) == 0) item.AddedStats[Stat.MaxDC] = (byte)(RandomomRange(stat.MaxDcMaxStat - 1, stat.MaxDcStatChance) + 1);
- if (stat.MaxMcChance > 0 && Random.Next(stat.MaxMcChance) == 0) item.AddedStats[Stat.MaxMC] = (byte)(RandomomRange(stat.MaxMcMaxStat - 1, stat.MaxMcStatChance) + 1);
- if (stat.MaxScChance > 0 && Random.Next(stat.MaxScChance) == 0) item.AddedStats[Stat.MaxSC] = (byte)(RandomomRange(stat.MaxScMaxStat - 1, stat.MaxScStatChance) + 1);
- if (stat.AccuracyChance > 0 && Random.Next(stat.AccuracyChance) == 0) item.AddedStats[Stat.Accuracy] = (byte)(RandomomRange(stat.AccuracyMaxStat - 1, stat.AccuracyStatChance) + 1);
- if (stat.AgilityChance > 0 && Random.Next(stat.AgilityChance) == 0) item.AddedStats[Stat.Agility] = (byte)(RandomomRange(stat.AgilityMaxStat - 1, stat.AgilityStatChance) + 1);
- if (stat.HpChance > 0 && Random.Next(stat.HpChance) == 0) item.AddedStats[Stat.HP] = (byte)(RandomomRange(stat.HpMaxStat - 1, stat.HpStatChance) + 1);
- if (stat.MpChance > 0 && Random.Next(stat.MpChance) == 0) item.AddedStats[Stat.MP] = (byte)(RandomomRange(stat.MpMaxStat - 1, stat.MpStatChance) + 1);
- if (stat.StrongChance > 0 && Random.Next(stat.StrongChance) == 0) item.AddedStats[Stat.Strong] = (byte)(RandomomRange(stat.StrongMaxStat - 1, stat.StrongStatChance) + 1);
- if (stat.MagicResistChance > 0 && Random.Next(stat.MagicResistChance) == 0) item.AddedStats[Stat.MagicResist] = (byte)(RandomomRange(stat.MagicResistMaxStat - 1, stat.MagicResistStatChance) + 1);
- if (stat.PoisonResistChance > 0 && Random.Next(stat.PoisonResistChance) == 0) item.AddedStats[Stat.PoisonResist] = (byte)(RandomomRange(stat.PoisonResistMaxStat - 1, stat.PoisonResistStatChance) + 1);
- if (stat.HpRecovChance > 0 && Random.Next(stat.HpRecovChance) == 0) item.AddedStats[Stat.HealthRecovery] = (byte)(RandomomRange(stat.HpRecovMaxStat - 1, stat.HpRecovStatChance) + 1);
- if (stat.MpRecovChance > 0 && Random.Next(stat.MpRecovChance) == 0) item.AddedStats[Stat.SpellRecovery] = (byte)(RandomomRange(stat.MpRecovMaxStat - 1, stat.MpRecovStatChance) + 1);
- if (stat.PoisonRecovChance > 0 && Random.Next(stat.PoisonRecovChance) == 0) item.AddedStats[Stat.PoisonRecovery] = (byte)(RandomomRange(stat.PoisonRecovMaxStat - 1, stat.PoisonRecovStatChance) + 1);
- if (stat.CriticalRateChance > 0 && Random.Next(stat.CriticalRateChance) == 0) item.AddedStats[Stat.CriticalRate] = (byte)(RandomomRange(stat.CriticalRateMaxStat - 1, stat.CriticalRateStatChance) + 1);
- if (stat.CriticalDamageChance > 0 && Random.Next(stat.CriticalDamageChance) == 0) item.AddedStats[Stat.CriticalDamage] = (byte)(RandomomRange(stat.CriticalDamageMaxStat - 1, stat.CriticalDamageStatChance) + 1);
- if (stat.FreezeChance > 0 && Random.Next(stat.FreezeChance) == 0) item.AddedStats[Stat.Freezing] = (byte)(RandomomRange(stat.FreezeMaxStat - 1, stat.FreezeStatChance) + 1);
- if (stat.PoisonAttackChance > 0 && Random.Next(stat.PoisonAttackChance) == 0) item.AddedStats[Stat.PoisonAttack] = (byte)(RandomomRange(stat.PoisonAttackMaxStat - 1, stat.PoisonAttackStatChance) + 1);
- if (stat.AttackSpeedChance > 0 && Random.Next(stat.AttackSpeedChance) == 0) item.AddedStats[Stat.AttackSpeed] = (sbyte)(RandomomRange(stat.AttackSpeedMaxStat - 1, stat.AttackSpeedStatChance) + 1);
- if (stat.LuckChance > 0 && Random.Next(stat.LuckChance) == 0) item.AddedStats[Stat.Luck] = (sbyte)(RandomomRange(stat.LuckMaxStat - 1, stat.LuckStatChance) + 1);
- if (stat.CurseChance > 0 && Random.Next(100) <= stat.CurseChance) item.Cursed = true;
- if (stat.SlotChance > 0 && Random.Next(stat.SlotChance) == 0)
- {
- var slot = (byte)(RandomomRange(stat.SlotMaxStat - 1, stat.SlotStatChance) + 1);
- if (slot > item.Info.Slots)
- {
- item.SetSlotSize(slot);
- }
- }
- }
- public int RandomomRange(int count, int rate)
- {
- var x = 0;
- for (var i = 0; i < count; i++) if (Random.Next(rate) == 0) x++;
- return x;
- }
- public bool BindItem(UserItem item)
- {
- for (var i = 0; i < ItemInfoList.Count; i++)
- {
- var info = ItemInfoList[i];
- if (info.Index != item.ItemIndex) continue;
- item.Info = info;
- return BindSlotItems(item);
- }
- return false;
- }
- public bool BindGameShop(GameShopItem item, bool editEnvir = true)
- {
- for (var i = 0; i < Edit.ItemInfoList.Count; i++)
- {
- var info = Edit.ItemInfoList[i];
- if (info.Index != item.ItemIndex) continue;
- item.Info = info;
- return true;
- }
- return false;
- }
- public bool BindSlotItems(UserItem item)
- {
- for (var i = 0; i < item.Slots.Length; i++)
- {
- if (item.Slots[i] == null) continue;
- if (!BindItem(item.Slots[i])) return false;
- }
- return true;
- }
- public bool BindQuest(QuestProgressInfo quest)
- {
- for (var i = 0; i < QuestInfoList.Count; i++)
- {
- var info = QuestInfoList[i];
- if (info.Index != quest.Index) continue;
- quest.Info = info;
- return true;
- }
- return false;
- }
- public Map GetMap(int index)
- {
- return MapList.FirstOrDefault(t => t.Info.Index == index);
- }
- public Map GetMap(string name, bool strict = true)
- {
- return MapList.FirstOrDefault(t => strict ? string.Equals(t.Info.Title, name, StringComparison.CurrentCultureIgnoreCase) : t.Info.Title.StartsWith(name, StringComparison.CurrentCultureIgnoreCase));
- }
- public Map GetWorldMap(string name)
- {
- return MapList.FirstOrDefault(t => t.Info.Title.StartsWith(name, StringComparison.CurrentCultureIgnoreCase) && t.Info.BigMap > 0);
- }
- public MapInfo GetMapInfo(int index)
- {
- return MapInfoList.FirstOrDefault(t => t.Index == index);
- }
- public Map GetMapByNameAndInstance(string name, int instanceValue = 0)
- {
- if (instanceValue < 0) instanceValue = 0;
- if (instanceValue > 0) instanceValue--;
- var instanceMapList = MapList.Where(t => string.Equals(t.Info.FileName, name, StringComparison.CurrentCultureIgnoreCase)).ToList();
- return instanceValue < instanceMapList.Count() ? instanceMapList[instanceValue] : null;
- }
- public MapObject GetObject(uint objectID)
- {
- return Objects.FirstOrDefault(e => e.ObjectID == objectID);
- }
- public List<MapObject> GetObjects(int map, ObjectType race)
- {
- return Objects.Where(x => x.CurrentMapIndex == map && x.Race == race).ToList();
- }
- public MonsterInfo GetMonsterInfo(int index)
- {
- for (var i = 0; i < MonsterInfoList.Count; i++)
- if (MonsterInfoList[i].Index == index) return MonsterInfoList[i];
- return null;
- }
- public NPCInfo GetNPCInfo(int index)
- {
- for (var i = 0; i < NPCInfoList.Count; i++)
- {
- if (NPCInfoList[i].Index == index)
- return NPCInfoList[i];
- }
- return null;
- }
- public MonsterInfo GetMonsterInfo(int ai, int effect = -1)
- {
- for (var i = 0; i < MonsterInfoList.Count; i++)
- if (MonsterInfoList[i].AI == ai && (MonsterInfoList[i].Effect == effect || effect < 0)) return MonsterInfoList[i];
- return null;
- }
- public NPCObject GetNPC(string name)
- {
- return MapList.SelectMany(t1 => t1.NPCs.Where(t => t.Info.Name == name)).FirstOrDefault();
- }
- public NPCObject GetWorldMapNPC(string name)
- {
- return MapList.SelectMany(t1 => t1.NPCs.Where(t => t.Info.GameName.StartsWith(name, StringComparison.CurrentCultureIgnoreCase) && t.Info.ShowOnBigMap)).FirstOrDefault();
- }
- public MonsterInfo GetMonsterInfo(int id, bool strict = false)
- {
- String monsterName = MonsterInfoList.FirstOrDefault(x => x.Index == id)?.Name;
- if (monsterName == null)
- {
- return null;
- }
- else
- {
- return (GetMonsterInfo(monsterName, strict));
- }
- }
- public MonsterInfo GetMonsterInfo(string name, bool Strict = false)
- {
- for (var i = 0; i < MonsterInfoList.Count; i++)
- {
- var info = MonsterInfoList[i];
- if (Strict)
- {
- if (info.Name != name) continue;
- return info;
- }
- else
- {
- if (string.Compare(info.Name, name, StringComparison.OrdinalIgnoreCase) != 0 &&
- string.Compare(info.Name.Replace(" ", string.Empty), name.Replace(" ", string.Empty), StringComparison.OrdinalIgnoreCase) != 0) continue;
- return info;
- }
- }
- return null;
- }
- public PlayerObject GetPlayer(string name)
- {
- for (var i = 0; i < Players.Count; i++)
- if (string.Compare(Players[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
- return Players[i];
- return null;
- }
- public PlayerObject GetPlayer(uint PlayerId)
- {
- for (var i = 0; i < Players.Count; i++)
- if (Players[i].Info.Index == PlayerId)
- return Players[i];
- return null;
- }
- public CharacterInfo GetCharacterInfo(string name)
- {
- for (var i = 0; i < CharacterList.Count; i++)
- if (string.Compare(CharacterList[i].Name, name, StringComparison.OrdinalIgnoreCase) == 0)
- return CharacterList[i];
- return null;
- }
- public CharacterInfo GetCharacterInfo(int index)
- {
- for (var i = 0; i < CharacterList.Count; i++)
- if (CharacterList[i].Index == index)
- return CharacterList[i];
- return null;
- }
- public HeroInfo GetHeroInfo(int index)
- {
- return HeroList.FirstOrDefault(x => x.Index == index);
- }
- public ItemInfo GetItemInfo(int index)
- {
- for (var i = 0; i < ItemInfoList.Count; i++)
- {
- var info = ItemInfoList[i];
- if (info.Index != index) continue;
- return info;
- }
- return null;
- }
- public ItemInfo GetItemInfo(string name)
- {
- for (var i = 0; i < ItemInfoList.Count; i++)
- {
- var info = ItemInfoList[i];
- if (string.Compare(info.Name.Replace(" ", ""), name, StringComparison.OrdinalIgnoreCase) != 0) continue;
- return info;
- }
- return null;
- }
- public QuestInfo GetQuestInfo(int index)
- {
- return QuestInfoList.FirstOrDefault(info => info.Index == index);
- }
- public ItemInfo GetBook(short Skill)
- {
- for (var i = 0; i < ItemInfoList.Count; i++)
- {
- var info = ItemInfoList[i];
- if (info.Type != ItemType.Book || info.Shape != Skill) continue;
- return info;
- }
- return null;
- }
- public BuffInfo GetBuffInfo(BuffType type)
- {
- for (int i = 0; i < BuffInfoList.Count; i++)
- {
- var info = BuffInfoList[i];
- if (info.Type != type) continue;
- return info;
- }
- throw new NotImplementedException($"{type} has not been implemented.");
- }
- public void MessageAccount(AccountInfo account, string message, ChatType type)
- {
- if (account?.Characters == null) return;
- for (var i = 0; i < account.Characters.Count; i++)
- {
- if (account.Characters[i].Player == null) continue;
- account.Characters[i].Player.ReceiveChat(message, type);
- return;
- }
- }
- public void MailCharacter(CharacterInfo info, UserItem item = null, uint gold = 0, int reason = 0, string customMessage = null)
- {
- string sender = "Bichon Administrator";
- string message = "You have been mailed due to the following reason:\r\n\r\n";
- switch (reason)
- {
- case 1:
- message += "Could not return item to bag after trade.";
- break;
- case 99:
- message += "Code didn't correctly handle checking inventory space.";
- break;
- default:
- message += customMessage ?? "No reason provided.";
- break;
- }
- MailInfo mail = new MailInfo(info.Index)
- {
- Sender = sender,
- Message = message,
- Gold = gold
- };
- if (item != null)
- {
- mail.Items.Add(item);
- }
- mail.Send();
- }
- public GuildObject GetGuild(string name)
- {
- for (var i = 0; i < Guilds.Count; i++)
- {
- if (string.Compare(Guilds[i].Name.Replace(" ", ""), name, StringComparison.OrdinalIgnoreCase) != 0) continue;
- return Guilds[i];
- }
- return null;
- }
- public GuildObject GetGuild(int index)
- {
- for (var i = 0; i < Guilds.Count; i++)
- {
- if (Guilds[i].Guildindex == index)
- {
- return Guilds[i];
- }
- }
- return null;
- }
- public void ProcessNewDay()
- {
- foreach (var c in CharacterList)
- {
- ClearDailyQuests(c);
- c.NewDay = true;
- c.Player?.CallDefaultNPC(DefaultNPCType.Daily);
- }
- }
- private void ProcessRentedItems()
- {
- foreach (var characterInfo in CharacterList)
- {
- if (characterInfo.RentedItems.Count <= 0)
- {
- continue;
- }
- foreach (var rentedItemInfo in characterInfo.RentedItems)
- {
- if (rentedItemInfo.ItemReturnDate >= Now)
- continue;
- var rentingPlayer = GetCharacterInfo(rentedItemInfo.RentingPlayerName);
- for (var i = 0; i < rentingPlayer.Inventory.Length; i++)
- {
- if (rentedItemInfo.ItemId != rentingPlayer?.Inventory[i]?.UniqueID)
- {
- continue;
- }
- var item = rentingPlayer.Inventory[i];
- if (item?.RentalInformation == null)
- {
- continue;
- }
- if (Now <= item.RentalInformation.ExpiryDate)
- {
- continue;
- }
- ReturnRentalItem(item, item.RentalInformation.OwnerName, rentingPlayer, false);
- rentingPlayer.Inventory[i] = null;
- rentingPlayer.HasRentedItem = false;
- if (rentingPlayer.Player == null)
- {
- continue;
- }
- rentingPlayer.Player.ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.ItemExpiredFromInventory), item.Info.FriendlyName), ChatType.Hint);
- rentingPlayer.Player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count });
- rentingPlayer.Player.RefreshStats();
- }
- for (var i = 0; i < rentingPlayer.Equipment.Length; i++)
- {
- var item = rentingPlayer.Equipment[i];
- if (item?.RentalInformation == null)
- {
- continue;
- }
- if (Now <= item.RentalInformation.ExpiryDate)
- {
- continue;
- }
- ReturnRentalItem(item, item.RentalInformation.OwnerName, rentingPlayer, false);
- rentingPlayer.Equipment[i] = null;
- rentingPlayer.HasRentedItem = false;
- if (rentingPlayer.Player == null)
- {
- continue;
- }
- rentingPlayer.Player.ReceiveChat(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.ItemExpiredInventory), item.Info.FriendlyName), ChatType.Hint);
- rentingPlayer.Player.Enqueue(new S.DeleteItem { UniqueID = item.UniqueID, Count = item.Count });
- rentingPlayer.Player.RefreshStats();
- }
- }
- }
- foreach (var characterInfo in CharacterList)
- {
- if (characterInfo.RentedItemsToRemove.Count <= 0)
- {
- continue;
- }
- foreach (var rentalInformationToRemove in characterInfo.RentedItemsToRemove)
- {
- characterInfo.RentedItems.Remove(rentalInformationToRemove);
- }
- characterInfo.RentedItemsToRemove.Clear();
- }
- }
- public bool ReturnRentalItem(UserItem rentedItem, string ownerName, CharacterInfo rentingCharacterInfo, bool removeNow = true)
- {
- if (rentedItem.RentalInformation == null)
- {
- return false;
- }
- var owner = GetCharacterInfo(ownerName);
- var returnItems = new List<UserItem>();
- foreach (var rentalInformation in owner.RentedItems)
- {
- if (rentalInformation.ItemId == rentedItem.UniqueID)
- {
- owner.RentedItemsToRemove.Add(rentalInformation);
- }
- }
- rentedItem.RentalInformation.BindingFlags = BindMode.None;
- rentedItem.RentalInformation.RentalLocked = true;
- rentedItem.RentalInformation.ExpiryDate = rentedItem.RentalInformation.ExpiryDate.AddDays(1);
- returnItems.Add(rentedItem);
- var mail = new MailInfo(owner.Index, true)
- {
- Sender = rentingCharacterInfo.Name,
- Message = rentedItem.Info.FriendlyName,
- Items = returnItems
- };
- mail.Send();
- if (removeNow)
- {
- foreach (var rentalInformationToRemove in owner.RentedItemsToRemove)
- {
- owner.RentedItems.Remove(rentalInformationToRemove);
- }
- owner.RentedItemsToRemove.Clear();
- }
- return true;
- }
- private void ClearDailyQuests(CharacterInfo info)
- {
- foreach (var quest in QuestInfoList)
- {
- if (quest.Type != QuestType.Daily) continue;
- for (var i = 0; i < info.CompletedQuests.Count; i++)
- {
- if (info.CompletedQuests[i] != quest.Index) continue;
- info.CompletedQuests.RemoveAt(i);
- }
- }
- info.Player?.GetCompletedQuests();
- }
- public GuildBuffInfo FindGuildBuffInfo(int Id)
- {
- for (var i = 0; i < Settings.Guild_BuffList.Count; i++)
- {
- if (Settings.Guild_BuffList[i].Id == Id)
- {
- return Settings.Guild_BuffList[i];
- }
- }
- return null;
- }
- public void ClearGameshopLog()
- {
- Main.GameshopLog.Clear();
- for (var i = 0; i < AccountList.Count; i++)
- {
- for (var f = 0; f < AccountList[i].Characters.Count; f++)
- {
- AccountList[i].Characters[f].GSpurchases.Clear();
- }
- }
- ResetGS = false;
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.GameshopPurchaseLogsCleared));
- }
- public void Inspect(MirConnection con, uint id)
- {
- if (ObjectID == id) return;
- PlayerObject player = Players.SingleOrDefault(x => x.ObjectID == id || x.Pets.Count(y => y.ObjectID == id && y is HumanWizard) > 0);
- if (player == null) return;
- Inspect(con, player.Info.Index);
- }
- public void Inspect(MirConnection con, int id)
- {
- if (ObjectID == id) return;
- CharacterInfo player = GetCharacterInfo(id);
- if (player == null) return;
- CharacterInfo Lover = null;
- string loverName = "";
- if (player.Married != 0) Lover = GetCharacterInfo(player.Married);
- if (Lover != null)
- {
- loverName = Lover.Name;
- }
- for (int i = 0; i < player.Equipment.Length; i++)
- {
- UserItem u = player.Equipment[i];
- if (u == null) continue;
- con.CheckItem(u);
- }
- string guildname = "";
- string guildrank = "";
- GuildObject guild = null;
- GuildRank guildRank = null;
- if (player.GuildIndex != -1)
- {
- guild = GetGuild(player.GuildIndex);
- if (guild != null)
- {
- guildRank = guild.FindRank(player.Name);
- if (guildRank == null)
- {
- guild = null;
- }
- else
- {
- guildname = guild.Name;
- guildrank = guildRank.Name;
- }
- }
- }
- con.Enqueue(new S.PlayerInspect
- {
- Name = player.Name,
- Equipment = player.Equipment,
- GuildName = guildname,
- GuildRank = guildrank,
- Hair = player.Hair,
- Gender = player.Gender,
- Class = player.Class,
- Level = player.Level,
- LoverName = loverName,
- AllowObserve = player.AllowObserve && Settings.AllowObserve
- });
- }
- public void InspectHero(MirConnection con, int id)
- {
- if (ObjectID == id)
- {
- return;
- }
- HeroObject heroObject = Heroes.SingleOrDefault(h => h.ObjectID == id);
- if (heroObject == null)
- {
- return;
- }
- HeroInfo heroInfo = GetHeroInfo(heroObject.Info.Index);
- if (heroInfo == null)
- {
- return;
- }
- for (int i = 0; i < heroInfo.Equipment.Length; i++)
- {
- UserItem u = heroInfo.Equipment[i];
- if (u == null)
- {
- continue;
- }
- con.CheckItem(u);
- }
- var ownerName = heroObject.Owner.Name;
- con.Enqueue(new S.PlayerInspect
- {
- Name = GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.PlayerHero), ownerName),
- Equipment = heroInfo.Equipment,
- GuildName = String.Empty,
- GuildRank = String.Empty,
- Hair = heroInfo.Hair,
- Gender = heroInfo.Gender,
- Class = heroInfo.Class,
- Level = heroInfo.Level,
- LoverName = String.Empty,
- AllowObserve = false,
- IsHero = true
- });
- }
- public void Observe(MirConnection con, string Name)
- {
- var player = GetPlayer(Name);
- if (player == null) return;
- if (!player.AllowObserve || !Settings.AllowObserve) return;
- player.AddObserver(con);
- }
- public void GetRanking(MirConnection con, byte RankType, int RankIndex, bool OnlineOnly)
- {
- if (RankType > 6) return;
- List<RankCharacterInfo> listings = RankType == 0 ? RankTop : RankClass[RankType - 1];
- if (RankIndex >= listings.Count || RankIndex < 0) return;
- S.Rankings p = new S.Rankings
- {
- RankType = RankType,
- Count = OnlineOnly ? OnlineRankingCount[RankType] : listings.Count
- };
- if (con.Player != null)
- {
- if (RankType == 0)
- p.MyRank = con.Player.Info.Rank[0];
- else
- p.MyRank = (byte)con.Player.Class == (RankType - 1) ? con.Player.Info.Rank[1] : 0;
- }
- int c = 0;
- for (int i = RankIndex; i < listings.Count; i++)
- {
- if (OnlineOnly && GetPlayer(listings[i].Name) == null) continue;
- if (!CheckListing(con, listings[i]))
- p.ListingDetails.Add(listings[i]);
- p.Listings.Add(listings[i].PlayerId);
- c++;
- if (c > 19 || c >= p.Count) break;
- }
- con.Enqueue(p);
- }
- private bool CheckListing(MirConnection con, RankCharacterInfo listing)
- {
- if (!con.SentRankings.ContainsKey(listing.PlayerId))
- {
- con.SentRankings.Add(listing.PlayerId, listing.LastUpdated);
- return false;
- }
- DateTime lastUpdated = con.SentRankings[listing.PlayerId];
- if (lastUpdated != listing.LastUpdated)
- {
- con.SentRankings[listing.PlayerId] = lastUpdated;
- return false;
- }
- return true;
- }
- public int InsertRank(List<RankCharacterInfo> Ranking, RankCharacterInfo NewRank)
- {
- if (Ranking.Count == 0)
- {
- Ranking.Add(NewRank);
- return Ranking.Count;
- }
- for (var i = 0; i < Ranking.Count; i++)
- {
- //if level is lower
- if (Ranking[i].level < NewRank.level)
- {
- Ranking.Insert(i, NewRank);
- return i + 1;
- }
- //if exp is lower but level = same
- if (Ranking[i].level == NewRank.level && Ranking[i].Experience < NewRank.Experience)
- {
- Ranking.Insert(i, NewRank);
- return i + 1;
- }
- }
- Ranking.Add(NewRank);
- return Ranking.Count;
- }
- public bool TryAddRank(List<RankCharacterInfo> Ranking, CharacterInfo info, byte type)
- {
- var NewRank = new RankCharacterInfo() { Name = info.Name, Class = info.Class, Experience = info.Experience, level = info.Level, PlayerId = info.Index, info = info, LastUpdated = Now };
- var NewRankIndex = InsertRank(Ranking, NewRank);
- if (NewRankIndex == 0) return false;
- for (var i = NewRankIndex; i < Ranking.Count; i++)
- {
- SetNewRank(Ranking[i], i + 1, type);
- }
- info.Rank[type] = NewRankIndex;
- return true;
- }
- public int FindRank(List<RankCharacterInfo> Ranking, CharacterInfo info, byte type)
- {
- var startindex = info.Rank[type];
- if (startindex > 0) //if there's a previously known rank then the user can only have gone down in the ranking (or stayed the same)
- {
- for (var i = startindex - 1; i < Ranking.Count; i++)
- {
- if (Ranking[i].Name == info.Name)
- return i;
- }
- info.Rank[type] = 0;//set the rank to 0 to tell future searches it's not there anymore
- }
- return -1;//index can be 0
- }
- public bool UpdateRank(List<RankCharacterInfo> Ranking, CharacterInfo info, byte type)
- {
- var CurrentRank = FindRank(Ranking, info, type);
- if (CurrentRank == -1) return false;//not in ranking list atm
- var NewRank = CurrentRank;
- //next find our updated rank
- for (var i = CurrentRank - 1; i >= 0; i--)
- {
- if (Ranking[i].level > info.Level || Ranking[i].level == info.Level && Ranking[i].Experience > info.Experience) break;
- NewRank = i;
- }
- Ranking[CurrentRank].level = info.Level;
- Ranking[CurrentRank].Experience = info.Experience;
- Ranking[CurrentRank].LastUpdated = Now;
- if (NewRank < CurrentRank)
- {//if we gained any ranks
- Ranking.Insert(NewRank, Ranking[CurrentRank]);
- Ranking.RemoveAt(CurrentRank + 1);
- for (var i = NewRank + 1; i < Math.Min(Ranking.Count, CurrentRank + 1); i++)
- {
- SetNewRank(Ranking[i], i + 1, type);
- }
- }
- info.Rank[type] = NewRank + 1;
- return true;
- }
- public void SetNewRank(RankCharacterInfo Rank, int Index, byte type)
- {
- Rank.LastUpdated = Now;
- if (!(Rank.info is CharacterInfo Player)) return;
- Player.Rank[type] = Index;
- }
- public void RemoveRank(CharacterInfo info)
- {
- List<RankCharacterInfo> Ranking;
- var Rankindex = -1;
- //first check overall top
- Ranking = RankTop;
- Rankindex = FindRank(Ranking, info, 0);
- if (Rankindex >= 0)
- {
- Ranking.RemoveAt(Rankindex);
- for (var i = Rankindex; i < Ranking.Count(); i++)
- {
- SetNewRank(Ranking[i], i, 0);
- }
- }
- //next class based top
- Ranking = RankTop;
- Rankindex = FindRank(Ranking, info, 1);
- if (Rankindex >= 0)
- {
- Ranking.RemoveAt(Rankindex);
- for (var i = Rankindex; i < Ranking.Count(); i++)
- {
- SetNewRank(Ranking[i], i, 1);
- }
- }
- }
- public void CheckRankUpdate(CharacterInfo info)
- {
- List<RankCharacterInfo> Ranking;
- //first check overall top
- Ranking = RankTop;
- if (!UpdateRank(Ranking, info, 0))
- {
- TryAddRank(Ranking, info, 0);
- }
- //now check class top
- Ranking = RankClass[(byte)info.Class];
- if (!UpdateRank(Ranking, info, 1))
- {
- TryAddRank(Ranking, info, 1);
- }
- }
- public void ReloadNPCs()
- {
- SaveGoods(true);
- Robot.Clear();
- var keys = Scripts.Keys;
- foreach (var key in keys)
- {
- Scripts[key].Load();
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.NpcScriptsReloaded));
- }
- public void ReloadDrops()
- {
- for (var i = 0; i < MonsterInfoList.Count; i++)
- {
- string path = Path.Combine(Settings.DropPath, MonsterInfoList[i].Name + ".txt");
- if (!string.IsNullOrEmpty(MonsterInfoList[i].DropPath))
- {
- path = Path.Combine(Settings.DropPath, MonsterInfoList[i].DropPath + ".txt");
- }
- MonsterInfoList[i].Drops.Clear();
- DropInfo.Load(MonsterInfoList[i].Drops, MonsterInfoList[i].Name, path, 0, true);
- }
- FishingDrops.Clear();
- for (int i = 0; i < 19; i++)
- {
- var path = Path.Combine(Settings.DropPath, Settings.FishingDropFilename + ".txt");
- path = path.Replace("00", i.ToString("D2"));
- DropInfo.Load(FishingDrops, $"Fishing {i}", path, (byte)i, i < 2);
- }
- AwakeningDrops.Clear();
- DropInfo.Load(AwakeningDrops, "Awakening", Path.Combine(Settings.DropPath, Settings.AwakeningDropFilename + ".txt"));
- StrongboxDrops.Clear();
- DropInfo.Load(StrongboxDrops, "StrongBox", Path.Combine(Settings.DropPath, Settings.StrongboxDropFilename + ".txt"));
- BlackstoneDrops.Clear();
- DropInfo.Load(BlackstoneDrops, "Blackstone", Path.Combine(Settings.DropPath, Settings.BlackstoneDropFilename + ".txt"));
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.DropsLoaded));
- }
- public void ReloadLineMessages()
- {
- LineMessages.Clear();
- var path = Path.Combine(Settings.EnvirPath, "LineMessage.txt");
- if (!File.Exists(path))
- {
- File.WriteAllText(path, "");
- }
- else
- {
- var lines = File.ReadAllLines(path);
- for (var i = 0; i < lines.Length; i++)
- {
- if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i])) continue;
- LineMessages.Add(lines[i]);
- }
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization(ServerTextKeys.LineMessagesReloaded));
- }
- }
- private WorldMapIcon ValidateWorldMap()
- {
- foreach (WorldMapIcon wmi in Settings.WorldMapSetup.Icons)
- {
- MapInfo info = GetMapInfo(wmi.MapIndex);
- if (info == null)
- return wmi;
- }
- return null;
- }
- public void DeleteGuild(GuildObject guild)
- {
- Guilds.Remove(guild);
- GuildList.Remove(guild.Info);
- GuildRefreshNeeded = true;
- MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.GuildWillBeDeletedFromServer), guild.Info.Name));
- }
- }
- }
|