少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-14 fa456af06ddef00145aff72bdee795390c78586e
6197 【前端】【1.6】跨服匹配玩法
4个文件已添加
3个文件已修改
316 ■■■■■ 已修改文件
Core/NetworkPackage/ClientPack/ClientToMapServer/CA2_Interaction/CA231_tagCMClientStartCustomScene.cs 19 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/ClientPack/ClientToMapServer/CA2_Interaction/CA231_tagCMClientStartCustomScene.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/ClientPack/ClientToMapServer/CC1_CrossRealm/CC108_tagCMCrossRealmPKRobotOver.cs 21 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/ClientPack/ClientToMapServer/CC1_CrossRealm/CC108_tagCMCrossRealmPKRobotOver.cs.meta 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/CrossServerOneVsOne/CrossServerOneVsOnePkResult.cs 25 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/CrossServerOneVsOneClient/ClientCrossServerOneVsOne.cs 33 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
System/CrossServerOneVsOneClient/ClientCrossServerOneVsOneStage.cs 194 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
Core/NetworkPackage/ClientPack/ClientToMapServer/CA2_Interaction/CA231_tagCMClientStartCustomScene.cs
New file
@@ -0,0 +1,19 @@
using UnityEngine;
using System.Collections;
// A2 31 前端开始自定义场景 #tagCMClientStartCustomScene
public class CA231_tagCMClientStartCustomScene : GameNetPackBasic
{
    public CA231_tagCMClientStartCustomScene()
    {
        combineCmd = (ushort)0x03FE;
        _cmd = (ushort)0xA231;
    }
    public override void WriteToBytes()
    {
    }
}
Core/NetworkPackage/ClientPack/ClientToMapServer/CA2_Interaction/CA231_tagCMClientStartCustomScene.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: dac5e3d3907d6e94a86612907372331c
timeCreated: 1550133153
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
Core/NetworkPackage/ClientPack/ClientToMapServer/CC1_CrossRealm/CC108_tagCMCrossRealmPKRobotOver.cs
New file
@@ -0,0 +1,21 @@
using UnityEngine;
using System.Collections;
// C1 08 跨服PK挑战机器人结算 #tagCMCrossRealmPKRobotOver
public class CC108_tagCMCrossRealmPKRobotOver : GameNetPackBasic
{
    public byte IsWin;    //是否获胜
    public CC108_tagCMCrossRealmPKRobotOver()
    {
        combineCmd = (ushort)0x03FE;
        _cmd = (ushort)0xC108;
    }
    public override void WriteToBytes()
    {
        WriteBytes(IsWin, NetDataType.BYTE);
    }
}
Core/NetworkPackage/ClientPack/ClientToMapServer/CC1_CrossRealm/CC108_tagCMCrossRealmPKRobotOver.cs.meta
New file
@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 920284967326a6b4cbb749c4c87899f9
timeCreated: 1550133362
licenseType: Pro
MonoImporter:
  serializedVersion: 2
  defaultReferences: []
  executionOrder: 0
  icon: {instanceID: 0}
  userData:
  assetBundleName:
  assetBundleVariant:
System/CrossServerOneVsOne/CrossServerOneVsOnePkResult.cs
@@ -32,16 +32,29 @@
        public void UpdatePkResult(HC003_tagGCCrossRealmPKOverInfo pKOverInfo)
        {
            this.PkEndTime = pKOverInfo.TimeStr;
            this.OverType = pKOverInfo.OverType;
            this.WinnerID = (int)pKOverInfo.WinnerID;
            this.RoundCount = pKOverInfo.RoundCount;
            this.RoundWinnerIDs = pKOverInfo.RoundWinnerID;
            this.AddScore = pKOverInfo.AddScore;
            this.CurScore = (int)pKOverInfo.Score;
            this.DanLV = pKOverInfo.DanLV;
            this.WinStreak = pKOverInfo.CWinCnt;
            this.VsPlayerName = pKOverInfo.TagName;
            if (ClientCrossServerOneVsOne.isClientCrossServerOneVsOne)
            {
                this.PkEndTime = ClientCrossServerOneVsOne.resultSupplement.endTime.ToString();
                this.OverType = ClientCrossServerOneVsOne.resultSupplement.overType;
                this.WinnerID = ClientCrossServerOneVsOne.resultSupplement.winPlayerId;
                this.RoundCount = ClientCrossServerOneVsOne.resultSupplement.roundCount;
                this.RoundWinnerIDs = ClientCrossServerOneVsOne.resultSupplement.roundWinnerId;
                this.VsPlayerName = ClientCrossServerOneVsOne.resultSupplement.opponentName;
            }
            else
            {
                this.PkEndTime = pKOverInfo.TimeStr;
                this.OverType = pKOverInfo.OverType;
                this.WinnerID = (int)pKOverInfo.WinnerID;
                this.RoundCount = pKOverInfo.RoundCount;
                this.RoundWinnerIDs = pKOverInfo.RoundWinnerID;
                this.VsPlayerName = pKOverInfo.TagName;
            }
        }
        public void GetWinAndFailNum(out int winNum, out int failNum)
System/CrossServerOneVsOneClient/ClientCrossServerOneVsOne.cs
@@ -2,10 +2,12 @@
using System.Collections.Generic;
using UnityEngine;
using Snxxz.UI;
using System;
public class ClientCrossServerOneVsOne
{
    public static bool isClientCrossServerOneVsOne { get; private set; }
    public static FightResultSupplement resultSupplement;
    public static string GetRandomOpponentName(int job)
    {
@@ -14,8 +16,8 @@
        {
            try
            {
                var groupRandom = Random.Range(0, ServerListCenter.Instance.serverInfoCommon.common.Length);
                var serverRandom = Random.Range(0, ServerListCenter.Instance.serverInfoCommon.common[groupRandom].group_list.Length);
                var groupRandom = UnityEngine.Random.Range(0, ServerListCenter.Instance.serverInfoCommon.common.Length);
                var serverRandom = UnityEngine.Random.Range(0, ServerListCenter.Instance.serverInfoCommon.common[groupRandom].group_list.Length);
                var serverData = ServerListCenter.Instance.serverInfoCommon.common[groupRandom].group_list[serverRandom];
                if (serverData.running_status == (int)ServerState.Normal
@@ -49,14 +51,14 @@
        var serverName = ServerListCenter.Instance.currentServer.name;
        var playerName = PlayerDatas.Instance.baseData.PlayerName;
        package.PlayerName = StringUtility.Contact("[", serverName, "]", playerName);
        package.Number = (byte)Random.Range(1, 3);
        package.Number = (byte)UnityEngine.Random.Range(1, 3);
        var opponent = new HC001_tagGCCrossRealmPKMatchOK.tagGCCrossRealmPKMatchPlayer();
        opponent.Job = (byte)Random.Range(1, 3);
        opponent.Job = (byte)UnityEngine.Random.Range(1, 3);
        opponent.PlayerName = GetRandomOpponentName(opponent.Job);
        opponent.LV = (ushort)(PlayerDatas.Instance.baseData.LV + Random.Range(0, 5));
        opponent.LV = (ushort)(PlayerDatas.Instance.baseData.LV + UnityEngine.Random.Range(0, 5));
        opponent.MaxProDef = 0;
        opponent.MaxHP = (uint)(PlayerDatas.Instance.extersion.MaxHP + Random.Range(-100000, 100000));
        opponent.MaxHP = (uint)(PlayerDatas.Instance.extersion.MaxHP + UnityEngine.Random.Range(-100000, 100000));
        package.MatchPlayer = new HC001_tagGCCrossRealmPKMatchOK.tagGCCrossRealmPKMatchPlayer[] { opponent };
        CrossServerLogin.Instance.UpdateCrossServerOneVsOneData(package, true);
@@ -67,7 +69,8 @@
    public static void StartClientCrossServerOneVsOne()
    {
        isClientCrossServerOneVsOne = true;
        //发包
        var sendInfo = new CA231_tagCMClientStartCustomScene();
        GameNetSystem.Instance.SendInfo(sendInfo);
        StageLoad.Instance.PushSceneLoadCommand(new StageLoad.StageLoadCommand()
        {
            toMapId = 1000,
@@ -89,9 +92,11 @@
    }
    public static void FakeDungeonResult()
    public static void ReportDungeonResult(FightResultSupplement resultSupplement)
    {
        ClientCrossServerOneVsOne.resultSupplement = resultSupplement;
        var sendInfo = new CC108_tagCMCrossRealmPKRobotOver();
        sendInfo.IsWin = (byte)(resultSupplement.winPlayerId == PlayerDatas.Instance.baseData.PlayerID ? 1 : 0);
    }
    public static void StopClientCrossServerOneVsOne()
@@ -111,4 +116,14 @@
        });
    }
    public struct FightResultSupplement
    {
        public DateTime endTime;
        public int overType;
        public int winPlayerId;
        public int roundCount;
        public uint[] roundWinnerId;
        public string opponentName;
    }
}
System/CrossServerOneVsOneClient/ClientCrossServerOneVsOneStage.cs
@@ -4,6 +4,200 @@
public class ClientCrossServerOneVsOneStage : Stage
{
    static FightInfo fightInfo;
    static PKStageType pkStageType;
    PKStage currentStage;
    public override void Initialize()
    {
        base.Initialize();
        fightInfo = default(FightInfo);
        currentStage = null;
    }
    protected override void OnStageLoadFinish()
    {
        base.OnStageLoadFinish();
        currentStage = new WaitStartStage();
        currentStage.Begin();
    }
    protected override void OnUpdate()
    {
        base.OnUpdate();
        if (currentStage != null)
        {
            currentStage.Update();
            if (currentStage.completed)
            {
                currentStage.End();
                currentStage = null;
                switch (pkStageType)
                {
                    case PKStageType.WaitStart:
                        currentStage = new FightStage();
                        break;
                    case PKStageType.Fight:
                        if (fightInfo.isOver)
                        {
                            currentStage = new FightOverStage();
                        }
                        else
                        {
                            currentStage = new RoundPauseStage();
                        }
                        break;
                    case PKStageType.RoundPause:
                        currentStage = new FightStage();
                        break;
                    case PKStageType.FightOver:
                        break;
                    default:
                        break;
                }
                if (currentStage != null)
                {
                    currentStage.Begin();
                }
            }
        }
    }
    public abstract class PKStage
    {
        public float timer { get; protected set; }
        public float duration { get; protected set; }
        public bool completed { get; protected set; }
        public abstract void Begin();
        public abstract void Update();
        public abstract void End();
    }
    public class WaitStartStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.WaitStart;
            duration = 10f;
            //模拟开始倒计时
        }
        public override void End()
        {
            //模拟战斗开始包
        }
        public override void Update()
        {
            timer += duration;
            completed = timer >= duration;
        }
    }
    public class FightStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.Fight;
            duration = 60f;
            fightInfo.roundCount++;
        }
        public override void End()
        {
            fightInfo.roundWinnerIds[fightInfo.roundCount - 1] = 1000;//记录获胜者的id
            if (fightInfo.roundCount >= 2)
            {
                if (fightInfo.roundCount == 2)
                {
                    if (fightInfo.roundWinnerIds[0] == fightInfo.roundWinnerIds[1])
                    {
                        fightInfo.isOver = true;
                    }
                }
                else
                {
                    fightInfo.isOver = true;
                }
            }
        }
        public override void Update()
        {
            timer += Time.deltaTime;
            if (timer >= duration)//时间到或者有一方死亡,就算结束
            {
                completed = true;
            }
            else
            {
                completed = false;
            }
        }
    }
    public class RoundPauseStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.RoundPause;
            duration = 3f;
        }
        public override void End()
        {
            //模拟发战斗开始包
        }
        public override void Update()
        {
            timer += Time.deltaTime;
            completed = timer >= duration;
        }
    }
    public class FightOverStage : PKStage
    {
        public override void Begin()
        {
            pkStageType = PKStageType.FightOver;
            duration = 10f;
        }
        public override void End()
        {
            if (ClientCrossServerOneVsOne.isClientCrossServerOneVsOne)
            {
                ClientCrossServerOneVsOne.StopClientCrossServerOneVsOne();
            }
        }
        public override void Update()
        {
            timer += Time.deltaTime;
            completed = timer >= duration;
        }
    }
    public enum PKStageType
    {
        WaitStart,
        Fight,
        RoundPause,
        FightOver,
    }
    public struct FightInfo
    {
        public bool isOver;
        public int roundCount;
        public int[] roundWinnerIds;
    }
}