Gridarta Editor
NamedGameObjectMatcher.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.match;
21 
23 import org.jetbrains.annotations.NotNull;
24 import org.jetbrains.annotations.Nullable;
25 
33 public class NamedGameObjectMatcher implements GameObjectMatcher {
34 
38  private static final long serialVersionUID = 1L;
39 
44  private final int editType;
45 
50  @NotNull
51  private final String name;
52 
58  private final boolean systemMatcher;
59 
66  @Nullable
68 
73  @NotNull
75 
80  @NotNull
81  private final String id;
82 
92  public NamedGameObjectMatcher(final int editType, @NotNull final String id, @NotNull final String name, final boolean systemMatcher, @Nullable final GameObjectMatcher envGameObjectMatcher, @NotNull final GameObjectMatcher gameObjectMatcher) {
93  this.editType = editType;
94  this.id = id;
95  this.name = name;
96  this.systemMatcher = systemMatcher;
97  this.envGameObjectMatcher = envGameObjectMatcher;
98  this.gameObjectMatcher = gameObjectMatcher;
99  }
100 
105  @NotNull
106  public String getName() {
107  return name;
108  }
109 
110  @Override
111  public boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject) {
112  if (envGameObjectMatcher != null) {
113  return envGameObjectMatcher.isMatching(gameObject) && isMatchingInventory(gameObject);
114  }
115 
116  return gameObjectMatcher.isMatching(gameObject);
117  }
118 
127  private boolean isMatchingInventory(@NotNull final GameObject<?, ?, ?> gameObject) {
128  for (final GameObject<?, ?, ?> inv : gameObject) {
129  if (gameObjectMatcher.isMatching(inv)) {
130  return true;
131  }
132  if (isMatchingInventory(inv)) {
133  return true;
134  }
135  }
136  return false;
137  }
138 
143  @NotNull
144  public String getID() {
145  return id;
146  }
147 
153  public int getEditType() {
154  return editType;
155  }
156 
161  public boolean isSystemMatcher() {
162  return systemMatcher;
163  }
164 
165 }
NamedGameObjectMatcher(final int editType, @NotNull final String id, @NotNull final String name, final boolean systemMatcher, @Nullable final GameObjectMatcher envGameObjectMatcher, @NotNull final GameObjectMatcher gameObjectMatcher)
Creates a new instance.
final int editType
The edit type of this matcher.
Interface for classes that match GameObjects.
boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject)
Matches an GameObject.
static final long serialVersionUID
The serial version UID.
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
int getEditType()
Returns the edit type associated with this matcher.
final GameObjectMatcher gameObjectMatcher
The GameObjectMatcher to wrap.
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
GameObjects are the objects based on Archetypes found on maps.
boolean isMatchingInventory(@NotNull final GameObject<?, ?, ?> gameObject)
Returns whether this matcher matches any inventory game object of a given game object.
boolean isSystemMatcher()
Returns whether this matcher is a system matcher.
final String id
The id of this GameObjectMatcher.
final boolean systemMatcher
Whether this matcher is a system matcher.
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches an GameObject.
final GameObjectMatcher envGameObjectMatcher
The environment GameObjectMatcher.