protected override void OnUpdate() { Entities.WithNone <BEResourceSource>().ForEach((Entity entity, ref TriggerGather trigger) => { PostUpdateCommands.AddBuffer <BEResourceSource>(entity); }); //agrega elementos al buffer y si no hay elementos. Se quita Entities.WithAll <BEResourceSource>().ForEach((Entity entity, ref TriggerGather trigger) => { var buffer = EntityManager.GetBuffer <BEResourceSource>(entity); buffer.Clear(); //necesito conocer donde hay recursos. ResourceSourceAndEntity res; if (ResourceSourceManagerSystem.TryGetResourceAtHex(trigger.targetResourcePos, out res)) { var type = res.resourceSource.resourceType; var allConectedResources = ResourceSourceManagerSystem.GetAllConectedResourcesOfType(trigger.targetResourcePos, type); foreach (var keyValue in allConectedResources) { buffer.Add((BEResourceSource)keyValue.Value); } if (EntityManager.HasComponent <GroupOnGather>(entity)) { PostUpdateCommands.SetComponent <GroupOnGather>(entity, new GroupOnGather() { GatheringResourceType = type }); } else { PostUpdateCommands.AddComponent <GroupOnGather>(entity, new GroupOnGather() { GatheringResourceType = type }); } } else { //NO HAY RECURSOS EN EL HEXAGONO. //detiene ejecucion de gather. //es decir no agrega el componente "GroupOnGather" que trigerrea el resto de componentes del systema de gather. } }); //remove the component after use Entities.ForEach((Entity entity, ref TriggerGather trigger) => { PostUpdateCommands.RemoveComponent <TriggerGather>(entity); }); }
protected override void OnUpdate() { //actualiza el buffer y ve si aun hay recursos disponibles. y luego elimina el componente que update buffer. /* * para lograrlo lo que hace es que actualiza todas las frames el buffer. */ //ANTES INCLUIA EL COMPONENTE UpdateResourceBuffer EN EL WITH ALL Entities.WithAll <BEResourceSource>().ForEach((Entity entity, ref GroupOnGather onGather) => { var buffer = EntityManager.GetBuffer <BEResourceSource>(entity); bool haveValidSource = false; Hex startinghex = new Hex(0, 0); for (int i = 0; i < buffer.Length; i++) { var resSourceData = buffer[i]; if (ResourceSourceManagerSystem.TryGetResourceAtHex(resSourceData.position, onGather.GatheringResourceType, out ResourceSourceAndEntity res)) { haveValidSource = true; startinghex = resSourceData.position; break; } } buffer.Clear(); if (haveValidSource) { var allConectedResources = ResourceSourceManagerSystem.GetAllConectedResourcesOfType(startinghex, onGather.GatheringResourceType); foreach (var keyValue in allConectedResources) { buffer.Add((BEResourceSource)keyValue.Value); } } //else //{ // PostUpdateCommands.RemoveComponent<GroupOnGather>(entity); //} PostUpdateCommands.RemoveComponent <UpdateResourceBuffer>(entity); }); }
protected override void OnUpdate() { if (Input.GetMouseButtonDown(1)) { var currentSelected = SelectionSystem.CurrentSelection; if (MapManager.ActiveMap == null) { Debug.Log("we need the active map"); return; } else if (currentSelected == null) { Debug.Log("There is not an entity selected"); return; } //early out if the entity is of other team or doesn't have team. if (!EntityManager.HasComponent <Team>(currentSelected.entity)) { return; } var selectedTeam = EntityManager.GetComponentData <Team>(currentSelected.entity).Number; if (!GameManager.PlayerTeams.Contains(selectedTeam)) { return; } var currentSelectedEntity = currentSelected.entity; if (EntityManager.HasComponent <Commandable>(currentSelectedEntity)) { //here we see the default command for the commandable var defaultCommandType = EntityManager.GetComponentData <Commandable>(currentSelectedEntity).DeafaultCommand; Hex clickHex = MapManager.ActiveMap.layout.PixelToHex(Input.mousePosition, Camera.main); switch (defaultCommandType) { case CommandType.MOVE_COMMAND: var moveCommand = new MoveCommand() { Target = currentSelectedEntity, Destination = new DestinationHex() { FinalDestination = clickHex } }; CommandStorageSystem.TryAddLocalCommand(moveCommand, World.Active); break; case CommandType.GATHER_COMMAND: //gather si es que se cliquea a un recurso, si no solo moverse. if (ResourceSourceManagerSystem.TryGetResourceAtHex(clickHex, out ResourceSourceAndEntity source)) { var gatherCommand = new GatherCommand() { Target = currentSelectedEntity, TargetPos = clickHex }; CommandStorageSystem.TryAddLocalCommand(gatherCommand, World.Active); } else { var moveCommand2 = new MoveCommand() { Target = currentSelectedEntity, Destination = new DestinationHex() { FinalDestination = clickHex } }; CommandStorageSystem.TryAddLocalCommand(moveCommand2, World.Active); } break; default: Debug.LogError("commandable doesn't have a valid default command"); break; } } else { Debug.Log("The selected entity cannot recieve commands. It isn't commandable!"); } } }
protected override void OnCreate() { inputSystem = World.GetOrCreateSystem <InputSystem>(); selectionSystem = World.GetOrCreateSystem <SelectionSystem>(); lockstepSystemGroup = World.GetOrCreateSystem <LockstepSystemGroup>(); lockstepSystemGroup.AddSystemToUpdateList(World.GetOrCreateSystem <CommandExecutionSystem>()); lockstepSystemGroup.AddSystemToUpdateList(World.GetOrCreateSystem <VolatileCommandSystem>()); lockstepSystemGroup.AddSystemToUpdateList(World.GetOrCreateSystem <CommandableSafetySystem>()); blockMovementSystem = World.GetOrCreateSystem <BlockMovementSystem>(); onGroupCheckSystem = World.GetOrCreateSystem <OnGroupCheckSystem>(); updateReachableHexListSystem = World.GetOrCreateSystem <UpdateReachableHexListSystem>(); resourceSourceManagerSystem = World.GetOrCreateSystem <ResourceSourceManagerSystem>(); triggerGatherSystem = World.GetOrCreateSystem <TriggerGatherSystem>(); dropPointSystem = World.GetOrCreateSystem <DropPointSystem>(); triggerUpdateResBufferSystem = World.GetOrCreateSystem <TriggerUpdateResBufferSystem>(); updateResourceBufferSystem = World.GetOrCreateSystem <UpdateResourceBufferSystem>(); updateOcupationMapSystem = World.GetOrCreateSystem <UpdateOcupationMapSystem>(); updateDestinationSystem = World.GetOrCreateSystem <UpdateDestinationSystem>(); sightSystem = World.GetOrCreateSystem <SightSystem>(); pathRefreshSystem = World.GetOrCreateSystem <PathRefreshSystem>(); pathFindingSystem = World.GetOrCreateSystem <PathFindingSystem>(); pathChangeIndexSystem = World.GetOrCreateSystem <PathChangeIndexSystem>(); findPosibleTargetsSystem = World.GetOrCreateSystem <FindPosibleTargetsSystem>(); findActionTargetSystem = World.GetOrCreateSystem <FindActionTargetSystem>(); findMovementTargetSystem = World.GetOrCreateSystem <FindMovementTargetSystem>(); steeringSystem = World.GetOrCreateSystem <SteeringSystem>(); translationSystem = World.GetOrCreateSystem <TranslationSystem>(); movementFinisherSystem = World.GetOrCreateSystem <MovementFinisherSystem>(); collisionSystem = World.GetOrCreateSystem <CollisionSystem>(); directionSystem = World.GetOrCreateSystem <DirectionSystem>(); startActSystem = World.GetOrCreateSystem <StartActSystem>(); removeReceivingActComponentsSystem = World.GetOrCreateSystem <RemoveReceivingActComponentsSystem>(); initReceivingActComponentsSystem = World.GetOrCreateSystem <InitReceivingActComponentsSystem>(); attackSystem = World.GetOrCreateSystem <AttackSystem>(); receiveDamageSystem = World.GetOrCreateSystem <ReceiveDamageSystem>(); gatherSystem = World.GetOrCreateSystem <GatherSystem>(); extractResourceSystem = World.GetOrCreateSystem <ExtractResourceSystem>(); updateGathererAmmountSystem = World.GetOrCreateSystem <UpdateGathererAmmountSystem>(); endActionSystem = World.GetOrCreateSystem <EndActionSystem>(); resourceSystem = World.GetOrCreateSystem <ResourceSystem>(); deathSystem = World.GetOrCreateSystem <DeathSystem>(); //simulationSystemGroup = World.GetOrCreateSystem<SimulationSystemGroup>(); //simulationSystemGroup.AddSystemToUpdateList(World.GetOrCreateSystem<PathFindingSystem>()); //simulationSystemGroup.AddSystemToUpdateList(World.GetOrCreateSystem<PathFollowSystem>()); //lateSimulationSystemGroup = World.GetOrCreateSystem<LateSimulationSystemGroup>(); //applicationSystemGroup = World.GetOrCreateSystem<ApplicationSystemGroup>(); }