Exemplo n.º 1
0
        private IProp GenerateProp(IDropTableRecordSubScheme record)
        {
            var scheme    = _schemeService.GetScheme <IPropScheme>(record.SchemeSid);
            var propClass = GetPropClass(scheme);

            switch (propClass)
            {
            case PropClass.Equipment:
                var equipment = _propFactory.CreateEquipment(scheme);
                return(equipment);

            case PropClass.Resource:
                var rolledCount = _randomSource.RollResourceCount(record.MinCount, record.MaxCount);
                var resource    = _propFactory.CreateResource(scheme, rolledCount);
                return(resource);

            case PropClass.Concept:

                throw new ArgumentException($"Пока концепты не поддерживаются.");

                var propScheme = _schemeService.GetScheme <IPropScheme>("record.Concept");

                return(new Concept(scheme, propScheme));

            default:
                throw new ArgumentException($"Неизвестный класс {propClass} объекта {scheme}.");
            }
        }
Exemplo n.º 2
0
        private IProp GenerateProp(IDropTableRecordSubScheme record)
        {
            try
            {
                var scheme    = _schemeService.GetScheme <IPropScheme>(record.SchemeSid);
                var propClass = GetPropClass(scheme);

                switch (propClass)
                {
                case PropClass.Equipment:
                    var equipment = _propFactory.CreateEquipment(scheme);
                    return(equipment);

                case PropClass.Resource:
                    var rolledCount = _randomSource.RollResourceCount(record.MinCount, record.MaxCount);
                    var resource    = _propFactory.CreateResource(scheme, rolledCount);
                    return(resource);

                case PropClass.Concept:

                    var propScheme = _schemeService.GetScheme <IPropScheme>("record.Concept");

                    return(new Concept(scheme, propScheme));

                default:
                    throw new ArgumentException($"Неизвестный класс {propClass} объекта {scheme}.");
                }
            }
            catch (Exception exception)
            {
                //TODO Оборачивать в доменное исключение. Создать собственный тип.
                throw new Exception($"Ошибка при обработке записи дропа {record.SchemeSid}", exception);
            }
        }
Exemplo n.º 3
0
 private void AddResource(IInventoryModule inventory, string resourceSid, int count)
 {
     try
     {
         var resourceScheme = _schemeService.GetScheme <IPropScheme>(resourceSid);
         var resource       = _propFactory.CreateResource(resourceScheme, count);
         inventory.Add(resource);
     }
     catch (KeyNotFoundException)
     {
         Debug.LogError($"Не найден объект {resourceSid}");
     }
 }
Exemplo n.º 4
0
 private void AddResource(Inventory inventory, string resourceSid, int count)
 {
     try
     {
         var resourceScheme = _schemeService.GetScheme <IPropScheme>(resourceSid);
         var resource       = _propFactory.CreateResource(resourceScheme, count);
         inventory.Add(resource);
     }
     catch (KeyNotFoundException exception)
     {
         throw new CreatePersonException($"Не найден объект {resourceSid}", exception);
     }
 }
Exemplo n.º 5
0
 private static void AddResourceToActor(Inventory inventory, string resourceSid, int count,
                                        ISchemeService schemeService, IPropFactory propFactory)
 {
     try
     {
         var resourceScheme = schemeService.GetScheme <IPropScheme>(resourceSid);
         var resource       = propFactory.CreateResource(resourceScheme, count);
         inventory.Add(resource);
     }
     catch (KeyNotFoundException)
     {
         Debug.WriteLine($"Не найден объект {resourceSid}");
     }
 }
Exemplo n.º 6
0
        protected void AddResource(IInventoryModule inventory, string resourceSid, int count)
        {
            if (inventory is null)
            {
                throw new ArgumentNullException(nameof(inventory));
            }

            try
            {
                var resourceScheme = SchemeService.GetScheme <IPropScheme>(resourceSid);
                var resource       = _propFactory.CreateResource(resourceScheme, count);
                inventory.Add(resource);
            }
            catch (KeyNotFoundException exception)
            {
                throw new CreatePersonException($"Не найден объект {resourceSid}", exception);
            }
        }
        public HumanPerson Restore(ISchemeService schemeService,
                                   ISurvivalRandomSource survivalRandomSource,
                                   IPropFactory propFactory)
        {
            if (schemeService is null)
            {
                throw new ArgumentNullException(nameof(schemeService));
            }

            if (survivalRandomSource is null)
            {
                throw new ArgumentNullException(nameof(survivalRandomSource));
            }

            if (propFactory is null)
            {
                throw new ArgumentNullException(nameof(propFactory));
            }

            var storedPerson = this;

            var personScheme = schemeService.GetScheme <IPersonScheme>("human-person");

            var inventory = new InventoryModule();

            var evolutionData = new EvolutionModule(schemeService);

            RestoreEvolutionData(schemeService, storedPerson, evolutionData);

            var person = new HumanPerson(personScheme);

            //TODO Создать необходимые модули и заполнить их.

            foreach (var survivalStoredItem in storedPerson.Survival)
            {
                var normalizedValueShare = RangeHelper.NormalizeShare(survivalStoredItem.Value);

                var stat = person.GetModule <ISurvivalModule>().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.GetModule <IEquipmentModule>()[i] = equipment;
                //TODO Уменьшать прочность согласно сохранённым данным
            }

            return(person);
        }
        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);
        }