Android Open Source - Ready-Set-Rogue Combat Processor






From Project

Back to project page Ready-Set-Rogue.

License

The source code is released under:

GNU General Public License

If you think the Android project Ready-Set-Rogue listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.warsheep.scamp.processors;
//from  www.  j  ava  2  s  . com
import com.badlogic.ashley.core.Engine;
import com.badlogic.ashley.core.Entity;
import com.badlogic.ashley.core.EntitySystem;
import com.badlogic.ashley.core.Family;
import com.badlogic.ashley.utils.ImmutableArray;
import com.badlogic.gdx.graphics.Color;
import com.warsheep.scamp.components.*;

import java.lang.reflect.Array;
import java.util.ArrayList;

public class CombatProcessor extends EntitySystem implements StateProcessor.StateListener {

    private ImmutableArray<Entity> damageableEntities;
    private CollisionProcessor collisions;
    private TileProcessor tileProcessor;

    public void addedToEngine(Engine engine) {
        damageableEntities = engine.getEntitiesFor(Family.all(DamageableComponent.class, TileComponent.class, FactionComponent.class, StateComponent.class).get());
        collisions = engine.getSystem(CollisionProcessor.class);
        tileProcessor = engine.getSystem(TileProcessor.class);
    }

    @Override
    public void attacking(Entity entity, StateComponent.Directionality direction) {
        StateComponent atkState = ECSMapper.state.get(entity);

        if (atkState.state != StateComponent.State.DEAD) {
            AttackerComponent atkComp = ECSMapper.attack.get(entity);
            TileComponent atkPos = ECSMapper.tile.get(entity);
            FactionComponent atkFaction = ECSMapper.faction.get(entity);

            int checkPosX = atkPos.x;
            int checkPosY = atkPos.y;

            for (int i = 0; i < atkComp.attackRange; i++) {
                if (collisions.checkMove(checkPosX, checkPosY, entity, direction, true)) {
                    switch (direction) {
                        case UP:
                            checkPosY++;
                            break;
                        case DOWN:
                            checkPosY--;
                            break;
                        case RIGHT:
                            checkPosX++;
                            break;
                        case LEFT:
                            checkPosX--;
                            break;
                    }

                    ArrayList<Entity> entitiesInPos = tileProcessor.queryByPosition(checkPosX, checkPosY);

                    if (entitiesInPos != null) {
                        boolean hadDamageable = false;

                        for (Entity damageable : entitiesInPos) {
                            DamageableComponent dmgComp = ECSMapper.damage.get(damageable);
                            FactionComponent dmgFaction = ECSMapper.faction.get(damageable);

                            if (dmgComp != null && dmgFaction != null) {
                                hadDamageable = true;
                                if (!shareFaction(atkFaction, dmgFaction)) {

                                    // Apply damage
                                    System.out.println("Hit! ");
                                    dmgComp.currentHealth -= atkComp.baseDamage;

                                    // Check to see if the damageable entity is dead and if it has anything to drop
                                    DropComponent dropComponent = ECSMapper.drop.get(damageable);
                                    if (dmgComp.currentHealth <= 0 && dropComponent != null) {

                                        // Check to see if exp points can be applied to attacker entity
                                        LevelComponent levelComp = ECSMapper.level.get(entity);
                                        if (levelComp != null) {
                                            levelComp.experiencePoints += dropComponent.experience;
                                            if (dropComponent.itemDrop != null) {
                                                // TODO: Drop item
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        // If the attack collided with something that was not damageable, stop the attack
                        if (!hadDamageable) {
                            break;
                        }
                    }
                }
            }

            atkState.state = StateComponent.State.IDLE;
            atkState.inProgress = false;
        }


    }

    private boolean shareFaction(FactionComponent fc1, FactionComponent fc2) {
        for (FactionComponent.Faction f : fc1.factions)
            if (fc2.factions.contains(f))
                return true;
        return false;
    }

    @Override
    public void hurt(Entity entity) {
        for (int i = 0; i < damageableEntities.size(); i++) {
            ECSMapper.visible.get(damageableEntities.get(i)).color = Color.WHITE;

        }
        VisibleComponent vc = ECSMapper.visible.get(entity); // TODO: Temporary
        vc.color = Color.RED;
    }
}




Java Source Code List

com.warsheep.scamp.AssetDepot.java
com.warsheep.scamp.IOSLauncher.java
com.warsheep.scamp.MapImporter.java
com.warsheep.scamp.PrefabFactory.java
com.warsheep.scamp.Scamp.java
com.warsheep.scamp.adt.BSPRectangle.java
com.warsheep.scamp.adt.Container.java
com.warsheep.scamp.adt.Pair.java
com.warsheep.scamp.adt.Room.java
com.warsheep.scamp.algorithms.BSPMapGenerator.java
com.warsheep.scamp.algorithms.Compositor.java
com.warsheep.scamp.android.AndroidLauncher.java
com.warsheep.scamp.client.HtmlLauncher.java
com.warsheep.scamp.components.AIControllableComponent.java
com.warsheep.scamp.components.AttackerComponent.java
com.warsheep.scamp.components.CameraComponent.java
com.warsheep.scamp.components.CollidableComponent.java
com.warsheep.scamp.components.ControllableComponent.java
com.warsheep.scamp.components.DamageableComponent.java
com.warsheep.scamp.components.DropComponent.java
com.warsheep.scamp.components.ECSMapper.java
com.warsheep.scamp.components.FactionComponent.java
com.warsheep.scamp.components.InventoryComponent.java
com.warsheep.scamp.components.LevelComponent.java
com.warsheep.scamp.components.MovementComponent.java
com.warsheep.scamp.components.StateComponent.java
com.warsheep.scamp.components.TileComponent.java
com.warsheep.scamp.components.TransformComponent.java
com.warsheep.scamp.components.VisibleComponent.java
com.warsheep.scamp.desktop.AssetPacker.java
com.warsheep.scamp.desktop.DesktopLauncher.java
com.warsheep.scamp.processors.AIProcessor.java
com.warsheep.scamp.processors.CameraProcessor.java
com.warsheep.scamp.processors.CollisionProcessor.java
com.warsheep.scamp.processors.CombatProcessor.java
com.warsheep.scamp.processors.ControlProcessor.java
com.warsheep.scamp.processors.DeathProcessor.java
com.warsheep.scamp.processors.LevelingProcessor.java
com.warsheep.scamp.processors.MovementProcessor.java
com.warsheep.scamp.processors.StateProcessor.java
com.warsheep.scamp.processors.TileProcessor.java
com.warsheep.scamp.processors.VisibilityProcessor.java
com.warsheep.scamp.screens.MainGameScreen.java
com.warsheep.scamp.screens.MainMenuScreen.java