using System;
using System.Linq;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using static global::LinqExt;
///
/// 战斗模块
///
public class FightProxy : ProxyBase
{
#region 构造函数
public FightProxy() => this.opeCode = OpeCode.ope_fight;
#endregion
#region ' 680x '
///
/// 【6800】关卡挑战预先计算下奖励字符串
///
/// 区域Id
///
///
/// 奖励字符串 id,num;id,num
public void ArenasPreFight(int domainId, int gateId, int difficulty, Action callback = null)
{
Post(CmdCode.cmd_fight_ArenasPreFight, new object[] { gateId, difficulty }, resp =>
{
var rewardstr = resp.result["r"].ToString();
DropManager.Instance.DropStr = rewardstr;
callback?.Invoke(rewardstr);
});
}
///
/// [6801] 挑战关卡
///
/// 玩家Uid
/// 区域id
/// 关卡索引
/// 难度选择 0,1,2
/// 获得评星0,1,2,3, 如果战斗失败star=-1
/// 队伍列表
/// 回调函数
public void ArenasFight(int domainId, int gateId, int difficulty, GateStar stars,
List TeamArray,
Action callback = null)
{
UnityEngine.Debug.Assert(gateId > 0, "关卡id必须大于0(503001开始)");
Post(CmdCode.cmd_fight_ArenasFight, new object[] { gateId, difficulty, stars.ToIntValue(), TeamArray },
resp =>
{
var player = UserProxy.Instance.player;
var nandu = difficulty + 1;
FightProxy_RetVo.ArenasFight_RetVo vo = new FightProxy_RetVo.ArenasFight_RetVo(gateId, domainId);
var smGate = sm_gate.GetMoById(gateId);
vo.commander = new FightProxy_RetVo.CommanderChangeInfo();
vo.commander.addExp = resp.result["exp"].ToObject();
vo.GateName = smGate.gateName;
vo.WorldName = sm_gate_zone.GetMoById(domainId)?.zoneName ?? "本章之章";
vo.teamChange = new List();
foreach (var heroUid in TeamArray)
{
if (string.IsNullOrEmpty(heroUid))
{
continue;
}
var info = new FightProxy_RetVo.HeroChangedInfo();
info.addExp = smGate.HeroExp(nandu);
info.uid = int.Parse(heroUid);
vo.teamChange.Add(info);
}
player.ChangeUserAccount(AccountType.exp, vo.commander.addExp); // 指挥官经验
//player.ChangeUserAccount(AccountType.gold, vo.dropGold); // 掉落金币
player.areansRecord.InitArenasGateData((JObject)resp.result["gates"]); // 同步关卡记录
player.collectHero.InitData((JObject)resp.result["heros"],player); // 同步英雄数据
//player.InitFromStore((JObject)resp.result["store"]); // 同步背包数据
player.baseInfo.tili = resp.result["tili"].ToObject(); // 同步体力
player.baseInfo.gold = Convert.ToInt32(resp.result["gold"].ToString()); // 同步金币
player.baseInfo.resPoint = Convert.ToInt32(resp.result["resPoint"].ToString()); // 同步资源点
player.baseInfo.cash = Convert.ToInt32(resp.result["cash"].ToString()); // 同步钻石
var priv = resp.result.TryGetValue("priv",out var prJ)?prJ.ToObject() : null; // 私有字段记录了挑战记录
if (null != priv)
{
player.PrivateState = priv; // 同步挑战记录
}
TiliTime.Instance.SetTiliTime((long)resp.result["time"]); // 同步体力时间
if (resp.result["isFirst"].ToObject())
{
if (smGate.First_Hero(nandu) > 0)
{
vo.UnlockHero = player.collectHero.GetHeroGameInfoByModelID(smGate.First_Hero(nandu).ToString());
}
}
callback?.Invoke(vo);
});
}
///
/// [6803] 拉取(挑战)对手的信息
///
/// 对手UID
///
public void GetChallengeAdversaryInfo(string targetUID, Action callback = null)
{
Post(CmdCode.cmd_fight_GetChallengeAdversaryInfo, new object[] { targetUID },
resp =>
{
if (null != resp.result)
{
var adversary = resp.result["adversaryInfo"].ToObject();
foreach (var eqps in adversary.equipment.equipments.Values)
{ // 同步调整herouid的偏移
if (eqps.herouid > 0)
{
eqps.herouid -= 10000;
}
}
foreach (var yanls in adversary.yanling.items.Values)
{ // 同步进行herouid的偏移
if (yanls.herouid > 0)
{
yanls.herouid -= 10000;
}
}
foreach (var heroVo in adversary.heros.Values)
{
if (null == heroVo) continue;
heroVo.uid = (int.Parse(heroVo.uid) - 10000).ToString();
heroVo.EquipRef = adversary.equipment;
heroVo.YanlingRef = adversary.yanling;
}
callback?.Invoke(adversary);
}
else
{
throw new Exception("故障, 未找到该玩家数据!");
// 发生错误, 后台未找到此玩家数据...
}
});
}
///
/// [6804] 记录 挑战结果
///
/// 对手UID
///
public void LogChallengeResult(string targetUID, string name, string headImg, bool win, string msg = "", Action callback = null)
{
Post(CmdCode.cmd_fight_LogChallengeResult, new object[] { targetUID, name, headImg, win, msg }, resp => callback?.Invoke());
}
///
/// [6805] 拉取(挑战)记录
///
/// 对手UID
///
public void GetChallengeLog(Action callback = null)
{
Post(CmdCode.cmd_fight_GetChallengeLog, new object[] { },
resp =>
{
if (null != resp.result)
{
var vo = resp.result.ToObject();
callback?.Invoke(vo);
}
else
{
throw new Exception("故障, 未找到挑战记录数据!");
}
});
}
///
/// [6806] 领取(累计)星数奖励
///
///
///
///
///
public void GetStarRewards(int domainId, int diffculty, int stars, Action callback = null)
{
Post(CmdCode.cmd_fight_GetArenasActiveReward, new object[] { domainId, diffculty, stars },
resp =>
{
var p = UserProxy.Instance.player;
p.baseInfo.gold = resp.result["gold"].ToObject();
p.baseInfo.cash = resp.result["cash"].ToObject();
//p.InitFromStore((JObject)resp.result["store"]); // 同步背包
// 同步领取奖励记录
if (!p.areansRecord.chapterStarsRwd.ContainsKey(domainId))
{
p.areansRecord.chapterStarsRwd.Add(domainId, new Dictionary>() { });
}
int hardLevel = 1 + diffculty;
if (!p.areansRecord.chapterStarsRwd[domainId].ContainsKey(hardLevel))
{
p.areansRecord.chapterStarsRwd[domainId].Add(hardLevel, new List());
}
p.areansRecord.chapterStarsRwd[domainId][hardLevel].Add(stars);
callback?.Invoke();
});
}
#endregion
#region 闲置函数
///
/// [6802] 扫荡关卡
///
///
///
/// 关卡索引
/// 难度
/// 扫荡券id
///
[Obsolete("暂时不用2019年12月19日14:12:24")]
public void ArenasSweep(int gateId, int difficulty, int sweepItemId, Action callback = null)
{
Post(CmdCode.cmd_fight_ArenasSweep, new object[] { gateId, difficulty, sweepItemId },
resp =>
{
if (callback != null)
{
callback.Invoke(resp.result);
}
});
}
#endregion
#region ' 竞技场 681x '
///
/// [6810] 竞技场 - 主界面信息
///
///
public void PVP_MainInfo(Action callback)
{
Post(CmdCode.cmd_pvp_maininfo, new object[] { },
resp =>
{
if (callback != null)
{
var ret = resp.result.ToObject();
var pvp = UserProxy.Instance.player.pvpRecord;
pvp.defTeam = ret.defTeam;
pvp.pvpCoins = ret.pvpCoins;
pvp.fightTicket = ret.fightTicket;
FixArenasAdversaryInfo(ret.matches);
callback.Invoke(ret);
}
});
}
private static void FixArenasAdversaryInfo(List li)
{
li.ForEach(adversary =>
{
foreach (var eqps in adversary.equipment.equipments.Values)
{ // 同步调整herouid的偏移
if (eqps.herouid > 0)
{
eqps.herouid -= 10000;
}
}
foreach (var yanls in adversary.yanling.items.Values)
{ // 同步进行herouid的偏移
if (yanls.herouid > 0)
{
yanls.herouid -= 10000;
}
}
foreach (var heroVo in adversary.heros.Values)
{
if (null == heroVo) continue;
heroVo.uid = (int.Parse(heroVo.uid) - 10000).ToString();
heroVo.EquipRef = adversary.equipment;
heroVo.YanlingRef = adversary.yanling;
}
});
}
///
/// [6811] 竞技场 - 刷新对手(建议客户端设置时间间隔)
///
///
public void PVP_Refresh(Action> callback)
{
Post(CmdCode.cmd_pvp_refresh, new object[] { },
resp =>
{
var matches = resp.result["curMatches"].ToObject>();
callback?.Invoke(matches.ToList());
});
}
///
/// [6812] 竞技场 - 挑战对手
///
///
/// 战斗结果0负, 1 胜
///
public void PVP_PK(string target_uid, bool win, string target_name, string target_headImg, Action callback)
{
Post(CmdCode.cmd_pvp_pk, new object[] { target_uid, win, target_name, target_headImg },
resp => callback?.Invoke(resp.result.ToObject()));
}
///
/// [6813] 竞技场 - 设置防守队伍
///
///
///
public void PVP_SetDefTeam(List newTeam, Action> callback)
{
Post(CmdCode.cmd_pvp_setteam, new object[] { newTeam },
resp =>
{
var ret = resp.result.ToObject();
//UnityEngine.Debug.Assert(newTeam == ret);
UserProxy.Instance.player.pvpRecord = ret;
callback?.Invoke(ret.defTeam);
});
}
///
/// [6814] 竞技场 - 购买挑战票
///
/// 补充几个
///
public void PVP_BuyTicket(int amt, Action callback)
{
Post(CmdCode.cmd_pvp_buyTicket, new object[] { amt },
resp =>
{
if (callback != null)
{
var ret = resp.result.ToObject();
UserProxy.Instance.player.pvpRecord.fightTicket = ret.fightTicket; // 同步挑战票
UserProxy.Instance.player.baseInfo.cash = ret.userCash; // 同步玩家钻石
callback.Invoke(ret);
}
});
}
///
/// 6815 竞技场 - 拉取排行榜信息
///
/// 排名起始索引 1,11,21,31,41,51,61,71,81,91
/// 拉取数量,建议不超10, 排行榜最大500人
///
public void PVP_getRank(int start, int num, Action callback)
{
Post(CmdCode.cmd_pvp_getRank, new object[] { start, num },
resp => callback?.Invoke(resp.result.ToObject()));
}
///
/// 6816 竞技场 - 查询战报
///
///
public void PVP_getLog(Action callback)
{
Post(CmdCode.cmd_pvp_getLog, new object[] { }, resp => callback?.Invoke(resp.result.ToObject()));
}
#endregion
#region ' 竞技 商店 '
///
/// [6820] 竞技商店 - 主界面
///
///
public void PVP_ShopMain(Action callback)
{
Post(CmdCode.cmd_fight_pvpShop_getMainInfo, new object[] { },
resp =>
{
var ret = resp.result.ToObject();
UserProxy.Instance.player.pvpRecord = ret;
callback?.Invoke(ret);
});
}
///
/// [6821] 竞技商店 - 购买道具
///
///
public void PVP_ShopBuy(int itemId, Action callback)
{
Post(CmdCode.cmd_fight_pvpShop_buy, new object[] { itemId },
resp =>
{
var p = UserProxy.Instance.player;
var ret = resp.result["pvp"].ToObject();
//p.InitFromStore(resp.result["store"] as JObject);
p.pvpRecord = ret;
callback?.Invoke(ret);
});
}
///
/// [6822] 竞技商店 - 刷新道具
///
///
public void PVP_ShopRefresh(Action callback)
{
Post(CmdCode.cmd_fight_pvpShop_refresh, new object[] { },
resp =>
{
var ret = resp.result.ToObject();
UserProxy.Instance.player.pvpRecord = ret;
callback?.Invoke(ret);
});
}
#endregion
#region ' 世界boss '
public void BossFight_Enter(int bossid) {
Post(CmdCode.fight_worldBoss_enter, new object[] { BossFight.Instance.bossId },
resp => {
});
}
///
/// 6834 世界boss, 拉取排行榜
///
///
public void BossFight_GetRank(Action> callback)
{
Post(CmdCode.fight_worldBoss_refresh_rank, new object[] {BossFight.Instance.bossId },
resp =>
{
var dic2 = new Dictionary();
if (resp.result["rank"].Count() > 0)
{
var dic = resp.result["rank"].ToObject>();
foreach (var kv in dic)
{
var arr = kv.Key.Explode("__");
var name = (arr.Length > 1 ? arr[1] : arr[0]) ?? "-";
dic2.Add(kv.Key.Substring(kv.Key.IndexOf("__") + 2), kv.Value);
}
}
callback?.Invoke(dic2);
});
}
#endregion
#region ' 无尽塔 '
///
/// 6841 无尽塔 - 查询当前进度
///
///
public void EndlessTower_Get(Action callback)
{
Post(CmdCode.fight_endlessTower_Get, new object[] { },
resp => callback?.Invoke(resp.result["index"].ToObject()));
}
///
/// 6842 无尽塔 - 前进
///
/// 刚通关的索引
///
public void EndlessTower_Up(int passIndex, Action callback)
{
Post(CmdCode.fight_endlessTower_Up, new object[] { passIndex },
resp =>
{
var p = UserProxy.Instance.player;
p.baseInfo = resp.result["baseInfo"].ToObject();
callback?.Invoke(resp.result["index"].ToObject());
});
}
///
/// 6843 无尽塔 - 领取特殊奖励
///
/// 遇到 5/10 会有特殊奖励可领取
/// 奖励字符串请自取
public void EndlessTower_Drawreward(int index, Action callback)
{
Post(CmdCode.fight_endlessTower_Drawreward, new object[] { index },
resp =>
{
var p = UserProxy.Instance.player;
p.baseInfo = resp.result["baseInfo"].ToObject();
callback?.Invoke();
});
}
#endregion
#region-------战斗复活
///
/// 满血复活
///
///
public void BackBloodRevive(Action callback)
{
Post(CmdCode.fight_fullBlood, new object[] { },
resp =>
{
var p = UserProxy.Instance.player;
p.baseInfo.cash = int.Parse(resp.result["cash"].ToString());
callback?.Invoke(true);
});
}
#endregion
#region 内部类
///
/// 任务/挑战目标达成记录(三星评价)
///
/// gwang
//[Obsolete("评星已经没什么意义了, 现在追求的是关卡内掉落.")] // ps. 2021.又给恢复了
[Obsolete("后来又改成开放地图模式, 没有关卡了 -gwang 2022")]
public class GateStar
{
///
/// 根据三个条件达成情况构造(战斗结果转给后台)
///
///
///
///
public GateStar(bool p1, bool p2, bool p3)
{ this.S1 = p1; this.S2 = p2; this.S3 = p3; }
///
/// 根据后台记录的数值构造(反向提供给前端显示层)
///
///
public GateStar(int i)
{
this.S1 = (i & 1) > 0;
this.S2 = (i & 2) > 0;
this.S3 = (i & 4) > 0;
}
///
/// 第一个目标达成
///
public readonly bool S1;
///
/// 第二个目标达成
///
public readonly bool S2;
///
/// 第三个目标达成
///
public readonly bool S3;
///
/// 取其压缩格式(三个变量压缩到一个int值中)
///
///
public int ToIntValue()
{
return ((S3 ? 1 : 0) << 2) | ((S2 ? 1 : 0) << 1) | (S1 ? 1 : 0);
}
///
/// 统计总星数
///
public int Count => (S3 ? 1 : 0) + (S2 ? 1 : 0) + (S1 ? 1 : 0);
}
#region 普通挑战
///
/// (挑战)对手信息
///
/// 用该数据初始化对手战场信息的时候, 注意理清数据来源,不要引用到玩家的数据去(比如hero,equip和yanling)
public class AdversaryInfo
{
///
/// uid
///
public string uid;
///
/// 昵称
///
public string name;
///
/// 等级
///
public int level;
///
/// 头像
///
public string headImg;
///
/// 玩家装备数据
///
public GameCollectEquips equipment;
///
/// 玩家言灵数据
///
public GameCollectYanling yanling;
///
/// 玩家战队英雄数据集合
///
public Dictionary heros = new Dictionary();
}
///
/// (挑战)日志
///
public class MyChallengeLog
{
///
/// 主动挑战记录
///
public List offLog;
///
/// 被动防守记录
///
public List defLog;
///
/// 对手信息(简)
///
public class AdversaryInfo
{
///
/// uid
///
public string uid;
///
/// 昵称
///
public string name;
///
/// 头像
///
public string headImg;
///
/// 战斗结果
///
public bool win;
///
/// 胜利者留言
///
public string msg;
///
/// 时间戳
///
public int ts;
// 其他信息再添加
// . . . . . .
}
}
#endregion
#region 竞技场
///
/// 竞技场 对手信息(比普通挑战对手增加了竞技场积分和总战力信息)
///
public class AdversaryInfo_Arenas : AdversaryInfo
{
///
/// 竞技场积分
///
public int score = 0;
///
/// 总战力
///
public int fpower = 0;
}
///
/// 竞技场主界面所需信息
///
public class PVP_Main_UIVo
{
///
/// 竞技场积分
///
public int score;
///
/// 竞技场排名
///
public int rank;
///
/// 竞技币
///
public int pvpCoins;
///
/// 总战力
///
public int fPower;
///
/// 挑战票
///
public int fightTicket;
///
/// 玩家自己的防守战队(英雄的uid列表)
///
public List defTeam;
///
/// 新挑战记录条数
///
public int numNewLog;
///
/// 匹配对手
///
public List matches;
///
/// 当前奖励
///
///
public sm_pvp_rankreward currentReward()
{
return sm_pvp_rankreward.GetMoByRank(this.rank);
}
///
/// 产看所有奖励
///
///
public List HaveALookOfAllRewards()
{
return GameConfigData.Ins.pvp_rankreward.Values.ToList();
}
}
///
/// 竞技场挑战对手返回值
///
public class PVP_PK_Ret
{
///
/// 自己剩余免费票
///
public int freeFightTickets;
///
/// 自己剩余挑战票
///
public int fightTicket;
///
/// 自己挑战之前积分
///
public int RA;
///
/// 对手挑战之前积分
///
public int RB;
///
/// 自己最新积分
///
public int R_A;
///
/// 对手最新积分
///
public int R_B;
///
/// 排名变化
///
public int rank_diff;
///
/// 最新排名
///
public int rank_new;
}
///
/// 竞技场 购买挑战票返回值
///
public class PVP_BuyTicket_Ret
{
///
/// 最新挑战票数量
///
public int fightTicket;
///
/// 花费钻石
///
public int costCash;
///
/// 玩家剩余钻石
///
public int userCash;
}
///
/// (竞技场)战斗日志
///
public class MyPVPLog
{
///
/// 主动挑战记录
///
public List offLog;
///
/// 被动防守记录
///
public List defLog;
///
/// 对手信息(简)
///
public class AdversaryInfo
{
///
/// uid
///
public string uid;
///
/// 昵称
///
public string name;
///
/// 头像
///
public string headImg;
///
/// 战斗结果
///
public bool win;
///
/// 胜利者留言
///
public string msg;
///
/// 时间戳
///
public int ts;
///
/// 积分变更信息
///
public int scoreInfo;
// 其他信息再添加
// . . . . . .
}
}
///
/// 竞技场 排行榜信息
///
public class PVP_RankInfo
{
///
/// 玩家列表
///
public Dictionary dic;
///
/// 我的排名
///
public int myRank;
///
/// 我的积分
///
public int myScore;
}
#endregion
#endregion
}