// Grab a rope public void grabRope(int entityId, RopeComponent ropeComponent, Body ropeBody) { RopeGrabExclusionComponent ropeGrabExclusionComponent = EntityManager.getRopeGrabExclusionComponent(entityId); if (ropeGrabExclusionComponent == null || !ropeGrabExclusionComponent.excludedRopeComponents.Contains(ropeComponent)) { GroupComponent groupComponent = SystemManager.groupSystem.getGroupComponentContaining(entityId); CharacterComponent characterComponent = EntityManager.getCharacterComponent(entityId); int index = ropeComponent.bodies.IndexOf(ropeBody); RevoluteJoint joint = JointFactory.CreateRevoluteJoint(SystemManager.physicsSystem.world, ropeBody, characterComponent.body, Vector2.Zero, Vector2.Zero); RopeGrabComponent ropeGrabComponent = new RopeGrabComponent(entityId, ropeComponent, joint, (float)index); EntityManager.addComponent(entityId, ropeGrabComponent); if (groupComponent != null) { Formation activeFormation = groupComponent.activeFormation; float maxPosition = ropeComponent.anchorBody.Position.X + 2f * groupComponent.entities.Count; LimitedRangeFormation newFormation = new LimitedRangeFormation(groupComponent.entities, activeFormation.position, activeFormation.speed, float.MinValue, maxPosition); ropeGrabComponent.formationToRemove = newFormation; activeFormation.position = (ropeComponent.anchorBody.Position.X + maxPosition) * 0.5f; groupComponent.addFormation(newFormation); } } }
// Perform throw rope skill public void performThrowRopeSkill(int entityId, ThrowRopeSkill throwRopeSkill, Vector2 anchor) { PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId); HasProxyComponent hasProxyComponent = EntityManager.getHasProxyComponent(entityId); IsProxyComponent isProxyComponent = EntityManager.getIsProxyComponent(entityId); GroupComponent groupComponent; ExecuteThrowRopeSkill executeSkill; // Find group if (isProxyComponent != null) { groupComponent = SystemManager.groupSystem.getGroupComponentContaining(isProxyComponent.proxyForId); } else { groupComponent = SystemManager.groupSystem.getGroupComponentContaining(entityId); } // Check for has proxy component if (hasProxyComponent != null) { EntityManager.removeComponent(hasProxyComponent.proxyId, ComponentType.PositionTarget); performThrowRopeSkill(hasProxyComponent.proxyId, throwRopeSkill, anchor); return; } // Create execute skill object executeSkill = new ExecuteThrowRopeSkill( throwRopeSkill, anchor, () => { 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; }); // Check for a group if (groupComponent != null) { LimitedRangeFormation formation = new LimitedRangeFormation(groupComponent.entities, groupComponent.activeFormation.position, groupComponent.activeFormation.speed, float.MinValue, anchor.X - 4f); groupComponent.addFormation(formation); executeSkill.formationToRemove = formation; } EntityManager.addComponent(entityId, new PositionTargetComponent(entityId, anchor.X, throwRopeSkill.range)); performingSkillsComponent.executingSkills.Add(executeSkill); }
// Perform build bridge skill public void performBuildBridgeSkill(int entityId, BuildBridgeSkill buildBridgeSkill, Vector2 anchorA, Vector2 anchorB) { PerformingSkillsComponent performingSkillsComponent = EntityManager.getPerformingSkillsComponent(entityId); HasProxyComponent hasProxyComponent = EntityManager.getHasProxyComponent(entityId); IsProxyComponent isProxyComponent = EntityManager.getIsProxyComponent(entityId); ExecuteBuildBridgeSkill executeSkill; GroupComponent groupComponent = SystemManager.groupSystem.getGroupComponentContaining(entityId); PositionComponent positionComponent = EntityManager.getPositionComponent(entityId); float distanceA = Math.Abs(anchorA.X - positionComponent.position.X); float distanceB = Math.Abs(anchorB.X - positionComponent.position.X); Vector2 closestAnchor = distanceA > distanceB ? anchorB : anchorA; // Find group if (isProxyComponent != null) { groupComponent = SystemManager.groupSystem.getGroupComponentContaining(isProxyComponent.proxyForId); } else { groupComponent = SystemManager.groupSystem.getGroupComponentContaining(entityId); } // Handle proxy if (hasProxyComponent != null) { EntityManager.removeComponent(hasProxyComponent.proxyId, ComponentType.PositionTarget); performBuildBridgeSkill(hasProxyComponent.proxyId, buildBridgeSkill, anchorA, anchorB); return; } // Create execute skill object executeSkill = new ExecuteBuildBridgeSkill( buildBridgeSkill, anchorA, anchorB, () => { PositionComponent futurePositionComponent = EntityManager.getPositionComponent(entityId); PositionTargetComponent positionTargetComponent = EntityManager.getPositionTargetComponent(entityId); float distance = Math.Abs(positionTargetComponent.position - futurePositionComponent.position.X); return distance <= positionTargetComponent.tolerance + SKILL_RANGE_TOLERANCE; }); if (groupComponent != null) { LimitedRangeFormation formation = new LimitedRangeFormation(groupComponent.entities, groupComponent.activeFormation.position, groupComponent.activeFormation.speed, float.MinValue, closestAnchor.X - 2f); executeSkill.formationToRemove = formation; groupComponent.addFormation(formation); } EntityManager.addComponent(entityId, new PositionTargetComponent(entityId, closestAnchor.X, buildBridgeSkill.range)); performingSkillsComponent.executingSkills.Add(executeSkill); }