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-2023 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 
125  @SuppressWarnings("TypeMayBeWeakened") // is false warning: weakened type would
126  private boolean isMatchingInventory(@NotNull final GameObject<?, ?, ?> gameObject) {
127  for (final GameObject<?, ?, ?> inv : gameObject) {
128  if (gameObjectMatcher.isMatching(inv)) {
129  return true;
130  }
131  if (isMatchingInventory(inv)) {
132  return true;
133  }
134  }
135  return false;
136  }
137 
142  @NotNull
143  public String getID() {
144  return id;
145  }
146 
152  public int getEditType() {
153  return editType;
154  }
155 
160  public boolean isSystemMatcher() {
161  return systemMatcher;
162  }
163 
164 }
net.sf.gridarta.model.match.NamedGameObjectMatcher.gameObjectMatcher
final GameObjectMatcher gameObjectMatcher
The GameObjectMatcher to wrap.
Definition: NamedGameObjectMatcher.java:74
net.sf.gridarta
Base package of all Gridarta classes.
net.sf.gridarta.model.match.NamedGameObjectMatcher.isSystemMatcher
boolean isSystemMatcher()
Returns whether this matcher is a system matcher.
Definition: NamedGameObjectMatcher.java:160
net.sf
net.sf.gridarta.model.match.GameObjectMatcher
Interface for classes that match GameObjects.
Definition: GameObjectMatcher.java:30
net.sf.gridarta.model.gameobject.GameObject
Reflects a game object (object on a map).
Definition: GameObject.java:36
net.sf.gridarta.model.match.NamedGameObjectMatcher.isMatchingInventory
boolean isMatchingInventory(@NotNull final GameObject<?, ?, ?> gameObject)
Returns whether this matcher matches any inventory game object of a given game object.
Definition: NamedGameObjectMatcher.java:126
net.sf.gridarta.model.match.GameObjectMatcher.isMatching
boolean isMatching(@NotNull GameObject<?, ?, ?> gameObject)
Matches a GameObject.
net.sf.gridarta.model.match.NamedGameObjectMatcher
Decorates an arbitrary GameObjectMatcher with a localized name that is suitable for the user interfac...
Definition: NamedGameObjectMatcher.java:33
net.sf.gridarta.model.gameobject
GameObjects are the objects based on Archetypes found on maps.
Definition: AbstractGameObject.java:20
net.sf.gridarta.model.match.NamedGameObjectMatcher.NamedGameObjectMatcher
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.
Definition: NamedGameObjectMatcher.java:92
net
net.sf.gridarta.model.match.NamedGameObjectMatcher.getID
String getID()
Gets the ID of this.
Definition: NamedGameObjectMatcher.java:143
net.sf.gridarta.model.match.NamedGameObjectMatcher.envGameObjectMatcher
final GameObjectMatcher envGameObjectMatcher
The environment GameObjectMatcher.
Definition: NamedGameObjectMatcher.java:67
net.sf.gridarta.model.match.NamedGameObjectMatcher.name
final String name
The localized name.
Definition: NamedGameObjectMatcher.java:51
net.sf.gridarta.model.match.NamedGameObjectMatcher.editType
final int editType
The edit type of this matcher.
Definition: NamedGameObjectMatcher.java:44
net.sf.gridarta.model.match.NamedGameObjectMatcher.serialVersionUID
static final long serialVersionUID
The serial version UID.
Definition: NamedGameObjectMatcher.java:38
net.sf.gridarta.model.match.NamedGameObjectMatcher.isMatching
boolean isMatching(@NotNull final GameObject<?, ?, ?> gameObject)
Matches a GameObject.
Definition: NamedGameObjectMatcher.java:111
net.sf.gridarta.model
net.sf.gridarta.model.match.NamedGameObjectMatcher.id
final String id
The id of this GameObjectMatcher.
Definition: NamedGameObjectMatcher.java:81
net.sf.gridarta.var.crossfire.model.gameobject.GameObject<?, ?, ?>
net.sf.gridarta.model.match.NamedGameObjectMatcher.getEditType
int getEditType()
Returns the edit type associated with this matcher.
Definition: NamedGameObjectMatcher.java:152
net.sf.gridarta.model.match.NamedGameObjectMatcher.getName
String getName()
Gets the name of this.
Definition: NamedGameObjectMatcher.java:106
net.sf.gridarta.model.match.NamedGameObjectMatcher.systemMatcher
final boolean systemMatcher
Whether this matcher is a system matcher.
Definition: NamedGameObjectMatcher.java:58