public static bool TryAddLocalCommand(GatherCommand command, World world) { if (CommandUtils.CommandIsValid(command, world)) { if (volatileGatherCommands.ContainsKey(command.Target)) { //el commando es igual al que ya esta almacenado if (volatileGatherCommands[command.Target].Equals(command)) { return(false); } else { volatileGatherCommands[command.Target] = command; return(true); } } else { volatileGatherCommands.Add(command.Target, command); return(true); } } else { return(false); } }
public void _1_GatherCommand_Should_Gather_Resources() { var unit = new Probe(); var gatherCommand = new GatherCommand(unit); gatherCommand.Execute(); Assert.AreEqual(5, unit.Minerals); }
public static object[] Serialize(GatherCommand command) { int entityIndex = command.Target.Index; int entityVersion = command.Target.Version; int targetQ = command.TargetPos.q; int targetR = command.TargetPos.r; object[] data = new object[] { entityIndex, entityVersion, targetQ, targetR }; return(data); }
public static GatherCommand DeserializeGatherCommand(object[] data) { GatherCommand command = new GatherCommand() { Target = new Entity() { Index = (int)data[0], Version = (int)data[1], }, TargetPos = new Hex((int)data[2], (int)data[3]), }; return(command); }
private void ExecuteCommand(GatherCommand command) { PostUpdateCommands.AddComponent(command.Target, new TriggerGather() { targetResourcePos = command.TargetPos }); //además mueve al grupo hacia el recurso PostUpdateCommands.SetComponent(command.Target, new DestinationHex() { FinalDestination = command.TargetPos }); PostUpdateCommands.AddComponent(command.Target, new RefreshPathNow()); // }
public void _2_GatherCommand_Should_Only_Gather_Resources_If_Minerals_Equal_0() { var unit = new Probe(); var gatherCommand = new GatherCommand(unit); Assert.AreEqual(0, unit.Minerals); gatherCommand.Execute(); Assert.AreEqual(5, unit.Minerals); unit.Minerals = 6; gatherCommand.Execute(); Assert.IsTrue(unit.Minerals == 6, "you should increment only when it can execute"); }
public static bool CommandIsValid(GatherCommand command, World world = null) { if (world == null) { world = World.Active; } bool gatherCompontnentsValidation; if (world.EntityManager.HasComponent <HasGatherer>(command.Target) && world.EntityManager.HasComponent <Team>(command.Target)) { gatherCompontnentsValidation = true; } else { gatherCompontnentsValidation = false; } bool basicCommandValidation = TargetIsValid(command.Target, world); return(gatherCompontnentsValidation && basicCommandValidation); }
//event data layout: //it must be a object array. //and always the first element is the turn of execution. private void CommandCallback(EventData photonEvent) { //null check is important object[] eventData = (object[])photonEvent.CustomData; int turnToExecute = (int)eventData[0]; object[] serializedMoveCommands = (object[])eventData[1]; MoveCommand[] moveCommands; if (serializedMoveCommands != null) { moveCommands = new MoveCommand[serializedMoveCommands.Length]; for (int i = 0; i < serializedMoveCommands.Length; i++) { moveCommands[i] = CommandUtils.DeserializeMoveCommand((object[])serializedMoveCommands[i]); } } else { moveCommands = null; } object[] serializedChangeBehaviourCommand = (object[])eventData[2]; ChangeBehaviourCommand[] changeBehaviourCommands; if (serializedChangeBehaviourCommand != null) { changeBehaviourCommands = new ChangeBehaviourCommand[serializedChangeBehaviourCommand.Length]; for (int i = 0; i < changeBehaviourCommands.Length; i++) { changeBehaviourCommands[i] = CommandUtils.DeserializeChangeBehaviourCommand((object[])serializedChangeBehaviourCommand[i]); } } else { changeBehaviourCommands = null; } object[] serializedGatherCommand = (object[])eventData[3]; GatherCommand[] gatherCommands; if (serializedGatherCommand != null) { gatherCommands = new GatherCommand[serializedGatherCommand.Length]; for (int i = 0; i < gatherCommands.Length; i++) { gatherCommands[i] = CommandUtils.DeserializeGatherCommand((object[])serializedGatherCommand[i]); } } else { gatherCommands = null; } //otros commandos CommandStorageSystem.QueueNetworkedCommands(turnToExecute, moveCommands, changeBehaviourCommands, gatherCommands); CreateCommandLockstepCheck(turnToExecute); SendCommandConfirmationEvent(turnToExecute); }
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!"); } } }
static void Main(string[] args) { Console.Clear(); ConsoleKeyInfo op; do { //Limpiar la pantalla Console.WriteLine(""); Console.WriteLine("Menú - Patrón Command"); Console.WriteLine(""); Console.WriteLine(""); Console.WriteLine("Que desea realizar."); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("[A] - Mover una unidad"); Console.WriteLine("[E] - Reunir recursos"); Console.WriteLine("[Esc]Salirtnn"); Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Seleccione opcion..."); op = Console.ReadKey(true); switch (op.Key) { case ConsoleKey.A: Console.WriteLine("Ud seleccionó la opción [Mover una unidad]"); Console.Write("Presione una tecla para continuar..."); Console.ReadKey(); Console.WriteLine("Ingrese el valor de X"); var _X = Console.ReadLine(); Console.WriteLine("Ingrese el valor de Y"); var _Y = Console.ReadLine(); var unit = new Probe(); var moveCommand = new MoveCommand(unit, Convert.ToInt32(_X), Convert.ToInt32(_Y)); moveCommand.Execute(); Console.Write("Las posiciones de movimiento fueron, X : " + unit.Position.X + " y Y : " + unit.Position.Y); break; case ConsoleKey.E: Console.WriteLine("Ud seleccionó la opción [Reunir recursos]"); Console.Write("Presione una tecla para continuar..."); Console.ReadKey(); var unit_ = new Probe(); var gatherCommand = new GatherCommand(unit_); gatherCommand.Execute(); Console.Write("El valor fue de " + unit_.Minerals); break; case ConsoleKey.Escape: Console.WriteLine("Chao"); break; } } while (op.Key != ConsoleKey.Escape); Console.WriteLine("Hello World!"); }