# Source's custom OT game engine (TypeScriptFTW)

when does this release? can I contribute? im quite good at typescript but im fucking lazy id never build something like this XD
would love to see this bigbig
For now it's a private project as I've had to write and design everything myself.

I could release part of the C++ base if more people with C++ experience would like to contribute as there are some functions that are difficult to design and so forth.

Currently I'm working on implementing Destination spells and struggling with getting them just perfect, if this is something you'd like to try helping out with.
I got Dragon's fireballs just right, but Demon/Orshabaal's GFBs are slightly off (Cip engine):

TSS

My formula is if (abs(orig_x) + abs(orig_y) > spell.ShapeParam3) { continue; } where orig_x/y is the relative offsets before plotting actual coords.
I tried reverse engineering the Cip engine, but the only mention of radius is: radius != 0.

Anyways, don't worry if you can't help, I'm used to working on my own, if you'd like to help and are able to help that's great, but either way I'm enjoying the journey, you know

Last edited:
For now it's a private project as I've had to write and design everything myself.

I could release part of the C++ base if more people with C++ experience would like to contribute as there are some functions that are difficult to design and so forth.

Currently I'm working on implementing Destination spells and struggling with getting them just perfect, if this is something you'd like to try helping out with.
I got Dragon's fireballs just right, but Demon/Orshabaal's GFBs are slightly off (Cip engine):

TSS

My formula is if (abs(orig_x) + abs(orig_y) > spell.ShapeParam3) { continue; } where orig_x/y is the relative offsets before plotting actual coords.
I tried reverse engineering the Cip engine, but the only mention of radius is: radius != 0.

Anyways, don't worry if you can't help, I'm used to working on my own, if you'd like to help and are able to help that's great, but either way I'm enjoying the journey, you know
Great project, I'm watching this to evolve in a decent source and client.
It would be nice to release some usable versions and let the people look for bugs.
Congrats.

PD: I wonder on what version of Tibia are you working. It seems to be old school watching your screenshots.

Great project, I'm watching this to evolve in a decent source and client.
It would be nice to release some usable versions and let the people look for bugs.
Congrats.

PD: I wonder on what version of Tibia are you working. It seems to be old school watching your screenshots.
Thank you. I host the server from time to time for people, if they want, to look for bugs and try the server out.
It's version 7.72/7.7. Version 7.6 is also accepted, but some sprites will be missing if 7.7 object files are not used.
The server file data (objects.srv, mon/.mon, moveuse.dat, map/.sec, etc) is all the original 7.7 server data, so I'm basically writing my own cip server/clone using all the original server data, with some additions and potential for tweaks, like the cast system, where you can control certain monster behaviors yourself, etc.

Btw, solved the circle spell shape:

I tried asking chatGPT for advice, but its answers were pretty bad, it started making hollow circles and other bad patterns that it thought would output the circle I was looking for, in fact it told me "this will output [...]", but every single time it generated code whose output was anything between different to very different from the original shape. It even suggested using the mathematical function sin to generate the pattern, which made the "circle" more like the night sky, just a bunch of scattered dots.

It was right about one thing though, I had to use the euclidean distance for computation (which I had already tried), but I had to experiment and discover another hidden (strange and arbitrary) factor which made the spells now look like the original cip circle shapes.

Thank you. I host the server from time to time for people, if they want, to look for bugs and try the server out.
It's version 7.72/7.7. Version 7.6 is also accepted, but some sprites will be missing if 7.7 object files are not used.
The server file data (objects.srv, mon/.mon, moveuse.dat, map/.sec, etc) is all the original 7.7 server data, so I'm basically writing my own cip server/clone using all the original server data, with some additions and potential for tweaks, like the cast system, where you can control certain monster behaviors yourself, etc.
I hope that you can finish the project, it's the most interesting thing I saw in years here. Don't let the trolls disturb you and good luck, if this ends in a open source project I would be pleased to try it.

Update since the 20th of April:
• All spell shapes have been implemented and (hopefully) perfected.
• Fixed worldlight (easy to fix, but worth showing off, not many people will probably know just how dark it gets!).
• Experience is given when a monster dies. The experience is distributed based on damage to all attackers and are removed when a monster is healed (seems flawless in practice).
• Tons of bug fixes.

All spell shapes:

Darkness after 23:00 o'clock:

Fixed Warlock shooting 5x fire fields instead of 1x (other monsters seem to shoot the right size):

As you can see in the first GIF, monsters are not walking on elemental fields even though they're immune. This is something I discovered just a few days ago and am working on it, I had many bugs to fix so I prioritized others first.

Full changelog:
• Monsters no longer cast spells when health == 0.
• Actually fixed "Bear is trapped" bug, verified this time.
• Monsters cast potentially all the spells at once like they do on Cip engine.
• Monsters are now immune to certain spells/damage/elemental types.
• Fixed player (viewer) being attacked instead of the monster that's being casted.
• Fixed segfault when multiple monsters die.
• Monsters killing castviewed monster after player (viewer) is gone.
• NoLifeDrain flag is now being parsed (accidental typo in my code "NoLifedrain").
• Improved elemental immunities, colors and hitpoint/mana message.
• Monster self healing now updates health while castviewing.
• "You lose x hitpoints" message shouldn't fire when damage value is negative (healing).
• Added correct magic effects and colors for different monster types and spell elements (last ones were wrong?).
• Whispers for both players and monsters implemented (monsters don't whisper, even if they have #W in there).
• Monsters without an article damaging you should say "by name" not "by name" with two spaces.
• Implemented exp tracking and giving out exp on creature death (damageDistribution).
• Created and perfected shape of the func castDestinationSpell (circle spells).
• Can shoot UH rune on all players and SD runes on all non-self players.
• Monsters no longer walks off roofs.
• Fixed worldlight at time 23:00 (much darker).
• Fixed so spells doesn't trigger in PZ tiles.
• Fixed monsters spamming spells each step target is making (partially it seems, it's still or has become an issue again).
• Spells no longer cast on Unthrow tiles.
• Field magic (monsters cast and internal function to remove/add fields) implemented.
• Fixed world2.deleteItem() inaccurately deleting item and decrementing groundCount.
• Fixed handleItemsExpire not accounting for creatures stackpos when deleting item and not decrementing/incrementing Avoid and Unpass and Elements.
• Fixed warlock fire fields should shoot 5x fields.
• Health and mana can now be > 65535 up to 0xFFFFFFFF and beyond (sll)
• Fixed gameGetPlayers offsets (bottom and right side of screen not being shown).
• Fixed gameMoveObject offsets.
• Monsters are healing again.
• Monsters are doing Victim spells again (bug).
• Improved/fixed updateWorldLight().
• Other bugs.

Full server feature list so far:
• Original Zanera/Cip map and files including objects.srv, monster spells, attack and defense, etc
• Cast system (including monsters and controlling monster behaviors)
• Most monster damage spells (incl. distance attacks) with 100% cip engine formulaes and %chance
• 100% cip engine physical damage and defense/armor formulaes
• 100% cip engine randomized spawning algorithm
• Auto respawn when monsters die
• 100% accurate monster item inventories, amounts and lootchances
• 100% accurate certain monster behaviors: random walking (including timing/delay), casting certain spells when random walking, only turning every 2 seconds unless moving, turning before spellcasting (even if no spells are cast)
• Item movement (not in/out to/of inventory)
• A* Pathfinding for player (follow) and monster (chase/distance)
• Monster fleeing and keep distance behavior
• Monster spell immunities, spell colors and effects
• Walk with time delay (cannot speedhack)
• Attack with time delay
• Full alevo command to create items ("alevo 3031 100", 'alevo "gold coin" 100')
• /m command to spawn arbitrary monsters
• Full alani command ("alani -5,-5,-5", "alani 32000,32000,7", "alani thais")
• High performance XTEA and RSA encryption/decryption
• Server keeps track of player IPs and uses TCP_NODELAY aka Leatrix latency fix on server side
• Items decay and server keeps track of whether tile is Unpassable/Avoidable or not
• Builtin IRC bot

Summary of performance and language advantages:
• You can write pretty much anything in either a scripting language or C++, it's your choice; great to prototype using scripting language, then replace with C++ if necessary for performance later on
• Same or better getCreatures performance compared with TFS (initial benchmarks indicates better performance than TFS)
• Same or better activated monster CPU usage* (with or without spells) including A* pathfinding cost compared with TFS (*using TFS 1.4.2 with OTRS data pack and real map)
• So far very good performance with large amount of monster spells, much better performance than Cip engine (haven't tested TFS), however there's no canShoot(...) function implemented yet, so it's possible that function is going to be costly

Summary of performance and language disadvantages:
• Many minor issues/missing features (the language is a work in development) that needs to be worked around when developing
• Code is a bit messy. Two different world-classes for example

Last edited:
this is amazing

Quick update since Saturday evening:

Improved A* and all other forms of pathfinding by including elemental immunities and "KickBoxes" (ignores Avoid tile flag) flags.
In other words monsters immune to say fire will now step on fire fields, monsters that aren't won't, same with e.g. parcels, poison fields and energy fields.

Solved another important and medium-easy (took many hours to figure out) bug:
Distance monsters stopped turning and casting spells when target moves around adjacent to the monster (i.e. no monster movement is triggered).

Here it's solved:

Solving this required checking if the current "monster behavior function" event was completed before creating a new one, functionality that's not directly implemented through any method, but was pretty trivial to implement.

• You can do some pretty cool stuff with Lambdas/anonymous functions if you wish to, like call an anonymous function as a scheduled event with any arbitrary delay attached to it. Anonymous functions are also way easier on the eye and your hands to type out in this language compared to say C++.
• You can raise exceptions to create a stack trace which shows you an entire trace of the function calls that was involved eventually leading to an exception being raised. Exceptions are automatically raised when stuff goes wrong, as long as the code is not written in C/C++ (if you try writing to the nth+1 element of a std::vector your program is going to crash just like any other C/C++ program. but trying to write to a nth+1 non-C/C++ or "TypeScript" array will just raise an exception).
• Bonus: You can also use, as I have, Valgrind to trace down segfaults, memory leaks and performance issues on Linux with ease.

Last edited:
Update since 8th of May:

Monsters no longer attack in PZ

Conditions implemented; paralyze and haste

Invisibility + fixed casting involved with viewing an invisible creature

Outfits (the hardest one to implement for sure) + cancels invisibility

Surprise feature for a future stream: jungle mode (all nearby monsters attack random monsters based on Cip engine strategies) when castviewing and informs viewer of what new monster is being targeted

In addition to these gifs here's some main fixes:
• Implemented all 4 monster strategies for targeting monsters (distance, lowest health, most damage, random)
• Runes have been moved into BP and all EQ including weapons load stats, so the new giant sword item has the appropriate 46:22 stats. You also instakill all monsters with SDs now (except in aimtraining mode)
• Distance monsters now random walk, including the ones in the corner (the ones in the corner needed a bug fix)
• More than half of the monster spells has been implemented now, the ones remaining rely on more conditions development like drunkenness

Full list of fixes:
• Monsters now keep casting spells even when player runs back and forth adjacent to the monster
• Monsters should only cast spells up to once each second now
• DistanceMonsters only has 2 sec delay when player is dist <=1 + cornered now
• Melee monsters now shoots spells also when continueWalking
• No more casting angle and origin damage spells when randWalking
• Monster healing doesn't have 2 sec delay; regular 1 sec delay now
• Monsters now go into randWalk mode when player is in pz
• Distance monsters now randomSteps
• Un-hardcoded the IRCbot (parameters like channels, username and password in config)
• When dead ignore all packets except for logout packet
• You are dead message upon onDeath
• Fixed occasional segfault in onDeath (exp distribution)
• basecreature::changeTarget() with all 4 strategies
• Avoid tiles no longer ignored when Avoid item is not MagicField or moveable
• Infinite loop in onDeath caused by cr.attackTarget(0) in the middle of iteration
• Inventory items dropped when castviewing again
• Corner distance monsters (4 + 4 tiles away) now "distanceRandWalk"s like they should
• Started implementing conditions; haste and paralyze implemented
• Invisibility implemented
• Invisible creatures appears and sends steps for castviewers
• Changing outfits implemented

How do you plan to create and manage accounts for this server? It will be compatible with any acc maker?

How do you plan to create and manage accounts for this server? It will be compatible with any acc maker?
Hey. There are no accounts for now. It's just a test server. Everyone are GMs and can enable/disable their GM status to fight with/test monsters out. It's a neat little server to play with to test things with many built-in functions to test things, but it's far from ready for production purposes.
I can create websites, in fact the server has a built-in webserver with a tiny little page that displays some server stats:

Not the best demonstration of my website development skills, but yeah, making an AAC won't be an issue, but doing so is far down the line, first we'll need to be able to store and load players to begin with
There is also no SQL connection yet. Only a SQLite database used to keep track of quiz points through IRC on stream.
No event system, so you won't fall down holes, you can't rope yourself up, no fishing, no quests, etc.
No player spells, no regeneration, no vocations, no NPCs, and so on.
So there's a long way to go for full server functionality. I'm guessing we're about halfway there or so from nothing.
But it's fully possible that this server will never be completed. I'm not looking forward to parsing player data, NPCs and moveuse.dat.
It's just a fun little project for now, teaching myself C/C++ and having something interesting to work on.