Example #1
0
        public void InitTest()
        {
            //BitArray bitArray = new BitArray(8);
            //bitArray.Set(0, true);
            //Console.WriteLine(bitArray.);
            //DataManager.Init();
            //Entity entity = new Entity("123");
            //EntityManager.DataChain.Add(entity);
            //Console.WriteLine(typeof(SystemAction<A1, B1>).FullName);
            //ActionManager.Init();
            EntityManager.Init();
            //for (int i = 0; i < 64; i++)
            //{
            //    EntityManager.CreateEntity(1, null);
            //}
            //LE2 e2 = new LE2();
            //DataBlock<D1> dataBlock = new DataBlock<D1>();
            //D1[] d1s = dataBlock.Datas;
            //A1 a1 = new A1();
            //C1 c1 = new C1();
            //Execute<A1, C1, D1> execute = e2.Execute;
            //execute?.Invoke(-12, ref a1, ref c1, ref d1s[2]);
            //Console.WriteLine(d1s[2].a);
            Console.WriteLine(EntityManager.CreateEntity(1, "123asd"));
            Console.WriteLine(EntityManager.CreateEntity(1, "1234"));
            Console.WriteLine(EntityManager.CreateEntity(1, "12"));
            Console.WriteLine(EntityManager.CreateEntity(0, "12345"));
            Console.WriteLine(EntityManager.CreateEntity(0, "12367"));
            EntityManager.RemoveEntity(EntityTypeManager.GetEntityTypeId(typeof(GroupB)), 0);
            EntityManager.Execute();
            Thread.Sleep(100);
            EntityManager.Execute();
            Thread.Sleep(100);
            EntityManager.Execute();
            Thread.Sleep(100);
            EntityManager.Execute();
            Thread.Sleep(100);
            Entity entity = EntityManager.GetEntity(1);

            Console.WriteLine("----------");
            Console.WriteLine(entity.GetData <D1>().a);
            Assert.AreEqual(entity.GetData <D1>().a, 1);
            Console.WriteLine(entity.Name);

            //GroupManager.GetEntityType(0).Execute(1);
            //Console.WriteLine();
            //GroupManager.GetEntityType(1).Execute(1);
            //LEAction lEAction = new LEAction();
            //Execute<A1, B1> action = lEAction.Execute;
        }
Example #2
0
        private string GetName(Entity entity, out bool hasName)
        {
            hasName = entity.HasData <ME.ECS.Name.Name>();
            var name = hasName == true?entity.GetData <ME.ECS.Name.Name>().value : "Unnamed";

            return(string.Format("{0} ({1})", name, entity));
        }
Example #3
0
    public static void giveWeaponComponent(this Entity entity, WeaponHash weaponHash, uint componentHash)
    {
        var weaponComponents = entity.GetData <List <model> >("weaponComponents");

        weaponComponents.Add(new model(weaponHash, componentHash));
        entity.SetData("weaponComponents", weaponComponents);
    }
    /// <summary>
    /// Returns true if an entity has a certain attachment
    /// </summary>
    /// <param name="entity">The entity to check</param>
    /// <param name="attachment">The attachment to look for</param>
    /// <returns>True if attachment was found, false otherwise</returns>
    public static bool HasAttachment(this Entity entity, dynamic attachment)
    {
        if (!entity.HasData("Attachments"))
        {
            return(false);
        }

        List <uint> currentAttachments = entity.GetData("Attachments");

        uint attachmentHash = 0;

        if (attachment.GetType( ) == typeof(string))
        {
            attachmentHash = NAPI.Util.GetHashKey(attachment);
        }
        else
        {
            attachmentHash = Convert.ToUInt32(attachment);
        }

        if (attachmentHash == 0)
        {
            Console.WriteLine($"Attachment hash couldn't be found for { attachment }");
            return(false);
        }

        return(currentAttachments.IndexOf(attachmentHash) != -1);
    }
Example #5
0
        private void CheckEntityRules(Entity entity, EntityModel em)
        {
            foreach (var rule in em.Rules)
            {
                if (rule is FutureOrPastDateRuleModel)
                {
                    var r = rule as FutureOrPastDateRuleModel;
                    if (!entity.Data.ContainsKey(r.Property.Name))
                    {
                        continue;
                    }

                    var value = entity.GetData <DateTime>(r.Property.Name);
                    if (r.Future)
                    {
                        if (DateTime.Now.Add(r.Offset) > value)
                        {
                            throw new Exception(string.Format("EntityRuleViolation for property '{0}'", r.Property.Name)); //TODO: EntityRuleValidationException
                        }
                    }
                    else
                    {
                        if (value.Add(r.Offset) > DateTime.Now)
                        {
                            throw new Exception(string.Format("EntityRuleViolation for property '{0}'", r.Property.Name)); //TODO: EntityRuleValidationException
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Adds/Removes an attachment for an entity
        /// </summary>
        /// <param name="entity">The entity to attach the object to</param>
        /// <param name="attachment">The attachment, should be in string or long type</param>
        /// <param name="remove">Pass true to remove the specified attachment, false otherwise.</param>
        public static void ToggleAttachment(this Entity entity, dynamic attachment, bool remove)
        {
            if (!entity.HasData("Attachments"))
            {
                entity.SetData("Attachments", new List <uint>( ));
            }

            List <uint> currentAttachments = entity.GetData <List <uint> >("Attachments");

            var attachmentHash = attachment is string?(uint)NAPI.Util.GetHashKey(attachment) : (uint)Convert.ToUInt32(attachment);

            if (attachmentHash == 0)
            {
                Console.WriteLine($"Attachment hash couldn't be found for { attachment }");
                return;
            }

            if (currentAttachments.IndexOf(attachmentHash) == -1) // if current attachment hasn't already been added
            {
                if (!remove)                                      // if it needs to be added
                {
                    currentAttachments.Add(attachmentHash);
                }
            }
            else if (remove)  // if it was found and needs to be removed
            {
                currentAttachments.Remove(attachmentHash);
            }

            // send updated data to clientside
            entity.SetSharedData("attachmentsData", JsonConvert.SerializeObject(currentAttachments));
        }
        /// <summary>
        /// Returns true if an entity has a certain attachment
        /// </summary>
        /// <param name="entity">The entity to check</param>
        /// <param name="attachment">The attachment to look for</param>
        /// <returns>True if attachment was found, false otherwise</returns>
        public static bool HasAttachment(this Entity entity, dynamic attachment)
        {
            if (!entity.HasData("Attachments"))
            {
                return(false);
            }

            List <uint> currentAttachments = entity.GetData <List <uint> >("Attachments");

            var attachmentHash = attachment is string?(uint)NAPI.Util.GetHashKey(attachment) : (uint)Convert.ToUInt32(attachment);

            if (attachmentHash == 0)
            {
                Console.WriteLine($"Attachment hash couldn't be found for { attachment }");
                return(false);
            }

            return(currentAttachments.IndexOf(attachmentHash) != -1);
        }
    /// <summary>
    /// Clears the entity's current attachments
    /// </summary>
    /// <param name="entity">The entity to clear the attachments of</param>
    public static void ClearAttachments(this Entity entity)
    {
        if (!entity.HasData("Attachments"))
        {
            return;
        }

        List <uint> currentAttachments = entity.GetData("Attachments");

        if (currentAttachments.Count > 0)
        {
            for (int i = currentAttachments.Count - 1; i >= 0; i--)
            {
                entity.AddAttachment(currentAttachments[i], true);
            }
        }

        entity.ResetSharedData("attachmentsData");
        entity.SetData("Attachments", new List <uint>( ));
    }
    /// <summary>
    /// Adds/Removes an attachment for an entity
    /// </summary>
    /// <param name="entity">The entity to attach the object to</param>
    /// <param name="attachment">The attachment, should be in string or long type</param>
    /// <param name="remove">Pass true to remove the specified attachment, false otherwise.</param>
    public static void AddAttachment(this Entity entity, dynamic attachment, bool remove)
    {
        if (!entity.HasData("Attachments"))
        {
            entity.SetData("Attachments", new List <uint>( ));
        }

        List <uint> currentAttachments = entity.GetData("Attachments");

        uint attachmentHash = 0;

        if (attachment.GetType( ) == typeof(string))
        {
            attachmentHash = NAPI.Util.GetHashKey(attachment);
        }
        else
        {
            attachmentHash = Convert.ToUInt32(attachment);
        }

        if (attachmentHash == 0)
        {
            Console.WriteLine($"Attachment hash couldn't be found for { attachment }");
            return;
        }

        if (currentAttachments.IndexOf(attachmentHash) == -1) // if current attachment hasn't already been added
        {
            if (!remove)                                      // if it needs to be added
            {
                currentAttachments.Add(attachmentHash);
            }
        }
        else if (remove)  // if it was found and needs to be removed
        {
            currentAttachments.Remove(attachmentHash);
        }

        // send updated data to clientside
        entity.SetSharedData("attachmentsData", currentAttachments.Serialize( ));
    }
Example #10
0
    public static void DrawEntityGrid(Entity entity)
    {
        if (entity == null)
            return;

        Vector3 pos1 = new Vector3();
        Vector3 pos2 = new Vector3();
        Vector3 pos3 = new Vector3();
        Vector3 pos4 = new Vector3();
        pos1.y = pos2.y = pos3.y = pos4.y = 0.5f;
        float gridSize = World.GetInstance().gridSize;
        List<GridPos> list = World.GetInstance().GetGrids(entity.obj.transform.position.x, entity.obj.transform.position.z, entity.GetData().range);
        foreach ( GridPos gridPos in list)
        {
            Vector2 pos = World.GetInstance().GetGridCenter(gridPos);
            pos1.x = pos4.x = pos.x - gridSize * 0.5f;
            pos1.z = pos3.z = pos.y - gridSize * 0.5f;
            pos2.x = pos3.x = pos.x + gridSize * 0.5f;
            pos2.z = pos4.z = pos.y + gridSize * 0.5f;
            DrawLine(pos1, pos2, Color.black);
            DrawLine(pos3, pos4, Color.black);
        }
    }
Example #11
0
 public void RemoveEntity(Entity entity)
 {
     entityList[(int)entity.GetData().type].Remove(entity);
     dirty = true;
 }
Example #12
0
 public void AddEntity(Entity entity)
 {
     entityList[(int)entity.GetData().type].Add(entity);
     dirty = true;
 }