using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; /* 野狼关卡-本地pk模式 */ public class WolfHuntGameMode_LocalPK : WolfHuntGameMode, ChallengeGameModeLocalPK { public int currentPlayerIndex = 0; // 双人0和1 float singleShootReadyTime = 30f; float singleShootReadyTimeMax = 30f; int[] playerHpList = {20, 20}; public bool[] playerDieList = {false, false}; public WolfHuntGameMode_LocalPK(GameMgr gameMgr) : base(gameMgr) { hunterGamePlayerScoreCounter = new HunterGamePlayerScoreCounter(this); InitByCurPlayerIndex(); GameEventCenter.ins.onBowArrowShootOut += (a, b) => { hasShootOut = true; }; onHpZero += () => {//监听到当前玩家死亡 playerDieList[currentPlayerIndex] = true; if (hasShootOut) return; //此时箭已射出,避免重复处理下面的逻辑,等NextShoot来处理 //切换到下一个玩家 if (IsOtherPlayerNotDie()) { ArmBow.ins.readyShoot(); NextPlayerFinal(); } else { //游戏结束 AnnounceGameOver(); } }; // this.playerHpList[0] = this.playerHpList[1] = this.hpMax = this.hp = 2; // QuicklyCreateAnimalForDebug(); } public override void Start() { GameMgr.ins.transform.Find("WolfActGrid").gameObject.SetActive(true); SetLevel(5); AddHuntGameView(); this.gameMgr.transform.Find("HunterGameView_LocalPK").gameObject.SetActive(true); AddReadyView(); } public override void Update() { base.Update(); if (gameMgr.gameOver || pauseTimeCounting) return; if (!IsOtherPlayerNotDie()) { //另一个玩家已经死了,倒计时就不要走了 singleShootReadyTime = singleShootReadyTimeMax; return; } singleShootReadyTime -= Time.deltaTime; if (singleShootReadyTime <= 0) { //切换玩家 ArmBow.ins.readyShoot(); NextPlayerFinal(); } } bool hasShootOut; public override bool DoNextShoot() { hasShootOut = false; if (IsAllPlayerDie()) { AnnounceGameOver(); return false; } bool canDo = base.DoNextShoot(); if (canDo && IsOtherPlayerNotDie()) { NextPlayerFinal(); } return canDo; } void AddReadyView() { GameObject view = Resources.Load("Prefabs/Views/PKGameReadyView_Challenge"); GameObject o = GameObject.Instantiate(view); PKGameReadyView_Challenge script = o.GetComponent(); script.currentPlayerIndex = currentPlayerIndex; } //切换到下一个玩家 void NextPlayerFinal() { NextPlayer(); BanBowReady(); AddReadyView(); } void NextPlayer() { RecordByCurPlayerIndex(); currentPlayerIndex = GetNextPlayerIndex(); InitByCurPlayerIndex(); singleShootReadyTime = singleShootReadyTimeMax; } int GetNextPlayerIndex() { return (currentPlayerIndex + 1) % 2; } bool IsAllPlayerDie() { return playerHpList[GetNextPlayerIndex()] <= 0 && hp <= 0; } bool IsOtherPlayerNotDie() { return playerHpList[GetNextPlayerIndex()] > 0; } void InitByCurPlayerIndex() { hp = playerHpList[currentPlayerIndex]; HunterGameView v = GameObject.FindObjectOfType(); if (v) v.RenderHPImmediate(); } void RecordByCurPlayerIndex() { playerHpList[currentPlayerIndex] = hp; } //localPK interface public int GetCurrentPlayIndex() { return currentPlayerIndex; } public (float, float) GetSingleShootReadyTime() { return (singleShootReadyTime, singleShootReadyTimeMax); } HunterGamePlayerScoreCounter hunterGamePlayerScoreCounter; public HunterGamePlayerScoreCounter getHunterGamePlayerScoreCounter() { return hunterGamePlayerScoreCounter; } }