Crossfire JXClient, Trunk  R20561
ItemsManager.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.items;
23 
31 import org.jetbrains.annotations.NotNull;
32 
39 public class ItemsManager {
40 
44  @NotNull
45  private final FacesManager facesManager;
46 
50  @NotNull
51  private final Stats stats;
52 
56  @NotNull
57  private final SkillSet skillSet;
58 
62  @NotNull
63  private final ItemSet itemSet;
64 
69  @NotNull
70  @SuppressWarnings("FieldCanBeLocal")
72 
73  @Override
74  public void start() {
75  itemSet.reset();
76  }
77 
78  @Override
79  public void metaserver() {
80  itemSet.reset();
81  }
82 
83  @Override
84  public void preConnecting(@NotNull final String serverInfo) {
85  // ignore
86  }
87 
88  @Override
89  public void connecting(@NotNull final String serverInfo) {
90  itemSet.reset();
91  }
92 
93  @Override
94  public void connecting(@NotNull final ClientSocketState clientSocketState) {
95  // ignore
96  }
97 
98  @Override
99  public void connected() {
100  // ignore
101  }
102 
103  @Override
104  public void connectFailed(@NotNull final String reason) {
105  // ignore
106  }
107 
108  };
109 
118  public ItemsManager(@NotNull final FacesManager facesManager, @NotNull final Stats stats, @NotNull final SkillSet skillSet, @NotNull final GuiStateManager guiStateManager, @NotNull final ItemSet itemSet) {
119  this.facesManager = facesManager;
120  this.stats = stats;
121  this.skillSet = skillSet;
122  this.itemSet = itemSet;
123  guiStateManager.addGuiStateListener(guiStateListener);
124  }
125 
130  public void delinvReceived(final int tag) {
131  itemSet.cleanInventory(tag);
132  }
133 
138  public void delitemReceived(@NotNull final int[] tags) {
139  itemSet.removeItems(tags);
140  }
141 
156  public void addItemReceived(final int location, final int tag, final int flags, final int weight, final int faceNum, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof, final int type) {
157  itemSet.addItem(new CfItem(location, tag, flags, weight, facesManager.getFace(faceNum), name, namePl, anim, animSpeed, nrof, type));
158  }
159 
167  public void playerReceived(final int tag, final int weight, final int faceNum, @NotNull final String name) {
168  stats.setActiveSkill("");
169  skillSet.clearNumberedSkills();
170  itemSet.setPlayer(tag == 0 ? null : new CfPlayer(tag, weight, facesManager.getFace(faceNum), name));
171  stats.setStat(Stats.C_STAT_WEIGHT, weight);
172  }
173 
188  public void upditemReceived(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final int valFaceNum, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof) {
189  itemSet.updateItem(flags, tag, valLocation, valFlags, valWeight, facesManager.getFace(valFaceNum), valName, valNamePl, valAnim, valAnimSpeed, valNrof);
190  if ((flags&UpdItem.UPD_WEIGHT) != 0) {
191  final CfItem player = itemSet.getPlayer();
192  if (player != null && player.getTag() == tag) {
193  stats.setStat(Stats.C_STAT_WEIGHT, valWeight);
194  }
195  }
196  }
197 
198 }
Interface for listeners interested gui state changes.
void setPlayer(@Nullable final CfItem player)
Sets the player object this client controls.
Definition: ItemSet.java:294
void removeItems(@NotNull final int[] tags)
Deletes items by tag.
Definition: ItemSet.java:204
void updateItem(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final Face valFace, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof)
Processes an "upditem" command.
Definition: ItemSet.java:361
Manages items known to the character.
void upditemReceived(final int flags, final int tag, final int valLocation, final int valFlags, final int valWeight, final int valFaceNum, @NotNull final String valName, @NotNull final String valNamePl, final int valAnim, final int valAnimSpeed, final int valNrof)
An "upditem" command has been received.
void setActiveSkill(@NotNull final String activeSkill)
Sets the active skill name.
Definition: Stats.java:707
ItemsManager(@NotNull final FacesManager facesManager, @NotNull final Stats stats, @NotNull final SkillSet skillSet, @NotNull final GuiStateManager guiStateManager, @NotNull final ItemSet itemSet)
Creates a new instance.
void delitemReceived(@NotNull final int[] tags)
A "delitem" command has been received.
Manages image information ("faces") needed to display the map view, items, and spell icons...
final SkillSet skillSet
The SkillSet instance to update.
void reset()
Resets the manager's state.
Definition: ItemSet.java:403
void addItem(@NotNull final CfItem item)
Adds an item.
Definition: ItemSet.java:216
CfItem getPlayer()
Returns the player object this client controls.
Definition: ItemSet.java:284
A CfItem that represents a character.
Definition: CfPlayer.java:31
final ItemSet itemSet
The known CfItems.
void cleanInventory(final int tag)
Clears the inventory of an item.
Definition: ItemSet.java:338
static final int C_STAT_WEIGHT
The character's weight.
Definition: Stats.java:189
final GuiStateListener guiStateListener
The GuiStateListener for detecting established or dropped connections.
Face getFace(int faceNum)
Returns the Face instance for a given face ID.
Interface defining constants for the "upditem" Crossfire protocol message.
Definition: UpdItem.java:28
final Stats stats
The Stats instance to update.
void addItemReceived(final int location, final int tag, final int flags, final int weight, final int faceNum, @NotNull final String name, @NotNull final String namePl, final int anim, final int animSpeed, final int nrof, final int type)
An "additem" has been received.
Model class maintaining the CfItems known to the player.
Definition: ItemSet.java:43
int UPD_WEIGHT
The update flags value for weight updates.
Definition: UpdItem.java:43
void setStat(final int statNo, final int value)
Sets the given statistic numerical value.
Definition: Stats.java:633
This is the representation of all the statistics of a player, like its speed or its experience...
Definition: Stats.java:43
void delinvReceived(final int tag)
A "delinv" command has been received.
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
void playerReceived(final int tag, final int weight, final int faceNum, @NotNull final String name)
A "player" command has been received.
The representation of a Crossfire Item, client-side.
Definition: CfItem.java:36
final FacesManager facesManager
The FacesManager instance for looking up faces.
Connection progress states of the Crossfire server connection.
Maintains a mapping of face numbers to face data.