示例#1
0
        // Perform power shot skill
        public void performPowerShotSkill(int entityId, PowerShotSkill powerShotSkill, Vector2 target)
        {
            FactionComponent factionComponent = EntityManager.getFactionComponent(entityId);
            PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId);
            ExecutePowerShotSkill executePowerShotSkill = null;
            List<Fixture> fixtures = SystemManager.physicsSystem.world.TestPointAll(target);

            foreach (Fixture fixture in fixtures)
            {
                int targetEntityId;
                FactionComponent targetFactionComponent;

                // Skip bodies without any userdata
                if (fixture.Body.UserData == null)
                {
                    continue;
                }

                targetEntityId = (int)fixture.Body.UserData;

                // Skip entities without a faction component
                if ((targetFactionComponent = EntityManager.getFactionComponent(targetEntityId)) == null)
                {
                    continue;
                }

                // Skip over non-attackable entities
                if (!SystemManager.combatSystem.isFactionAttackable(factionComponent.faction, targetFactionComponent.faction))
                {
                    continue;
                }

                // Create execute skill object
                executePowerShotSkill = new ExecutePowerShotSkill(
                    powerShotSkill,
                    targetEntityId,
                    () =>
                    {
                        PositionComponent positionComponent = EntityManager.getPositionComponent(entityId);
                        PositionTargetComponent positionTargetComponent = EntityManager.getPositionTargetComponent(entityId);
                        float distance = Math.Abs(positionTargetComponent.position - positionComponent.position.X);

                        return distance <= positionTargetComponent.tolerance + SKILL_RANGE_TOLERANCE;
                    });

                EntityManager.addComponent(entityId, new PositionTargetComponent(entityId, fixture.Body, powerShotSkill.range));
                break;
            }

            if (executePowerShotSkill != null)
            {
                performingSkillsComponent.executingSkills.Add(executePowerShotSkill);
            }
        }
示例#2
0
        // Execute power shot
        private void executePowerShot(int entityId, ExecutePowerShotSkill executePowerShotSkill)
        {
            PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId);
            PowerShotSkill powerShotSkill = executePowerShotSkill.skill as PowerShotSkill;

            if (EntityManager.doesEntityExist(executePowerShotSkill.defenderId))    // defender could have died already
            {
                SystemManager.combatSystem.attack(powerShotSkill, entityId, executePowerShotSkill.defenderId, powerShotSkill.calculateExtraDamage());
            }

            EntityManager.removeComponent(entityId, ComponentType.PositionTarget);
            resetCooldown(entityId, SkillType.PowerShot);
            removeExecutedSkill(entityId, executePowerShotSkill);
        }