Exemplo n.º 1
0
 /// <summary>
 /// trigger the action if active
 /// </summary>
 /// <param name="ecsInstance">pass a copy of the ecsInstance</param>
 public void fire(ECSInstance ecsInstance)
 {
     if (TriggerAction != null)
     {
         TriggerAction(ecsInstance, t_Params);
         t_HasFired = true;
     }
 }
Exemplo n.º 2
0
 public ComponentMapper(IComponent component, ECSInstance instance)
 {
     this._type_id = component.type_id;
     if (ecs_instance == null)
     {
         ComponentMapper.ecs_instance = instance;
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// creates a base window UI control
 /// </summary>
 /// <param name='owner'>
 /// Owning entity
 /// </param>
 /// <param name='caller'>
 /// Calling entity
 /// </param>
 /// <param name='ecsInstance'>
 /// ECSInstance entities are from
 /// </param>
 /// <param name='position'>
 /// Position to display the window
 /// </param>
 /// <param name='dimensions'>
 /// Dimensions of the window
 /// </param>
 /// <param name='buttonHeight'>
 /// Height of the top button
 /// </param>
 public BasicWindow(Entity owner, Entity caller, ECSInstance ecsInstance, Point position, Point dimensions, int buttonHeight)
 {
     _Owner        = owner;
     _Caller       = caller;
     _ECSInstance  = ecsInstance;
     _Position     = position;
     _Dimensions   = dimensions;
     _ButtonHeight = buttonHeight;
 }
Exemplo n.º 4
0
        public FollowPath(Entity entity, Entity target, float followDistance, ECSInstance ecsInstance)
        {
            //perform all needed setup
            f_ThisEntity     = entity;
            f_FollowDistance = followDistance;
            f_Target         = target;
            s_EcsInstance    = ecsInstance;

            tooClose      = new Conditional(isTooClose);
            targetMoved   = new Conditional(hasTargetMoved);
            pathFound     = new Conditional(hasPathBeenFound);
            reachedCell   = new Conditional(hasReachedCell);
            reachedTarget = new Conditional(hasReachedTarget);
            isNewPath     = new Conditional(hasNewPath);

            moveToCell     = new BehaviorAction(moveTowardsCell);
            calcPath       = new BehaviorAction(calculatePath);
            initPathfinder = new BehaviorAction(initializePathfinder);
            getNextCell    = new BehaviorAction(getNextPathCell);
            setPath        = new BehaviorAction(setNewPath);
            getPath        = new BehaviorAction(getCurrentPath);
            updatePosition = new BehaviorAction(updateTargetPosision);
            reset          = new BehaviorAction(resetPathfinder);
            animate        = new BehaviorAction(updateAnimation);

            Sequence pSeqA = new Sequence(initPathfinder, calcPath);



            Selector pSelA = new Selector(new Inverter(targetMoved), new Inverter(reachedTarget), new Inverter(reset), calcPath);
            //Selector pSelA = new Selector(new Inverter(targetMoved));//, new Inverter(reset), calcPath);
            Selector pSelB = new Selector(new Inverter(pathFound), getPath);
            Selector pSelC = new Selector(new Inverter(isNewPath), setPath);
            Selector pSelD = new Selector(new Inverter(reachedCell), getNextCell);
            Selector pSelE = new Selector(reachedTarget, moveToCell);
            //Sequence pSeqC = new Sequence(pSelE, reset, calcPath);


            Sequence pSeqB = new Sequence(new Inverter(tooClose), updatePosition, pSelA, pSelB, pSelC, pSelD, pSelE, animate);

            //setup root node, choose initialization phase or pathing/movement phase
            root = new IndexSelector(switchBehaviors, pSeqA, pSeqB);

            f_Behavior = new Behavior(root);

            f_PositionMapper = new ComponentMapper(new Position(), ecsInstance);
            f_VelocityMapper = new ComponentMapper(new Velocity(), ecsInstance);
            f_HeadingMapper  = new ComponentMapper(new Heading(), ecsInstance);
            f_GameMapMapper  = new ComponentMapper(new GameMap(), ecsInstance);
            f_ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance);
            f_MapDebugMapper = new ComponentMapper(new MapDebug(), ecsInstance);
            f_SpatialMapper  = new ComponentMapper(new SpatialPartition(), ecsInstance);
            f_SpriteMapper   = new ComponentMapper(new Sprite(), ecsInstance);
            f_PathMapper     = new ComponentMapper(new APath(), ecsInstance);
        }
Exemplo n.º 5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="owner"></param>
 /// <param name="caller"></param>
 /// <param name="ecsInstance"></param>
 /// <param name="buttonCount"></param>
 /// <param name="height"></param>
 /// <param name="width"></param>
 /// <param name="border"></param>
 public ButtonMenu(Entity owner, Entity caller, ECSInstance ecsInstance, int buttonCount, Point position, int height, int width, int border, int spacing)
 {
     _Owner       = owner;
     _Caller      = caller;
     _ECSInstance = ecsInstance;
     _ButtonCount = buttonCount;
     _Position    = position;
     _Height      = height;
     _Width       = width;
     _border      = border;
     _Spacing     = spacing;
 }
Exemplo n.º 6
0
        public override void Initialize()
        {
            //setup instnace and container
            ecs_instance = new ECSInstance();
            s_Container  = ScreenManager.GameContainer;

            //setup component mapper
            ComponentMapper.ecs_instance = ecs_instance;

            UIFactory.Container    = ScreenManager.GameContainer;
            UIFactory.ecs_instance = ecs_instance;

            //define and init systems
            s_UiUpdateSystem = ecs_instance.system_manager.set_system(new UIUpdateSystem(), new UserInterface());
            s_UiDrawSystem   = ecs_instance.system_manager.set_system(new UIDrawSystem(s_Container.ContentManager, s_Container.SpriteBatch), new UserInterface());
            ecs_instance.system_manager.initialize_systems();

            //setup json manager
            s_JsonManager = new JsonManager();

            base.Initialize();
        }
Exemplo n.º 7
0
        /// <summary>
        /// handles the wanderer trigger actions
        /// </summary>
        /// <param name="ecsInstance"></param>
        /// <param name="parameters"></param>
        private void OnTriggerActionCreateWanders(ECSInstance ecsInstance, Object[] parameters)
        {
            int     count      = (int)parameters[0];
            GameMap map        = (GameMap)parameters[1];
            int     skillLevel = (int)parameters[2];

            Bag <Entity> wanderers = ecs_instance.group_manager.get_group("WANDERERS");

            int size = 0;

            if (wanderers != null)
            {
                size = wanderers.count;
            }

            int create = count - size;

            if (create != 0)
            {
                createWanders(create, map, skillLevel);
            }
        }
Exemplo n.º 8
0
 public SystemManager(ECSInstance instance)
 {
     this._ecs_instance = instance;
     this._systems      = new List <EntitySystem> ();
 }
Exemplo n.º 9
0
 public ComponentManager(ECSInstance instance)
 {
     this._ecs_instance = instance;
     this.components    = new Bag <Bag <IComponent> > ();
 }
Exemplo n.º 10
0
        //private ComponentMapper h_PositionMapper;

        public HpLabelUpdater(ECSInstance ecsInstnace)
        {
            h_ECSInstance  = ecsInstnace;
            h_HealthMapper = new ComponentMapper(new Health(), h_ECSInstance);
        }
Exemplo n.º 11
0
 public FindPathAction(ECSInstance ecsInstance, Vector2 start, Vector2 finish, GameMap map)
 {
     f_EcsInstance = ecsInstance;
     f_Pathing     = new AStarPathing(start, finish, map);
 }
Exemplo n.º 12
0
 public NPCFactory(ECSInstance ecsInstance)
 {
     ecs_instance = ecsInstance;
 }
Exemplo n.º 13
0
 public EntityManager(ECSInstance instance)
 {
     this._ecs_instance = instance;
     this._entities     = new Bag <Entity> ();
     this._old_ids      = new Queue <int> ();
 }
Exemplo n.º 14
0
        public override void Initialize()
        {
            base.Initialize();

            spriteBatch = new SpriteBatch(this.ScreenManager.GraphicsDevice);

            ecsInstance = new ECSInstance();

            ComponentMapper.ecs_instance = ecsInstance;

            gameContainer = ScreenManager.GameContainer;

            //setup factories
            AnimationFactory.ecs_instance = ecsInstance;
            ActionFactory.ECSInstance     = ecsInstance;

            EntityFactory.ecs_instance  = ecsInstance;
            EntityFactory.GameContainer = gameContainer;
            UtilFactory.ecs_instance    = ecsInstance;
            UtilFactory.Container       = gameContainer;
            UIFactory.ecs_instance      = ecsInstance;
            UIFactory.Container         = gameContainer;



            //create & register systems
            //register update systems
            playerInputSystem  = ecsInstance.system_manager.set_system(new PlayerInputSystem(), new Position(), new Velocity(), new Controllable());
            cameraFocusSystem  = ecsInstance.system_manager.set_system(new CameraFocusSystem(), new CameraFocus(), new Position());
            mousePointerSystem = ecsInstance.system_manager.set_system(new MousePointerSystem(), new Position(), new MousePosition());
            behaviorSystem     = ecsInstance.system_manager.set_system(new BehaviorSystem(), new AiBehavior());
            mapCollisionSystem = ecsInstance.system_manager.set_system(new MapCollisionSystem(), new MapCollidable());
            projectileSystem   = ecsInstance.system_manager.set_system(new ProjectileSystem(), new Projectile());
            meleeSystem        = ecsInstance.system_manager.set_system(new MeleeSystem(), new MeleeAction());
            attackSystem       = ecsInstance.system_manager.set_system(new AttackSystem(), new Attack());
            damageSystem       = ecsInstance.system_manager.set_system(new DamageSystem(), new Damage());
            healthSystem       = ecsInstance.system_manager.set_system(new HealthSystem(), new Health());
            lifeSystem         = ecsInstance.system_manager.set_system(new LifeSystem(), new Life());
            victorySystem      = ecsInstance.system_manager.set_system(new AwardSystem(), new Award());
            uiUpdateSystem     = ecsInstance.system_manager.set_system(new UIUpdateSystem(), new UserInterface());
            triggerSystem      = ecsInstance.system_manager.set_system(new TriggerSystem(), new Trigger());
            actionSystem       = ecsInstance.system_manager.set_system(new ActionSystem(), new VAction());
            lightSystem        = ecsInstance.system_manager.set_system(new LightSystem(), new Light(), new Position());
            targetingSystem    = ecsInstance.system_manager.set_system(new TargetingSystem(), new Target());

            //audio systems
            audioSystem = ecsInstance.system_manager.set_system(new AudioSystem(gameContainer), new Audio());

            //register render systems
            spriteRenderSystem        = ecsInstance.system_manager.set_system(new SpriteRenderSystem(gameContainer), new Position(), new Sprite());
            animationSystem           = ecsInstance.system_manager.set_system(new AnimationSystem(gameContainer), new Character(), new Position());
            mapSystem                 = ecsInstance.system_manager.set_system(new MapSystem(gameContainer), new GameMap());
            healthBarRenderSystem     = ecsInstance.system_manager.set_system(new HealthBarRenderSystem(gameContainer), new Health());
            floatingTextDisplaySystem = ecsInstance.system_manager.set_system(new FloatingTextDisplaySystem(gameContainer), new FloatingText());
            quadTreeDebugRenderSystem = ecsInstance.system_manager.set_system(new QuadTreeDebugRenderSystem(gameContainer), new Position(), new AiBehavior());
            uiDrawSystem              = ecsInstance.system_manager.set_system(new UIDrawSystem(gameContainer.ContentManager, gameContainer.SpriteBatch), new UserInterface());



            //any additional component registration
            ecsInstance.component_manager.register_component_type(new Vaerydian.Components.Graphical.ViewPort());
            ecsInstance.component_manager.register_component_type(new MousePosition());
            ecsInstance.component_manager.register_component_type(new Heading());
            ecsInstance.component_manager.register_component_type(new MapDebug());
            ecsInstance.component_manager.register_component_type(new Transform());
            ecsInstance.component_manager.register_component_type(new SpatialPartition());
            ecsInstance.component_manager.register_component_type(new Interactable());
            ecsInstance.component_manager.register_component_type(new BoundingPolygon());
            ecsInstance.component_manager.register_component_type(new Item());
            ecsInstance.component_manager.register_component_type(new Equipment());
            //ecsInstance.component_manager.register_component_type(new Armor());
            //ecsInstance.component_manager.register_component_type(new Weapon());
            ecsInstance.component_manager.register_component_type(new Statistics());
            ecsInstance.component_manager.register_component_type(new Skills());
            ecsInstance.component_manager.register_component_type(new Knowledges());
            ecsInstance.component_manager.register_component_type(new Factions());
            ecsInstance.component_manager.register_component_type(new Award());
            ecsInstance.component_manager.register_component_type(new Information());
            ecsInstance.component_manager.register_component_type(new Aggrivation());
            ecsInstance.component_manager.register_component_type(new Audio());
            ecsInstance.component_manager.register_component_type(new APath());
            ecsInstance.component_manager.register_component_type(new Light());

            //initialize all systems
            ecsInstance.system_manager.initialize_systems();

            //create the entity factory
            npcFactory = new NPCFactory(ecsInstance);
            mapFactory = new MapFactory(ecsInstance, gameContainer);

            //setup local geometrymapper
            geometryMapper = new ComponentMapper(new GeometryMap(), ecsInstance);
        }
Exemplo n.º 15
0
 public DialogTimer(int duration, ECSInstance ecsInstance)
 {
     _Duration       = duration;
     _PositionMapper = new ComponentMapper(new Position(), ecsInstance);
     _ViewPortMapper = new ComponentMapper(new ViewPort(), ecsInstance);
 }
Exemplo n.º 16
0
 public ItemFactory(ECSInstance ecsInstance)
 {
     ecs_instance = ecsInstance;
 }
Exemplo n.º 17
0
 public ItemFactory(ECSInstance ecsInstance, GameContainer container)
 {
     ecs_instance = ecsInstance;
     i_Container  = container;
 }
Exemplo n.º 18
0
 public MapFactory(ECSInstance ecsInstance, GameContainer container)
 {
     ecs_instance = ecsInstance;
     m_Container  = container;
 }
Exemplo n.º 19
0
 public MapFactory(ECSInstance ecsInstance)
 {
     ecs_instance = ecsInstance;
 }
Exemplo n.º 20
0
        public WanderingEnemyBehavior(Entity entity, ECSInstance ecsInstance)
        {
            w_ECSInstance = ecsInstance;
            w_ThisEntity  = entity;

            w_CurrentState = STATE_INITIALIZE;


            //setup all conditionals
            tooClose        = new Conditional(tooCloseToTarget);
            tooFar          = new Conditional(tooFarFromTarget);
            detectedHostile = new Conditional(hasDetectedHostile);
            collided        = new Conditional(hasCollided);
            healthy         = new Conditional(isHealthy);
            targetDead      = new Conditional(isTargetDead);

            //setup all behavior actions
            init           = new BehaviorAction(initialize);
            setStateWander = new BehaviorAction(stateChangeWander);
            setStatePursue = new BehaviorAction(stateChangePursue);
            setStateFlee   = new BehaviorAction(stateChangeFlee);

            choseDirection    = new BehaviorAction(chooseRandomDirection);
            collideCorrection = new BehaviorAction(correctHeadingForCollision);
            move           = new BehaviorAction(moveViaHeading);
            towardsHeading = new BehaviorAction(headingTowardsTarget);
            awayHeading    = new BehaviorAction(headingAwayTarget);
            fireShot       = new BehaviorAction(fireAtTarget);
            animate        = new BehaviorAction(updateAnimation);
            playDetected   = new BehaviorAction(playDetectedSound);
            playFlee       = new BehaviorAction(playFleeSound);


            Sequence setPursue = new Sequence(playDetected, setStatePursue);
            Sequence setFlee   = new Sequence(playFlee, setStateFlee);

            //initialize sequence
            Sequence initSeq = new Sequence(init, setStateWander);

            //if not healthy, flee
            Selector healthSel = new Selector(healthy, new Inverter(setFlee));

            //if target is dead, wander
            Selector deadTargetSel = new Selector(new Inverter(targetDead), setStateWander);

            //if not collided, then chose a new direction every second
            Sequence randWalk = new Sequence(new Inverter(collided), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, choseDirection));

            //if not randomly walking, correct for a collision
            Selector walkOrCorrect = new Selector(randWalk, collideCorrection);

            //wander sequence, while no hostiles detected, walk around randomly
            Sequence wanderSeq = new Sequence(new Inverter(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, detectedHostile)), walkOrCorrect, move, animate);
            //Sequence wanderSeq = new Sequence(new Inverter(detectedHostile), walkOrCorrect, move, animate);

            //wander or change to pursue state88
            Selector wanderSel2 = new Selector(wanderSeq, new Inverter(setPursue));

            //move towards your target
            Sequence moveTowards = new Sequence(towardsHeading, move, animate);

            //move away from your target
            Sequence moveAway = new Sequence(new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate);

            //if too far from your target, move towards it
            Selector moveTooFar = new Selector(new Inverter(tooFar), moveTowards);

            //if too close to your target, move away from it
            Selector moveTooClose = new Selector(new Inverter(tooClose), moveAway);

            //if target isnt dead and you're not too far and not too close, shoot at it
            Sequence attackSeq = new Sequence(deadTargetSel, new Inverter(tooFar), new Inverter(tooClose), new BehaviorLib.Components.Decorators.Timer(elapsedTime, 500, fireShot), animate);

            //move towards or away from your target, then attemp to attack it
            Sequence pursAttackSeq1 = new Sequence(moveTooFar, moveTooClose, attackSeq);

            //as long as your healthy, pursue and attack your target
            Sequence pursAttackSeq2 = new Sequence(healthSel, pursAttackSeq1);

            //flee sequence, while unhealthy, flee
            Sequence fleeSeq = new Sequence(new Inverter(healthy), deadTargetSel, new BehaviorLib.Components.Decorators.Timer(elapsedTime, 250, awayHeading), move, animate);
            Selector fleeSel = new Selector(fleeSeq, setStateWander);

            //setup root selector
            w_Root = new IndexSelector(switchBehaviors, initSeq, wanderSel2, pursAttackSeq2, fleeSel);

            //set tree reference
            w_Behavior = new Behavior(w_Root);

            //initialize mappers
            w_PositionMapper  = new ComponentMapper(new Position(), ecsInstance);
            w_VelocityMapper  = new ComponentMapper(new Velocity(), ecsInstance);
            w_HeadingMapper   = new ComponentMapper(new Heading(), ecsInstance);
            w_ColidableMapper = new ComponentMapper(new MapCollidable(), ecsInstance);
            w_ViewPortMapper  = new ComponentMapper(new ViewPort(), ecsInstance);
            w_SpatialMapper   = new ComponentMapper(new SpatialPartition(), ecsInstance);
            //w_SpriteMapper = new ComponentMapper(new Sprite(), ecsInstance);
            w_FactionMapper   = new ComponentMapper(new Factions(), ecsInstance);
            w_HealthMapper    = new ComponentMapper(new Health(), ecsInstance);
            w_EquipmentMapper = new ComponentMapper(new Equipment(), ecsInstance);
            w_ItemMapper      = new ComponentMapper(new Item(), ecsInstance);
            w_AggroMapper     = new ComponentMapper(new Aggrivation(), ecsInstance);
        }