private static Cell[] getCeldasAccesibles(Cell celda, Mover mover) { Cell[] vecinas = celda.Map.getNeightbours(celda); List <Cell> accesibles = new List <Cell>(); foreach (Cell c in vecinas) { if (c != null) { if (mover.CanMoveTo(celda, c)) { accesibles.Add(c); } } } return(accesibles.ToArray() as Cell[]); }
public void onControllerEvent(IsoUnity.ControllerEventArgs args) { // # Avoid responding controller event when inactive if (!active) { return; } // # Normal threatment // Multiple controller events only give one launch result per tick if (toLaunch == null) { if (args.cell != null) { var cell = args.cell; if (args.cell.VirtualNeighbors.Count > 0) { cell = args.cell.VirtualNeighbors[0].Destination; } GameEvent ge = new GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("cell", cell); ge.Name = "teleport"; Game.main.enqueueEvent(ge); } // Otherwise, the controller event should contain keys pressed else { int to = -1; if (args.LEFT) { to = 0; } else if (args.UP) { to = 1; } else if (args.RIGHT) { to = 2; } else if (args.DOWN) { to = 3; } if (to > -1) { if (movement == null || !movingArrow) { if (Entity == null) { Debug.Log("Null!"); } IsoUnity.Cell destination = Entity.Position.Map.getNeightbours(Entity.Position)[to]; // Can move to checks if the entity can DIRECT move to this cells. // This should solve bug #29 IsoUnity.Entities.Mover em = this.Entity.GetComponent <IsoUnity.Entities.Mover>(); if (em != null && em.CanMoveTo(destination)) { IsoUnity.GameEvent ge = new IsoUnity.GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("cell", destination); ge.setParameter("synchronous", true); ge.Name = "move"; IsoUnity.Game.main.enqueueEvent(ge); movement = ge; } else { IsoUnity.GameEvent ge = new IsoUnity.GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("direction", fromIndex(to)); ge.setParameter("synchronous", true); ge.Name = "turn"; IsoUnity.Game.main.enqueueEvent(ge); movement = ge; } movingArrow = true; } } } } }
public void onControllerEvent(ControllerEventArgs args) { // # Avoid responding controller event when inactive if (!active) { return; } // # Normal threatment // Multiple controller events only give one launch result per tick if (toLaunch == null) { // If options received (from entities) if (args.options != null) { // If there's only one, proceed to launch if (args.options.Length == 1) { // The action is the event we have to launch, // so in order to know who's launching, we put a mark if (args.options[0].Action != null) { args.options[0].Action.setParameter("Executer", this.Entity); } actionCell = args.cell; actionEntity = args.entity; // If we've to move to perform the action if (args.options[0].HasToMove) { GameEvent ge = new GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("follow", args.entity); ge.setParameter("distance", args.options[0].Distance); ge.setParameter("synchronous", true); ge.Name = "follow"; movement = ge; movingArrow = false; Game.main.enqueueEvent(ge); // Here we've launched the movement. As it's synchronous, we'll receive // the movement finished when the Mover considers it's done. } toLaunch = args.options[0].Action; } // If there're multiple actions we have to display a menu so player can choose else if (args.options.Length > 1) { OptionsGUI gui = ScriptableObject.CreateInstance <OptionsGUI>(); gui.init(args, Camera.main.WorldToScreenPoint(args.entity.transform.position), args.options); GUIManager.addGUI(gui, 100); } } // If the argument doesn't contain options but it has a cell, we'll try to move over there else if (args.cell != null) { var cell = args.cell; if (args.cell.VirtualNeighbors.Count > 0) { cell = args.cell.VirtualNeighbors[0].Destination; } GameEvent ge = new GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("cell", cell); ge.Name = "move"; Game.main.enqueueEvent(ge); } // Otherwise, the controller event should contain keys pressed else { int to = -1; if (args.LEFT) { to = 0; } else if (args.UP) { to = 1; } else if (args.RIGHT) { to = 2; } else if (args.DOWN) { to = 3; } if (to > -1) { if (movement == null || !movingArrow) { if (Entity == null) { Debug.Log("Null!"); } Cell destination = Entity.Position.Map.getNeightbours(Entity.Position)[to]; // Can move to checks if the entity can DIRECT move to this cells. // This should solve bug #29 Mover em = this.Entity.GetComponent <Mover>(); if (em != null && em.CanMoveTo(destination)) { GameEvent ge = new GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("cell", destination); ge.setParameter("synchronous", true); ge.Name = "move"; Game.main.enqueueEvent(ge); movement = ge; } else { GameEvent ge = new GameEvent(); ge.setParameter("mover", this.Entity.mover); ge.setParameter("direction", fromIndex(to)); ge.setParameter("synchronous", true); ge.Name = "turn"; Game.main.enqueueEvent(ge); movement = ge; } movingArrow = true; } } } } }