Gridarta Editor
ExitMatcher.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.model.exitconnector;
21 
22 import java.awt.Point;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
36 public class ExitMatcher<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> implements GameObjectMatcher {
37 
41  private static final long serialVersionUID = 1L;
42 
46  @NotNull
48 
53  public ExitMatcher(@NotNull final GameObjectMatcher exitMatcher) {
54  this.exitMatcher = exitMatcher;
55  }
56 
64  @Nullable
65  public G getValidExit(@NotNull final MapModel<G, A, R> mapModel, @NotNull final Point point) {
66  if (!mapModel.getMapArchObject().isPointValid(point)) {
67  return null;
68  }
69  for (final GameObject<G, A, R> part : mapModel.getMapSquare(point)) {
70  final G head = part.getHead();
71  if (isValidExit(head)) {
72  return head;
73  }
74  }
75  return null;
76  }
77 
85  @Nullable
86  public GameObject<G, A, R> getValidExit(@Nullable final G exit) {
87  if (exit == null) {
88  return null;
89  }
90  final GameObject<G, A, R> head = exit.getHead();
91  if (!isValidExit(head)) {
92  return null;
93  }
94  return head;
95  }
96 
104  @Nullable
105  @SuppressWarnings("TypeMayBeWeakened")
106  public G getExit(@NotNull final MapModel<G, A, R> mapModel, @Nullable final Point point) {
107  if (point == null || !mapModel.getMapArchObject().isPointValid(point)) {
108  return null;
109  }
110  for (final GameObject<G, A, R> part : mapModel.getMapSquare(point)) {
111  final G head = part.getHead();
112  if (isExit(head)) {
113  return head;
114  }
115  }
116  return null;
117  }
118 
125  @Nullable
126  public G getExit(@Nullable final G exit) {
127  if (exit == null) {
128  return null;
129  }
130  final G head = exit.getHead();
131  if (!isExit(head)) {
132  return null;
133  }
134  return head;
135  }
136 
142  private boolean isValidExit(@NotNull final GameObject<G, A, R> gameObject) {
143  return isExit(gameObject) && gameObject.hasAttribute(BaseObject.SLAYING);
144  }
145 
151  private boolean isExit(@NotNull final GameObject<?, ?, ?> gameObject) {
152  return exitMatcher.isMatching(gameObject);
153  }
154 
155  @Override
156  public boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject) {
157  return isExit(gameObject);
158  }
159 
160 }
T getHead()
Return the head part of a multi-part object.
A MapModel reflects the data of a map.
Definition: MapModel.java:75
G getExit(@NotNull final MapModel< G, A, R > mapModel, @Nullable final Point point)
Returns an exit game object on a given map square.
ExitMatcher(@NotNull final GameObjectMatcher exitMatcher)
Creates a new instance.
Interface for classes that match GameObjects.
This package contains classes related to matching GameObjects, so called GameObjectMatchers.
final GameObjectMatcher exitMatcher
The matcher for selecting exit objects.
boolean isValidExit(@NotNull final GameObject< G, A, R > gameObject)
Returns whether a GameObject is a valid exit.
String SLAYING
The name of the "slaying" attribute.
Base package of all Gridarta classes.
G getExit(@Nullable final G exit)
Returns whether the given game object is an exit game object.
Reflects a game object (object on a map).
Definition: GameObject.java:36
boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject)
Matches an GameObject.
Selects valid exit game objects from maps.
static final long serialVersionUID
The serial version UID.
GameObjects are the objects based on Archetypes found on maps.
G getValidExit(@NotNull final MapModel< G, A, R > mapModel, @NotNull final Point point)
Returns an exit game object on a given map square having exit information.
boolean isExit(@NotNull final GameObject<?, ?, ?> gameObject)
Returns whether a GameObject is a valid exit.
GameObject< G, A, R > getValidExit(@Nullable final G exit)
Returns whether the given game object is an exit game object having exit information.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.
MapSquare< G, A, R > getMapSquare()
Get the MapSquare of this GameObjectContainer.