Crossfire JXClient, Trunk  R20561
SkillSet.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.skills;
23 
28 import java.util.Arrays;
29 import java.util.HashMap;
30 import java.util.Map;
31 import org.jetbrains.annotations.NotNull;
32 import org.jetbrains.annotations.Nullable;
33 
38 public class SkillSet {
39 
44  @NotNull
45  private final Skill[] numberedSkills = new Skill[Stats.CS_NUM_SKILLS];
46 
50  @NotNull
51  private final Map<String, Skill> namedSkills = new HashMap<>();
52 
57  @NotNull
58  @SuppressWarnings("FieldCanBeLocal")
60 
61  @Override
62  public void start() {
63  // ignore
64  }
65 
66  @Override
67  public void metaserver() {
68  // ignore
69  }
70 
71  @Override
72  public void preConnecting(@NotNull final String serverInfo) {
73  // ignore
74  }
75 
76  @Override
77  public void connecting(@NotNull final String serverInfo) {
79  }
80 
81  @Override
82  public void connecting(@NotNull final ClientSocketState clientSocketState) {
83  // ignore
84  }
85 
86  @Override
87  public void connected() {
88  // ignore
89  }
90 
91  @Override
92  public void connectFailed(@NotNull final String reason) {
93  // ignore
94  }
95 
96  };
97 
102  public SkillSet(@NotNull final GuiStateManager guiStateManager) {
103  guiStateManager.addGuiStateListener(guiStateListener);
104  }
105 
109  public void clearSkills() {
111  Arrays.fill(numberedSkills, null);
112  }
113 
120  public void addSkill(final int id, @NotNull final String skillName, final int face) {
121  final int index = id-Stats.CS_STAT_SKILLINFO;
122  final Skill oldSkill = numberedSkills[index];
123  final Skill newSkill = getNamedSkill(skillName, face);
124  if (oldSkill == newSkill) {
125  return;
126  }
127 
128  if (oldSkill != null) {
129  oldSkill.set(0, 0);
130  }
131  numberedSkills[index] = newSkill;
132  }
133 
140  @NotNull
141  public Skill getNamedSkill(@NotNull final String skillName, final int face) {
142  final Skill oldSkill = namedSkills.get(skillName);
143  if (oldSkill != null) {
144  oldSkill.setFace(face);
145  return oldSkill;
146  }
147 
148  final Skill newSkill = new Skill(skillName);
149  newSkill.setFace(face);
150  namedSkills.put(skillName, newSkill);
151  return newSkill;
152  }
153 
157  public void clearNumberedSkills() {
158  for (final Skill skill : numberedSkills) {
159  if (skill != null) {
160  skill.set(0, 0);
161  }
162  }
163  }
164 
171  @Nullable
172  public Skill getSkill(final int id) {
173  return numberedSkills[id-Stats.CS_STAT_SKILLINFO];
174  }
175 
182  public int getSkillId(final String name) {
183  for (int i = 0; i < numberedSkills.length; i++) {
184  if (numberedSkills[i] != null && numberedSkills[i].toString().equals(name)) {
185  return i+Stats.CS_STAT_SKILLINFO;
186  }
187  }
188  return -1;
189  }
190 
191 }
Interface for listeners interested gui state changes.
Skill getNamedSkill(@NotNull final String skillName, final int face)
Returns the skill instance for a given skill name.
Definition: SkillSet.java:141
static final int CS_NUM_SKILLS
CS_NUM_SKILLS does not match how many skills there really are - instead, it is used as a range of val...
Definition: Stats.java:447
final Map< String, Skill > namedSkills
Maps skill name to skill instance.
Definition: SkillSet.java:51
void set(final int level, final long experience)
Updates the skill attributes.
Definition: Skill.java:74
SkillSet(@NotNull final GuiStateManager guiStateManager)
Creates a new instance.
Definition: SkillSet.java:102
One skill of the character.
Definition: Skill.java:32
int getSkillId(final String name)
Get a skill identifier from the skill name.
Definition: SkillSet.java:182
final Skill [] numberedSkills
Maps stat number to skill instance.
Definition: SkillSet.java:45
static final int CS_STAT_SKILLINFO
CS_STAT_SKILLINFO is used as the starting index point.
Definition: Stats.java:454
void addSkill(final int id, @NotNull final String skillName, final int face)
Adds a new skill to the list of known skills.
Definition: SkillSet.java:120
void setFace(final int face)
Defines the skill&#39;s face.
Definition: Skill.java:113
Skill getSkill(final int id)
Returns the given skill as a Skill object.
Definition: SkillSet.java:172
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
Definition: SkillSet.java:59
This is the representation of all the statistics of a player, like its speed or its experience...
Definition: Stats.java:43
void clearNumberedSkills()
Clears all stat info in numberedSkills.
Definition: SkillSet.java:157
Maintain the set of skills as sent by the server.
Definition: SkillSet.java:38
Connection progress states of the Crossfire server connection.