mirror of
https://github.com/collinsmith/riiablo.git
synced 2025-02-21 20:18:14 +07:00
Created CharData (See #35)
This commit is contained in:
parent
8b590d109c
commit
d4858781c9
133
core/src/com/riiablo/CharData.java
Normal file
133
core/src/com/riiablo/CharData.java
Normal file
@ -0,0 +1,133 @@
|
||||
package com.riiablo;
|
||||
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.riiablo.codec.D2S;
|
||||
import com.riiablo.item.BodyLoc;
|
||||
import com.riiablo.item.Item;
|
||||
import com.riiablo.item.StoreLoc;
|
||||
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
|
||||
import java.util.EnumMap;
|
||||
|
||||
public class CharData {
|
||||
private D2S d2s;
|
||||
private Item cursor;
|
||||
private final EnumMap<StoreLoc, Array<Item>> store = new EnumMap<>(StoreLoc.class);
|
||||
private final EnumMap<BodyLoc, Item> equipped = new EnumMap<>(BodyLoc.class);
|
||||
private final Array<Item> belt = new Array<>(16);
|
||||
private final Array<EquippedListener> EQUIPPED_LISTENERS = new Array<>();
|
||||
|
||||
public CharData() {
|
||||
for (StoreLoc storeLoc : StoreLoc.values()) store.put(storeLoc, new Array<Item>());
|
||||
}
|
||||
|
||||
public D2S getD2S() {
|
||||
return d2s;
|
||||
}
|
||||
|
||||
public CharData setD2S(D2S d2s) {
|
||||
if (this.d2s != d2s) {
|
||||
this.d2s = d2s;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public CharData createD2S(String name, CharacterClass charClass) {
|
||||
return this;
|
||||
}
|
||||
|
||||
public void loadItems() {
|
||||
for (Array<Item> array : store.values()) array.clear();
|
||||
equipped.clear();
|
||||
belt.clear();
|
||||
for (Item item : d2s.items.items) {
|
||||
switch (item.location) {
|
||||
case BELT:
|
||||
belt.add(item);
|
||||
break;
|
||||
case CURSOR:
|
||||
cursor = item;
|
||||
break;
|
||||
case EQUIPPED:
|
||||
setEquipped(item.bodyLoc, item);
|
||||
break;
|
||||
case STORED:
|
||||
store.get(item.storeLoc).add(item);
|
||||
break;
|
||||
}
|
||||
//item.load();
|
||||
}
|
||||
}
|
||||
|
||||
public int getSkill(int alternate, int button) {
|
||||
return d2s.header.actions[alternate][button];
|
||||
}
|
||||
|
||||
public int getHotKey(int button, int skill) {
|
||||
return ArrayUtils.indexOf(d2s.header.hotkeys, button == Input.Buttons.LEFT
|
||||
? skill | D2S.HOTKEY_LEFT_MASK
|
||||
: skill);
|
||||
}
|
||||
|
||||
public Item getCursor() {
|
||||
return cursor;
|
||||
}
|
||||
|
||||
public Item setCursor(Item item) {
|
||||
Item oldItem = cursor;
|
||||
this.cursor = item;
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
public Array<Item> getStore(StoreLoc storeLoc) {
|
||||
return store.get(storeLoc);
|
||||
}
|
||||
|
||||
public Item getEquipped(BodyLoc bodyLoc) {
|
||||
return equipped.get(bodyLoc);
|
||||
}
|
||||
|
||||
public Item setEquipped(BodyLoc bodyLoc, Item item) {
|
||||
Item oldItem = equipped.put(bodyLoc, item);
|
||||
notifyEquippedChanged(bodyLoc, oldItem, item);
|
||||
return oldItem;
|
||||
}
|
||||
|
||||
public Array<Item> getBelt() {
|
||||
return belt;
|
||||
}
|
||||
|
||||
public int getAlternate() {
|
||||
return d2s.header.alternate;
|
||||
}
|
||||
|
||||
public void setAlternate(int alternate) {
|
||||
if (d2s.header.alternate != alternate) {
|
||||
d2s.header.alternate = alternate;
|
||||
Item LH = getEquipped(alternate > 0 ? BodyLoc.LARM2 : BodyLoc.LARM);
|
||||
Item RH = getEquipped(alternate > 0 ? BodyLoc.RARM2 : BodyLoc.RARM);
|
||||
notifyEquippedAlternated(LH, RH);
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyEquippedChanged(BodyLoc bodyLoc, Item oldItem, Item item) {
|
||||
for (EquippedListener l : EQUIPPED_LISTENERS) l.onChanged(this, bodyLoc, oldItem, item);
|
||||
}
|
||||
|
||||
private void notifyEquippedAlternated(Item LH, Item RH) {
|
||||
for (EquippedListener l : EQUIPPED_LISTENERS) l.onAlternated(this, LH, RH);
|
||||
}
|
||||
|
||||
public interface EquippedListener {
|
||||
void onChanged(CharData client, BodyLoc bodyLoc, Item oldItem, Item item);
|
||||
void onAlternated(CharData client, Item LH, Item RH);
|
||||
}
|
||||
|
||||
public static class EquippedAdapter implements EquippedListener {
|
||||
@Override public void onChanged(CharData client, BodyLoc bodyLoc, Item oldItem, Item item) {}
|
||||
@Override public void onAlternated(CharData client, Item LH, Item RH) {}
|
||||
}
|
||||
}
|
@ -109,6 +109,7 @@ public class Client extends Game {
|
||||
private Audio audio;
|
||||
private MusicController music;
|
||||
private Cursor cursor;
|
||||
private CharData charData;
|
||||
|
||||
private boolean forceWindowed;
|
||||
private boolean forceDrawFps;
|
||||
@ -268,6 +269,7 @@ public class Client extends Game {
|
||||
Riiablo.bundle = bundle = I18NBundle.createBundle(Gdx.files.internal("lang/Client"));
|
||||
Riiablo.textures = textures = new Textures();
|
||||
Riiablo.cursor = cursor = new Cursor();
|
||||
Riiablo.charData = charData = new CharData();
|
||||
|
||||
Collection<Throwable> throwables;
|
||||
Riiablo.commands = commands = new GdxCommandManager();
|
||||
@ -498,6 +500,7 @@ public class Client extends Game {
|
||||
Riiablo.audio = audio;
|
||||
Riiablo.music = music;
|
||||
Riiablo.cursor = cursor;
|
||||
Riiablo.charData = charData;
|
||||
super.resume();
|
||||
}
|
||||
|
||||
|
@ -50,4 +50,5 @@ public class Riiablo {
|
||||
public static Audio audio;
|
||||
public static MusicController music;
|
||||
public static Cursor cursor;
|
||||
public static CharData charData;
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ import com.riiablo.Client;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.Animation;
|
||||
import com.riiablo.codec.DC6;
|
||||
import com.riiablo.entity.Player;
|
||||
import com.riiablo.graphics.BlendMode;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.loader.DC6Loader;
|
||||
@ -189,7 +188,7 @@ public class CreateCharacterScreen extends ScreenAdapter {
|
||||
Riiablo.client.popScreen();
|
||||
} else if (actor == btnOK) {
|
||||
if (selected == null) return;
|
||||
Riiablo.client.clearAndSet(new LoadingScreen(new GameScreen(new Player(tfCharName.getText(), selected.charClass))));
|
||||
Riiablo.client.clearAndSet(new LoadingScreen(new GameScreen(Riiablo.charData.createD2S(tfCharName.getText(), selected.charClass))));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -31,6 +31,7 @@ import com.badlogic.gdx.utils.Scaling;
|
||||
import com.badlogic.gdx.utils.Timer;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
import com.riiablo.Client;
|
||||
import com.riiablo.CharData;
|
||||
import com.riiablo.Cvars;
|
||||
import com.riiablo.Keys;
|
||||
import com.riiablo.Riiablo;
|
||||
@ -140,7 +141,6 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
Client.ScreenBoundsListener screenBoundsListener;
|
||||
TextArea output;
|
||||
|
||||
//Char character;
|
||||
public Player player;
|
||||
public IntMap<Entity> entities = new IntMap<>();
|
||||
Timer.Task updateTask;
|
||||
@ -159,14 +159,14 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
public GameScreen(Player player) {
|
||||
public GameScreen(CharData player) {
|
||||
this(player, new PipedSocket());
|
||||
}
|
||||
|
||||
//public GameScreen(final Char character) {
|
||||
public GameScreen(final Player player, Socket socket) {
|
||||
this.player = player;
|
||||
public GameScreen(CharData player, Socket socket) {
|
||||
this.player = new Player(player.getD2S());
|
||||
this.socket = socket;
|
||||
player.loadItems();
|
||||
|
||||
Riiablo.viewport = viewport = Riiablo.extendViewport;
|
||||
stage = new Stage(viewport, Riiablo.batch);
|
||||
@ -336,8 +336,8 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
String text = input.getText();
|
||||
if (!text.isEmpty()) {
|
||||
Gdx.app.debug(TAG, text);
|
||||
Message message = new Message(player.stats.getName(), text);
|
||||
out.println(Packets.build(message));
|
||||
//Message message = new Message(player.stats.getName(), text);
|
||||
//out.println(Packets.build(message));
|
||||
input.setText("");
|
||||
}
|
||||
}
|
||||
@ -361,7 +361,7 @@ public class GameScreen extends ScreenAdapter implements LoadingScreen.Loadable
|
||||
characterPanel.setVisible(false);
|
||||
stashPanel.setVisible(!stashPanel.isVisible());
|
||||
} else if (key == Keys.SwapWeapons) {
|
||||
player.setAlternate(!player.isAlternate());
|
||||
Riiablo.charData.setAlternate(~Riiablo.charData.getAlternate());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -27,9 +27,9 @@ import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.Json;
|
||||
import com.badlogic.gdx.utils.ObjectMap;
|
||||
import com.badlogic.gdx.utils.SerializationException;
|
||||
import com.riiablo.CharData;
|
||||
import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.DC6;
|
||||
import com.riiablo.entity.Player;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.server.Account;
|
||||
@ -81,8 +81,8 @@ public class LobbyScreen extends ScreenAdapter {
|
||||
|
||||
private Stage stage;
|
||||
|
||||
private Account account;
|
||||
private Player player;
|
||||
private Account account;
|
||||
private CharData player;
|
||||
|
||||
private TextArea taChatOutput;
|
||||
private TextField tfChatInput;
|
||||
@ -91,7 +91,7 @@ public class LobbyScreen extends ScreenAdapter {
|
||||
private PrintWriter out;
|
||||
private BufferedReader in;
|
||||
|
||||
public LobbyScreen(Account account, Player player) {
|
||||
public LobbyScreen(Account account, CharData player) {
|
||||
this.account = account;
|
||||
this.player = player;
|
||||
|
||||
|
@ -19,7 +19,6 @@ import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.D2S;
|
||||
import com.riiablo.codec.DC6;
|
||||
import com.riiablo.codec.StringTBL;
|
||||
import com.riiablo.entity.Player;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.widget.CharacterSelectButton;
|
||||
@ -58,7 +57,7 @@ public class SelectCharacterScreen extends ScreenAdapter {
|
||||
Riiablo.client.popScreen();
|
||||
} else if (actor == btnOK) {
|
||||
assert selected != null;
|
||||
GameScreen game = new GameScreen(new Player(selected.getD2S()));
|
||||
GameScreen game = new GameScreen(Riiablo.charData.setD2S(selected.getD2S()));
|
||||
Riiablo.client.clearAndSet(new LoadingScreen(game));
|
||||
} else if (actor == btnCreateNewCharacter) {
|
||||
Riiablo.client.pushScreen(new CreateCharacterScreen());
|
||||
|
@ -19,7 +19,6 @@ import com.riiablo.Riiablo;
|
||||
import com.riiablo.codec.D2S;
|
||||
import com.riiablo.codec.DC6;
|
||||
import com.riiablo.codec.StringTBL;
|
||||
import com.riiablo.entity.Player;
|
||||
import com.riiablo.graphics.PaletteIndexedBatch;
|
||||
import com.riiablo.loader.DC6Loader;
|
||||
import com.riiablo.server.Account;
|
||||
@ -62,7 +61,7 @@ public class SelectCharacterScreen2 extends ScreenAdapter {
|
||||
Riiablo.client.popScreen();
|
||||
} else if (actor == btnOK) {
|
||||
assert selected != null;
|
||||
Riiablo.client.pushScreen(new LobbyScreen(SelectCharacterScreen2.this.account, new Player(selected.getD2S())));
|
||||
Riiablo.client.pushScreen(new LobbyScreen(SelectCharacterScreen2.this.account, Riiablo.charData.setD2S(selected.getD2S())));
|
||||
} else if (actor == btnCreateNewCharacter) {
|
||||
//Riiablo.client.pushScreen(new CreateCharacterScreen());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user