/*
* AQP Project
* http://http://code.google.com/p/aqp-project/
* Alexandre Gomez - Clément Troesch - Fabrice Latterner
*/
package com.aqpproject.worldmodel.game.entity;
import com.aqpproject.game.Singleton;
import com.aqpproject.tools.Vector2D;
import com.aqpproject.worldmodel.data.Item;
import com.aqpproject.worldmodel.data.ItemController;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.parsers.ParserConfigurationException;
import org.xml.sax.SAXException;
/**
*
* @author admlatterner
*/
public class WEBox extends WorldEntity {
public WEBox(String name, String spriteName, Vector2D pos, float rotation, int frame, ItemController Ic) {
super(name, spriteName, pos, rotation, frame, false, true);
m_controller = Ic;
m_lastTime = -1 * Ic.getDelay();
}
public Item getItem() {
Item item = null;
if (Singleton.getOptionsController().getRole().equals("SERVER")) {
item = m_currentItem;
}
m_currentItem = null;
m_lastTime = Singleton.getWorldModel().getTime();
return item;
}
@Override
public void update(long time) {
//super.update(time);
if (m_currentItem != null) {
Singleton.getVisualisation().updateActorFrame(m_name, 1);
} else {
if (Singleton.getWorldModel().getTime() - m_lastTime > m_controller.getDelay()) {
try {
m_currentItem = m_controller.getItem();
} catch (ParserConfigurationException | SAXException | IOException ex) {
Logger.getLogger(WEBox.class.getName()).log(Level.SEVERE, null, ex);
}
if (m_currentItem != null || "CLIENT".equals(Singleton.getOptionsController().getRole())) {
Singleton.getVisualisation().updateActorFrame(m_name, 1);
} else {
Singleton.getVisualisation().updateActorFrame(m_name, 2);
}
} else {
Singleton.getVisualisation().updateActorFrame(m_name, 2);
}
}
}
private long m_lastTime;
private Item m_currentItem = null;
private ItemController m_controller = null;
}