コード例 #1
0
ファイル: SkillSystem.cs プロジェクト: klutch/Loderpit
        // Perform power swing skill
        public void performPowerSwingSkill(int entityId, PowerSwingSkill powerSwingSkill, Vector2 target)
        {
            FactionComponent factionComponent = EntityManager.getFactionComponent(entityId);
            PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId);
            ExecutePowerSwingSkill executePowerSwingSkill = 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
                executePowerSwingSkill = new ExecutePowerSwingSkill(
                    powerSwingSkill,
                    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, powerSwingSkill.range));
                break;
            }

            if (executePowerSwingSkill != null)
            {
                performingSkillsComponent.executingSkills.Add(executePowerSwingSkill);
            }
        }
コード例 #2
0
ファイル: SkillSystem.cs プロジェクト: klutch/Loderpit
        // Execute power swing
        private void executePowerSwing(int entityId, ExecutePowerSwingSkill executePowerSwingSkill)
        {
            PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId);
            PowerSwingSkill powerSwingSkill = executePowerSwingSkill.skill as PowerSwingSkill;

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

            EntityManager.removeComponent(entityId, ComponentType.PositionTarget);
            resetCooldown(entityId, SkillType.PowerSwing);
            removeExecutedSkill(entityId, executePowerSwingSkill);
        }