private static Func <CT, CT, bool> GetComparerForCollections <CT>(Delegate comparer, IPropFactory propFactory, bool useRefEquality) { Func <CT, CT, bool> compr; if (useRefEquality || comparer == null) { return(propFactory.GetRefEqualityComparer <CT>()); } else { return(compr = (Func <CT, CT, bool>)comparer); } }
public HumanPerson Restore(ISchemeService schemeService, ISurvivalRandomSource survivalRandomSource, IPropFactory propFactory) { var storedPerson = this; var personScheme = schemeService.GetScheme <IPersonScheme>("human-person"); var inventory = new Inventory(); var evolutionData = new EvolutionData(schemeService); RestoreEvolutionData(schemeService, storedPerson, evolutionData); var defaultActScheme = schemeService.GetScheme <ITacticalActScheme>(personScheme.DefaultAct); var person = new HumanPerson(personScheme, defaultActScheme, evolutionData, survivalRandomSource, inventory); foreach (var survivalStoredItem in storedPerson.Survival) { var normalizedValueShare = RangeHelper.NormalizeShare(survivalStoredItem.Value); var stat = person.Survival.Stats.Single(x => x.Type == survivalStoredItem.Type); stat.SetShare(normalizedValueShare); } foreach (var storedProp in storedPerson.Inventory) { var propScheme = schemeService.GetScheme <IPropScheme>(storedProp.Sid); IProp prop; switch (storedProp.Type) { case PropType.Resource: prop = propFactory.CreateResource(propScheme, storedProp.Count); break; case PropType.Equipment: var equipment = propFactory.CreateEquipment(propScheme); equipment.Durable.Value = storedProp.Durable; prop = equipment; break; default: throw new Exception(); } inventory.Add(prop); } for (var i = 0; i < storedPerson.Equipments.Length; i++) { var storedEquipment = storedPerson.Equipments[i]; if (storedEquipment == null) { continue; } var equipmentScheme = schemeService.GetScheme <IPropScheme>(storedEquipment.Sid); var equipment = propFactory.CreateEquipment(equipmentScheme); equipment.Durable.Value = storedEquipment.Durable; person.EquipmentCarrier[i] = equipment; //TODO Уменьшать прочность согласно сохранённым данным } return(person); }
static public ExtStoreModel Create(PSAccessServiceCreatorInterface storeAccessCreator, IPropFactory factory) { // TODO: AAA, ExtStoreModel esm = new ExtStoreModel(PropBagTypeSafetyMode.AllPropsMustBeRegistered, storeAccessCreator, factory, null); PropExternStore <int> pi = (PropExternStore <int>)esm.AddPropNoStore <int>("PropInt", null); PropExternStore <string> ps = (PropExternStore <string>)esm.AddPropNoStore <string>("PropString", null); ExtData ed = new ExtData(); pi.Getter = (x) => ed.PropIntStandard; pi.Setter = (x, v) => ed.PropIntStandard = v; ps.Getter = (x) => ed.PropStringStandard; ps.Setter = (x, v) => ed.PropStringStandard = v; return(esm); }