战斗数据完成

This commit is contained in:
Yutousama 2020-01-13 22:44:03 +08:00
parent 02da8f3512
commit 89e337ddf1
10 changed files with 257 additions and 74 deletions

View File

@ -98,40 +98,33 @@ public class WarAdapter extends RecyclerAdapter<List<Map<String, JSONObject>>> {
name.setText("("+data.get(0).get("data").get("mapId")+")"+item.getJSONObject("warReport").getString("enemyName")+"("+lev+")"); name.setText("("+data.get(0).get("data").get("mapId")+")"+item.getJSONObject("warReport").getString("enemyName")+"("+lev+")");
time.setText(SimpleDateFormat.getDateTimeInstance(DateFormat.YEAR_FIELD,DateFormat.SHORT).format(new Date(Long.valueOf(data.get(0).get("DealNode").getString("time"))))); time.setText(SimpleDateFormat.getDateTimeInstance(DateFormat.YEAR_FIELD,DateFormat.SHORT).format(new Date(Long.valueOf(data.get(0).get("DealNode").getString("time")))));
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); name.setText("蹭了一下就溜了(无记录)");
} }
} }
@Override @Override
public void onItemViewClick(List<Map<String, JSONObject>> data) { public void onItemViewClick(List<Map<String, JSONObject>> data) {
super.onItemViewClick(data); super.onItemViewClick(data);
// Utils.toast(getContext(),"详细内容正在咕,敬请期待:"+ AppData.magicPackageName);
/*JSONArray array=new JSONArray();
for (Map<String, JSONObject> datum : data) {
try {
JSONObject json=new JSONObject();
json.put("data",datum.get("data"));
json.put("DealNode",datum.get("DealNode"));
json.put("WarReport",datum.get("GetWarResult"));
array.put(json);
}catch (Exception e){
e.printStackTrace();
}
}*/
Map<String,JSONObject> map=data.get(0); Map<String,JSONObject> map=data.get(0);
JSONObject json=new JSONObject(); JSONObject json=new JSONObject();
try { try {
json.put("data",map.get("data")); json.put("data",map.get("data"));
json.put("DealNode",map.get("DealNode")); json.put("DealNode",map.get("DealNode"));
json.put("WarReport",map.get("GetWarResult")); json.put("WarReport",map.get("GetWarResult"));
} catch (JSONException e) { if(map.get("GetWarResult")==null){
e.printStackTrace(); Utils.toast(getContext(),"没有战斗数据");
return;
} }
Intent intent=new Intent(getContext(), WarLogActivity.class); Intent intent=new Intent(getContext(), WarLogActivity.class);
intent.putExtra("data", json.toString()); intent.putExtra("data", json.toString());
getContext().startActivity(intent); getContext().startActivity(intent);
} catch (Exception e) {
e.printStackTrace();
}
} }
} }

View File

@ -268,7 +268,7 @@ public class JianRDataDataBase extends SQLiteOpenHelper {
public List<Map<String,JSONObject>> getDataList(int id){ public List<Map<String,JSONObject>> getDataList(int id){
List<Map<String,JSONObject>> list=new ArrayList<>(); List<Map<String,JSONObject>> list=new ArrayList<>();
try{ try{
Cursor cursor=readDatabase.rawQuery("select * from t_data_GAME game,t_data_name name,t_data_type type where name._id=? and type._id=name.typeId and game.nameId=name._id",new String[]{id+""}); Cursor cursor=readDatabase.rawQuery("select * from t_data_GAME game,t_data_name name,t_data_type type where name._id=? and type._id=name.typeId and game.nameId=name._id order by _id desc",new String[]{id+""});
while (cursor.moveToNext()){ while (cursor.moveToNext()){
Map<String,JSONObject> map=new HashMap<>(); Map<String,JSONObject> map=new HashMap<>();
String m=cursor.getString(cursor.getColumnIndex("m")); String m=cursor.getString(cursor.getColumnIndex("m"));

View File

@ -60,7 +60,6 @@ public class WarFragment extends Fragment {
if(srcList==null){ if(srcList==null){
srcList = new ArrayList<>(); srcList = new ArrayList<>();
} }
System.out.println("当前模式下的战斗数据:" + srcList.size());
initView(); initView();
return view; return view;
} }
@ -153,21 +152,16 @@ public class WarFragment extends Fragment {
for (int i = 0; i < srcList.size(); i++) { for (int i = 0; i < srcList.size(); i++) {
Map<String, JSONObject> maps = srcList.get(i); Map<String, JSONObject> maps = srcList.get(i);
JSONObject item = maps.get("data"); JSONObject item = maps.get("data");
if(maps.get("DealNode").getString("time").contains("2430")){
System.out.println("此时正是430");
}
if (item == null) { if (item == null) {
return; return;
} }
if(item.getInt("mapId")==999202){
System.out.println("找到活动地图"); System.out.println(">>>>>>"+item.getInt("mapId"));
}
if(Objects.requireNonNull(maps.get("DealNode")).getString("type").equals("DealNode")) { if(Objects.requireNonNull(maps.get("DealNode")).getString("type").equals("DealNode")) {
if (item.getInt("mapId") % 10 == 2) {
getItem(i, srcList); getItem(i, srcList);
} }
} }
}
AppData.handler.post(() -> { AppData.handler.post(() -> {
adapter.clear(); adapter.clear();
adapter.addAll(data); adapter.addAll(data);

View File

@ -52,6 +52,11 @@ public class DaytimeListViewAdapter extends BaseAdapter {
holder = (ViewHolder) view.getTag(); holder = (ViewHolder) view.getTag();
} }
WarData warData = list.get(i); WarData warData = list.get(i);
if(warData.getAttackModel().equals("夜战")&&warData.getUserName()==null){
holder.user.setText("");
holder.arrow.setText("----进入夜战----");
holder.enemy.setText("");
}else {
holder.user.setText(warData.getUserName()); holder.user.setText(warData.getUserName());
holder.arrow.setText("--" + warData.getAttackModel() + "-->"); holder.arrow.setText("--" + warData.getAttackModel() + "-->");
String[] enemyName = warData.getEnemy(); String[] enemyName = warData.getEnemy();
@ -59,8 +64,9 @@ public class DaytimeListViewAdapter extends BaseAdapter {
for (int j = 0; j < enemyName.length; j++) { for (int j = 0; j < enemyName.length; j++) {
name += enemyName[j] + "(-" + warData.getDamage()[j] + "HP)\n"; name += enemyName[j] + "(-" + warData.getDamage()[j] + "HP)\n";
} }
name=name.substring(0,name.length()-1);
holder.enemy.setText(name); holder.enemy.setText(name);
System.out.println(i+" "+list.size()); }
return view; return view;
} }

View File

@ -12,6 +12,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ListView; import android.widget.ListView;
import com.umeng.commonsdk.debug.W;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.Adapters.DaytimeListViewAdapter; import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.Adapters.DaytimeListViewAdapter;
import org.json.JSONArray; import org.json.JSONArray;
@ -19,9 +20,10 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.List; import java.util.List;
public class DaytimeFragment extends Fragment { public class DaytimeFragment extends Fragment implements WarLogInterface{
private ListView listView; private ListView listView;
private DaytimeListViewAdapter adapter; private DaytimeListViewAdapter adapter;
private JSONObject warReport, json; private JSONObject warReport, json;
@ -29,7 +31,7 @@ public class DaytimeFragment extends Fragment {
private static DaytimeFragment daytime; private static DaytimeFragment daytime;
public static DaytimeFragment init() { public static DaytimeFragment getInstance() {
if (daytime == null) { if (daytime == null) {
daytime = new DaytimeFragment(); daytime = new DaytimeFragment();
} }
@ -58,16 +60,16 @@ public class DaytimeFragment extends Fragment {
public void setData(JSONObject json) { public void setData(JSONObject json) {
try { try {
this.json = json; this.json = json;
shipVO = json.getJSONArray("shipVO"); shipVO = new JSONObject(json.getJSONObject("DealNode").getString("message")).getJSONArray("shipVO");
warReport = json.getJSONObject("warReport"); warReport = new JSONObject(json.getJSONObject("DealNode").getString("message")).getJSONObject("warReport");
initData();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
getActivity().finish();
} }
} }
private void initData() { private void initData() {
if(adapter!=null)
adapter.clear();
List<WarData> list = new ArrayList<>(); List<WarData> list = new ArrayList<>();
list.addAll(nextData("openAirAttack", WarData.OPEN_AIR)); list.addAll(nextData("openAirAttack", WarData.OPEN_AIR));
list.addAll(nextData("openMissileAttack", WarData.OPEN_MISSILE)); list.addAll(nextData("openMissileAttack", WarData.OPEN_MISSILE));
@ -77,10 +79,37 @@ public class DaytimeFragment extends Fragment {
list.addAll(nextData("normalAttacks2", WarData.ATTACK_NORMAL_2)); list.addAll(nextData("normalAttacks2", WarData.ATTACK_NORMAL_2));
list.addAll(nextData("closeTorpedoAttack", WarData.CLOSE_TORPEDO)); list.addAll(nextData("closeTorpedoAttack", WarData.CLOSE_TORPEDO));
list.addAll(nextData("closeMissileAttack", WarData.CLOSE_MISSILE)); list.addAll(nextData("closeMissileAttack", WarData.CLOSE_MISSILE));
try {
if (warReport.getInt("canDoNightWar") == 1) {
WarData data = new WarData();
data.setAttackModel(WarData.NIGHT_WAR);
list.add(data);
list.addAll(nightWar());
}
} catch (JSONException e) {
e.printStackTrace();
}
if (adapter != null) if (adapter != null)
adapter.setData(list); adapter.setData(list);
} }
private List<WarData> nightWar() {
List<WarData> list = new ArrayList<>();
try {
JSONArray nightAttacks = new JSONObject(json.getJSONObject("WarReport").getString("message")).getJSONObject("extraProgress").getJSONArray("nightAttacks");
System.out.println("--------->夜战数量:"+nightAttacks.length());
for (int i = 0; i < nightAttacks.length(); i++) {
System.out.println(nightAttacks.getJSONObject(i));
WarData warData=WarData.getInstance(WarData.NIGHT_WAR,nightAttacks.getJSONObject(i),warReport);
System.out.println(warData.toString());
list.add(warData);
}
} catch (Exception e) {
e.printStackTrace();
}
return list;
}
private List<WarData> nextData(String name, int model) { private List<WarData> nextData(String name, int model) {
List<WarData> list = new ArrayList<>(); List<WarData> list = new ArrayList<>();
try { try {

View File

@ -1,6 +1,148 @@
package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments; package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments;
import android.content.Context;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import com.umeng.commonsdk.debug.W;
import com.yutou.jianr_mg.Tools.Utils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
public class NightFragment extends Fragment { public class NightFragment extends Fragment implements WarLogInterface {
private static NightFragment nightFragment;
private JSONObject json;
private JSONArray shipOV;
private ListView list;
private NightFragment() {
}
public static NightFragment getInstance() {
if (nightFragment == null) {
nightFragment = new NightFragment();
}
return nightFragment;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
list = new ListView(getContext());
list.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
list.setAdapter(new ListAdapter(new ArrayList<>()));
return list;
}
private void initData() {
try {
List<ViewGroup> list=new ArrayList<>();
list.add(nextItem("提督名字", json.getJSONObject("detailInfo").getString("username")));
list.add(nextItem("提督等级", json.getJSONObject("detailInfo").getInt("level") + ""));
list.add(nextItem("下一级需要经验", json.getJSONObject("detailInfo").getInt("exp") + ""));
list.add(nextItem("拥有舰娘数", json.getJSONObject("detailInfo").getInt("shipNum") + ""));
try {
list.add(nextItem("打捞", json.getJSONArray("newShipVO").getJSONObject(0).getString("title")));
} catch (Exception ignored) {
}
for (int i = 0; i < shipOV.length(); i++) {
JSONObject selfShipResults = json.getJSONObject("warResult").getJSONArray("selfShipResults").getJSONObject(i);
String mvp = selfShipResults.getInt("isMvp") == 1 ? "(MVP)" : "";
try {
String levelUp="";
if(selfShipResults.getInt("isLevelUp")==1){
levelUp=" UP!!";
}
list.add(nextItem(mvp+shipOV.getJSONObject(i).getString("title") ,
selfShipResults.getInt("exp") + "EXP (+" + selfShipResults.getInt("expAdd") + "exp)"+levelUp));
}catch (Exception e){
list.add(nextItem(shipOV.getJSONObject(i).getString("title") + mvp, "MAX(+" + selfShipResults.getInt("expAdd") + "exp)"));
}
}
((ListAdapter)this.list.getAdapter()).setData(list);
} catch (JSONException e) {
e.printStackTrace();
}
}
private LinearLayout nextItem(String title, String massage) {
TextView titleView = new TextView(getContext());
TextView messageView = new TextView(getContext());
titleView.setText(title + ":");
messageView.setText(massage);
LinearLayout layout = new LinearLayout(getContext());
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Utils.getPixelsFromDp(getActivity(),50));
params.gravity= Gravity.CENTER;
layout.setLayoutParams(params);
layout.setGravity(Gravity.CENTER);
layout.setOrientation(LinearLayout.HORIZONTAL);
layout.addView(titleView);
layout.addView(messageView);
return layout;
}
@Override
public void setData(JSONObject json) {
try {
this.json = new JSONObject(json.getJSONObject("WarReport").getString("message"));
shipOV= new JSONObject(json.getJSONObject("DealNode").getString("message")).getJSONObject("warReport").getJSONArray("selfShips");
initData();
} catch (JSONException e) {
e.printStackTrace();
}
}
private class ListAdapter extends BaseAdapter {
private List<ViewGroup> list;
public ListAdapter(List<ViewGroup> list) {
this.list = list;
}
@Override
public int getCount() {
return list.size();
}
@Override
public Object getItem(int position) {
return list.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
return list.get(position);
}
public void setData(List<ViewGroup> list) {
this.list=list;
notifyDataSetChanged();
}
}
} }

View File

@ -5,6 +5,8 @@ import com.umeng.commonsdk.debug.W;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Arrays;
public class WarData { public class WarData {
public final static int OPEN_AIR = 0; public final static int OPEN_AIR = 0;
public final static int OPEN_MISSILE = 1; public final static int OPEN_MISSILE = 1;
@ -14,6 +16,7 @@ public class WarData {
public final static int ATTACK_NORMAL_2 = 5; public final static int ATTACK_NORMAL_2 = 5;
public final static int CLOSE_TORPEDO = 6; public final static int CLOSE_TORPEDO = 6;
public final static int CLOSE_MISSILE = 7; public final static int CLOSE_MISSILE = 7;
public final static int NIGHT_WAR = 8;
private String title; private String title;
private String userName; private String userName;
private long cid; private long cid;
@ -50,6 +53,9 @@ public class WarData {
case WarData.CLOSE_MISSILE: case WarData.CLOSE_MISSILE:
model = "闭幕导弹"; model = "闭幕导弹";
break; break;
case WarData.NIGHT_WAR:
model = "夜战";
break;
default: default:
model = "未知攻击"; model = "未知攻击";
} }
@ -115,29 +121,44 @@ public class WarData {
public void setDamage(int[] damage) { public void setDamage(int[] damage) {
this.damage = damage; this.damage = damage;
} }
public static WarData getInstance(int attackModel,JSONObject json,JSONObject warReport){
WarData warData=null; public static WarData getInstance(int attackModel, JSONObject json, JSONObject warReport) {
try{ WarData warData = null;
warData=new WarData(); try {
warData.userAttack= json.getInt("attackSide") == 1; warData = new WarData();
JSONArray array=warData.isUserAttack()?warReport.getJSONArray("selfShips"):warReport.getJSONArray("enemyShips"); warData.userAttack = json.getInt("attackSide") == 1;
JSONArray array = warData.isUserAttack() ? warReport.getJSONArray("selfShips") : warReport.getJSONArray("enemyShips");
warData.setUserName(array.getJSONObject(json.getInt("fromIndex")).getString("title")); warData.setUserName(array.getJSONObject(json.getInt("fromIndex")).getString("title"));
warData.setCid(array.getJSONObject(json.getInt("fromIndex")).getLong("shipCid")); warData.setCid(array.getJSONObject(json.getInt("fromIndex")).getLong("shipCid"));
int[] damages=new int[json.getJSONArray("damages").length()]; int[] damages = new int[json.getJSONArray("damages").length()];
for (int i = 0; i < json.getJSONArray("damage").length(); i++) { for (int i = 0; i < json.getJSONArray("damage").length(); i++) {
damages[i]=json.getJSONArray("damage").getInt(i); damages[i] = json.getJSONArray("damage").getInt(i);
} }
warData.setDamage(damages); warData.setDamage(damages);
String[] enemyNames=new String[json.getJSONArray("targetIndex").length()]; String[] enemyNames = new String[json.getJSONArray("targetIndex").length()];
array=!warData.isUserAttack()?warReport.getJSONArray("selfShips"):warReport.getJSONArray("enemyShips"); array = !warData.isUserAttack() ? warReport.getJSONArray("selfShips") : warReport.getJSONArray("enemyShips");
for (int i = 0; i < json.getJSONArray("targetIndex").length(); i++) { for (int i = 0; i < json.getJSONArray("targetIndex").length(); i++) {
enemyNames[i]=array.getJSONObject(json.getJSONArray("targetIndex").getInt(i)).getString("title"); enemyNames[i] = array.getJSONObject(json.getJSONArray("targetIndex").getInt(i)).getString("title");
} }
warData.setEnemy(enemyNames); warData.setEnemy(enemyNames);
warData.setAttackModel(attackModel); warData.setAttackModel(attackModel);
}catch (Exception e){ } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return warData; return warData;
} }
@Override
public String toString() {
return "WarData{" +
"title='" + title + '\'' +
", userName='" + userName + '\'' +
", cid=" + cid +
", fromIndex=" + fromIndex +
", enemy=" + Arrays.toString(enemy) +
", damage=" + Arrays.toString(damage) +
", userAttack=" + userAttack +
", attackModel=" + attackModel +
'}';
}
} }

View File

@ -0,0 +1,7 @@
package com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments;
import org.json.JSONObject;
public interface WarLogInterface {
void setData(JSONObject json);
}

View File

@ -6,10 +6,10 @@ package com.yutou.jianr_mg.Network;
public class HttpApi { public class HttpApi {
//public static final String HOME="http://jianr.jianrmod.cn/"; //public static final String HOME="http://jianr.jianrmod.cn/";
//public static final String HOME = "http://192.168.31.240:8088/"; //zzz_gz wifi public static final String HOME = "http://192.168.31.92:8080/"; //zzz_gz wifi
// public static final String HOME = "http://192.168.43.68:8088/"; //zzz_gz wifi // public static final String HOME = "http://192.168.43.68:8088/"; //zzz_gz wifi
//public static final String HOME = "http://192.168.137.1:8088/"; //笔记本本身WIFI //public static final String HOME = "http://192.168.137.1:8088/"; //笔记本本身WIFI
public static final String HOME = "http://192.168.1.151:8080/"; //公司 // public static final String HOME = "http://192.168.1.151:8080/"; //公司
public static final String HOME_URL=HOME+"android/"; //服务器 public static final String HOME_URL=HOME+"android/"; //服务器
public static final String MOD_ALL = "mod/all.do"; public static final String MOD_ALL = "mod/all.do";

View File

@ -9,10 +9,10 @@ import androidx.appcompat.app.AppCompatActivity;
import com.yutou.jianr_mg.Adapters.ViewPagerAdapter; import com.yutou.jianr_mg.Adapters.ViewPagerAdapter;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.DaytimeFragment; import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.DaytimeFragment;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.NightFragment; import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.NightFragment;
import com.yutou.jianr_mg.Fragments.GameDataFragments.WarLogFragments.WarLogInterface;
import com.yutou.jianr_mg.R; import com.yutou.jianr_mg.R;
import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
@ -51,26 +51,20 @@ public class WarLogActivity extends AppCompatActivity {
tab = findViewById(R.id.tab); tab = findViewById(R.id.tab);
pager = findViewById(R.id.pager); pager = findViewById(R.id.pager);
List<Fragment> list = new ArrayList<>(); List<Fragment> list = new ArrayList<>();
list.add(DaytimeFragment.init()); list.add(DaytimeFragment.getInstance());
list.add(new NightFragment()); list.add(NightFragment.getInstance());
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), list); ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager(), list);
pager.setAdapter(adapter); pager.setAdapter(adapter);
pager.setCurrentItem(0); pager.setCurrentItem(0);
navigationController = tab.material() navigationController = tab.material()
.addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "战斗过程") .addItem(R.drawable.icon_daytime, R.drawable.icon_daytime_select, "战斗过程")
.addItem(R.drawable.icon_night, R.drawable.icon_night_select, "战斗结束") .addItem(R.drawable.icon_night, R.drawable.icon_night_select, "战斗报告")
.build(); .build();
navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() { navigationController.addTabItemSelectedListener(new OnTabItemSelectedListener() {
@Override @Override
public void onSelected(int index, int old) { public void onSelected(int index, int old) {
pager.setCurrentItem(index); pager.setCurrentItem(index);
if(index==0){ ((WarLogInterface)list.get(index)).setData(json);
try {
((DaytimeFragment)list.get(index)).setData(new JSONObject(json.getJSONObject("DealNode").getString("message")));
} catch (JSONException e) {
e.printStackTrace();
}
}
} }
@Override @Override
@ -80,11 +74,8 @@ public class WarLogActivity extends AppCompatActivity {
}); });
navigationController.setupWithViewPager(pager); navigationController.setupWithViewPager(pager);
navigationController.setSelect(0); navigationController.setSelect(0);
try {//message //message
((DaytimeFragment)list.get(0)).setData(new JSONObject(json.getJSONObject("DealNode").getString("message"))); ((WarLogInterface)list.get(0)).setData(json);
} catch (JSONException e) {
e.printStackTrace();
}
} }
} }