| | 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.gameMain.RealTime3DFragment; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.ModelFactory; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Object3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Property3D; |
---|
| | import org.ntlab.radishforandroidstudio.framework.model3D.Universe; |
---|
| |
---|
| | |
---|
| | 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 RealTime3DFragment fragment; |
---|
| | private Resources resources; |
---|
| | private BulletGetConnection con; |
---|
| | private int nextConnectRenaimdTime = 0; |
---|
| | private int connectInterval = 100; |
---|
| | private Map<String, Integer> visibleBullets = new HashMap<>(); |
---|
| | private Map<String, Integer> playerVisibleBullets = new HashMap<>(); |
---|
| | private String instanceId; |
---|
| | private String playerId; |
---|
| | |
---|
| | public BulletsManager(RealTime3DFragment fragment, Universe universe) { |
---|
| | private Set<String> bulletsSet; |
---|
| | |
---|
| | public BulletsManager(Resources fragment, Universe universe) { |
---|
| | this.universe = universe; |
---|
| | this.fragment = fragment; |
---|
| | this.resources = fragment; |
---|
| | } |
---|
| | |
---|
| | public void setInstanceId(String id) { |
---|
| | this.instanceId = id; |
---|
| |
---|
| | |
---|
| | @Override |
---|
| | public void onResponse(String response) { |
---|
| | Map<String, Integer> lastVisibleBullets = new HashMap<>(visibleBullets); |
---|
| | Map<String, Integer> lastPlayerVisibleBullets = new HashMap<>(playerVisibleBullets); |
---|
| | visibleBullets.clear(); |
---|
| | JSON json = new JSON(); |
---|
| | ArrayList<Map<String, DummyBullet>> m = json.decode(response, new TypeReference<ArrayList<Map<String, DummyBullet>>>(){}); |
---|
| | for(Map<String, DummyBullet> eachPlayerBullets : m) { |
---|
| |
---|
| | ArrayList<Property3D> properties = new ArrayList<>(); |
---|
| | DummyBullet player = entry.getValue(); |
---|
| | |
---|
| | // 自分自身は無視する |
---|
| | if (entry.getKey().equals(playerId)) continue; |
---|
| | if (entry.getKey().equals(playerId)) { |
---|
| | playerVisibleBullets.put(entry.getKey(), 1); |
---|
| | continue; |
---|
| | } |
---|
| | |
---|
| | // 情報の取得 |
---|
| | // Map position = (Map)player.get("position"); |
---|
| | // Map angle = (Map)player.get("angle"); |
---|
| |
---|
| | ap1.setMaterial(mat); |
---|
| | |
---|
| | Object3D pochaBody = null; |
---|
| | try { |
---|
| | pochaBody = ModelFactory.loadModel(fragment.getResources(), "pocha.stl", ap1).createObject(); |
---|
| | pochaBody = ModelFactory.loadModel(resources, "pocha.stl", ap1).createObject(); |
---|
| | pochaBody.scale(5.0); |
---|
| | } catch (Exception e) { |
---|
| | e.printStackTrace(); |
---|
| | } |
---|
| |
---|
| | if (visibleBullets.get(key) == null) { |
---|
| | universe.displace(key); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | // 消えた弾の削除(プレイヤーのみ) |
---|
| | for(String key: lastPlayerVisibleBullets.keySet()) { |
---|
| | bulletsSet.add(key); |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | /** |
---|
| | * 消えた弾のうち,セットしたプレイヤーに該当する弾を取得する |
---|
| | * |
---|
| | * @return ArrayList<String> |
---|
| | */ |
---|
| | public ArrayList<String> getDeletedPlayerBullets() { |
---|
| | ArrayList<String> bullets = new ArrayList<>(); |
---|
| | |
---|
| | for(String key : bulletsSet) { |
---|
| | bullets.add(key); |
---|
| | } |
---|
| | bulletsSet.clear(); |
---|
| | return bullets; |
---|
| | } |
---|
| | } |
---|
| | |
---|
| | |