Search Unity

TurnBased-Toolkit (TBTK)

Discussion in 'Assets and Asset Store' started by Song_Tan, Aug 11, 2013.

  1. Rajmahal

    Rajmahal

    Joined:
    Apr 20, 2011
    Posts:
    2,101
    Hi Songtan,

    I'm running into a major problem that I"m hoping you can help on. As you know, I'm trying to release a game based on your older version of TBTK (mid version 2). I've customized the scripts heavily and so I'm not able to update to the latest version of v2 build. My game loads different levels and has its own code for tracking the player units and their statlines between levels. What I'm finding is that in the editor, everything works great. However, when I put it on a device (android or iOS), the first level loaded (either from a new game or a saved game in progress) works fine. However, if I then progress from that level to a subsequent level ... I almost always run into some null reference exceptions.

    What I find odd is that if I then exit the game and load back into it and go to the same level that had the null reference exceptions, the game plays fine for one more level. So I'm guessing that some file / game object is persisting through the levels and causing issue for me. Do you know of a way to delete all objects and singletons between levels? I have a loading screen in between each level so I believe I could destroy all objects there. I believe everything I need is in the next level so I think I should be able to destroy all persistent objects and start fresh. Essentially, I'm trying to fake it and set up the next level as if I had exited the game and started the game in that level ... presumably creating all singletons like GameControlTB.instance and so forth.

    I'm thinking I could use Destroy (GameControlTB.instance) in the leading scene between game levels. Do you think that would work? I'm in the process of testing it as I type. Do you know of any other persistent game objects in TBTK?
     
  2. Thoreandon

    Thoreandon

    Joined:
    Aug 21, 2014
    Posts:
    37
    Ok, here is a link to Steam that shows some parts of the game i did using TBTK as a framework.
    Its just a concept right now but i will move it to the Steam Greenlight Game Area in a couple of weeks, still a lot of polishing have to be done but technically almost any parts that i need are implemented.
    Its time now to work on the gfx.

    I have to say that i did make a lot of additions to TBTK and i also changed a lot of Code.
    It would be nice if a lot of you can check it out and leave some comments in Steam.
    (Hope, Songtan dond mind that i do some sort of spaming here ;-) , but i think that anybody interessted in TBTK might like to see whats possible.
    Thanks of course, to Songtan, trying to answer some of my wired problems sometimes.

    http://steamcommunity.com/sharedfiles/filedetails/?id=359598730

     
  3. Fred69

    Fred69

    Joined:
    Oct 5, 2014
    Posts:
    6
    i songtan,
    I am trying to integrate my custom terrain tiles in the map of the toolkit....
    but I have trouble placing my tiles in the right place ...
    Is there a way to snap tiles to hex ?
    a screenshot of my tiles :


    thank you
    Fred
     
  4. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    First of all, very sorry for being missing for the past few days. For some reason I'm not getting any notification at all so I must have miss them.

    The hit animation not playing is indeed a bug. Just change line 950 in Unit.cs to if(unitAnim!=null) unitAnim.Hit(); will fix it.

    For the unit info panel, UnitInfoPanel.Show() and UnitInfoPanel.Hide() is called from UIOverlay.cs to show the panel when a unit overlay is hovered over so first you will have to disable that. Then you simply call the same function when a unit is selected/deselected in GameControl.SelectUnit().


    GridManager.IsInLOS() does not exist. FogOfWar.InLOS() does. If the obstacle you are using for the wall is halfObstacle (based on layer), it doesnt not block LOS. And yes, depend on the circumstance, you can shoot at a unit behind a wall. It can happen when it's a "half cover" wall, or the target is hiding at the edge of the wall (where the attacker can still gain LOS and attack via 'peeking', which can be set in GameControl). There's also a AttackThroughObstacle flag (on GameControl) to considered if a unit can attack through wall.


    As far as I know, in term of TBTK anyway, there's no persistent game object involved. My guess you have some static variable that is not reset properly, or some event subscription that doesnt clear up properly. In that case, destroying object probably wont solve the issue. Another clue is it happen only on Android and iOS so is there anything that is exclusive to those plaform. If you can see the null reference error message, cant you see where the error is coming from, which script, which line?


    You can snap a particular vertex of a mesh to a particular vertex of another mesh while holding v-key while moving the mesh. So you can snap a corner of your terrain mesh to the corner of the tile mesh.

    Hope I didn't miss any question. Sorry again for the inconveniences.
     
    Last edited: Dec 31, 2014
  5. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Btw I've just uploaded another minor update. This one fixes various bugs from the initial release. :)
     
  6. primus88

    primus88

    Joined:
    May 14, 2013
    Posts:
    611
    Hello Songtan.

    I'm interested in your toolkit but first I want to know if it would suit my needs.
    I'm planning to do a turnbase 2D game similar to Xcom and such.

    Please check this video:


    The combat / ai / map will be similar in functionality. Very similar.
    Can you tell me if this can be done by using your toolkit as starting point?

    Thanks
     
  7. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, it's a pretty open question. To use it as a starting point, yes. But that also means that you definitely going to need some modification if you want it to be exactly the same as the video you show me. For a start, TBTK doesnt quite support 2D asset. You are going to have to make your own solution in that regard (sprite facing, animation/display depends on the unit facing, etc.). Also TBTK doesnt supports inventory and loot system.
     
  8. Exeneva

    Exeneva

    Joined:
    Dec 7, 2013
    Posts:
    432
    TBTK does have a spawn system, right? It's just not tied to any inventory system.
     
  9. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You mean spawn during a runtime, in the middle of gameplay? If so, it's not really a spawn system. You can add unit to the grid during runtime using abilities. But there isnt a system that would procedurally place unit on the grid during gameplay.

    On the other hand if you meant procedurally generating unit on the grid in edit mode or before the game start, the answer is yes.
     
  10. Crival

    Crival

    Joined:
    Sep 3, 2014
    Posts:
    21
    First of all Happy New Year to all of you!

    I'm curious... Is it easy to implement an objective in battle like survive for a number of turns in TBTK v2?
     
  11. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, it depend on the objective and how comfortable you are with coding. If you are relatively good with coding. I imagine it's probably not too hard to implement most custom objective. Survive for number of turns for instance, should be relatively easy.
     
  12. Crival

    Crival

    Joined:
    Sep 3, 2014
    Posts:
    21
    I'm not familiar with c# but I used to do programming with C and reading your codes is really taking its toll on me... XD

    Can you guide how to implement the survive for number of turns objective in battle?
     
  13. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Right, so there's a variable in TurnControl.cs, currentTurnID which keep track of how many turn there has been in the game. When the value passed a threshold, simply call GameContorl.GameOver(), passing ID of the winning faction. The ID of faction being the index of the faction in the FactionManager. First faction being 0, second being 1 and so on. Make sense?
     
  14. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    In games such as Might and Magic Heroes VI, we can see units turn order (which one will move after another). Can this be done using any existing scripts?
     
  15. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately no. For some certain turn-mode in TBTK. Unit order simply doesnt apply. So there's no UI script that is used for displaying unit turn order. Also, turn order is no pre-determined . The next unit in turn is determined as the current unit ends its turn. So you will need to pre-determined the unit order for a start.
     
  16. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    Okay. I see. I guess I have to put that on hold first for my game.

    Another question on a different topic.
    Let's say I want to have mecha-based game, where a mecha can have either its left or right arm detached and replaced with different weapons. Each weapon will affect the mecha stats (damage point, etc). This change in stats should be reflected on that particular mecha unit.

    Also, if a mecha has been modified, any modifications (such as change in left or right arm) will be carried on to a TBTK battle map. In other words, the mesh that is displayed will be based on the previous modifications.

    How do I do this within the TBTK framework?
     
  17. kilik128

    kilik128

    Joined:
    Jul 15, 2013
    Posts:
    909
    i don't understand one lilttle starting think's when i'am on android Platform build i can't move unit any more so can't testing
     
  18. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'll have to say that it's not going to be straight-forward. I'm working on the exact same thing in my own game. First you will need a custom mech class that stores the weapon and stats info. For each mecha, you need to create a corresponding unit prefab. These unit prefabs are the one that is going to be used on the grid. You are going to have to modify FactionManager.Init() by quite a lot. By which I mean after the unit are instantiated, you will need to modify the unit based on the infomation on the information on the mech. It's hard to tell you exactly how to changes the mesh and so on as this very much depends on how you setup your unit hierarchy. The way I did it, I set a left/right weapon mount point (an empty transform) for each of the unit and simply instantaite and attach the weapon object on the mount point (by setting the weapon mount as the weapon's parent transform).


    If you set your target platform to Android, the code will stop responding to mouse input. So you can no longer test it using mouse input, you need to test it on an actual touch device.
     
  19. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    What if I simplify the game system so that the requirement is for mecha or any unit to be able to change their armor texture or clothing. Will the implementation be more straight forward? How do I carry this change of texture to a different scene?
     
  20. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    You still end up with pretty much the same process, only that it (probably) looks cleaner on the prefab hierarchy and slightly less code required. Instead of creating and swapping mesh, you will be swapping mesh's material or texture.
     
  21. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    Okay. So the process largely will remain the same.

    After I swap a unit mesh material, how do I make sure that this information is saved?
    I understand that in the campaign example, the changes in unit level and stats can be carried forward to another scene.

    If I were to also save the changes in unit mesh material or texture, I am guessing that the scripts to modify would be TBTK_Class_Data or DataUnit. Am I on the right track? :)
     
  22. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Yes, that's one way to do it. But you will need to modify Unit.cs, ModifyStatsToData() as well. You create any extra variable (weapon type and so on) that you need to store any additional information you may need in DataUnit class. Once the level is loaded and the unit is instantiated, ModifyStatsToData() will be called to modify unit's stat. So that's where you need to add in your new code to edit the unit based on the infor stored in the DataUnit instance. Make sense?
     
  23. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    Right. So ModifyStatsToData() is the function to load the unit attributes.

    So my understanding about the process is like this:
    - decide additional stuff that a unit can have, let's say texture, weapon in left arm, and MP (Mana Points)
    - go to TBTK_Class_Data script and modify the DataUnit class. Add texture, variable based on a custom class (for weapon), and integer for MP
    - go to Unit script and modify the ModifyStatsToData to cater for the above three additional stuff.
     
  24. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    correct! Save a backup and go ahead with some trial and error. Let me know if you got stuck. :)
     
  25. AndyMul

    AndyMul

    Joined:
    Jul 13, 2013
    Posts:
    41
    Okay. Will give it a go. :)
     
  26. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    Hi, I've just brought your kit and I must say that its amazing. I was just wondering what the difference is between passive and trigger, I've tested both and I cant quite tell the difference. also I was wondering if there was a way to get the AI faction to randomly move around the grid without them going straight for the kill. I have generated a bigger map and I wanted the AI faction to move around the map until they come in range to someone they can attack. I just didn't want it to look like the AI was gunning straight for the kill. I'm kind of wanting it to look like the AI was making a choice to were there going.
     
  27. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Thanks for your purchase.

    For your information, under 'Passive' AI, units only active when there are hostile in pressence (within the range of sight). If you run away from passive AI unit, they will stop pursuing and become inactive again. Using 'Trigger' AI, once the AI unit is triggred by hostile pressence, it will stay active. Even when the hostile units have clear off sight.

    I'm afraid additional code modification will be required to have the AI unit moving around when there's no hostile is in range. I'll see if I can do that in the next update, but that wont happen immediately tho. In the meant time, you can try to modify the code yourself if you are comfortable with coding. All the code for the AI is in AIManager.cs.
     
  28. shadow-river

    shadow-river

    Joined:
    May 29, 2013
    Posts:
    63
    cool it would be great if you were able to do that when you can,but ill see what I can do in the mean time. is it possible to use a mix of passive and aggressive at the same time with different factions..
     
  29. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    That shouldnt be a problem. :)
     
  30. roh032

    roh032

    Joined:
    Sep 6, 2014
    Posts:
    4
    Does you framework support different heights for grid tiles? I mean i want to give longer sight and better chance to hit target to units on the hill, or just on higher points.
     
  31. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    While you can adjust the height of the tiles, there's no support for changing the unit stats based on height. So no, unless you do some customization of your own, what you are looking for is not available.
     
  32. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    Here is what I have been using the kit for (it also uses ORK):



    I'm working on a Steam Green-light today!
     
    testament32 likes this.
  33. W1ntermute

    W1ntermute

    Joined:
    Aug 24, 2014
    Posts:
    9
    Does tbtk 2.0 support pre-battle unit choosing (buying) for hotseat mode? And how difficult is it for implementing, maybe someone has analogic experience?
     
  34. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Sorry for the slow respond. To answer your question, it's supported to an extent. By which I mean it's supported in term of code. The default UI tho, doesnt allow that, it assumes one player only and all unit selected are for that player alone.

    It's relatively easy in term of code, just a few lines max. The tricky bit is the UI (and the code that comes with it). That means you have to build your own UI that can switch between the hotseat player and allow them to select unit. Once that is sorted, it's just a matter of assigning unit selection of playerN to factionN, unit selection of playerM to factionM and so on.
     
  35. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Hey Song - figured I would take the conversation over here from your blog page. I bought your pack last night and am working on getting my units set up in your system. I have a skeleton warrior that I set up. I can deploy him and move him around during game play, but when I attack something (or trigger a counterattack), you see my unit rotate toward the enemy, but no animation plays (all other animations play) and the game just gets stuck there (doesn't freeze, just doesn't progress). I have set up the unit to use the 'empty effect' prefab. He can attack and counterattack once, which costs AP. moving doesn't. I have not assigned any shootpoints, turrets, or barrels. The target point I set up is the basic skeleton of the unit (so the transform is at its feet. I have even tried with different ranged attacks, replicating how the default units are setup. Still the same issue happens.

    Any Thoughts?

    Edit: Also, no error messages or exceptions are thrown, Unity reports no issues. Is something possibly getting hung up in the chain of methods that are called once an attack is made? I took a gander at the code and placed some debug.log lines, and none of them seemed to be called. I placed one in the Unit.cs Attack method, and in the game manager section where it calls the Unit.cs attack method. Neither seemed to be called.

    Also, I can say more about what happens at the time. Basically I click to attack, my unit rotates, AP gets deducted, but no attack is made. If I click end turn, it goes to the AI. They do the same thing - go to attack, their AP bar goes down, but no attack actually happens. I can't progress past this because it hangs on their turn. If I keep my guy out of counterattack range and make no manual attacks, the default units will function normally until my unit is dead. Basically, my unit attacking interferes with both the AI and my own units from being able to take appropriate actions.

    Thanks!
     
    Last edited: Jan 23, 2015
  36. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Just done a quick test on my end. Basically what happen is a small bug for unit with no turret/barrel but is told to aim in both x and y-axis. What you need to do is uncheck the "Rotate in x-axis when aiming" option in UnitEditor. That should fix the issue. I'll go fix it so it's not going to be an issue in the future.
     
  37. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Oh god what an easy fix. I spent hours on this. I figured that was the bit that made the unit rotate toward the enemy, so I wanted to keep that. Thank you SO much for the reply.

    Will the unit still rotate towards what it is attacking?

    Edit - Disregard. You said both X and Y - Y is active by default which controls his facing toward an enemy. got it!
     
  38. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    A unit will always rotate to face it's target when attacking. The difference between the option is weather it points towards the target point precisely or just face the general direction. The former is generally used for units that have a turret and shoots so you want the turret to point towards where the shootObject will hit. The later is generally for melee units where you just want it to face the right direction when attacking.
     
  39. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Thanks for the more in depth explanation!

    I also took a gander at the code, seeing where I need to do my editing to create my own stat system that effects damage of base attacks as well as abilities. Do you have any documentation for figuring out where to make changes to customize the types of stats a unit has and how they effect damage, life, etc?

    really excited about this package. I had a whole game system built stat/ability/mechanic wise. My (small) team and I wanted to change gears and make it turn based, so I want to replicate, in a turn based way, what we have already done, and this package fits the bill for what we need. I just need to learn what strings to tug on to make my changes and alterations.

    I am the programmer of the group, so feel free to get technical with me.

    I have figured out how to make different options appear in the UnitEditor already, and have added options for starting strength, vitality, magic, dexterity, and how much of these stats the unit gains per level. I created the variables that hold this data in Unit.cs and kinda want to make sure I am on the right track. I need to do a -lot- of tweaking to mold this to my own needs and am just unsure what classes to work with to control stats, leveling up, and abilities that grow in power based on the stats of the unit using them.
     
  40. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Unfortunately I dont have any documentation specifically about code. But you are on the right track there. The stats goes into Unit.cs. You will find all the calculation about those stats in TBTK_Class_AttackInstance.cs. And the damage/effect are applied to the unit back in Unit.cs, in function ApplyEffect(). The stats are pretty much self-explainatory so you shouldnt have any touble figuring out what does what.

    As for the abilities, they are a self-sustain component that carry their own stats. They are not tied to the unit in any way by default. That is something you will need to work on.
     
  41. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Awesome, thanks Song. I will focus on just build the stat system for now. thank you for the advice! I noticed there is a section in Unit.cs where it declares level and provides a getter and setter for it. Would this be the best 'section' of unit.cs to place the stats?

    Just to be clear on abilities - when you have a unit selected and he uses an ability, the ability is just a stand alone class with no link to the actual unit using it? I am asking because if the ability already carries a reference to the unit (possibly for transforms for projectile instantiation) it would be easy to have the damage of the ability first pull from the Unit.cs attached to the unit to get stats and calculate damage before actually using the ability. Even if multiple units shared the same ability instance, the ability would just adapt to whatever unit is accessing it. Does this sound feasible in the TBTK framework? I have not yet tinkered with Abilities or seen their code.
     
  42. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    The 'level' section you refer to are code section used for bringing unit from other scene and passing unit to another scene. Basically the mini-campaign kind of stuff in the demo where you can set a line up, and then track how many have survive the battle, and modify their stats in the next battle. There's no best section to do any particular thing. It all depends on the implementation, code design and personal preference. Simply put, as long as you get it right, it works. Simple as that. Afterall, anything from here on is your addition, so It's up to you to decide since you are the one that is going to expand and maintain it.

    An ability is simply a class that contain all the information (including the stats). It's the unit and AbilityManager that execute the it based on the information. Each ability on a unit is an ability instance referenced by the unit. They have their own cooldown, usesage tracking and so on. Stats like damage, modifier and so on however are copied from a base copy (the one modified in the editor and stored in AbilityDB prefab). Effectively they are the same for two unit using the same ability, but technically they are not shared. You can modify one ability instance in the unit's abilityList without affecting other similar ability. For now the stats in the abilities are self-contained. But you can easily modify it so that it's in some way modify by the unit that uses it.
     
  43. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Thanks Song, I will get to it and see what I can do! thank you for being so responsive as I get used to the structure of TBTK!
     
  44. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I think I discovered a bug in the first version. Not sure if it anything I did or not, but if I have a unit with more than 6 abilities, I get an "Argument Out of Range error; Parameter name: Index" on UINGUIAbilityButtons.cs: 148 (the line where it positions the ability buttons). Works fine for six and fewer abilities, but not for seven or more. I have 10 possible abilities for each of my units so I'd like to be able to have all ten of them at once. Any thoughts on this? Thanks!

    EDIT: I think I figured it out: Change the ButtonList number from 6-10 in theScAbilityButtons game object; but that seems to make things run really slow. Maybe a Unity restart will solve this.

    EDIT again... Oh, I forgot to actually add additional buttons so the list is reusing the last one!

    EDIT final: Solved!
     
    Last edited: Jan 23, 2015
  45. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Well, by default each unit is limited to 6 abilities because there's only 6 unit ability button created for the UI. But I think you have already figure that out.
     
  46. drewradley

    drewradley

    Joined:
    Sep 22, 2010
    Posts:
    3,063
    I did indeed figure it out. I reactivated your debug just above that and it lead me in the right direction, seeing where it was having problems. Then I looked at the object with that script attached to it (which is where I should have started!) and saw that it had a list that only had 6 and it all made sense. Now I have up to ten ability buttons, just like I wanted.
     
  47. Nickamus

    Nickamus

    Joined:
    Feb 8, 2014
    Posts:
    17
    Hello Folks - on the topic of abilities...

    My AI units do not seem to ever use the abilities I give them. One unit has a heal, the other has a fireball. Neither get used. Can you point me in the right direction to enabling them for AI? If this is not supported let me know and I can build my own class for handling that!

    Thank you!
     
  48. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    I'm sorry to say that the current AI algorithm doesnt support unit abilties. You can assign abilities to AI unit but they wont use them. Since you are a coder yourself I'm sure you unsderstand given the open nature of the abilities, it's very difficult for me to make an AI that reliable use those abilities at the correct time and place and on the correct target.
     
  49. Mikeoncrete

    Mikeoncrete

    Joined:
    Jan 8, 2015
    Posts:
    2
    I would like to have a look into your documentation before I buy.
    The video doesn't help me a lot. So is it possible?
     
  50. Song_Tan

    Song_Tan

    Joined:
    Apr 9, 2011
    Posts:
    2,993
    Of course you can. I've just pm you a link. Please let me know if there's anything else I can do to help.