Search Unity

[RELEASED] Turn Based Strategy Framework

Discussion in 'Assets and Asset Store' started by michal-zetkowski, Jul 2, 2019.

  1. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    You can implement ICellGridGenerator class to generate maps with some custom properties. Your generator will be available to use in GridHelper. If you want to generate the maps on runtime, you can reuse the same code, just make sure that the map is generated before CellGrid.Start method is invoked.
     
  2. Neil2TheKing

    Neil2TheKing

    Joined:
    Sep 14, 2017
    Posts:
    15
    Want a break from making games? Want to play one instead? Check this out: https://storytime.itch.io/anthology

    Made this game over the past two years. You and a friend choose 9 characters and play to see who ends up with the most characters. There's also a story mode to help players experiment with the game in a safe environment. I'm finalizing the roster for the full release and I'm working with artists to finalize art. All feedback is welcome. Definitely share your thoughts
     
    michal-zetkowski likes this.
  3. Sergeyshall

    Sergeyshall

    Joined:
    Sep 3, 2013
    Posts:
    4
    @michal-zetkowski Hello, Michal. I'm wondering if it is possible to implement a counter-attack unit feature without touching base TbsFramework.Units.Unit class? I saw some advice on this forum but that advice proposes to modify the base Unit class instead of overriding in custom class extended from the Base Unit. Is there an option to do that (maybe with a new ability system or in some other way without touching base TBS code)?
     
  4. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Check out how I implemented it in Ability System. Basically inherit from regular Attack Ability, and attack back after the initial attack is done.

    What might be a bit strange about it is that the ability needs to be attached to the unit that is initiating the attack. I imagine it would be more intuitive if it was just a "CounterattackAbility" attached to the defending unit. But well, it is what it is and it works :)
     

    Attached Files:

  5. Sergeyshall

    Sergeyshall

    Joined:
    Sep 3, 2013
    Posts:
    4
    Thanks for your reply, @michal-zetkowski. The solution with ability works, but I see that an Enemy player (AI) is not waiting for the finishing of the counter-attack and immediately pass the moving turn to the next unit. This produce a strange behavior:
    - enemy unit A1 is attacking unit B1
    - immediately the next enemy unit A2 moving and attacking the next unit B2
    - after this B1 is doing a counter-attack to A1
    - B2 is doing a counter-attack to A2

    Also, sometimes human units can't do a move after counter-attacks (even if I return them TotalActionPoints)

    Here is the code I used:
    Code (CSharp):
    1. public class CounterableAttackAbilityGPW : AttackAbility
    2. {
    3.     public override IEnumerator Act(CellGrid cellGrid)
    4.     {
    5.         // Base unit attack
    6.         yield return base.Act(cellGrid);
    7.  
    8.         // Counter attack if unit is not dead and able to attack
    9.         if (UnitToAttack != null && UnitToAttack.IsUnitAttackable(UnitReference, UnitToAttack.Cell))
    10.         {
    11.             // Pause for a while
    12.             yield return new WaitForSeconds(0.5f);
    13.  
    14.             UnitToAttack.AttackHandler(UnitReference);
    15.             yield return new WaitForSeconds(0.5f);
    16.  
    17.             // Counterattack should not use actions. Return action point spent on the attack in AttackHandler
    18.             // TODO: something wrong here - sometimes units can't walk after a counterattack
    19.             // Maybe because the enemy unit is not waiting for the finishing counterattack of the human unit?
    20.             UnitToAttack.ActionPoints = UnitToAttack.TotalActionPoints;
    21.         }
    22.  
    23.         yield return 0;
    24.     }
    25. }
     
  6. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Sounds similar to an issue that @Thundar had before. Check out his post, linked below. Please try the solution that Thundar proposed and let me know if that was it.

    https://forum.unity.com/threads/released-turn-based-strategy-framework.704129/page-12#post-7893607
     
    Sergeyshall likes this.
  7. Deleted User

    Deleted User

    Guest

    Hi,
    Every time I regenerate the map, the framework remove every gameobject in the scene. So I need to handle the camera and add other gameobjects. Could I keep some game object from being cleared?
     
  8. Thundar

    Thundar

    Joined:
    Nov 16, 2012
    Posts:
    6
    upload_2022-2-26_15-23-5.png

    After digging through the documentation and experimenting I've successfully managed to create the first ability and set up a template to easily make more with basic options such as warm-up, cooldown and charges. It was also surprisingly easy to get the AI to use it by creating a custom AIAction, though making the AI use abilities in a smart and strategic way is something I'll probably reserve for later down the line.

    While it was no problem to create a custom buff and apply it to a unit I am bit puzzled by the list of buffs inside Unit.cs being private. This makes it impossible to read the current buffs from outside this script, something that's necessary if you want to display information about buffs in the UI or change whether they should stack with/override existing buffs.

    upload_2022-2-26_15-23-58.png

    The only solution I've been able to think of without editing Unit.cs is creating a new list of buffs in the inherited class and override/replace any method that references the base list.
     
  9. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    @liuchunyao90 Hmm, how about copy-pasting the objects? Or you could parent all the objects that you want to save to an empty gameobject, save it as prefab and re-add it after generating the grid.

    @Thundar That's a good point. Will be fixed. BTW, would you mind sharing more screenshots of your game later on? Looks interesting already. And thanks for your feedback regarding the AI, keep it coming :)
     
  10. Thundar

    Thundar

    Joined:
    Nov 16, 2012
    Posts:
    6
    unitdetailsscreenshot.png
    Certainly would not describe it as a game yet at this stage, but here's a screenshot anyway. Decided on just making the list of buffs in Unit.cs public so the player can easily see the buffs and mouse over for more information.

    Looked into the turn resolver system and was able to create one that uses the unit's initiative value to decide the turn order. Combined with adapting the auto turn finish ability code from example 5 the turns now work as intended.

    Wanted to ask one question about the ability system. My goal is to make it possible to change the player's units' abilities when not in a battle. Do you think it would be a good approach to create prefabs out of abilities and instantiate them in an awake function?
     
  11. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Ah, I remember now, you posted a screenshot before, looks nice :)

    Take a look at SpellCastingAbility from Example5. It's an ability that acts as container for different equipable abilities. I believe you could do something similar.
     
  12. kawaiianthony

    kawaiianthony

    Joined:
    Feb 15, 2021
    Posts:
    7

    Hi, I want to build a game that is similar to Paper Mario: Origami King, where the grid is circular. I want to know if I can modify the code for the grid/cell part so that it works with the rest of the features of the framework. I haven't bought the asset yet.
     
  13. CaptainRainbow

    CaptainRainbow

    Joined:
    Nov 23, 2021
    Posts:
    2
    Hey, how can i call the OnCellClicked on my HumanPlayer.cs?
     
  14. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, interesting concept. The main challenge would be to translate it to the coordinate system that the famework uses and provide function for distance calculation. Other than that, everything else should work fine. I'll try creating a proof of concept soon, until then my answer is that it is possible, but relatively hard.

    @CaptainRainbow what exactly are you trying to do? There is no OnCellClicked method in Player class, you probably should use the new Ability system.
     
  15. kawaiianthony

    kawaiianthony

    Joined:
    Feb 15, 2021
    Posts:
    7
    upload_2022-3-17_20-26-12.png
    Thanks for your reply @michal-zetkowski . I guess I couldn't wait any longer to test out the idea so I bought the asset and tried to prototype the idea. I think the prototype calculated the grid and cell distance correctly? There are problems like wrong placement of units and the rotation of cells severely messed up, which are just my fault. Are there any more stuff that I should be aware of to modify?
     

    Attached Files:

    Last edited: Mar 17, 2022
  16. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Oh, nice! Would you mind exporting the project and sending it to me at crookedhead@outlook.com? I would be able to identify issues faster this way.
     
  17. kawaiianthony

    kawaiianthony

    Joined:
    Feb 15, 2021
    Posts:
    7
    Sure! Let me fix some of the easier to fix problems first. I will send it to you once it's ready.
     
    michal-zetkowski likes this.
  18. guicamarotto

    guicamarotto

    Joined:
    Jun 23, 2020
    Posts:
    25
    Hello, It would be great if you create a discord for us to discuss, help each other etc about creating games with TBSF. Other thing, do you think to create a new and improved framework? we will have discount in this new one right? :p
     
    Last edited: Mar 22, 2022
  19. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, actually I just recently set up a Discord server for the Framework. It is a work in progress, and not public yet. I will announce it soon, I'll post about it in this thread and add a link to the project description. Thanks for your interest :)

    Regarding the Framework future - I have lots and lots of ideas for improvements and the plan is to keep updating the Turn Based Strategy Framework (the current one - not some other, new asset). I'm personally working on some side projects based on the Framework and it never crossed my mind to stop supporting it.

    Let me know what features you would like to see in the improved framework, I'll consider adding them to TBSF :)
     
    guicamarotto likes this.
  20. guicamarotto

    guicamarotto

    Joined:
    Jun 23, 2020
    Posts:
    25
    Nice!! Continue with the great work! Hey, as you are working in some projects, how about record and make some video tutorials on how to use the framework? :D
     
  21. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    @guicamarotto These projects are commissioned, so I can't really disclose any details about them. I realise that the Framework is lacking video tutorials. Eventually I will probably make some, but this is not something I'm currently working on.
     
    guicamarotto likes this.
  22. guicamarotto

    guicamarotto

    Joined:
    Jun 23, 2020
    Posts:
    25
    oh I got it, no problem. when you have time, please do this video for us :)
     
  23. wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    Joined:
    May 17, 2021
    Posts:
    3
    I want to generate a isometric scene, but failed.
     

    Attached Files:

  24. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    65
    @michal-zetkowski Quick question for you.

    Using example 4 wizard wars, I'm wanting the units that are built to be usable in the same turn.

    I've tried several different things but seem to be missing something, consider it does use
    Initialize() and OnTurnStart() when the unit is deployed.. logically it should activate the unit, but atm you can't even select a unit until a turn has passed.
     
  25. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, show me your tile prefab please
     
  26. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, the problem is the new Turn Resolver system. Turn Resolvers dictate which units can be used in a given turn. I'm working on fixing it, but for now you need to make CellGrid.PlayableUnits list public and add the spawned unit to the list manually. That should work for now.
     
    Liberation85 likes this.
  27. Liberation85

    Liberation85

    Joined:
    Apr 16, 2019
    Posts:
    65
    Thanks that worked a treat. I just couldn't see the missing link :)
     
    michal-zetkowski likes this.
  28. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey everyone, I've got two updates today:

    1. TBSF Discord server started! On the server you can expect a more relaxed discussions and more interactions between framework users. This is my first Discord server, we'll see how it goes. The server is not meant to replace forum - this thread is not going anywhere, so those of you who prefer this form of communication, feel free to keep using it.
    2. I created a Crooked Head twitter account. I'll post mostly updates regarding the Framework, but in the future you can expect news about my other projects. I'll be happy if you wanted to follow me.
    Discord: https://discord.gg/uBJNPJHFjB
    twitter: https://twitter.com/crookedhead_
     
    guicamarotto and Liberation85 like this.
  29. wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    Joined:
    May 17, 2021
    Posts:
    3
    upload_2022-4-8_12-8-34.png
     
  30. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Sorry, I meant the scripts that are attached to the prefab. But anyway, the point is that you used RectangularHexGridGenerator - it requires a hexagon prefab, that's what the error message is saying. The prefab you provided is square. You need to use different grid generator - RectangularSquareGridGenerator.
     
  31. wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    wechat_os_Qy0zgswrC8OIkzF28RlIbMawA

    Joined:
    May 17, 2021
    Posts:
    3
    thx, Successed
     
  32. hanryong97

    hanryong97

    Joined:
    Nov 18, 2021
    Posts:
    3
    hi, Im using gridhelper which based on tutorial with your documentation. I could understand how to create grid but I still can not understand how units generate. after filling unit prefab and player number, but it still doesn't generate. when I click the cube(unit), there is an error which
    "ArgumentNullException: Value cannot be null.
    Parameter name: key"
    How can I resolve this problem
     
    Last edited: Apr 14, 2022
  33. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, could you post a screenshot?
     
  34. hanryong97

    hanryong97

    Joined:
    Nov 18, 2021
    Posts:
    3
    thank you for your reply:)
     

    Attached Files:

  35. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hmm, interesting, I can barely see it, but the error is coming from pathfinding script... As I understand, you generate the grid with grid helper and then place unit with unit painter, right? Did you change something in code or prefabs? Could you show me the full error, so just the unity console window?
     
  36. hanryong97

    hanryong97

    Joined:
    Nov 18, 2021
    Posts:
    3
    oh, It was my fault. I dragged unit prefab into unit gameobject directly. Now I knew how to use grid helper correctly. Thank you for your support.
     
    michal-zetkowski likes this.
  37. shape5hifter

    shape5hifter

    Joined:
    Dec 6, 2012
    Posts:
    3
    Hello, I'm following your Tutorial but find that, after placing units with the Grid Helper, when I run the game all my units shift one cell down. Also, they're a pale color for some reason, rather than the bright texture I applied. Any tips?

    I'm on Unity 2021.3.0f1. No errors in console.

    upload_2022-4-16_16-4-47.png

    Edit: when I comment out this line I don't get the offset at start:

    Code (CSharp):
    1. public class SampeUnit : Unit
    2. {
    3.     public Color LeadingColor;
    4.     public override void Initialize()
    5.     {
    6.         base.Initialize();
    7.         //transform.localPosition -= new Vector3(0, 0, 1);
    8.         GetComponentInChildren<Renderer>().material.color = LeadingColor;
    9.     }
    Edit: I see you commented this out in your example Tutorial code as well, missed that - sorry.
     
    Last edited: Apr 16, 2022
  38. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    No problem, is should be removed rather than commented out, my mistake.

    Regarding unit coloring - did you uncomment MarkAsFriendly function (again, this should be either removed or uncommented by me, I'll fix it)? The function is setting material color to a lighter version of unit Leading Color, that's what it seems to me is happening here.
     
  39. shape5hifter

    shape5hifter

    Joined:
    Dec 6, 2012
    Posts:
    3
    Yes, I found that as well. Thanks!
     
    michal-zetkowski likes this.
  40. Neil2TheKing

    Neil2TheKing

    Joined:
    Sep 14, 2017
    Posts:
    15
    Anyone here have experience making a level editor? Wanna let players create levels and save them
     
  41. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Not really, but I guess it's just a matter of creating a custom GridGenerator that will read the output from your editor
     
  42. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Version 2.2 has been released! Please find full release notes below, in short this update includes polishing systems introduced in the previous release, performance improvements and a few fixes.

    Also, I encourage everyone to join Discord server that was recently launched - https://discord.gg/uBJNPJHFjB

    Version 2.2
    -Improved pathfinding performance
    -Improved AI performance

    -Added InitializeAction method to AIAction
    -Added ReadGeneratorParams method to ICellGridGenerator
    -Added GetGridInfo helper method to ICellGridGenerator
    -Added KeepMainCamera flag to GridHelper to indicate if main camera should be re-generated
    -Added ShouldStartGameImmediately flag to CellGrid to indicate if the game should start immediately on scene launch
    -Added InitializeAndStart method to CellGrid to start the game manually
    -Added execution time measurement to MoveToPositionAIAction and AttackAIAction
    -Added AttackRangeHighlightAbility

    -Modified TurnResolver to allow updating playable units mid-turn

    -Fixed IsCellMovableTo usage in GetGraphEdges
    -Fixed CellGrid.AddUnit method to properly add unit spawned on runtime to the game
    -Fixed a bug where AI froze when there were no units on the map
    -Fixed a bug where units were not highlighted when selected
    -Fixed switching between actions in AI debug mode
    -Fixed cell dimensions in Example1 and Example 5
    -Fixed comments in SampleUnit
     
  43. Snoozed

    Snoozed

    Joined:
    Apr 17, 2020
    Posts:
    1
    Hi Michal!

    Just getting started with your tool, looking nice so far!

    I ran into an issue with tile + unit painting not working. Debugging a bit, this was because I had added my cell collider to a child GO within my Cell prefab, and in
    GetSelectedCell 
    you don't check for the Cell component in the raycast hit's parent.

    I'm not sure if I'm the only one who likes to add colliders to separate child GOs? Maybe consider checking on the parent as well, or alternatively, put a brief warning in section 4.1 in your documentation that the painting tools will not work out of the box if the collider is not attached to the top level GO in the Cell prefab? Maybe it'll save another person the time I spent debugging. :)

    Cheers
     
  44. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey, I guess it doesn't hurt to check for Cell also in parent GO. I'll add it in the next update, thanks for pointing it out :)
     
  45. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Hi!
    Can this framework work with webgl build?
     
  46. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
  47. RitsumeiWang

    RitsumeiWang

    Joined:
    Jun 7, 2021
    Posts:
    13
    Thanks for the demo scenes!
    I bought this asset for my next game development!
    Also I have some problems after quick reading the document
    1.I found buff related cs in assets but not mentioned in document, I have a big interest in buff/debuff implement. So how can I implement buff/debuff system?
    2.In document it says only one unit can take action in its turn, and I want to implement a specific position exchange ability, which means when a unit move to another unit with same player id they can exchange their posion, is that possible? any hint?
    3.If I want to build it also on mobile, can it work well with events like finger touch or should some more things need to be added to project?
     
    Last edited: Jul 1, 2022
  48. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    1. Hmm, that's correct, it's missing in the documentation. In example 1 Hero unit provide some buffs to nearby units, you can start by examining Hero unit prefab. Let me know here or on Discord if you have any more questions.

    2. Where exactly does it say that? :) What you want can be achieved with the Ability system, check it out in the documentation

    3. In geenral, it just works on mobile. You'll probably need to do some work on the controls to make it comfortable to play.
     
  49. Shakthar

    Shakthar

    Joined:
    Jul 6, 2022
    Posts:
    1
    Hi,

    I need to do just a prototype of a fight, something like the old Final Fantasy, Chrono Trigger type of games, where there is no movement except the attacks or skills.

    With this asset I can create it? Like, when is player time opens a menu with options, regular attack, skill/magic, use item?

    Thank you.
     
  50. michal-zetkowski

    michal-zetkowski

    Joined:
    Mar 11, 2015
    Posts:
    282
    Hey,

    This is possible, but the are no demo scenes in this style in the project. Feel free to join our Discord, check out what other users are creating and ask for tips :)

    https://discord.gg/uBJNPJHFjB