[SOLVED]Invalid cast exception (Neurotrainer -> Trait trainer)

Started by cuproPanda, April 24, 2016, 10:43:03 PM

Previous topic - Next topic

cuproPanda

I'm trying to make neurotrainers for traits, but I can't get past this one error. I think I may need the source for JobDriver_UseItem, then I'd be able to figure it out. Maybe someone else can spot the problem? I'm very new with working with toils and the like, so it may just be a stupid mistake I'm making.

This is the error I get,


This is the code for the BrainMod (Trait trainer), based off of the Neurotrainer source,
using System.Collections.Generic;

using RimWorld;
using Verse;
using Verse.AI;

namespace BrainMod {

  public interface IUsable {
    void UsedBy(Pawn pawn);
  }


  public class BrainMod : ThingWithComps, IUsable {
    //Config
    private Trait trait;
    private TraitDef traitDef;
    private JobDef UseBrainMod;


    //Properties
    public override string LabelBase {
      get {
        return trait.Label + " " + def.label;
      }
    }



    public override void ExposeData() {
      base.ExposeData();
      Scribe_Defs.LookDef(ref traitDef, "traitDef");
    }

    public override void PostMake() {
      base.PostMake();

      UseBrainMod = DefDatabase<JobDef>.GetNamed("UseBrainMod");
      traitDef = DefDatabase<TraitDef>.AllDefsListForReading.RandomElement();
      trait = new Trait(traitDef);
      trait.degree = PawnGenerator.RandomTraitDegree(traitDef);
    }


    public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn myPawn) {
      foreach (var ch in base.GetFloatMenuOptions(myPawn)) {
        yield return ch;
      }

      FloatMenuOption useopt = new FloatMenuOption("UseBrainMod".Translate(trait.Label), () => {
        Job job = new Job(UseBrainMod, this);
        myPawn.drafter.TakeOrderedJob(job);
      });

      yield return useopt;
    }

    public void UsedBy(Pawn user) {

      user.story.traits.GainTrait(trait);
     

      if (PawnUtility.ShouldSendNotificationAbout(user))
        Messages.Message("BrainModUsed".Translate(user.LabelBaseShort, trait.Label), user, MessageSound.Standard);

      Destroy();
    }

    public override bool CanStackWith(Thing other) {
      if (!base.CanStackWith(other))
        return false;

      BrainMod on = other as BrainMod;
      if (on == null || on.traitDef != traitDef)
        return false;

      return true;
    }

    public override Thing SplitOff(int count) {

      BrainMod bm = (BrainMod)base.SplitOff(count);

      if (bm != null)
        bm.traitDef = traitDef;

      return bm;
    }
  }
}


... and the jobDef/thingDef,
<JobDef>
    <defName>UseBrainMod</defName>
    <driverClass>JobDriver_UseItem</driverClass>
    <reportString>Using BrainMod.</reportString>
  </JobDef>

<ThingDef ParentName="ResourceBase">
<defName>BrainMod</defName>
<thingClass>BrainMod.BrainMod</thingClass>
<label>BrainMod</label>
<description>A one-use nanotech device. The BrainMod is inserted through the orbit of the eye and releases nanomachines into the subject's brain, rewriting neural pathways and adding personality traits.</description>
<graphicData>
<texPath>Things/Item/Special/Neurotrainer</texPath>
<color>(255,224,128)</color>
<graphicClass>Graphic_Single</graphicClass>
</graphicData>
<resourceReadoutPriority>Middle</resourceReadoutPriority>
<stackLimit>1</stackLimit>
<tradeNeverStack>true</tradeNeverStack>
<useHitPoints>true</useHitPoints>
<statBases>
<MarketValue>2000</MarketValue>
<MaxHitPoints>80</MaxHitPoints>
</statBases>
<thingCategories>
<li>Items</li>
</thingCategories>
<drawGUIOverlay>false</drawGUIOverlay>
<tradeTags>
<li>Exotic</li>
</tradeTags>
</ThingDef>


Any help would be greatly appreciated, as I have tried everything I can think of, to no avail.
cuproPanda's Mods: Survivalist's Additions, Additional Joy Objects, Cupro's Drinks, Quarry, Cupro's Stones, Zen Garden, Cupro's Alloys, Preset Filtered Zones, & more!

RawCode

please provide log as text, image not acceptable.

you can find logfile at
%gamedir%\RimWorld1135Win_Data\output_log.txt

cuproPanda

Log attached

[attachment deleted by admin - too old]
cuproPanda's Mods: Survivalist's Additions, Additional Joy Objects, Cupro's Drinks, Quarry, Cupro's Stones, Zen Garden, Cupro's Alloys, Preset Filtered Zones, & more!

cuproPanda

I figured it out. The problem was from the IUsable block which was found in the source script, but not in the decompiled script. All I had to do was remove it.
cuproPanda's Mods: Survivalist's Additions, Additional Joy Objects, Cupro's Drinks, Quarry, Cupro's Stones, Zen Garden, Cupro's Alloys, Preset Filtered Zones, & more!