• Visit Rebornbuddy
  • API starting guide - Custom Mulligan

    Discussion in 'HearthBuddy Custom Decks' started by hankerspace, Oct 6, 2014.

    Thread Status:
    Not open for further replies.
    1. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      API released

      Here is a little guide to explain how to make your custom mulligan.

      Errors

      Script compilation is done during Bot startup. Compilation errors are displayed in log window. If your custom mulligan is avaible, it will be avaible in 'custom mulligan" list. Else you deck contains errors. Check log window.

      Documentation

      Your custom mulligan MUST inheritate ICustomMulligan

      The entrypoint of a custom mulligan is
      Code:
      IEnumerator DoMulligan()
      . In this function, you must end mulligan on your own with TritonHS.EndMulligan();.

      Your custom mulligan must be placed in CustomMulligan folder.

      Only 3 functions are needed to create a custom mulligan :

      Code:
      TritonHS.EndMulligan(); // To end the mulligan and draw new cards
      TritonHS.GetMulliganCards(); // Which returns a List of HSCard. This list contains the 3 (or 4) cards available for the mulligan.
      TritonHS.ToggleMulliganCard(HSCard); // This function toggle the state of a mulligan card (replace it or not)
      Samples

      Here is the default Custom mulligan sourcecode :

      Code:
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using Triton.Common;
      using Triton.Game;
      
      namespace Triton.Bot
      {
          class DefaultMulligan : ICustomMulligan
          {
              private const int MaximumCost = 3;
              public IEnumerator DoMulligan()
              {
                  List<HSCard> cards = TritonHS.GetMulliganCards();
      
                  // Find mulligans cards where cost > MaxCost
                  foreach (HSCard c in cards.Where(c => c.Card.GetCost() > MaximumCost))
                  {
                      // Toggle this card
                      TritonHS.ToggleMulliganCard(c);
      
                      // Make sure we give the game time to actually click stuff.
                      yield return Coroutine.Sleep(1000);
                  }
      
      
                  yield return Coroutine.Sleep(2000);
                  TritonHS.EndMulligan();
              }
          }
      }
      
      Good luck everyone ;)
       
      Last edited: Oct 7, 2014
    2. SIL3N7

      SIL3N7 Active Member

      Joined:
      Jun 12, 2012
      Messages:
      1,119
      Likes Received:
      11
      Trophy Points:
      38
      Hanker Every time. You say "Good Luck Everyone" it always makes me laugh and think of this
      [video=youtube;LLuaPZWkvZ0]http://www.youtube.com/watch?v=LLuaPZWkvZ0[/video]
       
    3. picsa2

      picsa2 New Member

      Joined:
      Sep 28, 2014
      Messages:
      14
      Likes Received:
      0
      Trophy Points:
      0
      can we change only maximum cost? (sorry im retarded when it comes to coding)
       
    4. SIL3N7

      SIL3N7 Active Member

      Joined:
      Jun 12, 2012
      Messages:
      1,119
      Likes Received:
      11
      Trophy Points:
      38
      I'm the same but looking over what hanker wrote I don't think so but we wait for him or other to let us know. Because to me it's gibberish

      Even tho mana cost is a good start. And deff helps

      Mulligan should be done with card I'd. And with options to keep one or 2 of the same card if you get that. Like silverfish mulligan.
       
    5. wujun3838521

      wujun3838521 New Member

      Joined:
      Aug 12, 2014
      Messages:
      60
      Likes Received:
      0
      Trophy Points:
      0
      Sounds great!
      But how can we use this ?
       
    6. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Create a .cs file in CustomMulligans/MyMulligans/MyFirstMulligan.cs

      Insert this sourcecode inside the file :

      Code:
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using Triton.Common;
      using Triton.Game;
      using Triton.Bot;
      
      namespace MyMulligans
      {
          class MyFirstMulligan: ICustomMulligan
          {
              private const int MaximumCost = 3;
              public IEnumerator DoMulligan()
              {
                  List<HSCard> cards = TritonHS.GetMulliganCards();
      
                  // Find mulligans cards where cost > MaxCost
                  foreach (HSCard c in cards.Where(c => c.Card.GetCost() > MaximumCost))
                  {
                      // Toggle this card
                      TritonHS.ToggleMulliganCard(c);
      
                      // Make sure we give the game time to actually click stuff.
                      yield return Coroutine.Sleep(1000);
                  }
      
      
                  yield return Coroutine.Sleep(2000);
                  TritonHS.EndMulligan();
              }
          }
      }
      
      Change this value : private const int MaximumCost = 3; to replace cards with cost > MaximumCost.

      Thats a simple way to change Maximum cost.
       
      Last edited: Oct 7, 2014
    7. smypm

      smypm New Member

      Joined:
      Oct 7, 2014
      Messages:
      5
      Likes Received:
      0
      Trophy Points:
      0
      [Compiler Error] \CustomMulligans\MyMulligans\MyFirstMulligan.cs(9,29) : error CS0246: The type or namespace name 'ICustomMulligan' could not be found (are you missing a using directive or an assembly reference?)

      i get this error when i try your code in the post over me, and this when i try the one on the first post

      [Compiler Error] \CustomMulligans\MyMulligans\MyFirstMulligan.cs(17,53) : error CS1061: 'Triton.Game.HSCard' does not contain a definition for 'Card' and no extension method 'Card' accepting a first argument of type 'Triton.Game.HSCard' could be found (are you missing a using directive or an assembly reference?)
       
    8. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Try again code in last post, ive updated it.
       
    9. smypm

      smypm New Member

      Joined:
      Oct 7, 2014
      Messages:
      5
      Likes Received:
      0
      Trophy Points:
      0
      [Compiler Error] \CustomMulligans\MyMulligans\second.cs(18,53) : error CS1061: 'Triton.Game.HSCard' does not contain a definition for 'Card' and no extension method 'Card' accepting a first argument of type 'Triton.Game.HSCard' could be found (are you missing a using directive or an assembly reference?)

      now i get this with that code
       
    10. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Oh my bad, remove this line : Logging.Write("Replacing {0} in starting hand.", c.Card.GetName());
       
    11. smypm

      smypm New Member

      Joined:
      Oct 7, 2014
      Messages:
      5
      Likes Received:
      0
      Trophy Points:
      0
      nope, still the same
       
    12. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Damn, replace c.Card.GetCost() by c.Cost :D
       
    13. smypm

      smypm New Member

      Joined:
      Oct 7, 2014
      Messages:
      5
      Likes Received:
      0
      Trophy Points:
      0
      [Compiler Error] c:\Users\Smypm\Desktop\buddy\CustomMulligans\MyMulligans\second.cs(18,53) : error CS1955: Non-invocable member 'Triton.Game.HSCard.Cost' cannot be used like a method.

      well xD
       
    14. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Without brackets, just c.Cost
       
    15. smypm

      smypm New Member

      Joined:
      Oct 7, 2014
      Messages:
      5
      Likes Received:
      0
      Trophy Points:
      0
      working ty
       
    16. zada

      zada New Member

      Joined:
      Apr 7, 2013
      Messages:
      23
      Likes Received:
      0
      Trophy Points:
      0
      i'm a new guy,what‘s the meaning of custom mulligan?What effect does it have?What is the difference between custom deck and custom mulligan?
       
    17. SoulCrusher

      SoulCrusher New Member

      Joined:
      Oct 21, 2014
      Messages:
      1
      Likes Received:
      0
      Trophy Points:
      0
      Adding any folder to CustomMulligans makes HearthBuddy stop responding. Taking it out makes it function normally. Including just the .cs file leads to HearthBuddy not recognizing it. What can I do?
       
    18. hankerspace

      hankerspace DEVELOPER Buddy Core Dev

      Joined:
      Apr 4, 2014
      Messages:
      164
      Likes Received:
      3
      Trophy Points:
      0
      Yeah, the .cs file need to be in a subfolder (CustomMulligans/MyMulligans/mulligan1.cs)

      Do you have this error with CustomDecks too ?

      Try to run as admin.
       
    19. Poc

      Poc New Member

      Joined:
      Nov 4, 2014
      Messages:
      2
      Likes Received:
      0
      Trophy Points:
      0
      Edited. Previously it was a question here, but i figured it out by myself.

      So, here, mb it might help to some one.

      Idea of mulligan logic: replace any card, if it's not Undertaker (FP1_028), Leper Gnome (EX1_029), Webspinner (FP1_011), Spectral Spider (FP1_002), Mad Scientist (FP1_004).

      Code:
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using Triton.Common;
      using Triton.Game;
      
      namespace Triton.Bot
      {
          class HunterMulligan : ICustomMulligan
          {
              public IEnumerator DoMulligan()
              {
                  List<HSCard> cards = TritonHS.GetMulliganCards();
      
                  foreach (HSCard c in cards)
                  {
                      if(c.Id != "FP1_028" && c.Id != "EX1_029" && c.Id != "FP1_011" && c.Id != "FP1_002" && c.Id != "FP1_004" && c.Id != "GAME_005")
                      {
      
                         TritonHS.ToggleMulliganCard(c);
                         //Logging.Write("Replacing {0} in starting hand.", c.Id); 
      
                         // Make sure we give the game time to actually click stuff.
                         yield return Coroutine.Sleep(1000);
                      }
                  }
      
      
                  yield return Coroutine.Sleep(2000);
                  TritonHS.EndMulligan();
              }
          }
      
      }
      Also, this line:
      Code:
          class HunterMulligan : ICustomMulligan
      HunterMulligan - name of mulligan rule, you are free to change it, to distinguish them if there is many of rules.

      P.S. Can some one explain to me: is it normal, that bot trying to replace Coin (GAME_005)? Or it's some kind of game code, that gives you a coin, but hides it from visible mulligan, but bot still can see it?

      P.P.S. Is there any way to determine class of the opponent? I want to create few exception rules, based on a opponent class, but not sure how to determine it.
       
      Last edited: Nov 4, 2014
    20. Poc

      Poc New Member

      Joined:
      Nov 4, 2014
      Messages:
      2
      Likes Received:
      0
      Trophy Points:
      0
      Made one more script. I like it better, because here i'm choosing cards what i want to keep in my hand, and not the ones that i should replace (no need to create rules for high cost cards, or cards like shadowflame, shadow word: death).
      Also i found how determine what class is my hero, and what class is opponent, it helped to create few rules for specific classes.

      Here is example, with few rules of keeping cards, and hero checking. I hope somebody can find it useful.

      Code:
      using System.Collections;
      using System.Collections.Generic;
      using System.Linq;
      using Triton.Common;
      using Triton.Game;
      
      namespace Triton.Bot
      {
          class HunterAggro : ICustomMulligan
          {
              public IEnumerator DoMulligan()
              {
                  List<HSCard> cards = TritonHS.GetMulliganCards(); //list of cards on mulligan
      
                  HSCard eP = TritonHS.EnemyHero; //enemy hero info
                  HSCard oP = TritonHS.OurHero;   //our hero info
                  //Possible hero id's:
                  //HERO_01 - Warrior
                  //HERO_02 - Shaman
                  //HERO_03 - Rogue
                  //HERO_04 - Paladin
                  //HERO_05 - Hunter
                  //HERO_06 - Druid
                  //HERO_07 - Warlock
                  //HERO_08 - Mage
                  //HERO_09 - Priest
      
                  foreach (HSCard c in cards)
                  {
                      //Coin (id: GAME_005). Deal with it.
                      if(c.Id == "GAME_005") { continue; }
      
                      //Keepeing in hand cards: Undertaker (FP1_028), Leper Gnome (EX1_029), Webspinner (FP1_011), Spectral Spider (FP1_002), Mad Scientist (FP1_004)
                      if(c.Id == "FP1_028" || c.Id == "EX1_029" || c.Id == "FP1_011" || c.Id == "FP1_002" || c.Id == "FP1_004")
                      {
                         continue;
                      }
      
                      //Special rules if our hero is Hunter
                      if(oP.Id == "HERO_05")
                      {
                        //If opponent is Priest, keep Eaglehorn Bow (EX1_536)
                        if(eP.Id == "HERO_09" && c.Id == "EX1_536")
                        {
                           continue;
                        }
                      }
      
                      TritonHS.ToggleMulliganCard(c);
      
                      // Make sure we give the game time to actually click stuff.
                      yield return Coroutine.Sleep(1);
      
                  }
      
      
                  yield return Coroutine.Sleep(2);
                  TritonHS.EndMulligan();
              }
          }
      
      }
       
      Last edited: Nov 4, 2014
    Thread Status:
    Not open for further replies.

    Share This Page