public override void Process(Entity e)
        {
            Sprite sprite = e.GetComponent<Sprite>();
            Animation anim = e.GetComponent<Animation>();

            if (anim.Type != AnimationType.None)
            {
                anim._Tick++;
                anim._Tick %= anim.FrameRate;
                if (anim._Tick == 0) //If time to animate.
                {
                    switch (anim.Type)
                    {
                        case AnimationType.Loop:
                            sprite.FrameIndex++;
                            break;

                        case AnimationType.ReverseLoop:
                            sprite.FrameIndex--;
                            break;

                        case AnimationType.Increment:
                            sprite.FrameIndex++;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Decrement:
                            sprite.FrameIndex--;
                            anim.Type = AnimationType.None;
                            break;

                        case AnimationType.Bounce:
                            sprite.FrameIndex += anim.FrameInc;
                            if (sprite.FrameIndex == sprite.Source.Count() - 1)
                                anim.FrameInc = -1;

                            if (sprite.FrameIndex == 0)
                                anim.FrameInc = 1;
                            break;

                        case AnimationType.Once:
                            if (sprite.FrameIndex < sprite.Source.Count() - 1)
                                sprite.FrameIndex++;
                            else
                                anim.Type = AnimationType.None;
                            break;
                    }
                    e.RemoveComponent<Sprite>(e.GetComponent<Sprite>());
                    e.AddComponent<Sprite>(sprite);
                }
            }
        }
        public override void Process(Entity entity)
        {
            var position = entity.GetComponent<Position> ().position;
            var target = entity.GetComponent<Target> ().Entity;

            if(target == null || !target.HasComponent<Position>() || target.GetComponent<UnitState>().state == UnitState.State.dead)
            {
            //				EntityWorld.DeleteEntity(entity);
                entity.RemoveComponent<Position>();
                return;
            }

            var targetPosition = target.GetComponent<Position> ().position;
            var projectile = entity.GetComponent<Projectile> ();

            if (!AIUtils.MakeStepToPosition(entity, new SlimMath.Vector2(targetPosition.X+300, targetPosition.Y+1000)))
                return;

            entity.RemoveComponent<Position>();
            switch(projectile.AttackAction)
            {
                case Attack.TargetAction.block:
                    target.AddComponent(new Block());
                    AIUtils.TriggerBlock(target);
                    break;
                case Attack.TargetAction.dodge:
                    target.AddComponent(new Dodge());
                    AIUtils.TriggerDodge(target);
                    break;
                case Attack.TargetAction.hit:
                    AIUtils.TriggerHit (target, projectile.Damage);
                    break;
                default:
                    break;
            }
        }
 public override void Process(Entity entity)
 {
     var perkNames = entity.GetComponent<PerkTemplate> ().perks;
     List<Entity> perksCollection = new List<Entity> ();
     foreach(var name in perkNames)
         perksCollection.Add(DBMagager.CreateEntityByTemplateName(EntityWorld, name));
     perksCollection = perksCollection.OrderBy (p => p.GetComponent<Perk> ().branch).ThenBy (p => p.GetComponent<Perk> ().perkLevel).ToList();
     foreach (var perkEntity in perksCollection)
     {
         var putOnCommand = EntityWorld.CreateEntity ();
         putOnCommand.AddComponent (new Command ());
         putOnCommand.AddComponent (new SetPerkCommand (entity.entityId, perkEntity.entityId));
         putOnCommand.Refresh ();
     }
     entity.RemoveComponent<PerkTemplate>();
 }
Example #4
0
 public override void Process(Entity entity)
 {
     var hit = entity.GetComponent<Hit>();
     if (AIUtils.IsDead(entity))
     {
         entity.RemoveComponent<Hit>();
         return;
     }
     hit.timer--;
     if(hit.timer <= 0)
     {
         AIUtils.SetState(entity, UnitState.State.idle);
         entity.RemoveComponent<Hit>();
     }
 }
Example #5
0
        public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = EntityExtension.RemoveComponentSuffix(componentType.Name);
            if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {
                var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);

                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (fields.Length == 0) {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        } else {
                            unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
                        }
                        if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
                            entity.RemoveComponent(index);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if (unfoldedComponents[index]) {
                        foreach (var field in fields) {
                            var value = field.GetValue(component);
                            DrawAndSetElement(field.FieldType, field.Name, value,
                                entity, index, component, field.SetValue);
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
        void drawComponent(EntityBehaviour entityBehaviour, Entity entity, int index, IComponent component) {
            var componentType = component.GetType();
            var fields = componentType.GetFields(BindingFlags.Public | BindingFlags.Instance);

            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                EditorGUILayout.BeginHorizontal();
                {
                    if (fields.Length == 0) {
                        EditorGUILayout.LabelField(componentType.RemoveComponentSuffix(), EditorStyles.boldLabel);
                    } else {
                        entityBehaviour.unfoldedComponents[index] = EditorGUILayout.Foldout(entityBehaviour.unfoldedComponents[index], componentType.RemoveComponentSuffix(), _foldoutStyle);
                    }
                    if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
                        entity.RemoveComponent(index);
                    }
                }
                EditorGUILayout.EndHorizontal();

                if (entityBehaviour.unfoldedComponents[index]) {
                    foreach (var field in fields) {
                        var value = field.GetValue(component);
                        DrawAndSetElement(field.FieldType, field.Name, value,
                            entity, index, component, newValue => field.SetValue(component, newValue));
                    }
                }
            }
            EditorGUILayout.EndVertical();
        }
 public void EnslaveMovementAndSprite(Entity master, Entity slave)
 {
     slave.RemoveComponent(ComponentFamily.Mover);
     slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<SlaveMoverComponent>());
     slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover).Attach(master);
     if (slave.HasComponent(ComponentFamily.Renderable) && master.HasComponent(ComponentFamily.Renderable))
     {
         slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).SetMaster(master);
     }
 }
        public void FreeMovementAndSprite(Entity slave)
        {
            var toRemoveSlaveMover = slave.GetComponent<SlaveMoverComponent>(ComponentFamily.Mover);
            if (toRemoveSlaveMover != null)
            {
                toRemoveSlaveMover.Detach();
            }

            if (slave.HasComponent(ComponentFamily.Renderable))
            {
                slave.GetComponent<IRenderableComponent>(ComponentFamily.Renderable).UnsetMaster();
            }
            slave.RemoveComponent(ComponentFamily.Mover);
            slave.AddComponent(ComponentFamily.Mover, EntityManager.ComponentFactory.GetComponent<BasicMoverComponent>());
            slave.GetComponent<BasicItemComponent>(ComponentFamily.Item).HandleDropped();
        }
Example #9
0
        public override void Process(Entity unit)
        {
            var target = unit.GetComponent<Target>();
            var isUnitDead = AIUtils.IsDead (unit);
            if (isUnitDead || AIUtils.IsDead(target.Entity) ||
                !AIUtils.IsTargetInRange(unit)){
                Debug.Log("Cant attack, return");
                unit.RemoveComponent<Attack>();
                if(!isUnitDead)
                    AIUtils.SetState(unit, UnitState.State.idle);
                return;
            }
            var attack = unit.GetComponent<Attack>();
            attack.timer--;
            Entity projectile = null;

            if (attack.timer == 0 && unit.HasComponent<Ranged>())
            {
                projectile = _dbManager.CreateEntityByTemplateName(entityWorld, unit.GetComponent<Ranged>().Projectile.ToString());
                projectile.AddComponent<Target>(new Target(unit.GetComponent<Target>().Entity));
                projectile.AddComponent<Position>(new Position(){position = new Vector2(unit.GetComponent<Position>().position.X, unit.GetComponent<Position>().position.Y)});
                projectile.GetComponent<Projectile>().Damage = attack.damage;
            }
            switch (attack.targetAction)
            {
                case Attack.TargetAction.hit:
                    if (unit.HasComponent<Ranged>())
                    {
                        if(projectile != null)
                            projectile.GetComponent<Projectile>().AttackAction = Attack.TargetAction.hit;
                    }
                    else if(attack.timer == 0)
                    {
                        AIUtils.TriggerHit(target.Entity, attack.damage);
                    }
                    break;
                case Attack.TargetAction.block:
                    if (unit.HasComponent<Ranged>())
                    {
                        if(projectile != null)
                            projectile.GetComponent<Projectile>().AttackAction = Attack.TargetAction.block;
                    }
                    else if (attack.timer == 8)
                    {
                        target.Entity.AddComponent(new Block());
                        AIUtils.TriggerBlock(target.Entity);
                    }
                    break;
                case Attack.TargetAction.dodge:
                    if (unit.HasComponent<Ranged>())
                    {
                        if(projectile != null)
                            projectile.GetComponent<Projectile>().AttackAction = Attack.TargetAction.dodge;
                    }
                    else if (attack.timer == 8)
                    {
                        target.Entity.AddComponent(new Dodge());
                        AIUtils.TriggerDodge(target.Entity);
                    }
                    break;
                case Attack.TargetAction.miss:
                    break;
                default:
                    break;
            }

            if (attack.timer != 0)
                return;
            unit.RemoveComponent<Attack>();
            var cd = new AttackCD(unit.GetComponent<Unit>().cooldownDuration);
            unit.AddComponent(cd);
            AIUtils.SetState(unit, UnitState.State.idle);
        }
Example #10
0
        public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = componentType.Name.RemoveComponentSuffix();
            if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {
                var memberInfos = componentType.GetPublicMemberInfos();

                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (memberInfos.Length == 0) {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        } else {
                            unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
                        }
                        if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
                            entity.RemoveComponent(index);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if (unfoldedComponents[index]) {
                        foreach (var info in memberInfos) {
                            DrawAndSetElement(info.type, info.name, info.GetValue(component),
                                entity, index, component, info.SetValue);
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
        public static void DrawComponent(bool[] unfoldedComponents, Entity entity, int index, IComponent component)
        {
            var componentType = component.GetType();

            var componentName = componentType.Name.RemoveComponentSuffix();
            if (componentName.ToLower().Contains(_componentNameSearchTerm.ToLower())) {

                var boxStyle = getColoredBoxStyle(entity.totalComponents, index);
                EntitasEditorLayout.BeginVerticalBox(boxStyle);
                {
                    var memberInfos = componentType.GetPublicMemberInfos();
                    EntitasEditorLayout.BeginHorizontal();
                    {
                        if (memberInfos.Count == 0) {
                            EditorGUILayout.LabelField(componentName, EditorStyles.boldLabel);
                        } else {
                            unfoldedComponents[index] = EditorGUILayout.Foldout(unfoldedComponents[index], componentName, _foldoutStyle);
                        }
                        if (GUILayout.Button("-", GUILayout.Width(19), GUILayout.Height(14))) {
                            entity.RemoveComponent(index);
                        }
                    }
                    EntitasEditorLayout.EndHorizontal();

                    if (unfoldedComponents[index]) {

                        var componentDrawer = getComponentDrawer(componentType);
                        if (componentDrawer != null) {
                            var newComponent = entity.CreateComponent(index, componentType);
                            component.CopyPublicMemberValues(newComponent);
                            EditorGUI.BeginChangeCheck();
                            {
                                componentDrawer.DrawComponent(newComponent);
                            }
                            var changed = EditorGUI.EndChangeCheck();
                            if (changed) {
                                entity.ReplaceComponent(index, newComponent);
                            } else {
                                entity.GetComponentPool(index).Push(newComponent);
                            }
                        } else {
                            foreach (var info in memberInfos) {
                                DrawAndSetElement(info.type, info.name, info.GetValue(component),
                                    entity, index, component, info.SetValue);
                            }
                        }
                    }
                }
                EntitasEditorLayout.EndVertical();
            }
        }
Example #12
0
 public static void CommandSuccseded(Entity command)
 {
     if (command.HasComponent<ProcessCommand>())
     {
         command.RemoveComponent<ProcessCommand>();
     }
     command.AddComponent(new CommandComplete());
     command.AddComponent(new SaveCommand());
 }
Example #13
0
        public override void Process(Entity entity)
        {
            var itemNames = entity.GetComponent<EquipmentTemplate>().equippedItems.Values;
            foreach(var name in itemNames)
            {
                Debug.Log("CreateEntityByTemplateName:" + name);
                var item = DBMagager.CreateEntityByTemplateName(EntityWorld, name);

                Debug.Log(item.entityId);

                Debug.Log(Newtonsoft.Json.JsonConvert.SerializeObject(item));
                if (item != null)
                {
                    var putOnCommand = EntityWorld.CreateEntity();
                    putOnCommand.AddComponent(new Command());
                    putOnCommand.AddComponent(new SetItemCommand(entity.entityId, item.entityId));
                    putOnCommand.Refresh();
                }
            }
            entity.RemoveComponent<EquipmentTemplate>();
        }
Example #14
0
 public override void Process(Entity entity)
 {
     var cd = entity.GetComponent<AttackCD>();
     cd.cooldown--;
     if (cd.cooldown <= 0)
     {
         entity.RemoveComponent<AttackCD>();
     }
 }
Example #15
0
 public override void Process(Entity entity)
 {
     var itemNames = entity.GetComponent<BagTemplates>().items;
     foreach(var name in itemNames)
     {
         var item = DBMagager.CreateEntityByTemplateName(EntityWorld, name);
         item.Refresh();
     }
     entity.RemoveComponent<BagTemplates>();
     EntityWorld.DeleteEntity(entity);
 }
Example #16
0
        private void AddEditorComponentsToPartEntity(Entity entity)
        {
            entity.AddComponent(new EditorComponent());

            var select = new BoundingBoxSelectorComponent() { IsEnabled = false };
            entity.AddComponent(select);

            var drawbounds = new DrawBoundingBoxComponent();
            drawbounds.IsEnabled = false;
            entity.AddComponent(drawbounds);
            select.SelectedChanged += (s, e) =>
            {
                drawbounds.IsEnabled = select.IsSelected;
                if (!select.IsSelected)
                    entity.RemoveComponent<MouseControlledTransformComponent>();
            };

            entity.AddComponent(entity.GetComponent<IShipPartComponent>().Part.Transform);
            if (entity.HasComponent<DummyPartComponent>())
            {
                entity.AddComponent(new GenericDrawableComponent((a, b, e) => {
                    var xform = e.GetComponent<Transform>();
                    b.DrawCircle(xform.Position, 9, 15, Color.Cyan);
                    b.DrawLine(xform.Position.X - 10, xform.Position.Y, xform.Position.X + 10, xform.Position.Y, Color.LightCyan);
                    b.DrawLine(xform.Position.X, xform.Position.Y - 10, xform.Position.X, xform.Position.Y + 10, Color.LightCyan);
                }));
            }
            entity.Refresh();
        }
Example #17
0
 public void ChangeGun(Entity e, GunType gun)
 {
     if (e.GetComponent<Gun>() != null)
     {
         CurrentGun.Ammunition = e.GetComponent<Gun>().Ammunition;
         e.RemoveComponent<Gun>(e.GetComponent<Gun>());
     }
     _CurrentGunType = gun;
     e.AddComponent<Gun>(CurrentGun);
 }
Example #18
0
        public override void Process(Entity entity)
        {
            if( AIUtils.GetState(entity) != UnitState.State.hit) {
                var battleField = EntityWorld.TagManager.GetEntity("BattleField");

                var map = battleField.GetComponent<UnitMap>();

                var unitPositionComp = entity.GetComponent<Position>();

                var target = entity.GetComponent<Target>().Entity;
                Vector2 targetPosition = target.GetComponent<Position>().position;
                Vector2 unitPostition = unitPositionComp.position;

                Vector2 targetHex = AIUtils.ToHex(targetPosition);
                Vector2 unitHex = AIUtils.ToHex(unitPostition);

                if(map.map.ContainsKey(unitHex) && map.map[unitHex] == entity.Id)
                    map.map.Remove(unitHex);

                Vector2 destanationHex = GetAvailableHexForTargetHex(unitHex, targetHex);
                bool hasArrived = AIUtils.MakeStepToPosition(entity, AIUtils.ToCoord(destanationHex));

                if (hasArrived)
                {
                    AIUtils.SetState(entity, UnitState.State.idle);
                    Vector2 currentHex = AIUtils.ToHex(unitPositionComp.position);
                    unitPositionComp.direction = (unitHex.X < targetHex.X)?1:-1;
                    map.map[currentHex] = entity.Id;
                    entity.RemoveComponent<MoveToTarget>();
                }
            }
        }
Example #19
0
        public override void Process(Entity e)
        {
            AI ai = e.GetComponent<AI>();

            switch (ai.Targeting)
            {
                case Targeting.Closest:
                    ai.Target = ClosestTarget(e);
                    break;

                case Targeting.Strongest:
                    ai.Target = StrongestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>();
                    break;

                case Targeting.Weakest:
                    ai.Target = WeakestEntity(world.GetBodiesInArea(e.GetComponent<ITransform>().Position, ai.SearchRadius)).GetComponent<Body>();
                    break;
            }

            if (e.Group == "Crystals")
            {
                if ((ai.Target.UserData as Entity).DeletingState != true)
                {
                    Vector2 distance = e.GetComponent<AI>().Target.Position - e.GetComponent<Body>().Position;
                    distance.Normalize();
                    e.GetComponent<Body>().LinearVelocity = distance * new Vector2(7);
                }
                else
                {
                    e.Delete();

                    //ai.Target = ClosestTarget(e);
                }
            }
            e.RemoveComponent<AI>(e.GetComponent<AI>());
            e.AddComponent<AI>(ai);
        }