diff --git a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java b/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java deleted file mode 100644 index 77a7adf..0000000 --- a/app/src/main/java/org/ntlab/radishforandroidstudio/cactusClient/models/BulletsManager.java +++ /dev/null @@ -1,152 +0,0 @@ -package org.ntlab.radishforandroidstudio.cactusClient.models; - -import android.content.res.Resources; - -import net.arnx.jsonic.JSON; -import net.arnx.jsonic.TypeReference; - -import org.ntlab.radishforandroidstudio.cactusClient.connections.BulletGetConnection; -import org.ntlab.radishforandroidstudio.framework.gameMain.GameBaseModel; -import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; -import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Position3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; -import org.ntlab.radishforandroidstudio.framework.model3D.Universe; -import org.ntlab.radishforandroidstudio.framework.network.CallBack; -import org.ntlab.radishforandroidstudio.java3d.Appearance; -import org.ntlab.radishforandroidstudio.java3d.Material; - -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -public class -BulletsManager implements GameBaseModel, CallBack { - private Universe universe; - private Resources resources; - private BulletGetConnection con; - private int nextConnectRenaimdTime = 0; - static final private int CONNECT_INTERVAL = 100; - private Map visibleBullets = new HashMap<>(); - private Map playerVisibleBullets = new HashMap<>(); - private String instanceId; - private String playerId; - - private Set bulletsSet; - - public enum BulletType { - Normal - } - - public BulletsManager(Resources fragment, Universe universe) { - this.universe = universe; - this.resources = fragment; - } - - @Override - public void setInstanceId(String id) { - this.instanceId = id; - } - - public void setPlayerId(String id) { - playerId = id; - } - - /** - * 玉の状態を更新する - * - * @author s.iwatani - * @param interval 前回の更新からの時間差 - */ - @Override - public void update(double interval) { - nextConnectRenaimdTime -= interval; - if (nextConnectRenaimdTime <= 0 && instanceId != null) { - nextConnectRenaimdTime = CONNECT_INTERVAL; - con = new BulletGetConnection(instanceId); - con.setCallBack(this); - con.doGet(); - } - } - - @Override - public void onResponse(String response) { - Map lastVisibleBullets = new HashMap<>(visibleBullets); - Map lastPlayerVisibleBullets = new HashMap<>(playerVisibleBullets); - visibleBullets.clear(); - JSON json = new JSON(); - if (!response.equals("{}")) { - ArrayList> m = json.decode(response, new TypeReference>>() {}); - for (Map eachPlayerBullets : m) { - for (Map.Entry entry : eachPlayerBullets.entrySet()) { - visibleBullets.put(entry.getKey(), 1); - ArrayList properties = new ArrayList<>(); - - Bullet b = entry.getValue(); - - // 自分自身は無視する - if (b.getPlayerID().equals(playerId)) { - playerVisibleBullets.put(entry.getKey(), 1); - continue; - } - - - // 情報の取得 - properties.add(b.getPosition()); - properties.add(b.getAngle()); - - if (!universe.doHaveObj(entry.getKey())) { - Appearance ap1 = new Appearance(); - Material mat = new Material(); - mat.setDiffuseColor(0.0f, 0.3f, 1.0f); - mat.setAmbientColor(0.0f, 0.0f, 0.0f); - mat.setEmissiveColor(0.0f, 0.0f, 0.0f); - mat.setSpecularColor(0.0f, 0.0f, 0.0f); - mat.setShininess(5.0f); - ap1.setMaterial(mat); - - Object3D pochaBody = null; - try { - pochaBody = ModelFactory.loadModel(resources, "pocha.stl", ap1).createObject(); - pochaBody.scale(0.5); - } catch (Exception e) { - e.printStackTrace(); - } - OtherPlayerBullet bullet = new OtherPlayerBullet(pochaBody); - universe.place(entry.getKey(), bullet); - universe.place(bullet); - } - universe.apply(entry.getKey(), properties); - } - } - } - // 見えなくなったキャラクターの削除 - for (String key : lastVisibleBullets.keySet()) { - if (visibleBullets.get(key) == null) { - universe.displace(key); - } - } - - // 消えた弾の削除(プレイヤーのみ) - for(String key: lastPlayerVisibleBullets.keySet()) { - bulletsSet.add(key); - } - } - - /** - * 消えた弾のうち,セットしたプレイヤーに該当する弾を取得する - * - * @return ArrayList - */ - public ArrayList getDeletedPlayerBullets() { - ArrayList bullets = new ArrayList<>(); - - for(String key : bulletsSet) { - bullets.add(key); - } - bulletsSet.clear(); - return bullets; - } -}