Rain World

Rain World

SlugBase
Artificer's spear gimmic, help appreciated
i want to make a slugcat that can convert normal spears into electric spears at the cost of food pips but i dont find the way to make it work..
< >
Showing 1-3 of 3 comments
KitTheCatsune 4 Apr @ 5:23pm 
I know SlugBase isn't working at the moment, so this won't be too much use immediately, and I haven't been able to test the code myself to see if it works, but you should be able to copy and paste

On.Player.CraftingResults += CustomCraftingResults;
On.Player.GraspsCanBeCrafted += CraftCheck;
On.Player.SpitUpCraftedObject += MakeElectricSpear;

between the curly brackets of the OnEnable() method of the
SlugTemplate.csproj
file and paste these methods below that method:

private AbstractPhysicalObject.AbstractObjectType CustomCraftingResults(On.Player.orig_CraftingResults orig, Player self)
{
if (self.SlugCatClass.value == "YOUR SLUGCAT'S ID" && self.FoodInStomach > 0)
{
Creature.Grasp[] grasps = self.grasps;
for (int i = 0; i < self.grasps.Length; i++)
{
if (grasps != null && grasps is IPlayerEdible && (grasps as IPlayerEdible).Edible)
{
return null;
}
}
if (grasps[0] != null && grasps[0].grabbed is Spear && !(grasps[0].grabbed as Spear).abstractSpear.explosive && !(grasps[0].grabbed as Spear).abstractSpear.electric)
{
return AbstractPhysicalObject.AbstractObjectType.Spear;
}
if (grasps[0] == null && grasps[1] != null && grasps[1].grabbed is Spear && !(grasps[1].grabbed as Spear).abstractSpear.explosive && !(grasps[1].grabbed as Spear).abstractSpear.electric)
{
return AbstractPhysicalObject.AbstractObjectType.Spear;
}
}
return orig(self);
}
private bool CraftCheck(On.Player.orig_GraspsCanBeCrafted orig, Player self)
{
if (self.SlugCatClass.value == "YOUR SLUGCAT'S ID")
{
return self.CraftingResults() != null;
}
return orig(self);
}

private void MakeElectricSpear(On.Player.orig_SpitUpCraftedObject orig, Player self)
{
orig(self);
if (self.SlugCatClass.value == "YOUR SLUGCAT'S ID")
{
for (int j = 0; j < self.grasps.Length; j++)
{
AbstractPhysicalObject obj = self.grasps[j].grabbed.abstractPhysicalObject;
if (self.grasps[j] != null && obj.type == AbstractPhysicalObject.AbstractObjectType.Spear && !(obj as AbstractSpear).electric && !(obj as AbstractSpear).explosive)
{
self.room.PlaySound(SoundID.Zapper_Zap, self.firstChunk.pos, 0.8f, 1.5f + UnityEngine.Random.value * 1.5f);
self.ReleaseGrasp(j);
self.SubtractFood(1);
obj.realizedObject.RemoveFromRoom();
self.room.abstractRoom.RemoveEntity(obj);
AbstractSpear eSpear = new AbstractSpear(self.room.world, null, self.abstractCreature.pos, self.room.game.GetNewID(), false, true);
self.room.abstractRoom.AddEntity(eSpear);
eSpear.RealizeInRoom();
if (self.FreeHand() != -1)
{
self.SlugcatGrab(eSpear.realizedObject, self.FreeHand());
}
return;
}
}
}
}

Then, you can replace "YOUR SLUGCAT'S ID" with whatever your slugcat's ID is. I probably didn't need to hook into all three methods, to be honest, but this is how the game does it, and it keeps it from getting too clunky with long if() statements. This is almost exactly copying Artificer's ability code to make sure that it functions the way you want it to.
I OW YOU MY LIFE AND SOUL TYSM
Serau 19 May @ 2:37am 
so cool:goobert:
< >
Showing 1-3 of 3 comments
Per page: 1530 50