/// <summary> /// Bans foods if necessary from a Duplicant. /// </summary> /// <param name="consumer">The food consumer to update.</param> /// <returns>true if foods were banned, or false if no change was made.</returns> internal static bool ApplyBannedFoods(ConsumableConsumer consumer) { var obj = consumer.gameObject; Traits traits; bool changed = false; if (obj != null && (traits = obj.GetComponent <Traits>()) != null) { if (traits.HasTrait("ScaredyCat")) { #if DEBUG PUtil.LogDebug("Removing Pacifist foods from " + obj.name); #endif // Pacifist BanFoods(TraitTuning.MEAT_FOODS, consumer); changed = true; } else if (traits.HasTrait("CantCook")) { // Gastrophobia #if DEBUG PUtil.LogDebug("Removing Gas Range foods from " + obj.name); #endif BanFoods(TraitTuning.GASRANGE_FOODS, consumer); changed = true; } } return(changed); }
/// <summary> /// Applied after SetPermitted runs. /// </summary> internal static void Postfix(ConsumableConsumer __instance) { if (TraitReworkUtils.ApplyBannedFoods(__instance)) { __instance.consumableRulesChanged.Signal(); } }
private void CopyMinion(MinionIdentity src_id, StoredMinionIdentity dest_id) { dest_id.storedName = src_id.name; dest_id.nameStringKey = src_id.nameStringKey; dest_id.gender = src_id.gender; dest_id.genderStringKey = src_id.genderStringKey; dest_id.arrivalTime = src_id.arrivalTime; dest_id.voiceIdx = src_id.voiceIdx; dest_id.bodyData = src_id.bodyData; Traits component = src_id.GetComponent <Traits>(); dest_id.traitIDs = new List <string>(component.GetTraitIds()); dest_id.assignableProxy.Set(src_id.assignableProxy.Get()); dest_id.assignableProxy.Get().SetTarget(dest_id, dest_id.gameObject); Accessorizer component2 = src_id.GetComponent <Accessorizer>(); dest_id.accessories = component2.GetAccessories(); ConsumableConsumer component3 = src_id.GetComponent <ConsumableConsumer>(); if (component3.forbiddenTags != null) { dest_id.forbiddenTags = new List <Tag>(component3.forbiddenTags); } MinionResume component4 = src_id.GetComponent <MinionResume>(); dest_id.MasteryBySkillID = component4.MasteryBySkillID; dest_id.AptitudeBySkillGroup = component4.AptitudeBySkillGroup; dest_id.TotalExperienceGained = component4.TotalExperienceGained; dest_id.currentHat = component4.CurrentHat; dest_id.targetHat = component4.TargetHat; ChoreConsumer component5 = src_id.GetComponent <ChoreConsumer>(); dest_id.choreGroupPriorities = component5.GetChoreGroupPriorities(); AttributeLevels component6 = src_id.GetComponent <AttributeLevels>(); component6.OnSerializing(); dest_id.attributeLevels = new List <AttributeLevels.LevelSaveLoad>(component6.SaveLoadLevels); StoreModifiers(src_id, dest_id); Schedulable component7 = src_id.GetComponent <Schedulable>(); Schedule schedule = component7.GetSchedule(); if (schedule != null) { schedule.Unassign(component7); Schedulable component8 = dest_id.GetComponent <Schedulable>(); schedule.Assign(component8); } }
/// <summary> /// Bans food items from a duplicant. /// </summary> /// <param name="banned">The foods to ban.</param> /// <param name="instance">The consumer who cannot eat these items.</param> private static void BanFoods(IEnumerable <string> banned, ConsumableConsumer instance) { var set = HashSetPool <Tag, ConsumableConsumer> .Allocate(); foreach (var tag in instance.forbiddenTags) { set.Add(tag); } foreach (var bannedTag in banned) { set.Add(bannedTag); } // Create new tag list var newTags = new Tag[set.Count]; set.CopyTo(newTags, 0); set.Recycle(); instance.forbiddenTags = newTags; }
public ChoreConsumerState(ChoreConsumer consumer) { this.consumer = consumer; navigator = consumer.GetComponent <Navigator>(); prefabid = consumer.GetComponent <KPrefabID>(); ownable = consumer.GetComponent <Ownable>(); gameObject = consumer.gameObject; solidTransferArm = consumer.GetComponent <SolidTransferArm>(); hasSolidTransferArm = ((Object)solidTransferArm != (Object)null); resume = consumer.GetComponent <MinionResume>(); choreDriver = consumer.GetComponent <ChoreDriver>(); schedulable = consumer.GetComponent <Schedulable>(); traits = consumer.GetComponent <Traits>(); choreProvider = consumer.GetComponent <ChoreProvider>(); MinionIdentity component = consumer.GetComponent <MinionIdentity>(); if ((Object)component != (Object)null) { if (component.assignableProxy == null) { component.assignableProxy = MinionAssignablesProxy.InitAssignableProxy(component.assignableProxy, component); } assignables = component.GetSoleOwner(); equipment = component.GetEquipment(); } else { assignables = consumer.GetComponent <Assignables>(); equipment = consumer.GetComponent <Equipment>(); } storage = consumer.GetComponent <Storage>(); consumableConsumer = consumer.GetComponent <ConsumableConsumer>(); worker = consumer.GetComponent <Worker>(); selectable = consumer.GetComponent <KSelectable>(); if ((Object)schedulable != (Object)null) { int blockIdx = Schedule.GetBlockIdx(); scheduleBlock = schedulable.GetSchedule().GetBlock(blockIdx); } }
/// <summary> /// Applied after OnPrefabInit runs. /// </summary> internal static void Postfix(ConsumableConsumer __instance) { TraitReworkUtils.ApplyBannedFoods(__instance); }
private static void CopyMinion(StoredMinionIdentity src_id, MinionIdentity dest_id) { dest_id.SetName(src_id.storedName); dest_id.nameStringKey = src_id.nameStringKey; dest_id.gender = src_id.gender; dest_id.genderStringKey = src_id.genderStringKey; dest_id.arrivalTime = src_id.arrivalTime; dest_id.voiceIdx = src_id.voiceIdx; dest_id.bodyData = src_id.bodyData; if (src_id.traitIDs != null) { Traits component = dest_id.GetComponent <Traits>(); component.SetTraitIds(src_id.traitIDs); } if (src_id.accessories != null) { Accessorizer component2 = dest_id.GetComponent <Accessorizer>(); component2.SetAccessories(src_id.accessories); } ConsumableConsumer component3 = dest_id.GetComponent <ConsumableConsumer>(); if (src_id.forbiddenTags != null) { component3.forbiddenTags = src_id.forbiddenTags.ToArray(); } if (src_id.MasteryBySkillID != null) { MinionResume component4 = dest_id.GetComponent <MinionResume>(); component4.RestoreResume(src_id.MasteryBySkillID, src_id.AptitudeBySkillGroup, src_id.TotalExperienceGained); component4.SetHats(src_id.currentHat, src_id.targetHat); } if (src_id.choreGroupPriorities != null) { ChoreConsumer component5 = dest_id.GetComponent <ChoreConsumer>(); component5.SetChoreGroupPriorities(src_id.choreGroupPriorities); } AttributeLevels component6 = dest_id.GetComponent <AttributeLevels>(); if (src_id.attributeLevels != null) { component6.SaveLoadLevels = src_id.attributeLevels.ToArray(); component6.OnDeserialized(); } dest_id.GetComponent <Accessorizer>().ApplyAccessories(); dest_id.assignableProxy = new Ref <MinionAssignablesProxy>(); dest_id.assignableProxy.Set(src_id.assignableProxy.Get()); dest_id.assignableProxy.Get().SetTarget(dest_id, dest_id.gameObject); Equipment equipment = dest_id.GetEquipment(); foreach (AssignableSlotInstance slot in equipment.Slots) { Equippable equippable = slot.assignable as Equippable; if ((UnityEngine.Object)equippable != (UnityEngine.Object)null) { equipment.Equip(equippable); } } Schedulable component7 = src_id.GetComponent <Schedulable>(); Schedule schedule = component7.GetSchedule(); if (schedule != null) { schedule.Unassign(component7); Schedulable component8 = dest_id.GetComponent <Schedulable>(); schedule.Assign(component8); } }
private ResultValues get_value_consumable_info(IAssignableIdentity minion, GameObject widget_go) { ConsumableInfoTableColumn consumableInfoTableColumn = GetWidgetColumn(widget_go) as ConsumableInfoTableColumn; IConsumableUIItem consumable_info = consumableInfoTableColumn.consumable_info; TableRow widgetRow = GetWidgetRow(widget_go); ResultValues result = ResultValues.Partial; switch (widgetRow.rowType) { case TableRow.RowType.Header: { bool flag = true; bool flag2 = true; bool flag3 = false; bool flag4 = false; foreach (KeyValuePair <TableRow, GameObject> item in consumableInfoTableColumn.widgets_by_row) { GameObject value = item.Value; if (!((UnityEngine.Object)value == (UnityEngine.Object)widget_go) && !((UnityEngine.Object)value == (UnityEngine.Object)null)) { switch (consumableInfoTableColumn.get_value_action(item.Key.GetIdentity(), value)) { case ResultValues.False: flag2 = false; if (!flag) { flag4 = true; } break; case ResultValues.Partial: flag3 = true; flag4 = true; break; case ResultValues.True: flag = false; if (!flag2) { flag4 = true; } break; } if (flag4) { break; } } } result = (flag3 ? ResultValues.Partial : (flag2 ? ResultValues.True : ((!flag) ? ResultValues.Partial : ResultValues.False))); break; } case TableRow.RowType.Default: result = ((!ConsumerManager.instance.DefaultForbiddenTagsList.Contains(consumable_info.ConsumableId.ToTag())) ? ResultValues.True : ResultValues.False); break; case TableRow.RowType.Minion: if ((UnityEngine.Object)(minion as MinionIdentity) != (UnityEngine.Object)null) { ConsumableConsumer component = ((MinionIdentity)minion).GetComponent <ConsumableConsumer>(); result = (component.IsPermitted(consumable_info.ConsumableId) ? ResultValues.True : ResultValues.False); } else { result = ResultValues.True; } break; case TableRow.RowType.StoredMinon: result = ((!((UnityEngine.Object)(minion as StoredMinionIdentity) != (UnityEngine.Object)null)) ? ResultValues.True : (((StoredMinionIdentity)minion).IsPermittedToConsume(consumable_info.ConsumableId) ? ResultValues.True : ResultValues.False)); break; } return(result); }
private void on_click_consumable_info(GameObject widget_go) { ConsumableConsumer consumableConsumer = null; IConsumableUIItem consumableUIItem = null; TableRow widgetRow = GetWidgetRow(widget_go); IAssignableIdentity identity = widgetRow.GetIdentity(); ConsumableInfoTableColumn consumableInfoTableColumn = GetWidgetColumn(widget_go) as ConsumableInfoTableColumn; switch (widgetRow.rowType) { case TableRow.RowType.Header: switch (get_value_consumable_info(null, widget_go)) { case ResultValues.True: consumableInfoTableColumn.on_set_action(widget_go, ResultValues.False); break; case ResultValues.False: case ResultValues.Partial: case ResultValues.ConditionalGroup: consumableInfoTableColumn.on_set_action(widget_go, ResultValues.True); break; } consumableInfoTableColumn.on_load_action(null, widget_go); break; case TableRow.RowType.Default: { consumableUIItem = consumableInfoTableColumn.consumable_info; bool flag3 = !ConsumerManager.instance.DefaultForbiddenTagsList.Contains(consumableUIItem.ConsumableId.ToTag()); consumableInfoTableColumn.on_set_action(widget_go, (!flag3) ? ResultValues.True : ResultValues.False); break; } case TableRow.RowType.Minion: { MinionIdentity minionIdentity = identity as MinionIdentity; if ((UnityEngine.Object)minionIdentity != (UnityEngine.Object)null) { consumableUIItem = consumableInfoTableColumn.consumable_info; consumableConsumer = minionIdentity.GetComponent <ConsumableConsumer>(); if ((UnityEngine.Object)consumableConsumer == (UnityEngine.Object)null) { Debug.LogError("Could not find minion identity / row associated with the widget"); } else { bool flag2 = consumableConsumer.IsPermitted(consumableUIItem.ConsumableId); consumableInfoTableColumn.on_set_action(widget_go, (!flag2) ? ResultValues.True : ResultValues.False); } } break; } case TableRow.RowType.StoredMinon: { StoredMinionIdentity storedMinionIdentity = identity as StoredMinionIdentity; if ((UnityEngine.Object)storedMinionIdentity != (UnityEngine.Object)null) { consumableUIItem = consumableInfoTableColumn.consumable_info; bool flag = storedMinionIdentity.IsPermittedToConsume(consumableUIItem.ConsumableId); consumableInfoTableColumn.on_set_action(widget_go, (!flag) ? ResultValues.True : ResultValues.False); } break; } } }
private void set_value_consumable_info(GameObject widget_go, ResultValues new_value) { ConsumableConsumer consumableConsumer = null; IConsumableUIItem consumableUIItem = null; TableRow widgetRow = GetWidgetRow(widget_go); if ((UnityEngine.Object)widgetRow == (UnityEngine.Object)null) { Debug.LogWarning("Row is null"); } else { ConsumableInfoTableColumn consumableInfoTableColumn = GetWidgetColumn(widget_go) as ConsumableInfoTableColumn; IAssignableIdentity identity = widgetRow.GetIdentity(); consumableUIItem = consumableInfoTableColumn.consumable_info; switch (widgetRow.rowType) { case TableRow.RowType.StoredMinon: break; case TableRow.RowType.Header: set_value_consumable_info(default_row.GetComponent <TableRow>().GetWidget(consumableInfoTableColumn), new_value); StartCoroutine(CascadeSetColumnCheckBoxes(sortable_rows, consumableInfoTableColumn, new_value, widget_go)); break; case TableRow.RowType.Default: if (new_value == ResultValues.True) { ConsumerManager.instance.DefaultForbiddenTagsList.Remove(consumableUIItem.ConsumableId.ToTag()); } else { ConsumerManager.instance.DefaultForbiddenTagsList.Add(consumableUIItem.ConsumableId.ToTag()); } consumableInfoTableColumn.on_load_action(identity, widget_go); foreach (KeyValuePair <TableRow, GameObject> item in consumableInfoTableColumn.widgets_by_row) { if (item.Key.rowType == TableRow.RowType.Header) { consumableInfoTableColumn.on_load_action(null, item.Value); break; } } break; case TableRow.RowType.Minion: { MinionIdentity minionIdentity = identity as MinionIdentity; if ((UnityEngine.Object)minionIdentity != (UnityEngine.Object)null) { consumableConsumer = minionIdentity.GetComponent <ConsumableConsumer>(); if ((UnityEngine.Object)consumableConsumer == (UnityEngine.Object)null) { Debug.LogError("Could not find minion identity / row associated with the widget"); } else { switch (new_value) { case ResultValues.True: case ResultValues.ConditionalGroup: consumableConsumer.SetPermitted(consumableUIItem.ConsumableId, true); break; case ResultValues.False: case ResultValues.Partial: consumableConsumer.SetPermitted(consumableUIItem.ConsumableId, false); break; } consumableInfoTableColumn.on_load_action(widgetRow.GetIdentity(), widget_go); foreach (KeyValuePair <TableRow, GameObject> item2 in consumableInfoTableColumn.widgets_by_row) { if (item2.Key.rowType == TableRow.RowType.Header) { consumableInfoTableColumn.on_load_action(null, item2.Value); break; } } } } break; } } } }