1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "LuaFunctions.h"
- #include "Spawn.h"
- #include "WorldDatabase.h"
- #include "LuaInterface.h"
- #include "../common/ConfigReader.h"
- #include "client.h"
- #include "World.h"
- #include "Commands/Commands.h"
- #include "races.h"
- #include "classes.h"
- #include "Variables.h"
- #include "SpellProcess.h"
- #include "Rules/Rules.h"
- #include "../common/Log.h"
- #include <math.h>
- #include "HeroicOp/HeroicOp.h"
- #include "RaceTypes/RaceTypes.h"
- #include "ClientPacketFunctions.h"
- #include "Transmute.h"
- #include "Titles.h"
- #include <boost/algorithm/string/predicate.hpp>
- #include <sstream>
- #include <boost/algorithm/string.hpp>
- extern MasterFactionList master_faction_list;
- extern WorldDatabase database;
- extern LuaInterface* lua_interface;
- extern ConfigReader configReader;
- extern MasterQuestList master_quest_list;
- extern MasterItemList master_item_list;
- extern MasterSpellList master_spell_list;
- extern World world;
- extern Commands commands;
- extern ZoneList zone_list;
- extern Races races;
- extern Classes classes;
- extern Variables variables;
- extern MasterSkillList master_skill_list;
- extern MasterHeroicOPList master_ho_list;
- extern MasterRaceTypeList race_types_list;
- extern MasterLanguagesList master_languages_list;
- extern MasterTitlesList master_titles_list;
- extern RuleManager rule_manager;
- vector<string> ParseString(string strVal, char delim) {
- stringstream ss(strVal);
- vector<string> ret;
- while (ss.good())
- {
- string substr;
- getline(ss, substr, delim);
- ret.push_back(substr);
- }
- return ret;
- }
- vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
- stringstream ss(strVal);
- vector<unsigned int> ret;
- while (ss.good())
- {
- string substr;
- getline(ss, substr, delim);
- stringstream valss(substr);
- unsigned int val = 0;
- valss >> val;
- ret.push_back(val);
- }
- return ret;
- }
- map<string, signed int> ParseStringMap(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<string, signed int> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- int32 val = 0;
- valss >> val;
- ret[keyvaluepair[0]] = val;
- }
- }
-
- return ret;
- }
- map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<unsigned int, unsigned short> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- int32 key = 0;
- if (keyvaluepair.size() > 0) {
- stringstream keyss(keyvaluepair[0]);
- keyss >> key;
- }
- if (keyvaluepair.size() == 1) {
- ret[key] = 1;
- }
- else if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- unsigned short val = 0;
- valss >> val;
- ret[key] = val;
- }
- }
- return ret;
- }
- map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
- vector<string> pairs = ParseString(strVal, delim);
- vector<string>::iterator itr;
- map<unsigned int, signed int> ret;
- for (itr = pairs.begin(); itr != pairs.end(); itr++) {
- vector<string> keyvaluepair = ParseString(*itr, ':');
- int32 key = 0;
- if (keyvaluepair.size() > 0) {
- stringstream keyss(keyvaluepair[0]);
- keyss >> key;
- }
- if (keyvaluepair.size() == 1) {
- ret[key] = 1;
- }
- else if (keyvaluepair.size() == 2) {
- stringstream valss(keyvaluepair[1]);
- signed int val = 0;
- valss >> val;
- ret[key] = val;
- }
- }
- return ret;
- }
- int EQ2Emu_lua_PlayFlavor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string mp3_string = lua_interface->GetStringValue(state, 2);
- string text_string = lua_interface->GetStringValue(state, 3);
- string emote_string = lua_interface->GetStringValue(state, 4);
- int32 key1 = lua_interface->GetInt32Value(state, 5);
- int32 key2 = lua_interface->GetInt32Value(state, 6);
- Spawn* player = lua_interface->GetSpawn(state, 7);
- int8 language = lua_interface->GetInt8Value(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- const char* mp3 = 0;
- const char* text = 0;
- const char* emote = 0;
- if (mp3_string.length() > 0)
- mp3 = mp3_string.c_str();
- if (text_string.length() > 0)
- text = text_string.c_str();
- if (emote_string.length() > 0)
- emote = emote_string.c_str();
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- if (((Player*)player)->WasSentSpawn(spawn->GetID()))
- spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
- }
- else
- spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
- }
- return 0;
- }
- int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- int8 type = lua_interface->GetInt8Value(state, 2);
- int32 id = lua_interface->GetInt32Value(state, 3);
- int16 index = lua_interface->GetInt16Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- int8 language = lua_interface->GetInt8Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- VoiceOverStruct non_garble, garble;
- bool garble_success = false;
- bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
- client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
- }
- else
- spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
- }
- return 0;
- }
- int EQ2Emu_lua_PlaySound(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string sound_string = lua_interface->GetStringValue(state, 2);
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- Spawn* player = lua_interface->GetSpawn(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn && sound_string.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
- else
- spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
- }
- return 0;
- }
- int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int16 quest_step = lua_interface->GetInt16Value(state, 3);
- bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
- bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
- int16 flag_override = lua_interface->GetInt16Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id > 0) {
- //Add this quest to the list of required quests for this spawn
- spawn->SetQuestsRequired(quest_id, quest_step);
- //If private spawn value set
- if (private_spawn) {
- //Set the spawn to be private when not granted access through this quest
- spawn->AddAllowAccessSpawn(spawn);
- spawn->SetPrivateQuestSpawn(true);
- }
- //This value allows access after a quest step, or the whole quest has been completed
- if (continued_access)
- spawn->SetQuestsRequiredContinuedAccess(true);
- //This value will override vis_flags in the vis packet
- if (flag_override > 0)
- spawn->SetQuestsRequiredOverride(flag_override);
- }
- return 0;
- }
- int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float max_distance = lua_interface->GetFloatValue(state, 2);
- string variable = lua_interface->GetStringValue(state, 3);
- string value = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
- spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
- return 0;
- }
- int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- float intensity = lua_interface->GetFloatValue(state, 2);
- int8 direction = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
- return 0;
- }
- if (player->GetZone())
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
- if (packet) {
- /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
- v1 = *(float *)(a1 + 4);
- if ( v1 > 0.0 )
- v2 = fminf(v1, 1.0);
- else
- v2 = 0.1;
- */
- packet->setDataByName("intensity", intensity);
- if ( client->GetVersion() > 561 )
- packet->setDataByName("direction", direction);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_KillSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* dead = lua_interface->GetSpawn(state);
- Spawn* killer = lua_interface->GetSpawn(state, 2);
- bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
- lua_interface->ResetFunctionStack(state);
- if (dead && dead->Alive() && dead->GetZone())
- dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
- return 0;
- }
- int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float max_distance = lua_interface->GetFloatValue(state, 2);
- bool include_players = lua_interface->GetInt8Value(state, 3);
- bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (max_distance > 0 && spawn && spawn->GetZone())
- spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
- return 0;
- }
- int EQ2Emu_lua_Despawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 delay = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->GetZone())
- spawn->GetZone()->Despawn(spawn, delay);
- return 0;
- }
- int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->info_changed = true;
- spawn->SetShowHandIcon(displayHandIcon);
- }
- return 0;
- }
- //this function is used to force an update packet to be sent.
- //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
- int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->vis_changed = true;
- spawn->GetZone()->AddChangedSpawn(spawn);
- }
- return 0;
- }
- //this function is used to force an update packet to be sent.
- //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
- int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->info_changed = true;
- spawn->GetZone()->AddChangedSpawn(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_SendStateCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_state = lua_interface->GetInt32Value(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if(player)
- {
- if(player->IsPlayer())
- {
- Client* client = ((Player*)player)->GetClient();
- if(client)
- {
- ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
- }
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
- }
- else
- {
- spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_SpawnSet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string variable = lua_interface->GetStringValue(state, 2);
- string value = lua_interface->GetStringValue(state, 3);
- bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
- bool temporary_flag = true;
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- int8 index = 0;
- if(num_args >= 5)
- {
- temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
-
- index = lua_interface->GetInt8Value(state, 6);
- }
-
- lua_interface->ResetFunctionStack(state);
- int32 type = commands.GetSpawnSetType(variable);
- if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
- commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
- return 0;
- }
- int EQ2Emu_lua_GetSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn_id > 0) {
- Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
- if (closest_spawn) {
- lua_interface->SetSpawnValue(state, closest_spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- vector<Spawn*> spawns;
- int32 position = 0;
-
- if(lua_istable(state, 1)) {
- size_t len = lua_rawlen(state, 1);
- for(int i=1;i <= len; i++)
- {
- // get the entry to stack
- lua_rawgeti(state, 1, i);
- int Top = lua_gettop(state);
-
- if(lua_islightuserdata(state,Top)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
- if(data->IsSpawn()) {
- spawns.push_back(data->spawn);
- }
- }
- // remove entry from stack
- lua_pop(state,1);
- }
- }
-
- position = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
-
- Spawn* spawn = 0;
- if(position < spawns.size()) {
- spawn = spawns.at(position);
- }
-
- if(spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- vector<Spawn*> spawns;
-
- if(lua_istable(state, 1)) {
- size_t len = lua_rawlen(state, 1);
- for(int i=1;i <= len; i++)
- {
- // get the entry to stack
- lua_rawgeti(state, 1, i);
- int Top = lua_gettop(state);
-
- if(lua_islightuserdata(state,Top)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
- if(data->IsSpawn()) {
- spawns.push_back(data->spawn);
- }
- }
- // remove entry from stack
- lua_pop(state,1);
- }
- }
-
- lua_interface->ResetFunctionStack(state);
-
- lua_interface->SetInt32Value(state, spawns.size());
- return 1;
- }
- int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- vector<Spawn*> spawns = spawn->GetPassengersOnRail();
- if (spawns.size() > 0) {
- lua_createtable(state, spawns.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < spawns.size(); i++) {
- lua_interface->SetSpawnValue(state, spawns.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetVariableValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- string variable_name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- Variable* var = variables.FindVariable(variable_name);
- if (var) {
- lua_interface->SetStringValue(state, var->GetValue());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 total_coins = lua_interface->GetInt32Value(state);
- lua_interface->ResetFunctionStack(state);
- if (total_coins == 0) {
- lua_interface->SetStringValue(state, "0 copper");
- return 1;
- }
- char tmp[64] = { 0 };
- string message = "";
- int32 val = 0;
- if (total_coins >= 1000000) {
- val = total_coins / 1000000;
- total_coins -= 1000000 * val;
- sprintf(tmp, " %u Platinum", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 10000) {
- val = total_coins / 10000;
- total_coins -= 10000 * val;
- sprintf(tmp, " %u Gold", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins >= 100) {
- val = total_coins / 100;
- total_coins -= 100 * val;
- sprintf(tmp, " %u Silver", val);
- message.append(tmp);
- memset(tmp, 0, 64);
- }
- if (total_coins > 0) {
- sprintf(tmp, " %u Copper", (int32)total_coins);
- message.append(tmp);
- }
- lua_interface->SetStringValue(state, message.c_str());
- return 1;
- }
- int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnGroup(group_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnByLocationID(location_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetSpawnGroupID(new_group_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 new_group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if(spawn->GetSpawnGroupID() == new_group_id) {
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && faction_id > 0) {
- lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetFactionID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetFactionID(value);
- }
- return 0;
- }
- int EQ2Emu_lua_GetFactionID(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetFactionID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetGender(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetGender());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetTarget(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_PlayVoice(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string mp3_string = lua_interface->GetStringValue(state, 2);
- int32 key1 = lua_interface->GetInt32Value(state, 3);
- int32 key2 = lua_interface->GetInt32Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (spawn && mp3_string.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client) {
- if (((Player*)player)->WasSentSpawn(spawn->GetID()))
- spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
- }
- else
- spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
- lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
- return 3;
- }
- return 0;
- }
- int EQ2Emu_lua_HasLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
- return 1;
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 charges = lua_interface->GetInt16Value(state, 3);
- if (charges == 0)
- charges = 1;
- ((Entity*)spawn)->AddLootItem(item_id, charges);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- Item* item = spawn->LootItem(item_id);
- lua_interface->SetLuaUserDataStale(item);
- safe_delete(item);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- int32 val = lua_interface->GetInt32Value(state, 2);
- spawn->AddLootCoins(val);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GiveLoot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- if (entity && player && player->IsPlayer()) {
- int32 coins = lua_interface->GetInt32Value(state, 3);
- vector<Item*>* items = 0;
- int i = 0;
- int32 item_id = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (items == 0)
- items = new vector<Item*>;
- if (master_item_list.GetItem(item_id))
- items->push_back(master_item_list.GetItem(item_id));
- i++;
- }
- Client* client = 0;
- client = ((Player*)player)->GetClient();
- if (client)
- ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
- if(coins > 0)
- entity->AddLootCoins(coins);
- safe_delete(items);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 item_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (entity && player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_CreateConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- lua_interface->ResetFunctionStack(state);
- conversation = new vector<ConversationOption>();
- lua_interface->SetConversationValue(state, conversation);
- return 1;
- }
- int EQ2Emu_lua_AddConversationOption(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- if (conversation) {
- ConversationOption conv_option;
- conv_option.option = lua_interface->GetStringValue(state, 2);
- conv_option.function = lua_interface->GetStringValue(state, 3);
- if (conv_option.option.length() > 0)
- conversation->push_back(conv_option);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_CloseConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && player && player->IsPlayer() && player->GetZone()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- int32 conversation_id = client->GetConversationID(npc, 0);
- client->CloseDialog(conversation_id);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (item && player && player->IsPlayer() && player->GetZone()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- int32 conversation_id = client->GetConversationID(0, item);
- client->CloseDialog(conversation_id);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- Spawn* spawn = 0;
- Item* item = 0;
- int8 type = lua_interface->GetInt8Value(state, 2);
- if (type == 1 || type == 3)
- spawn = lua_interface->GetSpawn(state, 3);
- else if (type == 2 || type == 4)
- item = lua_interface->GetItem(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- string text = lua_interface->GetStringValue(state, 5);
- string mp3 = lua_interface->GetStringValue(state, 6);
- int32 key1 = lua_interface->GetInt32Value(state, 7);
- int32 key2 = lua_interface->GetInt32Value(state, 8);
- int8 language = lua_interface->GetInt8Value(state, 9);
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- int8 can_close = 1;
- if(numargs > 9)
- can_close = lua_interface->GetInt32Value(state, 10);
- lua_interface->ResetFunctionStack(state);
- if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- if (spawn) {
- // Need to do this so the function works the same as it did before
- if (type == 1)
- type++;
- if (mp3.length() > 0)
- client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
- }
- else {
- if (mp3.length() > 0)
- client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
- }
- }
- }
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- return 0;
- }
- int EQ2Emu_lua_StartConversation(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
- Spawn* source = lua_interface->GetSpawn(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- string text = lua_interface->GetStringValue(state, 4);
- string mp3 = lua_interface->GetStringValue(state, 5);
- int32 key1 = lua_interface->GetInt32Value(state, 6);
- int32 key2 = lua_interface->GetInt32Value(state, 7);
- int8 language = lua_interface->GetInt32Value(state, 8);
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- int8 can_close = 1;
- if(numargs > 8)
- can_close = lua_interface->GetInt32Value(state, 9);
-
- lua_interface->ResetFunctionStack(state);
- if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (mp3.length() > 0)
- client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
- else
- client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
- lua_interface->SetLuaUserDataStale(conversation);
- safe_delete(conversation);
- }
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
- return 0;
- }
- int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- string in_range_function = lua_interface->GetStringValue(state, 3);
- string leaving_range_function = lua_interface->GetStringValue(state, 4);
- if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
- spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float max_variation = lua_interface->GetFloatValue(state, 5);
- string in_range_function = lua_interface->GetStringValue(state, 6);
- string leaving_range_function = lua_interface->GetStringValue(state, 7);
- lua_interface->ResetFunctionStack(state);
- if (zone && in_range_function.length() > 0)
- zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_SetLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int32 val = lua_interface->GetInt32Value(state, 2);
- ((Entity*)spawn)->SetLootCoins(val);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetLootCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float speed = lua_interface->GetFloatValue(state, 5);
- int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
- string function = lua_interface->GetStringValue(state, 7);
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- float heading = lua_interface->GetFloatValue(state, 8);
- if (spawn) {
- spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
- spawn->GetZone()->AddMovementNPC(spawn);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_IsPlayer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->IsPlayer());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharacterID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_FaceTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
-
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool reset_action_state = true;
- if(num_args > 2)
- reset_action_state = lua_interface->GetBooleanValue(state, 3);
-
- if (spawn && target) {
- if (spawn->IsEntity())
- // ((Entity*)spawn)->FaceTarget(target);
- static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_MoveToLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float speed = lua_interface->GetFloatValue(state, 5);
- string lua_function = lua_interface->GetStringValue(state, 6);
- bool more_points = lua_interface->GetBooleanValue(state, 7);
- if (spawn) {
- if (speed == 0)
- speed = spawn->GetSpeed();
- spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->ClearRunningLocations();
- }
- return 0;
- }
- int EQ2Emu_lua_Say(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Shout(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SayOOC(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* player = lua_interface->GetSpawn(state, 3);
- float dist = lua_interface->GetFloatValue(state, 4);
- int32 language = lua_interface->GetInt32Value(state, 5);
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- else
- spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Emote(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- char* to = 0;
- if (spawn2)
- to = spawn2->GetName();
- if (spawn && message.length() > 0) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (client)
- spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
- else
- spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SpellHeal(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Spawn* caster = luaspell->caster;
- string heal_type = lua_interface->GetStringValue(state);//power, heal ect
- int32 min_heal = lua_interface->GetInt32Value(state, 2);
- int32 max_heal = lua_interface->GetInt32Value(state, 3);
- Spawn* target = lua_interface->GetSpawn(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
- lua_interface->ResetFunctionStack(state);
-
- boost::to_lower(heal_type);
- if (caster && caster->IsEntity()) {
- bool success = false;
- luaspell->resisted = false;
- if (target) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
- success = true;
- }
- if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
- Spawn* target = 0;
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- success = true;
- }
- if (success) {
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SpellHealPct(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Spawn* caster = luaspell->caster;
- string heal_type = lua_interface->GetStringValue(state);//power, heal ect
- float percentage = lua_interface->GetFloatValue(state, 2);
- bool current_value = lua_interface->GetBooleanValue(state, 3);
- bool caster_value = lua_interface->GetBooleanValue(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- int8 crit_mod = lua_interface->GetInt32Value(state, 6);
- bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
- string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
- lua_interface->ResetFunctionStack(state);
- boost::to_lower(heal_type);
- int32 min_heal = 0, max_heal = 0;
- if (caster && caster->IsEntity() && target) {
- if(percentage <= 0.0f)
- {
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
- return 0;
- }
- if(heal_type == "power")
- {
- if(current_value)
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
- }
- else
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
- }
- }
- else
- {
- if(current_value)
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
- }
- else
- {
- if(caster_value)
- min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
- else
- min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
- }
- }
- bool success = false;
- luaspell->resisted = false;
- if (target) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
- success = true;
- }
- if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
- Spawn* target = 0;
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- success = true;
- }
- if (success) {
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 quantity = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- // default of 1 quantity to add
- if (quantity == 0)
- quantity = 1;
- if (spawn && spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client && item_id > 0) {
- lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_SummonItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
- string location = lua_interface->GetStringValue(state, 4);
- int16 item_count = lua_interface->GetInt16Value(state,5);
-
- //devn00b: if we dont have a count, assume 1 item.
- if(!item_count) {
- item_count = 1;
- }
-
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client && item_id > 0) {
- if (strncasecmp(location.c_str(), "bank", 4) == 0)
- lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
- else
- lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
- if (send_messages) {
- Item* item = master_item_list.GetItem(item_id);
- if (item) {
- if(item_count > 1) {
- client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
- string popup_text1 = "You receive "+ item_count;
- string popup_text2 = " " + item->name;
- string popup_text = popup_text1 + popup_text2;
- client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
- // return 1;
- } else {
- client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
- string popup_text = "You receive " + item->name;
- client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
- }
- }
- }
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_RemoveItem(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int16 quantity = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- // default of 1 to remove
- if (quantity == 0)
- quantity = 1;
- Client* client;
- Item* item;
- if (spawn && spawn->IsPlayer() && item_id > 0) {
- if ((client = ((Player*)spawn)->GetClient())) {
- if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
- if (client->RemoveItem(item, quantity)) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_HasItem(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- bool include_bank = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- bool hasItem = false;
- hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
- if (!hasItem)
- hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
- lua_interface->SetBooleanValue(state, hasItem);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_Spawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- float heading = lua_interface->GetFloatValue(state, 7);
- if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
- Spawn* spawn = zone->GetSpawn(spawn_id);
- if (!spawn)
- lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
- else {
- spawn->SetX(x);
- spawn->SetZ(z);
- spawn->SetY(y,true,true);
- spawn->SetLocation(zone->GetClosestLocation(spawn));
- spawn->SetHeading(heading);
- if (restricted_npc)
- spawn->AddAllowAccessSpawn(spawn);
- const char* spawn_script = world.GetSpawnScript(spawn_id);
- bool scriptActive = false;
- if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
- scriptActive = true;
- spawn->SetSpawnScript(string(spawn_script));
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
- zone->AddSpawn(spawn);
- if (scriptActive) {
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- else {
- string output = "Invalid paramaters to LUA Spawn command: \n";
- if (!zone)
- output = output.append("\t").append("Missing zone reference. \n");
- if (spawn_id == 0)
- output = output.append("\t").append("Missing spawn_id.");
- lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetZoneName(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetStringValue(state, zone->GetZoneName());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZoneID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetZoneID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZone(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 zone_id = lua_interface->GetInt32Value(state);
- ZoneServer* zone = 0;
- if (zone_id > 0)
- zone = zone_list.Get(zone_id, true, false, false);
- else {
- string zone_name = lua_interface->GetStringValue(state);
- if (zone_name.length() > 0) {
- zone = zone_list.Get(zone_name.c_str(), true, false, false);
- }
- else {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn)
- zone = spawn->GetZone();
- }
- }
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetZoneValue(state, zone);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddHate(lua_State* state) {
- Spawn* entity = lua_interface->GetSpawn(state);
- Spawn* npc = lua_interface->GetSpawn(state, 2);
- sint32 amount = lua_interface->GetSInt32Value(state, 3);
- bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
-
- if(luaspell && luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if (entity && entity->IsEntity() && amount != 0) {
- if (luaspell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
- if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
- entity->CheckEncounterState((Entity*)spawn);
- ((NPC*)spawn)->AddHate((Entity*)entity, amount);
- if (send_packet)
- entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (npc && npc->IsNPC() && npc->GetZone()) {
- entity->CheckEncounterState((Entity*)npc);
- ((NPC*)npc)->AddHate((Entity*)entity, amount);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Zone(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- float heading = lua_interface->GetFloatValue(state, 6);
- if (zone && client) {
- LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
- LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
- if (!client->CheckZoneAccess(zone->GetZoneName()))
- {
- LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
- return 0;
- }
- if (x != 0 || y != 0 || z != 0) {
- LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
- player->SetX(x);
- player->SetY(y);
- player->SetZ(z);
- player->SetHeading(heading);
- client->Zone(zone->GetZoneName(), false);
- }
- else
- client->Zone(zone->GetZoneName());
- }
- else
- lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- if (spawn && spawn2)
- spawn->AddAllowAccessSpawn(spawn2);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_CastSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- int32 spell_id = lua_interface->GetInt32Value(state, 2);
- int8 spell_tier = lua_interface->GetInt8Value(state, 3);
- Spawn* caster = lua_interface->GetSpawn(state, 4);
- int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!target) {
- lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
- return 0;
- }
- if (spell_id <= 0) {
- lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (caster && !caster->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
- return 0;
- }
- if (spell_tier == 0)
- spell_tier = 1;
- if (!caster)
- caster = target;
- target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
- return 0;
- }
- int EQ2Emu_lua_SpellDamage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Spawn* caster = luaspell->caster;
- sint32 type = lua_interface->GetSInt32Value(state, 2);
- int32 min_damage = lua_interface->GetInt32Value(state, 3);
- int32 max_damage = lua_interface->GetInt32Value(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- //lua_interface->ResetFunctionStack(state);
- int32 class_id = lua_interface->GetInt32Value(state, 7);
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_req = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- lua_interface->ResetFunctionStack(state);
- if (caster && caster->IsEntity()) {
- bool race_match = false;
- bool success = false;
- luaspell->resisted = false;
- if (luaspell->targets.size() > 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
- }
- }
- }
- success = true;
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (target) {
- //check class and race/faction here
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
- success = true;
- }
- }
- lua_interface->SetBooleanValue(state, luaspell->has_damaged);
- if (success) {
- Spell* spell = luaspell->spell;
- if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
- ((Player*)caster)->InCombat(true);
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
- return 1;
- }
- int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Spawn* caster = luaspell->caster;
- sint32 type = lua_interface->GetSInt32Value(state, 2);
- int32 min_damage = lua_interface->GetInt32Value(state, 3);
- int32 max_damage = lua_interface->GetInt32Value(state, 4);
- int8 crit_mod = lua_interface->GetInt32Value(state, 5);
- bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
- int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
- bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
- //lua_interface->ResetFunctionStack(state);
- int32 class_id = lua_interface->GetInt32Value(state, 9);
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_req = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- lua_interface->ResetFunctionStack(state);
- if (caster && caster->IsEntity()) {
- bool race_match = false;
- bool success = false;
- luaspell->resisted = false;
- if (luaspell->targets.size() > 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
- }
- }
- }
- success = true;
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (target) {
- //check class and race/faction here
- if (race_req.size() > 0) {
- for (int8 i = 0; i < race_req.size(); i++) {
- if(race_req[i] == target->GetRace() ||
- race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
- race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
- race_match = true;
- }
- }
- }
- else
- race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
- if (race_match == true) {
- float distance = caster->GetDistance(target, true);
- if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
- success = true;
- }
- }
- lua_interface->SetBooleanValue(state, luaspell->has_damaged);
- if (success) {
- Spell* spell = luaspell->spell;
- if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
- ((Player*)caster)->InCombat(true);
- if (caster->GetZone())
- caster->GetZone()->TriggerCharSheetTimer();
- }
- }
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
- return 1;
- }
- int EQ2Emu_lua_ModifyPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- if (spawn->GetPower() + value > spawn->GetTotalPower())
- spawn->SetPower(spawn->GetTotalPower());
- else
- spawn->SetPower(spawn->GetPower() + value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- if (spawn->GetHP() + value > spawn->GetTotalHP())
- spawn->SetHP(spawn->GetTotalHP());
- else
- spawn->SetHP(spawn->GetHP() + value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- spawn->SetTotalPower(value);
- spawn->SetTotalPowerBaseInstance(value);
- }
- return 0;
- }
- int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value != 0) {
- spawn->SetTotalHP(value);
- spawn->SetTotalHPBaseInstance(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetHP(value);
- if (value > spawn->GetTotalHPBase())
- spawn->SetTotalHP(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
- if (spawn && spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- return 0;
- }
- int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->SetTotalHPBase(value);
- return 0;
- }
- int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && value > 0) {
- spawn->SetPower(value);
- if (value > spawn->GetTotalPowerBase())
- spawn->SetTotalPower(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
- return 0;
- }
- int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity() && value > 0)
- ((Entity*)spawn)->SetTotalPowerBase(value);
- return 0;
- }
- int EQ2Emu_lua_SetPosition(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- float heading = lua_interface->GetFloatValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetX(x);
- spawn->SetY(y);
- spawn->SetZ(z);
- if (heading != 0)
- spawn->SetHeading(heading);
- spawn->SetSpawnOrigX(spawn->GetX());
- spawn->SetSpawnOrigY(spawn->GetY());
- spawn->SetSpawnOrigZ(spawn->GetZ());
- spawn->SetSpawnOrigHeading(spawn->GetHeading());
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
- client->QueuePacket(packet);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetHeading(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetHeading(value);
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
- client->QueuePacket(packet);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn)
- spawn->SetModelType(value);
- return 0;
- }
- int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetPlayerAdventureClass(value);
- else
- spawn->SetAdventureClass(value);
- }
- return 0;
- }
- int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetTradeskillClass(value);
- if (spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
- ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
- }
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetMount(value);
- EQ2_Color color;
- color.red = 255;
- color.green = 255;
- color.blue = 255;
- ((Entity*)spawn)->SetMountColor(&color);
- ((Entity*)spawn)->SetMountSaddleColor(&color);
- }
- return 0;
- }
- int EQ2Emu_lua_SetMountColor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- EQ2_Color mount_color;
- EQ2_Color saddle_color;
- mount_color.red = lua_interface->GetInt8Value(state, 2);
- mount_color.green = lua_interface->GetInt8Value(state, 3);
- mount_color.blue = lua_interface->GetInt8Value(state, 4);
- saddle_color.red = lua_interface->GetInt8Value(state, 5);
- saddle_color.green = lua_interface->GetInt8Value(state, 6);
- saddle_color.blue = lua_interface->GetInt8Value(state, 7);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetMountColor(&mount_color);
- ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
- }
- return 0;
- }
- int EQ2Emu_lua_GetMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetRace(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn)
- {
- LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
- lua_interface->SetInt32Value(state, spawn->GetRace());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetRaceName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetClass(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetClassName(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpeed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetSpeed(value);
-
- if(spawn->IsEntity())
- ((Entity*)spawn)->SetSpeed(value);
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- packet->setDataByName("speed", value);
- packet->setDataByName("size", 0.51);
- EQ2Packet* app = packet->serialize();
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- const int16 type = lua_interface->GetInt16Value(state, 2);
- const float value = lua_interface->GetFloatValue(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
-
- if(!luaspell || luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int64 class_req = 0;
- int32 class_id = 0;
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- if (value != 0 && type >= 0) {
- if (luaspell && luaspell->spell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (target->IsPlayer()) {
- ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
- if (((Player*)target)->GetGroupMemberInfo())
- ((Player*)target)->UpdateGroupMemberInfo();
- ((Player*)target)->SetCharSheetChanged(true);
- }
- else if (target->IsNPC())
- ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- else
- lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
- }
- else if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- else
- lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
- }
- else
- lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 type = lua_interface->GetInt16Value(state, 2);
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value == 0) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int32 class_req = 0;
- vector<int16> faction_req;
- vector<int16> race_req;
- int32 class_id = 0;
- int32 i = 0;
- int8 f = 0;
- int8 r = 0;
- while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
- if (class_id < 100) {
- class_req += pow(2.0, double(class_id - 1));
- }
- else if (class_id > 100 && class_id < 1000) {
- race_req.push_back(class_id);
- r++;
- }
- else {
- faction_req.push_back(class_id);
- f++;
- }
- i++;
- }
- ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ((Entity*)spawn)->RemoveSpellBonus(luaspell);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
-
- return 0;
- }
- int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (luaspell && luaspell->spell) {
- ZoneServer* zone = nullptr;
- if (luaspell->caster != nullptr)
- zone = luaspell->caster->GetZone();
- if(!zone && spawn) {
- zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
- }
- Spawn* target = 0;
- if(zone) {
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->IsEntity()) {
- ((Entity*)target)->RemoveSpellBonus(luaspell);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else {
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
- }
- }
- else if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->RemoveSpellBonus(luaspell);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- float value = lua_interface->GetFloatValue(state, 3);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (value != 0) {
- int32 spell_id = 0;
- if (luaspell && luaspell->spell && luaspell->caster) {
- if(luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- spell_id = luaspell->spell->GetSpellID();
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->Alive()) {
- if (target->IsPlayer()) {
- ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
- }
- else if (target->IsNPC()) {
- ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
- luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
- }
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (spawn->IsNPC())
- ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- }
- else
- lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (spawn && spawn->IsPlayer()) {
- int32 spell_id = 0;
- if (luaspell && luaspell->spell && luaspell->caster) {
- if(luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- spell_id = luaspell->spell->GetSpellID();
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (target->IsPlayer()) {
- ((Player*)target)->RemoveSkillBonus(spell_id);
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (target->IsNPC())
- ((NPC*)target)->RemoveSkillBonus(spell_id);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->RemoveSkillBonus(spell_id);
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- else if (spawn->IsNPC())
- ((NPC*)spawn)->RemoveSkillBonus(spell_id);
- else
- LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt32Value(state, 2);
- bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
-
- if(luaspell && luaspell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target && target->IsEntity()) {
- if (type == CONTROL_EFFECT_TYPE_MEZ) {
- ((Entity*)target)->AddMezSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
- luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
- ((Entity*)target)->AddStifleSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
- luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_DAZE) {
- ((Entity*)target)->AddDazeSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
- luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_STUN) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
- luaspell->effect_bitmask += EFFECT_FLAG_STUN;
- ((Entity*)target)->AddStunSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_ROOT) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
- luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
- ((Entity*)target)->AddRootSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_FEAR) {
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
- luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
- ((Entity*)target)->AddFearSpell(luaspell);
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
- ((Entity*)target)->AddWaterwalkSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
- }
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
- ((Entity*)target)->AddWaterjumpSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
- }
- else if (type == CONTROL_EFFECT_TYPE_SNARE) {
- ((Entity*)target)->AddSnareSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
- luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
- if (target->IsNPC())
- ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
- }
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
- ((Entity*)target)->AddFlightSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
- luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
- }
- else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
- ((Entity*)target)->AddGlideSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
- luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
- }
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
- ((Entity*)target)->AddSafefallSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
- luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
- }
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- else
- lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (only_add_spawn && spawn && spawn->IsEntity()) {
- if (type == CONTROL_EFFECT_TYPE_MEZ) {
- ((Entity*)spawn)->AddMezSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
- luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
- }
- else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
- ((Entity*)spawn)->AddStifleSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
- luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
- }
- else if (type == CONTROL_EFFECT_TYPE_DAZE) {
- ((Entity*)spawn)->AddDazeSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
- luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
- }
- else if (type == CONTROL_EFFECT_TYPE_STUN) {
- ((Entity*)spawn)->AddStunSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
- luaspell->effect_bitmask += EFFECT_FLAG_STUN;
- }
- else if (type == CONTROL_EFFECT_TYPE_ROOT) {
- ((Entity*)spawn)->AddRootSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
- luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
- }
- else if (type == CONTROL_EFFECT_TYPE_FEAR) {
- ((Entity*)spawn)->AddFearSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
- luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
- }
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
- ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
- }
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
- ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
- luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
- }
- else if (type == CONTROL_EFFECT_TYPE_SNARE) {
- ((Entity*)spawn)->AddSnareSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
- luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
- }
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
- ((Entity*)spawn)->AddFlightSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
- luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
- }
- else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
- ((Entity*)spawn)->AddGlideSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
- luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
- }
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
- ((Entity*)spawn)->AddSafefallSpell(luaspell);
- if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
- luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
- }
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- else
- lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
- return 0;
- }
- int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (spawn && spawn->IsEntity()) {
- if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
- ZoneServer* zone = luaspell->caster->GetZone();
- Spawn* target = 0;
- luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < luaspell->targets.size(); i++) {
- target = zone->GetSpawnByID(luaspell->targets[i]);
- if (target) {
- if (type == CONTROL_EFFECT_TYPE_MEZ)
- ((Entity*)target)->RemoveMezSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STIFLE)
- ((Entity*)target)->RemoveStifleSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_DAZE)
- ((Entity*)target)->RemoveDazeSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STUN)
- ((Entity*)target)->RemoveStunSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_ROOT)
- ((Entity*)target)->RemoveRootSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FEAR)
- ((Entity*)target)->RemoveFearSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
- ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
- ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SNARE)
- ((Entity*)target)->RemoveSnareSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
- ((Entity*)target)->RemoveFlightSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_GLIDE)
- ((Entity*)target)->RemoveGlideSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
- ((Entity*)target)->RemoveGlideSpell(luaspell);
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- }
- luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else if (only_remove_spawn) {
- if (type == CONTROL_EFFECT_TYPE_MEZ)
- ((Entity*)spawn)->RemoveMezSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STIFLE)
- ((Entity*)spawn)->RemoveStifleSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_DAZE)
- ((Entity*)spawn)->RemoveDazeSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_STUN)
- ((Entity*)spawn)->RemoveStunSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_ROOT)
- ((Entity*)spawn)->RemoveRootSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FEAR)
- ((Entity*)spawn)->RemoveFearSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
- ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
- ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SNARE)
- ((Entity*)spawn)->RemoveSnareSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
- ((Entity*)spawn)->RemoveFlightSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_GLIDE)
- ((Entity*)spawn)->RemoveGlideSpell(luaspell);
- else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
- ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
- else
- lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- bool hasEffect = false;
- if (!spawn)
- lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsEntity())
- lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
- else if (type < CONTROL_MAX_EFFECTS)
- hasEffect = ((Entity*)spawn)->HasControlEffect(type);
- else
- lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
- lua_interface->SetBooleanValue(state, hasEffect);
- return 1;
- }
- int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = 0.0f;
- if (!spawn)
- lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- distance = ((NPC*)spawn)->GetBaseAggroRadius();
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = 0.0f;
- if (!spawn)
- lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- distance = ((NPC*)spawn)->GetAggroRadius();
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- bool override = lua_interface->GetBooleanValue(state, 3);
- bool result = false;
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- ((NPC*)spawn)->SetAggroRadius(distance, override);
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_SetIntBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetAgiBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetWisBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStaBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStrBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetDeity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 value = lua_interface->GetInt8Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetDeity(value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetDeity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- int8 deity = ((Entity*)spawn)->GetDeity();
- lua_interface->SetInt32Value(state, deity);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- sint32 value = lua_interface->GetSInt32Value(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetWis(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetSta(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float value = lua_interface->GetFloatValue(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStr(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_SetAgi(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- float value = lua_interface->GetFloatValue(state, 2);
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetHP());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalHP());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetStringValue(state, spawn->GetName());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetLevel(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetLevel());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetDifficulty(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetDifficulty());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetPower());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalPower());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
- if (spawn && spawn2) {
- float distance = spawn->GetDistance(spawn2, false, include_radius);
- lua_interface->SetFloatValue(state, distance);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetX(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetX());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetY(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetY());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZ(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetZ());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetHeading(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetHeading());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetModelType());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpeed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- lua_interface->SetFloatValue(state, spawn->GetSpeed());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasMoved(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetWis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSta(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStr(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetAgi(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetIntBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetWisBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStaBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetStrBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetAgiBase(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetStepComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (quest_id <= 0) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
- return 0;
- } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
- lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 step = lua_interface->GetInt32Value(state, 3);
- if (step > 0) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->AddPendingQuestUpdate(quest_id, step);
- } else {
- lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_AddStepProgress(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- int32 progress = lua_interface->GetInt32Value(state, 4);
- if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->AddPendingQuestUpdate(quest_id, step, progress);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step_id = lua_interface->GetInt32Value(state, 3);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_RegisterQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string name = lua_interface->GetStringValue(state, 2);
- string type = lua_interface->GetStringValue(state, 3);
- string zone = lua_interface->GetStringValue(state, 4);
- int16 level = lua_interface->GetInt16Value(state, 5);
- string description = lua_interface->GetStringValue(state, 6);
- bool load = true;
- if (!quest) {
- lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
- load = false;
- }
- if (load && name.length() == 0) {
- lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
- load = false;
- }
- if (load && type.length() == 0) {
- lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && zone.length() == 0) {
- lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && description.length() == 0) {
- lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load && level == 0) {
- lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
- load = false;
- }
- if (load)
- quest->RegisterQuest(name, type, zone, level, description);
- return 0;
- }
- int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int8 level = lua_interface->GetInt16Value(state, 2);
- quest->SetPrereqLevel(level);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- quest->AddPrereqQuest(quest_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt32Value(state, 3);
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddPrereqItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- if(!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- if (quest_id > 0) {
- lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
- return 1;
- } else {
- lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && spawn_id > 0)
- quest->SetQuestReturnNPC(spawn_id);
- return 0;
- }
- int EQ2Emu_lua_AddTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 time = lua_interface->GetInt32Value(state, 2);
- string function = lua_interface->GetStringValue(state, 3);
- int32 max_count = lua_interface->GetInt32Value(state, 4);
- Spawn* player = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (time <= 0) {
- lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (function.length() == 0) {
- lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
- return 0;
- }
- SpawnScriptTimer* timer = new SpawnScriptTimer;
- if ( time < 10)
- time = 10;
-
- timer->timer = Timer::GetCurrentTime2() + time;
- timer->function = function;
- timer->spawn = spawn->GetID();
- timer->player = player ? player->GetID() : 0;
- if (max_count == 0)
- max_count = 1;
- timer->max_count = max_count;
- timer->current_count = 0;
- spawn->GetZone()->AddSpawnScriptTimer(timer);
- return 0;
- }
- int EQ2Emu_lua_StopTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string function = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if(!spawn->GetZone()) {
- lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
- return 0;
- }
- int EQ2Emu_lua_GetQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
- Quest* quest = ((Player*)player)->player_quests[quest_id];
- if (quest)
- lua_interface->SetBooleanValue(state, quest->GetCompleted());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && quest_id > 0) {
- lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && !npc->IsPlayer() && quest_id > 0)
- npc->AddProvidedQuest(quest_id);
- return 0;
- }
- int EQ2Emu_lua_OfferQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 quest_id = lua_interface->GetInt32Value(state, 3);
- bool forced = lua_interface->GetBooleanValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- /* NPC is allowed to be null */
- if (player && player->IsPlayer() && quest_id > 0) {
- Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
- if (master_quest) {
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
- }
- Quest* quest = new Quest(master_quest);
- if (!quest) {
- lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
- }
- if (client && quest) {
- if (npc)
- quest->SetQuestGiver(npc->GetDatabaseID());
- else
- quest->SetQuestGiver(0);
- client->AddPendingQuest(quest, forced);
- }
- }
- else {
- lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
- }
- }
- else {
- lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqClass(class_id);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 race = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqRace(race);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int16 model_type = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqModelType(model_type);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetPrereqTSLevel(level);
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->AddPrereqTradeskillClass(class_id);
- return 0;
- }
- int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 min = lua_interface->GetSInt32Value(state, 3);
- sint32 max = lua_interface->GetSInt32Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddPrereqFaction(faction_id, min, max);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddSelectableRewardItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (quest) {
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- vector<Item*>* items = quest->GetRewardItems();
- if (items) {
- vector<Item*>::iterator itr;
- for (itr = items->begin(); itr != items->end(); itr++) {
- if (*itr && (*itr)->details.item_id == item_id) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
- int8 quantity = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (quantity == 0)
- quantity = 1;
- Item* master_item = master_item_list.GetItem(item_id);
- if (master_item) {
- Item* item = new Item(master_item);
- item->details.count = quantity;
- quest->AddRewardItem(item);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 copper = lua_interface->GetInt32Value(state, 2);
- int32 silver = lua_interface->GetInt32Value(state, 3);
- int32 gold = lua_interface->GetInt32Value(state, 4);
- int32 plat = lua_interface->GetInt32Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->AddRewardCoins(copper, silver, gold, plat);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 amount = lua_interface->GetSInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest && faction_id > 0 && amount != 0)
- quest->AddRewardFaction(faction_id, amount);
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 status = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardStatus(status);
- }
- return 0;
- }
- int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 status = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetStatusTmpReward(status);
- }
- return 0;
- }
- int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int64 coins = lua_interface->GetInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetCoinTmpReward(coins);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string comment = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardComment(comment);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 exp = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- quest->SetRewardXP(exp);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStep(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- int32 usableitemid = lua_interface->GetInt32Value(state, 8);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
-
-
- int32 id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
- if (quest_step && icon && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
- {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
-
- int32 id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
- return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
- }
- int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
- return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
- }
- int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 npc_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(npc_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- if(client)
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int8 i = 7;
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 4;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int8 i = 7;
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- loc.zone_id = 0;
-
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 3;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- float max_variation = lua_interface->GetFloatValue(state, 4);
- string str_taskgroup = lua_interface->GetStringValue(state, 5);
- int16 icon = lua_interface->GetInt16Value(state, 6);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- vector<Location>* locations = 0;
- int i = 7;
- while (true) {
- Location loc;
- loc.x = lua_interface->GetFloatValue(state, i);
- loc.y = lua_interface->GetFloatValue(state, i + 1);
- loc.z = lua_interface->GetFloatValue(state, i + 2);
- if (loc.x == 0 && loc.y == 0 && loc.z == 0)
- break;
- if (locations == 0)
- locations = new vector<Location>;
- locations->push_back(loc);
- i += 3;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
- safe_delete(locations); // gets duplicated into new table in QuestStep constructor
- if (quest_step && icon > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 spell_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(spell_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 quantity = lua_interface->GetInt32Value(state, 4);
- float percentage = lua_interface->GetFloatValue(state, 5);
- string str_taskgroup = lua_interface->GetStringValue(state, 6);
- int16 icon = lua_interface->GetInt16Value(state, 7);
- if (quest) {
- const char* taskgroup = 0;
- if (str_taskgroup.length() > 0)
- taskgroup = str_taskgroup.c_str();
- int32 item_id = 0;
- vector<int32>* ids = 0;
- int i = 0;
- while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
- if (ids == 0)
- ids = new vector<int32>;
- ids->push_back(item_id);
- i++;
- }
- QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
- if (quest_step && icon > 0 && quantity > 0)
- quest_step->SetIcon(icon);
- if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
- Client* client = ((Player*)quest->GetPlayer())->GetClient();
- quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
- }
- safe_delete(ids);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string action = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (action.length() > 0)
- quest->SetCompleteAction(action);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (step > 0 && action.length() > 0)
- quest->AddCompleteAction(step, action);
- }
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest) {
- if (step > 0 && action.length() > 0)
- quest->AddProgressAction(step, action);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string description = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && description.length() > 0)
- quest->SetDescription(description);
- return 0;
- }
- int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- string description = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && description.length() > 0)
- quest->SetCompletedDescription(description);
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (quest && step > 0 && description.length() > 0) {
- quest->SetTaskGroupDescription(step, description, display_bullets);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (quest && step > 0 && description.length() > 0) {
- quest->SetStepDescription(step, description);
- }
- return 0;
- }
- int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
- Quest* quest = lua_interface->GetQuest(state);
- string zone = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && zone.length() > 0)
- quest->SetZone(zone);
- return 0;
- }
- int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (quest && spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- client->AddPendingQuestReward(quest);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_Harvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* node = lua_interface->GetSpawn(state, 2);
- if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- ((GroundSpawn*)node)->ProcessHarvest(client);
- if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
- }
- }
- }
- else if (player && player->IsPlayer()) {
- Client* client = ((Player*)player)->GetClient();
- if (client)
- client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_Bind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 zone_id = lua_interface->GetInt32Value(state, 2);
- float x = lua_interface->GetFloatValue(state, 3);
- float y = lua_interface->GetFloatValue(state, 4);
- float z = lua_interface->GetFloatValue(state, 5);
- float h = lua_interface->GetFloatValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (zone_id == 0) {
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!client->Bind())
- client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
- }
- else {
- Player* player = (Player*)spawn;
- player->GetPlayerInfo()->SetBindZone(zone_id);
- player->GetPlayerInfo()->SetBindX(x);
- player->GetPlayerInfo()->SetBindY(y);
- player->GetPlayerInfo()->SetBindZ(z);
- player->GetPlayerInfo()->SetBindHeading(h);
- }
- return 0;
- }
- int EQ2Emu_lua_Gate(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- if (!client->Gate((spell != nullptr) ? true : false))
- client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool ret = false;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ret = client->BindAllowed();
- }
- }
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool ret = false;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- ZoneServer* zone = lua_interface->GetZone(state);
- if (client && zone){
- ret = zone->GetCanGate();
- }
- }
- }
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_IsAlive(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->Alive());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsInCombat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SendMessage(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- string color_str = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- int8 color = CHANNEL_NARRATIVE;
- if (spawn && spawn->IsPlayer() && message.length() > 0) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- if (color_str.length() > 0) {
- // leave for backwards compat, but all future should just use the number
- if (strncasecmp(color_str.c_str(), "red", 3) == 0)
- color = CHANNEL_COLOR_RED;
- else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
- color = CHANNEL_COLOR_YELLOW;
- else
- {
- // use a number to specify the channel as per Commands/Commands.h defines
- color = (int8)atoul(color_str.c_str());
- }
- }
- client->SimpleMessage(color, message.c_str());
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- string message = lua_interface->GetStringValue(state, 2);
- int8 red = lua_interface->GetInt8Value(state, 3);
- int8 green = lua_interface->GetInt8Value(state, 4);
- int8 blue = lua_interface->GetInt8Value(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 words = ::CountWordsInString(message.c_str());
- if (words < 5)
- words = 5;
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
- return 0;
- }
- int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 param = lua_interface->GetInt8Value(state, 2);
- int8 param_value = lua_interface->GetInt8Value(state, 3);
- int8 value = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
- switch (param) {
- case 1: {
- packet->setDataByName("parameter1", param_value);
- break;
- }
- case 2: {
- packet->setDataByName("parameter2", param_value);
- break;
- }
- case 3: {
- packet->setDataByName("parameter3", param_value);
- break;
- }
- case 4: {
- packet->setDataByName("parameter4", param_value);
- break;
- }
- case 5: {
- packet->setDataByName("parameter5", param_value);
- break;
- }
- }
- packet->setDataByName("value", value);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_ToggleTracking(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsPlayer()) {
- if (((Player*)spawn)->GetIsTracking())
- spawn->GetZone()->AddPlayerTracking((Player*)spawn);
- else
- spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
- }
- return 0;
- }
- int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string command = lua_interface->GetStringValue(state, 5);
- string error_text = lua_interface->GetStringValue(state, 6);
- int16 cast_time = lua_interface->GetInt16Value(state, 7);
- int32 spell_visual = lua_interface->GetInt32Value(state, 8);
- bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (distance == 0)
- distance = 10.0f;
- if (command.length() == 0)
- command = name;
- if (command.length() < 1 && name.length() < 1)
- {
- // have to run this first to send a 'blank' default command, then remove all commands from the list
- spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
- spawn->RemovePrimaryCommands();
- }
- else
- {
- spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- int16 tier = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- int16 tier = lua_interface->GetInt16Value(state, 3);
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool add_silently = lua_interface->GetBooleanValue(state, 4);
- bool add_to_hotbar = true;
- if (num_args > 4) {
- add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
- }
- lua_interface->ResetFunctionStack(state);
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- if (player && spell && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
- {
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- client->GetPlayer()->UnlockSpell(spell);
- client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
- }
- else
- {
- Spell* spell = master_spell_list.GetSpell(spellid, tier);
- int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
- client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
- client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- client->GetPlayer()->UnlockSpell(spell);
- client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
- }
- //if (client ) {
- // ((Player*)player)->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), ((Player*)player)->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 type_selection = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- ((Player*)player)->DeleteSpellBook(type_selection);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- client->SendNewAdventureSpells();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client) {
- client->SendNewTradeskillSpells();
- }
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spellid = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
- Client* client = player->GetClient();
- if (sbe && client) {
- ((Player*)player)->RemoveSpellBookEntry(spellid);
- EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
- if (outapp)
- client->QueuePacket(outapp);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_Attack(lua_State* state) {
- if (lua_interface) {
- Spawn* npc = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (npc && player && npc->IsNPC() && player->IsEntity())
- ((NPC*)npc)->AddHate((Entity*)player, 100);
- }
- return 0;
- }
- int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
- if (lua_interface) {
- Spawn* target = lua_interface->GetSpawn(state);
- int32 spell_visual = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (target && target->GetZone())
- target->GetZone()->SendCastSpellPacket(spell_visual, target);
- }
- return 0;
- }
- int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
- Spawn* player;
- if (lua_interface) {
- player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_HandInCollections(lua_State* state) {
- Spawn* player;
- Client* client;
- if (lua_interface) {
- player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
- if ((client = ((Player*)player)->GetClient()))
- client->HandInCollections();
- }
- return 0;
- }
- int EQ2Emu_lua_UseWidget(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleUse(nullptr, "");
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellList(lua_State* state) {
- Spawn* spawn = 0;
- int32 primary_list = 0;
- int32 secondary_list = 0;
- if (lua_interface) {
- spawn = lua_interface->GetSpawn(state);
- primary_list = lua_interface->GetInt32Value(state, 2);
- secondary_list = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- NPC* npc = (NPC*)spawn;
- npc->SetPrimarySpellList(primary_list);
- npc->SetSecondarySpellList(secondary_list);
- npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
- }
- return 0;
- }
- int EQ2Emu_lua_GetPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetDeityPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
- lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_Charm(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* owner = lua_interface->GetSpawn(state);
- Spawn* pet = lua_interface->GetSpawn(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell) {
- lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
- ((Entity*)owner)->SetCharmedPet((Entity*)pet);
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
- ((NPC*)pet)->SetOwner((Entity*)owner);
- // If owner is player and player does not have a summoned pet set the players charsheet
- if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
- Player* player = (Player*)owner;
- player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
- player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
- player->GetInfoStruct()->set_pet_movement(2);
- player->GetInfoStruct()->set_pet_behavior(3);
- player->GetInfoStruct()->set_pet_health_pct(1.0f);
- player->GetInfoStruct()->set_pet_power_pct(1.0f);
- // Make sure the values get sent to the client
- player->SetCharSheetChanged(true);
- }
- // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
- pet->SetSpawnScript("");
- // Set faction to the same as the owner
- pet->SetFactionID(owner->GetFactionID());
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Clear hate list
- ((NPC*)pet)->Brain()->ClearHate();
- // Set the brain to a pet brain
- ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
- }
- return 0;
- }
- int EQ2Emu_lua_GetGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Spawn*> groupMembers;
- if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
- groupMembers = *spawn->GetSpawnGroup();
- }
- else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- GroupMemberInfo* info = 0;
- for (itr = members->begin(); itr != members->end(); itr++) {
- info = *itr;
- if (info->client)
- groupMembers.push_back(info->client->GetPlayer());
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else
- return 0;
- lua_createtable(state, groupMembers.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < groupMembers.size(); i++) {
- lua_interface->SetSpawnValue(state, groupMembers.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
- vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
- lua_interface->SetOptionWindowValue(state, option_window);
- return 1;
- }
- int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
- if (option_window) {
- OptionWindowOption option_window_option;
- option_window_option.optionName = lua_interface->GetStringValue(state, 2);
- option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
- option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
- option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
- option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
- option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
- if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
- option_window->push_back(option_window_option);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- string window_title = lua_interface->GetStringValue(state, 3);
- string cancel_command = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
-
- if (option_window && window_title.length() > 0 && client) {
- PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
- if (!packet)
- return 0;
- packet->setDataByName("title_text", window_title.c_str());
- if (cancel_command.length() > 0)
- packet->setDataByName("command_text_cancel", cancel_command.c_str());
- packet->setArrayLengthByName("num_selections", option_window->size());
- vector<OptionWindowOption>::iterator itr;
- int8 i = 0;
- for (itr = option_window->begin(); itr != option_window->end(); itr++) {
- OptionWindowOption opt = *itr;
- packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
- packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
- packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
- packet->setArrayDataByName("icon_id", opt.optionIconID, i);
- if (opt.optionCommand.length() > 0)
- packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
- if (opt.optionConfirmTitle.length() > 0)
- packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
- i++;
- }
- client->QueuePacket(packet->serialize());
- lua_interface->SetLuaUserDataStale(option_window);
- safe_delete(option_window);
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetInt32Value(state, spawn->GetTSLevel());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- int8 class_id = spawn->GetTradeskillClass();
- // Need to add 42 for the offset in the array
- class_id += 44;
- lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 level = lua_interface->GetInt8Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
- ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
- else
- spawn->SetTSLevel(level);
- }
- else
- lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetAttackable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 attackable = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetAttackable(attackable);
- spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
- }
- return 0;
- }
- int EQ2Emu_lua_SummonPet(lua_State* state) {
- // Check to see if we have a valid lua_interface
- if (!lua_interface)
- return 0;
- // Get the spawn that is getting the pet
- Spawn* spawn = lua_interface->GetSpawn(state);
- // Get the DB ID of the pet
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- // The max level the pet can gain
- int8 max_level = lua_interface->GetInt8Value(state, 3);
- // Get the spell that this command was called from
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Check to make sure the spawn pointer is valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn is an entity
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn doesn't already have a pet of this type
- if (((Entity*)spawn)->GetPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
- }
- lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the DB ID for the pet is set
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the pointer to the spell is valid
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
-
- // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- // Check to make sure the pet is an npc
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- // Spawn the pet at the same location as the owner
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- std::string petName = std::string("");
- if(spawn->IsEntity()) {
- petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
- }
-
- if(petName.size() < 1) {
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- petName = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
- }
- // If player set various values for the char sheet (pet window)
- if (spawn->IsPlayer()) {
- Player* player = (Player*)spawn;
-
- player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
- player->GetInfoStruct()->set_pet_name(petName);
- player->GetInfoStruct()->set_pet_movement(2);
- player->GetInfoStruct()->set_pet_behavior(3);
- player->GetInfoStruct()->set_pet_health_pct(1.0f);
- player->GetInfoStruct()->set_pet_power_pct(1.0f);
- // Make sure the values get sent to the client
- player->SetCharSheetChanged(true);
- }
- // Set the pets name
- pet->SetName(petName.c_str());
- // Set the level of the pet to the owners level or max level(if set) if owners level is greater
- if (max_level > 0)
- pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
- else
- pet->SetLevel(spawn->GetLevel());
- // Set the max level this pet can reach
- ((NPC*)pet)->SetMaxPetLevel(max_level);
-
- ((NPC*)pet)->UpdateWeapons();
-
- // Set the faction of the pet to the same faction as the owner
- pet->SetFactionID(spawn->GetFactionID());
- // Set the spawn as a pet
- pet->SetPet(true);
- // Give a pointer of the owner to the pet
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- // Give a pointer of the pet to the owner
- ((Entity*)spawn)->SetCombatPet((Entity*)pet);
- // Set the pet type
- ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
- // Set the spell id used to create this pet
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- // Set the spell tier used to create this pet
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Set the pets spawn type to 6
- pet->SetSpawnType(6);
- // Set the pets brain
- ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
- // Check to see if the pet has a subtitle
- if (strlen(pet->GetSubTitle()) > 0) {
- // Add the players name to the front of the sub title
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- // Set the pets subtitle to the new one
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // Add the "Pet Options" entity command to the pet
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
-
- const char* spawn_script = world.GetSpawnScript(pet_id);
- bool runScript = false;
- if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
- runScript = true;
- pet->SetSpawnScript(string(spawn_script));
- spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
- }
-
- spawn->GetZone()->AddSpawn(pet);
-
- if(runScript){
- spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
- }
-
- // Set the pet as the return value for this function
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetDeityPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
- }
- lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
- string random_pet_name;
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
- pet->SetName(random_pet_name.c_str());
- pet->SetLevel(spawn->GetLevel());
- pet->SetFactionID(spawn->GetFactionID());
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- ((Entity*)spawn)->SetDeityPet((Entity*)pet);
- pet->SetSpawnType(6);
- ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- if (strlen(pet->GetSubTitle()) > 0) {
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // deity and cosmetic pets are not attackable
- pet->SetAttackable(false);
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 pet_id = lua_interface->GetInt32Value(state, 2);
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetCosmeticPet()) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
- }
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
-
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- if (!pet->IsNPC()) {
- lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
- return 0;
- }
- pet->SetX(spawn->GetX());
- pet->SetY(spawn->GetY());
- pet->SetZ(spawn->GetZ());
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
- string random_pet_name;
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
- pet->SetName(random_pet_name.c_str());
- pet->SetLevel(spawn->GetLevel());
- pet->SetFactionID(spawn->GetFactionID());
- pet->SetPet(true);
- ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
- pet->SetSpawnType(6);
- ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- if (strlen(pet->GetSubTitle()) > 0) {
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- pet->SetAttackable(false);
- pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_DismissPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPet()) {
- lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
- ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
- return 0;
- }
- int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestFeatherColor command error: valid quest not found, SetQuestFeatherColor can only be called from a quest script", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int8 feather_color = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (feather_color > 0)
- quest->SetFeatherColor(feather_color);
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn2) {
- lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->RemoveSpawnAccess(spawn2);
- return 0;
- }
- int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (location_id == 0) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
- return 0;
- }
- SpawnLocation* location = zone->GetSpawnLocation(location_id);
- if (!location) {
- lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
- return 0;
- }
-
- int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
- Spawn* spawn = 0;
- if (location->entities[rand_number]) {
- if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
- if(spawn && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
- safe_delete(spawn);
- spawn = 0;
- return 0;
- }
- if (spawn) {
- const char* script = 0;
- for (int x = 0; x < 3; x++) {
- switch (x) {
- case 0:
- script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(location->entities[0]->spawn_id);
- break;
- }
- if (script && lua_interface->GetSpawnScript(script) != 0) {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
- safe_delete(spawn);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 id = lua_interface->GetInt32Value(state, 3);
- string command = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsPlayer()) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
- if (!entity_command) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid EntityCommand with the given ID (%u) and name (%s)", lua_interface->GetScriptName(state), id, command.c_str());
- return 0;
- }
- Client* client = ((Player*)caster)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
- return 0;
- }
- client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
- return 0;
- }
- int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
- return 0;
- }
- int EQ2Emu_lua_SetBrainTick(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 tick = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
- return 0;
- }
- if (tick < 20) {
- lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->SetTick(tick);
- return 0;
- }
- int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 follow_distance = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
- spawn->SetFollowTarget(target, follow_distance);
- return 0;
- }
- int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* target = spawn->GetFollowTarget();
- if (target) {
- lua_interface->SetSpawnValue(state, target);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ToggleFollow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->following)
- spawn->following = false;
- else
- spawn->following = true;
- return 0;
- }
- int EQ2Emu_lua_IsFollowing(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->following);
- return 1;
- }
- int EQ2Emu_lua_SetTempVariable(lua_State* state) {
- // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
- // I will attempt to explain how this function works for future refrence
- // Fist lets make sure lua_interface is valid, if not return out
- if (!lua_interface)
- return 0;
- // Next we grab the first 2 params same as we usually would
- Spawn* spawn = lua_interface->GetSpawn(state);
- string var = lua_interface->GetStringValue(state, 2);
- // DataType will let us know the value type so we can handle it correctly, we set these ourself so the values I used are made up
- // 1 = Spawn
- // 2 = Zone
- // 3 = Item
- // 4 = Quest
- // 5 = String
- // 6 = nil (null)
- int8 dataType = 0;
- // Define pointers for each potential type
- Spawn* spawnVal = 0;
- ZoneServer* zone = 0;
- Item* item = 0;
- Quest* quest = 0;
- string val;
- // Finally we get to grabbing the third param, we will first check to see if it is light user data
- // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
- // options window are also light user data be we do not handle those.
- // We check with lua_islightuserdata(lua_State*, index)
- if (lua_islightuserdata(state, 3)) {
- // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
- // and convert it to LUAUserData*
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
- // Check to make sure the data we got is valid, if not give an error
- if (!data || !data->IsCorrectlyInitialized()) {
- lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
- }
- // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
- else if (data->IsSpawn()) {
- spawnVal = data->spawn;
- dataType = 1;
- }
- // Check if data is a Zone, if so set our Zone pointer and the dataType variable
- else if (data->IsZone()) {
- zone = data->zone;
- dataType = 2;
- }
- // Check if data is a Item, if so set our Item pointer and the dataType variable
- else if (data->IsItem()) {
- item = data->item;
- dataType = 3;
- }
- // Check if data is a Ques, if so set our Quest pointer and the dataType variable
- else if (data->IsQuest()) {
- quest = data->quest;
- dataType = 4;
- }
- }
- // Wasn't light user data, check if it is nil(null)
- else if (lua_isnil(state, 3)) {
- // It is nil (null) set the dataType variable, no need to set a pointer in this case
- dataType = 6;
- }
- // Wasn't light user data or nil (null), must be a string
- else {
- // Set the string and dataType variable
- val = lua_interface->GetStringValue(state, 3);
- dataType = 5;
- }
-
- lua_interface->ResetFunctionStack(state);
- // We now have all the params, lets check to make sure they are valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (var.length() == 0) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (dataType == 0) {
- lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
- return 0;
- }
- // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
- // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
- // param gets sent to the correct list so we check the value of dataType to know where it should go.
- switch (dataType) {
- case 1:
- // 1 = Spawn
- spawn->AddTempVariable(var, spawnVal);
- break;
- case 2:
- // 2 = Zone
- spawn->AddTempVariable(var, zone);
- break;
- case 3:
- // 3 = Item
- spawn->AddTempVariable(var, item);
- break;
- case 4:
- // 4 = Quest
- spawn->AddTempVariable(var, quest);
- break;
- case 5:
- // 5 = String
- spawn->AddTempVariable(var, val);
- break;
- case 6:
- // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
- spawn->DeleteTempVariable(var);
- break;
- }
- // And we are done so return out
- return 0;
- }
- int EQ2Emu_lua_GetTempVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string var = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (var.length() == 0) {
- lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- // This will tell us the type of data this variable contains, uses the same values as the previous function
- int8 type = spawn->GetTempVariableType(var);
- Spawn* spawn2 = 0;
- ZoneServer* zone = 0;
- Item* item = 0;
- Quest* quest = 0;
- // Set the lua function return value based on the type of data the variable contains
- switch (type) {
- case 1:
- spawn2 = spawn->GetTempVariableSpawn(var);
- if (!spawn2)
- return 0;
- lua_interface->SetSpawnValue(state, spawn2);
- break;
- case 2:
- zone = spawn->GetTempVariableZone(var);
- if (!zone)
- return 0;
- lua_interface->SetZoneValue(state, zone);
- break;
- case 3:
- item = spawn->GetTempVariableItem(var);
- if (!item)
- return 0;
- lua_interface->SetItemValue(state, item);
- break;
- case 4:
- quest = spawn->GetTempVariableQuest(var);
- if (!quest)
- return 0;
- lua_interface->SetQuestValue(state, quest);
- break;
- case 5:
- lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
- break;
- default:
- // Not a valid type then the variable was not set so return out
- return 0;
- }
- // Return value was set so return out
- return 1;
- }
- int EQ2Emu_lua_GiveQuestItem(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string description = lua_interface->GetStringValue(state, 3);
- int32 item_id = lua_interface->GetInt32Value(state, 4);
- if (!quest) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (item_id == 0) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- Item* item = master_item_list.GetItem(item_id);
- if (!item) {
- lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- Item* firstItem = new Item(item);
- quest->AddTmpRewardItem(firstItem);
- int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
- bool itemsAddedSuccessfully = true;
- if(num_args > 4)
- {
- for(int8 n=5;n<num_args+1;n++)
- {
- int32 new_item = lua_interface->GetInt32Value(state, n);
- Item* tmpItem = master_item_list.GetItem(new_item);
- if(tmpItem)
- {
- Item* newTmpItem = new Item(tmpItem);
- quest->AddTmpRewardItem(newTmpItem);
- }
- else
- itemsAddedSuccessfully = false;
- }
- }
- client->AddPendingQuestReward(quest, true, true, description); // queue for display
-
- lua_interface->ResetFunctionStack(state);
-
- lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
- return 1;
- }
- int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetRepeatable(true);
- return 0;
- }
- int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
- string ret = classes.GetClassNameCase(base_class);
- if (ret.length() > 0) {
- lua_interface->SetStringValue(state, ret.c_str());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SendWaypoints(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->SendWaypoints();
- }
- return 0;
- }
- int EQ2Emu_lua_AddWaypoint(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- int32 type = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (type == 0)
- type = 2;
- if (name.length() > 0) {
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->AddWaypoint(name, type);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (name.length() > 0) {
- if (player && player->IsPlayer()) {
- Client* client = player->GetClient();
- if (client)
- client->RemoveWaypoint(name);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_AddWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 damage = lua_interface->GetInt32Value(state);
- bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
- int8 wardType = lua_interface->GetInt8Value(state, 3);
- int8 damageTypes = lua_interface->GetInt8Value(state, 4);
- int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
- int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
- int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
- int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spell || spell->resisted) {
- return 0;
- }
-
- bool ward_was_added = false;
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (!target)
- continue;
- if (target->IsEntity()) {
- // If the ward is already active remove it
- if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
- ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
- // Create new ward info
- WardInfo* ward = new WardInfo;
- ward->Spell = spell;
- ward->BaseDamage = damage;
- ward->DamageLeft = damage;
- ward->AbsorbAllDamage = (damage == 0) ? true : false;
- ward->keepWard = keepWard;
- ward->WardType = wardType;
- if (damageAbsorptionPercent > 100)
- damageAbsorptionPercent = 100;
- ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
- if (damageAbsorptionMaxHealthPercent > 100)
- damageAbsorptionMaxHealthPercent = 100;
- ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
- ward->RedirectDamagePercent = redirectDamagePercent;
- ward->LastRedirectDamage = 0;
- ward->LastAbsorbedDamage = 0;
- ward->HitCount = 0;
- spell->num_triggers = maxHitCount;
- spell->had_triggers = true;
- spell->cancel_after_all_triggers = false;
- ward->MaxHitCount = maxHitCount;
- ward->RoundTriggered = false;
- if (wardType == WARD_TYPE_MAGICAL)
- ward->DamageType = damageTypes;
- // Add the ward to the entity
- ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
- ward_was_added = true;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (ward_was_added && spell->caster->IsPlayer()) {
- spell->had_dmg_remaining = true;
- ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
- }
- return 0;
- }
- int EQ2Emu_lua_AddToWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 amount = lua_interface->GetInt32Value(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- WardInfo* ward = 0;
-
- if(!spell || spell->resisted) {
- return 0;
- }
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
- ward = target->GetWard(spell->spell->GetSpellID());
- if (target && ward) {
- ward->DamageLeft += amount;
- if (ward->DamageLeft > ward->BaseDamage)
- ward->DamageLeft = ward->BaseDamage;
- for (int32 i = 0; i < spell->targets.size(); i++) {
- if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
- zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
- }
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- if (ward && spell->caster->IsPlayer())
- ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
- return 0;
- }
- int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
- WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
- if (ward) {
- lua_interface->SetInt32Value(state, ward->DamageLeft);
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 1;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_GetWardValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string type = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
- Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
- WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
- if (ward) {
- if (boost::iequals(type, "damageleft"))
- lua_interface->SetInt32Value(state, ward->DamageLeft);
- else if (boost::iequals(type, "basedamage"))
- lua_interface->SetInt32Value(state, ward->BaseDamage);
- else if (boost::iequals(type, "keepward"))
- lua_interface->SetBooleanValue(state, ward->keepWard);
- else if (boost::iequals(type, "wardtype"))
- lua_interface->SetInt32Value(state, ward->WardType);
- else if (boost::iequals(type, "dmgabsorptionpct"))
- lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
- else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
- lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
- else if (boost::iequals(type, "redirectdamagepercent"))
- lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
- else if (boost::iequals(type, "lastredirectdamage"))
- lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
- else if (boost::iequals(type, "lastabsorbeddamage"))
- lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
- else if (boost::iequals(type, "hitcount"))
- lua_interface->SetInt32Value(state, ward->HitCount);
- else if (boost::iequals(type, "maxhitcount"))
- lua_interface->SetInt32Value(state, ward->MaxHitCount);
- else
- lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
-
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 1;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_RemoveWard(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spell) {
- return 0;
- }
-
- ZoneServer* zone = spell->caster->GetZone();
- Spawn* target = 0;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- return 0;
- }
- int EQ2Emu_lua_Interrupt(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
- Spawn* target = lua_interface->GetSpawn(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!caster)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity() && !spell)
- {
- lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target && spell) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
- return 0;
- }
- int EQ2Emu_lua_Stealth(lua_State* state) {
- if (!lua_interface)
- return 0;
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spell->caster->GetZone();
- if (spawn) {
- if (spawn->IsEntity()) {
- if (type == 1) {
- ((Entity*)spawn)->AddStealthSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
- spell->effect_bitmask += EFFECT_FLAG_STEALTH;
- }
- else if (type == 2) {
- ((Entity*)spawn)->AddInvisSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
- spell->effect_bitmask += EFFECT_FLAG_INVIS;
- }
- return 0;
- }
- else {
- lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
- return 0;
- }
- }
- else {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- if (type == 1) {
- ((Entity*)spawn)->AddStealthSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
- spell->effect_bitmask += EFFECT_FLAG_STEALTH;
- }
- else if (type == 2) {
- ((Entity*)spawn)->AddInvisSpell(spell);
- if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
- spell->effect_bitmask += EFFECT_FLAG_INVIS;
- }
- else {
- lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
- break;
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_IsStealthed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_IsInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsEntity()) {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
- return 1;
- }
- else
- lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 item_id = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
- return 1;
- }
- int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
- if (!item) {
- lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
- if (!item) {
- lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- int32 item_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- Item* item = master_item_list.GetItem(item_id);
- if (!item) {
- lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
- return 0;
- }
-
- Item* copy = new Item(item);
- bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
- if(result)
- {
- ((Entity*)spawn)->SetEquipment(copy, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- }
- else
- {
- safe_delete(copy);
- }
-
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- Item* item = lua_interface->GetItem(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item) {
- lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
- return 0;
- }
-
- bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
- if(result)
- {
- ((Entity*)spawn)->SetEquipment(item, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_UnequipSlot(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if(slot >= NUM_SLOTS) {
- lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
- return 0;
- }
-
- if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
- Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
- if(item) {
- item->save_needed = true;
- if(no_delete_item) {
- database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
- ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
- }
- else{
- Client* client = ((Player*)spawn)->GetClient();
- client->UnequipItem(item->details.index);
- }
- }
- }
- else
- ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
-
- ((Entity*)spawn)->SetEquipment(nullptr, slot);
- spawn->vis_changed = true;
- if(spawn->IsPlayer())
- ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SetEquipment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 slot = lua_interface->GetInt8Value(state, 2);
- int16 type = lua_interface->GetInt16Value(state, 3);
- int8 r = lua_interface->GetInt8Value(state, 4);
- int8 g = lua_interface->GetInt8Value(state, 5);
- int8 b = lua_interface->GetInt8Value(state, 6);
- int8 h_r = lua_interface->GetInt8Value(state, 7);
- int8 h_g = lua_interface->GetInt8Value(state, 8);
- int8 h_b = lua_interface->GetInt8Value(state, 9);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
- spawn->vis_changed = true;
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_GetItemByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- int8 count = lua_interface->GetInt8Value(state, 3);
- bool include_bank = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!count)
- count = 1;
- Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetItemValue(state, item);
- return 1;
- }
- int EQ2Emu_lua_PlayAnimation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 anim = lua_interface->GetInt32Value(state, 2);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
- int8 type = lua_interface->GetInt8Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn2) {
- if (spawn2->IsPlayer()) {
- if (type != 1 && type != 2)
- spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
- else
- spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
- return 0;
- }
- else {
- lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- }
- else
- spawn->GetZone()->PlayAnimation(spawn, anim);
- return 0;
- }
- int EQ2Emu_lua_IsPet(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsPet());
- return 1;
- }
- int EQ2Emu_lua_GetOwner(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((NPC*)spawn)->GetOwner()) {
- lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetTarget(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetTarget(target);
- return 0;
- }
- int EQ2Emu_lua_SetInCombat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->InCombat(val);
- if (val) {
- spawn->ClearRunningLocations();
- spawn->CalculateRunningLocation(true);
- }
- return 0;
- }
- int EQ2Emu_lua_CompareSpawns(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn1 = lua_interface->GetSpawn(state);
- Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn1) {
- lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn2) {
- lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
- return 1;
- }
- int EQ2Emu_lua_ClearRunback(lua_State* state){
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->ClearRunback();
- return 0;
- }
- int EQ2Emu_lua_Runback(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Runback();
- return 0;
- }
- int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
- return 1;
- }
- int EQ2Emu_lua_IsCasting(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
- return 1;
- }
- int EQ2Emu_lua_IsMezzed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
- return 1;
- }
- int EQ2Emu_lua_IsStunned(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
- return 1;
- }
- int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
- return 1;
- }
- int EQ2Emu_lua_ProcessSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float distance = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
- return 1;
- }
- int EQ2Emu_lua_ProcessMelee(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float distance = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
- return 0;
- }
- int EQ2Emu_lua_HasRecovered(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
- return 1;
- }
- int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
- return 1;
- }
- int EQ2Emu_lua_GetMostHated(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
- if (hated) {
- lua_interface->SetSpawnValue(state, hated);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_ClearHate(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* hated = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!hated) {
- ((NPC*)spawn)->Brain()->ClearHate();
- return 0;
- }
- else
- {
- if (!hated->IsEntity()) {
- lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
- return 0;
- }
- return 0;
- }
- int EQ2Emu_lua_ClearEncounter(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- ((NPC*)spawn)->Brain()->ClearEncounter();
- return 0;
- }
- int EQ2Emu_lua_GetEncounter(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- // Temp list to store hate list
- vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
- if (encounterList->size() == 0) {
- safe_delete(encounterList);
- return 0;
- }
- lua_createtable(state, encounterList->size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < encounterList->size(); i++) {
- Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
- if (temp)
- lua_interface->SetSpawnValue(state, temp);
- lua_rawseti(state, newTable, i + 1);
- }
- safe_delete(encounterList);
- return 1;
- }
- int EQ2Emu_lua_GetHateList(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsNPC()) {
- lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
- return 0;
- }
- // Temp list to store hate list
- vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
- if (hateList->size() == 0) {
- safe_delete(hateList);
- return 0;
- }
- lua_createtable(state, hateList->size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < hateList->size(); i++) {
- lua_interface->SetSpawnValue(state, hateList->at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- safe_delete(hateList);
- return 1;
- }
- int EQ2Emu_lua_HasGroup(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->IsPlayer()) {
- if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- else {
- lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
- return 1;
- }
- }
- int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetCompletedFlag(true);
- return 0;
- }
- int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spellID = lua_interface->GetInt32Value(state, 2);
- int8 tier = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spellID == 0) {
- lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
- if (effect) {
- if (tier > 0) {
- // If a tier was passed chec to see if it is the same as the effect
- if (tier == effect->tier)
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- else {
- // Have an effect but no tier was passed so return true
- lua_interface->SetBooleanValue(state, true);
- }
- return 1;
- }
- // no effect so return false
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- ZoneServer* zone = lua_interface->GetZone(state, 3);
- lua_interface->ResetFunctionStack(state);
- Spawn* spawn2 = 0;
- vector<Spawn*> list;
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //If zone not provided, use spawn's zone
- if (!zone)
- zone = spawn->GetZone();
- list = zone->GetSpawnsByID(id);
- if (list.size() == 0) {
- lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Spawn*>::iterator itr = list.begin();
- for (int8 i = 0; i < list.size(); i++) {
- spawn2 = itr[i];
- if (spawn2)
- spawn2->AddAllowAccessSpawn(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 id = lua_interface->GetInt32Value(state, 2);
- ZoneServer* zone = lua_interface->GetZone(state, 3);
- lua_interface->ResetFunctionStack(state);
- Spawn* spawn2 = 0;
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //If zone not provided, use spawn's zone
- if (!zone)
- zone = spawn->GetZone();
- vector<Spawn*> list = zone->GetSpawnsByID(id);
- vector<Spawn*>::iterator itr = list.begin();
- if (list.size() == 0) {
- lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- for (int8 i = 0; i < list.size(); i++) {
- spawn2 = itr[i];
- if (spawn2)
- spawn2->RemoveSpawnAccess(spawn);
- }
- return 0;
- }
- int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetYellowName(true);
- return 0;
- }
- int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
- return 1;
- }
- int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- Instance_Type iType = zone->GetInstanceType();
- if (iType == SOLO_LOCKOUT_INSTANCE ||
- iType == GROUP_LOCKOUT_INSTANCE ||
- iType == RAID_LOCKOUT_INSTANCE ||
- iType == SOLO_PERSIST_INSTANCE ||
- iType == GROUP_PERSIST_INSTANCE ||
- iType == RAID_PERSIST_INSTANCE) {
- InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
- if (data) {
- // Check to see if the timer has already been set, if it has return out.
- if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
- return 0;
- database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
- data->last_success_timestamp = Timer::GetUnixTimeStamp();
-
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- string time_msg = "";
- int32 time = data->success_lockout_time;
- int16 hour;
- int8 min;
- int8 sec;
- hour = time / 3600;
- time = time % 3600;
- min = time / 60;
- time = time % 60;
- sec = time;
- if (hour > 0) {
- char temp[10];
- sprintf(temp, " %i", hour);
- time_msg.append(temp);
- time_msg.append(" hour");
- time_msg.append((hour > 1) ? "s" : "");
- }
- if (min > 0) {
- char temp[5];
- sprintf(temp, " %i", min);
- time_msg.append(temp);
- time_msg.append(" minute");
- time_msg.append((min > 1) ? "s" : "");
- }
- // Only add seconds if minutes and hours are 0
- if (hour == 0 && min == 0 && sec > 0) {
- char temp[5];
- sprintf(temp, " %i", sec);
- time_msg.append(temp);
- time_msg.append(" second");
- time_msg.append((sec > 1) ? "s" : "");
- }
- client->Message(CHANNEL_COLOR_YELLOW, "The success zone reuse timer for %s has been set. You can return in%s.", data->zone_name.c_str(), time_msg.c_str());
- }
- else {
- lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- }
- }
- else
- lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- else
- lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- Instance_Type iType = zone->GetInstanceType();
- if (iType == SOLO_LOCKOUT_INSTANCE ||
- iType == GROUP_LOCKOUT_INSTANCE ||
- iType == RAID_LOCKOUT_INSTANCE ||
- iType == SOLO_PERSIST_INSTANCE ||
- iType == GROUP_PERSIST_INSTANCE ||
- iType == RAID_PERSIST_INSTANCE) {
- InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
- if (data) {
- // Check to see if the timer has already been set, if it has return out.
- if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
- return 0;
- database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
- data->last_failure_timestamp = Timer::GetUnixTimeStamp();
-
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- string time_msg = "";
- int32 time = data->failure_lockout_time;
- int16 hour;
- int8 min;
- int8 sec;
- hour = time / 3600;
- time = time % 3600;
- min = time / 60;
- time = time % 60;
- sec = time;
- if (hour > 0) {
- char temp[10];
- sprintf(temp, " %i", hour);
- time_msg.append(temp);
- time_msg.append(" hour");
- time_msg.append((hour > 1) ? "s" : "");
- }
- if (min > 0) {
- char temp[5];
- sprintf(temp, " %i", min);
- time_msg.append(temp);
- time_msg.append(" minute");
- time_msg.append((min > 1) ? "s" : "");
- }
- // Only add seconds if minutes and hours are 0
- if (hour == 0 && min == 0 && sec > 0) {
- char temp[5];
- sprintf(temp, " %i", sec);
- time_msg.append(temp);
- time_msg.append(" second");
- time_msg.append((sec > 1) ? "s" : "");
- }
- client->Message(CHANNEL_COLOR_YELLOW, "The failure zone reuse timer for %s has been set. You can return in%s", data->zone_name.c_str(), time_msg.c_str());
- }
- }
- else {
- lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- }
- else
- lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
- }
- else
- lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
- return 1;
- }
- int EQ2Emu_lua_CanHarvest(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* ground = lua_interface->GetSpawn(state, 2);
- if (!player) {
- lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!ground) {
- lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!ground->IsGroundSpawn()) {
- lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
- if (!groundspawn_entries) {
- lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- Skill* skill = 0;
- string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
- if (collection_skill == "Collecting")
- skill = ((Player*)player)->GetSkillByName("Gathering");
- else
- skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
- if (!skill) {
- lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- vector<GroundSpawnEntry*>::iterator itr;
- GroundSpawnEntry* entry = 0;
- bool can_harvest = false;
- sint32 min_skill = -1;
- int16 totalSkill = skill->current_val;
- int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
- if(skillID != 0xFFFFFFFF)
- {
- ((Entity*)player)->MStats.lock();
- totalSkill += ((Entity*)player)->stats[skillID];
- ((Entity*)player)->MStats.unlock();
- }
-
- // first, iterate through groundspawn_entries, discard tables player cannot use
- for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
- {
- entry = *itr;
- if (min_skill == -1 || entry->min_skill_level < min_skill)
- min_skill = entry->min_skill_level;
- // if player lacks skill, skip table
- if (entry->min_skill_level > totalSkill)
- continue;
- // if bonus, but player lacks level, skip table
- if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
- continue;
- can_harvest = true;
- break;
- }
- lua_interface->SetBooleanValue(state, can_harvest);
- // If false, send the message to the client
- if (!can_harvest) {
- Client* client = ((Player*)player)->GetClient();
- if (client) {
- string msg = "You do not have enough skill to ";
- if (collection_skill == "Gathering" || collection_skill == "Collecting")
- msg.append("gather");
- else if (collection_skill == "Mining")
- msg.append("mine");
- else if (collection_skill == "Trapping")
- msg.append("trap");
- else if (collection_skill == "Foresting")
- msg.append("forest");
- else if (collection_skill == "Fishing")
- msg.append("catch");
- msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
- client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
- // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
- }
- }
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
- // Check to see if we have a valid lua_interface
- if (!lua_interface)
- return 0;
- // Get the spawn that is getting the pet
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- // Get the DB ID of the pet
- int32 pet_id = lua_interface->GetInt32Value(state, 3);
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- // Get the spell that this command was called from
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Check to make sure the spawn pointer is valid
- if (!spawn) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to make sure the spawn is an entity
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the DB ID for the pet is set
- if (pet_id == 0) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
- return 0;
- }
- // Check to see if the pointer to the spell is valid
- if (!luaspell) {
- lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(luaspell->resisted) {
- return 0;
- }
- // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
- Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
- if (!pet) {
- lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
- return 0;
- }
- // Check to make sure the pet is an npc
- if (!pet->IsNPC()) {
- lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
- return 0;
- }
- if (x == 0)
- x = spawn->GetX();
- if (y == 0)
- y = spawn->GetY();
- if (z == 0)
- z = spawn->GetZ();
- // Spawn the pet at the same location as the owner
- pet->SetX(x);
- pet->SetY(y);
- pet->SetZ(z);
- pet->SetLocation(spawn->GetLocation());
- pet->SetHeading(spawn->GetHeading());
- spawn->GetZone()->AddSpawn(pet);
-
- const char* spawn_script = world.GetSpawnScript(pet_id);
- if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
- spawn->SetSpawnScript(string(spawn_script));
- spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- std::string petName = std::string("");
- if(spawn->IsEntity()) {
- petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
- }
-
- if(petName.size() < 1) {
- int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
- petName = spawn->GetZone()->pet_names.at(rand_index);
- LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
- }
-
- // Set the pets name
- pet->SetName(petName.c_str());
-
- // Set the level of the pet to the owners level
- pet->SetLevel(spawn->GetLevel());
- // Set the faction of the pet to the same faction as the owner
- pet->SetFactionID(spawn->GetFactionID());
- // Set the spawn as a pet
- pet->SetPet(true);
- // Give a pointer of the owner to the pet
- ((NPC*)pet)->SetOwner((Entity*)spawn);
- // Set the pet type
- ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
- // Set the spell id used to create this pet
- ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
- // Set the spell tier used to create this pet
- ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
- // Set the pets spawn type to 6
- pet->SetSpawnType(6);
- // Set the pets brain
- ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
- // Check to see if the pet has a subtitle
- if (strlen(pet->GetSubTitle()) > 0) {
- // Add the players name to the front of the sub title
- string pet_subtitle;
- pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
- LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
- // Set the pets subtitle to the new one
- pet->SetSubTitle(pet_subtitle.c_str());
- }
- // Set the pet as the return value for this function
- lua_interface->SetSpawnValue(state, pet);
- return 1;
- }
- int EQ2Emu_lua_SpawnMove(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- float max_distance = lua_interface->GetFloatValue(state, 3);
- string type = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!spawn || (spawn && spawn->IsPlayer())) {
- lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
- return 0;
- }
- //Set max_distance to default if not set or not proper value
- if (max_distance <= 0)
- max_distance = 500;
- PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
- if (packet) {
- float unknown2_3 = 0;
- int8 placement_mode = 0;
- if (type == "wall") {
- placement_mode = 2;
- unknown2_3 = 150;
- }
- else if (type == "ceiling")
- placement_mode = 1;
- packet->setDataByName("placement_mode", placement_mode);
- packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("model_type", spawn->GetModelType());
- packet->setDataByName("unknown", 1); //size
- packet->setDataByName("unknown2", 1); //size 2
- packet->setDataByName("unknown2", .5, 1); //size 3
- packet->setDataByName("unknown2", 3, 2);
- packet->setDataByName("unknown2", unknown2_3, 3);
- packet->setDataByName("max_distance", max_distance);
- packet->setDataByName("CoEunknown", 0xFFFFFFFF);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetItemType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->generic_info.item_type);
- return 1;
- }
- int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->effect_type);
- return 1;
- }
- int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn->GetZone())
- spawn->GetZone()->AddTransportSpawn(spawn);
- return 0;
- }
- int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
- return 1;
- }
- int EQ2Emu_lua_GetSkillValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->current_val);
- return 1;
- }
- int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->max_val);
- return 1;
- }
- int EQ2Emu_lua_GetSkillName(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetStringValue(state, skill->name.data.c_str());
- return 1;
- }
- int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- skill->max_val = value;
- if (skill->max_val < skill->current_val)
- skill->current_val = skill->max_val;
- return 0;
- }
- int EQ2Emu_lua_SetSkillValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Skill* skill = lua_interface->GetSkill(state);
- int16 value = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!skill) {
- lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value > skill->max_val)
- skill->current_val = skill->max_val;
- else
- skill->current_val = value;
- return 0;
- }
- int EQ2Emu_lua_HasSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0 && player && player->IsPlayer()) {
- lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- int16 current_val = lua_interface->GetInt16Value(state, 3);
- int16 max_val = lua_interface->GetInt16Value(state, 4);
- bool more_to_add = lua_interface->GetBooleanValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0 && current_val > 0 && max_val > 0) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- bool added = false;
- if (!player->skill_list.HasSkill(skill_id)) {
- player->AddSkill(skill_id, current_val, max_val, true);
- added = true;
- }
- if (!more_to_add) { //need to send update regardless, even if THIS skill wasn't added, otherwise if you have a list and the last item wasn't added but the previous ones were, it wouldn't send the update
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- if (added) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- else {
- lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_RemoveSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int32 skill_id = lua_interface->GetInt32Value(state, 2);
- bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (skill_id > 0) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- if (player->skill_list.HasSkill(skill_id)) {
- player->RemovePlayerSkill(skill_id, true);
- if (!more_to_remove) {
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- }
- }
- else {
- lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player_spawn = lua_interface->GetSpawn(state);
- int8 skill_type = lua_interface->GetInt8Value(state, 2);
- int16 amount = lua_interface->GetInt8Value(state, 3);
- bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (amount > 0 && skill_type < 100) {
- if (player_spawn && player_spawn->IsPlayer()) {
- Player* player = (Player*)player_spawn;
- player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
- if (!more_to_increase) {
- Client* client = player->GetClient();
- if (client) {
- EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
- if (packet)
- client->QueuePacket(packet);
- }
- }
- }
- else {
- lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
- }
- }
- else {
- lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_GetSkill(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
- if (skill) {
- lua_interface->SetSkillValue(state, skill);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddProc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- float chance = lua_interface->GetFloatValue(state, 3);
- Item* item = lua_interface->GetItem(state, 4);
- bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
- LuaSpell* spell = 0;
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
-
- if (!spawn && (!spell || !use_all_spelltargets)) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->AddProc(type, chance, item, spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- ((Entity*)spawn)->AddProc(type, chance, item, spell);
- return 0;
- }
- int EQ2Emu_lua_AddProcExt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- int8 damage_type = lua_interface->GetInt8Value(state, 3);
- float chance = lua_interface->GetFloatValue(state, 4);
- int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
- bool below_health = lua_interface->GetBooleanValue(state, 6);
- bool target_health = lua_interface->GetBooleanValue(state, 7);
- Item* item = lua_interface->GetItem(state, 8);
- bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
- bool extended_version = true;
- LuaSpell* spell = 0;
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
- if (!spawn && (!spell || !use_all_spelltargets)) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else
- ((Entity*)spawn)->AddProc(type, chance, item, spell);
- return 0;
- }
- int EQ2Emu_lua_RemoveProc(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Item* item = lua_interface->GetItem(state, 2);
- LuaSpell* spell = 0;
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!item)
- spell = lua_interface->GetCurrentSpell(state);
-
- lua_interface->ResetFunctionStack(state);
- if (!item && !spell) {
- lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->caster && spell->caster->GetZone()) {
- Spawn* target;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->RemoveProc(item, spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- spell->caster->RemoveProc(item, spell);
- }
- else
- ((Entity*)spawn)->RemoveProc(item, spell);
- return 0;
- }
- int EQ2Emu_lua_Knockback(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target_spawn = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- int32 duration = lua_interface->GetInt32Value(state, 3);
- float vertical = lua_interface->GetFloatValue(state, 4);
- float horizontal = lua_interface->GetFloatValue(state, 5);
- bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
- lua_interface->ResetFunctionStack(state);
- if (!target_spawn) {
- lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn) {
- lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if ((vertical != 0 || horizontal != 0)) {
- if(spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
- if (packet) {
- packet->setDataByName("target_x", target_spawn->GetX());
- packet->setDataByName("target_y", target_spawn->GetY());
- packet->setDataByName("target_z", target_spawn->GetZ());
- packet->setDataByName("vertical_movement", vertical);
- packet->setDataByName("horizontal_movement", horizontal);
- if (use_heading)
- packet->setDataByName("use_player_heading", 1);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- else {
- spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_IsEpic(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
- return 1;
- }
- int EQ2Emu_lua_ProcDamage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- int8 dmg_type = lua_interface->GetInt8Value(state, 4);
- int32 low_damage = lua_interface->GetInt32Value(state, 5);
- int32 high_damage = lua_interface->GetInt32Value(state, 6);
- string success_msg = lua_interface->GetStringValue(state, 7);
- string effect_msg = lua_interface->GetStringValue(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
- return 0;
- }
- int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
- return 0;
- }
- Skill* skill = master_skill_list.GetSkillByName(name.c_str());
- if (!skill) {
- lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
- return 0;
- }
- lua_interface->SetInt32Value(state, skill->skill_id);
- return 1;
- }
- int EQ2Emu_lua_IsHeroic(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
- return 1;
- }
- int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell) {
- lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
- return 1;
- }
- int EQ2Emu_lua_IsBehind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
- return 1;
- }
- int EQ2Emu_lua_IsFlanking(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
- return 1;
- }
- int EQ2Emu_lua_InFront(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
- return 1;
- }
- int EQ2Emu_lua_GetItemCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->details.count);
- return 1;
- }
- int EQ2Emu_lua_SetItemCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- Spawn* owner = lua_interface->GetSpawn(state, 2);
- int16 new_count = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!owner) {
- lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!owner->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (item->stack_count < new_count) {
- lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
- return 0;
- }
- if (new_count > 0) {
- item->details.count = new_count;
- item->save_needed = true;
- }
- else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
- ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
- else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
- ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
- else
- {
- lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)owner)->GetClient();
- if (!client)
- return 0;
- ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
- EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
- if (app)
- client->QueuePacket(app);
- return 0;
- }
- int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 time = lua_interface->GetInt32Value(state);
- string function = lua_interface->GetStringValue(state, 2);
- Spawn* caster = lua_interface->GetSpawn(state, 3);
- Spawn* target = lua_interface->GetSpawn(state, 4);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (time == 0) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (function.length() == 0) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell || (!spell->caster || !spell->caster->GetZone())) {
- lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- SpellScriptTimer* timer = new SpellScriptTimer;
- /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
- #ifdef WIN32
- ZeroMemory(timer, sizeof(SpellScriptTimer));
- #else
- bzero(timer, sizeof(SpellScriptTimer));
- #endif*/
- timer->caster = 0;
- timer->deleteWhenDone = false;
- timer->target = 0;
- timer->time = Timer::GetCurrentTime2() + time;
- timer->customFunction = function;
- timer->spell = spell;
- if (caster)
- timer->caster = caster->GetID();
- if (target)
- timer->target = target->GetID();
- spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
- return 0;
- }
- int EQ2Emu_lua_Resurrect(lua_State* state) {
- if (!lua_interface)
- return 0;
- float hp_perc = lua_interface->GetFloatValue(state);
- float power_perc = lua_interface->GetFloatValue(state, 2);
- bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
- Spawn* target = lua_interface->GetSpawn(state, 4);
- string heal_name = lua_interface->GetStringValue(state, 5);
- int8 crit_mod = lua_interface->GetInt32Value(state, 6);
- bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* caster = spell->caster;
- if (!caster) {
- lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = 0;
- PendingResurrection* rez = 0;
- ZoneServer* zone = spell->caster->GetZone();
- if (!target) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if (spell->targets.size() > 0) {
- vector<int32> spell_targets = spell->targets;
- for (int8 i = 0; i < spell_targets.size(); i++) {
- target = zone->GetSpawnByID(spell_targets.at(i));
- if (!target)
- continue;
- if (!target->IsPlayer())
- continue;
- client = ((Player*)target)->GetClient();
- if (!client)
- continue;
- rez = client->GetCurrentRez();
- if (rez->active)
- continue;
- client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
- rez->active = true;
- rez->caster = caster;
- rez->expire_timer = new Timer;
- int32 duration = spell->spell->GetSpellDuration();
- rez->expire_timer->Start(duration * 100);
- rez->hp_perc = hp_perc;
- rez->mp_perc = power_perc;
- rez->range = spell->spell->GetSpellData()->range;
- rez->spell_name = spell->spell->GetName();
- if (heal_name.length() > 0)
- rez->heal_name = heal_name;
- else
- rez->heal_name = rez->spell_name;
- rez->no_calcs = no_calcs;
- rez->crit_mod = crit_mod;
- rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
- if (send_window)
- client->SendResurrectionWindow();
- else {
- target->GetZone()->ResurrectSpawn(target, client);
- rez->should_delete = true;
- }
- client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- else {
- if(!target->IsPlayer())
- return 0;
-
- client = ((Player*)target)->GetClient();
- if (!client)
- return 0;
- rez = client->GetCurrentRez();
- if (rez->active)
- return 0;
- client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
- rez->active = true;
- rez->caster = caster;
- rez->expire_timer = new Timer;
- int32 duration = spell->spell->GetSpellDuration();
- rez->expire_timer->Start(duration * 100);
- rez->hp_perc = hp_perc;
- rez->mp_perc = power_perc;
- rez->range = spell->spell->GetSpellData()->range;
- rez->spell_name = spell->spell->GetName();
- if (heal_name.length() > 0)
- rez->heal_name = heal_name;
- else
- rez->heal_name = rez->spell_name;
- rez->no_calcs = no_calcs;
- rez->crit_mod = crit_mod;
- rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
- if (send_window)
- client->SendResurrectionWindow();
- else {
- target->GetZone()->ResurrectSpawn(target, client);
- rez->should_delete = true;
- }
- client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_SetVision(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 vision = lua_interface->GetInt32Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_vision(vision);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_BlurVision(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float intensity = lua_interface->GetFloatValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- int8 type = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (type == 1)
- lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
- else if (type == 2)
- lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
- return 1;
- }
- int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- float val = lua_interface->GetFloatValue(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- // Added from Gangrenous post
- if (spell && spell->resisted)
- return 0;
- // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
- if (val > 1.0f)
- val = 1.0f - (val / 100.0f);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i != spell->targets.size(); i++) {
- Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (spawn && spawn->IsEntity()) {
- ((Entity*)spawn)->SetSpeedMultiplier(val);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- if (target && target->IsEntity()) {
- ((Entity*)target)->SetSpeedMultiplier(val);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetIllusion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 model = lua_interface->GetInt16Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target)
- target->SetIllusionModel(model);
- }
- }
- else {
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetIllusionModel(model);
- }
- return 0;
- }
- int EQ2Emu_lua_ResetIllusion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target)
- target->SetIllusionModel(0);
- }
- }
- else {
- if (!spawn) {
- lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetIllusionModel(0);
- }
- return 0;
- }
- int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- float chance = lua_interface->GetFloatValue(state, 3);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (chance <= 0) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell->resisted) {
- return 0;
- }
- if (((Entity*)caster)->GetThreatTransfer()) {
- return 0;
- }
- ThreatTransfer* transfer = new ThreatTransfer;
- transfer->Target = target->GetID();
- transfer->Amount = chance;
- transfer->Spell = spell;
- ((Entity*)caster)->SetThreatTransfer(transfer);
- return 0;
- }
- int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
- ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
- if(transfer && transfer->Spell != spell) {
- lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->SetThreatTransfer(nullptr);
- }
- return 0;
- }
- int EQ2Emu_lua_CureByType(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 cure_count = lua_interface->GetInt8Value(state);
- int8 cure_type = lua_interface->GetInt8Value(state, 2);
- string cure_name = lua_interface->GetStringValue(state, 3);
- int8 cure_level = lua_interface->GetInt8Value(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
- lua_interface->ResetFunctionStack(state);
-
- if(spell && spell->resisted) {
- return 0;
- }
-
- if (target) {
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
- std::string alternate_name = "item";
- if(spell)
- alternate_name = std::string(spell->spell->GetName());
-
- if(!caster && spell)
- caster = (Spawn*)spell->caster;
-
- ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
- }
- }
- else {
- ZoneServer* zone = spell->caster->GetZone();
- vector<int32> targets = spell->targets;
- vector<Entity*> targets_to_cure;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < targets.size(); i++) {
- target = zone->GetSpawnByID(targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
- targets_to_cure.push_back((Entity*)target);
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
-
- vector<Entity*>::iterator itr;
- for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
- ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if(spell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- int8 cure_count = lua_interface->GetInt8Value(state);
- int8 cure_type = lua_interface->GetInt8Value(state, 2);
- string cure_name = lua_interface->GetStringValue(state, 3);
- int8 cure_level = lua_interface->GetInt8Value(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (target) {
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
- return 0;
- }
- if (((Entity*)target)->GetDetCount() > 0)
- ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- else {
- ZoneServer* zone = spell->caster->GetZone();
- vector<int32> targets = spell->targets;
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < targets.size(); i++) {
- target = zone->GetSpawnByID(targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- if (((Entity*)target)->GetDetCount() > 0)
- ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_CancelSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->caster) {
- lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
- return 0;
- }
- int EQ2Emu_lua_RemoveStealth(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->RemoveStealthSpell(spell);
- else {
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->RemoveStealthSpell(spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->RemoveInvisSpell(spell);
- else {
- ZoneServer* zone = spell->caster->GetZone();
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- spawn = zone->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->RemoveInvisSpell(spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- int8 class_id = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsPlayer()) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* target = caster->GetTarget();
- if (!target) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)caster)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
- return 0;
- }
- HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
- if (ho) {
- ho->SetTarget(target->GetID());
- LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
- LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
- if (((Entity*)caster)->GetGroupMemberInfo()) {
- if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- for (itr = members->begin(); itr != members->end(); itr++) {
- if ((*itr)->client)
- ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else
- safe_delete(ho);
- }
- else {
- if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
- ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
- }
- else
- safe_delete(ho);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- return 0;
- }
- int16 triggerCount = lua_interface->GetInt16Value(state);
- bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
- if (!triggerCount) {
- lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
- return 0;
- }
- spell->num_triggers = triggerCount;
- spell->had_triggers = true;
- spell->cancel_after_all_triggers = cancel_after_triggers;
- return 0;
- }
- int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, spell->num_triggers);
- return 1;
- }
- int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if (!spell->caster || !spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int16 remove_count = lua_interface->GetInt16Value(state);
- lua_interface->ResetFunctionStack(state);
-
- if (!remove_count)
- remove_count = 1;
- if (remove_count >= spell->num_triggers) {
- spell->num_triggers = 0;
- if (spell->cancel_after_all_triggers)
- spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
- }
- else {
- spell->num_triggers -= remove_count;
- Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
- ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
- }
- return 0;
- }
- int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!copy_spawn) {
- lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->CopySpawnAppearance(copy_spawn);
- return 0;
- }
- int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- else if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
- return 0;
- }
-
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
- return 1;
- }
- int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
-
- if(spell->resisted) {
- return 0;
- }
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* entity = ((Entity*)spawn);
- entity->AddImmunity(spell, type);
- }
- else if(spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- Entity* entity = ((Entity*)spawn);
- entity->AddImmunity(spell, type);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- int8 type = lua_interface->GetInt8Value(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* entity = ((Entity*)spawn);
- entity->RemoveImmunity(spell, type);
- }
- else if(spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- Entity* entity = ((Entity*)spawn);
- entity->RemoveImmunity(spell, type);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- if(spell->resisted) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- float snare = lua_interface->GetFloatValue(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- // convert the val to the speed multipler value (100 - val)
- float val = 100.0 - snare;
- val /= 100.0;
- if (spawn) {
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Entity*)spawn)->SetSnareValue(spell, val);
- }
- else if(spell->caster && spell->caster->GetZone()) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!spawn || !spawn->IsEntity())
- continue;
- ((Entity*)spawn)->SetSnareValue(spell, val);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_CheckRaceType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int16 race_id = lua_interface->GetInt16Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (race_id == 0) {
- lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
- return 1;
- }
- int EQ2Emu_lua_GetRaceType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
- return 1;
- }
- int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
- return 1;
- }
- int EQ2Emu_lua_GetSpellName(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetStringValue(state, spell->spell->GetName());
- return 1;
- }
- int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, quest->GetQuestFlags());
- return 1;
- }
- int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 flags = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetQuestFlags(flags);
- return 0;
- }
- int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- int32 duration = lua_interface->GetInt32Value(state, 4);
- string action = lua_interface->GetStringValue(state, 5);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (duration == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (action.length() == 0) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetTimerStep(step);
- quest->AddFailedAction(step, action);
- quest->SetStepTimer(duration);
- client->AddQuestTimer(quest->GetQuestID());
- return 0;
- }
- int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->SetTimerStep(0);
- quest->SetStepTimer(0);
- client->RemoveQuestTimer(quest->GetQuestID());
- return 0;
- }
- int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Quest* quest = lua_interface->GetQuest(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!quest) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest->RemoveQuestStep(step, client)) {
- client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
- client->GetCurrentZone()->SendQuestUpdates(client);
- }
- else
- lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
- return 0;
- }
- int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state, 1);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string desc = lua_interface->GetStringValue(state, 3);
- string task_group = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- QuestStep* quest_step = quest->GetQuestStep(step);
- if (!quest_step) {
- lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest_step->SetStepProgress(0);
- quest_step->SetTaskGroup(task_group);
- quest_step->SetDescription(desc);
- return 0;
- }
- int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
- if (!lua_interface)
- return 0;
- Quest* quest = lua_interface->GetQuest(state);
- int32 step = lua_interface->GetInt32Value(state, 2);
- string action = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!quest) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (action.length() == 0) {
- lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- quest->AddFailedAction(step, action);
- return 0;
- }
- int EQ2Emu_lua_SetStepFailed(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id == 0) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- if (step == 0) {
- lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
- return 0;
- }
- Quest* quest = ((Player*)player)->GetQuest(quest_id);
- if (!quest) {
- lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
- return 0;
- }
- quest->StepFailed(step);
- return 0;
- }
- int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (quest_id == 0) {
- lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
- return 1;
- }
- int EQ2Emu_lua_SetServerVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- string value = lua_interface->GetStringValue(state, 2);
- string comment = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (value.length() == 0) {
- lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- string varname = string("lua_").append(name);
- Variable* var = variables.FindVariable(varname);
- if (var)
- var->SetValue(value.c_str());
- else {
- var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
- variables.AddVariable(var);
- }
- database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
- return 0;
- }
- int EQ2Emu_lua_GetServerVariable(lua_State* state) {
- if (!lua_interface)
- return 0;
- string name = lua_interface->GetStringValue(state);
- lua_interface->ResetFunctionStack(state);
- if (name.length() == 0) {
- lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- string varname = string("lua_").append(name);
- Variable* var = variables.FindVariable(varname);
- if (var)
- lua_interface->SetStringValue(state, var->GetValue());
- else
- lua_interface->SetStringValue(state, "NULL");
- return 1;
- }
- int EQ2Emu_lua_HasLanguage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 language_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
- return 1;
- }
- int EQ2Emu_lua_AddLanguage(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 language_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
- return 0;
- }
- Language* language = master_languages_list.GetLanguage(language_id);
- if (language)
- {
- ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
- ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
- }
- return 0;
- }
- int EQ2Emu_lua_IsNight(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, zone->IsDusk());
- return 1;
- }
- int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsWidget()) {
- lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Widget*)spawn)->SetMultiFloorLift(true);
- if (spawn->GetZone())
- spawn->GetZone()->AddTransportSpawn(spawn);
- return 0;
- }
- int EQ2Emu_lua_StartAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 path = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (path == 0) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SendFlightAutoMount(path);
- return 0;
- }
- int EQ2Emu_lua_EndAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- if (!player) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- client->EndAutoMount();
- return 0;
- }
- int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
- return 1;
- }
- int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- int32 value = lua_interface->GetInt32Value(state, 3);
- int32 value2 = lua_interface->GetInt32Value(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
- return 0;
- }
- int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
- if (!hd)
- return 0;
- lua_interface->SetInt32Value(state, hd->Value);
- lua_interface->SetInt32Value(state, hd->Value2);
- return 2;
- }
- int EQ2Emu_lua_SetGridID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 grid = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (grid == 0) {
- lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- spawn->SetLocation(grid);
- return 0;
- }
- int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 event_id = lua_interface->GetInt32Value(state, 2);
- int32 value1 = lua_interface->GetInt32Value(state, 3);
- int32 value2 = lua_interface->GetInt32Value(state, 4);
- bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
- int16 flag_override = lua_interface->GetInt16Value(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- //Add this quest to the list of required quests for this spawn
- spawn->SetRequiredHistory(event_id, value1, value2);
- //If private spawn value set
- if (private_spawn) {
- //Set the spawn to be private when not granted access via history
- spawn->AddAllowAccessSpawn(spawn);
- spawn->SetPrivateQuestSpawn(true);
- }
- //This value will override vis_flags in the vis packet
- if (flag_override > 0)
- spawn->SetQuestsRequiredOverride(flag_override);
- return 0;
- }
- int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 quest_id = lua_interface->GetInt32Value(state, 2);
- int32 step_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
- return 1;
- }
- int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (level == 0) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
- return 0;
- }
- int EQ2Emu_lua_AddCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (amount == 0) {
- lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->AddCoins(amount);
- return 0;
- }
- int EQ2Emu_lua_RemoveCoin(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- if (amount == 0) {
- lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
- return 1;
- }
- int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (!zone) {
- lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Entity*> players = zone->GetPlayers();
- if (players.size() == 0)
- return 0;
- lua_createtable(state, players.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < players.size(); i++) {
- lua_interface->SetSpawnValue(state, players.at(i));
- lua_rawseti(state, newTable, i + 1);
- }
- return 1;
- }
- int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state, 1);
- if (!zone) {
- lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 group_id = lua_interface->GetInt32Value(state, 2);
- int16 custom_level = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
-
- //Map of <placement_id, location_id>
- map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
- map<int32, int32>::iterator itr;
- vector<Spawn*> group;
- Spawn* leader = 0;
- if(locs == nullptr)
- return 0;
-
- for (itr = locs->begin(); itr != locs->end(); itr++) {
- SpawnLocation* location = zone->GetSpawnLocation(itr->second);
- if (!location) {
- lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
- return 0;
- }
-
- int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
-
- Spawn* spawn = 0;
- if (location->entities[rand_number]) {
- if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
- else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
- if(spawn && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[rand_number]->spawn_id);
- safe_delete(spawn);
- continue;
- }
- if (spawn) {
- if(!leader)
- leader = spawn;
- if(leader)
- leader->AddSpawnToGroup(spawn);
-
- spawn->SetSpawnGroupID(group_id);
-
- if(custom_level > 0 && custom_level != 0xFFFF) {
- spawn->SetLevel(custom_level);
- }
-
- const char* script = 0;
- for (int x = 0; x < 3; x++) {
- switch (x) {
- case 0:
- script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
- break;
- }
- if (script && lua_interface->GetSpawnScript(script) != 0) {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- lua_interface->SetSpawnValue(state, spawn);
- group.push_back(spawn);
- }
- else {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
- safe_delete(spawn);
- }
- }
- }
- if (!group.empty()) {
- lua_createtable(state, group.size(), 0);
- int newTable = lua_gettop(state);
- for (int32 i = 0; i < group.size(); i++) {
- lua_interface->SetSpawnValue(state, group[i]);
- lua_rawseti(state, newTable, i + 1);
- }
- }
- else
- lua_pushnil(state);
- return 1;
- }
- int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- int32 anim_id = lua_interface->GetInt32Value(state, 2);
- int16 leeway = lua_interface->GetInt16Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (anim_id == 0) {
- lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (leeway == 0)
- leeway = 5000;
- spawn->SetSpawnAnim(anim_id);
- spawn->SetSpawnAnimLeeway(leeway);
- return 0;
- }
- int EQ2Emu_lua_GetClientVersion(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer()) {
- return 0;
- }
- Client* client = ((Player*)player)->GetClient();
- if (!client) {
- return 0;
- }
- lua_interface->SetInt32Value(state, client->GetVersion());
- return 1;
- }
- int EQ2Emu_lua_GetItemID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Item* item = lua_interface->GetItem(state);
- lua_interface->ResetFunctionStack(state);
- if (!item) {
- lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, item->details.item_id);
- return 1;
- }
- int EQ2Emu_lua_IsEntity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetBooleanValue(state, spawn->IsEntity());
- return 1;
- }
- int EQ2Emu_lua_GetOrigX(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
- return 1;
- }
- int EQ2Emu_lua_GetOrigY(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
- return 1;
- }
- int EQ2Emu_lua_GetOrigZ(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
- return 1;
- }
- int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float pct = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pct == 0) {
- lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
- lua_interface->SetInt32Value(state, amount);
- return 1;
- }
- int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float pct = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (pct == 0) {
- lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
- lua_interface->SetInt32Value(state, amount);
- return 1;
- }
- int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
- return 1;
- }
- int EQ2Emu_lua_Evac(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* target = lua_interface->GetSpawn(state);
- if (target) {
- float x = target->GetZone()->GetSafeX();
- float y = target->GetZone()->GetSafeY();
- float z = target->GetZone()->GetSafeZ();
- float h = target->GetZone()->GetSafeHeading();
- target->SetX(x);
- target->SetY(y);
- target->SetZ(z);
- target->SetHeading(h);
- target->SetSpawnOrigX(x);
- target->SetSpawnOrigY(y);
- target->SetSpawnOrigZ(z);
- target->SetSpawnOrigHeading(h);
- if (target->IsPlayer()) {
- Client* client = ((Player*)target)->GetClient();
- if (client) {
- client->GetCurrentZone()->ClearHate(client->GetPlayer());
-
- int numargs = lua_interface->GetNumberOfArgs(state);
- if(numargs == 4) {
- x = lua_interface->GetFloatValue(state,1);
- y = lua_interface->GetFloatValue(state,2);
- z = lua_interface->GetFloatValue(state,3);
- h = lua_interface->GetFloatValue(state,4);
- }
- client->SetReloadingZone(true);
- target->SetX(x);
- target->SetY(y);
- target->SetZ(z);
- target->SetHeading(h);
- target->SetSpawnOrigX(x);
- target->SetSpawnOrigY(y);
- target->SetSpawnOrigZ(z);
- target->SetSpawnOrigHeading(h);
- target->SetAppearancePosition(x,y,z);
-
- client->SetZoningCoords(x,y,z,h);
- PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
- if (packet)
- {
- packet->setDataByName("x", x);
- packet->setDataByName("y", y);
- packet->setDataByName("z", z);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
-
- client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
- }
- }
- lua_interface->ResetFunctionStack(state);
- }
- else {
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
-
- if(!spell || !spell->caster || !spell->caster->GetZone()) {
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- ZoneServer* zone = spell->caster->GetZone();
-
- float x = spell->caster->GetZone()->GetSafeX();
- float y = spell->caster->GetZone()->GetSafeY();
- float z = spell->caster->GetZone()->GetSafeZ();
- float h = spell->caster->GetZone()->GetSafeHeading();
- int numargs = lua_interface->GetNumberOfArgs(state);
-
- if(numargs == 4) {
- x = lua_interface->GetFloatValue(state,1);
- y = lua_interface->GetFloatValue(state,2);
- z = lua_interface->GetFloatValue(state,3);
- h = lua_interface->GetFloatValue(state,4);
- }
-
- lua_interface->ResetFunctionStack(state);
-
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < spell->targets.size(); i++) {
- Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
- if (!target2)
- continue;
- if (target2->IsPlayer()) {
- Client* client = ((Player*)target2)->GetClient();
- if (client) {
- client->GetCurrentZone()->ClearHate(client->GetPlayer());
-
- client->SetReloadingZone(true);
- target2->SetX(x);
- target2->SetY(y);
- target2->SetZ(z);
- target2->SetHeading(h);
- target2->SetSpawnOrigX(x);
- target2->SetSpawnOrigY(y);
- target2->SetSpawnOrigZ(z);
- target2->SetSpawnOrigHeading(h);
- target2->SetAppearancePosition(x,y,z);
-
- client->SetZoningCoords(x,y,z,h);
-
- PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
- if (packet)
- {
- packet->setDataByName("x", x);
- packet->setDataByName("y", y);
- packet->setDataByName("z", z);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
-
- client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
- }
- }
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpellTier(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- int8 tier = luaspell->spell->GetSpellTier();
- lua_interface->SetInt32Value(state, tier);
- return 1;
- }
- int EQ2Emu_lua_GetSpellID(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
- lua_interface->ResetFunctionStack(state);
- if (!luaspell || !luaspell->spell) {
- lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
- return 0;
- }
- int32 spell_id = luaspell->spell->GetSpellID();
- lua_interface->SetInt32Value(state, spell_id);
- return 1;
- }
- int EQ2Emu_lua_StartTransmute(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- return 0;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- return 0;
- }
- Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
- return 0;
- }
- int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state, 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsPlayer()) {
- lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ZoneServer* zone = spawn->GetZone();
- if (!zone) {
- return 0;
- }
- Client* client = ((Player*)spawn)->GetClient();
- if (!client) {
- return 0;
- }
- Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
- return 0;
- }
- int EQ2Emu_lua_ProcHate(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* caster = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- int32 threat_amt = lua_interface->GetInt32Value(state, 3);
- string spell_name = lua_interface->GetStringValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (!caster) {
- lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!caster->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target) {
- lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
- caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GiveExp(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 amount = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (player && player->IsPlayer() && amount > 0) {
- ((Player*)player)->AddXP(amount);
- }
- return 0;
- }
- int EQ2Emu_lua_DisplayText(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 type = lua_interface->GetInt8Value(state, 2);
- string text = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client || text.length() == 0) {
- lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SimpleMessage(type, text.c_str());
- return 0;
- }
- int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client || !spawn) {
- lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
- return 0;
- }
- vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
- if (!items) {
- lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
- return 0;
- }
- client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
- return 0;
- }
- int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawnref = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn_id > 0 && spawnref) {
- vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() == 0) {
- lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = 0;
- int16 index = MakeRandomInt(0, spawns.size());
- if (index >= spawns.size() || index < 0)
- index = 0;
- spawn = spawns[index];
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
- Spawn* player = lua_interface->GetSpawn(state);
- int32 spawn_id = lua_interface->GetInt32Value(state, 2);
- string name = lua_interface->GetStringValue(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string command = lua_interface->GetStringValue(state, 5);
- string error_text = lua_interface->GetStringValue(state, 6);
- int16 cast_time = lua_interface->GetInt16Value(state, 7);
- int32 spell_visual = lua_interface->GetInt32Value(state, 8);
- lua_interface->ResetFunctionStack(state);
- if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
- if (distance == 0)
- distance = 10.0f;
- if (command.length() == 0)
- command = name;
- vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
- if (spawns.size() == 0) {
- lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = 0;
- for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
- spawn = *itr;
- if (spawn) {
- spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
- player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 goal_num = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && player->GetZone())
- client = ((Player*)player)->GetClient();
- else{
- lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
- return 0;
- }
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("goal_num", goal_num);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && player->GetZone())
- client = ((Player*)player)->GetClient();
- else {
- lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
- return 0;
- }
- if (client && client->GetVersion() >= 374) {
- client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
- }
- return 0;
- }
- int EQ2Emu_lua_InstructionWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- float duration = lua_interface->GetFloatValue(state, 2);
- string text = lua_interface->GetStringValue(state, 3);
- string voice = lua_interface->GetStringValue(state, 4);
- int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
- int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
- string signal = lua_interface->GetStringValue(state, 7);
- string goal1 = lua_interface->GetStringValue(state, 8);
- string task1 = lua_interface->GetStringValue(state, 9);
- string goal2 = lua_interface->GetStringValue(state, 10);
- string task2 = lua_interface->GetStringValue(state, 11);
- string goal3 = lua_interface->GetStringValue(state, 12);
- string task3 = lua_interface->GetStringValue(state, 13);
- string goal4 = lua_interface->GetStringValue(state, 14);
- string task4 = lua_interface->GetStringValue(state, 15);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA InstructionWindow command error: could not find client");
- return 0;
- }
- if (text.length() == 0) {
- lua_interface->LogError("LUA InstructionWindow required parameters not given");
- return 0;
- }
- if (duration >= 0 && duration < 2)
- duration = 2;
- PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("open_seconds_max", duration);
- packet->setDataByName("text", text.c_str());
- packet->setDataByName("voice", voice.c_str());
- int8 num_goals = 1;
- if (task2.length() > 0)
- num_goals++;
- if (task3.length() > 0)
- num_goals++;
- if (task4.length() > 0)
- num_goals++;
- packet->setArrayLengthByName("num_goals", num_goals);
- for (int8 i = 0; i < num_goals; i++) {
- packet->setSubArrayLengthByName("num_tasks", 1, i);
- }
- if (goal1.length() > 0)
- packet->setArrayDataByName("goal_text", goal1.c_str());
- if (goal2.length() > 0)
- packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
- if (goal3.length() > 0)
- packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
- if (goal4.length() > 0)
- packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
- packet->setSubArrayDataByName("task_text", task1.c_str());
- if (task2.length() > 0)
- packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
- if (task3.length() > 0)
- packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
- if (task4.length() > 0)
- packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
- packet->setDataByName("complete_sound", "click");
- packet->setDataByName("signal", signal.c_str());
- packet->setDataByName("voice_key1", voice_key1);
- packet->setDataByName("voice_key2", voice_key2);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_ShowWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string window = lua_interface->GetStringValue(state, 2);
- int8 show = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA ShowWindow command error: could not find client");
- return 0;
- }
- if (window.length() == 0) {
- lua_interface->LogError("LUA ShowWindow required parameters not given");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("window", window.c_str());
- packet->setDataByName("show", show);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
- //See GameEvents.txt for options that can be used for this function
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string event_name = lua_interface->GetStringValue(state, 2);
- int8 enabled = lua_interface->GetInt8Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer()) {
- lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
- return 0;
- }
-
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA EnableGameEvent error: could not find client");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
- if (packet) {
- packet->setDataByName("event_name", event_name.c_str());
- packet->setDataByName("enabled", enabled);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int8 step = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && step > 0) {
- ((Player*)player)->SetTutorialStep(step);
- }
- return 0;
- }
- int EQ2Emu_lua_FlashWindow(lua_State* state) {
- if (!lua_interface)
- return 0;
- Client* client = 0;
- Spawn* player = lua_interface->GetSpawn(state);
- string window = lua_interface->GetStringValue(state, 2);
- float flash_seconds = lua_interface->GetFloatValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
- return 0;
- }
- else
- client = ((Player*)player)->GetClient();
- if (!client) {
- lua_interface->LogError("LUA FlashWindow command error: could not find client");
- return 0;
- }
- if (window.length() == 0) {
- lua_interface->LogError("LUA FlashWindow required parameters not given");
- return 0;
- }
- PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
- if (packet) {
- packet->setDataByName("window", window.c_str());
- packet->setDataByName("flash_seconds", flash_seconds);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- return 0;
- }
- int EQ2Emu_lua_CheckLOS(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && target)
- return spawn->CheckLoS(target);
- return 0;
- }
- int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float x = lua_interface->GetFloatValue(state, 2);
- float y = lua_interface->GetFloatValue(state, 3);
- float z = lua_interface->GetFloatValue(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn)
- return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
- return 0;
- }
- int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetExpansionFlag(xpackFlag);
- return 0;
- }
- int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone)
- zone->SetHolidayFlag(holidayFlag);
- return 0;
- }
- int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanBind(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool canbind = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanBind(canbind);
- return 0;
- }
- int EQ2Emu_lua_GetCanBind(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanBind());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanGate(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool cangate = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanGate(cangate);
- return 0;
- }
- int EQ2Emu_lua_GetCanGate(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanGate());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetCanEvac(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool canevac = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone)
- zone->SetCanEvac(canevac);
- return 0;
- }
- int EQ2Emu_lua_GetCanEvac(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn) {
- lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ZoneServer* zone = spawn->GetZone();
- if (zone) {
- lua_interface->SetInt32Value(state, zone->GetCanEvac());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spawn_value = lua_interface->GetInt32Value(state, 2);
- int8 spawn_type = lua_interface->GetInt8Value(state, 3);
- float distance = lua_interface->GetFloatValue(state, 4);
- string in_range_function = lua_interface->GetStringValue(state, 5);
- string leaving_range_function = lua_interface->GetStringValue(state, 6);
- lua_interface->ResetFunctionStack(state);
- if (spawn && distance > 0 && in_range_function.length() > 0)
- spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
- return 0;
- }
- int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* target = lua_interface->GetSpawn(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && target)
- {
- if (spawn->IsPlayer() && target->IsEntity())
- {
- lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
- return 1;
- }
- else if (spawn->IsEntity() && target->IsEntity())
- {
- lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity())
- {
- ((Entity*)spawn)->SetSeeInvisSpell(val);
- if (spawn->IsPlayer())
- {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetSeeHide(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool val = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && spawn->IsEntity())
- {
- ((Entity*)spawn)->SetSeeHideSpell(val);
- if (spawn->IsPlayer())
- {
- Client* client = ((Player*)spawn)->GetClient();
- if (client)
- ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- bool val = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && player && player->IsPlayer())
- {
- EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
- bool res = false;
- if (cmd)
- res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 charID = lua_interface->GetInt32Value(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- bool val = (lua_interface->GetInt8Value(state, 4) == 1);
- lua_interface->ResetFunctionStack(state);
- if (spawn && charID)
- {
- EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
- bool res = false;
- if (cmd)
- res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
- {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string command = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn && command.length() > 0)
- spawn->RemovePrimaryEntityCommand(command.c_str());
- return 0;
- }
- int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- float distance = lua_interface->GetFloatValue(state, 2);
- string command = lua_interface->GetStringValue(state, 3);
- Spawn* player = lua_interface->GetSpawn(state, 4);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
- }
- return 0;
- }
- int EQ2Emu_lua_SendTransporters(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- Spawn* player = lua_interface->GetSpawn(state, 2);
- int32 transport_id = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn && player && transport_id && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- vector<TransportDestination*> destinations;
- player->GetZone()->GetTransporters(&destinations, client, transport_id);
- if (destinations.size())
- {
- client->SetTemporaryTransportID(transport_id);
- client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
- }
- else
- client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
- }
- return 0;
- }
- int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 transport_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- client->SetTemporaryTransportID(transport_id);
- }
- return 0;
- }
- int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer()) {
- Client* client = 0;
- if (player && player->IsPlayer())
- client = ((Player*)player)->GetClient();
- if (!client)
- return 0;
- lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetAlignment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint32 alignment = lua_interface->GetSInt32Value(state, 2);
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- if (!spawn) {
- lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
- {
- lua_interface->LogError("%s: LUA SetAlignment command error: alignment value beyond supported min: %i and max: %i", lua_interface->GetScriptName(state), SCHAR_MIN, SCHAR_MAX);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
- if (spell && spell->targets.size() > 0) {
- ZoneServer* zone = spell->caster->GetZone();
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
- if (target && target->IsEntity()) {
- ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
- if (target->IsPlayer())
- ((Player*)target)->SetCharSheetChanged(true);
- }
- }
- }
- else {
- ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
- if (spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_GetAlignment(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spawn->IsEntity()) {
- lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
-
- lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
- return 1;
- }
- int EQ2Emu_lua_GetSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 spell_id = lua_interface->GetInt32Value(state);
- int8 spell_tier = lua_interface->GetInt8Value(state, 2);
- string custom_lua_script = lua_interface->GetStringValue(state, 3);
- if (spell_id > 0) {
- if (spell_tier == 0)
- spell_tier = 1;
- Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
-
- if(!spell) {
- lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
-
- LuaSpell* lua_spell = 0;
- if(custom_lua_script.size() > 0)
- {
- // attempt to load the custom script since it isn't already loaded
- // we will re-obtain the lua_spell further below
- if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
- {
- LogWrite(LUA__WARNING, 0, "LUA", "GetSpell(%u, %u, '%s'), custom lua script not loaded, attempting to load.", spell_id, spell_tier, custom_lua_script.c_str());
- }
- }
- else
- custom_lua_script = spell->GetSpellData()->lua_script;
-
- if (!lua_spell && lua_interface)
- lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
- lua_interface->ResetFunctionStack(state);
-
- if (!lua_spell)
- {
- LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
- return 0;
- }
- lua_spell->spell = new Spell(spell);
- lua_interface->AddCustomSpell(lua_spell);
- lua_interface->SetSpellValue(state, lua_spell);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpellData(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- string field = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
- return 0;
- }
- boost::to_lower(field);
- return spell->spell->GetSpellData(state, field);
- }
- int EQ2Emu_lua_SetSpellData(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- string field = lua_interface->GetStringValue(state, 2);
- int8 fieldArg = 3; // field value after the initial set
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- boost::to_lower(field);
- bool valSet = false;
- spell->spell->SetSpellData(state, field, fieldArg);
- lua_interface->ResetFunctionStack(state);
- return valSet;
- }
- int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (spell->spell->lua_data.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- bool setVal = true;
- LUAData* data = spell->spell->lua_data[idx];
- switch (data->type)
- {
- case 0:
- {
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- sint32 value2 = lua_interface->GetSInt32Value(state, 4);
- data->int_value = value;
- data->int_value2 = value2;
- break;
- }
- case 1:
- {
- float value = lua_interface->GetFloatValue(state, 3);
- float value2 = lua_interface->GetFloatValue(state, 4);
- data->float_value = value;
- data->float_value2 = value2;
- break;
- }
- case 2:
- {
- bool value = lua_interface->GetBooleanValue(state, 3);
- data->bool_value = value;
- break;
- }
- case 3:
- {
- string value = lua_interface->GetStringValue(state, 3);
- string value2 = lua_interface->GetStringValue(state, 4);
- data->string_value = value;
- data->string_value2 = value2;
- break;
- }
- default:
- setVal = false;
- }
-
- lua_interface->ResetFunctionStack(state);
- return setVal;
- }
- int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- bool secondfield = lua_interface->GetBooleanValue(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell->spell->lua_data.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- return 0;
- }
- bool setVal = true;
- LUAData* data = spell->spell->lua_data[idx];
- switch (data->type)
- {
- case 0:
- {
- if(!secondfield)
- lua_interface->SetSInt32Value(state, data->int_value);
- else
- lua_interface->SetSInt32Value(state, data->int_value2);
- break;
- }
- case 1:
- {
- if (!secondfield)
- lua_interface->SetFloatValue(state, data->float_value);
- else
- lua_interface->SetFloatValue(state, data->float_value2);
- break;
- }
- case 2:
- {
- lua_interface->SetBooleanValue(state, data->bool_value);
- break;
- }
- case 3:
- {
- if (!secondfield)
- lua_interface->SetStringValue(state, data->string_value.c_str());
- else
- lua_interface->SetStringValue(state, data->string_value2.c_str());
- break;
- }
- default:
- setVal = false;
- }
- return setVal;
- }
- int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- string field = lua_interface->GetStringValue(state, 3);
- boost::to_lower(field);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- if (spell->spell->effects.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- // do we need to lock? eh probably not this should only be used before use of the custom spell
- SpellDisplayEffect* effect = spell->spell->effects[idx];
- if (field == "description")
- effect->description = string(lua_interface->GetStringValue(state, 4));
- else if (field == "bullet")
- effect->subbullet = lua_interface->GetInt8Value(state, 4);
- else if (field == "percentage")
- effect->percentage = lua_interface->GetInt8Value(state, 4);
- else { // no match
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
-
- return 1;
- }
- int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- int8 idx = lua_interface->GetInt32Value(state, 2);
- string field = lua_interface->GetStringValue(state, 3);
- lua_interface->ResetFunctionStack(state);
-
- boost::to_lower(field);
- if (!spell) {
- lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!spell->spell || !spell->spell->GetSpellData()) {
- lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
- return 0;
- }
- if (spell->spell->effects.size() <= idx)
- {
- lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
- return 0;
- }
- // do we need to lock? eh probably not this should only be used before use of the custom spell
- SpellDisplayEffect* effect = spell->spell->effects[idx];
- if (field == "description")
- lua_interface->SetStringValue(state, effect->description.c_str());
- else if (field == "bullet")
- lua_interface->SetInt32Value(state, effect->subbullet);
- else if (field == "percentage")
- lua_interface->SetInt32Value(state, effect->percentage);
- else // no match
- return 0;
- return 1;
- }
- int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetSpell(state);
- Spawn* caster = lua_interface->GetSpawn(state, 2);
- Spawn* target = lua_interface->GetSpawn(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!target) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!target->IsEntity()) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
- return 0;
- }
- if (!spell) {
- lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (caster && !caster->IsEntity()) {
- lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
- return 0;
- }
- target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
- return 0;
- }
- int EQ2Emu_lua_InWater(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->InWater());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_InLava(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->InLava());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_DamageSpawn(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* attacker = lua_interface->GetSpawn(state);
- Spawn* victim = lua_interface->GetSpawn(state, 2);
- int8 type = lua_interface->GetInt8Value(state, 3);
- int8 dmg_type = lua_interface->GetInt8Value(state, 4);
- int32 low_damage = lua_interface->GetInt32Value(state, 5);
- int32 high_damage = lua_interface->GetInt32Value(state, 6);
- string spell_name = lua_interface->GetStringValue(state, 7);
- int8 crit_mod = lua_interface->GetInt8Value(state, 8);
- bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
- bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
- bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
- bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
- lua_interface->ResetFunctionStack(state);
- if (!attacker) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!attacker->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!victim) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!victim->IsEntity()) {
- lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
- lua_interface->SetBooleanValue(state, has_damaged);
- return 1;
- }
- int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool invul = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- spawn->SetInvulnerable(invul);
- }
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetBooleanValue(state, ret->GetBool());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetInt32Value(state, ret->GetInt32());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- string category = lua_interface->GetStringValue(state);
- string name = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- Rule *ret = 0;
- if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
-
- lua_interface->SetFloatValue(state, ret->GetFloat());
- return 1;
- }
-
- lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
- return 0;
- }
- int EQ2Emu_lua_GetAAInfo(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string type = lua_interface->GetStringValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- int res = 1;
- boost::to_lower(type);
- if(type == "assigned_aa")
- lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
- else if ( type == "unassigned_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
- else if ( type == "assigned_tradeskill_aa")
- lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
- else if ( type == "unassigned_tradeskill_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
- else if ( type == "assigned_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
- else if ( type == "unassigned_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
- else if ( type == "assigned_tradeskill_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
- else if ( type == "unassigned_tradeskill_prestige_aa")
- lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
- else
- res = 0;
- return res;
- }
-
- lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
- return 0;
- }
- int EQ2Emu_lua_SetAAInfo(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string type = lua_interface->GetStringValue(state, 2);
- sint32 value = lua_interface->GetSInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- boost::to_lower(type);
- if(type == "assigned_aa")
- spawn->SetAssignedAA((sint16)value);
- else if ( type == "unassigned_aa")
- spawn->SetUnassignedAA((sint16)value);
- else if ( type == "assigned_tradeskill_aa")
- spawn->SetTradeskillAA((sint16)value);
- else if ( type == "unassigned_tradeskill_aa")
- spawn->SetUnassignedTradeskillAA((sint16)value);
- else if ( type == "assigned_prestige_aa")
- spawn->SetPrestigeAA((sint16)value);
- else if ( type == "unassigned_prestige_aa")
- spawn->SetUnassignedPrestigeAA((sint16)value);
- else if ( type == "assigned_tradeskill_prestige_aa")
- spawn->SetTradeskillPrestigeAA((sint16)value);
- else if ( type == "unassigned_tradeskill_prestige_aa")
- spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
- if(spawn->IsPlayer())
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- return 0;
- }
- int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
- if (!lua_interface)
- return 0;
- string titleName = lua_interface->GetStringValue(state);
- int8 isPrefix = lua_interface->GetInt8Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
- lua_interface->SetSInt32Value(state, index);
- return 1;
- }
- int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
- lua_interface->SetSInt32Value(state, -1);
- return 1;
- }
- Player* player = (Player*)spawn;
- // check if player already has the title, don't need to add twice
- Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
- if ( playerHasTitle)
- {
- lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
- return 1;
- }
- Title* title = master_titles_list.GetTitleByName(titleName.c_str());
-
- if(!title)
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- lua_interface->SetSInt32Value(state, -1);
- return 1;
- }
-
- sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
- if(returnIdx < 0)
- {
- lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- }
- lua_interface->SetSInt32Value(state, returnIdx);
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
-
- if(!title)
- {
- lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
-
- if(title->GetPrefix())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title with name '%s' is not valid as a suffix, only prefix", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
- database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string titleName = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
- if(!title)
- {
- lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
-
- if(!title->GetPrefix())
- {
- lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title with name '%s' is not valid as a prefix, only suffix", lua_interface->GetScriptName(state), titleName.c_str());
- return 0;
- }
-
- database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- Player* player = (Player*)spawn;
- database.SaveCharSuffixIndex(-1, player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
-
- Player* player = (Player*)spawn;
- database.SaveCharPrefixIndex(-1, player->GetCharacterID());
- player->GetClient()->SendTitleUpdate();
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA GetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA GetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA GetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
- return 1;
- }
- int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA GetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- string value = lua_interface->GetStringValue(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA SetInfoStructString command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructString(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- int64 value = lua_interface->GetInt64Value(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA SetInfoStructUInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructUInt(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- sint64 value = lua_interface->GetSInt64Value(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA SetInfoStructSInt command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructSInt(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- string field = lua_interface->GetStringValue(state, 2);
- float value = lua_interface->GetFloatValue(state, 3);
-
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsEntity())
- {
- lua_interface->LogError("%s: LUA SetInfoStructFloat command error: spawn is not valid, either does not exist or is not an entity", lua_interface->GetScriptName(state));
- return 0;
- }
- Entity* ent = (Entity*)spawn;
- bool set_ = ent->SetInfoStructFloat(field, value);
- lua_interface->SetBooleanValue(state, set_);
- return 1;
- }
- int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool value = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn || !spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA SetCharSheetChanged command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
-
- ((Player*)spawn)->SetCharSheetChanged(value);
- return 0;
- }
- int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- std::string fromName = lua_interface->GetStringValue(state, 2);
- std::string subjectName = lua_interface->GetStringValue(state, 3);
- std::string mailBody = lua_interface->GetStringValue(state, 4);
- int8 mailType = lua_interface->GetInt8Value(state, 5);
- int32 copper = lua_interface->GetInt32Value(state, 6);
- int32 silver = lua_interface->GetInt32Value(state, 7);
- int32 gold = lua_interface->GetInt32Value(state, 8);
- int32 platinum = lua_interface->GetInt32Value(state, 9);
-
- int32 item_id = lua_interface->GetInt32Value(state, 10);
- int16 stack_size = lua_interface->GetInt32Value(state, 11);
- int32 expire_time = lua_interface->GetInt32Value(state, 12);
-
- int32 sent_time = lua_interface->GetInt32Value(state, 13);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn || !spawn->IsPlayer())
- {
- lua_interface->LogError("%s: LUA AddPlayerMail command error: spawn is not valid, either does not exist or is not a player", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
- ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 char_id = lua_interface->GetInt32Value(state);
- std::string fromName = lua_interface->GetStringValue(state, 2);
- std::string subjectName = lua_interface->GetStringValue(state, 3);
- std::string mailBody = lua_interface->GetStringValue(state, 4);
- int8 mailType = lua_interface->GetInt8Value(state, 5);
- int32 copper = lua_interface->GetInt32Value(state, 6);
- int32 silver = lua_interface->GetInt32Value(state, 7);
- int32 gold = lua_interface->GetInt32Value(state, 8);
- int32 platinum = lua_interface->GetInt32Value(state, 9);
-
- int32 item_id = lua_interface->GetInt32Value(state, 10);
- int16 stack_size = lua_interface->GetInt32Value(state, 11);
- int32 expire_time = lua_interface->GetInt32Value(state, 12);
-
- int32 sent_time = lua_interface->GetInt32Value(state, 13);
- lua_interface->ResetFunctionStack(state);
-
- int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
- Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_OpenDoor(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- ((Widget*)widget)->OpenDoor();
- if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
- widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
- }
- else
- lua_interface->LogError("%s: LUA OpenDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_CloseDoor(lua_State* state) {
- Spawn* widget;
- if (lua_interface) {
- widget = lua_interface->GetSpawn(state);
- bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- ((Widget*)widget)->CloseDoor();
- if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
- widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
- }
- else
- lua_interface->LogError("%s: LUA CloseDoor command error: spawn is not valid, either does not exist or is not a widget", lua_interface->GetScriptName(state));
- }
- return 0;
- }
- int EQ2Emu_lua_IsOpen(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* widget = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (widget && widget->IsWidget())
- {
- lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
- if (!lua_interface)
- return 0;
- sint32 min = lua_interface->GetSInt32Value(state);
- sint32 max = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- sint32 result = MakeRandomInt(min, max);
- lua_interface->SetSInt32Value(state, result);
- return 1;
- }
- int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
- if (!lua_interface)
- return 0;
- float min = lua_interface->GetFloatValue(state);
- float max = lua_interface->GetFloatValue(state, 2);
- lua_interface->ResetFunctionStack(state);
- float result = MakeRandomFloat(min, max);
- lua_interface->SetFloatValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_AddIconValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->AddIconValue(value);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 value = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!spawn)
- {
- lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- spawn->RemoveIconValue(value);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_GetShardID(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int32 shardid = shard->GetShardID();
- lua_interface->SetInt32Value(state, shardid);
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_GetShardCharID(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int32 charid = shard->GetShardCharID();
- lua_interface->SetInt32Value(state, charid);
- return 1;
- }
- lua_interface->SetInt32Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
- Spawn* npc = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (npc && npc->IsNPC()) {
- NPC* shard = (NPC*)npc;
- int64 timestamp = shard->GetShardCreatedTimestamp();
- lua_interface->SetSInt64Value(state, timestamp);
- return 1;
- }
- lua_interface->SetSInt64Value(state, 0);
- return 1;
- }
- int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
- if (!lua_interface)
- return 0;
- int32 shardid = lua_interface->GetInt32Value(state);
- lua_interface->ResetFunctionStack(state);
- if(shardid < 1)
- lua_interface->SetBooleanValue(state, false);
- else
- lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
- return 1;
- }
- int EQ2Emu_lua_PauseMovement(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
- if (spawn) {
- spawn->PauseMovement(delay_in_ms);
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_StopMovement(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- if (spawn) {
- spawn->ResetMovement();
- }
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- int EQ2Emu_lua_GetArrowColor(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && level > 0) {
- lua_interface->SetInt32Value(state, player->GetArrowColor(level));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int8 level = lua_interface->GetInt8Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (player && player->IsPlayer() && level > 0) {
- lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetTransportByRailID(rail_id);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_SetRailID(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- bool res = false;
- if(spawn && spawn->IsTransportSpawn())
- {
- //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
- spawn->SetRailID(rail_id);
- res = true;
- }
- else if (!spawn) {
- lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
- }
- else if(!spawn->IsTransportSpawn()) {
- lua_interface->LogError("%s: LUA SetRailID command error: spawn %s is not a transport spawn, call AddTransportSpawn(NPC) first", lua_interface->GetScriptName(state), spawn->GetName());
- }
- lua_interface->SetBooleanValue(state, res);
- return 1;
- }
- int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- ZoneServer* zone = lua_interface->GetZone(state);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- lua_interface->SetBooleanValue(state, zone->IsLoading());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_IsRunning(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- lua_interface->SetBooleanValue(state, spawn->IsRunning());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 zoneID = lua_interface->GetInt32Value(state, 2);
- bool displayClient = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (!player || !player->IsPlayer() || !player->GetClient()) {
- lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
- }
- else if(!zoneID) {
- lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
- }
- else
- {
- lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetWorldTime(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- int16 newYear = lua_interface->GetInt16Value(state, 1);
- sint32 newMonth = lua_interface->GetInt16Value(state, 2);
- int16 newHour = lua_interface->GetInt16Value(state, 3);
- int16 newMinute = lua_interface->GetInt16Value(state, 4);
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.writelock(__FUNCTION__, __LINE__);
- world.GetWorldTimeStruct()->year = newYear;
- world.GetWorldTimeStruct()->month = newMonth;
- world.GetWorldTimeStruct()->hour = newHour;
- world.GetWorldTimeStruct()->minute = newMinute;
- world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
-
- return 0;
- }
- int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
- if (!lua_interface)
- return 0;
-
- lua_interface->ResetFunctionStack(state);
-
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
-
- return 1;
- }
- int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
- if (!lua_interface)
- return 0;
- lua_interface->ResetFunctionStack(state);
-
- world.SendTimeUpdate();
-
- return 0;
- }
- int EQ2Emu_lua_ChangeFaction(lua_State* state) {
- bool update_result = false;
- Faction* faction = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 faction_id = lua_interface->GetInt32Value(state, 2);
- sint32 increase = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if(!spawn || !spawn->IsPlayer()) {
- lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
- return 0;
- }
- Player* player = (Player*)spawn;
- Client* client = player->GetClient();
- if (faction_id > 0) {
- bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
- if(hasfaction == 0) {
- //they do not have the faction. Lets get the default value and feed it in.
- sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
- //add the default faction for the player.
- player->SetFactionValue(faction_id, defaultfaction);
- }
- if(increase >= 0) {
- update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
- faction = master_faction_list.GetFaction(faction_id);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- if(increase < 0){
- //change the negative to a positive, since thats how decreasefaction() likes it.
- increase *= -1;
- update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
- faction = master_faction_list.GetFaction(faction_id);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_HasCoin(lua_State* state) {
- bool hascoin = 0;
- Player* player = (Player*)lua_interface->GetSpawn(state);
- int32 coins = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (player && player->IsPlayer()) {
- hascoin = player->HasCoins(coins);
- if(hascoin == 0) {
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(hascoin == 1) {
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetLootTier(lua_State* state) {
- int32 loot_tier = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- loot_tier = spawn->GetLootTier();
- lua_interface->SetInt32Value(state, loot_tier);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetLootTier(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 loot_tier = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (spawn) {
- spawn->SetLootTier(loot_tier);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_GetLootDropType(lua_State* state) {
- int32 loot_drop_type = 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (spawn) {
- loot_drop_type = spawn->GetLootDropType();
- lua_interface->SetInt32Value(state, loot_drop_type);
- return 1;
- }
- return 0;
- }
- int EQ2Emu_lua_SetLootDropType(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if (spawn) {
- spawn->SetLootDropType(loot_drop_type);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int8 damage_amount = lua_interface->GetInt32Value(state, 2);
- if(damage_amount > 100) {
- damage_amount = 100;
- }
-
- if (!spawn) {
- lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- lua_interface->ResetFunctionStack(state);
- if (spawn->IsPlayer()) {
- if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
- lua_interface->SetBooleanValue(state, true);
- else
- lua_interface->SetBooleanValue(state, false);
- }
- else {
- lua_interface->SetBooleanValue(state, false);
- }
-
- return 1;
- }
- int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 version = lua_interface->GetInt32Value(state, 2);
-
- RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
- if(region_map == nullptr) {
- lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string region_name = lua_interface->GetStringValue(state, 3);
- string env_name = lua_interface->GetStringValue(state, 4);
- int32 grid_id = lua_interface->GetInt32Value(state, 5);
- int32 widget_id = lua_interface->GetInt32Value(state, 6);
- float dist = lua_interface->GetFloatValue(state, 7);
- region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveRegion(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 version = lua_interface->GetInt32Value(state, 2);
-
- RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
- if(region_map == nullptr) {
- lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
- lua_interface->ResetFunctionStack(state);
- return 0;
- }
- string region_name = lua_interface->GetStringValue(state, 3);
- region_map->RemoveRegionNode(region_name);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- if (!player) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- lua_interface->ResetFunctionStack(state);
- return 1;
- }
-
- Spawn* spawn = lua_interface->GetSpawn(state, 2);
-
- bool success_sight = client->SetPlayerPOVGhost(spawn);
-
- lua_interface->ResetFunctionStack(state);
- lua_interface->SetBooleanValue(state, success_sight);
- return 1;
- }
- int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool result = false;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
- if (!lua_interface)
- return 0;
- bool result = false;
-
- Spawn* spawn = lua_interface->GetSpawn(state);
- lua_interface->ResetFunctionStack(state);
- if (!spawn)
- lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
- else if (!spawn->IsNPC())
- lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
- else
- {
- if(((NPC*)spawn)->cast_on_aggro_completed)
- result = true;
- }
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- bool result = client->AddRecipeBookToPlayer(recipe_book_id);
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 recipe_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- bool result = client->RemoveRecipeFromPlayer(recipe_id);
- lua_interface->SetBooleanValue(state, result);
- return 1;
- }
- int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
- Client* client = nullptr;
- Spawn* player = lua_interface->GetSpawn(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
- bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
-
- // rest are all optional fields
- float x = lua_interface->GetFloatValue(state, 4);
- float y = lua_interface->GetFloatValue(state, 5);
- float z = lua_interface->GetFloatValue(state, 6);
- int32 grid_id = lua_interface->GetInt32Value(state, 7);
-
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!player->GetZone()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- client = player->GetClient();
- if (!client) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!client->IsReadyForUpdates()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
- Client* client = nullptr;
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
-
- lua_interface->ResetFunctionStack(state);
- if (!spawn) {
- lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
- if(!spawn->GetZone()) {
- lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- spawn->AddIgnoredWidget(widget_id);
-
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 widget_id = lua_interface->GetInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
-
- if(!zone) {
- lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- if(!zone->IsLoading()) {
- lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
-
- zone->AddIgnoredWidget(widget_id);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- int EQ2Emu_lua_SendHearCast(lua_State* state) {
- if (!lua_interface)
- return 0;
- LuaSpell* spell = lua_interface->GetCurrentSpell(state);
- Spawn* spawn = lua_interface->GetSpawn(state);
- int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
- int16 cast_time = lua_interface->GetInt16Value(state, 3);
- Spawn* caster = lua_interface->GetSpawn(state, 4);
- Spawn* target = lua_interface->GetSpawn(state, 5);
- lua_interface->ResetFunctionStack(state);
- if(spell && spawn && spawn->IsEntity()) {
- ZoneServer* zone = spawn->GetZone();
- if(zone) {
- zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
- }
- }
- else if (spawn) {
- if (spawn->IsPlayer()) {
- Client* client = ((Player*)spawn)->GetClient();
- if (client) {
- client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
- }
- }
- }
- return 0;
- }
- int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- bool ret = ((Player*)player)->get_character_flag(flag_id);
- lua_interface->SetBooleanValue(state, ret);
- return 1;
- }
- int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
- if (!lua_interface)
- return 0;
- Spawn* player = lua_interface->GetSpawn(state);
- sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
- lua_interface->ResetFunctionStack(state);
- if (!player) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
- return 0;
- }
- if (!player->IsPlayer()) {
- lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
- return 0;
- }
- ((Player*)player)->toggle_character_flag(flag_id);
- return 0;
- }
- int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
- LuaSpell* spell = lua_interface->GetSpell(state);
-
- if(!spell) {
- spell = lua_interface->GetCurrentSpell(state);
- }
-
- lua_interface->ResetFunctionStack(state);
- if (spell) {
- if(!spell->caster) {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- if(!spell->caster->GetZone()) {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
- return 0;
- }
- Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
- if (spawn) {
- lua_interface->SetSpawnValue(state, spawn);
- return 1;
- }
- else {
- lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
- }
- }
- return 0;
- }
- int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
- ZoneServer* zone = lua_interface->GetZone(state);
- int32 location_id = lua_interface->GetInt32Value(state, 2);
- int32 delay = lua_interface->GetInt32Value(state, 3);
- lua_interface->ResetFunctionStack(state);
- if (zone) {
- Spawn* spawn = zone->GetSpawnByLocationID(location_id);
- if (spawn) {
- vector<Spawn*> groupMembers;
- if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
- groupMembers = *spawn->GetSpawnGroup();
- for (int32 i = 0; i < groupMembers.size(); i++) {
- Spawn* member = groupMembers.at(i);
- if(member && !member->IsPlayer() && member != spawn) {
- member->GetZone()->Despawn(member, delay);
- }
- }
- }
-
- zone->Despawn(spawn, delay);
- lua_interface->SetBooleanValue(state, true);
- return 1;
- }
- }
- lua_interface->SetBooleanValue(state, false);
- return 1;
- }
|