删除打怪兽代码

This commit is contained in:
oujunhui
2020-08-10 12:51:17 +08:00
parent 68273056e7
commit 087feb17ea
4 changed files with 1 additions and 714 deletions

View File

@@ -762,13 +762,7 @@
android:name=".decoration.view.MyDecorationActivity"
android:label="座驾"
android:screenOrientation="portrait" />
<activity
android:name=".monsterhunting.MonsterHuntingActivity"
android:hardwareAccelerated="true"
android:label="打怪兽"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:theme="@style/TranslucentTheme" />
<activity
android:name=".decoration.view.DecorationStoreActivity"
android:screenOrientation="portrait"

View File

@@ -52,7 +52,6 @@ import com.yizhuan.erban.common.widget.CircleImageView;
import com.yizhuan.erban.common.widget.CustomImageSpan;
import com.yizhuan.erban.common.widget.dialog.DialogManager;
import com.yizhuan.erban.home.adapter.FragmentViewPagerAdapter;
import com.yizhuan.erban.monsterhunting.MonsterHuntingActivity;
import com.yizhuan.erban.ui.patriarch.help.LimitEnterRoomHelper;
import com.yizhuan.erban.ui.pay.ChargeActivity;
import com.yizhuan.erban.ui.user.UserInfoActivity;
@@ -871,7 +870,6 @@ public class AVRoomActivity extends BaseMvpActivity<IAvRoomView, AvRoomPresenter
if (monsterDialog != null && monsterDialog.isShowing()) {
monsterDialog.dismiss();
}
MonsterHuntingActivity.start(this);
}
break;
}

View File

@@ -1,700 +0,0 @@
package com.yizhuan.erban.monsterhunting;
import android.content.Context;
import android.content.Intent;
import android.os.CountDownTimer;
import androidx.recyclerview.widget.LinearLayoutManager;
import android.util.Log;
import android.view.View;
import com.yizhuan.erban.R;
import com.yizhuan.erban.avroom.widget.GiftV2View;
import com.yizhuan.erban.base.BaseBindingActivity;
import com.yizhuan.erban.databinding.ActivityMonsterHuntingBinding;
import com.yizhuan.erban.monsterhunting.bean.UpdateMyGoldInfo;
import com.yizhuan.erban.monsterhunting.bean.AttackMonsterResultInfo;
import com.yizhuan.erban.monsterhunting.viewmodel.MonsterHuntingViewModel;
import com.yizhuan.erban.ui.pay.ChargeActivity;
import com.yizhuan.erban.ui.widget.MagicAdapter;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.event.KickOutEvent;
import com.yizhuan.xchat_android_core.magic.MagicModel;
import com.yizhuan.xchat_android_core.magic.bean.MagicInfo;
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
import com.yizhuan.xchat_android_core.manager.RoomEvent;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterAttackInfo;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterEvent;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterHuntingResult;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterInfo;
import com.yizhuan.xchat_android_core.monsterhunting.bean.MonsterProtocol;
import com.yizhuan.xchat_android_core.monsterhunting.manager.MonsterDataManager;
import com.yizhuan.xchat_android_core.pay.bean.WalletInfo;
import com.yizhuan.xchat_android_core.statistic.LogFactory;
import com.yizhuan.xchat_android_core.statistic.StatisticManager;
import com.yizhuan.xchat_android_core.statistic.protocol.LogProtocol;
import com.yizhuan.xchat_android_library.annatation.ActLayoutRes;
import com.yizhuan.xchat_android_library.utils.JavaUtil;
import com.yizhuan.xchat_android_library.utils.ListUtils;
import com.yizhuan.xchat_android_library.utils.SingleToastUtil;
import com.yizhuan.xchat_android_library.utils.TimeUtils;
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_NOTI_SUB_GAME_END;
import static com.yizhuan.xchat_android_core.im.custom.bean.CustomAttachment.CUSTOM_NOTI_SUB_GAME_RESULT;
/**
* Created by MadisonRong on 29/03/2018.
*/
@ActLayoutRes(R.layout.activity_monster_hunting)
public class MonsterHuntingActivity extends BaseBindingActivity<ActivityMonsterHuntingBinding> {
private static final String TAG = "MonsterHuntingActivity";
private MonsterHuntingViewModel viewModel;
private double mGoldNum;
private GiftV2View giftView;
private MagicAdapter mMagicAdapter;
private volatile int monsterTotalBlood = 10;
private volatile int monsterRemainBlood = 10;
private CountDownTimer countDownTimer;
private volatile int sequence;
private volatile int currentMonsterStatus = MonsterInfo.MONSTER_STATUS_DID_APPEAR;
private volatile MonsterHuntingRewardDialog monsterHuntingRewardDialog;
private volatile MonsterEscapeDialog monsterEscapeDialog;
private volatile long beforeDisappearSeconds = 0;
private List<MonsterAttackInfo> infoList;
private Disposable subscribe;
public static void start(Context context) {
context.startActivity(new Intent(context, MonsterHuntingActivity.class));
}
@Override
protected void init() {
initial();
IMNetEaseManager.get().getChatRoomEventObservable()
.compose(bindToLifecycle())
.subscribe(this::onReceiveRoomEvent);
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.compose(bindToLifecycle())
.subscribe(this::onReceiveMonsterEvent);
EventBus.getDefault().register(this);
}
@Override
protected void onResume() {
super.onResume();
MonsterInfo monsterInfo = MonsterDataManager.get().getCurrentRoomMonsterInfo();
if (monsterInfo.getMonsterStatus() != MonsterInfo.MONSTER_STATUS_DID_APPEAR) {
finish();
}
if (beforeDisappearSeconds == 0){
finish();
}
intervalAttack();
sequence = 0;
// 自动打怪代码,需要的时候就打开注释运行程序
// Observable.interval(250, TimeUnit.MILLISECONDS)
// .compose(bindToLifecycle())
// .observeOn(AndroidSchedulers.mainThread())
// .subscribe(integer -> {
// if (magicLayout.getVisibility() == View.VISIBLE) {
// magicRecyclerView.smoothScrollToPosition(new Random().nextInt(mMagicAdapter.getItemCount()));
// magicRecyclerView.getChildAt(new Random().nextInt(magicRecyclerView.getChildCount())).performClick();
// tvSendMagic.performClick();
// }
// });
}
private void intervalAttack() {
subscribe = Observable.interval(200, TimeUnit.MILLISECONDS)
.compose(bindToLifecycle())
.observeOn(AndroidSchedulers.mainThread())
.filter(aLong -> infoList != null && infoList.size() > 0)
.flatMap(aLong -> {
return Observable.just(infoList.get(0));
}).subscribe(monsterAttackInfo -> {
if (monsterAttackInfo != null) {
giftView.onReceiveMonsterAttackMsg(monsterAttackInfo, mBinding.rlMonsterLayout);
infoList.remove(0);
}
}, throwable -> {
intervalAttack();
});
}
private void onReceiveMonsterEvent(MonsterEvent monsterEvent) {
if (monsterEvent == null) return;
switch (monsterEvent.getEvent()) {
case MonsterEvent.ANIMATION_LOADED:
// 资源加载完毕,关掉 loading
getDialogManager().dismissDialog();
// 开始 MonsterLayout 的进场动画
MonsterHuntingAnimationManager.get().monsterLayoutShowIn(this, mBinding.rlMonsterLayout);
break;
case MonsterEvent.MONSTER_APPEAR_ANIMATION_FINISHED:
case MonsterEvent.MONSTER_ATTACK_ANIMATION_FINISHED:
MonsterHuntingSvgaManager.get().displayNormalAnimation();
// monsterLayout 的进场动画结束,开始 monsterInfoLayout 的进场动画
MonsterHuntingAnimationManager.get().monsterInfoLayoutShowIn(this, mBinding.rlMonsterInfo);
break;
case MonsterEvent.MONSTER_DEFAT_ANIMATION_START:
// 结束倒计时
if (infoList != null) {
infoList.clear();
}
if (subscribe != null) {
subscribe.dispose();
}
cancelTimer();
// 收起其他控件
MonsterHuntingAnimationManager.get().monsterInfoLayoutShowOut(this, mBinding.rlMonsterInfo);
MonsterHuntingAnimationManager.get().magicLayoutShowOut(this, mBinding.rlDialogBottomMagic);
MonsterHuntingAnimationManager.get().countDownTimerShowOut(this, mBinding.tvCountdown);
MonsterHuntingAnimationManager.get().closeImgShowOut(this, mBinding.ivMonsterHuntingExit);
MonsterHuntingSvgaManager.get().displayDefeatAnimation();
break;
case MonsterEvent.MONSTER_DEFEAT_ANIMATION_FINISHED:
// 怪兽被打爆后,展示抽奖动画
MonsterHuntingSvgaManager.get().displayDrawAnimation();
break;
case MonsterEvent.MONSTER_LOTTERY_ANIMATION_FINISHED:
// 结束倒计时
cancelTimer();
// 收起其他控件
MonsterHuntingAnimationManager.get().monsterLayoutShowOut(this, mBinding.rlMonsterLayout);
// 展示抽奖结果
if (monsterHuntingRewardDialog == null) {
monsterHuntingRewardDialog = new MonsterHuntingRewardDialog();
monsterHuntingRewardDialog.show(getSupportFragmentManager());
currentMonsterStatus = MonsterInfo.MONSTER_RESULT_SHOWN;
}
break;
case MonsterEvent.MONSTER_HUNTING_TIME_OUT:
// 结束倒计时
cancelTimer();
// 收起其他控件
MonsterHuntingAnimationManager.get().monsterLayoutShowOut(this, mBinding.rlMonsterLayout);
MonsterHuntingAnimationManager.get().monsterInfoLayoutShowOut(this, mBinding.rlMonsterInfo);
MonsterHuntingAnimationManager.get().magicLayoutShowOut(this, mBinding.rlDialogBottomMagic);
MonsterHuntingAnimationManager.get().countDownTimerShowOut(this, mBinding.tvCountdown);
MonsterHuntingAnimationManager.get().closeImgShowOut(this, mBinding.ivMonsterHuntingExit);
// 怪兽逃跑了
if (monsterEscapeDialog == null) {
monsterEscapeDialog = new MonsterEscapeDialog();
monsterEscapeDialog.show(getSupportFragmentManager());
}
break;
case MonsterEvent.MONSTER_LAYOUT_SHOW_IN_ANIMATION_START:
mBinding.rlMonsterLayout.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_LAYOUT_SHOW_OUT_ANIMATION_FINISHED:
mBinding.rlMonsterLayout.setVisibility(View.INVISIBLE);
break;
case MonsterEvent.MONSTER_LAYOUT_SHOW_IN_ANIMATION_FINISHED:
MonsterInfo monsterInfo = MonsterDataManager.get().getCurrentRoomMonsterInfo();
if (monsterInfo.getAppearTime() + 5 * 1000 > monsterInfo.getServerTime()) {
// 如果打怪兽刚开始,则播放进场动画
// 同时开始怪兽的进场动画
MonsterHuntingSvgaManager.get().displayAppearAnimation();
} else {
// 否则直接显示怪兽
MonsterHuntingSvgaManager.get().displayNormalAnimation();
// monsterLayout 的进场动画结束,开始 monsterInfoLayout 的进场动画
MonsterHuntingAnimationManager.get().monsterInfoLayoutShowIn(this, mBinding.rlMonsterInfo);
}
break;
case MonsterEvent.MONSTER_INFO_LAYOUT_SHOW_IN_ANIMATION_START:
mBinding.rlMonsterInfo.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_INFO_LAYOUT_SHOW_OUT_ANIMATION_FINISHED:
mBinding.rlMonsterInfo.setVisibility(View.INVISIBLE);
break;
case MonsterEvent.MONSTER_INFO_LAYOUT_SHOW_IN_ANIMATION_FINISHED:
// monsterInfoLayout 的进场动画结束,
// 开始 magicLayout, countDownTimer 和 closeImg 的进场动画
MonsterHuntingAnimationManager.get().magicLayoutShowIn(this, mBinding.rlDialogBottomMagic);
MonsterHuntingAnimationManager.get().countDownTimerShowIn(this, mBinding.tvCountdown);
MonsterHuntingAnimationManager.get().closeImgShowIn(this, mBinding.ivMonsterHuntingExit);
break;
case MonsterEvent.MONSTER_MAGIC_LAYOUT_SHOW_IN_ANIMATION_START:
mBinding.rlDialogBottomMagic.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_MAGIC_LAYOUT_SHOW_OUT_ANIMATION_FINISHED:
mBinding.rlDialogBottomMagic.setVisibility(View.INVISIBLE);
break;
case MonsterEvent.MONSTER_COUNT_DOWN_SHOW_IN_ANIMATION_START:
mBinding.tvCountdown.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_COUNT_DOWN_SHOW_OUT_ANIMATION_FINISHED:
mBinding.tvCountdown.setVisibility(View.INVISIBLE);
break;
case MonsterEvent.MONSTER_CLOSE_SHOW_IN_ANIMATION_START:
mBinding.ivMonsterHuntingExit.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_CLOSE_SHOW_OUT_ANIMATION_FINISHED:
mBinding.ivMonsterHuntingExit.setVisibility(View.INVISIBLE);
break;
case MonsterEvent.MONSTER_IMPACT_SHOW_OUT_ANIMATION_START:
// impactValueView.setVisibility(View.VISIBLE);
break;
case MonsterEvent.MONSTER_IMPACT_SHOW_OUT_ANIMATION_FINISHED:
// impactValueView.setVisibility(View.INVISIBLE);
break;
}
}
private void cancelTimer() {
if (countDownTimer != null) {
countDownTimer.cancel();
}
}
private void onReceiveRoomEvent(RoomEvent roomEvent) {
if (roomEvent == null) return;
int event = roomEvent.getEvent();
switch (event) {
case RoomEvent.MONSTER_HUNTING:
if (mBinding.rlMonsterLayout.getVisibility() == View.VISIBLE) {
// 当怪兽显示时才出现发魔法的动画
onReceiveMagicMsg(roomEvent.getMonsterAttackReceiveInfo());
//每次攻击怪兽打log到阿里云
MonsterAttackInfo monsterAttackInfo = roomEvent.getMonsterAttackReceiveInfo();
StatisticManager.Instance().sendAliyunLog(LogFactory.create(
LogProtocol.LogLevel.LEVEL_VERBOSE,
LogProtocol.Topic.TOPIC_BUSINESS_LOG,
LogProtocol.Event.EVENT_MONSTER_ONGOING_MONSTER
).append(LogProtocol.CommonKey.KEY_UID.getName(), String.valueOf(AuthModel.get().getCurrentUid()))
.append("monsterId", String.valueOf(monsterAttackInfo.getMonsterId()))
.append("remainBlood", String.valueOf(monsterAttackInfo.getMonsterRemainBlood()))
.append("beforeDisappearSeconds", String.valueOf(JavaUtil.str2long(monsterAttackInfo.getRemainMills()) / 1000.0f)));
}
break;
case RoomEvent.MONSTER_HUNTING_ANIMATION_FINISHED:
// onReceiveMagicAnimationFinishedMsg(roomEvent.getMonsterAttackReceiveInfo());
displayImpactAnimation(roomEvent.getMonsterAttackReceiveInfo().getImpactValue());
break;
case RoomEvent.WALLET_UPDATE:
break;
case RoomEvent.MONSTER_STATUS_CHANGED:
MonsterProtocol.DataBean dataBean = roomEvent.getMonsterStatusAttachment().getDataBean();
Log.e(TAG, "onResume room event: " + dataBean);
// 判断是否为当前房间的怪兽消息
if (Objects.equals(MonsterDataManager.get().getCurrentRoomMonsterInfo().getAppearRoomUid(),
dataBean.getAppearRoomUid())) {
switch (dataBean.getMonsterStatus()) {
case MonsterInfo.MONSTER_STATUS_DID_DEAD:
switch (roomEvent.getMonsterStatusAttachment().getSecond()) {
case CUSTOM_NOTI_SUB_GAME_END:
if (currentMonsterStatus == MonsterInfo.MONSTER_STATUS_DID_APPEAR) {
manualShowDefeatAnimation();
}
break;
}
break;
case MonsterInfo.MONSTER_STATUS_DID_LEAVE:
if (currentMonsterStatus == MonsterInfo.MONSTER_STATUS_DID_APPEAR) {
manualShowEscapeAnimation();
}
break;
}
}
break;
case RoomEvent.MONSTER_HUNTING_RESULT:
MonsterHuntingResult result = roomEvent.getMonsterHuntingResultAttachment().getResult();
Log.e(TAG, "onResume: room event monster result: " + result);
// 判断是否为当前房间的怪兽消息
if (Objects.equals(MonsterDataManager.get().getCurrentRoomMonsterInfo().getAppearRoomUid(),
result.getMonster().getAppearRoomUid())) {
switch (result.getMonster().getMonsterStatus()) {
case MonsterInfo.MONSTER_STATUS_DID_DEAD:
switch (roomEvent.getMonsterHuntingResultAttachment().getSecond()) {
case CUSTOM_NOTI_SUB_GAME_RESULT:
if (currentMonsterStatus == MonsterInfo.MONSTER_STATUS_DID_DEAD) {
//怪兽结果 打log 到 阿里云
StatisticManager.Instance().sendAliyunLog(LogFactory.create(
LogProtocol.LogLevel.LEVEL_VERBOSE,
LogProtocol.Topic.TOPIC_BUSINESS_LOG,
LogProtocol.Event.EVENT_MONSTER_GAME_RESULT
).append(LogProtocol.CommonKey.KEY_UID.getName(), String.valueOf(AuthModel.get().getCurrentUid()))
.append("monsterId", String.valueOf(MonsterDataManager.get().getCurrentRoomMonsterInfo().getMonsterId()))
.append("monsterStatus", String.valueOf(result.getMonster().getMonsterStatus()))
.append("luckMan_erbanNo", String.valueOf(result.getLuckyDog().getErbanNo())));
// 奖励结果出来了
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_LOTTERY_ANIMATION_FINISHED));
}
break;
}
break;
}
}
break;
case RoomEvent.KICK_OUT_ROOM:
finish();
break;
case RoomEvent.ADD_BLACK_LIST:
String account = roomEvent.getAccount();
if (Objects.equals(account,
String.valueOf(AuthModel.get().getCurrentUid()))) {
finish();
}
break;
}
}
private void manualShowDefeatAnimation() {
currentMonsterStatus = MonsterInfo.MONSTER_STATUS_DID_DEAD;
// 怪兽已经挂了
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_DEFAT_ANIMATION_START));
}
private void manualShowEscapeAnimation() {
currentMonsterStatus = MonsterInfo.MONSTER_STATUS_DID_LEAVE;
// 怪兽逃跑了
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_HUNTING_TIME_OUT)
.setType(MonsterEvent.TYPE_BROADCAST));
}
@Override
protected void onPause() {
super.onPause();
}
@Override
protected void onDestroy() {
super.onDestroy();
cancelTimer();
// 释放 SvgaManager避免内存泄露
MonsterHuntingSvgaManager.get().release();
EventBus.getDefault().unregister(this);
}
private void initial() {
viewModel = new MonsterHuntingViewModel();
viewModel.attackMonsterResultInfo.addOnPropertyChangedCallback(new androidx.databinding.Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(androidx.databinding.Observable sender, int propertyId) {
AttackMonsterResultInfo resultInfo = (AttackMonsterResultInfo) sender;
switch (resultInfo.getStatus()){
case 1:
if (resultInfo.getMonsterAttackInfo() != null)
attackMonsterSuccess(resultInfo.getMonsterAttackInfo());
break;
case 2:
attackMonsterFail(resultInfo.getCode(), resultInfo.getErrorMessage());
break;
case 3:
attackMonsterFail(-1, resultInfo.getErrorMessage());
break;
default:
break;
}
}
});
viewModel.updateMyGoldInfo.addOnPropertyChangedCallback(new androidx.databinding.Observable.OnPropertyChangedCallback() {
@Override
public void onPropertyChanged(androidx.databinding.Observable sender, int propertyId) {
UpdateMyGoldInfo updateInfo = (UpdateMyGoldInfo) sender;
if (updateInfo.isSucceed()) {
updateMyGoldInternal(updateInfo.getWalletInfo());
} else {
updateMyGoldInternalFail();
}
}
});
mBinding.rlMonsterImpactValue.getAnimator().getmConfig().initX = mBinding.roomMonsterSvga.getWidth() / 2;
mBinding.rlMonsterImpactValue.getAnimator().getmConfig().initY = mBinding.roomMonsterSvga.getHeight() / 2;
mBinding.ivMonsterHuntingExit.setOnClickListener(this);
mBinding.tvCharge.setOnClickListener(this);
mBinding.tvSend.setOnClickListener(this);
mBinding.ivMonsterHuntingIntroduction.setOnClickListener(this);
MonsterInfo monsterInfo = MonsterDataManager.get().getCurrentRoomMonsterInfo();
beforeDisappearSeconds = monsterInfo.getBeforeDisappearSeconds();
if (monsterInfo != null) {
switch (monsterInfo.getMonsterStatus()) {
case MonsterInfo.MONSTER_STATUS_DID_APPEAR:
if (monsterInfo.getBeforeDisappearSeconds() > 0) {
// 初始化 SVGA parser
MonsterHuntingSvgaManager.get().initParser(this, mBinding.roomMonsterSvga);
// 预加载 SVGA 资源
MonsterHuntingSvgaManager.get().preLoadMonsterAnimation(
monsterInfo.getAppearSvg(),
monsterInfo.getNormalSvg(),
monsterInfo.getAttackSvg(),
monsterInfo.getDefeatSvg());
// 更新自己的钻石
viewModel.updateMyGold();
// 更新魔法礼物列表
updateMagicList();
// 根据怪兽状态显示 UI
updateMonsterInfo(monsterInfo);
} else {
finish();
}
break;
case MonsterInfo.MONSTER_STATUS_DID_DEAD:
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_DEFAT_ANIMATION_START)
.setType(MonsterEvent.TYPE_ALREADY_FINISHED));
break;
case MonsterInfo.MONSTER_STATUS_DID_LEAVE:
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_HUNTING_TIME_OUT)
.setType(MonsterEvent.TYPE_ALREADY_FINISHED));
break;
}
}
getDialogManager().showProgressDialog(this, "怪兽加载中",
false, true, null, dialog -> finish());
}
private void updateMagicList() {
MagicModel.get().getRemoteMagicList().subscribe((magicInfos, throwable) -> {
if (!ListUtils.isListEmpty(magicInfos)) {
for (MagicInfo magicInfo : magicInfos) {
magicInfo.setMagicType(MagicInfo.MONSTER_MAGIC);
}
mMagicAdapter = new MagicAdapter(this, magicInfos);
mBinding.recyclerViewMagic.setAdapter(mMagicAdapter);
mBinding.recyclerViewMagic.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
} else if (throwable != null) {
// Toast.makeText(this, "获取魔法列表失败,请重试!", Toast.LENGTH_SHORT).show();
SingleToastUtil.showToastShort("获取魔法列表失败,请重试!");
}
});
}
private void updateMyGoldInternal(WalletInfo walletInfo) {
mGoldNum = walletInfo.getDiamondNum();
mBinding.tvGold.setText(this.getResources().getString(R.string.gold_num_text, mGoldNum));
}
private void updateMyGoldInternalFail() {
// Toast.makeText(this, "获取钻石失败,请重试!", Toast.LENGTH_SHORT).show();
SingleToastUtil.showToastShort("获取钻石失败,请重试!");
}
private void updateMonsterInfo(MonsterInfo monsterInfo) {
mBinding.tvMonsterName.setText(monsterInfo.getMonsterName());
monsterTotalBlood = monsterInfo.getTotalBlood();
mBinding.tvMonsterTotalHp.setText(String.valueOf(monsterTotalBlood));
monsterRemainBlood = monsterInfo.getRemainBlood();
mBinding.tvMonsterHp.setText(String.valueOf(monsterRemainBlood));
mBinding.pbMonsterHp.setMax(monsterTotalBlood);
mBinding.pbMonsterHp.setProgress(monsterRemainBlood);
long timeLeft = monsterInfo.getBeforeDisappearSeconds();
countDownTimer = new CountDownTimer(
timeLeft * 1000,
1000) {
@Override
public void onTick(long millisUntilFinished) {
beforeDisappearSeconds--;
mBinding.tvCountdown.setText(TimeUtils.ms2MS(millisUntilFinished));
}
@Override
public void onFinish() {
beforeDisappearSeconds = 0;
mBinding.tvCountdown.setText("00:00");
MonsterHuntingAnimationManager.get().getMonsterEventObservable()
.onNext(new MonsterEvent(MonsterEvent.MONSTER_HUNTING_TIME_OUT));
}
};
countDownTimer.start();
}
@Override
public void onBackPressed() {
MonsterInfo monsterInfo = MonsterDataManager.get().getCurrentRoomMonsterInfo();
switch (monsterInfo.getMonsterStatus()) {
case MonsterInfo.MONSTER_STATUS_DID_DEAD:
case MonsterInfo.MONSTER_STATUS_DID_LEAVE:
super.onBackPressed();
Log.e(TAG, "onBackPressed: ");
break;
case MonsterInfo.MONSTER_STATUS_DID_APPEAR:
new QuitConfirmDialog().show(getSupportFragmentManager());
break;
}
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.iv_monster_hunting_exit:
new QuitConfirmDialog().show(getSupportFragmentManager());
break;
case R.id.iv_monster_hunting_introduction:
new MonsterHuntingIntroductionDialog().show(getSupportFragmentManager());
break;
case R.id.tv_charge:
ChargeActivity.start(this);
break;
case R.id.tv_send:
if (mMagicAdapter != null && mMagicAdapter.getItemCount() > 0 &&
monsterRemainBlood > 0) {
MonsterInfo monsterInfo = MonsterDataManager.get().getCurrentRoomMonsterInfo();
attackMonster(monsterInfo);
}
break;
}
}
private void attackMonster(MonsterInfo monsterInfo) {
viewModel.attackMonster(String.valueOf(monsterInfo.getMonsterId()),
String.valueOf(monsterInfo.getAppearRoomUid()),
String.valueOf(mMagicAdapter.getCurrentMagicInfo().getMagicId()));
}
private void attackMonsterSuccess(MonsterAttackInfo monsterAttackInfo) {
// 设置魔法底图,动画时候显示使用
monsterAttackInfo.setMagicIcon(mMagicAdapter.getCurrentMagicInfo().getIcon());
}
private void attackMonsterFail(int code, String errorMsg) {
switch (code) {
case 6502:
toast(errorMsg);
monsterRemainBlood = 0;
displayImpactAnimation(mBinding.pbMonsterHp.getProgress());
mBinding.pbMonsterHp.incrementProgressBy(monsterRemainBlood - mBinding.pbMonsterHp.getProgress());
mBinding.tvMonsterHp.setText(String.valueOf(monsterRemainBlood));
// 怪兽已被打败,清空缓存队列
infoList.clear();
if (subscribe != null) {
subscribe.dispose();
}
manualShowDefeatAnimation();
break;
case 6503:
toast(errorMsg);
cancelTimer();
manualShowEscapeAnimation();
break;
default:
toast(errorMsg);
}
}
public void onReceiveMagicMsg(MonsterAttackInfo monsterAttackReceiveInfo) {
if (monsterAttackReceiveInfo == null || currentMonsterStatus != MonsterInfo.MONSTER_STATUS_DID_APPEAR)
return;
if (giftView == null) {
giftView = (GiftV2View) mBinding.vsMagicView.getViewStub().inflate();
}
if (infoList == null) {
infoList = new ArrayList<>();
}
if (infoList.size() > 200) {
Iterator<MonsterAttackInfo> iterator = infoList.iterator();
for (int i = 0; i < 50; i++) {
if (iterator.hasNext()) {
iterator.next();
iterator.remove();
}
}
}
if (monsterAttackReceiveInfo.getUid().equals(AuthModel.get().getCurrentUid() + "")) {
giftView.onReceiveMonsterAttackMsg(monsterAttackReceiveInfo, mBinding.rlMonsterLayout);
} else {
infoList.add(monsterAttackReceiveInfo);
}
onReceiveMagicAnimationFinishedMsg(monsterAttackReceiveInfo);
}
public void onReceiveMagicAnimationFinishedMsg(MonsterAttackInfo monsterAttackReceiveInfo) {
updateRemainBlood(monsterAttackReceiveInfo);
}
private void updateRemainBlood(MonsterAttackInfo monsterAttackReceiveInfo) {
if (sequence <= monsterAttackReceiveInfo.getSequence()) {
sequence = monsterAttackReceiveInfo.getSequence();
monsterRemainBlood = Integer.parseInt(monsterAttackReceiveInfo.getMonsterRemainBlood());
Log.e(TAG, String.format(Locale.getDefault(), "attackMonsterSuccess: monsterTotalBlood: %s, monsterRemainBlood: %s",
monsterTotalBlood, monsterRemainBlood));
mBinding.pbMonsterHp.incrementProgressBy(monsterRemainBlood - mBinding.pbMonsterHp.getProgress());
mBinding.tvMonsterHp.setText(String.valueOf(monsterRemainBlood));
if (monsterRemainBlood == 0) {
manualShowDefeatAnimation();
}
}
}
private void displayImpactAnimation(int impactValue) {
mBinding.rlMonsterImpactValue.addImpact(impactValue);
}
@Subscribe(threadMode = ThreadMode.MAIN)
public void onKickedOutEvent(KickOutEvent event) {
// 被踢下线,直接退出该页面
finish();
}
}

View File

@@ -18,11 +18,6 @@ public class GiftInfo implements Serializable {
*/
public final static int CONSUME_TYPE_GOLD = 1;
/**
* 萝卜礼物
*/
public final static int CONSUME_TYPE_RADISH = 2;
private int count;
private int giftId;
private int giftType;