private static void CreateInventionAndAddToInventory(InventionData data, Sim Actor, bool isCheapToy, out GameObject invention) { Simulator.ObjectInitParameters initData = null; InventingSkill skill = Actor.SkillManager.GetSkill <InventingSkill>(SkillNames.Inventing); bool isImprovedWidget = false; if (data.InventType == InventionType.Widget) { Widget.Awesomeness standard = Widget.Awesomeness.Standard; if (skill.OppMasterInventorCompleted) { standard = Widget.Awesomeness.Masterful; } else if (skill.OppWidgetWonderCompleted) { standard = Widget.Awesomeness.Improved; } else { float chance = 0f; if (skill.SkillLevel >= InventionWorkbench.kLevelCanMakeImprovedWidget) { chance += InventionWorkbench.kChanceOfImprovedWidget; if (Actor.HasTrait(TraitNames.Eccentric)) { chance += InventionWorkbench.kChanceOfImprovedWidgetEccentric; } if (RandomUtil.RandomChance01(chance)) { standard = Widget.Awesomeness.Improved; } } } isImprovedWidget = standard == Widget.Awesomeness.Improved; initData = new WidgetInitParameters(standard, Actor.SimDescription, data.InventType, data.MedatorName); } if ((data.InventType == InventionType.Invention) || (data.InventType == InventionType.Toy)) { initData = new CraftedToyInitParameters(skill.OppMasterInventorCompleted, Actor.SimDescription, data.InventType, isCheapToy); } invention = GlobalFunctions.CreateObject(data.MedatorName, data.ProdVersion, Vector3.OutOfWorld, 0x0, Vector3.UnitZ, null, initData) as GameObject; if (invention != null) { skill.RegisterInventionMade(data); if (data.PutInFamilyInventory) { if (!Actor.Household.SharedFamilyInventory.Inventory.TryToAdd(invention)) { invention.Destroy(); invention = null; } } else if (!Inventories.TryToMove(invention, Actor)) { invention.Destroy(); invention = null; } if (invention != null) { EventTracker.SendEvent(new CreatedInventionEvent(EventTypeId.kCreatedInvention, Actor, invention, data.InventType, isImprovedWidget)); if (data.InventType == InventionType.Widget) { EventTracker.SendEvent(EventTypeId.kInventorMadeWidget, Actor); } if (invention is TimeMachine) { EventTracker.SendEvent(EventTypeId.kInventorMadeTimeMachine, Actor); } } } }
private static void CreateInventionAndAddToInventory(InventionData data, Sim Actor, bool isCheapToy, out GameObject invention) { Simulator.ObjectInitParameters initData = null; InventingSkill skill = Actor.SkillManager.GetSkill<InventingSkill>(SkillNames.Inventing); bool isImprovedWidget = false; if (data.InventType == InventionType.Widget) { Widget.Awesomeness standard = Widget.Awesomeness.Standard; if (skill.OppMasterInventorCompleted) { standard = Widget.Awesomeness.Masterful; } else if (skill.OppWidgetWonderCompleted) { standard = Widget.Awesomeness.Improved; } else { float chance = 0f; if (skill.SkillLevel >= InventionWorkbench.kLevelCanMakeImprovedWidget) { chance += InventionWorkbench.kChanceOfImprovedWidget; if (Actor.HasTrait(TraitNames.Eccentric)) { chance += InventionWorkbench.kChanceOfImprovedWidgetEccentric; } if (RandomUtil.RandomChance01(chance)) { standard = Widget.Awesomeness.Improved; } } } isImprovedWidget = standard == Widget.Awesomeness.Improved; initData = new WidgetInitParameters(standard, Actor.SimDescription, data.InventType, data.MedatorName); } if ((data.InventType == InventionType.Invention) || (data.InventType == InventionType.Toy)) { initData = new CraftedToyInitParameters(skill.OppMasterInventorCompleted, Actor.SimDescription, data.InventType, isCheapToy); } invention = GlobalFunctions.CreateObject(data.MedatorName, data.ProdVersion, Vector3.OutOfWorld, 0x0, Vector3.UnitZ, null, initData) as GameObject; if (invention != null) { skill.RegisterInventionMade(data); if (data.PutInFamilyInventory) { if (!Actor.Household.SharedFamilyInventory.Inventory.TryToAdd(invention)) { invention.Destroy(); invention = null; } } else if (!Inventories.TryToMove(invention, Actor)) { invention.Destroy(); invention = null; } if (invention != null) { EventTracker.SendEvent(new CreatedInventionEvent(EventTypeId.kCreatedInvention, Actor, invention, data.InventType, isImprovedWidget)); if (data.InventType == InventionType.Widget) { EventTracker.SendEvent(EventTypeId.kInventorMadeWidget, Actor); } if (invention is TimeMachine) { EventTracker.SendEvent(EventTypeId.kInventorMadeTimeMachine, Actor); } } } }