Esempio n. 1
0
 /// <summary>
 /// Create a new dynamic object of given type.
 /// </summary>
 /// <typeparam name="T">The type of dynamic object to return.</typeparam>
 /// <param name="entity">An instance of the class that extends DynamicObject.</param>
 /// <param name="model">The model of the object in hash format.</param>
 /// <param name="rotation">The rotation to spawn the object at(degrees).</param>
 /// <param name="dimension">The dimension to spawn the object in.</param>
 /// <param name="isDynamic">(Optional): Set object dynamic or not.</param>
 /// <param name="frozen">(Optional): Set object frozen.</param>
 /// <param name="lodDistance">(Optional): Set LOD distance.</param>
 /// <param name="lightColor">(Optional): set light color.</param>
 /// <param name="onFire">(Optional): set object on fire(DOESN'T WORK PROPERLY YET!)</param>
 /// <param name="textureVariation">(Optional): Set object texture variation.</param>
 /// <param name="visible">(Optional): Set object visibility.</param>
 /// <returns>Newly created dynamic object of given type.</returns>
 public static T CreateDynamicObject <T>(
     IDynamicObject entity, uint model, Vector3 rotation, bool?isDynamic = null, bool?frozen = null, uint?lodDistance = null,
     Rgb lightColor = null, bool?onFire = null, TextureVariation?textureVariation = null, bool?visible = null
     )
 {
     if (!(entity is T))
     {
         Console.WriteLine($"[OBJECT-STREAMER] Given object is of type { entity.GetType() } but type { typeof(T) } was expected.");
         return(default);
Esempio n. 2
0
 public void AddDynamicObject(IDynamicObject dynamicObject)
 {
     dynamicObject.ParentSimulation = this;
     if (dynamicObject.Name == string.Empty)
     {
         _name = dynamicObject.GetType().ToString() + DynamicObjects.Count.ToString() ?? "0";
     }
     DynamicObjects.Add(dynamicObject);
 }
Esempio n. 3
0
        public override void Fight(IDynamicObject other)
        {
            Type t = other.GetType();

            if (t.IsAssignableFrom(GetType()))
            {
                FightSpider(other);
            }
            else
            {
                FightDifferentObject(other);
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="SqlParameter"/> and initializes its properties.
        /// </summary>
        /// <param name="source">
        /// The source object.
        /// </param>
        /// <returns>
        /// The <see cref="SqlParameter"/>.
        /// </returns>
        public SqlParameter CreateParameter(IDynamicObject source)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            if (!(source is IEditableRoot))
                throw new ArgumentException(
                    string.Format(CultureInfo.InvariantCulture, "Editable root source expected. Actual type: {0}.", source.GetType().AssemblyQualifiedName),
                    "source");

            var crList = (IList)source.GetValueByPropertyName(_fieldName);
            var idList = crList != null ? crList.OfType<IDynamicObject>().Select(x => x.Id) : Enumerable.Empty<int>();

            return new SqlParameter(_parameterName, SqlDbType.Xml) { Value = ConvertToXml(idList) };
        }
        private static object GetFieldValue(IDynamicObject source, string fieldName)
        {
            if (source == null)
                throw new ArgumentNullException("source");

            var property = source.GetPropertyByName(fieldName);
            if (property == null)
                throw new ArgumentException(
                    string.Format(
                        CultureInfo.InvariantCulture,
                        "Could not find the property '{0}' in type '{1}'.",
                        fieldName,
                        source.GetType().AssemblyQualifiedName),
                    "fieldName");

            return source.GetValueByPropertyName(fieldName);
        }
        private IEnumerable<IDynamicObject> GetEnumerable(string rootPrefix, IDynamicObject rootObject, string propertyPath)
        {
            if (rootObject == null)
                return Enumerable.Empty<IDynamicObject>();

            var propertyNames = (propertyPath ?? string.Empty).Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
            var currentPrefix = string.IsNullOrEmpty(rootPrefix) ? string.Empty : rootPrefix + ".";
            var result = Enumerable.Repeat(rootObject, 1);
            var itemType = rootObject.GetType();

            foreach (var property in propertyNames)
            {
                var itemsRetriever = ItemsRetrieverFactory.CreateItemsRetriever(itemType, property);
                result = Enumerate(result, currentPrefix + property, itemsRetriever);
                currentPrefix = currentPrefix + property + ".";
                itemType = itemsRetriever.ItemType;
            }

            return result;
        }
        /// <summary>
        /// Removes the old action items.
        /// </summary>
        /// <param name="item">The target item.</param>
        /// <param name="oldItem">The old item.</param>
        public override void RemoveOldActionItems(IDynamicObject item, IDynamicObject oldItem)
        {
            if (item == null)
                throw new ArgumentNullException("item");

            var approval = item.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName);

            if (approval == null)
                throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Approval field \"{0}\" not found in item \"{1}\" or you don't have access. Action will not run.", ApprovalFieldName, item.GetType()), "item");

            var oldApproval = oldItem != null
                                  ? oldItem.ReadValueByPropertyName<IApprovalEdit>(ApprovalFieldName)
                                  : null;

            var readyForApproval = approval.GetApprovalState() == ApprovalStates.ReadyForApproval;
            var approvalLevelChanged = oldApproval == null || approval.CurrentLevel != oldApproval.CurrentLevel;

            Collection<int> actionIds;

            if (!readyForApproval || approvalLevelChanged)
            {
                actionIds = DataContext.GetAllActionItems(item);
            }
            else
            {
                actionIds = DataContext.GetInvalidActionItems(item);
            }

            if (actionIds.Count == 0)
                return;

            var affectedPersonIds = new HashSet<int>();

            foreach (var id in actionIds)
            {
                var action = DynamicTypeManager.GetActionItem(id);
                if (action == null || action.Id != id)
                    continue;

                var personId = action.PersonId;
                action.Delete();
                action.Save();

                if (personId.HasValue)
                {
                    affectedPersonIds.Add(personId.Value);
                }
            }

            foreach (var personId in affectedPersonIds)
            {
                CommunicationService.NotifyActionsChanged(personId);
            }
        }