// weaponDesignVM._pieceLists[pieceType] would be cleaner but it's private private CraftPartVM GetCraftPartVM(WeaponDesignVM weaponDesignVM, CraftingPiece.PieceTypes pieceType, string pieceId) { MBBindingList <CraftPartVM> partList = null; switch (pieceType) { case CraftingPiece.PieceTypes.Blade: partList = weaponDesignVM.BladePartList; break; case CraftingPiece.PieceTypes.Guard: partList = weaponDesignVM.GuardPartList; break; case CraftingPiece.PieceTypes.Handle: partList = weaponDesignVM.HandlePartList; break; case CraftingPiece.PieceTypes.Pommel: partList = weaponDesignVM.PommelPartList; break; case CraftingPiece.PieceTypes.Invalid: case CraftingPiece.PieceTypes.NumberOfPieceTypes: break; } return(partList.First(p => p.CraftingPiece.CraftingPiece.StringId == pieceId)); }
private static bool Prefix(WeaponDesignVM __instance) { try //very bad code !! { var crafting = ((Crafting)Traverse.Create(__instance).Field("_crafting").GetValue()); if (RememberLastDesignFix.Designs.ContainsKey(crafting.CurrentCraftingTemplate.TemplateName.ToString())) { var designToApply = RememberLastDesignFix.Designs[crafting.CurrentCraftingTemplate.TemplateName.ToString()]; for (int i = 0; i < 4; i++) { crafting.SwitchToPiece(designToApply.UsedPieces[i]); crafting.ScaleThePiece(designToApply.UsedPieces[i].CraftingPiece.PieceType, designToApply.UsedPieces[i].ScalePercentage); } return(false); } } catch (Exception ex) { InformationManager.DisplayMessage(new InformationMessage("Exception occured when loading last design " + ex.Message)); } return(true); }