Modding Help Loading my custom class instead of vanilla

Discussion in 'Mods' started by Hiran, Mar 13, 2017.

  1. Hiran

    Hiran Subatomic Cosmonaut

    Ling story short I want to override "checkForAction" of CrabPot. I have inherited class, overrided said method, but what now? How do i tell the game to load my BaitMasterCrabPot class instead of vanilla CrabPot?

    BTW the goal is to prevent picking up crabpots if player has Luremaster skill and holds scythe :)
     
    • Platonymous

      Platonymous Big Damn Hero

      You could either write a method to find all the existing crab pots and switch them out with new ones created from your class or you give yourself the new BaitMasterCrabPot and use them instead of the vanilla ones. Keep in mind that new classes will have to be removed before saving.
      In your case you could just switch out crabpots that are next to you and reswitch once the player moves away. Don't forget to copy over the respective field values.
       
      • Hiran

        Hiran Subatomic Cosmonaut

        I would prefer solutions that are compatible both ways. Could you point me to an example that does this "switching"?
         
        • Platonymous

          Platonymous Big Damn Hero



          List<Vector2> crabpots;

          foreach (GameLocation location in Game1.locations)
          {
          crabpots = new List<Vector2>();

          foreach (Vector2 keyV in location.objects.Keys)
          {
          if (location.objects[keyV] is CrabPot)
          {
          crabpots.Add(keyV);
          }
          }

          for (int x = 0; x < crabpots.Count; x++)
          {
          Vector2 keyV = crabpots[x];
          CrabPot oldCrapPot = (CrabPot)location.objects[keyV];
          BaitMasterCrabPot replacement = new BaitMasterCrabPot(oldCrapPot.tileLocation);

          replacement.bait = oldCrapPot.bait;
          replacement.heldObject = oldCrapPot.heldObject;
          replacement.readyForHarvest = oldCrapPot.readyForHarvest;
          replacement.tileIndexToShow = oldCrapPot.tileIndexToShow;
          replacement.directionOffset = oldCrapPot.directionOffset;
          replacement.owner = oldCrapPot.owner;
          location.objects[keyV] = replacement;

          }
          }

           

          Share This Page